# HG changeset patch
# User Eric Allen <ericpallen@gmail.com>
# Date 1342540708 25200
# Node ID 3deda8456d9390c02a3ab1445e2820dbd81539e7
# Parent  4a3dbf10d64bedeb358dd6272b95a759d827796b
[t7h] initial support for ICOM IC-T7H

diff -r 4a3dbf10d64b -r 3deda8456d93 chirp/ict7h.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/chirp/ict7h.py	Tue Jul 17 08:58:28 2012 -0700
@@ -0,0 +1,121 @@
+# Copyright 2012 Eric Allen <ericpallen@gmail.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from chirp import chirp_common, icf, directory
+from chirp import bitwise
+
+mem_format = """
+struct {
+  bbcd freq[2];
+  u8  lastfreq:4,
+      fraction:4;
+  bbcd offset[2];
+  u8  unknown;
+  u8  rtone;
+  u8  ctone;
+} memory[60];
+
+#seekto 0x0270;
+struct {
+  u8 empty:1,
+     tmode:2,
+     duplex:2,
+     unknown3:1,
+     skip:1,
+     unknown4:1;
+} flags[60];
+"""
+
+TMODES = ["", "", "Tone", "TSQL", "TSQL"] # last one is pocket beep
+DUPLEX = ["", "", "-", "+"]
+MODES  = ["FM"]
+STEPS =  [5.0, 10.0, 12.5, 15.0, 20.0, 25.0, 30.0, 50.0]
+
+@directory.register
+class ICT7HRadio(icf.IcomCloneModeRadio):
+    VENDOR = "Icom"
+    MODEL = "IC-T7H"
+
+    _model = "\x18\x10\x00\x01"
+    _memsize = 0x03B0
+    _endframe = "Icom Inc\x2e"
+
+    _ranges = [(0x0000, _memsize, 16)]
+
+    def get_features(self):
+        rf = chirp_common.RadioFeatures()
+        rf.memory_bounds = (0, 59)
+        rf.valid_modes = list(MODES)
+        rf.valid_tmodes = list(TMODES)
+        rf.valid_duplexes = list(DUPLEX)
+        rf.valid_tuning_steps = list(STEPS)
+        rf.valid_bands = [(118000000, 174000000),
+                          (400000000, 470000000)]
+        rf.valid_skips = ["", "S"]
+        rf.has_dtcs = False
+        rf.has_dtcs_polarity = False
+        rf.has_bank = False
+        rf.has_name = False
+        rf.has_tuning_step = False
+        return rf
+
+    def process_mmap(self):
+        self._memobj = bitwise.parse(mem_format, self._mmap)
+
+    def get_raw_memory(self, number):
+        return repr(self._memobj.memory[number])
+
+    def get_memory(self, number):
+        _mem = self._memobj.memory[number]
+        _flag = self._memobj.flags[number]
+
+        mem = chirp_common.Memory()
+        mem.number = number
+
+        mem.empty = _flag.empty == 1 and True or False
+
+        mem.freq = int(_mem.freq) * 100000
+        mem.freq += _mem.lastfreq * 10000
+        mem.freq += int((_mem.fraction / 2.0) * 1000)
+
+        mem.offset = int(_mem.offset) * 10000
+        mem.rtone = chirp_common.TONES[_mem.rtone-1]
+        mem.ctone = chirp_common.TONES[_mem.ctone-1]
+        mem.tmode = TMODES[_flag.tmode]
+        mem.duplex = DUPLEX[_flag.duplex]
+        mem.mode = "FM" #MODES[_flag.mode]
+        if _flag.skip:
+            mem.skip = "S"
+
+        return mem
+
+    def set_memory(self, mem):
+        _mem = self._memobj.memory[mem.number]
+        _flag = self._memobj.flags[mem.number]
+
+        _mem.freq = int(mem.freq / 100000)
+        topfreq = int(mem.freq / 100000) * 100000
+        lastfreq = int((mem.freq - topfreq) / 10000)
+        _mem.lastfreq = lastfreq
+        midfreq = (mem.freq - topfreq - lastfreq*10000)
+        _mem.fraction = midfreq/500
+
+        _mem.offset = mem.offset / 10000
+        _mem.rtone = chirp_common.TONES.index(mem.rtone)+1
+        _mem.ctone = chirp_common.TONES.index(mem.ctone)+1
+        _flag.tmode = TMODES.index(mem.tmode)
+        _flag.duplex = DUPLEX.index(mem.duplex)
+        _flag.skip = mem.skip == "S" and 1 or 0
+        _flag.empty = mem.empty and 1 or 0
diff -r 4a3dbf10d64b -r 3deda8456d93 tests/images/Icom_IC-T7H.img
Binary file tests/images/Icom_IC-T7H.img has changed
diff -r 4a3dbf10d64b -r 3deda8456d93 tests/run_tests
--- a/tests/run_tests	Fri Jul 13 16:43:41 2012 -0700
+++ b/tests/run_tests	Tue Jul 17 08:58:28 2012 -0700
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
 #
 # Copyright 2011 Dan Smith <dsmith@danplanet.com>
 #
# HG changeset patch
# User Eric Allen <ericpallen@gmail.com>
# Date 1342623739 25200
# Node ID 4ed0004285f11b18ef1371b67f12c5ffc4f62f83
# Parent  3deda8456d9390c02a3ab1445e2820dbd81539e7
need a delay to let serial buffer flush

diff -r 3deda8456d93 -r 4ed0004285f1 chirp/icf.py
--- a/chirp/icf.py	Tue Jul 17 08:58:28 2012 -0700
+++ b/chirp/icf.py	Wed Jul 18 08:02:19 2012 -0700
@@ -15,6 +15,7 @@
 
 import struct
 import re
+import time
 
 from chirp import chirp_common, errors, util, memmap
 
@@ -365,6 +366,7 @@
         frames += stream.get_frames()
 
     send_clone_frame(radio.pipe, CMD_CLONE_END, radio.get_endframe(), raw=True)
+    time.sleep(3.5)
     frames += stream.get_frames(True)
 
     if SAVE_PIPE:
