Project

General

Profile

New Model #11458 » tri148.py

Lars Larping , 08/02/2024 04:29 AM

 
# Copyright 2016-2023:
# Jim Unroe KC9HI, <rock.unroe@gmail.com>
# Rick DeWitt (RJD), <aa0rd@yahoo.com>
# Mark Hartong, AJ4YI <mark.hartong@verizon.net>
# Mark Hartong, AJ4YI <mark.hartong@verizon.net>
# Jim Unroe, KC9HI <rock.unroe@gmail.com>
#
# New model for TRI PRC-148
# Michael, m@ilovecode.dk
#
# 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 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

LOG = logging.getLogger(__name__)

MEM_FORMAT = """
#seekto 0x0200;
struct {
u8 init_bank; // determines which VFO is primary A or B
u8 volume; // not used BJ-318, band volume is controlled vfo u8 bvol
u16 fm_freq; // not used BJ-318, freq is controlled hello_lims u16 fm_318
u8 wtled; // not used BJ-318
u8 rxled; // not used BJ-318
u8 txled; // not used BJ-318
u8 ledsw;
u8 beep;
u8 ring;
u8 bcl;
u8 tot;
u16 sig_freq;
u16 dtmf_txms;
u8 init_sql; // not used BJ-318, band squelch is controlled vfo u8 sql
u8 rptr_mode;
u8 unknown1;
u8 vol_sw; // 0 = Potentio, 1 = Elec
u8 speaker; // 0 = Inside, 1 = External
u8 mic_type; // 0 = cap, 1 = Dyn
} settings;

#seekto 0x0240;
struct {
u8 dtmf1_cnt;
u8 dtmf1[7];
u8 dtmf2_cnt;
u8 dtmf2[7];
u8 dtmf3_cnt;
u8 dtmf3[7];
u8 dtmf4_cnt;
u8 dtmf4[7];
u8 dtmf5_cnt;
u8 dtmf5[7];
u8 dtmf6_cnt;
u8 dtmf6[7];
u8 dtmf7_cnt;
u8 dtmf7[7];
u8 dtmf8_cnt;
u8 dtmf8[7];
} dtmf_tab;

#seekto 0x0280;
struct {
u8 native_id_cnt;
u8 native_id_code[7];
u8 master_id_cnt;
u8 master_id_code[7];
u8 alarm_cnt;
u8 alarm_code[5];
u8 id_disp_cnt;
u8 id_disp_code[5];
u8 revive_cnt;
u8 revive_code[5];
u8 stun_cnt;
u8 stun_code[5];
u8 kill_cnt;
u8 kill_code[5];
u8 monitor_cnt;
u8 monitor_code[5];
u8 state_now;
} codes;

#seekto 0x02d0;
struct {
u8 hello1_cnt; // not used in BJ-318, is set in memory map
char hello1[7]; // not used in BJ-318, is set in memory map
u8 hello2_cnt; // not used in BJ-318, is set in memory map
char hello2[7]; // not used in BJ-318, is set in memory map
u32 vhf_low;
u32 vhf_high;
u32 uhf_low;
u32 uhf_high;
u8 lims_on; // first byte @ at address 0x02f0;
} hello_lims;

struct vfo {
u8 frq_chn_mode;
u8 chan_num;
u32 rxfreq;
u16 is_rxdigtone:1,
rxdtcs_pol:1,
rx_tone:14;
u8 rx_mode;
u8 unknown_ff;
u16 is_txdigtone:1,
txdtcs_pol:1,
tx_tone:14;
u8 launch_sig;
u8 tx_end_sig;
u8 bpower; // sets power Hi=02h, Medium=01h, Low=00
// sets power for entire vfo band
u8 fm_bw;
u8 cmp_nder;
u8 scrm_blr;
u8 shift;
u32 offset;
u16 step;
u8 sql; // squelch for entire vfo band
// integer values 0 (low) to 9 (high)
};

#seekto 0x0300;
struct {
struct vfo vfoa;
} upper;

#seekto 0x0380;
struct {
struct vfo vfob;
} lower;

struct mem {
u32 rxfreq;
u16 is_rxdigtone:1,
rxdtcs_pol:1,
rxtone:14;
u8 recvmode;
u32 txfreq;
u16 is_txdigtone:1,
txdtcs_pol:1,
txtone:14;
u8 botsignal;
u8 eotsignal;
u8 power:1, // binary value for
// individual channel power
// set to "High" or "Low"
// BJ-318 band power overrides any
// individual channel power setting
wide:1,
compander:1,
scrambler:1,
unknown:4;
u8 namelen;
u8 name[7];
};

#seekto 0x0400;
struct mem upper_memory[128];

#seekto 0x1000;
struct mem lower_memory[128];

#seekto 0x2160;
struct {
char mod_num[6];
} mod_id;
"""
MEM_SIZE = 0x2160
BLOCK_SIZE = 0x40
STIMEOUT = 2
BAUD_RATE = 19200

