34#if (defined(__GNUC__) || defined(__GNUG__)) && !defined(__clang__)
35 #pragma GCC diagnostic push
36 #pragma GCC diagnostic ignored "-Wstringop-overflow"
41#if (defined(__GNUC__) || defined(__GNUG__)) && !defined(__clang__)
42 #pragma GCC diagnostic pop
47#if LOG_LEVEL <= LOG_LEVEL_DATA
58 LOG_ERROR(
"{}: Discarding current packet, because buffer is full",
_name);
63#if LOG_LEVEL <= LOG_LEVEL_DATA
133 LOG_DATA(
"{}: Binary packet: Class={:0x} [{}], Id={:0x} [{}], payload length={}",
_name,
145 auto p = std::make_unique<uart::protocol::Packet>(
_buffer, &
_sensor);
176 auto p = std::make_unique<uart::protocol::Packet>(
_buffer, &
_sensor);
181 LOG_DATA(
"{}: Valid ascii packet: {}",
_name, p->datastr().substr(0, p->getRawDataLength() - 2));
203 for (
size_t i = 0; i < data.size(); i++, sensor->_runningDataIndex++)
205 auto packetPointer = sensor->findPacket(data.at(i));
207 if (packetPointer !=
nullptr)
209 uart::protocol::Packet packet = *packetPointer;
210 dispatchPacket(dispatchPacketUserData, packet, sensor->_runningDataIndex, timestamp);
217 if (packet.getRawDataLength() < 1)
222 if (packet.getRawData().at(0) ==
'$')
224 return uart::protocol::Packet::Type::TYPE_ASCII;
230 return uart::protocol::Packet::Type::TYPE_BINARY;
234 return uart::protocol::Packet::Type::TYPE_UNKNOWN;
239 if (packet.getRawDataLength() <= 8)
244 if (packet.type() == uart::protocol::Packet::Type::TYPE_ASCII)
247 if (packet.getRawData().at(packet.getRawDataLength() - 5) !=
'*')
253 if (packet.getRawData().at(packet.getRawDataLength() - 3) ==
'X'
254 && packet.getRawData().at(packet.getRawDataLength() - 4) ==
'X')
260 std::array<uint8_t, 2> checksumRecv = { packet.getRawData().at(packet.getRawDataLength() - 4),
261 packet.getRawData().at(packet.getRawDataLength() - 3) };
262 return uart::to_uint8_from_hexstr(
reinterpret_cast<char*
>(checksumRecv.data())) == checksumHex;
265 if (packet.type() == uart::protocol::Packet::Type::TYPE_BINARY)
269 return packet.getRawData().at(packet.getRawDataLength() - 2) == checksum.first
270 && packet.getRawData().at(packet.getRawDataLength() - 1) == checksum.second;
273 LOG_CRITICAL(
"Can't calculate checksum of packet with unknown type");
#define LOG_CRITICAL(...)
Critical Event, which causes the program to work entirely and throws an exception.
#define LOG_DEBUG
Debug information. Should not be called on functions which receive observations (spamming)
#define LOG_DATA
All output which occurs repeatedly every time observations are received.
#define LOG_ERROR
Error occurred, which stops part of the program to work, but not everything.
Algorithms concerning the STL containers.
Class to read out Ublox Sensors.
Helper Functions to work with Ublox Sensors.
Abstract Uart Sensor Class.
uint8_t _binaryMsgClass
Message class of the current packet.
static constexpr uint8_t BINARY_SYNC_CHAR_2
b - Second sync character which begins a new binary message
bool _binaryMsgIdFound
Flag if the message id was found.
std::unique_ptr< uart::protocol::Packet > findPacket(uint8_t dataByte)
Collects data bytes and searches for packages inside of them.
static void packetFinderFunction(const std::vector< uint8_t > &data, const uart::xplat::TimeStamp ×tamp, uart::sensors::UartSensor::ValidPacketFoundHandler dispatchPacket, void *dispatchPacketUserData, void *userData)
Function which is called to find packets in the provided data buffer.
static constexpr uint8_t ASCII_END_CHAR_2
Second Ascii End character.
static bool isErrorFunction(const uart::protocol::Packet &packet)
Function which determines, if the packet is an Error Packet.
UbloxUartSensor()=default
Default constructor.
bool _binaryMsgClassFound
Flag if the message class was found.
bool _binaryPayloadLength2Found
Flag if the second byte of the payload length was found.
const std::string _name
Name of the Parent Node.
bool _asciiEndChar1Found
Flag if the first ascii end character was found.
void resetTracking()
Resets the current message tracking.
static constexpr uint8_t ASCII_ESCAPE_CHAR
Ascii Escape charater.
bool _currentlyBuildingAsciiPacket
Flag if currently a ascii packet is built.
static uart::protocol::Packet::Type packetTypeFunction(const uart::protocol::Packet &packet)
Function which is called to determine the packet type (ascii/binary)
uart::sensors::UartSensor _sensor
UartSensor object which handles the UART interface.
static constexpr uint8_t ASCII_END_CHAR_1
First Ascii End character.
bool _currentlyBuildingBinaryPacket
Flag if currently a binary packet is built.
static constexpr uint8_t ASCII_START_CHAR
Ascii character which begins a new ascii message.
static constexpr uart::Endianness ENDIANNESS
Endianess of the sensor.
bool _binaryPayloadLength1Found
Flag if the first byte of the payload length was found.
static constexpr uint8_t BINARY_SYNC_CHAR_1
ยต - First sync character which begins a new binary message
size_t _numOfBytesRemainingForCompletePacket
Amount of bytes remaining for a complete packet.
std::vector< uint8_t > _unrecognizedBytes
Bytes which were not recognized as messages.
UbloxUartSensor(std::string name)
Constructor.
uint16_t _binaryPayloadLength
Payload length of the current packet.
static bool checksumFunction(const uart::protocol::Packet &packet)
Function which is called to verify packet integrity.
static bool isResponseFunction(const uart::protocol::Packet &packet)
Function which determines, if the packet is a Response.
std::vector< uint8_t > _buffer
Buffer to collect messages till they are complete.
uint8_t _binaryMsgId
Message id of the current packet.
bool _binarySyncChar2Found
Flag if the second binary end character was found.
uint8_t checksumNMEA(const std::vector< uint8_t > &data)
Calculates the NMEA checksum for the provided data vector.
std::string getStringFromMsgId(UbxClass msgClass, uint8_t msgId)
Get the a string from a UBX Msg Id.
std::pair< uint8_t, uint8_t > checksumUBX(const std::vector< uint8_t > &data)
Calculates the two UBX checksums for the provided data vector.
UbxClass
The available UBX Class IDs.
std::string getStringFromMsgClass(UbxClass msgClass)
Get the a string from a UBX Msg Class.
std::string joinToString(const T &container, const char *delimiter=", ", const std::string &elementFormat="")
Joins the container to a string.
void move(std::vector< T > &v, size_t sourceIdx, size_t targetIdx)
Moves an element within a vector to a new position.