From fd4b309e0b98ffe1f73ce51bc687e46ca854f9b2 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Wed, 10 Oct 2018 09:47:34 +0200 Subject: [PATCH] PXX2 uses S.PORT CRC algorithm --- radio/src/pulses/pxx2.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/radio/src/pulses/pxx2.h b/radio/src/pulses/pxx2.h index 1f1384a62..939d0204d 100644 --- a/radio/src/pulses/pxx2.h +++ b/radio/src/pulses/pxx2.h @@ -23,11 +23,29 @@ #include "./pxx.h" -class Pxx2Transport: public DataBuffer, public PxxCrcMixin { +class SportCrcMixin { + protected: + void initCrc() + { + crc = 0; + } + + void addToCrc(uint8_t byte) + { + crc += byte; // 0-1FF + crc += crc >> 8; // 0-100 + crc &= 0x00ff; + } + + uint16_t crc; +}; + + +class Pxx2Transport: public DataBuffer, public SportCrcMixin { protected: void addByte(uint8_t byte) { - PxxCrcMixin::addToCrc(byte); + SportCrcMixin::addToCrc(byte); *ptr++ = byte; }