remove HDLC framing including CRC
Some checks failed
EIVE/eive-obsw/pipeline/pr-develop There was a failure building this commit

This commit is contained in:
Robin Müller 2022-11-16 14:42:18 +01:00
parent 3510cc85fc
commit 5b770a6407
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
4 changed files with 32 additions and 7 deletions

View File

@ -1051,9 +1051,14 @@ ReturnValue_t PlocSupvUartManager::parseRecRingBufForHdlc(size_t& readSize, size
if (encodedBuf[idx] == HDLC_END_MARKER) {
if (startMarkerFound) {
// Probably a packet, so decode it
hdlc_remove_framing(encodedBuf.data() + startIdx, idx + 1 - startIdx, decodedBuf.data(),
&decodedLen);
int retval = hdlc_remove_framing_with_crc_check(
encodedBuf.data() + startIdx, idx + 1 - startIdx, decodedBuf.data(), &decodedLen);
readSize = idx + 1;
if (retval == -1 or retval == -2) {
triggerEvent(HDLC_FRAME_REMOVAL_ERROR, retval);
} else if (retval == 1) {
triggerEvent(HDLC_CRC_ERROR);
}
return returnvalue::OK;
} else {
readSize = ++idx;

View File

@ -114,6 +114,8 @@ class PlocSupvUartManager : public DeviceCommunicationIF,
//! [EXPORT] : [COMMENT] Will be triggered every 5 percent of the update progress.
//! P1: First byte percent, third and fourth byte Sequence Count, P2: Bytes written
static constexpr Event SUPV_UPDATE_PROGRESS = MAKE_EVENT(30, severity::INFO);
static constexpr Event HDLC_FRAME_REMOVAL_ERROR = MAKE_EVENT(31, severity::INFO);
static constexpr Event HDLC_CRC_ERROR = MAKE_EVENT(32, severity::INFO);
PlocSupvUartManager(object_id_t objectId);
virtual ~PlocSupvUartManager();
@ -167,6 +169,7 @@ class PlocSupvUartManager : public DeviceCommunicationIF,
static constexpr ReturnValue_t POSSIBLE_PACKET_LOSS_CONSECUTIVE_START =
returnvalue::makeCode(1, 3);
static constexpr ReturnValue_t POSSIBLE_PACKET_LOSS_CONSECUTIVE_END = returnvalue::makeCode(1, 4);
static constexpr ReturnValue_t HDLC_ERROR = returnvalue::makeCode(1, 5);
static const uint16_t CRC16_INIT = 0xFFFF;
// Event buffer reply will carry 24 space packets with 1016 bytes and one space packet with

12
thirdparty/tas/hdlc.c vendored
View File

@ -55,15 +55,15 @@ void hdlc_add_framing(const uint8_t *src, size_t slen, uint8_t *dst, size_t *dle
*dlen = tlen;
}
int hdlc_remove_framing(const uint8_t *src, size_t slen, uint8_t *dst, size_t *dlen)
int hdlc_remove_framing_with_crc_check(const uint8_t *src, size_t slen, uint8_t *dst, size_t *dlen)
{
uint16_t tlen = 0;
uint16_t ii;
uint8_t bt;
*dlen = 0;
if (slen == 0) return -1;
if ((src[tlen] != 0x7E) && (src[slen-1] != 0x7C)) return -1;
if (slen < 4) return -1;
if ((src[tlen] != 0x7E) && (src[slen-1] != 0x7C)) return -2;
for (ii = 1; ii < slen-1; ii++)
{
bt = *src++;
@ -74,7 +74,11 @@ int hdlc_remove_framing(const uint8_t *src, size_t slen, uint8_t *dst, size_t *d
}
dst[tlen++] = bt;
}
*dlen = tlen;
// calc crc16
if(calc_crc16_buff_reflected( dst, tlen ) != 0) {
return 1;
}
*dlen = tlen - 2;
return 0;
}

View File

@ -28,7 +28,20 @@ extern "C" {
void hdlc_add_framing(const uint8_t *src, size_t slen, uint8_t *dst, size_t *dlen);
int hdlc_remove_framing(const uint8_t *src, size_t slen, uint8_t *dst, size_t *dlen);
/**
* Decode a HDLC frame, including CRC check and CRC removal in addition
* to the removal of the frame markers.
* @param src
* @param slen
* @param dst
* @param dlen
* @return
* -1 Invalid source length
* -2 No start marker at first byte or end marker at slen - 1
* 1 Invalid CRC
* 0 CRC OK, framing and CRC removed
*/
int hdlc_remove_framing_with_crc_check(const uint8_t *src, size_t slen, uint8_t *dst, size_t *dlen);
#ifdef __cplusplus
}