A class that uses serial communication. More...
#include <serialcommunicator.h>
Public Member Functions | |
void | closePort () override |
Closes the port. More... | |
XsVersion | firmwareRevision () |
void | flushPort () override |
Flushes all remaining data on the open port. More... | |
XsResultValue | gotoConfig (bool detectRs485=false) override |
Request a device to go to config mode. More... | |
XsResultValue | gotoMeasurement () override |
Request a device to go to measurement mode. More... | |
void | handleMessage (const XsMessage &msg) override |
Handles a message. More... | |
XsVersion | hardwareRevision () |
bool | isDockedAt (Communicator *other) const override |
bool | isPortOpen () const override |
bool | openPort (const XsPortInfo &portInfo, OpenPortStage stage=OPS_Full, bool detectRs485=false) override |
Open a serial port and return the main device connected to it. More... | |
XsPortInfo | portInfo () const override |
bool | reopenPort (OpenPortStage stage=OPS_Full, bool skipDeviceIdCheck=false) override |
Reopens the port. More... | |
SerialCommunicator () | |
Default constructor. More... | |
XsResultValue | writeRawData (const XsByteArray &data) override |
Write raw data to the open COM or USB port. More... | |
![]() | |
void | abortLoadLogFile () override |
Aborts loading a logfile. More... | |
void | closeLogFile () override |
Close the log file. More... | |
DeviceCommunicator (RxChannelId rxChannels=1) | |
Default constructor. 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 bool | doTransaction (const XsMessage &msg, XsMessage &rcv, uint32_t timeout) override |
Write a message and await the reply. More... | |
XsResultValue | getDeviceId () override |
Request a device to get device ID. More... | |
uint32_t | gotoConfigTimeout () const |
bool | isReadingFromFile () const override |
void | loadLogFile (XsDevice *device) override |
Load a complete logfile. More... | |
XsTimeStamp | logFileDate () const override |
XsString | logFileName () const override |
XsFilePos | logFileReadPosition () const override |
XsFilePos | logFileSize () const override |
bool | openLogFile (const XsString &filename) override |
Open the log file `. More... | |
virtual XsResultValue | readLogFile (XsDevice *device) |
Read a log file into cache. More... | |
XsMessage | readMessage (uint8_t msgId=0) override |
Read a message from the open file. More... | |
XsMessage | readMessageFromStartOfFile (uint8_t msgId, int maxMsgs=0) override |
Read a message from the start of the open file. More... | |
std::deque< XsMessage > | readMessagesFromStartOfFile (uint8_t msgId, int maxMsgs=0) override |
Read multiple similar messages from the start of the open file. More... | |
virtual XsResultValue | readSinglePacketFromFile () |
Read a single XsDataPacket from an open log file. More... | |
void | resetLogFileReadPosition (void) override |
Resets the logfile read position. More... | |
void | setGotoConfigTimeout (uint32_t timeout) override |
Set the timeout for the gotoConfig function. More... | |
void | setKeepAlive (bool enable) override |
Does nothing. More... | |
void | waitForLastTaskCompletion () override |
Wait for the last processing task to complete in the threadpool. More... | |
bool | writeMessage (const XsMessage &message) override |
Write message to the device. 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 |
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... | |
bool | hasProtocol (XsProtocolType type) const |
virtual bool | isLoadLogFileInProgress () const |
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... | |
XsDeviceId | masterDeviceId () const |
void | removeProtocolHandler (XsProtocolType type) |
Removes a protocol handler. 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... | |
void | setMasterDevice (XsDevice *masterDevice) |
Sets a master 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... | |
![]() | |
void | addRawData (const XsByteArray &arr) |
Adds the raw data to an array. More... | |
void | clear () |
Clears the data queue. More... | |
DataParser () | |
Default constructor. More... | |
virtual const char * | parserType () const |
void | terminate () |
Terminates the thread. More... | |
~DataParser () override | |
Protected Member Functions | |
virtual std::shared_ptr< StreamInterface > | createStreamInterface (const XsPortInfo &pi)=0 |
Creates a stream interface. More... | |
virtual uint32_t | defaultInterfaceTimeout () const |
virtual XsResultValue | getFirmwareRevision () |
Requests the firmware revision from the connected device. More... | |
virtual XsResultValue | getHardwareRevision () |
Requests the hardware revision from the connected device. More... | |
bool | isActive () const |
virtual void | prepareForDestruction () override |
Prepares for a destruction. More... | |
XsResultValue | processBufferedData (const XsByteArray &rawIn, std::deque< XsMessage > &messages) override |
Read all messages from the buffered read data after adding new data supplied in rawIn. More... | |
XsResultValue | readDataToBuffer (XsByteArray &raw) override |
Read available data from the open IO device. More... | |
void | setDoGotoConfig (bool doit) |
Sets do go to config in a thread. More... | |
void | stopPollThread () |
Stops polling the thread. More... | |
virtual | ~SerialCommunicator () |
![]() | |
RxChannelId | addRxChannel () |
Adds an RX (receive) channel to the device communicator. Each channel maintains its own message parsing state. More... | |
XsResultValue | extractMessages (const XsByteArray &rawIn, std::deque< XsMessage > &messages, RxChannelId channel=0) |
Read all messages available in the incoming data stream after adding new data supplied in rawIn. More... | |
MessageExtractor & | messageExtractor (RxChannelId=0) |
Returns the message extractor for the given rx channel. More... | |
XsSize | messageExtractorCount () const |
Returns the number of message extractor this device communicator has. More... | |
~DeviceCommunicator () override | |
![]() | |
XsDevice * | masterDevice () const |
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... | |
![]() | |
void | initFunction () override |
Initializes the thread. More... | |
int32_t | innerFunction () override |
The inner thread function. More... | |
void | signalStopThread (void) override |
Tells the thread to stop but does not wait for it to end. More... | |
![]() | |
virtual void | exitFunction (void) |
Virtual exit function. More... | |
XsThread | threadHandle () const |
Return the thread handle. More... | |
XsThreadId | getThreadId (void) const |
bool | isAlive (void) volatile const noexcept |
bool | isRunning (void) volatile const noexcept |
Returns whether the thread is currently running. More... | |
bool | isTerminating () volatile const noexcept |
Returns whether the thread should (have) terminate(d) More... | |
bool | setPriority (XsThreadPriority pri) |
Sets the priority of the thread. More... | |
StandardThread () | |
bool | startThread (const char *name=NULL) |
Starts the thread. More... | |
void | stopThread (void) noexcept |
Tells the thread to stop and waits for it to end. More... | |
virtual | ~StandardThread () |
Protected Attributes | |
XsPortInfo | m_activePortInfo |
The information about the port this communicator is currently connected to. More... | |
![]() | |
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... | |
![]() | |
pthread_attr_t | m_attr |
Duplicates m_stop functionality for external dependent classes such as Semaphore. More... | |
bool | m_running |
Indicates that the thread is running. More... | |
volatile std::atomic_bool | m_stop |
Indicates that the thread should stop. Derived classes should check isTerminating() instead of directly polling this value when checking if the thread should stop. However, there are some cases (tests, SignallingThread) where direct access from within the class is desired, which is why the vlaue is protected instead of private. More... | |
volatile std::atomic_bool | m_yieldOnZeroSleep |
When true, a sleep value of 0 returned by innerFunction will trigger a thread yield operation. When false, the next cycle is started immediately. More... | |
Private Member Functions | |
void | startPollThread () |
Starts polling the thread. More... | |
Private Attributes | |
XsVersion | m_firmwareRevision |
XsVersion | m_hardwareRevision |
std::shared_ptr< StreamInterface > | m_streamInterface |
MtThread | m_thread |
Additional Inherited Members | |
![]() | |
typedef XsSize | RxChannelId |
A typedef for Rx chanel ID. More... | |
![]() | |
template<typename T > | |
using | UniquePtr = std::unique_ptr< T, Deleter > |
Initializes of UniquePtr<T> More... | |
![]() | |
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... | |
A class that uses serial communication.
Definition at line 75 of file serialcommunicator.h.
SerialCommunicator::SerialCommunicator | ( | ) |
Default constructor.
Definition at line 86 of file serialcommunicator.cpp.
|
protectedvirtual |
Definition at line 95 of file serialcommunicator.cpp.
|
overridevirtual |
|
protectedpure virtual |
Creates a stream interface.
pi | The port information to use |
Implemented in ProxyCommunicator, UsbCommunicator, and SerialPortCommunicator.
|
inlineprotectedvirtual |
Reimplemented in ProxyCommunicator.
Definition at line 119 of file serialcommunicator.h.
XsVersion SerialCommunicator::firmwareRevision | ( | ) |
Definition at line 476 of file serialcommunicator.cpp.
|
overridevirtual |
Flushes all remaining data on the open port.
Implements Communicator.
Definition at line 189 of file serialcommunicator.cpp.
|
protectedvirtual |
Requests the firmware revision from the connected device.
Definition at line 443 of file serialcommunicator.cpp.
|
protectedvirtual |
Requests the hardware revision from the connected device.
Definition at line 460 of file serialcommunicator.cpp.
|
overridevirtual |
Request a device to go to config mode.
Reimplemented from DeviceCommunicator.
Reimplemented in UsbCommunicator.
Definition at line 138 of file serialcommunicator.cpp.
|
overridevirtual |
Request a device to go to measurement mode.
Reimplemented from DeviceCommunicator.
Reimplemented in UsbCommunicator.
Definition at line 121 of file serialcommunicator.cpp.
|
overridevirtual |
Handles a message.
msg | The XsMessage to handle |
Implements DataParser.
Definition at line 424 of file serialcommunicator.cpp.
XsVersion SerialCommunicator::hardwareRevision | ( | ) |
Definition at line 483 of file serialcommunicator.cpp.
|
protected |
Definition at line 358 of file serialcommunicator.cpp.
|
overridevirtual |
other | The communicator of an other device |
Implements Communicator.
Definition at line 376 of file serialcommunicator.cpp.
|
overridevirtual |
Implements Communicator.
Definition at line 229 of file serialcommunicator.cpp.
|
overridevirtual |
Open a serial port and return the main device connected to it.
Implements Communicator.
Definition at line 243 of file serialcommunicator.cpp.
|
overridevirtual |
Implements Communicator.
Definition at line 236 of file serialcommunicator.cpp.
|
overrideprotectedvirtual |
Prepares for a destruction.
Reimplemented from Communicator.
Definition at line 101 of file serialcommunicator.cpp.
|
overrideprotectedvirtual |
Read all messages from the buffered read data after adding new data supplied in rawIn.
rawIn | The byte array with all data |
messages | The message to process |
This function will read all present messages in the read buffer. In order for this function to work, you need to call readDataToBuffer() first.
Implements DataParser.
Definition at line 436 of file serialcommunicator.cpp.
|
overrideprotectedvirtual |
Read available data from the open IO device.
This function will attempt to read all available data from the open device (COM port or USB port). The function will read from the device, but it won't wait for data to become available.
raw | A buffer that will receive the read data. |
Implements DataParser.
Definition at line 391 of file serialcommunicator.cpp.
|
overridevirtual |
|
protected |
Sets do go to config in a thread.
doit | The boolean value to set |
Definition at line 366 of file serialcommunicator.cpp.
|
private |
Starts polling the thread.
Definition at line 204 of file serialcommunicator.cpp.
|
protected |
Stops polling the thread.
Definition at line 197 of file serialcommunicator.cpp.
|
overridevirtual |
Write raw data to the open COM or USB port.
Implements DeviceCommunicator.
Definition at line 180 of file serialcommunicator.cpp.
|
protected |
The information about the port this communicator is currently connected to.
Definition at line 124 of file serialcommunicator.h.
|
private |
Definition at line 129 of file serialcommunicator.h.
|
private |
Definition at line 130 of file serialcommunicator.h.
|
private |
Definition at line 128 of file serialcommunicator.h.
|
private |
Definition at line 127 of file serialcommunicator.h.