diff --git a/SpectrumScan.py b/SpectrumScan.py index fb17802..1bc0513 100644 --- a/SpectrumScan.py +++ b/SpectrumScan.py @@ -50,6 +50,7 @@ def parse_line(line): POLY = 0x1021 def crc16(s, c): + c = c ^ 0xffff for ch in s: c = c ^ (ord(ch) << 8) for i in range(8): @@ -58,7 +59,7 @@ def crc16(s, c): else: c = (c << 1) & 0xffff - return c + return c ^ 0xffff def main(): parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description='''\ diff --git a/lib/comms/comms.cpp b/lib/comms/comms.cpp index 9fd3c4e..176ec6a 100644 --- a/lib/comms/comms.cpp +++ b/lib/comms/comms.cpp @@ -123,6 +123,7 @@ String _wrap_str(String); #define POLY 0x1021 uint16_t crc16(String v, uint16_t c) { + c ^= 0xffff; for (int i = 0; i < v.length(); i++) { uint16_t ch = v.charAt(i); @@ -140,7 +141,7 @@ uint16_t crc16(String v, uint16_t c) } } - return c; + return c ^ 0xffff; } void ReadlineComms::_onReceive() diff --git a/spectrum_scan.c b/spectrum_scan.c index aa8c9c9..f23cd85 100644 --- a/spectrum_scan.c +++ b/spectrum_scan.c @@ -13,6 +13,7 @@ typedef struct { #define POLY 0x1021 uint16_t crc16(char *p, char *end, uint16_t c) { + c ^= 0xffff; if (end == NULL) { end = strchr(p, 0); } @@ -29,7 +30,7 @@ uint16_t crc16(char *p, char *end, uint16_t c) { } } - return c; + return c ^ 0xffff; } #define BUFSIZE 102400