Robox Library for Cpp: BCC/31 module 1.0.0
RLibCpp BCC/31 protocol implementation
|
The class to handle BCC protocol monitors. More...
#include <monitor.h>
Classes | |
class | PtrVector |
Class to handle with lists of Monitor. More... | |
Public Types | |
typedef Monitor * | pMonitor |
Public Member Functions | |
Monitor () | |
Class constructor. | |
virtual | ~Monitor () |
Class destructor. | |
Globals::Results | start () |
Starts the monitor. | |
Globals::Results | stop () |
Stops the monitor. | |
Globals::Results | read (MonitorStruct::ReadData &data) |
Read the last monitor data from the device. | |
Globals::Results | write (MonitorStruct::WriteData &data) |
Writes the monitor data to the device. | |
uint32_t | activeEventFrequency () |
The effective event notification frequency (Hz) | |
uint32_t | changeId () |
The id of the data read from the device. | |
Globals::Results | add (const Variable &var) override |
Adds a variable to the monitor. | |
Globals::Results | clear () override |
Clears the monitor items list. | |
uint64_t | id () const |
This monitor identifier: this is the value specified in the signals' senderId parameter. | |
void | setCoherentValues (bool value) override |
Flag setted to use coherent operations , i.e. don't split the command into multiple requests. | |
bool | active () const |
Get the flag to indicate if the monitor has been started into the device. | |
bool | autoRestart () const |
Get the flag to restart the monitor automatically when the device variable set has changed. | |
void | setAutoRestart (bool value) |
Set the flag to restart the monitor 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 | watchDog () const |
Get the monitor watchdog time (msec) | |
void | setWatchDog (uint32_t value) |
Set the monitor watchdog time (msec) | |
Public Member Functions inherited from BaseMonitor | |
BaseMonitor () | |
Class constructor. | |
virtual | ~BaseMonitor () |
Class desstructor. | |
virtual bool | connected () |
Get the flag to indicate if the monitor is connected to the device. | |
virtual uint32_t | count () |
Get the number of registered variables. | |
virtual bool | coherentValues () |
Get the flag setted to use coherent operations , i.e. don't split the command into multiple requests. | |
virtual Client * | client () |
Get the owner setted Client object. | |
virtual Connection * | connection () |
Get the Connection object. | |
Public Attributes | |
Signal2< uint64_t, uint32_t > | started |
Event fired when the monitor is successfully started. | |
Signal1< uint64_t > | stopped |
Event fired when the monitor is successfully stopped. | |
Signal2< uint64_t, uint32_t > | restarted |
Event fired when the monitor is successfully restarted. | |
Signal2< uint64_t, uint32_t > | dataChanged |
Event fired when the monitor data has changed i.e. some new monitor data has been received. | |
Signal2< uint64_t, RLibCpp::Bcc::MonitorStruct::ErrorData > | error |
Event fired when an error occurs during monitor operations. | |
Protected Member Functions | |
Globals::Results | doStop (bool wait, bool emitError=false) |
Stops the monitor, i.e. destroys it on the device and stops the handling thread. | |
void | setConnection (Connection *value) override |
The Connection object setted when invoking Connection::getMonitor(Monitor *&) method. | |
void | setClient (Client *value) override |
The client object setted when invoking Connection::getMonitor(Monitor *&) method. | |
void | handleThread () override |
The handling thread methods. | |
Globals::Results | doPrepareRuntime (Client *client, bool coherentValues) override |
Override of the BaseMonitor::doPrepareRuntime(Client *, bool) to set some class specific properties. | |
Message::MsgCodes | createMsgCode () override |
Get the message code to create the monitor. | |
ByteVector * | createMsgDataPrefix () override |
Get a pointer to byte array containg data per for the create message. | |
Message::MsgCodes | writeMsgCode () override |
Get the message code for the monitor write command. | |
ByteVector * | writeMsgDataPrefix () override |
Get a pointer to byte array containg data per for the write message. | |
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. | |
Client * | writeClient () const |
Get the internal Client object setted when invoking Connection::getMonitor(Monitor *&) method. | |
void | setWriteClient (Client *value) |
Set the internal Client object setted when invoking Connection::getMonitor(Monitor *&) method. | |
QuickMonitor *& | quickMonitor () |
Get the QuickMonitor object used to implement read(MonitorStruct::ReadData &) when the monitor is not active() | |
Tool::ThreadHelper::ScheduleTypes | scheduleType () const |
Get the thread schedule type for monitor. | |
void | setScheduleType (Tool::ThreadHelper::ScheduleTypes value) |
Set the thread schedule type for monitor. | |
uint32_t | monitorId () const |
Get the monitor identifier for the connected device. | |
void | setMonitorId (uint32_t value) |
Set the monitor identifier for the connected device. | |
Protected Member Functions inherited from BaseMonitor | |
void | synchronizeCompleted (uint64_t senderId, RLibCpp::Bcc::Globals::Results re) |
Private handler for the Connection::synchronizeCompleted(uint64_t , Globals::Results); event. | |
void | clearUserMonitors () |
Clears the BaseMonitorStruct::UserMonitorItem | |
void | clearDevices () |
Clear the BaseMonitorStruct::DeviceItem | |
void | addUserMonitor (BaseMonitorStruct::UserMonitorItem *item) |
Adds the item to the BaseMonitorStruct::UserMonitorItem list. | |
void | addDevice (BaseMonitorStruct::DeviceItem *item) |
Adds the item to the BaseMonitorStruct::DeviceItem list. | |
Globals::Results | doSetupReadData (BaseMonitorStruct::BaseData &data) |
Setups the BaseMonitorStruct::DeviceMonitorItem::readSrcValues() and BaseMonitorStruct::DeviceMonitorItem::readSrcValuesOffset(); of the BaseMonitorStruct::DeviceItem to the data values storage. | |
Globals::Results | doParseReadData (BaseMonitorStruct::DeviceItem *deviceItem, ByteVector &rawData, uint32_t dataOff) |
Parses the rawData raw data buffer read from the devices and stores values into the deviceItem proper list (BaseMonitorStruct::DeviceMonitorItem::readSrcValues()) | |
Globals::Results | doParseReadData (BaseMonitorStruct::DeviceItem *deviceItem, const uint8_t *rawData, uint32_t rawDataSize, uint32_t dataOff) |
Parses the rawData raw data buffer read from the devices and stores values into the deviceItem proper list (BaseMonitorStruct::DeviceMonitorItem::readSrcValues()) | |
Globals::Results | doSetupWriteData (BaseMonitorStruct::BaseData &data) |
Setups the BaseMonitorStruct::DeviceMonitorItem::writeSrcValues() and BaseMonitorStruct::DeviceMonitorItem::writeSrcValuesOffset() of the BaseMonitorStruct::DeviceItem to the data values storage. | |
Globals::Results | doParseWriteData (ByteVector &data, uint32_t dataOff, BaseMonitorStruct::DeviceItem *deviceItem) |
Parses the deviceItem proper list (BaseMonitorStruct::DeviceMonitorItem::readSrcValues()) and stores the data into the rawData raw data buffer to be written to the device. | |
Globals::Results | doParseWriteData (uint8_t *rawData, uint32_t rawDataSize, uint32_t dataOff, BaseMonitorStruct::DeviceItem *deviceItem) |
Parses the deviceItem proper list (BaseMonitorStruct::DeviceMonitorItem::readSrcValues()) and stores the data into the rawData raw data buffer to be written to the device. | |
BaseMonitorStruct::DeviceItem::PtrVector & | deviceItems () |
Get the list of items to read, i.e. the list of BCC message sent to the device. | |
BaseMonitorStruct::UserMonitorItem::PtrVector & | items () |
Get the original user defined monitor items' list
| |
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. | |
bool | releasing () const |
Get the releasing flag: when set the monitor is about to be released from connection. | |
void | setReleasing (bool value) |
Set the releasing flag: when set the monitor is about to be released from connection. | |
Friends | |
class | Connection |
class | Tool::ThreadHandler |
class | Tool::EventDispatcherThread |
Additional Inherited Members | |
Static Protected Attributes inherited from BaseMonitor | |
static const int | MaxItemsPerMonitor = 25 |
The number of maximun variable definition for each device monitor. | |
The class to handle BCC protocol monitors.
Example of general usage of the monitor class:
And that's an example for the dataChanged event handler
The monitor must be obtained from a valid connection. It is best practise to explictly release or dispose the monitor when done with it. Otherwise it will be released on connection destruction.
All the methods of the monitor class are blocking, that do not return until the operation is finished (with success or error).
For more usage examples, look at specific monitor methods.
Monitor | ( | ) |
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()
|
overridevirtual |
Adds a variable to the monitor.
var | The variable to add |
Variable may be added only if the monitor is not active(), otherwise an error will be returned
If the total size of variable added (including repetition values for array of variables) exceeds the maximun BCC protocol specification, you have to reset the coherentValues() flag
Reimplemented from BaseMonitor.
bool autoRestart | ( | ) | const |
Get the flag to restart the monitor 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 ifyou are not using the dataChanged event but pooling data with th read(MonitorStruct::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.
|
overridevirtual |
Clears the monitor items list.
Variable may be added only if the monitor is not active(), otherwise an error will be returned
Reimplemented from BaseMonitor.
|
overrideprotectedvirtual |
Get the message code to create the monitor.
Implements BaseMonitor.
|
overrideprotectedvirtual |
Get a pointer to byte array containg data per for the create message.
Implements BaseMonitor.
uint16_t dataFrequency | ( | ) | const |
Get the desired frequency of the data returned from the device (Hz)
|
protected |
The method that effectively invokes the event.
|
overrideprotectedvirtual |
Override of the BaseMonitor::doPrepareRuntime(Client *, bool) to set some class specific properties.
client | The Client to be used for comunicate to the device |
coherentValues | Flag to use coeherent values |
Reimplemented from BaseMonitor.
|
protected |
Stops the monitor, 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 monitor is not active() |
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 monitor 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 monitor identifier: this is the value specified in the signals' senderId parameter.
|
overrideprotected |
The method to be invoked for event dispatch.
|
protected |
Get the monitor identifier for the connected device.
|
protected |
Get the QuickMonitor object used to implement read(MonitorStruct::ReadData &) when the monitor is not active()
Globals::Results read | ( | MonitorStruct::ReadData & | data | ) |
Read the last monitor data from the device.
data | The storage filled with the monitor data |
If the monitor is active() , then this methods doesn't really reads the data from the connected device but fills the data parameters with the last values asynchronously returned from the device
|
protected |
Get the thread schedule type for monitor.
void setAutoRestart | ( | bool | value | ) |
Set the flag to restart the monitor automatically when the device variable set has changed.
value | The value to set |
|
overrideprotectedvirtual |
The client object setted when invoking Connection::getMonitor(Monitor *&) method.
value | The value to set |
Reimplemented from BaseMonitor.
|
overridevirtual |
Flag setted to use coherent operations , i.e. don't split the command into multiple requests.
value | The value to set |
This parameter may be changed at any time but it's assumed only upon the monitor start() command
Reimplemented from BaseMonitor.
|
overrideprotectedvirtual |
The Connection object setted when invoking Connection::getMonitor(Monitor *&) method.
The value to set
Reimplemented from BaseMonitor.
void setDataFrequency | ( | uint16_t | value | ) |
Set the desired frequency of the data returned from the device (Hz)
value | The value to set |
void setEventFrequency | ( | uint32_t | value | ) |
Set the desired event frequency (Hz)
value | The value to set |
|
protected |
Set the monitor identifier for the connected device.
value | The value to set |
|
protected |
void setWatchDog | ( | uint32_t | value | ) |
Set the monitor watchdog time (msec)
value | The value to set |
|
protected |
Set the internal Client object setted when invoking Connection::getMonitor(Monitor *&) method.
value | The value to set |
Globals::Results start | ( | ) |
Starts the monitor.
If the monitor is active() then it destroys the monitor on the device, and then creates the new one with the actual properties
If any error occurs , an error event will be fired
On successfull completition, the active() will be setted and the started event fired
Globals::Results stop | ( | ) |
uint32_t watchDog | ( | ) | const |
Get the monitor watchdog time (msec)
Globals::Results write | ( | MonitorStruct::WriteData & | data | ) |
Writes the monitor data to the device.
data | The storage filled by the caller with the monitor data to be written |
Example of general usage of the monitor write method:
This operation will fails if the monitor state is not active(). If you need a monitor just for writing purposes you may setup the monitor at lowest data and event frequency and start() it without connecting to the dataChanged event.
|
protected |
Get the internal Client object setted when invoking Connection::getMonitor(Monitor *&) method.
|
overrideprotectedvirtual |
Get the message code for the monitor write command.
Implements BaseMonitor.
|
overrideprotectedvirtual |
Get a pointer to byte array containg data per for the write message.
Implements BaseMonitor.
|
friend |
|
friend |
|
friend |
Signal2<uint64_t, uint32_t> dataChanged |
Event fired when the monitor data has changed i.e. some new monitor data has been received.
senderId | This monitor identifier as return from id() |
changeId | The progressive Id of the data received from the connected device |
Signal2<uint64_t, RLibCpp::Bcc::MonitorStruct::ErrorData> error |
Event fired when an error occurs during monitor operations.
senderId | This monitor identifier as return from id() |
data | The error data |
Signal2<uint64_t, uint32_t> restarted |
Event fired when the monitor is successfully restarted.
The monitor is restarted and this event fired only if the autoRestart() property is setted
senderId | This monitor identifier as return from id() |
activeDataFrequency | The data frequency effectively assumed by the device |
Signal2<uint64_t, uint32_t> started |
Event fired when the monitor is successfully started.
senderId | This monitor identifier as return from id() |
activeDataFrequency | The data frequency effectively assumed by the device |
Signal1<uint64_t> stopped |
Event fired when the monitor is successfully stopped.
senderId | This monitor identifier as return from id() |