[chirp_devel] [PATCH] [IC-T8A] Fix frequency encoding and decoding. Fixes #577

Tom Hayward
Wed May 4 18:20:19 PDT 2016


# HG changeset patch
# User Tom Hayward <tom at tomh.us>
# Date 1462411076 25200
#      Wed May 04 18:17:56 2016 -0700
# Node ID edcad67aca5154dddce0813302eacda0b1849131
# Parent  95af553dbb2e2ddea5f6fa70a532cf6f4d2747df
[IC-T8A] Fix frequency encoding and decoding. Fixes #577

The IC-T8 stores frequencies in three bcd bytes. The last nibble of these three
bytes would naturally be the least significant digit in KHz, but this leaves no
way to encode frequencies divisible by 2.5 KHz. To account for this, the IC-T8
deviates from its standard bcd encoding for the final nibble. Instead of the
nibble representing 1 KHz, it represents 500 Hz: 0x5 is 2.5 KHz, 0xA is 5 KHz,
and so on. This patch implements this encoding and decoding in Chirp.

diff -r 95af553dbb2e -r edcad67aca51 chirp/drivers/ict8.py
--- a/chirp/drivers/ict8.py	Tue May 03 14:44:38 2016 -0700
+++ b/chirp/drivers/ict8.py	Wed May 04 18:17:56 2016 -0700
@@ -19,8 +19,8 @@
 
 mem_format = """
 struct memory {
-  bbcd freq[4];
-  bbcd offset[2];
+  bbcd freq[3];
+  bbcd offset[3];
   u8 rtone;
   u8 ctone;
 };
@@ -48,6 +48,16 @@
 TMODES = ["", "", "Tone", "TSQL"]
 
 
+def _get_freq(bcd_array):
+    lastnibble = bcd_array[2].get_bits(0x0F)
+    return (int(bcd_array) - lastnibble) * 1000 + lastnibble * 500
+
+
+def _set_freq(bcd_array, freq):
+    bitwise.int_to_bcd(bcd_array, freq / 1000)
+    bcd_array[2].set_raw(bcd_array[2].get_bits(0xF0) + freq % 10000 / 500)
+
+
 @directory.register
 class ICT8ARadio(icf.IcomCloneModeRadio):
     """Icom IC-T8A"""
@@ -99,8 +109,8 @@
             mem.empty = True
             return mem
 
-        mem.freq = int(_mem.freq) * 10
-        mem.offset = int(_mem.offset) * 1000
+        mem.freq = _get_freq(_mem.freq)
+        mem.offset = _get_freq(_mem.offset)
         mem.rtone = chirp_common.TONES[_mem.rtone - 1]
         mem.ctone = chirp_common.TONES[_mem.ctone - 1]
         mem.duplex = DUPLEX[_flg.duplex]
@@ -123,8 +133,8 @@
         _mem.set_raw("\x00" * 8)
         _flg.set_raw("\x00")
 
-        _mem.freq = mem.freq / 10
-        _mem.offset = mem.offset / 1000
+        _set_freq(_mem.freq, mem.freq)
+        _set_freq(_mem.offset, mem.offset)
         _mem.rtone = chirp_common.TONES.index(mem.rtone) + 1
         _mem.ctone = chirp_common.TONES.index(mem.ctone) + 1
         _flg.duplex = DUPLEX.index(mem.duplex)



More information about the chirp_devel mailing list