A class that uses serial port to communicate. More...
#include <serialportcommunicator.h>
Public Member Functions | |
SerialPortCommunicator () | |
![]() | |
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 | |
Static Public Member Functions | |
static Communicator * | construct () |
Constructs new SerialPortCommunicator. 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... | |
Protected Member Functions | |
std::shared_ptr< StreamInterface > | createStreamInterface (const XsPortInfo &pi) override |
Creates a stream interface. More... | |
~SerialPortCommunicator () | |
![]() | |
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 () |
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... | |
![]() | |
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... | |
A class that uses serial port to communicate.
Definition at line 70 of file serialportcommunicator.h.
SerialPortCommunicator::SerialPortCommunicator | ( | ) |
Default constructor
Definition at line 81 of file serialportcommunicator.cpp.
|
protected |
Definition at line 85 of file serialportcommunicator.cpp.
|
static |
Constructs new SerialPortCommunicator.
Definition at line 74 of file serialportcommunicator.cpp.
|
overrideprotectedvirtual |
Creates a stream interface.
pi | The port to use |
Implements SerialCommunicator.
Reimplemented in UsbCommunicator.
Definition at line 93 of file serialportcommunicator.cpp.