[chirp_devel] [PATCH] Fix Icom radio detection

Martin Cooper
Sun Jul 26 20:45:04 PDT 2020


# HG changeset patch
# User Martin Cooper <mfncooper at gmail.com>
# Date 1595606974 25200
#      Fri Jul 24 09:09:34 2020 -0700
# Node ID 7c40348d9e67a9877bd9ea57970deebe835f95f2
# Parent  37a6a6d6f42535562669c8d3fc4e3765a218aa2d
Fix Icom radio detection

Icom radio detection has been broken for a long time, because the
detection code is expecting to be passed a radio instance, but is
being passed a serial port instead. Since we are trying to determine
the model, we don't have the relevant class yet. Instead, create a
minimal radio instance to allow us to query for the model.

These changes fix both the 'Detect' option in the 'Download From
Radio' menu and the 'chirpc --id' command.

Fixes #7905

diff --git a/chirp/detect.py b/chirp/detect.py
--- a/chirp/detect.py
+++ b/chirp/detect.py
@@ -16,12 +16,20 @@
 import serial
 import logging
 
-from chirp import errors, directory
+from chirp import chirp_common, errors, directory
 from chirp.drivers import ic9x_ll, icf, kenwood_live, icomciv
 
 LOG = logging.getLogger(__name__)
 
 
+class DetectorRadio(chirp_common.Radio):
+    """Minimal radio for model detection"""
+    MUNCH_CLONE_RESP = False
+
+    def get_payload(self, data, raw, checksum):
+        return data
+
+
 def _icom_model_data_to_rclass(md):
     for _rtype, rclass in directory.DRV_TO_RADIO.items():
         if rclass.VENDOR != "Icom":
@@ -40,7 +48,7 @@
 
     try:
         ser.baudrate = 9600
-        md = icf.get_model_data(ser)
+        md = icf.get_model_data(DetectorRadio(ser))
         return _icom_model_data_to_rclass(md)
     except errors.RadioError, e:
         LOG.error("_detect_icom_radio: %s", e)
diff --git a/chirpc b/chirpc
--- a/chirpc
+++ b/chirpc
@@ -196,10 +196,9 @@
         sys.exit(0)
 
     if options.id:
-        from chirp import icf
-        s = serial.Serial(port=options.serial, baudrate=9600, timeout=0.5)
-        md = icf.get_model_data(s)
-        print "Model:\n%s" % util.hexprint(md)
+        from chirp import detect
+        md = detect.detect_icom_radio(options.serial)
+        print "Model:\n%s" % md.MODEL
         sys.exit(0)
 
     if not options.radio:



More information about the chirp_devel mailing list