diff --git a/exampleNew.m b/exampleNew.m index c94a81d..56df4cc 100644 --- a/exampleNew.m +++ b/exampleNew.m @@ -245,8 +245,6 @@ pvStruct.epicsTS; %[secPastEpoch, nsec] %END (2) Simple single channel operations %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %(3) Understanding the Status Error Code / MATLAB Exceptions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -545,8 +543,6 @@ pvData(3).val %END (8) Multiple Struct operations on several PVS returning PVData Objects plus Multiple Sets for Scalars/Vectors %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - - %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %(9) Asynchronous interactions and retrieving data from Cache %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -762,7 +758,7 @@ mocha('monitorFlushEvent', pv(1)); %will execute the MATLAB script monitorAction mocha('monitorFlushEvent'); %will execute all 'actions' for all 'handles' that have received new data %The above command is used in conjunction with MATLAB timer (as for MCA's mcamontimer.m) -obj.t = timer('TimerFcn', 'mocha(''monitorFlushEvent'')', 'Period', 2.0, 'ExecutionMode', 'fixedSpacing'); +obj.t = timer('TimerFcn', 'mocha(''monitorFlushEvent'')', 'Period', 1.0, 'ExecutionMode', 'fixedSpacing'); %Else if double quotes cannot be used in the above; here's a way around the problem: %obj.t = timer('TimerFcn', 'mocha(402)', 'Period', 2.0, 'ExecutionMode', 'fixedSpacing'); start(obj.t); diff --git a/macchinettaHelper.h b/macchinettaHelper.h index 8e71a58..712349c 100644 --- a/macchinettaHelper.h +++ b/macchinettaHelper.h @@ -215,6 +215,8 @@ void msInsert() { 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, "setopentimeout")); + ms.insert(mochaccino(OPEN_WAIT_TIME_TO_DEFAULT, "setopentimeouttodefault")); ms.insert(mochaccino(OPEN_WAIT_WITH_TIME, "setopenwaittime")); ms.insert(mochaccino(OPEN_WAIT_TIME_TO_DEFAULT, "setopenwaittimetodefault")); @@ -1012,7 +1014,6 @@ vector openArray(vector vstr) { } - unsigned int open(char _pv[PVNAME_MAX_SIZE]) { uint32_T _handle=0; diff --git a/macchinettaHelper.h- b/macchinettaHelper.h- new file mode 100644 index 0000000..8e71a58 --- /dev/null +++ b/macchinettaHelper.h- @@ -0,0 +1,2052 @@ +#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 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); + //cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_AFTER_EACH_CHANNEL_CREATION); + //cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); } + break; @@ -916,7 +921,8 @@ void macchinettaFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prh } } - + mexPrintf("openArray - when %d\n", cafe.channelOpenPolicy.getWhenToFlushSendBuffer()); + mexPrintf("openArray - with %d\n", cafe.channelOpenPolicy.getFlushSendBufferKind()); vector vuint32=NS_MOCHA::openArray(vstr); diff --git a/macchinettaSwitch.cpp- b/macchinettaSwitch.cpp- index 5be274b..8d871bb 100644 --- a/macchinettaSwitch.cpp- +++ b/macchinettaSwitch.cpp- @@ -453,7 +453,7 @@ void macchinettaFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prh break; case MOCHA_VERSION: - plhs[0]=mxCreateString((char *) "mocha-1.3.0-final-1 : September 2017"); + plhs[0]=mxCreateString((char *) "mocha-1.4.0-final-1 : November 2017"); break; case SHOW: @@ -743,8 +743,9 @@ void macchinettaFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prh } case OPEN_NOWAIT: - cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_DESIGNATED_TO_CLIENT); - cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); + //cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_DESIGNATED_TO_CLIENT); + //cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); + cafe.openPrepare(); break; @@ -755,13 +756,14 @@ void macchinettaFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prh case OPEN_NOW: - cafe.channelOpenPolicy.flushSendBufferNow(); - cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_AFTER_EACH_CHANNEL_CREATION); - cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); + //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); @@ -776,6 +778,7 @@ void macchinettaFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prh cafe.channelOpenPolicy.setTimeout(mxGetScalar(prhs[1])); cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_AFTER_EACH_CHANNEL_CREATION); cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); + } break; @@ -809,17 +812,18 @@ void macchinettaFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prh } //Get Timeput - double tPrevious=cafe.channelOpenPolicy.getTimeout(); - cafe.channelOpenPolicy.setTimeout(mxGetScalar(prhs[1])); - cafe.channelOpenPolicy.flushSendBufferNow(); + //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); + //cafe.channelOpenPolicy.setWhenToFlushSendBuffer(FLUSH_NOW); + //cafe.channelOpenPolicy.setFlushSendBufferKind(WITH_PEND_EVENT); //Set to previous //cafe.channelOpenPolicy.setTimeoutToDefault(); - cafe.channelOpenPolicy.setTimeout(tPrevious); + //cafe.channelOpenPolicy.setTimeout(tPrevious); + cafe.openNowAndWait(mxGetScalar(prhs[1])); } break; diff --git a/makefile_rel_1.5 b/makefile_rel_1.5 index 6a7aff2..96db762 100644 --- a/makefile_rel_1.5 +++ b/makefile_rel_1.5 @@ -16,9 +16,9 @@ MATLAB_VERSION=$(notdir $(MATLAB_ROOT)) ##### CHANGE AS APPROPRIATE ################# #Mocha Version to install -MOCHA_VERSION=mocha-1.5.0-final-1 +MOCHA_VERSION=mocha-1.5.0-final-2 #CAFE version to link to -CAFE_VERSION=cafe-1.5.0-final-1 +CAFE_VERSION=cafe-1.5.0-final-2 #CAFE_VERSION_M=cafe-1.3.0-final-2m #PYTHON_INCLUDE=/usr/include/python2.6