0.2.0
Loading...
Searching...
No Matches
EmlidUartSensor.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::emlid
21{
24{
25 public:
28 explicit EmlidUartSensor(std::string name);
29
31 EmlidUartSensor() = default;
33 ~EmlidUartSensor() = default;
43 uart::sensors::UartSensor* operator->() { return &_sensor; };
44
48 std::unique_ptr<uart::protocol::Packet> findPacket(uint8_t dataByte);
49
50 static constexpr uint8_t BINARY_SYNC_CHAR_1 = 0x82;
51 static constexpr uint8_t BINARY_SYNC_CHAR_2 = 0x45;
52 static constexpr uint8_t ASCII_START_CHAR = '$';
53
54 private:
56 const std::string _name;
57
59 uart::sensors::UartSensor _sensor{ ENDIANNESS,
60 packetFinderFunction,
61 this,
62 packetTypeFunction,
63 checksumFunction,
64 isErrorFunction,
65 isResponseFunction,
66 PACKET_HEADER_LENGTH };
67
74 static void packetFinderFunction(const std::vector<uint8_t>& data,
75 const uart::xplat::TimeStamp& timestamp,
76 uart::sensors::UartSensor::ValidPacketFoundHandler dispatchPacket, void* dispatchPacketUserData,
77 void* userData);
78
82 static uart::protocol::Packet::Type packetTypeFunction(const uart::protocol::Packet& packet);
83
87 static bool checksumFunction(const uart::protocol::Packet& packet);
88
91 static bool isErrorFunction(const uart::protocol::Packet& packet);
92
95 static bool isResponseFunction(const uart::protocol::Packet& packet);
96
97 static constexpr uart::Endianness ENDIANNESS = uart::Endianness::ENDIAN_LITTLE;
98 static constexpr size_t PACKET_HEADER_LENGTH = 2;
99 static constexpr uint8_t ASCII_END_CHAR_1 = '\r';
100 static constexpr uint8_t ASCII_END_CHAR_2 = '\n';
101 static constexpr uint8_t ASCII_ESCAPE_CHAR = '\0';
102
103 bool _currentlyBuildingAsciiPacket{ false };
104 bool _currentlyBuildingBinaryPacket{ false };
105
106 bool _asciiEndChar1Found{ false };
107 bool _binarySyncChar2Found{ false };
108 bool _binaryMsgIdFound{ false };
109 bool _binaryPayloadLength1Found{ false };
110 bool _binaryPayloadLength2Found{ false };
111
113 uint8_t _binaryMsgId{ 0 };
115 uint16_t _binaryPayloadLength{ 0 };
116
118 std::vector<uint8_t> _buffer;
119
121 size_t _runningDataIndex{ 0 };
123 size_t _numOfBytesRemainingForCompletePacket{ 0 };
124
126 void resetTracking();
127};
128
129} // namespace NAV::vendor::emlid
Class to read out Emlid Sensors.
Definition EmlidUartSensor.hpp:24
uart::sensors::UartSensor * operator->()
Arrow operator overload.
Definition EmlidUartSensor.hpp:43
~EmlidUartSensor()=default
Destructor.
EmlidUartSensor(EmlidUartSensor &&)=delete
Move constructor.
EmlidUartSensor & operator=(const EmlidUartSensor &)=delete
Copy assignment operator.
static constexpr uint8_t BINARY_SYNC_CHAR_2
E - Second sync character which begins a new binary message.
Definition EmlidUartSensor.hpp:51
EmlidUartSensor(const EmlidUartSensor &)=delete
Copy constructor.
EmlidUartSensor()=default
Default constructor.
static constexpr uint8_t ASCII_START_CHAR
Ascii character which begins a new ascii message.
Definition EmlidUartSensor.hpp:52
EmlidUartSensor & operator=(EmlidUartSensor &&)=delete
Move assignment operator.
std::unique_ptr< uart::protocol::Packet > findPacket(uint8_t dataByte)
Collects data bytes and searches for packages inside of them.
EmlidUartSensor(std::string name)
Constructor.
static constexpr uint8_t BINARY_SYNC_CHAR_1
R - First sync character which begins a new binary message.
Definition EmlidUartSensor.hpp:50