diff options
48 files changed, 8133 insertions, 650 deletions
@@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: chirp -Version: daily-20190104 +Version: daily-20190718 Summary: UNKNOWN Home-page: UNKNOWN Author: UNKNOWN diff --git a/chirp/__init__.py b/chirp/__init__.py index 03a22a2..8772324 100644 --- a/chirp/__init__.py +++ b/chirp/__init__.py @@ -17,7 +17,7 @@ import os import sys from glob import glob -CHIRP_VERSION="daily-20190104" +CHIRP_VERSION="daily-20190718" module_dir = os.path.dirname(sys.modules["chirp"].__file__) __all__ = [] diff --git a/chirp/chirp_common.py b/chirp/chirp_common.py index 89b1abb..4f64865 100644 --- a/chirp/chirp_common.py +++ b/chirp/chirp_common.py @@ -17,6 +17,7 @@ import base64 import json import logging import math +import sys from chirp import errors, memmap, CHIRP_VERSION LOG = logging.getLogger(__name__) @@ -93,6 +94,9 @@ TUNING_STEPS = [ # Need to fix drivers using this list as an index! 9.0, 1.0, 2.5, ] +# These are the default for RadioFeatures.valid_tuning_steps +COMMON_TUNING_STEPS = [5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 50.0, 100.0] + SKIP_VALUES = ["", "S", "P"] @@ -729,6 +733,7 @@ class RadioFeatures: "has_sub_devices": BOOLEAN, "memory_bounds": (0, 0), "can_odd_split": BOOLEAN, + "can_delete": BOOLEAN, # D-STAR "requires_call_lists": BOOLEAN, @@ -827,7 +832,7 @@ class RadioFeatures: "Supported tone squelch modes") self.init("valid_duplexes", ["", "+", "-"], "Supported duplex modes") - self.init("valid_tuning_steps", list(TUNING_STEPS), + self.init("valid_tuning_steps", list(COMMON_TUNING_STEPS), "Supported tuning steps") self.init("valid_bands", [], "Supported frequency ranges") @@ -857,7 +862,8 @@ class RadioFeatures: self.init("can_odd_split", False, "Indicates that the radio can store an independent " + "transmit frequency") - + self.init("can_delete", True, + "Indicates that the radio can delete memories") self.init("requires_call_lists", True, "[D-STAR] Indicates that the radio requires all callsigns " + "to be in the master list and cannot be stored " + @@ -1591,3 +1597,11 @@ def is_version_newer(version): my_version = (0,) return version > my_version + + +def http_user_agent(): + ver = sys.version_info + return 'chirp/%s (Python %i.%i.%i on %s)' % ( + CHIRP_VERSION, + ver.major, ver.minor, ver.micro, + sys.platform) diff --git a/chirp/drivers/alinco.py b/chirp/drivers/alinco.py index 7ca252e..54d8ce3 100644 --- a/chirp/drivers/alinco.py +++ b/chirp/drivers/alinco.py @@ -281,6 +281,7 @@ class DRx35Radio(AlincoStyleRadio): rf.has_ctone = True rf.has_bank = False rf.has_dtcs_polarity = False + rf.can_delete = False rf.valid_tuning_steps = STEPS rf.valid_name_length = 7 rf.valid_power_levels = self._power_levels diff --git a/chirp/drivers/baofeng_common.py b/chirp/drivers/baofeng_common.py index 8877bf1..9a6581c 100644 --- a/chirp/drivers/baofeng_common.py +++ b/chirp/drivers/baofeng_common.py @@ -377,6 +377,7 @@ class BaofengCommonHT(chirp_common.CloneModeRadio, rf.memory_bounds = (0, 127) rf.valid_power_levels = self.POWER_LEVELS rf.valid_bands = self.VALID_BANDS + rf.valid_tuning_steps = [2.5, 5.0, 6.25, 10.0, 12.5, 20.0, 25.0, 50.0] return rf diff --git a/chirp/drivers/baofeng_uv3r.py b/chirp/drivers/baofeng_uv3r.py index 7c72a96..a68bc60 100644 --- a/chirp/drivers/baofeng_uv3r.py +++ b/chirp/drivers/baofeng_uv3r.py @@ -210,6 +210,7 @@ class UV3RRadio(chirp_common.CloneModeRadio): rf.valid_duplexes = ["", "-", "+", "split"] rf.valid_cross_modes = ["Tone->Tone", "Tone->DTCS", "DTCS->Tone", "->Tone", "->DTCS"] + rf.valid_tuning_steps = STEPS rf.has_ctone = True rf.has_cross = True rf.has_tuning_step = False diff --git a/chirp/drivers/baofeng_wp970i.py b/chirp/drivers/baofeng_wp970i.py index 74b25ef..95949cd 100644 --- a/chirp/drivers/baofeng_wp970i.py +++ b/chirp/drivers/baofeng_wp970i.py @@ -331,6 +331,11 @@ class WP970I(baofeng_common.BaofengCommonHT): """)) return rp + def get_features(self): + rf = baofeng_common.BaofengCommonHT.get_features(self) + rf.valid_tuning_steps = STEPS + return rf + def process_mmap(self): """Process the mem map into the mem object""" self._memobj = bitwise.parse(self.MEM_FORMAT, self._mmap) diff --git a/chirp/drivers/bf-t1.py b/chirp/drivers/bf-t1.py index 2f6c393..c5b4e04 100644 --- a/chirp/drivers/bf-t1.py +++ b/chirp/drivers/bf-t1.py @@ -530,6 +530,7 @@ class BFT1(chirp_common.CloneModeRadio, chirp_common.ExperimentalRadio): rf.valid_skips = SKIP_VALUES rf.valid_dtcs_codes = DTCS rf.memory_bounds = (1, self._upper) + rf.valid_tuning_steps = [2.5, 5., 6.25, 10., 12.5, 25.] # normal dual bands rf.valid_bands = [self._vhf_range, self._uhf_range] diff --git a/chirp/drivers/bjuv55.py b/chirp/drivers/bjuv55.py index fc9f43c..36cb98e 100644 --- a/chirp/drivers/bjuv55.py +++ b/chirp/drivers/bjuv55.py @@ -36,7 +36,7 @@ BJUV55_MODEL = "\x50\xBB\xDD\x55\x63\x98\x4D" COLOR_LIST = ["Off", "Blue", "Red", "Pink"] -STEPS = uv5r.STEPS +STEPS = list(uv5r.STEPS) STEPS.remove(2.5) STEP_LIST = [str(x) for x in STEPS] diff --git a/chirp/drivers/boblov_x3plus.py b/chirp/drivers/boblov_x3plus.py index 309f055..d170c4e 100644 --- a/chirp/drivers/boblov_x3plus.py +++ b/chirp/drivers/boblov_x3plus.py @@ -271,7 +271,7 @@ class BoblovX3Plus(chirp_common.CloneModeRadio, mem.freq = int(rmem.rxfreq) * 10 # A blank (0MHz) or 0xFFFFFFFF frequency is considered empty - if mem.freq == 0 and rmem.rxfreq.get_raw() == '\xFF\xFF\xFF\xFF': + if mem.freq == 0 or rmem.rxfreq.get_raw() == '\xFF\xFF\xFF\xFF': LOG.debug('empty channel %d', number) mem.freq = 0 mem.empty = True diff --git a/chirp/drivers/btech.py b/chirp/drivers/btech.py index 23af957..ac9f4c6 100644 --- a/chirp/drivers/btech.py +++ b/chirp/drivers/btech.py @@ -19,8 +19,6 @@ import time import struct import logging -LOG = logging.getLogger(__name__) - from time import sleep from chirp import chirp_common, directory, memmap from chirp import bitwise, errors, util @@ -30,6 +28,8 @@ from chirp.settings import RadioSettingGroup, RadioSetting, \ RadioSettingValueFloat, RadioSettings, InvalidValueError from textwrap import dedent +LOG = logging.getLogger(__name__) + # A note about the memmory in these radios # # The real memory of these radios extends to 0x4000 @@ -59,8 +59,9 @@ LIST_ABCD = LIST_AB + ["C", "D"] LIST_ANIL = ["3", "4", "5"] LIST_APO = ["Off"] + ["%s minutes" % x for x in range(30, 330, 30)] LIST_COLOR4 = ["Off", "Blue", "Orange", "Purple"] -LIST_COLOR8 = ["Black", "White", "Red", "Blue", "Green", "Yellow", "Indego", +LIST_COLOR7 = ["White", "Red", "Blue", "Green", "Yellow", "Indego", "Purple", "Gray"] +LIST_COLOR8 = ["Black"] + LIST_COLOR7 LIST_DTMFST = ["OFF", "Keyboard", "ANI", "Keyboad + ANI"] LIST_EMCTP = ["TX alarm sound", "TX ANI", "Both"] LIST_EMCTPX = ["Off"] + LIST_EMCTP @@ -79,12 +80,19 @@ LIST_SKIPTX = ["Off", "Skip 1", "Skip 2"] STEPS = [2.5, 5.0, 6.25, 10.0, 12.5, 25.0] LIST_STEP = [str(x) for x in STEPS] LIST_SYNC = ["Off", "AB", "CD", "AB+CD"] -LIST_TMR = ["OFF", "M+A", "M+B", "M+C", "M+D", "M+A+B", "M+A+C", "M+A+D", - "M+B+C", "M+B+D", "M+C+D", "M+A+B+C", "M+A+B+D", "M+A+C+D", - "M+B+C+D", "A+B+C+D"] +# the first 12 TMR choices common to all color display mobile radios +LIST_TMR12 = ["OFF", "M+A", "M+B", "M+C", "M+D", "M+A+B", "M+A+C", "M+A+D", + "M+B+C", "M+B+D", "M+C+D", "M+A+B+C"] +# the 16 choice list for color display mobile radios that correctly implement +# the full 16 TMR choices +LIST_TMR16 = LIST_TMR12 + ["M+A+B+D", "M+A+C+D", "M+B+C+D", "A+B+C+D"] +# the 15 choice list for color mobile radios that are missing the M+A+B+D +# choice in the TMR menu +LIST_TMR15 = LIST_TMR12 + ["M+A+C+D", "M+B+C+D", "A+B+C+D"] LIST_TOT = ["%s sec" % x for x in range(15, 615, 15)] LIST_TXDISP = ["Power", "Mic Volume"] LIST_TXP = ["High", "Low"] +LIST_TXP3 = ["High", "Mid", "Low"] LIST_SCREV = ["TO (timeout)", "CO (carrier operated)", "SE (search)"] LIST_VFOMR = ["Frequency", "Channel"] LIST_WIDE = ["Wide", "Narrow"] @@ -109,9 +117,9 @@ LIST_DTMF_SPEED = ["%s ms" % x for x in range(50, 2010, 10)] LIST_DTMF_DIGITS = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "#", "*"] LIST_DTMF_VALUES = [0x0A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, - 0x0D, 0x0E, 0x0F, 0x00, 0x0C, 0x0B ] -LIST_DTMF_SPECIAL_DIGITS = [ "*", "#", "A", "B", "C", "D"] -LIST_DTMF_SPECIAL_VALUES = [ 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00] + 0x0D, 0x0E, 0x0F, 0x00, 0x0C, 0x0B] +LIST_DTMF_SPECIAL_DIGITS = ["*", "#", "A", "B", "C", "D"] +LIST_DTMF_SPECIAL_VALUES = [0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00] LIST_DTMF_DELAY = ["%s ms" % x for x in range(100, 4100, 100)] CHARSET_DTMF_DIGITS = "0123456789AaBbCcDd#*" LIST_2TONE_DEC = ["A-B", "A-C", "A-D", @@ -133,7 +141,7 @@ VALID_CHARS = chirp_common.CHARSET_ALPHANUMERIC + \ "`{|}!\"#$%&'()*+,-./:;<=>?@[]^_" -##### ID strings ##################################################### +# #### ID strings ##################################################### # BTECH UV2501 pre-production units UV2501pp_fp = "M2C294" @@ -176,6 +184,10 @@ UV25X4_fp = "UC4014" # B-TECH UV-50X2 UV50X2_fp = "UC2M12" +# B-TECH GMRS-50X1 +GMRS50X1_fp = "NC1802" +GMRS50X1_fp1 = "NC1932" + # special var to know when we found a BTECH Gen 3 BTECH3 = [UV2501G3_fp, UV2501_220G3_fp, UV5001G3_fp] @@ -210,6 +222,8 @@ KT8900R_fp3 = "M39164" KT8900R_fp4 = "M3G314" # this radio has an extra ID KT8900R_id = "280528" +# another extra ID in dec/2018 +KT8900R_id2 = "\x05\x58\x3d\xf0\x10" # KT7900D (quad band) KT7900D_fp = "VC4004" @@ -228,7 +242,7 @@ LT588UV_fp = "V2G1F4" LT588UV_fp1 = "V2G214" -#### MAGICS +# ### MAGICS # for the Waccom Mini-8900 MSTRING_MINI8900 = "\x55\xA5\xB5\x45\x55\x45\x4d\x02" # for the B-TECH UV-2501+220 (including pre production ones) @@ -244,6 +258,8 @@ MSTRING_KT8900D = "\x55\x20\x16\x08\x01\xFF\xDC\x02" MSTRING_UV25X2 = "\x55\x20\x16\x12\x28\xFF\xDC\x02" # for the BTECH UV-25X4 MSTRING_UV25X4 = "\x55\x20\x16\x11\x18\xFF\xDC\x02" +# for the BTECH GMRS-50X1 +MSTRING_GMRS50X1 = "\x55\x20\x18\x10\x18\xFF\xDC\x02" def _clean_buffer(radio): @@ -312,7 +328,7 @@ def _send(radio, data): # hits some models more than others. # # To cope with that we introduce a delay on the writes. - # Many option have been tested (delaying only after error occures, + # Many option have been tested (delaying only after error occures, # after short reads, only for linux, ...) # Finally, a static delay was chosen as simplest of all solutions # (Michael Wagner, OE4AMW) @@ -461,7 +477,13 @@ def _do_ident(radio, status, upload=False): raise errors.RadioError("The extra ID is short, aborting.") # ok, the correct string must be in the received data - if radio._id2 not in id2: + # the radio._id2 var will be always a list + flag2 = False + for _id2 in radio._id2: + if _id2 in id2: + flag2 = True + + if not flag2: LOG.debug("Full *BAD* extra ID on the %s is: \n%s" % (radio.MODEL, util.hexprint(id2))) raise errors.RadioError("The extra ID is wrong, aborting.") @@ -551,7 +573,7 @@ def _upload(radio): # The UPLOAD mem is restricted to lower than 0x3100, # so we will overide that here localy - MEM_SIZE = 0x3100 + MEM_SIZE = radio.UPLOAD_MEM_SIZE # UI progress status = chirp_common.Status() @@ -598,10 +620,10 @@ def _upload(radio): if len(ack) != 1: raise errors.RadioError("No ACK when writing block 0x%04x" % addr) - if not ack in "\x06\x05": + if ack not in "\x06\x05": raise errors.RadioError("Bad ACK writing block 0x%04x:" % addr) - # UI Update + # UI Update status.cur = addr / TX_BLOCK_SIZE status.msg = "Cloning to radio..." radio.status_fn(status) @@ -651,7 +673,9 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, IDENT = "" BANDS = 2 COLOR_LCD = False + COLOR_LCD2 = False NAME_LENGTH = 6 + UPLOAD_MEM_SIZE = 0X3100 _power_levels = [chirp_common.PowerLevel("High", watts=25), chirp_common.PowerLevel("Low", watts=10)] _vhf_range = (130000000, 180000000) @@ -729,6 +753,7 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, "DTCS->DTCS"] rf.valid_skips = SKIP_VALUES rf.valid_dtcs_codes = DTCS + rf.valid_tuning_steps = STEPS rf.memory_bounds = (0, self._upper) # power levels @@ -837,7 +862,8 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, # TX freq set offset = (int(_mem.txfreq) * 10) - mem.freq if offset != 0: - if _split(self.get_features(), mem.freq, int(_mem.txfreq) * 10): + if _split(self.get_features(), mem.freq, int( + _mem.txfreq) * 10): mem.duplex = "split" mem.offset = int(_mem.txfreq) * 10 elif offset < 0: @@ -871,7 +897,7 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, mem.extra = RadioSettingGroup("extra", "Extra") if not self.COLOR_LCD or \ - (self.COLOR_LCD and not self.VENDOR == "BTECH"): + (self.COLOR_LCD and not self.VENDOR == "BTECH"): scramble = RadioSetting("scramble", "Scramble", RadioSettingValueBoolean(bool( _mem.scramble))) @@ -920,7 +946,7 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, if _mem.get_raw()[0] == "\xFF": LOG.debug("This mem was empty before") mem_was_empty = True - + # if empty memmory if mem.empty: # the channel itself @@ -1028,8 +1054,8 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, if self.COLOR_LCD: tmr = RadioSetting("settings.tmr", "Transceiver multi-receive", RadioSettingValueList( - LIST_TMR, - LIST_TMR[_mem.settings.tmr])) + self.LIST_TMR, + self.LIST_TMR[_mem.settings.tmr])) basic.append(tmr) else: tdr = RadioSetting("settings.tdr", "Transceiver dual receive", @@ -1040,6 +1066,12 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, RadioSettingValueInteger(0, 9, _mem.settings.sql)) basic.append(sql) + if self.MODEL == "GMRS-50X1": + autolk = RadioSetting("settings.autolk", "Auto keylock", + RadioSettingValueBoolean( + _mem.settings.autolk)) + basic.append(autolk) + tot = RadioSetting("settings.tot", "Time out timer", RadioSettingValueList( LIST_TOT, @@ -1055,7 +1087,7 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, else: toa = RadioSetting("settings.apo", "Time out alert timer", RadioSettingValueList( - LIST_OFF1TO10, + LIST_OFF1TO10, LIST_OFF1TO10[_mem.settings.apo])) basic.append(toa) @@ -1082,8 +1114,8 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, basic.append(prisc) prich = RadioSetting("settings.prich", "Priority channel", - RadioSettingValueInteger(0, 199, - _mem.settings.prich)) + RadioSettingValueInteger(0, self._upper, + _mem.settings.prich)) basic.append(prich) screv = RadioSetting("settings.screv", "Scan resume method", @@ -1094,7 +1126,7 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, pttlt = RadioSetting("settings.pttlt", "PTT transmit delay", RadioSettingValueInteger(0, 30, - _mem.settings.pttlt)) + _mem.settings.pttlt)) basic.append(pttlt) if self.VENDOR == "BTECH" and self.COLOR_LCD: @@ -1111,8 +1143,8 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, basic.append(emctp) emcch = RadioSetting("settings.emcch", "Alarm channel", - RadioSettingValueInteger(0, 199, - _mem.settings.emcch)) + RadioSettingValueInteger(0, self._upper, + _mem.settings.emcch)) basic.append(emcch) if self.COLOR_LCD: @@ -1120,7 +1152,7 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, val = 0x00 else: val = _mem.settings.sigbp - sigbp = RadioSetting("settings.sigbp", "Roger beep", + sigbp = RadioSetting("settings.sigbp", "Signal beep", RadioSettingValueBoolean(val)) basic.append(sigbp) else: @@ -1186,19 +1218,19 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, LIST_PONMSG[_mem.settings.ponmsg])) basic.append(ponmsg) - if self.COLOR_LCD: - mainfc = RadioSetting("settings.mainfc", + if self.COLOR_LCD and not self.COLOR_LCD2: + mainfc = RadioSetting("settings.mainfc", "Main LCD foreground color", - RadioSettingValueList( - LIST_COLOR8, - LIST_COLOR8[_mem.settings.mainfc])) + RadioSettingValueList( + LIST_COLOR8, + LIST_COLOR8[_mem.settings.mainfc])) basic.append(mainfc) mainbc = RadioSetting("settings.mainbc", "Main LCD background color", - RadioSettingValueList( - LIST_COLOR8, - LIST_COLOR8[_mem.settings.mainbc])) + RadioSettingValueList( + LIST_COLOR8, + LIST_COLOR8[_mem.settings.mainbc])) basic.append(mainbc) menufc = RadioSetting("settings.menufc", "Menu foreground color", @@ -1215,30 +1247,30 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, stafc = RadioSetting("settings.stafc", "Top status foreground color", - RadioSettingValueList( - LIST_COLOR8, - LIST_COLOR8[_mem.settings.stafc])) + RadioSettingValueList( + LIST_COLOR8, + LIST_COLOR8[_mem.settings.stafc])) basic.append(stafc) stabc = RadioSetting("settings.stabc", "Top status background color", - RadioSettingValueList( - LIST_COLOR8, - LIST_COLOR8[_mem.settings.stabc])) + RadioSettingValueList( + LIST_COLOR8, + LIST_COLOR8[_mem.settings.stabc])) basic.append(stabc) sigfc = RadioSetting("settings.sigfc", "Bottom status foreground color", - RadioSettingValueList( - LIST_COLOR8, - LIST_COLOR8[_mem.settings.sigfc])) + RadioSettingValueList( + LIST_COLOR8, + LIST_COLOR8[_mem.settings.sigfc])) basic.append(sigfc) sigbc = RadioSetting("settings.sigbc", "Bottom status background color", - RadioSettingValueList( - LIST_COLOR8, - LIST_COLOR8[_mem.settings.sigbc])) + RadioSettingValueList( + LIST_COLOR8, + LIST_COLOR8[_mem.settings.sigbc])) basic.append(sigbc) rxfc = RadioSetting("settings.rxfc", "Receiving character color", @@ -1249,16 +1281,107 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, txfc = RadioSetting("settings.txfc", "Transmitting character color", - RadioSettingValueList( - LIST_COLOR8, - LIST_COLOR8[_mem.settings.txfc])) + RadioSettingValueList( + LIST_COLOR8, + LIST_COLOR8[_mem.settings.txfc])) basic.append(txfc) txdisp = RadioSetting("settings.txdisp", "Transmitting status display", - RadioSettingValueList( - LIST_TXDISP, - LIST_TXDISP[_mem.settings.txdisp])) + RadioSettingValueList( + LIST_TXDISP, + LIST_TXDISP[_mem.settings.txdisp])) + basic.append(txdisp) + elif self.COLOR_LCD2: + stfc = RadioSetting("settings.stfc", + "ST-FC", + RadioSettingValueList( + LIST_COLOR7, + LIST_COLOR7[_mem.settings.stfc])) + basic.append(stfc) + + mffc = RadioSetting("settings.mffc", + "MF-FC", + RadioSettingValueList( + LIST_COLOR7, + LIST_COLOR7[_mem.settings.mffc])) + basic.append(mffc) + + sfafc = RadioSetting("settings.sfafc", + "SFA-FC", + RadioSettingValueList( + LIST_COLOR7, + LIST_COLOR7[_mem.settings.sfafc])) + basic.append(sfafc) + + sfbfc = RadioSetting("settings.sfbfc", + "SFB-FC", + RadioSettingValueList( + LIST_COLOR7, + LIST_COLOR7[_mem.settings.sfbfc])) + basic.append(sfbfc) + + sfcfc = RadioSetting("settings.sfcfc", + "SFC-FC", + RadioSettingValueList( + LIST_COLOR7, + LIST_COLOR7[_mem.settings.sfcfc])) + basic.append(sfcfc) + + sfdfc = RadioSetting("settings.sfdfc", + "SFD-FC", + RadioSettingValueList( + LIST_COLOR7, + LIST_COLOR7[_mem.settings.sfdfc])) + basic.append(sfdfc) + + subfc = RadioSetting("settings.subfc", + "SUB-FC", + RadioSettingValueList( + LIST_COLOR7, + LIST_COLOR7[_mem.settings.subfc])) + basic.append(subfc) + + fmfc = RadioSetting("settings.fmfc", + "FM-FC", + RadioSettingValueList( + LIST_COLOR7, + LIST_COLOR7[_mem.settings.fmfc])) + basic.append(fmfc) + + sigfc = RadioSetting("settings.sigfc", + "SIG-FC", + RadioSettingValueList( + LIST_COLOR7, + LIST_COLOR7[_mem.settings.sigfc])) + basic.append(sigfc) + + modfc = RadioSetting("settings.modfc", + "MOD-FC", + RadioSettingValueList( + LIST_COLOR7, + LIST_COLOR7[_mem.settings.modfc])) + basic.append(modfc) + + menufc = RadioSetting("settings.menufc", + "MENUFC", + RadioSettingValueList( + LIST_COLOR7, + LIST_COLOR7[_mem.settings.menufc])) + basic.append(menufc) + + txfc = RadioSetting("settings.txfc", + "TX-FC", + RadioSettingValueList( + LIST_COLOR7, + LIST_COLOR7[_mem.settings.txfc])) + basic.append(txfc) + + txdisp = RadioSetting("settings.txdisp", + "Transmitting status display", + RadioSettingValueList( + LIST_TXDISP, + LIST_TXDISP[_mem.settings.txdisp])) basic.append(txdisp) else: wtled = RadioSetting("settings.wtled", "Standby backlight Color", @@ -1291,11 +1414,12 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, LIST_REPS[_mem.settings.reps])) basic.append(reps) - repm = RadioSetting("settings.repm", "Relay condition", - RadioSettingValueList( - LIST_REPM, - LIST_REPM[_mem.settings.repm])) - basic.append(repm) + if not self.MODEL == "GMRS-50X1": + repm = RadioSetting("settings.repm", "Relay condition", + RadioSettingValueList( + LIST_REPM, + LIST_REPM[_mem.settings.repm])) + basic.append(repm) if self.VENDOR == "BTECH" or self.COLOR_LCD: if self.COLOR_LCD: @@ -1307,7 +1431,7 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, else: tdrab = RadioSetting("settings.tdrab", "TDR return time", RadioSettingValueList( - LIST_OFF1TO50, + LIST_OFF1TO50, LIST_OFF1TO50[_mem.settings.tdrab])) basic.append(tdrab) @@ -1330,19 +1454,19 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, if str(_mem.fingerprint.fp) in BTECH3: mgain = RadioSetting("settings.mgain", "Mic gain", RadioSettingValueInteger(0, 120, - _mem.settings.mgain)) + _mem.settings.mgain)) basic.append(mgain) if str(_mem.fingerprint.fp) in BTECH3 or self.COLOR_LCD: dtmfg = RadioSetting("settings.dtmfg", "DTMF gain", RadioSettingValueInteger(0, 60, - _mem.settings.dtmfg)) + _mem.settings.dtmfg)) basic.append(dtmfg) if self.VENDOR == "BTECH" and self.COLOR_LCD: mgain = RadioSetting("settings.mgain", "Mic gain", RadioSettingValueInteger(0, 120, - _mem.settings.mgain)) + _mem.settings.mgain)) basic.append(mgain) skiptx = RadioSetting("settings.skiptx", "Skip TX", @@ -1367,57 +1491,64 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, filtered += " " return filtered - _msg = self._memobj.poweron_msg - if self.COLOR_LCD: + if self.COLOR_LCD and not self.COLOR_LCD2: + _msg = self._memobj.poweron_msg line1 = RadioSetting("poweron_msg.line1", "Power-on message line 1", - RadioSettingValueString(0, 8, _filter( - _msg.line1))) + RadioSettingValueString(0, 8, _filter( + _msg.line1))) advanced.append(line1) line2 = RadioSetting("poweron_msg.line2", "Power-on message line 2", - RadioSettingValueString(0, 8, _filter( - _msg.line2))) + RadioSettingValueString(0, 8, _filter( + _msg.line2))) advanced.append(line2) line3 = RadioSetting("poweron_msg.line3", "Power-on message line 3", - RadioSettingValueString(0, 8, _filter( - _msg.line3))) + RadioSettingValueString(0, 8, _filter( + _msg.line3))) advanced.append(line3) line4 = RadioSetting("poweron_msg.line4", "Power-on message line 4", - RadioSettingValueString(0, 8, _filter( - _msg.line4))) + RadioSettingValueString(0, 8, _filter( + _msg.line4))) advanced.append(line4) line5 = RadioSetting("poweron_msg.line5", "Power-on message line 5", - RadioSettingValueString(0, 8, _filter( - _msg.line5))) + RadioSettingValueString(0, 8, _filter( + _msg.line5))) advanced.append(line5) line6 = RadioSetting("poweron_msg.line6", "Power-on message line 6", - RadioSettingValueString(0, 8, _filter( - _msg.line6))) + RadioSettingValueString(0, 8, _filter( + _msg.line6))) advanced.append(line6) line7 = RadioSetting("poweron_msg.line7", "Power-on message line 7", - RadioSettingValueString(0, 8, _filter( - _msg.line7))) + RadioSettingValueString(0, 8, _filter( + _msg.line7))) advanced.append(line7) line8 = RadioSetting("poweron_msg.line8", "Static message", RadioSettingValueString(0, 8, _filter( - _msg.line8))) + _msg.line8))) advanced.append(line8) + elif self.COLOR_LCD2: + _msg = self._memobj.static_msg + line = RadioSetting("static_msg.line", "Static message", + RadioSettingValueString(0, 16, _filter( + _msg.line))) + advanced.append(line) else: + _msg = self._memobj.poweron_msg line1 = RadioSetting("poweron_msg.line1", "Power-on message line 1", - RadioSettingValueString(0, 6, _filter( - _msg.line1))) + RadioSettingValueString(0, 6, _filter( + _msg.line1))) advanced.append(line1) line2 = RadioSetting("poweron_msg.line2", "Power-on message line 2", - RadioSettingValueString(0, 6, _filter( - _msg.line2))) + RadioSettingValueString(0, 6, _filter( + _msg.line2))) advanced.append(line2) if self.MODEL in ("UV-2501", "UV-5001"): @@ -1508,7 +1639,6 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, fp = RadioSetting("fingerprint.fp", "Fingerprint", val) other.append(fp) - # Work if self.COLOR_LCD: dispab = RadioSetting("settings2.dispab", "Display", @@ -1554,30 +1684,30 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, LIST_VFOMR[_mem.settings2.vfomr])) work.append(vfomr) - keylock = RadioSetting("settings2.keylock", "Keypad lock", - RadioSettingValueBoolean(_mem.settings2.keylock)) + RadioSettingValueBoolean( + _mem.settings2.keylock)) work.append(keylock) mrcha = RadioSetting("settings2.mrcha", "MR A channel", - RadioSettingValueInteger(0, 199, - _mem.settings2.mrcha)) + RadioSettingValueInteger(0, self._upper, + _mem.settings2.mrcha)) work.append(mrcha) mrchb = RadioSetting("settings2.mrchb", "MR B channel", - RadioSettingValueInteger(0, 199, - _mem.settings2.mrchb)) + RadioSettingValueInteger(0, self._upper, + _mem.settings2.mrchb)) work.append(mrchb) if self.COLOR_LCD: mrchc = RadioSetting("settings2.mrchc", "MR C channel", - RadioSettingValueInteger(0, 199, - _mem.settings2.mrchc)) + RadioSettingValueInteger( + 0, self._upper, _mem.settings2.mrchc)) work.append(mrchc) mrchd = RadioSetting("settings2.mrchd", "MR D channel", - RadioSettingValueInteger(0, 199, - _mem.settings2.mrchd)) + RadioSettingValueInteger( + 0, self._upper, _mem.settings2.mrchd)) work.append(mrchd) def convert_bytes_to_freq(bytes): @@ -1605,24 +1735,24 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, msg = ("Can't be betweeb %i.9975-%i.0000") if self.BANDS == 2: if (_vhf_upper + 1) * 1000000 <= value and \ - value < _uhf_lower * 1000000: + value < _uhf_lower * 1000000: raise InvalidValueError(msg % (_vhf_upper, _uhf_lower)) if self.BANDS == 3: if (_vhf_upper + 1) * 1000000 <= value and \ - value < _vhf2_lower * 1000000: + value < _vhf2_lower * 1000000: raise InvalidValueError(msg % (_vhf_upper, _vhf2_lower)) if (_vhf2_upper + 1) * 1000000 <= value and \ - value < _uhf_lower * 1000000: + value < _uhf_lower * 1000000: raise InvalidValueError(msg % (_vhf2_upper, _uhf_lower)) if self.BANDS == 4: if (_vhf_upper + 1) * 1000000 <= value and \ - value < _vhf2_lower * 1000000: + value < _vhf2_lower * 1000000: raise InvalidValueError(msg % (_vhf_upper, _vhf2_lower)) if (_vhf2_upper + 1) * 1000000 <= value and \ - value < _uhf2_lower * 1000000: + value < _uhf2_lower * 1000000: raise InvalidValueError(msg % (_vhf2_upper, _uhf2_lower)) if (_uhf2_upper + 1) * 1000000 <= value and \ - value < _uhf_lower * 1000000: + value < _uhf_lower * 1000000: raise InvalidValueError(msg % (_uhf2_upper, _uhf_lower)) msg = ("Can't be greater then %i.9975") if value > 99000000 and value >= _uhf_upper * 1000000: @@ -1664,30 +1794,31 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, vfodfreq.set_apply_callback(apply_freq, _mem.vfo.d) work.append(vfodfreq) - vfoashiftd = RadioSetting("vfo.a.shiftd", "VFO A shift", - RadioSettingValueList( - LIST_SHIFT, - LIST_SHIFT[_mem.vfo.a.shiftd])) - work.append(vfoashiftd) - - vfobshiftd = RadioSetting("vfo.b.shiftd", "VFO B shift", - RadioSettingValueList( - LIST_SHIFT, - LIST_SHIFT[_mem.vfo.b.shiftd])) - work.append(vfobshiftd) - - if self.COLOR_LCD: - vfocshiftd = RadioSetting("vfo.c.shiftd", "VFO C shift", + if not self.MODEL == "GMRS-50X1": + vfoashiftd = RadioSetting("vfo.a.shiftd", "VFO A shift", RadioSettingValueList( LIST_SHIFT, - LIST_SHIFT[_mem.vfo.c.shiftd])) - work.append(vfocshiftd) + LIST_SHIFT[_mem.vfo.a.shiftd])) + work.append(vfoashiftd) - vfodshiftd = RadioSetting("vfo.d.shiftd", "VFO D shift", + vfobshiftd = RadioSetting("vfo.b.shiftd", "VFO B shift", RadioSettingValueList( LIST_SHIFT, - LIST_SHIFT[_mem.vfo.d.shiftd])) - work.append(vfodshiftd) + LIST_SHIFT[_mem.vfo.b.shiftd])) + work.append(vfobshiftd) + + if self.COLOR_LCD: + vfocshiftd = RadioSetting("vfo.c.shiftd", "VFO C shift", + RadioSettingValueList( + LIST_SHIFT, + LIST_SHIFT[_mem.vfo.c.shiftd])) + work.append(vfocshiftd) + + vfodshiftd = RadioSetting("vfo.d.shiftd", "VFO D shift", + RadioSettingValueList( + LIST_SHIFT, + LIST_SHIFT[_mem.vfo.d.shiftd])) + work.append(vfodshiftd) def convert_bytes_to_offset(bytes): real_offset = 0 @@ -1701,99 +1832,105 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, obj.offset[i] = value % 10 value /= 10 - if self.COLOR_LCD: - val1a = RadioSettingValueString(0, 10, convert_bytes_to_offset( - _mem.vfo.a.offset)) - vfoaoffset = RadioSetting("vfo.a.offset", - "VFO A offset (0.000-999.999)", val1a) - vfoaoffset.set_apply_callback(apply_offset, _mem.vfo.a) - work.append(vfoaoffset) - - val1b = RadioSettingValueString(0, 10, convert_bytes_to_offset( - _mem.vfo.b.offset)) - vfoboffset = RadioSetting("vfo.b.offset", - "VFO B offset (0.000-999.999)", val1b) - vfoboffset.set_apply_callback(apply_offset, _mem.vfo.b) - work.append(vfoboffset) - - val1c = RadioSettingValueString(0, 10, convert_bytes_to_offset( - _mem.vfo.c.offset)) - vfocoffset = RadioSetting("vfo.c.offset", - "VFO C offset (0.000-999.999)", val1c) - vfocoffset.set_apply_callback(apply_offset, _mem.vfo.c) - work.append(vfocoffset) - - val1d = RadioSettingValueString(0, 10, convert_bytes_to_offset( - _mem.vfo.d.offset)) - vfodoffset = RadioSetting("vfo.d.offset", - "VFO D offset (0.000-999.999)", val1d) - vfodoffset.set_apply_callback(apply_offset, _mem.vfo.d) - work.append(vfodoffset) - else: - val1a = RadioSettingValueString(0, 10, convert_bytes_to_offset( - _mem.vfo.a.offset)) - vfoaoffset = RadioSetting("vfo.a.offset", - "VFO A offset (0.000-99.999)", val1a) - vfoaoffset.set_apply_callback(apply_offset, _mem.vfo.a) - work.append(vfoaoffset) - - val1b = RadioSettingValueString(0, 10, convert_bytes_to_offset( - _mem.vfo.b.offset)) - vfoboffset = RadioSetting("vfo.b.offset", - "VFO B offset (0.000-99.999)", val1b) - vfoboffset.set_apply_callback(apply_offset, _mem.vfo.b) - work.append(vfoboffset) - - - vfoatxp = RadioSetting("vfo.a.power", "VFO A power", - RadioSettingValueList( - LIST_TXP, - LIST_TXP[_mem.vfo.a.power])) - work.append(vfoatxp) - - vfobtxp = RadioSetting("vfo.b.power", "VFO B power", - RadioSettingValueList( - LIST_TXP, - LIST_TXP[_mem.vfo.b.power])) - work.append(vfobtxp) - - if self.COLOR_LCD: - vfoctxp = RadioSetting("vfo.c.power", "VFO C power", + if not self.MODEL == "GMRS-50X1": + if self.COLOR_LCD: + val1a = RadioSettingValueString(0, 10, convert_bytes_to_offset( + _mem.vfo.a.offset)) + vfoaoffset = RadioSetting("vfo.a.offset", + "VFO A offset (0.000-999.999)", + val1a) + vfoaoffset.set_apply_callback(apply_offset, _mem.vfo.a) + work.append(vfoaoffset) + + val1b = RadioSettingValueString(0, 10, convert_bytes_to_offset( + _mem.vfo.b.offset)) + vfoboffset = RadioSetting("vfo.b.offset", + "VFO B offset (0.000-999.999)", + val1b) + vfoboffset.set_apply_callback(apply_offset, _mem.vfo.b) + work.append(vfoboffset) + + val1c = RadioSettingValueString(0, 10, convert_bytes_to_offset( + _mem.vfo.c.offset)) + vfocoffset = RadioSetting("vfo.c.offset", + "VFO C offset (0.000-999.999)", + val1c) + vfocoffset.set_apply_callback(apply_offset, _mem.vfo.c) + work.append(vfocoffset) + + val1d = RadioSettingValueString(0, 10, convert_bytes_to_offset( + _mem.vfo.d.offset)) + vfodoffset = RadioSetting("vfo.d.offset", + "VFO D offset (0.000-999.999)", + val1d) + vfodoffset.set_apply_callback(apply_offset, _mem.vfo.d) + work.append(vfodoffset) + else: + val1a = RadioSettingValueString(0, 10, convert_bytes_to_offset( + _mem.vfo.a.offset)) + vfoaoffset = RadioSetting("vfo.a.offset", + "VFO A offset (0.000-99.999)", val1a) + vfoaoffset.set_apply_callback(apply_offset, _mem.vfo.a) + work.append(vfoaoffset) + + val1b = RadioSettingValueString(0, 10, convert_bytes_to_offset( + _mem.vfo.b.offset)) + vfoboffset = RadioSetting("vfo.b.offset", + "VFO B offset (0.000-99.999)", val1b) + vfoboffset.set_apply_callback(apply_offset, _mem.vfo.b) + work.append(vfoboffset) + + if not self.MODEL == "GMRS-50X1": + vfoatxp = RadioSetting("vfo.a.power", "VFO A power", RadioSettingValueList( LIST_TXP, - LIST_TXP[_mem.vfo.c.power])) - work.append(vfoctxp) + LIST_TXP[_mem.vfo.a.power])) + work.append(vfoatxp) - vfodtxp = RadioSetting("vfo.d.power", "VFO D power", + vfobtxp = RadioSetting("vfo.b.power", "VFO B power", RadioSettingValueList( LIST_TXP, - LIST_TXP[_mem.vfo.d.power])) - work.append(vfodtxp) - - vfoawide = RadioSetting("vfo.a.wide", "VFO A bandwidth", - RadioSettingValueList( - LIST_WIDE, - LIST_WIDE[_mem.vfo.a.wide])) - work.append(vfoawide) + LIST_TXP[_mem.vfo.b.power])) + work.append(vfobtxp) - vfobwide = RadioSetting("vfo.b.wide", "VFO B bandwidth", - RadioSettingValueList( - LIST_WIDE, - LIST_WIDE[_mem.vfo.b.wide])) - work.append(vfobwide) - - if self.COLOR_LCD: - vfocwide = RadioSetting("vfo.c.wide", "VFO C bandwidth", + if self.COLOR_LCD: + vfoctxp = RadioSetting("vfo.c.power", "VFO C power", + RadioSettingValueList( + LIST_TXP, + LIST_TXP[_mem.vfo.c.power])) + work.append(vfoctxp) + + vfodtxp = RadioSetting("vfo.d.power", "VFO D power", + RadioSettingValueList( + LIST_TXP, + LIST_TXP[_mem.vfo.d.power])) + work.append(vfodtxp) + + if not self.MODEL == "GMRS-50X1": + vfoawide = RadioSetting("vfo.a.wide", "VFO A bandwidth", RadioSettingValueList( LIST_WIDE, - LIST_WIDE[_mem.vfo.c.wide])) - work.append(vfocwide) + LIST_WIDE[_mem.vfo.a.wide])) + work.append(vfoawide) - vfodwide = RadioSetting("vfo.d.wide", "VFO D bandwidth", + vfobwide = RadioSetting("vfo.b.wide", "VFO B bandwidth", RadioSettingValueList( LIST_WIDE, - LIST_WIDE[_mem.vfo.d.wide])) - work.append(vfodwide) + LIST_WIDE[_mem.vfo.b.wide])) + work.append(vfobwide) + + if self.COLOR_LCD: + vfocwide = RadioSetting("vfo.c.wide", "VFO C bandwidth", + RadioSettingValueList( + LIST_WIDE, + LIST_WIDE[_mem.vfo.c.wide])) + work.append(vfocwide) + + vfodwide = RadioSetting("vfo.d.wide", "VFO D bandwidth", + RadioSettingValueList( + LIST_WIDE, + LIST_WIDE[_mem.vfo.d.wide])) + work.append(vfodwide) vfoastep = RadioSetting("vfo.a.step", "VFO A step", RadioSettingValueList( @@ -1871,7 +2008,7 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, work.append(vfodspmute) if not self.COLOR_LCD or \ - (self.COLOR_LCD and not self.VENDOR == "BTECH"): + (self.COLOR_LCD and not self.VENDOR == "BTECH"): vfoascr = RadioSetting("vfo.a.scramble", "VFO A scramble", RadioSettingValueBoolean( _mem.vfo.a.scramble)) @@ -1893,39 +2030,41 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, _mem.vfo.d.scramble)) work.append(vfodscr) - vfoascode = RadioSetting("vfo.a.scode", "VFO A PTT-ID", - RadioSettingValueList( - PTTIDCODE_LIST, - PTTIDCODE_LIST[_mem.vfo.a.scode])) - work.append(vfoascode) - - vfobscode = RadioSetting("vfo.b.scode", "VFO B PTT-ID", - RadioSettingValueList( - PTTIDCODE_LIST, - PTTIDCODE_LIST[_mem.vfo.b.scode])) - work.append(vfobscode) - - if self.COLOR_LCD: - vfocscode = RadioSetting("vfo.c.scode", "VFO C PTT-ID", + if not self.MODEL == "GMRS-50X1": + vfoascode = RadioSetting("vfo.a.scode", "VFO A PTT-ID", RadioSettingValueList( PTTIDCODE_LIST, - PTTIDCODE_LIST[_mem.vfo.c.scode])) - work.append(vfocscode) + PTTIDCODE_LIST[_mem.vfo.a.scode])) + work.append(vfoascode) - vfodscode = RadioSetting("vfo.d.scode", "VFO D PTT-ID", + vfobscode = RadioSetting("vfo.b.scode", "VFO B PTT-ID", RadioSettingValueList( PTTIDCODE_LIST, - PTTIDCODE_LIST[_mem.vfo.d.scode])) - work.append(vfodscode) + PTTIDCODE_LIST[_mem.vfo.b.scode])) + work.append(vfobscode) - pttid = RadioSetting("settings.pttid", "PTT ID", - RadioSettingValueList( - PTTID_LIST, - PTTID_LIST[_mem.settings.pttid])) - work.append(pttid) + if self.COLOR_LCD: + vfocscode = RadioSetting("vfo.c.scode", "VFO C PTT-ID", + RadioSettingValueList( + PTTIDCODE_LIST, + PTTIDCODE_LIST[_mem.vfo.c.scode])) + work.append(vfocscode) + + vfodscode = RadioSetting("vfo.d.scode", "VFO D PTT-ID", + RadioSettingValueList( + PTTIDCODE_LIST, + PTTIDCODE_LIST[_mem.vfo.d.scode])) + work.append(vfodscode) + + if not self.MODEL == "GMRS-50X1": + pttid = RadioSetting("settings.pttid", "PTT ID", + RadioSettingValueList( + PTTID_LIST, + PTTID_LIST[_mem.settings.pttid])) + work.append(pttid) if not self.COLOR_LCD: - #FM presets + # FM presets fm_presets = RadioSettingGroup("fm_presets", "FM Presets") top.append(fm_presets) @@ -1933,13 +2072,14 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, if value == 0: return chirp_common.format_freq(value) if not (87.5 <= value and value <= 108.0): # 87.5-108MHz - msg = ("FM-Preset-Frequency: Must be between 87.5 and 108 MHz") + msg = ("FM-Preset-Frequency: " + + "Must be between 87.5 and 108 MHz") raise InvalidValueError(msg) return value def apply_fm_preset_name(setting, obj): - valstring = str (setting.value) - for i in range(0,6): + valstring = str(setting.value) + for i in range(0, 6): if valstring[i] in VALID_CHARS: obj[i] = valstring[i] else: @@ -1950,43 +2090,43 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, for i in range(7, -1, -1): obj.freq[i] = value % 10 value /= 10 - + _presets = self._memobj.fm_radio_preset i = 1 for preset in _presets: - line = RadioSetting("fm_presets_"+ str(i), + line = RadioSetting("fm_presets_" + str(i), "Station name " + str(i), - RadioSettingValueString(0, 6, _filter( - preset.broadcast_station_name))) - line.set_apply_callback(apply_fm_preset_name, + RadioSettingValueString(0, 6, _filter( + preset.broadcast_station_name))) + line.set_apply_callback(apply_fm_preset_name, preset.broadcast_station_name) - + val = RadioSettingValueFloat(0, 108, convert_bytes_to_freq( preset.freq)) - fmfreq = RadioSetting("fm_presets_"+ str(i) + "_freq", - "Frequency "+ str(i), val) + fmfreq = RadioSetting("fm_presets_" + str(i) + "_freq", + "Frequency " + str(i), val) val.set_validate_callback(fm_validate) fmfreq.set_apply_callback(apply_fm_freq, preset) fm_presets.append(line) fm_presets.append(fmfreq) - + i = i + 1 - # DTMF-Setting - dtmf_enc_settings = RadioSettingGroup ("dtmf_enc_settings", - "DTMF Encoding Settings") - dtmf_dec_settings = RadioSettingGroup ("dtmf_dec_settings", - "DTMF Decoding Settings") + # DTMF-Setting + dtmf_enc_settings = RadioSettingGroup("dtmf_enc_settings", + "DTMF Encoding Settings") + dtmf_dec_settings = RadioSettingGroup("dtmf_dec_settings", + "DTMF Decoding Settings") top.append(dtmf_enc_settings) top.append(dtmf_dec_settings) - txdisable = RadioSetting("dtmf_settings.txdisable", + txdisable = RadioSetting("dtmf_settings.txdisable", "TX-Disable", RadioSettingValueBoolean( _mem.dtmf_settings.txdisable)) dtmf_enc_settings.append(txdisable) - rxdisable = RadioSetting("dtmf_settings.rxdisable", + rxdisable = RadioSetting("dtmf_settings.rxdisable", "RX-Disable", RadioSettingValueBoolean( _mem.dtmf_settings.rxdisable)) @@ -2017,22 +2157,22 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, return dtmf_string def apply_dmtf_frame(setting, obj): - LOG.debug("Setting DTMF-Code: " + str(setting.value) ) + LOG.debug("Setting DTMF-Code: " + str(setting.value)) val_string = str(setting.value) - for i in range(0,16): + for i in range(0, 16): obj[i] = 255 i = 0 for current_char in val_string: current_char = current_char.upper() index = LIST_DTMF_DIGITS.index(current_char) - obj[i] = LIST_DTMF_VALUES[ index ] + obj[i] = LIST_DTMF_VALUES[index] i = i + 1 codes = self._memobj.dtmf_codes i = 1 for dtmfcode in codes: - val = RadioSettingValueString(0, 16, - memory2string(dtmfcode.code), + val = RadioSettingValueString(0, 16, memory2string( + dtmfcode.code), False, CHARSET_DTMF_DIGITS) line = RadioSetting("dtmf_code_" + str(i) + "_code", "DMTF Code " + str(i), val) @@ -2040,146 +2180,138 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, dtmf_enc_settings.append(line) i = i + 1 - line = RadioSetting("dtmf_settings.mastervice", + line = RadioSetting("dtmf_settings.mastervice", "Master and Vice ID", RadioSettingValueBoolean( _mem.dtmf_settings.mastervice)) dtmf_dec_settings.append(line) - val = RadioSettingValueString(0, 16, - memory2string( + val = RadioSettingValueString(0, 16, memory2string( _mem.dtmf_settings.masterid), - False, CHARSET_DTMF_DIGITS) + False, CHARSET_DTMF_DIGITS) line = RadioSetting("dtmf_settings.masterid", "Master Control ID ", val) line.set_apply_callback(apply_dmtf_frame, _mem.dtmf_settings.masterid) dtmf_dec_settings.append(line) - line = RadioSetting("dtmf_settings.minspection", + line = RadioSetting("dtmf_settings.minspection", "Master Inspection", RadioSettingValueBoolean( _mem.dtmf_settings.minspection)) dtmf_dec_settings.append(line) - line = RadioSetting("dtmf_settings.mmonitor", + line = RadioSetting("dtmf_settings.mmonitor", "Master Monitor", RadioSettingValueBoolean( _mem.dtmf_settings.mmonitor)) dtmf_dec_settings.append(line) - line = RadioSetting("dtmf_settings.mstun", + line = RadioSetting("dtmf_settings.mstun", "Master Stun", RadioSettingValueBoolean( _mem.dtmf_settings.mstun)) dtmf_dec_settings.append(line) - line = RadioSetting("dtmf_settings.mkill", + line = RadioSetting("dtmf_settings.mkill", "Master Kill", RadioSettingValueBoolean( _mem.dtmf_settings.mkill)) dtmf_dec_settings.append(line) - line = RadioSetting("dtmf_settings.mrevive", + line = RadioSetting("dtmf_settings.mrevive", "Master Revive", RadioSettingValueBoolean( _mem.dtmf_settings.mrevive)) dtmf_dec_settings.append(line) - val = RadioSettingValueString(0, 16, - memory2string( + val = RadioSettingValueString(0, 16, memory2string( _mem.dtmf_settings.viceid), - False, CHARSET_DTMF_DIGITS) + False, CHARSET_DTMF_DIGITS) line = RadioSetting("dtmf_settings.viceid", "Vice Control ID ", val) line.set_apply_callback(apply_dmtf_frame, _mem.dtmf_settings.viceid) dtmf_dec_settings.append(line) - line = RadioSetting("dtmf_settings.vinspection", + line = RadioSetting("dtmf_settings.vinspection", "Vice Inspection", RadioSettingValueBoolean( _mem.dtmf_settings.vinspection)) dtmf_dec_settings.append(line) - line = RadioSetting("dtmf_settings.vmonitor", + line = RadioSetting("dtmf_settings.vmonitor", "Vice Monitor", RadioSettingValueBoolean( _mem.dtmf_settings.vmonitor)) dtmf_dec_settings.append(line) - line = RadioSetting("dtmf_settings.vstun", + line = RadioSetting("dtmf_settings.vstun", "Vice Stun", RadioSettingValueBoolean( _mem.dtmf_settings.vstun)) dtmf_dec_settings.append(line) - line = RadioSetting("dtmf_settings.vkill", + line = RadioSetting("dtmf_settings.vkill", "Vice Kill", RadioSettingValueBoolean( _mem.dtmf_settings.vkill)) dtmf_dec_settings.append(line) - line = RadioSetting("dtmf_settings.vrevive", + line = RadioSetting("dtmf_settings.vrevive", "Vice Revive", RadioSettingValueBoolean( _mem.dtmf_settings.vrevive)) dtmf_dec_settings.append(line) - val = RadioSettingValueString(0, 16, - memory2string( + val = RadioSettingValueString(0, 16, memory2string( _mem.dtmf_settings.inspection), - False, CHARSET_DTMF_DIGITS) + False, CHARSET_DTMF_DIGITS) line = RadioSetting("dtmf_settings.inspection", "Inspection", val) line.set_apply_callback(apply_dmtf_frame, _mem.dtmf_settings.inspection) dtmf_dec_settings.append(line) - val = RadioSettingValueString(0, 16, - memory2string( + val = RadioSettingValueString(0, 16, memory2string( _mem.dtmf_settings.alarmcode), - False, CHARSET_DTMF_DIGITS) + False, CHARSET_DTMF_DIGITS) line = RadioSetting("dtmf_settings.alarmcode", "Alarm", val) line.set_apply_callback(apply_dmtf_frame, _mem.dtmf_settings.alarmcode) dtmf_dec_settings.append(line) - val = RadioSettingValueString(0, 16, - memory2string( + val = RadioSettingValueString(0, 16, memory2string( _mem.dtmf_settings.kill), - False, CHARSET_DTMF_DIGITS) + False, CHARSET_DTMF_DIGITS) line = RadioSetting("dtmf_settings.kill", "Kill", val) line.set_apply_callback(apply_dmtf_frame, _mem.dtmf_settings.kill) dtmf_dec_settings.append(line) - val = RadioSettingValueString(0, 16, - memory2string( + val = RadioSettingValueString(0, 16, memory2string( _mem.dtmf_settings.monitor), - False, CHARSET_DTMF_DIGITS) + False, CHARSET_DTMF_DIGITS) line = RadioSetting("dtmf_settings.monitor", "Monitor", val) line.set_apply_callback(apply_dmtf_frame, _mem.dtmf_settings.monitor) dtmf_dec_settings.append(line) - val = RadioSettingValueString(0, 16, - memory2string( + val = RadioSettingValueString(0, 16, memory2string( _mem.dtmf_settings.stun), - False, CHARSET_DTMF_DIGITS) + False, CHARSET_DTMF_DIGITS) line = RadioSetting("dtmf_settings.stun", "Stun", val) line.set_apply_callback(apply_dmtf_frame, _mem.dtmf_settings.stun) dtmf_dec_settings.append(line) - val = RadioSettingValueString(0, 16, - memory2string( + val = RadioSettingValueString(0, 16, memory2string( _mem.dtmf_settings.revive), - False, CHARSET_DTMF_DIGITS) + False, CHARSET_DTMF_DIGITS) line = RadioSetting("dtmf_settings.revive", "Revive", val) line.set_apply_callback(apply_dmtf_frame, @@ -2187,7 +2319,7 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, dtmf_dec_settings.append(line) def apply_dmtf_listvalue(setting, obj): - LOG.debug("Setting value: "+ str(setting.value) + " from list") + LOG.debug("Setting value: " + str(setting.value) + " from list") val = str(setting.value) index = LIST_DTMF_SPECIAL_DIGITS.index(val) val = LIST_DTMF_SPECIAL_VALUES[index] @@ -2238,12 +2370,11 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, _mem.dtmf_settings.delayproctime])) dtmf_dec_settings.append(line) - # 5 Tone Settings - stds_5tone = RadioSettingGroup ("stds_5tone", "Standards") - codes_5tone = RadioSettingGroup ("codes_5tone", "Codes") + stds_5tone = RadioSettingGroup("stds_5tone", "Standards") + codes_5tone = RadioSettingGroup("codes_5tone", "Codes") - group_5tone = RadioSettingGroup ("group_5tone", "5 Tone Settings") + group_5tone = RadioSettingGroup("group_5tone", "5 Tone Settings") group_5tone.append(stds_5tone) group_5tone.append(codes_5tone) @@ -2251,22 +2382,22 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, def apply_list_value(setting, obj): options = setting.value.get_options() - obj.set_value ( options.index(str(setting.value)) ) + obj.set_value(options.index(str(setting.value))) _5tone_standards = self._memobj._5tone_std_settings i = 0 for standard in _5tone_standards: - std_5tone = RadioSettingGroup ("std_5tone_" + str(i), - LIST_5TONE_STANDARDS[i]) + std_5tone = RadioSettingGroup("std_5tone_" + str(i), + LIST_5TONE_STANDARDS[i]) stds_5tone.append(std_5tone) - + period = standard.period if period == 255: - LOG.debug("Period for " + LIST_5TONE_STANDARDS[i] + + LOG.debug("Period for " + LIST_5TONE_STANDARDS[i] + " is not yet configured. Setting to 70ms.") period = 5 - if period <= len( LIST_5TONE_STANDARD_PERIODS ): + if period <= len(LIST_5TONE_STANDARD_PERIODS): line = RadioSetting( "_5tone_std_settings_" + str(i) + "_period", "Period (ms)", RadioSettingValueList @@ -2283,7 +2414,7 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, " is not yet configured. Setting to A.") group_tone = 10 - if group_tone <= len( LIST_5TONE_DIGITS ): + if group_tone <= len(LIST_5TONE_DIGITS): line = RadioSetting( "_5tone_std_settings_" + str(i) + "_grouptone", "Group Tone", @@ -2298,11 +2429,11 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, repeat_tone = standard.repeat_tone if repeat_tone == 255: - LOG.debug("Repeat-Tone for " + LIST_5TONE_STANDARDS[i] + + LOG.debug("Repeat-Tone for " + LIST_5TONE_STANDARDS[i] + " is not yet configured. Setting to E.") repeat_tone = 14 - if repeat_tone <= len( LIST_5TONE_DIGITS ): + if repeat_tone <= len(LIST_5TONE_DIGITS): line = RadioSetting( "_5tone_std_settings_" + str(i) + "_repttone", "Repeat Tone", @@ -2320,18 +2451,18 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, if LIST_5TONE_STANDARDS.index(str(setting.value)) == 15: obj.set_value(0xFF) else: - obj.set_value( LIST_5TONE_STANDARDS. - index(str(setting.value)) ) + obj.set_value(LIST_5TONE_STANDARDS. + index(str(setting.value))) def apply_5tone_frame(setting, obj): - LOG.debug("Setting 5 Tone: " + str(setting.value) ) + LOG.debug("Setting 5 Tone: " + str(setting.value)) valstring = str(setting.value) if len(valstring) == 0: - for i in range(0,5): + for i in range(0, 5): obj[i] = 255 else: validFrame = True - for i in range(0,5): + for i in range(0, 5): currentChar = valstring[i].upper() if currentChar in LIST_5TONE_DIGITS: obj[i] = LIST_5TONE_DIGITS.index(currentChar) @@ -2339,12 +2470,12 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, validFrame = False LOG.debug("invalid char: " + str(currentChar)) if not validFrame: - LOG.debug("setting whole frame to FF" ) - for i in range(0,5): + LOG.debug("setting whole frame to FF") + for i in range(0, 5): obj[i] = 255 def validate_5tone_frame(value): - if (len(str(value)) != 5) and (len(str(value)) != 0) : + if (len(str(value)) != 5) and (len(str(value)) != 0): msg = ("5 Tone must have 5 digits or 0 digits") raise InvalidValueError(msg) for digit in str(value): @@ -2363,25 +2494,25 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, _5tone_codes = self._memobj._5tone_codes i = 1 for code in _5tone_codes: - code_5tone = RadioSettingGroup ("code_5tone_" + str(i), - "5 Tone code " + str(i)) + code_5tone = RadioSettingGroup("code_5tone_" + str(i), + "5 Tone code " + str(i)) codes_5tone.append(code_5tone) - if (code.standard == 255 ): + if (code.standard == 255): currentVal = 15 else: currentVal = code.standard - line = RadioSetting("_5tone_code_" + str(i) + "_std", + line = RadioSetting("_5tone_code_" + str(i) + "_std", " Standard", RadioSettingValueList(LIST_5TONE_STANDARDS, LIST_5TONE_STANDARDS[ - currentVal]) ) + currentVal])) line.set_apply_callback(my_apply_5tonestdlist_value, code.standard) code_5tone.append(line) val = RadioSettingValueString(0, 6, frame2string(code.frame1), False) - line = RadioSetting("_5tone_code_" + str(i) + "_frame1", + line = RadioSetting("_5tone_code_" + str(i) + "_frame1", " Frame 1", val) val.set_validate_callback(validate_5tone_frame) line.set_apply_callback(apply_5tone_frame, code.frame1) @@ -2449,8 +2580,8 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, decode_standard = _mem._5tone_settings.decode_standard if decode_standard == 255: decode_standard = 0 - if decode_standard <= len (LIST_5TONE_STANDARDS_without_none) : - line = RadioSetting("_5tone_settings.decode_standard", + if decode_standard <= len(LIST_5TONE_STANDARDS_without_none): + line = RadioSetting("_5tone_settings.decode_standard", "5 Tone-decode Standard", RadioSettingValueList( LIST_5TONE_STANDARDS_without_none, @@ -2459,13 +2590,13 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, group_5tone.append(line) else: LOG.debug("Invalid decode std...") - + _5tone_delay1 = _mem._5tone_settings._5tone_delay1 if _5tone_delay1 == 255: _5tone_delay1 = 20 - if _5tone_delay1 <= len( LIST_5TONE_DELAY ): - list = RadioSettingValueList(LIST_5TONE_DELAY, + if _5tone_delay1 <= len(LIST_5TONE_DELAY): + list = RadioSettingValueList(LIST_5TONE_DELAY, LIST_5TONE_DELAY[ _5tone_delay1]) line = RadioSetting("_5tone_settings._5tone_delay1", @@ -2479,7 +2610,7 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, _5tone_delay2 = 20 LOG.debug("5 Tone delay unconfigured! Resetting to 200ms.") - if _5tone_delay2 <= len( LIST_5TONE_DELAY ): + if _5tone_delay2 <= len(LIST_5TONE_DELAY): list = RadioSettingValueList(LIST_5TONE_DELAY, LIST_5TONE_DELAY[ _5tone_delay2]) @@ -2494,12 +2625,12 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, _5tone_delay3 = 20 LOG.debug("5 Tone delay unconfigured! Resetting to 200ms.") - if _5tone_delay3 <= len( LIST_5TONE_DELAY ): + if _5tone_delay3 <= len(LIST_5TONE_DELAY): list = RadioSettingValueList(LIST_5TONE_DELAY, LIST_5TONE_DELAY[ _5tone_delay3]) line = RadioSetting("_5tone_settings._5tone_delay3", - "5 Tone Delay Frame 3", list ) + "5 Tone Delay Frame 3", list) group_5tone.append(line) else: LOG.debug("Invalid value for 5tone delay (frame3)! Disabling.") @@ -2509,10 +2640,9 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, ext_length = 0 LOG.debug("1st Tone ext lenght unconfigured! Resetting to 0") - if ext_length <= len( - LIST_5TONE_DELAY ): + if ext_length <= len(LIST_5TONE_DELAY): list = RadioSettingValueList( - LIST_5TONE_DELAY, + LIST_5TONE_DELAY, LIST_5TONE_DELAY[ ext_length]) line = RadioSetting( @@ -2538,8 +2668,8 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, LOG.debug("Invalid value decode reset time! Disabling.") # 2 Tone - encode_2tone = RadioSettingGroup ("encode_2tone", "2 Tone Encode") - decode_2tone = RadioSettingGroup ("decode_2tone", "2 Code Decode") + encode_2tone = RadioSettingGroup("encode_2tone", "2 Tone Encode") + decode_2tone = RadioSettingGroup("decode_2tone", "2 Code Decode") top.append(encode_2tone) top.append(decode_2tone) @@ -2550,8 +2680,8 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, "configured. Setting to 600ms") duration_1st_tone = 60 - if duration_1st_tone <= len( LIST_5TONE_DELAY ): - line = RadioSetting("_2tone.duration_1st_tone", + if duration_1st_tone <= len(LIST_5TONE_DELAY): + line = RadioSetting("_2tone.duration_1st_tone", "Duration 1st Tone", RadioSettingValueList(LIST_5TONE_DELAY, LIST_5TONE_DELAY[ @@ -2564,8 +2694,8 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, "configured. Setting to 600ms") duration_2nd_tone = 60 - if duration_2nd_tone <= len( LIST_5TONE_DELAY ): - line = RadioSetting("_2tone.duration_2nd_tone", + if duration_2nd_tone <= len(LIST_5TONE_DELAY): + line = RadioSetting("_2tone.duration_2nd_tone", "Duration 2nd Tone", RadioSettingValueList(LIST_5TONE_DELAY, LIST_5TONE_DELAY[ @@ -2578,7 +2708,7 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, "configured. Setting to 300ms") duration_gap = 30 - if duration_gap <= len( LIST_5TONE_DELAY ): + if duration_gap <= len(LIST_5TONE_DELAY): line = RadioSetting("_2tone.duration_gap", "Duration of gap", RadioSettingValueList(LIST_5TONE_DELAY, LIST_5TONE_DELAY[ @@ -2603,8 +2733,8 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, obj.set_value(val) i = 1 - for code in self._memobj._2tone._2tone_encode: - code_2tone = RadioSettingGroup ("code_2tone_" + str(i), + for code in self._memobj._2tone._2tone_encode: + code_2tone = RadioSettingGroup("code_2tone_" + str(i), "Encode Code " + str(i)) encode_2tone.append(code_2tone) @@ -2612,7 +2742,7 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, if tmp == 65535: tmp = 0 val1 = RadioSettingValueInteger(0, 65535, tmp) - freq1 = RadioSetting("2tone_code_"+ str(i) + "_freq1", + freq1 = RadioSetting("2tone_code_" + str(i) + "_freq1", "Frequency 1", val1) val1.set_validate_callback(_2tone_validate) freq1.set_apply_callback(apply_2tone_freq, code.freq1) @@ -2622,7 +2752,7 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, if tmp == 65535: tmp = 0 val2 = RadioSettingValueInteger(0, 65535, tmp) - freq2 = RadioSetting("2tone_code_"+ str(i) + "_freq2", + freq2 = RadioSetting("2tone_code_" + str(i) + "_freq2", "Frequency 2", val2) val2.set_validate_callback(_2tone_validate) freq2.set_apply_callback(apply_2tone_freq, code.freq2) @@ -2657,27 +2787,27 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, else: derived_val = int(round(2304000.0/val)) - obj[frqname].set_value( val ) - obj[derivedname].set_value( derived_val ) + obj[frqname].set_value(val) + obj[derivedname].set_value(derived_val) - LOG.debug("Apply " + frqname + ": " + str(val) + " | " - + derivedname + ": " + str(derived_val)) + LOG.debug("Apply " + frqname + ": " + str(val) + " | " + + derivedname + ": " + str(derived_val)) i = 1 - for decode_code in self._memobj._2tone._2tone_decode: - _2tone_dec_code = RadioSettingGroup ("code_2tone_" + str(i), - "Decode Code " + str(i)) + for decode_code in self._memobj._2tone._2tone_decode: + _2tone_dec_code = RadioSettingGroup("code_2tone_" + str(i), + "Decode Code " + str(i)) decode_2tone.append(_2tone_dec_code) j = 1 for dec in decode_code.decs: val = dec.dec if val == 255: - LOG.debug("Dec for Code " + str(i) + " Dec " + str(j) + + LOG.debug("Dec for Code " + str(i) + " Dec " + str(j) + " is not yet configured. Setting to 0.") val = 0 - if val <= len( LIST_2TONE_DEC ): + if val <= len(LIST_2TONE_DEC): line = RadioSetting( "_2tone_dec_settings_" + str(i) + "_dec_" + str(j), "Dec " + str(j), RadioSettingValueList @@ -2690,11 +2820,11 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, val = dec.response if val == 255: - LOG.debug("Response for Code " + str(i) + " Dec " + str(j)+ - " is not yet configured. Setting to 0.") + LOG.debug("Response for Code " + str(i) + " Dec " + + str(j) + " is not yet configured. Setting to 0.") val = 0 - if val <= len( LIST_2TONE_RESPONSE ): + if val <= len(LIST_2TONE_RESPONSE): line = RadioSetting( "_2tone_dec_settings_" + str(i) + "_resp_" + str(j), "Response " + str(j), RadioSettingValueList @@ -2707,11 +2837,11 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, val = dec.alert if val == 255: - LOG.debug("Alert for Code " + str(i) + " Dec " + str(j) + + LOG.debug("Alert for Code " + str(i) + " Dec " + str(j) + " is not yet configured. Setting to 0.") val = 0 - if val <= len( PTTIDCODE_LIST ): + if val <= len(PTTIDCODE_LIST): line = RadioSetting( "_2tone_dec_settings_" + str(i) + "_alert_" + str(j), "Alert " + str(j), RadioSettingValueList @@ -2734,13 +2864,13 @@ class BTechMobileCommon(chirp_common.CloneModeRadio, expected = int(round(2304000.0/tmp)) from_mem = freq["derived_from_" + setting_name] if expected != from_mem: - LOG.error("Expected " + str(expected) + - " but read " + str(from_mem ) + + LOG.error("Expected " + str(expected) + + " but read " + str(from_mem) + ". Disabling 2Tone Decode Freqs!") break val = RadioSettingValueInteger(0, 65535, tmp) - frq = RadioSetting("2tone_dec_"+ str(i) + "_freq" + str(char), - ("Decode Frequency " +str(char)), val) + frq = RadioSetting("2tone_dec_" + str(i) + "_freq" + str(char), + ("Decode Frequency " + str(char)), val) val.set_validate_callback(_2tone_validate) frq.set_apply_callback(apply_2tone_freq_pair, freq) _2tone_dec_code.append(frq) @@ -3181,7 +3311,7 @@ class UV2501_220(BTech): MODEL = "UV-2501+220" BANDS = 3 _magic = MSTRING_220 - _id2 = UV2501_220pp_id + _id2 = [UV2501_220pp_id, ] _fileid = [UV2501_220G3_fp, UV2501_220G2_fp, UV2501_220_fp, @@ -3226,6 +3356,8 @@ class KTUV980(BTech): # Please note that there is a version of this radios that is a clone of the # Waccom Mini8900, maybe an early version? + + @directory.register class KT9800(BTech): """QYT KT8900""" @@ -3240,7 +3372,7 @@ class KT9800(BTech): KT8900_fp3, KT8900_fp4, KT8900_fp5] - _id2 = KT8900_id + _id2 = [KT8900_id, ] # Clones ALIASES = [JT6188Mini, SSGT890, ZastoneMP300] @@ -3260,7 +3392,7 @@ class KT9800R(BTech): KT8900R_fp2, KT8900R_fp3, KT8900R_fp4] - _id2 = KT8900R_id + _id2 = [KT8900R_id, KT8900R_id2] @directory.register @@ -3305,44 +3437,44 @@ struct { #seekto 0x0E00; struct { u8 tmr; - u8 unknown1; - u8 sql; - u8 unknown2[2]; - u8 tot; - u8 apo; - u8 unknown3; - u8 abr; - u8 beep; - u8 unknown4[4]; - u8 dtmfst; - u8 unknown5[2]; - u8 screv; + u8 unknown1; + u8 sql; + u8 unknown2[2]; + u8 tot; + u8 apo; + u8 unknown3; + u8 abr; + u8 beep; + u8 unknown4[4]; + u8 dtmfst; + u8 unknown5[2]; + u8 screv; u8 unknown6[2]; u8 pttid; u8 pttlt; u8 unknown7; - u8 emctp; - u8 emcch; - u8 sigbp; + u8 emctp; + u8 emcch; + u8 sigbp; u8 unknown8; - u8 camdf; - u8 cbmdf; - u8 ccmdf; - u8 cdmdf; + u8 camdf; + u8 cbmdf; + u8 ccmdf; + u8 cdmdf; u8 langua; u8 sync; // BTech radios use this as the display sync // setting, other radios use this as the auto // keypad lock setting u8 mainfc; - u8 mainbc; - u8 menufc; - u8 menubc; - u8 stafc; - u8 stabc; - u8 sigfc; - u8 sigbc; - u8 rxfc; - u8 txfc; + u8 mainbc; + u8 menufc; + u8 menubc; + u8 stafc; + u8 stabc; + u8 sigfc; + u8 sigbc; + u8 rxfc; + u8 txfc; u8 txdisp; u8 unknown9[5]; u8 anil; @@ -3370,17 +3502,17 @@ struct { reseten:1, menuen:1; u8 unknown5[11]; - u8 dispab; - u8 unknown6[2]; - u8 menu; - u8 unknown7[7]; - u8 vfomra; - u8 vfomrb; - u8 vfomrc; - u8 vfomrd; - u8 mrcha; - u8 mrchb; - u8 mrchc; + u8 dispab; + u8 unknown6[2]; + u8 menu; + u8 unknown7[7]; + u8 vfomra; + u8 vfomrb; + u8 vfomrc; + u8 vfomrd; + u8 mrcha; + u8 mrchb; + u8 mrchc; u8 mrchd; } settings2; @@ -3580,6 +3712,7 @@ class BTechColor(BTechMobileCommon): """BTECH's Color LCD Mobile and alike radios""" COLOR_LCD = True NAME_LENGTH = 8 + LIST_TMR = LIST_TMR16 def process_mmap(self): """Process the mem map into the mem object""" @@ -3621,7 +3754,7 @@ class BTechColor(BTechMobileCommon): # set the class with the real data self._vhf_range = vhf self._uhf_range = uhf - + # Declaring Aliases (Clones of the real radios) class SKT8900D(chirp_common.Alias): @@ -3678,6 +3811,7 @@ class KT7900D(BTechColor): VENDOR = "QYT" MODEL = "KT7900D" BANDS = 4 + LIST_TMR = LIST_TMR15 _vhf_range = (136000000, 175000000) _220_range = (200000000, 271000000) _uhf_range = (400000000, 481000000) @@ -3694,7 +3828,364 @@ class KT8900D(BTechColor): VENDOR = "QYT" MODEL = "KT8900D" BANDS = 2 + LIST_TMR = LIST_TMR15 _vhf_range = (136000000, 175000000) _uhf_range = (400000000, 481000000) _magic = MSTRING_KT8900D _fileid = [KT8900D_fp, KT8900D_fp1] + + +GMRS_MEM_FORMAT = """ +#seekto 0x0000; +struct { + lbcd rxfreq[4]; + lbcd txfreq[4]; + ul16 rxtone; + ul16 txtone; + u8 unknown0:4, + scode:4; + u8 unknown1:2, + spmute:1, + unknown2:3, + optsig:2; + u8 unknown3:3, + scramble:1, + unknown4:2, + power:2; + u8 unknown5:1, + wide:1, + unknown6:2, + bcl:1, + add:1, + pttid:2; +} memory[256]; + +#seekto 0x1000; +struct { + char name[7]; + u8 unknown1[9]; +} names[256]; + +#seekto 0x2400; +struct { + u8 period; // one out of LIST_5TONE_STANDARD_PERIODS + u8 group_tone; + u8 repeat_tone; + u8 unused[13]; +} _5tone_std_settings[15]; + +#seekto 0x2500; +struct { + u8 frame1[5]; + u8 frame2[5]; + u8 frame3[5]; + u8 standard; // one out of LIST_5TONE_STANDARDS +} _5tone_codes[15]; + +#seekto 0x25F0; +struct { + u8 _5tone_delay1; // * 10ms + u8 _5tone_delay2; // * 10ms + u8 _5tone_delay3; // * 10ms + u8 _5tone_first_digit_ext_length; + u8 unknown1; + u8 unknown2; + u8 unknown3; + u8 unknown4; + u8 decode_standard; + u8 unknown5:5, + _5tone_decode_call_frame3:1, + _5tone_decode_call_frame2:1, + _5tone_decode_call_frame1:1; + u8 unknown6:5, + _5tone_decode_disp_frame3:1, + _5tone_decode_disp_frame2:1, + _5tone_decode_disp_frame1:1; + u8 decode_reset_time; // * 100 + 100ms +} _5tone_settings; + +#seekto 0x2900; +struct { + u8 code[16]; // 0=x0A, A=0x0D, B=0x0E, C=0x0F, D=0x00, #=0x0C *=0x0B +} dtmf_codes[15]; + +#seekto 0x29F0; +struct { + u8 dtmfspeed_on; //list with 50..2000ms in steps of 10 + u8 dtmfspeed_off; //list with 50..2000ms in steps of 10 + u8 unknown0[14]; + u8 inspection[16]; + u8 monitor[16]; + u8 alarmcode[16]; + u8 stun[16]; + u8 kill[16]; + u8 revive[16]; + u8 unknown1[16]; + u8 unknown2[16]; + u8 unknown3[16]; + u8 unknown4[16]; + u8 unknown5[16]; + u8 unknown6[16]; + u8 unknown7[16]; + u8 masterid[16]; + u8 viceid[16]; + u8 unused01:7, + mastervice:1; + u8 unused02:3, + mrevive:1, + mkill:1, + mstun:1, + mmonitor:1, + minspection:1; + u8 unused03:3, + vrevive:1, + vkill:1, + vstun:1, + vmonitor:1, + vinspection:1; + u8 unused04:6, + txdisable:1, + rxdisable:1; + u8 groupcode; + u8 spacecode; + u8 delayproctime; // * 100 + 100ms + u8 resettime; // * 100 + 100ms +} dtmf_settings; + +#seekto 0x2D00; +struct { + struct { + ul16 freq1; + u8 unused01[6]; + ul16 freq2; + u8 unused02[6]; + } _2tone_encode[15]; + u8 duration_1st_tone; // *10ms + u8 duration_2nd_tone; // *10ms + u8 duration_gap; // *10ms + u8 unused03[13]; + struct { + struct { + u8 dec; // one out of LIST_2TONE_DEC + u8 response; // one out of LIST_2TONE_RESPONSE + u8 alert; // 1-16 + } decs[4]; + u8 unused04[4]; + } _2tone_decode[15]; + u8 unused05[16]; + + struct { + ul16 freqA; + ul16 freqB; + ul16 freqC; + ul16 freqD; + // unknown what those values mean, but they are + // derived from configured frequencies + ul16 derived_from_freqA; // 2304000/freqA + ul16 derived_from_freqB; // 2304000/freqB + ul16 derived_from_freqC; // 2304000/freqC + ul16 derived_from_freqD; // 2304000/freqD + }freqs[15]; + u8 reset_time; // * 100 + 100ms - 100-8000ms +} _2tone; + +#seekto 0x3000; +struct { + u8 freq[8]; + char broadcast_station_name[6]; + u8 unknown[2]; +} fm_radio_preset[16]; + +#seekto 0x3200; +struct { + u8 tmr; + u8 unknown1; + u8 sql; + u8 unknown2; + u8 autolk; + u8 tot; + u8 apo; + u8 unknown3; + u8 abr; + u8 beep; + u8 unknown4[4]; + u8 dtmfst; + u8 unknown5[2]; + u8 screv; + u8 unknown6[2]; + u8 pttid; + u8 pttlt; + u8 unknown7; + u8 emctp; + u8 emcch; + u8 sigbp; + u8 unknown8; + u8 camdf; + u8 cbmdf; + u8 ccmdf; + u8 cdmdf; + u8 langua; + u8 sync; + + + u8 stfc; + u8 mffc; + u8 sfafc; + u8 sfbfc; + u8 sfcfc; + u8 sfdfc; + u8 subfc; + u8 fmfc; + u8 sigfc; + u8 modfc; + u8 menufc; + u8 txfc; + u8 txdisp; + u8 unknown9[5]; + u8 anil; + u8 reps; + u8 repm; + u8 tmrmr; + u8 ste; + u8 rpste; + u8 rptdl; + u8 dtmfg; + u8 mgain; + u8 skiptx; + u8 scmode; +} settings; + +#seekto 0x3280; +struct { + u8 unknown1; + u8 vfomr; + u8 keylock; + u8 unknown2; + u8 unknown3:4, + vfomren:1, + unknown4:1, + reseten:1, + menuen:1; + u8 unknown5[11]; + u8 dispab; + u8 unknown6[2]; + u8 smenu; + u8 unknown7[7]; + u8 vfomra; + u8 vfomrb; + u8 vfomrc; + u8 vfomrd; + u8 mrcha; + u8 mrchb; + u8 mrchc; + u8 mrchd; +} settings2; + +struct settings_vfo { + u8 freq[8]; + u8 offset[6]; + u8 unknown2[2]; + ul16 rxtone; + ul16 txtone; + u8 scode; + u8 spmute; + u8 optsig; + u8 scramble; + u8 wide; + u8 power; + u8 shiftd; + u8 step; + u8 unknown3[4]; +}; + +#seekto 0x3300; +struct { + struct settings_vfo a; + struct settings_vfo b; + struct settings_vfo c; + struct settings_vfo d; +} vfo; + +#seekto 0x3D80; +struct { + u8 vhf_low[3]; + u8 vhf_high[3]; + u8 unknown1[4]; + u8 unknown2[6]; + u8 vhf2_low[3]; + u8 vhf2_high[3]; + u8 unknown3[4]; + u8 unknown4[6]; + u8 uhf_low[3]; + u8 uhf_high[3]; + u8 unknown5[4]; + u8 unknown6[6]; + u8 uhf2_low[3]; + u8 uhf2_high[3]; +} ranges; + +#seekto 0x33B0; +struct { + char line[16]; +} static_msg; + +#seekto 0x3F70; +struct { + char fp[6]; +} fingerprint; + +""" + + +class BTechGMRS(BTechMobileCommon): + """BTECH's GMRS Mobile""" + COLOR_LCD = True + COLOR_LCD2 = True + NAME_LENGTH = 7 + UPLOAD_MEM_SIZE = 0X3400 + + def process_mmap(self): + """Process the mem map into the mem object""" + + # Get it + self._memobj = bitwise.parse(GMRS_MEM_FORMAT, self._mmap) + + # load specific parameters from the radio image + self.set_options() + + def set_options(self): + """This is to read the options from the image and set it in the + environment, for now just the limits of the freqs in the VHF/UHF + ranges""" + + # setting the correct ranges for each radio type + ranges = self._memobj.ranges + + # the normal dual bands + vhf = _decode_ranges(ranges.vhf_low, ranges.vhf_high) + uhf = _decode_ranges(ranges.uhf_low, ranges.uhf_high) + + # DEBUG + LOG.info("Radio ranges: VHF %d to %d" % vhf) + LOG.info("Radio ranges: UHF %d to %d" % uhf) + + # set the class with the real data + self._vhf_range = vhf + self._uhf_range = uhf + + +# real radios +@directory.register +class GMRS50X1(BTechGMRS): + """Baofeng Tech GMRS50X1""" + MODEL = "GMRS-50X1" + BANDS = 2 + LIST_TMR = LIST_TMR16 + _power_levels = [chirp_common.PowerLevel("High", watts=50), + chirp_common.PowerLevel("Mid", watts=10), + chirp_common.PowerLevel("Low", watts=5)] + _vhf_range = (136000000, 175000000) + _uhf_range = (400000000, 521000000) + _upper = 255 + _magic = MSTRING_GMRS50X1 + _fileid = [GMRS50X1_fp1, GMRS50X1_fp, ] diff --git a/chirp/drivers/ft4.py b/chirp/drivers/ft4.py new file mode 100644 index 0000000..26b550c --- /dev/null +++ b/chirp/drivers/ft4.py @@ -0,0 +1,1181 @@ +# Copyright 2019 Dan Clemmensen <DanClemmensen@Gmail.com> +# Derives loosely from two sources released under GPLv2: +# ./template.py, Copyright 2012 Dan Smith <dsmith@danplanet.com> +# ./ft60.py, Copyright 2011 Dan Smith <dsmith@danplanet.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/>. + +""" +CHIRP driver for Yaesu radios that use the SCU-35 cable. This includes at +least the FT-4, FT-25, FT-35, and FT-65. This driver will not work with +older Yaesu models. +""" +import logging +import struct +import copy +from chirp import chirp_common, directory, memmap, bitwise, errors, util +from chirp.settings import RadioSetting, RadioSettingGroup, \ + RadioSettingValueList, RadioSettingValueString, RadioSettings + +LOG = logging.getLogger(__name__) + + +# Layout of Radio memory image. +# This module and the serial protocol treat the FT-4 memory as 16-byte blocks. +# There in nothing magic about 16-byte blocks, but it simplifies the +# description. There are 17 groups of blocks, each with a different purpose +# and format. Five groups consist of channel memories, or "mems" in CHIRP. +# A "mem" describes a radio channel, and all "mems" have the same internal +# format. Three of the groups consist of bitmaps, which all have the same +# internal mapping. also groups for Name, misc, DTMF digits, and prog, +# plus some unused groups. The MEM_FORMAT describes the radio image memory. +# MEM_FORMAT is parsed in module ../bitwise.py. Syntax is similar but not +# identical to C data and structure definitions. + +# Define the structures for each type of group here, but do not associate them +# with actual memory addresses yet +MEM_FORMAT = """ +struct slot { + u8 tx_pwr; //0, 1, 2 == lo, medium, high + bbcd freq[4]; // Hz/10 but must end in 00 + u8 tx_ctcss; //see ctcss table, but radio code = CHIRP code+1. 0==off + u8 rx_ctcss; //see ctcss table, but radio code = CHIRP code+1. 0==off + u8 tx_dcs; //see dcs table, but radio code = CHIRP code+1. 0==off + u8 rx_dcs; //see dcs table, but radio code = CHIRP code+1. 0==off + u8 duplex; //(auto,offset). (0,2,4,5)= (+,-,0, auto) + ul16 offset; //little-endian binary * scaler, +- per duplex + //scaler is 25 kHz for FT-4, 50 kHz for FT-65. + u8 tx_width; //0=wide, 1=narrow + u8 step; //STEPS (0-9)=(auto,5,6.25,10,12.5,15,20,25,50,100) kHz + u8 sql_type; //(0-6)==(off,r-tone,t-tone,tsql,rev tn,dcs,pager) + u8 unused; +}; +// one bit per channel. 220 bits (200 mem+ 2*10 PMS) padded to fill +//exactly 2 blocks +struct bitmap { +u8 b8[28]; +u8 unused[4]; +}; +//name struct occupies half a block (8 bytes) +//the code restricts the actual len to 6 for an FT-4 +struct name { + u8 chrs[8]; //[0-9,A-z,a-z, -] padded with spaces +}; +//txfreq struct occupies 4 bytes (1/4 slot) +struct txfreq { + bbcd freq[4]; +}; + +//miscellaneous params. One 4-block group. +//"SMI": "Set Mode Index" of the FT-4 radio keypad function to set parameter. +//"SMI numbers on the FT-65 are different but the names in mem are the same. +struct misc { + u8 apo; //SMI 01. 0==off, (1-24) is the number of half-hours. + u8 arts_beep; //SMI 02. 0==off, 1==inrange, 2==always + u8 arts_intv; //SMI 03. 0==25 seconds, 1==15 seconds + u8 battsave; //SMI 32. 0==off, (1-5)==(200,300,500,1000,2000) ms + u8 bclo; //SMI 04. 0==off, 1==on + u8 beep; //SMI 05. (0-2)==(key+scan,key, off) + u8 bell; //SMI 06. (0-5)==(0,1,3,5,8,continuous) bells + u8 cw_id[6]; //SMI 08. callsign (A_Z,0-9) (pad with space if <6) + u8 unknown1[3]; + // addr= 2010 + u8 dtmf_mode; //SMI 12. 0==manual, 1==auto + u8 dtmf_delay; //SMI 11. (0-4)==(50,250,450,750,1000) ms + u8 dtmf_speed; //SMI 13. (0,1)=(50,100) ms + u8 edg_beep; //SMI 14. 0==off, 1==on + u8 key_lock; //SMI 18. (0-2)==(key,ptt,key+ptt) + u8 lamp; //SMI 15. (0-4)==(5,10,30,continuous,off) secKEY + u8 tx_led; //SMI 17. 0==off, 1==on + u8 bsy_led; //SMI 16. 0==off, 1==on + u8 moni_tcall; //SMI 19. (0-4)==(mon,1750,2100,1000,1450) tcall Hz. + u8 pri_rvt; //SMI 23. 0==off, 1==on + u8 scan_resume; //SMI 34. (0-2)==(busy,hold,time) + u8 rf_squelch; //SMI 28. 0==off, 8==full, (1-7)==(S1-S7) + u8 scan_lamp; //SMI 33 0==off,1==on + u8 unknown2; + u8 use_cwid; //SMI 7. 0==no, 1==yes + u8 compander; // compander on FT_65 + // addr 2020 + u8 unknown3; + u8 tx_save; //SMI 41. 0==off, 1==on (addr==2021) + u8 vfo_spl; //SMI 42. 0==off, 1==on + u8 vox; //SMI 43. 0==off, 1==on + u8 wfm_rcv; //SMI 44. 0==off, 1==on + u8 unknown4; + u8 wx_alert; //SMI 46. 0==off, 1==0n + u8 tot; //SMI 39. 0-off, (1-30)== (1-30) minutes + u8 pager_tx1; //SMI 21. (0-49)=(1-50) epcs code (i.e., value is code-1) + u8 pager_tx2; //SMI 21 same + u8 pager_rx1; //SMI 23 same + u8 pager_rx2; //SMI 23 same + u8 pager_ack; //SMI 22 same + u8 unknown5[3]; //possibly sql_setting and pgm_vfo_scan on FT-65? + // addr 2030 + u8 use_passwd; //SMI 26 0==no, 1==yes + u8 passwd[4]; //SMI 27 ASCII (0-9) + u8 unused2[11]; // pad out to a block boundary +}; + +struct dtmfset { + u8 digit[16]; //ASCII (*,#,-,0-9,A-D). (dash-filled) +}; + +// area to be filled with 0xff, or just ignored +struct notused { + u8 unused[16]; +}; +// areas we are still analyzing +struct unknown { + u8 notknown[16]; +}; + +struct progc { + u8 usage; //P key is (0-2) == unused, use P channel, use parm + u8 submode:2, //if parm!=0 submode 0-3 of mode + parm:6; //if usage == 2: if 0, use m-channel, else mode +}; +""" +# Actual memory layout. 0x215 blocks, in 20 groups. +MEM_FORMAT += """ +#seekto 0x0000; +struct unknown radiotype; //0000 probably a radio type ID but not sure +struct slot memory[200]; //0010 channel memory array +struct slot pms[20]; //0c90 10 PMS (L,U) slot pairs +struct slot vfo[5]; //0dd0 VFO (A UHF, A VHF, B FM, B UHF, B VHF) +struct slot home[3]; //0e20 Home (FM, VHF, UHF) +struct bitmap enable; //0e50 +struct bitmap scan; //0e70 +struct notused notused0; //0e90 +struct bitmap bankmask[10]; //0ea0 +struct notused notused1[2]; //0fe0 +struct name names[220]; //1000 220 names in 110 blocks +struct notused notused2[2]; //16e0 +struct txfreq txfreqs[220]; //1700 220 freqs in 55 blocks +struct notused notused3[89]; //1a20 +struct misc settings; //2000 4-block collection of misc params +struct notused notused4[2]; //2040 +struct dtmfset dtmf[9]; //2060 sets 1-9 +struct notused notused5; //20f0 +//struct progs progkeys; //2100 not a struct. bitwise.py refuses +struct progc progctl[4]; //2100 8 bytes. 1 2-byte struct per P key +u8 pmemndx[4]; //2108 4 bytes, 1 per P key +u8 notused6[4]; //210c fill out the block +struct slot prog[4]; //2110 P key "channel" array +//---------------- end of FT-4 mem? +""" +# The remaining mem is (apparently) not available on the FT4 but is +# reported to be available on the FT-65. Not implemented here yet. +# Possibly, memory-mapped control registers that allow for "live-mode" +# operation instead of "clone-mode" operation. +# 2150 27ff (unused?) +# 2800 285f 6 MRU operation? +# 2860 2fff (unused?) +# 3000 310f 17 (version info, etc?) +# ----------END of memory map + + +# Begin Serial transfer utilities for the SCU-35 cable. + +# The serial transfer protocol was implemented here after snooping the wire. +# After it was implemented, we noticed that it is identical to the protocol +# implemented in th9000.py. A non-echo version is implemented in anytone_ht.py. +# +# The pipe.read and pipe.write functions use bytes, not strings. The serial +# transfer utilities operate only to move data between the memory object and +# the serial port. The code runs on either Python 2 or Python3, so some +# constructs could be better optimized for one or the other, but not both. + + +def get_mmap_data(radio): + """ + horrible kludge needed until we convert entirely to Python 3 OR we add a + slightly less horrible kludge to the Py2 or Py3 versions of memmap.py. + The minimal change have Py3 code return a bytestring instead of a string. + This is the only function in this module that must explicitly test for the + data string type. It is used only in the do_upload function. + returns the memobj data as a byte-like object. + """ + data = radio.get_mmap().get_packed() + if isinstance(data, bytes): + return data + return bytearray(radio.get_mmap()._data) + + +def checkSum8(data): + """ + Calculate the 8 bit checksum of buffer + Input: buffer - bytes + returns: integer + """ + return sum(x for x in bytearray(data)) & 0xFF + + +def variable_len_resp(pipe): + """ + when length of expected reply is not known, read byte at a time + until the ack character is found. + """ + response = b"" + i = 0 + toolong = 256 # arbitrary + while True: + b = pipe.read(1) + if b == b'\x06': + break + else: + response += b + i += 1 + if i > toolong: + LOG.debug("Response too long. got" + util.hexprint(response)) + raise errors.RadioError("Response from radio too long.") + return(response) + + +def sendcmd(pipe, cmd, response_len): + """ + send a command bytelist to radio,receive and return the resulting bytelist. + Input: pipe - serial port object to use + cmd - bytes to send + response_len - number of bytes of expected response, + not including the ACK. (if None, read until ack) + This cable is "two-wire": The TxD and RxD are "or'ed" so we receive + whatever we send and then whatever response the radio sends. We check the + echo and strip it, returning only the radio's response. + We also check and strip the ACK character at the end of the response. + """ + pipe.write(cmd) + echo = pipe.read(len(cmd)) + if echo != cmd: + msg = "Bad echo. Sent:" + util.hexprint(cmd) + ", " + msg += "Received:" + util.hexprint(echo) + LOG.debug(msg) + raise errors.RadioError("Incorrect echo on serial port. Bad cable?") + if response_len is None: + return variable_len_resp(pipe) + if response_len > 0: + response = pipe.read(response_len) + else: + response = b"" + ack = pipe.read(1) + if ack != b'\x06': + LOG.debug("missing ack: expected 0x06, got" + util.hexprint(ack)) + raise errors.RadioError("Incorrect ACK on serial port.") + return response + + +def enter_clonemode(radio): + """ + Send the PROGRAM command and check the response. Retry if + needed. After 3 tries, send an "END" and try some more if + it is acknowledged. + """ + for use_end in range(0, 3): + for i in range(0, 3): + try: + if b"QX" == sendcmd(radio.pipe, b"PROGRAM", 2): + return + except: + continue + sendcmd(radio.pipe, b"END", 0) + raise errors.RadioError("expected QX from radio.") + + +def startcomms(radio, way): + """ + For either upload or download, put the radio into PROGRAM mode + and check the radio's ID. In this preliminary version of the driver, + the exact nature of the ID has been inferred from a single test case. + set up the progress bar + send "PROGRAM" to command the radio into clone mode + read the initial string (version?) + """ + progressbar = chirp_common.Status() + progressbar.msg = "Cloning " + way + " radio" + progressbar.max = radio.numblocks + enter_clonemode(radio) + id_response = sendcmd(radio.pipe, b'\x02', None) + if id_response != radio.id_str: + substr0 = radio.id_str[:radio.id_str.find('\x00')] + if id_response[:id_response.find('\x00')] != substr0: + msg = "ID mismatch. Expected" + util.hexprint(radio.id_str) + msg += ", Received:" + util.hexprint(id_response) + LOG.warning(msg) + raise errors.RadioError("Incorrect ID read from radio.") + else: + msg = "ID suspect. Expected" + util.hexprint(radio.id_str) + msg += ", Received:" + util.hexprint(id_response) + LOG.warning(msg) + return progressbar + + +def getblock(pipe, addr, image): + """ + read a single 16-byte block from the radio. + send the command and check the response + places the response into the correct offset in the supplied bytearray + returns True if successful, False if error. + """ + cmd = struct.pack(">cHb", b"R", addr, 16) + response = sendcmd(pipe, cmd, 21) + if (response[0] != b"W"[0]) or (response[1:4] != cmd[1:4]): + msg = "Bad response. Sent:" + util.hexprint(cmd) + ", " + msg += b"Received:" + util.hexprint(response) + LOG.debug(msg) + return False + if checkSum8(response[1:20]) != bytearray(response)[20]: + LOG.debug(b"Bad checksum: " + util.hexprint(response)) + return False + image[addr:addr+16] = response[4:20] + return True + + +def do_download(radio): + """ + Read memory from the radio. + call startcomms to go into program mode and check version + create an mmap + read the memory blocks and place the data into the mmap + send "END" + """ + image = bytearray(radio.get_memsize()) + pipe = radio.pipe # Get the serial port connection + progressbar = startcomms(radio, "from") + for blocknum in range(radio.numblocks): + for i in range(0, 3): + if getblock(pipe, 16 * blocknum, image): + break + if i == 2: + raise errors.RadioError( + "read block from radio failed 3 times") + progressbar.cur = blocknum + radio.status_fn(progressbar) + sendcmd(pipe, b"END", 0) + return memmap.MemoryMap(bytes(image)) + + +def putblock(pipe, addr, data): + """ + write a single 16-byte block to the radio + send the command and check the response + """ + chkstr = struct.pack(">Hb", addr, 16) + data + msg = b'W' + chkstr + struct.pack('B', checkSum8(chkstr)) + b'\x06' + sendcmd(pipe, msg, 0) + + +def do_upload(radio): + """ + Write memory image to radio + call startcomms to go into program mode and check version + write the memory blocks. Skip the first block + send "END" + """ + pipe = radio.pipe # Get the serial port connection + progressbar = startcomms(radio, "to") + data = get_mmap_data(radio) + for _i in range(1, radio.numblocks): + putblock(pipe, 16*_i, data[16*_i:16*(_i+1)]) + progressbar.cur = _i + radio.status_fn(progressbar) + sendcmd(pipe, b"END", 0) + return +# End serial transfer utilities + + +def bit_loc(bitnum): + """ + return the ndx and mask for a bit location + """ + return (bitnum // 8, 1 << (bitnum & 7)) + + +def store_bit(bankmem, bitnum, val): + """ + store a bit in a bankmem. Store 0 or 1 for False or True + """ + ndx, mask = bit_loc(bitnum) + if val: + bankmem.b8[ndx] |= mask + else: + bankmem.b8[ndx] &= ~mask + return + + +def retrieve_bit(bankmem, bitnum): + """ + return True or False for a bit in a bankmem + """ + ndx, mask = bit_loc(bitnum) + return (bankmem.b8[ndx] & mask) != 0 + + +# A bank is a bitmap of 220 bits. 200 mem slots and 2*10 PMS slots. +# There are 10 banks. +class YaesuSC35GenericBankModel(chirp_common.BankModel): + + def get_num_mappings(self): + return 10 + + def get_mappings(self): + banks = [] + for i in range(1, 1 + self.get_num_mappings()): + bank = chirp_common.Bank(self, "%i" % i, "Bank %i" % i) + bank.index = i - 1 + banks.append(bank) + return banks + + def add_memory_to_mapping(self, memory, bank): + bankmem = self._radio._memobj.bankmask[bank.index] + store_bit(bankmem, memory.number-1, True) + + def remove_memory_from_mapping(self, memory, bank): + bankmem = self._radio._memobj.bankmask[bank.index] + if not retrieve_bit(bankmem, memory.number-1): + raise Exception("Memory %i is not in bank %s." % + (memory.number, bank)) + store_bit(bankmem, memory.number-1, False) + + # return a list of slots in a bank + def get_mapping_memories(self, bank): + memories = [] + for i in range(*self._radio.get_features().memory_bounds): + if retrieve_bit(self._radio._memobj.bankmask[bank.index], i - 1): + memories.append(self._radio.get_memory(i)) + return memories + + # return a list of banks a slot is a member of + def get_memory_mappings(self, memory): + memndx = memory.number - 1 + banks = [] + for bank in self.get_mappings(): + if retrieve_bit(self._radio._memobj.bankmask[bank.index], memndx): + banks.append(bank) + return banks + +# the values in these lists must also be in the canonical UI list +# we can re-arrange the order, and we don't need to have all +# the values, but we cannot add our own values here. +DUPLEX = ["+", "", "-", "", "off", "", "split"] # (0,2,4,5)= (+,-,0, auto) +# the radio implements duplex "auto" as 5. we map to "" It appears to be +# a convienience function in the radio that affects the offset, but I do not +# understand it. + +SKIPS = ["", "S"] + +BASETYPE_FT4 = ["FT-4XR", "FT-4XE"] +BASETYPE_FT65 = ["FT-65R"] +POWER_LEVELS = [chirp_common.PowerLevel("Low", watts=0.5), + chirp_common.PowerLevel("Mid", watts=2.5), + chirp_common.PowerLevel("High", watts=5.0)] + +# these steps encode to 0-9 on all radios, but encoding #2 is disallowed +# on the US versions (FT-4XR) +STEP_CODE = [0, 5.0, 6.25, 10.0, 12.5, 15.0, 20.0, 25.0, 50.0, 100.0] +US_LEGAL_STEPS = list(STEP_CODE) # copy to pass to UI on US radios +US_LEGAL_STEPS.remove(6.25) # euro radios just use STEP_CODE + +# Map the radio image sql_type (0-6) to the CHIRP mem values. +# Yaesu "TSQL" and "DCS" each map to different CHIRP values depending on the +# radio values of the tx and rx tone codes. The table is a list of rows, one +# per Yaesu sql_type (0-5). The code does not use this table when the sql_type +# is 6 (PAGER). Each row is a tuple. Its first member is a list of +# [tmode,cross] or [tmode, cross, suppress]. "Suppress" is used only when +# encoding UI-->radio. When decoding radio-->UI, two of the sql_types each +# result in 5 possibible UI decodings depending on the tx and rx codes, and the +# list in each of these rows has five members. These two row tuples each have +# two additional members to specify which of the radio fields to examine. +# The map from CHIRP UI to radio image types is also built from this table. +RADIO_TMODES = [ + ([["", None], ], ), # sql_type= 0. off + ([["Cross", "->Tone"], ], ), # sql_type= 1. R-TONE + ([["Tone", None], ], ), # sql_type= 2. T-TONE + ([ # sql_type= 3. TSQL: + ["", None], # tx==0, rx==0 : invalid + ["TSQL", None], # tx==0 + ["Tone", None], # rx==0 + ["Cross", "Tone->Tone"], # tx!=rx + ["TSQL", None] # tx==rx + ], "tx_ctcss", "rx_ctcss"), # tx and rx fields to check + ([["TSQL-R", None], ], ), # sql_type= 4. REV TN + ([ # sql_type= 5.DCS: + ["", None], # tx==0, rx==0 : invalid + ["Cross", "->DTCS", "tx_dcs"], # tx==0. suppress tx + ["Cross", "DTCS->", "rx_dcs"], # rx==0. suppress rx + ["Cross", "DTCS->DTCS"], # tx!=rx + ["DTCS", None] # tx==rx + ], "tx_dcs", "rx_dcs"), # tx and rx fields to check + # # sql_type= 6. PAGER is a CHIRP "extra" + ] + +# Find all legal values for the tmode and cross fields for the UI. +# We build two dictionaries to do the lookups when encoding. +# The reversed range is a kludge: by happenstance, earlier duplicates +# in the above table are the preferred mapping, they override the +# later ones when we process the table backwards. +TONE_DICT = {} # encode sql_type. +CROSS_DICT = {} # encode sql_type. + +for sql_type in reversed(range(0, len(RADIO_TMODES))): + sql_type_row = RADIO_TMODES[sql_type] + for decode_row in sql_type_row[0]: + suppress = None + if len(decode_row) == 3: + suppress = decode_row[2] + TONE_DICT[decode_row[0]] = (sql_type, suppress) + if decode_row[1]: + CROSS_DICT[decode_row[1]] = (sql_type, suppress) + +# The keys are added to the "VALID" lists using code that puts those lists +# in the same order as the UI's default order instead of the random dict +# order or the arbitrary build order. +VALID_TONE_MODES = [] # list for UI. +VALID_CROSS_MODES = [] # list for UI. +for name in chirp_common.TONE_MODES: + if name in TONE_DICT: + VALID_TONE_MODES += [name] +for name in chirp_common.CROSS_MODES: + if name in CROSS_DICT: + VALID_CROSS_MODES += [name] + + +DTMF_CHARS = "0123456789ABCD*#- " +CW_ID_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ " +PASSWD_CHARS = "0123456789" +CHARSET = CW_ID_CHARS + "abcdefghijklmnopqrstuvwxyz*+-/@" +PMSNAMES = ["%s%02d" % (c, i) for i in range(1, 11) for c in ('L', 'U')] + +# Four separate arrays of special channel mems. +# Each special has unique constrants: band, name yes/no, and pms L/U +# The FT-65 class replaces the "prog" entry in this list. +# The name field must be the name of a slot array in MEM_FORMAT +SPECIALS = [ + ("pms", PMSNAMES), + ("vfo", ["VFO A UHF", "VFO A VHF", "VFO B FM", "VFO B VHF", "VFO B UHF"]), + ("home", ["HOME FM", "HOME VHF", "HOME UHF"]), + ("prog", ["P1", "P2"]) + ] +BAND_ASSIGNMENTS = [2, 1, 0, 1, 2, 0, 1, 2] # bands for the vfos and homes +FT65_PROGS = ("prog", ["P1", "P2", "P3", "P4"]) +FT65_SPECIALS = list(SPECIALS) # a shallow copy works here +FT65_SPECIALS[-1] = FT65_PROGS # replace the last entry (P key names) + + +# None, and 50 Tones. Use this explicit array because the +# one in chirp_common could change and no longer describe our radio +TONE_MAP = [ + None, 67.0, 69.3, 71.9, 74.4, 77.0, 79.7, 82.5, + 85.4, 88.5, 91.5, 94.8, 97.4, 100.0, 103.5, + 107.2, 110.9, 114.8, 118.8, 123.0, 127.3, + 131.8, 136.5, 141.3, 146.2, 151.4, 156.7, + 159.8, 162.2, 165.5, 167.9, 171.3, 173.8, + 177.3, 179.9, 183.5, 186.2, 189.9, 192.8, + 196.6, 199.5, 203.5, 206.5, 210.7, 218.1, + 225.7, 229.1, 233.6, 241.8, 250.3, 254.1 + ] + +# None, and 104 DTCS Codes. Use this explicit array because the +# one in chirp_common could change and no longer describe our radio +DTCS_MAP = [ + None, 23, 25, 26, 31, 32, 36, 43, 47, 51, 53, 54, + 65, 71, 72, 73, 74, 114, 115, 116, 122, 125, 131, + 132, 134, 143, 145, 152, 155, 156, 162, 165, 172, 174, + 205, 212, 223, 225, 226, 243, 244, 245, 246, 251, 252, + 255, 261, 263, 265, 266, 271, 274, 306, 311, 315, 325, + 331, 332, 343, 346, 351, 356, 364, 365, 371, 411, 412, + 413, 423, 431, 432, 445, 446, 452, 454, 455, 462, 464, + 465, 466, 503, 506, 516, 523, 526, 532, 546, 565, 606, + 612, 624, 627, 631, 632, 654, 662, 664, 703, 712, 723, + 731, 732, 734, 743, 754 + ] + +# The legal PAGER codes are the same as the CTCSS codes, but we +# pass them to the UI as a list of strings +EPCS_CODES = [format(flt) for flt in [0] + TONE_MAP[1:]] + + +# allow a child class to add a param to its class +# description list. used when a specific radio class has +# a param that is not in the generic list. +def add_paramdesc(desc_list, group, param): + for description in desc_list: + groupname, title, parms = description + if group == groupname: + description[2].append(param) + return + + +class YaesuSC35GenericRadio(chirp_common.CloneModeRadio, + chirp_common.ExperimentalRadio): + """ + Base class for all Yaesu radios using the SCU-35 programming cable + and its protocol. Classes for specific radios extend this class and + are found at the end of this file. + """ + VENDOR = "Yaesu" + MODEL = "SCU-35Generic" # No radio directly uses the base class + BAUD_RATE = 9600 + MAX_MEM_SLOT = 200 + NEEDS_COMPAT_SERIAL = False + + @classmethod + def get_prompts(cls): + rp = chirp_common.RadioPrompts() + rp.experimental = ( + 'Tested only by the developer and only on a single radio.\n' + 'Proceed at your own risk!' + ) + + rp.pre_download = "".join([ + "1. Connect programming cable to MIC jack.\n", + "2. Press OK." + ] + ) + rp.pre_upload = rp.pre_download + return rp + + # identify the features that can be manipulated on this radio. + # mentioned here only when different from defaults in chirp_common.py + def get_features(self): + + rf = chirp_common.RadioFeatures() + specials = [name for s in self.class_specials for name in s[1]] + rf.valid_special_chans = specials + rf.memory_bounds = (1, self.MAX_MEM_SLOT) + rf.valid_duplexes = DUPLEX + rf.valid_tmodes = VALID_TONE_MODES + rf.valid_cross_modes = VALID_CROSS_MODES + rf.valid_power_levels = POWER_LEVELS + rf.valid_tuning_steps = self.legal_steps + rf.valid_skips = SKIPS + rf.valid_characters = CHARSET + rf.valid_name_length = self.namelen + rf.valid_modes = ["FM", "NFM"] + rf.valid_bands = self.valid_bands + rf.can_odd_split = True + rf.has_ctone = True + rf.has_rx_dtcs = True + rf.has_dtcs_polarity = False # REV TN reverses the tone, not the dcs + rf.has_cross = True + rf.has_settings = True + + return rf + + def get_bank_model(self): + return YaesuSC35GenericBankModel(self) + + # read and parse the radio memory + def sync_in(self): + try: + self._mmap = do_download(self) + except Exception as e: + raise errors.RadioError("Failed to communicate with radio: %s" % e) + self.process_mmap() + + # write the memory image to the radio + def sync_out(self): + try: + do_upload(self) + except Exception as e: + raise errors.RadioError("Failed to communicate with radio: %s" % e) + + def process_mmap(self): + self._memobj = bitwise.parse(MEM_FORMAT, self._mmap) + + # There are about 40 settings and most are handled generically in + # get_settings. get_settings invokes these handlers for the few + # that are more complicated. + + # callback for setting byte arrays: DTMF[0-9], passwd, and CW_ID + def apply_str_to_bytearray(self, element, obj): + lng = len(obj) + strng = (element.value.get_value() + " ")[:lng] + bytes = bytearray(strng, "ascii") + for x in range(0, lng): # memobj cannot iterate, so byte-by-byte + obj[x] = bytes[x] + return + + # add a string value to the RadioSettings + def get_string_setting(self, obj, valid_chars, desc1, desc2, group): + content = '' + maxlen = len(obj) + for x in range(0, maxlen): + content += chr(obj[x]) + val = RadioSettingValueString(0, maxlen, content, True, valid_chars) + rs = RadioSetting(desc1, desc2, val) + rs.set_apply_callback(self.apply_str_to_bytearray, obj) + group.append(rs) + + # called when found in the group_descriptions table to handle string value + def get_strset(self, group, parm): + # parm =(paramname, paramtitle,(handler,[handler params])). + objname, title, fparms = parm + myparms = fparms[1] + obj = getattr(self._memobj.settings, objname) + self.get_string_setting(obj, myparms[0], objname, title, group) + + # called when found in the group_descriptions table for DTMF strings + def get_dtmfs(self, group, parm): + objname, title, fparms = parm + for i in range(1, 10): + dtmf_digits = self._memobj.dtmf[i - 1].digit + self.get_string_setting( + dtmf_digits, DTMF_CHARS, + "dtmf_%i" % i, "DTMF Autodialer Memory %i" % i, group) + + def apply_P(self, element, pnum, memobj): + memobj.progctl[pnum].usage = element.value + + def apply_Pmode(self, element, pnum, memobj): + memobj.progctl[pnum].parm = element.value + + def apply_Psubmode(self, element, pnum, memobj): + memobj.progctl[pnum].submode = element.value + + def apply_Pmem(self, element, pnum, memobj): + memobj.pmemndx[pnum] = element.value + + MEMLIST = ["%d" % i for i in range(1, MAX_MEM_SLOT + 1)] + PMSNAMES + USAGE_LIST = ["unused", "P channel", "mode or M channel"] + + # called when found in the group_descriptions table + # returns the settings for the programmable keys (P1-P4) + def get_progs(self, group, parm): + _progctl = self._memobj.progctl + _progndx = self._memobj.pmemndx + + def get_prog(i, val_list, valndx, sname, longname, f_apply): + k = str(i + 1) + val = val_list[valndx] + valuelist = RadioSettingValueList(val_list, val) + rs = RadioSetting(sname + k, longname + k, valuelist) + rs.set_apply_callback(f_apply, i, self._memobj) + group.append(rs) + for i in range(0, self.Pkeys): + get_prog(i, self.USAGE_LIST, _progctl[i].usage, + "P", "Programmable key ", self.apply_P) + get_prog(i, self.SETMODES, _progctl[i].parm, "modeP", + "mode for Programmable key ", self.apply_Pmode) + get_prog(i, ["0", "1", "2", "3"], _progctl[i].submode, "submodeP", + "submode for Programmable key ", self.apply_Psubmode) + get_prog(i, self.MEMLIST, _progndx[i], "memP", + "mem for Programmable key ", self.apply_Pmem) + # ------------ End of special settings handlers. + + # list of group description tuples: [groupame,group title, [param list]]. + # A param is a tuple: + # for a simple param: (paramname, paramtitle,[valuename list]) + # for a handler param: (paramname, paramtitle,( handler,[handler params])) + # This is a class variable. subclasses msut create a variable named + # class_group_descs. The FT-4 classes simply equate this, but the + # FT-65 classes must copy and modify this. + group_descriptions = [ + ("misc", "Miscellaneous Settings", [ # misc + ("apo", "Automatic Power Off", + ["OFF"] + ["%0.1f" % (x * 0.5) for x in range(1, 24 + 1)]), + ("bclo", "Busy Channel Lock-Out", ["OFF", "ON"]), + ("beep", "Enable the Beeper", ["OFF", "KEY", "KEY+SC"]), + ("bsy_led", "Busy LED", ["ON", "OFF"]), + ("edg_beep", "Band Edge Beeper", ["OFF", "ON"]), + ("vox", "VOX", ["OFF", "ON"]), + ("rf_squelch", "RF Squelch Threshold", + ["OFF", "S-1", "S-2", "S-3", "S-4", "S-5", "S-6", "S-7", "S-FULL"]), + ("tot", "Timeout Timer", + ["OFF"] + ["%dMIN" % (x) for x in range(1, 30 + 1)]), + ("tx_led", "TX LED", ["OFF", "ON"]), + ("use_cwid", "use CW ID", ["NO", "YES"]), + ("cw_id", "CW ID Callsign", (get_strset, [CW_ID_CHARS])), # handler + ("vfo_spl", "VFO Split", ["OFF", "ON"]), + ("wfm_rcv", "Enable Broadband FM", ["ON", "OFF"]), + ("passwd", "Password", (get_strset, [PASSWD_CHARS])) # handler + ]), + ("arts", "ARTS Settings", [ # arts + ("arts_beep", "ARTS BEEP", ["OFF", "INRANG", "ALWAYS"]), + ("arts_intv", "ARTS Polling Interval", ["25 SEC", "15 SEC"]) + ]), + ("ctcss", "CTCSS/DCS/DTMF Settings", [ # ctcss + ("bell", "Bell Repetitions", ["OFF", "1T", "3T", "5T", "8T", "CONT"]), + ("dtmf_mode", "DTMF Mode", ["Manual", "Auto"]), + ("dtmf_delay", "DTMF Autodialer Delay Time", + ["50 MS", "100 MS", "250 MS", "450 MS", "750 MS", "1000 MS"]), + ("dtmf_speed", "DTMF Autodialer Sending Speed", ["50 MS", "100 MS"]), + ("dtmf", "DTMF Autodialer Memory ", (get_dtmfs, [])) # handler + ]), + ("switch", "Switch/Knob Settings", [ # switch + ("lamp", "Lamp Mode", ["5SEC", "10SEC", "30SEC", "KEY", "OFF"]), + ("moni_tcall", "MONI Switch Function", + ["MONI", "1750", "2100", "1000", "1450"]), + ("key_lock", "Lock Function", ["KEY", "PTT", "KEY+PTT"]), + ("Pkeys", "Pkey fields", (get_progs, [])) + ]), + ("scan", "Scan Settings", [ # scan + ("scan_resume", "Scan Resume Mode", ["BUSY", "HOLD", "TIME"]), + ("pri_rvt", "Priority Revert", ["OFF", "ON"]), + ("scan_lamp", "Scan Lamp", ["OFF", "ON"]), + ("wx_alert", "Weather Alert Scan", ["OFF", "ON"]) + ]), + ("power", "Power Saver Settings", [ # power + ("battsave", "Receive Mode Battery Save Interval", + ["OFF", "200 MS", "300 MS", "500 MS", "1 S", "2 S"]), + ("tx_save", "Transmitter Battery Saver", ["OFF", "ON"]) + ]), + ("eai", "EAI/EPCS Settings", [ # eai + ("pager_tx1", "TX pager frequency 1", EPCS_CODES), + ("pager_tx2", "TX pager frequency 2", EPCS_CODES), + ("pager_rx1", "RX pager frequency 1", EPCS_CODES), + ("pager_rx2", "RX pager frequency 2", EPCS_CODES), + ("pager_ack", "Pager answerback", ["NO", "YES"]) + ]) + ] + # ----------------end of group_descriptions + + # returns the current values of all the settings in the radio memory image, + # in the form of a RadioSettings list. Uses the class_group_descs + # list to create the groups and params. Valuelist scalars are handled + # inline. More complex params are built by calling the special handlers. + def get_settings(self): + _settings = self._memobj.settings + groups = RadioSettings() + for description in self.class_group_descs: + groupname, title, parms = description + group = RadioSettingGroup(groupname, title) + groups.append(group) + for parm in parms: + param, title, opts = parm + try: + if isinstance(opts, list): + # setting is a single value from the list + objval = getattr(_settings, param) + value = opts[objval] + valuelist = RadioSettingValueList(opts, value) + group.append(RadioSetting(param, title, valuelist)) + else: + # setting needs special handling. opts[0] is a + # function name + opts[0](self, group, parm) + except Exception as e: + LOG.debug( + "%s: cannot set %s to %s" % (e, param, repr(objval)) + ) + return groups + # end of get_settings + + # modify settings values in the radio memory image + def set_settings(self, uisettings): + _settings = self._memobj.settings + for element in uisettings: + if not isinstance(element, RadioSetting): + self.set_settings(element) + continue + if not element.changed(): + continue + + try: + name = element.get_name() + value = element.value + + if element.has_apply_callback(): + LOG.debug("Using apply callback") + element.run_apply_callback() + else: + setattr(_settings, name, value) + + LOG.debug("Setting %s: %s" % (name, value)) + except: + LOG.debug(element.get_name()) + raise + + # maps a boolean pair (tx==0,rx==0) to the numbers 0-3 + LOOKUP = [[True, True], [True, False], [False, True], [False, False]] + + def decode_sql(self, mem, chan): + """ + examine the radio channel fields and determine the correct + CHIRP CSV values for tmode, cross_mode, and sql_override + """ + mem.extra = RadioSettingGroup("Extra", "extra") + extra_modes = ["(None)", "PAGER"] + value = extra_modes[chan.sql_type == 6] + valuelist = RadioSettingValueList(extra_modes, value) + rs = RadioSetting("sql_override", "Squelch override", valuelist) + mem.extra.append(rs) + if chan.sql_type == 6: + return + sql_map = RADIO_TMODES[chan.sql_type] + ndx = 0 + if len(sql_map[0]) > 1: + # the sql_type is TSQL or DCS, so there are multiple UI mappings + x = getattr(chan, sql_map[1]) + r = getattr(chan, sql_map[2]) + ndx = self.LOOKUP.index([x == 0, r == 0]) + if ndx == 3 and x == r: + ndx = 4 + mem.tmode = sql_map[0][ndx][0] + cross = sql_map[0][ndx][1] + if cross: + mem.cross_mode = cross + if chan.rx_ctcss: + mem.ctone = TONE_MAP[chan.rx_ctcss] + if chan.tx_ctcss: + mem.rtone = TONE_MAP[chan.tx_ctcss] + if chan.tx_dcs: + mem.dtcs = DTCS_MAP[chan.tx_dcs] + if chan.rx_dcs: + mem.rx_dtcs = DTCS_MAP[chan.rx_dcs] + + def encode_sql(self, mem, chan): + """ + examine CHIRP's mem.tmode and mem.cross_mode and set the values + for the radio sql_type, dcs codes, and ctcss codes. We set all four + codes, and then zero out a code if needed when Tone or DCS is one-way + """ + chan.tx_ctcss = TONE_MAP.index(mem.rtone) + chan.tx_dcs = DTCS_MAP.index(mem.dtcs) + chan.rx_ctcss = TONE_MAP.index(mem.ctone) + chan.rx_dcs = DTCS_MAP.index(mem.rx_dtcs) + if mem.tmode == "TSQL": + chan.tx_ctcss = chan.rx_ctcss # CHIRP uses ctone for TSQL + if mem.tmode == "DTCS": + chan.tx_dcs = chan.rx_dcs # CHIRP uses rx_dtcs for DTCS + # select the correct internal dictionary and key + mode_dict, key = [ + (TONE_DICT, mem.tmode), + (CROSS_DICT, mem.cross_mode) + ][mem.tmode == "Cross"] + # now look up that key in that dictionary. + chan.sql_type, suppress = mode_dict[key] + if suppress: + setattr(chan, suppress, 0) + for setting in mem.extra: + if (setting.get_name() == 'sql_override'): + value = str(setting.value) + if value == "PAGER": + chan.sql_type = 6 + return + + # given a CHIRP memory ref, get the radio memobj for it. + # A memref is either a number or the name of a special + # CHIRP will sometimes use numbers (>MAX_SLOTS) for specials + # returns the obj and several attributes + def slotloc(self, memref): + array = None + num = memref + sname = memref + if isinstance(memref, str): # named special? + num = self.MAX_MEM_SLOT + 1 + for x in self.class_specials: + try: + ndx = x[1].index(memref) + array = x[0] + break + except: + num += len(x[1]) + if array is None: + LOG.debug("unknown Special %s", memref) + raise + num += ndx + elif memref > self.MAX_MEM_SLOT: # numbered special? + ndx = memref - (self.MAX_MEM_SLOT + 1) + for x in self.class_specials: + if ndx < len(x[1]): + array = x[0] + sname = x[1][ndx] + break + ndx -= len(x[1]) + if array is None: + LOG.debug("memref number %d out of range", memref) + raise + else: # regular memory slot + array = "memory" + ndx = memref - 1 + memloc = getattr(self._memobj, array)[ndx] + return (memloc, ndx, num, array, sname) + # end of slotloc + + # return the raw info for a memory channel + def get_raw_memory(self, memref): + memloc, ndx, num, regtype, sname = self.slotloc(memref) + if regtype == "memory": + return repr(memloc) + else: + return repr(memloc) + repr(self._memobj.names[ndx]) + + # return the info for a memory channel In CHIRP canonical form + def get_memory(self, memref): + + def clean_name(obj): # helper func to tidy up the name + name = '' + for x in range(0, self.namelen): + y = obj[x] + if y == 0: + break + name += chr(y) + return name.rstrip() + + mem = chirp_common.Memory() + _mem, ndx, num, regtype, sname = self.slotloc(memref) + mem.number = num + mem.freq = int(_mem.freq) * 10 + mem.offset = int(_mem.offset) * self.freq_offset_scale + mem.duplex = DUPLEX[_mem.duplex] + + self.decode_sql(mem, _mem) + mem.power = POWER_LEVELS[_mem.tx_pwr] + mem.mode = ["FM", "NFM"][_mem.tx_width] + mem.tuning_step = STEP_CODE[_mem.step] + + if regtype == "pms": + mem.extd_number = sname + if regtype in ["memory", "pms"]: + ndx = num - 1 + mem.name = clean_name(self._memobj.names[ndx].chrs) + mem.empty = not retrieve_bit(self._memobj.enable, ndx) + mem.skip = SKIPS[retrieve_bit(self._memobj.scan, ndx)] + txfreq = int(self._memobj.txfreqs[ndx].freq) * 10 + if (txfreq != 0) and (txfreq != mem.freq): + mem.duplex = "split" + mem.offset = txfreq + else: + mem.empty = False + mem.extd_number = sname + mem.immutable = ["number", "extd_number", "name", "skip"] + + return mem + + def enforce_band(self, memloc, freq, mem_num, sname): + """ + vfo and home channels are each restricted to a particular band. + If the frequency is not in the band, use the lower bound + Raise an exception to cause UI to pop up an error message + """ + first_vfo_num = self.MAX_MEM_SLOT + len(PMSNAMES) + 1 + band = BAND_ASSIGNMENTS[mem_num - first_vfo_num] + frange = self.valid_bands[band] + if freq >= frange[0] and freq <= frange[1]: + memloc.freq = freq / 10 + return freq + memloc.freq = frange[0] / 10 + raise Exception("freq out of range for %s" % sname) + + # modify a radio channel in memobj based on info in CHIRP canonical form + def set_memory(self, mem): + _mem, ndx, num, regtype, sname = self.slotloc(mem.number) + assert(_mem) + if mem.empty: + if regtype in ["memory", "pms"]: + store_bit(self._memobj.enable, ndx, False) + return + + txfreq = mem.freq / 10 # really. RX freq is used for TX base + _mem.freq = txfreq + self.encode_sql(mem, _mem) + if mem.power: + _mem.tx_pwr = POWER_LEVELS.index(mem.power) + _mem.tx_width = mem.mode == "NFM" + _mem.step = STEP_CODE.index(mem.tuning_step) + + _mem.offset = mem.offset / self.freq_offset_scale + duplex = mem.duplex + if regtype in ["memory", "pms"]: + ndx = num - 1 + store_bit(self._memobj.enable, ndx, True) + store_bit(self._memobj.scan, ndx, SKIPS.index(mem.skip)) + nametrim = (mem.name + " ")[:8] + self._memobj.names[ndx].chrs = bytearray(nametrim, "ascii") + if mem.duplex == "split": + txfreq = mem.offset / 10 + duplex = "off" # radio ignores when tx != rx + self._memobj.txfreqs[num-1].freq = txfreq + _mem.duplex = DUPLEX.index(duplex) + if regtype in ["vfo", "home"]: + self.enforce_band(_mem, mem.freq, num, sname) + + return + + +@directory.register +class YaesuFT4Radio(YaesuSC35GenericRadio): + MODEL = "FT-4XR" + _basetype = BASETYPE_FT4 + valid_bands = [ + (65000000, 108000000), # broadcast FM, receive only + (144000000, 148000000), # VHF, US version, TX and RX + (430000000, 450000000) # UHF, US version, TX and RX + # VHF, RX (136000000, 174000000) + # UHF, RX (400000000, 480000000) + ] + _valid_chars = chirp_common.CHARSET_ASCII + numblocks = 0x215 # number of 16-byte blocks in the radio + _memsize = 16 * numblocks # used by CHIRP file loader to guess radio type + MAX_MEM_SLOT = 200 + Pkeys = 2 # number of programmable keys on the FT-4 + namelen = 6 # length of the mem name display on the FT-4 front-panel + id_str = b'IFT-35R\x00\x00V100\x00\x00' + freq_offset_scale = 25000 + legal_steps = US_LEGAL_STEPS + class_group_descs = YaesuSC35GenericRadio.group_descriptions + class_specials = SPECIALS + # names for the setmode function for the programmable keys. Mode zero means + # that the key is programmed for a memory not a setmode. + SETMODES = [ + "mem", "apo", "ar bep", "ar int", "beclo", # 00-04 + "beep", "bell", "cw id", "cw wrt", "dc vlt", # 05-09 + "dcs cod", "dt dly", "dt set", "dtc spd", "edg.bep", # 10-14 + "lamp", "led.bsy", "led.tx", "lock", "m/t-cl", # 15-19 + "mem.del", "mem.tag", "pag.abk", "pag.cdr", "pag.cdt", # 20-24 + "pri.rvt", "pswd", "pswdwt", "rf sql", "rpt.ars", # 25-29 + "rpt.frq", "rpt.sft", "rxsave", "scn.lmp", "scn.rsm", # 30-34 + "skip", "sql.typ", "step", "tn frq", "tot", # 35-39 + "tx pwr", "tx save", "vfo.spl", "vox", "wfm.rcv", # 40-44 + "w/n.dev", "wx.alert" # 45-46 + ] + + +@directory.register +class YaesuFT65Radio(YaesuSC35GenericRadio): + MODEL = "FT-65R" + _basetype = BASETYPE_FT65 + valid_bands = [ + (65000000, 108000000), # broadcast FM, receive only + (144000000, 148000000), # VHF, US version, TX and RX + (430000000, 450000000) # UHF, US version, TX and RX + # VHF, RX (136000000, 174000000) + # UHF, RX (400000000, 480000000) + ] + _valid_chars = chirp_common.CHARSET_ASCII + numblocks = 0x215 # number of 16-byte blocks in the radio + _memsize = 16 * numblocks # used by CHIRP file loader to guess radio type + MAX_MEM_SLOT = 200 + Pkeys = 4 # number of programmable keys on the FT-65 + namelen = 8 # length of the mem name display on the FT-65 front panel + id_str = b'IH-420\x00\x00\x00V100\x00\x00' + freq_offset_scale = 50000 + legal_steps = US_LEGAL_STEPS + # we need a deep copy here because we are adding deeper than the top level. + class_group_descs = copy.deepcopy(YaesuSC35GenericRadio.group_descriptions) + add_paramdesc( + class_group_descs, "misc", ("compander", "Compander", ["OFF", "ON"])) + class_specials = FT65_SPECIALS + # names for the setmode function for the programmable keys. Mode zero means + # that the key is programmed for a memory not a setmode. + SETMODES = [ + "mem", "apo", "arts", "battsave", "b-ch.l/o", # 00-04 + "beep", "bell", "compander", "ctcss", "cw id", # 05-09 + "dc volt", "dcs code", "dtmf set", "dtmf wrt", "edg bep", # 10-14 + "key lock", "lamp", "ledbsy", "mem del", "mon/t-cl", # 15-19 + "name tag", "pager", "password", "pri.rvt", "repeater", # 20-24 + "resume", "rf.sql", "scn.lamp", "skip", "sql type", # 25-29 + "step", "tot", "tx pwr", "tx save", "vfo.spl", # 30-34 + "vox", "wfm.rcv", "wide/nar", "wx alert", "scramble" # 35-39 + ] diff --git a/chirp/drivers/ft50.py b/chirp/drivers/ft50.py index 5840c02..9f28110 100644 --- a/chirp/drivers/ft50.py +++ b/chirp/drivers/ft50.py @@ -281,7 +281,6 @@ class FT50Radio(yaesu_clone.YaesuCloneModeRadio): if mem.empty: _flg.used = False - self._wipe_memory_banks(mem) return if (len(mem.name) == 0): diff --git a/chirp/drivers/ft7100.py b/chirp/drivers/ft7100.py index aef5d6a..ca51367 100644 --- a/chirp/drivers/ft7100.py +++ b/chirp/drivers/ft7100.py @@ -19,7 +19,6 @@ import time import logging -import copy from chirp import util, memmap, chirp_common, bitwise, directory, errors from chirp.drivers.yaesu_clone import YaesuCloneModeRadio @@ -35,73 +34,74 @@ ACK = "\x06" NB_OF_BLOCKS = 248 BLOCK_LEN = 32 + def _send(pipe, data): time.sleep(0.035) # Same delay as "FT7100 Programmer" from RT Systems - #pipe.write(data) --> It seems, that the single bytes are sent too fast + # pipe.write(data) --> It seems, that the single bytes are sent too fast + # so send character per character with a delay for ch in data: pipe.write(ch) - time.sleep(0.0012) # Ok - #time.sleep(0.0011) Too short. No ACK after a few packets + time.sleep(0.0012) # 0.0011 is to short. No ACK after a few packets echo = pipe.read(len(data)) if data == "": - raise Exception("Failed to read echo. Maybe serial hardware not connected." + raise Exception("Failed to read echo." + " Maybe serial hardware not connected." " Maybe radio not powered or not in receiving mode.") if data != echo: LOG.debug("expecting echo\n%s\n", util.hexprint(data)) LOG.debug("got echo\n%s\n", util.hexprint(echo)) raise Exception("Got false echo. Expected: '{}', got: '{}'." - .format(data, echo)) + .format(data, echo)) + def _send_ack(pipe): - time.sleep(0.01) # Wait for radio input buffer ready - #time.sleep(0.0003) Absolute working minimum + time.sleep(0.01) # Wait for radio input buffer ready + # time.sleep(0.0003) is the absolute working minimum. + # This delay is not critical for the transfer as there are not many ACKs. _send(pipe, ACK) + def _wait_for_ack(pipe): echo = pipe.read(1) if echo == "": raise Exception("Failed to read ACK. No response from radio.") if echo != ACK: raise Exception("Failed to read ACK. Expected: '{}', got: '{}'." - .format(util.hexprint(ACK), util.hexprint(echo))) + .format(util.hexprint(ACK), util.hexprint(echo))) + def _download(radio): LOG.debug("in _download\n") - -# import ipdb; ipdb.set_trace() - data = "" for _i in range(0, 60): data = radio.pipe.read(BLOCK_LEN) LOG.debug("Header:\n%s", util.hexprint(data)) LOG.debug("len(header) = %s\n", len(data)) - if data == radio.IDBLOCK: break - if data == "": raise Exception("Got no data from radio.") if data != radio.IDBLOCK: raise Exception("Got false header. Expected: '{}', got: '{}'." - .format(radio.IDBLOCK, data)) - + .format(radio.IDBLOCK, data)) _send_ack(radio.pipe) # read 16 Byte block + # and ignore it because it is constant. This might be a bug. + # It was built in at the very beginning and discovered very late that the + # data might be necessary later to write to the radio. + # Now the data is hardcoded in _upload(radio) data = radio.pipe.read(16) - #LOG.debug("16 Byte bloc:\n%s", util.hexprint(data)) - #LOG.debug("len(data) = %s\n", len(data)) _send_ack(radio.pipe) # initialize data, the big var that holds all memory data = "" - for block_nr in range(NB_OF_BLOCKS): chunk = radio.pipe.read(BLOCK_LEN) - #LOG.debug("Block %i ", (block_nr)) - #LOG.debug("Got: %i:\n%s", (len(chunk), util.hexprint(chunk))) if len(chunk) != BLOCK_LEN: - LOG.debug("len chunk is %i\n", (len(chunk))) + LOG.debug("Block %i ", block_nr) + LOG.debug("Got: %i:\n%s", len(chunk), util.hexprint(chunk)) + LOG.debug("len chunk is %i\n", len(chunk)) raise Exception("Failed to get full data block") else: data += chunk @@ -127,23 +127,20 @@ def _download(radio): def _upload(radio): - -# import ipdb; ipdb.set_trace() - - data = radio.pipe.read(256) # Clear buffer + data = radio.pipe.read(256) # Clear buffer _send(radio.pipe, radio.IDBLOCK) _wait_for_ack(radio.pipe) # write 16 Byte block + # If there should be a problem, see remarks in _download(radio) _send(radio.pipe, "\xCC\x77\x01\x00\x0C\x07\x0C\x07" "\x00\x00\x00\x00\x00\x00\x00\x00") _wait_for_ack(radio.pipe) for block_nr in range(NB_OF_BLOCKS): - data = radio.get_mmap()[block_nr * BLOCK_LEN:(block_nr + 1) * BLOCK_LEN] - + data = radio.get_mmap()[block_nr * BLOCK_LEN: + (block_nr + 1) * BLOCK_LEN] LOG.debug("Writing block_nr %i:\n%s", block_nr, util.hexprint(data)) - _send(radio.pipe, data) _wait_for_ack(radio.pipe) @@ -503,11 +500,12 @@ MODES_UHF = ["FM"] # AM can be set but is ignored by the radio DUPLEX = ["", "-", "+", "split"] TONE_MODES_RADIO = ["", "Tone", "TSQL", "CTCSS Bell", "DTCS"] TONE_MODES = ["", "Tone", "TSQL", "DTCS"] -POWER_LEVELS = [chirp_common.PowerLevel("Low", watts=5), - chirp_common.PowerLevel("Low2", watts=10), - chirp_common.PowerLevel("Low3", watts=20), - chirp_common.PowerLevel("High", watts=35), - ] +POWER_LEVELS = [ + chirp_common.PowerLevel("Low", watts=5), + chirp_common.PowerLevel("Low2", watts=10), + chirp_common.PowerLevel("Low3", watts=20), + chirp_common.PowerLevel("High", watts=35), + ] TUNING_STEPS = [5.0, 10.0, 12.5, 15.0, 20.0, 25.0, 50.0] SKIP_VALUES = ["", "S"] CHARSET = r"!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^ _" @@ -515,10 +513,12 @@ DTMF_CHARSET = "0123456789*# " SPECIAL_CHANS = ['VFO-VHF', 'VFO-UHF', 'Home-VHF', 'Home-UHF', 'VFO', 'Home'] SCAN_LIMITS = ["L1", "U1", "L2", "U2", "L3", "U3", "L4", "U4", "L5", "U5"] + def do_download(radio): """This is your download function""" return _download(radio) + @directory.register class FT7100Radio(YaesuCloneModeRadio): @@ -532,16 +532,16 @@ class FT7100Radio(YaesuCloneModeRadio): # how many memories it has, what bands it supports, etc def get_features(self): LOG.debug("get_features") - -# import ipdb; ipdb.set_trace() - rf = chirp_common.RadioFeatures() rf.has_bank = False - rf.memory_bounds = (0, 259) # This radio supports 120 + 10 + 120 + 10 = 260 memories, zero based for chirpc - rf.valid_bands = [(108000000, 180000000), # Supports 2-meters tx - (320000000, 999990000), # Supports 70-centimeters tx - ] + rf.memory_bounds = (0, 259) + # This radio supports 120 + 10 + 120 + 10 = 260 memories + # These are zero based for chirpc + rf.valid_bands = [ + (108000000, 180000000), # Supports 2-meters tx + (320000000, 999990000), # Supports 70-centimeters tx + ] rf.can_odd_split = True rf.has_ctone = True rf.has_rx_dtcs = True @@ -554,14 +554,12 @@ class FT7100Radio(YaesuCloneModeRadio): rf.valid_tuning_steps = TUNING_STEPS rf.valid_modes = MODES_VHF rf.valid_tmodes = TONE_MODES - #rf.valid_cross_modes = CROSS_MODES rf.valid_power_levels = POWER_LEVELS rf.valid_duplexes = DUPLEX rf.valid_skips = SKIP_VALUES rf.valid_name_length = 6 rf.valid_characters = CHARSET rf.valid_special_chans = SPECIAL_CHANS - return rf def sync_in(self): @@ -650,9 +648,6 @@ class FT7100Radio(YaesuCloneModeRadio): else: mem.tmode = tmode_radio - #mem.cross_mode = "Tone->Tone" - #mem.dtcs_polarity = "NN" - mem.duplex = "" if _mem.is_offset_plus: mem.duplex = "+" @@ -680,7 +675,7 @@ class FT7100Radio(YaesuCloneModeRadio): else: mem.skip = "" - #mem.comment = "" + # mem.comment = "" mem.empty = not _mem.is_used @@ -714,7 +709,8 @@ class FT7100Radio(YaesuCloneModeRadio): elif number == 'Home-UHF': _mem = self._memobj.home_vhf_uhf[1].mem_struct else: - raise errors.RadioError("Unexpected Memory Number: {}".format(mem.number)) + raise errors.RadioError("Unexpected Memory Number: {}" + .format(mem.number)) else: _mem = self._memobj.memory[mem.number] @@ -759,7 +755,6 @@ class FT7100Radio(YaesuCloneModeRadio): # if name not empty: show name _mem.show_name = mem.name.strip() != "" - # In testmode there is no setting in mem.extra # This is why the following line is not located in the else part of # the if structure below @@ -769,8 +764,6 @@ class FT7100Radio(YaesuCloneModeRadio): if setting.get_name() == "is_ctcss_bell": if mem.tmode == "TSQL" and setting.value: _mem.tone_mode_index = TONE_MODES_RADIO.index("CTCSS Bell") - #else: - #_mem.tone_mode_index = TONE_MODES_RADIO.index(mem.tmode) else: setattr(_mem, setting.get_name(), setting.value) @@ -780,7 +773,8 @@ class FT7100Radio(YaesuCloneModeRadio): def get_settings(self): common = RadioSettingGroup("common", "Common Settings") band = RadioSettingGroup("band", "Band dependent Settings") - arts = RadioSettingGroup("arts", "Auto Range Transponder System (ARTS)") + arts = RadioSettingGroup("arts", + "Auto Range Transponder System (ARTS)") dtmf = RadioSettingGroup("dtmf", "DTMF Settings") mic_button = RadioSettingGroup("mic_button", "Microphone Buttons") setmode = RadioSettings(common, band, arts, dtmf, mic_button) @@ -792,20 +786,21 @@ class FT7100Radio(YaesuCloneModeRadio): # page 49 of the manual # 1 Automatic Power Off - opts = ["Off", "30 Min", - "1 Hour", "1.5 Hours", - "2 Hours", "2.5 Hours", - "3 Hours", "3.5 Hours", - "4 Hours", "4.5 Hours", - "5 Hours", "5.5 Hours", - "6 Hours", "6.5 Hours", - "7 Hours", "7.5 Hours", - "8 Hours", "8.5 Hours", - "9 Hours", "9.5 Hours", - "10 Hours", "10.5 Hours", - "11 Hours", "11.5 Hours", - "12 Hours", - ] + opts = [ + "Off", "30 Min", + "1 Hour", "1.5 Hours", + "2 Hours", "2.5 Hours", + "3 Hours", "3.5 Hours", + "4 Hours", "4.5 Hours", + "5 Hours", "5.5 Hours", + "6 Hours", "6.5 Hours", + "7 Hours", "7.5 Hours", + "8 Hours", "8.5 Hours", + "9 Hours", "9.5 Hours", + "10 Hours", "10.5 Hours", + "11 Hours", "11.5 Hours", + "12 Hours", + ] common.append( RadioSetting( "apo", "Automatic Power Off", @@ -823,16 +818,7 @@ class FT7100Radio(YaesuCloneModeRadio): RadioSettingValueList(opts, opts[_overlay.ars_uhf]))) # 3 Selects the ARTS mode. - # -> Only useful to set it on radio directly - #opts = ["Off", "Range", "All"] - #arts.append( - #RadioSetting( - #"arts_vhf", "ARTS Mode VHF", - #RadioSettingValueList(opts, opts[_overlay.arts_vhf]))) - #arts.append( - #RadioSetting( - #"arts_uhf", "ARTS Mode UHF", - #RadioSettingValueList(opts, opts[_overlay.arts_uhf]))) + # -> Only useful to set it on the radio directly # 4 Enables/disables the key/button beeper. opts = ["Off", "On"] @@ -853,8 +839,8 @@ class FT7100Radio(YaesuCloneModeRadio): cwidw = cwidw.rstrip('\x00') val = RadioSettingValueString(0, 6, cwidw) val.set_charset(CHARSET) - rs = RadioSetting( - "cwidw", "CW Identifier Callsign", val) + rs = RadioSetting("cwidw", "CW Identifier Callsign", val) + def apply_cwid(setting): value_string = setting.value.get_value() _overlay.cwidw.set_value(value_string) @@ -887,7 +873,8 @@ class FT7100Radio(YaesuCloneModeRadio): RadioSettingValueList(opts, opts[_overlay.dcsnr_uhf]))) # 11 Selects the 'sub' band display format - opts = ["Frequency", "Off / Sub Band disabled", "DC Input Voltage", "CW ID"] + opts = ["Frequency", "Off / Sub Band disabled", + "DC Input Voltage", "CW ID"] common.append( RadioSetting( "disp", "Sub Band Display Format", @@ -908,9 +895,9 @@ class FT7100Radio(YaesuCloneModeRadio): RadioSettingValueList(opts, opts[_overlay.dtmfs]))) # 14 Current DTMF Autodialer memory - rs = RadioSetting( - "dtmfw", "Current Autodialer memory", - RadioSettingValueInteger(1, 16, _overlay.dtmfw + 1)) + rs = RadioSetting("dtmfw", "Current Autodialer memory", + RadioSettingValueInteger(1, 16, _overlay.dtmfw + 1)) + def apply_dtmfw(setting): _overlay.dtmfw = setting.value.get_value() - 1 rs.set_apply_callback(apply_dtmfw) @@ -931,11 +918,13 @@ class FT7100Radio(YaesuCloneModeRadio): elif dtmf_int == 255: break dtmf_string += dtmf_char - radio_setting_value_string = RadioSettingValueString(0, 16, dtmf_string) + radio_setting_value_string = RadioSettingValueString(0, 16, + dtmf_string) radio_setting_value_string.set_charset(DTMF_CHARSET) rs = RadioSetting("dtmf_{0:02d}".format(i), "DTMF Mem " + str(i+1), radio_setting_value_string) + def apply_dtmf(setting, index): radio_setting_value_string = setting.value.get_value().rstrip() j = 0 @@ -969,7 +958,8 @@ class FT7100Radio(YaesuCloneModeRadio): "mic", "Microphone type", RadioSettingValueList(opts, opts[_overlay.mic]))) - # 18 Reduces the audio level on the sub receiver when the main receiver is active + # 18 Reduces the audio level on the sub receiver when the + # main receiver is active opts = ["Off", "On"] common.append( RadioSetting( @@ -977,17 +967,21 @@ class FT7100Radio(YaesuCloneModeRadio): RadioSettingValueList(opts, opts[_overlay.mute]))) # 20 - 23 Programming the microphones button assignment - buttons = ["ACC / P1", - "P / P2", - "P1 / P3", - "P2 / P4", - ] - opts_button = ["Low", "Tone", "MHz", "Rev", "Home", "Band", "VFO / Memory", - "Sql Off", "1750 Hz Tone Call", "Repeater", "Priority"] + buttons = [ + "ACC / P1", + "P / P2", + "P1 / P3", + "P2 / P4", + ] + opts_button = ["Low", "Tone", "MHz", "Rev", "Home", "Band", + "VFO / Memory", "Sql Off", "1750 Hz Tone Call", + "Repeater", "Priority"] for i, button in enumerate(buttons): rs = RadioSetting( "button" + str(i), button, - RadioSettingValueList(opts_button, opts_button[_overlay.button[i]])) + RadioSettingValueList(opts_button, + opts_button[_overlay.button[i]])) + def apply_button(setting, index): value_string = setting.value.get_value() value_int = opts_button.index(value_string) @@ -1064,11 +1058,13 @@ class FT7100Radio(YaesuCloneModeRadio): RadioSettingValueList(opts, opts[_overlay.current_band]))) # Show number of VHF and UHF channels - val = RadioSettingValueString(0, 7, str(int(self._memobj.nb_mem_used_vhf))) + val = RadioSettingValueString(0, 7, + str(int(self._memobj.nb_mem_used_vhf))) val.set_mutable(False) rs = RadioSetting("num_chan_vhf", "Number of VHF channels", val) common.append(rs) - val = RadioSettingValueString(0, 7, str(int(self._memobj.nb_mem_used_uhf))) + val = RadioSettingValueString(0, 7, + str(int(self._memobj.nb_mem_used_uhf))) val.set_mutable(False) rs = RadioSetting("num_chan_uhf", "Number of UHF channels", val) common.append(rs) @@ -1092,7 +1088,6 @@ class FT7100Radio(YaesuCloneModeRadio): LOG.debug("Using apply callback") element.run_apply_callback() else: - obj = getattr(_overlay, name) setattr(_overlay, name, value) LOG.debug("Setting %s: %s", name, value) @@ -1101,7 +1096,7 @@ class FT7100Radio(YaesuCloneModeRadio): raise def _get_upper_vhf_limit(self): - if self._memobj == None: + if self._memobj is None: # test with tox has no _memobj upper_vhf_limit = 130 else: @@ -1109,7 +1104,7 @@ class FT7100Radio(YaesuCloneModeRadio): return upper_vhf_limit def _get_upper_uhf_limit(self): - if self._memobj == None: + if self._memobj is None: # test with tox has no _memobj upper_uhf_limit = 130 else: @@ -1118,7 +1113,6 @@ class FT7100Radio(YaesuCloneModeRadio): @classmethod def match_model(cls, filedata, filename): - #return len(filedata) == 7936 --> Filelength changed due to MAGIC appended at end of file return filedata[0x1ec0:0x1ec0+len(cls.IDBLOCK)] == cls.IDBLOCK @classmethod @@ -1139,8 +1133,12 @@ class FT7100Radio(YaesuCloneModeRadio): return rp def get_sub_devices(self): - return [FT7100RadioVHF(self._mmap), - FT7100RadioUHF(self._mmap)] + if not self.VARIANT: + return [FT7100RadioVHF(self._mmap), + FT7100RadioUHF(self._mmap)] + else: + return [] + class FT7100RadioVHF(FT7100Radio): VARIANT = "VHF Band" @@ -1149,10 +1147,12 @@ class FT7100RadioVHF(FT7100Radio): LOG.debug("VHF get_features") upper_vhf_limit = self._get_upper_vhf_limit() rf = FT7100Radio.get_features(self) - rf.memory_bounds = (1, upper_vhf_limit) # Normally this band supports 120 + 10 memories. 1 based for chirpw + rf.memory_bounds = (1, upper_vhf_limit) + # Normally this band supports 120 + 10 memories. 1 based for chirpw rf.valid_bands = [(108000000, 180000000)] # Supports 2-meters tx rf.valid_modes = MODES_VHF rf.valid_special_chans = ['VFO', 'Home'] + rf.has_sub_devices = False return rf def get_memory(self, number): @@ -1166,7 +1166,6 @@ class FT7100RadioVHF(FT7100Radio): else: mem = FT7100Radio.get_memory(self, number + '-VHF') mem.extd_number = number - #TODO immutable does not work mem.immutable = ["number", "extd_number", "skip"] return mem @@ -1184,6 +1183,7 @@ class FT7100RadioVHF(FT7100Radio): mem.number = _number return + class FT7100RadioUHF(FT7100Radio): VARIANT = "UHF Band" @@ -1191,10 +1191,12 @@ class FT7100RadioUHF(FT7100Radio): LOG.debug("UHF get_features") upper_uhf_limit = self._get_upper_uhf_limit() rf = FT7100Radio.get_features(self) - rf.memory_bounds = (1, upper_uhf_limit) # Normally this band supports 120 + 10 memories. 1 based for chirpw + rf.memory_bounds = (1, upper_uhf_limit) + # Normally this band supports 120 + 10 memories. 1 based for chirpw rf.valid_bands = [(320000000, 999990000)] # Supports 70-centimeters tx rf.valid_modes = MODES_UHF rf.valid_special_chans = ['VFO', 'Home'] + rf.has_sub_devices = False return rf def get_memory(self, number): @@ -1202,14 +1204,14 @@ class FT7100RadioUHF(FT7100Radio): upper_vhf_limit = self._get_upper_vhf_limit() if isinstance(number, int): if number >= 0: - mem = FT7100Radio.get_memory(self, number + upper_vhf_limit - 1) + mem = FT7100Radio.get_memory(self, number + + upper_vhf_limit - 1) else: mem = FT7100Radio.get_memory(self, number) mem.number = number else: mem = FT7100Radio.get_memory(self, number + '-UHF') mem.extd_number = number - #TODO immutable does not work mem.immutable = ["number", "extd_number", "skip"] return mem @@ -1227,4 +1229,3 @@ class FT7100RadioUHF(FT7100Radio): # Restore modified members mem.number = _number return - diff --git a/chirp/drivers/ft818.py b/chirp/drivers/ft818.py index 4263a8b..c7a0a32 100755 --- a/chirp/drivers/ft818.py +++ b/chirp/drivers/ft818.py @@ -226,13 +226,13 @@ class FT818Radio(ft817.FT817Radio): "VFOb-50M": -11, "VFOb-FM": -10, "VFOb-AIR": -9, - "VFOb-144M": -8, - "VFOb-430M": -7, + "VFOb-144": -8, + "VFOb-430": -7, "VFOb-HF": -6, "HOME HF": -5, "HOME 50M": -4, - "HOME 144M": -3, - "HOME 430M": -2, + "HOME 144": -3, + "HOME 430": -2, "QMB": -1, } FIRST_VFOB_INDEX = -6 @@ -251,6 +251,7 @@ class FT818Radio(ft817.FT817Radio): SPECIAL_MEMORIES_REV = dict(zip(SPECIAL_MEMORIES.values(), SPECIAL_MEMORIES.keys())) + @directory.register class FT818NDUSRadio(FT818Radio): @@ -264,13 +265,13 @@ class FT818NDUSRadio(FT818Radio): _block_lengths = [2, 40, 208, 208, 208, 208, 198, 53, 130, 118, 130, 130] SPECIAL_60M = { - "M-601": -42, - "M-602": -41, - "M-603": -40, - "M-604": -39, - "M-605": -38, + "M-601": -44, + "M-602": -43, + "M-603": -42, + "M-604": -41, + "M-605": -40, } - LAST_SPECIAL60M_INDEX = -42 + LAST_SPECIAL60M_INDEX = -44 SPECIAL_MEMORIES = dict(FT818Radio.SPECIAL_MEMORIES) SPECIAL_MEMORIES.update(SPECIAL_60M) @@ -339,4 +340,3 @@ class FT818NDUSRadio(FT818Radio): self._memobj.settings.emergency)) basic.append(rs) return top - diff --git a/chirp/drivers/gmrsuv1.py b/chirp/drivers/gmrsuv1.py index d8fd594..7bb1d2f 100644 --- a/chirp/drivers/gmrsuv1.py +++ b/chirp/drivers/gmrsuv1.py @@ -39,9 +39,10 @@ MSTRING_GMRSV1 = "\x50\x5F\x20\x15\x12\x15\x4D" ##### ID strings ##################################################### # BTECH GMRS-V1 -GMRSV1_fp1 = "US32411" -GMRSV1_fp2 = "US32416" -GMRSV1_fp3 = "US32418" +GMRSV1_fp1 = "US32411" # original +GMRSV1_fp2 = "US32416" # original +GMRSV1_fp3 = "US32418" # new rules +GMRSV1_fp4 = "US32412" # original DTMF_CHARS = "0123456789 *#ABCD" STEPS = [2.5, 5.0, 6.25, 10.0, 12.5, 20.0, 25.0, 50.0] @@ -97,7 +98,7 @@ class GMRSV1(baofeng_common.BaofengCommonHT): MODEL = "GMRS-V1" _fileid = [GMRSV1_fp3, GMRSV1_fp2, GMRSV1_fp1, ] - _is_orig = [GMRSV1_fp2, GMRSV1_fp1, ] + _is_orig = [GMRSV1_fp2, GMRSV1_fp1, GMRSV1_fp4, ] _magic = [MSTRING_GMRSV1, ] _magic_response_length = 8 @@ -162,6 +163,7 @@ class GMRSV1(baofeng_common.BaofengCommonHT): rf.memory_bounds = (0, 127) rf.valid_power_levels = self.POWER_LEVELS rf.valid_bands = self.VALID_BANDS + rf.valid_tuning_steps = STEPS return rf diff --git a/chirp/drivers/h777.py b/chirp/drivers/h777.py index f542ad1..dc689f5 100644 --- a/chirp/drivers/h777.py +++ b/chirp/drivers/h777.py @@ -237,6 +237,21 @@ class ArcshellAR6(chirp_common.Alias): MODEL = 'AR-6' +class GV8SAlias(chirp_common.Alias): + VENDOR = 'Greaval' + MODEL = 'GV-8S' + + +class GV9SAlias(chirp_common.Alias): + VENDOR = 'Greaval' + MODEL = 'GV-9S' + + +class A8SAlias(chirp_common.Alias): + VENDOR = 'Ansoko' + MODEL = 'A-8S' + + @directory.register class H777Radio(chirp_common.CloneModeRadio): """HST H-777""" @@ -246,7 +261,7 @@ class H777Radio(chirp_common.CloneModeRadio): MODEL = "BF-888" BAUD_RATE = 9600 - ALIASES = [ArcshellAR5, ArcshellAR6] + ALIASES = [ArcshellAR5, ArcshellAR6, GV8SAlias, GV9SAlias, A8SAlias] # This code currently requires that ranges start at 0x0000 # and are continious. In the original program 0x0388 and 0x03C8 @@ -292,6 +307,8 @@ class H777Radio(chirp_common.CloneModeRadio): rf.memory_bounds = (1, 16) rf.valid_bands = [(400000000, 470000000)] rf.valid_power_levels = H777_POWER_LEVELS + rf.valid_tuning_steps = [2.5, 5.0, 6.25, 10.0, 12.5, 15.0, 20.0, 25.0, + 50.0, 100.0] return rf diff --git a/chirp/drivers/ic2730.py b/chirp/drivers/ic2730.py index 44af362..c3d192f 100644 --- a/chirp/drivers/ic2730.py +++ b/chirp/drivers/ic2730.py @@ -1,4 +1,5 @@ # Copyright 2018 Rhett Robinson <rrhett@gmail.com> +# Added Settings support, 6/2019 Rick DeWitt <aa0rd@yahoo.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 @@ -13,23 +14,27 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +import struct +import logging from chirp.drivers import icf from chirp import chirp_common, util, directory, bitwise, memmap +from chirp import errors +from chirp.settings import RadioSettingGroup, RadioSetting, \ + RadioSettingValueBoolean, RadioSettingValueList, \ + RadioSettingValueString, RadioSettingValueInteger, \ + RadioSettingValueFloat, RadioSettings, InvalidValueError +from textwrap import dedent +LOG = logging.getLogger(__name__) -# Still missing: -# - scan edges -# - priority watch -# - hope channel beep -# - DTMF memory -# - weather channel alert MEM_FORMAT = """ struct { - u24 freq; + u24 freq_flags:6 + freq:18; u16 offset; u8 tune_step:4, - unknown5:3, - mode:1; + unknown5:2, + mode:2; u8 unknown6:2, rtone:6; u8 unknown7:2, @@ -51,31 +56,164 @@ u8 pskip_flags[125]; #seekto 0x4440; struct { - u8 bank; - u8 index; +u8 bank; +u8 index; } bank_info[1000]; +#seekto 0x4c40; +struct { +char com[16]; +} comment; + #seekto 0x4c50; struct { - char name[6]; +char name[6]; } bank_names[10]; -#seekto 0x5004; -u8 unknown12:4, - autorptr:2, - unknown13:2; +#seekto 0x4cc8; +struct{ +u8 codes[24]; +} dtmfcode[16]; -#seekto 0x5030; -u8 unknown14:6, - backlight:2; +#seekto 0x4c8c; +struct { +char nam[6]; +} pslnam[10]; -#seekto 0x5056; -u8 unknown15:6, - power:2; +#seekto 0x4e80; +struct { +u24 loflags:6 + lofreq:18; +u24 hiflags:6 + hifreq:18; +u8 flag:4 + mode:4; +u8 tstp; +char name[6]; +} pgmscanedge[25]; + +#seekto 0x5000; +struct { +u8 aprichn; +u8 bprichn; +u8 autopwr; +u8 unk5003; +u8 autorptr; +u8 rmtmic; // 0x05005 +u8 pttlock; +u8 bcl; +u8 tot; +u8 actband; +u8 unk500a; +u8 dialspdup; +u8 toneburst; +u8 micgain; +u8 unk500e; +u8 civaddr; +u8 civbaud; +u8 civtcvr; +u8 sqlatt; +u8 sqldly; +u8 unk5014a:4 + fanspeed:4; +u8 unk5015; +u8 bthvox; +u8 bthvoxlvl; +u8 bthvoxdly; +u8 bthvoxtot; // 0x05019 +u8 btoothon; +u8 btoothauto; +u8 bthdset; +u8 bthhdpsav; +u8 bth1ptt; // 0x0501e +u8 bthpttbeep; +u8 bthcustbeep; // 0x05020 +u8 ascanpause; +u8 bscanpause; +u8 ascanresume; +u8 bscanresume; +u8 dtmfspd; +u8 unk5026; +u8 awxalert; +u8 bwxalert; +u8 aprgskpscn; +u8 bprgskpscn; +u8 memname; +u8 contrast; +u8 autodimtot; +u8 autodim; +u8 unk502f; +u8 backlight; +u8 unk5031; +u8 unk5032; +u8 openmsg; +u8 beeplvl; // 0x05034 +u8 keybeep; +u8 scanstpbeep; +u8 bandedgbeep; +u8 subandmute; +u8 atmpskiptym; +u8 btmpskiptym; +u32 vfohome; +u8 vfohomeset; +u16 homech; +u8 mickyrxf1; +u8 mickyrxf2; +u8 mickyrxup; +u8 mickyrxdn; // 0x05045 +u8 bthplaykey; +u8 bthfwdkey; +u8 bthrwdkey; +u8 mickytxf1; +u8 mickytxf2; +u8 mickytxup; +u8 mickytxdn; +u8 unk504d; +u8 unk504e; +u8 unk504f; +u8 homebeep; +u8 bthfctn; +u8 unk5052; +u8 unk5053; +u8 ifxchg; +u8 airbandch; +u8 vhfpower; +u8 uhfpower; +u8 unk5058; +u8 unk5059; +u8 unk505a; +u8 unk505b; +u8 unk505c; +u8 unk505d; +u8 unk505e:6 + rpthangup:1 + unk505e2:1; +u8 unk505f; +} settings; #seekto 0x5220; +struct { u16 left_memory; u16 right_memory; +} initmem; + +#seekto 0x523e; +struct { +u8 awxchan; +u8 bwxchan; +} abwx; + +#seekto 0x5250; +struct { +u8 alnk[2]; +u16 unk5252; +u8 blnk[2]; +} banklink; + +#seekto 0x5258; +struct { +u8 msk[4]; +} pslgrps[25]; #seekto 0x5280; u16 mem_writes_count; @@ -84,12 +222,18 @@ u16 mem_writes_count; # Guessing some of these intermediate values are with the Pocket Beep function, # but I haven't reliably reproduced these. TMODES = ["", "Tone", "??0", "TSQL", "??1", "DTCS", "TSQL-R", "DTCS-R", - "DTC.OFF", "TON.DTC", "DTC.TSQ", "TON.TSQ"] + "DTC.OFF", "TON.DTC", "DTC.TSQ", "TON.TSQ"] DUPLEX = ["", "-", "+"] -MODES = ["FM", "NFM"] +MODES = ["FM", "NFM", "AM", "NAM"] DTCSP = ["NN", "NR", "RN", "RR"] - +DTMF_CHARS = list("0123456789ABCD*#") +BANKLINK_CHARS = list("ABCDEFGHIJ") AUTOREPEATER = ["OFF", "DUP", "DUP.TON"] +MICKEYOPTS = ["Off", "Up", "Down", "Vol Up", "Vol Down", "SQL Up", + "SQL Down", "Monitor", "Call", "MR (Ch 0)", "MR (Ch 1)", + "VFO/MR", "Home Chan", "Band/Bank", "Scan", "Temp Skip", + "Main", "Mode", "Low", "Dup", "Priority", "Tone", "MW", "Mute", + "T-Call", "DTMF Direct"] class IC2730Bank(icf.IcomNamedBank): @@ -104,8 +248,7 @@ class IC2730Bank(icf.IcomNamedBank): def _get_special(): - special = {"C0": 1000, - "C1": 1001} + special = {"C0": -2, "C1": -1} return special @@ -127,18 +270,46 @@ class IC2730Radio(icf.IcomRawCloneModeRadio): MODEL = "IC-2730A" _model = "\x35\x98\x00\x01" - _memsize = 21312 # 0x5340 + _memsize = 21312 # 0x5340 _endframe = "Icom Inc\x2e4E" _ranges = [(0x0000, 0x5300, 64), (0x5300, 0x5310, 16), - (0x5310, 0x5340, 48), - ] + (0x5310, 0x5340, 48)] _num_banks = 10 _bank_class = IC2730Bank _can_hispeed = True + @classmethod + def get_prompts(cls): + rp = chirp_common.RadioPrompts() + rp.info = ('Click the Special Channels tab on the main screen to ' + 'access the C0 and C1 frequencies.\n') + + rp.pre_download = _(dedent("""\ + Follow these instructions to download your config: + + 1 - Turn off your radio + 2 - Connect your interface cable to the Speaker-2 jack + 3 - Turn on your radio + 4 - Radio > Download from radio + 5 - Disconnect the interface cable! Otherwise there will be + no right-side audio! + """)) + rp.pre_upload = _(dedent("""\ + Follow these instructions to upload your config: + + 1 - Turn off your radio + 2 - Connect your interface cable to the Speaker-2 jack + 3 - Turn on your radio + 4 - Radio > Upload to radio + 5 - Disconnect the interface cable, otherwise there will be + no right-side audio! + 6 - Cycle power on the radio to exit clone mode + """)) + return rp + def _get_bank(self, loc): _bank = self._memobj.bank_info[loc] if _bank.bank == 0x1F: @@ -173,8 +344,7 @@ class IC2730Radio(icf.IcomRawCloneModeRadio): rf.valid_duplexes = list(set(DUPLEX)) rf.valid_tuning_steps = list(chirp_common.TUNING_STEPS[0:9]) rf.valid_bands = [(118000000, 174000000), - (375000000, 550000000), - ] + (375000000, 550000000)] rf.valid_skips = ["", "S", "P"] rf.valid_characters = chirp_common.CHARSET_ASCII rf.valid_name_length = 6 @@ -186,32 +356,50 @@ class IC2730Radio(icf.IcomRawCloneModeRadio): self._memobj = bitwise.parse(MEM_FORMAT, self._mmap) def get_memory(self, number): - bitpos = (1 << (number % 8)) - bytepos = number / 8 - - _mem = self._memobj.memory[number] - _used = self._memobj.used_flags[bytepos] - - is_used = ((_used & bitpos) == 0) - mem = chirp_common.Memory() + mem.number = _resolve_memory_number(number) + if mem.number >= 0: + _mem = self._memobj.memory[mem.number] + bitpos = (1 << (number % 8)) + bytepos = number / 8 + _used = self._memobj.used_flags[bytepos] + is_used = ((_used & bitpos) == 0) - mem.number = number - - _skip = self._memobj.skip_flags[bytepos] - _pskip = self._memobj.pskip_flags[bytepos] - if _skip & bitpos: - mem.skip = "S" - elif _pskip & bitpos: - mem.skip = "P" + _skip = self._memobj.skip_flags[bytepos] + _pskip = self._memobj.pskip_flags[bytepos] + if _skip & bitpos: + mem.skip = "S" + elif _pskip & bitpos: + mem.skip = "P" + if not is_used: + mem.empty = True + return mem + else: # C0, C1 specials + _mem = self._memobj.memory[1002 + mem.number] - if not is_used: - mem.empty = True - return mem + # _mem.freq is stored as a multiple of a tuning step + frequency_flags = int(_mem.freq_flags) + frequency_multiplier = 5000 + offset_multiplier = 5000 + if frequency_flags & 0x08: + frequency_multiplier = 6250 + if frequency_flags & 0x01: + offset_multiplier = 6250 + if frequency_flags & 0x10: + frequency_multiplier = 8333 + if frequency_flags & 0x02: + offset_multiplier = 8333 - # Frequencies are stored as kHz/5 - mem.freq = int(_mem.freq) * 5000 - mem.offset = int(_mem.offset) * 5000 + if frequency_flags & 0x10: # fix underflow + val = int(_mem.freq) * frequency_multiplier + mem.freq = round(val) + else: + mem.freq = int(_mem.freq) * frequency_multiplier + if frequency_flags & 0x02: + val = int(_mem.offset) * offset_multiplier + mem.offset = round(val) + else: + mem.offset = int(_mem.offset) * offset_multiplier mem.rtone = chirp_common.TONES[_mem.rtone] mem.ctone = chirp_common.TONES[_mem.ctone] mem.tmode = TMODES[_mem.tmode] @@ -224,41 +412,68 @@ class IC2730Radio(icf.IcomRawCloneModeRadio): else: mem.tuning_step = chirp_common.TUNING_STEPS[_mem.tune_step] mem.name = str(_mem.name).rstrip() + if mem.number == -2: + mem.name = "C0" + mem.extd_number = "C0" + if mem.number == -1: + mem.name = "C1" + mem.extd_number = "C1" return mem def set_memory(self, mem): - bitpos = (1 << (mem.number % 8)) - bytepos = mem.number / 8 + if mem.number >= 0: # Normal + bitpos = (1 << (mem.number % 8)) + bytepos = mem.number / 8 - _mem = self._memobj.memory[mem.number] - _used = self._memobj.used_flags[bytepos] + _mem = self._memobj.memory[mem.number] + _used = self._memobj.used_flags[bytepos] - was_empty = _used & bitpos + was_empty = _used & bitpos - skip = self._memobj.skip_flags[bytepos] - pskip = self._memobj.pskip_flags[bytepos] - if mem.skip == "S": - skip |= bitpos - else: - skip &= ~bitpos - if mem.skip == "P": - pskip |= bitpos - else: - pskip &= ~bitpos + skip = self._memobj.skip_flags[bytepos] + pskip = self._memobj.pskip_flags[bytepos] + if mem.skip == "S": + skip |= bitpos + else: + skip &= ~bitpos + if mem.skip == "P": + pskip |= bitpos + else: + pskip &= ~bitpos - if mem.empty: - _used |= bitpos - _wipe_memory(_mem, "\xFF") - self._set_bank(mem.number, None) - return + if mem.empty: + _used |= bitpos + _wipe_memory(_mem, "\xFF") + self._set_bank(mem.number, None) + return - _used &= ~bitpos - if was_empty: - _wipe_memory(_mem, "\x00") + _used &= ~bitpos + if was_empty: + _wipe_memory(_mem, "\x00") + _mem.name = mem.name.ljust(6) + else: # Specials: -2 and -1 + _mem = self._memobj.memory[1002 + mem.number] - _mem.freq = mem.freq / 5000 - _mem.offset = mem.offset / 5000 + # Common to both types + frequency_flags = 0x00 + frequency_multiplier = 5000 + offset_multiplier = 5000 + if mem.freq % 5000 != 0 and mem.freq % 6250 == 0: + frequency_flags |= 0x08 + frequency_multiplier = 6250 + elif mem.freq % 8333 == 0: + frequency_flags |= 0x10 + frequency_multiplier = 8333 + if mem.offset % 5000 != 0 and mem.offset % 6250 == 0: + frequency_flags |= 0x01 + offset_multiplier = 6250 + elif mem.offset % 8333 == 0: + frequency_flags |= 0x02 + offset_multiplier = 8333 + _mem.freq = mem.freq / frequency_multiplier + _mem.offset = mem.offset / offset_multiplier + _mem.freq_flags = frequency_flags _mem.rtone = chirp_common.TONES.index(mem.rtone) _mem.ctone = chirp_common.TONES.index(mem.ctone) _mem.tmode = TMODES.index(mem.tmode) @@ -267,7 +482,809 @@ class IC2730Radio(icf.IcomRawCloneModeRadio): _mem.dtcs = chirp_common.DTCS_CODES.index(mem.dtcs) _mem.dtcs_polarity = DTCSP.index(mem.dtcs_polarity) _mem.tune_step = chirp_common.TUNING_STEPS.index(mem.tuning_step) - _mem.name = mem.name.ljust(6) def get_raw_memory(self, number): return repr(self._memobj.memory[number]) + + def get_settings(self): + """Translate the MEM_FORMAT structs into settings in the UI""" + # Define mem struct write-back shortcuts + _sets = self._memobj.settings + _cmnt = self._memobj.comment + _wxch = self._memobj.abwx + _dtm = self._memobj.dtmfcode + _pses = self._memobj.pgmscanedge + _bklk = self._memobj.banklink + + basic = RadioSettingGroup("basic", "Basic Settings") + mickey = RadioSettingGroup("mickey", "Microphone Keys") + bluet = RadioSettingGroup("bluet", "Bluetooth") + disp = RadioSettingGroup("disp", "Display") + sound = RadioSettingGroup("sound", "Sounds") + dtmf = RadioSettingGroup("dtmf", "DTMF Codes") + abset = RadioSettingGroup("abset", "A/B Band Settings") + edges = RadioSettingGroup("edges", "Program Scan Edges") + pslnk = RadioSettingGroup("pslnk", "Program Scan Links") + other = RadioSettingGroup("other", "Other Settings") + + group = RadioSettings(basic, disp, sound, mickey, dtmf, + abset, bluet, edges, pslnk, other) + + def mic_keys(setting, obj, atrb): + """ Callback to set subset of mic key options """ + stx = str(setting.value) + value = MICKEYOPTS.index(stx) + setattr(obj, atrb, value) + return + + def hex_val(setting, obj, atrb): + """ Callback to store string as hex values """ + value = int(str(setting.value), 16) + setattr(obj, atrb, value) + return + + def unpack_str(codestr): + """Convert u8 DTMF array to a string: NOT a callback.""" + stx = "" + for i in range(0, 24): # unpack up to ff + if codestr[i] != 0xff: + if codestr[i] == 0x0E: + stx += "#" + elif codestr[i] == 0x0F: + stx += "*" + else: + stx += format(int(codestr[i]), '0X') + return stx + + def pack_chars(setting, obj, atrb, ndx): + """Callback to build 0-9,A-D,*# nibble array from string""" + # String will be f padded to 24 bytes + # Chars are stored as hex values + ary = [] + stx = str(setting.value).upper() + stx = stx.strip() # trim spaces + # Remove illegal characters first + sty = "" + for j in range(0, len(stx)): + if stx[j] in DTMF_CHARS: + sty += stx[j] + for j in range(0, 24): + if j < len(sty): + if sty[j] == "#": + chrv = 0xE + elif sty[j] == "*": + chrv = 0xF + else: + chrv = int(sty[j], 16) + else: # pad to 24 bytes + chrv = 0xFF + ary.append(chrv) # append byte + setattr(obj[ndx], atrb, ary) + return + + def myset_comment(setting, obj, atrb, knt): + """ Callback to create space-padded char array""" + stx = str(setting.value) + for i in range(0, knt): + if i > len(stx): + str.append(0x20) + setattr(obj, atrb, stx) + return + + def myset_psnam(setting, obj, ndx, atrb, knt): + """ Callback to generate space-padded, uppercase char array """ + # This sub also is specific to object arrays + stx = str(setting.value).upper() + for i in range(0, knt): + if i > len(stx): + str.append(0x20) + setattr(obj[ndx], atrb, stx) + return + + def myset_frqflgs(setting, obj, ndx, flg, frq): + """ Callback to gen flag/freq pairs """ + vfrq = float(str(setting.value)) + vfrq = int(vfrq * 1000000) + vflg = 0x10 + if vfrq % 6250 == 0: + vflg = 0x08 + vfrq = int(vfrq / 6250) + elif vfrq % 5000 == 0: + vflg = 0 + vfrq = int(vfrq / 5000) + else: + vfrq = int(vfrq / 8333) + setattr(obj[ndx], flg, vflg) + setattr(obj[ndx], frq, vfrq) + return + + def banklink(ary): + """ Sub to generate A-J string from 2-byte bit pattern """ + stx = "" + for kx in range(0, 10): + if kx < 8: + val = ary[0] + msk = 1 << kx + else: + val = ary[1] + msk = 1 << (kx - 8) + if val & msk: + stx += chr(kx + 65) + else: + stx += "_" + return stx + + def myset_banklink(setting, obj, atrb): + """Callback to create 10-bit, u8[2] array from 10 char string""" + stx = str(setting.value).upper() + ary = [0, 0] + for kx in range(0, 10): + if stx[kx] == chr(kx + 65): + if kx < 8: + ary[0] = ary[0] + (1 << kx) + else: + ary[1] = ary[1] + (1 << (kx - 8)) + setattr(obj, atrb, ary) + return + + def myset_tsopt(setting, obj, ndx, atrb, bx): + """ Callback to set scan Edge tstep """ + stx = str(setting.value) + flg = 0 + if stx == "-": + val = 0xff + else: + if bx == 1: # Air band + if stx == "Auto": + val = 0xe + elif stx == "25k": + val = 8 + elif stx == "8.33k": + val = 2 + else: # VHF or UHF + optx = ["-", "5k", "6.25k", "10k", "12.5k", "15k", + "20k", "25k", "30k", "50k"] + val = optx.index(stx) + 1 + setattr(obj[ndx], atrb, val) + # and set flag + setattr(obj[ndx], "flag", flg) + return + + def myset_mdopt(setting, obj, ndx, atrb, bx): + """ Callback to set Scan Edge mode """ + stx = str(setting.value) + if stx == "-": + val = 0xf + elif stx == "FM": + val = 0 + else: + val = 1 + setattr(obj[ndx], atrb, val) + return + + def myset_bitmask(setting, obj, ndx, atrb, knt): + """ Callback to gnerate byte-array bitmask from string""" + # knt is BIT count to process + lsx = str(setting.value).strip().split(",") + for kx in range(0, len(lsx)): + try: + lsx[kx] = int(lsx[kx]) + except Exception: + lsx[kx] = -99 # will nop + ary = [0, 0, 0, 0xfe] + for kx in range(0, knt): + if kx < 8: + if kx in lsx: + ary[0] += 1 << kx + elif kx >= 8 and kx < 16: + if kx in lsx: + ary[1] += 1 << (kx - 8) + elif kx >= 16 and kx < 24: + if kx in lsx: + ary[2] += 1 << (kx - 16) + else: + if kx in lsx: # only bit 25 + ary[3] += 1 + setattr(obj[ndx], atrb, ary) + return + + # --- Basic + options = ["Off", "S-Meter Squelch", "ATT"] + rx = RadioSettingValueList(options, options[_sets.sqlatt]) + rset = RadioSetting("settings.sqlatt", "Squelch/ATT", rx) + basic.append(rset) + + options = ["Short", "Long"] + rx = RadioSettingValueList(options, options[_sets.sqldly]) + rset = RadioSetting("settings.sqldly", "Squelch Delay", rx) + basic.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.pttlock)) + rset = RadioSetting("settings.pttlock", "PTT Lockout", rx) + basic.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.bcl)) + rset = RadioSetting("settings.bcl", "Busy Channel Lockout", rx) + basic.append(rset) + + options = ["Off", "1m", "3m", "5m", "10m", "15m", "30m"] + rx = RadioSettingValueList(options, options[_sets.tot]) + rset = RadioSetting("settings.tot", "Tx Timeout", rx) + basic.append(rset) + + val = int(_sets.vfohome) + if val == 0xffff: + val = 0 + val = val / 1000000.0 + rx = RadioSettingValueFloat(0.0, 550.0, val, 0.005, 4) + rx.set_mutable(False) + rset = RadioSetting("settings.vfohome", "Home VFO (Read-Only)", rx) + basic.append(rset) + + val = _sets.homech + if val == 0xffff: + val = -1 + rx = RadioSettingValueInteger(-1, 999, val) + rx.set_mutable(False) + rset = RadioSetting("settings.homech", + "Home Channel (Read-Only)", rx) + basic.append(rset) + + options = ["1", "2", "3", "4"] + rx = RadioSettingValueList(options, options[_sets.micgain]) + rset = RadioSetting("settings.micgain", "Microphone Gain", rx) + basic.append(rset) + + _bmem = self._memobj.initmem + rx = RadioSettingValueInteger(0, 999, _bmem.left_memory) + rset = RadioSetting("initmem.left_memory", + "Left Bank Initial Mem Chan", rx) + basic.append(rset) + + rx = RadioSettingValueInteger(0, 999, _bmem.right_memory) + rset = RadioSetting("initmem.right_memory", + "Right Bank Initial Mem Chan", rx) + basic.append(rset) + + stx = "" + for i in range(0, 16): + stx += chr(_cmnt.com[i]) + stx = stx.rstrip() + rx = RadioSettingValueString(0, 16, stx) + rset = RadioSetting("comment.com", "Comment (16 chars)", rx) + rset.set_apply_callback(myset_comment, _cmnt, "com", 16) + basic.append(rset) + + # --- Other + rset = RadioSetting("drv_clone_speed", "Use Hi-Speed Clone", + RadioSettingValueBoolean(self._can_hispeed)) + other.append(rset) + + options = ["Single", "All", "Ham"] + rx = RadioSettingValueList(options, options[_sets.actband]) + rset = RadioSetting("settings.actband", "Active Band", rx) + other.append(rset) + + options = ["Slow", "Mid", "Fast", "Auto"] + rx = RadioSettingValueList(options, options[_sets.fanspeed]) + rset = RadioSetting("settings.fanspeed", "Fan Speed", rx) + other.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.dialspdup)) + rset = RadioSetting("settings.dialspdup", "Dial Speed-Up", rx) + other.append(rset) + + options = ["Off", "On(Dup)", "On(Dup+Tone)"] + rx = RadioSettingValueList(options, options[_sets.autorptr]) + rset = RadioSetting("settings.autorptr", "Auto Repeater", rx) + other.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.rmtmic)) + rset = RadioSetting("settings.rmtmic", + "One-Touch PTT (Remote Mic)", rx) + other.append(rset) + + options = ["Low", "Mid", "High"] + rx = RadioSettingValueList(options, options[_sets.vhfpower]) + rset = RadioSetting("settings.vhfpower", "VHF Power Default", rx) + other.append(rset) + + rx = RadioSettingValueList(options, options[_sets.uhfpower]) + rset = RadioSetting("settings.uhfpower", "UHF Power Default", rx) + other.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.toneburst)) + rset = RadioSetting("settings.toneburst", "1750 Htz Tone Burst", rx) + other.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.ifxchg)) + rset = RadioSetting("settings.ifxchg", "IF Exchange", rx) + other.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.rpthangup)) + rset = RadioSetting("settings.rpthangup", + "Repeater Hang up Timeout", rx) + other.append(rset) + + stx = str(_sets.civaddr)[2:] # Hex value + rx = RadioSettingValueString(1, 2, stx) + rset = RadioSetting("settings.civaddr", "CI-V Address (90)", rx) + rset.set_apply_callback(hex_val, _sets, "civaddr") + other.append(rset) + + options = ["1200", "2400", "4800", "9600", "19200", "Auto"] + rx = RadioSettingValueList(options, options[_sets.civbaud]) + rset = RadioSetting("settings.civbaud", "CI-V Baud Rate (bps)", rx) + other.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.civtcvr)) + rset = RadioSetting("settings.civtcvr", "CI-V Transceive", rx) + other.append(rset) + + # A/B Band Settings + options = ["Off", "On", "Bell"] + rx = RadioSettingValueList(options, options[_sets.aprichn]) + rset = RadioSetting("settings.aprichn", + "A Band: VFO Priority Watch Mode", rx) + abset.append(rset) + + options = ["2", "4", "6", "8", "10", "12", "14", + "16", "18", "20", "Hold"] + rx = RadioSettingValueList(options, options[_sets.ascanpause]) + rset = RadioSetting("settings.ascanpause", + "-- A Band: Scan Pause Time (Secs)", rx) + abset.append(rset) + + options = ["0", "1", "2", "3", "4", "5", "Hold"] + rx = RadioSettingValueList(options, options[_sets.ascanresume]) + rset = RadioSetting("settings.ascanresume", + "-- A Band: Scan Resume Time (Secs)", rx) + abset.append(rset) + + options = ["5", "10", "15"] + rx = RadioSettingValueList(options, options[_sets.atmpskiptym]) + rset = RadioSetting("settings.atmpskiptym", + "-- A Band: Temp Skip Time (Secs)", rx) + abset.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.aprgskpscn)) + rset = RadioSetting("settings.aprgskpscn", + "-- A Band: Program Skip Scan", rx) + abset.append(rset) + + rx = RadioSettingValueString(10, 10, banklink(_bklk.alnk)) + rset = RadioSetting("banklink.alnk", + "-- A Band Banklink (use _ to skip)", rx) + rset.set_apply_callback(myset_banklink, _bklk, "alnk") + abset.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.awxalert)) + rset = RadioSetting("settings.awxalert", + "-- A Band: Weather Alert", rx) + abset.append(rset) + + # Use list for Wx chans since chan 1 = index 0 + options = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"] + rx = RadioSettingValueList(options, options[_wxch.awxchan]) + rset = RadioSetting("abwx.awxchan", "-- A Band: Weather Channel", rx) + abset.append(rset) + + options = ["Off", "On", "Bell"] + rx = RadioSettingValueList(options, options[_sets.bprichn]) + rset = RadioSetting("settings.bprichn", + "B Band: VFO Priority Watch Mode", rx) + abset.append(rset) + + options = ["2", "4", "6", "8", "10", "12", "14", + "16", "18", "20", "Hold"] + rx = RadioSettingValueList(options, options[_sets.bscanpause]) + rset = RadioSetting("settings.bscanpause", + "-- B Band: Scan Pause Time (Secs)", rx) + abset.append(rset) + + options = ["0", "1", "2", "3", "4", "5", "Hold"] + rx = RadioSettingValueList(options, options[_sets.bscanresume]) + rset = RadioSetting("settings.bscanresume", + "-- B Band: Scan Resume Time (Secs)", rx) + abset.append(rset) + + options = ["5", "10", "15"] + rx = RadioSettingValueList(options, options[_sets.btmpskiptym]) + rset = RadioSetting("settings.btmpskiptym", + "-- B Band: Temp Skip Time (Secs)", rx) + abset.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.bprgskpscn)) + rset = RadioSetting("settings.bprgskpscn", + "-- B Band: Program Skip Scan", rx) + abset.append(rset) + + rx = RadioSettingValueString(10, 10, banklink(_bklk.blnk)) + rset = RadioSetting("banklink.blnk", + "-- B Band Banklink (use _ to skip)", rx) + rset.set_apply_callback(myset_banklink, _bklk, "blnk") + abset.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.bwxalert)) + rset = RadioSetting("settings.bwxalert", + "-- B Band: Weather Alert", rx) + abset.append(rset) + + options = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"] + rx = RadioSettingValueList(options, options[_wxch.bwxchan]) + rset = RadioSetting("abwx.bwxchan", "-- B Band: Weather Channel", rx) + abset.append(rset) + + # --- Microphone Keys + # The Mic keys get wierd: stored values are indecis to the full + # options list, but only a subset is valid... + shortopts = ["Off", "Monitor", "MR (Ch 0)", "MR (Ch 1)", "Band/Bank", + "Scan", "Temp Skip", "Mode", "Low", "Dup", "Priority", + "Tone", "MW", "Mute", "DTMF Direct", "T-Call"] + ptr = shortopts.index(MICKEYOPTS[_sets.mickyrxf1]) + rx = RadioSettingValueList(shortopts, shortopts[ptr]) + rset = RadioSetting("settings.mickyrxf1", + "During Rx/Standby [F-1]", rx) + rset.set_apply_callback(mic_keys, _sets, "mickyrxf1") + mickey.append(rset) + + ptr = shortopts.index(MICKEYOPTS[_sets.mickyrxf2]) + rx = RadioSettingValueList(shortopts, shortopts[ptr]) + rset = RadioSetting("settings.mickyrxf2", + "During Rx/Standby [F-2]", rx) + rset.set_apply_callback(mic_keys, _sets, "mickyrxf2") + mickey.append(rset) + + options = ["Off", "Low", "T-Call"] # NOT a subset of MICKEYOPTS + rx = RadioSettingValueList(options, options[_sets.mickytxf1]) + rset = RadioSetting("settings.mickytxf1", "During Tx [F-1]", rx) + mickey.append(rset) + + rx = RadioSettingValueList(options, options[_sets.mickytxf2]) + rset = RadioSetting("settings.mickytxf2", "During Tx [F-2]", rx) + mickey.append(rset) + + # These next two get the full options list + rx = RadioSettingValueList(MICKEYOPTS, MICKEYOPTS[_sets.mickyrxup]) + rset = RadioSetting("settings.mickyrxup", + "During Rx/Standby [Up]", rx) + mickey.append(rset) + + rx = RadioSettingValueList(MICKEYOPTS, MICKEYOPTS[_sets.mickyrxdn]) + rset = RadioSetting("settings.mickyrxdn", + "During Rx/Standby [Down]", rx) + mickey.append(rset) + + options = ["Off", "Low", "T-Call"] + rx = RadioSettingValueList(options, options[_sets.mickytxup]) + rset = RadioSetting("settings.mickytxup", "During Tx [Up]", rx) + mickey.append(rset) + + rx = RadioSettingValueList(options, options[_sets.mickytxdn]) + rset = RadioSetting("settings.mickytxdn", "During Tx [Down]", rx) + mickey.append(rset) + + # --- Bluetooth + rx = RadioSettingValueBoolean(bool(_sets.btoothon)) + rset = RadioSetting("settings.btoothon", "Bluetooth", rx) + bluet.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.btoothauto)) + rset = RadioSetting("settings.btoothauto", "Auto Connect", rx) + bluet.append(rset) + + options = ["Headset Only", "Headset & Speaker"] + rx = RadioSettingValueList(options, options[_sets.bthdset]) + rset = RadioSetting("settings.bthdset", "Headset Audio", rx) + bluet.append(rset) + + options = ["Normal", "Microphone", "PTT (Audio:Main)", + "PTT(Audio:Controller)"] + rx = RadioSettingValueList(options, options[_sets.bthfctn]) + rset = RadioSetting("settings.bthfctn", "Headset Function", rx) + bluet.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.bthvox)) + rset = RadioSetting("settings.bthvox", "Vox", rx) + bluet.append(rset) + + options = ["Off", "1.0", "2", "3", "4", "5", "6", "7", "8", "9", "10"] + rx = RadioSettingValueList(options, options[_sets.bthvoxlvl]) + rset = RadioSetting("settings.bthvoxlvl", "Vox Level", rx) + bluet.append(rset) + + options = ["0.5", "1.0", "1.5", "2.0", "2.5", "3.0"] + rx = RadioSettingValueList(options, options[_sets.bthvoxdly]) + rset = RadioSetting("settings.bthvoxdly", "Vox Delay (Secs)", rx) + bluet.append(rset) + + options = ["Off", "1", "2", "3", "4", "5", "10", "15"] + rx = RadioSettingValueList(options, options[_sets.bthvoxtot]) + rset = RadioSetting("settings.bthvoxtot", "Vox Time-Out (Mins)", rx) + bluet.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.bthhdpsav)) + rset = RadioSetting("settings.bthhdpsav", + "ICOM Headset Power-Save", rx) + bluet.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.bth1ptt)) + rset = RadioSetting("settings.bth1ptt", + "ICOM Headset One-Touch PTT", rx) + bluet.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.bthpttbeep)) + rset = RadioSetting("settings.bthpttbeep", + "ICOM Headset PTT Beep", rx) + bluet.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.bthcustbeep)) + rset = RadioSetting("settings.bthcustbeep", + "ICOM Headset Custom Key Beep", rx) + bluet.append(rset) + + rx = RadioSettingValueList(MICKEYOPTS, MICKEYOPTS[_sets.bthplaykey]) + rset = RadioSetting("settings.bthplaykey", + "ICOM Headset Custom Key [Play]", rx) + bluet.append(rset) + + rx = RadioSettingValueList(MICKEYOPTS, MICKEYOPTS[_sets.bthfwdkey]) + rset = RadioSetting("settings.bthfwdkey", + "ICOM Headset Custom Key [Fwd]", rx) + bluet.append(rset) + + rx = RadioSettingValueList(MICKEYOPTS, MICKEYOPTS[_sets.bthrwdkey]) + rset = RadioSetting("settings.bthrwdkey", + "ICOM Headset Custom Key [Rwd]", rx) + bluet.append(rset) + + # ---- Display + options = ["1: Dark", "2", "3", "4: Bright"] + rx = RadioSettingValueList(options, options[_sets.backlight]) + rset = RadioSetting("settings.backlight", "Backlight Level", rx) + disp.append(rset) + + options = ["Off", "Auto-Off", "Auto-1", "Auto-2", "Auto-3"] + rx = RadioSettingValueList(options, options[_sets.autodim]) + rset = RadioSetting("settings.autodim", "Auto Dimmer", rx) + disp.append(rset) + + options = ["5", "10"] + rx = RadioSettingValueList(options, options[_sets.autodimtot]) + rset = RadioSetting("settings.autodimtot", + "Auto-Dimmer Timeout (Secs)", rx) + disp.append(rset) + + options = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"] + rx = RadioSettingValueList(options, options[_sets.contrast]) + rset = RadioSetting("settings.contrast", "LCD Contrast", rx) + disp.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.openmsg)) + rset = RadioSetting("settings.openmsg", "Opening Message", rx) + disp.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.memname)) + rset = RadioSetting("settings.memname", "Memory Names", rx) + disp.append(rset) + + options = ["CH ID", "Frequency"] + rx = RadioSettingValueList(options, options[_sets.airbandch]) + rset = RadioSetting("settings.airbandch", "Air Band Display", rx) + disp.append(rset) + + # -- Sounds + rx = RadioSettingValueInteger(0, 9, _sets.beeplvl) + rset = RadioSetting("settings.beeplvl", "Beep Level", rx) + sound.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.homebeep)) + rset = RadioSetting("settings.homebeep", "Home Chan Beep", rx) + sound.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.keybeep)) + rset = RadioSetting("settings.keybeep", "Key Touch Beep", rx) + sound.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.bandedgbeep)) + rset = RadioSetting("settings.bandedgbeep", "Band Edge Beep", rx) + sound.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.scanstpbeep)) + rset = RadioSetting("settings.scanstpbeep", "Scan Stop Beep", rx) + sound.append(rset) + + options = ["Off", "Mute", "Beep", "Mute & Beep"] + rx = RadioSettingValueList(options, options[_sets.subandmute]) + rset = RadioSetting("settings.subandmute", "Sub Band Mute", rx) + sound.append(rset) + + # --- DTMF Codes + options = ["100", "200", "300", "500"] + rx = RadioSettingValueList(options, options[_sets.dtmfspd]) + rset = RadioSetting("settings.dtmfspd", "DTMF Speed (mSecs)", rx) + dtmf.append(rset) + + for kx in range(0, 16): + stx = unpack_str(_dtm[kx].codes) + rx = RadioSettingValueString(0, 24, stx) + # NOTE the / to indicate indexed array + rset = RadioSetting("dtmfcode/%d.codes" % kx, + "DTMF Code %X" % kx, rx) + rset.set_apply_callback(pack_chars, _dtm, "codes", kx) + dtmf.append(rset) + + # --- Program Scan Edges + for kx in range(0, 25): + stx = "" + for i in range(0, 6): + stx += chr(_pses[kx].name[i]) + stx = stx.rstrip() + rx = RadioSettingValueString(0, 6, stx) + rset = RadioSetting("pgmscanedge/%d.name" % kx, + "Program Scan %d Name" % kx, rx) + rset.set_apply_callback(myset_psnam, _pses, kx, "name", 6) + edges.append(rset) + + # Freq's use the multiplier flags + fmult = 5000.0 + if _pses[kx].loflags == 0x10: + fmult = 8333 + if _pses[kx].loflags == 0x08: + fmult = 6250.0 + flow = (int(_pses[kx].lofreq) * fmult) / 1000000.0 + flow = round(flow, 4) + + fmult = 5000.0 + if _pses[kx].hiflags == 0x10: + fmult = 8333 + if _pses[kx].hiflags == 0x08: + fmult = 6250.0 + fhigh = (int(_pses[kx].hifreq) * fmult) / 1000000.0 + fhigh = round(fhigh, 4) + if (flow > 0) and (flow >= fhigh): # reverse em + val = flow + flow = fhigh + fhigh = val + rx = RadioSettingValueFloat(0, 550.0, flow, 0.010, 3) + rset = RadioSetting("pgmscanedge/%d.lofreq" % kx, + "-- Scan %d Low Limit" % kx, rx) + rset.set_apply_callback(myset_frqflgs, _pses, kx, "loflags", + "lofreq") + edges.append(rset) + + rx = RadioSettingValueFloat(0, 550.0, fhigh, 0.010, 3) + rset = RadioSetting("pgmscanedge/%d.hifreq" % kx, + "-- Scan %d High Limit" % kx, rx) + rset.set_apply_callback(myset_frqflgs, _pses, kx, "hiflags", + "hifreq") + edges.append(rset) + + # Tstep and Mode depend on the bands + ndxt = 0 + ndxm = 0 + bxnd = 0 + tsopt = ["-", "5k", "6.25k", "10k", "12.5k", "15k", + "20k", "25k", "30k", "50k"] + mdopt = ["-", "FM", "FM-N"] + if fhigh > 0: + if fhigh < 135.0: # Air band + bxnd = 1 + tsopt = ["-", "8.33k", "25k", "Auto"] + ndxt = _pses[kx].tstp + if ndxt == 0xe: # Auto + ndxt = 3 + elif ndxt == 8: # 25k + ndxt = 2 + elif ndxt == 2: # 8.33k + ndxt = 1 + else: + ndxt = 0 + mdopt = ["-"] + elif (flow >= 137.0) and (fhigh <= 174.0): # VHF + ndxt = _pses[kx].tstp - 1 + ndxm = _pses[kx].mode + 1 + bxnd = 2 + elif (flow >= 375.0) and (fhigh <= 550.0): # UHF + ndxt = _pses[kx].tstp - 1 + ndxm = _pses[kx].mode + 1 + bxnd = 3 + else: # Mixed, ndx's = 0 default + tsopt = ["-"] + mdopt = ["-"] + bxnd = 4 + if (ndxt > 9) or (ndxt < 0): + ndxt = 0 # trap ff + if ndxm > 2: + ndxm = 0 + # end if fhigh > 0 + rx = RadioSettingValueList(tsopt, tsopt[ndxt]) + rset = RadioSetting("pgmscanedge/%d.tstp" % kx, + "-- Scan %d Freq Step" % kx, rx) + rset.set_apply_callback(myset_tsopt, _pses, kx, "tstp", bxnd) + edges.append(rset) + + rx = RadioSettingValueList(mdopt, mdopt[ndxm]) + rset = RadioSetting("pgmscanedge/%d.mode" % kx, + "-- Scan %d Mode" % kx, rx) + rset.set_apply_callback(myset_mdopt, _pses, kx, "mode", bxnd) + edges.append(rset) + # End for kx + + # --- Program Scan Links + _psln = self._memobj.pslnam + _pslg = self._memobj.pslgrps + for kx in range(0, 10): + stx = "" + for i in range(0, 6): + stx += chr(_psln[kx].nam[i]) + stx = stx.rstrip() + rx = RadioSettingValueString(0, 6, stx) + rset = RadioSetting("pslnam/%d.nam" % kx, + "Program Scan Link %d Name" % kx, rx) + rset.set_apply_callback(myset_psnam, _psln, kx, "nam", 6) + pslnk.append(rset) + + for px in range(0, 25): + # Generate string numeric representation of 4-byte bitmask + stx = "" + for nx in range(0, 25): + if nx < 8: + if (_pslg[kx].msk[0] & (1 << nx)): + stx += "%0d, " % nx + elif (nx >= 8) and (nx < 16): + if (_pslg[kx].msk[1] & (1 << (nx - 8))): + sstx += "%0d, " % nx + elif (nx >= 16) and (nx < 24): + if (_pslg[kx].msk[2] & (1 << (nx - 16))): + stx += "%0d, " % nx + elif (nx >= 24): + if (_pslg[kx].msk[3] & (1 << (nx - 24))): + stx += "%0d, " % nx + rx = RadioSettingValueString(0, 80, stx) + rset = RadioSetting("pslgrps/%d.msk" % kx, + "--- Scan Link %d Scans" % kx, rx) + rset.set_apply_callback(myset_bitmask, _pslg, + kx, "msk", 25) + pslnk.append(rset) + # end for px + # End for kx + return group # END get_settings() + + def set_settings(self, settings): + _settings = self._memobj.settings + _mem = self._memobj + for element in settings: + if not isinstance(element, RadioSetting): + self.set_settings(element) + continue + else: + try: + name = element.get_name() + if "." in name: + bits = name.split(".") + obj = self._memobj + for bit in bits[:-1]: + if "/" in bit: + bit, index = bit.split("/", 1) + index = int(index) + obj = getattr(obj, bit)[index] + else: + obj = getattr(obj, bit) + setting = bits[-1] + else: + obj = _settings + setting = element.get_name() + + if element.has_apply_callback(): + LOG.debug("Using apply callback") + element.run_apply_callback() + elif element.get_name() == "drv_clone_speed": + val = element.value.get_value() + self.__class__._can_hispeed = val + elif element.value.get_mutable(): + LOG.debug("Setting %s = %s" % (setting, element.value)) + setattr(obj, setting, element.value) + except Exception, e: + LOG.debug(element.get_name()) + raise diff --git a/chirp/drivers/icx8x.py b/chirp/drivers/icx8x.py index 4564f89..9958ec1 100644 --- a/chirp/drivers/icx8x.py +++ b/chirp/drivers/icx8x.py @@ -21,9 +21,9 @@ from chirp import chirp_common, errors, directory LOG = logging.getLogger(__name__) -def _isuhf(pipe): +def _isuhf(radio): try: - md = icf.get_model_data(pipe) + md = icf.get_model_data(radio) val = ord(md[20]) uhf = val & 0x10 except: @@ -87,7 +87,7 @@ class ICx8xRadio(icf.IcomCloneModeRadio, chirp_common.IcomDstarSupport): return rf def _get_type(self): - flag = (_isuhf(self.pipe) != 0) + flag = (_isuhf(self) != 0) if self._isuhf is not None and (self._isuhf != flag): raise errors.RadioError("VHF/UHF model mismatch") diff --git a/chirp/drivers/kguv8d.py b/chirp/drivers/kguv8d.py index bd7aa84..5fe16b4 100644 --- a/chirp/drivers/kguv8d.py +++ b/chirp/drivers/kguv8d.py @@ -464,6 +464,7 @@ class KGUV8DRadio(chirp_common.CloneModeRadio, rf.can_odd_split = True rf.valid_skips = ["", "S"] rf.valid_tmodes = ["", "Tone", "TSQL", "DTCS", "Cross"] + rf.valid_tuning_steps = STEPS rf.valid_cross_modes = [ "Tone->Tone", "Tone->DTCS", diff --git a/chirp/drivers/kguv8e.py b/chirp/drivers/kguv8e.py new file mode 100644 index 0000000..b76f0e5 --- /dev/null +++ b/chirp/drivers/kguv8e.py @@ -0,0 +1,1146 @@ +# Copyright 2019 Pavel Milanes CO7WT <pavelmc@gmail.com> +# +# Based on the work of Krystian Struzik <toner_82@tlen.pl> +# who figured out the crypt used and made possible the +# Wuoxun KG-UV8D Plus driver, in which this work is based. +# +# 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/>. + +"""Wouxun KG-UV8E radio management module""" + +import time +import os +import logging +from chirp import util, chirp_common, bitwise, memmap, errors, directory +from chirp.settings import RadioSetting, RadioSettingGroup, \ + RadioSettingValueBoolean, RadioSettingValueList, \ + RadioSettingValueInteger, RadioSettingValueString, \ + RadioSettings + +LOG = logging.getLogger(__name__) + +CMD_ID = 128 +CMD_END = 129 +CMD_RD = 130 +CMD_WR = 131 + +MEM_VALID = 158 + +AB_LIST = ["A", "B"] +STEPS = [2.5, 5.0, 6.25, 10.0, 12.5, 25.0, 50.0, 100.0] +STEP_LIST = [str(x) for x in STEPS] +ROGER_LIST = ["Off", "Begin", "End", "Both"] +TIMEOUT_LIST = ["Off"] + [str(x) + "s" for x in range(15, 901, 15)] +VOX_LIST = ["Off"] + ["%s" % x for x in range(1, 10)] +BANDWIDTH_LIST = ["Narrow", "Wide"] +VOICE_LIST = ["Off", "On"] +LANGUAGE_LIST = ["Chinese", "English"] +SCANMODE_LIST = ["TO", "CO", "SE"] +PF1KEY_LIST = ["Call", "VFTX"] +PF3KEY_LIST = ["Disable", "Scan", "Lamp", "Tele Alarm", "SOS-CH", "Radio"] +WORKMODE_LIST = ["VFO", "Channel No.", "Ch. No.+Freq.", "Ch. No.+Name"] +BACKLIGHT_LIST = ["Always On"] + [str(x) + "s" for x in range(1, 21)] + \ + ["Always Off"] +OFFSET_LIST = ["+", "-"] +PONMSG_LIST = ["Bitmap", "Battery Volts"] +SPMUTE_LIST = ["QT", "QT+DTMF", "QT*DTMF"] +DTMFST_LIST = ["DT-ST", "ANI-ST", "DT-ANI", "Off"] +DTMF_TIMES = ["%s" % x for x in range(50, 501, 10)] +RPTSET_LIST = ["", "X-DIRRPT", "X-TWRPT"] # TODO < what is index 0? +ALERTS = [1750, 2100, 1000, 1450] +ALERTS_LIST = [str(x) for x in ALERTS] +PTTID_LIST = ["Begin", "End", "Both"] +LIST_10 = ["Off"] + ["%s" % x for x in range(1, 11)] +SCANGRP_LIST = ["All"] + ["%s" % x for x in range(1, 11)] +SCQT_LIST = ["Decoder", "Encoder", "All"] +SMUTESET_LIST = ["Off", "Tx", "Rx", "Tx/Rx"] +POWER_LIST = ["Lo", "Hi"] +HOLD_TIMES = ["Off"] + ["%s" % x for x in range(100, 5001, 100)] +RPTMODE_LIST = ["Radio", "Repeater"] + +# memory slot 0 is not used, start at 1 (so need 1000 slots, not 999) +# structure elements whose name starts with x are currently unidentified + +_MEM_FORMAT = """ + #seekto 0x0030; + struct { + u32 rx_start; + u32 rx_stop; + u32 tx_start; + u32 tx_stop; + } vhf1_limits; + + #seekto 0x0044; + struct { + u32 rx_start; + u32 rx_stop; + u32 tx_start; + u32 tx_stop; + } uhf_limits; + + #seekto 0x0054; + struct { + u32 rx_start; + u32 rx_stop; + u32 tx_start; + u32 tx_stop; + } vhf_limits; + + #seekto 0x0400; + struct { + u8 oem1[8]; + u8 unknown[2]; + u8 unknown2[10]; + u8 unknown3[10]; + u8 unknown4[8]; + u8 model[10]; + u8 version[6]; + u8 date[8]; + u8 unknown5[1]; + u8 oem2[8]; + } oem_info; + + #seekto 0x0480; + struct { + u16 lower; + u16 upper; + } scan_groups[10]; + + #seekto 0x0500; + struct { + u8 call_code[6]; + } call_groups[20]; + + #seekto 0x0580; + struct { + char call_name[6]; + } call_group_name[20]; + + #seekto 0x0800; + struct { + u8 ponmsg; + char dispstr[15]; + u8 x0810; + u8 x0811; + u8 x0812; + u8 x0813; + u8 x0814; + u8 voice; + u8 timeout; + u8 toalarm; + u8 channel_menu; + u8 power_save; + u8 autolock; + u8 keylock; + u8 beep; + u8 stopwatch; + u8 vox; + u8 scan_rev; + u8 backlight; + u8 roger_beep; + u8 x0822[6]; + u8 x0823[6]; + u16 pri_ch; + u8 ani_sw; + u8 ptt_delay; + u8 ani_code[6]; + u8 dtmf_st; + u8 bcl_a; + u8 bcl_b; + u8 ptt_id; + u8 prich_sw; + u8 rpt_set; + u8 rpt_spk; + u8 rpt_ptt; + u8 alert; + u8 pf1_func; + u8 pf3_func; + u8 x0843; + u8 workmode_a; + u8 workmode_b; + u8 dtmf_tx_time; + u8 dtmf_interval; + u8 main_ab; + u16 work_cha; + u16 work_chb; + u8 x084d; + u8 x084e; + u8 x084f; + u8 x0850; + u8 x0851; + u8 x0852; + u8 x0853; + u8 x0854; + u8 rpt_mode; + u8 language; + u8 x0857; + u8 x0858; + u8 x0859; + u8 x085a; + u8 x085b; + u8 x085c; + u8 x085d; + u8 x085e; + u8 single_display; + u8 ring_time; + u8 scg_a; + u8 scg_b; + u8 x0863; + u8 rpt_tone; + u8 rpt_hold; + u8 scan_det; + u8 sc_qt; + u8 x0868; + u8 smuteset; + u8 callcode; + } settings; + + #seekto 0x0880; + struct { + u32 rxfreq; + u32 txoffset; + u16 rxtone; + u16 txtone; + u8 scrambler:4, + unknown1:2, + power:1, + unknown2:1; + u8 unknown3:1, + shift_dir:2 + unknown4:1, + compander:1, + mute_mode:2, + iswide:1; + u8 step; + u8 squelch; + } vfoa; + + #seekto 0x08c0; + struct { + u32 rxfreq; + u32 txoffset; + u16 rxtone; + u16 txtone; + u8 scrambler:4, + unknown1:2, + power:1, + unknown2:1; + u8 unknown3:1, + shift_dir:2 + unknown4:1, + compander:1, + mute_mode:2, + iswide:1; + u8 step; + u8 squelch; + } vfob; + + #seekto 0x0900; + struct { + u32 rxfreq; + u32 txfreq; + u16 rxtone; + u16 txtone; + u8 scrambler:4, + unknown1:2, + power:1, + unknown2:1; + u8 unknown3:2, + scan_add:1, + unknown4:1, + compander:1, + mute_mode:2, + iswide:1; + u16 padding; + } memory[1000]; + + #seekto 0x4780; + struct { + u8 name[8]; + u8 unknown[4]; + } names[1000]; + + #seekto 0x7670; + u8 valid[1000]; + """ + + # Support for the Wouxun KG-UV8E radio + # Serial coms are at 19200 baud + # The data is passed in variable length records + # Record structure: + # Offset Usage + # 0 start of record (\x7a) + # 1 Command (\x80 Identify \x81 End/Reboot \x82 Read \x83 Write) + # 2 direction (\xff PC-> Radio, \x00 Radio -> PC) + # 3 length of payload (excluding header/checksum) (n) + # 4 payload (n bytes) + # 4+n+1 checksum - byte sum (% 256) of bytes 1 -> 4+n + # + # Memory Read Records: + # the payload is 3 bytes, first 2 are offset (big endian), + # 3rd is number of bytes to read + # Memory Write Records: + # the maximum payload size (from the Wouxun software) seems to be 66 bytes + # (2 bytes location + 64 bytes data). + +@directory.register +class KGUV8ERadio(chirp_common.CloneModeRadio, + chirp_common.ExperimentalRadio): + + """Wouxun KG-UV8E""" + VENDOR = "Wouxun" + MODEL = "KG-UV8E" + _model = "KG-UV8D-A" + _file_ident = "kguv8e" # lowercase + BAUD_RATE = 19200 + POWER_LEVELS = [chirp_common.PowerLevel("L", watts=1), + chirp_common.PowerLevel("H", watts=5)] + _mmap = "" + + def _checksum(self, data): + cs = 0 + for byte in data: + cs += ord(byte) + return chr(cs % 256) + + def _write_record(self, cmd, payload = None): + # build the packet + _header = '\x7b' + chr(cmd) + '\xff' + + _length = 0 + if payload: + _length = len(payload) + + # update the length field + _header += chr(_length) + + if payload: + # calculate checksum then add it with the payload to the packet and encrypt + crc = self._checksum(_header[1:] + payload) + payload += crc + _header += self.encrypt(payload) + else: + # calculate and add encrypted checksum to the packet + crc = self._checksum(_header[1:]) + _header += self.strxor(crc, '\x57') + + try: + self.pipe.write(_header) + except Exception, e: + raise errors.RadioError("Failed to communicate with radio: %s" % e) + + def _read_record(self): + # read 4 chars for the header + _header = self.pipe.read(4) + if len(_header) != 4: + raise errors.RadioError('Radio did not respond') + _length = ord(_header[3]) + _packet = self.pipe.read(_length) + _rcs_xor = _packet[-1] + _packet = self.decrypt(_packet) + _cs = ord(self._checksum(_header[1:] + _packet)) + # read the checksum and decrypt it + _rcs = ord(self.strxor(self.pipe.read(1), _rcs_xor)) + return (_rcs != _cs, _packet) + + def decrypt(self, data): + result = '' + for i in range(len(data)-1, 0, -1): + result += self.strxor(data[i], data[i - 1]) + result += self.strxor(data[0], '\x57') + return result[::-1] + + def encrypt(self, data): + result = self.strxor('\x57', data[0]) + for i in range(1, len(data), 1): + result += self.strxor(result[i - 1], data[i]) + return result + + def strxor (self, xora, xorb): + return chr(ord(xora) ^ ord(xorb)) + + # Identify the radio + # + # A Gotcha: the first identify packet returns a bad checksum, subsequent + # attempts return the correct checksum... (well it does on my radio!) + # + # The ID record returned by the radio also includes the current frequency range + # as 4 bytes big-endian in 10Hz increments + # + # Offset + # 0:10 Model, zero padded (Use first 7 chars for 'KG-UV8D') + # 11:14 UHF rx lower limit (in units of 10Hz) + # 15:18 UHF rx upper limit + # 19:22 UHF tx lower limit + # 23:26 UHF tx upper limit + # 27:30 VHF rx lower limit + # 31:34 VHF rx upper limit + # 35:38 VHF tx lower limit + # 39:42 VHF tx upper limit + + @classmethod + def match_model(cls, filedata, filename): + id = cls._file_ident + return cls._file_ident in 'kg' + filedata[0x426:0x430].replace('(', '').replace(')', '').lower() + + def _identify(self): + """Do the identification dance""" + for _i in range(0, 10): + self._write_record(CMD_ID) + _chksum_err, _resp = self._read_record() + LOG.debug("Got:\n%s" % util.hexprint(_resp)) + if _chksum_err: + LOG.error("Checksum error: retrying ident...") + time.sleep(0.100) + continue + LOG.debug("Model %s" % util.hexprint(_resp[0:9])) + if _resp[0:9] == self._model: + return + if len(_resp) == 0: + raise Exception("Radio not responding") + else: + raise Exception("Unable to identify radio") + + def _finish(self): + self._write_record(CMD_END) + + def process_mmap(self): + self._memobj = bitwise.parse(_MEM_FORMAT, self._mmap) + + def sync_in(self): + try: + self._mmap = self._download() + except errors.RadioError: + raise + except Exception, e: + raise errors.RadioError("Failed to communicate with radio: %s" % e) + self.process_mmap() + + def sync_out(self): + self._upload() + + # TODO: Load all memory. + # It would be smarter to only load the active areas and none of + # the padding/unused areas. Padding still need to be investigated. + def _download(self): + """Talk to a wouxun KG-UV8E and do a download""" + try: + self._identify() + return self._do_download(0, 32768, 64) + except errors.RadioError: + raise + except Exception, e: + LOG.exception('Unknown error during download process') + raise errors.RadioError("Failed to communicate with radio: %s" % e) + + def _do_download(self, start, end, blocksize): + # allocate & fill memory + image = "" + for i in range(start, end, blocksize): + req = chr(i / 256) + chr(i % 256) + chr(blocksize) + self._write_record(CMD_RD, req) + cs_error, resp = self._read_record() + if cs_error: + LOG.debug(util.hexprint(resp)) + raise Exception("Checksum error on read") + LOG.debug("Got:\n%s" % util.hexprint(resp)) + image += resp[2:] + if self.status_fn: + status = chirp_common.Status() + status.cur = i + status.max = end + status.msg = "Cloning from radio" + self.status_fn(status) + self._finish() + return memmap.MemoryMap(''.join(image)) + + def _upload(self): + """Talk to a wouxun KG-UV8E and do a upload""" + try: + self._identify() + self._do_upload(0, 32768, 64) + except errors.RadioError: + raise + except Exception, e: + raise errors.RadioError("Failed to communicate with radio: %s" % e) + return + + def _do_upload(self, start, end, blocksize): + ptr = start + for i in range(start, end, blocksize): + req = chr(i / 256) + chr(i % 256) + chunk = self.get_mmap()[ptr:ptr + blocksize] + self._write_record(CMD_WR, req + chunk) + # ~ LOG.debug(util.hexprint(req + chunk)) + cserr, ack = self._read_record() + # ~ LOG.debug(util.hexprint(ack)) + j = ord(ack[0]) * 256 + ord(ack[1]) + if cserr or j != ptr: + raise Exception("Radio did not ack block %i" % ptr) + ptr += blocksize + if self.status_fn: + status = chirp_common.Status() + status.cur = i + status.max = end + status.msg = "Cloning to radio" + self.status_fn(status) + self._finish() + + def get_features(self): + rf = chirp_common.RadioFeatures() + rf.has_settings = True + rf.has_ctone = True + rf.has_rx_dtcs = True + rf.has_cross = True + rf.has_tuning_step = False + rf.has_bank = False + rf.can_odd_split = True + rf.valid_skips = ["", "S"] + rf.valid_tmodes = ["", "Tone", "TSQL", "DTCS", "Cross"] + rf.valid_cross_modes = [ + "Tone->Tone", + "Tone->DTCS", + "DTCS->Tone", + "DTCS->", + "->Tone", + "->DTCS", + "DTCS->DTCS", + ] + rf.valid_modes = ["FM", "NFM"] + rf.valid_power_levels = self.POWER_LEVELS + rf.valid_name_length = 8 + rf.valid_duplexes = ["", "-", "+", "split", "off"] + rf.valid_bands = [(134000000, 175000000), # supports 2m + (220000000, 260000000), # supports 1.25m + (400000000, 520000000)] # supports 70cm + rf.valid_characters = chirp_common.CHARSET_ASCII + rf.memory_bounds = (1, 999) # 999 memories + rf.valid_tuning_steps = STEPS + return rf + + @classmethod + def get_prompts(cls): + rp = chirp_common.RadioPrompts() + rp.experimental = \ + ('This driver is experimental.\n' + '\n' + 'Please keep a copy of your memories with the original software ' + 'if you treasure them, this driver is new and may contain' + ' bugs.\n' + '\n' + ) + return rp + + def get_raw_memory(self, number): + return repr(self._memobj.memory[number]) + + def _get_tone(self, _mem, mem): + def _get_dcs(val): + code = int("%03o" % (val & 0x07FF)) + pol = (val & 0x8000) and "R" or "N" + return code, pol + + tpol = False + if _mem.txtone != 0xFFFF and (_mem.txtone & 0x2800) == 0x2800: + tcode, tpol = _get_dcs(_mem.txtone) + mem.dtcs = tcode + txmode = "DTCS" + elif _mem.txtone != 0xFFFF and _mem.txtone != 0x0: + mem.rtone = (_mem.txtone & 0x7fff) / 10.0 + txmode = "Tone" + else: + txmode = "" + + rpol = False + if _mem.rxtone != 0xFFFF and (_mem.rxtone & 0x2800) == 0x2800: + rcode, rpol = _get_dcs(_mem.rxtone) + mem.rx_dtcs = rcode + rxmode = "DTCS" + elif _mem.rxtone != 0xFFFF and _mem.rxtone != 0x0: + mem.ctone = (_mem.rxtone & 0x7fff) / 10.0 + rxmode = "Tone" + else: + rxmode = "" + + if txmode == "Tone" and not rxmode: + mem.tmode = "Tone" + elif txmode == rxmode and txmode == "Tone" and mem.rtone == mem.ctone: + mem.tmode = "TSQL" + elif txmode == rxmode and txmode == "DTCS" and mem.dtcs == mem.rx_dtcs: + mem.tmode = "DTCS" + elif rxmode or txmode: + mem.tmode = "Cross" + mem.cross_mode = "%s->%s" % (txmode, rxmode) + + # always set it even if no dtcs is used + mem.dtcs_polarity = "%s%s" % (tpol or "N", rpol or "N") + + LOG.debug("Got TX %s (%i) RX %s (%i)" % + (txmode, _mem.txtone, rxmode, _mem.rxtone)) + + def get_memory(self, number): + _mem = self._memobj.memory[number] + _nam = self._memobj.names[number] + + mem = chirp_common.Memory() + mem.number = number + _valid = self._memobj.valid[mem.number] + LOG.debug("%d %s", number, _valid == MEM_VALID) + if _valid != MEM_VALID: + mem.empty = True + return mem + else: + mem.empty = False + + mem.freq = int(_mem.rxfreq) * 10 + + if _mem.txfreq == 0xFFFFFFFF: + # TX freq not set + mem.duplex = "off" + mem.offset = 0 + elif int(_mem.rxfreq) == int(_mem.txfreq): + mem.duplex = "" + mem.offset = 0 + elif abs(int(_mem.rxfreq) * 10 - int(_mem.txfreq) * 10) > 70000000: + mem.duplex = "split" + mem.offset = int(_mem.txfreq) * 10 + else: + mem.duplex = int(_mem.rxfreq) > int(_mem.txfreq) and "-" or "+" + mem.offset = abs(int(_mem.rxfreq) - int(_mem.txfreq)) * 10 + + for char in _nam.name: + if char != 0: + mem.name += chr(char) + mem.name = mem.name.rstrip() + + self._get_tone(_mem, mem) + + mem.skip = "" if bool(_mem.scan_add) else "S" + + mem.power = self.POWER_LEVELS[_mem.power] + mem.mode = _mem.iswide and "FM" or "NFM" + return mem + + def _set_tone(self, mem, _mem): + def _set_dcs(code, pol): + val = int("%i" % code, 8) + 0x2800 + if pol == "R": + val += 0x8000 + return val + + rx_mode = tx_mode = None + rxtone = txtone = 0x0000 + + if mem.tmode == "Tone": + tx_mode = "Tone" + rx_mode = None + txtone = int(mem.rtone * 10) + 0x8000 + elif mem.tmode == "TSQL": + rx_mode = tx_mode = "Tone" + rxtone = txtone = int(mem.ctone * 10) + 0x8000 + elif mem.tmode == "DTCS": + tx_mode = rx_mode = "DTCS" + txtone = _set_dcs(mem.dtcs, mem.dtcs_polarity[0]) + rxtone = _set_dcs(mem.dtcs, mem.dtcs_polarity[1]) + elif mem.tmode == "Cross": + tx_mode, rx_mode = mem.cross_mode.split("->") + if tx_mode == "DTCS": + txtone = _set_dcs(mem.dtcs, mem.dtcs_polarity[0]) + elif tx_mode == "Tone": + txtone = int(mem.rtone * 10) + 0x8000 + if rx_mode == "DTCS": + rxtone = _set_dcs(mem.rx_dtcs, mem.dtcs_polarity[1]) + elif rx_mode == "Tone": + rxtone = int(mem.ctone * 10) + 0x8000 + + _mem.rxtone = rxtone + _mem.txtone = txtone + + LOG.debug("Set TX %s (%i) RX %s (%i)" % + (tx_mode, _mem.txtone, rx_mode, _mem.rxtone)) + + def set_memory(self, mem): + number = mem.number + + _mem = self._memobj.memory[number] + _nam = self._memobj.names[number] + + if mem.empty: + _mem.set_raw("\x00" * (_mem.size() / 8)) + self._memobj.valid[number] = 0 + self._memobj.names[number].set_raw("\x00" * (_nam.size() / 8)) + return + + _mem.rxfreq = int(mem.freq / 10) + if mem.duplex == "off": + _mem.txfreq = 0xFFFFFFFF + elif mem.duplex == "split": + _mem.txfreq = int(mem.offset / 10) + elif mem.duplex == "off": + for i in range(0, 4): + _mem.txfreq[i].set_raw("\xFF") + elif mem.duplex == "+": + _mem.txfreq = int(mem.freq / 10) + int(mem.offset / 10) + elif mem.duplex == "-": + _mem.txfreq = int(mem.freq / 10) - int(mem.offset / 10) + else: + _mem.txfreq = int(mem.freq / 10) + _mem.scan_add = int(mem.skip != "S") + _mem.iswide = int(mem.mode == "FM") + # set the tone + self._set_tone(mem, _mem) + # set the scrambler and compander to off by default + _mem.scrambler = 0 + _mem.compander = 0 + # set the power + if mem.power: + _mem.power = self.POWER_LEVELS.index(mem.power) + else: + _mem.power = True + # set to mute mode to QT (not QT+DTMF or QT*DTMF) by default + _mem.mute_mode = 0 + + for i in range(0, len(_nam.name)): + if i < len(mem.name) and mem.name[i]: + _nam.name[i] = ord(mem.name[i]) + else: + _nam.name[i] = 0x0 + self._memobj.valid[mem.number] = MEM_VALID + + def _get_settings(self): + _settings = self._memobj.settings + _vfoa = self._memobj.vfoa + _vfob = self._memobj.vfob + cfg_grp = RadioSettingGroup("cfg_grp", "Configuration") + vfoa_grp = RadioSettingGroup("vfoa_grp", "VFO A Settings") + vfob_grp = RadioSettingGroup("vfob_grp", "VFO B Settings") + key_grp = RadioSettingGroup("key_grp", "Key Settings") + lmt_grp = RadioSettingGroup("lmt_grp", "Frequency Limits") + uhf_lmt_grp = RadioSettingGroup("uhf_lmt_grp", "UHF") + vhf_lmt_grp = RadioSettingGroup("vhf_lmt_grp", "VHF") + vhf1_lmt_grp = RadioSettingGroup("vhf1_lmt_grp", "VHF1") + oem_grp = RadioSettingGroup("oem_grp", "OEM Info") + + lmt_grp.append(vhf_lmt_grp); + lmt_grp.append(vhf1_lmt_grp); + lmt_grp.append(uhf_lmt_grp); + group = RadioSettings(cfg_grp, vfoa_grp, vfob_grp, + key_grp, lmt_grp, oem_grp) + + # + # Configuration Settings + # + rs = RadioSetting("channel_menu", "Menu available in channel mode", + RadioSettingValueBoolean(_settings.channel_menu)) + cfg_grp.append(rs) + rs = RadioSetting("ponmsg", "Poweron message", + RadioSettingValueList( + PONMSG_LIST, PONMSG_LIST[_settings.ponmsg])) + cfg_grp.append(rs) + rs = RadioSetting("voice", "Voice Guide", + RadioSettingValueBoolean(_settings.voice)) + cfg_grp.append(rs) + rs = RadioSetting("language", "Language", + RadioSettingValueList(LANGUAGE_LIST, + LANGUAGE_LIST[_settings. + language])) + cfg_grp.append(rs) + rs = RadioSetting("timeout", "Timeout Timer", + RadioSettingValueList( + TIMEOUT_LIST, TIMEOUT_LIST[_settings.timeout])) + cfg_grp.append(rs) + rs = RadioSetting("toalarm", "Timeout Alarm", + RadioSettingValueInteger(0, 10, _settings.toalarm)) + cfg_grp.append(rs) + rs = RadioSetting("roger_beep", "Roger Beep", + RadioSettingValueList(ROGER_LIST, + ROGER_LIST[_settings.roger_beep])) + cfg_grp.append(rs) + rs = RadioSetting("power_save", "Power save", + RadioSettingValueBoolean(_settings.power_save)) + cfg_grp.append(rs) + rs = RadioSetting("autolock", "Autolock", + RadioSettingValueBoolean(_settings.autolock)) + cfg_grp.append(rs) + rs = RadioSetting("keylock", "Keypad Lock", + RadioSettingValueBoolean(_settings.keylock)) + cfg_grp.append(rs) + rs = RadioSetting("beep", "Keypad Beep", + RadioSettingValueBoolean(_settings.beep)) + cfg_grp.append(rs) + rs = RadioSetting("stopwatch", "Stopwatch", + RadioSettingValueBoolean(_settings.stopwatch)) + cfg_grp.append(rs) + rs = RadioSetting("backlight", "Backlight", + RadioSettingValueList(BACKLIGHT_LIST, + BACKLIGHT_LIST[_settings. + backlight])) + cfg_grp.append(rs) + rs = RadioSetting("dtmf_st", "DTMF Sidetone", + RadioSettingValueList(DTMFST_LIST, + DTMFST_LIST[_settings. + dtmf_st])) + cfg_grp.append(rs) + rs = RadioSetting("ani_sw", "ANI-ID Switch", + RadioSettingValueBoolean(_settings.ani_sw)) + cfg_grp.append(rs) + rs = RadioSetting("ptt_id", "PTT-ID Delay", + RadioSettingValueList(PTTID_LIST, + PTTID_LIST[_settings.ptt_id])) + cfg_grp.append(rs) + rs = RadioSetting("ring_time", "Ring Time", + RadioSettingValueList(LIST_10, + LIST_10[_settings.ring_time])) + cfg_grp.append(rs) + rs = RadioSetting("scan_rev", "Scan Mode", + RadioSettingValueList(SCANMODE_LIST, + SCANMODE_LIST[_settings. + scan_rev])) + cfg_grp.append(rs) + rs = RadioSetting("vox", "VOX", + RadioSettingValueList(LIST_10, + LIST_10[_settings.vox])) + cfg_grp.append(rs) + rs = RadioSetting("prich_sw", "Priority Channel Switch", + RadioSettingValueBoolean(_settings.prich_sw)) + cfg_grp.append(rs) + rs = RadioSetting("pri_ch", "Priority Channel", + RadioSettingValueInteger(1, 999, _settings.pri_ch)) + cfg_grp.append(rs) + rs = RadioSetting("rpt_mode", "Radio Mode", + RadioSettingValueList(RPTMODE_LIST, + RPTMODE_LIST[_settings. + rpt_mode])) + cfg_grp.append(rs) + rs = RadioSetting("rpt_set", "Repeater Setting", + RadioSettingValueList(RPTSET_LIST, + RPTSET_LIST[_settings. + rpt_set])) + cfg_grp.append(rs) + rs = RadioSetting("rpt_spk", "Repeater Mode Speaker", + RadioSettingValueBoolean(_settings.rpt_spk)) + cfg_grp.append(rs) + rs = RadioSetting("rpt_ptt", "Repeater PTT", + RadioSettingValueBoolean(_settings.rpt_ptt)) + cfg_grp.append(rs) + rs = RadioSetting("dtmf_tx_time", "DTMF Tx Duration", + RadioSettingValueList(DTMF_TIMES, + DTMF_TIMES[_settings. + dtmf_tx_time])) + cfg_grp.append(rs) + rs = RadioSetting("dtmf_interval", "DTMF Interval", + RadioSettingValueList(DTMF_TIMES, + DTMF_TIMES[_settings. + dtmf_interval])) + cfg_grp.append(rs) + rs = RadioSetting("alert", "Alert Tone", + RadioSettingValueList(ALERTS_LIST, + ALERTS_LIST[_settings.alert])) + cfg_grp.append(rs) + rs = RadioSetting("rpt_tone", "Repeater Tone", + RadioSettingValueBoolean(_settings.rpt_tone)) + cfg_grp.append(rs) + rs = RadioSetting("rpt_hold", "Repeater Hold Time", + RadioSettingValueList(HOLD_TIMES, + HOLD_TIMES[_settings. + rpt_hold])) + cfg_grp.append(rs) + rs = RadioSetting("scan_det", "Scan DET", + RadioSettingValueBoolean(_settings.scan_det)) + cfg_grp.append(rs) + rs = RadioSetting("sc_qt", "SC-QT", + RadioSettingValueList(SCQT_LIST, + SCQT_LIST[_settings.sc_qt])) + cfg_grp.append(rs) + rs = RadioSetting("smuteset", "SubFreq Mute", + RadioSettingValueList(SMUTESET_LIST, + SMUTESET_LIST[_settings. + smuteset])) + cfg_grp.append(rs) + + # + # VFO A Settings + # + rs = RadioSetting("workmode_a", "VFO A Workmode", + RadioSettingValueList(WORKMODE_LIST, WORKMODE_LIST[_settings.workmode_a])) + vfoa_grp.append(rs) + rs = RadioSetting("work_cha", "VFO A Channel", + RadioSettingValueInteger(1, 999, _settings.work_cha)) + vfoa_grp.append(rs) + rs = RadioSetting("vfoa.rxfreq", "VFO A Rx Frequency", + RadioSettingValueInteger( + 134000000, 520000000, _vfoa.rxfreq * 10, 5000)) + vfoa_grp.append(rs) + rs = RadioSetting("vfoa.txoffset", "VFO A Tx Offset", + RadioSettingValueInteger( + 0, 520000000, _vfoa.txoffset * 10, 5000)) + vfoa_grp.append(rs) + # u16 rxtone; + # u16 txtone; + rs = RadioSetting("vfoa.power", "VFO A Power", + RadioSettingValueList( + POWER_LIST, POWER_LIST[_vfoa.power])) + vfoa_grp.append(rs) + # shift_dir:2 + rs = RadioSetting("vfoa.iswide", "VFO A NBFM", + RadioSettingValueList( + BANDWIDTH_LIST, BANDWIDTH_LIST[_vfoa.iswide])) + vfoa_grp.append(rs) + rs = RadioSetting("vfoa.mute_mode", "VFO A Mute", + RadioSettingValueList( + SPMUTE_LIST, SPMUTE_LIST[_vfoa.mute_mode])) + vfoa_grp.append(rs) + rs = RadioSetting("vfoa.step", "VFO A Step (kHz)", + RadioSettingValueList( + STEP_LIST, STEP_LIST[_vfoa.step])) + vfoa_grp.append(rs) + rs = RadioSetting("vfoa.squelch", "VFO A Squelch", + RadioSettingValueList( + LIST_10, LIST_10[_vfoa.squelch])) + vfoa_grp.append(rs) + rs = RadioSetting("bcl_a", "Busy Channel Lock-out A", + RadioSettingValueBoolean(_settings.bcl_a)) + vfoa_grp.append(rs) + + # + # VFO B Settings + # + rs = RadioSetting("workmode_b", "VFO B Workmode", + RadioSettingValueList(WORKMODE_LIST, WORKMODE_LIST[_settings.workmode_b])) + vfob_grp.append(rs) + rs = RadioSetting("work_chb", "VFO B Channel", + RadioSettingValueInteger(1, 999, _settings.work_chb)) + vfob_grp.append(rs) + rs = RadioSetting("vfob.rxfreq", "VFO B Rx Frequency", + RadioSettingValueInteger( + 134000000, 520000000, _vfob.rxfreq * 10, 5000)) + vfob_grp.append(rs) + rs = RadioSetting("vfob.txoffset", "VFO B Tx Offset", + RadioSettingValueInteger( + 0, 520000000, _vfob.txoffset * 10, 5000)) + vfob_grp.append(rs) + # u16 rxtone; + # u16 txtone; + rs = RadioSetting("vfob.power", "VFO B Power", + RadioSettingValueList( + POWER_LIST, POWER_LIST[_vfob.power])) + vfob_grp.append(rs) + # shift_dir:2 + rs = RadioSetting("vfob.iswide", "VFO B NBFM", + RadioSettingValueList( + BANDWIDTH_LIST, BANDWIDTH_LIST[_vfob.iswide])) + vfob_grp.append(rs) + rs = RadioSetting("vfob.mute_mode", "VFO B Mute", + RadioSettingValueList( + SPMUTE_LIST, SPMUTE_LIST[_vfob.mute_mode])) + vfob_grp.append(rs) + rs = RadioSetting("vfob.step", "VFO B Step (kHz)", + RadioSettingValueList( + STEP_LIST, STEP_LIST[_vfob.step])) + vfob_grp.append(rs) + rs = RadioSetting("vfob.squelch", "VFO B Squelch", + RadioSettingValueList( + LIST_10, LIST_10[_vfob.squelch])) + vfob_grp.append(rs) + rs = RadioSetting("bcl_b", "Busy Channel Lock-out B", + RadioSettingValueBoolean(_settings.bcl_b)) + vfob_grp.append(rs) + + # + # Key Settings + # + _msg = str(_settings.dispstr).split("\0")[0] + val = RadioSettingValueString(0, 15, _msg) + val.set_mutable(True) + rs = RadioSetting("dispstr", "Display Message", val) + key_grp.append(rs) + + dtmfchars = "0123456789" + _codeobj = _settings.ani_code + _code = "".join([dtmfchars[x] for x in _codeobj if int(x) < 0x0A]) + val = RadioSettingValueString(3, 6, _code, False) + val.set_charset(dtmfchars) + rs = RadioSetting("ani_code", "ANI Code", val) + def apply_ani_id(setting, obj): + value = [] + for j in range(0, 6): + try: + value.append(dtmfchars.index(str(setting.value)[j])) + except IndexError: + value.append(0xFF) + obj.ani_code = value + rs.set_apply_callback(apply_ani_id, _settings) + key_grp.append(rs) + + rs = RadioSetting("pf1_func", "PF1 Key function", + RadioSettingValueList( + PF1KEY_LIST, + PF1KEY_LIST[_settings.pf1_func])) + key_grp.append(rs) + rs = RadioSetting("pf3_func", "PF3 Key function", + RadioSettingValueList( + PF3KEY_LIST, + PF3KEY_LIST[_settings.pf3_func])) + key_grp.append(rs) + + # + # Limits settings + # + rs = RadioSetting("vhf_limits.rx_start", "VHF RX Lower Limit", + RadioSettingValueInteger( + 134000000, 174997500, + self._memobj.vhf_limits.rx_start * 10, 5000)) + vhf_lmt_grp.append(rs) + rs = RadioSetting("vhf_limits.rx_stop", "VHF RX Upper Limit", + RadioSettingValueInteger( + 134000000, 174997500, + self._memobj.vhf_limits.rx_stop * 10, 5000)) + vhf_lmt_grp.append(rs) + rs = RadioSetting("vhf_limits.tx_start", "VHF TX Lower Limit", + RadioSettingValueInteger( + 134000000, 174997500, + self._memobj.vhf_limits.tx_start * 10, 5000)) + vhf_lmt_grp.append(rs) + rs = RadioSetting("vhf_limits.tx_stop", "VHF TX Upper Limit", + RadioSettingValueInteger( + 134000000, 174997500, + self._memobj.vhf_limits.tx_stop * 10, 5000)) + vhf_lmt_grp.append(rs) + + rs = RadioSetting("vhf1_limits.rx_start", "VHF1 RX Lower Limit", + RadioSettingValueInteger( + 220000000, 265000000, + self._memobj.vhf1_limits.rx_start * 10, 5000)) + vhf1_lmt_grp.append(rs) + rs = RadioSetting("vhf1_limits.rx_stop", "VHF1 RX Upper Limit", + RadioSettingValueInteger( + 220000000, 265000000, + self._memobj.vhf1_limits.rx_stop * 10, 5000)) + vhf1_lmt_grp.append(rs) + rs = RadioSetting("vhf1_limits.tx_start", "VHF1 TX Lower Limit", + RadioSettingValueInteger( + 220000000, 265000000, + self._memobj.vhf1_limits.tx_start * 10, 5000)) + vhf1_lmt_grp.append(rs) + rs = RadioSetting("vhf1_limits.tx_stop", "VHF1 TX Upper Limit", + RadioSettingValueInteger( + 220000000, 265000000, + self._memobj.vhf1_limits.tx_stop * 10, 5000)) + vhf1_lmt_grp.append(rs) + + rs = RadioSetting("uhf_limits.rx_start", "UHF RX Lower Limit", + RadioSettingValueInteger( + 400000000, 520000000, + self._memobj.uhf_limits.rx_start * 10, 5000)) + uhf_lmt_grp.append(rs) + rs = RadioSetting("uhf_limits.rx_stop", "UHF RX Upper Limit", + RadioSettingValueInteger( + 400000000, 520000000, + self._memobj.uhf_limits.rx_stop * 10, 5000)) + uhf_lmt_grp.append(rs) + rs = RadioSetting("uhf_limits.tx_start", "UHF TX Lower Limit", + RadioSettingValueInteger( + 400000000, 520000000, + self._memobj.uhf_limits.tx_start * 10, 5000)) + uhf_lmt_grp.append(rs) + rs = RadioSetting("uhf_limits.tx_stop", "UHF TX Upper Limit", + RadioSettingValueInteger( + 400000000, 520000000, + self._memobj.uhf_limits.tx_stop * 10, 5000)) + uhf_lmt_grp.append(rs) + + # + # OEM info + # + def _decode(lst): + _str = ''.join([chr(c) for c in lst + if chr(c) in chirp_common.CHARSET_ASCII]) + return _str + + def do_nothing(setting, obj): + return + + _str = _decode(self._memobj.oem_info.model) + val = RadioSettingValueString(0, 15, _str) + val.set_mutable(False) + rs = RadioSetting("oem_info.model", "Model", val) + rs.set_apply_callback(do_nothing, _settings) + oem_grp.append(rs) + _str = _decode(self._memobj.oem_info.oem1) + val = RadioSettingValueString(0, 15, _str) + val.set_mutable(False) + rs = RadioSetting("oem_info.oem1", "OEM String 1", val) + rs.set_apply_callback(do_nothing, _settings) + oem_grp.append(rs) + _str = _decode(self._memobj.oem_info.oem2) + val = RadioSettingValueString(0, 15, _str) + val.set_mutable(False) + rs = RadioSetting("oem_info.oem2", "OEM String 2", val) + rs.set_apply_callback(do_nothing, _settings) + oem_grp.append(rs) + _str = _decode(self._memobj.oem_info.version) + val = RadioSettingValueString(0, 15, _str) + val.set_mutable(False) + rs = RadioSetting("oem_info.version", "Software Version", val) + rs.set_apply_callback(do_nothing, _settings) + oem_grp.append(rs) + _str = _decode(self._memobj.oem_info.date) + val = RadioSettingValueString(0, 15, _str) + val.set_mutable(False) + rs = RadioSetting("oem_info.date", "OEM Date", val) + rs.set_apply_callback(do_nothing, _settings) + oem_grp.append(rs) + + return group + + def get_settings(self): + try: + return self._get_settings() + except: + import traceback + LOG.error("Failed to parse settings: %s", traceback.format_exc()) + return None + + def set_settings(self, settings): + for element in settings: + if not isinstance(element, RadioSetting): + self.set_settings(element) + continue + else: + try: + if "." in element.get_name(): + bits = element.get_name().split(".") + obj = self._memobj + for bit in bits[:-1]: + obj = getattr(obj, bit) + setting = bits[-1] + else: + obj = self._memobj.settings + setting = element.get_name() + + if element.has_apply_callback(): + LOG.debug("Using apply callback") + element.run_apply_callback() + else: + LOG.debug("Setting %s = %s" % (setting, element.value)) + if self._is_freq(element): + setattr(obj, setting, int(element.value)/10) + else: + setattr(obj, setting, element.value) + except Exception, e: + LOG.debug(element.get_name()) + raise + + def _is_freq(self, element): + return "rxfreq" in element.get_name() or "txoffset" in element.get_name() or "rx_start" in element.get_name() or "rx_stop" in element.get_name() or "tx_start" in element.get_name() or "tx_stop" in element.get_name() diff --git a/chirp/drivers/kguv9dplus.py b/chirp/drivers/kguv9dplus.py index e7bfa30..c08dc92 100644 --- a/chirp/drivers/kguv9dplus.py +++ b/chirp/drivers/kguv9dplus.py @@ -1022,6 +1022,7 @@ class KGUV9DPlusRadio(chirp_common.CloneModeRadio, (400000000, 520000000), # supports 70cm (700000000, 985000000)] rf.valid_characters = chirp_common.CHARSET_ASCII + rf.valid_tuning_steps = STEPS rf.memory_bounds = (1, 999) # 999 memories return rf diff --git a/chirp/drivers/kyd.py b/chirp/drivers/kyd.py index 7a44c34..27ebc74 100644 --- a/chirp/drivers/kyd.py +++ b/chirp/drivers/kyd.py @@ -243,6 +243,7 @@ class NC630aRadio(chirp_common.CloneModeRadio): rf.valid_duplexes = ["", "-", "+", "split", "off"] rf.valid_modes = ["NFM", "FM"] # 12.5 KHz, 25 kHz. rf.memory_bounds = (1, 16) + rf.valid_tuning_steps = [2.5, 5., 6.25, 10., 12.5, 25.] rf.valid_bands = [(400000000, 520000000)] return rf diff --git a/chirp/drivers/kyd_IP620.py b/chirp/drivers/kyd_IP620.py index 5200a40..47507b8 100644 --- a/chirp/drivers/kyd_IP620.py +++ b/chirp/drivers/kyd_IP620.py @@ -488,6 +488,8 @@ class IP620Radio(chirp_common.CloneModeRadio, self._set_tone(mem, _mem) _mem.power = mem.power == POWER_LEVELS[1] + for setting in ('lout', 'busy_loc', 'scan_add'): + setattr(_mem, setting, 0) for setting in mem.extra: setattr(_mem, setting.get_name(), setting.value) diff --git a/chirp/drivers/leixen.py b/chirp/drivers/leixen.py index 16402f5..d96c5d0 100644 --- a/chirp/drivers/leixen.py +++ b/chirp/drivers/leixen.py @@ -171,7 +171,8 @@ APO_LIST = ["OFF", "10M", "20M", "30M", "40M", "50M", "60M", "90M", SQL_LIST = ["%s" % x for x in range(0, 10)] SCANM_LIST = ["CO", "TO"] TOT_LIST = ["OFF"] + ["%s seconds" % x for x in range(10, 130, 10)] -STEP_LIST = ["2.5 KHz", "5 KHz", "6.25 KHz", "10 KHz", "12.5 KHz", "25 KHz"] +_STEP_LIST = [2.5, 5., 6.25, 10., 12.5, 25.] +STEP_LIST = ["{} KHz".format(x) for x in _STEP_LIST] MONITOR_LIST = ["CTC/DCS", "DTMF", "CTC/DCS and DTMF", "CTC/DCS or DTMF"] VFOMR_LIST = ["MR", "VFO"] MRCHA_LIST = ["MR CHA", "Freq. MR"] @@ -417,6 +418,7 @@ class LeixenVV898Radio(chirp_common.CloneModeRadio): rf.valid_power_levels = self._power_levels rf.valid_duplexes = ["", "-", "+", "split", "off"] rf.valid_skips = ["", "S"] + rf.valid_tuning_steps = _STEP_LIST rf.valid_bands = [(136000000, 174000000), (400000000, 470000000)] rf.memory_bounds = (1, 199) diff --git a/chirp/drivers/lt725uv.py b/chirp/drivers/lt725uv.py index ca4461f..a21a9c5 100644 --- a/chirp/drivers/lt725uv.py +++ b/chirp/drivers/lt725uv.py @@ -503,6 +503,7 @@ class LT725UV(chirp_common.CloneModeRadio): rf.valid_dtcs_codes = self.DTCS_CODES rf.valid_bands = self.VALID_BANDS rf.memory_bounds = (1, 128) + rf.valid_tuning_steps = STEPS return rf def get_sub_devices(self): diff --git a/chirp/drivers/puxing.py b/chirp/drivers/puxing.py index 4ceecb5..fb10d6b 100644 --- a/chirp/drivers/puxing.py +++ b/chirp/drivers/puxing.py @@ -165,6 +165,8 @@ class Puxing777Radio(chirp_common.CloneModeRadio): rf.valid_power_levels = POWER_LEVELS rf.valid_characters = ''.join(set(PUXING_CHARSET)) rf.valid_name_length = 6 + rf.valid_tuning_steps = [2.5, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, + 50.0, 100.0] rf.has_ctone = False rf.has_tuning_step = False rf.has_bank = False diff --git a/chirp/drivers/radioddity_r2.py b/chirp/drivers/radioddity_r2.py index d28696a..c0b2778 100644 --- a/chirp/drivers/radioddity_r2.py +++ b/chirp/drivers/radioddity_r2.py @@ -331,6 +331,10 @@ class RadioddityR2Radio(chirp_common.CloneModeRadio): rf.has_ctone = True rf.has_cross = True rf.can_odd_split = False + # FIXME: Is this right? The get_memory() has no checking for + # deleted memories, but set_memory() used to reference a missing + # variable likely copied from another driver + rf.can_delete = False rf.valid_modes = MODE_LIST rf.valid_duplexes = ["", "-", "+", "off"] rf.valid_tmodes = ["", "Tone", "TSQL", "DTCS", "Cross"] @@ -496,10 +500,7 @@ class RadioddityR2Radio(chirp_common.CloneModeRadio): # Get a low-level memory object mapped to the image _mem = self._memobj.memory[mem.number - 1] - if mem.empty: - LOG.debug("initializing memory channel %d" % mem.number) - _mem.set_raw(BLANK_MEMORY) - + LOG.warning('This driver may be broken for deleted memories') if mem.empty: return diff --git a/chirp/drivers/retevis_rt1.py b/chirp/drivers/retevis_rt1.py index e91300a..96baa13 100644 --- a/chirp/drivers/retevis_rt1.py +++ b/chirp/drivers/retevis_rt1.py @@ -369,6 +369,7 @@ class RT1Radio(chirp_common.CloneModeRadio): rf.valid_duplexes = ["", "-", "+", "split", "off"] rf.valid_modes = ["NFM", "FM"] # 12.5 KHz, 25 kHz. rf.memory_bounds = (1, 16) + rf.valid_tuning_steps = [2.5, 5., 6.25, 10., 12.5, 25.] if self._mmap is None: rf.valid_bands = [self._vhf_range, self._uhf_range] elif self._my_band() == RT1_VHF_fp: diff --git a/chirp/drivers/retevis_rt21.py b/chirp/drivers/retevis_rt21.py index 35f0521..856b33e 100644 --- a/chirp/drivers/retevis_rt21.py +++ b/chirp/drivers/retevis_rt21.py @@ -269,6 +269,7 @@ class RT21Radio(chirp_common.CloneModeRadio): rf.valid_duplexes = ["", "-", "+", "split", "off"] rf.valid_modes = ["NFM", "FM"] # 12.5 KHz, 25 kHz. rf.memory_bounds = (1, 16) + rf.valid_tuning_steps = [2.5, 5., 6.25, 10., 12.5, 25.] rf.valid_bands = [(400000000, 480000000)] return rf diff --git a/chirp/drivers/retevis_rt22.py b/chirp/drivers/retevis_rt22.py index c9bf0e1..9edb9c4 100644 --- a/chirp/drivers/retevis_rt22.py +++ b/chirp/drivers/retevis_rt22.py @@ -317,6 +317,7 @@ class RT22Radio(chirp_common.CloneModeRadio): rf.valid_duplexes = ["", "-", "+", "split", "off"] rf.valid_modes = ["NFM", "FM"] # 12.5 KHz, 25 kHz. rf.memory_bounds = (1, 16) + rf.valid_tuning_steps = [2.5, 5., 6.25, 10., 12.5, 25.] rf.valid_bands = [(400000000, 520000000)] return rf diff --git a/chirp/drivers/retevis_rt23.py b/chirp/drivers/retevis_rt23.py index 0ccb088..d424131 100644 --- a/chirp/drivers/retevis_rt23.py +++ b/chirp/drivers/retevis_rt23.py @@ -172,8 +172,8 @@ LIST_SCANS = ["Time Operated", "Carrier Operated", "Search"] LIST_SIGNALING = ["No", "DTMF"] LIST_TOT = ["OFF"] + ["%s seconds" % x for x in range(30, 300, 30)] LIST_TXSEL = ["Edit", "Busy"] -LIST_STEP = ["2.50K", "5.00K", "6.25K", "10.00K", "12,50K", "20.00K", "25.00K", - "50.00K"] +_STEP_LIST = [2.5, 5., 6.25, 10., 12.5, 20., 25., 50.] +LIST_STEP = ["{0:.2f}K".format(x) for x in _STEP_LIST] LIST_VFOMR = ["VFO", "MR(Frequency)", "MR(Channel #/Name)"] LIST_VFOMRFM = ["VFO", "Channel"] LIST_VOICE = ["Off", "Chinese", "English"] @@ -387,6 +387,7 @@ class RT23Radio(chirp_common.CloneModeRadio): rf.valid_duplexes = ["", "-", "+", "split", "off"] rf.valid_modes = ["FM", "NFM"] # 25 KHz, 12.5 KHz. rf.memory_bounds = (1, 128) + rf.valid_tuning_steps = _STEP_LIST rf.valid_bands = [ (136000000, 174000000), (400000000, 480000000)] diff --git a/chirp/drivers/retevis_rt26.py b/chirp/drivers/retevis_rt26.py index ab138e2..3840575 100644 --- a/chirp/drivers/retevis_rt26.py +++ b/chirp/drivers/retevis_rt26.py @@ -393,6 +393,7 @@ class RT26Radio(chirp_common.CloneModeRadio): rf.valid_duplexes = ["", "-", "+", "split", "off"] rf.valid_modes = ["NFM", "FM"] # 12.5 KHz, 25 kHz. rf.memory_bounds = (1, 16) + rf.valid_tuning_steps = [2.5, 5., 6.25, 10., 12.5, 25.] rf.valid_bands = [(400000000, 520000000)] return rf diff --git a/chirp/drivers/tdxone_tdq8a.py b/chirp/drivers/tdxone_tdq8a.py index 122c056..6793a9f 100644 --- a/chirp/drivers/tdxone_tdq8a.py +++ b/chirp/drivers/tdxone_tdq8a.py @@ -551,6 +551,7 @@ class TDXoneTDQ8A(chirp_common.CloneModeRadio, #rf.valid_dtcs_codes = self.DTCS_CODES rf.memory_bounds = (1, 128) rf.valid_power_levels = POWER_LEVELS + rf.valid_tuning_steps = STEPS rf.valid_bands = VALID_BANDS return rf diff --git a/chirp/drivers/th350.py b/chirp/drivers/th350.py new file mode 100644 index 0000000..3994f28 --- /dev/null +++ b/chirp/drivers/th350.py @@ -0,0 +1,395 @@ +# Copyright 2019 Zhaofeng Li <hello@zhaofeng.li> +# Copyright 2013 Dan Smith <dsmith@danplanet.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 2 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/>. + +import struct +import logging +from math import floor +from chirp import chirp_common, directory, bitwise, memmap, errors, util +from uvb5 import BaofengUVB5 + +LOG = logging.getLogger(__name__) + +mem_format = """ +struct memory { + lbcd freq[4]; + lbcd offset[4]; + u8 unknown1:2, + txpol:1, + rxpol:1, + compander:1, + scrambler:1, + unknown2:2; + u8 rxtoneb; + u8 rxtonea; + u8 txtoneb; + u8 txtonea; + u8 pttid:1, + scanadd:1, + isnarrow:1, + bcl:1, + highpower:1, + revfreq:1, + duplex:2; + u8 unknown[2]; +}; + +#seekto 0x0000; +char ident[32]; +u8 blank[16]; +struct memory vfo1; +struct memory channels[128]; +#seekto 0x0840; +struct memory vfo3; +struct memory vfo2; + +#seekto 0x09D0; +u16 fm_presets[16]; + +#seekto 0x0A30; +struct { + u8 name[5]; +} names[128]; + +#seekto 0x0D30; +struct { + u8 squelch; + u8 freqmode_ab:1, + save_funct:1, + backlight:1, + beep_tone_disabled:1, + roger:1, + tdr:1, + scantype:2; + u8 language:1, + workmode_b:1, + workmode_a:1, + workmode_fm:1, + voice_prompt:1, + fm:1, + pttid:2; + u8 unknown_0:5, + timeout:3; + u8 mdf_b:2, + mdf_a:2, + unknown_1:2, + txtdr:2; + u8 unknown_2:4, + ste_disabled:1, + unknown_3:2, + sidetone:1; + u8 vox; + u8 unk1; + u8 mem_chan_a; + u16 fm_vfo; + u8 unk4; + u8 unk5; + u8 mem_chan_b; + u8 unk6; + u8 last_menu; // number of last menu item accessed +} settings; + +#seekto 0x0D50; +struct { + u8 code[6]; +} pttid; + +#seekto 0x0F30; +struct { + lbcd lower_vhf[2]; + lbcd upper_vhf[2]; + lbcd lower_uhf[2]; + lbcd upper_uhf[2]; +} limits; + +#seekto 0x0FF0; +struct { + u8 vhfsquelch0; + u8 vhfsquelch1; + u8 vhfsquelch2; + u8 vhfsquelch3; + u8 vhfsquelch4; + u8 vhfsquelch5; + u8 vhfsquelch6; + u8 vhfsquelch7; + u8 vhfsquelch8; + u8 vhfsquelch9; + u8 unknown1[6]; + u8 uhfsquelch0; + u8 uhfsquelch1; + u8 uhfsquelch2; + u8 uhfsquelch3; + u8 uhfsquelch4; + u8 uhfsquelch5; + u8 uhfsquelch6; + u8 uhfsquelch7; + u8 uhfsquelch8; + u8 uhfsquelch9; + u8 unknown2[6]; + u8 vhfhipwr0; + u8 vhfhipwr1; + u8 vhfhipwr2; + u8 vhfhipwr3; + u8 vhfhipwr4; + u8 vhfhipwr5; + u8 vhfhipwr6; + u8 vhfhipwr7; + u8 vhflopwr0; + u8 vhflopwr1; + u8 vhflopwr2; + u8 vhflopwr3; + u8 vhflopwr4; + u8 vhflopwr5; + u8 vhflopwr6; + u8 vhflopwr7; + u8 uhfhipwr0; + u8 uhfhipwr1; + u8 uhfhipwr2; + u8 uhfhipwr3; + u8 uhfhipwr4; + u8 uhfhipwr5; + u8 uhfhipwr6; + u8 uhfhipwr7; + u8 uhflopwr0; + u8 uhflopwr1; + u8 uhflopwr2; + u8 uhflopwr3; + u8 uhflopwr4; + u8 uhflopwr5; + u8 uhflopwr6; + u8 uhflopwr7; +} test; +""" + + +def do_ident(radio): + radio.pipe.timeout = 3 + radio.pipe.write("\x05TROGRAM") + for x in xrange(10): + ack = radio.pipe.read(1) + if ack == '\x06': + break + else: + raise errors.RadioError("Radio did not ack programming mode") + radio.pipe.write("\x02") + ident = radio.pipe.read(8) + LOG.debug(util.hexprint(ident)) + if not ident.startswith('HKT511'): + raise errors.RadioError("Unsupported model") + radio.pipe.write("\x06") + ack = radio.pipe.read(1) + if ack != "\x06": + raise errors.RadioError("Radio did not ack ident") + + +def do_status(radio, direction, addr): + status = chirp_common.Status() + status.msg = "Cloning %s radio" % direction + status.cur = addr + status.max = 0x1000 + radio.status_fn(status) + + +def do_download(radio): + do_ident(radio) + data = "TH350 Radio Program data v1.08\x00\x00" + data += ("\x00" * 16) + firstack = None + for i in range(0, 0x1000, 16): + frame = struct.pack(">cHB", "R", i, 16) + radio.pipe.write(frame) + result = radio.pipe.read(20) + if frame[1:4] != result[1:4]: + LOG.debug(util.hexprint(result)) + raise errors.RadioError("Invalid response for address 0x%04x" % i) + data += result[4:] + do_status(radio, "from", i) + + return memmap.MemoryMap(data) + + +def do_upload(radio): + do_ident(radio) + data = radio._mmap[0x0030:] + + for i in range(0, 0x1000, 16): + frame = struct.pack(">cHB", "W", i, 16) + frame += data[i:i + 16] + radio.pipe.write(frame) + ack = radio.pipe.read(1) + if ack != "\x06": + # UV-B5/UV-B6 radios with 27 menus do not support service settings + # and will stop ACKing when the upload reaches 0x0F10 + if i == 0x0F10: + # must be a radio with 27 menus detected - stop upload + break + else: + LOG.debug("Radio NAK'd block at address 0x%04x" % i) + raise errors.RadioError( + "Radio NAK'd block at address 0x%04x" % i) + LOG.debug("Radio ACK'd block at address 0x%04x" % i) + do_status(radio, "to", i) + + +DUPLEX = ["", "-", "+"] +CHARSET = "0123456789- ABCDEFGHIJKLMNOPQRSTUVWXYZ/_+*" +POWER_LEVELS = [chirp_common.PowerLevel("Low", watts=1), + chirp_common.PowerLevel("High", watts=5)] + + +@directory.register +class Th350Radio(BaofengUVB5): + """TYT TH-350""" + VENDOR = "TYT" + MODEL = "TH-350" + BAUD_RATE = 9600 + SPECIALS = { + "VFO1": -3, + "VFO2": -2, + "VFO3": -1, + } + + _memsize = 0x1000 + + @classmethod + def get_prompts(cls): + rp = chirp_common.RadioPrompts() + rp.experimental = \ + ("This TYT TH-350 driver is an alpha version. " + "Proceed with Caution and backup your data. " + "Always confirm the correctness of your settings with the " + "official programmer.") + return rp + + def get_features(self): + rf = chirp_common.RadioFeatures() + rf.has_settings = True + rf.has_cross = True + rf.has_rx_dtcs = True + rf.valid_tmodes = ["", "Tone", "TSQL", "DTCS", "Cross"] + rf.valid_cross_modes = ["Tone->Tone", "Tone->DTCS", "DTCS->Tone", + "->Tone", "->DTCS", "DTCS->", "DTCS->DTCS"] + rf.valid_duplexes = DUPLEX + ["split"] + rf.can_odd_split = True + rf.valid_skips = ["", "S"] + rf.valid_characters = CHARSET + rf.valid_name_length = 5 + rf.valid_bands = [(130000000, 175000000), + (220000000, 269000000), + (400000000, 520000000)] + rf.valid_modes = ["FM", "NFM"] + rf.valid_special_chans = self.SPECIALS.keys() + rf.valid_power_levels = POWER_LEVELS + rf.has_ctone = True + rf.has_bank = False + rf.has_tuning_step = False + rf.memory_bounds = (1, 128) + return rf + + def sync_in(self): + try: + self._mmap = do_download(self) + except errors.RadioError: + raise + except Exception, e: + raise errors.RadioError("Failed to communicate with radio: %s" % e) + self.process_mmap() + + def sync_out(self): + try: + do_upload(self) + except errors.RadioError: + raise + except Exception, e: + raise errors.RadioError("Failed to communicate with radio: %s" % e) + + def process_mmap(self): + self._memobj = bitwise.parse(mem_format, self._mmap) + + def _decode_tone(self, _mem, which): + def _get(field): + return getattr(_mem, "%s%s" % (which, field)) + + tonea, toneb = _get('tonea'), _get('toneb') + + if tonea == 0xff: + mode = val = pol = None + elif tonea >= 0x80: + # DTCS + # D754N -> 0x87 0x54 + # D754I -> 0xc7 0x54 + # Yes. Decimal digits as hex. You're seeing that right. + # No idea why TYT engineers would do something like that. + pold = tonea / 16 + if pold not in [0x8, 0xc]: + LOG.warn("Bug: tone is %04x %04x" % (tonea, toneb)) + mode = val = pol = None + else: + mode = 'DTCS' + val = (tonea % 16) * 100 + \ + toneb / 16 * 10 + \ + (toneb % 16) + pol = 'N' if pold == 8 else 'R' + else: + # Tone + # 107.2 -> 0x10 0x72. Seriously. + mode = 'Tone' + val = tonea / 16 * 100 + \ + (tonea % 16) * 10 + \ + toneb / 16 + \ + float(toneb % 16) / 10 + pol = None + + return mode, val, pol + + def _encode_tone(self, _mem, which, mode, val, pol): + def _set(field, value): + setattr(_mem, "%s%s" % (which, field), value) + + if mode == "Tone": + tonea = int( + floor(val / 100) * 16 + + floor(val / 10) % 10 + ) + toneb = int( + floor(val % 10) * 16 + + floor(val * 10) % 10 + ) + elif mode == "DTCS": + tonea = (0x80 if pol == 'N' else 0xc0) + \ + val / 100 + toneb = (val / 10) % 10 * 16 + \ + val % 10 + else: + tonea = toneb = 0xff + + _set('tonea', tonea) + _set('toneb', toneb) + + def _get_memobjs(self, number): + if isinstance(number, str): + return (getattr(self._memobj, number.lower()), None) + elif number < 0: + for k, v in self.SPECIALS.items(): + if number == v: + return (getattr(self._memobj, k.lower()), None) + else: + return (self._memobj.channels[number - 1], + self._memobj.names[number - 1].name) + + @classmethod + def match_model(cls, filedata, filename): + return (filedata.startswith("TH350 Radio Program data") and + len(filedata) == (cls._memsize + 0x30)) diff --git a/chirp/drivers/th_uv3r25.py b/chirp/drivers/th_uv3r25.py index 6100d4b..ece7959 100644 --- a/chirp/drivers/th_uv3r25.py +++ b/chirp/drivers/th_uv3r25.py @@ -159,7 +159,7 @@ class TYTUV3R25Radio(TYTUV3RRadio): if mem.empty: self._memobj.emptyflags[byte] |= bit - _mem.set_raw("\xFF" * 16) + _mem.set_raw("\xFF" * 20) return self._memobj.emptyflags[byte] &= ~bit diff --git a/chirp/drivers/th_uv8000.py b/chirp/drivers/th_uv8000.py new file mode 100644 index 0000000..3897d54 --- /dev/null +++ b/chirp/drivers/th_uv8000.py @@ -0,0 +1,1491 @@ +# Copyright 2019: Rick DeWitt (RJD), <aa0rd@yahoo.com> +# Version 1.0 for TYT-UV8000D/E +# Thanks to Damon Schaefer (K9CQB) and the Loudoun County, VA ARES +# club for the donated radio. +# And thanks to Ian Harris (VA3IHX) for decoding the memory map. +# +# 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 2 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/>. + +import time +import struct +import logging +import re +import math +from chirp import chirp_common, directory, memmap +from chirp import bitwise, errors, util +from chirp.settings import RadioSettingGroup, RadioSetting, \ + RadioSettingValueBoolean, RadioSettingValueList, \ + RadioSettingValueString, RadioSettingValueInteger, \ + RadioSettingValueFloat, RadioSettings, InvalidValueError +from textwrap import dedent + +LOG = logging.getLogger(__name__) + +MEM_FORMAT = """ +struct chns { + ul32 rxfreq; + ul32 txfreq; + u8 rxtone[2]; + u8 txtone[2]; + u8 wide:1 // 0x0c + vox_on:1 + chunk01:1 + bcl:1 // inv bool + epilogue:1 + power:1 + chunk02:1 + chunk03:1; + u8 ani:1 // 0x0d inv + chunk08:1 + ptt:2 + chpad04:4; + u8 chunk05; // 0x0e + u16 id_code; // 0x0f, 10 + u8 chunk06; + u8 name[7]; + ul32 chpad06; // Need 56 byte pad + ul16 chpad07; + u8 chpad08; +}; + +struct fm_chn { + ul16 rxfreq; +}; + +struct frqx { + ul32 rxfreq; + ul24 ofst; + u8 fqunk01:4 // 0x07 + funk10:2 + duplx:2; + u8 rxtone[2]; // 0x08, 9 + u8 txtone[2]; // 0x0a, b + u8 wide:1 // 0x0c + vox_on:1 + funk11:1 + bcl:1 // inv bool + epilogue:1 + power:1 + fqunk02:2; + u8 ani:1 // 0x0d inv bool + fqunk03:1 + ptt:2 + fqunk12:1 + fqunk04:3; + u8 fqunk07; // 0x0e + u16 id_code; // 0x0f, 0x10 + u8 name[7]; // dummy + u8 fqunk09[8]; // empty bytes after 1st entry +}; + +struct bitmap { + u8 map[16]; +}; + +#seekto 0x0010; +struct chns chan_mem[128]; + +#seekto 0x1010; +struct frqx frq[2]; + +#seekto 0x1050; +struct fm_chn fm_stations[25]; + +#seekto 0x1080; +struct { + u8 fmunk01[14]; + ul16 fmcur; +} fmfrqs; + +#seekto 0x1190; +struct bitmap chnmap; + +#seekto 0x11a0; +struct bitmap skpchns; + +#seekto 0x011b0; +struct { + u8 fmset[4]; +} fmmap; + +#seekto 0x011b4; +struct { + u8 setunk01[4]; + u8 setunk02[3]; + u8 chs_name:1 // 0x11bb + txsel:1 + dbw:1 + setunk05:1 + ponfmchs:2 + ponchs:2; + u8 voltx:2 // 0x11bc + setunk04:1 + keylok:1 + setunk07:1 + batsav:3; + u8 setunk09:1 // 0x11bd + rxinhib:1 + rgrbeep:1 // inv bool + lampon:2 + voice:2 + beepon:1; + u8 setunk11:1 // 0x11be + manualset:1 + xbandon:1 // inv + xbandenable:1 + openmsg:2 + ledclr:2; + u8 tot:4 // 0x11bf + sql:4; + u8 setunk27:1 // 0x11c0 + voxdelay:2 + setunk28:1 + voxgain:4; + u8 fmstep:4 // 0x11c1 + freqstep:4; + u8 scanspeed:4 // 0x11c2 + scanmode:4; + u8 scantmo; // 0x11c3 + u8 prichan; // 0x11c4 + u8 setunk12:4 // 0x11c5 + supersave:4; + u8 setunk13; + u8 fmsclo; // 0x11c7 ??? placeholder + u8 radioname[7]; // hex char codes, not true ASCII + u8 fmschi; // ??? placeholder + u8 setunk14[3]; // 0x11d0 + u8 setunk17[2]; // 0x011d3, 4 + u8 setunk18:4 + dtmfspd:4; + u8 dtmfdig1dly:4 // 0x11d6 + dtmfdig1time:4; + u8 stuntype:1 + setunk19:1 + dtmfspms:2 + grpcode:4; + u8 setunk20:1 // 0x11d8 + txdecode:1 + codeabcd:1 + idedit:1 + pttidon:2 + setunk40:1, + dtmfside:1; + u8 setunk50:4, + autoresettmo:4; + u8 codespctim:4, // 0x11da + decodetmo:4; + u8 pttecnt:4 // 0x11db + pttbcnt:4; + lbcd dtmfdecode[3]; + u8 setunk22; + u8 stuncnt; // 0x11e0 + u8 stuncode[5]; + u8 setunk60; + u8 setunk61; + u8 pttbot[8]; // 0x11e8-f + u8 ptteot[8]; // 0x11f0-7 + u8 setunk62; // 0x11f8 + u8 setunk63; + u8 setunk64; // 0x11fa + u8 setunk65; + u8 setunk66; + u8 manfrqyn; // 0x11fd + u8 setunk27:3 + frqr3:1 + setunk28:1 + frqr2:1 + setunk29:1 + frqr1:1; + u8 setunk25; + ul32 frqr1lo; // 0x1200 + ul32 frqr1hi; + ul32 frqr2lo; + ul32 frqr2hi; + ul32 frqr3lo; // 0x1210 + ul32 frqr3hi; + u8 setunk26[8]; +} setstuf; + +#seekto 0x1260; +struct { + u8 modnum[7]; +} modcode; + +#seekto 0x1300; +struct { + char mod_num[9]; +} mod_id; +""" + +MEM_SIZE = 0x1300 +BLOCK_SIZE = 0x10 # can read 0x20, but must write 0x10 +STIMEOUT = 2 +BAUDRATE = 4800 +# Channel power: 2 levels +POWER_LEVELS = [chirp_common.PowerLevel("Low", watts=5.00), + chirp_common.PowerLevel("High", watts=10.00)] + +LIST_RECVMODE = ["QT/DQT", "QT/DQT + Signaling"] +LIST_COLOR = ["Off", "Orange", "Blue", "Purple"] +LIST_LEDSW = ["Auto", "On"] +LIST_TIMEOUT = ["Off"] + ["%s" % x for x in range(30, 390, 30)] +LIST_VFOMODE = ["Frequency Mode", "Channel Mode"] +# Tones are numeric, Defined in \chirp\chirp_common.py +TONES_CTCSS = sorted(chirp_common.TONES) +# Converted to strings +LIST_CTCSS = ["Off"] + [str(x) for x in TONES_CTCSS] +# Now append the DxxxN and DxxxI DTCS codes from chirp_common +for x in chirp_common.DTCS_CODES: + LIST_CTCSS.append("D{:03d}N".format(x)) +for x in chirp_common.DTCS_CODES: + LIST_CTCSS.append("D{:03d}R".format(x)) +LIST_BW = ["Narrow", "Wide"] +LIST_SHIFT = ["off", "+", "-"] +STEPS = [0.5, 2.5, 5.0, 6.25, 10.0, 12.5, 25.0, 37.5, 50.0, 100.0] +LIST_STEPS = [str(x) for x in STEPS] +LIST_VOXDLY = ["0.5", "1.0", "2.0", "3.0"] # LISTS must be strings +LIST_PTT = ["Both", "EoT", "BoT", "Off"] + +SETTING_LISTS = {"tot": LIST_TIMEOUT, "wtled": LIST_COLOR, + "rxled": LIST_COLOR, "txled": LIST_COLOR, + "ledsw": LIST_LEDSW, "frq_chn_mode": LIST_VFOMODE, + "rx_tone": LIST_CTCSS, "tx_tone": LIST_CTCSS, + "rx_mode": LIST_RECVMODE, "fm_bw": LIST_BW, + "shift": LIST_SHIFT, "step": LIST_STEPS, + "vox_dly": LIST_VOXDLY, "ptt": LIST_PTT} + + +def _clean_buffer(radio): + radio.pipe.timeout = 0.005 + junk = radio.pipe.read(256) + radio.pipe.timeout = STIMEOUT + if junk: + LOG.debug("Got %i bytes of junk before starting" % len(junk)) + + +def _rawrecv(radio, amount): + """Raw read from the radio device""" + data = "" + try: + data = radio.pipe.read(amount) + except Exception: + _exit_program_mode(radio) + msg = "Generic error reading data from radio; check your cable." + raise errors.RadioError(msg) + + if len(data) != amount: + _exit_program_mode(radio) + msg = "Error reading from radio: not the amount of data we want." + raise errors.RadioError(msg) + + return data + + +def _rawsend(radio, data): + """Raw send to the radio device""" + try: + radio.pipe.write(data) + except Exception: + raise errors.RadioError("Error sending data to radio") + + +def _make_frame(cmd, addr, length, data=""): + """Pack the info in the headder format""" + frame = struct.pack(">shB", cmd, addr, length) + # Add the data if set + if len(data) != 0: + frame += data + # Return the data + return frame + + +def _recv(radio, addr, length): + """Get data from the radio """ + + data = _rawrecv(radio, length) + + # DEBUG + LOG.info("Response:") + LOG.debug(util.hexprint(data)) + + return data + + +def _do_ident(radio): + """Put the radio in PROGRAM mode & identify it""" + radio.pipe.baudrate = BAUDRATE + radio.pipe.parity = "N" + radio.pipe.timeout = STIMEOUT + + # Flush input buffer + _clean_buffer(radio) + + magic = "PROGRAMa" + _rawsend(radio, magic) + ack = _rawrecv(radio, 1) + # LOG.warning("PROGa Ack:" + util.hexprint(ack)) + if ack != "\x06": + _exit_program_mode(radio) + if ack: + LOG.debug(repr(ack)) + raise errors.RadioError("Radio did not respond") + magic = "PROGRAMb" + _rawsend(radio, magic) + ack = _rawrecv(radio, 1) + if ack != "\x06": + _exit_program_mode(radio) + if ack: + LOG.debug(repr(ack)) + raise errors.RadioError("Radio did not respond to B") + magic = chr(0x02) + _rawsend(radio, magic) + ack = _rawrecv(radio, 1) # s/b: 0x50 + magic = _rawrecv(radio, 7) # s/b TC88... + magic = "MTC88CUMHS3E7BN-" + _rawsend(radio, magic) + ack = _rawrecv(radio, 1) # s/b 0x80 + magic = chr(0x06) + _rawsend(radio, magic) + ack = _rawrecv(radio, 1) + + return True + + +def _exit_program_mode(radio): + endframe = "E" + _rawsend(radio, endframe) + + +def _download(radio): + """Get the memory map""" + + # Put radio in program mode and identify it + _do_ident(radio) + + # UI progress + status = chirp_common.Status() + status.cur = 0 + status.max = MEM_SIZE / BLOCK_SIZE + status.msg = "Cloning from radio..." + radio.status_fn(status) + + data = "" + for addr in range(0, MEM_SIZE, BLOCK_SIZE): + frame = _make_frame("R", addr, BLOCK_SIZE) + # DEBUG + LOG.info("Request sent:") + LOG.debug("Frame=" + util.hexprint(frame)) + + # Sending the read request + _rawsend(radio, frame) + dx = _rawrecv(radio, 4) + + # Now we read data + d = _recv(radio, addr, BLOCK_SIZE) + # LOG.warning("Data= " + util.hexprint(d)) + + # Aggregate the data + data += d + + # UI Update + status.cur = addr / BLOCK_SIZE + status.msg = "Cloning from radio..." + radio.status_fn(status) + + _exit_program_mode(radio) + + return data + + +def _upload(radio): + """Upload procedure""" + # Put radio in program mode and identify it + _do_ident(radio) + + # UI progress + status = chirp_common.Status() + status.cur = 0 + status.max = MEM_SIZE / BLOCK_SIZE + status.msg = "Cloning to radio..." + radio.status_fn(status) + + # The fun starts here + for addr in range(0, MEM_SIZE, BLOCK_SIZE): + # Sending the data + data = radio.get_mmap()[addr:addr + BLOCK_SIZE] + + frame = _make_frame("W", addr, BLOCK_SIZE, data) + # LOG.warning("Frame:%s:" % util.hexprint(frame)) + _rawsend(radio, frame) + + # Receiving the response + ack = _rawrecv(radio, 1) + if ack != "\x06": + _exit_program_mode(radio) + msg = "Bad ack writing block 0x%04x" % addr + raise errors.RadioError(msg) + + # UI Update + status.cur = addr / BLOCK_SIZE + status.msg = "Cloning to radio..." + radio.status_fn(status) + + _exit_program_mode(radio) + + +def set_tone(_mem, txrx, ctdt, tval, pol): + """Set rxtone[] or txtone[] word values as decimal bytes""" + # txrx: Boolean T= set Rx tones, F= set Tx tones + # ctdt: Boolean T = CTCSS, F= DTCS + # tval = integer tone freq (*10) or DTCS code + # pol = string for DTCS polarity "R" or "N" + xv = int(str(tval), 16) + if txrx: # True = set rxtones + _mem.rxtone[0] = xv & 0xFF # Low byte + _mem.rxtone[1] = (xv >> 8) # Hi byte + if not ctdt: # dtcs, + if pol == "R": + _mem.rxtone[1] = _mem.rxtone[1] | 0xC0 + else: + _mem.rxtone[1] = _mem.rxtone[1] | 0x80 + else: # txtones + _mem.txtone[0] = xv & 0xFF # Low byte + _mem.txtone[1] = (xv >> 8) + if not ctdt: # dtcs + if pol == "R": + _mem.txtone[1] = _mem.txtone[1] | 0xC0 + else: + _mem.txtone[1] = _mem.txtone[1] | 0x80 + + return 0 + + +def _do_map(chn, sclr, mary): + """Set or Clear the chn (1-128) bit in mary[] word array map""" + # chn is 1-based channel, sclr:1 = set, 0= = clear, 2= return state + # mary[] is u8 array, but the map is by nibbles + ndx = int(math.floor((chn - 1) / 8)) + bv = (chn - 1) % 8 + msk = 1 << bv + mapbit = sclr + if sclr == 1: # Set the bit + mary[ndx] = mary[ndx] | msk + elif sclr == 0: # clear + mary[ndx] = mary[ndx] & (~ msk) # ~ is complement + else: # return current bit state + mapbit = 0 + if (mary[ndx] & msk) > 0: + mapbit = 1 + return mapbit + + +@directory.register +class THUV8000Radio(chirp_common.CloneModeRadio): + """TYT UV8000D Radio""" + VENDOR = "TYT" + MODEL = "TH-UV8000" + MODES = ["NFM", "FM"] + TONES = chirp_common.TONES + DTCS_CODES = sorted(chirp_common.DTCS_CODES + [645]) + NAME_LENGTH = 7 + DTMF_CHARS = list("0123456789ABCD*#") + # NOTE: SE Model supports 220-260 MHz + # The following bands are the the range the radio is capable of, + # not the legal FCC amateur bands + VALID_BANDS = [(87500000, 107900000), (136000000, 174000000), + (220000000, 260000000), (400000000, 520000000)] + + # Valid chars on the LCD + VALID_CHARS = chirp_common.CHARSET_ALPHANUMERIC + \ + "`!\"#$%&'()*+,-./:;<=>?@[]^_" + + # Special Channels Declaration + # WARNING Indecis are hard wired in get/set_memory code !!! + # Channels print in + increasing index order (most negative first) + SPECIAL_MEMORIES = { + "UpVFO": -2, + "LoVFO": -1 + } + FIRST_FREQ_INDEX = -1 + LAST_FREQ_INDEX = -2 + + SPECIAL_MEMORIES_REV = dict(zip(SPECIAL_MEMORIES.values(), + SPECIAL_MEMORIES.keys())) + + @classmethod + def get_prompts(cls): + rp = chirp_common.RadioPrompts() + rp.info = \ + ('Click on the "Special Channels" toggle-button of the memory ' + 'editor to see/set the upper and lower frequency-mode values.\n') + + rp.pre_download = _(dedent("""\ + Follow these instructions to download the radio memory: + + 1 - Turn off your radio + 2 - Connect your interface cable + 3 - Turn on your radio, volume @ 50% + 4 - Radio > Download from radio + """)) + rp.pre_upload = _(dedent("""\ + Follow these instructions to upload the radio memory: + + 1 - Turn off your radio + 2 - Connect your interface cable + 3 - Turn on your radio, volume @ 50% + 4 - Radio > Upload to radio + """)) + return rp + + def get_features(self): + rf = chirp_common.RadioFeatures() + # .has. attributes are boolean, .valid. are lists + rf.has_settings = True + rf.has_bank = False + rf.has_comment = False + rf.has_nostep_tuning = True # Radio accepts any entered freq + rf.has_tuning_step = False # Not as chan feature + rf.can_odd_split = False + rf.has_name = True + rf.has_offset = True + rf.has_mode = True + rf.has_dtcs = True + rf.has_rx_dtcs = True + rf.has_dtcs_polarity = True + rf.has_ctone = True + rf.has_cross = True + rf.has_sub_devices = False + rf.valid_name_length = self.NAME_LENGTH + rf.valid_modes = self.MODES + rf.valid_characters = self.VALID_CHARS + rf.valid_duplexes = ["-", "+", "off", ""] + rf.valid_tmodes = ['', 'Tone', 'TSQL', 'DTCS', 'Cross'] + rf.valid_cross_modes = ["Tone->Tone", "DTCS->", "->DTCS", + "Tone->DTCS", "DTCS->Tone", "->Tone", + "DTCS->DTCS"] + rf.valid_skips = [] + rf.valid_power_levels = POWER_LEVELS + rf.valid_dtcs_codes = self.DTCS_CODES + rf.valid_bands = self.VALID_BANDS + rf.memory_bounds = (1, 128) + rf.valid_skips = ["", "S"] + rf.valid_special_chans = sorted(self.SPECIAL_MEMORIES.keys()) + return rf + + def sync_in(self): + """Download from radio""" + try: + data = _download(self) + except errors.RadioError: + # Pass through any real errors we raise + raise + except Exception: + # If anything unexpected happens, make sure we raise + # a RadioError and log the problem + LOG.exception('Unexpected error during download') + raise errors.RadioError('Unexpected error communicating ' + 'with the radio') + self._mmap = memmap.MemoryMap(data) + self.process_mmap() + + def sync_out(self): + """Upload to radio""" + + try: + _upload(self) + except Exception: + # If anything unexpected happens, make sure we raise + # a RadioError and log the problem + LOG.exception('Unexpected error during upload') + raise errors.RadioError('Unexpected error communicating ' + 'with the radio') + + def process_mmap(self): + """Process the mem map into the mem object""" + self._memobj = bitwise.parse(MEM_FORMAT, self._mmap) + + def get_raw_memory(self, number): + return repr(self._memobj.memory[number - 1]) + + def get_memory(self, number): + if isinstance(number, str): + return self._get_special(number) + elif number < 0: + # I can't stop delete operation from loosing extd_number but + # I know how to get it back + return self._get_special(self.SPECIAL_MEMORIES_REV[number]) + else: + return self._get_normal(number) + + def set_memory(self, memory): + """A value in a UI column for chan 'number' has been modified.""" + # update all raw channel memory values (_mem) from UI (mem) + if memory.number < 0: + return self._set_special(memory) + else: + return self._set_normal(memory) + + def _get_normal(self, number): + # radio first channel is 1, mem map is base 0 + _mem = self._memobj.chan_mem[number - 1] + mem = chirp_common.Memory() + mem.number = number + + return self._get_memory(mem, _mem) + + def _get_memory(self, mem, _mem): + """Convert raw channel memory data into UI columns""" + mem.extra = RadioSettingGroup("extra", "Extra") + + if _mem.get_raw()[0] == "\xff": + mem.empty = True + return mem + + mem.empty = False + # This function process both 'normal' and Freq up/down' entries + mem.freq = int(_mem.rxfreq) * 10 + mem.power = POWER_LEVELS[_mem.power] + mem.mode = self.MODES[_mem.wide] + dtcs_pol = ["N", "N"] + + if _mem.rxtone[0] == 0xFF: + rxmode = "" + elif _mem.rxtone[1] < 0x26: + # CTCSS + rxmode = "Tone" + tonehi = int(str(_mem.rxtone[1])[2:]) + tonelo = int(str(_mem.rxtone[0])[2:]) + mem.ctone = int(tonehi * 100 + tonelo) / 10.0 + else: + # Digital + rxmode = "DTCS" + tonehi = int(str(_mem.rxtone[1] & 0x3f)) + tonelo = int(str(_mem.rxtone[0])[2:]) + mem.rx_dtcs = int(tonehi * 100 + tonelo) + if (_mem.rxtone[1] & 0x40) != 0: + dtcs_pol[1] = "R" + + if _mem.txtone[0] == 0xFF: + txmode = "" + elif _mem.txtone[1] < 0x26: + # CTCSS + txmode = "Tone" + tonehi = int(str(_mem.txtone[1])[2:]) + tonelo = int(str(_mem.txtone[0])[2:]) + mem.rtone = int(tonehi * 100 + tonelo) / 10.0 + else: + # Digital + txmode = "DTCS" + tonehi = int(str(_mem.txtone[1] & 0x3f)) + tonelo = int(str(_mem.txtone[0])[2:]) + mem.dtcs = int(tonehi * 100 + tonelo) + if (_mem.txtone[1] & 0x40) != 0: + dtcs_pol[0] = "R" + + mem.tmode = "" + if txmode == "Tone" and not rxmode: + mem.tmode = "Tone" + elif txmode == rxmode and txmode == "Tone" and mem.rtone == mem.ctone: + mem.tmode = "TSQL" + elif txmode == rxmode and txmode == "DTCS" and mem.dtcs == mem.rx_dtcs: + mem.tmode = "DTCS" + elif rxmode or txmode: + mem.tmode = "Cross" + mem.cross_mode = "%s->%s" % (txmode, rxmode) + + mem.dtcs_polarity = "".join(dtcs_pol) + + # Now test the mem.number to process special vs normal + if mem.number >= 0: # Normal + mem.name = "" + for i in range(self.NAME_LENGTH): # 0 - 6 + mem.name += chr(_mem.name[i] + 32) + mem.name = mem.name.rstrip() # remove trailing spaces + + if _mem.txfreq == 0xFFFFFFFF: + # TX freq not set + mem.duplex = "off" + mem.offset = 0 + elif int(_mem.rxfreq) == int(_mem.txfreq): + mem.duplex = "" + mem.offset = 0 + else: + mem.duplex = int(_mem.rxfreq) > int(_mem.txfreq) \ + and "-" or "+" + mem.offset = abs(int(_mem.rxfreq) - int(_mem.txfreq)) * 10 + + if _do_map(mem.number, 2, self._memobj.skpchns.map) > 0: + mem.skip = "S" + else: + mem.skip = "" + + else: # specials VFO + mem.name = "----" + mem.duplex = LIST_SHIFT[_mem.duplx] + mem.offset = int(_mem.ofst) * 10 + mem.skip = "" + # End if specials + + # Channel Extra settings: Only Boolean & List methods, no call-backs + rx = RadioSettingValueBoolean(bool(not _mem.bcl)) # Inverted bool + # NOTE: first param of RadioSetting is the object attribute name + rset = RadioSetting("bcl", "Busy Channel Lockout", rx) + mem.extra.append(rset) + + rx = RadioSettingValueBoolean(bool(not _mem.vox_on)) + rset = RadioSetting("vox_on", "Vox", rx) + mem.extra.append(rset) + + rx = RadioSettingValueBoolean(bool(not _mem.ani)) + rset = RadioSetting("ani", "Auto Number ID (ANI)", rx) + mem.extra.append(rset) + + # ID code can't be done in extra - no Integer method or call-back + + rx = RadioSettingValueList(LIST_PTT, LIST_PTT[_mem.ptt]) + rset = RadioSetting("ptt", "Xmit PTT ID", rx) + mem.extra.append(rset) + + rx = RadioSettingValueBoolean(bool(_mem.epilogue)) + rset = RadioSetting("epilogue", "Epilogue/Tail", rx) + mem.extra.append(rset) + + return mem + + def _get_special(self, number): + mem = chirp_common.Memory() + mem.number = self.SPECIAL_MEMORIES[number] + mem.extd_number = number + # Unused attributes are ignored in Set_memory + if (mem.number == -1) or (mem.number == -2): + # Print Upper[1] first, and Lower[0] next + rx = 0 + if mem.number == -2: + rx = 1 + _mem = self._memobj.frq[rx] + # immutable = ["number", "extd_number", "name"] + mem = self._get_memory(mem, _mem) + else: + raise Exception("Sorry, you can't edit that special" + " memory channel %i." % mem.number) + + # mem.immutable = immutable + + return mem + + def _set_memory(self, mem, _mem): + """Convert UI column data (mem) into MEM_FORMAT memory (_mem).""" + # At this point mem points to either normal or Freq chans + # These first attributes are common to all types + if mem.empty: + if mem.number > 0: + _mem.rxfreq = 0xffffffff + # Set 'empty' and 'skip' bits + _do_map(mem.number, 1, self._memobj.chnmap.map) + _do_map(mem.number, 1, self._memobj.skpchns.map) + elif mem.number == -2: # upper VFO Freq + _mem.rxfreq = 14652000 # VHF National Calling freq + elif mem.number == -1: # lower VFO + _mem.rxfreq = 44600000 # UHF National Calling freq + return + + _mem.rxfreq = mem.freq / 10 + + if str(mem.power) == "Low": + _mem.power = 0 + else: + _mem.power = 1 + + _mem.wide = self.MODES.index(mem.mode) + + rxmode = "" + txmode = "" + + if mem.tmode == "Tone": + txmode = "Tone" + elif mem.tmode == "TSQL": + rxmode = "Tone" + txmode = "TSQL" + elif mem.tmode == "DTCS": + rxmode = "DTCSSQL" + txmode = "DTCS" + elif mem.tmode == "Cross": + txmode, rxmode = mem.cross_mode.split("->", 1) + + sx = mem.dtcs_polarity[1] + if rxmode == "": + _mem.rxtone[0] = 0xFF + _mem.rxtone[1] = 0xFF + elif rxmode == "Tone": + val = int(mem.ctone * 10) + i = set_tone(_mem, True, True, val, sx) + elif rxmode == "DTCSSQL": + i = set_tone(_mem, True, False, mem.dtcs, sx) + elif rxmode == "DTCS": + i = set_tone(_mem, True, False, mem.rx_dtcs, sx) + + sx = mem.dtcs_polarity[0] + if txmode == "": + _mem.txtone[0] = 0xFF + _mem.txtone[1] = 0xFF + elif txmode == "Tone": + val = int(mem.rtone * 10) + i = set_tone(_mem, False, True, val, sx) + elif txmode == "TSQL": + val = int(mem.ctone * 10) + i = set_tone(_mem, False, True, val, sx) + elif txmode == "DTCS": + i = set_tone(_mem, False, False, mem.dtcs, sx) + + if mem.number > 0: # Normal chans + for i in range(self.NAME_LENGTH): + pq = ord(mem.name.ljust(self.NAME_LENGTH)[i]) - 32 + if pq < 0: + pq = 0 + _mem.name[i] = pq + + if mem.duplex == "off": + _mem.txfreq = 0xFFFFFFFF + elif mem.duplex == "+": + _mem.txfreq = (mem.freq + mem.offset) / 10 + elif mem.duplex == "-": + _mem.txfreq = (mem.freq - mem.offset) / 10 + else: + _mem.txfreq = mem.freq / 10 + + # Set the channel map bit FALSE = Enabled + _do_map(mem.number, 0, self._memobj.chnmap.map) + # Skip + if mem.skip == "S": + _do_map(mem.number, 1, self._memobj.skpchns.map) + else: + _do_map(mem.number, 0, self._memobj.skpchns.map) + + else: # Freq (VFO) chans + _mem.duplx = 0 + _mem.ofst = 0 + if mem.duplex == "+": + _mem.duplx = 1 + _mem.ofst = mem.offset / 10 + elif mem.duplex == "-": + _mem.duplx = 2 + _mem.ofst = mem.offset / 10 + for i in range(self.NAME_LENGTH): + _mem.name[i] = 0xff + + # All mem.extra << Once the channel is defined + for setting in mem.extra: + # Overide list strings with signed value + if setting.get_name() == "ptt": + sx = str(setting.value) + for i in range(0, 4): + if sx == LIST_PTT[i]: + val = i + setattr(_mem, "ptt", val) + elif setting.get_name() == "epilogue": # not inverted bool + setattr(_mem, setting.get_name(), setting.value) + else: # inverted booleans + setattr(_mem, setting.get_name(), not setting.value) + + def _set_special(self, mem): + + cur_mem = self._get_special(self.SPECIAL_MEMORIES_REV[mem.number]) + + if mem.number == -2: # upper frq[1] + _mem = self._memobj.frq[1] + elif mem.number == -1: # lower frq[0] + _mem = self._memobj.frq[0] + else: + raise Exception("Sorry, you can't edit that special memory.") + + self._set_memory(mem, _mem) # Now update the _mem + + def _set_normal(self, mem): + _mem = self._memobj.chan_mem[mem.number - 1] + + self._set_memory(mem, _mem) + + def get_settings(self): + """Translate the MEM_FORMAT structs into setstuf in the UI""" + # Define mem struct write-back shortcuts + _sets = self._memobj.setstuf + _fmx = self._memobj.fmfrqs + + basic = RadioSettingGroup("basic", "Basic Settings") + adv = RadioSettingGroup("adv", "Other Settings") + fmb = RadioSettingGroup("fmb", "FM Broadcast") + scn = RadioSettingGroup("scn", "Scan Settings") + dtmf = RadioSettingGroup("dtmf", "DTMF Settings") + frng = RadioSettingGroup("frng", "Frequency Ranges") + group = RadioSettings(basic, adv, scn, fmb, dtmf, frng) + + def my_val_list(setting, obj, atrb): + """Callback:from ValueList with non-sequential, actual values.""" + # This call back also used in get_settings + value = int(str(setting.value)) # Get the integer value + setattr(obj, atrb, value) + return + + def my_adjraw(setting, obj, atrb, fix): + """Callback from Integer add or subtract fix from value.""" + vx = int(str(setting.value)) + value = vx + int(fix) + if value < 0: + value = 0 + setattr(obj, atrb, value) + return + + def my_strnam(setting, obj, atrb, mln): + """Callback from String to build u8 array with -32 offset.""" + # mln is max string length + ary = [] + knt = mln + for j in range(mln - 1, -1, -1): # Strip trailing spaces or nulls + pq = str(setting.value)[j] + if pq == "" or pq == " ": + knt = knt - 1 + else: + break + for j in range(mln): # 0 to mln-1 + pq = str(setting.value).ljust(mln)[j] + if j < knt: + ary.append(ord(pq) - 32) + else: + ary.append(0) + setattr(obj, atrb, ary) + return + + def unpack_str(cary, cknt, mxw): + """Convert u8 nibble array to a string: NOT a callback.""" + # cknt is char count, 2/word; mxw is max WORDS + stx = "" + mty = True + for i in range(mxw): # unpack entire array + nib = (cary[i] & 0xf0) >> 4 # LE, Hi nib first + if nib != 0xf: + mty = False + stx += format(nib, '0X') + nib = cary[i] & 0xf + if nib != 0xf: + mty = False + stx += format(nib, '0X') + stx = stx[:cknt] + if mty: # all ff, empty string + sty = "" + else: + # Convert E to #, F to * + sty = "" + for i in range(cknt): + if stx[i] == "E": + sty += "#" + elif stx[i] == "F": + sty += "*" + else: + sty += stx[i] + + return sty + + def pack_chars(setting, obj, atrstr, atrcnt, mxl): + """Callback to build 0-9,A-D,*# nibble array from string""" + # cknt is generated char count, 2 chars per word + # String will be f padded to mxl + # Chars are stored as hex values + # store cknt-1 in atrcnt, 0xf if empty + cknt = 0 + ary = [] + stx = str(setting.value).upper() + stx = stx.strip() # trim spaces + # Remove illegal characters first + sty = "" + for j in range(0, len(stx)): + if stx[j] in self.DTMF_CHARS: + sty += stx[j] + for j in range(mxl): + if j < len(sty): + if sty[j] == "#": + chrv = 0xE + elif sty[j] == "*": + chrv = 0xF + else: + chrv = int(sty[j], 16) + cknt += 1 # char count + else: # pad to mxl, cknt does not increment + chrv = 0xF + if (j % 2) == 0: # odd count (0-based), high nibble + hi_nib = chrv + else: # even count, lower nibble + lo_nib = chrv + nibs = lo_nib | (hi_nib << 4) + ary.append(nibs) # append word + setattr(obj, atrstr, ary) + if setting.get_name() != "setstuf.stuncode": # cknt is actual + if cknt > 0: + cknt = cknt - 1 + else: + cknt = 0xf + setattr(obj, atrcnt, cknt) + return + + def myset_freq(setting, obj, atrb, mult): + """ Callback to set frequency by applying multiplier""" + value = int(float(str(setting.value)) * mult) + setattr(obj, atrb, value) + return + + def my_invbool(setting, obj, atrb): + """Callback to invert the boolean """ + bval = not setting.value + setattr(obj, atrb, bval) + return + + def my_batsav(setting, obj, atrb): + """Callback to set batsav attribute """ + stx = str(setting.value) # Off, 1:1... + if stx == "Off": + value = 0x1 # bit value 4 clear, ratio 1 = 1:2 + elif stx == "1:1": + value = 0x4 # On, ratio 0 = 1:1 + elif stx == "1:2": + value = 0x5 # On, ratio 1 = 1:2 + elif stx == "1:3": + value = 0x6 # On, ratio 2 = 1:3 + else: + value = 0x7 # On, ratio 3 = 1:4 + # LOG.warning("Batsav stx:%s:, value= %x" % (stx, value)) + setattr(obj, atrb, value) + return + + def my_manfrq(setting, obj, atrb): + """Callback to set 2-byte manfrqyn yes/no """ + # LOG.warning("Manfrq value = %d" % setting.value) + if (str(setting.value)) == "No": + value = 0xff + else: + value = 0xaa + setattr(obj, atrb, value) + return + + def myset_mask(setting, obj, atrb, nx): + if bool(setting.value): # Enabled = 0 + vx = 0 + else: + vx = 1 + _do_map(nx + 1, vx, self._memobj.fmmap.fmset) + return + + def myset_fmfrq(setting, obj, atrb, nx): + """ Callback to set xx.x FM freq in memory as xx.x * 40""" + # in-valid even KHz freqs are allowed; to satisfy run_tests + vx = float(str(setting.value)) + vx = int(vx * 40) + setattr(obj[nx], atrb, vx) + return + + rx = RadioSettingValueInteger(1, 9, _sets.voxgain + 1) + rset = RadioSetting("setstuf.voxgain", "Vox Level", rx) + rset.set_apply_callback(my_adjraw, _sets, "voxgain", -1) + basic.append(rset) + + rx = RadioSettingValueList(LIST_VOXDLY, LIST_VOXDLY[_sets.voxdelay]) + rset = RadioSetting("setstuf.voxdelay", "Vox Delay (secs)", rx) + basic.append(rset) + + rx = RadioSettingValueInteger(0, 9, _sets.sql) + rset = RadioSetting("setstuf.sql", "Squelch", rx) + basic.append(rset) + + rx = RadioSettingValueList(LIST_STEPS, LIST_STEPS[_sets.freqstep]) + rset = RadioSetting("setstuf.freqstep", "VFO Tune Step (KHz))", rx) + basic.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.dbw)) # true logic + rset = RadioSetting("setstuf.dbw", "Dual Band Watch (D.WAIT)", rx) + basic.append(rset) + + options = ["Off", "On", "Auto"] + rx = RadioSettingValueList(options, options[_sets.lampon]) + rset = RadioSetting("setstuf.lampon", "Backlight (LED)", rx) + basic.append(rset) + + options = ["Orange", "Purple", "Blue"] + rx = RadioSettingValueList(options, options[_sets.ledclr]) + rset = RadioSetting("setstuf.ledclr", "Backlight Color (LIGHT)", rx) + basic.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.beepon)) + rset = RadioSetting("setstuf.beepon", "Keypad Beep", rx) + basic.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.xbandenable)) + rset = RadioSetting("setstuf.xbandenable", "Cross Band Allowed", rx) + basic.append(rset) + + rx = RadioSettingValueBoolean(bool(not _sets.xbandon)) + rset = RadioSetting("setstuf.xbandon", "Cross Band On", rx) + rset.set_apply_callback(my_invbool, _sets, "xbandon") + basic.append(rset) + + rx = RadioSettingValueList(LIST_TIMEOUT, LIST_TIMEOUT[_sets.tot]) + rset = RadioSetting("setstuf.tot", "TX Timeout (Secs)", rx) + basic.append(rset) + + rx = RadioSettingValueBoolean(bool(not _sets.rgrbeep)) # Invert + rset = RadioSetting("setstuf.rgrbeep", "Beep at Eot (Roger)", rx) + rset.set_apply_callback(my_invbool, _sets, "rgrbeep") + basic.append(rset) + + rx = RadioSettingValueBoolean(bool(not _sets.keylok)) + rset = RadioSetting("setstuf.keylok", "Keypad AutoLock", rx) + rset.set_apply_callback(my_invbool, _sets, "keylok") + basic.append(rset) + + options = ["None", "Message", "DC Volts"] + rx = RadioSettingValueList(options, options[_sets.openmsg]) + rset = RadioSetting("setstuf.openmsg", "Power-On Display", rx) + basic.append(rset) + + options = ["Channel Name", "Frequency"] + rx = RadioSettingValueList(options, options[_sets.chs_name]) + rset = RadioSetting("setstuf.chs_name", "Display Name/Frq", rx) + basic.append(rset) + + sx = "" + for i in range(7): + if _sets.radioname[i] != 0: + sx += chr(_sets.radioname[i] + 32) + rx = RadioSettingValueString(0, 7, sx) + rset = RadioSetting("setstuf.radioname", "Power-On Message", rx) + rset.set_apply_callback(my_strnam, _sets, "radioname", 7) + basic.append(rset) + + # Advanced (Strange) Settings + options = ["Busy: Last Tx Band", "Edit: Current Band"] + rx = RadioSettingValueList(options, options[_sets.txsel]) + rset = RadioSetting("setstuf.txsel", "Transmit Priority", rx) + rset.set_doc("'Busy' transmits on last band used, not current one.") + adv.append(rset) + + options = ["Off", "English", "Unk", "Chinese"] + val = _sets.voice + rx = RadioSettingValueList(options, options[val]) + rset = RadioSetting("setstuf.voice", "Voice", rx) + adv.append(rset) + + options = ["Off", "1:1", "1:2", "1:3", "1:4"] + val = (_sets.batsav & 0x3) + 1 # ratio + if (_sets.batsav & 0x4) == 0: # Off + val = 0 + rx = RadioSettingValueList(options, options[val]) + rset = RadioSetting("setstuf.batsav", "Battery Saver", rx) + rset.set_apply_callback(my_batsav, _sets, "batsav") + adv.append(rset) + + # Find out what & where SuperSave is + options = ["Off", "1", "2", "3", "4", "5", "6", "7", "8", "9"] + rx = RadioSettingValueList(options, options[_sets.supersave]) + rset = RadioSetting("setstuf.supersave", "Super Save (Secs)", rx) + rset.set_doc("Unknown radio attribute??") + adv.append(rset) + + sx = unpack_str(_sets.pttbot, _sets.pttbcnt + 1, 8) + rx = RadioSettingValueString(0, 16, sx) + rset = RadioSetting("setstuf.pttbot", "PTT BoT Code", rx) + rset.set_apply_callback(pack_chars, _sets, "pttbot", "pttbcnt", 16) + adv.append(rset) + + sx = unpack_str(_sets.ptteot, _sets.pttecnt + 1, 8) + rx = RadioSettingValueString(0, 16, sx) + rset = RadioSetting("setstuf.ptteot", "PTT EoT Code", rx) + rset.set_apply_callback(pack_chars, _sets, "ptteot", "pttecnt", 16) + adv.append(rset) + + options = ["None", "Low", "High", "Both"] + rx = RadioSettingValueList(options, options[_sets.voltx]) + rset = RadioSetting("setstuf.voltx", "Transmit Inhibit Voltage", rx) + rset.set_doc("Block Transmit if battery volts are too high or low,") + adv.append(rset) + + val = 0 # No = 0xff + if _sets.manfrqyn == 0xaa: + val = 1 + options = ["No", "Yes"] + rx = RadioSettingValueList(options, options[val]) + rset = RadioSetting("setstuf.manfrqyn", "Manual Frequency", rx) + rset.set_apply_callback(my_manfrq, _sets, "manfrqyn") + adv.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.manualset)) + rset = RadioSetting("setstuf.manualset", "Manual Setting", rx) + adv.append(rset) + + # Scan Settings + options = ["CO: During Rx", "TO: Timed", "SE: Halt"] + rx = RadioSettingValueList(options, options[_sets.scanmode]) + rset = RadioSetting("setstuf.scanmode", + "Scan Mode (Scan Pauses When)", rx) + scn.append(rset) + + options = ["100", "150", "200", "250", + "300", "350", "400", "450"] + rx = RadioSettingValueList(options, options[_sets.scanspeed]) + rset = RadioSetting("setstuf.scanspeed", "Scan Speed (ms)", rx) + scn.append(rset) + + val = _sets.scantmo + 3 + rx = RadioSettingValueInteger(3, 30, val) + rset = RadioSetting("setstuf.scantmo", + "TO Mode Timeout (secs)", rx) + rset.set_apply_callback(my_adjraw, _sets, "scantmo", -3) + scn.append(rset) + + val = _sets.prichan + if val <= 0: + val = 1 + rx = RadioSettingValueInteger(1, 128, val) + rset = RadioSetting("setstuf.prichan", "Priority Channel", rx) + scn.append(rset) + + # FM Broadcast Settings + val = _fmx.fmcur + val = val / 40.0 + if val < 87.5 or val > 107.9: + val = 88.0 + rx = RadioSettingValueFloat(87.5, 107.9, val, 0.1, 1) + rset = RadioSetting("fmfrqs.fmcur", "Manual FM Freq (MHz)", rx) + rset.set_apply_callback(myset_freq, _fmx, "fmcur", 40) + fmb.append(rset) + + options = ["5", "50", "100", "200(USA)"] # 5 is not used + rx = RadioSettingValueList(options, options[_sets.fmstep]) + rset = RadioSetting("setstuf.fmstep", "FM Freq Step (KHz)", rx) + fmb.append(rset) + + # FM Scan Range fmsclo and fmschi are unknown memory locations, + # Not supported at this time + + rx = RadioSettingValueBoolean(bool(_sets.rxinhib)) + rset = RadioSetting("setstuf.rxinhib", + "Rcvr Will Interupt FM (DW)", rx) + fmb.append(rset) + + _fmfrq = self._memobj.fm_stations + _fmap = self._memobj.fmmap + for j in range(0, 25): + val = _fmfrq[j].rxfreq + if val == 0xFFFF: + val = 88.0 + fmset = False + else: + val = (float(int(val)) / 40) + # get fmmap bit value: 0 = enabled + ndx = int(math.floor((j) / 8)) + bv = j % 8 + msk = 1 << bv + vx = _fmap.fmset[ndx] + fmset = not bool(vx & msk) + rx = RadioSettingValueBoolean(fmset) + rset = RadioSetting("fmmap.fmset/%d" % j, + "FM Preset %02d" % (j + 1), rx) + rset.set_apply_callback(myset_mask, _fmap, "fmset", j) + fmb.append(rset) + + rx = RadioSettingValueFloat(87.5, 107.9, val, 0.1, 1) + rset = RadioSetting("fm_stations/%d.rxfreq" % j, + " Preset %02d Freq" % (j + 1), rx) + # This callback uses the array index + rset.set_apply_callback(myset_fmfrq, _fmfrq, "rxfreq", j) + fmb.append(rset) + + # DTMF Settings + options = [str(x) for x in range(4, 16)] + rx = RadioSettingValueList(options, options[_sets.dtmfspd]) + rset = RadioSetting("setstuf.dtmfspd", + "Tx Speed (digits/sec)", rx) + dtmf.append(rset) + + options = [str(x) for x in range(0, 1100, 100)] + rx = RadioSettingValueList(options, options[_sets.dtmfdig1time]) + rset = RadioSetting("setstuf.dtmfdig1time", + "Tx 1st Digit Time (ms)", rx) + dtmf.append(rset) + + options = [str(x) for x in range(100, 1100, 100)] + rx = RadioSettingValueList(options, options[_sets.dtmfdig1dly]) + rset = RadioSetting("setstuf.dtmfdig1dly", + "Tx 1st Digit Delay (ms)", rx) + dtmf.append(rset) + + options = ["0", "100", "500", "1000"] + rx = RadioSettingValueList(options, options[_sets.dtmfspms]) + rset = RadioSetting("setstuf.dtmfspms", + "Tx Star & Pound Time (ms)", rx) + dtmf.append(rset) + + options = ["None"] + [str(x) for x in range(600, 2100, 100)] + rx = RadioSettingValueList(options, options[_sets.codespctim]) + rset = RadioSetting("setstuf.codespctim", + "Tx Code Space Time (ms)", rx) + dtmf.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.codeabcd)) + rset = RadioSetting("setstuf.codeabcd", "Tx Codes A,B,C,D", rx) + dtmf.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.dtmfside)) + rset = RadioSetting("setstuf.dtmfside", "DTMF Side Tone", rx) + dtmf.append(rset) + + options = ["Off", "A", "B", "C", "D"] + rx = RadioSettingValueList(options, options[_sets.grpcode]) + rset = RadioSetting("setstuf.grpcode", "Rx Group Code", rx) + dtmf.append(rset) + + options = ["Off"] + [str(x) for x in range(1, 16)] + rx = RadioSettingValueList(options, options[_sets.autoresettmo]) + rset = RadioSetting("setstuf.autoresettmo", + "Rx Auto Reset Timeout (secs)", rx) + dtmf.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.txdecode)) + rset = RadioSetting("setstuf.txdecode", "Tx Decode", rx) + dtmf.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.idedit)) + rset = RadioSetting("setstuf.idedit", "Allow ANI Code Edit", rx) + dtmf.append(rset) + + options = [str(x) for x in range(500, 1600, 100)] + rx = RadioSettingValueList(options, options[_sets.decodetmo]) + rset = RadioSetting("setstuf.decodetmo", + "Rx Decode Timeout (ms)", rx) + dtmf.append(rset) + + options = ["Tx & Rx Inhibit", "Tx Inhibit"] + rx = RadioSettingValueList(options, options[_sets.stuntype]) + rset = RadioSetting("setstuf.stuntype", "Stun Type", rx) + dtmf.append(rset) + + sx = unpack_str(_sets.stuncode, _sets.stuncnt, 5) + rx = RadioSettingValueString(0, 10, sx) + rset = RadioSetting("setstuf.stuncode", "Stun Code", rx) + rset.set_apply_callback(pack_chars, _sets, + "stuncode", "stuncnt", 10) + dtmf.append(rset) + + # Frequency ranges + rx = RadioSettingValueBoolean(bool(_sets.frqr1)) + rset = RadioSetting("setstuf.frqr1", "Freq Range 1 (UHF)", rx) + rset.set_doc("Enable the UHF frequency bank.") + frng.append(rset) + + rx = RadioSettingValueBoolean(bool(_sets.frqr2)) + rset = RadioSetting("setstuf.frqr2", "Freq Range 2 (VHF)", rx) + rset.set_doc("Enable the VHF frequency bank.") + frng.append(rset) + + mod_se = True # UV8000SE has 3rd freq bank + if mod_se: + rx = RadioSettingValueBoolean(bool(_sets.frqr3)) + rset = RadioSetting("setstuf.frqr3", "Freq Range 3 (220Mhz)", rx) + rset.set_doc("Enable the 220MHz frequency bank.") + frng.append(rset) + + frqm = 100000 + val = _sets.frqr1lo / frqm + rx = RadioSettingValueFloat(400.0, 520.0, val, 0.005, 3) + rset = RadioSetting("setstuf.frqr1lo", + "UHF Range Low Limit (MHz)", rx) + rset.set_apply_callback(myset_freq, _sets, "frqr1lo", frqm) + rset.set_doc("Low limit of the UHF frequency bank.") + frng.append(rset) + + val = _sets.frqr1hi / frqm + rx = RadioSettingValueFloat(400.0, 520.0, val, 0.005, 3) + rset = RadioSetting("setstuf.frqr1hi", + "UHF Range High Limit (MHz)", rx) + rset.set_apply_callback(myset_freq, _sets, "frqr1hi", frqm) + rset.set_doc("High limit of the UHF frequency bank.") + frng.append(rset) + + val = _sets.frqr2lo / frqm + rx = RadioSettingValueFloat(136.0, 174.0, val, 0.005, 3) + rset = RadioSetting("setstuf.frqr2lo", + "VHF Range Low Limit (MHz)", rx) + rset.set_apply_callback(myset_freq, _sets, "frqr2lo", frqm) + rset.set_doc("Low limit of the VHF frequency bank.") + frng.append(rset) + + val = _sets.frqr2hi / frqm + rx = RadioSettingValueFloat(136.0, 174.0, val, 0.005, 3) + rset = RadioSetting("setstuf.frqr2hi", + "VHF Range High Limit (MHz)", rx) + rset.set_apply_callback(myset_freq, _sets, "frqr2hi", frqm) + rset.set_doc("High limit of the VHF frequency bank.") + frng.append(rset) + + if mod_se: + val = _sets.frqr3lo / frqm + if val < 220.0: + val = 220.0 + rx = RadioSettingValueFloat(220.0, 260.0, val, 0.005, 3) + rset = RadioSetting("setstuf.frqr3lo", + "1.25m Range Low Limit (MHz)", rx) + rset.set_apply_callback(myset_freq, _sets, "frqr3lo", frqm) + frng.append(rset) + + val = _sets.frqr3hi / frqm + if val < 220.0: + val = 260.0 + rx = RadioSettingValueFloat(220.0, 260.0, val, 0.005, 3) + rset = RadioSetting("setstuf.frqr3hi", + "1.25m Range High Limit (MHz)", rx) + rset.set_apply_callback(myset_freq, _sets, "frqr3hi", 1000) + frng.append(rset) + + return group # END get_settings() + + def set_settings(self, settings): + _settings = self._memobj.setstuf + _mem = self._memobj + for element in settings: + if not isinstance(element, RadioSetting): + self.set_settings(element) + continue + else: + try: + name = element.get_name() + if "." in name: + bits = name.split(".") + obj = self._memobj + for bit in bits[:-1]: + if "/" in bit: + bit, index = bit.split("/", 1) + index = int(index) + obj = getattr(obj, bit)[index] + else: + obj = getattr(obj, bit) + setting = bits[-1] + else: + obj = _settings + setting = element.get_name() + + if element.has_apply_callback(): + LOG.debug("Using apply callback") + element.run_apply_callback() + elif element.value.get_mutable(): + LOG.debug("Setting %s = %s" % (setting, element.value)) + setattr(obj, setting, element.value) + except Exception, e: + LOG.debug(element.get_name()) + raise diff --git a/chirp/drivers/tk8180.py b/chirp/drivers/tk8180.py new file mode 100644 index 0000000..d52a69c --- /dev/null +++ b/chirp/drivers/tk8180.py @@ -0,0 +1,1158 @@ +# Copyright 2019 Dan Smith <dsmith@danplanet.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 2 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/>. + +import struct +import os +import time +import logging +from collections import OrderedDict + +from chirp import chirp_common, directory, memmap, errors, util +from chirp import bitwise +from chirp.settings import RadioSettingGroup, RadioSetting +from chirp.settings import RadioSettingValueBoolean, RadioSettingValueList +from chirp.settings import RadioSettingValueString, RadioSettingValueInteger +from chirp.settings import RadioSettings + +LOG = logging.getLogger(__name__) + +# Gross hack to handle missing future module on un-updatable +# platforms like MacOS. Just avoid registering these radio +# classes for now. +try: + from builtins import bytes + has_future = True +except ImportError: + has_future = False + LOG.warning('python-future package is not ' + 'available; %s requires it' % __name__) + + +HEADER_FORMAT = """ +#seekto 0x0100; +struct { + char sw_name[7]; + char sw_ver[5]; + u8 unknown1[4]; + char sw_key[12]; + u8 unknown2[4]; + char model[5]; + u8 unknown3[11]; +} header; + +#seekto 0x0140; +struct { + // 0x0140 + u8 unknown1; + u8 sublcd; + u8 unknown2[30]; + + // 0x0160 + char pon_msgtext[12]; + u8 min_volume; + u8 max_volume; + u8 lo_volume; + u8 hi_volume; + + // 0x0170 + u8 tone_volume_offset; + u8 poweron_tone; + u8 control_tone; + u8 warning_tone; + u8 alert_tone; + u8 sidetone; + u8 locator_tone; + u8 unknown3[2]; + u8 ignition_mode; + u8 ignition_time; // In tens of minutes (6 = 1h) + u8 micsense; + ul16 modereset; + u8 min_vol_preset; + u8 unknown4; + + // 0x0180 + u8 unknown5[16]; + + // 0x0190 + u8 unknown6[3]; + u8 pon_msgtype; + u8 unknown7[8]; + u8 unknown8_1:2, + ssi:1, + busy_led:1, + power_switch_memory:1, + scrambler_memory:1, + unknown8_2:1, + off_hook_decode:1; + u8 unknown9_1:5, + clockfmt:1, + datefmt:1, + ignition_sense:1; + u8 unknownA[2]; + + // 0x01A0 + u8 unknownB[8]; + u8 ptt_timer; + u8 unknownB2[3]; + u8 ptt_proceed:1, + unknownC_1:3, + tone_off:1, + ost_memory:1, + unknownC_2:1, + ptt_release:1; + u8 unknownD[3]; +} settings; + +#seekto 0x01E0; +struct { + char name[12]; + ul16 rxtone; + ul16 txtone; +} ost_tones[40]; + +#seekto 0x0A00; +ul16 zone_starts[128]; + +struct zoneinfo { + u8 number; + u8 zonetype; + u8 unknown1[2]; + u8 count; + char name[12]; + u8 unknown2[2]; + ul16 timeout; // 15-1200 + ul16 tot_alert; // 10 + ul16 tot_rekey; // 60 + ul16 tot_reset; // 15 + u8 unknown3[3]; + u8 unknown21:2, + bcl_override:1, + unknown22:5; + u8 unknown5; +}; + +struct memory { + u8 number; + lbcd rx_freq[4]; + lbcd tx_freq[4]; + u8 unknown1[2]; + ul16 rx_tone; + ul16 tx_tone; + char name[12]; + u8 unknown2[19]; + u8 unknown3_1:4, + highpower:1, + unknown3_2:1, + wide:1, + unknown3_3:1; + u8 unknown4; +}; + +#seekto 0xC570; // Fixme +u8 skipflags[64]; +""" + + +SYSTEM_MEM_FORMAT = """ +#seekto 0x%(addr)x; +struct { + struct zoneinfo zoneinfo; + struct memory memories[%(count)i]; +} zone%(index)i; +""" + +STARTUP_MODES = ['Text', 'Clock'] + +VOLUMES = OrderedDict([(str(x), x) for x in range(0, 30)]) +VOLUMES.update({'Selectable': 0x30, + 'Current': 0xFF}) +VOLUMES_REV = {v: k for k, v in VOLUMES.items()} + +MIN_VOL_PRESET = {'Preset': 0x30, + 'Lowest Limit': 0x31} +MIN_VOL_PRESET_REV = {v: k for k, v in MIN_VOL_PRESET.items()} + +SUBLCD = ['Zone Number', 'CH/GID Number', 'OSD List Number'] +CLOCKFMT = ['12H', '24H'] +DATEFMT = ['Day/Month', 'Month/Day'] +MICSENSE = ['On'] + +POWER_LEVELS = [chirp_common.PowerLevel("Low", watts=5), + chirp_common.PowerLevel("High", watts=50)] + + +def set_choice(setting, obj, key, choices, default='Off'): + settingstr = str(setting.value) + if settingstr == default: + val = 0xFF + else: + val = choices.index(settingstr) + 0x30 + setattr(obj, key, val) + + +def get_choice(obj, key, choices, default='Off'): + val = getattr(obj, key) + if val == 0xFF: + return default + else: + return choices[val - 0x30] + + +def make_frame(cmd, addr, data=b""): + return struct.pack(">BH", ord(cmd), addr) + data + + +def send(radio, frame): + # LOG.debug("%04i P>R:\n%s" % (len(frame), util.hexprint(frame))) + radio.pipe.write(frame) + + +def do_ident(radio): + radio.pipe.baudrate = 9600 + radio.pipe.stopbits = 2 + radio.pipe.timeout = 1 + send(radio, b'PROGRAM') + ack = radio.pipe.read(1) + LOG.debug('Read %r from radio' % ack) + if ack != b'\x16': + raise errors.RadioError('Radio refused hi-speed program mode') + radio.pipe.baudrate = 19200 + ack = radio.pipe.read(1) + if ack != b'\x06': + raise errors.RadioError('Radio refused program mode') + radio.pipe.write(b'\x02') + ident = radio.pipe.read(8) + LOG.debug('Radio ident is %r' % ident) + radio.pipe.write(b'\x06') + ack = radio.pipe.read(1) + if ack != b'\x06': + raise errors.RadioError('Radio refused program mode') + if ident[:5] not in (b'M8180',): + raise errors.RadioError('Unsupported radio model %s' % ident[:5]) + + +def checksum_data(data): + _chksum = 0 + for byte in data: + _chksum = (_chksum + byte) & 0xFF + return _chksum + + +def do_download(radio): + do_ident(radio) + + data = bytes() + + def status(): + status = chirp_common.Status() + status.cur = len(data) + status.max = radio._memsize + status.msg = "Cloning from radio" + radio.status_fn(status) + LOG.debug('Radio address 0x%04x' % len(data)) + + # Addresses 0x0000-0xBF00 pulled by block number (divide by 0x100) + for block in range(0, 0xBF + 1): + send(radio, make_frame('R', block)) + cmd = radio.pipe.read(1) + chunk = b'' + if cmd == b'Z': + data += bytes(b'\xff' * 256) + LOG.debug('Radio reports empty block %02x' % block) + elif cmd == b'W': + chunk = bytes(radio.pipe.read(256)) + if len(chunk) != 256: + LOG.error('Received %i for block %02x' % (len(chunk), block)) + raise errors.RadioError('Radio did not send block') + data += chunk + else: + LOG.error('Radio sent %r (%02x), expected W(0x57)' % (cmd, + chr(cmd))) + raise errors.RadioError('Radio sent unexpected response') + + LOG.debug('Read block index %02x' % block) + status() + + chksum = radio.pipe.read(1) + if len(chksum) != 1: + LOG.error('Checksum was %r' % chksum) + raise errors.RadioError('Radio sent invalid checksum') + _chksum = checksum_data(chunk) + + if chunk and _chksum != ord(chksum): + LOG.error( + 'Checksum failed for %i byte block 0x%02x: %02x != %02x' % ( + len(chunk), block, _chksum, ord(chksum))) + raise errors.RadioError('Checksum failure while reading block. ' + 'Check serial cable.') + + radio.pipe.write(b'\x06') + if radio.pipe.read(1) != b'\x06': + raise errors.RadioError('Post-block exchange failed') + + # Addresses 0xC000 - 0xD1F0 pulled by address + for block in range(0x0100, 0x1200, 0x40): + send(radio, make_frame('S', block, b'\x40')) + x = radio.pipe.read(1) + if x != b'X': + raise errors.RadioError('Radio did not send block') + chunk = radio.pipe.read(0x40) + data += chunk + + LOG.debug('Read memory address %04x' % block) + status() + + radio.pipe.write(b'\x06') + if radio.pipe.read(1) != b'\x06': + raise errors.RadioError('Post-block exchange failed') + + radio.pipe.write(b'E') + if radio.pipe.read(1) != b'\x06': + raise errors.RadioError('Radio failed to acknowledge completion') + + LOG.debug('Read %i bytes total' % len(data)) + return data + + +def do_upload(radio): + do_ident(radio) + + def status(addr): + status = chirp_common.Status() + status.cur = addr + status.max = radio._memsize + status.msg = "Cloning to radio" + radio.status_fn(status) + LOG.debug('Radio address 0x%04x' % len(data)) + + for block in range(0, 0xBF + 1): + addr = block * 0x100 + chunk = bytes(radio._mmap[addr:addr + 0x100]) + if all(byte == b'\xff' for byte in chunk): + LOG.debug('Sending zero block %i, range 0x%04x' % (block, addr)) + send(radio, make_frame('Z', block, b'\xFF')) + else: + checksum = checksum_data(chunk) + send(radio, make_frame('W', block, chunk + chr(checksum))) + + ack = radio.pipe.read(1) + if ack != b'\x06': + LOG.error('Radio refused block 0x%02x with %r' % (block, ack)) + raise errors.RadioError('Radio refused data block') + + status(addr) + + addr_base = 0xC000 + for addr in range(addr_base, radio._memsize, 0x40): + block_addr = addr - addr_base + 0x0100 + chunk = radio._mmap[addr:addr + 0x40] + send(radio, make_frame('X', block_addr, b'\x40' + chunk)) + + ack = radio.pipe.read(1) + if ack != b'\x06': + LOG.error('Radio refused address 0x%02x with %r' % (block_addr, + ack)) + raise errors.RadioError('Radio refused data block') + + status(addr) + + radio.pipe.write(b'E') + if radio.pipe.read(1) != b'\x06': + raise errors.RadioError('Radio failed to acknowledge completion') + + +def reset(self): + try: + self.pipe.baudrate = 9600 + self.pipe.write(b'E') + time.sleep(0.5) + self.pipe.baudrate = 19200 + self.pipe.write(b'E') + except Exception: + LOG.error('Unable to send reset sequence') + + +class KenwoodTKx180Radio(chirp_common.CloneModeRadio): + """Kenwood TK-x180""" + VENDOR = 'Kenwood' + MODEL = 'TK-x180' + BAUD_RATE = 9600 + NEEDS_COMPAT_SERIAL = False + + _system_start = 0x0B00 + _memsize = 0xD100 + + def __init__(self, *a, **k): + self._zones = [] + chirp_common.CloneModeRadio.__init__(self, *a, **k) + + def sync_in(self): + try: + data = do_download(self) + self._mmap = memmap.MemoryMapBytes(data) + except errors.RadioError: + reset(self) + raise + except Exception as e: + reset(self) + LOG.exception('General failure') + raise errors.RadioError('Failed to download from radio: %s' % e) + self.process_mmap() + + def sync_out(self): + try: + do_upload(self) + except Exception as e: + reset(self) + LOG.exception('General failure') + raise errors.RadioError('Failed to upload to radio: %s' % e) + + def probe_layout(self): + start_addrs = [] + tmp_format = '#seekto 0x0A00; ul16 zone_starts[128];' + mem = bitwise.parse(tmp_format, self._mmap) + zone_format = """struct zoneinfo { + u8 number; + u8 zonetype; + u8 unknown1[2]; + u8 count; + char name[12]; + u8 unknown2[15]; + };""" + + zone_addresses = [] + for i in range(0, 128): + if mem.zone_starts[i] == 0xFFFF: + break + zone_addresses.append(mem.zone_starts[i]) + zone_format += '#seekto 0x%x; struct zoneinfo zone%i;' % ( + mem.zone_starts[i], i) + + zoneinfo = bitwise.parse(zone_format, self._mmap) + zones = [] + for i, addr in enumerate(zone_addresses): + zone = getattr(zoneinfo, 'zone%i' % i) + if zone.zonetype != 0x31: + LOG.error('Zone %i is type 0x%02x; ' + 'I only support 0x31 (conventional)') + raise errors.RadioError( + 'Unsupported non-conventional zone found in radio; ' + 'Refusing to load to safeguard your data!') + zones.append((addr, zone.count)) + + LOG.debug('Zones: %s' % zones) + return zones + + def process_mmap(self): + self._zones = self.probe_layout() + + mem_format = HEADER_FORMAT + for index, (addr, count) in enumerate(self._zones): + mem_format += '\n\n' + ( + SYSTEM_MEM_FORMAT % { + 'addr': addr, + 'count': max(count, 2), # bitwise bug, one-element array + 'index': index}) + + print(mem_format) + self._memobj = bitwise.parse(mem_format, self._mmap) + + def expand_mmap(self, zone_sizes): + """Remap memory into zones of the specified sizes, copying things + around to keep the contents, as appropriate.""" + old_zones = self._zones + old_memobj = self._memobj + + self._mmap = memmap.MemoryMapBytes(bytes(self._mmap.get_packed())) + + new_format = HEADER_FORMAT + addr = self._system_start + self._zones = [] + for index, count in enumerate(zone_sizes): + new_format += SYSTEM_MEM_FORMAT % { + 'addr': addr, + 'count': max(count, 2), # bitwise bug + 'index': index} + self._zones.append((addr, count)) + addr += 0x20 + (count * 0x30) + + self._memobj = bitwise.parse(new_format, self._mmap) + + # Set all known zone addresses and clear the rest + for index in range(0, 128): + try: + self._memobj.zone_starts[index] = self._zones[index][0] + except IndexError: + self._memobj.zone_starts[index] = 0xFFFF + + for zone_number, count in enumerate(zone_sizes): + dest_zone = getattr(self._memobj, 'zone%i' % zone_number) + dest = dest_zone.memories + dest_zoneinfo = dest_zone.zoneinfo + + if zone_number < len(old_zones): + LOG.debug('Copying existing zone %i' % zone_number) + _, old_count = old_zones[zone_number] + source_zone = getattr(old_memobj, 'zone%i' % zone_number) + source = source_zone.memories + source_zoneinfo = source_zone.zoneinfo + + if old_count != count: + LOG.debug('Zone %i going from %i to %i' % (zone_number, + old_count, + count)) + + # Copy the zone record from the source, but then update + # the count + dest_zoneinfo.set_raw(source_zoneinfo.get_raw()) + dest_zoneinfo.count = count + + source_i = 0 + for dest_i in range(0, min(count, old_count)): + dest[dest_i].set_raw(source[dest_i].get_raw()) + else: + LOG.debug('New zone %i' % zone_number) + dest_zone.zoneinfo.number = zone_number + 1 + dest_zone.zoneinfo.zonetype = 0x31 + dest_zone.zoneinfo.count = count + dest_zone.zoneinfo.name = ( + 'Zone %i' % (zone_number + 1)).ljust(12) + + def shuffle_zone(self): + """Sort the memories in the zone according to logical channel number""" + # FIXME: Move this to the zone + raw_memories = self.raw_memories + memories = [(i, raw_memories[i].number) + for i in range(0, self.raw_zoneinfo.count)] + current = memories[:] + memories.sort(key=lambda t: t[1]) + if current == memories: + LOG.debug('Shuffle not required') + return + raw_data = [raw_memories[i].get_raw() for i, n in memories] + for i, raw_mem in enumerate(raw_data): + raw_memories[i].set_raw(raw_mem) + + @classmethod + def get_prompts(cls): + rp = chirp_common.RadioPrompts() + rp.info = ('This radio is zone-based, which is different from how ' + 'most radios work (that CHIRP supports). The zone count ' + 'can be adjusted in the Settings tab, but you must save ' + 'and re-load the file after changing that value in order ' + 'to be able to add/edit memories there.') + rp.experimental = ('This driver is very experimental. Every attempt ' + 'has been made to be overly pedantic to avoid ' + 'destroying data. However, you should use caution, ' + 'maintain backups, and proceed at your own risk.') + return rp + + def get_features(self): + rf = chirp_common.RadioFeatures() + rf.has_ctone = True + rf.has_cross = True + rf.has_tuning_step = False + rf.has_settings = True + rf.has_bank = False + rf.has_sub_devices = True + rf.can_odd_split = True + rf.valid_tmodes = ['', 'Tone', 'TSQL', 'DTCS'] + rf.valid_bands = [(400000000, 520000000)] + rf.valid_modes = ['FM', 'NFM'] + rf.valid_tuning_steps = [2.5, 5.0, 6.25, 12.5, 10.0, 15.0, 20.0, + 25.0, 50.0, 100.0] + rf.valid_duplexes = ['', '-', '+', 'split', 'off'] + rf.valid_power_levels = POWER_LEVELS + rf.valid_name_length = 12 + rf.valid_characters = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ' + 'abcdefghijklmnopqrstuvwxyz' + '0123456789' + '!"#$%&\'()~+-,./:;<=>?@[\\]^`{}*| ') + rf.memory_bounds = (1, 512) + return rf + + @property + def raw_zone(self): + return getattr(self._memobj, 'zone%i' % self._zone) + + @property + def raw_zoneinfo(self): + return self.raw_zone.zoneinfo + + @property + def raw_memories(self): + return self.raw_zone.memories + + @property + def max_mem(self): + return self.raw_memories[self.raw_zoneinfo.count].number + + def _get_raw_memory(self, number): + for i in range(0, self.raw_zoneinfo.count): + if self.raw_memories[i].number == number: + return self.raw_memories[i] + return None + + def get_raw_memory(self, number): + return repr(self._get_raw_memory(number)) + + @staticmethod + def _decode_tone(toneval): + # DCS examples: + # D024N - 2814 - 0010 1000 0001 0100 + # ^--DCS + # D024I - A814 - 1010 1000 0001 0100 + # ^----inverted + # D754I - A9EC - 1010 1001 1110 1100 + # code in octal-------^^^^^^^^^^^ + + pol = toneval & 0x8000 and 'R' or 'N' + if toneval == 0xFFFF: + return '', None, None + elif toneval & 0x2000: + # DTCS + code = int('%o' % (toneval & 0x1FF)) + return 'DTCS', code, pol + else: + return 'Tone', toneval / 10.0, None + + @staticmethod + def _encode_tone(mode, val, pol): + if not mode: + return 0xFFFF + elif mode == 'Tone': + return int(val * 10) + elif mode == 'DTCS': + code = int('%i' % val, 8) + code |= 0x2000 + if pol == 'R': + code |= 0x8000 + return code + else: + raise errors.RadioError('Unsupported tone mode %r' % mode) + + def get_memory(self, number): + mem = chirp_common.Memory() + mem.number = number + _mem = self._get_raw_memory(number) + if _mem is None: + mem.empty = True + return mem + + mem.name = str(_mem.name).rstrip('\x00') + mem.freq = int(_mem.rx_freq) * 10 + chirp_common.split_tone_decode(mem, + self._decode_tone(_mem.tx_tone), + self._decode_tone(_mem.rx_tone)) + if _mem.wide: + mem.mode = 'FM' + else: + mem.mode = 'NFM' + + mem.power = POWER_LEVELS[_mem.highpower] + + offset = (int(_mem.tx_freq) - int(_mem.rx_freq)) * 10 + if offset == 0: + mem.duplex = '' + elif abs(offset) < 10000000: + mem.duplex = offset < 0 and '-' or '+' + mem.offset = abs(offset) + else: + mem.duplex = 'split' + mem.offset = int(_mem.tx_freq) * 10 + + skipbyte = self._memobj.skipflags[(mem.number - 1) // 8] + skipbit = skipbyte & (1 << (mem.number - 1) % 8) + mem.skip = skipbit and 'S' or '' + + return mem + + def set_memory(self, mem): + _mem = self._get_raw_memory(mem.number) + if _mem is None: + LOG.debug('Need to expand zone %i' % self._zone) + + # Calculate the new zone sizes and remap memory + new_zones = [x[1] for x in self._parent._zones] + new_zones[self._zone] = new_zones[self._zone] + 1 + self._parent.expand_mmap(new_zones) + + # Assign the new memory (at the end) to the desired + # number + _mem = self.raw_memories[self.raw_zoneinfo.count - 1] + _mem.number = mem.number + + # Sort the memory into place + self.shuffle_zone() + + # Now find it in the right spot + _mem = self._get_raw_memory(mem.number) + if _mem is None: + raise errors.RadioError('Internal error after ' + 'memory allocation') + + # Default values for unknown things + _mem.unknown1[0] = 0x36 + _mem.unknown1[1] = 0x36 + _mem.unknown2 = [0xFF for i in range(0, 19)] + _mem.unknown3_1 = 0xF + _mem.unknown3_2 = 0x1 + _mem.unknown3_3 = 0x0 + _mem.unknown4 = 0xFF + + if mem.empty: + LOG.debug('Need to shrink zone %i' % self._zone) + # Make the memory sort to the end, and sort the zone + _mem.number = 0xFF + self.shuffle_zone() + + # Calculate the new zone sizes and remap memory + new_zones = [x[1] for x in self._parent._zones] + new_zones[self._zone] = new_zones[self._zone] - 1 + self._parent.expand_mmap(new_zones) + return + + _mem.name = mem.name[:12].encode().rstrip().ljust(12, b'\x00') + _mem.rx_freq = mem.freq // 10 + + txtone, rxtone = chirp_common.split_tone_encode(mem) + _mem.tx_tone = self._encode_tone(*txtone) + _mem.rx_tone = self._encode_tone(*rxtone) + + _mem.wide = mem.mode == 'FM' + _mem.highpower = mem.power == POWER_LEVELS[1] + + if mem.duplex == '': + _mem.tx_freq = mem.freq // 10 + elif mem.duplex == 'split': + _mem.tx_freq = mem.offset // 10 + elif mem.duplex == 'off': + _mem.tx_freq.set_raw(b'\xff\xff\xff\xff') + elif mem.duplex == '-': + _mem.tx_freq = (mem.freq - mem.offset) // 10 + elif mem.duplex == '+': + _mem.tx_freq = (mem.freq + mem.offset) // 10 + else: + raise errors.RadioError('Unsupported duplex mode %r' % mem.duplex) + + skipbyte = self._memobj.skipflags[(mem.number - 1) // 8] + if mem.skip == 'S': + skipbyte |= (1 << (mem.number - 1) % 8) + else: + skipbyte &= ~(1 << (mem.number - 1) % 8) + + def _pure_choice_setting(self, settings_key, name, choices, default='Off'): + if default is not None: + choices = [default] + choices + s = RadioSetting( + settings_key, name, + RadioSettingValueList( + choices, + get_choice(self._memobj.settings, settings_key, + choices, default))) + s.set_apply_callback(set_choice, self._memobj.settings, + settings_key, choices, default) + return s + + def _inverted_flag_setting(self, key, name, obj=None): + if obj is None: + obj = self._memobj.settings + + def apply_inverted(setting, key): + setattr(obj, key, not int(setting.value)) + + v = not getattr(obj, key) + s = RadioSetting( + key, name, + RadioSettingValueBoolean(v)) + s.set_apply_callback(apply_inverted, key) + return s + + def _get_common1(self): + settings = self._memobj.settings + common1 = RadioSettingGroup('common1', 'Common 1') + + common1.append(self._pure_choice_setting('sublcd', + 'Sub LCD Display', + SUBLCD)) + + def apply_clockfmt(setting): + settings.clockfmt = CLOCKFMT.index(str(setting.value)) + + clockfmt = RadioSetting( + 'clockfmt', 'Clock Format', + RadioSettingValueList(CLOCKFMT, + CLOCKFMT[settings.clockfmt])) + clockfmt.set_apply_callback(apply_clockfmt) + common1.append(clockfmt) + + def apply_datefmt(setting): + settings.datefmt = DATEFMT.index(str(setting.value)) + + datefmt = RadioSetting( + 'datefmt', 'Date Format', + RadioSettingValueList(DATEFMT, + DATEFMT[settings.datefmt])) + datefmt.set_apply_callback(apply_datefmt) + common1.append(datefmt) + + common1.append(self._pure_choice_setting('micsense', + 'Mic Sense High', + MICSENSE)) + + def apply_modereset(setting): + val = int(setting.value) + if val == 0: + val = 0xFFFF + settings.modereset = val + + _modereset = int(settings.modereset) + if _modereset == 0xFFFF: + _modereset = 0 + modereset = RadioSetting( + 'modereset', 'Mode Reset Timer', + RadioSettingValueInteger(0, 300, _modereset)) + modereset.set_apply_callback(apply_modereset) + common1.append(modereset) + + inverted_flags = [('power_switch_memory', 'Power Switch Memory'), + ('scrambler_memory', 'Scrambler Memory'), + ('off_hook_decode', 'Off-Hook Decode'), + ('ssi', 'Signal Strength Indicator'), + ('ignition_sense', 'Ingnition Sense')] + for key, name in inverted_flags: + common1.append(self._inverted_flag_setting(key, name)) + + common1.append(self._pure_choice_setting('ignition_mode', + 'Ignition Mode', + ['Ignition & SW', + 'Ignition Only'], + None)) + + def apply_it(setting): + settings.ignition_time = int(setting.value) / 600 + + _it = int(settings.ignition_time) * 600 + it = RadioSetting( + 'it', 'Ignition Timer (s)', + RadioSettingValueInteger(10, 28800, _it)) + it.set_apply_callback(apply_it) + common1.append(it) + + return common1 + + def _get_common2(self): + settings = self._memobj.settings + common2 = RadioSettingGroup('common2', 'Common 2') + + def apply_ponmsgtext(setting): + settings.pon_msgtext = ( + str(setting.value)[:12].strip().ljust(12, '\x00')) + + common2.append( + self._pure_choice_setting('pon_msgtype', 'Power On Message Type', + STARTUP_MODES)) + + _text = str(settings.pon_msgtext).rstrip('\x00') + text = RadioSetting('settings.pon_msgtext', + 'Power On Text', + RadioSettingValueString( + 0, 12, _text)) + text.set_apply_callback(apply_ponmsgtext) + common2.append(text) + + def apply_volume(setting, key): + setattr(settings, key, VOLUMES[str(setting.value)]) + + volumes = {'poweron_tone': 'Power-on Tone', + 'control_tone': 'Control Tone', + 'warning_tone': 'Warning Tone', + 'alert_tone': 'Alert Tone', + 'sidetone': 'Sidetone', + 'locator_tone': 'Locator Tone'} + for value, name in volumes.items(): + setting = getattr(settings, value) + volume = RadioSetting('settings.%s' % value, name, + RadioSettingValueList( + VOLUMES.keys(), + VOLUMES_REV.get(int(setting), 0))) + volume.set_apply_callback(apply_volume, value) + common2.append(volume) + + def apply_vol_level(setting, key): + setattr(settings, key, int(setting.value)) + + levels = {'lo_volume': 'Low Volume Level (Fixed Volume)', + 'hi_volume': 'High Volume Level (Fixed Volume)', + 'min_volume': 'Minimum Volume', + 'max_volume': 'Maximum Volume'} + for value, name in levels.items(): + setting = getattr(settings, value) + volume = RadioSetting( + 'settings.%s' % value, name, + RadioSettingValueInteger(1, 31, int(setting))) + volume.set_apply_callback(apply_vol_level, value) + common2.append(volume) + + def apply_vo(setting): + val = int(setting.value) + if val < 0: + val = abs(val) | 0x80 + settings.tone_volume_offset = val + + _voloffset = int(settings.tone_volume_offset) + if _voloffset & 0x80: + _voloffset = abs(_voloffset & 0x7F) * -1 + voloffset = RadioSetting( + 'tvo', 'Tone Volume Offset', + RadioSettingValueInteger( + -5, 5, + _voloffset)) + voloffset.set_apply_callback(apply_vo) + common2.append(voloffset) + + def apply_mvp(setting): + settings.min_vol_preset = MIN_VOL_PRESET[str(setting.value)] + + _volpreset = int(settings.min_vol_preset) + volpreset = RadioSetting( + 'mvp', 'Minimum Volume Preset', + RadioSettingValueList(MIN_VOL_PRESET.keys(), + MIN_VOL_PRESET_REV[_volpreset])) + volpreset.set_apply_callback(apply_mvp) + common2.append(volpreset) + + return common2 + + def _get_conventional(self): + settings = self._memobj.settings + + conv = RadioSettingGroup('conv', 'Conventional') + inverted_flags = [('busy_led', 'Busy LED'), + ('ost_memory', 'OST Status Memory'), + ('tone_off', 'Tone Off'), + ('ptt_release', 'PTT Release tone'), + ('ptt_proceed', 'PTT Proceed Tone')] + for key, name in inverted_flags: + conv.append(self._inverted_flag_setting(key, name)) + + def apply_pttt(setting): + settings.ptt_timer = int(setting.value) + + pttt = RadioSetting( + 'pttt', 'PTT Proceed Tone Timer (ms)', + RadioSettingValueInteger(0, 6000, int(settings.ptt_timer))) + pttt.set_apply_callback(apply_pttt) + conv.append(pttt) + + self._get_ost(conv) + + return conv + + def _get_zones(self): + zones = RadioSettingGroup('zones', 'Zones') + + zone_count = RadioSetting('_zonecount', + 'Number of Zones', + RadioSettingValueInteger( + 1, 128, len(self._zones))) + zone_count.set_doc('Number of zones in the radio. ' + 'Requires a save and re-load of the ' + 'file to take effect. Reducing this number ' + 'will DELETE memories in affected zones!') + zones.append(zone_count) + + for i in range(len(self._zones)): + zone = RadioSettingGroup('zone%i' % i, 'Zone %i' % (i + 1)) + + _zone = getattr(self._memobj, 'zone%i' % i).zoneinfo + _name = str(_zone.name).rstrip('\x00') + name = RadioSetting('name%i' % i, 'Name', + RadioSettingValueString(0, 12, _name)) + zone.append(name) + + def apply_timer(setting, key): + val = int(setting.value) + if val == 0: + val = 0xFFFF + setattr(_zone, key, val) + + def collapse(val): + val = int(val) + if val == 0xFFFF: + val = 0 + return val + + timer = RadioSetting( + 'timeout', 'Time-out Timer', + RadioSettingValueInteger(15, 1200, collapse(_zone.timeout))) + timer.set_apply_callback(apply_timer, 'timeout') + zone.append(timer) + + timer = RadioSetting( + 'tot_alert', 'TOT Pre-Alert', + RadioSettingValueInteger(0, 10, collapse(_zone.tot_alert))) + timer.set_apply_callback(apply_timer, 'tot_alert') + zone.append(timer) + + timer = RadioSetting( + 'tot_rekey', 'TOT Re-Key Time', + RadioSettingValueInteger(0, 60, collapse(_zone.tot_rekey))) + timer.set_apply_callback(apply_timer, 'tot_rekey') + zone.append(timer) + + timer = RadioSetting( + 'tot_reset', 'TOT Reset Time', + RadioSettingValueInteger(0, 15, collapse(_zone.tot_reset))) + timer.set_apply_callback(apply_timer, 'tot_reset') + zone.append(timer) + + zone.append(self._inverted_flag_setting( + 'bcl_override', 'BCL Override', + _zone)) + + zones.append(zone) + + return zones + + def _get_ost(self, parent): + tones = chirp_common.TONES[:] + + def apply_tone(setting, index, which): + if str(setting.value) == 'Off': + val = 0xFFFF + else: + val = int(float(str(setting.value)) * 10) + setattr(self._memobj.ost_tones[index], '%stone' % which, val) + + def _tones(): + return ['Off'] + [str(x) for x in tones] + + for i in range(0, 40): + _ost = self._memobj.ost_tones[i] + ost = RadioSettingGroup('ost%i' % i, + 'OST %i' % (i + 1)) + + cur = str(_ost.name).rstrip('\x00') + name = RadioSetting('name%i' % i, 'Name', + RadioSettingValueString(0, 12, cur)) + ost.append(name) + + if _ost.rxtone == 0xFFFF: + cur = 'Off' + else: + cur = round(int(_ost.rxtone) / 10.0, 1) + if cur not in tones: + LOG.debug('Non-standard OST rx tone %i %s' % (i, cur)) + tones.append(cur) + tones.sort() + rx = RadioSetting('rxtone%i' % i, 'RX Tone', + RadioSettingValueList(_tones(), + str(cur))) + rx.set_apply_callback(apply_tone, i, 'rx') + ost.append(rx) + + if _ost.txtone == 0xFFFF: + cur = 'Off' + else: + cur = round(int(_ost.txtone) / 10.0, 1) + if cur not in tones: + LOG.debug('Non-standard OST tx tone %i %s' % (i, cur)) + tones.append(cur) + tones.sort() + tx = RadioSetting('txtone%i' % i, 'TX Tone', + RadioSettingValueList(_tones(), + str(cur))) + tx.set_apply_callback(apply_tone, i, 'tx') + ost.append(tx) + + parent.append(ost) + + def get_settings(self): + settings = self._memobj.settings + + zones = self._get_zones() + common1 = self._get_common1() + common2 = self._get_common2() + conv = self._get_conventional() + top = RadioSettings(zones, common1, common2, conv) + return top + + def set_settings(self, settings): + for element in settings: + if not isinstance(element, RadioSetting): + self.set_settings(element) + continue + elif element.get_name() == '_zonecount': + new_zone_count = int(element.value) + zone_sizes = [x[1] for x in self._zones[:new_zone_count]] + if len(self._zones) > new_zone_count: + self.expand_mmap(zone_sizes[:new_zone_count]) + elif len(self._zones) < new_zone_count: + self.expand_mmap(zone_sizes + ( + [0] * (new_zone_count - len(self._zones)))) + elif element.has_apply_callback(): + element.run_apply_callback() + + def get_sub_devices(self): + zones = [] + for i, _ in enumerate(self._zones): + zone = getattr(self._memobj, 'zone%i' % i) + + class _Zone(KenwoodTKx180RadioZone): + VENDOR = self.VENDOR + MODEL = self.MODEL + VARIANT = 'Zone %s' % ( + str(zone.zoneinfo.name).rstrip('\x00').rstrip()) + + zones.append(_Zone(self, i)) + return zones + + +class KenwoodTKx180RadioZone(KenwoodTKx180Radio): + _zone = None + + def __init__(self, parent, zone=0): + if isinstance(parent, KenwoodTKx180Radio): + self._parent = parent + else: + LOG.warning('Parent was not actually our parent, expect failure') + self._zone = zone + + @property + def _zones(self): + return self._parent._zones + + @property + def _memobj(self): + return self._parent._memobj + + def load_mmap(self, filename): + self._parent.load_mmap(filename) + + def get_features(self): + rf = KenwoodTKx180Radio.get_features(self) + rf.has_sub_devices = False + rf.memory_bounds = (1, 250) + return rf + + def get_sub_devices(self): + return [] + + +if has_future: + @directory.register + class KenwoodTK8180Radio(KenwoodTKx180Radio): + MODEL = 'TK-8180' diff --git a/chirp/drivers/uv5r.py b/chirp/drivers/uv5r.py index d2e8594..737c1f6 100644 --- a/chirp/drivers/uv5r.py +++ b/chirp/drivers/uv5r.py @@ -280,14 +280,14 @@ struct { vhf_220_radio = "\x02" -BASETYPE_UV5R = ["BFS", "BFB", "N5R-2", "N5R2", "N5RV", "BTS", "D5R2"] +BASETYPE_UV5R = ["BFS", "BFB", "N5R-2", "N5R2", "N5RV", "BTS", "D5R2", "B5R2"] BASETYPE_F11 = ["USA"] BASETYPE_UV82 = ["US2S2", "B82S", "BF82", "N82-2", "N822"] BASETYPE_BJ55 = ["BJ55"] # needed for for the Baojie UV-55 in bjuv55.py BASETYPE_UV6 = ["BF1", "UV6"] BASETYPE_KT980HP = ["BFP3V3 B"] BASETYPE_F8HP = ["BFP3V3 F", "N5R-3", "N5R3", "F5R3", "BFT"] -BASETYPE_UV82HP = ["N82-3", "N823"] +BASETYPE_UV82HP = ["N82-3", "N823", "N5R2"] BASETYPE_LIST = BASETYPE_UV5R + BASETYPE_F11 + BASETYPE_UV82 + \ BASETYPE_BJ55 + BASETYPE_UV6 + BASETYPE_KT980HP + \ BASETYPE_F8HP + BASETYPE_UV82HP @@ -773,6 +773,7 @@ class BaofengUV5R(chirp_common.CloneModeRadio, rf.valid_power_levels = UV5R_POWER_LEVELS rf.valid_duplexes = ["", "-", "+", "split", "off"] rf.valid_modes = ["FM", "NFM"] + rf.valid_tuning_steps = STEPS normal_bands = [self._vhf_range, self._uhf_range] rax_bands = [self._vhf_range, self._220_range] @@ -1216,7 +1217,7 @@ class BaofengUV5R(chirp_common.CloneModeRadio, COLOR_LIST, COLOR_LIST[_settings.txled])) basic.append(rs) - if self.MODEL == "UV-82": + if isinstance(self, BaofengUV82Radio): rs = RadioSetting("roger", "Roger Beep (TX)", RadioSettingValueBoolean(_settings.roger)) basic.append(rs) @@ -1259,7 +1260,7 @@ class BaofengUV5R(chirp_common.CloneModeRadio, RadioSettingValueBoolean(_settings.vfomrlock)) advanced.append(rs) - if self.MODEL == "UV-82": + if isinstance(self, BaofengUV82Radio): # this is a UV-82C only feature rs = RadioSetting("vfomrlock", "VFO/MR Switching (UV-82C only)", RadioSettingValueBoolean(_settings.vfomrlock)) @@ -1272,7 +1273,7 @@ class BaofengUV5R(chirp_common.CloneModeRadio, RadioSettingValueBoolean(_settings.vfomrlock)) advanced.append(rs) - if self.MODEL == "UV-82": + if isinstance(self, BaofengUV82Radio): # this is an UV-82C only feature rs = RadioSetting("singleptt", "Single PTT (UV-82C only)", RadioSettingValueBoolean(_settings.singleptt)) @@ -1759,10 +1760,15 @@ class ROUV5REXAlias(chirp_common.Alias): MODEL = "UV-5R EX" +class A5RAlias(chirp_common.Alias): + VENDOR = "Ansoko" + MODEL = "A-5R" + + @directory.register class BaofengUV5RGeneric(BaofengUV5R): ALIASES = [UV5XAlias, RT5RAlias, RT5RVAlias, RT5Alias, RH5RAlias, - ROUV5REXAlias] + ROUV5REXAlias, A5RAlias] @directory.register @@ -1792,6 +1798,19 @@ class BaofengUV82Radio(BaofengUV5R): @directory.register +class Radioddity82X3Radio(BaofengUV82Radio): + VENDOR = "Radioddity" + MODEL = "UV-82X3" + + def get_features(self): + rf = BaofengUV5R.get_features(self) + rf.valid_bands = [self._vhf_range, + (200000000, 260000000), + self._uhf_range] + return rf + + +@directory.register class BaofengUV6Radio(BaofengUV5R): """Baofeng UV-6/UV-7""" diff --git a/chirp/drivers/uvb5.py b/chirp/drivers/uvb5.py index 3300005..e4d53ba 100644 --- a/chirp/drivers/uvb5.py +++ b/chirp/drivers/uvb5.py @@ -253,10 +253,6 @@ def do_upload(radio): DUPLEX = ["", "-", "+"] UVB5_STEPS = [5.00, 6.25, 10.0, 12.5, 20.0, 25.0] CHARSET = "0123456789- ABCDEFGHIJKLMNOPQRSTUVWXYZ/_+*" -SPECIALS = { - "VFO1": -2, - "VFO2": -1, - } POWER_LEVELS = [chirp_common.PowerLevel("Low", watts=1), chirp_common.PowerLevel("High", watts=5)] @@ -268,6 +264,10 @@ class BaofengUVB5(chirp_common.CloneModeRadio, VENDOR = "Baofeng" MODEL = "UV-B5" BAUD_RATE = 9600 + SPECIALS = { + "VFO1": -2, + "VFO2": -1, + } _memsize = 0x1000 @@ -310,11 +310,12 @@ class BaofengUVB5(chirp_common.CloneModeRadio, rf.valid_skips = ["", "S"] rf.valid_characters = CHARSET rf.valid_name_length = 5 + rf.valid_tuning_steps = UVB5_STEPS rf.valid_bands = [(130000000, 175000000), (220000000, 269000000), (400000000, 520000000)] rf.valid_modes = ["FM", "NFM"] - rf.valid_special_chans = SPECIALS.keys() + rf.valid_special_chans = self.SPECIALS.keys() rf.valid_power_levels = POWER_LEVELS rf.has_ctone = True rf.has_bank = False @@ -345,7 +346,13 @@ class BaofengUVB5(chirp_common.CloneModeRadio, def get_raw_memory(self, number): return repr(self._memobj.channels[number - 1]) - def _decode_tone(self, value, flag): + def _decode_tone(self, _mem, which): + def _get(field): + return getattr(_mem, "%s%s" % (which, field)) + + value = _get('tone') + flag = _get('pol') + if value > 155: mode = val = pol = None elif value > 50: @@ -389,7 +396,7 @@ class BaofengUVB5(chirp_common.CloneModeRadio, _mem, _nam = self._get_memobjs(number) mem = chirp_common.Memory() if isinstance(number, str): - mem.number = SPECIALS[number] + mem.number = self.SPECIALS[number] mem.extd_number = number else: mem.number = number @@ -403,10 +410,10 @@ class BaofengUVB5(chirp_common.CloneModeRadio, chirp_common.split_tone_decode( mem, - self._decode_tone(_mem.txtone, _mem.txpol), - self._decode_tone(_mem.rxtone, _mem.rxpol)) + self._decode_tone(_mem, "tx"), + self._decode_tone(_mem, "rx")) - if _mem.step > 0x05: + if 'step' in _mem and _mem.step > 0x05: _mem.step = 0x00 mem.duplex = DUPLEX[_mem.duplex] mem.mode = _mem.isnarrow and "NFM" or "FM" diff --git a/chirp/drivers/vgc.py b/chirp/drivers/vgc.py index e47a057..f5da899 100644 --- a/chirp/drivers/vgc.py +++ b/chirp/drivers/vgc.py @@ -318,9 +318,9 @@ LIST_WORK = ["VFO", "Memory System"] LIST_WBANDB = ["Air", "H-V", "GR1-V", "GR1-U", "H-U", "GR2"] LIST_WBANDA = ["Line-in", "AM", "FM"] + LIST_WBANDB LIST_SQL = ["Open"] + ["%s" % x for x in range(1, 10)] -LIST_STEP = ["Auto", "2.50 KHz", "5.00 KHz", "6.25 KHz", "8.33 KHz", - "9.00 KHz", "10.00 KHz", "12.50 KHz", "15.00 KHz", "20.00 KHz", - "25.00 KHz", "50.00 KHz", "100.00 KHz", "200.00 KHz"] +_STEP_LIST = [2.5, 5., 6.25, 8.33, 9., 10., 12.5, 15., 20., 25., 50., 100., + 200.] +LIST_STEP = ["Auto"] + ["{0:.2f} KHz".format(x) for x in _STEP_LIST] LIST_SMODE = ["F-1", "F-2"] # DTMF settings lists @@ -631,6 +631,7 @@ class VGCStyleRadio(chirp_common.CloneModeRadio, rf.valid_skips = SKIP_VALUES rf.valid_name_length = NAME_LENGTH rf.valid_dtcs_codes = DTCS_CODES + rf.valid_tuning_steps = _STEP_LIST rf.valid_bands = [self._air_range, self._vhf_range, self._vhf2_range, diff --git a/chirp/drivers/vx6.py b/chirp/drivers/vx6.py index bfbc109..15f34e2 100644 --- a/chirp/drivers/vx6.py +++ b/chirp/drivers/vx6.py @@ -15,7 +15,11 @@ from chirp.drivers import yaesu_clone from chirp import chirp_common, directory, bitwise +from chirp.settings import RadioSettingGroup, RadioSetting, RadioSettings +from chirp.settings import RadioSettingValueString, RadioSettingValueList +from chirp.settings import RadioSettingValueBoolean from textwrap import dedent +import re # flags.{even|odd}_pskip: These are actually "preferential *scan* channels". # Is that what they mean on other radios as well? @@ -37,15 +41,110 @@ from textwrap import dedent # D Tone: Encodes DCS code, decodes tone # } MEM_FORMAT = """ +#seekto 0x010A; +struct { + u8 auto_power_off; + u8 arts_beep; + u8 bell; + u8 beep_level; + u8 arts_cwid_alpha[16]; + u8 unk1[2]; + u8 channel_counter_width; + u8 lcd_dimmer; + u8 last_dtmf; + u8 unk2; + u8 internet_code; + u8 last_internet_dtmf; + u8 unk3[3]; + u8 emergency; + u8 unk4[16]; + u8 lamp; + u8 lock; + u8 unk5; + u8 mic_gain; + u8 unk6[2]; + u8 on_timer; + u8 open_message_mode; + u8 open_message[6]; + u8 unk7; + u8 unk8:6, + pager_answer_back:1, + unk9:1; + u8 pager_rx_tone1; + u8 pager_rx_tone2; + u8 pager_tx_tone1; + u8 pager_tx_tone2; + u8 password[4]; + u8 ptt_delay; + u8 rf_squelch; + u8 rx_save; + u8 resume; + u8 unk10[5]; + u8 tx_timeout; + u8 wakeup; + u8 vfo_mode:1, + arts_cwid:1, + scan_lamp:1, + ts_speed:1, + unk11:1, + beep:1, + unk12:1, + dtmf_autodial:1; + u8 busy_led:1, + tone_search_mute:1, + int_autodial:1, + bclo:1, + edge_beep:1, + unk13:1, + dmr_wrt:1, + tx_saver:1; + u8 unk14:2, + smart_search:1, + unk15:3, + home_rev:1, + moni_tcall:1; + u8 unk16:3, + arts_interval:1, + unk17:3, + memory_method:1; + u8 unk18:2, + internet_mode:1, + wx_alert:1, + unk19:1, + att:1, + unk20:2; +} settings; + #seekto 0x018A; struct { - u16 in_use; + u16 in_use; } bank_used[24]; +#seekto 0x01D8; +u8 clock_shift; + #seekto 0x0214; -u16 banksoff1; +u16 banksoff1; + +#seekto 0x0248; +u8 lastsetting1; + #seekto 0x0294; -u16 banksoff2; +u16 banksoff2; + +#seekto 0x0248; +u8 lastsetting2; + +#seekto 0x02CA; +struct { + u8 memory[16]; +} dtmf[10]; + +#seekto 0x03CA; +struct { + u8 memory[8]; + u8 empty_ff[8]; +} internet_dtmf[64]; #seekto 0x097A; struct { @@ -95,15 +194,17 @@ struct { DUPLEX = ["", "-", "+", "split"] MODES = ["FM", "AM", "WFM", "FM"] # last is auto TMODES = ["", "Tone", "TSQL", "DTCS"] +DTMFCHARSET = list("0123456789ABCD*#-") STEPS = [5.0, 10.0, 12.5, 15.0, 20.0, 25.0, 50.0, 100.0, 9.0, 200.0, 5.0] # last is auto, 9.0k and 200.0k are unadvertised - -CHARSET = ["%i" % int(x) for x in range(0, 10)] + \ +CHARSET = ["%i" % int(x) for x in range(10)] + \ [chr(x) for x in range(ord("A"), ord("Z")+1)] + \ list(" +-/\x00[]__" + ("\x00" * 9) + "$%%\x00**.|=\\\x00@") + \ list("\x00" * 100) +PASS_CHARSET = list("0123456789ABCDEF") + POWER_LEVELS = [chirp_common.PowerLevel("Hi", watts=5.00), chirp_common.PowerLevel("L3", watts=2.50), chirp_common.PowerLevel("L2", watts=1.00), @@ -220,6 +321,42 @@ class VX6Radio(yaesu_clone.YaesuCloneModeRadio): _block_lengths = [10, 32577] _block_size = 16 + _APO = ("OFF", "30 min", "1 hour", "3 hour", "5 hour", "8 hour") + _ARTSBEEP = ("Off", "In Range", "Always") + _ARTS_INT = ("15 S", "25 S") + _BELL = ("OFF", "1", "3", "5", "8", "Continuous") + _BEEP_LEVEL = ["%i" % int(x) for x in range(1, 10)] + _CH_CNT = ("5 MHZ", "10 MHZ", "50 MHZ", "100 MHZ") + _DIM_LEVEL = ["%i" % int(x) for x in range(0, 13)] + _EMERGENCY = ("Beep", "Strobe", "Bp+Str", "Beam", "Bp+Bem", "CW", + "Bp+CW", "CWT") + _HOME_REV = ("HOME", "REV") + _INT_CD = ["%i" % int(x) for x in range(0, 10)] + \ + [chr(x) for x in range(ord("A"), ord("F")+1)] + _INT_MD = ("SRG: Sister Radio Group", "FRG: Friendly Radio Group") + _LAMP = ("Key", "Continuous", "Off") + _LOCK = ("Key", "Dial", "Key+Dial", "PTT", "Key+PTT", "Dial+PTT", "All") + _MAN_AUTO = ("Manual", "Auto") + _MEM_W_MD = ("Lower", "Next") + _MONI_TCALL = ("MONI", "T-CALL") + _NUM_1_9 = ["%i" % int(x) for x in range(1, 10)] + _NUM_0_9 = ["%i" % int(x) for x in range(10)] + _NUM_0_63 = ["%i" % int(x) for x in range(64)] + _NUM_1_50 = ["%i" % int(x) for x in range(1, 51)] + _ON_TIMER = ["OFF"] + \ + ["%02d:%02d" % (t / 60, t % 60) for t in range(10, 1450, 10)] + _OPEN_MSG = ("Off", "DC Voltage", "Message") + _PTT_DELAY = ("OFF", "20MS", "50MS", "100MS", "200MS") + _RF_SQL = ("OFF", "S1", "S2", "S3", "S4", "S5", + "S6", "S7", "S8", "S9", "S9+") + _RX_SAVE = ("OFF", "200 ms", "300 MS", "500 MS", "1 S", "2 S") + _RESUME = ("3 SEC", "5 SEC", "10 SEC", "BUSY", "HOLD") + _SMART_SEARCH = ("SINGLE", "CONT") + _TOT = ("OFF", "1MIN", "3MIN", "5MIN", "10MIN") + _TS_SPEED = ("FAST", "SLOW") + _VFO_MODE = ("ALL", "BAND") + _WAKEUP = ("OFF", "5S", "10S", "20S", "30S", "EAI") + @classmethod def get_prompts(cls): rp = chirp_common.RadioPrompts() @@ -259,6 +396,7 @@ class VX6Radio(yaesu_clone.YaesuCloneModeRadio): rf.valid_name_length = 6 rf.can_odd_split = True rf.has_ctone = False + rf.has_settings = True return rf def get_raw_memory(self, number): @@ -367,3 +505,371 @@ class VX6Radio(yaesu_clone.YaesuCloneModeRadio): def get_bank_model(self): return VX6BankModel(self) + + def _decode_chars(self, inarr): + outstr = "" + for i in inarr: + if i == 0xFF: + break + outstr += CHARSET[i & 0x7F] + return outstr.rstrip() + + def _encode_chars(self, instr, length=16): + outarr = [] + instr = str(instr) + for i in range(length): + if i < len(instr): + outarr.append(CHARSET.index(instr[i])) + else: + outarr.append(0xFF) + return outarr + + def _get_settings(self): + _settings = self._memobj.settings + basic = RadioSettingGroup("basic", "Basic") + arts = RadioSettingGroup("arts", "ARTS") + dtmf = RadioSettingGroup("dtmf", "DTMF") + wires = RadioSettingGroup("wires", "WIRES") + misc = RadioSettingGroup("misc", "Misc") + top = RadioSettings(basic, arts, dtmf, wires, misc) + + # BASIC + + val = RadioSettingValueList( + self._APO, self._APO[_settings.auto_power_off]) + rs = RadioSetting("auto_power_off", "Auto Power Off", val) + basic.append(rs) + + val = RadioSettingValueList( + self._BEEP_LEVEL, self._BEEP_LEVEL[_settings.beep_level]) + rs = RadioSetting("beep_level", "Beep Level", val) + basic.append(rs) + + val = RadioSettingValueList( + self._DIM_LEVEL, self._DIM_LEVEL[_settings.lcd_dimmer]) + rs = RadioSetting("lcd_dimmer", "Dimmer Level", val) + basic.append(rs) + + val = RadioSettingValueList( + self._LAMP, self._LAMP[_settings.lamp]) + rs = RadioSetting("lamp", "Keypad Lamp", val) + basic.append(rs) + + val = RadioSettingValueList( + self._LOCK, self._LOCK[_settings.lock]) + rs = RadioSetting("lock", "Lock", val) + basic.append(rs) + + val = RadioSettingValueList( + self._NUM_1_9, self._NUM_1_9[_settings.mic_gain]) + rs = RadioSetting("mic_gain", "Mic Gain", val) + basic.append(rs) + + val = RadioSettingValueList( + self._OPEN_MSG, self._OPEN_MSG[_settings.open_message_mode]) + rs = RadioSetting("open_message_mode", + "Open Message Mode", val) + basic.append(rs) + + val = RadioSettingValueString(0, 6, + self._decode_chars( + _settings.open_message)) + val.set_charset(CHARSET) + rs = RadioSetting("open_message", "Opening Message", val) + basic.append(rs) + + passstr = "" + for c in _settings.password: + if c < len(PASS_CHARSET): + passstr += PASS_CHARSET[c] + val = RadioSettingValueString(0, 4, passstr) + val.set_charset(PASS_CHARSET) + rs = RadioSetting("password", "Password", val) + basic.append(rs) + + val = RadioSettingValueList( + self._RESUME, self._RESUME[_settings.resume]) + rs = RadioSetting("resume", "Scan Resume", val) + basic.append(rs) + + val = RadioSettingValueList( + self._MONI_TCALL, self._MONI_TCALL[_settings.moni_tcall]) + rs = RadioSetting("moni_tcall", "MONI/T-CALL switch", val) + basic.append(rs) + + rs = RadioSetting("scan_lamp", "Scan Lamp", + RadioSettingValueBoolean(_settings.scan_lamp)) + basic.append(rs) + + rs = RadioSetting("beep", "Keypad Beep", + RadioSettingValueBoolean(_settings.beep)) + basic.append(rs) + + rs = RadioSetting("busy_led", "Busy LED", + RadioSettingValueBoolean(_settings.busy_led)) + basic.append(rs) + + rs = RadioSetting("bclo", "Busy Channel Lock-Out", + RadioSettingValueBoolean(_settings.bclo)) + basic.append(rs) + + rs = RadioSetting("wx_alert", "WX Alert", + RadioSettingValueBoolean(_settings.wx_alert)) + basic.append(rs) + + rs = RadioSetting("att", "Attenuator", + RadioSettingValueBoolean(_settings.att)) + basic.append(rs) + + # ARTS + + val = RadioSettingValueList( + self._ARTS_INT, self._ARTS_INT[_settings.arts_interval]) + rs = RadioSetting("arts_interval", "ARTS Interval", val) + arts.append(rs) + + val = RadioSettingValueList( + self._ARTSBEEP, self._ARTSBEEP[_settings.arts_beep]) + rs = RadioSetting("arts_beep", "ARTS Beep", val) + arts.append(rs) + + rs = RadioSetting("arts_cwid", "ARTS Send CWID", + RadioSettingValueBoolean(_settings.arts_cwid)) + arts.append(rs) + + val = RadioSettingValueString(0, 16, + self._decode_chars( + _settings.arts_cwid_alpha)) + val.set_charset(CHARSET) + rs = RadioSetting("arts_cwid_alpha", "ARTS CW ID", val) + arts.append(rs) + + # DTMF + + val = RadioSettingValueList( + self._MAN_AUTO, self._MAN_AUTO[_settings.dtmf_autodial]) + rs = RadioSetting("dtmf_autodial", "DTMF Autodial", val) + dtmf.append(rs) + + val = RadioSettingValueList( + self._NUM_0_9, self._NUM_0_9[_settings.last_dtmf]) + rs = RadioSetting("last_dtmf", "Last DTMF Memory Set", val) + dtmf.append(rs) + + for i in range(10): + name = "dtmf_" + str(i) + dtmfsetting = self._memobj.dtmf[i] + dtmfstr = "" + for c in dtmfsetting.memory: + if c < len(DTMFCHARSET): + dtmfstr += DTMFCHARSET[c] + dtmfentry = RadioSettingValueString(0, 16, dtmfstr) + rs = RadioSetting(name, name.upper(), dtmfentry) + dtmf.append(rs) + + # WIRES + + val = RadioSettingValueList( + self._INT_CD, self._INT_CD[_settings.internet_code]) + rs = RadioSetting("internet_code", "Internet Code", val) + wires.append(rs) + + val = RadioSettingValueList( + self._INT_MD, self._INT_MD[_settings.internet_mode]) + rs = RadioSetting("internet_mode", + "Internet Link Connection mode", val) + wires.append(rs) + + val = RadioSettingValueList( + self._MAN_AUTO, self._MAN_AUTO[_settings.int_autodial]) + rs = RadioSetting("int_autodial", "Internet Autodial", val) + wires.append(rs) + + val = RadioSettingValueList( + self._NUM_0_63, self._NUM_0_63[_settings.last_internet_dtmf]) + rs = RadioSetting("last_internet_dtmf", + "Last Internet DTMF Memory Set", val) + wires.append(rs) + + for i in range(64): + name = "wires_dtmf_" + str(i) + dtmfsetting = self._memobj.internet_dtmf[i] + dtmfstr = "" + for c in dtmfsetting.memory: + if c < len(DTMFCHARSET): + dtmfstr += DTMFCHARSET[c] + dtmfentry = RadioSettingValueString(0, 8, dtmfstr) + rs = RadioSetting(name, name.upper(), dtmfentry) + wires.append(rs) + + # MISC + + val = RadioSettingValueList( + self._BELL, self._BELL[_settings.bell]) + rs = RadioSetting("bell", "CTCSS/DCS Bell", val) + misc.append(rs) + + val = RadioSettingValueList( + self._CH_CNT, self._CH_CNT[_settings.channel_counter_width]) + rs = RadioSetting("channel_counter_width", + "Channel Counter Search Width", val) + misc.append(rs) + + val = RadioSettingValueList( + self._EMERGENCY, self._EMERGENCY[_settings.emergency]) + rs = RadioSetting("emergency", "Emergency alarm", val) + misc.append(rs) + + val = RadioSettingValueList( + self._ON_TIMER, self._ON_TIMER[_settings.on_timer]) + rs = RadioSetting("on_timer", "On Timer", val) + misc.append(rs) + + rs = RadioSetting("pager_answer_back", "Pager Answer Back", + RadioSettingValueBoolean( + _settings.pager_answer_back)) + misc.append(rs) + + val = RadioSettingValueList( + self._NUM_1_50, self._NUM_1_50[_settings.pager_rx_tone1]) + rs = RadioSetting("pager_rx_tone1", "Pager RX Tone 1", val) + misc.append(rs) + + val = RadioSettingValueList( + self._NUM_1_50, self._NUM_1_50[_settings.pager_rx_tone2]) + rs = RadioSetting("pager_rx_tone2", "Pager RX Tone 2", val) + misc.append(rs) + + val = RadioSettingValueList( + self._NUM_1_50, self._NUM_1_50[_settings.pager_tx_tone1]) + rs = RadioSetting("pager_tx_tone1", "Pager TX Tone 1", val) + misc.append(rs) + + val = RadioSettingValueList( + self._NUM_1_50, self._NUM_1_50[_settings.pager_tx_tone2]) + rs = RadioSetting("pager_tx_tone2", "Pager TX Tone 2", val) + misc.append(rs) + + val = RadioSettingValueList( + self._PTT_DELAY, self._PTT_DELAY[_settings.ptt_delay]) + rs = RadioSetting("ptt_delay", "PTT Delay", val) + misc.append(rs) + + val = RadioSettingValueList( + self._RF_SQL, self._RF_SQL[_settings.rf_squelch]) + rs = RadioSetting("rf_squelch", "RF Squelch", val) + misc.append(rs) + + val = RadioSettingValueList( + self._RX_SAVE, self._RX_SAVE[_settings.rx_save]) + rs = RadioSetting("rx_save", "RX Save", val) + misc.append(rs) + + val = RadioSettingValueList( + self._TOT, self._TOT[_settings.tx_timeout]) + rs = RadioSetting("tx_timeout", "TOT", val) + misc.append(rs) + + val = RadioSettingValueList( + self._WAKEUP, self._WAKEUP[_settings.wakeup]) + rs = RadioSetting("wakeup", "Wakeup", val) + misc.append(rs) + + rs = RadioSetting("edge_beep", "Band-Edge Beep", + RadioSettingValueBoolean(_settings.edge_beep)) + misc.append(rs) + + val = RadioSettingValueList( + self._VFO_MODE, self._VFO_MODE[_settings.vfo_mode]) + rs = RadioSetting("vfo_mode", "VFO Band Edge Limiting", val) + misc.append(rs) + + rs = RadioSetting("tone_search_mute", "Tone Search Mute", + RadioSettingValueBoolean(_settings.tone_search_mute)) + misc.append(rs) + + val = RadioSettingValueList( + self._TS_SPEED, self._TS_SPEED[_settings.ts_speed]) + rs = RadioSetting("ts_speed", "Tone Search Speed", val) + misc.append(rs) + + rs = RadioSetting("dmr_wrt", "Direct Memory Recall Overwrite", + RadioSettingValueBoolean(_settings.dmr_wrt)) + misc.append(rs) + + rs = RadioSetting("tx_saver", "TX Battery Saver", + RadioSettingValueBoolean(_settings.tx_saver)) + misc.append(rs) + + val = RadioSettingValueList( + self._SMART_SEARCH, self._SMART_SEARCH[_settings.smart_search]) + rs = RadioSetting("smart_search", "Smart Search", val) + misc.append(rs) + + val = RadioSettingValueList( + self._HOME_REV, self._HOME_REV[_settings.home_rev]) + rs = RadioSetting("home_rev", "HM/RV(EMG)R/H key", val) + misc.append(rs) + + val = RadioSettingValueList( + self._MEM_W_MD, self._MEM_W_MD[_settings.memory_method]) + rs = RadioSetting("memory_method", "Memory Write Method", val) + misc.append(rs) + + return top + + def get_settings(self): + try: + return self._get_settings() + except: + import traceback + pring(traceback.format_exc()) + return None + + def set_settings(self, uisettings): + for element in uisettings: + if not isinstance(element, RadioSetting): + self.set_settings(element) + continue + if not element.changed(): + continue + try: + setting = element.get_name() + _settings = self._memobj.settings + if re.match('internet_dtmf_\d', setting): + # set dtmf fields + dtmfstr = str(element.value).strip() + newval = [] + for i in range(0, 8): + if i < len(dtmfstr): + newval.append(DTMFCHARSET.index(dtmfstr[i])) + else: + newval.append(0xFF) + idx = int(setting[-1:]) + _settings = self._memobj.internet_dtmf[idx] + _settings.memory = newval + continue + elif re.match('dtmf_\d', setting): + # set dtmf fields + dtmfstr = str(element.value).strip() + newval = [] + for i in range(0, 16): + if i < len(dtmfstr): + newval.append(DTMFCHARSET.index(dtmfstr[i])) + else: + newval.append(0xFF) + idx = int(setting[-1:]) + _settings = self._memobj.dtmf[idx] + _settings.memory = newval + continue + oldval = getattr(_settings, setting) + newval = element.value + if setting == "arts_cwid_alpha": + newval = self._encode_chars(newval) + elif setting == "open_message": + newval = self._encode_chars(newval, 6) + elif setting == "password": + newval = self._encode_chars(newval, 4) + setattr(_settings, setting, newval) + except Exception, e: + raise diff --git a/chirp/drivers/wouxun.py b/chirp/drivers/wouxun.py index fc482fe..ade91de 100644 --- a/chirp/drivers/wouxun.py +++ b/chirp/drivers/wouxun.py @@ -327,6 +327,7 @@ class KGUVD1PRadio(chirp_common.CloneModeRadio, rf.valid_characters = "".join(self.CHARSET) rf.valid_name_length = 6 rf.valid_duplexes = ["", "+", "-", "split", "off"] + rf.valid_tuning_steps = [5.0, 6.25, 10.0, 12.5, 25.0, 50.0, 100.0] rf.has_ctone = True rf.has_rx_dtcs = True rf.has_cross = True diff --git a/chirp/memmap.py b/chirp/memmap.py index af0706c..be83a1e 100644 --- a/chirp/memmap.py +++ b/chirp/memmap.py @@ -84,3 +84,10 @@ class MemoryMap: def truncate(self, size): """Truncate the memory map to @size""" self._data = self._data[:size] + + +# Py3 branch compatibility +class MemoryMapBytes(MemoryMap): + def __init__(self, data): + # Expects data is a newbytes + MemoryMap.__init__(self, ''.join(chr(b) for b in data)) diff --git a/chirp/ui/mainapp.py b/chirp/ui/mainapp.py index e8904e7..f527227 100644 --- a/chirp/ui/mainapp.py +++ b/chirp/ui/mainapp.py @@ -1015,7 +1015,7 @@ of file. except: band = 14 # 2m default - query = "http://www.repeaterbook.com/repeaters/downloads/chirp.php" + \ + query = "http://chirp.danplanet.com/query/rb/1.0/chirp" + \ "?func=default&state_id=%s&band=%s&freq=%%&band6=%%&loc=%%" + \ "&county_id=%s&status_id=%%&features=%%&coverage=%%&use=%%" query = query % (code, @@ -1125,8 +1125,8 @@ of file. except: band = '%' - query = "https://www.repeaterbook.com/repeaters/downloads/CHIRP/" \ - "app_direct.php?loc=%s&band=%s&dist=%s" % (loc, band, dist) + query = "http://chirp.danplanet.com/query/rb/1.0/app_direct" \ + "?loc=%s&band=%s&dist=%s" % (loc, band, dist) print query # Do this in case the import process is going to take a while @@ -1427,7 +1427,7 @@ of file. d.set_name("CHIRP") d.set_version(CHIRP_VERSION) - d.set_copyright("Copyright 2015 Dan Smith (KK7DS)") + d.set_copyright("Copyright 2019 CHIRP Software LLC") d.set_website("http://chirp.danplanet.com") d.set_authors(("Dan Smith KK7DS <dsmith@danplanet.com>", _("With significant contributions from:"), diff --git a/chirp/ui/radiobrowser.py b/chirp/ui/radiobrowser.py index 83cd968..90b2981 100644 --- a/chirp/ui/radiobrowser.py +++ b/chirp/ui/radiobrowser.py @@ -233,19 +233,19 @@ class RadioBrowser(common.Editor): tvc = gtk.TreeViewColumn('Element', rend, text=0) self._tree.append_column(tvc) self._tree.connect('button_press_event', self._tree_click) - self._tree.set_size_request(200, -1) - self.root = gtk.HBox(False, 3) + self.root = gtk.HPaned() + self.root.set_position(200) sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) sw.add(self._tree) sw.show() - self.root.pack_start(sw, 0, 0, 0) + self.root.add1(sw) sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) sw.add_with_viewport(self._display) sw.show() - self.root.pack_start(sw, 1, 1, 1) + self.root.add2(sw) self._tree.show() self._display.show() self.root.show() @@ -17,6 +17,7 @@ import os +from chirp import chirp_common from chirp import logger from chirp import elib_intl from chirp import platform @@ -30,10 +31,13 @@ import locale import gettext import argparse import logging +import urllib LOG = logging.getLogger("chirpw") +urllib.URLopener.version = chirp_common.http_user_agent() + localepath = platform.get_platform().find_resource("locale") conf = config.get() diff --git a/share/chirp.ico b/share/chirp.ico Binary files differnew file mode 100755 index 0000000..4006ff9 --- /dev/null +++ b/share/chirp.ico |
