119 LOG_ERROR(
"{}: Discarding current packet, because buffer is full.",
_name);
129 switch (binaryPacketType)
150 memcpy(
_buffer.data(), &header, 4);
172 auto p = std::make_unique<uart::protocol::Packet>(
_buffer, &
_sensor);
207 auto p = std::make_unique<uart::protocol::Packet>(
_buffer, &
_sensor);
212 LOG_DATA(
"{}: Valid ascii packet: {}",
_name, p->datastr().substr(0, p->getRawDataLength() - 2));
225 LOG_ERROR(
"{}: Buffer exceeded the Maximum Ascii Packet Size",
_name);
237 for (
size_t i = 0; i < data.size(); i++, sensor->_runningDataIndex++)
239 auto packetPointer = sensor->findPacket(data.at(i));
241 if (packetPointer !=
nullptr)
243 uart::protocol::Packet packet = *packetPointer;
244 dispatchPacket(dispatchPacketUserData, packet, sensor->_runningDataIndex, timestamp);
251 if (packet.getRawDataLength() < 1)
257 if (packet.getRawData().at(packet.getRawDataLength() - 2) == uart::CARRIAGE_RETURN
258 && packet.getRawData().at(packet.getRawDataLength() - 1) == uart::LINE_FEED)
260 return uart::protocol::Packet::Type::TYPE_ASCII;
263 uint32_t data_zero{};
264 memcpy(&data_zero, packet.getRawData().data(),
sizeof(uint32_t));
265 data_zero = uart::stoh(data_zero,
ENDIANNESS);
269 return uart::protocol::Packet::Type::TYPE_BINARY;
272 return uart::protocol::Packet::Type::TYPE_UNKNOWN;
278 if (packet.getRawDataLength() < 1)
283 if (packet.type() == uart::protocol::Packet::Type::TYPE_ASCII)
289 if (packet.type() == uart::protocol::Packet::Type::TYPE_BINARY)
293 uint32_t checksumPacket = 0;
294 memcpy(&checksumPacket, packet.getRawData().data() + packet.getRawDataLength() -
sizeof(uint32_t),
sizeof(uint32_t));
295 checksumPacket = uart::stoh(checksumPacket,
ENDIANNESS);
297 return checksumPacket == checksumCalc;
300 LOG_CRITICAL(
"Can't calculate checksum of packet with unknown type");
Class to read out KVH Sensors.
Helper Functions to work with Kvh 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 constexpr uint32_t HEADER_FMT_XBIT2
Header Format X Bit 2.
HeaderType _packetType
Current packet type determined by the header.
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 uint32_t HEADER_FMT_A
Header Format A.
static constexpr uint32_t HEADER_FMT_B
Header Format B.
std::unique_ptr< uart::protocol::Packet > findPacket(uint8_t dataByte)
Collects data bytes and searches for packages inside of them.
static bool checksumFunction(const uart::protocol::Packet &packet)
Function which is called to verify packet integrity.
bool _asciiEndChar1Found
Flag if the first ascii end character was found.
const std::string _name
Name of the Parent Node.
static constexpr uart::Endianness ENDIANNESS
Endianess of the sensor.
void resetTracking()
Resets the current message tracking.
std::vector< uint8_t > _buffer
Buffer to collect messages till they are complete.
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.
HeaderType
Possible Header Types.
@ FMT_UNKNOWN
Unknown format.
static uart::protocol::Packet::Type packetTypeFunction(const uart::protocol::Packet &packet)
Function which is called to determine the packet type (ascii/binary)
static constexpr uint32_t HEADER_FMT_C
Header Format C.
static bool isErrorFunction(const uart::protocol::Packet &packet)
Function which determines, if the packet is an Error Packet.
static constexpr uint32_t HEADER_FMT_XBIT
Header Format X Bit.
static constexpr uint8_t ASCII_END_CHAR_2
Second Ascii End character.
KvhUartSensor(std::string name)
Constructor.
static constexpr size_t MAX_SIZE_ASCII_PACKET
Maximum size of a ascii packet before resetting it.
static constexpr uint8_t ASCII_ESCAPE_CHAR
Ascii Escape charater.
TagState _eState
Current state of the header building process.
HeaderType bFindImuHeader(uint8_t ui8Data)
Function which finds the header from the provided data.
bool _currentlyBuildingAsciiPacket
Flag if currently a ascii packet is built.
KvhUartSensor()=default
Default constructor.
static bool isResponseFunction(const uart::protocol::Packet &packet)
Function which determines, if the packet is a Response.
uint32_t ui32CalcImuCRC(const std::vector< uint8_t > &rawData)
Calculates the checksum of the provided rawData vector.
void move(std::vector< T > &v, size_t sourceIdx, size_t targetIdx)
Moves an element within a vector to a new position.