38 LOG_ERROR(
"{}: Discarding current packet, because buffer is full.",
_name);
88 auto p = std::make_unique<uart::protocol::Packet>(
_buffer, &
_sensor);
110 for (
size_t i = 0; i < data.size(); i++, sensor->_runningDataIndex++)
112 auto packetPointer = sensor->findPacket(data.at(i));
114 if (packetPointer !=
nullptr)
116 uart::protocol::Packet packet = *packetPointer;
117 dispatchPacket(dispatchPacketUserData, packet, sensor->_runningDataIndex, timestamp);
128 return uart::protocol::Packet::Type::TYPE_BINARY;
132 return uart::protocol::Packet::Type::TYPE_UNKNOWN;
137 if (packet.getRawDataLength() <= 8)
144 return packet.getRawData().at(packet.getRawDataLength() - 2) == checksum.first
145 && packet.getRawData().at(packet.getRawDataLength() - 1) == checksum.second;
147 LOG_CRITICAL(
"Can't calculate checksum of packet with unknown type");
Class to read out Espressif Sensors.
Helper Functions to work with Espressif 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_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.
uart::sensors::UartSensor _sensor
UartSensor object which handles the UART interface.
static constexpr uint8_t BINARY_SYNC_CHAR_2
b - Second sync character which begins a new binary message
std::unique_ptr< uart::protocol::Packet > findPacket(uint8_t dataByte)
Collects data bytes and searches for packages inside of them.
static constexpr uint8_t BINARY_SYNC_CHAR_1
ยต - First sync character which begins a new binary message
EspressifUartSensor()=default
Default constructor.
bool _currentlyBuildingBinaryPacket
Flag if currently a binary packet is built.
bool _binaryPayloadLength1Found
Flag if the first byte of the payload length was found.
EspressifUartSensor(std::string name)
Constructor.
static uart::protocol::Packet::Type packetTypeFunction(const uart::protocol::Packet &packet)
Function which is called to determine the packet type (ascii/binary)
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.
bool _binarySyncChar2Found
Flag if the second binary end character was found.
static bool checksumFunction(const uart::protocol::Packet &packet)
Function which is called to verify packet integrity.
const std::string _name
Name of the Parent Node.
static bool isErrorFunction(const uart::protocol::Packet &packet)
Function which determines, if the packet is an Error Packet.
size_t _numOfBytesRemainingForCompletePacket
Amount of bytes remaining for a complete packet.
uint16_t _binaryPayloadLength
Payload length of the current packet.
bool _binaryPayloadLength2Found
Flag if the second byte of the payload length was found.
static bool isResponseFunction(const uart::protocol::Packet &packet)
Function which determines, if the packet is a Response.
void resetTracking()
Resets the current message tracking.
std::vector< uint8_t > _buffer
Buffer to collect messages till they are complete.
static constexpr uart::Endianness ENDIANNESS
Endianess of the sensor.
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.