Public Types | Public Member Functions | Protected Member Functions | Private Attributes | Static Private Attributes | List of all members
DeviceCommunicator Class Referenceabstract

A class that is used for the communcation with a device. More...

#include <devicecommunicator.h>

Inheritance diagram for DeviceCommunicator:
Inheritance graph
[legend]

Public Types

typedef XsSize RxChannelId
 A typedef for Rx chanel ID. More...
 
- Public Types inherited from Communicator
template<typename T >
using UniquePtr = std::unique_ptr< T, Deleter >
 Initializes of UniquePtr<T> More...
 

Public Member Functions

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...
 
XsResultValue gotoConfig (bool) override
 Request a device to go to config mode. More...
 
uint32_t gotoConfigTimeout () const
 
XsResultValue gotoMeasurement () override
 Request a device to go to measurement mode. More...
 
void handleMessage (const XsMessage &message) override
 Handles a message. More...
 
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< XsMessagereadMessagesFromStartOfFile (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...
 
- Public Member Functions inherited from Communicator
virtual void addProtocolHandler (IProtocolHandler *handler)
 Adds a protocol handler. More...
 
std::shared_ptr< ReplyObjectaddReplyObject (ReplyObject *obj)
 Add a custom ReplyObject. More...
 
std::shared_ptr< ReplyObjectaddReplyObject (uint8_t mid)
 Add a MidReplyObject. More...
 
std::shared_ptr< ReplyObjectaddReplyObject (uint8_t mid, XsSize offset, XsSize size, uint8_t const *data)
 Add a MidAndDataReplyObject. More...
 
virtual bool allowReprocessing () const
 
XsSize childDeviceCount () const
 
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 void flushPort ()=0
 Flushes all remaining data on the open port. 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
 
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
 
virtual bool openPort (const XsPortInfo &portInfo, OpenPortStage stage=OPS_Full, bool detectRs485=false)=0
 Opens a port. More...
 
virtual XsPortInfo portInfo () const =0
 
void removeProtocolHandler (XsProtocolType type)
 Removes a protocol handler. More...
 
virtual bool reopenPort (OpenPortStage stage=OPS_Full, bool skipDeviceIdCheck=false)=0
 Reopens the port. 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...
 
- Public Member Functions inherited from CallbackManagerXda
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...
 

Protected Member Functions

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...
 
MessageExtractormessageExtractor (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...
 
virtual XsResultValue writeRawData (const XsByteArray &data)=0
 Writes a raw data to a device. More...
 
 ~DeviceCommunicator () override
 
- Protected Member Functions inherited from Communicator
XsDevicemasterDevice () const
 
virtual void prepareForDestruction ()
 Prepares communicator for destruction. More...
 
std::shared_ptr< ProtocolManagerprotocolManager () 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...
 

Private Attributes

uint32_t m_gotoConfigTimeout
 
std::vector< MessageExtractorm_messageExtractors
 
RxChannelId m_nextRxChannelId
 

Static Private Attributes

static const uint32_t m_defaultGotoConfigTimeout = 200
 

Additional Inherited Members

- Static Public Member Functions inherited from Communicator
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 Attributes inherited from Communicator
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...
 
XsDevicem_masterInfo
 A master device object. More...
 
bool m_preparedForDestruction
 Prepared for destruction boolean variable. More...
 
std::shared_ptr< ProtocolManagerm_protocolManager
 A shared pointer to protocl manager. More...
 
std::unique_ptr< xsens::ReplyMonitorm_replyMonitor
 An unique pointer to a reply monitor. More...
 

Detailed Description

A class that is used for the communcation with a device.

Definition at line 76 of file devicecommunicator.h.

Member Typedef Documentation

◆ RxChannelId

A typedef for Rx chanel ID.

Definition at line 81 of file devicecommunicator.h.

Constructor & Destructor Documentation

◆ DeviceCommunicator()

DeviceCommunicator::DeviceCommunicator ( RxChannelId  rxChannels = 1)

Default constructor.

Definition at line 83 of file devicecommunicator.cpp.

◆ ~DeviceCommunicator()

DeviceCommunicator::~DeviceCommunicator ( )
overrideprotected

Definition at line 100 of file devicecommunicator.cpp.

Member Function Documentation

◆ abortLoadLogFile()

void DeviceCommunicator::abortLoadLogFile ( )
overridevirtual

Aborts loading a logfile.

Implements Communicator.

◆ addRxChannel()

DeviceCommunicator::RxChannelId DeviceCommunicator::addRxChannel ( )
protected

Adds an RX (receive) channel to the device communicator. Each channel maintains its own message parsing state.

Returns
The id of the added channel

Definition at line 274 of file devicecommunicator.cpp.

◆ closeLogFile()

void DeviceCommunicator::closeLogFile ( )
overridevirtual

Close the log file.

Returns
true if the log file was successfully closed or never open

Implements Communicator.

◆ doTransaction() [1/5]

bool Communicator::doTransaction

Write a message and await the reply.

Definition at line 222 of file communicator.cpp.

◆ doTransaction() [2/5]

bool Communicator::doTransaction

Write a message and await the reply.

Definition at line 214 of file communicator.cpp.

◆ doTransaction() [3/5]

bool Communicator::doTransaction

Write a message and await the reply.

Definition at line 229 of file communicator.cpp.

◆ doTransaction() [4/5]

virtual bool Communicator::doTransaction

Write a message and await the reply.

◆ doTransaction() [5/5]

bool DeviceCommunicator::doTransaction ( const XsMessage msg,
XsMessage rcv,
uint32_t  timeout 
)
overridevirtual

Write a message and await the reply.

Parameters
msgThe message to send
rcvThe message to receive
timeoutThe timeout in ms
Returns
True if successful

Implements Communicator.

Reimplemented in ProxyCommunicator.

Definition at line 110 of file devicecommunicator.cpp.

◆ extractMessages()

XsResultValue DeviceCommunicator::extractMessages ( const XsByteArray rawIn,
std::deque< XsMessage > &  messages,
RxChannelId  channel = 0 
)
protected

Read all messages available in the incoming data stream after adding new data supplied in rawIn.

This function will read all messages present in the DeviceCommunicator's message extracting buffer after appending it with the newly received data.

Parameters
[in]rawInthe newly incoming data
[out]messagesthe list of messages that was extracted
[in]channelthe channel to extract from
Returns
XRV_OK on success, something else on failure

Definition at line 290 of file devicecommunicator.cpp.

◆ getDeviceId()

XsResultValue DeviceCommunicator::getDeviceId ( )
overridevirtual

Request a device to get device ID.

Implements Communicator.

Definition at line 168 of file devicecommunicator.cpp.

◆ gotoConfig()

XsResultValue DeviceCommunicator::gotoConfig ( bool  )
overridevirtual

Request a device to go to config mode.

Implements Communicator.

Reimplemented in SerialCommunicator, and UsbCommunicator.

Definition at line 212 of file devicecommunicator.cpp.

◆ gotoConfigTimeout()

uint32_t DeviceCommunicator::gotoConfigTimeout ( ) const
inline
Returns
The timeout value for gotoConfig function

Definition at line 91 of file devicecommunicator.h.

◆ gotoMeasurement()

XsResultValue DeviceCommunicator::gotoMeasurement ( )
overridevirtual

Request a device to go to measurement mode.

Implements Communicator.

Reimplemented in SerialCommunicator, and UsbCommunicator.

Definition at line 229 of file devicecommunicator.cpp.

◆ handleMessage()

void DeviceCommunicator::handleMessage ( const XsMessage message)
overridevirtual

Handles a message.

Reimplemented from Communicator.

Reimplemented in SerialCommunicator, and ProxyCommunicator.

Definition at line 327 of file devicecommunicator.cpp.

◆ isReadingFromFile()

bool DeviceCommunicator::isReadingFromFile ( ) const
overridevirtual
Returns
true if we are reading from the file

Implements Communicator.

◆ loadLogFile()

void DeviceCommunicator::loadLogFile ( XsDevice device)
overridevirtual

Load a complete logfile.

Implements Communicator.

◆ logFileDate()

XsTimeStamp DeviceCommunicator::logFileDate ( ) const
overridevirtual
Returns
The date of the logfile

Implements Communicator.

◆ logFileName()

XsString DeviceCommunicator::logFileName ( ) const
overridevirtual
Returns
The name of the logfile

Implements Communicator.

◆ logFileReadPosition()

XsFilePos DeviceCommunicator::logFileReadPosition ( ) const
overridevirtual
Returns
The read position of the logfile

Implements Communicator.

◆ logFileSize()

XsFilePos DeviceCommunicator::logFileSize ( ) const
overridevirtual
Returns
The size of the logfile

Implements Communicator.

◆ messageExtractor()

MessageExtractor & DeviceCommunicator::messageExtractor ( RxChannelId  channel = 0)
protected

Returns the message extractor for the given rx channel.

Definition at line 319 of file devicecommunicator.cpp.

◆ messageExtractorCount()

XsSize DeviceCommunicator::messageExtractorCount ( ) const
protected

Returns the number of message extractor this device communicator has.

Definition at line 312 of file devicecommunicator.cpp.

◆ openLogFile()

bool DeviceCommunicator::openLogFile ( const XsString filename)
overridevirtual

Open the log file `.

Parameters
filenamea name of file to open
Returns
true if the file was opened successfully

Implements Communicator.

◆ readLogFile()

virtual XsResultValue DeviceCommunicator::readLogFile ( XsDevice device)
virtual

Read a log file into cache.

Parameters
deviceThe device to read log from
Returns
XRV_OK if successful

◆ readMessage()

XsMessage DeviceCommunicator::readMessage ( uint8_t  msgId = 0)
overridevirtual

Read a message from the open file.

Parameters
msgIdan ID of message
Returns
The message that was read or if no matching message was found a cleared message

Implements Communicator.

◆ readMessageFromStartOfFile()

XsMessage DeviceCommunicator::readMessageFromStartOfFile ( uint8_t  msgId,
int  maxMsgs = 0 
)
overridevirtual

Read a message from the start of the open file.

Parameters
msgIdan ID of message
maxMsgsa maximum of messages to read
Returns
The message that was read or if no matching message was found a cleared message

Implements Communicator.

◆ readMessagesFromStartOfFile()

std::deque<XsMessage> DeviceCommunicator::readMessagesFromStartOfFile ( uint8_t  msgId,
int  maxMsgs = 0 
)
overridevirtual

Read multiple similar messages from the start of the open file.

Parameters
msgIdan ID of message
maxMsgsa maximum of messages to read
Returns
The message that was read or if no matching message was found a cleared message

Implements Communicator.

◆ readSinglePacketFromFile()

virtual XsResultValue DeviceCommunicator::readSinglePacketFromFile ( )
virtual

Read a single XsDataPacket from an open log file.

Returns
XRV_OK if successful

◆ resetLogFileReadPosition()

void DeviceCommunicator::resetLogFileReadPosition ( void  )
overridevirtual

Resets the logfile read position.

Implements Communicator.

◆ setGotoConfigTimeout()

void DeviceCommunicator::setGotoConfigTimeout ( uint32_t  timeout)
overridevirtual

Set the timeout for the gotoConfig function.

\details The goto config function will try to put the device in config mode, but if the communication
channel is less than 100% reliable (especially in half-duplex communication like RS485) this
may fail. For this reason, the function will keep trying until it succeeds or until the timeout
is reached. Every attempt (even a successful one) will take between 20 and 30ms, so the specified
timeout is a lower bound for the actual timeout.

\param timeout The desired timeout value in ms, if 0 the default value is used

Implements Communicator.

Definition at line 158 of file devicecommunicator.cpp.

◆ setKeepAlive()

void DeviceCommunicator::setKeepAlive ( bool  enable)
overridevirtual

Does nothing.

Parameters
enable.

Implements Communicator.

Definition at line 143 of file devicecommunicator.cpp.

◆ waitForLastTaskCompletion()

void DeviceCommunicator::waitForLastTaskCompletion ( )
overridevirtual

Wait for the last processing task to complete in the threadpool.

Implements Communicator.

◆ writeMessage()

bool DeviceCommunicator::writeMessage ( const XsMessage message)
overridevirtual

Write message to the device.

Parameters
messageThe message to write
Returns
true on successful write, false otherwise. This doesn't guarantee proper delivery of the message. Use doTransaction for that.

Implements Communicator.

Definition at line 248 of file devicecommunicator.cpp.

◆ writeRawData()

virtual XsResultValue DeviceCommunicator::writeRawData ( const XsByteArray data)
protectedpure virtual

Writes a raw data to a device.

Parameters
dataThe raw data to write
Returns
XRV_OK if successful

Implemented in ProxyCommunicator, and SerialCommunicator.

Member Data Documentation

◆ m_defaultGotoConfigTimeout

const uint32_t DeviceCommunicator::m_defaultGotoConfigTimeout = 200
staticprivate

Definition at line 151 of file devicecommunicator.h.

◆ m_gotoConfigTimeout

uint32_t DeviceCommunicator::m_gotoConfigTimeout
private

Definition at line 153 of file devicecommunicator.h.

◆ m_messageExtractors

std::vector<MessageExtractor> DeviceCommunicator::m_messageExtractors
private

Definition at line 156 of file devicecommunicator.h.

◆ m_nextRxChannelId

RxChannelId DeviceCommunicator::m_nextRxChannelId
private

Definition at line 155 of file devicecommunicator.h.


The documentation for this class was generated from the following files:


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:21