A base struct for a communication interface. More...
#include <communicator.h>
Classes | |
struct | Deleter |
The communicator deleter. More... | |
Public Types | |
template<typename T > | |
using | UniquePtr = std::unique_ptr< T, Deleter > |
Initializes of UniquePtr<T> More... | |
Public Member Functions | |
virtual void | abortLoadLogFile ()=0 |
Aborts loading a logfile. More... | |
virtual void | addProtocolHandler (IProtocolHandler *handler) |
Adds a protocol handler. More... | |
std::shared_ptr< ReplyObject > | addReplyObject (ReplyObject *obj) |
Add a custom ReplyObject. More... | |
std::shared_ptr< ReplyObject > | addReplyObject (uint8_t mid) |
Add a MidReplyObject. More... | |
std::shared_ptr< ReplyObject > | addReplyObject (uint8_t mid, XsSize offset, XsSize size, uint8_t const *data) |
Add a MidAndDataReplyObject. More... | |
virtual bool | allowReprocessing () const |
XsSize | childDeviceCount () const |
virtual void | closeLogFile ()=0 |
Close the log file. More... | |
virtual void | closePort ()=0 |
Closes the open port. More... | |
Communicator (void) | |
Constructor, creates some management objects and clears the rest by calling initialize() More... | |
uint32_t | defaultTimeout () const |
void | destroy () |
Destroys the communicator. More... | |
bool | doTransaction (const XsMessage &message) |
Write a message and await the reply. More... | |
bool | doTransaction (const XsMessage &message, uint32_t timeout) |
Write a message and await the reply. More... | |
bool | doTransaction (const XsMessage &message, XsMessage &rcv) |
Write a message and await the reply. More... | |
virtual bool | doTransaction (const XsMessage &message, XsMessage &rcv, uint32_t timeout)=0 |
Write a message and await the reply. More... | |
virtual void | flushPort ()=0 |
Flushes all remaining data on the open port. More... | |
virtual XsResultValue | getDeviceId ()=0 |
Request a device to get device ID. More... | |
virtual XsResultValue | gotoConfig (bool detectRs485=false)=0 |
Request a device to go to config mode. More... | |
virtual XsResultValue | gotoMeasurement ()=0 |
Request a device to go to measurement mode. More... | |
virtual void | handleMessage (const XsMessage &message) |
Handles a message. More... | |
bool | hasProtocol (XsProtocolType type) const |
virtual bool | isDockedAt (Communicator *other) const =0 |
Returns true if the other device is docked at this device. More... | |
virtual bool | isLoadLogFileInProgress () const |
virtual bool | isPortOpen () const =0 |
virtual bool | isReadingFromFile () const =0 |
XsResultValue | lastResult () const |
Get the result value of the last operation. More... | |
XsString | lastResultText () const |
Get the accompanying error text for the value returned by lastResult() It may provide situation-specific information instead. More... | |
virtual void | loadLogFile (XsDevice *device)=0 |
Load a complete logfile. More... | |
virtual XsTimeStamp | logFileDate () const =0 |
virtual XsString | logFileName () const =0 |
virtual XsFilePos | logFileReadPosition () const =0 |
virtual XsFilePos | logFileSize () const =0 |
XsDeviceId | masterDeviceId () const |
virtual bool | openLogFile (const XsString &filename)=0 |
Open the log file `. More... | |
virtual bool | openPort (const XsPortInfo &portInfo, OpenPortStage stage=OPS_Full, bool detectRs485=false)=0 |
Opens a port. More... | |
virtual XsPortInfo | portInfo () const =0 |
virtual XsMessage | readMessage (uint8_t msgId=0)=0 |
Read a message from the open file. More... | |
virtual XsMessage | readMessageFromStartOfFile (uint8_t msgId, int maxMsgs=0)=0 |
Read a message from the start of the open file. More... | |
virtual std::deque< XsMessage > | readMessagesFromStartOfFile (uint8_t msgId, int maxMsgs=0)=0 |
Read multiple similar messages from the start of the open file. More... | |
void | removeProtocolHandler (XsProtocolType type) |
Removes a protocol handler. More... | |
virtual bool | reopenPort (OpenPortStage stage=OPS_Full, bool skipDeviceIdCheck=false)=0 |
Reopens the port. More... | |
virtual void | resetLogFileReadPosition (void)=0 |
Resets the logfile read position. More... | |
bool | sanityCheck (XsMessage const &msg) const |
Do a sanity check on a potential message. More... | |
virtual void | scheduleClosePort () |
Schedules to close the open port. More... | |
virtual void | setCredentials (XsString const &id, XsString const &key) |
Set the credentials required for using the device. More... | |
void | setDefaultTimeout (uint32_t timeout) |
Sets a default timeout. More... | |
virtual void | setGotoConfigTimeout (uint32_t timeout)=0 |
Set the timeout for the gotoConfig function. More... | |
virtual void | setKeepAlive (bool enable)=0 |
Either disable or enable (default) the keep alive mechanism (if supported by the device) More... | |
void | setMasterDevice (XsDevice *masterDevice) |
Sets a master device. More... | |
virtual void | waitForLastTaskCompletion ()=0 |
Wait for the last processing task to complete in the threadpool. More... | |
virtual bool | writeMessage (const XsMessage &message)=0 |
Write message to the device. More... | |
![]() | |
void | addCallbackHandler (XsCallbackPlainC *cb, bool chain=true) |
Add a handler to the list. More... | |
void | addChainedManager (CallbackManagerXda *cm) |
Add a chained manager to the list. More... | |
CallbackManagerXda () | |
Constructor, initializes the callback list. More... | |
void | clearCallbackHandlers (bool chain=true) |
Clear the callback list. More... | |
void | clearChainedManagers () |
Clear the chained manager list. More... | |
void | copyCallbackHandlersFrom (CallbackManagerXda *cm, bool chain=true) |
Copy all handlers from cm into this manager. More... | |
void | copyCallbackHandlersTo (CallbackManagerXda *cm, bool chain=true) |
Copy all handlers from this manager into cm. More... | |
void | onAllBufferedDataAvailable (XsDevicePtrArray *devs, const XsDataPacketPtrArray *packets) override |
The XsCallback::onAllBufferedDataAvailable() callback forwarding function. More... | |
void | onAllDataAvailable (XsDevicePtrArray *devs, const XsDataPacketPtrArray *packets) override |
The XsCallback::onAllDataAvailable() callback forwarding function. More... | |
void | onAllLiveDataAvailable (XsDevicePtrArray *devs, const XsDataPacketPtrArray *packets) override |
The XsCallback::onAllLiveDataAvailable() callback forwarding function. More... | |
void | onAllRecordedDataAvailable (XsDevicePtrArray *devs, const XsDataPacketPtrArray *packets) override |
The XsCallback::onAllRecordedDataAvailable() callback forwarding function. More... | |
void | onBufferedDataAvailable (XsDevice *dev, const XsDataPacket *data) override |
The XsCallback::onBufferedDataAvailable() callback forwarding function. More... | |
void | onConnectivityChanged (XsDevice *dev, XsConnectivityState newState) override |
The XsCallback::onConnectivityChanged() callback forwarding function. More... | |
void | onDataAvailable (XsDevice *dev, const XsDataPacket *data) override |
The XsCallback::onDataAvailable() callback forwarding function. More... | |
void | onDataUnavailable (XsDevice *dev, int64_t packetId) override |
The XsCallback::onDataUnavailable() callback forwarding function. More... | |
void | onDeviceStateChanged (XsDevice *dev, XsDeviceState newState, XsDeviceState oldState) override |
The XsCallback::onDeviceStateChanged() callback forwarding function. More... | |
void | onError (XsDevice *dev, XsResultValue error) override |
The Xscallback::onError() callback forwarding function. More... | |
void | onInfoResponse (XsDevice *dev, XsInfoRequest request) override |
The XsCallback::onInfoResponse() callback forwarding function. More... | |
void | onLiveDataAvailable (XsDevice *dev, const XsDataPacket *packet) override |
The XsCallback::onLiveDataAvailable() callback forwarding function. More... | |
void | onMessageDetected (XsDevice *dev, XsProtocolType type, XsByteArray const *rawMessage) override |
The Xscallback::onMessageReceivedFromDevice() callback forwarding function. More... | |
void | onMessageReceivedFromDevice (XsDevice *dev, XsMessage const *message) override |
The Xscallback::onMessageReceivedFromDevice() callback forwarding function. More... | |
void | onMessageSentToDevice (XsDevice *dev, XsMessage const *message) override |
The Xscallback::onMessageSentToDevice() callback forwarding function. More... | |
void | onMissedPackets (XsDevice *dev, int count, int first, int last) override |
The XsCallback::onMissedPackets() callback forwarding function. More... | |
void | onNonDataMessage (XsDevice *dev, XsMessage const *message) override |
The Xscallback::onNonDataMessage() callback forwarding function. More... | |
void | onProgressUpdated (XsDevice *dev, int current, int total, const XsString *identifier) override |
The XsCallback::onProgressUpdated() callback forwarding function. More... | |
void | onRecordedDataAvailable (XsDevice *dev, const XsDataPacket *data) override |
The XsCallback::onRecordedDataAvailable() callback forwarding function. More... | |
void | onRestoreCommunication (const XsString *portName, XsResultValue result) override |
The Xscallback::onRestoreCommunication callback forwarding function. More... | |
void | onTransmissionRequest (int channelId, const XsByteArray *data) override |
void | onWakeupReceived (XsDevice *dev) override |
The XsCallback::onWakeupReceived() callback forwarding function. More... | |
int | onWriteMessageToLogFile (XsDevice *dev, const XsMessage *message) override |
The XsCallback::onWriteMessageToLogFile() callback forwarding function. More... | |
void | removeCallbackHandler (XsCallbackPlainC *cb, bool chain=true) |
Remove a handler from the list. More... | |
void | removeChainedManager (CallbackManagerXda *cm) |
Remove achained manager from the list. More... | |
~CallbackManagerXda () | |
Destructor, clears the callback list. More... | |
Static Public Member Functions | |
static int | configurationMessageSearchLimit () |
template<typename T > | |
static UniquePtr< T > | createUniquePtr () |
Constructs a new Communicator of type T and returns it as a UniquePtr<T> More... | |
template<typename T > | |
static UniquePtr< T > | createUniquePtr (T *communicator) |
Creates a UniquePtr<T> from a Communicator*. More... | |
Protected Member Functions | |
XsDevice * | masterDevice () const |
virtual void | prepareForDestruction () |
Prepares communicator for destruction. More... | |
std::shared_ptr< ProtocolManager > | protocolManager () const |
XsResultValue | setAndReturnLastResult (XsResultValue lastResult, XsString const &text=XsString()) const |
Sets the last result and returns it. More... | |
void | setLastResult (XsResultValue lastResult, XsString const &text=XsString()) const |
Sets the last result. More... | |
void | setMasterDeviceId (const XsDeviceId &deviceId) |
Sets a master device ID. More... | |
virtual | ~Communicator () |
Destructor, waits for the last scheduled task to complete and then cleans up the object by calling clear() More... | |
Protected Attributes | |
uint32_t | m_defaultTimeout |
A default timeout variable. More... | |
xsens::Mutex | m_handleMux |
A handle mutex. More... | |
XsResultValue | m_lastResult |
A last result variable. More... | |
XsString | m_lastResultText |
A last result string. More... | |
XsDeviceId | m_masterDeviceId |
A master device ID. More... | |
XsDevice * | m_masterInfo |
A master device object. More... | |
bool | m_preparedForDestruction |
Prepared for destruction boolean variable. More... | |
std::shared_ptr< ProtocolManager > | m_protocolManager |
A shared pointer to protocl manager. More... | |
std::unique_ptr< xsens::ReplyMonitor > | m_replyMonitor |
An unique pointer to a reply monitor. More... | |
A base struct for a communication interface.
Definition at line 95 of file communicator.h.
using Communicator::UniquePtr = std::unique_ptr<T, Deleter> |
Initializes of UniquePtr<T>
Definition at line 113 of file communicator.h.
Communicator::Communicator | ( | void | ) |
Constructor, creates some management objects and clears the rest by calling initialize()
Definition at line 84 of file communicator.cpp.
|
protectedvirtual |
Destructor, waits for the last scheduled task to complete and then cleans up the object by calling clear()
Definition at line 105 of file communicator.cpp.
|
pure virtual |
Aborts loading a logfile.
Implemented in DeviceCommunicator, and MtbFileCommunicator.
|
virtual |
Adds a protocol handler.
handler | an IProtocolHandler |
Reimplemented in MtbFileCommunicator.
Definition at line 303 of file communicator.cpp.
std::shared_ptr< ReplyObject > Communicator::addReplyObject | ( | ReplyObject * | obj | ) |
Add a custom ReplyObject.
[in] | obj | The reply object to add |
Definition at line 297 of file communicator.cpp.
std::shared_ptr< ReplyObject > Communicator::addReplyObject | ( | uint8_t | mid | ) |
Add a MidReplyObject.
[in] | mid | the id of the message to wait for |
Definition at line 274 of file communicator.cpp.
std::shared_ptr< ReplyObject > Communicator::addReplyObject | ( | uint8_t | mid, |
XsSize | offset, | ||
XsSize | size, | ||
uint8_t const * | data | ||
) |
Add a MidAndDataReplyObject.
[in] | mid | the message id of the message to wait for |
[in] | offset | the offset in the data part of the message |
[in] | size | the size of the data in the data part of the message |
[in] | data | pointer to data to wait for (this object does not take ownership of the data) |
Definition at line 287 of file communicator.cpp.
|
virtual |
Reimplemented in ProxyCommunicator.
Definition at line 355 of file communicator.cpp.
XsSize Communicator::childDeviceCount | ( | ) | const |
Definition at line 184 of file communicator.cpp.
|
pure virtual |
Close the log file.
Implemented in DeviceCommunicator, and MtbFileCommunicator.
|
pure virtual |
Closes the open port.
Implemented in MtbFileCommunicator, SerialCommunicator, and ProxyCommunicator.
|
inlinestatic |
Definition at line 316 of file communicator.h.
|
inlinestatic |
Constructs a new Communicator of type T and returns it as a UniquePtr<T>
Definition at line 117 of file communicator.h.
|
inlinestatic |
Creates a UniquePtr<T> from a Communicator*.
Definition at line 124 of file communicator.h.
|
inline |
Definition at line 145 of file communicator.h.
void Communicator::destroy | ( | ) |
Destroys the communicator.
Definition at line 344 of file communicator.cpp.
bool Communicator::doTransaction | ( | const XsMessage & | message | ) |
Write a message and await the reply.
Definition at line 222 of file communicator.cpp.
Write a message and await the reply.
Definition at line 214 of file communicator.cpp.
Write a message and await the reply.
Definition at line 229 of file communicator.cpp.
|
pure virtual |
Write a message and await the reply.
Implemented in DeviceCommunicator, MtbFileCommunicator, and ProxyCommunicator.
|
pure virtual |
Flushes all remaining data on the open port.
Implemented in MtbFileCommunicator, SerialCommunicator, and ProxyCommunicator.
|
pure virtual |
Request a device to get device ID.
Implemented in MtbFileCommunicator, and DeviceCommunicator.
|
pure virtual |
Request a device to go to config mode.
detectRs485 | when set to true it will try to detect and use an RS485 interface |
Implemented in DeviceCommunicator, MtbFileCommunicator, SerialCommunicator, and UsbCommunicator.
|
pure virtual |
Request a device to go to measurement mode.
Implemented in MtbFileCommunicator, DeviceCommunicator, SerialCommunicator, and UsbCommunicator.
|
virtual |
Handles a message.
Reimplemented in SerialCommunicator, DeviceCommunicator, and ProxyCommunicator.
Definition at line 191 of file communicator.cpp.
bool Communicator::hasProtocol | ( | XsProtocolType | type | ) | const |
[in] | type | The protocol type to check |
Definition at line 327 of file communicator.cpp.
|
pure virtual |
Returns true if the other device is docked at this device.
Implemented in MtbFileCommunicator, SerialCommunicator, and ProxyCommunicator.
|
virtual |
Reimplemented in MtbFileCommunicator.
Definition at line 350 of file communicator.cpp.
|
pure virtual |
Implemented in MtbFileCommunicator, SerialCommunicator, and ProxyCommunicator.
|
pure virtual |
Implemented in DeviceCommunicator, and MtbFileCommunicator.
XsResultValue Communicator::lastResult | ( | ) | const |
Get the result value of the last operation.
The result values are codes that describe a failure in more detail.
Definition at line 167 of file communicator.cpp.
XsString Communicator::lastResultText | ( | ) | const |
Get the accompanying error text for the value returned by lastResult() It may provide situation-specific information instead.
Definition at line 177 of file communicator.cpp.
|
pure virtual |
Load a complete logfile.
Implemented in DeviceCommunicator, and MtbFileCommunicator.
|
pure virtual |
Implemented in DeviceCommunicator, and MtbFileCommunicator.
|
pure virtual |
Implemented in DeviceCommunicator, and MtbFileCommunicator.
|
pure virtual |
Implemented in DeviceCommunicator, and MtbFileCommunicator.
|
pure virtual |
Implemented in DeviceCommunicator, and MtbFileCommunicator.
|
protected |
Definition at line 135 of file communicator.cpp.
XsDeviceId Communicator::masterDeviceId | ( | ) | const |
Definition at line 157 of file communicator.cpp.
|
pure virtual |
Open the log file `.
filename | a name of file to open |
Implemented in DeviceCommunicator, and MtbFileCommunicator.
|
pure virtual |
Opens a port.
portInfo | A port information that you want to open |
stage | A openning stage of a communication port |
detectRs485 | When set to true it will try to detect and use an RS485 interface |
Implemented in MtbFileCommunicator, SerialCommunicator, and ProxyCommunicator.
|
pure virtual |
Implemented in MtbFileCommunicator, and SerialCommunicator.
|
protectedvirtual |
Prepares communicator for destruction.
Reimplemented in MtbFileCommunicator, and SerialCommunicator.
Definition at line 114 of file communicator.cpp.
|
protected |
Definition at line 142 of file communicator.cpp.
|
pure virtual |
Read a message from the open file.
msgId | an ID of message |
Implemented in DeviceCommunicator, and MtbFileCommunicator.
|
pure virtual |
Read a message from the start of the open file.
msgId | an ID of message |
maxMsgs | a maximum of messages to read |
Implemented in DeviceCommunicator, and MtbFileCommunicator.
|
pure virtual |
Read multiple similar messages from the start of the open file.
msgId | an ID of message |
maxMsgs | a maximum of messages to read |
Implemented in DeviceCommunicator, and MtbFileCommunicator.
void Communicator::removeProtocolHandler | ( | XsProtocolType | type | ) |
Removes a protocol handler.
type | a XsProtocolType |
Definition at line 317 of file communicator.cpp.
|
pure virtual |
Reopens the port.
stage | A openning stage of a communication port |
skipDeviceIdCheck | When set to true it will skip device ID check |
Implemented in MtbFileCommunicator, SerialCommunicator, and ProxyCommunicator.
|
pure virtual |
Resets the logfile read position.
Implemented in DeviceCommunicator, and MtbFileCommunicator.
bool Communicator::sanityCheck | ( | XsMessage const & | msg | ) | const |
Do a sanity check on a potential message.
msg | a message |
This check is done to prevent message loss due to a 'valid' message in a message Check if the busId can be valid. It can be XS_BID_MASTER and is must be below the number of devices The XS_BID_BROADCAST cannot be checked due to a bug in AwindaStation firmware 1.0.9 which sends flushing indications with BID 0 Later more checks like odd message ID checks may be added here
Definition at line 262 of file communicator.cpp.
|
inlinevirtual |
Schedules to close the open port.
Definition at line 199 of file communicator.h.
|
protected |
Sets the last result and returns it.
res | a result value |
text | a text string |
Definition at line 248 of file communicator.cpp.
Set the credentials required for using the device.
Mostly used for network access
id | The username or system ID or similar |
key | The authentication key or password or similar |
Definition at line 337 of file communicator.cpp.
|
inline |
Sets a default timeout.
Definition at line 139 of file communicator.h.
|
pure virtual |
Set the timeout for the gotoConfig function.
timeout | The desired timeout value in ms, if 0 the default value is used |
Implemented in MtbFileCommunicator, and DeviceCommunicator.
|
pure virtual |
Either disable or enable (default) the keep alive mechanism (if supported by the device)
Implemented in MtbFileCommunicator, and DeviceCommunicator.
|
protected |
Sets the last result.
res | a result value |
text | a text string |
Definition at line 238 of file communicator.cpp.
void Communicator::setMasterDevice | ( | XsDevice * | masterDevice | ) |
Sets a master device.
masterDevice | a master device. |
Definition at line 126 of file communicator.cpp.
|
protected |
|
pure virtual |
Wait for the last processing task to complete in the threadpool.
Implemented in MtbFileCommunicator, and DeviceCommunicator.
|
pure virtual |
Write message to the device.
message | a message |
Implemented in MtbFileCommunicator, and DeviceCommunicator.
|
protected |
A default timeout variable.
Definition at line 372 of file communicator.h.
|
mutableprotected |
A handle mutex.
Definition at line 369 of file communicator.h.
|
mutableprotected |
A last result variable.
Definition at line 363 of file communicator.h.
|
mutableprotected |
A last result string.
Definition at line 366 of file communicator.h.
|
protected |
A master device ID.
Definition at line 357 of file communicator.h.
|
protected |
A master device object.
Definition at line 351 of file communicator.h.
|
protected |
Prepared for destruction boolean variable.
Definition at line 348 of file communicator.h.
|
protected |
A shared pointer to protocl manager.
Definition at line 354 of file communicator.h.
|
protected |
An unique pointer to a reply monitor.
Definition at line 360 of file communicator.h.