Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: encode information in header format enum #64

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
35 changes: 20 additions & 15 deletions include/novatel_edie/decoders/common/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,28 @@ inline std::ostream& operator<<(std::ostream& os_, const ENCODE_FORMAT eFormat_)
//-----------------------------------------------------------------------
enum class HEADER_FORMAT
{
UNKNOWN = 1,
BINARY,
SHORT_BINARY,
PROPRIETARY_BINARY,
ASCII,
SHORT_ASCII,
ABB_ASCII,
NMEA,
JSON,
SHORT_ABB_ASCII,
ALL // Used in filters to indicate all filter types : all new enums should be added before this value
// Bit 0-3: Reserved
// Bit 4: Abbreviated
// Bit 5: Short
// Bit 6: ASCII
// Bit 7: Binary
UNKNOWN = 0b00000000,
BINARY = 0b10000000,
SHORT_BINARY = 0b10100000,
PROPRIETARY_BINARY = 0b10000001,
ASCII = 0b01000000,
SHORT_ASCII = 0b01100000,
ABB_ASCII = 0b01010000,
SHORT_ABB_ASCII = 0b01110000,
NMEA = 0b00000001,
JSON = 0b00000010,
ALL = 0b11111111
};

constexpr bool IsShortHeaderFormat(const HEADER_FORMAT eFormat_)
{
return eFormat_ == HEADER_FORMAT::SHORT_ASCII || eFormat_ == HEADER_FORMAT::SHORT_BINARY || eFormat_ == HEADER_FORMAT::SHORT_ABB_ASCII;
}
constexpr bool IsBinary(const HEADER_FORMAT eFormat_) { return static_cast<int32_t>(eFormat_) & 1 << 7; }
constexpr bool IsAscii(const HEADER_FORMAT eFormat_) { return static_cast<int32_t>(eFormat_) & 1 << 6; }
constexpr bool IsShort(const HEADER_FORMAT eFormat_) { return static_cast<int32_t>(eFormat_) & 1 << 5; }
constexpr bool IsAbbreviated(const HEADER_FORMAT eFormat_) { return static_cast<int32_t>(eFormat_) & 1 << 4; }

