<div dir="ltr">I fixed all of the items for which I received feedback, and also added the auto-identification of the image file.<div>anything else that needs to be modified? I would like to have this included in the main branch, as it should be ready to be used by a wider audience.</div><div><br></div><div>thanks</div><div>Dave KK6DF</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 27, 2015 at 11:40 PM, David Fannin <span dir="ltr"><<a href="mailto:dfannin@sushisoft.com" target="_blank">dfannin@sushisoft.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># HG changeset patch<br>
# User David Fannin <<a href="mailto:dfannin@sushisoft.com">dfannin@sushisoft.com</a>><br>
# Date 1430203203 25200<br>
# Mon Apr 27 23:40:03 2015 -0700<br>
# Node ID 237bb7557e557c689aa8d1863c40f2388b596974<br>
# Parent 31a7494c324a347634c30cc3c9bded2ce83eeb21<br>
[Th9000] Adding devices file for new radio TYT TH9000D models #1035<br>
<br>
diff -r 31a7494c324a -r 237bb7557e55 chirp/drivers/th9000.py<br>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000<br>
+++ b/chirp/drivers/th9000.py Mon Apr 27 23:40:03 2015 -0700<br>
@@ -0,0 +1,839 @@<br>
+# Copyright 2015 David Fannin KK6DF <<a href="mailto:kk6df@arrl.org">kk6df@arrl.org</a>><br>
+#<br>
+# This program is free software: you can redistribute it and/or modify<br>
+# it under the terms of the GNU General Public License as published by<br>
+# the Free Software Foundation, either version 2 of the License, or<br>
+# (at your option) any later version.<br>
+#<br>
+# This program is distributed in the hope that it will be useful,<br>
+# but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
+# GNU General Public License for more details.<br>
+#<br>
+# You should have received a copy of the GNU General Public License<br>
+# along with this program. If not, see <<a href="http://www.gnu.org/licenses/" target="_blank">http://www.gnu.org/licenses/</a>>.<br>
+<br>
+import os<br>
+import struct<br>
+import time<br>
+import logging<br>
+<br>
+from chirp import bitwise<br>
+from chirp import chirp_common<br>
+from chirp import directory<br>
+from chirp import errors<br>
+from chirp import memmap<br>
+from chirp import util<br>
+from chirp.settings import RadioSettingGroup, RadioSetting, RadioSettings, \<br>
+ RadioSettingValueList, RadioSettingValueString, RadioSettingValueBoolean, \<br>
+ RadioSettingValueInteger, RadioSettingValueString, \<br>
+ RadioSettingValueFloat, InvalidValueError<br>
+<br>
+LOG = logging.getLogger(__name__)<br>
+<br>
+#<br>
+# Chirp Driver for TYT TH-9000D (models: 2M (144 Mhz), 1.25M (220 Mhz) and 70cm (440 Mhz) radios)<br>
+#<br>
+# Version 1.0<br>
+#<br>
+# Note: Features not working:<br>
+# - DCS , Cross Signaling<br>
+# - Skip channels<br>
+#<br>
+# Global Parameters<br>
+#<br>
+MMAPSIZE = 16384<br>
+TONES = [62.5] + list(chirp_common.TONES)<br>
+TMODES = ['','Tone','DTCS']<br>
+DUPLEXES = ['','err','-','+'] # index 2 not used<br>
+MODES = ['WFM','FM','NFM'] # 25k, 20k,15k bw<br>
+TUNING_STEPS=[ 5.0, 6.25, 8.33, 10.0, 12.5, 15.0, 20.0, 25.0, 30.0, 50.0 ] # index 0-9<br>
+POWER_LEVELS=[chirp_common.PowerLevel("High", watts=65),<br>
+ chirp_common.PowerLevel("Mid", watts=25),<br>
+ chirp_common.PowerLevel("Low", watts=10)]<br>
+<br>
+CROSS_MODES = chirp_common.CROSS_MODES<br>
+<br>
+APO_LIST = [ "Off","30 min","1 hr","2 hrs" ]<br>
+BGCOLOR_LIST = ["Blue","Orange","Purple"]<br>
+BGBRIGHT_LIST = ["%s" % x for x in range(1,32)]<br>
+SQUELCH_LIST = ["Off"] + ["Level %s" % x for x in range(1,20)]<br>
+TIMEOUT_LIST = ["Off"] + ["%s min" % x for x in range(1,30)]<br>
+TXPWR_LIST = ["60W","25W"] # maximum power for Hi setting<br>
+TBSTFREQ_LIST = ["1750Hz","2100Hz","1000Hz","1450Hz"]<br>
+BEEP_LIST = ["Off","On"]<br>
+<br>
+SETTING_LISTS = {<br>
+ "auto_power_off": APO_LIST,<br>
+ "bg_color" : BGCOLOR_LIST,<br>
+ "bg_brightness" : BGBRIGHT_LIST,<br>
+ "squelch" : SQUELCH_LIST,<br>
+ "timeout_timer" : TIMEOUT_LIST,<br>
+ "choose_tx_power": TXPWR_LIST,<br>
+ "tbst_freq" : TBSTFREQ_LIST,<br>
+ "voice_prompt" : BEEP_LIST<br>
+}<br>
+<br>
+MEM_FORMAT = """<br>
+#seekto 0x0000;<br>
+struct {<br>
+ u8 unknown0000[16];<br>
+ char idhdr[16];<br>
+ u8 unknown0001[16];<br>
+} fidhdr;<br>
+"""<br>
+#Overall Memory Map:<br>
+#<br>
+# Memory Map (Range 0x0100-3FF0, step 0x10):<br>
+#<br>
+# Field Start End Size<br>
+# (hex) (hex) (hex)<br>
+#<br>
+# 1 Channel Set Flag 0100 011F 20<br>
+# 2 Channel Skip Flag 0120 013F 20<br>
+# 3 Blank/Unknown 0140 01EF B0<br>
+# 4 Unknown 01F0 01FF 10<br>
+# 5 TX/RX Range 0200 020F 10<br>
+# 6 Bootup Passwd 0210 021F 10<br>
+# 7 Options, Radio 0220 023F 20<br>
+# 8 Unknown 0240 019F<br>
+# 8B Startup Label 03E0 03E7 07<br>
+# 9 Channel Bank 2000 38FF 1900<br>
+# Channel 000 2000 201F 20<br>
+# Channel 001 2020 202F 20<br>
+# ...<br>
+# Channel 199 38E0 38FF 20<br>
+# 10 Blank/Unknown 3900 3FFF 6FF 14592 16383 1792<br>
+# Total Map Size 16128 (2^8 = 16384)<br>
+#<br>
+# TH9000/220 memory map<br>
+# section: 1 and 2: Channel Set/Skip Flags<br>
+#<br>
+# Channel Set (starts 0x100) : Channel Set bit is value 0 if a memory location in the channel bank is active.<br>
+# Channel Skip (starts 0x120): Channel Skip bit is value 0 if a memory location in the channel bank is active.<br>
+#<br>
+# Both flag maps are a total 24 bytes in length, aligned on 32 byte records.<br>
+# bit = 0 channel set/no skip, 1 is channel not set/skip<br>
+#<br>
+# to index a channel:<br>
+# cbyte = channel / 8 ;<br>
+# cbit = channel % 8 ;<br>
+# setflag = csetflag[cbyte].c[cbit] ;<br>
+# skipflag = cskipflag[cbyte].c[cbit] ;<br>
+#<br>
+# channel range is 0-199, range is 32 bytes (last 7 unknown)<br>
+#<br>
+MEM_FORMAT = MEM_FORMAT + """<br>
+#seekto 0x0100;<br>
+struct {<br>
+ bit c[8];<br>
+} csetflag[32];<br>
+<br>
+struct {<br>
+ u8 unknown0100[7];<br>
+} ropt0100;<br>
+<br>
+#seekto 0x0120;<br>
+struct {<br>
+ bit c[8];<br>
+} cskipflag[32];<br>
+<br>
+struct {<br>
+ u8 unknown0120[7];<br>
+} ropt0120;<br>
+"""<br>
+# TH9000 memory map<br>
+# section: 5 TX/RX Range<br>
+# used to set the TX/RX range of the radio (e.g. 222-228Mhz for 220 meter)<br>
+# possible to set range for tx/rx<br>
+#<br>
+MEM_FORMAT = MEM_FORMAT + """<br>
+#seekto 0x0200;<br>
+struct {<br>
+ bbcd txrangelow[4];<br>
+ bbcd txrangehi[4];<br>
+ bbcd rxrangelow[4];<br>
+ bbcd rxrangehi[4];<br>
+} freqrange;<br>
+"""<br>
+# TH9000 memory map<br>
+# section: 6 bootup_passwd<br>
+# used to set bootup passwd (see boot_passwd checkbox option)<br>
+#<br>
+# options - bootup password<br>
+#<br>
+# bytes:bit type description<br>
+# ---------------------------------------------------------------------------<br>
+# 6 u8 bootup_passwd[6] bootup passwd, 6 chars, numberic chars 30-39 , see boot_passwd checkbox to set<br>
+# 10 u8 unknown;<br>
+#<br>
+<br>
+MEM_FORMAT = MEM_FORMAT + """<br>
+#seekto 0x0210;<br>
+struct {<br>
+ u8 bootup_passwd[6];<br>
+ u8 unknown2010[10];<br>
+} ropt0210;<br>
+"""<br>
+# TH9000/220 memory map<br>
+# section: 7 Radio Options<br>
+# used to set a number of radio options<br>
+#<br>
+# bytes:bit type description<br>
+# ---------------------------------------------------------------------------<br>
+# 1 u8 display_mode display mode, range 0-2, 0=freq,1=channel,2=name (selecting name affects vfo_mr)<br>
+# 1 u8 vfo_mr; vfo_mr , 0=vfo, mr=1<br>
+# 1 u8 unknown;<br>
+# 1 u8 squelch; squelch level, range 0-19, hex for menu<br>
+# 1 u8 unknown[2];<br>
+# 1 u8 channel_lock; if display_mode[channel] selected, then lock=1,no lock =0<br>
+# 1 u8 unknown;<br>
+# 1 u8 bg_brightness ; background brightness, range 0-21, hex, menu index<br>
+# 1 u8 unknown;<br>
+# 1 u8 bg_color ; bg color, menu index, blue 0 , orange 1, purple 2<br>
+# 1 u8 tbst_freq ; tbst freq , menu 0 = 1750Hz, 1=2100 , 2=1000 , 3=1450hz<br>
+# 1 u8 timeout_timer; timeout timer, hex, value = minutes, 0= no timeout<br>
+# 1 u8 unknown;<br>
+# 1 u8 auto_power_off; auto power off, range 0-3, off,30min, 1hr, 2hr, hex menu index<br>
+# 1 u8 voice_prompt; voice prompt, value 0,1 , Beep ON = 1, Beep Off = 2<br>
+#<br>
+# description of function setup options, starting at 0x0230<br>
+#<br>
+# bytes:bit type description<br>
+# ---------------------------------------------------------------------------<br>
+# 1 u8 // 0<br>
+# :4 unknown:6<br>
+# :1 elim_sql_tail:1 eliminate squelsh tail when no ctcss checkbox (1=checked)<br>
+# :1 sql_key_function "squelch off" 1 , "squelch momentary off" 0 , menu index<br>
+# 2 u8 unknown[2] /1-2<br>
+# 1 u8 // 3<br>
+# :4 unknown:4<br>
+# :1 inhibit_init_ops:1 //bit 5<br>
+# :1 unknownD:1<br>
+# :1 inhibit_setup_bg_chk:1 //bit 7<br>
+# :1 unknown:1<br>
+# 1 u8 tail_elim_type menu , (off=0,120=1,180=2), // 4<br>
+# 1 u8 choose_tx_power menu , (60w=0,25w=1) // 5<br>
+# 2 u8 unknown[2]; // 6-7<br>
+# 1 u8 bootup_passwd_flag checkbox 1=on, 0=off // 8<br>
+# 7 u8 unknown[7]; // 9-F<br>
+#<br>
+MEM_FORMAT = MEM_FORMAT + """<br>
+#seekto 0x0220;<br>
+struct {<br>
+ u8 display_mode;<br>
+ u8 vfo_mr;<br>
+ u8 unknown0220A;<br>
+ u8 squelch;<br>
+ u8 unknown0220B[2];<br>
+ u8 channel_lock;<br>
+ u8 unknown0220C;<br>
+ u8 bg_brightness;<br>
+ u8 unknown0220D;<br>
+ u8 bg_color;<br>
+ u8 tbst_freq;<br>
+ u8 timeout_timer;<br>
+ u8 unknown0220E;<br>
+ u8 auto_power_off;<br>
+ u8 voice_prompt;<br>
+ u8 unknown0230A:6,<br>
+ elim_sql_tail:1,<br>
+ sql_key_function:1;<br>
+ u8 unknown0230B[2];<br>
+ u8 unknown0230C:4,<br>
+ inhibit_init_ops:1,<br>
+ unknown0230D:1,<br>
+ inhibit_setup_bg_chk:1,<br>
+ unknown0230E:1;<br>
+ u8 tail_elim_type;<br>
+ u8 choose_tx_power;<br>
+ u8 unknown0230F[2];<br>
+ u8 bootup_passwd_flag;<br>
+ u8 unknown0230G[7];<br>
+} settings;<br>
+"""<br>
+# TH9000 memory map<br>
+# section: 8B Startup Label<br>
+#<br>
+# bytes:bit type description<br>
+# ---------------------------------------------------------------------------<br>
+# 7 char start_label[7] label displayed at startup (usually your call sign)<br>
+#<br>
+MEM_FORMAT = MEM_FORMAT + """<br>
+#seekto 0x03E0;<br>
+struct {<br>
+ char startname[7];<br>
+} slabel;<br>
+"""<br>
+# TH9000/220 memory map<br>
+# section: 9 Channel Bank<br>
+# description of channel bank (200 channels , range 0-199)<br>
+# Each 32 Byte (0x20 hex) record:<br>
+# bytes:bit type description<br>
+# ---------------------------------------------------------------------------<br>
+# 4 bbcd freq[4] receive frequency in packed binary coded decimal<br>
+# 4 bbcd offset[4] transmit offset in packed binary coded decimal (note: plus/minus direction set by 'duplex' field)<br>
+# 1 u8<br>
+# :4 unknown:4<br>
+# :4 tuning_step:4 tuning step, menu index value from 0-9<br>
+# 5,6.25,8.33,10,12.5,15,20,25,30,50<br>
+# 1 u8<br>
+# :4 unknown:4 not yet decoded, used for DCS coding?<br>
+# :2 channel_width:2 channel spacing, menu index value from 0-3<br>
+# 25,20,12.5<br>
+# :1 reverse:1 reverse flag, 0=off, 1=on (reverses tx and rx freqs)<br>
+# :1 txoff:1 transmitt off flag, 0=transmit , 1=do not transmit<br>
+# 1 u8<br>
+# :1 talkaround:1 talkaround flag, 0=off, 1=on (bypasses repeater)<br>
+# :1 compander:1 compander flag, 0=off, 1=on (turns on/off voice compander option)<br>
+# :2 unknown:2<br>
+# :2 power:2 tx power setting, value range 0-2, 0=hi,1=med,2=lo<br>
+# :2 duplex:2 duplex settings, 0=simplex,2= minus(-) offset, 3= plus (+) offset (see offset field)<br>
+#<br>
+# 1 u8<br>
+# :4 unknown:4<br>
+# :2 rxtmode:2 rx tone mode, value range 0-2, 0=none, 1=CTCSS, 2=DCS (ctcss tone in field rxtone)<br>
+# :2 txtmode:2 tx tone mode, value range 0-2, 0=none, 1=CTCSS, 3=DCS (ctcss tone in field txtone)<br>
+# 1 u8<br>
+# :2 unknown:2<br>
+# :6 txtone:6 tx ctcss tone, menu index<br>
+# 1 u8<br>
+# :2 unknown:2<br>
+# :6 rxtone:6 rx ctcss tone, menu index<br>
+# 1 u8 txcode ?, not used for ctcss<br>
+# 1 u8 rxcode ?, not used for ctcss<br>
+# 3 u8 unknown[3]<br>
+# 7 char name[7] 7 byte char string for channel name<br>
+# 1 u8<br>
+# :6 unknown:6,<br>
+# :2 busychannellockout:2 busy channel lockout option , 0=off, 1=repeater, 2=busy (lock out tx if channel busy)<br>
+# 4 u8 unknownI[4];<br>
+# 1 u8<br>
+# :7 unknown:7<br>
+# :1 scrambler:1 scrambler flag, 0=off, 1=on (turns on tyt scrambler option)<br>
+#<br>
+MEM_FORMAT = MEM_FORMAT + """<br>
+#seekto 0x2000;<br>
+struct {<br>
+ bbcd freq[4];<br>
+ bbcd offset[4];<br>
+ u8 unknown2000A:4,<br>
+ tuning_step:4;<br>
+ u8 unknown2000B:4,<br>
+ channel_width:2,<br>
+ reverse:1,<br>
+ txoff:1;<br>
+ u8 talkaround:1,<br>
+ compander:1,<br>
+ unknown2000C:2,<br>
+ power:2,<br>
+ duplex:2;<br>
+ u8 unknown2000D:4,<br>
+ rxtmode:2,<br>
+ txtmode:2;<br>
+ u8 unknown2000E:2,<br>
+ txtone:6;<br>
+ u8 unknown2000F:2,<br>
+ rxtone:6;<br>
+ u8 txcode;<br>
+ u8 rxcode;<br>
+ u8 unknown2000G[3];<br>
+ char name[7];<br>
+ u8 unknown2000H:6,<br>
+ busychannellockout:2;<br>
+ u8 unknown2000I[4];<br>
+ u8 unknown2000J:7,<br>
+ scrambler:1;<br>
+} memory[200] ;<br>
+"""<br>
+<br>
+def _echo_write(radio, data):<br>
+ try:<br>
+ radio.pipe.write(data)<br>
+ radio.pipe.read(len(data))<br>
+ except Exception, e:<br>
+ LOG.error("Error writing to radio: %s" % e)<br>
+ raise errors.RadioError("Unable to write to radio")<br>
+<br>
+<br>
+def _checksum(data):<br>
+ cs = 0<br>
+ for byte in data:<br>
+ cs += ord(byte)<br>
+ return cs % 256<br>
+<br>
+def _read(radio, length):<br>
+ try:<br>
+ data = radio.pipe.read(length)<br>
+ except Exception, e:<br>
+ LOG.error( "Error reading from radio: %s" % e)<br>
+ raise errors.RadioError("Unable to read from radio")<br>
+<br>
+ if len(data) != length:<br>
+ LOG.error( "Short read from radio (%i, expected %i)" % (len(data),<br>
+ length))<br>
+ LOG.debug(util.hexprint(data))<br>
+ raise errors.RadioError("Short read from radio")<br>
+ return data<br>
+<br>
+<br>
+<br>
+def _ident(radio):<br>
+ radio.pipe.setTimeout(1)<br>
+ _echo_write(radio,"PROGRAM")<br>
+ response = radio.pipe.read(3)<br>
+ if response != "QX\06":<br>
+ LOG.debug( "Response was :\n%s" % util.hexprint(response))<br>
+ raise errors.RadioError("Unsupported model")<br>
+ _echo_write(radio, "\x02")<br>
+ response = radio.pipe.read(16)<br>
+ LOG.debug(util.hexprint(response))<br>
+ if response[1:8] != "TH-9000":<br>
+ LOG.error( "Looking for:\n%s" % util.hexprint("TH-9000"))<br>
+ LOG.error( "Response was:\n%s" % util.hexprint(response))<br>
+ raise errors.RadioError("Unsupported model")<br>
+<br>
+def _send(radio, cmd, addr, length, data=None):<br>
+ frame = struct.pack(">cHb", cmd, addr, length)<br>
+ if data:<br>
+ frame += data<br>
+ frame += chr(_checksum(frame[1:]))<br>
+ frame += "\x06"<br>
+ _echo_write(radio, frame)<br>
+ LOG.debug("Sent:\n%s" % util.hexprint(frame))<br>
+ if data:<br>
+ result = radio.pipe.read(1)<br>
+ if result != "\x06":<br>
+ LOG.debug( "Ack was: %s" % repr(result))<br>
+ raise errors.RadioError("Radio did not accept block at %04x" % addr)<br>
+ return<br>
+ result = _read(radio, length + 6)<br>
+ LOG.debug("Got:\n%s" % util.hexprint(result))<br>
+ header = result[0:4]<br>
+ data = result[4:-2]<br>
+ ack = result[-1]<br>
+ if ack != "\x06":<br>
+ LOG.debug("Ack was: %s" % repr(ack))<br>
+ raise errors.RadioError("Radio NAK'd block at %04x" % addr)<br>
+ _cmd, _addr, _length = struct.unpack(">cHb", header)<br>
+ if _addr != addr or _length != _length:<br>
+ LOG.debug( "Expected/Received:")<br>
+ LOG.debug(" Length: %02x/%02x" % (length, _length))<br>
+ LOG.debug( " Addr: %04x/%04x" % (addr, _addr))<br>
+ raise errors.RadioError("Radio send unexpected block")<br>
+ cs = _checksum(result[1:-2])<br>
+ if cs != ord(result[-2]):<br>
+ LOG.debug( "Calculated: %02x" % cs)<br>
+ LOG.debug( "Actual: %02x" % ord(result[-2]))<br>
+ raise errors.RadioError("Block at 0x%04x failed checksum" % addr)<br>
+ return data<br>
+<br>
+<br>
+def _finish(radio):<br>
+ endframe = "\x45\x4E\x44"<br>
+ _echo_write(radio, endframe)<br>
+ result = radio.pipe.read(1)<br>
+ if result != "\x06":<br>
+ LOG.error( "Got:\n%s" % util.hexprint(result))<br>
+ raise errors.RadioError("Radio did not finish cleanly")<br>
+<br>
+def do_download(radio):<br>
+<br>
+ _ident(radio)<br>
+<br>
+ _memobj = None<br>
+ data = ""<br>
+<br>
+ for start,end in radio._ranges:<br>
+ for addr in range(start,end,0x10):<br>
+ block = _send(radio,'R',addr,0x10)<br>
+ data += block<br>
+ status = chirp_common.Status()<br>
+ status.cur = len(data)<br>
+ status.max = end<br>
+ status.msg = "Downloading from radio"<br>
+ radio.status_fn(status)<br>
+<br>
+ _finish(radio)<br>
+<br>
+ return memmap.MemoryMap(data)<br>
+<br>
+def do_upload(radio):<br>
+<br>
+ _ident(radio)<br>
+<br>
+ for start,end in radio._ranges:<br>
+ for addr in range(start,end,0x10):<br>
+ if addr < 0x0100:<br>
+ continue<br>
+ block = radio._mmap[addr:addr+0x10]<br>
+ _send(radio,'W',addr,len(block),block)<br>
+ status = chirp_common.Status()<br>
+ status.cur = addr<br>
+ status.max = end<br>
+ status.msg = "Uploading to Radio"<br>
+ radio.status_fn(status)<br>
+<br>
+ _finish(radio)<br>
+<br>
+<br>
+<br>
+#<br>
+# The base class, extended for use with other models<br>
+#<br>
+@directory.register<br>
+class Th9000Radio(chirp_common.CloneModeRadio,<br>
+ chirp_common.ExperimentalRadio):<br>
+ """TYT TH-9000"""<br>
+ VENDOR = "TYT"<br>
+ MODEL = "TH9000 Base"<br>
+ BAUD_RATE = 9600<br>
+ valid_freq = [(900000000, 999000000)]<br>
+<br>
+<br>
+ _memsize = MMAPSIZE<br>
+ _ranges = [(0x0000,0x4000)]<br>
+<br>
+ @classmethod<br>
+ def get_prompts(cls):<br>
+ rp = chirp_common.RadioPrompts()<br>
+ rp.experimental = ("The TYT TH-9000 driver is an beta version."<br>
+ "Proceed with Caution and backup your data")<br>
+ return rp<br>
+<br>
+ def get_features(self):<br>
+ rf = chirp_common.RadioFeatures()<br>
+ rf.has_settings = True<br>
+ rf.has_bank = False<br>
+ rf.has_cross = True<br>
+ rf.has_tuning_step = False<br>
+ rf.has_rx_dtcs = True<br>
+ rf.valid_skips = ["","S"]<br>
+ rf.memory_bounds = (0, 199)<br>
+ rf.valid_name_length = 7<br>
+ rf.valid_characters = chirp_common.CHARSET_UPPER_NUMERIC + "-"<br>
+ rf.valid_modes = MODES<br>
+ rf.valid_tmodes = chirp_common.TONE_MODES<br>
+ rf.valid_cross_modes = CROSS_MODES<br>
+ rf.valid_power_levels = POWER_LEVELS<br>
+ rf.valid_dtcs_codes = chirp_common.ALL_DTCS_CODES<br>
+ rf.valid_bands = self.valid_freq<br>
+ return rf<br>
+<br>
+ # Do a download of the radio from the serial port<br>
+ def sync_in(self):<br>
+ self._mmap = do_download(self)<br>
+ self.process_mmap()<br>
+<br>
+ # Do an upload of the radio to the serial port<br>
+ def sync_out(self):<br>
+ do_upload(self)<br>
+<br>
+ def process_mmap(self):<br>
+ self._memobj = bitwise.parse(MEM_FORMAT, self._mmap)<br>
+<br>
+<br>
+ # Return a raw representation of the memory object, which<br>
+ # is very helpful for development<br>
+ def get_raw_memory(self, number):<br>
+ return repr(self._memobj.memory[number])<br>
+<br>
+ # not working yet<br>
+ def _get_dcs_index(self, _mem,which):<br>
+ base = getattr(_mem, '%scode' % which)<br>
+ extra = getattr(_mem, '%sdcsextra' % which)<br>
+ return (int(extra) << 8) | int(base)<br>
+<br>
+ def _set_dcs_index(self, _mem, which, index):<br>
+ base = getattr(_mem, '%scode' % which)<br>
+ extra = getattr(_mem, '%sdcsextra' % which)<br>
+ base.set_value(index & 0xFF)<br>
+ extra.set_value(index >> 8)<br>
+<br>
+<br>
+ # Extract a high-level memory object from the low-level memory map<br>
+ # This is called to populate a memory in the UI<br>
+ def get_memory(self, number):<br>
+ # Get a low-level memory object mapped to the image<br>
+ _mem = self._memobj.memory[number]<br>
+<br>
+ # get flag info<br>
+ cbyte = number / 8 ;<br>
+ cbit = 7 - (number % 8) ;<br>
+ setflag = self._memobj.csetflag[cbyte].c[cbit];<br>
+ skipflag = self._memobj.cskipflag[cbyte].c[cbit];<br>
+<br>
+ mem = chirp_common.Memory()<br>
+<br>
+ mem.number = number # Set the memory number<br>
+<br>
+ if setflag == 1:<br>
+ mem.empty = True<br>
+ return mem<br>
+<br>
+ mem.freq = int(_mem.freq) * 100<br>
+ mem.offset = int(_mem.offset) * 100<br>
+ <a href="http://mem.name" target="_blank">mem.name</a> = str(_<a href="http://mem.name" target="_blank">mem.name</a>).rstrip() # Set the alpha tag<br>
+ mem.duplex = DUPLEXES[_mem.duplex]<br>
+ mem.mode = MODES[_mem.channel_width]<br>
+ mem.power = POWER_LEVELS[_mem.power]<br>
+<br>
+ rxtone = txtone = None<br>
+<br>
+<br>
+ rxmode = TMODES[_mem.rxtmode]<br>
+ txmode = TMODES[_mem.txtmode]<br>
+<br>
+<br>
+ rxpol = txpol = ""<br>
+<br>
+ # doesn't work<br>
+ if rxmode == "Tone":<br>
+ rxpol = ""<br>
+ rxtone = TONES[_mem.rxtone]<br>
+ elif rxmode == "DTCS":<br>
+ rxpol = "N"<br>
+ rxtone = chirp_common.ALL_DTCS_CODES[self._get_dcs_index(_mem,'rx')]<br>
+<br>
+ if txmode == "Tone":<br>
+ txpol = ""<br>
+ txtone = TONES[_mem.txtone]<br>
+ elif txmode == "DTCS":<br>
+ txpol = "N"<br>
+ txtone = chirp_common.ALL_DTCS_CODES[self._get_dcs_index(_mem,'tx')]<br>
+<br>
+<br>
+ chirp_common.split_tone_decode(mem,<br>
+ (txmode, txtone, txpol),<br>
+ (rxmode, rxtone, rxpol))<br>
+<br>
+ mem.skip = "S" if skipflag == 1 else ""<br>
+<br>
+<br>
+ # We'll consider any blank (i.e. 0MHz frequency) to be empty<br>
+ if mem.freq == 0:<br>
+ mem.empty = True<br>
+<br>
+ return mem<br>
+<br>
+ # Store details about a high-level memory to the memory map<br>
+ # This is called when a user edits a memory in the UI<br>
+ def set_memory(self, mem):<br>
+ # Get a low-level memory object mapped to the image<br>
+<br>
+ _mem = self._memobj.memory[mem.number]<br>
+<br>
+ cbyte = mem.number / 8<br>
+ cbit = 7 - (mem.number % 8)<br>
+<br>
+ if mem.empty:<br>
+ self._memobj.csetflag[cbyte].c[cbit] = 1<br>
+ self._memobj.cskipflag[cbyte].c[cbit] = 1<br>
+ return<br>
+<br>
+ self._memobj.csetflag[cbyte].c[cbit] = 0<br>
+ self._memobj.cskipflag[cbyte].c[cbit] = 1 if (mem.skip == "S") else 0<br>
+<br>
+ _mem.set_raw("\x00" * 32)<br>
+<br>
+ _mem.freq = mem.freq / 100 # Convert to low-level frequency<br>
+ _mem.offset = mem.offset / 100 # Convert to low-level frequency<br>
+<br>
+ _<a href="http://mem.name" target="_blank">mem.name</a> = mem.name.ljust(7)[:7] # Store the alpha tag<br>
+ _mem.duplex = DUPLEXES.index(mem.duplex)<br>
+<br>
+<br>
+ try:<br>
+ _mem.channel_width = MODES.index(mem.mode)<br>
+ except ValueError:<br>
+ _mem.channel_width = 0<br>
+<br>
+ ((txmode, txtone, txpol),<br>
+ (rxmode, rxtone, rxpol)) = chirp_common.split_tone_encode(mem)<br>
+<br>
+ _mem.txtmode = TMODES.index(txmode)<br>
+ _mem.rxtmode = TMODES.index(rxmode)<br>
+<br>
+ if txmode == "Tone":<br>
+ _mem.txtone = TONES.index(txtone)<br>
+ elif txmode == "DTCS":<br>
+ self._set_dcs_index(_mem,'tx',chirp_common.ALL_DTCS_CODES.index(txtone))<br>
+<br>
+ if rxmode == "Tone":<br>
+ _mem.rxtone = TONES.index(rxtone)<br>
+ elif rxmode == "DTCS":<br>
+ self._set_dcs_index(_mem, 'rx', chirp_common.ALL_DTCS_CODES.index(rxtone))<br>
+<br>
+ #_mem.txinv = txpol == "N"<br>
+ #_mem.rxinv = rxpol == "N"<br>
+<br>
+<br>
+ if mem.power:<br>
+ _mem.power = POWER_LEVELS.index(mem.power)<br>
+ else:<br>
+ _mem.power = 0<br>
+<br>
+ def _get_settings(self):<br>
+ _settings = self._memobj.settings<br>
+ _freqrange = self._memobj.freqrange<br>
+ _slabel = self._memobj.slabel<br>
+<br>
+ basic = RadioSettingGroup("basic","Global Settings")<br>
+ freqrange = RadioSettingGroup("freqrange","Frequency Ranges")<br>
+ top = RadioSettingGroup("top","All Settings",basic,freqrange)<br>
+ settings = RadioSettings(top)<br>
+<br>
+ def _filter(name):<br>
+ filtered = ""<br>
+ for char in str(name):<br>
+ if char in chirp_common.CHARSET_ASCII:<br>
+ filtered += char<br>
+ else:<br>
+ filtered += ""<br>
+ return filtered<br>
+<br>
+ val = RadioSettingValueString(0,7,_filter(_slabel.startname))<br>
+ rs = RadioSetting("startname","Startup Label",val)<br>
+ basic.append(rs)<br>
+<br>
+ rs = RadioSetting("bg_color","LCD Color",<br>
+ RadioSettingValueList(BGCOLOR_LIST, BGCOLOR_LIST[_settings.bg_color]))<br>
+ basic.append(rs)<br>
+<br>
+ rs = RadioSetting("bg_brightness","LCD Brightness",<br>
+ RadioSettingValueList(BGBRIGHT_LIST, BGBRIGHT_LIST[_settings.bg_brightness]))<br>
+ basic.append(rs)<br>
+<br>
+ rs = RadioSetting("squelch","Squelch Level",<br>
+ RadioSettingValueList(SQUELCH_LIST, SQUELCH_LIST[_settings.squelch]))<br>
+ basic.append(rs)<br>
+<br>
+ rs = RadioSetting("timeout_timer","Timeout Timer (TOT)",<br>
+ RadioSettingValueList(TIMEOUT_LIST, TIMEOUT_LIST[_settings.timeout_timer]))<br>
+ basic.append(rs)<br>
+<br>
+ rs = RadioSetting("auto_power_off","Auto Power Off (APO)",<br>
+ RadioSettingValueList(APO_LIST, APO_LIST[_settings.auto_power_off]))<br>
+ basic.append(rs)<br>
+<br>
+ rs = RadioSetting("voice_prompt","Beep Prompt",<br>
+ RadioSettingValueList(BEEP_LIST, BEEP_LIST[_settings.voice_prompt]))<br>
+ basic.append(rs)<br>
+<br>
+ rs = RadioSetting("tbst_freq","Tone Burst Frequency",<br>
+ RadioSettingValueList(TBSTFREQ_LIST, TBSTFREQ_LIST[_settings.tbst_freq]))<br>
+ basic.append(rs)<br>
+<br>
+ rs = RadioSetting("choose_tx_power","Max Level of TX Power",<br>
+ RadioSettingValueList(TXPWR_LIST, TXPWR_LIST[_settings.choose_tx_power]))<br>
+ basic.append(rs)<br>
+<br>
+ (flow,fhigh) = self.valid_freq[0]<br>
+ flow /= 1000<br>
+ fhigh /= 1000<br>
+ fmidrange = (fhigh- flow)/2<br>
+<br>
+ rs = RadioSetting("txrangelow","TX Freq, Lower Limit (khz)", RadioSettingValueInteger(flow,<br>
+ flow + fmidrange,<br>
+ int(_freqrange.txrangelow)/10))<br>
+ freqrange.append(rs)<br>
+<br>
+ rs = RadioSetting("txrangehi","TX Freq, Upper Limit (khz)", RadioSettingValueInteger(fhigh-fmidrange,<br>
+ fhigh,<br>
+ int(_freqrange.txrangehi)/10))<br>
+ freqrange.append(rs)<br>
+<br>
+ rs = RadioSetting("rxrangelow","RX Freq, Lower Limit (khz)", RadioSettingValueInteger(flow,<br>
+ flow+fmidrange,<br>
+ int(_freqrange.rxrangelow)/10))<br>
+ freqrange.append(rs)<br>
+<br>
+ rs = RadioSetting("rxrangehi","RX Freq, Upper Limit (khz)", RadioSettingValueInteger(fhigh-fmidrange,<br>
+ fhigh,<br>
+ int(_freqrange.rxrangehi)/10))<br>
+ freqrange.append(rs)<br>
+<br>
+ return settings<br>
+<br>
+ def get_settings(self):<br>
+ try:<br>
+ return self._get_settings()<br>
+ except:<br>
+ import traceback<br>
+ LOG.error( "failed to parse settings")<br>
+ traceback.print_exc()<br>
+ return None<br>
+<br>
+ def set_settings(self,settings):<br>
+ _settings = self._memobj.settings<br>
+ for element in settings:<br>
+ if not isinstance(element,RadioSetting):<br>
+ self.set_settings(element)<br>
+ continue<br>
+ else:<br>
+ try:<br>
+ name = element.get_name()<br>
+<br>
+ if name in ["txrangelow","txrangehi","rxrangelow","rxrangehi"]:<br>
+ LOG.debug( "setting %s = %s" % (name,int(element.value)*10))<br>
+ setattr(self._memobj.freqrange,name,int(element.value)*10)<br>
+ continue<br>
+<br>
+ if name in ["startname"]:<br>
+ LOG.debug( "setting %s = %s" % (name, element.value))<br>
+ setattr(self._memobj.slabel,name,element.value)<br>
+ continue<br>
+<br>
+ obj = _settings<br>
+ setting = element.get_name()<br>
+<br>
+ if element.has_apply_callback():<br>
+ LOG.debug( "using apply callback")<br>
+ element.run_apply_callback()<br>
+ else:<br>
+ LOG.debug( "Setting %s = %s" % (setting, element.value))<br>
+ setattr(obj, setting, element.value)<br>
+ except Exception, e:<br>
+ LOG.debug( element.get_name())<br>
+ raise<br>
+<br>
+ @classmethod<br>
+ def match_model(cls, filedata, filename):<br>
+ if MMAPSIZE == len(filedata):<br>
+ (flow,fhigh) = cls.valid_freq[0]<br>
+ flow /= 1000000<br>
+ fhigh /= 1000000<br>
+<br>
+ txmin=ord(filedata[0x200])*100 + (ord(filedata[0x201])>>4)*10 + ord(filedata[0x201])%16<br>
+ txmax=ord(filedata[0x204])*100 + (ord(filedata[0x205])>>4)*10 + ord(filedata[0x205])%16<br>
+ rxmin=ord(filedata[0x208])*100 + (ord(filedata[0x209])>>4)*10 + ord(filedata[0x209])%16<br>
+ rxmax=ord(filedata[0x20C])*100 + (ord(filedata[0x20D])>>4)*10 + ord(filedata[0x20D])%16<br>
+<br>
+ if ( rxmin >= flow and rxmax <= fhigh and txmin >= flow and txmax <= fhigh ):<br>
+ return True<br>
+<br>
+ return False<br>
+<br>
+@directory.register<br>
+class Th9000220Radio(Th9000Radio):<br>
+ """TYT TH-9000 220"""<br>
+ VENDOR = "TYT"<br>
+ MODEL = "TH9000_220"<br>
+ BAUD_RATE = 9600<br>
+ valid_freq = [(220000000, 260000000)]<br>
+<br>
+@directory.register<br>
+class Th9000144Radio(Th9000220Radio):<br>
+ """TYT TH-9000 144"""<br>
+ VENDOR = "TYT"<br>
+ MODEL = "TH9000_144"<br>
+ BAUD_RATE = 9600<br>
+ valid_freq = [(136000000, 174000000)]<br>
+<br>
+@directory.register<br>
+class Th9000440Radio(Th9000220Radio):<br>
+ """TYT TH-9000 440"""<br>
+ VENDOR = "TYT"<br>
+ MODEL = "TH9000_440"<br>
+ BAUD_RATE = 9600<br>
+ valid_freq = [(400000000, 490000000)]<br>
</blockquote></div><br></div>