From 303f43e74aee56f64318be7b0507d0f7a70c1897 Mon Sep 17 00:00:00 2001
From: Gerhard Sittig <gerhard.sittig@gmx.net>
Date: Fri, 17 Jul 2020 09:12:17 +0200
Subject: pjon: unbreak CRC32 check, adjust data length

The previous implementation unconditionally assumed a CRC width of
one byte when it calculated the checksum for received frame data.
Do reflect on the CRC8/CRC32 choice instead.

This patch is based on a fix that was
Submitted-By: Julio Aguirre <jcallano@gmail.com>
---
 decoders/pjon/pd.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

(limited to 'decoders/pjon')

diff --git a/decoders/pjon/pd.py b/decoders/pjon/pd.py
index 0c75f89..f9634e1 100644
--- a/decoders/pjon/pd.py
+++ b/decoders/pjon/pd.py
@@ -381,12 +381,13 @@ class Decoder(srd.Decoder):
         # across meta and end checksums in a frame's fields.
         caption = 'META' if is_meta else 'END'
         crc_len = 8 if is_meta else 32 if self.cfg_crc32 else 8
+        crc_bytes = crc_len // 8
         crc_fmt = '{:08x}' if crc_len == 32 else '{:02x}'
         have_text = crc_fmt.format(have)
 
         # Check received against expected checksum. Emit warnings.
         warn_texts = []
-        data = self.frame_bytes[:-1]
+        data = self.frame_bytes[:-crc_bytes]
         want = calc_crc32(data) if crc_len == 32 else calc_crc8(data)
         if want != have:
             want_text = crc_fmt.format(want)
-- 
cgit v1.2.3-70-g09d2