Go to the documentation of this file.
73 #ifdef LOG_COMMUNICATOR_RX_TX
84 : m_gotoConfigTimeout(m_defaultGotoConfigTimeout)
85 , m_nextRxChannelId(0)
86 #ifdef LOG_COMMUNICATOR_RX_TX_TIMESTAMPED
90 assert(rxChannels > 0);
92 for (
XsSize i = 0; i < rxChannels; ++i)
95 #ifdef LOG_COMMUNICATOR_RX_TX
122 rcv = reply->message(timeout);
123 if (rcv.getMessageId() == expected)
134 JLALERTG(
"Timeout waiting for reply to " <<
msg.getMessageId() <<
", timeout = " << timeout <<
" ms.");
177 uint64_t deviceId = rcv_did.getDataLong();
178 if (rcv_did.getDataSize() == 8)
182 if (!did1.isLegacyDeviceId() || !did2.isLegacyDeviceId())
183 deviceId = rcv_did.getDataLongLong();
191 const char* pc = (
const char*) rcv_pdc.getDataBuffer();
192 std::string result(pc ? pc :
"", rcv_pdc.getDataSize());
193 std::string::size_type thingy = result.find(
" ");
194 if (thingy < rcv_pdc.getDataSize())
195 result.erase(result.begin() + (
unsigned)thingy, result.end());
196 productCode = result;
201 uint16_t hardwareVersion = 0;
203 hardwareVersion = rcv_hw.getDataShort();
220 JLALERTG(
"Failed to go to config, XRV: " << rcv.toResultValue());
223 JLDEBUGG(
"Received gotoConfig ACK");
240 JLDEBUGG(
"Now in measurement mode");
260 #ifdef LOG_COMMUNICATOR_RX_TX
261 logTxStream(message);
301 for (
auto const&
msg : messages)
329 #ifdef LOG_COMMUNICATOR_RX_TX
330 logRxStream(message);
349 return std::deque<XsMessage>();
415 #ifdef LOG_COMMUNICATOR_RX_TX
416 void DeviceCommunicator::generateLogFiles()
418 XsString date = XsTime::getDateAsString();
419 XsString time = XsTime::getTimeAsString();
421 #ifdef LOG_COMMUNICATOR_RX_TX_TIMESTAMPED
427 auto generateFilename = [&](
XsString const & stream)
429 std::string temp = xprintf(
"communicator_%s_%s_%s.%s", stream.c_str(), date.c_str(), time.c_str(), extension.c_str());
433 m_rxLog.create(generateFilename(
"rx"),
false);
434 m_txLog.create(generateFilename(
"tx"),
false);
437 void DeviceCommunicator::logTxStream(
XsMessage const& msg)
439 assert(m_txLog.isOpen());
441 #ifdef LOG_COMMUNICATOR_RX_TX_TIMESTAMPED
442 XsTimeStamp diff = XsTimeStamp::now() - m_logStart;
443 std::string timestamp = xprintf(
"%d ", diff.msTime());
444 m_txLog.write(timestamp.c_str(), 1, timestamp.length());
447 m_txLog.write(
msg.rawMessage().data(), 1,
msg.rawMessage().size());
451 void DeviceCommunicator::logRxStream(
XsMessage const& msg)
453 assert(m_rxLog.isOpen());
455 #ifdef LOG_COMMUNICATOR_RX_TX_TIMESTAMPED
456 XsTimeStamp diff = XsTimeStamp::now() - m_logStart;
457 std::string timestamp = xprintf(
"%d ", diff.msTime());
458 m_rxLog.write(timestamp.c_str(), 1, timestamp.length());
461 m_rxLog.write(
msg.rawMessage().data(), 1,
msg.rawMessage().size());
uint32_t m_gotoConfigTimeout
#define XS_BID_MASTER
The bus identifier of the master device.
XsString lastResultText() const
Get the accompanying error text for the value returned by lastResult() It may provide situation-speci...
void loadLogFile(XsDevice *device) override
Load a complete logfile.
struct XsMessage XsMessage
A list of uint8_t values.
uint32_t defaultTimeout() const
virtual bool doTransaction(const XsMessage &msg, XsMessage &rcv, uint32_t timeout) override
Write a message and await the reply.
void handleMessage(const XsMessage &message) override
Handles a message.
std::shared_ptr< ProtocolManager > protocolManager() const
@ XRV_TIMEOUT
258: A timeout occurred
void setMasterDeviceId(const XsDeviceId &deviceId)
Sets a master device ID.
XsDeviceId masterDeviceId() const
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.
XsResultValue gotoConfig(bool) override
Request a device to go to config mode.
virtual void handleMessage(const XsMessage &message)
Handles a message.
std::shared_ptr< ReplyObject > addReplyObject(uint8_t mid)
Add a MidReplyObject.
uint32_t gotoConfigTimeout() const
@ XRV_INVALIDMSG
4: The message is invalid or not implemented
bool openLogFile(const XsString &filename) override
Open the log file `.
RxChannelId addRxChannel()
Adds an RX (receive) channel to the device communicator. Each channel maintains its own message parsi...
@ XRV_ERROR
256: A generic error occurred
virtual XSNOEXPORT void onMessageReceived(const XsMessage &message)
static const uint32_t m_defaultGotoConfigTimeout
@ XRV_OK
0: Operation was performed successfully
static int composeMessage(XsByteArray &raw, const XsMessage &msg)
Compose a message for transmission.
XsResultValue
Xsens result values.
XsMessage readMessage(uint8_t msgId=0) override
Read a message from the open file.
XsResultValue lastResult() const
Get the result value of the last operation.
XsSize RxChannelId
A typedef for Rx chanel ID.
void closeLogFile() override
Close the log file.
bool writeMessage(const XsMessage &message) override
Write message to the device.
DeviceCommunicator(RxChannelId rxChannels=1)
Default constructor.
virtual XsResultValue writeRawData(const XsByteArray &data)=0
Writes a raw data to a device.
std::vector< MessageExtractor > m_messageExtractors
MessageExtractor & messageExtractor(RxChannelId=0)
Returns the message extractor for the given rx channel.
XsString logFileName() const override
~DeviceCommunicator() override
XsFilePos logFileReadPosition() const override
std::deque< XsMessage > readMessagesFromStartOfFile(uint8_t msgId, int maxMsgs=0) override
Read multiple similar messages from the start of the open file.
XsDevice * masterDevice() const
void setKeepAlive(bool enable) override
Does nothing.
size_t XsSize
XsSize must be unsigned number!
void abortLoadLogFile() override
Aborts loading a logfile.
XsXbusMessageId
Xsens Xbus Message Identifiers.
virtual XsResultValue readLogFile(XsDevice *device)
Read a log file into cache.
struct XsDeviceId XsDeviceId
Structure for storing a single message.
XsTimeStamp logFileDate() const override
XsFilePos logFileSize() const override
virtual XsResultValue readSinglePacketFromFile()
Read a single XsDataPacket from an open log file.
Contains an Xsens device ID and provides operations for determining the type of device.
virtual XSNOEXPORT void onMessageSent(const XsMessage &message)
XsMessage readMessageFromStartOfFile(uint8_t msgId, int maxMsgs=0) override
Read a message from the start of the open file.
XsResultValue gotoMeasurement() override
Request a device to go to measurement mode.
RxChannelId m_nextRxChannelId
XsSize messageExtractorCount() const
Returns the number of message extractor this device communicator has.
bool isReadingFromFile() const override
void setGotoConfigTimeout(uint32_t timeout) override
Set the timeout for the gotoConfig function.
@ XRV_CONFIGCHECKFAIL
293: A configuration-time check of the device failed
XsResultValue getDeviceId() override
Request a device to get device ID.
@ XRV_UNSUPPORTED
303: The requested functionality is not supported by the device
void setLastResult(XsResultValue lastResult, XsString const &text=XsString()) const
Sets the last result.
@ XMID_ReqHardwareVersion
@ XRV_COULDNOTREADSETTINGS
271: A required settings file could not be opened or is missing some data
XsResultValue setAndReturnLastResult(XsResultValue lastResult, XsString const &text=XsString()) const
Sets the last result and returns it.
int64_t XsFilePos
The type that is used for positioning inside a file.
A 0-terminated managed string of characters.
This class contains method to set, retrieve and compare timestamps.
void waitForLastTaskCompletion() override
Wait for the last processing task to complete in the threadpool.
void resetLogFileReadPosition(void) override
Resets the logfile read position.