diff --git a/macchinettaHelper.h- b/macchinettaHelper.h- deleted file mode 100644 index 8e71a58..0000000 --- a/macchinettaHelper.h- +++ /dev/null @@ -1,2052 +0,0 @@ -#include -#include "macchinetta.h" -#include "containerMochaccino.h" - -namespace NS_MOCHA { - -using boost::multi_index_container; -using namespace boost::multi_index; - - -const unsigned short METHOD_NAME_MAX_SIZE=80; -const unsigned short PVNAME_MAX_SIZE=80; - -const unsigned short MONITOR_ACTION_MAX_SIZE=255; -const unsigned short ME_MESSAGE_MAX_SIZE=255; - -CAFE cafe; -CAFEGlobalAlarmCondition cgac; -CAFEGlobalAlarmSeverity cgas; - - -bool isCAInitialized=false; -bool collectionsLoaded=false; -bool groupsLoaded=false; - -bool reportError=false; - -bool withExceptions=false; - -size_t neWithinAllDataCells=0; - -size_t neWithinAllCells=0; -size_t iWithinAllCells=0; -dbr_string_t * inputStringCell; -pv_string_t * inputPVStringCell; - -//Declarations -mxArray *mData; -mxArray *xData; -mxArray *yData; -mxArray *zData; - -mxLogical *logicalData; - - -int32_T * longStatus; -int64_T * longlongStatus; -int16_T * shortAlarmStatus; -int16_T * shortAlarmSeverity; - -epicsTimeStamp ets1; -uint32_T * d4; -uint32_T * d9; -uint32_T * fHandle; - -uint8_T * ucharArray; -uint16_T * ushortArray; -uint32_T * ulongArray; -uint64_T * ulonglongArray; -int8_T * charArray; -int16_T * shortArray; -int32_T * longArray; -int64_T * longlongArray; -float * floatArray; -double * doubleArray; - -bool * inputBool; -int8_T * inputChar; -float * inputFloat; -int16_T * inputShort; -double * inputDouble; -int32_T * inputLong; -int64_T * inputLongLong; - -uint8_T * inputUChar; -uint16_T * inputUShort; -uint32_T * inputULong; -uint64_T * inputULongLong; - -uint32_T * handleULong; -uint64_T * handleULongLong; - -uint32_T * handleULongReadback; - -dbr_string_t * stringArray; - - -//Ctrl -uint16_T * precision; -uint16_T * noEnumStrings; -double * udl; -double * ldl; -double * ual; -double * lal; -double * uwl; -double * lwl; -double * ucl; -double * lcl; - -int32_T status=ECA_NORMAL;; - -int32_T pvLength; -int32_T messLength; -int32_T MELength; - - -char acceleratorBase[PVNAME_MAX_SIZE]; - -char groupName[PVNAME_MAX_SIZE]; // -char pv[PVNAME_MAX_SIZE]; // -char mess[METHOD_NAME_MAX_SIZE]; // open get set close -char monAction[MONITOR_ACTION_MAX_SIZE]; // open get set close -char MEmess[METHOD_NAME_MAX_SIZE]; // open get set close - -mwSignedIndex nelem; - -double * dd; - -uint32_T handle=0; -uint32_T ghandle=0; - -uint32_T monitorID=0; - -int16_T nfieldsInfo=11; -int16_T nfieldsME=5; -int16_T nfields=5; -int16_T nfieldsExtra=11; -int16_T nfieldsCtrl=21; - -const char * fnamesInfo[11] ={"handle","pv","channelID","connectFlag","hostName","dataType", -"className","accessRead", "accessWrite","nelem","connectionState"}; - - -const char * fnamesME[5] ={"pv","handle","status","statusText","statusInfo"}; -const char * fnames[5] ={"val","status","alarmStatus","alarmSeverity","ts"}; -const char * fnamesExtra[11] ={"handle","pv","val","status","status_str","alarmStatus","alarmStatus_str", - "alarmSeverity","alarmSeverity_str","ts","epicsTS"}; -const char * fnamesCtrl[21]={"handle","pv","val","status","status_str","alarmStatus","alarmStatus_str", - "alarmSeverity","alarmSeverity_str", - "precision","units","noEnumStrings","enumStrings", - "upperDisplayLimit","lowerDisplayLimit","upperAlarmLimit", "lowerAlarmLimit", - "upperWarningLimit","lowerWarningLimit","upperControlLimit","lowerControlLimit"}; - -mxArray *fout0; mxArray *fout1; mxArray *fout2; mxArray *fout3; mxArray *fout4; -mxArray *fout5; mxArray *fout6; mxArray *fout7; mxArray *fout8; mxArray *fout9; -mxArray *fout10; mxArray *fout11; mxArray *fout12; mxArray *fout13; mxArray *fout14; -mxArray *fout15; mxArray *fout16; mxArray *fout17; mxArray *fout18; -mxArray *fout1a; mxArray *fout2a; mxArray *fout3a; - -unsigned int nc=0,nr=0,nn=0; - -mochaccino_set ms; -mochaccino_set mdt; - -enum mdtIndex {MOCHA_NATIVE=0, MOCHA_CHAR, MOCHA_UCHAR, MOCHA_SHORT, MOCHA_USHORT, - MOCHA_INT, MOCHA_UINT, MOCHA_LONG, MOCHA_ULONG, - MOCHA_FLOAT, MOCHA_DOUBLE, MOCHA_STRING}; -//map Strings to Integers - -enum mochaIndex {SHOW=1, OPEN, OPEN_ARRAY, OPEN_WAIT, GET_OPEN_WAIT_TIME, - OPEN_WAIT_WITH_TIME,OPEN_WAIT_TIME_TO_DEFAULT, - OPEN_NOWAIT, OPEN_NOW, OPEN_NOW_AND_WAIT, OPEN_GROUP, - CLOSE, CLOSE_ARRAY, CLOSE_GROUP, CA_POLL, MEX_UNLOCK, MOCHA_VERSION, - WITH_EXCEPTIONS, HAVE_EXCEPTIONS, SEND_NOW, - GET=100, GET_INT8, GET_INT16, GET_INT32, GET_INT64, GET_UINT8, - GET_UINT16, GET_UINT32, GET_UINT64, GET_FLOAT, GET_DOUBLE, - GET_STRING, GET_CACHE, GET_ASYN, GET_SCALAR_ARRAY, - GET_SCALAR_ARRAY_CACHE, GET_ARRAY_ASYN, - GET_STRUCT_ARRAY, GET_STRUCT_ARRAY_CACHE, - GET_STRUCT_EXTENDED_ARRAY, GET_STRUCT_EXTENDED_ARRAY_CACHE, - GET_CELL_ARRAY, GET_CELL_ARRAY_CACHE, - GET_WF_AS_STRING, GET_WF_AS_STRING_CACHE, - GET_GROUP, GET_GROUP_CACHE, GET_GROUP_EXTENDED, GET_GROUP_EXTENDED_CACHE, - GET_STRUCT, GET_STRUCT_CACHE, GET_STRUCT_EXTENDED, GET_STRUCT_EXTENDED_CACHE, - GET_CTRL_STRUCT, GET_CTRL_CACHE, GET_ME_STRUCT, GET_CHANNEL_INFO, - FETCH_INDEX_OF_GROUP_MEMBER, FETCH_INDEX_OF_COLLECTION_MEMBER, - GET_STATUS=200, GET_STATUS_TEXT, GET_STATUS_INFO, IS_STATUS_TIMEOUT, - GET_ALARM, GET_ALARM_AS_STRING, - STATUS_AS_STRING, ALARM_STATUS_AS_STRING, ALARM_SEVERITY_AS_STRING, - STATUS_LIST, ALARM_STATUS_LIST, ALARM_SEVERITY_LIST, - GET_TIMESTAMP, GET_EPICS_TIMESTAMP, GET_PULSEID_FROM_TIMESTAMP, - GET_PULSEID_FROM_TIMESTAMP_GROUP, - GET_READ_ACCESS, GET_WRITE_ACCESS, - INIT_GET_SYNC_WITH_CALLBACK_DEFAULT,INIT_GET_SYNC_WITHOUT_CALLBACK, - SET=300, SET_AND_GET, SET_AND_MATCH, SET_SCALAR_ARRAY, SET_STRUCT_ARRAY, SET_GROUP, SET_PUT_PREPARE, - SET_PUT_WAIT, SET_PUT_NOWAIT, - GET_TIMEOUT, SET_TIMEOUT, SET_TIMEOUT_DEFAULT, - SET_TIMEOUT_PUT, SET_TIMEOUT_GET, SET_SELF_GOVERNING_TIMEOUT, - GET_SG_TIMEOUT, SET_SG_TIMEOUT, SET_SG_TIMEOUT_DEFAULT, - SET_SG_TIMEOUT_PUT, SET_SG_TIMEOUT_GET, SET_SG_SELF_GOVERNING_TIMEOUT, - SET_NELEM, SET_NELEM_CACHE, SET_OFFSET, - GET_NELEM_CLIENT, GET_NELEM_NATIVE, GET_NELEM_REQUEST, - GET_NELEM, GET_NELEM_CACHE, GET_OFFSET, - MONITOR=400, MONITOR_STOP, MONITOR_FLUSH_EVENT, - GET_MONITOR_HANDLES, GET_MONITOR_HANDLES_AND_ACTIONS, - IS_CONNECTED=500, ALL_CONNECTED, - PRINT_STATUS=600, PRINT_MONITORS, PRINT_HANDLE, PRINT_HANDLES, - PRINT_DISCONNECTED_HANDLES,GET_HANDLES,GET_HANDLE_STATES, - GET_HANDLES_WITHIN_GROUP, - GET_DISCONNECTED_HANDLES, GET_CONNECTED_HANDLES, - HANDLE_FROM_PV, PV_FROM_HANDLE, LIST_COLLECTIONS, LIST_COLLECTION_MEMBERS, - LIST_GROUPS, LIST_GROUP_MEMBERS, DEFINE_GROUP, - LOAD_XML_COLLECTIONS=900, LOAD_XML_GROUPS, LOAD_SF_GROUPS, GET_CHANNEL_LIST, - TEST=999 }; - -void msInsert() { - - ms.insert(mochaccino(SHOW, "show")); - ms.insert(mochaccino(OPEN, "open")); - ms.insert(mochaccino(OPEN_ARRAY, "openarray")); - ms.insert(mochaccino(CLOSE_ARRAY, "closearray")); - ms.insert(mochaccino(OPEN_WAIT, "openwait")); - ms.insert(mochaccino(GET_OPEN_WAIT_TIME, "getopenwaittime")); - ms.insert(mochaccino(OPEN_NOWAIT, "opennowait")); - ms.insert(mochaccino(OPEN_NOWAIT, "openprepare")); - ms.insert(mochaccino(OPEN_NOW, "opennow")); - ms.insert(mochaccino(OPEN_NOW_AND_WAIT, "opennowandwait")); - ms.insert(mochaccino(OPEN_WAIT_WITH_TIME, "setopenwaittime")); - ms.insert(mochaccino(OPEN_WAIT_TIME_TO_DEFAULT, "setopenwaittimetodefault")); - - ms.insert(mochaccino(OPEN_GROUP, "opengroup")); - ms.insert(mochaccino(CLOSE, "close")); - - ms.insert(mochaccino(CLOSE_GROUP, "closegroup")); - - ms.insert(mochaccino(CA_POLL, "capoll")); - ms.insert(mochaccino(MEX_UNLOCK, "mexunlock")); - ms.insert(mochaccino(MOCHA_VERSION, "version")); - - ms.insert(mochaccino(WITH_EXCEPTIONS, "withexceptions")); - ms.insert(mochaccino(WITH_EXCEPTIONS, "setexceptions")); - ms.insert(mochaccino(HAVE_EXCEPTIONS, "haveexceptions")); - ms.insert(mochaccino(SEND_NOW, "sendnow")); - ms.insert(mochaccino(SEND_NOW, "caflush")); - ms.insert(mochaccino(GET_ASYN, "getasyn")); - ms.insert(mochaccino(GET_ME_STRUCT, "getmestruct")); - - ms.insert(mochaccino(GET_WF_AS_STRING, "getcharasstring")); - ms.insert(mochaccino(GET_WF_AS_STRING_CACHE, "getcharasstringcache")); - ms.insert(mochaccino(GET_WF_AS_STRING, "getwfasstring")); - ms.insert(mochaccino(GET_WF_AS_STRING_CACHE, "getwfasstringcache")); - - ms.insert(mochaccino(GET_SCALAR_ARRAY, "getscalararray")); - ms.insert(mochaccino(GET_SCALAR_ARRAY_CACHE,"getscalararraycache")); - - ms.insert(mochaccino(GET_CELL_ARRAY, "getcellarray")); - ms.insert(mochaccino(GET_CELL_ARRAY_CACHE, "getcellarraycache")); - - ms.insert(mochaccino(GET_ARRAY_ASYN, "getarrayasyn")); - - //ms.insert(mochaccino(GET_STRUCT_ARRAY, "getstructarray")); - //ms.insert(mochaccino(GET_STRUCT_ARRAY_CACHE,"getstructarraycache")); - ms.insert(mochaccino(GET_STRUCT_ARRAY, "getpvarray")); - ms.insert(mochaccino(GET_STRUCT_ARRAY_CACHE,"getpvarraycache")); - - - ms.insert(mochaccino(GET_STRUCT_EXTENDED_ARRAY, "getstructarray")); - ms.insert(mochaccino(GET_STRUCT_EXTENDED_ARRAY_CACHE,"getstructarraycache")); - //ms.insert(mochaccino(GET_STRUCT_EXTENDED_ARRAY, "getpvxarray")); - //ms.insert(mochaccino(GET_STRUCT_EXTENDED_ARRAY_CACHE,"getpvxarraycache")); - - ms.insert(mochaccino(INIT_GET_SYNC_WITH_CALLBACK_DEFAULT, "usesyncgetwithdefaultcallback")); - ms.insert(mochaccino(INIT_GET_SYNC_WITHOUT_CALLBACK, "usesyncgetwithoutcallback")); - - ms.insert(mochaccino(GET, "get")); - ms.insert(mochaccino(GET_CACHE, "getcache")); - ms.insert(mochaccino(GET_UINT8, "getuint8")); - ms.insert(mochaccino(GET_UINT16, "getuint16")); - ms.insert(mochaccino(GET_UINT32, "getuint32")); - ms.insert(mochaccino(GET_UINT64, "getuint64")); - ms.insert(mochaccino(GET_INT8, "getint8")); - ms.insert(mochaccino(GET_INT16, "getint16")); - ms.insert(mochaccino(GET_INT32, "getint32")); - ms.insert(mochaccino(GET_INT64, "getint64")); - ms.insert(mochaccino(GET_FLOAT, "getfloat")); - ms.insert(mochaccino(GET_FLOAT, "getsingle")); - ms.insert(mochaccino(GET_DOUBLE, "getdouble")); - ms.insert(mochaccino(GET_STRING, "getstring")); - - //ms.insert(mochaccino(GET_STRUCT, "getstruct")); - //ms.insert(mochaccino(GET_STRUCT_CACHE, "getstructcache")); - ms.insert(mochaccino(GET_STRUCT, "getpv")); - ms.insert(mochaccino(GET_STRUCT_CACHE, "getpvcache")); - - ms.insert(mochaccino(GET_STRUCT_EXTENDED, "getstruct")); - ms.insert(mochaccino(GET_STRUCT_EXTENDED_CACHE, "getstructcache")); - //ms.insert(mochaccino(GET_STRUCT_EXTENDED, "getpvx")); - //ms.insert(mochaccino(GET_STRUCT_EXTENDED_CACHE, "getpvxcache")); - - ms.insert(mochaccino(GET_GROUP, "getgroup")); - ms.insert(mochaccino(GET_GROUP_CACHE, "getgroupcache")); - ms.insert(mochaccino(GET_GROUP, "getpvgroup")); - ms.insert(mochaccino(GET_GROUP_CACHE, "getpvgroupcache")); - ms.insert(mochaccino(GET_GROUP_EXTENDED, "getstructgroup")); - ms.insert(mochaccino(GET_GROUP_EXTENDED_CACHE, "getstructgroupcache")); - - ms.insert(mochaccino(GET_CTRL_STRUCT, "getctrl")); - ms.insert(mochaccino(GET_CTRL_CACHE, "getctrlcache")); - - ms.insert(mochaccino(FETCH_INDEX_OF_GROUP_MEMBER, "idxgrpmem")); - ms.insert(mochaccino(FETCH_INDEX_OF_COLLECTION_MEMBER, "idxcolmem")); - ms.insert(mochaccino(LIST_GROUPS, "listgroups")); - ms.insert(mochaccino(LIST_GROUP_MEMBERS, "listgroupmembers")); - ms.insert(mochaccino(LIST_COLLECTIONS, "listcollections")); - ms.insert(mochaccino(LIST_COLLECTION_MEMBERS, "listcollectionmembers")); - ms.insert(mochaccino(STATUS_AS_STRING, "statusasstring")); - ms.insert(mochaccino(ALARM_STATUS_AS_STRING, "alarmstatusasstring")); - ms.insert(mochaccino(ALARM_SEVERITY_AS_STRING, "alarmseverityasstring")); - - ms.insert(mochaccino(STATUS_LIST, "statuslist")); - ms.insert(mochaccino(ALARM_STATUS_LIST, "alarmstatuslist")); - ms.insert(mochaccino(ALARM_SEVERITY_LIST, "alarmseveritylist")); - - ms.insert(mochaccino(GET_STATUS, "getstatus")); - ms.insert(mochaccino(GET_STATUS_TEXT, "statusastext")); - ms.insert(mochaccino(GET_STATUS_INFO, "statusinfo")); - ms.insert(mochaccino(IS_STATUS_TIMEOUT, "istimeout")); - ms.insert(mochaccino(GET_ALARM, "getalarm")); - ms.insert(mochaccino(GET_ALARM_AS_STRING, "getalarmasstring")); - ms.insert(mochaccino(GET_TIMESTAMP, "gettimestamp")); - ms.insert(mochaccino(GET_EPICS_TIMESTAMP, "getepicstimestamp")); - ms.insert(mochaccino(GET_EPICS_TIMESTAMP, "getets")); - ms.insert(mochaccino(GET_PULSEID_FROM_TIMESTAMP, "getpulseidfromts")); - ms.insert(mochaccino(GET_PULSEID_FROM_TIMESTAMP_GROUP,"getgrouppulseidfromts")); - - ms.insert(mochaccino(GET_READ_ACCESS, "getreadaccess")); - ms.insert(mochaccino(GET_WRITE_ACCESS, "getwriteaccess")); - ms.insert(mochaccino(GET_CHANNEL_INFO, "getchannelinfo")); - ms.insert(mochaccino(GET_CHANNEL_INFO, "getinfo")); - - ms.insert(mochaccino(SET, "set")); - ms.insert(mochaccino(SET_AND_GET, "setandget")); - ms.insert(mochaccino(SET_AND_MATCH, "setandmatch")); - ms.insert(mochaccino(SET_SCALAR_ARRAY, "setscalararray")); - ms.insert(mochaccino(SET_STRUCT_ARRAY, "setstructarray")); - ms.insert(mochaccino(SET_STRUCT_ARRAY, "setpvarray")); - ms.insert(mochaccino(SET_STRUCT_ARRAY, "setmany")); - - - ms.insert(mochaccino(SET_GROUP, "setgroup")); - ms.insert(mochaccino(SET_PUT_PREPARE, "setputprepare")); - ms.insert(mochaccino(SET_PUT_WAIT, "setputwait")); - ms.insert(mochaccino(SET_PUT_NOWAIT, "setputnowait")); - ms.insert(mochaccino(SET_PUT_NOWAIT, "setputdefault")); - - ms.insert(mochaccino(GET_TIMEOUT, "gettimeout")); - ms.insert(mochaccino(SET_TIMEOUT, "settimeout")); - ms.insert(mochaccino(SET_TIMEOUT_PUT, "settimeoutput")); - ms.insert(mochaccino(SET_TIMEOUT_GET, "settimeoutget")); - ms.insert(mochaccino(SET_TIMEOUT_DEFAULT,"settimeoutdefault")); - ms.insert(mochaccino(SET_SELF_GOVERNING_TIMEOUT,"setselfgoverningtimeout")); - - ms.insert(mochaccino(GET_SG_TIMEOUT, "getsgtimeout")); - ms.insert(mochaccino(SET_SG_TIMEOUT, "setsgtimeout")); - ms.insert(mochaccino(SET_SG_TIMEOUT_PUT, "setsgtimeoutput")); - ms.insert(mochaccino(SET_SG_TIMEOUT_GET, "setsgtimeoutget")); - ms.insert(mochaccino(SET_SG_TIMEOUT_DEFAULT,"setsgtimeoutdefault")); - ms.insert(mochaccino(SET_SG_SELF_GOVERNING_TIMEOUT,"setsgselfgoverningtimeout")); - - ms.insert(mochaccino(SET_NELEM, "setnelem")); - ms.insert(mochaccino(SET_NELEM_CACHE,"setnelemcache")); - - ms.insert(mochaccino(SET_OFFSET, "setoffset")); - ms.insert(mochaccino(GET_NELEM_CLIENT, "getnelemclient")); - ms.insert(mochaccino(GET_NELEM_NATIVE, "getnelemnative")); - ms.insert(mochaccino(GET_NELEM_REQUEST, "getnelemrequest")); - ms.insert(mochaccino(GET_NELEM, "getnelem")); - ms.insert(mochaccino(GET_NELEM_CACHE,"getnelemcache")); - - ms.insert(mochaccino(GET_OFFSET, "getoffset")); - - ms.insert(mochaccino(MONITOR, "monitor")); - ms.insert(mochaccino(MONITOR_STOP, "monitorstop")); - ms.insert(mochaccino(MONITOR_FLUSH_EVENT, "monitorflushevent")); - - ms.insert(mochaccino(GET_MONITOR_HANDLES, "getmonitorhandles")); - ms.insert(mochaccino(GET_MONITOR_HANDLES_AND_ACTIONS, "getmonitorhandlesandactions")); - - ms.insert(mochaccino(IS_CONNECTED, "isconnected")); - ms.insert(mochaccino(ALL_CONNECTED, "allconnected")); - - ms.insert(mochaccino(PRINT_STATUS, "printstatus")); - ms.insert(mochaccino(PRINT_DISCONNECTED_HANDLES,"printdisconnectedhandles")); - ms.insert(mochaccino(GET_HANDLES, "gethandles")); - ms.insert(mochaccino(GET_HANDLE_STATES, "gethandlestates")); - ms.insert(mochaccino(GET_HANDLES_WITHIN_GROUP, "gethandleswithingroup")); - - ms.insert(mochaccino(GET_CONNECTED_HANDLES, "getconnectedhandles")); - ms.insert(mochaccino(GET_DISCONNECTED_HANDLES, "getdisconnectedhandles")); - ms.insert(mochaccino(PRINT_MONITORS, "printmonitors")); - ms.insert(mochaccino(PRINT_HANDLE, "printhandle")); - ms.insert(mochaccino(PRINT_HANDLES, "printhandles")); - ms.insert(mochaccino(HANDLE_FROM_PV, "gethandlefrompv")); - ms.insert(mochaccino(PV_FROM_HANDLE, "getpvfromhandle")); - ms.insert(mochaccino(DEFINE_GROUP, "definegroup")); - - ms.insert(mochaccino(LOAD_XML_COLLECTIONS,"loadxmlcollections")); - ms.insert(mochaccino(LOAD_XML_GROUPS, "loadxmlgroups")); - ms.insert(mochaccino(LOAD_SF_GROUPS, "loadsfgroups")); - ms.insert(mochaccino(GET_CHANNEL_LIST, "getchannellist")); - ms.insert(mochaccino(TEST, "test")); -} - -void mdtInsert() { - mdt.insert(mochaccino(MOCHA_NATIVE, "native")); - mdt.insert(mochaccino(MOCHA_CHAR, "int8")); - mdt.insert(mochaccino(MOCHA_UCHAR, "uint8")); - mdt.insert(mochaccino(MOCHA_SHORT, "int16")); - mdt.insert(mochaccino(MOCHA_USHORT, "uint16")); - mdt.insert(mochaccino(MOCHA_INT, "int32")); - mdt.insert(mochaccino(MOCHA_UINT, "uint32")); - mdt.insert(mochaccino(MOCHA_LONG, "int64")); - mdt.insert(mochaccino(MOCHA_ULONG, "uint64")); - mdt.insert(mochaccino(MOCHA_FLOAT, "single")); - mdt.insert(mochaccino(MOCHA_FLOAT, "float")); - mdt.insert(mochaccino(MOCHA_DOUBLE, "double")); - mdt.insert(mochaccino(MOCHA_STRING, "char")); - mdt.insert(mochaccino(MOCHA_STRING, "string")); -} - -void printStatus(int status ) { - string s = cafe.getCafeStatus().csi.message(status); - string c = cafe.getCafeStatus().csc.message(status); - mexPrintf("%s\n",c.c_str()); - mexPrintf("%s\n",s.c_str()); -} - - -string prepareExceptionID(int status ) { - string exID="CAFE_"; exID.append(cafe.getCafeStatus().severity(status)); - exID.append(":"); exID.append(cafe.getCafeStatus().msgID(status)); - return exID; -} - - -string prepareExceptionText(unsigned int handle, int status ) { - string exText="PV="; - exText.append(cafe.getPVFromHandle(handle)); - exText.append(" Handle="); - exText.append(static_cast( &(ostringstream() << handle) )->str()); - exText.append(" statusCode="); - exText.append(static_cast( &(ostringstream() << status) )->str()); - exText.append(" statusText="); exText.append(cafe.getCafeStatus().msgID(status)); - exText.append(" statusInfo="); exText.append(cafe.getCafeStatus().info(status)); - return exText; -} - - - -void fillMEStruct(string sME) { - - - fout1 = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData (fout1); - - fout2 = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData (fout2); - - fout0 = mxCreateCellMatrix(1,1); - fout3 = mxCreateCellMatrix(1,1); - fout4 = mxCreateCellMatrix(1,1); - - std::string str2 =""; - std::string str =""; - - std::size_t found = sME.find("PV="); - - if (found != string::npos) { - str2 = sME.substr(found+3); - found = str2.find(" "); - str = str2.substr(0,found); - mexPrintf("PV %s\n", str.c_str()); - mxSetCell (fout0, 0, mxCreateString( str.c_str())); - } - - - found= sME.find("Handle="); - if (found!= string::npos) { - str2 = sME.substr(found+7); - found = str2.find(" "); - str = str2.substr(0,found); - //mexPrintf("handle %d\n", std::atoi(str.c_str())); - ulongArray[0]= std::atoi(str.c_str()); - } - - found= sME.find("statusCode="); - if (found!= string::npos) { - - str2 = sME.substr(found+11); - found = str2.find(" "); - str = str2.substr(0,found); - //mexPrintf("status %d\n", std::atoi(str.c_str())); - longStatus[0]= std::atoi(str.c_str()); - } - - - found= sME.find("statusText="); - if (found!= string::npos) { - str2 = sME.substr(found+11); - found = str2.find(" "); - str = str2.substr(0,found); - //mexPrintf("statusText %s\n", str.c_str()); - mxSetCell (fout3, 0, mxCreateString(str.c_str())); - } - - found= sME.find("statusInfo="); - if (found!= string::npos) { - str2 = sME.substr(found+11); - //mexPrintf("statusInfo %s\n", str2.c_str()); - mxSetCell (fout4, 0, mxCreateString(str2.c_str())); - } - - return; - -} - - - -bool isValidClass(const mxArray * inputClass) { - // Refuse these input mx classes; - - mxClassID mxid =mxGetClassID( inputClass); - - switch(mxid) { - case mxUNKNOWN_CLASS: - mexPrintf("Undetermined class: %s \n",mxGetClassName( inputClass) ); - return false; - break; - case mxSTRUCT_CLASS: - case mxFUNCTION_CLASS: - mexPrintf("The requested class is not yet supported: %s \n",mxGetClassName( inputClass) ); - return false; - break; - case mxVOID_CLASS: - mexPrintf("This requested class is reserved: %s \n",mxGetClassName( inputClass) ); - return false; - break; - } - - return true; -} - -unsigned int getMdtIndexFromCafeDataType(CAFE_DATATYPE cdt){ - unsigned int mdtIndex; - - switch ( cdt) - { - case CAFE_DOUBLE: - mdtIndex=MOCHA_DOUBLE; - break; - case CAFE_FLOAT: - mdtIndex=MOCHA_FLOAT; - break; - case CAFE_SHORT: - mdtIndex=MOCHA_SHORT; - break; - case CAFE_ENUM: - mdtIndex=MOCHA_USHORT; - break; - case CAFE_CHAR: - mdtIndex=MOCHA_UCHAR; - break; - case CAFE_LONG: - mdtIndex=MOCHA_INT; - break; - case CAFE_STRING: - mdtIndex=MOCHA_STRING; - break; - default: //If not connected for instance - mdtIndex=MOCHA_DOUBLE; - break; - } - return mdtIndex; -} - -unsigned int getMdtIndex(const mxArray * l){ - - char messStruct[METHOD_NAME_MAX_SIZE]; - mxArray * mDataStruct; - - unsigned int mdtIndex=MOCHA_NATIVE; - - mochaccino_set_by_name & name_mdt_index = mdt.get (); - mochaccino_set_by_name::iterator it_name_mdt; - - short messLengthStruct = METHOD_NAME_MAX_SIZE+1; - //message - mDataStruct = (mxArray *) l; - mxGetString(mDataStruct, messStruct, messLengthStruct); - - //Not allowed! - //mxFree(mxGetData(mDataStruct)); // Added line to avoid memory leak - //mxDestroyArray(mDataStruct); - - //remove leadingTrailing Blanks - const char * _messStruct=messStruct; - cafe.getHandleHelper().removeLeadingAndTrailingSpaces(_messStruct,messStruct); - - //tolowercase - std::string messString = messStruct; - - if(messString.size()==0) {return mdtIndex;} - - std::transform(messString.begin(), messString.end(), messString.begin(), ::tolower); - strcpy(messStruct,messString.c_str()); - - //Is Valid Data Type?? - it_name_mdt = name_mdt_index.find(messStruct); - - if (it_name_mdt != name_mdt_index.end()) { - mdtIndex=(*it_name_mdt).id; - //mexPrintf("MESSAGE INDEX: %d %s ", mdtIndex, messStruct); - } - else { - mexPrintf("WARNING: Unknown data type: %s\n", messStruct); - mexPrintf("WARNING: Possible data types are listed. \n"); - mexPrintf("WARNING: Using native type if known else double\n"); - print_out_by(mdt); - } - - return mdtIndex; -} - - - -void scanCell(const mxArray * thisCell) -{ - - size_t thisNeWithinObject = mxGetNumberOfElements (thisCell); - for (mwIndex i=0; i openArray(vector vstr) { - - - vector vuint32; - vuint32.reserve(vstr.size()); - - std::fill(vuint32.begin(), vuint32.end(), 0); - - try { - cafe.open(vstr, vuint32); - } - catch(CAFEException_open &e) { - - mexPrintf("---------------\n"); - //cout << e.what() << endl; - mexPrintf("%s\n", e.what() ); - mexPrintf("---------------\n"); - - cafe.printCAFEException_pv(e.pvEx); - printStatus(e.pvEx.statusCode); - mexPrintf("EXITING MATLAB\n"); - exit(1); - } - catch(exception &e) { - - mexPrintf("---------------\n"); - mexPrintf("%s\n", e.what() ); - mexPrintf("---------------\n"); - - mexPrintf("EXITING MATLAB\n"); - exit(1); - } - return vuint32; -} - - - -unsigned int open(char _pv[PVNAME_MAX_SIZE]) { - - uint32_T _handle=0; - - try { - cafe.open(_pv, (unsigned int&) _handle); - } - catch(CAFEException_open &e) { - - mexPrintf("---------------\n"); - cout << e.what() << endl; - mexPrintf("---------------\n"); - - cafe.printCAFEException_pv(e.pvEx); - printStatus(e.pvEx.statusCode); - mexPrintf("EXITING MATLAB\n"); - exit(1); - } - catch(exception &e) { - - mexPrintf("---------------\n"); - cout << e.what() << endl; - mexPrintf("---------------\n"); - - mexPrintf("EXITING MATLAB\n"); - exit(1); - } - return _handle; -} - - -unsigned int groupOpen(char _pv[PVNAME_MAX_SIZE]) { - uint32_T _ghandle=0; - - try { - status=cafe.groupOpen((const char *) _pv, (unsigned int &) _ghandle); - } - catch(CAFEException_groupOpen &e) { - mexPrintf("---------------\n"); - cout << e.what() << endl; - mexPrintf("---------------\n"); - NS_MOCHA::printStatus(e.groupEx.statusCode); - mexPrintf("EXITING MATLAB\n"); - exit(1); - } - catch(exception &e) { - mexPrintf("---------------\n"); - cout << e.what() << endl; - mexPrintf("---------------\n"); - mexPrintf("EXITING MATLAB\n"); - exit(1); - } - return _ghandle; -} - - - -unsigned int checkForHandleNoOpen(const mxArray * inputValue) { - - unsigned int _handle=0; - - if (mxIsNumeric(inputValue) ) { - _handle = (uint32_T) mxGetScalar(inputValue); - } - - else if (mxIsChar(inputValue) ) { - - //message pvname - xData = (mxArray *) inputValue; - - pvLength = PVNAME_MAX_SIZE+1; - mxGetString(xData, pv, pvLength); - - _handle=cafe.getHandleHelper().getHandleFromPV(pv); - if (_handle==0) { - mexPrintf("PV=%s has not yet been opened by user!\n", pv ); - } - - } - else if (mxIsCell(inputValue) ) { - - mxArray * newCell = mxGetCell(inputValue,0); - - if (mxIsNumeric(newCell) ) { - _handle = (uint32_T) mxGetScalar(newCell); - } - - else if (mxIsChar(newCell) ) { - - //message pvname - xData = (mxArray *) newCell; - - pvLength = PVNAME_MAX_SIZE+1; - mxGetString(xData, pv, pvLength); - - _handle=cafe.getHandleHelper().getHandleFromPV(pv); - if (_handle==0) { - mexPrintf("PV=%s has not yet been opened by user!\n", pv ); - } - } - - } - else { - mexPrintf("Error in checkForHandleNoOpen:\n"); - mexPrintf("Handle does not have a numeric value \n"); - mexPrintf("or PV name does not have a char value \n" ); - } - return _handle; -} - - - -unsigned int checkForHandle(const mxArray * inputValue) { - - unsigned int _handle=0; - - if (mxIsNumeric(inputValue) ) { - _handle = (uint32_T) mxGetScalar(inputValue); - - } - - else if (mxIsChar(inputValue) ) { - - //message pvname - xData = (mxArray *) inputValue; - - pvLength = PVNAME_MAX_SIZE+1; - mxGetString(xData, pv, pvLength); - - _handle=cafe.getHandleHelper().getHandleFromPV(pv); - - if (_handle==0) { - _handle=open(pv); - } - } - else if (mxIsCell(inputValue) ) { - - mxArray * newCell = mxGetCell(inputValue,0); - - if (mxIsNumeric(newCell) ) { - _handle = (uint32_T) mxGetScalar(newCell); - } - - else if (mxIsChar(newCell) ) { - - //message pvname - xData = (mxArray *) newCell; - - pvLength = PVNAME_MAX_SIZE+1; - mxGetString(xData, pv, pvLength); - - _handle=cafe.getHandleHelper().getHandleFromPV(pv); - - if (_handle==0) { - _handle=open(pv); - } - } - } - else { - mexPrintf("Error in checkForHandle:\n"); - mexPrintf("Handle does not have a numeric value \n"); - mexPrintf("or PV name does not have a char value \n"); - return _handle; - } - if (_handle==0) { - mexPrintf("Handle in input argument not given! \n"); - } - return _handle; -} - - -uint32_T * scanNumericForHandle (const mxArray * inputValue) { - - uint32_T * inputULong; - - if (mxIsNumeric(inputValue) ) { - - size_t numberOfHandles=mxGetNumberOfElements (inputValue); - mxArray * foutE = mxCreateNumericMatrix(1,numberOfHandles,mxUINT32_CLASS, mxREAL); - inputULong = (uint32_T *) mxGetData (foutE); - - mxClassID mxid =mxGetClassID(inputValue); - - switch(mxid) { - case mxDOUBLE_CLASS: - inputDouble = (double *) mxGetPr ( inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputDouble[i]; - } - break; - case mxSINGLE_CLASS: - inputFloat = (float *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputFloat[i]; - } - break; - case mxLOGICAL_CLASS: - inputBool = (bool *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputBool[i]; - } - break; - case mxINT8_CLASS: - inputChar = (int8_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputChar[i]; - } - break; - case mxUINT8_CLASS: - inputUChar = (uint8_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputUChar[i]; - } - break; - case mxINT16_CLASS: - inputShort = (int16_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputShort[i]; - } - break; - case mxUINT16_CLASS: - inputUShort = (uint16_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputUShort[i]; - } - break; - case mxINT32_CLASS: - inputLong = (int32_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputLong[i]; - } - break; - case mxUINT32_CLASS: - inputULong = (uint32_T *) mxGetData (inputValue); - //for (size_t i=0; i< numberOfHandles; ++i) { - // inputULongLong[i] = (uint64_T) inputULong[i]; - //} - break; - case mxINT64_CLASS: - inputLongLong = (int64_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputLongLong[i]; - } - break; - case mxUINT64_CLASS: - inputULongLong = (uint64_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputULongLong[i]; - } - break; - // Series of Strings go in a CELL - } - } - else { - mexPrintf("scanNumericForHandle was not given a numeric for input!"); - mxArray * foutE = mxCreateNumericMatrix(1,1,mxUINT32_CLASS, mxREAL); - inputULong = (uint32_T *) mxGetData (foutE); - inputULong[0] = 0; - } - return inputULong; -} - -uint32_T * checkHandleArray(const mxArray * inputValue, bool openIfNoHandle) { - - uint32_T * inputULong; - mxArray * foutE; - size_t numberOfHandles=0; - - if (mxIsNumeric(inputValue) ) { - - numberOfHandles=mxGetNumberOfElements (inputValue); - - foutE = mxCreateNumericMatrix(1,std::max((int)numberOfHandles,1),mxUINT32_CLASS, mxREAL); - inputULong= (uint32_T *) mxGetData (foutE); - - mxClassID mxid =mxGetClassID(inputValue); - - //mexPrintf("Class ID %d\n", mxid ); - //mexPrintf(mxGetClassName(inputValue)); - - switch(mxid) { - case mxDOUBLE_CLASS: - inputDouble = (double *) mxGetPr ( inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputDouble[i]; - } - break; - case mxSINGLE_CLASS: - inputFloat = (float *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputFloat[i]; - } - break; - case mxLOGICAL_CLASS: - inputBool = (bool *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputBool[i]; - } - break; - case mxINT8_CLASS: - inputChar = (int8_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputChar[i]; - } - break; - case mxUINT8_CLASS: - inputUChar = (uint8_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputUChar[i]; - } - break; - case mxINT16_CLASS: - inputShort = (int16_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputShort[i]; - } - break; - case mxUINT16_CLASS: - inputUShort = (uint16_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputUShort[i]; - } - break; - case mxINT32_CLASS: - inputLong = (int32_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputLong[i]; - } - break; - case mxUINT32_CLASS: - inputULong = (uint32_T *) mxGetData (inputValue); - - break; - case mxINT64_CLASS: - inputLongLong = (int64_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputLongLong[i]; - } - break; - case mxUINT64_CLASS: - inputULongLong = (uint64_T *) mxGetData (inputValue); - for (size_t i=0; i< numberOfHandles; ++i) { - inputULong[i] = (uint32_T) inputULongLong[i]; - } - break; - // Series of Strings go in a CELL - } - - //for (size_t i=0; i::quiet_NaN()); - - //foutE = mxCreateDoubleMatrix(1,1,mxREAL); - //doubleArray = (double *) mxGetPr ( plhs[0]); - //doubleArray[0]=numeric_limits::signaling_NaN(); - break; - case MOCHA_FLOAT: - foutE = mxCreateNumericMatrix(1,1,mxSINGLE_CLASS, mxREAL); - floatArray = (float *) mxGetData (foutE); - floatArray[0]=numeric_limits::quiet_NaN(); - break; - case MOCHA_INT: - foutE = mxCreateNumericMatrix(1,1,mxINT32_CLASS, mxREAL); - longArray = (int32_T *) mxGetData (foutE); - longArray[0]=numeric_limits::quiet_NaN(); - break; - case MOCHA_SHORT: - foutE = mxCreateNumericMatrix(1,1,mxINT16_CLASS, mxREAL); - shortArray = (int16_T *) mxGetData (foutE); - shortArray[0]=numeric_limits::quiet_NaN(); - break; - case MOCHA_USHORT: - foutE = mxCreateNumericMatrix(1,1,mxUINT16_CLASS, mxREAL); - ushortArray = (uint16_T *) mxGetData (foutE); - ushortArray[0]=numeric_limits::quiet_NaN(); - break; - case MOCHA_UCHAR: - foutE = mxCreateNumericMatrix(1,1,mxUINT8_CLASS, mxREAL); - ucharArray = (uint8_T *) mxGetData (foutE); - ucharArray[0]=numeric_limits::quiet_NaN(); - break; - case MOCHA_STRING: - foutE = mxCreateCellMatrix(1,1); - mxSetCell (foutE, 0, mxCreateString( numeric_limits::quiet_NaN() )); - break; - case MOCHA_CHAR: - foutE = mxCreateNumericMatrix(1,1,mxINT8_CLASS, mxREAL); - charArray = (int8_T *) mxGetData (foutE); - charArray[0]= numeric_limits::quiet_NaN(); - break; - case MOCHA_UINT: - foutE = mxCreateNumericMatrix(1,1,mxUINT32_CLASS, mxREAL); - ulongArray = (uint32_T *) mxGetData (foutE); - ulongArray[0]= numeric_limits::quiet_NaN(); - break; - case MOCHA_LONG: - foutE = mxCreateNumericMatrix(1,1,mxINT64_CLASS, mxREAL); - longlongArray = (int64_T *) mxGetData (foutE); - longlongArray[0]= numeric_limits::quiet_NaN(); - break; - case MOCHA_ULONG: - foutE = mxCreateNumericMatrix(1,1,mxUINT64_CLASS, mxREAL); - ulonglongArray = (uint64_T *) mxGetData (foutE); - ulonglongArray[0]= numeric_limits::quiet_NaN(); - break; - default: - foutE = mxCreateDoubleScalar(numeric_limits::quiet_NaN()); - break; - } - -return foutE; -} - - -void fillPVCell(unsigned int mdtIndex, PVDataHolder dh) { - - nelem= dh.getNelem(); - - switch ( mdtIndex) - { - case MOCHA_DOUBLE: - fout0 = mxCreateDoubleMatrix(1,nelem,mxREAL); - doubleArray = (double *) mxGetPr (fout0); - for (mwSignedIndex i=0; i< nelem; ++i) { doubleArray[i]=dh.getAsDouble(i);} - break; - - case MOCHA_FLOAT: - fout0 = mxCreateNumericMatrix(1,nelem,mxSINGLE_CLASS, mxREAL); - floatArray = (float *) mxGetData (fout0); - for (mwSignedIndex i=0; i< nelem; ++i) { floatArray[i]=dh.getAsFloat(i);} - break; - - case MOCHA_INT: - fout0 = mxCreateNumericMatrix(1,nelem,mxINT32_CLASS, mxREAL); - longArray = (int32_T *) mxGetData (fout0); - for (mwSignedIndex i=0; i< nelem; ++i) { longArray[i]=dh.getAsLong(i); } - break; - - case MOCHA_SHORT: - fout0 = mxCreateNumericMatrix(1,nelem,mxINT16_CLASS, mxREAL); - shortArray = (int16_T *) mxGetData (fout0); - for (mwSignedIndex i=0; i< nelem; ++i) { shortArray[i]=dh.getAsShort(i); } - break; - - case MOCHA_USHORT: - fout0 = mxCreateNumericMatrix(1,nelem,mxUINT16_CLASS, mxREAL); - ushortArray = (uint16_T *) mxGetData (fout0); - for (mwSignedIndex i=0; i< nelem; ++i) { ushortArray[i]=(unsigned short) dh.getAsEnum(i);} - break; - - case MOCHA_UCHAR: - fout0 = mxCreateNumericMatrix(1,nelem,mxUINT8_CLASS, mxREAL); - ucharArray = (uint8_T *) mxGetData (fout0); - for (mwSignedIndex i=0; i< nelem; ++i) { ucharArray[i]= (unsigned short) dh.getAsChar(i); } - break; - - case MOCHA_STRING: - { - //cells are best - - - if (nelem==1) { - fout0=mxCreateString(dh.getAsString(0).c_str() ); - } - else { - fout0 = mxCreateCellMatrix(1,nelem); - for (mwSignedIndex i=0; i -//#include -//#endif - - -extern void _main(); -using namespace NS_MOCHA; - -void macchinettaFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) -{ - - if (nrhs <1) { - mexPrintf("Input argument not entered. \n"); - mexPrintf("The command: mocha \'show\' will display the methods available. \n"); - return; - } - - if (mxIsCell(prhs[0])) { - mexPrintf("mocha message argument (1st input arg) must be a char and not a cell. \n"); - return; - } - - int32_T mochaIndex=-1; - - if ( mxIsNumeric(prhs[0]) && !mxIsChar(prhs[0]) ) { - mochaIndex= (int) mxGetScalar( prhs[0] ); - if (mochaIndex !=MONITOR_FLUSH_EVENT) { - mexPrintf("We prefer not to expose the numerical index value directly. \n"); - mexPrintf("Please use the method name (MATLAB char) as input to the first argument. \n"); - mexPrintf("The command: mocha \'show\' will display the methods available. \n"); - - mexPrintf("1st input argument Class Name: %s\n", mxGetClassName(prhs[0])); - mexPrintf("1st input argument Class ID: %d\n", mxGetClassID(prhs[0])); - mexPrintf("1st input argument to mocha must be of type char/mxCHAR_CLASS\n"); - - return; - } - } - - - /* - if (strcmp (mxGetClassName(prhs[0]),"string") ==0 ) { - - mxChar * mess2 = static_cast(mxGetData(prhs[0])); - - mData = (mxArray *) mess2; - messLength = METHOD_NAME_MAX_SIZE+1; - - if ( mxGetString(mData, mess, messLength) == 1) { - mexPrintf ("mxGetString has failed; input is not of mxChar type\n"); - } - - - - mexPrintf ("mocha does not support string/mxSTRING_CLASS as input\n"); - mexPrintf ("Please use char/mxCHAR_CLASS as data type for input\n"); - return; - } - else { - */ - //message - - //Trick to handle mocha(402) input from monitor Action - - messLength = METHOD_NAME_MAX_SIZE+1; - if (mxIsChar(prhs[0]) ) { - mData = (mxArray *) prhs[0]; - mxGetString(mData, mess, messLength); - } - else if (mochaIndex ==MONITOR_FLUSH_EVENT){ - strcpy(mess,"monitorflushevent"); - } - - - - char messOriginal[METHOD_NAME_MAX_SIZE+1]; - strcpy(messOriginal,mess); - - - //mexPrintf("message mess:%s\n", mess); - //mexPrintf("message orig:%s\n", messOriginal); - - - - //remove leadingTrailing Blanks - const char * _mess=mess; - cafe.getHandleHelper().removeLeadingAndTrailingSpaces(_mess,mess); - - std::string messString = mess; - - std::transform(messString.begin(), messString.end(), messString.begin(), ::tolower); - strcpy(mess,messString.c_str()); - - - if(!isCAInitialized && strcmp(mess,"monitorflushevent")!=0 && strcmp(mess,"close")!=0) { - NS_MOCHA::msInsert(); - NS_MOCHA::mdtInsert(); - - // print_out_by(ms); - } - else if (!isCAInitialized && strcmp(mess,"close")==0) { - mexPrintf("The CAFEteria was never opened! \n"); - return; - } - - if(!isCAInitialized && strcmp(mess,"close")!=0){ - - - if (!mexIsLocked()) { - mexLock(); - } - - //Remove PyCafe component should cafe have been compiled with pyCafe - //This flag controls import_PyCafe for when PyCafe_api.h is used - //If PyCafe.h is not used then you must link to non-Py cafe C++ librarry - - - //if ( cafe.setPyCafe(true) ) { - // mexPrintf("Py_Initialize \n"); - // Py_Initialize(); - //} - - #ifdef HAVE_PYTHON_H - //cafe.setPyCafe(true); - //dlopen("libpython2.6.so", RTLD_GLOBAL|RTLD_LAZY); - //dlopen("libpython3.5m.so", RTLD_GLOBAL|RTLD_LAZY); - mexPrintf("HAVE_PYTHON_H \n"); - //Py_Initialize(); - //mexPrintf("Py_Initialize from MATLAB \n"); - #endif - - cafe.init(); - - //#ifdef HAVE_PYTHON_H - // cafe.loadSFGroups("VA"); - //#endif - - isCAInitialized=true; - - if (strcmp(mess,"monitorflushevent")==0 ) { - mexPrintf("The CAFEteria is now open due to an outstanding monitorFlushEvent action (probably from a timer) \n"); - } - else { - mexPrintf("The CAFEteria is now open \n"); - } - } - - - mochaccino_set_by_name & name_index = ms.get (); - mochaccino_set_by_name::iterator it_name; - - - //mexPrintf("message %s\n", mess); - //mexPrintf("message %s\n", messString.c_str()); - - it_name = name_index.find(mess); - - if ( (it_name) != name_index.end() ) { - mochaIndex=(*it_name).id; - } - - int32_T mdtIndex=MOCHA_NATIVE; - int32_T mochaIndexOriginal=mochaIndex; - - bool cacheFlag=false; - bool sgTimeoutFlag=false; - bool extendedPV=false; - - size_t numberOfHandlesGetAsyn=0; - size_t nh=0; - size_t nv=0; - - //Wrapper methods - switch(mochaIndex) { - case GET_INT8: - mochaIndex=GET; - mdtIndex=MOCHA_CHAR; - break; - case GET_INT16: - mochaIndex=GET; - mdtIndex=MOCHA_SHORT; - break; - case GET_INT32: - mochaIndex=GET; - mdtIndex=MOCHA_INT; - break; - case GET_INT64: - mochaIndex=GET; - mdtIndex=MOCHA_LONG; - break; - case GET_UINT8: - mochaIndex=GET; - mdtIndex=MOCHA_UCHAR; - break; - case GET_UINT16: - mochaIndex=GET; - mdtIndex=MOCHA_USHORT; - break; - case GET_UINT32: - mochaIndex=GET; - mdtIndex=MOCHA_UINT; - break; - case GET_UINT64: - mochaIndex=GET; - mdtIndex=MOCHA_ULONG; - break; - case GET_FLOAT: - mochaIndex=GET; - mdtIndex=MOCHA_FLOAT; - break; - case GET_DOUBLE: - mochaIndex=GET; - mdtIndex=MOCHA_DOUBLE; - break; - case GET_STRING: - mochaIndex=GET; - mdtIndex=MOCHA_STRING; - break; - case GET_CELL_ARRAY_CACHE: - mochaIndex=GET_CELL_ARRAY; - cacheFlag=true; - break; - case GET_SCALAR_ARRAY_CACHE: - mochaIndex=GET_SCALAR_ARRAY; - cacheFlag=true; - break; - case GET_STRUCT_ARRAY_CACHE: - mochaIndex=GET_STRUCT_ARRAY; - cacheFlag=true; - break; - case GET_STRUCT_CACHE: - mochaIndex=GET_STRUCT; - cacheFlag=true; - break; - case GET_GROUP_CACHE: - mochaIndex=GET_GROUP; - cacheFlag=true; - break; - - - case GET_STRUCT_EXTENDED: - mochaIndex=GET_STRUCT; - extendedPV=true; - break; - - case GET_STRUCT_EXTENDED_ARRAY: - mochaIndex=GET_STRUCT_ARRAY; - extendedPV=true; - break; - - case GET_GROUP_EXTENDED: - mochaIndex=GET_GROUP; - extendedPV=true; - break; - - case GET_STRUCT_EXTENDED_ARRAY_CACHE: - mochaIndex=GET_STRUCT_ARRAY; - cacheFlag=true; - extendedPV=true; - break; - case GET_STRUCT_EXTENDED_CACHE: - mochaIndex=GET_STRUCT; - cacheFlag=true; - extendedPV=true; - break; - case GET_GROUP_EXTENDED_CACHE: - mochaIndex=GET_GROUP; - cacheFlag=true; - extendedPV=true; - break; - - case GET_WF_AS_STRING_CACHE: - mochaIndex=GET_WF_AS_STRING; - cacheFlag=true; - break; - - case GET_CACHE: - mochaIndex=GET; - cacheFlag=true; - break; - case GET_CTRL_CACHE: - mochaIndex=GET_CTRL_STRUCT; - cacheFlag=true; - break; - case GET_NELEM_CACHE: - mochaIndex=GET_NELEM_REQUEST; - cacheFlag=true; - break; - case GET_ASYN: - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle/pv \n", nrhs); - return; - } - if (mxIsChar(prhs[1]) ) { - numberOfHandlesGetAsyn=1; - } - else { - numberOfHandlesGetAsyn=mxGetNumberOfElements (prhs[1]); - } - if (numberOfHandlesGetAsyn >1) { - mochaIndex=GET_ARRAY_ASYN; - } - break; - - case SET: - - - if (nrhs<3) { - mexPrintf("Invalid Number of argument %d. Input: 'set', handle/pv, data \n", nrhs); - return; - } - - - if (mxIsChar(prhs[1])) { - nh=1; - } - else{ - nh=mxGetNumberOfElements (prhs[1]); - } - if (mxIsChar(prhs[2])) { - nv=1; - } - else{ - nv=mxGetNumberOfElements (prhs[2]); - } - - ///mexPrintf("nh=%d, nvalues=%d, nargin=%d\n", nh,nv, nrhs); - if (nh>1 && nh==nv && nrhs==3) { - mochaIndex=SET_SCALAR_ARRAY; - //mexPrintf("SET_SCALAR_ARRAY\n"); - } - else if (nh>1 && nh==(nrhs-2)) { - mochaIndex=SET_STRUCT_ARRAY; - //mexPrintf("SET_STRUCT_ARRAY\n"); - } - else if (nh>1) { - mochaIndex=SET_STRUCT_ARRAY; - mexPrintf("Inbalance between number of handles and input data\n"); - //mexPrintf("SET_STRUCT_ARRAY\n"); - } - - break; - - case SET_NELEM_CACHE: - mochaIndex=SET_NELEM; - cacheFlag=true; - break; - - case OPEN: - if (nrhs>1) { - if( mxIsCell(prhs[1]) ) { - mochaIndex=OPEN_ARRAY; - } - } - break; - - case CLOSE: - if (nrhs>1) { - if( mxGetNumberOfElements (prhs[1]) >1 ) { - mochaIndex=CLOSE_ARRAY; - } - } - break; - - case OPEN_WAIT_WITH_TIME: - if (nrhs<2) { - mochaIndex=OPEN_WAIT_TIME_TO_DEFAULT; - cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_AFTER_EACH_CHANNEL_CREATION); - cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); - } - break; - - default: - break; - } - - - //Test again for GET - //Wrapper methods - switch(mochaIndex) { - case GET: - - if (mxIsChar(prhs[1])) { - nh=1; - } - else{ - - nh=mxGetNumberOfElements (prhs[1]); - - } - - ///mexPrintf("nh=%d, nargin=%d\n", nh, nrhs); - if (nrhs>3) { - mexPrintf("Usage: get [pv] (optional)\n"); - return; - } - if (nh>1) { - mochaIndex=GET_SCALAR_ARRAY; - //mexPrintf("GET_SCALAR_ARRAY\n"); - if(nrhs==3 &&mxIsChar(prhs[nrhs-1])) { - mdtIndex=NS_MOCHA::getMdtIndex(prhs[nrhs-1]); - } - //else { - //mexPrintf("3rd input argument giving the must be a string\n"); - //} - - //mexPrintf("GET_SCALAR_ARRAY\n"); - } - break; - - case GET_STRUCT: - if (mxIsChar(prhs[1])) { - nh=1; - } - else{ - nh=mxGetNumberOfElements (prhs[1]); - } - - ///mexPrintf("nh=%d, nargin=%d\n", nh, nrhs); - if (nrhs>3) { - mexPrintf("Usage: get [pv] (optional)\n"); - return; - } - if (nh>1) { - mochaIndex=GET_STRUCT_ARRAY; - //mexPrintf("GET_STRUCT_ARRAY\n"); - if(nrhs==3 &&mxIsChar(prhs[nrhs-1])) { - mdtIndex=NS_MOCHA::getMdtIndex(prhs[nrhs-1]); - } - //else { - //mexPrintf("3rd input argument giving the must be a string\n"); - //} - } - - break; - } - - // The Big Switch - switch (mochaIndex) { - - case TEST: - mexPrintf("mocha mex file is active\n"); - break; - - case MOCHA_VERSION: - plhs[0]=mxCreateString((char *) "mocha-1.4.0-final-1 : November 2017"); - break; - - case SHOW: - //print_out_by(ms); - for (it_name=name_index.begin(); it_name != name_index.end(); ++it_name) { - mexPrintf("%s\n", ((*it_name).name).c_str()); - } - break; - - case CA_POLL: - cafe._ca_poll(); - break; - - case MEX_UNLOCK: - - if (!mexIsLocked()) { - mexUnlock(); - } - break; - - case SET_PUT_PREPARE: - { - - - if (nrhs<2) { - mexPrintf("Invalid Number of argument(s) %d. Input: setPutPrepare, handle(s) or handleArray \n", nrhs); - return; - } - - - size_t numberOfHandles=0; - - - for (size_t j=1; j dhV; - vector pvV; - cafe.getHandleHelper().getHandles(dhV,pvV); - numberOfHandles=dhV.size(); - - for (size_t i=0; i< numberOfHandles; ++i) { - - status=cafe.getPolicy().getChannelRequestPolicyPut(dhV[i], polput); - if (status==ECAFE_INVALID_HANDLE) { - mexPrintf("SET_PUT_WAIT: Invalid handle no = %d \n", dhV[i]); - continue; - } - - //mexPrintf("no wait for handle no = %d\n", handleULong[i]); - //mexPrintf("wait for handle no = %d\n", handleULong[i]); - polput.setMethodKind(WITH_CALLBACK_DEFAULT); - polput.setWaitKind(WAIT); - polput.setWhenToFlushSendBuffer(FLUSH_AFTER_EACH_MESSAGE); - cafe.getPolicy().setChannelRequestPolicyPut(dhV[i], polput); - } - - break; - } - - - for (size_t j=1; j dhV; - vector pvV; - cafe.getHandleHelper().getHandles(dhV,pvV); - numberOfHandles=dhV.size(); - - for (size_t i=0; i< numberOfHandles; ++i) { - - status=cafe.getPolicy().getChannelRequestPolicyPut(dhV[i], polput); - if (status==ECAFE_INVALID_HANDLE) { - mexPrintf("SET_PUT_NOWAIT: Invalid handle no = %d \n", dhV[i]); - continue; - } - - //mexPrintf("no wait for handle no = %d\n", handleULong[i]); - //mexPrintf("wait for handle no = %d\n", handleULong[i]); - polput.setMethodKind(WITH_CALLBACK_DEFAULT); - polput.setWaitKind(NO_WAIT); - polput.setWhenToFlushSendBuffer(FLUSH_AFTER_EACH_MESSAGE); - cafe.getPolicy().setChannelRequestPolicyPut(dhV[i], polput); - } - - break; - } - - - for (size_t j=1; j dhV; - vector pvV; - cafe.getHandleHelper().getHandles(dhV,pvV); - unsigned int numberOfHandles=dhV.size(); - - if (numberOfHandles==0) {return;} - - ChannelRequestPolicy polget; - polget.setPolicy(FLUSH_AFTER_EACH_MESSAGE, WAIT, WITHOUT_CALLBACK); - - for (size_t i=0; i< numberOfHandles; ++i) { - cafe.getPolicy().setChannelRequestPolicyGet(dhV[i], polget); - } - - break; - } - case INIT_GET_SYNC_WITH_CALLBACK_DEFAULT: - { - cafe.channelRequestPolicyMasterGet.setPolicy(FLUSH_AFTER_EACH_MESSAGE, WAIT, WITH_CALLBACK_DEFAULT); - - vector dhV; - vector pvV; - cafe.getHandleHelper().getHandles(dhV,pvV); - unsigned int numberOfHandles=dhV.size(); - - if (numberOfHandles==0) {return;} - - ChannelRequestPolicy polget; - polget.setPolicy(FLUSH_AFTER_EACH_MESSAGE, WAIT, WITH_CALLBACK_DEFAULT); - - for (size_t i=0; i< numberOfHandles; ++i) { - cafe.getPolicy().setChannelRequestPolicyGet(dhV[i], polget); - } - - break; - } - - case OPEN_NOWAIT: - //cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_DESIGNATED_TO_CLIENT); - //cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); - cafe.openPrepare(); - - break; - - case OPEN_WAIT: - cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_AFTER_EACH_CHANNEL_CREATION); - cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); - break; - - - case OPEN_NOW: - //cafe.channelOpenPolicy.flushSendBufferNow(); - //cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_AFTER_EACH_CHANNEL_CREATION); - //cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); - cafe.openNow(); - - break; - - //change open method to with pend_event - for single opens that wish to pend - case OPEN_WAIT_WITH_TIME: - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, timeout \n", nrhs); - return; - } - - if (nrhs>1) { - if (!mxIsNumeric(prhs[1]) ) { - mexPrintf("Timeout does not have a numeric value \n"); - return; - } - cafe.channelOpenPolicy.setTimeout(mxGetScalar(prhs[1])); - cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_AFTER_EACH_CHANNEL_CREATION); - cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); - - } - break; - - - case OPEN_WAIT_TIME_TO_DEFAULT: - if (nrhs>1) { - mexPrintf("Ignoring number of arguments %d\n", nrhs); - mexPrintf("This method resets open wait time to default value\n"); - } - - - plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); - doubleArray = (double *) mxGetPr (plhs[0]); - doubleArray[0]= cafe.channelOpenPolicy.setTimeoutToDefault(); - - - break; - - - case OPEN_NOW_AND_WAIT: - - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, timeout \n", nrhs); - return; - } - - if (nrhs>1) { - if (!mxIsNumeric(prhs[1]) ) { - mexPrintf("Timeout does not have a numeric value \n"); - return; - } - - //Get Timeput - //double tPrevious=cafe.channelOpenPolicy.getTimeout(); - //cafe.channelOpenPolicy.setTimeout(mxGetScalar(prhs[1])); - //cafe.channelOpenPolicy.flushSendBufferNow(); - //reset - //cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_NOW); - //cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); - - //Set to previous - //cafe.channelOpenPolicy.setTimeoutToDefault(); - //cafe.channelOpenPolicy.setTimeout(tPrevious); - - cafe.openNowAndWait(mxGetScalar(prhs[1])); - } - break; - - - case GET_OPEN_WAIT_TIME: - if (nrhs>1) { - mexPrintf("Ignoring number of arguments %d\n", nrhs); - mexPrintf("This method returns the current open wait time value\n"); - } - - plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); - doubleArray = (double *) mxGetPr (plhs[0]); - doubleArray[0]= cafe.channelOpenPolicy.getTimeout(); - break; - - case WITH_EXCEPTIONS: - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, bool \n", nrhs); - return; - } - - if( !mxIsLogical(prhs[1]) ) { - mexPrintf("2nd input argument must be of Matlab type Logical, i.e.true/false \n" ); - return; - } - - - //withExceptions = mxGetLogicals (prhs[1]); - withExceptions = mxIsLogicalScalarTrue (prhs[1]); - - break; - - - case HAVE_EXCEPTIONS: - - plhs[0] = mxCreateNumericMatrix(1,1,mxLOGICAL_CLASS,mxREAL); - logicalData = (mxLogical *) mxGetData (plhs[0]); - logicalData[0]=withExceptions; - - break; - - case SEND_NOW: - ca_flush_io(); - break; - - - case OPEN_ARRAY: - { - - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message Array, pv Output: handle Array \n", nrhs); - return; - } - - if( !mxIsCell(prhs[1]) ) { - mexPrintf("Process Variable names must be in a cell. \n" ); - return; - } - - size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); - - if(numberOfHandles==0) { - mexPrintf("ERROR: MISSING INPUT \n"); - return; - } - - vector vstr; - vstr.reserve(numberOfHandles); - - for (size_t i=0; i< numberOfHandles; ++i) { - - mxArray * newCell = mxGetCell(prhs[1],i); - - if (mxIsChar(newCell) ) { - - //message pvname - xData = (mxArray *) newCell; - - pvLength = PVNAME_MAX_SIZE+1; - mxGetString(xData, pv, pvLength); - vstr.push_back(pv); - } - else { - - plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData (plhs[0]); - ulongArray[0]=0; - mexPrintf("ERROR READING INPUT, ELEMENT %d of %d IS NOT A mxCHAR \n", i, numberOfHandles); - return; - } - } - - - - vector vuint32=NS_MOCHA::openArray(vstr); - - - plhs[0] = mxCreateNumericMatrix(1,vuint32.size(),mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData (plhs[0]); - for (size_t i=0; i::signaling_NaN(); - - groupStatus[0]=ECAFE_UNKNOWN_GROUP; - - return; - } - - mdtIndex=MOCHA_NATIVE; - - if (nrhs>2) { - //ischar? - if (!mxIsChar(prhs[2]) ) { - mexPrintf("3rd input argument must be a char \n"); - return; - } - mdtIndex=getMdtIndex(prhs[2]); - } - - - int32_T mdtIndexOriginal=mdtIndex; - - PVGroup pvgroup; - - status=cafe.groupAttach(ghandle, pvgroup); - - PVDataHolder * du; - unsigned int NPV=0; - bool isGroupTimeout=false; - - if (status!=ECAFE_UNKNOWN_GROUP && status != ECAFE_EMPTY_GROUP) { - - - if (cacheFlag) { - status=cafe.groupGetCache(ghandle, pvgroup); - } - else { - status=cafe.groupGet(ghandle, pvgroup); - } - - - // statusGroup != ICAFE_SUCCESS when one or more channels accesses fail - if ( pvgroup.getStatusGroup() != ICAFE_SUCCESS ) { - for (mwSignedIndex i=0; i dhV = cafe.getHandlesFromWithinGroupV(ghandle); - du = new PVDataHolder[dhV.size()]; - if (cacheFlag) { - status=cafe.getPVArray(dhV, du); - } - else { - //status=cafe.getPVArrayCache(dhV, du); - status=cafe.getCachePVArray(dhV, du); - } - NPV=dhV.size(); - isGroupTimeout=true; - - } - } - else { - - mexPrintf("status/handle %d / %d \n", status, ghandle); - mexPrintf("Returning NaN in place of struct \n"); - - NS_MOCHA::printStatus(status); - - doubleArray[0]=numeric_limits::signaling_NaN(); - - groupStatus[0]=status; - - return; - } - - - groupStatus[0]=status; - - if (extendedPV) { - plhs[0]=mxCreateStructMatrix(1,NPV, nfieldsExtra, fnamesExtra); - } - else { - plhs[0]=mxCreateStructMatrix(1,NPV, nfields, fnames); - } - - - - for (mwSignedIndex j=0; j 2) { - mexPrintf("Ignoring all input arguments after the 2nd \n"); - mexPrintf("Method is mocha ('getAsyn', \n"); - } - - handle=checkForHandle(prhs[1]); - if(handle==0) { - mexPrintf("Handle does not exist!\n"); - return;} - - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - - status=cafe.get(handle); - longStatus[0]=status; - - if (status!=ICAFE_NORMAL) { - //NS_MOCHA::printStatus(status); - cafe.printStatus(handle,status); - - } - - break; - } - - - case GET_ARRAY_ASYN: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle/pv \n", nrhs); - return; - } - size_t numberOfHandles=0; - - if (mxIsChar(prhs[1]) ) { - numberOfHandles=1; - } - else { - numberOfHandles=mxGetNumberOfElements (prhs[1]); - } - - handleULong = checkHandleArray(prhs[1],true); - - if (handleULong==NULL) { - mexPrintf("GET_ARRAY_SYNC: Ignoring NULL value in input \n"); - mexPrintf("Number of arguments should be %d. with Input: message, handle/pv \n", nrhs); - return; - } - - plhs[1] = mxCreateNumericMatrix(1,numberOfHandles,mxINT32_CLASS, mxREAL); - longArray = (int32_T *) mxGetData (plhs[1]); - - status=cafe.get( (unsigned int *) handleULong, numberOfHandles, - (int *) longArray); - - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS, mxREAL); - longStatus = (int32_T *) mxGetData (plhs[0]); - longStatus[0]=(int32_T) status; - - break; - } - - - case GET_CTRL_STRUCT: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle/pv, matlab type (optional)\n", nrhs); - return; - } - - - if (mxIsChar(prhs[1])) { - nh=1; - } - else{ - nh=mxGetNumberOfElements (prhs[1]); - } - if (nh >1) { - mexPrintf("Method limited to one handle/pv only. Reporting on first given"); - } - - handle=checkForHandle(prhs[1]); - if(handle==0) { - mexPrintf("Handle does not exist!\n"); - return;} - - mdtIndex=MOCHA_NATIVE; - - if (nrhs>2) { - //ischar? - if (!mxIsChar(prhs[2]) ) { - mexPrintf("3rd input argument must be a char \n"); - return; - } - mdtIndex=getMdtIndex(prhs[2]); - } - - fout1 = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData (fout1); - fout2 = mxCreateNumericMatrix(1,1,mxINT16_CLASS,mxREAL); - shortAlarmStatus = (int16_T *) mxGetData (fout2); - fout3 = mxCreateNumericMatrix(1,1,mxINT16_CLASS,mxREAL); - shortAlarmSeverity = (int16_T *) mxGetData (fout3); - fout4 = mxCreateNumericMatrix(1,1, mxUINT16_CLASS,mxREAL); - precision = (uint16_T *) mxGetData(fout4); - - fout6 = mxCreateNumericMatrix(1,1, mxUINT16_CLASS,mxREAL); - noEnumStrings = (uint16_T *) mxGetData(fout6); - fout8 = mxCreateDoubleMatrix(1,1,mxREAL); - udl = (double *) mxGetPr (fout8); - fout9 = mxCreateDoubleMatrix(1,1,mxREAL); - ldl = (double *) mxGetPr (fout9); - fout10 = mxCreateDoubleMatrix(1,1,mxREAL); - ual = (double *) mxGetPr (fout10); - fout11 = mxCreateDoubleMatrix(1,1,mxREAL); - lal = (double *) mxGetPr (fout11); - fout12 = mxCreateDoubleMatrix(1,1,mxREAL); - uwl = (double *) mxGetPr (fout12); - fout13 = mxCreateDoubleMatrix(1,1,mxREAL); - lwl = (double *) mxGetPr (fout13); - fout14 = mxCreateDoubleMatrix(1,1,mxREAL); - ucl = (double *) mxGetPr (fout14); - fout15 = mxCreateDoubleMatrix(1,1,mxREAL); - lcl = (double *) mxGetPr (fout15); - - - fout16=mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - fHandle = (uint32_T *) mxGetData(fout16); - fHandle[0]=handle; - string s = cafe.getPVFromHandle(handle); - fout17 =mxCreateString( s.c_str() ); - - - - nelem=cafe.getHandleHelper().getNelemRequestCtrl(handle); - - // mexPrintf("nelemRequested %d", nelem); - PVCtrlHolder du; - du.setNelem(nelem); - //du.setNelem(2); - // mexPrintf("nelem %d ", du.getNelem()); - - if (cacheFlag) { - status=cafe.getCtrlCache(handle,du); - } - else { - status=cafe.getCtrl(handle,du); - } - - reportError=false; - - plhs[0]=mxCreateStructMatrix(1, 1, nfieldsCtrl, fnamesCtrl); - - //Match INPUT to CAFE DATATYPE - if (mdtIndex==MOCHA_NATIVE) { - mdtIndex=getMdtIndexFromCafeDataType(du.getDataType()); - if (cafe.getHandleHelper().isEnum(handle)) { - mdtIndex=MOCHA_STRING; - } - } - - fillCtrlStruct(mdtIndex, du); - - if (status==ICAFE_NORMAL) { - fout5 = mxCreateString((char *) du.getUnits()); - ////fillCtrlStruct(mdtIndex, du); - } //if - else { - reportError=true; - } - // Use shared_ptr since cafe-1.0 - //delete [] du.val; - - if (reportError) { - fout0=getValueIfError(mdtIndex); - //longStatus[0] = (int32_T) status; - //shortAlarmStatus[0] = (int16_T) 0; - //shortAlarmSeverity[0] = (int16_T) 0; - fout5 = mxCreateString((const char *) ""); - precision[0]=0; - noEnumStrings[0]=0; - fout7 = mxCreateCellMatrix(1,1); - for (mwSignedIndex i=0; i <1; ++i) - mxSetCell (fout7, i, mxCreateString((const char *) "" ) ); - udl[0]=0; - ldl[0]=0; - ual[0]=0; - lal[0]=0; - uwl[0]=0; - lwl[0]=0; - ucl[0]=0; - lcl[0]=0; - //cafe.printStatus(handle,status); - } - - mxSetFieldByNumber(plhs[0], 0, 0, fout16); //handle - mxSetFieldByNumber(plhs[0], 0, 1, fout17); //pv - mxSetFieldByNumber(plhs[0], 0, 2, fout0); - mxSetFieldByNumber(plhs[0], 0, 3, fout1); - mxSetFieldByNumber(plhs[0], 0, 4, fout1a); - mxSetFieldByNumber(plhs[0], 0, 5, fout2); - mxSetFieldByNumber(plhs[0], 0, 6, fout2a); - mxSetFieldByNumber(plhs[0], 0, 7, fout3); - mxSetFieldByNumber(plhs[0], 0, 8, fout3a); - - mxSetFieldByNumber(plhs[0], 0, 9, fout4); - mxSetFieldByNumber(plhs[0], 0, 10, fout5); - mxSetFieldByNumber(plhs[0], 0, 11, fout6); - mxSetFieldByNumber(plhs[0], 0, 12, fout7); - mxSetFieldByNumber(plhs[0], 0, 13, fout8); - mxSetFieldByNumber(plhs[0], 0, 14, fout9); - mxSetFieldByNumber(plhs[0], 0, 15, fout10); - mxSetFieldByNumber(plhs[0], 0, 16, fout11); - mxSetFieldByNumber(plhs[0], 0, 17, fout12); - mxSetFieldByNumber(plhs[0], 0, 18, fout13); - mxSetFieldByNumber(plhs[0], 0, 19, fout14); - mxSetFieldByNumber(plhs[0], 0, 20, fout15); - break; - } - - case GET_STRUCT: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle/pv, matlab type (optional) \n", nrhs); - return; - } - - handle=checkForHandle(prhs[1]); - if(handle==0) { - mexPrintf("Handle does not exist!\n"); - return;} - - mdtIndex=MOCHA_NATIVE; - - if (nrhs>2) { - //ischar? - if (!mxIsChar(prhs[2]) ) { - mexPrintf("3rd input argument must be a char \n"); - return; - } - mdtIndex=getMdtIndex(prhs[2]); - } - - reportError=false; - - uint32_T * d4; - nelem = cafe.getHandleHelper().getNelemClient(handle); //change NelemRequest to NelemClient - - // OUTPUT - - if (extendedPV) { - plhs[0]=mxCreateStructMatrix(1, 1, nfieldsExtra, fnamesExtra); - } - else { - plhs[0]=mxCreateStructMatrix(1, 1, nfields, fnames); - } - /* - fout1 = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData (fout1); - - fout2 = mxCreateNumericMatrix(1,1,mxINT16_CLASS,mxREAL); - shortAlarmStatus = (int16_T *) mxGetData (fout2); - - fout3 = mxCreateNumericMatrix(1,1,mxINT16_CLASS,mxREAL); - shortAlarmSeverity = (int16_T *) mxGetData (fout3); - - fout4 = mxCreateNumericMatrix(1,7,mxUINT32_CLASS,mxREAL); - d4 = (uint32_T *) mxGetData(fout4); - - - - - fout9 = mxCreateNumericMatrix(1,2,mxUINT32_CLASS,mxREAL); - d9 = (uint32_T *) mxGetData(fout9); - */ - - PVDataHolder du; - - epicsTimeStamp ets1; - ets1.secPastEpoch=0; - ets1.nsec=0; - - unsigned int nelemPrevious=1; - bool nelemCacheChangeFlag=false; - - if(cacheFlag) { - nelem = cafe.getHandleHelper().getNelemToRetrieveFromCache(handle); - if (nelem > cafe.getHandleHelper().getNelemRequest(handle) ) { - nelemPrevious=nelem; - nelem = min( (unsigned int) nelem, cafe.getHandleHelper().getNelemRequest(handle)); - cafe.getHandleHelper().setNelemToRetrieveFromCache(handle,nelem); - nelemCacheChangeFlag=true; - } - } - - du.setNelem(nelem); - - if (cacheFlag) { - status=cafe.getCache(handle,du); - } - else { - status=cafe.get(handle,du); - } - - //Match INPUT to CAFE DATATYPE - if (mdtIndex==MOCHA_NATIVE) { - mdtIndex=getMdtIndexFromCafeDataType(du.getDataType()); - if (cafe.getHandleHelper().isEnum(handle)) { - mdtIndex=MOCHA_STRING; - } - } - - fillPVStruct(mdtIndex, du); - - if (extendedPV) { - fillPVStructExtra(handle, du); - } - - if (status!=ICAFE_NORMAL) { - reportError=true; - } - - - if(nelemCacheChangeFlag) { - cafe.getHandleHelper().setNelemToRetrieveFromCache(handle,nelemPrevious); - } - - // Use shared_ptr since cafe-1.0 - // delete [] du.val; - - if (reportError) { - - fout0=getValueIfError(mdtIndex); - //longStatus[0] = (int32_T) status; - //shortAlarmStatus[0] = (int16_T) 0; - //shortAlarmSeverity[0] = (int16_T) 0; - - //cafe.printStatus(handle,status); - } - - - if (extendedPV) { - mxSetFieldByNumber(plhs[0], 0, 0, fout10); - mxSetFieldByNumber(plhs[0], 0, 1, fout5); - mxSetFieldByNumber(plhs[0], 0, 2, fout0); - mxSetFieldByNumber(plhs[0], 0, 3, fout1); - mxSetFieldByNumber(plhs[0], 0, 4, fout6); - mxSetFieldByNumber(plhs[0], 0, 5, fout2); - mxSetFieldByNumber(plhs[0], 0, 6, fout7); - mxSetFieldByNumber(plhs[0], 0, 7, fout3); - mxSetFieldByNumber(plhs[0], 0, 8, fout8); - mxSetFieldByNumber(plhs[0], 0, 9, fout4); - mxSetFieldByNumber(plhs[0], 0,10, fout9); - } - else { - mxSetFieldByNumber(plhs[0], 0, 0, fout0); - mxSetFieldByNumber(plhs[0], 0, 1, fout1); - mxSetFieldByNumber(plhs[0], 0, 2, fout2); - mxSetFieldByNumber(plhs[0], 0, 3, fout3); - mxSetFieldByNumber(plhs[0], 0, 4, fout4); - } - - if (status!=ICAFE_NORMAL) { - if (withExceptions) { - mexErrMsgIdAndTxt(prepareExceptionID(status).c_str(), prepareExceptionText(handle,status).c_str()); - } - } - - break; - } - - case GET_SCALAR_ARRAY: - { - - if (nrhs<2) { - if(cacheFlag) { - mexPrintf("Invalid Number of argument %d. Input: 'getScalarArrayCache', handleArray \n", nrhs); - } - else { - mexPrintf("Invalid Number of argument %d. Input: 'getScalarArray', handleArray \n", nrhs); - } - return; - } - - if (nrhs>2 && (mochaIndex==mochaIndexOriginal || cacheFlag) ) { - //ischar? - if (!mxIsChar(prhs[nrhs-1]) ) { - mexPrintf("Last input argument must be a char \n"); - return; - } - mdtIndex=NS_MOCHA::getMdtIndex(prhs[nrhs-1]); - } - - - int32_T mdtIndexOriginal=mdtIndex; - size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); - - neWithinAllCells=0; // filled by checkHandleArray - - //What is dataType? - handleULong = checkHandleArray(prhs[1],true);//(uint64_T *) mxGetData ( prhs[1]); - - - if (handleULong==NULL) { - mexPrintf("GET_SCALAR_ARRAY: Ignoring NULL value in input\n"); - mexPrintf("Input Invalid. Should be: 'getStructArray(Cache)', handleArray \n"); - return; - } - - if (mxIsChar(prhs[1]) ) { - numberOfHandles=1; - //mexPrintf("char numberOfHandles %d",numberOfHandles); - } - else if (mxIsCell(prhs[1]) ) { - numberOfHandles=neWithinAllCells; - //mexPrintf(" cell numberOfHandles %d",numberOfHandles); - } - - - //for (size_t i=0; i1) { - nelem=1; // First element only - } - pvd[i].setNelem(nelem); - - //Is this really needed? - if(cacheFlag) { - cafe.getHandleHelper().setNelemToRetrieveFromCache((unsigned int) handleULong[i],nelem); - } - } - - if(cacheFlag) { - status=cafe.getCache( (unsigned int *) handleULong, numberOfHandles, - pvd); - } - else { - - status=cafe.get( (unsigned int *) handleULong, numberOfHandles, - pvd); - - } - - - int32_T * groupStatus; - - //overall groupStatus - plhs[1] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - groupStatus = (int32_T *) mxGetData (plhs[1]); - groupStatus[0]=status; - - plhs[2] = mxCreateNumericMatrix(1,numberOfHandles,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData (plhs[2]); - - //plhs[0] = mxCreateDoubleMatrix (1,numberOfHandles,mxREAL); - //doubleArray = (double *) mxGetPr (plhs[0]); - - //If no datatype is given, assume datatype of first element! - if (mdtIndexOriginal==MOCHA_NATIVE){ - mdtIndex=NS_MOCHA::getMdtIndexFromCafeDataType(pvd[0].getDataType()); - if (cafe.getHandleHelper().isEnum(handleULong[0])) { //check this for handleULong[0] - mdtIndex=MOCHA_STRING; - } - } - - - - switch (mdtIndex) - { - case MOCHA_DOUBLE: - plhs[0] = mxCreateDoubleMatrix(1,numberOfHandles,mxREAL); - doubleArray = (double *) mxGetPr (plhs[0]); - for (mwSignedIndex j=0; j ::quiet_NaN(); - } - longStatus[j]=pvd[j].getStatus(); - } - break; - - case MOCHA_FLOAT: - plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxSINGLE_CLASS, mxREAL); - floatArray = (float *) mxGetData (plhs[0]); - for (mwSignedIndex j=0; j ::quiet_NaN(); - } - longStatus[j]=pvd[j].getStatus(); - } - break; - - case MOCHA_INT: - plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxINT32_CLASS, mxREAL); - longArray = (int32_T *) mxGetData (plhs[0] ); - for (mwSignedIndex j=0; j ::quiet_NaN(); - } - longStatus[j]=pvd[j].getStatus(); - } - break; - - case MOCHA_SHORT: - plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxINT16_CLASS, mxREAL); - shortArray = (int16_T *) mxGetData (plhs[0]); - for (mwSignedIndex j=0; j ::quiet_NaN(); - } - longStatus[j]=pvd[j].getStatus(); - } - break; - - case MOCHA_USHORT: - plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxUINT16_CLASS, mxREAL); - ushortArray = (uint16_T *) mxGetData (plhs[0]); - for (mwSignedIndex j=0; j ::quiet_NaN(); - } - longStatus[j]=pvd[j].getStatus(); - } - break; - - case MOCHA_UCHAR: - plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxUINT8_CLASS, mxREAL); - ucharArray = (uint8_T *) mxGetData (plhs[0]); - for (mwSignedIndex j=0; j ::quiet_NaN(); - } - longStatus[j]=pvd[j].getStatus(); - } - break; - - case MOCHA_STRING: - { - plhs[0] = mxCreateCellMatrix(1,numberOfHandles); - for (mwSignedIndex j=0; j ::quiet_NaN() )); - } - longStatus[j]=pvd[j].getStatus(); - } - break; - } - // Non DBR_TYPES - case MOCHA_CHAR: - plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxINT8_CLASS, mxREAL); - charArray = (int8_T *) mxGetData (plhs[0]); - for (mwSignedIndex j=0; j ::quiet_NaN(); - } - longStatus[j]=pvd[j].getStatus(); - } - break; - case MOCHA_UINT: - plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxUINT32_CLASS, mxREAL); - ulongArray = (uint32_T *) mxGetData (plhs[0]); - for (mwSignedIndex j=0; j ::quiet_NaN(); - } - longStatus[j]=pvd[j].getStatus(); - } - break; - case MOCHA_LONG: - plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxINT64_CLASS, mxREAL); - longlongArray = (int64_T *) mxGetData (plhs[0]); - for (mwSignedIndex j=0; j ::quiet_NaN(); - } - longStatus[j]=pvd[j].getStatus(); - } - break; - case MOCHA_ULONG: - plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxUINT64_CLASS, mxREAL); - ulonglongArray = (uint64_T *) mxGetData (plhs[0]); - for (mwSignedIndex j=0; j ::quiet_NaN(); - } - longStatus[j]=pvd[j].getStatus(); - } - break; - default: - { - plhs[0] = mxCreateCellMatrix(1,numberOfHandles); - for (mwSignedIndex j=0; j ::quiet_NaN())); - } - longStatus[j]=pvd[j].getStatus(); - } - break; - } - } //switch - - // for (mwSignedIndex j=0; j 2 && (mochaIndex==mochaIndexOriginal || cacheFlag) ) { - //ischar? - if (!mxIsChar(prhs[2]) ) { - mexPrintf("3rd input argument (data type) must be a char \n"); - return; - } - mdtIndex=NS_MOCHA::getMdtIndex(prhs[2]); - } - - int32_T mdtIndexOriginal=mdtIndex; - size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); - - - neWithinAllCells=0; // filled by checkHandleArray - - //What is dataType? - handleULong = checkHandleArray(prhs[1],true);//(uint64_T *) mxGetData ( prhs[1]); - - if (handleULong==NULL) { - mexPrintf("GET_STRUCT_ARRAY: Ignoring NULL value in input \n"); - mexPrintf("Input Invalid. Should be: 'getStructArray', handleArray \n"); - return; - } - - - if(handleULong[0]==0) { - mexPrintf("Input Invalid. Should be: 'getStructArray', handleArray \n"); - return; - } - - if (mxIsChar(prhs[1]) ) { - numberOfHandles=1; - } - else if (mxIsCell(prhs[1]) ) { - numberOfHandles=neWithinAllCells; - //mexPrintf(" cell numberOfHandles %d",numberOfHandles); - } - - - - PVDataHolder * pvd = new PVDataHolder[numberOfHandles]; - - for (size_t i=0; i2 && (mochaIndex==mochaIndexOriginal || cacheFlag) ) { - //ischar? - if (!mxIsChar(prhs[2]) ) { - mexPrintf("3rd input argument (data type) must be a char \n"); - return; - } - mdtIndex=NS_MOCHA::getMdtIndex(prhs[2]); - } - - int32_T mdtIndexOriginal=mdtIndex; - size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); - - neWithinAllCells=0; // filled by checkHandleArray - - //What is dataType? - handleULong = checkHandleArray(prhs[1],true);//(uint64_T *) mxGetData ( prhs[1]); - - if (handleULong==NULL) { - mexPrintf("GET_CELL_ARRAY: Ignoring NULL value in input \n"); - mexPrintf("Input Invalid. Should be: 'getCellArray', handleArray \n"); - return; - } - - - if(handleULong[0]==0) { - mexPrintf("Input Invalid. Should be: 'getCellArray', handleArray \n"); - return; - } - - if (mxIsChar(prhs[1]) ) { - numberOfHandles=1; - } - else if (mxIsCell(prhs[1]) ) { - numberOfHandles=neWithinAllCells; - //mexPrintf(" cell numberOfHandles %d",numberOfHandles); - } - - - PVDataHolder * pvd = new PVDataHolder[numberOfHandles]; - - for (size_t i=0; i2 && (mochaIndex==mochaIndexOriginal || cacheFlag) ) { - //ischar? - if (!mxIsChar(prhs[2]) ) { - mexPrintf("3rd input argument must be a char \n"); - return; - } - mdtIndex=NS_MOCHA::getMdtIndex(prhs[2]); - - } - if (mdtIndex==MOCHA_NATIVE){ - - - - status=cafe.getHandleHelper().getDataTypeRequest(handle, rdt); - - - if (status!=ICAFE_NORMAL) { - mexPrintf("Error for handle input= %d \n", (uint32_T) mxGetScalar(prhs[1]) ); - NS_MOCHA::printStatus(status); - longStatus[0]=status; - plhs[0]=getValueIfError(mdtIndex); - return; - } - - CAFE_DATATYPE cdt = (CAFE_DATATYPE) rdt; - - - - mdtIndex=getMdtIndexFromCafeDataType(cdt); - - - - if (cafe.getHandleHelper().isEnum(handle)) { - - mdtIndex=MOCHA_STRING; - } - } - - nelem = cafe.getHandleHelper().getNelemClient(handle); //Change Request to Client - - - - if (cafe.getHandleHelper().getOffset(handle) > 0 ) { - - nelem = min( cafe.getHandleHelper().getNelemClient(handle), - (cafe.getHandleHelper().getNelemNative(handle)-cafe.getHandleHelper().getOffset(handle)) ); - - } - - if(nelem<1) { - nelem=1; // This is to build output matrix - } - - - unsigned int nelemPrevious=1; - bool nelemCacheChangeFlag=false; - - if(cacheFlag) { - - nelem = cafe.getHandleHelper().getNelemToRetrieveFromCache(handle) ; - - //mexPrintf("get Cache: nelem = %d \n", nelem); - - - if ( (cafe.getHandleHelper().getOffsetLast(handle) > 0) || - (cafe.getHandleHelper().getNelemToRetrieveFromCache(handle) > cafe.getHandleHelper().getNelemRequest(handle))){ - - - //if (nelem > cafe.getHandleHelper().getNelemRequest(handle) ) { - nelemPrevious=cafe.getHandleHelper().getNelemToRetrieveFromCache(handle); - nelem = min( (unsigned int) nelem, cafe.getHandleHelper().getNelemRequest(handle)-cafe.getHandleHelper().getOffsetLast(handle)); - - //mexPrintf("nelem to ret from Cache %d \n",cafe.getHandleHelper().getNelemToRetrieveFromCache(handle)); - //mexPrintf("nelem to ret from Cache %d \n",nelem); - //cafe.getHandleHelper().setNelemToRetrieveFromCache(handle,nelem+cafe.getHandleHelper().getOffsetLast(handle)); - cafe.getHandleHelper().setNelemToRetrieveFromCache(handle,nelem); - nelemCacheChangeFlag=true; - } - - } - - switch (mdtIndex) - { - case MOCHA_DOUBLE: - plhs[0] = mxCreateDoubleMatrix(1,nelem,mxREAL); - doubleArray = (double *) mxGetPr (plhs[0]); - if(cacheFlag) { status=cafe.getCache(handle,doubleArray);} - else {status=cafe.get(handle,doubleArray);} - break; - - case MOCHA_FLOAT: - plhs[0] = mxCreateNumericMatrix(1,nelem,mxSINGLE_CLASS, mxREAL); - floatArray = (float *) mxGetData (plhs[0]); - if(cacheFlag) { mexPrintf("here"); status=cafe.getCache(handle,floatArray); mexPrintf("status %d", status);} - else {status=cafe.get(handle,floatArray);} - break; - - case MOCHA_INT: - plhs[0] = mxCreateNumericMatrix(1,nelem,mxINT32_CLASS, mxREAL); - longArray = (int32_T *) mxGetData (plhs[0] ); - if(cacheFlag) { status=cafe.getCache(handle,longArray);} - else {status=cafe.get(handle,longArray);} - break; - - case MOCHA_SHORT: - plhs[0] = mxCreateNumericMatrix(1,nelem,mxINT16_CLASS, mxREAL); - shortArray = (int16_T *) mxGetData (plhs[0]); - if(cacheFlag) { status=cafe.getCache(handle,shortArray);} - else {status=cafe.get(handle,shortArray);} - break; - - case MOCHA_USHORT: - plhs[0] = mxCreateNumericMatrix(1,nelem,mxUINT16_CLASS, mxREAL); - ushortArray = (uint16_T *) mxGetData (plhs[0]); - if(cacheFlag) { status=cafe.getCache(handle,ushortArray);} - else {status=cafe.get(handle,ushortArray);} - break; - - case MOCHA_UCHAR: - plhs[0] = mxCreateNumericMatrix(1,nelem,mxUINT8_CLASS, mxREAL); - ucharArray = (uint8_T *) mxGetData (plhs[0]); - if(cacheFlag) { status=cafe.getCache(handle,ucharArray);} - else {status=cafe.get(handle,ucharArray);} - break; - - case MOCHA_STRING: - { - dbr_string_t * stringArrayc = new dbr_string_t[nelem]; - - if(cacheFlag) { status=cafe.getCache(handle,stringArrayc);} - else {status=cafe.get(handle,stringArrayc);} - - //char *test[40]; - //test[0]="test"; - //test[1]="again"; - //mxChar *pr; - //char *ptr_to_seed_data; - //int c; - - - if (status==ICAFE_NORMAL) { - - if (nelem==1) { - plhs[0]=mxCreateString( stringArrayc[0] ); - } - else { - plhs[0] = mxCreateCellMatrix(1,nelem); - for (mwSignedIndex i=0; i 1) { - mexPrintf("Method returns enumerated value/name pairs of alarm conditions \n"); - } - - vector vecS; vector vecI; - cgac.getStates(vecI, vecS); - - plhs[1] = mxCreateNumericMatrix(1,vecI.size(), mxINT32_CLASS,mxREAL); - longArray= (int32_T *) mxGetData(plhs[1]); - - //return string list - plhs[0] = mxCreateCellMatrix(1,vecS.size()); - - for (mwSignedIndex i=0; i1) { - mexPrintf("Method returns enumerated value/name pairs of alarm severities \n"); - } - - vector vecS; vector vecI; - cgas.getStates(vecI, vecS); - - plhs[1] = mxCreateNumericMatrix(1,vecI.size(), mxINT32_CLASS,mxREAL); - longArray= (int32_T *) mxGetData(plhs[1]); - - //return string list - plhs[0] = mxCreateCellMatrix(1,vecS.size()); - - for (mwSignedIndex i=0; i1) { - mexPrintf("Method returns enumerated value/name pairs of status codes \n"); - } - - vector vecS; vector vecI; - cafe.getCafeStatus().csc.getStates(vecI, vecS); - - plhs[1] = mxCreateNumericMatrix(1,vecI.size(), mxINT32_CLASS,mxREAL); - longArray= (int32_T *) mxGetData(plhs[1]); - - //return string list - plhs[0] = mxCreateCellMatrix(1,vecS.size()); - - for (mwSignedIndex i=0; i vi; - - status=cafe.groupAttach(ghandle, pvg); - - if (status!=ECAFE_UNKNOWN_GROUP && status != ECAFE_EMPTY_GROUP) { - - status=cafe.groupGetCache(ghandle, pvg); - - vi=cafe.getPulseIDFromTS(pvg); - - } - - plhs[0] = mxCreateNumericMatrix(1,vi.size(), mxUINT32_CLASS,mxREAL); - ulongArray= (uint32_T *) mxGetData(plhs[0]); - - for (mwSignedIndex i=0; i::signaling_NaN(); - - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - longStatus[0]=status; - } - - - break; - } - - case SET_STRUCT_ARRAY: - { - if (nrhs<3) { - mexPrintf("Invalid Number of argument %d. Input: 'setStructArray', handle/pv array, data array \n", nrhs); - return; - } - - - //What is dataType? - handleULong = checkHandleArray(prhs[1],true); - - if (handleULong==NULL) { - mexPrintf("SET_STRUCT_ARRAY: Ignoring NULL value in input\n"); - mexPrintf("Input Invalid. Should be: 'setStructArray', handle/pv array, data array \n"); - return; - } - - - if(handleULong[0]==0) { - mexPrintf("Input Invalid. Should be: 'setStructArray', handle/pv array, data array \n"); - return; - } - - size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); - size_t nDataInputs=nrhs-2; - - //Examine data input - //Break up a cell or an array - //Check no of data inputs - //nelem=nrhs-2; - - /* - if (nhrs=3} { - //neWithinAllDataCells=0; - - - if (mxIsCell(prhs[k])) { - - nDataInputs=getObjectsFromDataCell(prhs[k]); - - mexPrintf("Running No of Elements in Cell = %d \n", nDataInputs); - - } - //else { - // nDataInputs=nDataInputs+1; - //} - } - */ - - - //if (numberOfHandles != nrhs-2) { - if (numberOfHandles != nDataInputs) { - mexPrintf("Input Invalid. Data Array Length %d does not equal No of handles %d! \n", nrhs-2,numberOfHandles); - //mexPrintf("Input Invalid. Data Array Length %d does not equal No of handles %d! \n", nDataInputs,numberOfHandles); - return; - } - - PVDataHolder * du; - - //du = new PVDataHolder[nrhs-2]; - du = new PVDataHolder[nDataInputs]; - - mwSignedIndex j=0; - - for (mwSignedIndex k=2; k3) { - mexPrintf("Ignoring arguments after the 3rd from the %d entered. \nInput: 'setScalarArray', handle/pv array, data array \n", nrhs); - } - - //What is dataType? - handleULong = checkHandleArray(prhs[1],true); - - if (handleULong==NULL) { - mexPrintf("SET_SCALAR_ARRAY: Ignoring NULL value in input \n"); - mexPrintf("Input Invalid. Should be: 'setScalarArray', handle/pv array, data array \n"); - return; - } - - - if(handleULong[0]==0) { - mexPrintf("Input Invalid. Should be: 'setScalarArray', handle/pv array, data array \n"); - return; - } - - size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); - - nelem=mxGetNumberOfElements (prhs[2]); - - if(nelem==0) { - mexPrintf("Empty Data Array in Input \n"); - return; - } - - if (numberOfHandles != nelem) { - mexPrintf("Input Invalid. Data Array Length %d does not equal No of handles %d! \n", nelem,numberOfHandles); - return; - } - - - neWithinAllCells=0; - - if (mxIsChar(prhs[1]) ) { - numberOfHandles=1; - } - else if (mxIsCell(prhs[1]) ) { - scanCell(prhs[1]); - numberOfHandles=neWithinAllCells; - //mexPrintf(" cell numberOfHandles %d",numberOfHandles); - } - - - - //statuses - plhs[1] = mxCreateNumericMatrix(1,numberOfHandles,mxINT32_CLASS,mxREAL); - longArray = (int32_T *) mxGetData (plhs[1]); - - mxClassID mxid =mxGetClassID(prhs[2]); - - mxArray * fout; - - switch(mxid) { - case mxDOUBLE_CLASS: - inputDouble = (double *) mxGetPr (prhs[2]); - status=cafe.set((unsigned int *)handleULong, (unsigned int) numberOfHandles, inputDouble, (int *) longArray); - break; - case mxSINGLE_CLASS: - inputFloat = (float *) mxGetData (prhs[2]); - status=cafe.set((unsigned int *)handleULong, (unsigned int) numberOfHandles, inputFloat, (int *) longArray); - break; - case mxLOGICAL_CLASS: - inputBool = (bool *) mxGetData (prhs[2]); - fout = mxCreateNumericMatrix(1,numberOfHandles,mxINT8_CLASS, mxREAL); - inputShort = (short *) mxGetData ( fout ); - for (mwSignedIndex i=0; i3) { - mexPrintf("Ignoring arguments after the 3rd from the %d entered. Input: 'set', handle/pv, data \n", nrhs); - } - - handle=checkForHandle(prhs[1]); - if(handle==0) {return;} - - - if (!isValidClass(prhs[2])) return; - - size_t ne = mxGetNumberOfElements ( prhs[2]); - - if(ne==0) { - mexPrintf("Empty Data Array in Input \n"); - return; - } - - - neWithinAllCells=0; - iWithinAllCells=0; - - mxClassID mxid =mxGetClassID( prhs[2]); - - //This line is important for a string as the Number of Elements - //is interpreted as the number of characters!!! - //Hence for ne to be 1 - if (mxid==mxCHAR_CLASS) { ne=1; } - - nelem = cafe.getHandleHelper().getNelemClient(handle); - - - //handle does not exist - if(nelem==0) { - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - longStatus[0]=ECAFE_INVALID_HANDLE; - - if (withExceptions) { - mexErrMsgIdAndTxt(prepareExceptionID(ECAFE_INVALID_HANDLE).c_str(), prepareExceptionText(handle,ECAFE_INVALID_HANDLE).c_str()); - } - - return; - } - - if(nelem!=ne) {cafe.getHandleHelper().setNelem(handle,ne);} - - mxArray *fout; - switch(mxid) { - case mxDOUBLE_CLASS: - inputDouble = (double *) mxGetPr (prhs[2]); - status=cafe.set(handle,inputDouble); - break; - case mxSINGLE_CLASS: - inputFloat = (float *) mxGetData (prhs[2]); - status=cafe.set(handle,inputFloat); - break; - case mxLOGICAL_CLASS: - inputBool = (bool *) mxGetData (prhs[2]); - fout = mxCreateNumericMatrix(1,ne,mxINT8_CLASS, mxREAL); - inputShort = (short *) mxGetData ( fout ); - for (mwSignedIndex i=0; i3) { - mexPrintf("Ignoring arguments after the 3rd from the %d entered. Input: 'set', handle/pv, data \n", nrhs); - } - - handle=checkForHandle(prhs[1]); - if(handle==0) {return;} - - - if (!isValidClass(prhs[2])) return; - - size_t ne = mxGetNumberOfElements ( prhs[2]); - - if(ne==0) { - mexPrintf("Empty Data Array in Input \n"); - return; - } - - neWithinAllCells=0; - iWithinAllCells=0; - - mxClassID mxid =mxGetClassID( prhs[2]); - - //This line is important for a string as the Number of Elements - //is interpreted as the number of characters!!! - //Hence for ne to be 1 - if (mxid==mxCHAR_CLASS) { ne=1; } - - nelem = cafe.getHandleHelper().getNelemClient(handle); - - - //handle does not exist - if(nelem==0) { - - - plhs[0] = mxCreateDoubleMatrix(1,nelem,mxREAL); - doubleArray = (double *) mxGetPr (plhs[0]); - doubleArray[0]=numeric_limits::signaling_NaN(); - - //status - plhs[1] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[1]); - longStatus[0]=ECAFE_INVALID_HANDLE; - - if (withExceptions) { - mexErrMsgIdAndTxt(prepareExceptionID(ECAFE_INVALID_HANDLE).c_str(), prepareExceptionText(handle,ECAFE_INVALID_HANDLE).c_str()); - } - - return; - } - - if(nelem!=ne) {cafe.getHandleHelper().setNelem(handle,ne);} - - size_t neOne=1; //Only deal with first element for the waveform!! - - mxArray *fout; - switch(mxid) { - case mxDOUBLE_CLASS: - inputDouble = (double *) mxGetPr (prhs[2]); - - plhs[0] = mxCreateDoubleMatrix(1,ne,mxREAL); - doubleArray = (double *) mxGetPr (plhs[0]); - - status=cafe.setAndGet(handle,inputDouble[0], doubleArray[0]); - break; - case mxSINGLE_CLASS: - inputFloat = (float *) mxGetData (prhs[2]); - - plhs[0] = mxCreateNumericMatrix(1,ne,mxSINGLE_CLASS, mxREAL); - floatArray = (float *) mxGetData (plhs[0]); - - status=cafe.setAndGet(handle,inputFloat[0], floatArray[0]); - break; - case mxLOGICAL_CLASS: - inputBool = (bool *) mxGetData (prhs[2]); - fout = mxCreateNumericMatrix(1,ne,mxINT8_CLASS, mxREAL); - inputShort = (short *) mxGetData ( fout ); - for (mwSignedIndex i=0; i hV; hV.clear(); hV.reserve(numberOfHandles); - vector hrbV; hrbV.clear(); hrbV.reserve(numberOfHandles); - for (size_t i=0; i doubleV; doubleV.clear(); - vector floatV; floatV.clear(); - vector shortV; shortV.clear(); - vector ushortV; ushortV.clear(); - vector ucharV; ucharV.clear(); - vector longV; longV.clear(); - vector longlongV; longlongV.clear(); - vector stringV; stringV.clear(); - - switch(mxid) { - case mxDOUBLE_CLASS: - inputDouble = (double *) mxGetPr (prhs[2]); - doubleV.reserve(numberOfHandles); - for (size_t i=0; i2) { - - for (mwSize i=2; i numberOfHandles) { - mexPrintf("Handle does not exists for monAction: %s\n", monAction); - - } - - if (!mxIsChar(prhs[i]) ) { - mexPrintf("monitorAction does not have a string value \n" ); - mexPrintf("Input: 'monitor', handle/pv, monitorAction(optional)\n" ); - return; - } - //message - mData = (mxArray *) prhs[i]; - messLength = MONITOR_ACTION_MAX_SIZE; - mxGetString(mData, monAction, messLength); - - char monActionOriginal[MONITOR_ACTION_MAX_SIZE]; - strcpy(monActionOriginal,monAction); - - //remove leadingTrailing Blanks - const char * _monAction=monAction; - - cafe.getHandleHelper().removeLeadingAndTrailingSpaces(_monAction,monAction); - cafe.getHandleHelper().addMonitorAction(handleULong[i-2],monAction); - if (nrhs > 3) { - mexPrintf("Handle: %d has monAction: %s\n", handleULong[i-2], monAction); - } - } - } - - - int * statusArray = new int [numberOfHandles]; - unsigned int * monitorID = new unsigned int[numberOfHandles]; - - status=cafe.monitorStart(handleULong, (unsigned int) numberOfHandles, statusArray, monitorID); - - //monitorID - plhs[0] = mxCreateNumericMatrix(1,numberOfHandles,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - for (mwSignedIndex i=0; i stopping all monitors\n" ); - cafe.getHandleHelper().clearMonitorAction(); - status=cafe.monitorStop(); - - } - - else { - - handleULong = checkHandleArray(prhs[1],true); - - if (handleULong==NULL) { - mexPrintf("MONITOR: Ignoring NULL value in input \n"); - mexPrintf("Input Invalid. Should be: 'monitor', handle/pv array \n"); - return; - } - - if(handleULong[0]==0) { - mexPrintf("Input Invalid. Should be: 'monitor', handle/pv array \n"); - return; - } - - - size_t numberOfHandles=mxGetNumberOfElements (prhs[1]); - - - if (mxIsChar(prhs[1]) ) { - numberOfHandles=1; - } - else if (mxIsCell(prhs[1]) ) { - numberOfHandles=neWithinAllCells; - } - - //handle=checkForHandle(prhs[1]); - //if(handle==0) {return;} - handle=handleULong[0]; - if (numberOfHandles==1 && nrhs>2) { - - if (!mxIsNumeric(prhs[2]) ) { - mexPrintf("MonitorID does not have a numeric value \n" ); - mexPrintf("Input: 'monitorStop', handle/pv, monitorID(optional)\n" ); - return; - } - - monitorID = (uint32_T) mxGetScalar(prhs[2]); - cafe.getHandleHelper().clearMonitorAction(handle); - status=cafe.monitorStop(handle,monitorID); - - if (status!=ICAFE_NORMAL) { - cafe.printStatus(handle,status); - } - - } - else if (numberOfHandles==1) { - cafe.getHandleHelper().clearMonitorAction(handle); - status=cafe.monitorStop(handle); - if (status!=ICAFE_NORMAL) { - cafe.printStatus(handle,status); - } - - } - else { - - if (nrhs>2) { - mexPrintf("Ignoring third input argument; Stopping all monitors for given array of handles/pvs \n" ); - mexPrintf("Input: 'monitorStop', [handle/pv] array\n" ); - } - - int * statusArray = new int [numberOfHandles]; - - status=cafe.monitorStop(handleULong, (unsigned int) numberOfHandles, statusArray); - - if (status!=ICAFE_NORMAL) { - for (mwSignedIndex i=0; ial; - al=cafe.getHandleHelper().getMonitorAction(true); - - for (int i=0; ihwm; - vectoract; - - cafe.getHandleHelper().getMonitorHandlesAndActions(hwm,act); - - //return handle - plhs[0] = mxCreateNumericMatrix(1,hwm.size(),mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData(plhs[0]); - - //return action - plhs[1] = mxCreateCellMatrix(1,act.size()); - - for (size_t i=0; ihwm; - hwm=cafe.getHandleHelper().getHandlesWithMonitors(); - - //return handle - plhs[0] = mxCreateNumericMatrix(1,hwm.size(),mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData(plhs[0]); - - for (int i=0; i2) { - mexPrintf("Ignoring all input arguments to mocha after the first. \n"); - mexPrintf("Method returns all handles and their PV names \n"); - } - - - vector dhV; - vector pvV; - cafe.getHandleHelper().getHandles(dhV,pvV); - //return handle - plhs[0] = mxCreateNumericMatrix(1,dhV.size(),mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - for (size_t i=0; i1) { - mexPrintf("Ignoring all input arguments to mocha after the first. \n"); - mexPrintf("Method returns all handles, their PV names and connection states \n"); - } - - - vector dhV; - vector pvV; - vector connV; - cafe.getHandleHelper().getHandleStates(dhV,pvV,connV); - //return handle - plhs[0] = mxCreateNumericMatrix(1,dhV.size(),mxUINT32_CLASS,mxREAL); - plhs[2] = mxCreateNumericMatrix(1,dhV.size(),mxUINT16_CLASS,mxREAL); - - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - for (size_t i=0; i2) { - mexPrintf("Ignoring all input arguments to mocha after the first. \n"); - mexPrintf("Method returns all handles within a group \n"); - } - - - ghandle=checkForGroupHandle(prhs[1]); - if(ghandle==0) { - - //fill with data - mexPrintf("Group entered as input argument has not been defined!\n"); - plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - - return; - } - - vector dhV = cafe.getHandlesFromWithinGroupV(ghandle); - //return handle - plhs[0] = mxCreateNumericMatrix(1,dhV.size(),mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - for (size_t i=0; i dhV; - vector pvV; - cafe.getHandleHelper().getDisconnectedHandles(dhV,pvV); - //return handle - plhs[0] = mxCreateNumericMatrix(1,dhV.size(),mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - for (size_t i=0; i dhV; - vector pvV; - - cafe.getHandleHelper().getConnectedHandles(dhV,pvV); - //return handle - plhs[0] = mxCreateNumericMatrix(1,dhV.size(),mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - for (size_t i=0; i1) { - mexPrintf("Method limited to one handle/pv only. Reporting on first given"); - } - - handle=checkForHandle(prhs[1]); //NoOpen(prhs[1]); - - if (handle==0) { - mexPrintf("Handle does not exist!\n"); - return; - } - - ChannelRegalia channelInfo; - - status=cafe.getChannelInfo(handle, channelInfo); - - /* - cout << channelInfo.getConnectFlag() << endl; - cout << channelInfo.getHostName() << endl; - cout << channelInfo.getChannelID() << endl; - cout << channelInfo.getClassNameAsString() << endl; - cout << channelInfo.getDataType() << endl; - cout << channelInfo.getNelem() << endl; - cout << channelInfo.getConnectionStateAsString() << endl; - cout << channelInfo.getAccessRead() << endl; - cout << channelInfo.getAccessWrite() << endl; - */ - - if (status != ICAFE_SUCCESS) { - NS_MOCHA::printStatus(status); - return; - } - - - plhs[0]=mxCreateStructMatrix(1, 1, nfieldsInfo, fnamesInfo); - -//const char * fnamesInfo[9] ={"channelID","connectFlag","hostName","dataType", -//"className","accessRead", "accessWrite","nelem","connectionState"}; - - - //fout0 = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - //ulongArray = (uint32_T *) mxGetData (fout1); - //ulongArray[0]=(chid) channelInfo.getChannelID(); - fout0 = mxCreateCellMatrix(1,1); - stringstream ss; - ss << channelInfo.getChannelID(); - string strH = ss.str(); - //mxSetCell (fout0, 0, mxCreateString( strH.c_str())); - - fout0 = mxCreateString( strH.c_str()); - fout1 = mxCreateLogicalScalar(channelInfo.getConnectFlag()); - - fout2 = mxCreateString( channelInfo.getHostName()); - - //fout2 = mxCreateCellMatrix(1,1); - //fout3 = mxCreateCellMatrix(1,1); - //fout4 = mxCreateCellMatrix(1,1); - //fout8 = mxCreateCellMatrix(1,1); - - switch (channelInfo.getDataType()){ - case CAFE_DOUBLE: - fout3 = mxCreateString("DBR_DOUBLE"); - break; - case CAFE_FLOAT: - fout3 = mxCreateString("DBR_FLOAT"); - break; - case CAFE_SHORT: - fout3 = mxCreateString("DBR_SHORT"); - break; - case CAFE_ENUM: - fout3 = mxCreateString("DBR_ENUM"); - break; - case CAFE_CHAR: - fout3 = mxCreateString("DBR_CHAR"); - break; - case CAFE_LONG: - fout3 = mxCreateString("DBR_LONG"); - break; - case CAFE_STRING: - fout3 = mxCreateString("DBR_STRING"); - break; - default: //If not connected for instance - fout3 = mxCreateString("DBR_UNKNOWN"); - break; - } - - - //mxSetCell (fout2, 0, mxCreateString( channelInfo.getHostName())); - //mxSetCell (fout4, 0, mxCreateString( channelInfo.getClassName())); - //mxSetCell (fout8, 0, mxCreateString( channelInfo.getConnectionStateAsString().c_str())); - - fout4 = mxCreateString( channelInfo.getClassNameAsString().c_str()); - fout8 = mxCreateString( channelInfo.getConnectionStateAsString().c_str()); - - fout5 = mxCreateLogicalScalar(channelInfo.getAccessRead()); - fout6 = mxCreateLogicalScalar(channelInfo.getAccessWrite()); - - fout7 = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - - inputULong = (uint32_T *) mxGetData (fout7); - inputULong[0]=channelInfo.getNelem(); - - - - fout16=mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - fHandle = (uint32_T *) mxGetData(fout16); - fHandle[0]=handle; - string s = cafe.getPVFromHandle(handle); - fout17 =mxCreateString( s.c_str() ); - - - - //Prepare struct - - - - mxSetFieldByNumber(plhs[0], 0, 0, fout16); //handle - mxSetFieldByNumber(plhs[0], 0, 1, fout17); //pv - mxSetFieldByNumber(plhs[0], 0, 2, fout0); - mxSetFieldByNumber(plhs[0], 0, 3, fout1); - mxSetFieldByNumber(plhs[0], 0, 4, fout2); - mxSetFieldByNumber(plhs[0], 0, 5, fout3); - mxSetFieldByNumber(plhs[0], 0, 6, fout4); - mxSetFieldByNumber(plhs[0], 0, 7, fout5); - mxSetFieldByNumber(plhs[0], 0, 8, fout6); - mxSetFieldByNumber(plhs[0], 0, 9, fout7); - mxSetFieldByNumber(plhs[0], 0,10, fout8); - - break; - } - - - - - case GET_READ_ACCESS: - { - if (nrhs<2) { - mexPrintf( - "Invalid Number of arguments %d. Input: 'getReadAccess', handle \n", nrhs); - return; - } - handle=checkForHandleNoOpen(prhs[1]); - plhs[0] = mxCreateLogicalScalar(cafe.getReadAccess(handle)); - - break; - } - - case GET_WRITE_ACCESS: - { - if (nrhs<2) { - mexPrintf( - "Invalid Number of arguments %d. Input: 'getWriteAccess', handle \n", nrhs); - return; - } - handle=checkForHandleNoOpen(prhs[1]); - plhs[0] = mxCreateLogicalScalar(cafe.getWriteAccess(handle)); - - break; - } - - - - case FETCH_INDEX_OF_COLLECTION_MEMBER: - { - if (nrhs<3) { - mexPrintf("Invalid Number of argument %d. Input: message, collectionName, deviceName \n", nrhs); - return; - } - - if (!mxIsChar(prhs[1]) ) { - mexPrintf("collectionName does not have a string value \n" ); - return; - } - if (!mxIsChar(prhs[2]) ) { - mexPrintf("deviceName does not have a string value \n" ); - return; - } - - //message groupName - yData = (mxArray *) prhs[1]; - pvLength = PVNAME_MAX_SIZE+1; - mxGetString(yData, groupName, pvLength); - - //message pvname - xData = (mxArray *) prhs[2]; - mxGetString(xData, pv, pvLength); - - long idx=cafe.fetchIndexOfCollectionMember(groupName, pv); - idx=idx+1; - - plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - uint32_T * idxArray = (uint32_T *) mxGetData ( plhs[0]); - - idxArray[0]=(uint32_T) idx; //+1 as first element is matlab array indexed by 1 not 0!! - - break; - } - - case FETCH_INDEX_OF_GROUP_MEMBER: - { - if (nrhs<3) { - mexPrintf("Invalid Number of argument %d. Input: message, groupName, pv \n", nrhs); - return; - } - - if (!mxIsChar(prhs[1]) ) { - mexPrintf("groupName does not have a string value \n" ); - return; - } - if (!mxIsChar(prhs[2]) ) { - mexPrintf("pv does not have a string value \n"); - return; - } - - //message groupName - yData = (mxArray *) prhs[1]; - pvLength = PVNAME_MAX_SIZE+1; - mxGetString(yData, groupName, pvLength); - - //message pvname - xData = (mxArray *) prhs[2]; - mxGetString(xData, pv, pvLength); - - long idx=cafe.fetchIndexOfGroupMember(groupName, pv); - idx=idx+1; - - plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - uint32_T * idxArray = (uint32_T *) mxGetData ( plhs[0]); - - idxArray[0]=(uint32_T) idx; //+1 as first element is matlab array indexed by 1 not 0!! - - break; - } - case LIST_GROUPS: - { - vector glist; - glist.clear(); - cafe.groupList(glist); - plhs[0] = mxCreateCellMatrix(1,glist.size()); - for (size_t i=0; i glist; - glist.clear(); - cafe.groupMemberList(groupName,glist); - plhs[0] = mxCreateCellMatrix(glist.size(),1); - for (size_t i=0; i inList; - inList.clear(); - - for (mwSignedIndex k=1; k outList= cafe.generateChannelList(inList); - - - plhs[0] = mxCreateCellMatrix(1,outList.size()); - for (size_t i=0; i clist; - clist.clear(); - cafe.collectionList(clist); - plhs[0] = mxCreateCellMatrix(1,clist.size()); - for (size_t i=0; i clist; - clist.clear(); - cafe.collectionMemberList(groupName,clist); - plhs[0] = mxCreateCellMatrix(clist.size(),1); - for (size_t i=0; i/include/config.h is set to false.\n"); - mexPrintf("Please recompile the cafe library with qtxml to use this feature. \n"); - } - #endif - - } - else { - mexPrintf("Collections already loaded from XML. Collection names are:\n"); - - vector clist; - clist.clear(); - cafe.collectionList(clist); - - for (size_t i=0; i/include/config.h is false.\n"); - mexPrintf("Please recompile the cafe library with qtxml to use this feature. \n"); - - } - #endif - - } - else { - mexPrintf("Groups already loaded from XML. Group names are listed.\n"); - mexPrintf("mocha ('listGroupMembers', ) will list the members of the given group. \n"); - vector glist; - glist.clear(); - cafe.groupList(glist); - - for (size_t i=0; i2) { - if( !mxIsLogical(prhs[2]) ) { - mexPrintf("3rd input argument must be of Matlab type Logical, i.e.true/false \n" ); - return; - } - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - status=cafe.getPolicy().setSelfGoverningTimeout(handle,mxIsLogicalScalarTrue(prhs[2])); - } - else { - status=ECAFE_INVALID_HANDLE; - mexPrintf("handle=%d does not exist\n", handle); - } - } - else { - if( !mxIsLogical(prhs[1]) ) { - mexPrintf("If method is meant for all handles, then: \n" ); - mexPrintf("1st input argument must be of Matlab type Logical, i.e.true/false \n" ); - return; - } - status=cafe.getPolicy().setSelfGoverningTimeout(mxIsLogicalScalarTrue(prhs[1])); - } - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - longStatus[0]=status; - break; - - } - - - - - - case SET_TIMEOUT_DEFAULT: - { - if (nrhs>2) { - mexPrintf("Ignoring all input arguments after the 2nd\n"); - } - - if (nrhs>1) { - - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - status=cafe.getPolicy().setTimeoutToDefault(handle); - } - else { - status=ECAFE_INVALID_HANDLE; - } - } - else { - status=cafe.getPolicy().setTimeoutToDefault(); - - } - - plhs[0] = mxCreateDoubleMatrix(1,2,mxREAL); - doubleArray = mxGetPr ( plhs[0]); - - //Return default timeout - if (status==ICAFE_NORMAL) { - - - double ax=0,bx=0; - if (nrhs>1 && handle!=0) { - - cafe.getPolicy().getTimeout(handle,ax,bx); - doubleArray[0]=ax; - doubleArray[1]=bx; - break; - } - else { - double cx=0,dx=0; - cafe.getPolicy().getTimeoutRange(ax,bx,cx,dx); - - doubleArray[0]=min(ax,bx); //min put (min/max should be same) - doubleArray[1]=min(cx,dx); //min get (min/max should be same) - break; - } - } - else { - mexPrintf("Error in setting timeouts to default value!\n"); - doubleArray[0]=-1; - doubleArray[1]=-1; - } - break; - - } - - case SET_TIMEOUT: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle, timeout \n", nrhs); - mexPrintf("or message, timeout (applied to all handles) \n"); - - return; - } - - if (nrhs>2) { - if (!mxIsNumeric(prhs[2]) ) { - mexPrintf("Timeout does not have a numeric value \n" ); - return; - } - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - status=cafe.getPolicy().setTimeout(handle,mxGetScalar(prhs[2])); - } - else { - status=ECAFE_INVALID_HANDLE; - } - } - else { - status=cafe.getPolicy().setTimeout(mxGetScalar(prhs[1])); - } - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - longStatus[0]=status; - break; - } - - case SET_TIMEOUT_PUT: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle, timeout (for put) \n", nrhs); - mexPrintf("or message, timeout (for put, applied to all handles) \n"); - - return; - } - - if (nrhs>2) { - if (!mxIsNumeric(prhs[2]) ) { - mexPrintf("Timeout does not have a numeric value \n" ); - return; - } - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - status=cafe.getPolicy().setTimeoutPut(handle,mxGetScalar(prhs[2])); - } - else { - status=ECAFE_INVALID_HANDLE; - } - } - else { - status=cafe.getPolicy().setTimeoutPut(mxGetScalar(prhs[1])); - } - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - longStatus[0]=status; - break; - } - - - case SET_TIMEOUT_GET: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle, timeout (for get) \n", nrhs); - mexPrintf("or message, timeout (for get, applied to all handles) \n"); - - return; - } - - if (nrhs>2) { - if (!mxIsNumeric(prhs[2]) ) { - mexPrintf("Timeout does not have a numeric value \n"); - return; - } - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - status=cafe.getPolicy().setTimeoutGet(handle,mxGetScalar(prhs[2])); - } - else { - status=ECAFE_INVALID_HANDLE; - } - } - else { - status=cafe.getPolicy().setTimeoutGet(mxGetScalar(prhs[1])); - } - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - longStatus[0]=status; - break; - } - - - case GET_TIMEOUT: - { - - plhs[0] = mxCreateDoubleMatrix(1,2,mxREAL); - doubleArray = mxGetPr ( plhs[0]); - - double ax=0,bx=0; - if (nrhs>1) { - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - cafe.getPolicy().getTimeout(handle,ax,bx); - doubleArray[0]=ax; - doubleArray[1]=bx; - break; - } - else { - mexPrintf("handle=%d does not exist", handle); - } - } - else { - double cx=0,dx=0; - cafe.getPolicy().getTimeoutRange(ax,bx,cx,dx); - - doubleArray[0]=min(ax,bx); //min put - doubleArray[1]=min(cx,dx); //min,get - break; - } - doubleArray[0]=0; - doubleArray[1]=0; - break; - } - - - case SET_SG_SELF_GOVERNING_TIMEOUT: - { - - - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, gHandle, true/false \n", nrhs); - mexPrintf("or message, true/false (applied to all group handles) \n"); - - return; - } - - if (nrhs>2) { - if( !mxIsLogical(prhs[2]) ) { - mexPrintf("3rd input argument must be of Matlab type Logical, i.e.true/false \n" ); - return; - } - - ghandle=checkForGroupHandleNoOpen(prhs[1]); - if (ghandle != 0) { - status=cafe.getPolicy().setSGSelfGoverningTimeout(ghandle,mxIsLogicalScalarTrue(prhs[2])); - } - else { - status=ECAFE_INVALID_GROUP_HANDLE; - mexPrintf("ghandle=%d does not exist\n", ghandle); - } - } - else { - if( !mxIsLogical(prhs[1]) ) { - mexPrintf("If method is meant for all handles, then: \n" ); - mexPrintf("1st input argument must be of Matlab type Logical, i.e.true/false \n" ); - return; - } - status=cafe.getPolicy().setSGSelfGoverningTimeout(mxIsLogicalScalarTrue(prhs[1])); - } - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - longStatus[0]=status; - break; - - } - - - - - case SET_SG_TIMEOUT_DEFAULT: - { - - if (nrhs>2) { - mexPrintf("Ignoring all input arguments after the 2nd\n"); - } - - if (nrhs>1) { - - - ghandle=checkForGroupHandleNoOpen(prhs[1]); - if (ghandle != 0) { - status=cafe.getPolicy().setSGTimeoutToDefault(ghandle); - } - else { - status=ECAFE_INVALID_GROUP_HANDLE; - mexPrintf("ghandle=%d does not exist\n", ghandle); - } - } - else { - status=cafe.getPolicy().setSGTimeoutToDefault(); - } - - plhs[0] = mxCreateDoubleMatrix(1,2,mxREAL); - doubleArray = mxGetPr ( plhs[0]); - - //Return default timeout - if (status==ICAFE_NORMAL) { - - - double ax=0,bx=0; - if (nrhs>1 && ghandle!=0) { - - cafe.getPolicy().getSGTimeout(ghandle,ax,bx); - doubleArray[0]=ax; - doubleArray[1]=bx; - break; - } - else { - double cx=0,dx=0; - cafe.getPolicy().getSGTimeoutRange(ax,bx,cx,dx); - - doubleArray[0]=min(ax,bx); //min put (min/max should be same) - doubleArray[1]=min(cx,dx); //min get (min/max should be same) - break; - } - } - else { - mexPrintf("Error in setting timeouts to default value!\n"); - doubleArray[0]=-1; - doubleArray[1]=-1; - } - break; - - } - - case SET_SG_TIMEOUT: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, gHandle, timeout \n", nrhs); - mexPrintf("or message, timeout (applied to all group handles) \n"); - - return; - } - - if (nrhs>2) { - if (!mxIsNumeric(prhs[2]) ) { - mexPrintf("Timeout does not have a numeric value \n" ); - return; - } - - ghandle=checkForGroupHandleNoOpen(prhs[1]); - if (ghandle != 0) { - status=cafe.getPolicy().setSGTimeout(ghandle,mxGetScalar(prhs[2])); - } - else { - status=ECAFE_INVALID_GROUP_HANDLE; - mexPrintf("ghandle=%d does not exist\n", ghandle); - } - } - else { - status=cafe.getPolicy().setSGTimeout(mxGetScalar(prhs[1])); - } - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - longStatus[0]=status; - break; - } - - case SET_SG_TIMEOUT_PUT: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, gHandle, timeout (for put) \n", nrhs); - mexPrintf("or message, timeout (for put, applied to all group handles) \n"); - - return; - } - - if (nrhs>2) { - if (!mxIsNumeric(prhs[2]) ) { - mexPrintf("Timeout does not have a numeric value \n" ); - return; - } - - ghandle=checkForGroupHandleNoOpen(prhs[1]); - if (ghandle != 0) { - status=cafe.getPolicy().setSGTimeoutPut(ghandle,mxGetScalar(prhs[2])); - } - else { - status=ECAFE_INVALID_GROUP_HANDLE; - mexPrintf("ghandle=%d does not exist\n", ghandle); - } - } - else { - status=cafe.getPolicy().setSGTimeoutPut(mxGetScalar(prhs[1])); - } - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - longStatus[0]=status; - break; - } - - - case SET_SG_TIMEOUT_GET: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, gHandle, timeout (for get) \n", nrhs); - mexPrintf("or message, timeout (for get, applied to all group handles) \n"); - - return; - } - - if (nrhs>2) { - if (!mxIsNumeric(prhs[2]) ) { - mexPrintf("Timeout does not have a numeric value \n"); - return; - } - - ghandle=checkForGroupHandleNoOpen(prhs[1]); - if (ghandle != 0) { - status=cafe.getPolicy().setSGTimeoutGet(ghandle,mxGetScalar(prhs[2])); - } - else { - status=ECAFE_INVALID_GROUP_HANDLE; - mexPrintf("ghandle=%d does not exist\n", ghandle); - } - } - else { - status=cafe.getPolicy().setSGTimeoutGet(mxGetScalar(prhs[1])); - } - //status - plhs[0] = mxCreateNumericMatrix(1,1,mxINT32_CLASS,mxREAL); - longStatus = (int32_T *) mxGetData ( plhs[0]); - longStatus[0]=status; - break; - } - - - case GET_SG_TIMEOUT: - { - - plhs[0] = mxCreateDoubleMatrix(1,2,mxREAL); - doubleArray = mxGetPr ( plhs[0]); - - double ax=0,bx=0; - if (nrhs>1) { - ghandle=checkForGroupHandleNoOpen(prhs[1]); - if (ghandle != 0) { - cafe.getPolicy().getSGTimeout(ghandle,ax,bx); - doubleArray[0]=ax; - doubleArray[1]=bx; - break; - } - else { - mexPrintf("ghandle=%d does not exist\n", ghandle); - } - } - else { - double cx=0,dx=0; - cafe.getPolicy().getSGTimeoutRange(ax,bx,cx,dx); - - doubleArray[0]=min(ax,bx); //min put - doubleArray[1]=min(cx,dx); //min,get - break; - } - doubleArray[0]=0; - doubleArray[1]=0; - break; - } - - case SET_NELEM: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle, nelem (else to native if not given) \n", nrhs); - return; - } - - uint32_T nDataTransfer= 0; - - if (!mxIsNumeric(prhs[2]) ) { - mexPrintf("nelem does not have a numeric value \n"); - return; - } - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - if (cacheFlag) { - if (nrhs >2) { - nDataTransfer=cafe.getHandleHelper().setNelemToRetrieveFromCache(handle,mxGetScalar(prhs[2])); - } - else if (nrhs==2) { - nDataTransfer=cafe.getHandleHelper().setNelemToRetrieveFromCache(handle); - } - //mexPrintf("nDataTransfer for Cache = %d", nDataTransfer); - } - else { - if (nrhs >2) { - nDataTransfer=cafe.getHandleHelper().setNelem(handle,mxGetScalar(prhs[2])); - } - else if (nrhs==2) { - nDataTransfer=cafe.getHandleHelper().setNelem(handle); - } - - } - } - - //nDataTransfer - plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - ulongArray[0]= nDataTransfer; - break; - } - - case SET_OFFSET: - { - if (nrhs<3) { - mexPrintf("Invalid Number of argument %d. Input: message, handle, offset \n", nrhs); - return; - } - - uint32_T nOffset= 0; - - if (!mxIsNumeric(prhs[2]) ) { - mexPrintf("offset does not have a numeric value \n" ); - return; - } - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - nOffset=cafe.getHandleHelper().setOffset(handle,mxGetScalar(prhs[2])); - } - - - //nOffset - plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - ulongArray[0]= nOffset; - break; - } - - case GET_NELEM_NATIVE: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle\n", nrhs); - return; - } - - uint32_T nElements= 0; - - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - nElements=cafe.getHandleHelper().getNelemNative(handle); - } - - - //nElements - plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - ulongArray[0]= nElements; - break; - } - - case GET_NELEM_CLIENT: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle\n", nrhs); - return; - } - - uint32_T nElements= 0; - - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - nElements=cafe.getHandleHelper().getNelemClient(handle); - } - - - //nElements - plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - ulongArray[0]= nElements; - break; - } - - - case GET_NELEM_REQUEST: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle\n", nrhs); - return; - } - - uint32_T nElements= 0; - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - if(cacheFlag) { - nElements=cafe.getHandleHelper().getNelemToRetrieveFromCache(handle); - } - else { - nElements=cafe.getHandleHelper().getNelemRequest(handle); - } - } - - - //nElements - plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - ulongArray[0]= nElements; - break; - } - - - case GET_NELEM: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle\n", nrhs); - return; - } - - uint32_T nElements[3]; // client, native, requested - nElements[0]=0; nElements[1]=0; nElements[2]=0; - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - cafe.getHandleHelper().getNelem(handle, nElements[0], nElements[1], nElements[2]); - } - - - //nElements - plhs[0] = mxCreateNumericMatrix(1,3,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData ( plhs[0]); - ulongArray[0]= nElements[0]; - ulongArray[1]= nElements[1]; - ulongArray[2]= nElements[2]; - break; - } - - - case GET_OFFSET: - { - if (nrhs<2) { - mexPrintf("Invalid Number of argument %d. Input: message, handle\n", nrhs); - return; - } - - uint32_T nOffset= 0; - - handle=checkForHandleNoOpen(prhs[1]); - if (handle != 0) { - nOffset=cafe.getHandleHelper().getOffset(handle); - } - - //nOffset - plhs[0] = mxCreateNumericMatrix(1,1,mxUINT32_CLASS,mxREAL); - ulongArray = (uint32_T *) mxGetData (plhs[0]); - ulongArray[0]= nOffset; - break; - } - - - - - default: - char * _messOriginal=messOriginal; - cafe.getHandleHelper().removeLeadingAndTrailingSpaces(_messOriginal,messOriginal); - mexPrintf("%s %s\n","Unknown message--->", messOriginal); - plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); - doubleArray = mxGetPr ( plhs[0]); - doubleArray[0]=numeric_limits::signaling_NaN(); - break; - - }//End Big Switch - -return; -} - - - diff --git a/scripts/caget.m- b/scripts/caget.m- deleted file mode 100755 index 60e9f0a..0000000 --- a/scripts/caget.m- +++ /dev/null @@ -1,109 +0,0 @@ -function value = caget(channel,cached) -% caget('channel') returns current value and additional infos -% of given EPICS channel. -% caget('channel',1) returns last value and additional infos -% of given EPICS channel. -% -% channel can be a channel name or a handle as returned from mcaopen -% -% return value elements: -% val: value (scalar, vector or string) -% sevr: severity as a number -% sevr_str: severity as a string -% stat: status as a number -% stat_str: status as a string -% time: timestamp as a date vector -% units: units string - -persistent severity_str -persistent status_str -persistent zerotime -persistent units - -if ischar(channel) - pv = mocha('open',channel); - - if mocha('isConnected', channel) == false - mocha('openNowAndWait', 0.5) - end - - if mocha('isConnected', channel) == false - error('EPICS channel %s not found', channel); - end -elseif isnumeric(channel) - pv = channel; -else - error ('first argument must be channel name or handle'); -end -if isvector(pv) - pv=pv(1); % truncate -end -if nargin > 1 && cached - pvStruct = mocha('getPVCache',pv); -else - pvStruct = mocha('getPV', pv); -end - -val=pvStruct.val - -pvCtrl = mocha('getCtrlCache',pv); -%pvCtrl - -% initialize severity and status enums -if isempty(severity_str) - severity_str = {'NO_ALARM';'MINOR';'MAJOR';'INVALID'}; - status_str = {'NO_ALARM';'READ';'WRITE';'HIHI';'HIGH';'LOLO';'LOW';'STATE';'COS';'COMM';'TIMEOUT';'HWLIMIT';'CALC';'SCAN';'LINK';'SOFT';'BAD_SUB';'UDF';'DISABLE';'SIMM';'READ_ACCESS';'WRITE_ACCESS'}; -end - - -value.val = val; - -units = pvCtrl.units; -string = pvCtrl.enumStrings; - -if size(string) > 1 - disp(size(string)) - value.val_str = value.val; - value.val = mocha('getCache',pv,'int8'); -end - - -%if ~isempty(units{1}) - %value.units = units{1}; -%end -value.units=units; -value.sevr = pvStruct.alarmSeverity; -indx=max(pvStruct.alarmSeverity, 0); -value.sevr_str = severity_str{indx+1}; -value.stat = pvStruct.alarmStatus; -indx=max(pvStruct.alarmStatus, 0); -value.stat_str = status_str{ indx+1}; - - - -timestamp = mocha('getTimestamp',pv); -if (numel(timestamp) == 2) -% old mca version -% do not use mcatime here because 1. it is slow, 2. is returns UTC -% calculating zerotime only once is faster and takes localtime into account -% When daylight saving time begins or ends, restart the program! - if isempty(zerotime) - [status,timezone]=system('date +%z'); % get localtime offset - timeoffs=str2double(timezone); - houroffs=floor(timeoffs/100); - minoffs=(timeoffs-100*houroffs); - zerotime = datenum('1-Jan-1990') + (minoffs/60 + houroffs)/24; - end - time=timestamp(1)+timestamp(2)/1000000000; - if time - time = zerotime+time/24/3600; - end - value.time = datevec(time); -else -% new mca version - timestamp(6)=timestamp(6)+timestamp(7)/1000000000; - value.time = timestamp(1:6); -end - - -