LIST_RECVMODE = ["QT ( CTCSS )", "QT+ANI ( CTCSS+individual code )"]
LIST_SIGNAL = ["Off"] + ["DTMF%s" % x for x in range(1, 9)] + \
["DTMF%s + Identity" % x for x in range(1, 9)] + \
["Identity code"]
LIST_BPOWER = ["Low", "Mid", "High"] # Tri-power models
LIST_LEDSW = ["Off", "Auto"]
LIST_RING = ["Off"] + ["%s" % x for x in range(1, 10)]
LIST_TDR_DEF = ["A-Upper", "B-Lower"]
LIST_TIMEOUT = ["0"] + ["%s" % x for x in range(30, 600, 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 = [2.5, 5.0, 6.25, 10.0, 12.5, 25.0, 50.0]
LIST_STEPS = [str(x) for x in STEPS]
LIST_STATE = ["Normal", "Stun", "Kill"]
LIST_SSF = ["1000", "1450", "1750", "2100"]
LIST_DTMFTX = ["50", "100", "150", "200", "300", "500"]

## TRI-148 Specific options
LIST_VOL = ["Electron", "Potentiometer"]
LIST_SPEAKER = ["Inside", "External"]
LIST_MIC_TYPE = ["CAP", "DYN"]


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 = b""
try:
data = radio.pipe.read(amount)
except:
_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:
raise errors.RadioError("Error sending data to radio")


def _make_frame(cmd, addr, length, data=""):
"""Pack the info in the header format"""
frame = struct.pack(">4sHH", 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"""
# Set the serial discipline
radio.pipe.baudrate = BAUD_RATE
radio.pipe.parity = "N"
radio.pipe.timeout = STIMEOUT

# Flush input buffer
_clean_buffer(radio)

magic = b"PROM_LIN"

_rawsend(radio, magic)

ack = _rawrecv(radio, 1)
if ack != b"\x06":
_exit_program_mode(radio)
if ack:
LOG.debug(repr(ack))
raise errors.RadioError("Radio did not respond")

return True


def _exit_program_mode(radio):
endframe = b"EXIT"
_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 = b""
for addr in range(0, MEM_SIZE, BLOCK_SIZE):
frame = _make_frame(b"READ", addr, BLOCK_SIZE)
# DEBUG
LOG.info("Request sent:")
LOG.debug(util.hexprint(frame))

# Sending the read request
_rawsend(radio, frame)

# Now we read
d = _recv(radio, addr, BLOCK_SIZE)

# 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(b"WRIE", addr, BLOCK_SIZE, data)

_rawsend(radio, frame)

# Receiving the response
ack = _rawrecv(radio, 1)
if ack != b"\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 model_match(cls, data):
"""Match the opened/downloaded image to the correct version"""
if len(data) == 0x1C08:
rid = data[0x1C00:0x1C08]
return rid.startswith(cls.MODEL.encode())
else:
return False


def _split(rf, f1, f2):
"""Returns False if the two freqs are in the same band (no split)
or True otherwise"""

# Determine if the two freqs are in the same band
for low, high in rf.valid_bands:
if f1 >= low and f1 <= high and \
f2 >= low and f2 <= high:
# If the two freqs are on the same Band this is not a split
return False

# If you get here is because the freq pairs are split
return True

@directory.register
class TRI148(chirp_common.CloneModeRadio,
chirp_common.ExperimentalRadio):
"""TRI - Triumph Instrument PRC-148"""
VENDOR = "TRI - Triumph Instrument"
MODEL = "PRC-148"
MODES = ["NFM", "FM"]
TONES = chirp_common.TONES
DTCS_CODES = tuple(sorted(chirp_common.DTCS_CODES + (645,)))
DTMF_CHARS = list("0123456789ABCD*#")

VALID_BANDS = [(106000000, 135995000),
(136000000, 176000000),
(400000000, 470000000)]

# Valid chars on the LCD
NAME_LENGTH = 7
VALID_CHARS = chirp_common.CHARSET_UPPER_NUMERIC.replace(" ", "") + "#*_-"
#VALID_CHARS = VALID_CHARS.replace(" ", "")

@classmethod
def get_prompts(cls):
rp = chirp_common.RadioPrompts()
if cls.MODEL == "PRC-148":
msg = \
('\n'
'The individual PRC-148 channel power settings set in CHIRP'
' are ignored by the radio.\n'
'While the CHIRP driver will allow setting \n'
'\n')

rp.info = msg

rp.pre_download = _(
"Follow this instructions to download your info:\n"
"1 - Turn off your radio\n"
"2 - Connect your interface cable\n"
"3 - Turn on your radio\n"
"4 - Do the download of your radio data\n")
rp.pre_upload = _(
"Follow this instructions to upload your info:\n"
"1 - Turn off your radio\n"
"2 - Connect your interface cable\n"
"3 - Turn on your radio\n"
"4 - Do the upload of your radio data\n")
return rp

def get_features(self):
rf = chirp_common.RadioFeatures()
rf.has_settings = True
rf.has_bank = False
rf.has_tuning_step = False
rf.can_odd_split = True
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 = self.VARIANT == ""
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 = LIST_BPOWER
rf.valid_name_length = self.NAME_LENGTH
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):
return [TRI148Upper(self._mmap), TRI148Lower(self._mmap)]

def sync_in(self):
"""Download from radio"""
try:
data = _download(self)
except errors.RadioError:
# Pass through any real errors we raise
raise
except:
# 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.MemoryMapBytes(data)
self.process_mmap()

def sync_out(self):
"""Upload to radio"""
try:
_upload(self)
except:
# 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 _memory_obj(self, suffix=""):
return getattr(self._memobj, "%s_memory%s" % (self._vfo, suffix))

def _get_dcs(self, val):
return int(str(val)[2:-18])

def _set_dcs(self, val):
return int(str(val), 16)

def get_memory(self, number):
_mem = self._memory_obj()[number - 1]

mem = chirp_common.Memory()
mem.number = number

if _mem.get_raw(asbytes=False)[0] == "\xff":
mem.empty = True
return mem

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 _split(self.get_features(), mem.freq, int(_mem.txfreq) * 10):
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 _mem.name[0:_mem.namelen]:
mem.name += chr(char)

dtcs_pol = ["N", "N"]

if _mem.rxtone in [0x3FFF, 0x0000]:
rxmode = ""
elif _mem.is_rxdigtone == 0:
# CTCSS
rxmode = "Tone"
mem.ctone = int(_mem.rxtone) / 10.0
else:
# Digital
rxmode = "DTCS"
mem.rx_dtcs = self._get_dcs(_mem.rxtone)
if _mem.rxdtcs_pol == 1:
dtcs_pol[1] = "R"

if _mem.txtone in [0x3FFF, 0x0000]:
txmode = ""
elif _mem.is_txdigtone == 0:
# CTCSS
txmode = "Tone"
mem.rtone = int(_mem.txtone) / 10.0
else:
# Digital
txmode = "DTCS"
mem.dtcs = self._get_dcs(_mem.txtone)
if _mem.txdtcs_pol == 1:
dtcs_pol[0] = "R"

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)

mem.mode = _mem.wide and "FM" or "NFM"

mem.power = LIST_BPOWER[_mem.power]

# Extra
mem.extra = RadioSettingGroup("extra", "Extra")

if _mem.recvmode == 0xFF:
val = 0x00
else:
val = _mem.recvmode
recvmode = RadioSetting("recvmode", "Receiving mode",
RadioSettingValueList(LIST_RECVMODE,
LIST_RECVMODE[val]))
mem.extra.append(recvmode)

if _mem.botsignal == 0xFF:
val = 0x00
else:
val = _mem.botsignal
botsignal = RadioSetting("botsignal", "Launch signaling",
RadioSettingValueList(LIST_SIGNAL,
LIST_SIGNAL[val]))
mem.extra.append(botsignal)

if _mem.eotsignal == 0xFF:
val = 0x00
else:
val = _mem.eotsignal

rx = RadioSettingValueList(LIST_SIGNAL, LIST_SIGNAL[val])
eotsignal = RadioSetting("eotsignal", "Transmit end signaling", rx)
mem.extra.append(eotsignal)

rx = RadioSettingValueBoolean(bool(_mem.compander))
compander = RadioSetting("compander", "Compander", rx)
mem.extra.append(compander)

rx = RadioSettingValueBoolean(bool(_mem.scrambler))
scrambler = RadioSetting("scrambler", "Scrambler", rx)
mem.extra.append(scrambler)

return mem

def set_memory(self, mem):
_mem = self._memory_obj()[mem.number - 1]

if mem.empty:
_mem.set_raw("\xff" * 24)
_mem.namelen = 0
return

_mem.set_raw("\xFF" * 15 + "\x00\x00" + "\xFF" * 7)

_mem.rxfreq = mem.freq / 10
if mem.duplex == "off":
_mem.txfreq = 0xFFFFFFFF
elif mem.duplex == "split":
_mem.txfreq = mem.offset / 10
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

_mem.namelen = len(mem.name.rstrip())
_namelength = self.get_features().valid_name_length
for i in range(_namelength):
try:
_mem.name[i] = ord(mem.name[i])
except IndexError:
_mem.name[i] = 0xFF

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)

if rxmode == "":
_mem.rxdtcs_pol = 1
_mem.is_rxdigtone = 1
_mem.rxtone = 0x3FFF
elif rxmode == "Tone":
_mem.rxdtcs_pol = 0
_mem.is_rxdigtone = 0
_mem.rxtone = int(mem.ctone * 10)
elif rxmode == "DTCSSQL":
_mem.rxdtcs_pol = 1 if mem.dtcs_polarity[1] == "R" else 0
_mem.is_rxdigtone = 1
_mem.rxtone = self._set_dcs(mem.dtcs)
elif rxmode == "DTCS":
_mem.rxdtcs_pol = 1 if mem.dtcs_polarity[1] == "R" else 0
_mem.is_rxdigtone = 1
_mem.rxtone = self._set_dcs(mem.rx_dtcs)

if txmode == "":
_mem.txdtcs_pol = 1
_mem.is_txdigtone = 1
_mem.txtone = 0x3FFF
elif txmode == "Tone":
_mem.txdtcs_pol = 0
_mem.is_txdigtone = 0
_mem.txtone = int(mem.rtone * 10)
elif txmode == "TSQL":
_mem.txdtcs_pol = 0
_mem.is_txdigtone = 0
_mem.txtone = int(mem.ctone * 10)
elif txmode == "DTCS":
_mem.txdtcs_pol = 1 if mem.dtcs_polarity[0] == "R" else 0
_mem.is_txdigtone = 1
_mem.txtone = self._set_dcs(mem.dtcs)

_mem.wide = self.MODES.index(mem.mode)
_mem.power = mem.power == LIST_BPOWER[1]

# Extra settings
for setting in mem.extra:
setattr(_mem, setting.get_name(), setting.value)

def get_settings(self):
"""Translate the bit in the mem_struct into settings in the UI"""
# Define mem struct write-back shortcuts
_sets = self._memobj.settings
_vfoa = self._memobj.upper.vfoa
_vfob = self._memobj.lower.vfob
_lims = self._memobj.hello_lims
_codes = self._memobj.codes
_dtmf = self._memobj.dtmf_tab

basic = RadioSettingGroup("basic", "Basic Settings")
a_band = RadioSettingGroup("a_band", "VFO A-Upper Settings")
b_band = RadioSettingGroup("b_band", "VFO B-Lower Settings")
codes = RadioSettingGroup("codes", "Codes & DTMF Groups")
lims = RadioSettingGroup("lims", "PowerOn & Freq Limits")
group = RadioSettings(basic, a_band, b_band, lims, codes)


def my_word2raw(setting, obj, atrb, mlt=10):
"""Callback function to convert UI floating value to u16 int"""
if str(setting.value) == "Off":
frq = 0x0000
else:
frq = int(float(str(setting.value)) * float(mlt))
if frq == 0:
frq = 0x0000
setattr(obj, atrb, frq)
return

def my_adjraw(setting, obj, atrb, fix):
"""Callback: add or subtract fix from value."""
vx = int(str(setting.value))
value = vx + int(fix)
if value < 0:
value = 0
if atrb == "frq_chn_mode" and int(str(setting.value)) == 2:
value = vx * 2 # Special handling for frq_chn_mode
setattr(obj, atrb, value)
return

def my_dbl2raw(setting, obj, atrb, flg=1):
"""Callback: convert from freq 146.7600 to 14760000 U32."""
value = chirp_common.parse_freq(str(setting.value)) / 10
# flg=1 means 0 becomes ff, else leave as possible 0
if flg == 1 and value == 0:
value = 0xFFFFFFFF
setattr(obj, atrb, value)
return

def my_val_list(setting, obj, atrb):
"""Callback:from ValueList with non-sequential, actual values."""
value = int(str(setting.value)) # Get the integer value
if atrb == "tot":
value = int(value / 30) # 30 second increments
setattr(obj, atrb, value)
return

def my_spcl(setting, obj, atrb):
"""Callback: Special handling based on atrb."""
if atrb == "frq_chn_mode":
idx = LIST_VFOMODE.index(str(setting.value)) # Returns 0 or 1
value = idx * 2 # Set bit 1
setattr(obj, atrb, value)
return

def my_tone_strn(obj, is_atr, pol_atr, tone_atr):
"""Generate the CTCS/DCS tone code string."""
vx = int(getattr(obj, tone_atr))
if vx == 16383 or vx == 0:
return "Off" # 16383 is all bits set
if getattr(obj, is_atr) == 0: # Simple CTCSS code
tstr = str(vx / 10.0)
else: # DCS
if getattr(obj, pol_atr) == 0:
tstr = "D{:03x}R".format(vx)
else:
tstr = "D{:03x}N".format(vx)
return tstr

def my_set_tone(setting, obj, is_atr, pol_atr, tone_atr):
"""Callback- create the tone setting from string code."""
sx = str(setting.value) # '131.8' or 'D231N' or 'Off'
if sx == "Off":
isx = 1
polx = 1
tonx = 0x3FFF
elif sx[0] == "D": # DCS
isx = 1
if sx[4] == "N":
polx = 1
else:
polx = 0
tonx = int(sx[1:4], 16)
else: # CTCSS
isx = 0
polx = 0
tonx = int(float(sx) * 10.0)
setattr(obj, is_atr, isx)
setattr(obj, pol_atr, polx)
setattr(obj, tone_atr, tonx)
return

def my_frq(freq):
freq = int(freq * 10)
valid = False
for lo, hi in self.VALID_BANDS:
if lo <= freq <= hi:
valid = True
break
if not valid:
LOG.error("Freq not in range")
default_range = self.VALID_BANDS[2]
freq = (default_range[0] + default_range[1]) / 2

return freq / 1000000.0

# Basic Settings
bnd_mode = RadioSetting("settings.init_bank", "TDR Band Default",
RadioSettingValueList(LIST_TDR_DEF, LIST_TDR_DEF[ _sets.init_bank]))
basic.append(bnd_mode)

rs = RadioSettingValueInteger(0, 15, _sets.volume)
volume = RadioSetting("settings.volume", "Electronic volume ( Default: 10 )", rs)
basic.append(volume)


val = _sets.fm_freq / 10.0
if val == 0:
val = 88.9 # 0 is not valid
rx = RadioSettingValueFloat(65, 108.0, val, 0.1, 1)
rs = RadioSetting("settings.fm_freq", "FM Broadcast Freq (MHz)", rx)
rs.set_apply_callback(my_word2raw, _sets, "fm_freq")
basic.append(rs)
tmp = str(int(_sets.ledsw))
ledsw = RadioSetting("settings.ledsw", "LED-SW ( Back light mode )",
RadioSettingValueList(LIST_LEDSW, LIST_LEDSW[_sets.ledsw]))
basic.append(ledsw)

beep = RadioSetting("settings.beep", "BEEP ( Prompt tone )",
RadioSettingValueBoolean(bool(_sets.beep)))
basic.append(beep)

ring = RadioSetting("settings.ring", "RING ( Ring tone )",
RadioSettingValueList(LIST_RING, LIST_RING[_sets.ring])
)
basic.append(ring)

bcl = RadioSetting("settings.bcl", "BCL ( Busy channel lockout )",
RadioSettingValueBoolean(bool(_sets.bcl)))
basic.append(bcl)

tmp = str(int(_sets.tot) * 30) # 30 sec step counter
rs = RadioSetting("settings.tot", "TOT ( Transmit Timeout in Secs )",
RadioSettingValueList(LIST_TIMEOUT, tmp))
rs.set_apply_callback(my_val_list, _sets, "tot")
basic.append(rs)

tmp = str(int(_sets.sig_freq))
rs = RadioSetting("settings.sig_freq", "TONE ( Pilot carrier frequency in Hz )",
RadioSettingValueList(LIST_SSF, tmp))
rs.set_apply_callback(my_val_list, _sets, "sig_freq")
basic.append(rs)

tmp = str(int(_sets.dtmf_txms))
rs = RadioSetting("settings.dtmf_txms", "DTM-TM ( DTMF Tx Duration in mSecs )",
RadioSettingValueList(LIST_DTMFTX, tmp))
rs.set_apply_callback(my_val_list, _sets, "dtmf_txms")
basic.append(rs)

rs = RadioSetting("settings.rptr_mode", "RPT ( Cross-band repeater )",
RadioSettingValueBoolean(bool(_sets.rptr_mode)))
basic.append(rs)

vol_sw = RadioSetting("settings.vol_sw", "VOL-SW ( Volume adjustment mode )",
RadioSettingValueList(LIST_VOL, LIST_VOL[_sets.vol_sw]))
basic.append(vol_sw)

speaker = RadioSetting("settings.speaker", "SPEAKER ( Speaker output select )",
RadioSettingValueList(LIST_SPEAKER, LIST_SPEAKER[_sets.speaker]))
basic.append(speaker)

mic_type = RadioSetting("settings.mic_type", "MIC_TYPE ( Microphone Type )",
RadioSettingValueList(LIST_MIC_TYPE, LIST_MIC_TYPE[_sets.mic_type]))
basic.append(mic_type)


# ******************************************************
# UPPER BAND SETTINGS
# ******************************************************

# Freq Mode, convert bit 1 state to index pointer
val = _vfoa.frq_chn_mode // 2

rx = RadioSettingValueList(LIST_VFOMODE, LIST_VFOMODE[val])
rs = RadioSetting("upper.vfoa.frq_chn_mode", "Default Mode", rx)
rs.set_apply_callback(my_spcl, _vfoa, "frq_chn_mode")
a_band.append(rs)

val = _vfoa.chan_num + 1 # Add 1 for 1-128 displayed
rs = RadioSetting("upper.vfoa.chan_num", "Initial Channel",
RadioSettingValueInteger(1, 128, val))
rs.set_apply_callback(my_adjraw, _vfoa, "chan_num", -1)
a_band.append(rs)

val = my_frq(_vfoa.rxfreq)
rs = RadioSetting("upper.vfoa.rxfreq ", "Default Recv Freq in MHz",
RadioSettingValueFloat(106.0, 470.0, val, 0.001, 5))
rs.set_apply_callback(my_dbl2raw, _vfoa, "rxfreq")
a_band.append(rs)

tmp = my_tone_strn(_vfoa, "is_rxdigtone", "rxdtcs_pol", "rx_tone")
rs = RadioSetting("rx_tone", "R-CTC ( Setting of CTCSS for receiving in Hz )",
RadioSettingValueList(LIST_CTCSS, tmp))
rs.set_apply_callback(my_set_tone, _vfoa, "is_rxdigtone", "rxdtcs_pol", "rx_tone")
a_band.append(rs)

rx = RadioSettingValueList(LIST_RECVMODE, LIST_RECVMODE[_vfoa.rx_mode])
rs = RadioSetting("upper.vfoa.rx_mode", "R-MOD ( Default Recv Mode )", rx)
a_band.append(rs)

tmp = my_tone_strn(_vfoa, "is_txdigtone", "txdtcs_pol", "tx_tone")
rs = RadioSetting("tx_tone", "T-CTC ( Setting of CTCSS for transmit in Hz )",
RadioSettingValueList(LIST_CTCSS, tmp))
rs.set_apply_callback(my_set_tone, _vfoa, "is_txdigtone", "txdtcs_pol", "tx_tone")
a_band.append(rs)

rs = RadioSetting("upper.vfoa.launch_sig", "T-DTM1 ( Setting of dual tone multiple frequency for transmission 1 )",
RadioSettingValueList(LIST_SIGNAL, LIST_SIGNAL[_vfoa.launch_sig]))
a_band.append(rs)

rx = RadioSettingValueList(LIST_SIGNAL, LIST_SIGNAL[_vfoa.tx_end_sig])
rs = RadioSetting("upper.vfoa.tx_end_sig", "T-DTM2 ( Setting of dual tone multiple frequency for transmission 2 )", rx)
a_band.append(rs)

rx = RadioSettingValueList(LIST_BW, LIST_BW[_vfoa.fm_bw])
rs = RadioSetting("upper.vfoa.fm_bw", "W/NA ( Selection wide of broad or narrow band )", rx)
a_band.append(rs)

rx = RadioSettingValueBoolean(bool(_vfoa.cmp_nder))
rs = RadioSetting("upper.vfoa.cmp_nder", "COMP ( Voice companding )", rx)
a_band.append(rs)

rs = RadioSetting("upper.vfoa.scrm_blr", "SRMR ( Voice encryption )",
RadioSettingValueBoolean(bool(_vfoa.scrm_blr)))
a_band.append(rs)

rx = RadioSettingValueList(LIST_SHIFT, LIST_SHIFT[_vfoa.shift])
rs = RadioSetting("upper.vfoa.shift", "SFT ( Frequency offset setting direction )", rx)
a_band.append(rs)

val = _vfoa.offset / 100000.0
rs = RadioSetting("upper.vfoa.offset", "OFFSET ( Frequency offset range in MHz )",
RadioSettingValueFloat(0, 100.0, val, 0.001, 3))
# Allow zero value
rs.set_apply_callback(my_dbl2raw, _vfoa, "offset", 0)
a_band.append(rs)

tmp = str(_vfoa.step / 100.0)
rs = RadioSetting("step", "STEP ( Frequency step in kHz )",
RadioSettingValueList(LIST_STEPS, tmp))
rs.set_apply_callback(my_word2raw, _vfoa, "step", 100)
a_band.append(rs)

if _vfoa.sql == 0xFF:
valq = 0x04 # setting default squelch to 04
else:
valq = _vfoa.sql
sqla = RadioSetting("upper.vfoa.sql", "SQL ( Squelch level )",
RadioSettingValueInteger(0, 9, valq))
a_band.append(sqla)

val_b = _vfoa.bpower # 2bits values 0,1,2= Low, Mid, High
rx = RadioSettingValueList(LIST_BPOWER, LIST_BPOWER[val_b])
power_u = RadioSetting("upper.vfoa.bpower", "POWER", rx)
a_band.append(power_u)

# ******************************************************
# LOWER BAND SETTINGS
# ******************************************************

# Freq Mode, convert bit 1 state to index pointer
val = _vfob.frq_chn_mode // 2

rx = RadioSettingValueList(LIST_VFOMODE, LIST_VFOMODE[val])
rs = RadioSetting("upper.vfob.frq_chn_mode", "Default Mode", rx)
rs.set_apply_callback(my_spcl, _vfob, "frq_chn_mode")
b_band.append(rs)

val = _vfob.chan_num + 1 # Add 1 for 1-128 displayed
rs = RadioSetting("upper.vfob.chan_num", "Initial Channel",
RadioSettingValueInteger(1, 128, val))
rs.set_apply_callback(my_adjraw, _vfob, "chan_num", -1)
b_band.append(rs)

val = my_frq(_vfob.rxfreq)
rs = RadioSetting("upper.vfob.rxfreq ", "Default Recv Freq in MHz",
RadioSettingValueFloat(106.0, 470.0, val, 0.001, 5))
rs.set_apply_callback(my_dbl2raw, _vfob, "rxfreq")
b_band.append(rs)

tmp = my_tone_strn(_vfob, "is_rxdigtone", "rxdtcs_pol", "rx_tone")
rs = RadioSetting("rx_tone", "R-CTC ( Setting of CTCSS for receiving in Hz )",
RadioSettingValueList(LIST_CTCSS, tmp))
rs.set_apply_callback(my_set_tone, _vfob, "is_rxdigtone", "rxdtcs_pol", "rx_tone")
b_band.append(rs)

rx = RadioSettingValueList(LIST_RECVMODE, LIST_RECVMODE[_vfob.rx_mode])
rs = RadioSetting("upper.vfob.rx_mode", "R-MOD ( Default Recv Mode )", rx)
b_band.append(rs)

tmp = my_tone_strn(_vfob, "is_txdigtone", "txdtcs_pol", "tx_tone")
rs = RadioSetting("tx_tone", "T-CTC ( Setting of CTCSS for transmit in Hz )",
RadioSettingValueList(LIST_CTCSS, tmp))
rs.set_apply_callback(my_set_tone, _vfob, "is_txdigtone", "txdtcs_pol", "tx_tone")
b_band.append(rs)

rs = RadioSetting("upper.vfob.launch_sig", "T-DTM1 ( Setting of dual tone multiple frequency for transmission 1 )",
RadioSettingValueList(LIST_SIGNAL, LIST_SIGNAL[_vfob.launch_sig]))
b_band.append(rs)

rx = RadioSettingValueList(LIST_SIGNAL, LIST_SIGNAL[_vfob.tx_end_sig])
rs = RadioSetting("upper.vfob.tx_end_sig", "T-DTM2 ( Setting of dual tone multiple frequency for transmission 2 )", rx)
b_band.append(rs)

rx = RadioSettingValueList(LIST_BW, LIST_BW[_vfob.fm_bw])
rs = RadioSetting("upper.vfob.fm_bw", "W/NA ( Selection wide of broad or narrow band )", rx)
b_band.append(rs)

rx = RadioSettingValueBoolean(bool(_vfob.cmp_nder))
rs = RadioSetting("upper.vfob.cmp_nder", "COMP ( Voice companding )", rx)
b_band.append(rs)

rs = RadioSetting("upper.vfob.scrm_blr", "SRMR ( Voice encryption )",
RadioSettingValueBoolean(bool(_vfob.scrm_blr)))
b_band.append(rs)

rx = RadioSettingValueList(LIST_SHIFT, LIST_SHIFT[_vfob.shift])
rs = RadioSetting("upper.vfob.shift", "SFT ( Frequency offset setting direction )", rx)
b_band.append(rs)

val = _vfob.offset / 100000.0
rs = RadioSetting("upper.vfob.offset", "OFFSET ( Frequency offset range in MHz )",
RadioSettingValueFloat(0, 100.0, val, 0.001, 3))
# Allow zero value
rs.set_apply_callback(my_dbl2raw, _vfob, "offset", 0)
b_band.append(rs)

tmp = str(_vfob.step / 100.0)
rs = RadioSetting("step", "STEP ( Frequency step in kHz )",
RadioSettingValueList(LIST_STEPS, tmp))
rs.set_apply_callback(my_word2raw, _vfob, "step", 100)
b_band.append(rs)

if _vfob.sql == 0xFF:
valq = 0x04 # setting default squelch to 04
else:
valq = _vfob.sql
sqla = RadioSetting("upper.vfob.sql", "SQL ( Squelch level )",
RadioSettingValueInteger(0, 9, valq))
b_band.append(sqla)

val_b = _vfob.bpower # 2bits values 0,1,2= Low, Mid, High
rx = RadioSettingValueList(LIST_BPOWER, LIST_BPOWER[val_b])
power_u = RadioSetting("upper.vfob.bpower", "POWER", rx)
b_band.append(power_u)



# PowerOn & Freq Limits Settings
def chars2str(cary, knt):
"""Convert raw memory char array to a string: NOT a callback."""
stx = ""
for char in cary[0:knt]:
stx += chr(int(char))
return stx

def my_str2ary(setting, obj, atrba, atrbc):
"""Callback: convert 7-char string to char array with count."""
ary = ""
knt = 7
for j in range(6, -1, -1): # Strip trailing spaces
if str(setting.value)[j] == "" or str(setting.value)[j] == " ":
knt = knt - 1
else:
break
for j in range(0, 7, 1):
if j < knt:
ary += str(setting.value)[j]
else:
ary += chr(0xFF)
setattr(obj, atrba, ary)
setattr(obj, atrbc, knt)
return

lval = _lims.vhf_low / 100000.0
uval = _lims.vhf_high / 100000.0
if lval >= uval:
lval = 144.0
uval = 158.0

rs = RadioSetting("hello_lims.vhf_low", "Lower VHF Band Limit (MHz)",
RadioSettingValueFloat(106.0, 176.0, lval, 0.001, 3))
rs.set_apply_callback(my_dbl2raw, _lims, "vhf_low")
lims.append(rs)

rs = RadioSetting("hello_lims.vhf_high", "Upper VHF Band Limit (MHz)",
RadioSettingValueFloat(106.0, 176.0, uval, 0.001, 3))
rs.set_apply_callback(my_dbl2raw, _lims, "vhf_high")
lims.append(rs)

lval = _lims.uhf_low / 100000.0
uval = _lims.uhf_high / 100000.0
if lval >= uval:
lval = 420.0
uval = 470.0

rs = RadioSetting("hello_lims.uhf_low", "Lower UHF Band Limit (MHz)",
RadioSettingValueFloat(400.0, 490.0, lval, 0.001, 3))
rs.set_apply_callback(my_dbl2raw, _lims, "uhf_low")
lims.append(rs)

rs = RadioSetting("hello_lims.uhf_high", "Upper UHF Band Limit (MHz)",
RadioSettingValueFloat(400.0, 490.0, uval, 0.001, 3))
rs.set_apply_callback(my_dbl2raw, _lims, "uhf_high")
lims.append(rs)

# Codes and DTMF Groups Settings

def make_dtmf(ary, knt):
"""Generate the DTMF code 1-8, NOT a callback."""
tmp = ""
if knt > 0 and knt != 0xff:
for val in ary[0:knt]:
if val > 0 and val <= 9:
tmp += chr(val + 48)
elif val == 0x0a:
tmp += "0"
elif val == 0x0d:
tmp += "A"
elif val == 0x0e:
tmp += "B"
elif val == 0x0f:
tmp += "C"
elif val == 0x00:
tmp += "D"
elif val == 0x0b:
tmp += "*"
elif val == 0x0c:
tmp += "#"
else:
msg = ("Invalid Character. Must be: 0-9,A,B,C,D,*,#")
raise InvalidValueError(msg)
return tmp

def my_dtmf2raw(setting, obj, atrba, atrbc, syz=7):
"""Callback: DTMF Code; sends 5 or 7-byte string."""
draw = []
knt = syz
for j in range(syz - 1, -1, -1): # Strip trailing spaces
if str(setting.value)[j] == "" or str(setting.value)[j] == " ":
knt = knt - 1
else:
break
for j in range(0, syz):
bx = str(setting.value)[j]
obx = ord(bx)
dig = 0x0ff
if j < knt and knt > 0: # (Else) is pads
if bx == "0":
dig = 0x0a
elif bx == "A":
dig = 0x0d
elif bx == "B":
dig = 0x0e
elif bx == "C":
dig = 0x0f
elif bx == "D":
dig = 0x00
elif bx == "*":
dig = 0x0b
elif bx == "#":
dig = 0x0c
elif obx >= 49 and obx <= 57:
dig = obx - 48
else:
msg = ("Must be: 0-9,A,B,C,D,*,#")
raise InvalidValueError(msg)
# - End if/elif/else for bx
# - End if J<=knt
draw.append(dig) # Generate string of bytes
# - End for j
setattr(obj, atrba, draw)
setattr(obj, atrbc, knt)
return

tmp = make_dtmf(_codes.native_id_code, _codes.native_id_cnt)
rs = RadioSetting("codes.native_id_code", "Native ID Code",
RadioSettingValueString(0, 7, tmp))
rs.set_apply_callback(my_dtmf2raw, _codes, "native_id_code",
"native_id_cnt", 7)
codes.append(rs)

tmp = make_dtmf(_codes.master_id_code, _codes.master_id_cnt)
rs = RadioSetting("codes.master_id_code", "Master Control ID Code",
RadioSettingValueString(0, 7, tmp))
rs.set_apply_callback(my_dtmf2raw, _codes, "master_id_code",
"master_id_cnt", 7)
codes.append(rs)

tmp = make_dtmf(_codes.alarm_code, _codes.alarm_cnt)
rs = RadioSetting("codes.alarm_code", "Alarm Code",
RadioSettingValueString(0, 5, tmp))
rs.set_apply_callback(my_dtmf2raw, _codes, "alarm_code",
"alarm_cnt", 5)
codes.append(rs)

tmp = make_dtmf(_codes.id_disp_code, _codes.id_disp_cnt)
rs = RadioSetting("codes.id_disp_code", "Identify Display Code",
RadioSettingValueString(0, 5, tmp))
rs.set_apply_callback(my_dtmf2raw, _codes, "id_disp_code",
"id_disp_cnt", 5)
codes.append(rs)

tmp = make_dtmf(_codes.revive_code, _codes.revive_cnt)
rs = RadioSetting("codes.revive_code", "Revive Code",
RadioSettingValueString(0, 5, tmp))
rs.set_apply_callback(my_dtmf2raw, _codes, "revive_code",
"revive_cnt", 5)
codes.append(rs)

tmp = make_dtmf(_codes.stun_code, _codes.stun_cnt)
rs = RadioSetting("codes.stun_code", "Remote Stun Code",
RadioSettingValueString(0, 5, tmp))
rs.set_apply_callback(my_dtmf2raw, _codes, "stun_code",
"stun_cnt", 5)
codes.append(rs)

tmp = make_dtmf(_codes.kill_code, _codes.kill_cnt)
rs = RadioSetting("codes.kill_code", "Remote KILL Code",
RadioSettingValueString(0, 5, tmp))
rs.set_apply_callback(my_dtmf2raw, _codes, "kill_code",
"kill_cnt", 5)
codes.append(rs)

tmp = make_dtmf(_codes.monitor_code, _codes.monitor_cnt)
rs = RadioSetting("codes.monitor_code", "Monitor Code",
RadioSettingValueString(0, 5, tmp))
rs.set_apply_callback(my_dtmf2raw, _codes, "monitor_code",
"monitor_cnt", 5)
codes.append(rs)

val = _codes.state_now
if val > 2:
val = 0

rx = RadioSettingValueList(LIST_STATE, LIST_STATE[val])
rs = RadioSetting("codes.state_now", "Current State", rx)
codes.append(rs)

dtm = make_dtmf(_dtmf.dtmf1, _dtmf.dtmf1_cnt)
rs = RadioSetting("dtmf_tab.dtmf1", "DTMF1 String",
RadioSettingValueString(0, 7, dtm))
rs.set_apply_callback(my_dtmf2raw, _dtmf, "dtmf1", "dtmf1_cnt")
codes.append(rs)

dtm = make_dtmf(_dtmf.dtmf2, _dtmf.dtmf2_cnt)
rs = RadioSetting("dtmf_tab.dtmf2", "DTMF2 String",
RadioSettingValueString(0, 7, dtm))
rs.set_apply_callback(my_dtmf2raw, _dtmf, "dtmf2", "dtmf2_cnt")
codes.append(rs)

dtm = make_dtmf(_dtmf.dtmf3, _dtmf.dtmf3_cnt)
rs = RadioSetting("dtmf_tab.dtmf3", "DTMF3 String",
RadioSettingValueString(0, 7, dtm))
rs.set_apply_callback(my_dtmf2raw, _dtmf, "dtmf3", "dtmf3_cnt")
codes.append(rs)

dtm = make_dtmf(_dtmf.dtmf4, _dtmf.dtmf4_cnt)
rs = RadioSetting("dtmf_tab.dtmf4", "DTMF4 String",
RadioSettingValueString(0, 7, dtm))
rs.set_apply_callback(my_dtmf2raw, _dtmf, "dtmf4", "dtmf4_cnt")
codes.append(rs)

dtm = make_dtmf(_dtmf.dtmf5, _dtmf.dtmf5_cnt)
rs = RadioSetting("dtmf_tab.dtmf5", "DTMF5 String",
RadioSettingValueString(0, 7, dtm))
rs.set_apply_callback(my_dtmf2raw, _dtmf, "dtmf5", "dtmf5_cnt")
codes.append(rs)

dtm = make_dtmf(_dtmf.dtmf6, _dtmf.dtmf6_cnt)
rs = RadioSetting("dtmf_tab.dtmf6", "DTMF6 String",
RadioSettingValueString(0, 7, dtm))
rs.set_apply_callback(my_dtmf2raw, _dtmf, "dtmf6", "dtmf6_cnt")
codes.append(rs)

dtm = make_dtmf(_dtmf.dtmf7, _dtmf.dtmf7_cnt)
rs = RadioSetting("dtmf_tab.dtmf7", "DTMF7 String",
RadioSettingValueString(0, 7, dtm))
rs.set_apply_callback(my_dtmf2raw, _dtmf, "dtmf7", "dtmf7_cnt")
codes.append(rs)

dtm = make_dtmf(_dtmf.dtmf8, _dtmf.dtmf8_cnt)
rs = RadioSetting("dtmf_tab.dtmf8", "DTMF8 String",
RadioSettingValueString(0, 7, dtm))
rs.set_apply_callback(my_dtmf2raw, _dtmf, "dtmf8", "dtmf8_cnt")
codes.append(rs)

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.value.get_mutable():
LOG.debug("Setting %s = %s" % (setting, element.value))
setattr(obj, setting, element.value)
except Exception:
LOG.debug(element.get_name())
raise

@classmethod
def match_model(cls, filedata, filename):
match_size = False
match_model = False

# Testing the file data size
if len(filedata) == MEM_SIZE + 8:
match_size = True

# Testing the firmware model fingerprint
match_model = model_match(cls, filedata)

if match_size and match_model:
return True
else:
return False

class TRI148Upper(TRI148):
VARIANT = "Upper"
_vfo = "upper"

class TRI148Lower(TRI148):
VARIANT = "Lower"
_vfo = "lower"
(4-4/7)