devicecommunicator.h
Go to the documentation of this file.
1 
2 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions, and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions, and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the names of the copyright holders nor the names of their contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
26 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
28 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
29 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
30 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
31 //
32 
33 
34 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
35 // All rights reserved.
36 //
37 // Redistribution and use in source and binary forms, with or without modification,
38 // are permitted provided that the following conditions are met:
39 //
40 // 1. Redistributions of source code must retain the above copyright notice,
41 // this list of conditions, and the following disclaimer.
42 //
43 // 2. Redistributions in binary form must reproduce the above copyright notice,
44 // this list of conditions, and the following disclaimer in the documentation
45 // and/or other materials provided with the distribution.
46 //
47 // 3. Neither the names of the copyright holders nor the names of their contributors
48 // may be used to endorse or promote products derived from this software without
49 // specific prior written permission.
50 //
51 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
52 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
54 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
58 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
60 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
61 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
62 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
63 //
64 
65 #ifndef DEVICECOMMUNICATOR_H
66 #define DEVICECOMMUNICATOR_H
67 
68 #include "communicator.h"
69 #include "messageextractor.h"
70 
71 #ifdef LOG_COMMUNICATOR_RX_TX
72  #include <xstypes/xsfile.h>
73 #endif
74 
75 
77 {
78 public:
79 
82 
83  DeviceCommunicator(RxChannelId rxChannels = 1);
84 
85  // live stuff
86  XsResultValue getDeviceId() override;
87  XsResultValue gotoConfig(bool) override;
88  XsResultValue gotoMeasurement() override;
89 
92  {
93  return m_gotoConfigTimeout;
94  }
95  void setGotoConfigTimeout(uint32_t timeout) override;
96  bool writeMessage(const XsMessage& message) override;
97 
98  void handleMessage(const XsMessage& message) override;
99 
101  virtual bool doTransaction(const XsMessage& msg, XsMessage& rcv, uint32_t timeout) override;
102 
103  void setKeepAlive(bool enable) override;
104 
105  // file stuff
106  void closeLogFile() override;
107  XsMessage readMessage(uint8_t msgId = 0) override;
108  XsMessage readMessageFromStartOfFile(uint8_t msgId, int maxMsgs = 0) override;
109  std::deque<XsMessage> readMessagesFromStartOfFile(uint8_t msgId, int maxMsgs = 0) override;
110  void loadLogFile(XsDevice* device) override;
111  void abortLoadLogFile() override;
112  bool openLogFile(const XsString& filename) override;
113  XsString logFileName() const override;
114  XsFilePos logFileSize() const override;
115  XsTimeStamp logFileDate() const override;
116  XsFilePos logFileReadPosition() const override;
117  void resetLogFileReadPosition(void) override;
118  bool isReadingFromFile() const override;
119  void waitForLastTaskCompletion() override;
120 
125  virtual XsResultValue readLogFile(XsDevice* device);
126 
131 
132 protected:
133  ~DeviceCommunicator() override;
134  XsResultValue extractMessages(const XsByteArray& rawIn, std::deque<XsMessage>& messages, RxChannelId channel = 0);
135 
140  virtual XsResultValue writeRawData(const XsByteArray& data) = 0;
144 
145 #ifdef LOG_COMMUNICATOR_RX_TX
146  void logTxStream(XsMessage const& msg);
147  void logRxStream(XsMessage const& msg);
148 #endif
149 
150 private:
151  static const uint32_t m_defaultGotoConfigTimeout = 200; // 1500 just after powerup, 100ms is not enough sometimes during tests
152 
154 
156  std::vector<MessageExtractor> m_messageExtractors;
157 
158 #ifdef LOG_COMMUNICATOR_RX_TX
159  XsFile m_rxLog;
160  XsFile m_txLog;
161 #ifdef LOG_COMMUNICATOR_RX_TX_TIMESTAMPED
162  XsTimeStamp m_logStart;
163 #endif
164 
165  void generateLogFiles();
166 #endif
167 };
168 
169 #endif
DeviceCommunicator::m_gotoConfigTimeout
uint32_t m_gotoConfigTimeout
Definition: devicecommunicator.h:153
DeviceCommunicator
A class that is used for the communcation with a device.
Definition: devicecommunicator.h:76
DeviceCommunicator::loadLogFile
void loadLogFile(XsDevice *device) override
Load a complete logfile.
messageextractor.h
XsByteArray
A list of uint8_t values.
DeviceCommunicator::doTransaction
virtual bool doTransaction(const XsMessage &msg, XsMessage &rcv, uint32_t timeout) override
Write a message and await the reply.
Definition: devicecommunicator.cpp:110
DeviceCommunicator::handleMessage
void handleMessage(const XsMessage &message) override
Handles a message.
Definition: devicecommunicator.cpp:327
xsfile.h
DeviceCommunicator::extractMessages
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.
Definition: devicecommunicator.cpp:290
DeviceCommunicator::gotoConfig
XsResultValue gotoConfig(bool) override
Request a device to go to config mode.
Definition: devicecommunicator.cpp:212
DeviceCommunicator::gotoConfigTimeout
uint32_t gotoConfigTimeout() const
Definition: devicecommunicator.h:91
DeviceCommunicator::openLogFile
bool openLogFile(const XsString &filename) override
Open the log file `.
DeviceCommunicator::addRxChannel
RxChannelId addRxChannel()
Adds an RX (receive) channel to the device communicator. Each channel maintains its own message parsi...
Definition: devicecommunicator.cpp:274
DeviceCommunicator::m_defaultGotoConfigTimeout
static const uint32_t m_defaultGotoConfigTimeout
Definition: devicecommunicator.h:151
XsResultValue
XsResultValue
Xsens result values.
Definition: xsresultvalue.h:82
DeviceCommunicator::readMessage
XsMessage readMessage(uint8_t msgId=0) override
Read a message from the open file.
DeviceCommunicator::RxChannelId
XsSize RxChannelId
A typedef for Rx chanel ID.
Definition: devicecommunicator.h:81
Communicator::doTransaction
bool doTransaction(const XsMessage &message)
Write a message and await the reply.
Definition: communicator.cpp:222
DeviceCommunicator::closeLogFile
void closeLogFile() override
Close the log file.
Communicator
A base struct for a communication interface.
Definition: communicator.h:95
DeviceCommunicator::writeMessage
bool writeMessage(const XsMessage &message) override
Write message to the device.
Definition: devicecommunicator.cpp:248
uint32_t
unsigned int uint32_t
Definition: pstdint.h:485
DeviceCommunicator::DeviceCommunicator
DeviceCommunicator(RxChannelId rxChannels=1)
Default constructor.
Definition: devicecommunicator.cpp:83
DeviceCommunicator::writeRawData
virtual XsResultValue writeRawData(const XsByteArray &data)=0
Writes a raw data to a device.
DeviceCommunicator::m_messageExtractors
std::vector< MessageExtractor > m_messageExtractors
Definition: devicecommunicator.h:156
DeviceCommunicator::messageExtractor
MessageExtractor & messageExtractor(RxChannelId=0)
Returns the message extractor for the given rx channel.
Definition: devicecommunicator.cpp:319
DeviceCommunicator::logFileName
XsString logFileName() const override
DeviceCommunicator::~DeviceCommunicator
~DeviceCommunicator() override
Definition: devicecommunicator.cpp:100
DeviceCommunicator::logFileReadPosition
XsFilePos logFileReadPosition() const override
DeviceCommunicator::readMessagesFromStartOfFile
std::deque< XsMessage > readMessagesFromStartOfFile(uint8_t msgId, int maxMsgs=0) override
Read multiple similar messages from the start of the open file.
DeviceCommunicator::setKeepAlive
void setKeepAlive(bool enable) override
Does nothing.
Definition: devicecommunicator.cpp:143
XsSize
size_t XsSize
XsSize must be unsigned number!
Definition: xstypedefs.h:74
DeviceCommunicator::abortLoadLogFile
void abortLoadLogFile() override
Aborts loading a logfile.
DeviceCommunicator::readLogFile
virtual XsResultValue readLogFile(XsDevice *device)
Read a log file into cache.
XsMessage
Structure for storing a single message.
Definition: xsmessage.h:202
DeviceCommunicator::logFileDate
XsTimeStamp logFileDate() const override
DeviceCommunicator::logFileSize
XsFilePos logFileSize() const override
DeviceCommunicator::readSinglePacketFromFile
virtual XsResultValue readSinglePacketFromFile()
Read a single XsDataPacket from an open log file.
XsFile
Encapsulates a file, providing a platform independent interface.
Definition: xsfile.h:131
DeviceCommunicator::readMessageFromStartOfFile
XsMessage readMessageFromStartOfFile(uint8_t msgId, int maxMsgs=0) override
Read a message from the start of the open file.
DeviceCommunicator::gotoMeasurement
XsResultValue gotoMeasurement() override
Request a device to go to measurement mode.
Definition: devicecommunicator.cpp:229
MessageExtractor
Definition: messageextractor.h:75
DeviceCommunicator::m_nextRxChannelId
RxChannelId m_nextRxChannelId
Definition: devicecommunicator.h:155
DeviceCommunicator::messageExtractorCount
XsSize messageExtractorCount() const
Returns the number of message extractor this device communicator has.
Definition: devicecommunicator.cpp:312
DeviceCommunicator::isReadingFromFile
bool isReadingFromFile() const override
DeviceCommunicator::setGotoConfigTimeout
void setGotoConfigTimeout(uint32_t timeout) override
Set the timeout for the gotoConfig function.
Definition: devicecommunicator.cpp:158
DeviceCommunicator::getDeviceId
XsResultValue getDeviceId() override
Request a device to get device ID.
Definition: devicecommunicator.cpp:168
communicator.h
XsFilePos
int64_t XsFilePos
The type that is used for positioning inside a file.
Definition: xsfilepos.h:102
XsString
A 0-terminated managed string of characters.
XsDevice
Definition: xsdevice_def.h:164
XsTimeStamp
This class contains method to set, retrieve and compare timestamps.
Definition: xstimestamp.h:115
DeviceCommunicator::waitForLastTaskCompletion
void waitForLastTaskCompletion() override
Wait for the last processing task to complete in the threadpool.
DeviceCommunicator::resetLogFileReadPosition
void resetLogFileReadPosition(void) override
Resets the logfile read position.


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