0.2.0
Loading...
Searching...
No Matches
UbloxUartSensor.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#include <vector>
18
19#include "uart/sensors/sensors.hpp"
20#include "util/Logger.hpp"
21
22namespace NAV::vendor::ublox
23{
26{
27 public:
30 explicit UbloxUartSensor(std::string name);
31
33 UbloxUartSensor() = default;
35 ~UbloxUartSensor() = default;
45 uart::sensors::UartSensor* operator->() { return &_sensor; };
46
50 std::unique_ptr<uart::protocol::Packet> findPacket(uint8_t dataByte);
51
52 static constexpr uint8_t BINARY_SYNC_CHAR_1 = 0xB5;
53 static constexpr uint8_t BINARY_SYNC_CHAR_2 = 0x62;
54 static constexpr uint8_t ASCII_START_CHAR = '$';
55
56 private:
58 const std::string _name;
59
61 uart::sensors::UartSensor _sensor{ ENDIANNESS,
62 packetFinderFunction,
63 this,
64 packetTypeFunction,
65 checksumFunction,
66 isErrorFunction,
67 isResponseFunction,
68 PACKET_HEADER_LENGTH };
69
76 static void packetFinderFunction(const std::vector<uint8_t>& data,
77 const uart::xplat::TimeStamp& timestamp,
78 uart::sensors::UartSensor::ValidPacketFoundHandler dispatchPacket, void* dispatchPacketUserData,
79 void* userData);
80
84 static uart::protocol::Packet::Type packetTypeFunction(const uart::protocol::Packet& packet);
85
89 static bool checksumFunction(const uart::protocol::Packet& packet);
90
93 static bool isErrorFunction(const uart::protocol::Packet& packet);
94
97 static bool isResponseFunction(const uart::protocol::Packet& packet);
98
99 static constexpr uart::Endianness ENDIANNESS = uart::Endianness::ENDIAN_LITTLE;
100 static constexpr size_t PACKET_HEADER_LENGTH = 2;
101 static constexpr uint8_t ASCII_END_CHAR_1 = '\r';
102 static constexpr uint8_t ASCII_END_CHAR_2 = '\n';
103 static constexpr uint8_t ASCII_ESCAPE_CHAR = '\0';
104
105 bool _currentlyBuildingAsciiPacket{ false };
106 bool _currentlyBuildingBinaryPacket{ false };
107
108 bool _asciiEndChar1Found{ false };
109 bool _binarySyncChar2Found{ false };
110 bool _binaryMsgClassFound{ false };
111 bool _binaryMsgIdFound{ false };
112 bool _binaryPayloadLength1Found{ false };
113 bool _binaryPayloadLength2Found{ false };
114
116 uint8_t _binaryMsgClass{ 0 };
118 uint8_t _binaryMsgId{ 0 };
120 uint16_t _binaryPayloadLength{ 0 };
121
123 std::vector<uint8_t> _buffer;
124
126 size_t _runningDataIndex{ 0 };
128 size_t _numOfBytesRemainingForCompletePacket{ 0 };
129
130#if LOG_LEVEL <= LOG_LEVEL_DATA
132 std::vector<uint8_t> _unrecognizedBytes;
133#endif
134
136 void resetTracking();
137};
138
139} // namespace NAV::vendor::ublox
Utility class for logging to console and file.
Class to read out Ublox Sensors.
Definition UbloxUartSensor.hpp:26
static constexpr uint8_t BINARY_SYNC_CHAR_2
b - Second sync character which begins a new binary message
Definition UbloxUartSensor.hpp:53
std::unique_ptr< uart::protocol::Packet > findPacket(uint8_t dataByte)
Collects data bytes and searches for packages inside of them.
UbloxUartSensor & operator=(UbloxUartSensor &&)=delete
Move assignment operator.
uart::sensors::UartSensor * operator->()
Arrow operator overload.
Definition UbloxUartSensor.hpp:45
UbloxUartSensor()=default
Default constructor.
UbloxUartSensor & operator=(const UbloxUartSensor &)=delete
Copy assignment operator.
static constexpr uint8_t ASCII_START_CHAR
Ascii character which begins a new ascii message.
Definition UbloxUartSensor.hpp:54
UbloxUartSensor(const UbloxUartSensor &)=delete
Copy constructor.
static constexpr uint8_t BINARY_SYNC_CHAR_1
ยต - First sync character which begins a new binary message
Definition UbloxUartSensor.hpp:52
UbloxUartSensor(std::string name)
Constructor.
~UbloxUartSensor()=default
Destructor.
UbloxUartSensor(UbloxUartSensor &&)=delete
Move constructor.