44 LOG_ERROR(
"{}: Discarding current packet, because buffer is full.",
_name);
106 auto p = std::make_unique<uart::protocol::Packet>(
_buffer, &
_sensor);
137 auto p = std::make_unique<uart::protocol::Packet>(
_buffer, &
_sensor);
142 LOG_DATA(
"{}: Valid ascii packet: {}",
_name, p->datastr().substr(0, p->getRawDataLength() - 2));
147 LOG_ERROR(
"Invalid ascii packet: {}", p->datastr());
161 for (
size_t i = 0; i < data.size(); i++, sensor->_runningDataIndex++)
163 auto packetPointer = sensor->findPacket(data.at(i));
165 if (packetPointer !=
nullptr)
167 uart::protocol::Packet packet = *packetPointer;
168 dispatchPacket(dispatchPacketUserData, packet, sensor->_runningDataIndex, timestamp);
175 if (packet.getRawDataLength() < 1)
180 if (packet.getRawData().at(0) ==
'$')
182 return uart::protocol::Packet::Type::TYPE_ASCII;
188 return uart::protocol::Packet::Type::TYPE_BINARY;
192 return uart::protocol::Packet::Type::TYPE_UNKNOWN;
197 if (packet.getRawDataLength() <= 8)
202 if (packet.type() == uart::protocol::Packet::Type::TYPE_ASCII)
207 if (packet.type() == uart::protocol::Packet::Type::TYPE_BINARY)
211 return packet.getRawData().at(packet.getRawDataLength() - 2) == checksum.first
212 && packet.getRawData().at(packet.getRawDataLength() - 1) == checksum.second;
215 LOG_CRITICAL(
"Can't calculate checksum of packet with unknown type");
Class to read out Emlid Sensors.
Helper Functions to work with Emlid Sensors.
Utility class for logging to console and file.
#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.
Abstract Uart Sensor Class.
static uart::protocol::Packet::Type packetTypeFunction(const uart::protocol::Packet &packet)
Function which is called to determine the packet type (ascii/binary)
bool _binaryPayloadLength1Found
Flag if the first byte of the payload length was found.
bool _binarySyncChar2Found
Flag if the second binary end character was found.
bool _binaryPayloadLength2Found
Flag if the second byte of the payload length was found.
bool _binaryMsgIdFound
Flag if the message id was found.
bool _currentlyBuildingAsciiPacket
Flag if currently a ascii packet is built.
static bool isErrorFunction(const uart::protocol::Packet &packet)
Function which determines, if the packet is an Error Packet.
static constexpr uint8_t ASCII_END_CHAR_1
First Ascii End character.
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.
void resetTracking()
Resets the current message tracking.
static constexpr uart::Endianness ENDIANNESS
Endianess of the sensor.
static constexpr uint8_t BINARY_SYNC_CHAR_2
E - Second sync character which begins a new binary message.
static bool checksumFunction(const uart::protocol::Packet &packet)
Function which is called to verify packet integrity.
uint16_t _binaryPayloadLength
Payload length of the current packet.
const std::string _name
Name of the Parent Node.
EmlidUartSensor()=default
Default constructor.
static constexpr uint8_t ASCII_START_CHAR
Ascii character which begins a new ascii message.
size_t _numOfBytesRemainingForCompletePacket
Amount of bytes remaining for a complete packet.
static constexpr uint8_t ASCII_ESCAPE_CHAR
Ascii Escape charater.
uart::sensors::UartSensor _sensor
UartSensor object which handles the UART interface.
std::unique_ptr< uart::protocol::Packet > findPacket(uint8_t dataByte)
Collects data bytes and searches for packages inside of them.
static constexpr uint8_t ASCII_END_CHAR_2
Second Ascii End character.
uint8_t _binaryMsgId
Message id of the current packet.
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.
EmlidUartSensor(std::string name)
Constructor.
bool _asciiEndChar1Found
Flag if the first ascii end character was found.
static constexpr uint8_t BINARY_SYNC_CHAR_1
R - First sync character which begins a new binary message.
bool _currentlyBuildingBinaryPacket
Flag if currently a binary packet is built.
std::pair< uint8_t, uint8_t > checksumUBX(const std::vector< uint8_t > &data)
Calculates the two UBX checksums for the provided data vector.
void move(std::vector< T > &v, size_t sourceIdx, size_t targetIdx)
Moves an element within a vector to a new position.