//-----------------------------------------------------------------------
//! \enum MESSAGE_FORMAT
Expand Down
11 changes: 5 additions & 6 deletions src/decoders/common/src/message_decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,12 +743,11 @@ MessageDecoderBase::Decode(const unsigned char* pucMessage_, std::vector<FieldCo
stInterMessage_.reserve(pvCurrentMsgFields->size());

// Decode the detected format
return stMetaData_.eFormat == HEADER_FORMAT::ASCII || stMetaData_.eFormat == HEADER_FORMAT::SHORT_ASCII
? DecodeAscii<false>(*pvCurrentMsgFields, reinterpret_cast<const char**>(&pucTempInData), stInterMessage_)
: stMetaData_.eFormat == HEADER_FORMAT::ABB_ASCII || stMetaData_.eFormat == HEADER_FORMAT::SHORT_ABB_ASCII
? DecodeAscii<true>(*pvCurrentMsgFields, reinterpret_cast<const char**>(&pucTempInData), stInterMessage_)
: stMetaData_.eFormat == HEADER_FORMAT::BINARY || stMetaData_.eFormat == HEADER_FORMAT::SHORT_BINARY
? DecodeBinary(*pvCurrentMsgFields, &pucTempInData, stInterMessage_, stMetaData_.uiBinaryMsgLength)
return IsBinary(stMetaData_.eFormat) ? DecodeBinary(*pvCurrentMsgFields, &pucTempInData, stInterMessage_, stMetaData_.uiBinaryMsgLength)
: IsAscii(stMetaData_.eFormat)
? (IsAbbreviated(stMetaData_.eFormat)
? DecodeAscii<true>(*pvCurrentMsgFields, reinterpret_cast<const char**>(&pucTempInData), stInterMessage_)
: DecodeAscii<false>(*pvCurrentMsgFields, reinterpret_cast<const char**>(&pucTempInData), stInterMessage_))
: stMetaData_.eFormat == HEADER_FORMAT::JSON ? DecodeJson(*pvCurrentMsgFields, json::parse(pucTempInData)["body"], stInterMessage_)
: STATUS::UNKNOWN;
}
24 changes: 10 additions & 14 deletions src/decoders/oem/src/encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,30 +388,30 @@ Encoder::EncodeHeader(unsigned char** ppucBuffer_, uint32_t uiBufferSize_, const
switch (eFormat_)
{
case ENCODE_FORMAT::ASCII:
if (IsShortHeaderFormat(stMetaData_.eFormat) ? !EncodeAsciiShortHeader(stHeader_, ppcTempBuffer, uiBufferSize_)
: !EncodeAsciiHeader(stHeader_, ppcTempBuffer, uiBufferSize_))
if (IsShort(stMetaData_.eFormat) ? !EncodeAsciiShortHeader(stHeader_, ppcTempBuffer, uiBufferSize_)
: !EncodeAsciiHeader(stHeader_, ppcTempBuffer, uiBufferSize_))
{
return STATUS::BUFFER_FULL;
}
break;
case ENCODE_FORMAT::ABBREV_ASCII:
if (IsShortHeaderFormat(stMetaData_.eFormat) ? !EncodeAbbrevAsciiShortHeader(stHeader_, ppcTempBuffer, uiBufferSize_)
: !EncodeAbbrevAsciiHeader(stHeader_, ppcTempBuffer, uiBufferSize_, bIsEmbeddedHeader_))
if (IsShort(stMetaData_.eFormat) ? !EncodeAbbrevAsciiShortHeader(stHeader_, ppcTempBuffer, uiBufferSize_)
: !EncodeAbbrevAsciiHeader(stHeader_, ppcTempBuffer, uiBufferSize_, bIsEmbeddedHeader_))
{
return STATUS::BUFFER_FULL;
}
break;
case ENCODE_FORMAT::FLATTENED_BINARY: [[fallthrough]];
case ENCODE_FORMAT::BINARY:
if (IsShortHeaderFormat(stMetaData_.eFormat) ? !EncodeBinaryShortHeader(stHeader_, &pucTempBuffer, uiBufferSize_)
: !EncodeBinaryHeader(stHeader_, &pucTempBuffer, uiBufferSize_))
if (IsShort(stMetaData_.eFormat) ? !EncodeBinaryShortHeader(stHeader_, &pucTempBuffer, uiBufferSize_)
: !EncodeBinaryHeader(stHeader_, &pucTempBuffer, uiBufferSize_))
{
return STATUS::BUFFER_FULL;
}
break;
case ENCODE_FORMAT::JSON:
if (IsShortHeaderFormat(stMetaData_.eFormat) ? !EncodeJsonShortHeader(stHeader_, ppcTempBuffer, uiBufferSize_)
: !EncodeJsonHeader(stHeader_, ppcTempBuffer, uiBufferSize_))
if (IsShort(stMetaData_.eFormat) ? !EncodeJsonShortHeader(stHeader_, ppcTempBuffer, uiBufferSize_)
: !EncodeJsonHeader(stHeader_, ppcTempBuffer, uiBufferSize_))
{
return STATUS::BUFFER_FULL;
}
Expand Down Expand Up @@ -465,15 +465,11 @@ Encoder::EncodeBody(unsigned char** ppucBuffer_, uint32_t uiBufferSize_, const s
if (stMessageData_.pucMessageHeader == nullptr) { return STATUS::FAILURE; }
// Go back and set the length field in the header.
// TODO: this little block of code below is what's blocking us from moving this function to common
if (stMetaData_.eFormat == HEADER_FORMAT::ASCII || stMetaData_.eFormat == HEADER_FORMAT::BINARY ||
stMetaData_.eFormat == HEADER_FORMAT::ABB_ASCII)
{
reinterpret_cast<Oem4BinaryHeader*>(stMessageData_.pucMessageHeader)->usLength = static_cast<uint16_t>(pucTempBuffer - *ppucBuffer_);
}
else
if (IsShort(stMetaData_.eFormat))
{
reinterpret_cast<Oem4BinaryShortHeader*>(stMessageData_.pucMessageHeader)->ucLength = static_cast<uint8_t>(pucTempBuffer - *ppucBuffer_);
}
else { reinterpret_cast<Oem4BinaryHeader*>(stMessageData_.pucMessageHeader)->usLength = static_cast<uint16_t>(pucTempBuffer - *ppucBuffer_); }
uint32_t uiCrc = CalculateBlockCrc32(pucTempBuffer - stMessageData_.pucMessageHeader, 0, stMessageData_.pucMessageHeader);
if (!CopyToBuffer(&pucTempBuffer, uiBufferSize_, &uiCrc)) { return STATUS::BUFFER_FULL; }
break;
Expand Down
4 changes: 1 addition & 3 deletions src/decoders/oem/src/framer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ Framer::GetFrame(unsigned char* pucFrameBuffer_, const uint32_t uiFrameBufferSiz
stMetaData_.uiLength = uiMyByteCount;

// non-ASCII characters in an ASCII message indicates a corrupt log or unknown data. Either way, mark the data as unknown
if ((stMetaData_.eFormat == HEADER_FORMAT::ASCII || stMetaData_.eFormat == HEADER_FORMAT::SHORT_ASCII ||
stMetaData_.eFormat == HEADER_FORMAT::ABB_ASCII || stMetaData_.eFormat == HEADER_FORMAT::NMEA ||
stMetaData_.eFormat == HEADER_FORMAT::JSON) &&
if ((IsAscii(stMetaData_.eFormat) || stMetaData_.eFormat == HEADER_FORMAT::NMEA || stMetaData_.eFormat == HEADER_FORMAT::JSON) &&
ucDataByte > 127)
{
stMetaData_.eFormat = HEADER_FORMAT::UNKNOWN;
Expand Down
3 changes: 1 addition & 2 deletions src/decoders/oem/src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ Parser::Read(MessageDataStruct& stMessageData_, MetaDataStruct& stMetaData_, boo
// eFormat is HEADER_FORMAT::ABB_ASCII or HEADER_FORMAT::SHORT_ABB_ASCII then flush the framer
// and attempt to decode that data.

if (bDecodeIncompleteAbbreviated_ && eStatus == STATUS::INCOMPLETE &&
(stMetaData_.eFormat == HEADER_FORMAT::ABB_ASCII || stMetaData_.eFormat == HEADER_FORMAT::SHORT_ABB_ASCII))
if (bDecodeIncompleteAbbreviated_ && eStatus == STATUS::INCOMPLETE && IsAbbreviated(stMetaData_.eFormat))
{
uint32_t uiFlushSize = clMyFramer.Flush(pucMyFrameBufferPointer, uiParserInternalBufferSize);
if (uiFlushSize > 0)
Expand Down
12 changes: 4 additions & 8 deletions src/decoders/oem/src/rangecmp/range_decompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,14 +1057,10 @@ RangeDecompressor::Decompress(unsigned char* pucRangeMessageBuffer_, uint32_t ui
// Re-encode to the original format if a format was not specified.
if (eFormat_ == ENCODE_FORMAT::UNSPECIFIED)
{
eFormat_ =
(eInitialFormat == HEADER_FORMAT::BINARY || eInitialFormat == HEADER_FORMAT::SHORT_BINARY ||
eInitialFormat == HEADER_FORMAT::PROPRIETARY_BINARY)
? ENCODE_FORMAT::BINARY
: (eInitialFormat == HEADER_FORMAT::ASCII || eInitialFormat == HEADER_FORMAT::SHORT_ASCII || eInitialFormat == HEADER_FORMAT::ABB_ASCII)
? ENCODE_FORMAT::ASCII
: (eInitialFormat == HEADER_FORMAT::JSON) ? ENCODE_FORMAT::JSON
: ENCODE_FORMAT::ASCII; // Default to ASCII
eFormat_ = IsBinary(eInitialFormat) ? ENCODE_FORMAT::BINARY
: IsAscii(eInitialFormat) ? ENCODE_FORMAT::ASCII
: eInitialFormat == HEADER_FORMAT::JSON ? ENCODE_FORMAT::JSON
: ENCODE_FORMAT::ASCII; // Default to ASCII
}

// Re-encode the data back into the range message buffer.
Expand Down