mtbfilecommunicator.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 MTBFILECOMMUNICATOR_H
66 #define MTBFILECOMMUNICATOR_H
67 
68 #include "communicator.h"
69 #include "fileloader.h"
70 
72 #include <xstypes/xsresultvalue.h>
73 
74 #include <memory>
75 
76 class IoInterfaceFile;
77 class MessageExtractor;
78 
79 class MtbFileCommunicator : public Communicator, protected FileLoader
80 {
81 public:
82  static Communicator* construct();
84 
85  void closeLogFile() override;
86  XsMessage readMessage(uint8_t msgId = 0) override;
87  XsMessage readMessageFromStartOfFile(uint8_t msgId, int maxMsgs = 0) override;
88  std::deque<XsMessage> readMessagesFromStartOfFile(uint8_t msgId, int maxMsgs = 0) override;
89  void loadLogFile(XsDevice* device) override;
90  void abortLoadLogFile() override;
91  bool openLogFile(const XsString& filename) override;
92  XsString logFileName() const override;
93  XsFilePos logFileSize() const override;
94  XsTimeStamp logFileDate() const override;
95  XsFilePos logFileReadPosition() const override;
96  void resetLogFileReadPosition(void) override;
97  bool isReadingFromFile() const override;
98  bool isLoadLogFileInProgress() const override;
99 
100  bool doTransaction(const XsMessage& msg, XsMessage& rcv, uint32_t timeout) override;
101 
102  XsResultValue gotoConfig(bool detectRs485 = false) override;
103  XsResultValue gotoMeasurement() override;
104  XsResultValue getDeviceId() override;
105  void setGotoConfigTimeout(uint32_t timeout) override;
106  bool writeMessage(const XsMessage& message) override;
107  void flushPort() override;
108  void closePort() override;
109  bool isPortOpen() const override;
110  XsPortInfo portInfo() const override;
111  bool openPort(const XsPortInfo& portInfo, OpenPortStage stage = OPS_Full, bool detectRs485 = false) override;
112  bool reopenPort(OpenPortStage stage = OPS_Full, bool skipDeviceIdCheck = false) override;
113  bool isDockedAt(Communicator* other) const override;
114  void setKeepAlive(bool enable) override;
115  void addProtocolHandler(IProtocolHandler* handler) override;
116 
117 protected:
118  MtbFileCommunicator(std::shared_ptr<IoInterfaceFile> const& ioInterfaceFile);
120  void prepareForDestruction() override;
121 
122  virtual XsResultValue readLogFile(XsDevice* device) override;
123  virtual XsResultValue readSinglePacketFromFile() override;
124 
125  void waitForLastTaskCompletion() override;
126 
127  virtual XsMessage readNextMessage();
128 
129 private:
130  uint32_t timeoutToMaxMessages(uint32_t timeout) const;
132 
133  std::shared_ptr<IoInterfaceFile> m_ioInterfaceFile;
136 
138  std::deque<XsMessage>* m_extractedMessages;
139 };
140 
141 #endif
MtbFileCommunicator::logFileReadPosition
XsFilePos logFileReadPosition() const override
Retrieve the read position of the log file.
Definition: mtbfilecommunicator.cpp:617
MtbFileCommunicator::isPortOpen
bool isPortOpen() const override
MtbFileCommunicator::reopenPort
bool reopenPort(OpenPortStage stage=OPS_Full, bool skipDeviceIdCheck=false) override
Reopens the port.
msg
msg
MtbFileCommunicator::m_loadFileTaskId
xsens::ThreadPool::TaskId m_loadFileTaskId
Definition: mtbfilecommunicator.h:135
OpenPortStage
OpenPortStage
Port opening stages.
Definition: openportstage.h:76
MtbFileCommunicator::openPort
bool openPort(const XsPortInfo &portInfo, OpenPortStage stage=OPS_Full, bool detectRs485=false) override
Opens a port.
MtbFileCommunicator::readLogFile
virtual XsResultValue readLogFile(XsDevice *device) override
Read a log file into cache.
Definition: mtbfilecommunicator.cpp:437
MtbFileCommunicator::m_ioInterfaceFile
std::shared_ptr< IoInterfaceFile > m_ioInterfaceFile
Definition: mtbfilecommunicator.h:133
MtbFileCommunicator::logFileDate
XsTimeStamp logFileDate() const override
Retrieve the date of the open log file.
Definition: mtbfilecommunicator.cpp:600
MtbFileCommunicator::doTransaction
bool doTransaction(const XsMessage &msg, XsMessage &rcv, uint32_t timeout) override
Pretend to be a live system.
Definition: mtbfilecommunicator.cpp:147
MtbFileCommunicator::readMessageFromStartOfFile
XsMessage readMessageFromStartOfFile(uint8_t msgId, int maxMsgs=0) override
Read a message from the start of the open file.
Definition: mtbfilecommunicator.cpp:211
MtbFileCommunicator
A class that is used for the communcation with a mtb file.
Definition: mtbfilecommunicator.h:79
IoInterfaceFile
The low-level file communication class.
Definition: iointerfacefile.h:74
MtbFileCommunicator::MtbFileCommunicator
MtbFileCommunicator()
Default constructor.
Definition: mtbfilecommunicator.cpp:98
MtbFileCommunicator::readMessagesFromStartOfFile
std::deque< XsMessage > readMessagesFromStartOfFile(uint8_t msgId, int maxMsgs=0) override
Read multiple similar messages from the start of the open file.
Definition: mtbfilecommunicator.cpp:264
MtbFileCommunicator::resetLogFileReadPosition
void resetLogFileReadPosition(void) override
Restart reading from the start of the open log file.
Definition: mtbfilecommunicator.cpp:636
MtbFileCommunicator::construct
static Communicator * construct()
Constructs new MtbFileCommunicator.
Definition: mtbfilecommunicator.cpp:91
XsResultValue
XsResultValue
Xsens result values.
Definition: xsresultvalue.h:82
MtbFileCommunicator::timeoutToMaxMessages
uint32_t timeoutToMaxMessages(uint32_t timeout) const
A rather stupid function that tries to convert a live timeout into a number of messages.
Definition: mtbfilecommunicator.cpp:135
MtbFileCommunicator::closePort
void closePort() override
Closes the open port.
xsens::ThreadPool::TaskId
unsigned int TaskId
A type definition of a task ID.
Definition: xsens_threadpool.h:102
MtbFileCommunicator::gotoConfig
XsResultValue gotoConfig(bool detectRs485=false) override
Request a device to go to config mode.
MtbFileCommunicator::portInfo
XsPortInfo portInfo() const override
Communicator
A base struct for a communication interface.
Definition: communicator.h:95
uint32_t
unsigned int uint32_t
Definition: pstdint.h:485
MtbFileCommunicator::setKeepAlive
void setKeepAlive(bool enable) override
Either disable or enable (default) the keep alive mechanism (if supported by the device)
MtbFileCommunicator::prepareForDestruction
void prepareForDestruction() override
Prepares for the destruction.
Definition: mtbfilecommunicator.cpp:168
MtbFileCommunicator::m_extractedMessages
std::deque< XsMessage > * m_extractedMessages
Definition: mtbfilecommunicator.h:138
MtbFileCommunicator::writeMessage
bool writeMessage(const XsMessage &message) override
Write message to the device.
XsPortInfo
Contains a descriptor for opening a communication port to an Xsens device.
Definition: xsportinfo.h:128
MtbFileCommunicator::isDockedAt
bool isDockedAt(Communicator *other) const override
Returns true if the other device is docked at this device.
IProtocolHandler
Interface class for protocol handlers.
Definition: iprotocolhandler.h:78
MtbFileCommunicator::openLogFile
bool openLogFile(const XsString &filename) override
Open a log file for input.
Definition: mtbfilecommunicator.cpp:511
FileLoader
A class that loads file.
Definition: fileloader.h:73
MtbFileCommunicator::readMessage
XsMessage readMessage(uint8_t msgId=0) override
Read a message from the open file.
Definition: mtbfilecommunicator.cpp:662
MtbFileCommunicator::isLoadLogFileInProgress
bool isLoadLogFileInProgress() const override
Definition: mtbfilecommunicator.cpp:711
XsMessage
Structure for storing a single message.
Definition: xsmessage.h:202
MtbFileCommunicator::logFileSize
XsFilePos logFileSize() const override
Retrieve the size of the open log file in bytes.
Definition: mtbfilecommunicator.cpp:590
MtbFileCommunicator::closeLogFile
void closeLogFile() override
Close the log file.
Definition: mtbfilecommunicator.cpp:197
MtbFileCommunicator::completeAllThreadedWork
void completeAllThreadedWork()
Completes all threaded work.
Definition: mtbfilecommunicator.cpp:181
MtbFileCommunicator::isReadingFromFile
bool isReadingFromFile() const override
Return whether we are reading from file.
Definition: mtbfilecommunicator.cpp:649
fileloader.h
MtbFileCommunicator::m_extractor
MessageExtractor * m_extractor
Definition: mtbfilecommunicator.h:137
MtbFileCommunicator::loadLogFile
void loadLogFile(XsDevice *device) override
Load a log file with thread pool.
Definition: mtbfilecommunicator.cpp:419
MtbFileCommunicator::~MtbFileCommunicator
~MtbFileCommunicator()
Definition: mtbfilecommunicator.cpp:127
MtbFileCommunicator::setGotoConfigTimeout
void setGotoConfigTimeout(uint32_t timeout) override
Set the timeout for the gotoConfig function.
MessageExtractor
Definition: messageextractor.h:75
MtbFileCommunicator::getDeviceId
XsResultValue getDeviceId() override
Request a device to get device ID.
MtbFileCommunicator::readNextMessage
virtual XsMessage readNextMessage()
Read the next message from the open file.
Definition: mtbfilecommunicator.cpp:687
OPS_Full
@ OPS_Full
Definition: openportstage.h:83
MtbFileCommunicator::m_abortLoadLogFile
bool m_abortLoadLogFile
Definition: mtbfilecommunicator.h:134
MtbFileCommunicator::abortLoadLogFile
void abortLoadLogFile() override
Abort a process that takes a long time to complete.
Definition: mtbfilecommunicator.cpp:499
MtbFileCommunicator::flushPort
void flushPort() override
Flushes all remaining data on the open port.
communicator.h
xsens_threadpool.h
MtbFileCommunicator::waitForLastTaskCompletion
void waitForLastTaskCompletion() override
Wait for the last processing task to complete in the threadpool.
Definition: mtbfilecommunicator.cpp:190
xsresultvalue.h
MtbFileCommunicator::readSinglePacketFromFile
virtual XsResultValue readSinglePacketFromFile() override
Read a single XsDataPacket from an open log file.
Definition: mtbfilecommunicator.cpp:485
MtbFileCommunicator::logFileName
XsString logFileName() const override
Retrieve the name of the open log file or an empty string if no log file is open.
Definition: mtbfilecommunicator.cpp:577
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
MtbFileCommunicator::gotoMeasurement
XsResultValue gotoMeasurement() override
Request a device to go to measurement mode.
MtbFileCommunicator::addProtocolHandler
void addProtocolHandler(IProtocolHandler *handler) override
Add the protocol handler.
Definition: mtbfilecommunicator.cpp:719
XsTimeStamp
This class contains method to set, retrieve and compare timestamps.
Definition: xstimestamp.h:115


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