crc check now works
This commit is contained in:
10
thirdparty/tas/hdlc.c
vendored
10
thirdparty/tas/hdlc.c
vendored
@ -14,9 +14,9 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
static void hdlc_add_byte(uint8_t ch, uint8_t *buff, uint16_t *pos)
|
||||
void hdlc_add_byte(uint8_t ch, uint8_t *buff, size_t *pos)
|
||||
{
|
||||
uint16_t templen = *pos;
|
||||
size_t templen = *pos;
|
||||
|
||||
if ((ch == 0x7E) ||
|
||||
(ch == 0x7D) ||
|
||||
@ -32,7 +32,7 @@ static void hdlc_add_byte(uint8_t ch, uint8_t *buff, uint16_t *pos)
|
||||
|
||||
void hdlc_add_framing(const uint8_t *src, size_t slen, uint8_t *dst, size_t *dlen)
|
||||
{
|
||||
uint16_t tlen = 0;
|
||||
size_t tlen = 0;
|
||||
uint16_t ii;
|
||||
uint16_t crc16;
|
||||
uint8_t bt;
|
||||
@ -48,6 +48,9 @@ void hdlc_add_framing(const uint8_t *src, size_t slen, uint8_t *dst, size_t *dle
|
||||
}
|
||||
|
||||
// hdlc crc16 is in little endian format
|
||||
// WARNING: This is not portable code! Bytes need to be swapped on a big
|
||||
// endian system
|
||||
// TODO: Fix
|
||||
hdlc_add_byte((uint8_t) (crc16 & 0xFF), dst, &tlen);
|
||||
hdlc_add_byte((uint8_t) ((crc16 >> 8) & 0xFF), dst, &tlen);
|
||||
|
||||
@ -75,6 +78,7 @@ int hdlc_remove_framing_with_crc_check(const uint8_t *src, size_t slen, uint8_t
|
||||
dst[tlen++] = bt;
|
||||
}
|
||||
// calc crc16
|
||||
// TODO: Warning: This does not work because the CRC16 is little endian
|
||||
if(calc_crc16_buff_reflected( dst, tlen ) != 0) {
|
||||
return 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user