Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | List of all members
ProxyCommunicator Class Reference

#include <proxycommunicator.h>

Inheritance diagram for ProxyCommunicator:
Inheritance graph
[legend]

Public Member Functions

bool allowReprocessing () const override
 
void closePort () override
 Closes the port. More...
 
bool doTransaction (const XsMessage &msg, XsMessage &rcv, uint32_t timeout) override
 Write a message and await the reply. More...
 
void flushPort () override
 Flushes all remaining data on the open port. Has no effect for the ProxyCommunicator. More...
 
void handleMessage (const XsMessage &message) override
 Handles a message received on the communication channel. More...
 
void handleReceivedData (const XsByteArray &data)
 Handles data received from the communication channel. More...
 
bool isDockedAt (Communicator *other) const override
 Has no effect for the ProxyCommunicator. Always returns false. More...
 
bool isPortOpen () const override
 Checks if the associated port is open. More...
 
bool openPort (const XsPortInfo &portInfo, OpenPortStage stage=OPS_Full, bool detectRs485=false) override
 Opens a proxy port. 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...
 
 ProxyCommunicator (int channelId, uint32_t channelLatency)
 Constructor. More...
 
XsResultValue readDataToBuffer (XsByteArray &raw) override
 Has no effect for the ProxyCommunicator. More...
 
bool reopenPort (OpenPortStage stage=OPS_Full, bool skipDeviceIdCheck=false) override
 Closes and tries to reopen the port. More...
 
 ~ProxyCommunicator () override
 Destructor. More...
 
- Public Member Functions inherited from SerialCommunicator
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...
 
- Public Member Functions inherited from DeviceCommunicator
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...
 
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< 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...
 
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...
 
- 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...
 
- Public Member Functions inherited from DataParser
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 XsPortInfo createPortInfo (int channelId)
 Creates a default port info object based on the given user-provided channel identifier. More...
 
- 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 Member Functions

std::shared_ptr< StreamInterfacecreateStreamInterface (const XsPortInfo &pi) override
 Creates a stream interface. More...
 
uint32_t defaultInterfaceTimeout () const override
 Returns the default timeout needed for this interface. More...
 
XsResultValue writeRawData (const XsByteArray &data) override
 Writes raw data to the communication channel. More...
 
- Protected Member Functions inherited from SerialCommunicator
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 ()
 
- Protected Member Functions inherited from DeviceCommunicator
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...
 
 ~DeviceCommunicator () override
 
- Protected Member Functions inherited from Communicator
XsDevicemasterDevice () const
 
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...
 
- Protected Member Functions inherited from DataParser
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...
 
- Protected Member Functions inherited from xsens::StandardThread
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 ()
 

Private Attributes

int m_channelId
 
uint32_t m_channelLatency
 

Additional Inherited Members

- Public Types inherited from DeviceCommunicator
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...
 
- Protected Attributes inherited from SerialCommunicator
XsPortInfo m_activePortInfo
 The information about the port this communicator is currently connected to. 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...
 
- Protected Attributes inherited from xsens::StandardThread
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...
 

Detailed Description

The ProxyCommunicator is a communicator that uses an external user defined communication channel. Any data
to be transmitted by XDA to a device is given to the user in a callback (\a onTransmissionRequest) and it is
up to the user how that data is transported. Data coming back from a device is inserted into the ProxyCommunicator
by calling the \a handleReceivedData function. There can be multiple ProxyCommunicators as long as their user-provided
channel identifiers are different.

Definition at line 73 of file proxycommunicator.h.

Constructor & Destructor Documentation

◆ ProxyCommunicator()

ProxyCommunicator::ProxyCommunicator ( int  channelId,
uint32_t  channelLatency 
)

Constructor.

Parameters
channelIdThe user-provided identifier associated with this communicator
channelLatencyThe latency of channel

Definition at line 85 of file proxycommunicator.cpp.

◆ ~ProxyCommunicator()

ProxyCommunicator::~ProxyCommunicator ( )
override

Destructor.

Definition at line 93 of file proxycommunicator.cpp.

Member Function Documentation

◆ allowReprocessing()

bool ProxyCommunicator::allowReprocessing ( ) const
inlineoverridevirtual
Returns
true if reprocessing is allowed

Reimplemented from Communicator.

Definition at line 89 of file proxycommunicator.h.

◆ closePort()

void ProxyCommunicator::closePort ( )
overridevirtual

Closes the port.

Implements Communicator.

