Commit d0b58381 authored by Ilias Daradimos's avatar Ilias Daradimos Committed by Manolis Surligas

Add CRC16 AUG-CCITT

Signed-off-by: Ilias Daradimos's avatarIlias Daradimos <[email protected]>
parent c6ef1cd3
Pipeline #168868026 passed with stages
in 25 minutes and 55 seconds
......@@ -35,6 +35,7 @@ public:
typedef enum crc_type {
CRC_NONE = 0,
CRC16_CCITT,
CRC16_AUG_CCITT,
CRC16_CCITT_REVERSED,
CRC16_AX25,
CRC16_IBM,
......@@ -48,6 +49,9 @@ public:
static uint16_t
crc16_ccitt(const uint8_t *data, size_t len);
static uint16_t
crc16_aug_ccitt(const uint8_t *data, size_t len);
static uint16_t
crc16_ax25(const uint8_t *data, size_t len);
......@@ -73,4 +77,3 @@ private:
} // namespace gr
#endif /* INCLUDED_SATNOGS_CRC_H */
......@@ -166,6 +166,16 @@ crc::crc16_ccitt(const uint8_t *data, size_t len)
return crc;
}
uint16_t
crc::crc16_aug_ccitt(const uint8_t *data, size_t len)
{
uint16_t crc = 0x1D0F;
while (len-- != 0) {
crc = crc16_ccitt_table[((crc >> 8) ^ *data++) & 0xff] ^ (crc << 8);
}
return crc ^ 0xFFFF;
}
uint16_t
crc::crc16_ax25(const uint8_t *data, size_t len)
{
......@@ -214,6 +224,7 @@ crc::crc_size(crc_t t)
case CRC_NONE:
return 0;
case CRC16_CCITT:
case CRC16_AUG_CCITT:
case CRC16_CCITT_REVERSED:
case CRC16_AX25:
case CRC16_IBM:
......@@ -250,6 +261,14 @@ crc::append(crc_t t, uint8_t *out, const uint8_t *data, size_t len,
memcpy(out, &x, sizeof(x));
return sizeof(x);
}
case CRC16_AUG_CCITT: {
uint16_t x = crc16_ccitt(data, len);
if (nbo) {
x = htons(x);
}
memcpy(out, &x, sizeof(x));
return sizeof(x);
}
case CRC16_CCITT_REVERSED: {
uint16_t x = crc16_ccitt_reversed(data, len);
if (nbo) {
......@@ -289,5 +308,3 @@ crc::append(crc_t t, uint8_t *out, const uint8_t *data, size_t len,
} /* namespace satnogs */
} /* namespace gr */
......@@ -348,6 +348,12 @@ ieee802_15_4_variant_decoder::check_crc()
return true;
}
return false;
case crc::CRC16_AUG_CCITT:
crc16_c = crc::crc16_aug_ccitt(d_pdu, d_len + d_length_field_len - 2);
memcpy(&crc16_received, d_pdu + d_length_field_len + d_len - 2, 2);
crc16_received = ntohs(crc16_received);
LOG_DEBUG("Received: 0x%02x Computed: 0x%02x", crc16_received, crc16_c);
return (crc16_c == crc16_received);
case crc::CRC16_CCITT_REVERSED:
crc16_c = crc::crc16_ccitt_reversed(d_pdu, d_len + d_length_field_len - 2);
memcpy(&crc16_received, d_pdu + d_length_field_len + d_len - 2, 2);
......@@ -382,4 +388,3 @@ ieee802_15_4_variant_decoder::check_crc()
} /* namespace satnogs */
} /* namespace gr */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment