# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID 7021be6b7f7cb65e9694b85b4ff72ab54b2b3683
Fix style issues in th9800.py (#2355)
diff --git a/chirp/drivers/th9800.py b/chirp/drivers/th9800.py index 1f1d498..2d7e3c6 100644 --- a/chirp/drivers/th9800.py +++ b/chirp/drivers/th9800.py @@ -161,489 +161,526 @@ POWER_LEVELS = [chirp_common.PowerLevel("Low", watts=5.00), chirp_common.PowerLevel("Mid1", watts=20.00), chirp_common.PowerLevel("High", watts=50.00)] BUSY_LOCK = ["off", "Carrier", "2 tone"] -MICKEYFUNC = ["None","SCAN","SQL.OFF","TCALL","PPTR","PRI","LOW","TONE", - "MHz","REV","HOME","BAND","VFO/MR"] +MICKEYFUNC = ["None", "SCAN", "SQL.OFF", "TCALL", "PPTR", "PRI", "LOW", "TONE", + "MHz", "REV", "HOME", "BAND", "VFO/MR"] SQLPRESET = ["Off", "2", "5", "9", "Full"] BANDS = ["30MHz", "50MHz", "60MHz", "108MHz", "150MHz", "250MHz", "350MHz", "450MHz", "850MHz"] -STEPS = [ 2.5, 5.0, 6.25, 7.5, 8.33, 10.0, 12.5, - 15.0, 20.0, 25.0, 30.0, 50.0, 100.0 ] - +STEPS = [2.5, 5.0, 6.25, 7.5, 8.33, 10.0, 12.5, + 15.0, 20.0, 25.0, 30.0, 50.0, 100.0] + + class TYTTH9800Base(chirp_common.Radio): - """Base class for TYT TH-9800""" - VENDOR = "TYT" - def get_features(self): - rf = chirp_common.RadioFeatures() - rf.memory_bounds = (1, 800) - rf.has_bank = False - rf.has_tuning_step = True - rf.valid_tuning_steps = STEPS - rf.can_odd_split = True - rf.valid_duplexes = ["", "-", "+", "split", "off"] - rf.valid_tmodes = TMODES - rf.has_ctone = False - rf.valid_power_levels = POWER_LEVELS - rf.valid_characters = chirp_common.CHARSET_UPPER_NUMERIC + "#*-+" - rf.valid_bands = [( 26000000, 33000000), - ( 47000000, 54000000), - (108000000, 180000000), - (350000000, 399000000), - (430000000, 512000000), - (750000000, 947000000)] - rf.valid_skips = SCAN_MODES - rf.valid_modes = MODES + ["AM"] - rf.valid_name_length = 6 - rf.has_settings = True - return rf - - def process_mmap(self): - self._memobj = bitwise.parse( TH9800_MEM_FORMAT % - (self._mmap_offset, self._scanlimits_offset, self._settings_offset, - self._chan_active_offset, self._info_offset), self._mmap) - - def get_active(self, banktype, num): - """get active flag for channel active, scan enable, or priority banks""" - bank = getattr(self._memobj, banktype) - index = (num - 1) / 8 - bitpos = (num - 1) % 8 - mask = 2**bitpos - enabled = bank[index] & mask - if enabled: - return True - else: - return False - - def set_active(self, banktype, num, enable = True): - """set active flag for channel active, scan enable, or priority banks""" - bank = getattr(self._memobj, banktype) - index = (num - 1) / 8 - bitpos = (num - 1) % 8 - mask = 2**bitpos - if enable: - bank[index] |= mask - else: - bank[index] &= ~mask - - def get_raw_memory(self, number): - return repr(self._memobj.memory[number - 1]) - - def get_memory(self, number): - _mem = self._memobj.memory[number - 1] - mem = chirp_common.Memory() - mem.number = number - - mem.empty = not self.get_active("chan_active", number) - if mem.empty: - return mem - - mem.freq = int(_mem.rx_freq) * 10 - - txfreq = int(_mem.tx_freq) * 10 - if txfreq == mem.freq: - mem.duplex = "" - elif txfreq == 0: - mem.duplex = "off" - mem.offset = 0 - elif abs(txfreq - mem.freq) > 70000000: - mem.duplex = "split" - mem.offset = txfreq - elif txfreq < mem.freq: - mem.duplex = "-" - mem.offset = mem.freq - txfreq - elif txfreq > mem.freq: - mem.duplex = "+" - mem.offset = txfreq - mem.freq - - mem.dtcs_polarity = DTCS_POLARITY[_mem.dtcs_pol] - - mem.tmode = TMODES[int(_mem.tmode)] - mem.ctone = mem.rtone = int(_mem.ctcss) / 10.0 - mem.dtcs = int(_mem.dtcs) - - mem.name = str(_mem.name) - mem.name = mem.name.replace("\xFF", " ").rstrip() - - if not self.get_active("scan_enable", number): - mem.skip = "S" - elif self.get_active("priority", number): - mem.skip = "P" - else: - mem.skip = "" - - mem.mode = _mem.am and "AM" or MODES[int(_mem.fmdev)] - - mem.power = POWER_LEVELS[_mem.power] - mem.tuning_step = STEPS[_mem.step] - - mem.extra = RadioSettingGroup("extra", "Extra") - - opts = ["Frequency", "Name"] - display = RadioSetting("display", "Display", - RadioSettingValueList(opts, opts[_mem.display])) - mem.extra.append(display) - - bclo = RadioSetting("bclo", "Busy Lockout", - RadioSettingValueList(BUSY_LOCK, - BUSY_LOCK[_mem.bclo])) - bclo.set_doc("Busy Lockout") - mem.extra.append(bclo) - - emphasis = RadioSetting("emphasis", "Emphasis", - RadioSettingValueBoolean(bool(_mem.emphasis))) - emphasis.set_doc("Boosts 300Hz to 2500Hz mic response") - mem.extra.append(emphasis) - - compand = RadioSetting("compand", "Compand", - RadioSettingValueBoolean(bool(_mem.compand))) - compand.set_doc("Compress Audio") - mem.extra.append(compand) - - BeatShift = RadioSetting("BeatShift", "BeatShift", - RadioSettingValueBoolean(bool(_mem.BeatShift))) - BeatShift.set_doc("Beat Shift") - mem.extra.append(BeatShift) - - TalkAround = RadioSetting("talkaround", "Talk Around", - RadioSettingValueBoolean(bool(_mem.talkaround))) - TalkAround.set_doc("Simplex mode when out of range of repeater") - mem.extra.append(TalkAround) - - scramb = RadioSetting("scramb", "Scramble", - RadioSettingValueBoolean(bool(_mem.scramb))) - scramb.set_doc("Frequency inversion Scramble") - mem.extra.append(scramb) - - return mem - - def set_memory(self, mem): - _mem = self._memobj.memory[mem.number - 1] - - _prev_active = self.get_active("chan_active", mem.number) - self.set_active("chan_active", mem.number, not mem.empty) - if mem.empty or not _prev_active: - LOG.debug("initializing memory channel %d" % mem.number) - _mem.set_raw(BLANK_MEMORY) - - if mem.empty: - return - - _mem.rx_freq = mem.freq / 10 - if mem.duplex == "split": - _mem.tx_freq = mem.offset / 10 - elif mem.duplex == "-": - _mem.tx_freq = (mem.freq - mem.offset) / 10 - elif mem.duplex == "+": - _mem.tx_freq = (mem.freq + mem.offset) / 10 - elif mem.duplex == "off": - _mem.tx_freq = 0 - _mem.offset = 0 - else: - _mem.tx_freq = mem.freq / 10 - - _mem.tmode = TMODES.index(mem.tmode) - _mem.ctcss = mem.rtone * 10 - _mem.dtcs = mem.dtcs - _mem.dtcs_pol = DTCS_POLARITY.index(mem.dtcs_polarity) - - _mem.name = mem.name.ljust(6, "\xFF") - - # autoset display to name if filled, else show frequency - if mem.extra: - # mem.extra only seems to be populated when called from edit panel - display = mem.extra["display"] - else: - display = None - if mem.name: - _mem.display = True - if display and not display.changed(): - display.value = "Name" - else: - _mem.display = False - if display and not display.changed(): - display.value = "Frequency" - - _mem.scan = SCAN_MODES.index(mem.skip) - if mem.skip == "P": - self.set_active("priority", mem.number, True) - self.set_active("scan_enable", mem.number, True) - elif mem.skip == "S": - self.set_active("priority", mem.number, False) - self.set_active("scan_enable", mem.number, False) - elif mem.skip == "": - self.set_active("priority", mem.number, False) - self.set_active("scan_enable", mem.number, True) - - if mem.mode == "AM": - _mem.am = True - _mem.fmdev = 0 - else: - _mem.am = False - _mem.fmdev = MODES.index(mem.mode) - - if mem.power: - _mem.power = POWER_LEVELS.index(mem.power) - else: - _mem.power = 0 # low - _mem.step = STEPS.index(mem.tuning_step) - - for setting in mem.extra: - LOG.debug("@set_mem:", setting.get_name(), setting.value) - setattr(_mem, setting.get_name(), setting.value) - - def get_settings(self): - _settings = self._memobj.settings - _info = self._memobj.info - _bandlimits = self._memobj.bandlimits - basic = RadioSettingGroup("basic", "Basic") - info = RadioSettingGroup("info", "Model Info") - top = RadioSettings(basic, info) - basic.append( RadioSetting("beep", "Beep", - RadioSettingValueBoolean(_settings.beep))) - basic.append( RadioSetting("beep_vol", "Beep Volume", - RadioSettingValueInteger(0, 15,_settings.beep_vol))) - basic.append( RadioSetting("keylock", "Key Lock", - RadioSettingValueBoolean(_settings.keylock))) - basic.append( RadioSetting("ani_display", "ANI Display", - RadioSettingValueBoolean(_settings.ani_display))) - basic.append( RadioSetting("auto_xfer", "Auto Transfer", - RadioSettingValueBoolean(_settings.auto_xfer))) - basic.append( RadioSetting("auto_contact", - "Auto Contact Always Remind", - RadioSettingValueBoolean(_settings.auto_contact))) - basic.append( RadioSetting("auto_am", "Auto AM", - RadioSettingValueBoolean(_settings.auto_am))) - basic.append( RadioSetting("left_sql", "Left Squelch", - RadioSettingValueList(SQLPRESET, - SQLPRESET[_settings.left_sql]))) - basic.append( RadioSetting("right_sql", "Right Squelch", - RadioSettingValueList(SQLPRESET, - SQLPRESET[_settings.right_sql]))) -# basic.append( RadioSetting("apo", "Auto Power off (0.1h)", -# RadioSettingValueInteger(0, 20,_settings.apo))) - opts = ["Off"] + ["%0.1f" % (t / 10.0) for t in range(1,21,1) ] - basic.append( RadioSetting("apo", "Auto Power off (Hours)", - RadioSettingValueList(opts, opts[_settings.apo]))) - opts = ["Off", "1", "2", "3", "Full"] - basic.append( RadioSetting("backlight", "Display Backlight", - RadioSettingValueList(opts, opts[_settings.backlight]))) - opts = ["Off", "Right", "Left", "Both"] - basic.append( RadioSetting("pttlock", "PTT Lock", - RadioSettingValueList(opts, opts[_settings.pttlock]))) - opts = ["Manual", "Auto"] - basic.append( RadioSetting("hyper_chan", "Hyper Channel", - RadioSettingValueList(opts, opts[_settings.hyper_chan]))) - opts = ["Key 1", "Key 2"] - basic.append( RadioSetting("right_func_key", "Right Function Key", - RadioSettingValueList(opts, opts[_settings.right_func_key]))) - opts = ["1000Hz", "1450Hz", "1750Hz", "2100Hz"] - basic.append( RadioSetting("tbst_freq", "Tone Burst Frequency", - RadioSettingValueList(opts, opts[_settings.tbst_freq]))) - opts = ["Off", "TX", "RX", "TX RX"] - basic.append( RadioSetting("mute_mode", "Mute Mode", - RadioSettingValueList(opts, opts[_settings.mute_mode]))) - opts = ["MEM", "MSM"] - scanmode = RadioSetting("scan_mode", "Scan Mode", - RadioSettingValueList(opts, opts[_settings.scan_mode])) - scanmode.set_doc("MEM = Normal scan, bypass channels marked skip. " \ - " MSM = Scan only channels marked priority.") - basic.append(scanmode) - opts = ["TO", "CO"] - basic.append( RadioSetting("scan_resume", "Scan Resume", - RadioSettingValueList(opts, opts[_settings.scan_resume]))) - opts = ["%0.1f" % (t / 10.0) for t in range(0,51,1) ] - basic.append( RadioSetting("exit_delay", "Span Transit Exit Delay", - RadioSettingValueList(opts, opts[_settings.exit_delay]))) - basic.append( RadioSetting("tot", "Time Out Timer (minutes)", - RadioSettingValueInteger(0, 30,_settings.tot))) - basic.append( RadioSetting("tot_alert", - "Time Out Timer Pre Alert(seconds)", - RadioSettingValueInteger(0, 15,_settings.tot_alert))) - basic.append( RadioSetting("tot_rekey", "Time Out Rekey (seconds)", - RadioSettingValueInteger(0, 15,_settings.tot_rekey))) - basic.append( RadioSetting("tot_reset", "Time Out Reset(seconds)", - RadioSettingValueInteger(0, 15,_settings.tot_reset))) - basic.append( RadioSetting("p1", "P1 Function", - RadioSettingValueList(MICKEYFUNC, MICKEYFUNC[_settings.p1]))) - basic.append( RadioSetting("p2", "P2 Function", - RadioSettingValueList(MICKEYFUNC, MICKEYFUNC[_settings.p2]))) - basic.append( RadioSetting("p3", "P3 Function", - RadioSettingValueList(MICKEYFUNC, MICKEYFUNC[_settings.p3]))) - basic.append( RadioSetting("p4", "P4 Function", - RadioSettingValueList(MICKEYFUNC, MICKEYFUNC[_settings.p4]))) + """Base class for TYT TH-9800""" + VENDOR = "TYT" + + def get_features(self): + rf = chirp_common.RadioFeatures() + rf.memory_bounds = (1, 800) + rf.has_bank = False + rf.has_tuning_step = True + rf.valid_tuning_steps = STEPS + rf.can_odd_split = True + rf.valid_duplexes = ["", "-", "+", "split", "off"] + rf.valid_tmodes = TMODES + rf.has_ctone = False + rf.valid_power_levels = POWER_LEVELS + rf.valid_characters = chirp_common.CHARSET_UPPER_NUMERIC + "#*-+" + rf.valid_bands = [(26000000, 33000000), + (47000000, 54000000), + (108000000, 180000000), + (350000000, 399000000), + (430000000, 512000000), + (750000000, 947000000)] + rf.valid_skips = SCAN_MODES + rf.valid_modes = MODES + ["AM"] + rf.valid_name_length = 6 + rf.has_settings = True + return rf + + def process_mmap(self): + self._memobj = bitwise.parse( + TH9800_MEM_FORMAT % + (self._mmap_offset, self._scanlimits_offset, self._settings_offset, + self._chan_active_offset, self._info_offset), self._mmap) + + def get_active(self, banktype, num): + """get active flag for channel active, + scan enable, or priority banks""" + bank = getattr(self._memobj, banktype) + index = (num - 1) / 8 + bitpos = (num - 1) % 8 + mask = 2**bitpos + enabled = bank[index] & mask + if enabled: + return True + else: + return False + + def set_active(self, banktype, num, enable=True): + """set active flag for channel active, + scan enable, or priority banks""" + bank = getattr(self._memobj, banktype) + index = (num - 1) / 8 + bitpos = (num - 1) % 8 + mask = 2**bitpos + if enable: + bank[index] |= mask + else: + bank[index] &= ~mask + + def get_raw_memory(self, number): + return repr(self._memobj.memory[number - 1]) + + def get_memory(self, number): + _mem = self._memobj.memory[number - 1] + mem = chirp_common.Memory() + mem.number = number + + mem.empty = not self.get_active("chan_active", number) + if mem.empty: + return mem + + mem.freq = int(_mem.rx_freq) * 10 + + txfreq = int(_mem.tx_freq) * 10 + if txfreq == mem.freq: + mem.duplex = "" + elif txfreq == 0: + mem.duplex = "off" + mem.offset = 0 + elif abs(txfreq - mem.freq) > 70000000: + mem.duplex = "split" + mem.offset = txfreq + elif txfreq < mem.freq: + mem.duplex = "-" + mem.offset = mem.freq - txfreq + elif txfreq > mem.freq: + mem.duplex = "+" + mem.offset = txfreq - mem.freq + + mem.dtcs_polarity = DTCS_POLARITY[_mem.dtcs_pol] + + mem.tmode = TMODES[int(_mem.tmode)] + mem.ctone = mem.rtone = int(_mem.ctcss) / 10.0 + mem.dtcs = int(_mem.dtcs) + + mem.name = str(_mem.name) + mem.name = mem.name.replace("\xFF", " ").rstrip() + + if not self.get_active("scan_enable", number): + mem.skip = "S" + elif self.get_active("priority", number): + mem.skip = "P" + else: + mem.skip = "" + + mem.mode = _mem.am and "AM" or MODES[int(_mem.fmdev)] + + mem.power = POWER_LEVELS[_mem.power] + mem.tuning_step = STEPS[_mem.step] + + mem.extra = RadioSettingGroup("extra", "Extra") + + opts = ["Frequency", "Name"] + display = RadioSetting( + "display", "Display", + RadioSettingValueList(opts, opts[_mem.display])) + mem.extra.append(display) + + bclo = RadioSetting( + "bclo", "Busy Lockout", + RadioSettingValueList(BUSY_LOCK, BUSY_LOCK[_mem.bclo])) + bclo.set_doc("Busy Lockout") + mem.extra.append(bclo) + + emphasis = RadioSetting( + "emphasis", "Emphasis", + RadioSettingValueBoolean(bool(_mem.emphasis))) + emphasis.set_doc("Boosts 300Hz to 2500Hz mic response") + mem.extra.append(emphasis) + + compand = RadioSetting( + "compand", "Compand", + RadioSettingValueBoolean(bool(_mem.compand))) + compand.set_doc("Compress Audio") + mem.extra.append(compand) + + BeatShift = RadioSetting( + "BeatShift", "BeatShift", + RadioSettingValueBoolean(bool(_mem.BeatShift))) + BeatShift.set_doc("Beat Shift") + mem.extra.append(BeatShift) + + TalkAround = RadioSetting( + "talkaround", "Talk Around", + RadioSettingValueBoolean(bool(_mem.talkaround))) + TalkAround.set_doc("Simplex mode when out of range of repeater") + mem.extra.append(TalkAround) + + scramb = RadioSetting( + "scramb", "Scramble", + RadioSettingValueBoolean(bool(_mem.scramb))) + scramb.set_doc("Frequency inversion Scramble") + mem.extra.append(scramb) + + return mem + + def set_memory(self, mem): + _mem = self._memobj.memory[mem.number - 1] + + _prev_active = self.get_active("chan_active", mem.number) + self.set_active("chan_active", mem.number, not mem.empty) + if mem.empty or not _prev_active: + LOG.debug("initializing memory channel %d" % mem.number) + _mem.set_raw(BLANK_MEMORY) + + if mem.empty: + return + + _mem.rx_freq = mem.freq / 10 + if mem.duplex == "split": + _mem.tx_freq = mem.offset / 10 + elif mem.duplex == "-": + _mem.tx_freq = (mem.freq - mem.offset) / 10 + elif mem.duplex == "+": + _mem.tx_freq = (mem.freq + mem.offset) / 10 + elif mem.duplex == "off": + _mem.tx_freq = 0 + _mem.offset = 0 + else: + _mem.tx_freq = mem.freq / 10 + + _mem.tmode = TMODES.index(mem.tmode) + _mem.ctcss = mem.rtone * 10 + _mem.dtcs = mem.dtcs + _mem.dtcs_pol = DTCS_POLARITY.index(mem.dtcs_polarity) + + _mem.name = mem.name.ljust(6, "\xFF") + + # autoset display to name if filled, else show frequency + if mem.extra: + # mem.extra only seems to be populated when called from edit panel + display = mem.extra["display"] + else: + display = None + if mem.name: + _mem.display = True + if display and not display.changed(): + display.value = "Name" + else: + _mem.display = False + if display and not display.changed(): + display.value = "Frequency" + + _mem.scan = SCAN_MODES.index(mem.skip) + if mem.skip == "P": + self.set_active("priority", mem.number, True) + self.set_active("scan_enable", mem.number, True) + elif mem.skip == "S": + self.set_active("priority", mem.number, False) + self.set_active("scan_enable", mem.number, False) + elif mem.skip == "": + self.set_active("priority", mem.number, False) + self.set_active("scan_enable", mem.number, True) + + if mem.mode == "AM": + _mem.am = True + _mem.fmdev = 0 + else: + _mem.am = False + _mem.fmdev = MODES.index(mem.mode) + + if mem.power: + _mem.power = POWER_LEVELS.index(mem.power) + else: + _mem.power = 0 # low + _mem.step = STEPS.index(mem.tuning_step) + + for setting in mem.extra: + LOG.debug("@set_mem:", setting.get_name(), setting.value) + setattr(_mem, setting.get_name(), setting.value) + + def get_settings(self): + _settings = self._memobj.settings + _info = self._memobj.info + _bandlimits = self._memobj.bandlimits + basic = RadioSettingGroup("basic", "Basic") + info = RadioSettingGroup("info", "Model Info") + top = RadioSettings(basic, info) + basic.append(RadioSetting( + "beep", "Beep", + RadioSettingValueBoolean(_settings.beep))) + basic.append(RadioSetting( + "beep_vol", "Beep Volume", + RadioSettingValueInteger(0, 15, _settings.beep_vol))) + basic.append(RadioSetting( + "keylock", "Key Lock", + RadioSettingValueBoolean(_settings.keylock))) + basic.append(RadioSetting( + "ani_display", "ANI Display", + RadioSettingValueBoolean(_settings.ani_display))) + basic.append(RadioSetting( + "auto_xfer", "Auto Transfer", + RadioSettingValueBoolean(_settings.auto_xfer))) + basic.append(RadioSetting( + "auto_contact", "Auto Contact Always Remind", + RadioSettingValueBoolean(_settings.auto_contact))) + basic.append(RadioSetting( + "auto_am", "Auto AM", + RadioSettingValueBoolean(_settings.auto_am))) + basic.append(RadioSetting( + "left_sql", "Left Squelch", + RadioSettingValueList( + SQLPRESET, SQLPRESET[_settings.left_sql]))) + basic.append(RadioSetting( + "right_sql", "Right Squelch", + RadioSettingValueList( + SQLPRESET, SQLPRESET[_settings.right_sql]))) +# basic.append(RadioSetting("apo", "Auto Power off (0.1h)", +# RadioSettingValueInteger(0, 20, _settings.apo))) + opts = ["Off"] + ["%0.1f" % (t / 10.0) for t in range(1, 21, 1)] + basic.append(RadioSetting( + "apo", "Auto Power off (Hours)", + RadioSettingValueList(opts, opts[_settings.apo]))) + opts = ["Off", "1", "2", "3", "Full"] + basic.append(RadioSetting( + "backlight", "Display Backlight", + RadioSettingValueList(opts, opts[_settings.backlight]))) + opts = ["Off", "Right", "Left", "Both"] + basic.append(RadioSetting( + "pttlock", "PTT Lock", + RadioSettingValueList(opts, opts[_settings.pttlock]))) + opts = ["Manual", "Auto"] + basic.append(RadioSetting( + "hyper_chan", "Hyper Channel", + RadioSettingValueList(opts, opts[_settings.hyper_chan]))) + opts = ["Key 1", "Key 2"] + basic.append(RadioSetting( + "right_func_key", "Right Function Key", + RadioSettingValueList(opts, opts[_settings.right_func_key]))) + opts = ["1000Hz", "1450Hz", "1750Hz", "2100Hz"] + basic.append(RadioSetting( + "tbst_freq", "Tone Burst Frequency", + RadioSettingValueList(opts, opts[_settings.tbst_freq]))) + opts = ["Off", "TX", "RX", "TX RX"] + basic.append(RadioSetting( + "mute_mode", "Mute Mode", + RadioSettingValueList(opts, opts[_settings.mute_mode]))) + opts = ["MEM", "MSM"] + scanmode = RadioSetting( + "scan_mode", "Scan Mode", + RadioSettingValueList(opts, opts[_settings.scan_mode])) + scanmode.set_doc("MEM = Normal scan, bypass channels marked skip. " + " MSM = Scan only channels marked priority.") + basic.append(scanmode) + opts = ["TO", "CO"] + basic.append(RadioSetting( + "scan_resume", "Scan Resume", + RadioSettingValueList(opts, opts[_settings.scan_resume]))) + opts = ["%0.1f" % (t / 10.0) for t in range(0, 51, 1)] + basic.append(RadioSetting( + "exit_delay", "Span Transit Exit Delay", + RadioSettingValueList(opts, opts[_settings.exit_delay]))) + basic.append(RadioSetting( + "tot", "Time Out Timer (minutes)", + RadioSettingValueInteger(0, 30, _settings.tot))) + basic.append(RadioSetting( + "tot_alert", "Time Out Timer Pre Alert(seconds)", + RadioSettingValueInteger(0, 15, _settings.tot_alert))) + basic.append(RadioSetting( + "tot_rekey", "Time Out Rekey (seconds)", + RadioSettingValueInteger(0, 15, _settings.tot_rekey))) + basic.append(RadioSetting( + "tot_reset", "Time Out Reset(seconds)", + RadioSettingValueInteger(0, 15, _settings.tot_reset))) + basic.append(RadioSetting( + "p1", "P1 Function", + RadioSettingValueList(MICKEYFUNC, MICKEYFUNC[_settings.p1]))) + basic.append(RadioSetting( + "p2", "P2 Function", + RadioSettingValueList(MICKEYFUNC, MICKEYFUNC[_settings.p2]))) + basic.append(RadioSetting( + "p3", "P3 Function", + RadioSettingValueList(MICKEYFUNC, MICKEYFUNC[_settings.p3]))) + basic.append(RadioSetting( + "p4", "P4 Function", + RadioSettingValueList(MICKEYFUNC, MICKEYFUNC[_settings.p4]))) # opts = ["0", "1"] -# basic.append( RadioSetting("x", "Desc", +# basic.append(RadioSetting("x", "Desc", # RadioSettingValueList(opts, opts[_settings.x])))
- def _filter(name): - filtered = "" - for char in str(name): - if char in chirp_common.CHARSET_ASCII: - filtered += char - else: - filtered += " " - return filtered - - rsvs = RadioSettingValueString(0, 8, _filter(_info.sn)) - rsvs.set_mutable(False) - rs = RadioSetting("sn", "Serial Number", rsvs) - info.append(rs) - - rsvs = RadioSettingValueString(0, 8, _filter(_info.model)) - rsvs.set_mutable(False) - rs = RadioSetting("model", "Model Name", rsvs) - info.append(rs) - - rsvs = RadioSettingValueString(0, 16, _filter(_info.code)) - rsvs.set_mutable(False) - rs = RadioSetting("code", "Model Code", rsvs) - info.append(rs) - - progdate = "%d/%d/%d" % (_info.prog_mon, _info.prog_day, - _info.prog_yr ) - rsvs = RadioSettingValueString(0, 10, progdate) - rsvs.set_mutable(False) - rs = RadioSetting("progdate", "Last Program Date", rsvs) - info.append(rs) - - # 9 band limits - for i in range(0,9): - objname = BANDS[i] + "lorx" - objnamepp = BANDS[i] + " Rx Start" - #rsv = RadioSettingValueInteger(0,100000000, - # int(_bandlimits[i].lorx)) - rsv = RadioSettingValueString(0,10, - format_freq(int(_bandlimits[i].lorx)*10)) - rsv.set_mutable(False) - rs = RadioSetting(objname, objnamepp, rsv) - info.append(rs) - objname = BANDS[i] + "hirx" - objnamepp = BANDS[i] + " Rx end" - rsv = RadioSettingValueString(0,10, - format_freq(int(_bandlimits[i].hirx)*10)) - rsv.set_mutable(False) - rs = RadioSetting(objname, objnamepp, rsv) - info.append(rs) - objname = BANDS[i] + "lotx" - objnamepp = BANDS[i] + " Tx Start" - rsv = RadioSettingValueString(0,10, - format_freq(int(_bandlimits[i].lotx)*10)) - rsv.set_mutable(False) - rs = RadioSetting(objname, objnamepp, rsv) - info.append(rs) - objname = BANDS[i] + "hitx" - objnamepp = BANDS[i] + " Tx end" - rsv = RadioSettingValueString(0,10, - format_freq(int(_bandlimits[i].hitx)*10)) - rsv.set_mutable(False) - rs = RadioSetting(objname, objnamepp, rsv) - info.append(rs) - - return top - - def set_settings(self, settings): - _settings = self._memobj.settings - _info = self._memobj.info - _bandlimits = self._memobj.bandlimits - for element in settings: - if not isinstance(element, RadioSetting): - self.set_settings(element) - continue - if not element.changed(): - continue - try: - setting = element.get_name() - oldval = getattr(_settings, setting) - newval = element.value - - LOG.debug("Setting %s(%s) <= %s" % (setting, oldval, newval)) - setattr(_settings, setting, newval) - except Exception, e: - print element.get_name() - raise + def _filter(name): + filtered = "" + for char in str(name): + if char in chirp_common.CHARSET_ASCII: + filtered += char + else: + filtered += " " + return filtered + + rsvs = RadioSettingValueString(0, 8, _filter(_info.sn)) + rsvs.set_mutable(False) + rs = RadioSetting("sn", "Serial Number", rsvs) + info.append(rs) + + rsvs = RadioSettingValueString(0, 8, _filter(_info.model)) + rsvs.set_mutable(False) + rs = RadioSetting("model", "Model Name", rsvs) + info.append(rs) + + rsvs = RadioSettingValueString(0, 16, _filter(_info.code)) + rsvs.set_mutable(False) + rs = RadioSetting("code", "Model Code", rsvs) + info.append(rs) + + progdate = "%d/%d/%d" % (_info.prog_mon, _info.prog_day, + _info.prog_yr) + rsvs = RadioSettingValueString(0, 10, progdate) + rsvs.set_mutable(False) + rs = RadioSetting("progdate", "Last Program Date", rsvs) + info.append(rs) + + # 9 band limits + for i in range(0, 9): + objname = BANDS[i] + "lorx" + objnamepp = BANDS[i] + " Rx Start" + # rsv = RadioSettingValueInteger(0, 100000000, + # int(_bandlimits[i].lorx)) + rsv = RadioSettingValueString( + 0, 10, format_freq(int(_bandlimits[i].lorx)*10)) + rsv.set_mutable(False) + rs = RadioSetting(objname, objnamepp, rsv) + info.append(rs) + objname = BANDS[i] + "hirx" + objnamepp = BANDS[i] + " Rx end" + rsv = RadioSettingValueString( + 0, 10, format_freq(int(_bandlimits[i].hirx)*10)) + rsv.set_mutable(False) + rs = RadioSetting(objname, objnamepp, rsv) + info.append(rs) + objname = BANDS[i] + "lotx" + objnamepp = BANDS[i] + " Tx Start" + rsv = RadioSettingValueString( + 0, 10, format_freq(int(_bandlimits[i].lotx)*10)) + rsv.set_mutable(False) + rs = RadioSetting(objname, objnamepp, rsv) + info.append(rs) + objname = BANDS[i] + "hitx" + objnamepp = BANDS[i] + " Tx end" + rsv = RadioSettingValueString( + 0, 10, format_freq(int(_bandlimits[i].hitx)*10)) + rsv.set_mutable(False) + rs = RadioSetting(objname, objnamepp, rsv) + info.append(rs) + + return top + + def set_settings(self, settings): + _settings = self._memobj.settings + _info = self._memobj.info + _bandlimits = self._memobj.bandlimits + for element in settings: + if not isinstance(element, RadioSetting): + self.set_settings(element) + continue + if not element.changed(): + continue + try: + setting = element.get_name() + oldval = getattr(_settings, setting) + newval = element.value + + LOG.debug("Setting %s(%s) <= %s" % (setting, oldval, newval)) + setattr(_settings, setting, newval) + except Exception, e: + print element.get_name() + raise +
@directory.register class TYTTH9800File(TYTTH9800Base, chirp_common.FileBackedRadio): - """TYT TH-9800 .dat file""" - MODEL = "TH-9800 File" + """TYT TH-9800 .dat file""" + MODEL = "TH-9800 File"
- FILE_EXTENSION = "dat" + FILE_EXTENSION = "dat"
- _memsize = 69632 - _mmap_offset = 0x1100 - _scanlimits_offset = 0xC800 + _mmap_offset - _settings_offset = 0xCB20 + _mmap_offset - _chan_active_offset = 0xCB80 + _mmap_offset - _info_offset = 0xfe00 + _mmap_offset - - def __init__(self, pipe): - self.errors = [] - self._mmap = None + _memsize = 69632 + _mmap_offset = 0x1100 + _scanlimits_offset = 0xC800 + _mmap_offset + _settings_offset = 0xCB20 + _mmap_offset + _chan_active_offset = 0xCB80 + _mmap_offset + _info_offset = 0xfe00 + _mmap_offset
- if isinstance(pipe, str): - self.pipe = None - self.load_mmap(pipe) - else: - chirp_common.FileBackedRadio.__init__(self, pipe) + def __init__(self, pipe): + self.errors = [] + self._mmap = None
- @classmethod - def match_model(cls, filedata, filename): - return len(filedata) == cls._memsize and filename.endswith('.dat') + if isinstance(pipe, str): + self.pipe = None + self.load_mmap(pipe) + else: + chirp_common.FileBackedRadio.__init__(self, pipe) + + @classmethod + def match_model(cls, filedata, filename): + return len(filedata) == cls._memsize and filename.endswith('.dat')
def _identify(radio): - """Do identify handshake with TYT""" - try: - radio.pipe.write("\x02PROGRA") - ack = radio.pipe.read(1) - if ack != "A": - util.hexprint(ack) - raise errors.RadioError("Radio did not ACK first command: %x" - % ord(ack)) - except: - print util.hexprint(ack) - raise errors.RadioError("Unable to communicate with the radio") - - radio.pipe.write("M\x02") - ident = radio.pipe.read(16) - radio.pipe.write("A") - r = radio.pipe.read(1) - if r != "A": - raise errors.RadioError("Ack failed") - return ident - - -def _download(radio, memsize = 0x10000, blocksize = 0x80): - """Download from TYT TH-9800""" - data = _identify(radio) - print "ident:", util.hexprint(data) - offset = 0x100 - for addr in range(offset, memsize, blocksize): - msg = struct.pack(">cHB", "R", addr, blocksize) - radio.pipe.write(msg) - block = radio.pipe.read(blocksize + 4) - if len(block) != (blocksize + 4): - print util.hexprint(block) - raise errors.RadioError("Radio sent a short block") - radio.pipe.write("A") - ack = radio.pipe.read(1) - if ack != "A": + """Do identify handshake with TYT""" + try: + radio.pipe.write("\x02PROGRA") + ack = radio.pipe.read(1) + if ack != "A": + util.hexprint(ack) + raise errors.RadioError("Radio did not ACK first command: %x" + % ord(ack)) + except: print util.hexprint(ack) - raise errors.RadioError("Radio NAKed block") - data += block[4:] + raise errors.RadioError("Unable to communicate with the radio")
- if radio.status_fn: - status = chirp_common.Status() - status.cur = addr - status.max = memsize - status.msg = "Cloning from radio" - radio.status_fn(status) + radio.pipe.write("M\x02") + ident = radio.pipe.read(16) + radio.pipe.write("A") + r = radio.pipe.read(1) + if r != "A": + raise errors.RadioError("Ack failed") + return ident
- radio.pipe.write("ENDR")
- return memmap.MemoryMap(data) +def _download(radio, memsize=0x10000, blocksize=0x80): + """Download from TYT TH-9800""" + data = _identify(radio) + print "ident:", util.hexprint(data) + offset = 0x100 + for addr in range(offset, memsize, blocksize): + msg = struct.pack(">cHB", "R", addr, blocksize) + radio.pipe.write(msg) + block = radio.pipe.read(blocksize + 4) + if len(block) != (blocksize + 4): + print util.hexprint(block) + raise errors.RadioError("Radio sent a short block") + radio.pipe.write("A") + ack = radio.pipe.read(1) + if ack != "A": + print util.hexprint(ack) + raise errors.RadioError("Radio NAKed block") + data += block[4:]
+ if radio.status_fn: + status = chirp_common.Status() + status.cur = addr + status.max = memsize + status.msg = "Cloning from radio" + radio.status_fn(status)
-def _upload(radio, memsize = 0xF400, blocksize = 0x80): + radio.pipe.write("ENDR") + + return memmap.MemoryMap(data) + + +def _upload(radio, memsize=0xF400, blocksize=0x80): """Upload to TYT TH-9800""" data = _identify(radio)
@@ -651,8 +688,9 @@ def _upload(radio, memsize = 0xF400, blocksize = 0x80):
if data != radio._mmap[:radio._mmap_offset]: raise errors.RadioError( - "Model mis-match: \n%s\n%s" % (util.hexprint(data), - util.hexprint(radio._mmap[:radio._mmap_offset]))) + "Model mis-match: \n%s\n%s" % + (util.hexprint(data), + util.hexprint(radio._mmap[:radio._mmap_offset]))) # in the factory software they update the last program date when # they upload, So let's do the same today = date.today() @@ -664,8 +702,8 @@ def _upload(radio, memsize = 0xF400, blocksize = 0x80): ly = _info.prog_yr lm = _info.prog_mon ld = _info.prog_day - LOG.debug("Updating last program date:%d/%d/%d" % (lm,ld,ly)) - LOG.debug(" to today:%d/%d/%d" % (m,d,y)) + LOG.debug("Updating last program date:%d/%d/%d" % (lm, ld, ly)) + LOG.debug(" to today:%d/%d/%d" % (m, d, y))
_info.prog_yr = y _info.prog_mon = m @@ -675,14 +713,14 @@ def _upload(radio, memsize = 0xF400, blocksize = 0x80): for addr in range(offset, memsize, blocksize): mapaddr = addr + radio._mmap_offset - offset LOG.debug("addr: 0x%04X, mmapaddr: 0x%04X" % (addr, mapaddr)) - msg = struct.pack(">cHB", "W", addr, blocksize) + msg = struct.pack(">cHB", "W", addr, blocksize) msg += radio._mmap[mapaddr:(mapaddr + blocksize)] print util.hexprint(msg) radio.pipe.write(msg) ack = radio.pipe.read(1) if ack != "A": - print util.hexprint(ack) - raise errors.RadioError("Radio did not ack block 0x%04X" % addr) + print util.hexprint(ack) + raise errors.RadioError("Radio did not ack block 0x%04X" % addr)
if radio.status_fn: status = chirp_common.Status() @@ -698,47 +736,47 @@ def _upload(radio, memsize = 0xF400, blocksize = 0x80): final_data = radio.pipe.read(3) LOG.debug("final:", util.hexprint(final_data))
+ @directory.register class TYTTH9800Radio(TYTTH9800Base, chirp_common.CloneModeRadio, chirp_common.ExperimentalRadio): - VENDOR = "TYT" - MODEL = "TH-9800" - BAUD_RATE = 38400 - - _memsize = 65296 - _mmap_offset = 0x0010 - _scanlimits_offset = 0xC800 + _mmap_offset - _settings_offset = 0xCB20 + _mmap_offset - _chan_active_offset = 0xCB80 + _mmap_offset - _info_offset = 0xfe00 + _mmap_offset - - @classmethod - def match_model(cls, filedata, filename): - return len(filedata) == cls._memsize - - @classmethod - def get_prompts(cls): - rp = chirp_common.RadioPrompts() - rp.experimental = ( - 'This is experimental support for TH-9800 ' - 'which is still under development.\n' - 'Please ensure you have a good backup with OEM software.\n' - 'Also please send in bug and enhancement requests!\n' - 'You have been warned. Proceed at your own risk!') - return rp - - def sync_in(self): + VENDOR = "TYT" + MODEL = "TH-9800" + BAUD_RATE = 38400 + + _memsize = 65296 + _mmap_offset = 0x0010 + _scanlimits_offset = 0xC800 + _mmap_offset + _settings_offset = 0xCB20 + _mmap_offset + _chan_active_offset = 0xCB80 + _mmap_offset + _info_offset = 0xfe00 + _mmap_offset + + @classmethod + def match_model(cls, filedata, filename): + return len(filedata) == cls._memsize + + @classmethod + def get_prompts(cls): + rp = chirp_common.RadioPrompts() + rp.experimental = ( + 'This is experimental support for TH-9800 ' + 'which is still under development.\n' + 'Please ensure you have a good backup with OEM software.\n' + 'Also please send in bug and enhancement requests!\n' + 'You have been warned. Proceed at your own risk!') + return rp + + def sync_in(self): try: self._mmap = _download(self) except Exception, e: - raise errors.RadioError( \ - "Failed to communicate with the radio: %s" % e) + raise errors.RadioError( + "Failed to communicate with the radio: %s" % e) self.process_mmap()
- def sync_out(self): + def sync_out(self): try: _upload(self) except Exception, e: - raise errors.RadioError( \ - "Failed to communicate with the radio: %s" % e) - + raise errors.RadioError( + "Failed to communicate with the radio: %s" % e) diff --git a/tools/cpep8.blacklist b/tools/cpep8.blacklist index 8fda851..a92e97b 100644 --- a/tools/cpep8.blacklist +++ b/tools/cpep8.blacklist @@ -17,7 +17,6 @@ ./chirp/drivers/icw32.py ./chirp/drivers/icx8x.py ./chirp/drivers/icx8x_ll.py -./chirp/drivers/th9800.py ./chirp/drivers/th_uv3r.py ./chirp/drivers/th_uv3r25.py ./chirp/drivers/th_uvf8d.py