|
# Copyright 2023:
|
|
# * Sander van der Wel, <svdwel@icloud.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 logging
|
|
|
|
from chirp import chirp_common, directory
|
|
from chirp.settings import RadioSettingGroup, RadioSetting, \
|
|
RadioSettingValueBoolean, RadioSettingValueList, \
|
|
RadioSettings, RadioSettingValueString
|
|
import struct
|
|
from chirp.drivers import baofeng_common, baofeng_uv17Pro
|
|
from chirp import errors, util
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
LIST_DTMFST = ["Off", "DT-ST", "ANI-ST", "DT+ANI"]
|
|
LIST_SAVE = ["Off", "1:1", "1:2", "1:3", "1:4"]
|
|
LIST_SCANMODE = ["Time", "Carrier", "Search"]
|
|
|
|
|
|
# Radios seem to have different memory sizes
|
|
def _get_memory_size(radio):
|
|
response = baofeng_uv17Pro._sendmagic(radio, radio._magic_memsize[0][0],
|
|
radio._magic_memsize[0][1])
|
|
mem_size = struct.unpack("<I", response[7:])[0]
|
|
for magic, resplen in radio._magics2:
|
|
baofeng_uv17Pro._sendmagic(radio, magic, resplen)
|
|
return mem_size
|
|
|
|
|
|
# Locations of memory may differ each time, so a mapping has to be made first
|
|
def _get_memory_map(radio):
|
|
# Get memory map
|
|
memory_map = []
|
|
if radio._magic_memsize:
|
|
mem_size = _get_memory_size(radio)
|
|
else:
|
|
mem_size = radio._radio_memsize
|
|
if mem_size != radio._radio_memsize:
|
|
LOG.error('Mem size is %04x but expected %04x',
|
|
mem_size, radio._radio_memsize)
|
|
raise errors.RadioError("Incorrect radio model or model not supported "
|
|
"(memory size doesn't match)")
|
|
for addr in range(0x1FFF, mem_size + 0x1000, 0x1000):
|
|
frame = radio._make_frame(b"R", addr, 1)
|
|
baofeng_common._rawsend(radio, frame)
|
|
blocknr = ord(baofeng_common._rawrecv(radio, 6)[5:])
|
|
blocknr = (blocknr >> 4 & 0xf) * 10 + (blocknr & 0xf)
|
|
memory_map += [blocknr]
|
|
baofeng_uv17Pro._sendmagic(radio, b"\x06", 1)
|
|
return memory_map
|
|
|
|
|
|
def _download(radio):
|
|
"""Get the memory map"""
|
|
if not radio._DETECTED_BY:
|
|
# The GA510v2 (at least) is detected, and thus has already done ident
|
|
baofeng_uv17Pro._do_ident(radio)
|
|
data = b""
|
|
memory_map = _get_memory_map(radio)
|
|
|
|
status = chirp_common.Status()
|
|
status.cur = 0
|
|
status.max = radio.MEM_TOTAL // radio.BLOCK_SIZE
|
|
status.msg = "Cloning from radio..."
|
|
radio.status_fn(status)
|
|
|
|
for block_number in radio.BLOCK_O_READ:
|
|
if block_number not in memory_map:
|
|
# Memory block not found.
|
|
LOG.error('Block %i (0x%x) not in memory map: %s',
|
|
block_number, block_number, memory_map)
|
|
raise errors.RadioError('Radio memory is corrupted. ' +
|
|
'Fix this by uploading a backup image ' +
|
|
'to the radio.')
|
|
block_index = memory_map.index(block_number) + 1
|
|
start_addr = block_index * 0x1000
|
|
for addr in range(start_addr, start_addr + 0x1000,
|
|
radio.BLOCK_SIZE):
|
|
frame = radio._make_read_frame(addr, radio.BLOCK_SIZE)
|
|
# DEBUG
|
|
LOG.debug("Frame=" + util.hexprint(frame))
|
|
|
|
baofeng_common._rawsend(radio, frame)
|
|
|
|
d = baofeng_common._rawrecv(radio, radio.BLOCK_SIZE + 5)
|
|
|
|
LOG.debug("Response Data= " + util.hexprint(d))
|
|
|
|
data += d[5:]
|
|
|
|
status.cur = len(data) // radio.BLOCK_SIZE
|
|
status.msg = "Cloning from radio..."
|
|
radio.status_fn(status)
|
|
|
|
baofeng_uv17Pro._sendmagic(radio, b"\x06", 1)
|
|
return data
|
|
|
|
|
|
def _upload(radio):
|
|
"""Upload procedure"""
|
|
baofeng_uv17Pro._do_ident(radio)
|
|
memory_map = _get_memory_map(radio)
|
|
|
|
status = chirp_common.Status()
|
|
status.cur = 0
|
|
status.max = radio.WRITE_MEM_TOTAL // radio.BLOCK_SIZE
|
|
status.msg = "Cloning to radio..."
|
|
radio.status_fn(status)
|
|
|
|
for block_number in radio.BLOCK_ORDER:
|
|
# Choose a block number if memory map is corrupt
|
|
# This can happen when the upload process was interrupted
|
|
if block_number not in memory_map:
|
|
memory_map[memory_map.index(165)] = block_number
|
|
block_index = memory_map.index(block_number) + 1
|
|
start_addr = block_index * 0x1000
|
|
data_start_addr = radio.BLOCK_ORDER.index(block_number) * 0x1000
|
|
for addr in range(start_addr, start_addr + 0x1000,
|
|
radio.BLOCK_SIZE):
|
|
|
|
# sending the data
|
|
data_addr = data_start_addr + addr - start_addr
|
|
data = radio.get_mmap()[data_addr:data_addr + radio.BLOCK_SIZE]
|
|
frame = radio._make_frame(b"W", addr, radio.BLOCK_SIZE, data)
|
|
baofeng_common._rawsend(radio, frame)
|
|
|
|
# receiving the response
|
|
ack = baofeng_common._rawrecv(radio, 1)
|
|
if ack != b"\x06":
|
|
msg = "Bad ack writing block 0x%04x" % addr
|
|
raise errors.RadioError(msg)
|
|
|
|
# UI Update
|
|
status.cur = (data_addr) // radio.BLOCK_SIZE
|
|
status.msg = "Cloning to radio..."
|
|
radio.status_fn(status)
|
|
|
|
|
|
@directory.register
|
|
class UV17(baofeng_uv17Pro.UV17Pro):
|
|
"""Baofeng UV-17"""
|
|
VENDOR = "Baofeng"
|
|
MODEL = "UV-17"
|
|
|
|
download_function = _download
|
|
upload_function = _upload
|
|
|
|
MODES = ["FM", "NFM"]
|
|
BLOCK_ORDER = [16, 17, 18, 19, 24, 25, 26, 4, 6]
|
|
|
|
# Add extra read blocks (e.g. calibration block 2) to the end here:
|
|
BLOCK_O_READ = list(BLOCK_ORDER)
|
|
|
|
MEM_TOTAL = 0x9000
|
|
WRITE_MEM_TOTAL = 0x9000
|
|
BLOCK_SIZE = 0x40
|
|
BAUD_RATE = 57600
|
|
_magic = b"PSEARCH"
|
|
_magics = [(b"PASSSTA", 3),
|
|
(b"SYSINFO", 1),
|
|
(b"\x56\x00\x00\x0A\x0D", 13),
|
|
(b"\x06", 1),
|
|
(b"\x56\x00\x10\x0A\x0D", 13),
|
|
(b"\x06", 1),
|
|
(b"\x56\x00\x20\x0A\x0D", 13),
|
|
(b"\x06", 1)]
|
|
_magic_memsize = [(b"\x56\x00\x00\x00\x0A", 11)]
|
|
_radio_memsize = 0xffff
|
|
_magics2 = [(b"\x06", 1),
|
|
(b"\xFF\xFF\xFF\xFF\x0C\x55\x56\x31\x35\x39\x39\x39", 1),
|
|
(b"\02", 8),
|
|
(b"\x06", 1)]
|
|
_fingerprint = b"\x06" + b"UV15999"
|
|
_scode_offset = 1
|
|
_mem_positions = ()
|
|
|
|
_tri_band = False
|
|
POWER_LEVELS = [chirp_common.PowerLevel("Low", watts=1.00),
|
|
chirp_common.PowerLevel("High", watts=5.00)]
|
|
|
|
LENGTH_NAME = 11
|
|
VALID_BANDS = [baofeng_uv17Pro.UV17Pro._vhf_range,
|
|
baofeng_uv17Pro.UV17Pro._uhf_range]
|
|
SCODE_LIST = ["%s" % x for x in range(1, 16)]
|
|
SQUELCH_LIST = ["Off"] + list("123456789")
|
|
LIST_POWERON_DISPLAY_TYPE = ["Full", "Message", "Voltage"]
|
|
LIST_TIMEOUT = ["Off"] + ["%s sec" % x for x in range(15, 615, 15)]
|
|
LIST_VOICE = ["Chinese", "English"]
|
|
LIST_BACKLIGHT_TIMER = ["Always On"] + ["%s sec" % x for x in range(1, 11)]
|
|
LIST_MODE = ["Name", "Frequency"]
|
|
CHANNELS = 999
|
|
|
|
CHANNEL_DEF = """
|
|
struct channel {
|
|
lbcd rxfreq[4];
|
|
lbcd txfreq[4];
|
|
u8 unused1;
|
|
ul16 rxtone;
|
|
ul16 txtone;
|
|
u8 unknown1:1,
|
|
bcl:1,
|
|
pttid:2,
|
|
unknown2:1,
|
|
wide:1,
|
|
lowpower:1,
|
|
unknown:1;
|
|
u8 scode:4,
|
|
unknown3:3,
|
|
scan:1;
|
|
u8 unknown4;
|
|
};
|
|
"""
|
|
MEM_DEFS = """
|
|
struct channelname {
|
|
char name[11];
|
|
};
|
|
struct settings {
|
|
u8 powerondistype;
|
|
u8 unknown0[15];
|
|
char boottext1[10];
|
|
u8 unknown1[6];
|
|
char boottext2[10];
|
|
u8 unknown2[22];
|
|
u8 tot;
|
|
u8 squelch;
|
|
u8 vox;
|
|
u8 powersave: 4,
|
|
unknown3:2,
|
|
voice: 1,
|
|
voicesw: 1;
|
|
u8 backlight;
|
|
u8 beep:1,
|
|
autolock:1,
|
|
unknown4:1,
|
|
tail:1,
|
|
scanmode:2,
|
|
dtmfst:2;
|
|
u8 unknown5:1,
|
|
dualstandby:1,
|
|
roger:1,
|
|
unknown6:3,
|
|
fmenable:1,
|
|
unknown7:1;
|
|
u8 unknown8[9];
|
|
u8 unknown9:6,
|
|
chbdistype:1,
|
|
chadistype:1;
|
|
};
|
|
struct ani {
|
|
u8 unknown[5];
|
|
u8 code[5];
|
|
};
|
|
struct pttid {
|
|
u8 code[5];
|
|
};
|
|
"""
|
|
|
|
MEM_LAYOUT = """
|
|
#seekto 0x0030;
|
|
struct {
|
|
struct channel mem[252];
|
|
} mem1;
|
|
|
|
#seek 0x10;
|
|
struct {
|
|
struct channel mem[255];
|
|
} mem2;
|
|
|
|
#seek 0x10;
|
|
struct {
|
|
struct channel mem[255];
|
|
} mem3;
|
|
|
|
#seek 0x10;
|
|
struct {
|
|
struct channel mem[237];
|
|
} mem4;
|
|
|
|
#seekto 0x7000;
|
|
struct settings settings;
|
|
|
|
struct vfo {
|
|
lbcd rxfreq[4];
|
|
lbcd txfreq[4];
|
|
u8 unused1;
|
|
ul16 rxtone;
|
|
ul16 txtone;
|
|
u8 unknown1:1,
|
|
bcl:1,
|
|
pttid:2,
|
|
unknown2:1,
|
|
wide:1,
|
|
lowpower:1,
|
|
unknown:1;
|
|
u8 scode:4,
|
|
unknown3:3,
|
|
scan:1;
|
|
u8 unknown4;
|
|
};
|
|
|
|
#seekto 0x0010;
|
|
struct {
|
|
struct vfo a;
|
|
struct vfo b;
|
|
} vfo;
|
|
|
|
#seekto 0x4000;
|
|
struct channelname names1[372];
|
|
#seek 0x4;
|
|
struct channelname names2[372];
|
|
#seek 0x4;
|
|
struct channelname names3[255];
|
|
|
|
#seekto 0x8000;
|
|
struct pttid pttid[15];
|
|
|
|
struct ani ani;
|
|
"""
|
|
MEM_FORMAT = CHANNEL_DEF + MEM_DEFS + MEM_LAYOUT
|
|
|
|
def _make_frame(self, cmd, addr, length, data=""):
|
|
"""Pack the info in the header format"""
|
|
frame = struct.pack("<cI", cmd, addr)[:-1] + struct.pack(">B", length)
|
|
# add the data if set
|
|
if len(data) != 0:
|
|
frame += data
|
|
# return the data
|
|
return frame
|
|
|
|
def get_settings(self):
|
|
"""Translate the bit in the mem_struct into settings in the UI"""
|
|
_mem = self._memobj
|
|
basic = RadioSettingGroup("basic", "Basic Settings")
|
|
dtmfe = RadioSettingGroup("dtmfe", "DTMF Encode Settings")
|
|
top = RadioSettings(basic, dtmfe)
|
|
|
|
self.get_settings_common_basic(basic, _mem)
|
|
|
|
def _filter(name):
|
|
filtered = ""
|
|
for char in str(name):
|
|
if char in chirp_common.CHARSET_ASCII:
|
|
filtered += char
|
|
else:
|
|
filtered += " "
|
|
return filtered
|
|
|
|
rs = RadioSetting("settings.boottext1", "Power-On Message 1",
|
|
RadioSettingValueString(
|
|
0, 10, _filter(self._memobj.settings.boottext1)))
|
|
basic.append(rs)
|
|
|
|
rs = RadioSetting("settings.boottext2", "Power-On Message 2",
|
|
RadioSettingValueString(
|
|
0, 10, _filter(self._memobj.settings.boottext2)))
|
|
basic.append(rs)
|
|
|
|
if _mem.settings.powersave > 0x04:
|
|
val = 0x00
|
|
else:
|
|
val = _mem.settings.powersave
|
|
rs = RadioSetting("settings.powersave", "Battery Saver",
|
|
RadioSettingValueList(
|
|
LIST_SAVE, current_index=val))
|
|
basic.append(rs)
|
|
|
|
rs = RadioSetting("settings.scanmode", "Scan Mode",
|
|
RadioSettingValueList(
|
|
LIST_SCANMODE,
|
|
current_index=_mem.settings.scanmode))
|
|
basic.append(rs)
|
|
|
|
rs = RadioSetting(
|
|
"settings.dtmfst", "DTMF Sidetone",
|
|
RadioSettingValueList(
|
|
LIST_DTMFST, current_index=_mem.settings.dtmfst))
|
|
basic.append(rs)
|
|
|
|
rs = RadioSetting("settings.fmenable", "Enable FM radio",
|
|
RadioSettingValueBoolean(_mem.settings.fmenable))
|
|
basic.append(rs)
|
|
|
|
self.get_settings_common_dtmf(dtmfe, _mem)
|
|
|
|
return top
|
|
|
|
def decode_tone(self, val):
|
|
pol = "N"
|
|
mode = ""
|
|
if val in [0, 0xFFFF]:
|
|
xval = 0
|
|
elif (val & 0x8000) > 0:
|
|
mode = "DTCS"
|
|
xval = (val & 0x0f) + (val >> 4 & 0xf)\
|
|
* 10 + (val >> 8 & 0xf) * 100
|
|
if (val & 0xC000) == 0xC000:
|
|
pol = "R"
|
|
else:
|
|
mode = "Tone"
|
|
xval = int((val & 0x0f) + (val >> 4 & 0xf) * 10 +
|
|
(val >> 8 & 0xf) * 100 + (val >> 12 & 0xf)
|
|
* 1000) / 10.0
|
|
|
|
return mode, xval, pol
|
|
|
|
def _get_raw_memory(self, number):
|
|
# The flash memory contains page_numbers
|
|
# This is probably to do wear leveling on the memory
|
|
# These numbers are needed, but make the channel memory
|
|
# not continuous.
|
|
number = number - 1
|
|
if number >= 762:
|
|
_mem = self._memobj.mem4.mem[number - 762]
|
|
return _mem
|
|
if number >= 507:
|
|
_mem = self._memobj.mem3.mem[number - 507]
|
|
return _mem
|
|
if number >= 252:
|
|
_mem = self._memobj.mem2.mem[number - 252]
|
|
return _mem
|
|
_mem = self._memobj.mem1.mem[number]
|
|
return _mem
|
|
|
|
def get_raw_memory(self, number):
|
|
return repr(self._get_raw_memory(number))
|
|
|
|
def get_channel_name(self, number):
|
|
number = number - 1
|
|
if number >= 744:
|
|
_name = self._memobj.names3[number - 744]
|
|
return _name
|
|
if number >= 372:
|
|
_name = self._memobj.names2[number - 372]
|
|
return _name
|
|
_name = self._memobj.names1[number]
|
|
return _name
|
|
|
|
def get_memory(self, number):
|
|
_mem = self._get_raw_memory(number)
|
|
_nam = self.get_channel_name(number)
|
|
|
|
mem = chirp_common.Memory()
|
|
mem.number = number
|
|
|
|
self.get_memory_common(_mem, _nam.name, mem)
|
|
|
|
return mem
|
|
|
|
def encode_tone(self, memtone, mode, tone, pol):
|
|
if mode == "Tone":
|
|
xtone = '%04i' % (tone * 10)
|
|
memtone.set_value((int(xtone[0]) << 12) + (int(xtone[1]) << 8) +
|
|
(int(xtone[2]) << 4) + int(xtone[3]))
|
|
elif mode == "TSQL":
|
|
xtone = '%04i' % (tone * 10)
|
|
memtone.set_value((int(tone[0]) << 12) + (int(xtone[1]) << 8) +
|
|
(int(xtone[2]) << 4) + int(xtone[3]))
|
|
elif mode == "DTCS":
|
|
xtone = str(int(tone)).rjust(4, '0')
|
|
memtone.set_value((0x8000 + (int(xtone[0]) << 12) +
|
|
(int(xtone[1]) << 8) + (int(xtone[2]) << 4) +
|
|
int(xtone[3])))
|
|
else:
|
|
memtone.set_value(0)
|
|
|
|
if mode == "DTCS" and pol == "R":
|
|
memtone.set_value(memtone + 0x4000)
|
|
|
|
def set_memory(self, mem):
|
|
_mem = self._get_raw_memory(mem.number)
|
|
_nam = self.get_channel_name(mem.number)
|
|
|
|
if mem.empty:
|
|
_mem.set_raw(b"\xff" * 16)
|
|
return
|
|
|
|
_mem.set_raw(b"\x00" * 16)
|
|
|
|
_namelength = self.get_features().valid_name_length
|
|
_nam.name = mem.name[:_namelength].ljust(11, '\x00')
|
|
|
|
self.set_memory_common(mem, _mem)
|
|
|
|
|
|
@directory.register
|
|
class UV13Pro(UV17):
|
|
VENDOR = "Baofeng"
|
|
MODEL = "UV-13Pro"
|
|
|
|
_radio_memsize = 0x31fff
|
|
# Copyright 2024:
|
|
# * Pavel Moravec, OK2MOP <moravecp.cz@gmail.com>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 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 logging
|
|
from chirp import chirp_common, directory
|
|
from chirp.settings import RadioSettingGroup, RadioSetting, \
|
|
RadioSettingValueBoolean, RadioSettingValueList
|
|
from chirp.drivers import baofeng_uv17Pro, baofeng_uv17
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
@directory.register
|
|
class RT620(UV17):
|
|
"""Radtel RT-620"""
|
|
VENDOR = "Radtel"
|
|
MODEL = "RT-620"
|
|
_radio_memsize = 0x2efff
|
|
_has_workmode_support = True
|
|
_has_gps = True
|
|
_vfoscan = True
|
|
|
|
# Top key is referenced in CPS but does not exist in GPS model
|
|
_has_top_key = False
|
|
_has_pilot_tone = True
|
|
|
|
STEPS = [2.5, 5.0, 6.25, 10.0, 12.5, 20.0, 25.0, 50.0]
|
|
|
|
# Blocks 16-19 - channels, 24-26 channel names, 4 settings,
|
|
# 6 - secondary settings, identity codes,
|
|
# 2 - calibration, 1 - empty radio param
|
|
BLOCK_O_READ = UV17.BLOCK_O_READ + [2] # back up calibration
|
|
|
|
_airband = (108000000, 135999999)
|
|
_vhf_range = (136000000, 299999999)
|
|
_uhf_range = (300000000, 559999999)
|
|
VALID_BANDS = [_airband, _vhf_range, _uhf_range]
|
|
_fingerprint = b"\x06" + b"PROGR6F"
|
|
_magics2 = [(b"\x06", 1),
|
|
(b"\xFF\xFF\xFF\xFF\x0CPROGR6F", 1),
|
|
(b"\02", 8),
|
|
(b"\x06", 1)]
|
|
CHANNELS = 999
|
|
MODES = ["NFM", "FM", "WFM"]
|
|
POWER_LEVELS = [chirp_common.PowerLevel("Low", watts=1.00),
|
|
chirp_common.PowerLevel("Mid", watts=5.00),
|
|
chirp_common.PowerLevel("High", watts=10.00)]
|
|
LIST_MODE = ["VFO", "Channel Number",
|
|
"Frequency + Channel Number", "Name + Channel Number"]
|
|
LIST_BEEP = ["Off", "On"]
|
|
LIST_VOX_LEVEL = baofeng_uv17Pro.LIST_VOX_LEVEL
|
|
LIST_ALARMMODE = baofeng_uv17Pro.LIST_ALARMMODE
|
|
LIST_PILOT_TONE = baofeng_uv17Pro.LIST_PILOT_TONE
|
|
LIST_VOX_DELAY_TIME = ["Off"] + ["%s ms" %
|
|
x for x in range(500, 2100, 100)]
|
|
LIST_NOAA = ["NOAA OFF", "NOAA Forecast",
|
|
"NOAA Alarm", "NOAA Both"] # NOAA here
|
|
LIST_100ms = ["%s ms" % x for x in range(100, 1100, 100)]
|
|
LIST_AB = ["A", "B"]
|
|
LIST_BRIGHTNESS = ["%i" % x for x in range(1, 6)]
|
|
LIST_MENU_QUIT_TIME = ["Off"] + ["%s sec" % x for x in range(1, 31)]
|
|
LIST_KEYS = ["None", "Monitor", "Sweep", "Scan", "Voltage",
|
|
"Emergency", "Scrambler", "FM Radio", "Compander"]
|
|
MEM_DEFS = """
|
|
struct channel {
|
|
lbcd rxfreq[4];
|
|
lbcd txfreq[4];
|
|
ul16 rxtone;
|
|
ul16 txtone;
|
|
u8 unknown12_7:1,
|
|
bcl:1,
|
|
pttid:2,
|
|
wide:2,
|
|
lowpower:2;
|
|
u8 unknown13_5:3,
|
|
compander:1,
|
|
unknown_13_2:2,
|
|
scrambler:2;
|
|
u8 scode:4,
|
|
unknown14_1:3,
|
|
scan:1;
|
|
u8 step;
|
|
};
|
|
struct channelname {
|
|
char name[11];
|
|
};
|
|
struct settings {
|
|
u8 powerondistype;
|
|
u8 unknown0[15];
|
|
char boottext1[10];
|
|
u8 unknown1[6];
|
|
char boottext2[10];
|
|
u8 unknown2[22];
|
|
u8 tot;
|
|
u8 voxdlytime;
|
|
u8 vox;
|
|
u8 powersave: 4,
|
|
unknown3:1,
|
|
chedit:1,
|
|
voice: 1,
|
|
voicesw: 1;
|
|
u8 backlight;
|
|
u8 beep:1,
|
|
autolock:1,
|
|
unknown_5b5:1,
|
|
noaa:2,
|
|
tail:1,
|
|
dtmfst:2;
|
|
u8 fminterrupt:1,
|
|
dualstandby:1,
|
|
roger:1,
|
|
alarmmode:2,
|
|
alarmtone:1,
|
|
fmenable:1,
|
|
absel:1;
|
|
u8 tailrevert;
|
|
u8 taildelay;
|
|
u8 tone;
|
|
u8 backlightbr;
|
|
u8 squelch;
|
|
u8 chbsquelch;
|
|
u8 chbdistype;
|
|
u8 chadistype;
|
|
u8 menuquittime;
|
|
u8 sk1short;
|
|
u8 sk1long;
|
|
u8 sk2short;
|
|
u8 sk2long;
|
|
u8 topshort;
|
|
u8 toplong;
|
|
u8 scanmode; // Fake Scanmode to satisfy parent method
|
|
u8 unknown8[5];
|
|
};
|
|
struct ani {
|
|
u8 unknown[5];
|
|
u8 code[5];
|
|
};
|
|
struct pttid {
|
|
u8 code[5];
|
|
};
|
|
struct proglocks {
|
|
u8 writelock; //0x00 - off, 0xA5 - on
|
|
u8 readlock;
|
|
char writepass[8];
|
|
char readpass[8];
|
|
u8 empty[13];
|
|
char unknowncode[6]; //Kill code maybe
|
|
};
|
|
struct gps {
|
|
u8 state;
|
|
u8 tzadd12;
|
|
};
|
|
struct dtmfen {
|
|
u8 delay;
|
|
u8 digit;
|
|
u8 interval;
|
|
};
|
|
"""
|
|
MEM_LAYOUT = """
|
|
struct {
|
|
ul16 channels;
|
|
ul16 ch_a;
|
|
ul16 ch_b;
|
|
} chsel;
|
|
#seekto 0x0030;
|
|
struct {
|
|
struct channel mem[252];
|
|
} mem1;
|
|
#seek 0x10;
|
|
struct {
|
|
struct channel mem[255];
|
|
} mem2;
|
|
#seek 0x10;
|
|
struct {
|
|
struct channel mem[255];
|
|
} mem3;
|
|
#seek 0x10;
|
|
struct {
|
|
struct channel mem[237];
|
|
} mem4;
|
|
#seekto 0x7000;
|
|
struct settings settings;
|
|
#seekto 0x0010;
|
|
struct {
|
|
struct channel a;
|
|
struct channel b;
|
|
} vfo;
|
|
#seekto 0x4000;
|
|
struct channelname names1[372];
|
|
#seek 0x4;
|
|
struct channelname names2[372];
|
|
#seek 0x4;
|
|
struct channelname names3[255];
|
|
#seekto 0x7100;
|
|
struct gps gps;
|
|
#seekto 0x7069;
|
|
struct proglocks locks;
|
|
#seekto 0x8000;
|
|
struct pttid pttid[15];
|
|
struct ani ani;
|
|
#seekto 0x8061;
|
|
struct dtmfen dtmf;
|
|
"""
|
|
MEM_FORMAT = MEM_DEFS + MEM_LAYOUT
|
|
REMOVE_SETTINGS = ['settings.scanmode']
|
|
|
|
def remove_extras(self, settings):
|
|
for element in settings:
|
|
if not isinstance(element, RadioSetting):
|
|
settings.remove(element)
|
|
settings.append(self.remove_extra_items(element))
|
|
settings.sort()
|
|
|
|
def remove_extra_items(self, group):
|
|
tmp = RadioSettingGroup(group.get_name(), group.get_shortname())
|
|
for element in group:
|
|
name = element.get_name()
|
|
if not isinstance(element, RadioSetting):
|
|
tmp.append(self.remove_extra_items(element))
|
|
elif name not in self.REMOVE_SETTINGS:
|
|
tmp.append(element)
|
|
return tmp
|
|
|
|
def get_settings(self):
|
|
top = super().get_settings()
|
|
_mem = self._memobj
|
|
self.remove_extras(top)
|
|
extra = RadioSettingGroup("extra", "Extra Settings")
|
|
self.get_settings_extra(extra, _mem)
|
|
top.append(extra)
|
|
if self._has_gps:
|
|
gps = RadioSettingGroup("gps", "GPS Settings")
|
|
rs = RadioSetting("gps.state", "GPS Enable",
|
|
RadioSettingValueBoolean(_mem.gps.state))
|
|
gps.append(rs)
|
|
rs = RadioSetting("gps.tzadd12", "GPS Timezone",
|
|
RadioSettingValueList(
|
|
baofeng_uv17Pro.LIST_GPS_TIMEZONE,
|
|
current_index=_mem.gps.tzadd12))
|
|
gps.append(rs)
|
|
top.append(gps)
|
|
return top
|
|
|
|
def get_settings_extra(self, extra, _mem):
|
|
rs = RadioSetting("settings.absel", "Selected Channel",
|
|
RadioSettingValueList(
|
|
self.LIST_AB, current_index=_mem.settings.absel))
|
|
extra.append(rs)
|
|
if _mem.settings.chbsquelch >= len(self.SQUELCH_LIST):
|
|
val = 0x00
|
|
else:
|
|
val = _mem.settings.chbsquelch
|
|
rs = RadioSetting("settings.chbsquelch", "Channel B Squelch",
|
|
RadioSettingValueList(
|
|
self.SQUELCH_LIST, current_index=val))
|
|
extra.append(rs)
|
|
# Settings menu 4
|
|
rs = RadioSetting("settings.vox", "Vox Level",
|
|
RadioSettingValueList(
|
|
self.LIST_VOX_LEVEL,
|
|
current_index=_mem.settings.vox))
|
|
extra.append(rs)
|
|
# Settings menu 5
|
|
rs = RadioSetting("settings.voxdlytime", "Vox Delay Time",
|
|
RadioSettingValueList(
|
|
self.LIST_VOX_DELAY_TIME,
|
|
current_index=_mem.settings.voxdlytime))
|
|
extra.append(rs)
|
|
# Settings menu 12
|
|
rs = RadioSetting("settings.backlightbr", "Backlight Brightnes",
|
|
RadioSettingValueList(
|
|
self.LIST_BRIGHTNESS,
|
|
current_index=_mem.settings.backlightbr))
|
|
extra.append(rs)
|
|
rs = RadioSetting("settings.chedit", "Allow Channel Editing",
|
|
RadioSettingValueBoolean(_mem.settings.chedit))
|
|
extra.append(rs)
|
|
# Settings menu 22
|
|
rs = RadioSetting("settings.tail", "CTCSS Tail Revert",
|
|
RadioSettingValueBoolean(_mem.settings.tail))
|
|
extra.append(rs)
|
|
rs = RadioSetting("settings.tailrevert", "Repeater Tail Revert Time",
|
|
RadioSettingValueList(
|
|
self.LIST_100ms,
|
|
current_index=_mem.settings.tailrevert))
|
|
extra.append(rs)
|
|
rs = RadioSetting("settings.taildelay", "Repeater Tail Delay Time",
|
|
RadioSettingValueList(
|
|
self.LIST_100ms,
|
|
current_index=_mem.settings.taildelay))
|
|
extra.append(rs)
|
|
rs = RadioSetting("settings.fminterrupt", "FM radio Interruption",
|
|
RadioSettingValueBoolean(_mem.settings.fminterrupt))
|
|
extra.append(rs)
|
|
# Settings menu 21
|
|
rs = RadioSetting("settings.alarmmode", "Alarm Mode",
|
|
RadioSettingValueList(
|
|
self.LIST_ALARMMODE,
|
|
current_index=_mem.settings.alarmmode))
|
|
extra.append(rs)
|
|
rs = RadioSetting("settings.alarmtone", "Sound Alarm",
|
|
RadioSettingValueBoolean(_mem.settings.alarmtone))
|
|
extra.append(rs)
|
|
rs = RadioSetting("settings.menuquittime", "Menu Quit Timer",
|
|
RadioSettingValueList(
|
|
self.LIST_MENU_QUIT_TIME,
|
|
current_index=_mem.settings.menuquittime))
|
|
extra.append(rs)
|
|
if self._has_pilot_tone:
|
|
rs = RadioSetting("settings.tone", "Pilot Tone",
|
|
RadioSettingValueList(
|
|
self.LIST_PILOT_TONE,
|
|
current_index=_mem.settings.tone))
|
|
extra.append(rs)
|
|
# Settings menu 27
|
|
if _mem.settings.sk1short >= len(self.LIST_KEYS):
|
|
val = 0x00
|
|
else:
|
|
val = _mem.settings.sk1short
|
|
rs = RadioSetting("settings.sk1short", "Side Key 1 Short Press",
|
|
RadioSettingValueList(
|
|
self.LIST_KEYS, current_index=val))
|
|
extra.append(rs)
|
|
# Settings menu 28
|
|
if _mem.settings.sk1long >= len(self.LIST_KEYS):
|
|
val = 0x00
|
|
else:
|
|
val = _mem.settings.sk1long
|
|
rs = RadioSetting("settings.sk1long", "Side Key 1 Long Press",
|
|
RadioSettingValueList(
|
|
self.LIST_KEYS, current_index=val))
|
|
extra.append(rs)
|
|
# Settings menu 29
|
|
if _mem.settings.sk2short >= len(self.LIST_KEYS):
|
|
val = 0x00
|
|
else:
|
|
val = _mem.settings.sk2short
|
|
rs = RadioSetting("settings.sk2short", "Side Key 2 Short Press",
|
|
RadioSettingValueList(
|
|
self.LIST_KEYS, current_index=val))
|
|
extra.append(rs)
|
|
# Settings menu 30
|
|
if _mem.settings.sk2long >= len(self.LIST_KEYS):
|
|
val = 0x00
|
|
else:
|
|
val = _mem.settings.sk2long
|
|
rs = RadioSetting("settings.sk2long", "Side Key 2 Long Press",
|
|
RadioSettingValueList(
|
|
self.LIST_KEYS, current_index=val))
|
|
extra.append(rs)
|
|
# Official CPS sets this, but radio does not have top key
|
|
# Probably the non-GPS version or some other clone uses it so
|
|
# I have included it here when/if it will be needed
|
|
if self._has_top_key:
|
|
if _mem.settings.topshort >= len(self.LIST_KEYS):
|
|
val = 0x00
|
|
else:
|
|
val = _mem.settings.topshort
|
|
rs = RadioSetting("settings.topshort", "Top Key Short Press",
|
|
RadioSettingValueList(
|
|
self.LIST_KEYS, current_index=val))
|
|
extra.append(rs)
|
|
# Settings menu 30
|
|
if _mem.settings.toplong >= len(self.LIST_KEYS):
|
|
val = 0x00
|
|
else:
|
|
val = _mem.settings.toplong
|
|
rs = RadioSetting("settings.toplong", "Top Key Long Press",
|
|
RadioSettingValueList(
|
|
self.LIST_KEYS, current_index=val))
|
|
extra.append(rs)
|
|
# NOAA menu
|
|
rs = RadioSetting("settings.noaa", "NOAA Weather mode",
|
|
RadioSettingValueList(
|
|
self.LIST_NOAA,
|
|
current_index=_mem.settings.noaa))
|
|
extra.append(rs)
|
|
|
|
def _get_raw_memory(self, number):
|
|
if number == -1:
|
|
return self._memobj.vfo.b
|
|
elif number == -2:
|
|
return self._memobj.vfo.a
|
|
else:
|
|
return super()._get_raw_memory(number)
|
|
|
|
def get_memory(self, number):
|
|
mem = super().get_memory(number)
|
|
_mem = self._get_raw_memory(number)
|
|
if hasattr(mem.extra, "keys") and \
|
|
"compander" not in mem.extra.keys():
|
|
rs = RadioSetting("compander", "Compander",
|
|
RadioSettingValueBoolean(_mem.compander))
|
|
mem.extra.append(rs)
|
|
mem.tuning_step = self.STEPS[_mem.step] or self.STEPS[0]
|
|
if _mem.wide < len(self.MODES):
|
|
mem.mode = self.MODES[_mem.wide]
|
|
return mem
|
|
|
|
def set_memory(self, mem):
|
|
_mem = self._get_raw_memory(mem.number)
|
|
super().set_memory(mem)
|
|
_mem.step = self.STEPS.index(mem.tuning_step)
|
|
_mem.wide = self.MODES.index(mem.mode)
|
|
if _mem.rxtone == 0:
|
|
_mem.rxtone = 0xFFFF
|
|
if _mem.txtone == 0:
|
|
_mem.txtone = 0xFFFF
|
|
|
|
def get_features(self):
|
|
rf = super().get_features()
|
|
rf.has_tuning_step = True
|
|
rf.has_bank = False
|
|
return rf
|