PLOC SUPV Update to newer firmware #316

Merged
muellerr merged 99 commits from mueller/tas_ploc_supv_update into develop 2022-11-18 14:27:13 +01:00
4 changed files with 32 additions and 7 deletions
Showing only changes of commit 5b770a6407 - Show all commits

View File

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

View File

@ -114,6 +114,8 @@ class PlocSupvUartManager : public DeviceCommunicationIF,
//! [EXPORT] : [COMMENT] Will be triggered every 5 percent of the update progress. //! [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 //! 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 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); PlocSupvUartManager(object_id_t objectId);
virtual ~PlocSupvUartManager(); virtual ~PlocSupvUartManager();
@ -167,6 +169,7 @@ class PlocSupvUartManager : public DeviceCommunicationIF,
static constexpr ReturnValue_t POSSIBLE_PACKET_LOSS_CONSECUTIVE_START = static constexpr ReturnValue_t POSSIBLE_PACKET_LOSS_CONSECUTIVE_START =
returnvalue::makeCode(1, 3); returnvalue::makeCode(1, 3);
static constexpr ReturnValue_t POSSIBLE_PACKET_LOSS_CONSECUTIVE_END = returnvalue::makeCode(1, 4); 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; static const uint16_t CRC16_INIT = 0xFFFF;
// Event buffer reply will carry 24 space packets with 1016 bytes and one space packet with // 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; *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 tlen = 0;
uint16_t ii; uint16_t ii;
uint8_t bt; uint8_t bt;
*dlen = 0; *dlen = 0;
if (slen == 0) return -1; if (slen < 4) return -1;
if ((src[tlen] != 0x7E) && (src[slen-1] != 0x7C)) return -1; if ((src[tlen] != 0x7E) && (src[slen-1] != 0x7C)) return -2;
for (ii = 1; ii < slen-1; ii++) for (ii = 1; ii < slen-1; ii++)
{ {
bt = *src++; 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; dst[tlen++] = bt;
} }
*dlen = tlen; // calc crc16
if(calc_crc16_buff_reflected( dst, tlen ) != 0) {
return 1;
}
*dlen = tlen - 2;
return 0; 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); 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 #ifdef __cplusplus
} }