Definition at line 106 of file proxycommunicator.cpp.

◆ createPortInfo()

XsPortInfo ProxyCommunicator::createPortInfo ( int  channelId)
static

Creates a default port info object based on the given user-provided channel identifier.

Definition at line 231 of file proxycommunicator.cpp.

◆ createStreamInterface()

std::shared_ptr<StreamInterface> ProxyCommunicator::createStreamInterface ( const XsPortInfo pi)
inlineoverrideprotectedvirtual

Creates a stream interface.

Parameters
piThe port information to use
Returns
The shared pointer to a stream interface

Implements SerialCommunicator.

Definition at line 101 of file proxycommunicator.h.

◆ defaultInterfaceTimeout()

uint32_t ProxyCommunicator::defaultInterfaceTimeout ( ) const
overrideprotectedvirtual

Returns the default timeout needed for this interface.

Reimplemented from SerialCommunicator.

Definition at line 242 of file proxycommunicator.cpp.

◆ doTransaction()

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

Write a message and await the reply.

Reimplemented from DeviceCommunicator.

Definition at line 199 of file proxycommunicator.cpp.

◆ flushPort()

void ProxyCommunicator::flushPort ( )
overridevirtual

Flushes all remaining data on the open port. Has no effect for the ProxyCommunicator.

Implements Communicator.

Definition at line 99 of file proxycommunicator.cpp.

◆ handleMessage()

void ProxyCommunicator::handleMessage ( const XsMessage message)
overridevirtual

Handles a message received on the communication channel.

Implements DataParser.

Definition at line 214 of file proxycommunicator.cpp.

◆ handleReceivedData()

void ProxyCommunicator::handleReceivedData ( const XsByteArray data)

Handles data received from the communication channel.

Definition at line 193 of file proxycommunicator.cpp.

◆ isDockedAt()

bool ProxyCommunicator::isDockedAt ( Communicator other) const
overridevirtual

Has no effect for the ProxyCommunicator. Always returns false.

Implements Communicator.

Definition at line 178 of file proxycommunicator.cpp.

◆ isPortOpen()

bool ProxyCommunicator::isPortOpen ( ) const
overridevirtual

Checks if the associated port is open.

Implements Communicator.

Definition at line 113 of file proxycommunicator.cpp.

◆ openPort()

bool ProxyCommunicator::openPort ( const XsPortInfo portInfo,
OpenPortStage  stage = OPS_Full,
bool  detectRs485 = false 
)
overridevirtual

Opens a proxy port.

Parameters
portInfoThe port information
stageThe open port stage
detectRs485Enable more extended scan to detect rs485 devices

If successful information on the connected device is available in the port info

See also
portInfo
Returns
True if successful

Implements Communicator.

Definition at line 125 of file proxycommunicator.cpp.

◆ processBufferedData()

XsResultValue ProxyCommunicator::processBufferedData ( const XsByteArray rawIn,
std::deque< XsMessage > &  messages 
)
overridevirtual

Read all messages from the buffered read data after adding new data supplied in rawIn.

Parameters
rawInThe byte array with all data
messagesThe message to process
Returns
The messages that were read.

Implements DataParser.

Definition at line 224 of file proxycommunicator.cpp.

◆ readDataToBuffer()

XsResultValue ProxyCommunicator::readDataToBuffer ( XsByteArray raw)
overridevirtual

Has no effect for the ProxyCommunicator.

Implements DataParser.

Definition at line 206 of file proxycommunicator.cpp.

◆ reopenPort()

bool ProxyCommunicator::reopenPort ( OpenPortStage  stage = OPS_Full,
bool  skipDeviceIdCheck = false 
)
overridevirtual

Closes and tries to reopen the port.

Parameters
stageThe current stage of port
skipDeviceIdCheckIf set to true the it will skip device id check
Returns
true if the the port could be successfully reopened

Implements Communicator.

Definition at line 164 of file proxycommunicator.cpp.

◆ writeRawData()

XsResultValue ProxyCommunicator::writeRawData ( const XsByteArray data)
overrideprotectedvirtual

Writes raw data to the communication channel.

Implements DeviceCommunicator.

Definition at line 185 of file proxycommunicator.cpp.

Member Data Documentation

◆ m_channelId

int ProxyCommunicator::m_channelId
private

Definition at line 110 of file proxycommunicator.h.

◆ m_channelLatency

uint32_t ProxyCommunicator::m_channelLatency
private

Definition at line 111 of file proxycommunicator.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:22