[chirp_devel] [PATCH] [THD72] Fix buggy memory initialization. #1611

Tom Hayward
Mon Mar 20 22:07:59 PDT 2017


# HG changeset patch
# User Tom Hayward <tom at tomh.us>
# Date 1490072555 25200
#      Mon Mar 20 22:02:35 2017 -0700
# Node ID cb2203c77d167562ad77ce005a3fc76fff3645de
# Parent  6b5b397b4859dd64603d7c4a0b91ffdbdfbe2bb6
[THD72] Fix buggy memory initialization. #1611

Allows channels added by Chirp to transmit.

diff -r 6b5b397b4859 -r cb2203c77d16 chirp/drivers/thd72.py
--- a/chirp/drivers/thd72.py	Fri Mar 17 15:17:57 2017 -0700
+++ b/chirp/drivers/thd72.py	Mon Mar 20 22:02:35 2017 -0700
@@ -69,6 +69,12 @@
   u8   passwd[6];
 } frontmatter;
 
+#seekto 0x02c0;
+struct {
+  ul32 start_freq;
+  ul32 end_freq;
+} prog_vfo[6];
+
 #seekto 0x0300;
 struct {
   char power_on_msg[8];
@@ -89,8 +95,8 @@
 
 #seekto 0x0c00;
 struct {
-  u8 disabled:7,
-     unknown0:1;
+  u8 disabled:4,
+     prog_vfo:4;
   u8 skip;
 } flag[1032];
 
@@ -183,8 +189,23 @@
 EXCH_R = "R\x00\x00\x00\x00"
 EXCH_W = "W\x00\x00\x00\x00"
 
-# Uploads result in "MCP Error" and garbage data in memory
-# Clone driver disabled in favor of error-checking live driver.
+DEFAULT_PROG_VFO = (
+    (136000000, 174000000),
+    (410000000, 470000000),
+    (118000000, 136000000),
+    (136000000, 174000000),
+    (320000000, 400000000),
+    (400000000, 524000000),
+)
+# index of PROG_VFO used for setting memory.unknown1 and memory.unknown2
+# see http://chirp.danplanet.com/issues/1611#note-9
+UNKNOWN_LOOKUP = (0, 7, 4, 0, 4, 7)
+
+def get_prog_vfo(frequency):
+    for i, (start, end) in enumerate(DEFAULT_PROG_VFO):
+        if start <= frequency < end:
+            return i
+    raise ValueError("Frequency is out of range.")
 
 
 @directory.register
@@ -283,7 +304,7 @@
 
     def get_raw_memory(self, number):
         return repr(self._memobj.memory[number]) + \
-            repr(self._memobj.flag[(number)])
+            repr(self._memobj.flag[number])
 
     def get_memory(self, number):
         if isinstance(number, str):
@@ -305,7 +326,7 @@
 
         if number > 999:
             mem.extd_number = THD72_SPECIAL_REV[number]
-        if flag.disabled == 0x7f:
+        if flag.disabled == 0xf:
             mem.empty = True
             return mem
 
@@ -348,9 +369,9 @@
         self.add_dirty_block(self._memobj.flag[mem.number])
 
         # only delete non-WX channels
-        was_empty = flag.disabled == 0x7f
+        was_empty = flag.disabled == 0xf
         if mem.empty:
-            flag.disabled = 0x7f
+            flag.disabled = 0xf
             return
         flag.disabled = 0
 
@@ -373,6 +394,10 @@
         _mem.offset = mem.offset
         _mem.mode = MODES_REV[mem.mode]
 
+        prog_vfo = get_prog_vfo(mem.freq)
+        flag.prog_vfo = prog_vfo
+        _mem.unknown1 = _mem.unknown2 = UNKNOWN_LOOKUP[prog_vfo]
+
         if mem.number < 999:
             flag.skip = chirp_common.SKIP_VALUES.index(mem.skip)
 
@@ -509,9 +534,8 @@
             raise errors.RadioError("No response to ID command")
 
     def initialize(self, mmap):
-        mmap[0] = \
-            "\x80\xc8\xb3\x08\x00\x01\x00\x08" + \
-            "\x08\x00\xc0\x27\x09\x00\x00\xff"
+        mmap.set_raw("\x00\xc8\xb3\x08\x00\x01\x00\x08"
+                     "\x08\x00\xc0\x27\x09\x00\x00\x00")
 
     def _get_settings(self):
         top = RadioSettings(self._get_display_settings(),



More information about the chirp_devel mailing list