A class that is used for the communcation with a mtb file. More...
#include <mtbfilecommunicator.h>
Public Member Functions | |
void | abortLoadLogFile () override |
Abort a process that takes a long time to complete. More... | |
void | addProtocolHandler (IProtocolHandler *handler) override |
Add the protocol handler. More... | |
void | closeLogFile () override |
Close the log file. More... | |
void | closePort () override |
Closes the open port. More... | |
bool | doTransaction (const XsMessage &msg, XsMessage &rcv, uint32_t timeout) override |
Pretend to be a live system. More... | |
void | flushPort () override |
Flushes all remaining data on the open port. More... | |
XsResultValue | getDeviceId () override |
Request a device to get device ID. 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... | |
bool | isDockedAt (Communicator *other) const override |
Returns true if the other device is docked at this device. More... | |
bool | isLoadLogFileInProgress () const override |
bool | isPortOpen () const override |
bool | isReadingFromFile () const override |
Return whether we are reading from file. More... | |
void | loadLogFile (XsDevice *device) override |
Load a log file with thread pool. More... | |
XsTimeStamp | logFileDate () const override |
Retrieve the date of the open log file. More... | |
XsString | logFileName () const override |
Retrieve the name of the open log file or an empty string if no log file is open. More... | |
XsFilePos | logFileReadPosition () const override |
Retrieve the read position of the log file. More... | |
XsFilePos | logFileSize () const override |
Retrieve the size of the open log file in bytes. More... | |
MtbFileCommunicator () | |
Default constructor. More... | |
bool | openLogFile (const XsString &filename) override |
Open a log file for input. More... | |
bool | openPort (const XsPortInfo &portInfo, OpenPortStage stage=OPS_Full, bool detectRs485=false) override |
Opens a port. More... | |
XsPortInfo | portInfo () const override |
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... | |
bool | reopenPort (OpenPortStage stage=OPS_Full, bool skipDeviceIdCheck=false) override |
Reopens the port. More... | |
void | resetLogFileReadPosition (void) override |
Restart reading from the start of the open log file. More... | |
void | setGotoConfigTimeout (uint32_t timeout) override |
Set the timeout for the gotoConfig function. More... | |
void | setKeepAlive (bool enable) override |
Either disable or enable (default) the keep alive mechanism (if supported by the device) More... | |
bool | writeMessage (const XsMessage &message) override |
Write message to the device. 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... | |
virtual void | handleMessage (const XsMessage &message) |
Handles a message. More... | |
bool | hasProtocol (XsProtocolType type) 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... | |
Static Public Member Functions | |
static Communicator * | construct () |
Constructs new MtbFileCommunicator. 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 | |
MtbFileCommunicator (std::shared_ptr< IoInterfaceFile > const &ioInterfaceFile) | |
Constructor that uses ioInterfaceFile. More... | |
void | prepareForDestruction () override |
Prepares for the destruction. More... | |
virtual XsResultValue | readLogFile (XsDevice *device) override |
Read a log file into cache. More... | |
virtual XsMessage | readNextMessage () |
Read the next message from the open file. More... | |
virtual XsResultValue | readSinglePacketFromFile () override |
Read a single XsDataPacket from an open log file. More... | |
void | waitForLastTaskCompletion () override |
Wait for the last processing task to complete in the threadpool. More... | |
~MtbFileCommunicator () | |
![]() | |
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... | |
![]() | |
virtual | ~FileLoader () |
Private Member Functions | |
void | completeAllThreadedWork () |
Completes all threaded work. More... | |
uint32_t | timeoutToMaxMessages (uint32_t timeout) const |
A rather stupid function that tries to convert a live timeout into a number of messages. More... | |
Private Attributes | |
bool | m_abortLoadLogFile |
std::deque< XsMessage > * | m_extractedMessages |
MessageExtractor * | m_extractor |
std::shared_ptr< IoInterfaceFile > | m_ioInterfaceFile |
xsens::ThreadPool::TaskId | m_loadFileTaskId |
Additional Inherited Members | |
![]() | |
template<typename T > | |
using | UniquePtr = std::unique_ptr< T, Deleter > |
Initializes of UniquePtr<T> 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... | |
A class that is used for the communcation with a mtb file.
Definition at line 79 of file mtbfilecommunicator.h.
MtbFileCommunicator::MtbFileCommunicator | ( | ) |
Default constructor.
Definition at line 98 of file mtbfilecommunicator.cpp.
|
protected |
Constructor that uses ioInterfaceFile.
Definition at line 112 of file mtbfilecommunicator.cpp.
|
protected |
Destructor
Definition at line 127 of file mtbfilecommunicator.cpp.
|
overridevirtual |
Abort a process that takes a long time to complete.
This currently only includes readLogFile()
Implements Communicator.
Definition at line 499 of file mtbfilecommunicator.cpp.
|
overridevirtual |
Add the protocol handler.
handler | : The protocol hanlder to add |
Reimplemented from Communicator.
Definition at line 719 of file mtbfilecommunicator.cpp.
|
overridevirtual |
Close the log file.
Implements Communicator.
Definition at line 197 of file mtbfilecommunicator.cpp.
|
overridevirtual |
Closes the open port.
Implements Communicator.
|
private |
Completes all threaded work.
Definition at line 181 of file mtbfilecommunicator.cpp.
|
static |
Constructs new MtbFileCommunicator.
Definition at line 91 of file mtbfilecommunicator.cpp.
|
overridevirtual |
Pretend to be a live system.
msg | The message to send |
rcv | The message to receive |
timeout | The timeout in ms |
This one is nowhere near finished, but it does the trick for simple systems if a reply is available.
Implements Communicator.
Definition at line 147 of file mtbfilecommunicator.cpp.
|
overridevirtual |
Flushes all remaining data on the open port.
Implements Communicator.
|
overridevirtual |
|
overridevirtual |
Request a device to go to config mode.
detectRs485 | when set to true it will try to detect and use an RS485 interface |
Implements Communicator.
|
overridevirtual |
|
overridevirtual |
Returns true if the other device is docked at this device.
Implements Communicator.
|
overridevirtual |
Reimplemented from Communicator.
Definition at line 711 of file mtbfilecommunicator.cpp.
|
overridevirtual |
Implements Communicator.
|
overridevirtual |
Return whether we are reading from file.
Implements Communicator.
Definition at line 649 of file mtbfilecommunicator.cpp.
|
overridevirtual |
Load a log file with thread pool.
Implements Communicator.
Definition at line 419 of file mtbfilecommunicator.cpp.
|
overridevirtual |
Retrieve the date of the open log file.
Implements Communicator.
Definition at line 600 of file mtbfilecommunicator.cpp.
|
overridevirtual |
Retrieve the name of the open log file or an empty string if no log file is open.
Implements Communicator.
Definition at line 577 of file mtbfilecommunicator.cpp.
|
overridevirtual |
Retrieve the read position of the log file.
This function will return the current read position in the open log file in bytes from the start.
Implements Communicator.
Definition at line 617 of file mtbfilecommunicator.cpp.
|
overridevirtual |
Retrieve the size of the open log file in bytes.
Implements Communicator.
Definition at line 590 of file mtbfilecommunicator.cpp.
|
overridevirtual |
Open a log file for input.
This function opens the supplied log file for reading. The function will fail if a serial connection is currently open.
filename | The name of the file to open. It is recommended to use a fully qualified path+filename. |
Implements Communicator.
Definition at line 511 of file mtbfilecommunicator.cpp.
|
overridevirtual |
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 |
Implements Communicator.
|
overridevirtual |
Implements Communicator.
|
overrideprotectedvirtual |
Prepares for the destruction.
Reimplemented from Communicator.
Definition at line 168 of file mtbfilecommunicator.cpp.
|
overrideprotectedvirtual |
Read a log file into cache.
device | : The device to read log from |
Read all data for inf into the cache
Implements FileLoader.
Definition at line 437 of file mtbfilecommunicator.cpp.
|
overridevirtual |
Read a message from the open file.
This function will attempt to read a full message from the open device (file or COM port or USB port). If msgId is non-0, the function will look for a specific message ID. The function will read from the device, but it won't wait for data to become available.
msgId | Either 0 to read the first available message or non-0 to look for a specific message with this ID. |
Implements Communicator.
Definition at line 662 of file mtbfilecommunicator.cpp.
|
overridevirtual |
Read a message from the start of the open file.
This function will reset the read position in the file to the start and will then search for the message with the given message ID. After the message has been found (or not) the read position will be restored to its original position.
msgId | The ID of the message to search for |
maxMsgs | Optional parameter to limit the maximum number of messages to search. When 0, the function will continue until the message has been found or the end of the file has been reached. |
Implements Communicator.
Definition at line 211 of file mtbfilecommunicator.cpp.
|
overridevirtual |
Read multiple similar messages from the start of the open file.
This function will reset the read position in the file to the start and will then search for all messages with the given message ID. Afterwards the read position will be restored to its original position.
msgId | The ID of the message to search for. |
maxMsgs | Optional parameter to limit the maximum number of messages to search. When 0, the function will continue until the end of the file has been reached. |
Implements Communicator.
Definition at line 264 of file mtbfilecommunicator.cpp.
|
protectedvirtual |
Read the next message from the open file.
Definition at line 687 of file mtbfilecommunicator.cpp.
|
overrideprotectedvirtual |
Read a single XsDataPacket from an open log file.
Read a single XsDataPacket from the log file and place it in the correct data cache(s)
Implements FileLoader.
Definition at line 485 of file mtbfilecommunicator.cpp.
|
overridevirtual |
Reopens the port.
stage | A openning stage of a communication port |
skipDeviceIdCheck | When set to true it will skip device ID check |
Implements Communicator.
|
overridevirtual |
Restart reading from the start of the open log file.
This function resets the read position to the start of the open log file. Only the read position is affected, the write position remains the same.
Implements Communicator.
Definition at line 636 of file mtbfilecommunicator.cpp.
|
overridevirtual |
Set the timeout for the gotoConfig function.
timeout | The desired timeout value in ms, if 0 the default value is used |
Implements Communicator.
|
overridevirtual |
Either disable or enable (default) the keep alive mechanism (if supported by the device)
Implements Communicator.
A rather stupid function that tries to convert a live timeout into a number of messages.
Definition at line 135 of file mtbfilecommunicator.cpp.
|
overrideprotectedvirtual |
Wait for the last processing task to complete in the threadpool.
This function is usually called after abort() to make sure that no more processing is going on.
Implements Communicator.
Definition at line 190 of file mtbfilecommunicator.cpp.
|
overridevirtual |
Write message to the device.
message | a message |
Implements Communicator.
|
private |
Definition at line 134 of file mtbfilecommunicator.h.
|
private |
Definition at line 138 of file mtbfilecommunicator.h.
|
private |
Definition at line 137 of file mtbfilecommunicator.h.
|
private |
Definition at line 133 of file mtbfilecommunicator.h.
|
private |
Definition at line 135 of file mtbfilecommunicator.h.