serialcommunicator.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 SERIALCOMMUNICATOR_H
66 #define SERIALCOMMUNICATOR_H
67 
68 #include "devicecommunicator.h"
69 #include <xstypes/xsportinfo.h>
70 #include <xstypes/xsbytearray.h>
71 #include <xstypes/xsversion.h>
72 #include "dataparser.h"
73 #include "mtthread.h"
74 
76 {
77 public:
79 
80  XsResultValue gotoConfig(bool detectRs485 = false) override;
81  XsResultValue gotoMeasurement() override;
82 
83  void handleMessage(const XsMessage& msg) override;
84 
85  void flushPort() override;
86  void closePort() override;
87  bool isPortOpen() const override;
88  XsPortInfo portInfo() const override;
89  bool openPort(const XsPortInfo& portInfo, OpenPortStage stage = OPS_Full, bool detectRs485 = false) override;
90  bool reopenPort(OpenPortStage stage = OPS_Full, bool skipDeviceIdCheck = false) override;
91  bool isDockedAt(Communicator* other) const override;
92 
93  XsResultValue writeRawData(const XsByteArray& data) override;
94 
97 protected:
98  virtual ~SerialCommunicator();
99  virtual void prepareForDestruction() override;
100 
105  virtual std::shared_ptr<StreamInterface> createStreamInterface(const XsPortInfo& pi) = 0;
106 
108  XsResultValue processBufferedData(const XsByteArray& rawIn, std::deque<XsMessage>& messages) override;
109 
110  bool isActive() const;
111 
112  void setDoGotoConfig(bool doit);
113  void stopPollThread(); // made protected for TestCommunicator testing
116 
120  {
121  return 0;
122  }
123 
125 
126 private:
128  std::shared_ptr<StreamInterface> m_streamInterface;
131 
132  void startPollThread();
133 };
134 
135 #endif
SerialCommunicator::flushPort
void flushPort() override
Flushes all remaining data on the open port.
Definition: serialcommunicator.cpp:189
SerialCommunicator::m_firmwareRevision
XsVersion m_firmwareRevision
Definition: serialcommunicator.h:129
DeviceCommunicator
A class that is used for the communcation with a device.
Definition: devicecommunicator.h:76
SerialCommunicator::writeRawData
XsResultValue writeRawData(const XsByteArray &data) override
Write raw data to the open COM or USB port.
Definition: serialcommunicator.cpp:180
dataparser.h
SerialCommunicator::processBufferedData
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.
Definition: serialcommunicator.cpp:436
msg
msg
SerialCommunicator::defaultInterfaceTimeout
virtual uint32_t defaultInterfaceTimeout() const
Definition: serialcommunicator.h:119
XsByteArray
A list of uint8_t values.
OpenPortStage
OpenPortStage
Port opening stages.
Definition: openportstage.h:76
SerialCommunicator
A class that uses serial communication.
Definition: serialcommunicator.h:75
mtthread.h
SerialCommunicator::setDoGotoConfig
void setDoGotoConfig(bool doit)
Sets do go to config in a thread.
Definition: serialcommunicator.cpp:366
SerialCommunicator::portInfo
XsPortInfo portInfo() const override
Definition: serialcommunicator.cpp:236
SerialCommunicator::m_thread
MtThread m_thread
Definition: serialcommunicator.h:127
SerialCommunicator::m_streamInterface
std::shared_ptr< StreamInterface > m_streamInterface
Definition: serialcommunicator.h:128
SerialCommunicator::createStreamInterface
virtual std::shared_ptr< StreamInterface > createStreamInterface(const XsPortInfo &pi)=0
Creates a stream interface.
SerialCommunicator::handleMessage
void handleMessage(const XsMessage &msg) override
Handles a message.
Definition: serialcommunicator.cpp:424
SerialCommunicator::isDockedAt
bool isDockedAt(Communicator *other) const override
Definition: serialcommunicator.cpp:376
SerialCommunicator::hardwareRevision
XsVersion hardwareRevision()
Definition: serialcommunicator.cpp:483
xsportinfo.h
data
data
SerialCommunicator::startPollThread
void startPollThread()
Starts polling the thread.
Definition: serialcommunicator.cpp:204
SerialCommunicator::stopPollThread
void stopPollThread()
Stops polling the thread.
Definition: serialcommunicator.cpp:197
XsResultValue
XsResultValue
Xsens result values.
Definition: xsresultvalue.h:82
Communicator
A base struct for a communication interface.
Definition: communicator.h:95
SerialCommunicator::gotoConfig
XsResultValue gotoConfig(bool detectRs485=false) override
Request a device to go to config mode.
Definition: serialcommunicator.cpp:138
SerialCommunicator::isActive
bool isActive() const
Definition: serialcommunicator.cpp:358
uint32_t
unsigned int uint32_t
Definition: pstdint.h:485
MtThread
A class that implements thread for MT.
Definition: mtthread.h:74
XsPortInfo
Contains a descriptor for opening a communication port to an Xsens device.
Definition: xsportinfo.h:128
SerialCommunicator::m_hardwareRevision
XsVersion m_hardwareRevision
Definition: serialcommunicator.h:130
SerialCommunicator::getFirmwareRevision
virtual XsResultValue getFirmwareRevision()
Requests the firmware revision from the connected device.
Definition: serialcommunicator.cpp:443
SerialCommunicator::SerialCommunicator
SerialCommunicator()
Default constructor.
Definition: serialcommunicator.cpp:86
XsVersion
A class to store version information.
Definition: xsversion.h:95
xsversion.h
SerialCommunicator::closePort
void closePort() override
Closes the port.
Definition: serialcommunicator.cpp:210
XsMessage
Structure for storing a single message.
Definition: xsmessage.h:202
SerialCommunicator::m_activePortInfo
XsPortInfo m_activePortInfo
The information about the port this communicator is currently connected to.
Definition: serialcommunicator.h:124
SerialCommunicator::firmwareRevision
XsVersion firmwareRevision()
Definition: serialcommunicator.cpp:476
SerialCommunicator::prepareForDestruction
virtual void prepareForDestruction() override
Prepares for a destruction.
Definition: serialcommunicator.cpp:101
OPS_Full
@ OPS_Full
Definition: openportstage.h:83
DataParser
A class for the data parsing on a separete thread.
Definition: dataparser.h:76
SerialCommunicator::openPort
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.
Definition: serialcommunicator.cpp:243
SerialCommunicator::getHardwareRevision
virtual XsResultValue getHardwareRevision()
Requests the hardware revision from the connected device.
Definition: serialcommunicator.cpp:460
SerialCommunicator::~SerialCommunicator
virtual ~SerialCommunicator()
Definition: serialcommunicator.cpp:95
xsbytearray.h
SerialCommunicator::gotoMeasurement
XsResultValue gotoMeasurement() override
Request a device to go to measurement mode.
Definition: serialcommunicator.cpp:121
SerialCommunicator::readDataToBuffer
XsResultValue readDataToBuffer(XsByteArray &raw) override
Read available data from the open IO device.
Definition: serialcommunicator.cpp:391
devicecommunicator.h
SerialCommunicator::isPortOpen
bool isPortOpen() const override
Definition: serialcommunicator.cpp:229
SerialCommunicator::reopenPort
bool reopenPort(OpenPortStage stage=OPS_Full, bool skipDeviceIdCheck=false) override
Reopens the port.
Definition: serialcommunicator.cpp:319


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