0.2.0
Loading...
Searching...
No Matches
KvhUartSensor.hpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
13
14#pragma once
15
16#include <memory>
17
18#include "uart/sensors/sensors.hpp"
19
20namespace NAV::vendor::kvh
21{
24{
25 public:
28 explicit KvhUartSensor(std::string name);
29
31 KvhUartSensor() = default;
33 ~KvhUartSensor() = default;
35 KvhUartSensor(const KvhUartSensor&) = delete;
43 uart::sensors::UartSensor* operator->() { return &_sensor; };
44
48 std::unique_ptr<uart::protocol::Packet> findPacket(uint8_t dataByte);
49
50 static constexpr uint32_t HEADER_FMT_A = 0xFE81FF55;
51 static constexpr uint32_t HEADER_FMT_B = 0xFE81FF56;
52 static constexpr uint32_t HEADER_FMT_C = 0xFE81FF57;
53 static constexpr uint32_t HEADER_FMT_XBIT = 0xFE8100AA;
54 static constexpr uint32_t HEADER_FMT_XBIT2 = 0xFE8100AB;
55
56 static constexpr uart::Endianness ENDIANNESS = uart::Endianness::ENDIAN_BIG;
57
58 private:
60 const std::string _name;
61
63 uart::sensors::UartSensor _sensor{ ENDIANNESS,
64 packetFinderFunction,
65 this,
66 packetTypeFunction,
67 checksumFunction,
68 isErrorFunction,
69 isResponseFunction,
70 PACKET_HEADER_LENGTH };
71
78 static void packetFinderFunction(const std::vector<uint8_t>& data,
79 const uart::xplat::TimeStamp& timestamp,
80 uart::sensors::UartSensor::ValidPacketFoundHandler dispatchPacket, void* dispatchPacketUserData,
81 void* userData);
82
86 static uart::protocol::Packet::Type packetTypeFunction(const uart::protocol::Packet& packet);
87
91 static bool checksumFunction(const uart::protocol::Packet& packet);
92
95 static bool isErrorFunction(const uart::protocol::Packet& packet);
96
99 static bool isResponseFunction(const uart::protocol::Packet& packet);
100
101 static constexpr size_t PACKET_HEADER_LENGTH = 0;
102
103 static constexpr uint8_t ASCII_END_CHAR_1 = '\r';
104 static constexpr uint8_t ASCII_END_CHAR_2 = '\n';
105 static constexpr uint8_t ASCII_ESCAPE_CHAR = '\0';
106 static constexpr size_t MAX_SIZE_ASCII_PACKET = 256;
107
108 bool _currentlyBuildingAsciiPacket{ false };
109 bool _currentlyBuildingBinaryPacket{ false };
110
111 bool _asciiEndChar1Found{ false };
112
114 enum TagState
115 {
116 SM_H1,
117 SM_H2,
118 SM_H3,
119 SM_X3,
120 SM_IDLE,
121 };
122
124 TagState _eState = SM_IDLE;
125
127 enum HeaderType
128 {
129 FMT_A,
130 FMT_B,
131 FMT_C,
132 FMT_XBIT,
133 FMT_XBIT2,
134 FMT_UNKNOWN,
135 };
136
138 HeaderType _packetType = HeaderType::FMT_UNKNOWN;
139
143 HeaderType bFindImuHeader(uint8_t ui8Data);
144
146 std::vector<uint8_t> _buffer;
147
149 size_t _runningDataIndex{ 0 };
150
152 void resetTracking();
153};
154
155} // namespace NAV::vendor::kvh
Class to read out KVH Sensors.
Definition KvhUartSensor.hpp:24
static constexpr uint32_t HEADER_FMT_XBIT2
Header Format X Bit 2.
Definition KvhUartSensor.hpp:54
KvhUartSensor & operator=(const KvhUartSensor &)=delete
Copy assignment operator.
static constexpr uint32_t HEADER_FMT_A
Header Format A.
Definition KvhUartSensor.hpp:50
KvhUartSensor & operator=(KvhUartSensor &&)=delete
Move assignment operator.
static constexpr uint32_t HEADER_FMT_B
Header Format B.
Definition KvhUartSensor.hpp:51
std::unique_ptr< uart::protocol::Packet > findPacket(uint8_t dataByte)
Collects data bytes and searches for packages inside of them.
static constexpr uart::Endianness ENDIANNESS
Endianess of the sensor.
Definition KvhUartSensor.hpp:56
~KvhUartSensor()=default
Destructor.
KvhUartSensor(KvhUartSensor &&)=delete
Move constructor.
static constexpr uint32_t HEADER_FMT_C
Header Format C.
Definition KvhUartSensor.hpp:52
static constexpr uint32_t HEADER_FMT_XBIT
Header Format X Bit.
Definition KvhUartSensor.hpp:53
KvhUartSensor(std::string name)
Constructor.
uart::sensors::UartSensor * operator->()
Arrow operator overload.
Definition KvhUartSensor.hpp:43
KvhUartSensor(const KvhUartSensor &)=delete
Copy constructor.
KvhUartSensor()=default
Default constructor.