[chirp_devel] Issue #7075; Icom download checksum patch

Rick DeWitt AA0RD
Sun Sep 15 09:17:52 PDT 2019


A patch to the icf.py driver library; adding support for download 
checksum calculation and compare.
This patch has been tested for a raw-mode (IC-2730) radio only.
Nothing can go worng.

-- 
Rick DeWitt
AA0RD
Sequim, Washington, USA 98382
(360) 681-3494

-------------- next part --------------
# HG changeset patch
# User Rick DeWitt <aa0rd at yahoo.com>
# Date 1568563770 25200
#      Sun Sep 15 09:09:30 2019 -0700
# Node ID bb84274889422853066cb665bc9a5b759ae52583
# Parent  71eca0d98e427192ffb9702062977c08f47e0a89
[icf.py] Add download checksum calculation per issue #7075
Added logic in process_data_frame to calculate and compare csum. Issue #7075

diff -r 71eca0d98e42 -r bb8427488942 chirp/drivers/icf.py
--- a/chirp/drivers/icf.py	Tue Sep 03 06:15:04 2019 -0700
+++ b/chirp/drivers/icf.py	Sun Sep 15 09:09:30 2019 -0700
@@ -190,15 +190,35 @@
 def process_data_frame(radio, frame, _mmap):
     """Process a data frame, adding the payload to @_mmap"""
     _data = radio.process_frame_payload(frame.payload)
-    if len(_mmap) >= 0x10000:
+    # Checksum logic added by Rick DeWitt, 9/2019, issue # 7075
+    if len(_mmap) >= 0x10000:   # This map size not tested for checksum
         saddr, = struct.unpack(">I", _data[0:4])
         length, = struct.unpack("B", _data[4])
         data = _data[5:5+length]
-    else:
+        sumc, = struct.unpack("B", _data[5+length])
+        addr1, = struct.unpack("B", _data[0])
+        addr2, = struct.unpack("B", _data[1])
+        addr3, = struct.unpack("B", _data[2])
+        addr4, = struct.unpack("B", _data[3])
+    else:   # But this one has been tested for raw mode radio (IC-2730)
         saddr, = struct.unpack(">H", _data[0:2])
         length, = struct.unpack("B", _data[2])
         data = _data[3:3+length]
+        sumc, = struct.unpack("B", _data[3+length])
+        addr1, = struct.unpack("B", _data[0])
+        addr2, = struct.unpack("B", _data[1])
+        addr3 = 0
+        addr4 = 0
 
+    cs = addr1 + addr2 + addr3 + addr4 + length
+    for byte in data:
+        cs += ord(byte)
+    vx = ((cs ^ 0xFFFF) + 1) & 0xFF
+    if sumc != vx:
+        LOG.error("Bad checksum in address %04X frame: %02x "
+              "calculated, %02x sent!" % (saddr, vx, sumc))
+        raise errors.InvalidDataError("Checksum error in download! "
+              "Try disabling High Speed Clone option in Settings.")
     try:
         _mmap[saddr] = data
     except IndexError:


More information about the chirp_devel mailing list