diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..828f1f7 --- /dev/null +++ b/Readme.md @@ -0,0 +1,88 @@ +# ``XPLORE-Software`` + +### Introduction + +**How this project fits into the scheme of things** : +- The ``XPLORE`` system is a sophisticated research grade tool that allows for the measurement of electrical and magnetic transport properties of materials over a wide range of temperature. The system is divided into several modules (Fig.~\ref{fig:xplore_electronics}) described in the following sections, each of which allows the user to explore numerous important properties of their sample. + + + +- Each of XPLORE's modules has separate hardware/software + +- Each complete module is made up of the following inter-related layers : +*Hardware* -> *Firmware* -> **Driver -> Application** -> *GUI* + +**Functions of Software :** +- The software is C++ code that runs on the computer. The software can be categorized into : + 1. Driver : This is C++ code, that communicates with the firmware through an FTDI interface. + 2. Application Layer : This contains wrapper functions corresponding to each function in the Driver. `swig` is used to convert these C++ libraries into Python libraries, which further interface with the GUI layer. + +**Structure of Software :** +- The software's code resides in the folder `ModuleName/code`. `ModuleName/code` further contains the following directories : + + 1. `app` : Application code for XPLORE module + 2. `stl` : C++ standard template libraries + 3. `sys` : Libraries for the hardware interface + +`app` is further divided into `app` and `src`, where `app/app` contains all header (`.h`) files and `app/src` contains all `.cxx` files. + +- The libraries reside in the folder `ModuleName/wrapper/python`. The C++ libraries are of the form `libModuleName.h' and `libModuleName.cxx`. `libModuleName.i` is an interface file for `swig`. From these files, `swig` generates a corresponding python library for the module, `libModuleName.py`. The instructions to generate the python library are given in the **Installation** section. + +**Project Page :** + +**Known Issues :** https://github.com/QuazarTech/XPLORE-firmware/issues + +### Requirements + +- XPLORE Physical Quantites Measurement System (Modules on which you want to modify software) + +- Hardware requirements + - Processor : Intel i3 or above + - Storage : Atleast 10 GB + - RAM : Atleast 4 GB + +- OS requirements + The XPLORE system has been tested on the following Operating Systems : + - Ubuntu 16.04 + +- List of Dependencies: + - python 2.7x + - cmake + - swig + - avr-gcc toolchain + + Use the following command to get dependencies : + ``` + sudo apt-get install python cmake swig gcc-avr binutils-avr avr-libc gdb-avr avrdude + ``` +Found a missing dependency? Open an issue here : https://github.com/QuazarTech/XPLORE-software/issues + +### Installation + +1. Download the source code for this project using `git clone ` +2. Navigate to folder `XPLORE-software/ModuleName/` (eg. `XPLORE-software/XSMU-2.4.0/`) +3. Run `make clean` to remove old dependency (`.dep`) files +4. Run `make wrapper` to generate the python library (`libModuleName.py`) file using swig. +5. Run `make install` to install the code in system directories. You might need to run this as `sudo`. +6. The software libraries for the XPLORE module have now been installed on your system. Each module's libraries will need to be installed separately using the above steps. + +### Configuration + + +### Testing + +Tests are provided for each function inside `XPLORE-software/ModuleName/wrapper/python/tests/`. To run the test : + 1. Navigate to `XPLORE-software/ModuleName/wrapper/python/tests/` + 2. Type `python testName.py` and press Enter. + +### Troubleshooting and FAQ + + +### Maintainers + +- Active : + - Krishnendu Chatterjee (kc@quazartech.com) + - Nishant Gupta (nishant@quazartech.com) + - Gitansh Kataria (gitansh@quazartech.com) + +- Past \ No newline at end of file diff --git a/XSMU-2.4.0/ChangeLog b/XSMU-2.4.0/ChangeLog index 4ef1fda..c4b0b49 100644 --- a/XSMU-2.4.0/ChangeLog +++ b/XSMU-2.4.0/ChangeLog @@ -1,3 +1,132 @@ +#################################################### +# +# ^^ Means updated +# ++ Means added +# +#################################################### + +### 2.4.0 + +2017-09-12 Gitansh Kataria + +* Feature: A command keepAlive is added to tell the Firmware to keep streaming data. + + +* Comm.h/Comm/cxx: + + ^^ COMM_OPCODE + -- COMM_OPCODE_SYNC + ++ COMM_OPCODE_KEEP_ALIVE + + -- class CommPacket_Synchronize + -- class CommRequest_Synchronize + -- class CommResponse_Synchronize + + ++ class CommPacket_keepAlive + ++ class CommRequest_keepAlive + ++ class CommResponse_keepAlive + + ^^ COMM_CBCODE + -- COMM_CBCODE_SYNC + ++ COMM_CBCODE_KEEP_ALIVE + + -- class CommCB_Sync + ++ class CommCB_keepAlive + + ^^ union CommCB_Union + -- char gen2 [sizeof (CommCB_Sync)] + ++ char gen2 [sizeof (CommCB_keepAlive)] + + ^^ class Comm : public Applet + -- void SyncCB (void* uint16_t) + ++ void keepAlive_CB (void*, uint16_t) + + ++ void transmit_keepAlive (uint32_t) + +* virtuaSMU.h/virtuaSMU.cxx: + + ++ void keepAlive (uint32_t*, float*) + + -- void syncCB (const CommCB* oCB); + ++ void keepAliveCB (const CommCB* oCB); + +* libxsmu.h/libxsmu.cxx: + + ++ void keepAlive (int, unsigned int, float, + unsigned int*, float*); + +* libxsmu.i: + + ++ void keepAlive (int, unsigned int, float, + unsigned int*, float*); + ++ void keepAlive (int, unsigned int, float, + unsigned int*, float*); + +------------------------------------------------------------------------ + +### 2.4.0 + +2017-09-12 Gitansh Kataria + +* Feature: Python test file for changeBaud() function + +++ changeBaud.py + +------------------------------------------------------------------------ + +### 2.4.0 + +2017-09-12 Gitansh Kataria + +* Feature: A command to change baud-rate is added. + +* FTDI.h/FTDI.cxx: + + ++ void setBaudRate (uint32_t bd); + ++ void _setBaudrate (uint32_t baudrate) + +* virtuaSMU.h/virtuaSMU.cxx: + + ^^ class Driver + ++ uint32_t baudRate_ + ++ void changeBaud (uint32_t*, float*); + ++ void changeBaudCB (CommCB*); + +* libxsmu.h/libxsmu.cxx: + + ++ void changeBaud (int, unsigned int, float, + unsigned int*, float*); + +* libxsmu.i: + + ++ void changeBaud (int, unsigned int, float, + unsigned int*, float*); + ++ void changeBaud (int, unsigned int, float, + unsigned int*, float*); + +* Comm.h/Comm.cxx: + + ^^ COMM_OPCODE + ++ COMM_OPCODE_CHANGE_BAUD + + ++ class CommPacket_ChangeBaud + ++ class CommRequest_ChangeBaud + ++ class CommResponse_ChangeBaud + + ^^ COMM_CBCODE + ++ COMM_CBCODE_CHANGE_BAUD + + ++ class CommCB_ChangeBaud + + ^^ union CommCB_Union + ++ char gen4 [sizeof (CommCB_ChangeBaud)] + + ^^ class Comm : public Applet + ++ void changeBaud_CB (void*, uint16_t) + ++ void transmit_changeBaud (uint32_t) + + ++ void setBaudRate (uint32_t) + ------------------------------------------------------------------------ r6 | (no author) | 2013-08-30 12:51:38 +0530 (Fri, 30 Aug 2013) | 4 lines diff --git a/XSMU-2.4.0/TODO b/XSMU-2.4.0/TODO new file mode 100644 index 0000000..626649d --- /dev/null +++ b/XSMU-2.4.0/TODO @@ -0,0 +1,47 @@ +2.4.0 (Streamer) +================ + + Nature : Feature + Requested by : Quazar Research + + Status : Pending + Created on : 2017-09-09 by KC + Closed on : --- + +Description +----------- + +The SMU is to stream voltmeter data at a specified frequency. This requires following features to be implemented. + + 1) Dynamically change baudrate to suit data stream. + + -- CHANGE_BAUD + + 2) Start recording + + -- START_REC : Starts recording of timed data into internal buffer. + + 3) Transfer recorded data chunks to computer + + -- Two queues active and standby in firmware. + + -- REC_SIZE : Queries number of available data points in buffer + + -- Data from ADC keeps getting stored into the Active queue (interrupt driven) + -- Software asks for REC_SIZE, firmware returns size of Standby queue + + -- REC_DATA : Transfers requested number of data points to driver + + -- Firmware transfers data from Standby queue to software (may be in multiple packets; \ + depends on size of stored data and size of comm packet) + -- This transfer is uint32_t (ADC value) and not float. Conversion to float is to be done in software now. + -- This requires the functions XX_setCalibration() to also save the calibration table in software. + -- When no data remaining data in Standby queue (switch Active and Standby queues) + + 5) Stop recording + + -- STOP_REC : Stops recording gracefully. + + 6) + + -- KEEP_ALIVE : Stops recording if keep alive packets are not received, i.e. if driver is dead. diff --git a/XSMU-2.4.0/code/app/app/Comm.h b/XSMU-2.4.0/code/app/app/Comm.h index d73ba4d..5b16595 100644 --- a/XSMU-2.4.0/code/app/app/Comm.h +++ b/XSMU-2.4.0/code/app/app/Comm.h @@ -10,16 +10,17 @@ #include #include #include +#include namespace smu{ -/******************************************************************/ +/************************************************************************/ enum Comm_Opcode { COMM_OPCODE_NOP, //00 COMM_OPCODE_IDN, //01 - COMM_OPCODE_SYNC, //02 + COMM_OPCODE_KEEP_ALIVE, //02 COMM_OPCODE_SET_SOURCE_MODE, //03 COMM_OPCODE_CS_SET_RANGE, //04 COMM_OPCODE_CS_GET_CALIBRATION, //05 @@ -64,6 +65,12 @@ enum Comm_Opcode COMM_OPCODE_VM2_LOAD_DEFAULT_CALIBRATION, //40 COMM_OPCODE_VM_SET_TERMINAL, //41 COMM_OPCODE_VM_GET_TERMINAL, //42 + + COMM_OPCODE_CHANGE_BAUD, //43 + COMM_OPCODE_REC_SIZE, //44 + COMM_OPCODE_REC_DATA, //45 + COMM_OPCODE_START_REC, //46 + COMM_OPCODE_STOP_REC, //47 }; enum Comm_SourceMode @@ -132,7 +139,7 @@ enum Comm_VM_Terminal Comm_VM_Terminal toComm_VM_Terminal (uint16_t i); -/******************************************************************/ +/************************************************************************/ class CommPacket { @@ -150,7 +157,7 @@ class CommPacket uint16_t reserve_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_Identity : public CommPacket { @@ -197,29 +204,40 @@ class CommResponse_Identity : public CommPacket_Identity CommResponse_Identity (void); }; -/******************************************************************/ +/************************************************************************/ -class CommPacket_Synchronize : public CommPacket +class CommPacket_keepAlive : public CommPacket { protected: - CommPacket_Synchronize (void) : - CommPacket (COMM_OPCODE_SYNC) + CommPacket_keepAlive (void) : + CommPacket (COMM_OPCODE_KEEP_ALIVE) {} }; -class CommRequest_Synchronize : public CommPacket_Synchronize +class CommRequest_keepAlive : public CommPacket_keepAlive { public: - CommRequest_Synchronize (void) {} + CommRequest_keepAlive (uint32_t lease_time_ms) : + lease_time_ms_ (smu::hton (lease_time_ms)) + {} + +private: + uint32_t lease_time_ms_; }; -class CommResponse_Synchronize : public CommPacket_Synchronize +class CommResponse_keepAlive : public CommPacket_keepAlive { private: - CommResponse_Synchronize (void); + CommResponse_keepAlive (void); + +public: + uint32_t lease_time_ms (void) const {return smu::ntoh(lease_time_ms_);} + +private: + uint32_t lease_time_ms_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_SetSourceMode : public CommPacket { @@ -257,8 +275,8 @@ class CommResponse_SetSourceMode : public CommPacket_SetSourceMode CommResponse_SetSourceMode (void); }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommPacket_CS_SetRange : public CommPacket { @@ -296,7 +314,7 @@ class CommResponse_CS_SetRange : public CommPacket_CS_SetRange uint16_t reserve_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CS_GetCalibration : public CommPacket { @@ -334,7 +352,7 @@ class CommResponse_CS_GetCalibration : public CommPacket_CS_GetCalibration float current_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CS_VerifyCalibration : public CommPacket { @@ -374,7 +392,7 @@ class CommResponse_CS_VerifyCalibration : float current_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CS_SetCalibration : public CommPacket { @@ -415,7 +433,7 @@ class CommResponse_CS_SetCalibration : public CommPacket_CS_SetCalibration float current_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CS_SaveCalibration : public CommPacket { @@ -437,7 +455,7 @@ class CommResponse_CS_SaveCalibration : public CommPacket_CS_SaveCalibration CommResponse_CS_SaveCalibration (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CS_SetCurrent : public CommPacket { @@ -470,8 +488,8 @@ class CommResponse_CS_SetCurrent : public CommPacket_CS_SetCurrent float current_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommPacket_VS_SetRange : public CommPacket { @@ -509,7 +527,7 @@ class CommResponse_VS_SetRange : public CommPacket_VS_SetRange uint16_t reserve_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VS_GetCalibration : public CommPacket { @@ -547,7 +565,7 @@ class CommResponse_VS_GetCalibration : public CommPacket_VS_GetCalibration float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VS_VerifyCalibration : public CommPacket { @@ -587,7 +605,7 @@ class CommResponse_VS_VerifyCalibration : float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VS_SetCalibration : public CommPacket { @@ -628,7 +646,7 @@ class CommResponse_VS_SetCalibration : public CommPacket_VS_SetCalibration float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VS_SaveCalibration : public CommPacket { @@ -650,7 +668,7 @@ class CommResponse_VS_SaveCalibration : public CommPacket_VS_SaveCalibration CommResponse_VS_SaveCalibration (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VS_SetVoltage : public CommPacket { @@ -683,8 +701,8 @@ class CommResponse_VS_SetVoltage : public CommPacket_VS_SetVoltage float voltage_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommPacket_CM_SetRange : public CommPacket { @@ -722,7 +740,7 @@ class CommResponse_CM_SetRange : public CommPacket_CM_SetRange uint16_t reserve_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CM_GetCalibration : public CommPacket { @@ -762,7 +780,7 @@ class CommResponse_CM_GetCalibration : public CommPacket_CM_GetCalibration float current_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CM_SetCalibration : public CommPacket { @@ -804,7 +822,7 @@ class CommResponse_CM_SetCalibration : public CommPacket_CM_SetCalibration float current_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CM_SaveCalibration : public CommPacket { @@ -826,7 +844,7 @@ class CommResponse_CM_SaveCalibration : public CommPacket_CM_SaveCalibration CommResponse_CM_SaveCalibration (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CM_Read : public CommPacket { @@ -861,8 +879,8 @@ class CommResponse_CM_Read : public CommPacket_CM_Read float current_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommPacket_VM_SetRange : public CommPacket { @@ -900,7 +918,7 @@ class CommResponse_VM_SetRange : public CommPacket_VM_SetRange uint16_t reserve_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM_GetCalibration : public CommPacket { @@ -940,7 +958,7 @@ class CommResponse_VM_GetCalibration : public CommPacket_VM_GetCalibration float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM_SetCalibration : public CommPacket { @@ -982,7 +1000,7 @@ class CommResponse_VM_SetCalibration : public CommPacket_VM_SetCalibration float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM_SaveCalibration : public CommPacket { @@ -1004,7 +1022,7 @@ class CommResponse_VM_SaveCalibration : public CommPacket_VM_SaveCalibration CommResponse_VM_SaveCalibration (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM_Read : public CommPacket { @@ -1039,7 +1057,7 @@ class CommResponse_VM_Read : public CommPacket_VM_Read float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CS_LoadDefaultCalibration : public CommPacket { @@ -1061,7 +1079,7 @@ class CommResponse_CS_LoadDefaultCalibration : public CommPacket_CS_LoadDefaultC CommResponse_CS_LoadDefaultCalibration (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VS_LoadDefaultCalibration : public CommPacket { @@ -1083,7 +1101,7 @@ class CommResponse_VS_LoadDefaultCalibration : public CommPacket_VS_LoadDefaultC CommResponse_VS_LoadDefaultCalibration (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_CM_LoadDefaultCalibration : public CommPacket { @@ -1105,7 +1123,7 @@ class CommResponse_CM_LoadDefaultCalibration : public CommPacket_CM_LoadDefaultC CommResponse_CM_LoadDefaultCalibration (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM_LoadDefaultCalibration : public CommPacket { @@ -1127,8 +1145,8 @@ class CommResponse_VM_LoadDefaultCalibration : public CommPacket_VM_LoadDefaultC CommResponse_VM_LoadDefaultCalibration (void); }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommPacket_RM_ReadAutoscale : public CommPacket { @@ -1163,8 +1181,8 @@ class CommResponse_RM_ReadAutoscale : public CommPacket_RM_ReadAutoscale float resistance_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ enum SystemConfigParamID { @@ -1208,7 +1226,7 @@ class CommResponse_SystemConfig_Get : public CommPacket_SystemConfig_Get CommResponse_SystemConfig_Get (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_SystemConfig_Set : public CommPacket { @@ -1245,7 +1263,7 @@ class CommResponse_SystemConfig_Set : public CommPacket_SystemConfig_Set CommResponse_SystemConfig_Set (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_SystemConfig_Save : public CommPacket { @@ -1267,7 +1285,7 @@ class CommResponse_SystemConfig_Save : public CommPacket_SystemConfig_Save CommResponse_SystemConfig_Save (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_SystemConfig_LoadDefault : public CommPacket { @@ -1291,8 +1309,8 @@ class CommResponse_SystemConfig_LoadDefault : CommResponse_SystemConfig_LoadDefault (void); }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommPacket_VM2_SetRange : public CommPacket { @@ -1330,7 +1348,7 @@ class CommResponse_VM2_SetRange : public CommPacket_VM2_SetRange uint16_t reserve_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM2_GetCalibration : public CommPacket { @@ -1370,7 +1388,7 @@ class CommResponse_VM2_GetCalibration : public CommPacket_VM2_GetCalibration float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM2_SetCalibration : public CommPacket { @@ -1412,7 +1430,7 @@ class CommResponse_VM2_SetCalibration : public CommPacket_VM2_SetCalibration float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM2_SaveCalibration : public CommPacket { @@ -1434,7 +1452,7 @@ class CommResponse_VM2_SaveCalibration : public CommPacket_VM2_SaveCalibration CommResponse_VM2_SaveCalibration (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM2_Read : public CommPacket { @@ -1469,7 +1487,7 @@ class CommResponse_VM2_Read : public CommPacket_VM2_Read float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM2_LoadDefaultCalibration : public CommPacket { @@ -1491,7 +1509,7 @@ class CommResponse_VM2_LoadDefaultCalibration : public CommPacket_VM2_LoadDefaul CommResponse_VM2_LoadDefaultCalibration (void); }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM_SetTerminal : public CommPacket { @@ -1529,7 +1547,7 @@ class CommResponse_VM_SetTerminal : public CommPacket_VM_SetTerminal uint16_t reserve_; }; -/******************************************************************/ +/************************************************************************/ class CommPacket_VM_GetTerminal : public CommPacket { @@ -1561,67 +1579,223 @@ class CommResponse_VM_GetTerminal : public CommPacket_VM_GetTerminal uint16_t reserve_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ -enum Comm_CallbackCode +class CommPacket_changeBaud : public CommPacket { - COMM_CBCODE_NOP, - COMM_CBCODE_IDN, - COMM_CBCODE_SYNC, +protected: + CommPacket_changeBaud (void) : + CommPacket (COMM_OPCODE_CHANGE_BAUD) + {} +}; - COMM_CBCODE_SET_SOURCE_MODE, +class CommRequest_changeBaud : public CommPacket_changeBaud +{ +public: + CommRequest_changeBaud (uint32_t baudRate) : + baudRate_ (smu::hton (baudRate)) + {} - COMM_CBCODE_CS_SET_RANGE, - COMM_CBCODE_CS_GET_CALIBRATION, - COMM_CBCODE_CS_VERIFY_CALIBRATION, - COMM_CBCODE_CS_SET_CALIBRATION, - COMM_CBCODE_CS_SAVE_CALIBRATION, - COMM_CBCODE_CS_SET_CURRENT, +private: + uint32_t baudRate_; +}; - COMM_CBCODE_VS_SET_RANGE, - COMM_CBCODE_VS_GET_CALIBRATION, - COMM_CBCODE_VS_VERIFY_CALIBRATION, - COMM_CBCODE_VS_SET_CALIBRATION, - COMM_CBCODE_VS_SAVE_CALIBRATION, - COMM_CBCODE_VS_SET_VOLTAGE, +class CommResponse_changeBaud : public CommPacket_changeBaud +{ +private: + CommResponse_changeBaud (void); - COMM_CBCODE_CM_SET_RANGE, - COMM_CBCODE_CM_GET_CALIBRATION, - COMM_CBCODE_CM_SET_CALIBRATION, - COMM_CBCODE_CM_SAVE_CALIBRATION, - COMM_CBCODE_CM_READ, +public: + uint32_t baudRate (void) const {return smu::ntoh(baudRate_);} - COMM_CBCODE_VM_SET_RANGE, - COMM_CBCODE_VM_GET_CALIBRATION, - COMM_CBCODE_VM_SET_CALIBRATION, - COMM_CBCODE_VM_SAVE_CALIBRATION, - COMM_CBCODE_VM_READ, +private: + uint32_t baudRate_; +}; - COMM_CBCODE_CS_LOAD_DEFAULT_CALIBRATION, - COMM_CBCODE_VS_LOAD_DEFAULT_CALIBRATION, - COMM_CBCODE_CM_LOAD_DEFAULT_CALIBRATION, - COMM_CBCODE_VM_LOAD_DEFAULT_CALIBRATION, +/************************************************************************/ - COMM_CBCODE_RM_READ_AUTOSCALE, +class CommPacket_recSize : public CommPacket +{ +protected: + CommPacket_recSize (void) : + CommPacket (COMM_OPCODE_REC_SIZE) + {} +}; - COMM_CBCODE_SYSTEM_CONFIG_GET, - COMM_CBCODE_SYSTEM_CONFIG_SET, - COMM_CBCODE_SYSTEM_CONFIG_SAVE, - COMM_CBCODE_SYSTEM_CONFIG_LOAD_DEFAULT, +class CommRequest_recSize : public CommPacket_recSize +{ +public: + CommRequest_recSize (void) + {} +}; - COMM_CBCODE_VM2_SET_RANGE, - COMM_CBCODE_VM2_GET_CALIBRATION, - COMM_CBCODE_VM2_SET_CALIBRATION, - COMM_CBCODE_VM2_SAVE_CALIBRATION, - COMM_CBCODE_VM2_READ, - COMM_CBCODE_VM2_LOAD_DEFAULT_CALIBRATION, +class CommResponse_recSize : public CommPacket_recSize +{ +private: + CommResponse_recSize (void); - COMM_CBCODE_VM_SET_TERMINAL, - COMM_CBCODE_VM_GET_TERMINAL, +public: + uint16_t recSize (void) const {return smu::ntoh(recSize_);} + +private: + uint16_t recSize_; + uint16_t reserve_; }; -/******************************************************************/ +/************************************************************************/ + +class CommPacket_recData : public CommPacket +{ +protected: + CommPacket_recData (void) : + CommPacket (COMM_OPCODE_REC_DATA) + {} +}; + +class CommRequest_recData : public CommPacket_recData +{ +public: + CommRequest_recData (uint16_t size) : + size_ (smu::hton (size)), + reserve_ (0) + {} + +private: + uint16_t size_; + uint16_t reserve_; +}; + +class CommResponse_recData : public CommPacket_recData +{ +private: + CommResponse_recData (void); + +public: + uint16_t size (void) const {return smu::ntoh(size_);} + + int32_t recData (uint16_t idx) const + { + return smu::ntoh(recData_[idx]); + } + +private: + uint16_t size_; + uint16_t reserve_; + int32_t recData_[]; +}; + +/************************************************************************/ + +class CommPacket_StartRec : public CommPacket +{ +protected: + CommPacket_StartRec (void) : + CommPacket (COMM_OPCODE_START_REC) + {} +}; + +class CommRequest_StartRec : public CommPacket_StartRec +{ +public: + CommRequest_StartRec (void) {} +}; + +class CommResponse_StartRec : public CommPacket_StartRec +{ +private: + CommResponse_StartRec (void); +}; + +/************************************************************************/ + +class CommPacket_StopRec : public CommPacket +{ +protected: + CommPacket_StopRec (void) : + CommPacket (COMM_OPCODE_STOP_REC) + {} +}; + +class CommRequest_StopRec : public CommPacket_StopRec +{ +public: + CommRequest_StopRec (void) {} +}; + +class CommResponse_StopRec : public CommPacket_StopRec +{ +private: + CommResponse_StopRec (void); +}; + +/************************************************************************/ +/************************************************************************/ + +enum Comm_CallbackCode +{ + COMM_CBCODE_NOP, //00 + COMM_CBCODE_IDN, //01 + COMM_CBCODE_KEEP_ALIVE, //02 + + COMM_CBCODE_SET_SOURCE_MODE, //03 + + COMM_CBCODE_CS_SET_RANGE, //04 + COMM_CBCODE_CS_GET_CALIBRATION, //05 + COMM_CBCODE_CS_VERIFY_CALIBRATION, //06 + COMM_CBCODE_CS_SET_CALIBRATION, //07 + COMM_CBCODE_CS_SAVE_CALIBRATION, //08 + COMM_CBCODE_CS_SET_CURRENT, //09 + + COMM_CBCODE_VS_SET_RANGE, //10 + COMM_CBCODE_VS_GET_CALIBRATION, //11 + COMM_CBCODE_VS_VERIFY_CALIBRATION, //12 + COMM_CBCODE_VS_SET_CALIBRATION, //13 + COMM_CBCODE_VS_SAVE_CALIBRATION, //14 + COMM_CBCODE_VS_SET_VOLTAGE, //15 + + COMM_CBCODE_CM_SET_RANGE, //16 + COMM_CBCODE_CM_GET_CALIBRATION, //17 + COMM_CBCODE_CM_SET_CALIBRATION, //18 + COMM_CBCODE_CM_SAVE_CALIBRATION, //19 + COMM_CBCODE_CM_READ, //20 + + COMM_CBCODE_VM_SET_RANGE, //21 + COMM_CBCODE_VM_GET_CALIBRATION, //22 + COMM_CBCODE_VM_SET_CALIBRATION, //23 + COMM_CBCODE_VM_SAVE_CALIBRATION, //24 + COMM_CBCODE_VM_READ, //25 + + COMM_CBCODE_CS_LOAD_DEFAULT_CALIBRATION, //26 + COMM_CBCODE_VS_LOAD_DEFAULT_CALIBRATION, //27 + COMM_CBCODE_CM_LOAD_DEFAULT_CALIBRATION, //28 + COMM_CBCODE_VM_LOAD_DEFAULT_CALIBRATION, //29 + + COMM_CBCODE_RM_READ_AUTOSCALE, //30 + + COMM_CBCODE_SYSTEM_CONFIG_GET, //31 + COMM_CBCODE_SYSTEM_CONFIG_SET, //32 + COMM_CBCODE_SYSTEM_CONFIG_SAVE, //33 + COMM_CBCODE_SYSTEM_CONFIG_LOAD_DEFAULT, //34 + + COMM_CBCODE_VM2_SET_RANGE, //35 + COMM_CBCODE_VM2_GET_CALIBRATION, //36 + COMM_CBCODE_VM2_SET_CALIBRATION, //37 + COMM_CBCODE_VM2_SAVE_CALIBRATION, //38 + COMM_CBCODE_VM2_READ, //39 + COMM_CBCODE_VM2_LOAD_DEFAULT_CALIBRATION, //40 + + COMM_CBCODE_VM_SET_TERMINAL, //41 + COMM_CBCODE_VM_GET_TERMINAL, //42 + + COMM_CBCODE_CHANGE_BAUD, //43 + COMM_CBCODE_REC_SIZE, //44 + COMM_CBCODE_REC_DATA, //45 + COMM_CBCODE_START_REC, //46 + COMM_CBCODE_STOP_REC, //47 +}; + +/************************************************************************/ +/************************************************************************/ class CommCB { @@ -1637,7 +1811,7 @@ class CommCB Comm_CallbackCode code_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_Identity : public CommCB { @@ -1662,14 +1836,25 @@ class CommCB_Identity : public CommCB uint32_t firmware_version_; }; -class CommCB_Sync : public CommCB +/************************************************************************/ + +class CommCB_keepAlive : public CommCB { public: - CommCB_Sync (void) : - CommCB (COMM_CBCODE_SYNC) + CommCB_keepAlive (uint32_t lease_time_ms) : + CommCB (COMM_CBCODE_KEEP_ALIVE), + lease_time_ms_ (lease_time_ms) {} + +public: + uint32_t lease_time_ms (void) const {return lease_time_ms_;} + +private: + uint32_t lease_time_ms_; }; +/************************************************************************/ + class CommCB_SetSourceMode : public CommCB { public: @@ -1685,8 +1870,8 @@ class CommCB_SetSourceMode : public CommCB Comm_SourceMode mode_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommCB_CS_SetRange : public CommCB { @@ -1703,7 +1888,7 @@ class CommCB_CS_SetRange : public CommCB Comm_CS_Range range_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_CS_GetCalibration : public CommCB { @@ -1726,7 +1911,7 @@ class CommCB_CS_GetCalibration : public CommCB float current_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_CS_VerifyCalibration : public CommCB { @@ -1749,7 +1934,7 @@ class CommCB_CS_VerifyCalibration : public CommCB float current_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_CS_SetCalibration : public CommCB { @@ -1772,7 +1957,7 @@ class CommCB_CS_SetCalibration : public CommCB float current_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_CS_SaveCalibration : public CommCB { @@ -1797,8 +1982,8 @@ class CommCB_CS_SetCurrent : public CommCB float current_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommCB_VS_SetRange : public CommCB { @@ -1815,7 +2000,7 @@ class CommCB_VS_SetRange : public CommCB Comm_VS_Range range_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VS_GetCalibration : public CommCB { @@ -1838,7 +2023,7 @@ class CommCB_VS_GetCalibration : public CommCB float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VS_VerifyCalibration : public CommCB { @@ -1861,7 +2046,7 @@ class CommCB_VS_VerifyCalibration : public CommCB float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VS_SetCalibration : public CommCB { @@ -1884,7 +2069,7 @@ class CommCB_VS_SetCalibration : public CommCB float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VS_SaveCalibration : public CommCB { @@ -1909,8 +2094,8 @@ class CommCB_VS_SetVoltage : public CommCB float voltage_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommCB_CM_SetRange : public CommCB { @@ -1927,7 +2112,7 @@ class CommCB_CM_SetRange : public CommCB Comm_CM_Range range_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_CM_GetCalibration : public CommCB { @@ -1950,7 +2135,7 @@ class CommCB_CM_GetCalibration : public CommCB float current_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_CM_SetCalibration : public CommCB { @@ -1973,7 +2158,7 @@ class CommCB_CM_SetCalibration : public CommCB float current_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_CM_SaveCalibration : public CommCB { @@ -1983,7 +2168,7 @@ class CommCB_CM_SaveCalibration : public CommCB {} }; -/******************************************************************/ +/************************************************************************/ class CommCB_CM_Read : public CommCB { @@ -2000,8 +2185,8 @@ class CommCB_CM_Read : public CommCB float current_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommCB_VM_SetRange : public CommCB { @@ -2018,7 +2203,7 @@ class CommCB_VM_SetRange : public CommCB Comm_VM_Range range_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM_GetCalibration : public CommCB { @@ -2041,7 +2226,7 @@ class CommCB_VM_GetCalibration : public CommCB float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM_SetCalibration : public CommCB { @@ -2064,7 +2249,7 @@ class CommCB_VM_SetCalibration : public CommCB float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM_SaveCalibration : public CommCB { @@ -2074,7 +2259,7 @@ class CommCB_VM_SaveCalibration : public CommCB {} }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM_Read : public CommCB { @@ -2091,8 +2276,8 @@ class CommCB_VM_Read : public CommCB float voltage_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommCB_CS_LoadDefaultCalibration : public CommCB { @@ -2102,7 +2287,7 @@ class CommCB_CS_LoadDefaultCalibration : public CommCB {} }; -/******************************************************************/ +/************************************************************************/ class CommCB_VS_LoadDefaultCalibration : public CommCB { @@ -2112,7 +2297,7 @@ class CommCB_VS_LoadDefaultCalibration : public CommCB {} }; -/******************************************************************/ +/************************************************************************/ class CommCB_CM_LoadDefaultCalibration : public CommCB { @@ -2122,7 +2307,7 @@ class CommCB_CM_LoadDefaultCalibration : public CommCB {} }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM_LoadDefaultCalibration : public CommCB { @@ -2132,8 +2317,8 @@ class CommCB_VM_LoadDefaultCalibration : public CommCB {} }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommCB_RM_ReadAutoscale : public CommCB { @@ -2150,8 +2335,8 @@ class CommCB_RM_ReadAutoscale : public CommCB float resistance_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommCB_SystemConfig_Get : public CommCB { @@ -2205,8 +2390,8 @@ class CommCB_SystemConfig_LoadDefault : public CommCB {} }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class CommCB_VM2_SetRange : public CommCB { @@ -2223,7 +2408,7 @@ class CommCB_VM2_SetRange : public CommCB Comm_VM2_Range range_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM2_GetCalibration : public CommCB { @@ -2246,7 +2431,7 @@ class CommCB_VM2_GetCalibration : public CommCB float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM2_SetCalibration : public CommCB { @@ -2269,7 +2454,7 @@ class CommCB_VM2_SetCalibration : public CommCB float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM2_SaveCalibration : public CommCB { @@ -2279,7 +2464,7 @@ class CommCB_VM2_SaveCalibration : public CommCB {} }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM2_Read : public CommCB { @@ -2296,7 +2481,7 @@ class CommCB_VM2_Read : public CommCB float voltage_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM2_LoadDefaultCalibration : public CommCB { @@ -2306,7 +2491,7 @@ class CommCB_VM2_LoadDefaultCalibration : public CommCB {} }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM_SetTerminal : public CommCB { @@ -2323,7 +2508,7 @@ class CommCB_VM_SetTerminal : public CommCB Comm_VM_Terminal terminal_; }; -/******************************************************************/ +/************************************************************************/ class CommCB_VM_GetTerminal : public CommCB { @@ -2340,15 +2525,94 @@ class CommCB_VM_GetTerminal : public CommCB Comm_VM_Terminal terminal_; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ + +class CommCB_changeBaud : public CommCB +{ +public: + CommCB_changeBaud (uint32_t baudRate) : + CommCB (COMM_CBCODE_CHANGE_BAUD), + baudRate_ (baudRate) + {} + +public: + uint32_t baudRate (void) const {return baudRate_;} + +private: + uint32_t baudRate_; +}; + +/************************************************************************/ + +class CommCB_recSize : public CommCB +{ +public: + CommCB_recSize (uint32_t recSize) : + CommCB (COMM_CBCODE_REC_SIZE), + recSize_ (recSize) + {} + +public: + uint32_t recSize (void) const {return recSize_;} + +private: + uint32_t recSize_; +}; + +/************************************************************************/ + +class CommCB_recData : public CommCB +{ +public: + CommCB_recData (uint16_t size, std::vector recData) : + CommCB (COMM_CBCODE_REC_DATA), + size_ (size), + recData_ (recData) + + {} + +public: + uint16_t size (void) const {return size_;} + std::vector recData (void) const {return recData_;} + +private: + uint16_t size_; + std::vector recData_; +}; + +/************************************************************************/ + +class CommCB_StartRec : public CommCB +{ +public: + CommCB_StartRec (void) : + CommCB (COMM_CBCODE_START_REC) + {} +}; + +/************************************************************************/ + +class CommCB_StopRec : public CommCB +{ +public: + CommCB_StopRec (void) : + CommCB (COMM_CBCODE_STOP_REC) + {} +}; +/************************************************************************/ +/************************************************************************/ union CommCB_Union { char gen0[sizeof (CommCB)]; char gen1[sizeof (CommCB_Identity)]; - char gen2[sizeof (CommCB_Sync)]; + char gen2[sizeof (CommCB_keepAlive)]; char gen3[sizeof (CommCB_SetSourceMode)]; + char gen4[sizeof (CommCB_changeBaud)]; + char gen5[sizeof (CommCB_recSize)]; + char gen6[sizeof (CommCB_recData)]; + char gen7[sizeof (CommCB_StartRec)]; + char gen8[sizeof (CommCB_StopRec)]; char cs0[sizeof (CommCB_CS_SetRange)]; char cs1[sizeof (CommCB_CS_GetCalibration)]; @@ -2398,8 +2662,8 @@ union CommCB_Union char vm7[sizeof (CommCB_VM_GetTerminal)]; }; -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ class Comm : public Applet { @@ -2417,7 +2681,7 @@ class Comm : public Applet public: void check (void); void transmitIdentify (void); - void transmitSync (void); + void transmit_keepAlive (uint32_t lease_time_ms); void transmitSourceMode (Comm_SourceMode mode); /********************************/ @@ -2482,10 +2746,17 @@ class Comm : public Applet void transmit_VM2_loadDefaultCalibration (void); /********************************/ - - void transmit_VM_setTerminal (Comm_VM_Terminal terminal); - void transmit_VM_getTerminal (void); - + + void transmit_VM_setTerminal (Comm_VM_Terminal terminal); + void transmit_VM_getTerminal (void); + + /********************************/ + + void transmit_changeBaud (uint32_t baudRate); + void transmit_recSize (void); + void transmit_recData (uint16_t recSize); + void transmit_StartRec (void); + void transmit_StopRec (void); private: QP4* qp4_; @@ -2500,7 +2771,7 @@ class Comm : public Applet void nopCB (const void* data, uint16_t size); void identityCB (const void* data, uint16_t size); - void syncCB (const void* data, uint16_t size); + void keepAliveCB (const void* data, uint16_t size); void setSourceModeCB (const void* data, uint16_t size); @@ -2537,26 +2808,45 @@ class Comm : public Applet void RM_readAutoscaleCB (const void* data, uint16_t size); - void SystemConfig_GetCB (const void* data, uint16_t size); - void SystemConfig_SetCB (const void* data, uint16_t size); - void SystemConfig_SaveCB (const void* data, uint16_t size); + void SystemConfig_GetCB (const void* data, uint16_t size); + void SystemConfig_SetCB (const void* data, uint16_t size); + void SystemConfig_SaveCB (const void* data, uint16_t size); void SystemConfig_LoadDefaultCB (const void* data, uint16_t size); - void VM2_setRangeCB (const void* data, uint16_t size); - void VM2_getCalibrationCB (const void* data, uint16_t size); - void VM2_setCalibrationCB (const void* data, uint16_t size); - void VM2_saveCalibrationCB (const void* data, uint16_t size); - void VM2_readCB (const void* data, uint16_t size); + void VM2_setRangeCB (const void* data, uint16_t size); + void VM2_getCalibrationCB (const void* data, uint16_t size); + void VM2_setCalibrationCB (const void* data, uint16_t size); + void VM2_saveCalibrationCB (const void* data, uint16_t size); + void VM2_readCB (const void* data, uint16_t size); void VM2_loadDefaultCalibrationCB (const void* data, uint16_t size); - void VM_setTerminalCB (const void* data, uint16_t size); - void VM_getTerminalCB (const void* data, uint16_t size); + void VM_setTerminalCB (const void* data, uint16_t size); + void VM_getTerminalCB (const void* data, uint16_t size); + + void changeBaudCB (const void* data, uint16_t size); + + void recSizeCB (const void* data, uint16_t size); + void recDataCB (const void* data, uint16_t size); + void StartRecCB (const void* data, uint16_t size); + void StopRecCB (const void* data, uint16_t size); private: void transmit (const QP4_Packet* packet); + +public: + void setBaudRate (uint32_t baudRate); + +public: + std::unique_lock lock (void) + { + return std::unique_lock (_lock); + } + +private: + std::mutex _lock; }; -/******************************************************************/ +/************************************************************************/ } // namespace smu #endif diff --git a/XSMU-2.4.0/code/app/app/Exception.h b/XSMU-2.4.0/code/app/app/Exception.h new file mode 100644 index 0000000..4e0c7d3 --- /dev/null +++ b/XSMU-2.4.0/code/app/app/Exception.h @@ -0,0 +1,25 @@ +#ifndef __SMU_EXCEPTION__ +#define __SMU_EXCEPTION__ + +#include + +// class XSMU_Error : public std::runtime_error +// { +// +// protected: +// XSMU_Error ((std::string) error_msg) : +// runtime_error (error_msg) +// {} +// }; + + +class NoOperation : public std::runtime_error +{ + +public: + NoOperation (void) : + std::runtime_error ("XSMU Error : No Operation") + {} +}; + +#endif \ No newline at end of file diff --git a/XSMU-2.4.0/code/app/app/VM.h b/XSMU-2.4.0/code/app/app/VM.h index 3fae405..247e531 100644 --- a/XSMU-2.4.0/code/app/app/VM.h +++ b/XSMU-2.4.0/code/app/app/VM.h @@ -52,6 +52,20 @@ class VM return calibration_[index].second(); } + +public: + void setActiveCalibration (uint16_t index, int32_t adc, float voltage) { + activeCalibration_[index].set (adc, voltage); + } + + int32_t activeCalibration_adc (uint16_t index) const { + return activeCalibration_[index].first(); + } + + float activeCalibration_voltage (uint16_t index) const { + return activeCalibration_[index].second(); + } + public: VM_Terminal terminal (void) const { return terminal_; } void setTerminal (VM_Terminal __terminal) { terminal_ = __terminal;} @@ -60,8 +74,9 @@ class VM VM_Range range_; float voltage_; VM_CalibrationTable calibration_; + VM_CalibrationTable activeCalibration_; VM_Terminal terminal_; }; -} //namespace smu +} //namespace smu #endif diff --git a/XSMU-2.4.0/code/app/app/virtuaSMU.h b/XSMU-2.4.0/code/app/app/virtuaSMU.h index e2aaca4..94f0bdc 100644 --- a/XSMU-2.4.0/code/app/app/virtuaSMU.h +++ b/XSMU-2.4.0/code/app/app/virtuaSMU.h @@ -13,6 +13,9 @@ #include #include +#include +#include +#include namespace smu { @@ -58,7 +61,10 @@ class Driver { /***************************************************/ void identify (float* timeout); - void sync (float* timeout); + + void keepAlive (uint32_t* lease_time_ms, float* timeout); + void thread (void); + void poll_stream (void); void setSourceMode (SourceMode* mode, float* timeout); @@ -166,6 +172,14 @@ class Driver { /***************************************************/ + void changeBaud (uint32_t* baudRate, float* timeout); + + void recSize (uint16_t* recSize, float* timeout); + void recData (uint16_t* size, float* timeout); + void StartRec (float* timeout); + void StopRec (float* timeout); + + /***************************************************/ public: bool goodID (void) const; const char* identity (void) const { @@ -181,7 +195,7 @@ class Driver { void nopCB (const CommCB* oCB); void identityCB (const CommCB* oCB); - void syncCB (const CommCB* oCB); + void keepAliveCB (const CommCB* oCB); void setSourceModeCB (const CommCB* oCB); @@ -233,6 +247,12 @@ class Driver { void VM_setTerminalCB (const CommCB* oCB); void VM_getTerminalCB (const CommCB* oCB); + void changeBaudCB (const CommCB* oCB); + void recSizeCB (const CommCB* oCB); + void recDataCB (const CommCB* oCB); + void StartRecCB (const CommCB* oCB); + void StopRecCB (const CommCB* oCB); + private: Comm* comm_; CS* cs_; @@ -245,12 +265,38 @@ class Driver { VersionInfo* versionInfo_; AckBits ackBits_; std::string identity_; + +private: + uint32_t baudRate_; + bool _alive; + std::future _thread_future; + +private: + + uint16_t recSize_; //Stores size of available data with FW + std::queue _dataq_32; //Stores ADC data obtained from FW + + //Stores ADC data converted to float using calibration table + std::queue _dataq; + + std::mutex _dataq_lock; + +public: + std::vector getData (void); + +private: + bool _rec; + double _poll_stream_at = 100e-3; + static constexpr double _poll_stream_interval = 1000e-3; + +private: + float applyCalibration (int32_t adc_value); }; /************************************************************************/ /************************************************************************/ -} // namespae smu +} // namespace smu typedef smu::Driver VirtuaSMU; diff --git a/XSMU-2.4.0/code/app/src/Comm.cxx b/XSMU-2.4.0/code/app/src/Comm.cxx index eb08e17..6dc0199 100644 --- a/XSMU-2.4.0/code/app/src/Comm.cxx +++ b/XSMU-2.4.0/code/app/src/Comm.cxx @@ -1,8 +1,13 @@ #include "../app/Comm.h" +#include #include #include #include +#include + +#define PRINT_DEBUG(x) { \ +std::cerr << __PRETTY_FUNCTION__ << ":" << __LINE__ << ":" << x << std::endl; } using namespace std; @@ -101,8 +106,8 @@ Comm_VM_Terminal toComm_VM_Terminal (uint16_t i) values[i] : values[0]; } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ Comm::Comm (void) { @@ -132,16 +137,22 @@ void Comm::check (void) checkReceiveQueue(); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ void Comm::transmit (const QP4_Packet* packet) { ftdi_->write (packet, packet->size()); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ + +void Comm::setBaudRate (uint32_t baudRate) +{ + ftdi_->setBaudRate (baudRate); +} + +/************************************************************************/ +/************************************************************************/ void Comm::checkReceiveQueue (void) { @@ -158,6 +169,7 @@ void Comm::processReceivedData (const void* data, uint16_t size) if (size) do { + //std::printf ("%X %c\n", static_cast (*src), *src); qp4_->receiver().push_back (*src++); if (qp4_->receiver().ready()) { @@ -180,7 +192,7 @@ void Comm::interpret (const void* data, uint16_t size) { &Comm::nopCB, &Comm::identityCB, - &Comm::syncCB, + &Comm::keepAliveCB, &Comm::setSourceModeCB, &Comm::CS_setRangeCB, @@ -230,6 +242,12 @@ void Comm::interpret (const void* data, uint16_t size) &Comm::VM_setTerminalCB, &Comm::VM_getTerminalCB, + + &Comm::changeBaudCB, + &Comm::recSizeCB, + &Comm::recDataCB, + &Comm::StartRecCB, + &Comm::StopRecCB, }; if (size < sizeof (CommPacket)) @@ -242,11 +260,14 @@ void Comm::interpret (const void* data, uint16_t size) (this->*cbs[packet->opcode()])(data, size); } -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::nopCB (const void* data, uint16_t size) {} +/************************************************************************/ + void Comm::identityCB (const void* data, uint16_t size) { const CommResponse_Identity* res = @@ -258,11 +279,21 @@ void Comm::identityCB (const void* data, uint16_t size) res->containsVersionInfo (size) ? res->firmware_version() : 0)); } -void Comm::syncCB (const void* data, uint16_t size) +/************************************************************************/ + +void Comm::keepAliveCB (const void* data, uint16_t size) { - do_callback (new (&callbackObject_) CommCB_Sync); + if (size < sizeof (CommResponse_keepAlive)) + return; + + const CommResponse_keepAlive* res = + reinterpret_cast (data); + + do_callback (new (&callbackObject_) CommCB_keepAlive (res->lease_time_ms())); } +/************************************************************************/ + void Comm::setSourceModeCB (const void* data, uint16_t size) { if (size < sizeof (CommResponse_SetSourceMode)) @@ -274,7 +305,8 @@ void Comm::setSourceModeCB (const void* data, uint16_t size) do_callback (new (&callbackObject_) CommCB_SetSourceMode (res->mode())); } -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::CS_setRangeCB (const void* data, uint16_t size) { @@ -346,7 +378,7 @@ void Comm::CS_setCurrentCB (const void* data, uint16_t size) CommCB_CS_SetCurrent (res->current())); } -/******************************************************************/ +/************************************************************************/ void Comm::VS_setRangeCB (const void* data, uint16_t size) { @@ -418,7 +450,7 @@ void Comm::VS_setVoltageCB (const void* data, uint16_t size) CommCB_VS_SetVoltage (res->voltage())); } -/******************************************************************/ +/************************************************************************/ void Comm::CM_setRangeCB (const void* data, uint16_t size) { @@ -478,7 +510,7 @@ void Comm::CM_readCB (const void* data, uint16_t size) CommCB_CM_Read (res->current())); } -/******************************************************************/ +/************************************************************************/ void Comm::VM_setRangeCB (const void* data, uint16_t size) { @@ -538,7 +570,7 @@ void Comm::VM_readCB (const void* data, uint16_t size) CommCB_VM_Read (res->voltage())); } -/******************************************************************/ +/************************************************************************/ void Comm::CS_loadDefaultCalibrationCB (const void* data, uint16_t size) { @@ -572,8 +604,8 @@ void Comm::VM_loadDefaultCalibrationCB (const void* data, uint16_t size) do_callback (new (&callbackObject_) CommCB_VM_LoadDefaultCalibration); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::RM_readAutoscaleCB (const void* data, uint16_t size) { @@ -587,8 +619,8 @@ void Comm::RM_readAutoscaleCB (const void* data, uint16_t size) CommCB_RM_ReadAutoscale (res->resistance())); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::SystemConfig_GetCB (const void* data, uint16_t size) { @@ -630,8 +662,8 @@ void Comm::SystemConfig_LoadDefaultCB (const void* data, uint16_t size) do_callback (new (&callbackObject_) CommCB_SystemConfig_LoadDefault); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::VM2_setRangeCB (const void* data, uint16_t size) { @@ -699,7 +731,7 @@ void Comm::VM2_loadDefaultCalibrationCB (const void* data, uint16_t size) do_callback (new (&callbackObject_) CommCB_VM2_LoadDefaultCalibration); } -/******************************************************************/ +/************************************************************************/ void Comm::VM_setTerminalCB (const void* data, uint16_t size) { @@ -713,7 +745,6 @@ void Comm::VM_setTerminalCB (const void* data, uint16_t size) CommCB_VM_SetTerminal (res->terminal())); } - void Comm::VM_getTerminalCB (const void* data, uint16_t size) { if (size < sizeof (CommResponse_VM_GetTerminal)) @@ -726,8 +757,87 @@ void Comm::VM_getTerminalCB (const void* data, uint16_t size) CommCB_VM_GetTerminal (res->terminal())); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ + +void Comm::changeBaudCB (const void* data, uint16_t size) +{ + if (size < sizeof (CommResponse_changeBaud)) + return; + + const CommResponse_changeBaud* res = + reinterpret_cast (data); + + do_callback (new (&callbackObject_) + CommCB_changeBaud (res->baudRate())); +} + +void Comm::recSizeCB (const void* data, uint16_t size) +{ + if (size < sizeof (CommResponse_recSize)) + return; + + const CommResponse_recSize* res = + reinterpret_cast (data); + + do_callback (new (&callbackObject_) + CommCB_recSize (res->recSize())); +} + +/************************************************************************/ + +void Comm::recDataCB (const void* data, uint16_t size) +{ + PRINT_DEBUG ("Size : " << size << "Expected : " << sizeof(CommResponse_recData)) + + if (size < sizeof (CommResponse_recData)) + { + PRINT_DEBUG ("SIZE NOT OKAY") + return; + } + + PRINT_DEBUG ("SIZE OKAY") + + const CommResponse_recData* res = + reinterpret_cast (data); + + //Construct a std::vector from the recieved data array + uint16_t n = res->size(); + std::vector recData; + + for (uint16_t i = 0; i < n; ++i) + { + recData.push_back (res->recData(i)); + std::cout << "Data pushed: " << recData[i] << std::endl; + } + + PRINT_DEBUG ("VECTOR CONSTRUCTED") + + do_callback (new (&callbackObject_) + CommCB_recData (n, recData)); +} + +/************************************************************************/ + +void Comm::StartRecCB (const void* data, uint16_t size) +{ + if (size < sizeof (CommResponse_StartRec)) + return; + + do_callback (new (&callbackObject_) CommCB_StartRec); +} + +/************************************************************************/ + +void Comm::StopRecCB (const void* data, uint16_t size) +{ + if (size < sizeof (CommResponse_StopRec)) + return; + + do_callback (new (&callbackObject_) CommCB_StopRec); +} + +/************************************************************************/ +/************************************************************************/ void Comm::open (const char* serialNo) { @@ -739,8 +849,8 @@ void Comm::close (void) ftdi_->close(); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::transmitIdentify (void) { @@ -754,17 +864,23 @@ void Comm::transmitIdentify (void) qp4_->transmitter().free_packet (req); } -void Comm::transmitSync (void) +/************************************************************************/ + +void Comm::transmit_keepAlive (uint32_t lease_time_ms) { QP4_Packet* req = - qp4_->transmitter().alloc_packet (sizeof (CommRequest_Synchronize)); + qp4_->transmitter().alloc_packet ( + sizeof (CommRequest_keepAlive)); - new (req->body()) CommRequest_Synchronize; + new (req->body()) + CommRequest_keepAlive (lease_time_ms); req->seal(); transmit (req); + qp4_->transmitter().free_packet (req); } +/************************************************************************/ void Comm::transmitSourceMode (Comm_SourceMode mode) { @@ -780,7 +896,8 @@ void Comm::transmitSourceMode (Comm_SourceMode mode) qp4_->transmitter().free_packet (req); } -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::transmit_CS_setRange (Comm_CS_Range range) { @@ -866,7 +983,7 @@ void Comm::transmit_CS_setCurrent (float current) qp4_->transmitter().free_packet (req); } -/******************************************************************/ +/************************************************************************/ void Comm::transmit_VS_setRange (Comm_VS_Range range) { @@ -944,16 +1061,19 @@ void Comm::transmit_VS_setVoltage (float voltage) QP4_Packet* req = qp4_->transmitter().alloc_packet ( sizeof (CommRequest_VS_SetVoltage)); + //std::cout << "Comm : QP4_Packet allocated" << std::endl; new (req->body()) CommRequest_VS_SetVoltage (voltage); req->seal(); transmit (req); + //std::cout << "Comm : Packet Sealed and Transmitted" << std::endl; + qp4_->transmitter().free_packet (req); } -/******************************************************************/ +/************************************************************************/ void Comm::transmit_CM_setRange (Comm_CM_Range range) { @@ -1026,8 +1146,8 @@ void Comm::transmit_CM_read (uint16_t filterLength) qp4_->transmitter().free_packet (req); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::transmit_VM_setRange (Comm_VM_Range range) { @@ -1100,8 +1220,8 @@ void Comm::transmit_VM_read (uint16_t filterLength) qp4_->transmitter().free_packet (req); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::transmit_CS_loadDefaultCalibration (void) { @@ -1117,7 +1237,7 @@ void Comm::transmit_CS_loadDefaultCalibration (void) qp4_->transmitter().free_packet (req); } -/******************************************************************/ +/************************************************************************/ void Comm::transmit_VS_loadDefaultCalibration (void) { @@ -1133,7 +1253,7 @@ void Comm::transmit_VS_loadDefaultCalibration (void) qp4_->transmitter().free_packet (req); } -/******************************************************************/ +/************************************************************************/ void Comm::transmit_CM_loadDefaultCalibration (void) { @@ -1149,7 +1269,7 @@ void Comm::transmit_CM_loadDefaultCalibration (void) qp4_->transmitter().free_packet (req); } -/******************************************************************/ +/************************************************************************/ void Comm::transmit_VM_loadDefaultCalibration (void) { @@ -1165,8 +1285,8 @@ void Comm::transmit_VM_loadDefaultCalibration (void) qp4_->transmitter().free_packet (req); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::transmit_RM_readAutoscale (uint16_t filterLength) { @@ -1182,8 +1302,8 @@ void Comm::transmit_RM_readAutoscale (uint16_t filterLength) qp4_->transmitter().free_packet (req); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ +/************************************************************************/ void Comm::transmit_SystemConfig_Get (uint16_t paramID) { @@ -1237,7 +1357,7 @@ void Comm::transmit_SystemConfig_LoadDefault (void) qp4_->transmitter().free_packet (req); } -/******************************************************************/ +/************************************************************************/ void Comm::transmit_VM2_setRange (Comm_VM2_Range range) { @@ -1324,7 +1444,7 @@ void Comm::transmit_VM2_loadDefaultCalibration (void) qp4_->transmitter().free_packet (req); } -/******************************************************************/ +/************************************************************************/ void Comm::transmit_VM_setTerminal (Comm_VM_Terminal terminal) { @@ -1354,6 +1474,93 @@ void Comm::transmit_VM_getTerminal (void) qp4_->transmitter().free_packet (req); } -/******************************************************************/ -/******************************************************************/ +/************************************************************************/ + +void Comm::transmit_changeBaud (uint32_t baudRate) +{ + QP4_Packet* req = + qp4_->transmitter().alloc_packet ( + sizeof (CommRequest_changeBaud)); + + new (req->body()) + CommRequest_changeBaud (baudRate); + + req->seal(); + transmit (req); + + qp4_->transmitter().free_packet (req); +} + +/************************************************************************/ + +void Comm::transmit_recSize (void) +{ + QP4_Packet* req = + qp4_->transmitter().alloc_packet ( + sizeof (CommRequest_recSize)); + + new (req->body()) + CommRequest_recSize(); + + req->seal(); + transmit (req); + + qp4_->transmitter().free_packet (req); +} + +/************************************************************************/ + +void Comm::transmit_recData (uint16_t size) +/* + * Creates and transmits a CommRequest_recData packet, requesting for + * 'size' number of datapoints of recorded data to be transmitted + */ +{ + QP4_Packet* req = + qp4_->transmitter().alloc_packet ( + sizeof (CommRequest_recData)); + + new (req->body()) + CommRequest_recData (size); + + req->seal(); + transmit (req); + + qp4_->transmitter().free_packet (req); +} + +/************************************************************************/ + +void Comm::transmit_StartRec (void) +{ + QP4_Packet* req = + qp4_->transmitter().alloc_packet ( + sizeof (CommRequest_StartRec)); + + new (req->body()) + CommRequest_StartRec; + + req->seal(); + transmit (req); + qp4_->transmitter().free_packet (req); +} + +/************************************************************************/ + +void Comm::transmit_StopRec (void) +{ + QP4_Packet* req = + qp4_->transmitter().alloc_packet ( + sizeof (CommRequest_StopRec)); + + new (req->body()) + CommRequest_StopRec; + + req->seal(); + transmit (req); + qp4_->transmitter().free_packet (req); +} + +/************************************************************************/ +/************************************************************************/ } // namespace smu diff --git a/XSMU-2.4.0/code/app/src/Exception.cxx b/XSMU-2.4.0/code/app/src/Exception.cxx new file mode 100644 index 0000000..c5ed370 --- /dev/null +++ b/XSMU-2.4.0/code/app/src/Exception.cxx @@ -0,0 +1 @@ +#include "../app/Exception.h" \ No newline at end of file diff --git a/XSMU-2.4.0/code/app/src/Makefile b/XSMU-2.4.0/code/app/src/Makefile index cab2bbd..0e6df38 100644 --- a/XSMU-2.4.0/code/app/src/Makefile +++ b/XSMU-2.4.0/code/app/src/Makefile @@ -10,7 +10,8 @@ CPP_SRC = \ VM2.cxx \ virtuaSMU.cxx \ SystemConfig.cxx \ - version.cxx + version.cxx \ + Exception.cxx \ DEP = ${CPP_SRC:%.cxx=%.dep} OBJ = ${CPP_SRC:%.cxx=%.o} diff --git a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx index c46d307..6cd7cac 100644 --- a/XSMU-2.4.0/code/app/src/virtuaSMU.cxx +++ b/XSMU-2.4.0/code/app/src/virtuaSMU.cxx @@ -1,9 +1,14 @@ #include "../app/virtuaSMU.h" #include "../../sys/sys/Timer.h" +#include "../../app/app/Exception.h" +#include #include #include +#define PRINT_DEBUG(x) { \ +std::cerr << __PRETTY_FUNCTION__ << ":" << __LINE__ << ":" << x << std::endl; } + namespace smu { SourceMode toSourceMode (unsigned int i) @@ -35,6 +40,8 @@ std::vector Driver::scan (void) for (it = allDevices.begin(); it != allDevices.end(); ++it) if (std::string (it->description()) == "XPLORE SMU") device_list.push_back (*it); + else + std::cout << "Found: " << it->description() << std::endl; return device_list; } @@ -56,6 +63,8 @@ Driver::Driver (void) Driver::~Driver (void) { + close(); + delete comm_; delete vm_; delete cm_; @@ -80,7 +89,7 @@ void Driver::comm_cb (const CommCB* oCB) static const cb_t cbs[] = { &Driver::nopCB, &Driver::identityCB, - &Driver::syncCB, + &Driver::keepAliveCB, &Driver::setSourceModeCB, &Driver::CS_setRangeCB, @@ -130,21 +139,27 @@ void Driver::comm_cb (const CommCB* oCB) &Driver::VM_setTerminalCB, &Driver::VM_getTerminalCB, + + &Driver::changeBaudCB, + &Driver::recSizeCB, + &Driver::recDataCB, + &Driver::StartRecCB, + &Driver::StopRecCB, }; if (oCB->code() < sizeof (cbs) / sizeof (cbs[0])) (this->*cbs[oCB->code()]) (oCB); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::nopCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_NOP); } -/***************************************************************************/ +/************************************************************************/ void Driver::identityCB (const CommCB* oCB) { @@ -158,14 +173,14 @@ void Driver::identityCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_IDN); } -/***************************************************************************/ +/************************************************************************/ -void Driver::syncCB (const CommCB* oCB) +void Driver::keepAliveCB (const CommCB* oCB) { - ackBits_.set (COMM_CBCODE_SYNC); + ackBits_.set (COMM_CBCODE_KEEP_ALIVE); } -/***************************************************************************/ +/************************************************************************/ void Driver::setSourceModeCB (const CommCB* oCB) { @@ -187,8 +202,8 @@ void Driver::setSourceModeCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_SET_SOURCE_MODE); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::CS_setRangeCB (const CommCB* oCB) { @@ -199,7 +214,7 @@ void Driver::CS_setRangeCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_CS_SET_RANGE); } -/***************************************************************************/ +/************************************************************************/ void Driver::CS_getCalibrationCB (const CommCB* oCB) { @@ -210,7 +225,7 @@ void Driver::CS_getCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_CS_GET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::CS_verifyCalibrationCB (const CommCB* oCB) { @@ -221,7 +236,7 @@ void Driver::CS_verifyCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_CS_VERIFY_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::CS_setCalibrationCB (const CommCB* oCB) { @@ -232,14 +247,14 @@ void Driver::CS_setCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_CS_SET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::CS_saveCalibrationCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_CS_SAVE_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::CS_setCurrentCB (const CommCB* oCB) { @@ -250,8 +265,8 @@ void Driver::CS_setCurrentCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_CS_SET_CURRENT); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::VS_setRangeCB (const CommCB* oCB) { @@ -262,7 +277,7 @@ void Driver::VS_setRangeCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VS_SET_RANGE); } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_getCalibrationCB (const CommCB* oCB) { @@ -273,7 +288,7 @@ void Driver::VS_getCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VS_GET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_verifyCalibrationCB (const CommCB* oCB) { @@ -284,7 +299,7 @@ void Driver::VS_verifyCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VS_VERIFY_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_setCalibrationCB (const CommCB* oCB) { @@ -295,14 +310,14 @@ void Driver::VS_setCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VS_SET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_saveCalibrationCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_VS_SAVE_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_setVoltageCB (const CommCB* oCB) { @@ -311,10 +326,11 @@ void Driver::VS_setVoltageCB (const CommCB* oCB) vs_->setVoltage (o->voltage()); ackBits_.set (COMM_CBCODE_VS_SET_VOLTAGE); + } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::CM_setRangeCB (const CommCB* oCB) { @@ -325,7 +341,7 @@ void Driver::CM_setRangeCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_CM_SET_RANGE); } -/***************************************************************************/ +/************************************************************************/ void Driver::CM_getCalibrationCB (const CommCB* oCB) { @@ -336,7 +352,7 @@ void Driver::CM_getCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_CM_GET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::CM_setCalibrationCB (const CommCB* oCB) { @@ -347,14 +363,14 @@ void Driver::CM_setCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_CM_SET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::CM_saveCalibrationCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_CM_SAVE_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::CM_readCB (const CommCB* oCB) { @@ -365,19 +381,19 @@ void Driver::CM_readCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_CM_READ); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::VM_setRangeCB (const CommCB* oCB) { - const CommCB_VM_SetRange* o = - reinterpret_cast (oCB); + const CommCB_VM_GetCalibration* o = + reinterpret_cast (oCB); - vm_->setRange (toVM_Range (o->range())); - ackBits_.set (COMM_CBCODE_VM_SET_RANGE); + vm_->setCalibration (o->index(), o->adc(), o->voltage()); + ackBits_.set (COMM_CBCODE_VM_GET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_getCalibrationCB (const CommCB* oCB) { @@ -388,7 +404,7 @@ void Driver::VM_getCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VM_GET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_setCalibrationCB (const CommCB* oCB) { @@ -399,14 +415,14 @@ void Driver::VM_setCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VM_SET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_saveCalibrationCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_VM_SAVE_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_readCB (const CommCB* oCB) { @@ -417,37 +433,37 @@ void Driver::VM_readCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VM_READ); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::CS_loadDefaultCalibrationCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_CS_LOAD_DEFAULT_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_loadDefaultCalibrationCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_VS_LOAD_DEFAULT_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::CM_loadDefaultCalibrationCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_CM_LOAD_DEFAULT_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_loadDefaultCalibrationCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_VM_LOAD_DEFAULT_CALIBRATION); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::RM_readAutoscaleCB (const CommCB* oCB) { @@ -458,8 +474,8 @@ void Driver::RM_readAutoscaleCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_RM_READ_AUTOSCALE); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::SystemConfig_GetCB (const CommCB* oCB) { @@ -489,8 +505,8 @@ void Driver::SystemConfig_LoadDefaultCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_SYSTEM_CONFIG_LOAD_DEFAULT); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::VM2_setRangeCB (const CommCB* oCB) { @@ -501,7 +517,7 @@ void Driver::VM2_setRangeCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VM2_SET_RANGE); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM2_getCalibrationCB (const CommCB* oCB) { @@ -512,7 +528,7 @@ void Driver::VM2_getCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VM2_GET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM2_setCalibrationCB (const CommCB* oCB) { @@ -523,14 +539,14 @@ void Driver::VM2_setCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VM2_SET_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM2_saveCalibrationCB (const CommCB* oCB) { ackBits_.set (COMM_CBCODE_VM2_SAVE_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM2_readCB (const CommCB* oCB) { @@ -546,7 +562,7 @@ void Driver::VM2_loadDefaultCalibrationCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VM2_LOAD_DEFAULT_CALIBRATION); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_setTerminalCB (const CommCB* oCB) { @@ -567,11 +583,85 @@ void Driver::VM_getTerminalCB (const CommCB* oCB) ackBits_.set (COMM_CBCODE_VM_GET_TERMINAL); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ + +void Driver::changeBaudCB (const CommCB* oCB) +{ + const CommCB_changeBaud* o = + reinterpret_cast (oCB); + + baudRate_ = o->baudRate(); + + comm_->setBaudRate (baudRate_); + ackBits_.set (COMM_CBCODE_CHANGE_BAUD); +} + +/************************************************************************/ + +void Driver::recSizeCB (const CommCB* oCB) +{ + const CommCB_recSize* o = + reinterpret_cast (oCB); + + recSize_ = o->recSize(); + ackBits_.set (COMM_CBCODE_REC_SIZE); +} + +/************************************************************************/ + +void Driver::recDataCB (const CommCB* oCB) +{ + const CommCB_recData* o = + reinterpret_cast (oCB); + + uint16_t size = o->size(); //Size of data sent in this packet + PRINT_DEBUG ("***********recSize in CB : " << size) + std::vector data = o->recData(); //Data in this packet + + PRINT_DEBUG ("Trying to acquire dataq lock") + std::lock_guard lock(_dataq_lock); + + for (uint16_t i = 0; i < size; ++i) + { + _dataq_32.push (data[i]); + _dataq.push (applyCalibration (data[i])); + } + + PRINT_DEBUG ("Written to dataq") + + ackBits_.set (COMM_CBCODE_REC_DATA); +} + +/************************************************************************/ + +void Driver::StartRecCB (const CommCB* oCB) +{ + ackBits_.set (COMM_CBCODE_START_REC); + Timer timer; + _poll_stream_at = timer.get(); + _rec = true; + + /* + * Change Baud Rate of communication when streaming starts + */ + + // uint32_t baudRate = 9600; + // float timeout = 1; + // changeBaud (&baudRate, &timeout); +} + +void Driver::StopRecCB (const CommCB* oCB) +{ + ackBits_.set (COMM_CBCODE_STOP_REC); +} + +/************************************************************************/ +/************************************************************************/ void Driver::open (const char* serialNo, float* timeout) { + PRINT_DEBUG ("Opening Device") + std::cout << "libxsmu version: " << MAJOR_VERSION_NO (versionInfo_->libxsmu_version()) << "." << MINOR_VERSION_NO (versionInfo_->libxsmu_version()) << "." @@ -594,10 +684,33 @@ void Driver::open (const char* serialNo, float* timeout) << MINOR_VERSION_NO (versionInfo_->firmware_version()) << '.' << BUGFIX_VERSION_NO (versionInfo_->firmware_version()) << std::endl; + + _alive = true; + _rec = false; + _thread_future = std::async (std::launch::async, &Driver::thread, this); + PRINT_DEBUG ("Async thread launched") } void Driver::close (void) { + try { + PRINT_DEBUG ("Closing Device") + _alive = false; + if (_thread_future.valid()) + _thread_future.get(); + } + catch (...) + {} + + try + { + float timeout = 1; + uint32_t lease_time_ms = 0; + keepAlive (&lease_time_ms, &timeout); + } + catch (...) + {} + comm_->close(); } @@ -650,6 +763,8 @@ bool Driver::waitForResponse (uint16_t checkBit, float* timeout) if (elapsed > 100e-3) timer.sleep (10e-3); + if (ackBits_[COMM_CBCODE_NOP]) + throw NoOperation(); } while (!ackBits_[checkBit]); @@ -657,8 +772,8 @@ bool Driver::waitForResponse (uint16_t checkBit, float* timeout) return ackBits_[checkBit]; } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ bool Driver::goodID (void) const { @@ -669,26 +784,94 @@ void Driver::identify (float* timeout) { identity_.clear(); versionInfo_->clear(); - ackBits_.reset (COMM_CBCODE_IDN); + ackBits_.reset (COMM_CBCODE_IDN); comm_->transmitIdentify(); waitForResponse (COMM_CBCODE_IDN, timeout); } -/***************************************************************************/ +/************************************************************************/ + +void Driver::keepAlive (uint32_t* lease_time_ms, float* timeout) +{ + PRINT_DEBUG ("Trying to Acquire Lock") + auto unique_lock = comm_->lock(); + PRINT_DEBUG ("Lock Acquired") + + ackBits_.reset (COMM_CBCODE_KEEP_ALIVE); + comm_->transmit_keepAlive (*lease_time_ms); + + waitForResponse (COMM_CBCODE_KEEP_ALIVE, timeout); +} + +void Driver::thread (void) +{ + Timer timer; + + uint32_t lease_time_ms = 10000; + float timeout = 2; + + keepAlive (&lease_time_ms, &timeout); + double last_sent_at = timer.get(); + double elapsed = 0; + + while (_alive) + { + elapsed = timer.get() - last_sent_at; + if (elapsed > lease_time_ms/3000) + { + timeout = 1; + keepAlive (&lease_time_ms, &timeout); + last_sent_at = timer.get(); + } + + + if (_rec && timer.get() >= _poll_stream_at) + { + poll_stream(); + + _poll_stream_at = timer.get() + _poll_stream_interval; + } + + /******************************************************** + * Prevents 100% CPU utilization, + * in case the operation is taking longer than 100ms. + * *******************************************************/ + timer.sleep (10e-3); + } +} + +/************************************************************************/ -void Driver::sync (float* timeout) +void Driver::poll_stream (void) { - ackBits_.reset (COMM_CBCODE_SYNC); + uint16_t size; + + float timeout = 1; + recSize (&size, &timeout); + + PRINT_DEBUG ("*****************Size of data : " << size); + + if (size) do { + + uint16_t rx_size = size; + + float timeout = 10; + recData (&rx_size, &timeout); // Stores the data in _dataq_32 - comm_->transmitSync(); - waitForResponse (COMM_CBCODE_SYNC, timeout); + PRINT_DEBUG (">>>>>>>>>>>>>>>>>>Size of rx data : " << rx_size); + + size -= rx_size; + + } while (size); } -/***************************************************************************/ +/************************************************************************/ void Driver::setSourceMode (SourceMode* mode, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_SET_SOURCE_MODE); comm_->transmitSourceMode (toComm_SourceMode ((uint16_t)*mode)); if (waitForResponse (COMM_CBCODE_SET_SOURCE_MODE, timeout)) { @@ -701,20 +884,21 @@ void Driver::setSourceMode (SourceMode* mode, float* timeout) } } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::CS_setRange (CS_Range* range, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CS_SET_RANGE); comm_->transmit_CS_setRange (toComm_CS_Range (*range)); - comm_->transmit_CS_setRange (toComm_CS_Range (*range)); if (waitForResponse (COMM_CBCODE_CS_SET_RANGE, timeout)) *range = (cs_->range()); } -/***************************************************************************/ +/************************************************************************/ void Driver::CS_getCalibration (uint16_t* index, int16_t* dac, float* current, float* timeout) @@ -729,11 +913,13 @@ void Driver::CS_getCalibration (uint16_t* index, int16_t* dac, } } -/***************************************************************************/ +/************************************************************************/ void Driver::CS_verifyCalibration (uint16_t* index, int16_t* dac, float* current, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CS_VERIFY_CALIBRATION); comm_->transmit_CS_verifyCalibration (*index); @@ -744,11 +930,13 @@ void Driver::CS_verifyCalibration (uint16_t* index, int16_t* dac, } } -/***************************************************************************/ +/************************************************************************/ void Driver::CS_setCalibration (uint16_t* index, int16_t* dac, float* current, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CS_SET_CALIBRATION); comm_->transmit_CS_setCalibration (*index,* current); @@ -759,19 +947,23 @@ void Driver::CS_setCalibration (uint16_t* index, int16_t* dac, } } -/***************************************************************************/ +/************************************************************************/ void Driver::CS_saveCalibration (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CS_SAVE_CALIBRATION); comm_->transmit_CS_saveCalibration(); waitForResponse (COMM_CBCODE_CS_SAVE_CALIBRATION, timeout); } -/***************************************************************************/ +/************************************************************************/ void Driver::CS_setCurrent (float* current, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CS_SET_CURRENT); comm_->transmit_CS_setCurrent (*current); @@ -779,11 +971,13 @@ void Driver::CS_setCurrent (float* current, float* timeout) *current = cs_->current(); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::VS_setRange (VS_Range* range, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VS_SET_RANGE); comm_->transmit_VS_setRange (toComm_VS_Range (*range)); @@ -791,11 +985,13 @@ void Driver::VS_setRange (VS_Range* range, float* timeout) *range = (vs_->range()); } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_getCalibration (uint16_t* index, int16_t* dac, float* voltage, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VS_GET_CALIBRATION); comm_->transmit_VS_getCalibration (*index); @@ -806,11 +1002,13 @@ void Driver::VS_getCalibration (uint16_t* index, int16_t* dac, } } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_verifyCalibration (uint16_t* index, int16_t* dac, float* voltage, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VS_VERIFY_CALIBRATION); comm_->transmit_VS_verifyCalibration (*index); @@ -821,11 +1019,13 @@ void Driver::VS_verifyCalibration (uint16_t* index, int16_t* dac, } } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_setCalibration (uint16_t* index, int16_t* dac, float* voltage, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VS_SET_CALIBRATION); comm_->transmit_VS_setCalibration (*index,* voltage); @@ -836,19 +1036,23 @@ void Driver::VS_setCalibration (uint16_t* index, int16_t* dac, } } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_saveCalibration (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VS_SAVE_CALIBRATION); comm_->transmit_VS_saveCalibration(); waitForResponse (COMM_CBCODE_VS_SAVE_CALIBRATION, timeout); } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_setVoltage (float* voltage, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VS_SET_VOLTAGE); comm_->transmit_VS_setVoltage (*voltage); @@ -856,11 +1060,13 @@ void Driver::VS_setVoltage (float* voltage, float* timeout) *voltage = vs_->voltage(); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::CM_setRange (CM_Range* range, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CM_SET_RANGE); comm_->transmit_CM_setRange (toComm_CM_Range (*range)); @@ -868,11 +1074,13 @@ void Driver::CM_setRange (CM_Range* range, float* timeout) *range = (cm_->range()); } -/***************************************************************************/ +/************************************************************************/ void Driver::CM_getCalibration (uint16_t* index, int32_t* adc, float* current, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CM_GET_CALIBRATION); comm_->transmit_CM_getCalibration (*index); @@ -883,11 +1091,13 @@ void Driver::CM_getCalibration (uint16_t* index, int32_t* adc, } } -/***************************************************************************/ +/************************************************************************/ void Driver::CM_setCalibration (uint16_t* index, int32_t* adc, float* current, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CM_SET_CALIBRATION); comm_->transmit_CM_setCalibration (*index,* current); @@ -898,20 +1108,24 @@ void Driver::CM_setCalibration (uint16_t* index, int32_t* adc, } } -/***************************************************************************/ +/************************************************************************/ void Driver::CM_saveCalibration (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CM_SAVE_CALIBRATION); comm_->transmit_CM_saveCalibration(); waitForResponse (COMM_CBCODE_CM_SAVE_CALIBRATION, timeout); } -/***************************************************************************/ +/************************************************************************/ void Driver::CM_read (uint16_t* filterLength, float* current, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CM_READ); comm_->transmit_CM_read (*filterLength); if (waitForResponse (COMM_CBCODE_CM_READ, timeout)) { @@ -920,11 +1134,13 @@ void Driver::CM_read (uint16_t* filterLength, float* current, } } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::VM_setRange (VM_Range* range, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM_SET_RANGE); comm_->transmit_VM_setRange (toComm_VM_Range (*range)); @@ -932,11 +1148,13 @@ void Driver::VM_setRange (VM_Range* range, float* timeout) *range = (vm_->range()); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_getCalibration (uint16_t* index, int32_t* adc, float* voltage, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM_GET_CALIBRATION); comm_->transmit_VM_getCalibration (*index); @@ -947,11 +1165,13 @@ void Driver::VM_getCalibration (uint16_t* index, int32_t* adc, } } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_setCalibration (uint16_t* index, int32_t* adc, float* voltage, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM_SET_CALIBRATION); comm_->transmit_VM_setCalibration (*index,* voltage); @@ -962,20 +1182,24 @@ void Driver::VM_setCalibration (uint16_t* index, int32_t* adc, } } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_saveCalibration (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM_SAVE_CALIBRATION); comm_->transmit_VM_saveCalibration(); waitForResponse (COMM_CBCODE_VM_SAVE_CALIBRATION, timeout); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_read (uint16_t* filterLength, float* voltage, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM_READ); comm_->transmit_VM_read (*filterLength); if (waitForResponse (COMM_CBCODE_VM_READ, timeout)) { @@ -984,49 +1208,59 @@ void Driver::VM_read (uint16_t* filterLength, float* voltage, } } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::CS_loadDefaultCalibration (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CS_LOAD_DEFAULT_CALIBRATION); comm_->transmit_CS_loadDefaultCalibration(); waitForResponse (COMM_CBCODE_CS_LOAD_DEFAULT_CALIBRATION, timeout); } -/***************************************************************************/ +/************************************************************************/ void Driver::VS_loadDefaultCalibration (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VS_LOAD_DEFAULT_CALIBRATION); comm_->transmit_VS_loadDefaultCalibration(); waitForResponse (COMM_CBCODE_VS_LOAD_DEFAULT_CALIBRATION, timeout); } -/***************************************************************************/ +/************************************************************************/ void Driver::CM_loadDefaultCalibration (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_CM_LOAD_DEFAULT_CALIBRATION); comm_->transmit_CM_loadDefaultCalibration(); waitForResponse (COMM_CBCODE_CM_LOAD_DEFAULT_CALIBRATION, timeout); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_loadDefaultCalibration (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM_LOAD_DEFAULT_CALIBRATION); comm_->transmit_VM_loadDefaultCalibration(); waitForResponse (COMM_CBCODE_VM_LOAD_DEFAULT_CALIBRATION, timeout); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::RM_readAutoscale (uint16_t* filterLength, float* resistance,float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_RM_READ_AUTOSCALE); comm_->transmit_RM_readAutoscale (*filterLength); if (waitForResponse (COMM_CBCODE_RM_READ_AUTOSCALE, timeout)) { @@ -1034,11 +1268,13 @@ void Driver::RM_readAutoscale (uint16_t* filterLength, } } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::SystemConfig_Save (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_SYSTEM_CONFIG_SAVE); comm_->transmit_SystemConfig_Save(); waitForResponse (COMM_CBCODE_SYSTEM_CONFIG_SAVE, timeout); @@ -1046,6 +1282,8 @@ void Driver::SystemConfig_Save (float* timeout) void Driver::SystemConfig_LoadDefault (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_SYSTEM_CONFIG_LOAD_DEFAULT); comm_->transmit_SystemConfig_LoadDefault(); waitForResponse (COMM_CBCODE_SYSTEM_CONFIG_LOAD_DEFAULT, timeout); @@ -1054,6 +1292,8 @@ void Driver::SystemConfig_LoadDefault (float* timeout) void Driver:: SystemConfig_Get_hardwareVersion (uint32_t* version, float* timeout) { + auto unique_lock = comm_->lock(); + /**** Getting PCB information ****/ ackBits_.reset (COMM_CBCODE_SYSTEM_CONFIG_GET); comm_->transmit_SystemConfig_Get ( @@ -1088,6 +1328,8 @@ SystemConfig_Get_hardwareVersion (uint32_t* version, float* timeout) void Driver:: SystemConfig_Set_hardwareVersion (uint32_t* version, float* timeout) { + auto unique_lock = comm_->lock(); + /**** Setting PCB information ****/ ackBits_.reset (COMM_CBCODE_SYSTEM_CONFIG_SET); comm_->transmit_SystemConfig_Set ( @@ -1122,11 +1364,13 @@ SystemConfig_Set_hardwareVersion (uint32_t* version, float* timeout) sysconf_->hwBugfixNo()); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ void Driver::VM2_setRange (VM2_Range* range, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM2_SET_RANGE); comm_->transmit_VM2_setRange (toComm_VM2_Range (*range)); @@ -1134,11 +1378,13 @@ void Driver::VM2_setRange (VM2_Range* range, float* timeout) *range = (vm2_->range()); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM2_getCalibration (uint16_t* index, int32_t* adc, float* voltage, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM2_GET_CALIBRATION); comm_->transmit_VM2_getCalibration (*index); @@ -1149,11 +1395,13 @@ void Driver::VM2_getCalibration (uint16_t* index, int32_t* adc, } } -/***************************************************************************/ +/************************************************************************/ void Driver::VM2_setCalibration (uint16_t* index, int32_t* adc, float* voltage, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM2_SET_CALIBRATION); comm_->transmit_VM2_setCalibration (*index,* voltage); @@ -1164,20 +1412,24 @@ void Driver::VM2_setCalibration (uint16_t* index, int32_t* adc, } } -/***************************************************************************/ +/************************************************************************/ void Driver::VM2_saveCalibration (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM2_SAVE_CALIBRATION); comm_->transmit_VM2_saveCalibration(); waitForResponse (COMM_CBCODE_VM2_SAVE_CALIBRATION, timeout); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM2_read (uint16_t* filterLength, float* voltage, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM2_READ); comm_->transmit_VM2_read (*filterLength); @@ -1185,19 +1437,23 @@ void Driver::VM2_read (uint16_t* filterLength, float* voltage, *voltage = vm2_->voltage(); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM2_loadDefaultCalibration (float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM2_LOAD_DEFAULT_CALIBRATION); comm_->transmit_VM2_loadDefaultCalibration(); waitForResponse (COMM_CBCODE_VM2_LOAD_DEFAULT_CALIBRATION, timeout); } -/***************************************************************************/ +/************************************************************************/ void Driver::VM_setTerminal (VM_Terminal* terminal, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM_SET_TERMINAL); comm_->transmit_VM_setTerminal (toComm_VM_Terminal (*terminal)); @@ -1207,6 +1463,8 @@ void Driver::VM_setTerminal (VM_Terminal* terminal, float* timeout) void Driver::VM_getTerminal (VM_Terminal* terminal, float* timeout) { + auto unique_lock = comm_->lock(); + ackBits_.reset (COMM_CBCODE_VM_GET_TERMINAL); comm_->transmit_VM_getTerminal (); @@ -1214,6 +1472,154 @@ void Driver::VM_getTerminal (VM_Terminal* terminal, float* timeout) *terminal = (vm_->terminal()); } -/***************************************************************************/ -/***************************************************************************/ +/************************************************************************/ +/************************************************************************/ + +void Driver::changeBaud (uint32_t* baudRate, float* timeout) +/* + * Transmits a request for a change in the baudrate of communication + * channel; waits for acknowledgement of a change in baudrate in the + * firmware + */ +{ + auto unique_lock = comm_->lock(); + + ackBits_.reset (COMM_CBCODE_CHANGE_BAUD); + + comm_->transmit_changeBaud (*baudRate); + + if (waitForResponse (COMM_CBCODE_CHANGE_BAUD, timeout)) + *baudRate = baudRate_; +} + +/************************************************************************/ + +void Driver::recSize (uint16_t* recSize, float* timeout) +/* + * Transmits a request for the size of standby data queue stored in the + * SMU RAM, through the communication channel; and waits for a response + * within timeout duration. + */ +{ + auto unique_lock = comm_->lock(); + + ackBits_.reset (COMM_CBCODE_REC_SIZE); + + comm_->transmit_recSize(); + + if (waitForResponse (COMM_CBCODE_REC_SIZE, timeout)) + *recSize = recSize_; +} + +/************************************************************************/ + +void Driver::recData (uint16_t* size, float* timeout) +/* + * Transmits a request for data stored in the data queue in SMU RAM, + * through the communication channel; and waits for a response + * within timeout duration. + */ +{ + PRINT_DEBUG ("Trying to acquire lock") + auto unique_lock = comm_->lock(); + PRINT_DEBUG ("Lock Acquired") + + ackBits_.reset (COMM_CBCODE_REC_DATA); + + comm_->transmit_recData (*size); + PRINT_DEBUG ("Successfully transmitted, waiting for response") + + waitForResponse (COMM_CBCODE_REC_DATA, timeout); +} + +/************************************************************************/ + +std::vector Driver::getData (void) +/* + * Passes streamed data stored in the Driver to the Application layer. + * Data stored in the queue is cleared as it passed to the user. + * + * Output : std::vector + */ +{ + //std::vector data {1.0, 3.5, 5.1, 7.2}; + + std::vector data; + + std::lock_guard lock(_dataq_lock); + + while (!_dataq.empty()) + { + data.push_back(_dataq.front()); + _dataq.pop(); + _dataq_32.pop(); + } + + return data; +} + +/************************************************************************/ + +void Driver::StartRec (float *timeout) +/* + * Sets a flag to instruct the SMU to start streaming data, and the driver + * to start recording the streamed data. Then instructs the firmware to + * start streaming data from the ADC + */ +{ + auto unique_lock = comm_->lock(); + PRINT_DEBUG ("Lock Acquired") + + ackBits_.reset (COMM_CBCODE_START_REC); + + comm_->transmit_StartRec(); + PRINT_DEBUG ("Successfully transmitted, waiting for response") + + waitForResponse (COMM_CBCODE_START_REC, timeout); + PRINT_DEBUG ("Response Recieved") +} + +void Driver::StopRec (float *timeout) +/* + * Unsets a flag to instruct the SMU to stop streaming data, and the driver + * to stop recording. Then instructs the firmware to stop streaming data + * from the ADC + */ +{ + auto unique_lock = comm_->lock(); + PRINT_DEBUG ("Lock Acquired") + + ackBits_.reset (COMM_CBCODE_STOP_REC); + + comm_->transmit_StopRec(); + PRINT_DEBUG ("Successfully transmitted, waiting for response") + + waitForResponse (COMM_CBCODE_STOP_REC, timeout); + _rec = false; + PRINT_DEBUG ("Response Recieved") + + /* + * Restore Baud Rate of communication when streaming stops + */ + + // uint32_t baudRate = 9600; + // float time_out = 1; + // changeBaud (&baudRate, &time_out); +} + +/************************************************************************/ + +float Driver::applyCalibration (int32_t adc_value) +/* + * Applys the calibration (depending upon what physical quantity is being + * measured, and the range for the same; eg. current, 100uA range) to + * convert an ADC value into a voltage or current value + */ +{ + //TODO : How to apply calibration from a table? + return float (adc_value); +} + +/************************************************************************/ +/************************************************************************/ } diff --git a/XSMU-2.4.0/code/sys/src/FTDI.cxx b/XSMU-2.4.0/code/sys/src/FTDI.cxx index 6dc5c9a..76b1cb9 100644 --- a/XSMU-2.4.0/code/sys/src/FTDI.cxx +++ b/XSMU-2.4.0/code/sys/src/FTDI.cxx @@ -11,7 +11,7 @@ #endif namespace smu { - + /************************************************************************/ /************************************************************************/ @@ -239,6 +239,47 @@ bool FTDI::good (void) const return handle_; } +void FTDI::setBaudRate (uint32_t bd) +{ + switch (bd) + { + case 9600: + return _setBaudrate (9600); + + + case 19200: + return _setBaudrate (19200); + + + case 38400: + return _setBaudrate (38400); + + + case 57600: + return _setBaudrate (57600); + + + case 115200: + return _setBaudrate (115200); + } +} + +void FTDI::_setBaudrate (uint32_t baudrate) +{ + if (ftdi_set_baudrate (handle_, baudrate) != FTDI_OK) { + + close(); + return; + } + + if (ftdi_set_line_property2 (handle_, BITS_8, + STOP_BIT_1, NONE, BREAK_OFF) != FTDI_OK) { + + close(); + return; + } +} + /************************************************************************/ /************************************************************************/ diff --git a/XSMU-2.4.0/code/sys/sys/FTDI.h b/XSMU-2.4.0/code/sys/sys/FTDI.h index d1fcc75..3f60aca 100644 --- a/XSMU-2.4.0/code/sys/sys/FTDI.h +++ b/XSMU-2.4.0/code/sys/sys/FTDI.h @@ -1,4 +1,4 @@ -#ifndef __SMU_FTDI__ + #ifndef __SMU_FTDI__ #define __SMU_FTDI__ #include @@ -30,25 +30,33 @@ namespace smu { class FTDI { - public: +public: FTDI (void); - public: +public: static std::vector scan (void); - public: +public: void open (const char* serialNo); void open (const char* serialNo, int baudrate); uint32_t read (void* data, uint32_t size); uint32_t write (const void* data, uint32_t size); void close (void); - public: +public: bool good (void) const; - private: +private: ftdi_context* handle_; static std::vector scan (int vid, int pid); + +public: + void setBaudRate (uint32_t bd); + +private: + void _setBaudrate (uint32_t baudrate); + + }; } // end of namespace smu diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.cxx b/XSMU-2.4.0/wrapper/python/libxsmu.cxx index 9d886bc..3e29742 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.cxx +++ b/XSMU-2.4.0/wrapper/python/libxsmu.cxx @@ -50,7 +50,7 @@ int open_device(const char *serialNo, return it - virtuaSMUs.begin(); } -/********************************************************************/ +/************************************************************************/ void close_device(int deviceID) { @@ -58,8 +58,8 @@ void close_device(int deviceID) virtuaSMUs[deviceID] = 0; } -/********************************************************************/ -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void setSourceMode(int deviceID, int mode, float timeout, unsigned int *ret_mode, float *ret_timeout) @@ -81,8 +81,8 @@ void setSourceMode(int deviceID, int mode, float timeout, *ret_mode = (int) mode_; } -/********************************************************************/ -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void CS_setRange(int deviceID, int range, float timeout, unsigned int *ret_range, float *ret_timeout) @@ -101,7 +101,7 @@ void CS_setRange(int deviceID, int range, float timeout, *ret_range = range_; } -/********************************************************************/ +/************************************************************************/ void CS_getCalibration(int deviceID, unsigned int index, float timeout, unsigned int *ret_index, int *ret_dac, @@ -127,7 +127,7 @@ void CS_getCalibration(int deviceID, unsigned int index, float timeout, *ret_current = current_; } -/********************************************************************/ +/************************************************************************/ void CS_verifyCalibration(int deviceID, unsigned int index, float timeout, unsigned int *ret_index, int *ret_dac, @@ -153,7 +153,7 @@ void CS_verifyCalibration(int deviceID, unsigned int index, float timeout, *ret_current = current_; } -/********************************************************************/ +/************************************************************************/ void CS_setCalibration(int deviceID, unsigned int index, float current, float timeout, unsigned int *ret_index, int *ret_dac, @@ -179,7 +179,7 @@ void CS_setCalibration(int deviceID, unsigned int index, float current, *ret_current = current_; } -/********************************************************************/ +/************************************************************************/ void CS_saveCalibration(int deviceID, float timeout, float *ret_timeout) { @@ -188,7 +188,7 @@ void CS_saveCalibration(int deviceID, float timeout, float *ret_timeout) *ret_timeout = timeout; } -/********************************************************************/ +/************************************************************************/ void CS_setCurrent(int deviceID, float current, float timeout, float *ret_current, float *ret_timeout) @@ -216,8 +216,8 @@ void CS_loadDefaultCalibration(int deviceID, float timeout, *ret_timeout = timeout; } -/********************************************************************/ -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void VS_setRange(int deviceID, int range, float timeout, unsigned int *ret_range, float *ret_timeout) @@ -236,7 +236,7 @@ void VS_setRange(int deviceID, int range, float timeout, *ret_range = range_; } -/********************************************************************/ +/************************************************************************/ void VS_getCalibration(int deviceID, unsigned int index, float timeout, unsigned int *ret_index, int *ret_dac, @@ -262,7 +262,7 @@ void VS_getCalibration(int deviceID, unsigned int index, float timeout, *ret_voltage = voltage_; } -/********************************************************************/ +/************************************************************************/ void VS_verifyCalibration(int deviceID, unsigned int index, float timeout, unsigned int *ret_index, int *ret_dac, @@ -288,7 +288,7 @@ void VS_verifyCalibration(int deviceID, unsigned int index, float timeout, *ret_voltage = voltage_; } -/********************************************************************/ +/************************************************************************/ void VS_setCalibration(int deviceID, unsigned int index, float voltage, float timeout, unsigned int *ret_index, int *ret_dac, @@ -314,7 +314,7 @@ void VS_setCalibration(int deviceID, unsigned int index, float voltage, *ret_voltage = voltage_; } -/********************************************************************/ +/************************************************************************/ void VS_saveCalibration(int deviceID, float timeout, float *ret_timeout) { @@ -323,7 +323,7 @@ void VS_saveCalibration(int deviceID, float timeout, float *ret_timeout) *ret_timeout = timeout; } -/********************************************************************/ +/************************************************************************/ void VS_setVoltage(int deviceID, float voltage, float timeout, float *ret_voltage, float *ret_timeout) @@ -351,8 +351,8 @@ void VS_loadDefaultCalibration(int deviceID, float timeout, *ret_timeout = timeout; } -/********************************************************************/ -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void CM_setRange(int deviceID, int range, float timeout, unsigned int *ret_range, float *ret_timeout) @@ -371,7 +371,7 @@ void CM_setRange(int deviceID, int range, float timeout, *ret_range = range_; } -/********************************************************************/ +/************************************************************************/ void CM_getCalibration(int deviceID, unsigned int index, float timeout, unsigned int *ret_index, int *ret_adc, @@ -397,7 +397,7 @@ void CM_getCalibration(int deviceID, unsigned int index, float timeout, *ret_current = current_; } -/********************************************************************/ +/************************************************************************/ void CM_setCalibration(int deviceID, unsigned int index, float current, float timeout, unsigned int *ret_index, int *ret_adc, @@ -423,7 +423,7 @@ void CM_setCalibration(int deviceID, unsigned int index, float current, *ret_current = current_; } -/********************************************************************/ +/************************************************************************/ void CM_saveCalibration(int deviceID, float timeout, float *ret_timeout) { @@ -432,7 +432,7 @@ void CM_saveCalibration(int deviceID, float timeout, float *ret_timeout) *ret_timeout = timeout; } -/********************************************************************/ +/************************************************************************/ void CM_getReading(int deviceID, unsigned int filterLength, float timeout, float *ret_current, float *ret_timeout) @@ -461,8 +461,8 @@ void CM_loadDefaultCalibration(int deviceID, float timeout, *ret_timeout = timeout; } -/********************************************************************/ -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void VM_setRange(int deviceID, int range, float timeout, unsigned int *ret_range, float *ret_timeout) @@ -481,7 +481,7 @@ void VM_setRange(int deviceID, int range, float timeout, *ret_range = range_; } -/********************************************************************/ +/************************************************************************/ void VM_getCalibration(int deviceID, unsigned int index, float timeout,unsigned int *ret_index, @@ -507,7 +507,7 @@ void VM_getCalibration(int deviceID, unsigned int index, *ret_voltage = voltage_; } -/********************************************************************/ +/************************************************************************/ void VM_setCalibration(int deviceID, unsigned int index, float voltage, float timeout, unsigned int *ret_index, int *ret_adc, @@ -533,7 +533,7 @@ void VM_setCalibration(int deviceID, unsigned int index, float voltage, *ret_voltage = voltage_; } -/********************************************************************/ +/************************************************************************/ void VM_saveCalibration(int deviceID, float timeout, float *ret_timeout) { @@ -542,7 +542,7 @@ void VM_saveCalibration(int deviceID, float timeout, float *ret_timeout) *ret_timeout = timeout; } -/********************************************************************/ +/************************************************************************/ void VM_getReading(int deviceID, unsigned int filterLength, float timeout, float *ret_voltage, float *ret_timeout) @@ -563,6 +563,8 @@ void VM_getReading(int deviceID, unsigned int filterLength, float timeout, *ret_voltage = voltage_; } +/************************************************************************/ + void VM_loadDefaultCalibration(int deviceID, float timeout, float *ret_timeout) { @@ -571,8 +573,8 @@ void VM_loadDefaultCalibration(int deviceID, float timeout, *ret_timeout = timeout; } -/********************************************************************/ -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void RM_getReadingAutoscale (int deviceID, unsigned int filterLength, float timeout, float *ret_resistance, @@ -594,8 +596,8 @@ void RM_getReadingAutoscale (int deviceID, unsigned int filterLength, *ret_resistance = resistance_; } -/********************************************************************/ -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void SystemConfig_Save (int deviceID, float timeout, float* ret_timeout) { @@ -604,6 +606,8 @@ void SystemConfig_Save (int deviceID, float timeout, float* ret_timeout) *ret_timeout = timeout; } +/************************************************************************/ + void SystemConfig_LoadDefault (int deviceID, float timeout, float* ret_timeout) { VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; @@ -611,6 +615,8 @@ void SystemConfig_LoadDefault (int deviceID, float timeout, float* ret_timeout) *ret_timeout = timeout; } +/************************************************************************/ + void SystemConfig_Get_hardwareVersion (int deviceID, float timeout, unsigned int* ret_hardwareVersion, float* ret_timeout) { @@ -628,6 +634,8 @@ void SystemConfig_Get_hardwareVersion (int deviceID, *ret_hardwareVersion = hardwareVersion_; } +/************************************************************************/ + void SystemConfig_Set_hardwareVersion (int deviceID, unsigned int hardwareVersion, float timeout, unsigned int* ret_hardwareVersion, float* ret_timeout) @@ -646,8 +654,8 @@ void SystemConfig_Set_hardwareVersion (int deviceID, *ret_hardwareVersion = hardwareVersion_; } -/********************************************************************/ -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void library_version (int deviceID, unsigned int* version) { @@ -689,8 +697,8 @@ unsigned int bugfix_version_no (unsigned int version) return smu::BUGFIX_VERSION_NO (version); } -/********************************************************************/ -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void VM2_setRange(int deviceID, int range, float timeout, unsigned int *ret_range, float *ret_timeout) @@ -709,7 +717,7 @@ void VM2_setRange(int deviceID, int range, float timeout, *ret_range = range_; } -/********************************************************************/ +/************************************************************************/ void VM2_getCalibration(int deviceID, unsigned int index, float timeout, unsigned int *ret_index, @@ -735,7 +743,7 @@ void VM2_getCalibration(int deviceID, unsigned int index, *ret_voltage = voltage_; } -/********************************************************************/ +/************************************************************************/ void VM2_setCalibration(int deviceID, unsigned int index, float voltage, float timeout, unsigned int *ret_index, int *ret_adc, @@ -761,7 +769,7 @@ void VM2_setCalibration(int deviceID, unsigned int index, float voltage, *ret_voltage = voltage_; } -/********************************************************************/ +/************************************************************************/ void VM2_saveCalibration(int deviceID, float timeout, float *ret_timeout) { @@ -770,7 +778,7 @@ void VM2_saveCalibration(int deviceID, float timeout, float *ret_timeout) *ret_timeout = timeout; } -/********************************************************************/ +/************************************************************************/ void VM2_getReading(int deviceID, unsigned int filterLength, float timeout, float *ret_voltage, float *ret_timeout) @@ -791,6 +799,8 @@ void VM2_getReading(int deviceID, unsigned int filterLength, float timeout, *ret_voltage = voltage_; } +/************************************************************************/ + void VM2_loadDefaultCalibration(int deviceID, float timeout, float *ret_timeout) { @@ -799,7 +809,8 @@ void VM2_loadDefaultCalibration(int deviceID, float timeout, *ret_timeout = timeout; } -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ void VM_setTerminal(int deviceID, int terminal, float timeout, unsigned int *ret_terminal, float *ret_timeout) @@ -812,12 +823,14 @@ void VM_setTerminal(int deviceID, int terminal, float timeout, virtuaSMU->VM_setTerminal(&terminal_, &timeout_); *ret_terminal = 0; + if ((*ret_timeout = timeout_) == 0) return; *ret_terminal = terminal_; } +/************************************************************************/ void VM_getTerminal(int deviceID, float timeout, unsigned int *ret_terminal, float *ret_timeout) @@ -830,11 +843,125 @@ void VM_getTerminal(int deviceID, float timeout, virtuaSMU->VM_getTerminal(&terminal_, &timeout_); *ret_terminal = 0; + if ((*ret_timeout = timeout_) == 0) return; *ret_terminal = terminal_; } -/********************************************************************/ -/********************************************************************/ +/************************************************************************/ +/************************************************************************/ + +void changeBaud (int deviceID, unsigned int baudRate, float timeout, + unsigned int *ret_baudRate, float *ret_timeout) +{ + VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; + + unsigned int baudRate_ = baudRate; + float timeout_ = timeout; + + virtuaSMU->changeBaud (&baudRate_, &timeout_); + + *ret_baudRate = 9600; + + if ((*ret_timeout = timeout_) == 0) + return; + + *ret_baudRate = baudRate_; +} + +/************************************************************************/ + +std::vector getData (int deviceID) +{ + VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; + + std::vector data_ = virtuaSMU->getData(); + + return data_; +} + +/************************************************************************/ + +void StartRec (int deviceID, float timeout, + float *ret_timeout) +{ + VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; + + float timeout_ = timeout; + virtuaSMU->StartRec(&timeout_); + + *ret_timeout = timeout_; +} + +void StopRec (int deviceID, float timeout, + float *ret_timeout) +{ + VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; + + float timeout_ = timeout; + virtuaSMU->StopRec(&timeout_); + + *ret_timeout = timeout_; +} + +/************************************************************************/ +//Only for testing + +void keepAlive (int deviceID, unsigned int lease_time_ms, float timeout, + unsigned int *ret_lease_time_ms, float *ret_timeout) +{ + VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; + + unsigned int lease_time_ms_ = lease_time_ms; + float timeout_ = timeout; + + virtuaSMU->keepAlive (&lease_time_ms_, &timeout_); + + *ret_lease_time_ms = 0; + + if ((*ret_timeout = timeout_) == 0) + return; + + *ret_lease_time_ms = lease_time_ms_; +} + +void recSize (int deviceID, float timeout, + short unsigned int *ret_recSize, float *ret_timeout) +{ + VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; + + short unsigned int recSize_; + float timeout_ = timeout; + + virtuaSMU->recSize (&recSize_, &timeout_); + + *ret_recSize = 0; + + if ((*ret_timeout = timeout_) == 0) + return; + + *ret_recSize = recSize_; +} + +void recData (int deviceID, short unsigned int size, float timeout, + short unsigned int *ret_size, float *ret_timeout) +{ + VirtuaSMU *virtuaSMU = virtuaSMUs[deviceID]; + + short unsigned int size_ = size; + float timeout_ = timeout; + + virtuaSMU->recData (&size_, &timeout_); + + *ret_size = 0; + + if ((*ret_timeout = timeout_) == 0) + return; + + *ret_size = size_; +} + +/************************************************************************/ +/************************************************************************/ diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.h b/XSMU-2.4.0/wrapper/python/libxsmu.h index fbb41c3..3cabe7f 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.h +++ b/XSMU-2.4.0/wrapper/python/libxsmu.h @@ -1,23 +1,27 @@ #ifndef __XSMU__ #define __XSMU__ +#include + #ifdef __cplusplus extern "C" { #endif /** - * \brief Scans USB bus for XPLORE lock-in amplifier. + * \brief Scans USB bus for XPLORE Source-Meter Unit. * - * \return Number of XPLORE lock-in amplifier found. + * \return Number of XPLORE Source-Meter Unit found. * * This function must be called first. It creates an internal - * list of XPLORE lock-in amplifier hardware, whose details, + * list of XPLORE Source-Meter Unit hardware, whose details, * e.g. serial number etc., can then be accessed by other functions, * e.g. \ref serialNo. * */ int scan(void); +/************************************************************************/ + /** * \brief Returns the serial number of a previously scanned device. * @@ -35,7 +39,7 @@ int scan(void); */ const char *serialNo(int i); -/**************************************************************/ +/************************************************************************/ /** * \brief Opens a previously scanned device for communication, @@ -60,6 +64,8 @@ int open_device(const char *serialNo, float timeout, unsigned int *ret_goodID, float *ret_timeout); +/************************************************************************/ + /** * \brief Closes a previously opened device. * @@ -67,14 +73,14 @@ int open_device(const char *serialNo, */ void close_device(int deviceID); -/**************************************************************/ +/************************************************************************/ void setSourceMode(int deviceID, int mode, float timeout, unsigned int *ret_mode, float *ret_timeout); -/**************************************************************/ +/************************************************************************/ void CS_setRange(int deviceID, int range, float timeout, unsigned int *ret_range, float *ret_timeout); @@ -102,7 +108,7 @@ void CS_setCurrent(int deviceID, float current, float timeout, void CS_loadDefaultCalibration (int deviceID, float timeout, float *ret_timeout); -/**************************************************************/ +/************************************************************************/ void VS_setRange(int deviceID, int range, float timeout, unsigned int *ret_range, float *ret_timeout); @@ -130,7 +136,7 @@ void VS_setVoltage(int deviceID, float voltage, float timeout, void VS_loadDefaultCalibration (int deviceID, float timeout, float *ret_timeout); -/**************************************************************/ +/************************************************************************/ void CM_setRange(int deviceID, int range, float timeout, unsigned int *ret_range, float *ret_timeout); @@ -154,7 +160,7 @@ void CM_getReading(int deviceID, unsigned int filterLength, void CM_loadDefaultCalibration (int deviceID, float timeout, float *ret_timeout); -/**************************************************************/ +/************************************************************************/ void VM_setRange(int deviceID, int range, float timeout, unsigned int *ret_range, float *ret_timeout); @@ -178,13 +184,13 @@ void VM_getReading(int deviceID, unsigned int filterLength, void VM_loadDefaultCalibration (int deviceID, float timeout, float *ret_timeout); -/**************************************************************/ +/************************************************************************/ void RM_getReadingAutoscale (int deviceID, unsigned int filterLength, float timeout, float *ret_resistance, float *ret_timeout); -/**************************************************************/ +/************************************************************************/ void SystemConfig_Save (int deviceID, float timeout, @@ -201,7 +207,7 @@ void SystemConfig_Set_hardwareVersion (int deviceID, unsigned int hardwareVersion, float timeout, unsigned int* ret_hardwareVersion, float* ret_timeout); -/**************************************************************/ +/************************************************************************/ void library_version (int deviceID, unsigned int* version); void hardware_version (int deviceID, unsigned int* version); @@ -214,7 +220,7 @@ unsigned int major_version_no (unsigned int version); unsigned int minor_version_no (unsigned int version); unsigned int bugfix_version_no (unsigned int version); -/**************************************************************/ +/************************************************************************/ void VM2_setRange(int deviceID, int range, float timeout, unsigned int *ret_range, float *ret_timeout); @@ -244,8 +250,90 @@ void VM_setTerminal(int deviceID, int terminal, float timeout, void VM_getTerminal(int deviceID, float timeout, unsigned int *ret_terminal, float *ret_timeout); -/**************************************************************/ +/************************************************************************/ +/** + * \brief Changes the Baud Rate of communication between the computer and the SMU. + * + * \return Current Baud Rate of communcation if a valid Baud Rate was provided. + * Otherwise, a NoOperation() exception is thrown. + * + */ + +void changeBaud (int deviceID, unsigned int baudRate, float timeout, + unsigned int *ret_baudRate, float *ret_timeout); + +/************************************************************************/ +/** + * \brief Gets data streamed from the SMU. + * + * \return C++ Vector containing streamed data from the SMU as float type + * + * This function will only return non-zero data when the \ref startRec function has been called, that starts streaming data from the SMU. + * + */ + +std::vector getData (int deviceID); + +/************************************************************************/ +/** + * \brief Starts recording streamed data from the SMU + * + * \return None + * + * This function sets a flag in the driver, to start recording streamed data from the SMU. + */ + +void StartRec (int deviceID, float timeout, + float *ret_timeout); + +/************************************************************************/ +/** + * \brief Stops recording streamed data from the SMU + * + * \return None + * + * This function unsets a flag in the driver, to stop recording streamed data from the SMU. + */ + +void StopRec (int deviceID, float timeout, + float *ret_timeout); + +/************************************************************************/ +/** + * \brief Sends a KEEP_ALIVE packet to the SMU, asking the SMU to communcate as usual + * for the next \ref lease_time_ms milliseconds + * + * \return The duration for which the SMU has been asked to keep alive. + * + */ + +void keepAlive (int deviceID, unsigned int lease_time_ms, float timeout, + unsigned int *ret_lease_time_ms, float *ret_timeout); + +/************************************************************************/ +/** + * \brief Queries the number of datapoints in the standby data queue in the SMU + * + * \return Number of datapoints in the standby data queue in the SMU + * + */ + +void recSize (int deviceID, float timeout, + short unsigned int *ret_recSize, float *ret_timeout); + +/************************************************************************/ +/** + * \brief Queries the data in the standby data queue in the SMU + * + * \return Number of datapoints being transmitted by the SMU + * + */ + +void recData (int deviceID, short unsigned int size, float timeout, + short unsigned int *ret_size, float *ret_timeout); +/************************************************************************/ +/************************************************************************/ #ifdef __cplusplus } // extern "C" diff --git a/XSMU-2.4.0/wrapper/python/libxsmu.i b/XSMU-2.4.0/wrapper/python/libxsmu.i index d6365ed..3d849af 100644 --- a/XSMU-2.4.0/wrapper/python/libxsmu.i +++ b/XSMU-2.4.0/wrapper/python/libxsmu.i @@ -1,9 +1,16 @@ %module libxsmu %include "typemaps.i" +%include "std_vector.i" +%include "stdint.i" %{ #include "libxsmu.h" %} +namespace std +{ + %template(FloatVector) vector; +} + %{ extern int scan(void); @@ -205,9 +212,31 @@ extern void VM_getTerminal(int deviceID, /**************************************************************/ -%} +extern void changeBaud (int deviceID, unsigned int baudRate, float timeout, + unsigned int *ret_baudRate, float *ret_timeout); + +extern void keepAlive (int deviceID, unsigned int lease_time_ms, + float timeout, unsigned int *ret_lease_time_ms, + float *ret_timeout); + +extern std::vector getData (int deviceID); + +extern void StartRec (int deviceID, float timeout, + float *ret_timeout); + +extern void StopRec (int deviceID, float timeout, + float *ret_timeout); + +extern void recSize (int deviceID, float timeout, + short unsigned int *ret_recSize, float *ret_timeout); + +extern void recData (int deviceID, short unsigned int size, float timeout, + short unsigned int *ret_size, float *ret_timeout); /**************************************************************/ + +%} + /**************************************************************/ /**************************************************************/ @@ -380,5 +409,26 @@ extern void VM_getTerminal(int deviceID, float timeout, unsigned int *OUTPUT, float *OUTPUT); /**************************************************************/ -/**************************************************************/ +extern void changeBaud (int deviceID, unsigned int baudRate, float timeout, + unsigned int *OUTPUT, float *OUTPUT); + +extern void keepAlive (int deviceID, unsigned int lease_time_ms, float timeout, + unsigned int *OUTPUT, float *OUTPUT); + +extern std::vector getData (int deviceID); + +extern void StartRec (int deviceID, float timeout, + float *OUTPUT); + +extern void StopRec (int deviceID, float timeout, + float *OUTPUT); + +extern void recSize (int deviceID, float timeout, + short unsigned int *OUTPUT, float *OUTPUT); + +extern void recData (int deviceID, short unsigned int size, float timeout, + short unsigned int *OUTPUT, float *OUTPUT); + +/**************************************************************/ +/**************************************************************/ \ No newline at end of file diff --git a/XSMU-2.4.0/wrapper/python/test/VM_getReading.py b/XSMU-2.4.0/wrapper/python/test/VM_getReading.py index a68b2dd..1ae1419 100644 --- a/XSMU-2.4.0/wrapper/python/test/VM_getReading.py +++ b/XSMU-2.4.0/wrapper/python/test/VM_getReading.py @@ -34,7 +34,7 @@ logfile = open ('log.txt', 'w') -for n in range (0, 200): +for n in range (0, 100): filter_length = 32 timeout = 1 + 0.03 * filter_length voltage, timeout = libxsmu.VM_getReading (deviceID, filter_length, timeout) @@ -44,10 +44,10 @@ logfile.write (str (voltage) + '\n') logfile.flush() - # sleep (1) + #sleep (1) if (timeout == 0.0): - print 'Communication timeout in CM_getReading.' + print 'Communication timeout in VM_getReading.' exit (-2) ########################################################################## diff --git a/XSMU-2.4.0/wrapper/python/test/VS_setVoltage.py b/XSMU-2.4.0/wrapper/python/test/VS_setVoltage.py index fadca4c..c89218f 100644 --- a/XSMU-2.4.0/wrapper/python/test/VS_setVoltage.py +++ b/XSMU-2.4.0/wrapper/python/test/VS_setVoltage.py @@ -31,7 +31,7 @@ ########################################################################## # Set voltage source calibration table (for range selected above.) -timeout = 1.0 +timeout = 5.0 voltage = float(sys.argv[1]) #-10.0 voltage, timeout = libxsmu.VS_setVoltage (deviceID, voltage, timeout) print \ diff --git a/XSMU-2.4.0/wrapper/python/test/changeBaud.py b/XSMU-2.4.0/wrapper/python/test/changeBaud.py new file mode 100644 index 0000000..d58e5c2 --- /dev/null +++ b/XSMU-2.4.0/wrapper/python/test/changeBaud.py @@ -0,0 +1,50 @@ +import libxsmu, time, math, sys +from time import sleep + +########################################################################## +# Scans USB bus for Xplore SMU. + +N = libxsmu.scan() +print "Total device:", N + +if N == 0: + print 'No Xplore SMU device found.' + exit (-1) + +########################################################################## +# Queries serial number of the first device. +# This should be sufficient if only a single device is present. + +serialNo = libxsmu.serialNo(0) +print "Seial number:", serialNo + +timeout = 1.0 +deviceID, goodID, timeout = libxsmu.open_device (serialNo, timeout) +print \ + "Device ID :", deviceID, "\n" \ + "goodID :", goodID, "\n" \ + "Remaining time:", timeout, "sec", "\n" + +if (timeout == 0.0) or (not goodID): + print 'Communication timeout in open_device.' + exit (-2) + +########################################################################## +# Set Baud Rate of communication + +timeout = 5.0 +baudRate = 9600 + +baudRate, timeout = libxsmu.changeBaud (deviceID, baudRate, timeout) +print \ + "Baud Rate: ", baudRate, "\n" \ + "Timeout: ", timeout + +if (timeout == 0.0): + print 'Communication timeout in changeBaud' + exit (-2) + +########################################################################## +# closes the device. + +libxsmu.close_device(deviceID) diff --git a/XSMU-2.4.0/wrapper/python/test/getData.py b/XSMU-2.4.0/wrapper/python/test/getData.py new file mode 100644 index 0000000..df6c812 --- /dev/null +++ b/XSMU-2.4.0/wrapper/python/test/getData.py @@ -0,0 +1,71 @@ +import libxsmu, time, math, sys +from time import sleep + +########################################################################## +# Scans USB bus for Xplore SMU. + +N = libxsmu.scan() +print "Total device:", N + +if N == 0: + print 'No Xplore SMU device found.' + exit (-1) + +########################################################################## +# Queries serial number of the first device. +# This should be sufficient if only a single device is present. + +serialNo = libxsmu.serialNo(0) +print "Seial number:", serialNo + +timeout = 1.0 +deviceID, goodID, timeout = libxsmu.open_device (serialNo, timeout) +print \ + "Device ID :", deviceID, "\n" \ + "goodID :", goodID, "\n" \ + "Remaining time:", timeout, "sec", "\n" + +if (timeout == 0.0) or (not goodID): + print 'Communication timeout in open_device.' + exit (-2) + +########################################################################## +# Start recording streamed data from the XSMU + +timeout = 5 +timeout = libxsmu.StartRec (deviceID, timeout) +print \ + "Started Recording Streamed Data" + +sleep (5) + +########################################################################## +# Get streamed data from data queue + +print \ + "Getting Data" + +logfile = open ('log.txt', 'w') + +t0 = time.time() +_time_ = 0 +while (time.time() - t0 < 60*60): + print "Remaining time: ", 60 - (time.time() - t0) / 60.0, " minutes" + timeout = 5.0 + recSize, timeout = libxsmu.recSize (deviceID, timeout) + data = libxsmu.getData (deviceID) + for voltage in data: + logfile.write (str (_time_) + ", " + str (voltage) + '\n') + print _time_, ',\t', voltage * 1e9, ' ADC' + logfile.flush() + _time_ = _time_ + 0.1 + time.sleep (10) + +timeout = 5 +timeout = libxsmu.StopRec (deviceID, timeout) +print \ + "Stopped Recording Streamed Data" +########################################################################## +# closes the device. + +libxsmu.close_device(deviceID) diff --git a/XSMU-2.4.0/wrapper/python/test/keepAlive.py b/XSMU-2.4.0/wrapper/python/test/keepAlive.py new file mode 100644 index 0000000..cd35b41 --- /dev/null +++ b/XSMU-2.4.0/wrapper/python/test/keepAlive.py @@ -0,0 +1,51 @@ +import libxsmu, time, math, sys +from time import sleep + +########################################################################## +# Scans USB bus for Xplore SMU. + +N = libxsmu.scan() +print "Total device:", N + +if N == 0: + print 'No Xplore SMU device found.' + exit (-1) + +########################################################################## +# Queries serial number of the first device. +# This should be sufficient if only a single device is present. + +serialNo = libxsmu.serialNo(0) +print "Seial number:", serialNo + +timeout = 1.0 +deviceID, goodID, timeout = libxsmu.open_device (serialNo, timeout) +print \ + "Device ID :", deviceID, "\n" \ + "goodID :", goodID, "\n" \ + "Remaining time:", timeout, "sec", "\n" + +if (timeout == 0.0) or (not goodID): + print 'Communication timeout in open_device.' + exit (-2) + +########################################################################## +# Sends Keep_Alive Packet to device +for index in range (3): + timeout = 5.0 + lease_time_ms = 10000 + + lease_time_ms, timeout = libxsmu.keepAlive (deviceID, lease_time_ms, timeout) + print \ + "Lease Time: ", lease_time_ms, "\n" \ + "Timeout: ", timeout + + if (timeout == 0.0): + print 'Communication timeout in keepAlive' + exit (-2) + sleep (5) + +########################################################################## +# closes the device. + +libxsmu.close_device(deviceID) diff --git a/XSMU-2.4.0/wrapper/python/test/log.txt b/XSMU-2.4.0/wrapper/python/test/log.txt new file mode 100644 index 0000000..e69de29 diff --git a/XSMU-2.4.0/wrapper/python/test/recData.py b/XSMU-2.4.0/wrapper/python/test/recData.py new file mode 100644 index 0000000..562b451 --- /dev/null +++ b/XSMU-2.4.0/wrapper/python/test/recData.py @@ -0,0 +1,52 @@ +import libxsmu, time, math, sys +from time import sleep + +########################################################################## +# Scans USB bus for Xplore SMU. + +N = libxsmu.scan() +print "Total device:", N + +if N == 0: + print 'No Xplore SMU device found.' + exit (-1) + +########################################################################## +# Queries serial number of the first device. +# This should be sufficient if only a single device is present. + +serialNo = libxsmu.serialNo(0) +print "Seial number:", serialNo + +timeout = 1.0 +deviceID, goodID, timeout = libxsmu.open_device (serialNo, timeout) +print \ + "Device ID :", deviceID, "\n" \ + "goodID :", goodID, "\n" \ + "Remaining time:", timeout, "sec", "\n" + +if (timeout == 0.0) or (not goodID): + print 'Communication timeout in open_device.' + exit (-2) + +sleep (5) + +########################################################################## +# Queries the data stored in standby data queue in SMU + +timeout = 10.0 +size = 3 + +recSize, timeout = libxsmu.recData (deviceID, size, timeout) +print \ + "recSize: ", recSize, "\n" \ + "Timeout: ", timeout + +if (timeout == 0.0): + print 'Communication timeout in recData' + exit (-2) + +########################################################################## +# closes the device. + +libxsmu.close_device(deviceID) diff --git a/XSMU-2.4.0/wrapper/python/test/recSize.py b/XSMU-2.4.0/wrapper/python/test/recSize.py new file mode 100644 index 0000000..2a697ca --- /dev/null +++ b/XSMU-2.4.0/wrapper/python/test/recSize.py @@ -0,0 +1,51 @@ +import libxsmu, time, math, sys +from time import sleep + +########################################################################## +# Scans USB bus for Xplore SMU. + +N = libxsmu.scan() +print "Total device:", N + +if N == 0: + print 'No Xplore SMU device found.' + exit (-1) + +########################################################################## +# Queries serial number of the first device. +# This should be sufficient if only a single device is present. + +serialNo = libxsmu.serialNo(0) +print "Seial number:", serialNo + +timeout = 1.0 +deviceID, goodID, timeout = libxsmu.open_device (serialNo, timeout) +print \ + "Device ID :", deviceID, "\n" \ + "goodID :", goodID, "\n" \ + "Remaining time:", timeout, "sec", "\n" + +if (timeout == 0.0) or (not goodID): + print 'Communication timeout in open_device.' + exit (-2) + +sleep (5) + +########################################################################## +# Queries the number of datapoints stored in standby data queue in SMU + +timeout = 5.0 + +recSize, timeout = libxsmu.recSize (deviceID, timeout) +print \ + "recSize: ", recSize, "\n" \ + "Timeout: ", timeout + +if (timeout == 0.0): + print 'Communication timeout in recSize' + exit (-2) + +########################################################################## +# closes the device. + +libxsmu.close_device(deviceID) diff --git a/XSMU-2.4.0/wrapper/python/test/startRec.py b/XSMU-2.4.0/wrapper/python/test/startRec.py new file mode 100644 index 0000000..b6890a5 --- /dev/null +++ b/XSMU-2.4.0/wrapper/python/test/startRec.py @@ -0,0 +1,55 @@ +import libxsmu, time, math, sys +from time import sleep + +########################################################################## +# Scans USB bus for Xplore SMU. + +N = libxsmu.scan() +print "Total device:", N + +if N == 0: + print 'No Xplore SMU device found.' + exit (-1) + +########################################################################## +# Queries serial number of the first device. +# This should be sufficient if only a single device is present. + +serialNo = libxsmu.serialNo(0) +print "Seial number:", serialNo + +timeout = 1.0 +deviceID, goodID, timeout = libxsmu.open_device (serialNo, timeout) +print \ + "Device ID :", deviceID, "\n" \ + "goodID :", goodID, "\n" \ + "Remaining time:", timeout, "sec", "\n" + +if (timeout == 0.0) or (not goodID): + print 'Communication timeout in open_device.' + exit (-2) + +sleep (5) + +########################################################################## +# Start recording streamed data from the SMU + +timeout = 5.0 +print \ + "Starting Recording Streamed Data" +timeout = libxsmu.StartRec (deviceID, timeout) +print \ + "Started Recording Streamed Data" + +sleep(20) + +timeout = 5.0 +timeout = libxsmu.StopRec (deviceID, timeout) +print \ + "Stopped Recording Streamed Data" + +########################################################################## +# closes the device. + +sleep(5) +libxsmu.close_device(deviceID) diff --git a/XSMU-2.4.0/wrapper/python/test/version.py b/XSMU-2.4.0/wrapper/python/test/version.py index 1ce8eb3..1c919f3 100644 --- a/XSMU-2.4.0/wrapper/python/test/version.py +++ b/XSMU-2.4.0/wrapper/python/test/version.py @@ -1,4 +1,5 @@ import libxsmu, time, math +from time import sleep ########################################################################## # Scans USB bus for Xplore SMU. @@ -37,5 +38,5 @@ ########################################################################## # closes the device. - +sleep(100) libxsmu.close_device(deviceID) diff --git a/changeBaudTesting.md b/changeBaudTesting.md new file mode 100644 index 0000000..95fe519 --- /dev/null +++ b/changeBaudTesting.md @@ -0,0 +1,2048 @@ +# ``XPLORE Streamer`` + +### Feature + +Version : 2.4.0 +================ + + Nature : Feature + Requested by : Quazar Research + + Status : Pending + Created on : 2017-09-09 by KC + Closed on : --- + +Description +----------- + +The SMU is to stream voltmeter data at a specified frequency. This requires following features to be implemented. + + 1) Dynamically change baudrate to suit data stream. + + -- CHANGE_BAUD + + 2) Start recording + + -- START_REC : Starts recording of timed data into internal buffer. + + 3) Transfer recorded data chunks to computer + + -- REC_SIZE : Queries number of available data points in buffer + + -- REC_DATA : Transfers requested number of data points to driver. + + 5) Stop recording + + -- STOP_REC : Stops recording gracefully. + + -- KEEP_ALIVE : Stops recording if keep alive packets are not received, i.e. driver is dead. + +### Modifications + +##### Firmware +-------------- + +* Comm.h/Comm.cxx: + + ^^ COMM_OPCODE + ++ COMM_OPCODE_CHANGE_BAUD + + ++ class CommPacket_ChangeBaud + ++ class CommRequest_ChangeBaud + ++ class CommResponse_ChangeBaud + + ^^ COMM_CBCODE + ++ COMM_CBCODE_CHANGE_BAUD + + ++ class CommCB_ChangeBaud + + ^^ union CommCB_Union + ++ char gen4 [sizeof (CommCB_ChangeBaud)] + + ^^ class Comm : public Applet + ++ void changeBaud_CB (void*, uint16_t) + ++ void transmit_changeBaud (uint16_t) +-------------- + +##### Software +-------------- + +* virtuaSMU.h/virtuaSMU.cxx: + + ^^ class Driver + ++ uint32_t baudRate_ + ++ void changeBaud (uint32_t*, float*); + ++ void changeBaudCB (CommCB*); +-------------- + +* libxsmu.h/libxsmu.cxx/libxsmu.i: + + ++ void changeBaud (int, unsigned int, float, + unsigned int*, float*); + +-------------- + +* Comm.h/Comm.cxx: + + ^^ COMM_OPCODE + ++ COMM_OPCODE_CHANGE_BAUD + + ++ class CommPacket_ChangeBaud + ++ class CommRequest_ChangeBaud + ++ class CommResponse_ChangeBaud + + ^^ COMM_CBCODE + ++ COMM_CBCODE_CHANGE_BAUD + + ++ class CommCB_ChangeBaud + + ^^ union CommCB_Union + ++ char gen4 [sizeof (CommCB_ChangeBaud)] + + ^^ class Comm : public Applet + ++ void changeBaud_CB (void*, uint16_t) + ++ void transmit_changeBaud (uint32_t) + +-------------- + +++ changeBaud.py + +### Test-1 + +- Burn modified Firmware onto the SMU microcontroller (Follow : `XPLORE-firmware` README ) +- Install modified software on computer (Follow : `XPLORE-software` README) + +- Testing `changeBaud(baudRate)` function + - Testing : Communication Channel + - Navigate to `XPLORE-software/XSMU-2.4.0/wrapper/python/tests/` + - Run `python changeBaud.py` + - Expected Result : Control should return back to python within specified timeout (1 second) + +##### Result : Failed + +- Output : Communication Timeout in changeBaud + +--- + +##### Debugging + +- Add print statements to XPLORE-software part and use LCD to print from the XPLORE-firmware part + +^^ virtuaSMU.cxx + ^^ void Driver::changeBaudCB (const CommCB*) + ++ std::cout << "virtuaSMU : Entering changeBaudCB" << std::endl; + ++ std::cout << "virtuaSMU : Retrieved baudRate" << std::endl; + ++ std::cout << "virtuaSMU : AckBits Set" << std::endl; + + ^^ void Driver::changeBaud (uint32_t*, float*) + ++ std::cout << "virtuaSMU : AckBits Reset" << std::endl; + ++ std::cout << "virtuaSMU : Transmitted baudRate, Starting wait for response" << std::endl; + ++ std::cout << "virtuaSMU : Recieved Response" << std::endl; + +^^ Comm.cxx + ^^ void Comm::changeBaudCB (const void* data, uint16_t size) + ++ std::cout << "Comm : Packet Size Smaller than Expected" << std::endl; + ++ std::cout << "Comm : Packet Size Okay" << std::endl; + ++ std::cout << "Comm : Callback Completed" << std::endl; + + ^^ void Comm::transmit_changeBaud (uint32_t baudRate) + ++ std::cout << "Comm : QP4_Packet allocated" << std::endl; + ++ std::cout << "Comm : Packet Sealed and Transmitted" << std::endl; + + ^^ checkRecieveQueue() + ++ std::cout << "Comm : Recieved Data Size : " << rxsize << std::endl; + +- Looked at XPLORE-firmware Changelog, and realised that I haven't written functions to interface the firmware's (XPLORE-firmware) Comm.cxx to the driver (XPLORE-software). Adding the required functions in XPLORE-firmware, and updating its Changelog. + +- Also changing `timeout` to 5 seconds in `XPLORE-software/wrapper/python/test/changeBaud.py` + +- Redoing **Test-1** with the above mentioned modifications. + +##### Result : Communication Timeout + +- Output : Communication Timeout in changeBaud + +--- + +- Adding print statements increased the execution time, and the default timeout of 1 second is not sufficient. Retrying with the all print statements commited out. + +##### Result : Communication Timeout + +- Output : Communication Timeout in changeBaud + +--- + +- Added LCD print statements to firmware (Application.cxx) inside Application::changeBaudCB() function + + ``` + freezeLocalDisplay(); + lcd.cursorAt (0, 0); + lcd << " Entering "; + + lcd.cursorAt (1, 0); + lcd << " changeBaudCB "; + + + const CommCB_changeBaud* o = + reinterpret_cast (oCB); + + baudRate = o->baudRate(); + appComm.transmit_changeBaud (baudRate); + + + freezeLocalDisplay(); + lcd.cursorAt (0, 0); + lcd << " Transmitted "; + + lcd.cursorAt (1, 0); + lcd << " changeBaud "; + ``` +} + +##### Result : Failed + +- Output : + + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + libxsmu version: 2.1.2 + Hardware version: 4.0.0 + Firmware version: 255.255.253 + Device ID : 0 + goodID : 1 + Remaining time: 0.887270927429 sec + + virtuaSMU : AckBits Reset + Comm : QP4_Packet allocated + Comm : Packet Sealed and Transmitted + virtuaSMU : Transmitted baudRate, Starting wait for response + ``` + + On LCD -> "Entering changeBaudCB" + On LCD -> "Transmitted changeBaud" + + ``` + Baud Rate: 9600 + Timeout: 0.0 + Communication timeout in changeBaud + ``` +--- + +- Added print statements to VS_setVoltage functions to see internal working + +##### Result : Failed + +- Output : timeout error even in setVoltage functions, reason being printing these statements lead to execution time exceeding the timeout. +--- + +- Added print statement in virtuaSMU.cxx (software), to see the characters and corresponding hex numbers being transmitted. + +##### Result : Timeout + +- Output : + +``` +libxsmu version: 2.1.2 +Total device: 1 +Seial number: XSMU012A +libxsmu version: 2.1.2 +51 Q +50 P +34 4 +31 1 +0 +2C , +F9 � +12  +0 +1  +0 +0 +58 X +50 P +4C L +4F O +52 R +45 E +20 +53 S +4D M +55 U +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +4  +0 +0 +FF � +FF � +FF � +FD � +Hardware version: 4.0.0 +Firmware version: 255.255.253 +Device ID : 0 +goodID : 1 +Remaining time: 0.889459848404 sec + +51 Q +50 P +34 4 +31 1 +0 +8 +FF � +30 0 +0 +2B + +0 +0 +0 +0 +25 % +80 � +Baud Rate: 9600 +Timeout: 0.0 +Communication timeout in changeBaud +``` +--- + +``` +libxsmu version: 2.1.2 +Total device: 1 +Seial number: XSMU012A +libxsmu version: 2.1.2 +51 Q +50 P +34 4 +31 1 +0 +2C , +F9 � +12  +0 +1  +0 +0 +58 X +50 P +4C L +4F O +52 R +45 E +20 +53 S +4D M +55 U +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +4  +0 +0 +FF � +FF � +FF � +FD � +void smu::Comm::interpret(const void*, uint16_t):249:Opcode: 1 +Hardware version: 4.0.0 +Firmware version: 255.255.253 +Device ID : 0 +goodID : 1 +Remaining time: 0.882127046585 sec + +void smu::Comm::transmit_changeBaud(uint32_t):1393:Comm : QP4_Packet allocated +void smu::Comm::transmit_changeBaud(uint32_t):1400:Comm : Packet Sealed and Transmitted +51 Q +50 P +34 4 +31 1 +0 +8 +FF � +30 0 +0 +2B + +0 +0 +0 +0 +25 % +80 � +void smu::Comm::interpret(const void*, uint16_t):249:Opcode: 43 +void smu::Comm::changeBaudCB(const void*, uint16_t):746:Comm : Packet Size Okay +void smu::Comm::changeBaudCB(const void*, uint16_t):752:Comm : Callback Completed +Baud Rate: 9600 +Timeout: 0.0 +Communication timeout in changeBaud +``` +--- + +``` +libxsmu version: 2.1.2 +Total device: 1 +Seial number: XSMU012A +libxsmu version: 2.1.2 +51 Q +50 P +34 4 +31 1 +0 +2C , +F9 � +12  +0 +1  +0 +0 +58 X +50 P +4C L +4F O +52 R +45 E +20 +53 S +4D M +55 U +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +4  +0 +0 +FF � +FF � +FF � +FD � +void smu::Comm::interpret(const void*, uint16_t):249:Opcode: 1 +Hardware version: 4.0.0 +Firmware version: 255.255.253 +Device ID : 0 +goodID : 1 +Remaining time: 0.884266853333 sec + +libxsmu changeBaud 9600 5 + +void smu::Driver::changeBaud(uint32_t*, float*):1244:virtuaSMU : AckBits Reset +void smu::Comm::transmit_changeBaud(uint32_t):1393:Comm : QP4_Packet allocated +void smu::Comm::transmit_changeBaud(uint32_t):1400:Comm : Packet Sealed and Transmitted +void smu::Driver::changeBaud(uint32_t*, float*):1247:virtuaSMU : Transmitted baudRate, Starting wait for response +51 Q +50 P +34 4 +31 1 +0 +8 +FF � +30 0 +0 +2B + +0 +0 +0 +0 +25 % +80 � +void smu::Comm::interpret(const void*, uint16_t):249:Opcode: 43 +void smu::Comm::changeBaudCB(const void*, uint16_t):746:Comm : Packet Size Okay +void smu::Comm::changeBaudCB(const void*, uint16_t):752:Comm : Callback Completed + +*Did not print lines in virtuaSMU.cxx changeBaudCB()* +- conclusion : that function is not being executed +- bug found : in virtuaSMU.cxx,, changeBaudCB() not in Callback list + +*Waits here* + + +libxsmu timeout 9600 0 +Baud Rate: 9600 +Timeout: 0.0 +Communication timeout in changeBaud +``` +--- + + +``` +libxsmu version: 2.1.2 +Total device: 1 +Seial number: XSMU012A +libxsmu version: 2.1.2 +51 Q +50 P +34 4 +31 1 +0 +2C , +F9 � +12  +0 +1  +0 +0 +58 X +50 P +4C L +4F O +52 R +45 E +20 +53 S +4D M +55 U +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +0 +4  +0 +0 +FF � +FF � +FF � +FD � +void smu::Comm::interpret(const void*, uint16_t):249:Opcode: 1 +Hardware version: 4.0.0 +Firmware version: 255.255.253 +Device ID : 0 +goodID : 1 +Remaining time: 0.884332180023 sec + +libxsmu changeBaud 9600 5 +void smu::Driver::changeBaud(uint32_t*, float*):1246:virtuaSMU : AckBits Reset +void smu::Comm::transmit_changeBaud(uint32_t):1393:Comm : QP4_Packet allocated +void smu::Comm::transmit_changeBaud(uint32_t):1400:Comm : Packet Sealed and Transmitted +void smu::Driver::changeBaud(uint32_t*, float*):1249:virtuaSMU : Transmitted baudRate, Starting wait for response +51 Q +50 P +34 4 +31 1 +0 +8 +FF � +30 0 +0 +2B + +0 +0 +0 +0 +25 % +80 � +void smu::Comm::interpret(const void*, uint16_t):249:Opcode: 43 +void smu::Comm::changeBaudCB(const void*, uint16_t):746:Comm : Packet Size Okay +void smu::Driver::changeBaudCB(const smu::CommCB*):581:virtuaSMU : Entering changeBaudCB +void smu::Driver::changeBaudCB(const smu::CommCB*):587:virtuaSMU : Retrieved baudRate +void smu::Driver::changeBaudCB(const smu::CommCB*):590:virtuaSMU : AckBits Set +void smu::Comm::changeBaudCB(const void*, uint16_t):752:Comm : Callback Completed +void smu::Driver::changeBaud(uint32_t*, float*):1253:virtuaSMU : Recieved Response +libxsmu success9600 4.91463 +Baud Rate: 9600 +Timeout: 4.9146270752 + +``` + +### Testng for keepAlive (wrapper/python/test/keepAlive.py) + +- Result : Passed +-Output : + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + libxsmu version: 2.1.2 + 51 Q + 50 P + 34 4 + 31 1 + 0 + 2C , + F9 � + 12  + 0 + 1  + 0 + 0 + 58 X + 50 P + 4C L + 4F O + 52 R + 45 E + 20 + 53 S + 4D M + 55 U + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4  + 0 + 0 + FF � + FF � + FF � + FD � + Hardware version: 4.0.0 + Firmware version: 255.255.253 + Device ID : 0 + goodID : 1 + Remaining time: 0.849823951721 sec + + 51 Q + 50 P + 34 4 + 31 1 + 0 + 8 + FF � + C7 � + 0 + 2  + 0 + 0 + 0 + 0 + 27 ' + 10  + Lease Time: 10000 + Timeout: 4.91435289383 + ``` + + +--- + +### Testing for async thread calling keepAlive() and locking mechanism in Comm +Added : +- PRINT_DEBUG ("Asynch thread launched") in open() +- PRINT_DEBUG ("Inside thread : Keep Alive sent") inside thread() +- PRINT_DEBUG ("Lock Acquired") in keepAlive, changeBaud, VS_setVoltage and VM_Read functions +- Output for `python keepAlive.py` + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + libxsmu version: 2.1.2 + Hardware version: 4.0.0 + Firmware version: 255.255.253 + void smu::Driver::open(const char*, float*):622:Asynch thread launched + Device ID : 0 + goodID : 1 + Remaining time: 0.869105100632 sec + + void smu::Driver::keepAlive(uint32_t*, float*):719:Lock Acquired + Lease Time: 10000 + Timeout: 4.89869022369 + void smu::Driver::keepAlive(uint32_t*, float*):719:Lock Acquired + void smu::Driver::thread():735:Inside thread : Keep Alive sent + ``` + +- Output for `python changeBaud.py` + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + libxsmu version: 2.1.2 + Hardware version: 4.0.0 + Firmware version: 255.255.253 + void smu::Driver::open(const char*, float*):622:Asynch thread launched + Device ID : 0 + goodID : 1 + Remaining time: 0.869477987289 sec + + void smu::Driver::changeBaud(uint32_t*, float*):1373:Lock Acquired + Baud Rate: 9600 + Timeout: 4.9146399498 + void smu::Driver::keepAlive(uint32_t*, float*):719:Lock Acquired + void smu::Driver::thread():735:Inside thread : Keep Alive sent + ``` +- Output for `python VS_setVoltage.py 1` + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + libxsmu version: 2.1.2 + Hardware version: 4.0.0 + Firmware version: 255.255.253 + void smu::Driver::open(const char*, float*):622:Asynch thread launched + Device ID : 0 + goodID : 1 + Remaining time: 0.850958108902 sec + + void smu::Driver::VS_setVoltage(float*, float*):944:Lock Acquired + Voltage: 0.999929249287 + Timeout: 4.91469097137 + void smu::Driver::keepAlive(uint32_t*, float*):719:Lock Acquired + void smu::Driver::thread():735:Inside thread : Keep Alive sent + ``` +- Output for `python VM_Read.py` (Ended with `Ctrl+c`) + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + libxsmu version: 2.1.2 + Hardware version: 4.0.0 + Firmware version: 255.255.253 + void smu::Driver::open(const char*, float*):622:Asynch thread launched + Device ID : 0 + goodID : 1 + Remaining time: 0.870882987976 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.13914418221 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15525889397 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17055797577 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.1550321579 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17103505135 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20280408859 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15487217903 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17105913162 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20312213898 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20294713974 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15506291389 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.1709561348 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20299291611 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15482211113 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17106795311 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20310091972 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20291304588 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15489888191 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17089796066 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20286202431 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15500307083 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17052602768 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20300483704 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20285892487 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15503001213 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17059803009 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20324611664 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15489792824 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17091703415 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20329713821 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20329809189 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15476918221 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17097902298 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20291399956 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15500283241 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17109894753 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20278191566 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20280718803 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15464901924 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.17091703415 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.20296692848 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + voltage : -0.101999998093 + Remaining time : 1.15501594543 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1093:Lock Acquired + ^CTraceback (most recent call last): + File "VM_getReading.py", line 40, in + voltage, timeout = libxsmu.VM_getReading (deviceID, filter_length, timeout) + KeyboardInterrupt + ``` +The output of this last test is not as expected. Since the keepAlive function is being called in a parallel thread, it should the Lock Acquired for keeAlive should show up in between the Lock Acquired for VM_read. + + +But if the range is changed from (0, 200) to (0, 1) in `VM_getReading.py`, the output is : + +``` +libxsmu version: 2.1.2 +Total device: 1 +Seial number: XSMU012A +libxsmu version: 2.1.2 +Hardware version: 4.0.0 +Firmware version: 255.255.253 +void smu::Driver::open(const char*, float*):622:Async thread launched +Device ID : 0 +goodID : 1 +Remaining time: 0.832612991333 sec + +void smu::Driver::VM_read(uint16_t*, float*, float*):1094:Lock Acquired +voltage : -2.67028808594e-05 +Remaining time : 1.18702793121 sec + +void smu::Driver::keepAlive(uint32_t*, float*):718:Trying to Acquire Lock +void smu::Driver::keepAlive(uint32_t*, float*):720:Lock Acquired +void smu::Driver::thread():736:Inside thread : Keep Alive sent +``` +- Added std::launch::async as argument to std::async to always set asynchronous operation of thread. +- Fixed bug in `Driver::thread()` to convert ms into seconds for comparison inside while look +- Result : Passed +- Output : + + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + void smu::Driver::open(const char*, float*):598:Opening Device + libxsmu version: 2.1.2 + Hardware version: 4.0.0 + Firmware version: 255.255.253 + void smu::Driver::open(const char*, float*):624:Async thread launched + Device ID : 0 + goodID : 1 + Remaining time: void smu::Driver::keepAlive(uint32_t*, float*)0.88267493248 sec : + + 721:Trying to Acquire Lock + void smu::Driver::keepAlive(uint32_t*, float*):723:Lock Acquired + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::thread():void smu::Driver::VM_read(uint16_t*, float*, float*):739:1098:Lock Acquired + Inside thread : Keep Alive sent + void smu::Driver::thread():743:Inside thread : Alive 139 + voltage : -2.47955322266e-05 + Remaining time : 1.17120504379 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + voltage : -2.86102294922e-05 + Remaining time : 1.17108106613 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + voltage : -2.86102294922e-05 + Remaining time : 1.15503096581 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + void smu::Driver::keepAlive(uint32_t*, float*):721:Trying to Acquire Lock + voltage : -2.67028808594e-05 + Remaining time : void smu::Driver::keepAlive(uint32_t*, float*)1.17121624947 sec + + :723:Lock Acquired + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::thread():751:Inside thread : Keep Alive sent + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + voltage : -2.5749206543e-05 + Remaining time : 1.16077613831 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + voltage : -2.95639038086e-05 + Remaining time : 1.17108201981 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + voltage : -2.5749206543e-05 + Remaining time : 1.1545920372 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + void smu::Driver::keepAlive(uint32_t*, float*):721:Trying to Acquire Lock + voltage : void smu::Driver::keepAlive(uint32_t*, float*):-2.86102294922e-05723 + Remaining time ::Lock Acquired + 1.17104387283 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::thread():751:Inside thread : Keep Alive sentvoid smu::Driver::VM_read(uint16_t*, float*, float*):1098: + Lock Acquired + voltage : -2.5749206543e-05 + Remaining time : 1.16069293022 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + voltage : -2.67028808594e-05 + Remaining time : 1.17099499702 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + voltage : -2.67028808594e-05 + Remaining time : 1.15505194664 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + void smu::Driver::keepAlive(uint32_t*, float*):721:Trying to Acquire Lock + voltage : -2.47955322266e-05 + Remaining time : 1.1710100174 secvoid smu::Driver::keepAlive(uint32_t*, float*) + + :723:Lock Acquired + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::thread():751:Inside thread : Keep Alive sent + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + voltage : -2.5749206543e-05 + Remaining time : 1.16075015068 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + voltage : -2.5749206543e-05 + Remaining time : 1.1713449955 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + voltage : -2.5749206543e-05 + Remaining time : 1.15498399734 sec + + void smu::Driver::VM_read(uint16_t*, float*, float*):1096:Trying to Acquire Lock + void smu::Driver::VM_read(uint16_t*, float*, float*):1098:Lock Acquired + ^Cvoid smu::Driver::keepAlive(uint32_t*, float*):721:Trying to Acquire Lock + void smu::Driver::keepAlive(uint32_t*, float*):723:Lock Acquired + Traceback (most recent call last): + File "VM_getReading.py", line 40, in + voltage, timeout = libxsmu.VM_getReading (deviceID, filter_length, timeout) + KeyboardInterrupt + ``` + +--- +- Testing for REC_SIZE +- ``python wrapper/test/python/recSize.py` +- Result : Passed +- Output : + + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + void smu::Driver::open(const char*, float*):632:Opening Device + libxsmu version: 2.1.2 + Hardware version: 4.0.0 + Firmware version: 255.255.253 + void smu::Driver::open(const char*, float*):658:Async thread launched + Device ID : 0 + goodID : 1 + Remaining time: 0.873402833939 sec + + void smu::Driver::keepAlive(uint32_t*, float*):755:Trying to Acquire Lock + void smu::Driver::keepAlive(uint32_t*, float*):757:Lock Acquired + void smu::Driver::recSize(uint16_t*, float*):1424:Lock Acquired + recSize: 0 + Timeout: 4.91455888748 + void smu::Driver::close():664:Closing Device + ``` +--- + +- Testing for START_REC and STOP_REC +- `python wrapper/test/python/startRec.py` +- Result : Passed +- Output : + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + void smu::Driver::open(const char*, float*):632:Opening Device + libxsmu version: 2.1.2 + Hardware version: 4.0.0 + Firmware version: 255.255.253 + void smu::Driver::open(const char*, float*):658:Async thread launched + void smu::Driver::keepAlive(uint32_t*, float*)Device ID : :0 + goodID : 1 + Remaining time: 7550.869968891144:Trying to Acquire Lock sec + + + void smu::Driver::keepAlive(uint32_t*, float*):757:Lock Acquired + void smu::Driver::startRec():1472:REC : 1 + Started Recording Streamed Data + void smu::Driver::stopRec():1478:REC : 0 + Stopped Recording Streamed Data + void smu::Driver::close():664:Closing Device + ``` +--- + +- Testing for REC_DATA +- `python wrapper/test` +- Result : Failed +- Output : + + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + void smu::Driver::open(const char*, float*):632:Opening Device + libxsmu version: 2.1.2 + Hardware version: 4.0.0 + Firmware version: 255.255.253 + void smu::Driver::open(const char*, float*):658:Async thread launched + Device ID : 0 + goodID : 1void smu::Driver::keepAlive(uint32_t*, float*):755:Trying to Acquire Lock + void smu::Driver::keepAlive(uint32_t*, float*) + Remaining time: :757:0.866751909256Lock Acquired + sec + + void smu::Driver::recData(uint16_t*, float*):1454:Lock Acquired + recSize: 0 + Timeout: 0.0 + Communication timeout in recData + ``` + +- Added Opcode print statements, no opcodes shown for recData means that bug is in firmware (no data being transmitted from FW) +- Added lcd print statements to recDataCB in Application.h in FW. (Are not printed) +- Result : Failed +- Output : + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + void smu::Driver::open(const char*, float*):633:Opening Device + libxsmu version: 2.1.2 + 51 Q + 50 P + 34 4 + 31 1 + 0 + 2C , + F9 � + 12  + 0 + 1  + 0 + 0 + 58 X + 50 P + 4C L + 4F O + 52 R + 45 E + 20 + 53 S + 4D M + 55 U + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4  + 0 + 0 + FF � + FF � + FF � + FD � + Hardware version: 4.0.0 + Firmware version: 255.255.253 + void smu::Driver::open(const char*, float*):659:Async thread launched + Device ID : 0 + goodID : void smu::Driver::keepAlive(uint32_t*, float*)1 : + Remaining time: 756:Trying to Acquire Lock + void smu::Driver::keepAlive(uint32_t*, float*):758:Lock Acquired + 0.883061885834 sec + + 51 Q + 50 P + 34 4 + 31 1 + 0 + 8 + FF � + C7 � + 0 + 2  + 0 + 0 + 0 + 0 + 27 ' + 10  + void smu::Driver::keepAlive(uint32_t*, float*):756:Trying to Acquire Lock + void smu::Driver::keepAlive(uint32_t*, float*):758:Lock Acquired + 51 Q + 50 P + 34 4 + 31 1 + 0 + 8 + FF � + C7 � + 0 + 2  + 0 + 0 + 0 + 0 + 27 ' + 10  + void smu::Driver::recData(uint16_t*, float*):1455:Lock Acquired + void smu::Driver::recData(uint16_t*, float*):1464:Successfully transmitted, waiting for response + void smu::Driver::keepAlive(uint32_t*, float*):756:Trying to Acquire Lock + recSize: void smu::Driver::keepAlive(uint32_t*, float*)0 + Timeout: 0.0: + 758:Lock AcquiredCommunication timeout in recData + ``` + + +- Implemented START_REC and STOP_REC down to firmware +- New test (`wrapper/python/test/startRec.py`) +- Result : Passed +- Output : + + ``` + libxsmu version: 2.1.2 + Total device: 1 + Seial number: XSMU012A + void smu::Driver::open(const char*, float*):652:Opening Device + libxsmu version: 2.1.2 + 51 Q + 50 P + 34 4 + 31 1 + 0 + 2C , + F9 � + 12  + 0 + 1  + 0 + 0 + 58 X + 50 P + 4C L + 4F O + 52 R + 45 E + 20 + 53 S + 4D M + 55 U + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4  + 0 + 0 + FF � + FF � + FF � + FD � + Hardware version: 4.0.0 + Firmware version: 255.255.253 + void smu::Driver::open(const char*, float*):678:Async thread launched + Device ID : 0 + goodID : 1void smu::Driver::keepAlive(uint32_t*, float*): 775: + Remaining time:Trying to Acquire Lock + void smu::Driver::keepAlive(uint32_t*, float*):7770.886788845062 sec + + :Lock Acquired + 51 Q + 50 P + 34 4 + 31 1 + 0 + 8 + FF � + C7 � + 0 + 2  + 0 + 0 + 0 + 0 + 27 ' + 10  + void smu::Driver::keepAlive(uint32_t*, float*):775:Trying to Acquire Lock + void smu::Driver::keepAlive(uint32_t*, float*):777:Lock Acquired + 51 Q + 50 P + 34 4 + 31 1 + 0 + 8 + FF � + C7 � + 0 + 2  + 0 + 0 + 0 + 0 + 27 ' + 10  + void smu::Driver::StartRec(float*):1520:Lock Acquired + void smu::Driver::StartRec(float*):1525:Successfully transmitted, waiting for response + 51 Q + 50 P + 34 4 + 31 1 + 0 + 4  + FF � + D2 � + 0 + 2E . + 0 + 0 + Started Recording Streamed Data + void smu::Driver::keepAlive(uint32_t*, float*):775:Trying to Acquire Lock + void smu::Driver::keepAlive(uint32_t*, float*):777:Lock Acquired + 51 Q + 50 P + 34 4 + 31 1 + 0 + 8 + FF � + C7 � + 0 + 2  + 0 + 0 + 0 + 0 + 27 ' + 10  + void smu::Driver::keepAlive(uint32_t*, float*):775:Trying to Acquire Lock + void smu::Driver::keepAlive(uint32_t*, float*):777:Lock Acquired + 51 Q + 50 P + 34 4 + 31 1 + 0 + 8 + FF � + C7 � + 0 + 2  + 0 + 0 + 0 + 0 + 27 ' + 10  + void smu::Driver::StopRec(float*):1540:Lock Acquired + void smu::Driver::StopRec(float*):1545:Successfully transmitted, waiting for response + 51 Q + 50 P + 34 4 + 31 1 + 0 + 4  + FF � + D1 � + 0 + 2F / + 0 + 0 + Stopped Recording Streamed Data + void smu::Driver::close():684:Closing Device + ``` + +- Testing REC_DATA again +- Added more print statements to debug +- Result : Failed +- Output (only for recData function) : + + ``` + void smu::Driver::recData(uint16_t*, float*):1474:Lock Acquired + void smu::Driver::recData(uint16_t*, float*):1479:Successfully transmitted, waiting for response + 51 Q + 50 P + 34 4 + 31 1 + 1  + 8 + EA � + E1 � + 0 + 2D - + 0 + 0 + 0 + 1  + 0 + 0 + 53 S + 20 + 45 E + 52 R + 0 + 0 + 55 U + 4D M + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4  + 0 + FD � + FF � + FF � + FF � + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 3C < + 23 # + D7 � + A + + 0 + 0 + 0 + 1  + 0 + 0 + 0 + 0 + 8 + 2  + F0 � + 14  + 0 + 0 + 1  + 0 + 0 + 0 + 0 + 0 + 0 + 80 � + 25 % + 0 + 0 + 50 P + 51 Q + 0 + FF � + 8 + 0 + 31 1 + 0 + 2F / + 0 + D1 � + 27 ' + 0 + 0 + 0 + 0 + 0 + 0 + 10  + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + FF � + B3 � + 4  + 0 + 0 + 2D - + 0 + D2 � + 0 + 1  + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 10  + 27 ' + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + FF � + 0 + 0 + F5 � + 4  + B3 � + 4  + F5 � + 4  + 0 + 1  + 4  + 0 + 0 + 0 + 0 + 4  + AF � + AF � + 4  + E7 � + 10  + E3 � + 1  + 0 + 0 + 0 + 10  + 1  + 0 + 18  + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1  + 0 + 0 + 0 + 0 + 0 + 0 + 5 + B8 � + void smu::Driver::keepAlive(uint32_t*, float*):775:Trying to Acquire Lock + recSize: void smu::Driver::keepAlive(uint32_t*, float*)0:777 + Timeout: :Lock Acquired0.0 + + Communication timeout in recData + ``` +- Retest +- Result : Failed +- Output : + ``` + void smu::Driver::recData(uint16_t*, float*):1474:Lock Acquired + void smu::Driver::recData(uint16_t*, float*):1479:Successfully transmitted, waiting for response + 51 Q + 50 P + 34 4 + 31 1 + 1  + 8 + E7 � + 16  + 0 + 2D - + 0 + 0 + 0 + 1  + 0 + 0 + 53 S + 20 + 45 E + 52 R + 0 + 0 + 55 U + 4D M + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 4  + 0 + FD � + FF � + FF � + FF � + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 3C < + 23 # + D7 � + A + + 1  + 0 + 0 + 1  + 0 + 0 + 0 + 0 + 1C  + F0 � + 55 U + B + + 0 + 1  + 1  + 0 + 0 + 0 + 0 + 0 + 0 + 80 � + 25 % + 0 + 0 + 50 P + 51 Q + 0 + FF � + 8 + 0 + 31 1 + 0 + 2D - + 0 + D2 � + 0 + 1  + 0 + 0 + 10  + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 51 Q + B3 � + 4  + FF � + 0 + 31 1 + 34 4 + 50 P + 0 + C7 � + FF � + 8 + 0 + 0 + 0 + 2  + 0 + 10  + 27 ' + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + F5 � + 0 + 0 + F5 � + 4  + B3 � + 4  + F5 � + 4  + 0 + 1  + 4  + 0 + 0 + 0 + 0 + 4  + AF � + AF � + 4  + 1  + E3 � + 10  + E7 � + 10  + 0 + 0 + 0 + 0 + 18  + 0 + 1  + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1  + 0 + 0 + 0 + 0 + 0 + 0 + 0 + B8 � + 5 + 0 + 0 + void smu::Driver::keepAlive(uint32_t*, float*):775:Trying to Acquire Lock + recSize: void smu::Driver::keepAlive(uint32_t*, float*):0 + Timeout: 7770.0 + Communication timeout in recData + :Lock Acquired + ```