Robox Library for Cpp: BCC/31 module 1.0.0
RLibCpp BCC/31 protocol implementation
|
The class to handle BCC protocol oscilloscopes. More...
#include <oscilloscope.h>
Classes | |
class | PtrVector |
Class to handle with lists of Oscilloscope. More... | |
Public Types | |
typedef Oscilloscope * | pOscilloscope |
Public Member Functions | |
Oscilloscope () | |
Class constructor. | |
virtual | ~Oscilloscope () |
Class destructor. | |
uint32_t | changeId () |
The id of the data read from the device. | |
Globals::Results | clear () |
Clears the oscilloscope items list. | |
Globals::Results | add (const Variable &var) |
Adds a variable (i.e. a track) to the oscilloscope. | |
uint32_t | activeEventFrequency () |
The effective event notification frequency (Hz) | |
Globals::Results | start () |
Starts the oscilloscope. | |
Globals::Results | stop () |
Stops the oscilloscope. | |
Globals::Results | read (OscilloscopeStruct::ReadData &data) |
Reads the samples cached from the device since last invocation of thie method. | |
uint64_t | id () const |
This oscilloscpe identifier: this is the value specified in the signals' senderId parameter. | |
Connection * | connection () const |
Get the connection object to communicate to the device. | |
void | setConnection (Connection *value) |
Set the connection object to communicate to the device. | |
Client * | client () const |
Get the owner setted Client object. | |
void | setClient (Client *value) |
Set the owner setted Client object. | |
bool | active () const |
Get the flag to indicate if the oscilloscope has been started into the device. | |
bool | autoRestart () const |
Get the flag to restart the oscilloscope automatically when the device variable set has changed. | |
void | setAutoRestart (bool value) |
Set the flag to restart the oscilloscope automatically when the device variable set has changed. | |
uint16_t | dataFrequency () const |
Get the desired frequency of the data returned from the device (Hz) | |
void | setDataFrequency (uint16_t value) |
Set the desired frequency of the data returned from the device (Hz) | |
uint16_t | activeDataFrequency () const |
Get the effective data frequency returned from the device. | |
uint32_t | eventFrequency () const |
Get the desired event frequency (Hz) | |
void | setEventFrequency (uint32_t value) |
Set the desired event frequency (Hz) | |
uint32_t | maxDataSamples () const |
Get the maximum number of samples cached. | |
void | setMaxDataSamples (uint32_t value) |
Set the maximum number of samples cached. | |
uint32_t | watchDog () const |
Get the oscilloscope watchdog time (msec) | |
void | setWatchDog (uint32_t value) |
Set the oscilloscope watchdog time (msec) | |
bool | dataOverflow () const |
Get the flag setted when the maxDataSamples() limit has been reached without read(OscilloscopeStruct::ReadData &) method invocation. | |
bool | connected () const |
Get the flag to indicate if the oscilloscope is connected to the device. | |
size_t | count () const |
Get the number of registered variables. | |
Public Attributes | |
Signal2< uint64_t, uint32_t > | started |
Event fired when the oscilloscope is successfully started. | |
Signal1< uint64_t > | stopped |
Event fired when the oscilloscope is successfully stopped. | |
Signal2< uint64_t, uint32_t > | restarted |
Event fired when the oscilloscope is successfully restarted. | |
Signal2< uint64_t, uint32_t > | dataChanged |
Event fired when the oscilloscope data has changed i.e. some new oscilloscope data has been received. | |
Signal2< uint64_t, RLibCpp::Bcc::OscilloscopeStruct::ErrorData > | error |
Event fired when an error occurs during oscilloscope operations. | |
Signal1< uint64_t > | dataOverflowed |
Event fired when the number of cached samples exceeds maxDataSamples() . You have to invoke the read(OscilloscopeStruct::ReadData &) at proper rate to avoid that. | |
Signal1< uint64_t > | dataNormalFlow |
Event fired once when the oscilloscope exit from the dataOverflow() condition to the normal data flow. | |
Protected Member Functions | |
Globals::Results | doStop (bool wait, bool emitError=false) |
Stops the oscilloscope, i.e. destroys it on the device and stops the handling thread. | |
Message::MsgCodes | createMsgCode () |
Get the message code to create the oscilloscope. | |
ByteVector * | createMsgDataPrefix () |
Get a pointer to byte array containg data per for the create message. | |
Globals::Results | doPrepareRuntime (Client *client) |
Prepare the runtime device oscilloscope definitions, i.e. setups the OscilloscopeStruct::DeviceItem::deviceOscilloscopeItemsList() from the user defined items() list. | |
void | clearUserOscilloscopes () |
Clears and deletes the user oscilloscopes' items() list. | |
void | addUserOscilloscope (OscilloscopeStruct::UserOscilloscopeItem *item) |
Add a user oscilloscope to the items() list. | |
Globals::Results | doParseReadData (OscilloscopeStruct::DeviceItem *deviceItem, const uint8_t *rawData, uint32_t rawDataSize, uint32_t rawDataOff, uint8_t numSamples) |
Parses the rawData raw data buffer read from the devices and stores values into the m_readDataCache storage. | |
Globals::Results | doSetupReadData (OscilloscopeStruct::ReadData &data) |
Setups the OscilloscopeStruct::ReadData::samples() thats will hold the sampled data. | |
void | doStopHandleThread (bool wait) |
Stops the m_handleThread | |
void | doStartHandleThread () |
Starts the m_handleThread | |
Globals::Results | doDestroy (bool reportError) |
Destroys the oscilloscope on the device. | |
Globals::Results | doSendDestroyMessage (OscilloscopeStruct::ErrorData &errorData) |
Sends the BCC oscilloscope destroy message. | |
Globals::Results | doCreate (bool reportError) |
Creates the oscilloscope into the connected device. | |
Globals::Results | doSendCreateMessage (OscilloscopeStruct::ErrorData &errorData) |
Sends the BCC oscilloscope create message. | |
Globals::Results | doSendStartMessage (uint32_t watchDog, uint16_t dataFrequency, OscilloscopeStruct::ErrorData &errorData) |
Sends the BCC oscilloscope start message. | |
Globals::Results | doSendStopMessage (OscilloscopeStruct::ErrorData &errorData) |
Sends the BCC oscilloscope stop message. | |
void | doCheckForDataChangeEvent () |
Helper method to check if dataChanged(long, uint32_t) event has to be fired. | |
void | handleThread () override |
The handling thread methods. | |
void | invoke (long tagData) override |
The method to be invoked for event dispatch. | |
void | doInvokeEvent (const Event &event) |
The method that effectively invokes the event. | |
EventDispatcherThread * | eventsThread () |
The thread for event dispatching. | |
void | synchronizeCompleted (uint64_t senderId, RLibCpp::Bcc::Globals::Results re) |
Private handler for the Connection::synchronizeCompleted(uint64_t , Globals::Results); event. | |
OscilloscopeStruct::UserOscilloscopeItem::PtrVector & | items () |
Get the original user defined oscilloscope items' list (OscilloscopeStruct::UserOscilloscopeItem) | |
bool | dirty () const |
Get the dirty flag: when set, the internal data structures needs to be updated/recreated. | |
void | setDirty (bool value) |
Set the dirty flag: when set, the internal data structures needs to be updated/recreated. | |
void | setDataOverflow (bool value) |
Set the flag setted when the maxDataSamples() limit has been reached without read(OscilloscopeStruct::ReadData &) method invocation. | |
uint32_t | oscilloscopeId () const |
Get the oscilloscope identifier for the connected device. | |
void | setOscilloscopeId (uint32_t value) |
Set the oscilloscope identifier for the connected device. | |
Tool::ThreadHelper::ScheduleTypes | scheduleType () const |
Get the thread schedule type for oscilloscope. | |
void | setScheduleType (Tool::ThreadHelper::ScheduleTypes value) |
Set the thread schedule type for oscilloscope. | |
bool | releasing () const |
Get the releasing flag: when set the oscilloscope is about to be released from connection. | |
void | setReleasing (bool value) |
Set the releasing flag: when set the oscilloscope is about to be released from connection. | |
Protected Attributes | |
OscilloscopeStruct::DeviceItem | m_deviceItem |
The handler object for the BCC messages sent to the device. | |
Friends | |
class | Connection |
class | Tool::ThreadHandler |
class | Tool::EventDispatcherThread |
The class to handle BCC protocol oscilloscopes.
Example of general usage of the oscilloscope class:
And that's an example for the Oscilloscope.DataChanged event handler
The oscilloscope must be obtained from a valid connection. It is best practise to explictly release ( Connection::releaseOscilloscope(Oscilloscope *) ) the oscilloscope when done with it. Otherwise it will be released when the Connection object is destroyed.
All the methods of the oscilloscope class are blocking, that do not return until the operation is finished (with success or error).
For more usage examples, look at specific oscilloscope methods.
typedef Oscilloscope* pOscilloscope |
Oscilloscope | ( | ) |
Class constructor.
|
virtual |
Class destructor.
bool active | ( | ) | const |
uint16_t activeDataFrequency | ( | ) | const |
Get the effective data frequency returned from the device.
uint32_t activeEventFrequency | ( | ) |
The effective event notification frequency (Hz)
It's the smallest value between the eventFrequency() assumed on start and the activeDataFrequency()
Globals::Results add | ( | const Variable & | var | ) |
Adds a variable (i.e. a track) to the oscilloscope.
var | The variable to add |
Variable may be added only if the oscilloscope is not active(), otherwise an error will be returned
The maximum number of tracks per single oscilloscope is DataSample::MAX_TRACK
Array of variables are not accepted (i.e. the repea value must be one)
|
protected |
Add a user oscilloscope to the items() list.
item | The item to add |
The item is appended to the items() list and deleted on clearUserOscilloscopes() call
bool autoRestart | ( | ) | const |
Get the flag to restart the oscilloscope automatically when the device variable set has changed.
uint32_t changeId | ( | ) |
The id of the data read from the device.
This parameter may be useful if you are not using the dataChanged(long, uint32_t) event but pooling data with th read(OscilloscopeStruct::ReadData &) methods at your specific rate, to see if data has changed since last read.
This parameter is updated at any single data message received from the device.
Globals::Results clear | ( | ) |
|
protected |
Clears and deletes the user oscilloscopes' items() list.
bool connected | ( | ) | const |
Get the flag to indicate if the oscilloscope is connected to the device.
Connection * connection | ( | ) | const |
Get the connection object to communicate to the device.
int32_t count | ( | ) | const |
Get the number of registered variables.
|
protected |
Get the message code to create the oscilloscope.
|
protected |
Get a pointer to byte array containg data per for the create message.
uint16_t dataFrequency | ( | ) | const |
Get the desired frequency of the data returned from the device (Hz)
bool dataOverflow | ( | ) | const |
Get the flag setted when the maxDataSamples() limit has been reached without read(OscilloscopeStruct::ReadData &) method invocation.
On positive transition (false to true transition) a dataOverflowed event is fired.
|
protected |
Get the dirty flag: when set, the internal data structures needs to be updated/recreated.
|
protected |
Helper method to check if dataChanged(long, uint32_t) event has to be fired.
|
protected |
Creates the oscilloscope into the connected device.
reportError | If setted, an error(long, RLibQt::Bcc::OscilloscopeStruct::ErrorData) event will be fired if any error occurs |
|
protected |
Destroys the oscilloscope on the device.
reportError | If setted, an error(long, RLibQt::Bcc::OscilloscopeStruct::ErrorData) event will be fired if any error occurs |
|
protected |
The method that effectively invokes the event.
|
protected |
Parses the rawData raw data buffer read from the devices and stores values into the m_readDataCache storage.
deviceItem | The device containimg the list of DeviceOscilloscopeItem |
rawData | The raw data buffer read from the device |
rawDataSize | The raw data buffer size read from the device |
rawDataOff | The starting offset related to rawData |
numSamples | The number of samples to retrive from rawData |
If the number of sample stored into the m_readDataCache storage exceeds maxDataSamples(), then the dataOverflow() property will be setted and the dataOverflowed(long) event fired.
|
protected |
Prepare the runtime device oscilloscope definitions, i.e. setups the OscilloscopeStruct::DeviceItem::deviceOscilloscopeItemsList() from the user defined items() list.
client | The Client to be used for comunicate to the device |
|
protected |
Sends the BCC oscilloscope create message.
errorData | The storage filled with error information if any error occurs during the command execution |
|
protected |
Sends the BCC oscilloscope destroy message.
errorData | The storage filled with error information if any error occurs during the command execution |
|
protected |
Sends the BCC oscilloscope start message.
watchDog | The value for the WatchDog sent rate |
dataFrequency | The value for the desidered data frequency |
errorData | The storage filled with error information if any error occurs during the command execution |
|
protected |
Sends the BCC oscilloscope stop message.
errorData | The storage filled with error information if any error occurs during the command execution |
|
protected |
Setups the OscilloscopeStruct::ReadData::samples() thats will hold the sampled data.
data | The object to which save the samples read from the device |
|
protected |
Starts the m_handleThread
|
protected |
Stops the oscilloscope, i.e. destroys it on the device and stops the handling thread.
wait | If true, the method will not returns until the handling thread has exited |
emitError | Set this to emit an error signal when this method is invoked when the oscilloscope is not active() |
|
protected |
Stops the m_handleThread
wait | If set, the method returns only after the actual completion of the thread |
uint32_t eventFrequency | ( | ) | const |
Get the desired event frequency (Hz)
|
protected |
The thread for event dispatching.
|
overrideprotected |
The handling thread methods.
This thread provides to all the common oscilloscope operations such as sending watch dog message, checking system information changes and performing autoRestart() (if enabled), retriving data and dispatching events to the user
uint64_t id | ( | ) | const |
This oscilloscpe identifier: this is the value specified in the signals' senderId parameter.
|
overrideprotected |
The method to be invoked for event dispatch.
|
protected |
Get the original user defined oscilloscope items' list (OscilloscopeStruct::UserOscilloscopeItem)
uint32_t maxDataSamples | ( | ) | const |
Get the maximum number of samples cached.
The cached samples list is cleared at each read(OscilloscopeStruct::ReadData &) method invocation.
The number of samples retrived from the device exceeds this value, then the dataOverflow() property is set and a dataOverflowed event is fired. The successive data samples retrived will be discrded, until the next read(OscilloscopeStruct::ReadData &) method invocation.
|
protected |
Get the oscilloscope identifier for the connected device.
Globals::Results read | ( | OscilloscopeStruct::ReadData & | data | ) |
Reads the samples cached from the device since last invocation of thie method.
data | The storage filled with the oscilloscope samples |
This methods clears the list of cached samples and the dataOverflow() flag if setted
Make sure to call this method at proper a rate so that the number of cached sampless doesn't exceed the maxDataSamples(), otherwise the dataOverflow() flag will be setted, a dataOverflowed(long) event fired and any other retrived sample discarded
|
protected |
Get the releasing flag: when set the oscilloscope is about to be released from connection.
|
protected |
Get the thread schedule type for oscilloscope.
void setAutoRestart | ( | bool | value | ) |
Set the flag to restart the oscilloscope automatically when the device variable set has changed.
value | The value to set |
void setClient | ( | Client * | value | ) |
Set the owner setted Client object.
value | The value to set |
void setConnection | ( | Connection * | value | ) |
Set the connection object to communicate to the device.
value | The value to set |
void setDataFrequency | ( | uint16_t | value | ) |
Set the desired frequency of the data returned from the device (Hz)
value | The value to set |
|
protected |
Set the flag setted when the maxDataSamples() limit has been reached without read(OscilloscopeStruct::ReadData &) method invocation.
On positive transition (false to true transition) a dataOverflowed event is fired.
value | The value to set |
|
protected |
Set the dirty flag: when set, the internal data structures needs to be updated/recreated.
value | The value to set |
void setEventFrequency | ( | uint32_t | value | ) |
Set the desired event frequency (Hz)
value | The value to set |
void setMaxDataSamples | ( | uint32_t | value | ) |
Set the maximum number of samples cached.
The cached samples list is cleared at each read(OscilloscopeStruct::ReadData &) method invocation.
The number of samples retrived from the device exceeds this value, then the dataOverflow() property is set and a dataOverflowed event is fired. The successive data samples retrived will be discrded, until the next read(OscilloscopeStruct::ReadData &) method invocation.
value | The value to set |
|
protected |
Set the oscilloscope identifier for the connected device.
value | The value to set |
|
protected |
Set the releasing flag: when set the oscilloscope is about to be released from connection.
value | The value to set |
|
protected |
Set the thread schedule type for oscilloscope.
value | The value to set |
void setWatchDog | ( | uint32_t | value | ) |
Set the oscilloscope watchdog time (msec)
value | The value to set |
Globals::Results start | ( | ) |
Starts the oscilloscope.
If the oscilloscope is active() then it destroys the oscilloscope on the device, and then creates the new one with the actual properties
If any error occurs , an error(long, RLibQt::Bcc::OscilloscopeStruct::ErrorData) event will be fired
On successfull completition, the active() will be setted and the started() event fired
Globals::Results stop | ( | ) |
Stops the oscilloscope.
If the oscilloscope is not active() then an error codeis returned
If any error occurs , an error(long, RLibQt::Bcc::OscilloscopeStruct::ErrorData) event will be fired
On successfull completition, the active() will be resetted and the stopped() event fired
|
protected |
Private handler for the Connection::synchronizeCompleted(uint64_t , Globals::Results); event.
senderId | The event sender indentifier |
re | The opration result code |
uint32_t watchDog | ( | ) | const |
Get the oscilloscope watchdog time (msec)
|
friend |
|
friend |
|
friend |
Signal2<uint64_t, uint32_t> dataChanged |
Event fired when the oscilloscope data has changed i.e. some new oscilloscope data has been received.
senderId | This oscilloscope identifier as return from id() |
changeId | The progressive Id of the data received from the connected device |
Signal1<uint64_t> dataNormalFlow |
Event fired once when the oscilloscope exit from the dataOverflow() condition to the normal data flow.
To exit the dataOverflow() condition you have to make a read(OscilloscopeStruct::ReadData &) or stop() and start() the oscilloscope
senderId | This oscilloscope identifier as return from id() |
Signal1<uint64_t> dataOverflowed |
Event fired when the number of cached samples exceeds maxDataSamples() . You have to invoke the read(OscilloscopeStruct::ReadData &) at proper rate to avoid that.
Best practice is handling the dataChanged(long, uint32_t) event fired by the oscilloscope on new data sample and with activeEventFrequency()
senderId | This oscilloscope identifier as return from id() |
Signal2<uint64_t, RLibCpp::Bcc::OscilloscopeStruct::ErrorData> error |
Event fired when an error occurs during oscilloscope operations.
senderId | This oscilloscope identifier as return from id() |
data | The error data |
|
protected |
The handler object for the BCC messages sent to the device.
Signal2<uint64_t, uint32_t> restarted |
Event fired when the oscilloscope is successfully restarted.
The oscilloscope is restarted and this event fired only if the autoRestart() property is setted
senderId | This oscilloscope identifier as return from id() |
activeDataFrequency | The data frequency effectively assumed by the device |
Signal2<uint64_t, uint32_t> started |
Event fired when the oscilloscope is successfully started.
senderId | This oscilloscope identifier as return from id() |
activeDataFrequency | The data frequency effectively assumed by the device |
Signal1<uint64_t> stopped |
Event fired when the oscilloscope is successfully stopped.
senderId | This oscilloscope identifier as return from id() |