Skip to content

Commit

Permalink
improve memory mapping, fix narrow/wide modes, sort banks in memory, …
Browse files Browse the repository at this point in the history
…and rename variables
  • Loading branch information
Patronics committed Dec 14, 2024
1 parent f22a50f commit d844096
Showing 1 changed file with 47 additions and 32 deletions.
79 changes: 47 additions & 32 deletions chirp/drivers/tk690.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,17 @@
bcl:1, // busy channel lockout, 1 = on
pttid:1, // ptt id, 1 = on
signal:3; //off=0, 1=DTMF, 2,3,4 = "2-Tone 1,2,3"
u8 unknown1:4,
u8 unknown1:2,
txdisable:1, // 1=RX only, 0=RX/TX
unknown7:1,
add:1, // scan add, 1 = add
unknown2:1,
wide:1, // Wide = 1, narrow = 0
unknown2:1,
unknown4:1;
u8 unknown5;
u8 nose;
u8 unknown6:6,
compander:1, // 0 = compander active, only applicable on narrow band
valid:1; // 0 = valid entry, enabled; 1=invalid
} memory[160];
#seekto 0x3DF0;
Expand Down Expand Up @@ -161,9 +165,6 @@
EMPTY_BLOCK = b"\xFF" * 256
EMPTY_L = b"\xFF" * RX_BLOCK_SIZE_L
EMPTY_H = b"\xFF" * RX_BLOCK_SIZE_H
POWER_LEVELS = [chirp_common.PowerLevel("High", watts=45),
chirp_common.PowerLevel("Low", watts=5)]
MODES = ["NFM", "FM"] # 12.5 / 25 Khz
VALID_CHARS = chirp_common.CHARSET_UPPER_NUMERIC + "()/\\*@-+,.#_"
SKIP_VALUES = ["S", ""]
TONES = chirp_common.TONES
Expand Down Expand Up @@ -296,7 +297,6 @@ def _open_radio(radio):
raise errors.RadioError("Serial Connection Error")

ack = radio.pipe.read(10)
print(ack)
if ack == ACK_CMD:
# successful acknowledgement
pass
Expand Down Expand Up @@ -340,7 +340,7 @@ def do_download(radio):

# initialize variables
data = b""
bar = 0
memory_index = 0

for addr in MEM_LR:
radio.pipe.write(_make_framel(b"R", addr))
Expand All @@ -353,8 +353,8 @@ def do_download(radio):
data += d

# UI update
bar += RX_BLOCK_SIZE_L
status.cur = bar
memory_index += RX_BLOCK_SIZE_L
status.cur = memory_index # update the progress bar
status.msg = "Cloning from Main MCU (Low mem)..."
radio.status_fn(status)

Expand All @@ -371,8 +371,8 @@ def do_download(radio):
_handshake(radio, "Middle mem ack error")

# UI update
bar += RX_BLOCK_SIZE_M
status.cur = bar
memory_index += RX_BLOCK_SIZE_M
status.cur = memory_index
status.msg = "Cloning from 'unknown' (mid mem)..."
radio.status_fn(status)

Expand All @@ -387,8 +387,8 @@ def do_download(radio):
data += d

# UI update
bar += RX_BLOCK_SIZE_H
status.cur = bar
memory_index += RX_BLOCK_SIZE_H
status.cur = memory_index
status.msg = "Cloning from Head (High mem)..."
radio.status_fn(status)

Expand All @@ -407,12 +407,12 @@ def do_upload(radio):
_open_radio(radio)

# initialize variables
bar = 0
memory_index = 0
img = radio.get_mmap()

for addr in MEM_LR:
# this is the data to write
data = img[bar:bar + RX_BLOCK_SIZE_L]
data = img[memory_index:memory_index + RX_BLOCK_SIZE_L]
# sdata is the full packet to send

# flag
Expand All @@ -436,14 +436,14 @@ def do_upload(radio):
_handshake(radio, msg, False)

# UI Update
bar += RX_BLOCK_SIZE_L
status.cur = bar
memory_index += RX_BLOCK_SIZE_L
status.cur = memory_index # update the progress bar
status.msg = "Cloning to Main MCU (Low mem)..."
radio.status_fn(status)

for addr in MEM_MR:
# this is the data to write
data = img[bar:bar + RX_BLOCK_SIZE_M]
data = img[memory_index:memory_index + RX_BLOCK_SIZE_M]
sdata = _make_framem(b"Y", addr) + b"\x00" + data

# send it
Expand All @@ -454,14 +454,14 @@ def do_upload(radio):
_handshake(radio, msg, not short)

# UI Update
bar += RX_BLOCK_SIZE_M
status.cur = bar
memory_index += RX_BLOCK_SIZE_M
status.cur = memory_index
status.msg = "Cloning from middle mem..."
radio.status_fn(status)

for addr in MEM_HR:
# this is the data to write
data = img[bar:bar + RX_BLOCK_SIZE_H]
data = img[memory_index:memory_index + RX_BLOCK_SIZE_H]
# this is the full packet to send
sdata = b""

Expand All @@ -481,8 +481,8 @@ def do_upload(radio):
_handshake(radio, msg, False)

# UI Update
bar += RX_BLOCK_SIZE_H
status.cur = bar
memory_index += RX_BLOCK_SIZE_H
status.cur = memory_index
status.msg = "Cloning to Head MCU (high mem)..."
radio.status_fn(status)

Expand Down Expand Up @@ -556,6 +556,9 @@ class Kenwoodx90(chirp_common.CloneModeRadio, chirp_common.ExperimentalRadio):
BAUD_RATE = 9600
VARIANT = ""
MODEL = ""
POWER_LEVELS = [chirp_common.PowerLevel("High", watts=45),
chirp_common.PowerLevel("Low", watts=5)]
MODES = ["NFM", "FM"] # 12.5 / 25 Khz
_name_chars = 8
# others
_memsize = MEM_SIZE
Expand Down Expand Up @@ -600,7 +603,7 @@ def get_features(self):
rf.has_dtcs_polarity = True
rf.has_ctone = True
rf.has_cross = True
rf.valid_modes = MODES
rf.valid_modes = self.MODES
rf.valid_duplexes = ["", "-", "+", "off"]
rf.valid_tmodes = ['', 'Tone', 'TSQL', 'DTCS', 'Cross']
rf.valid_cross_modes = [
Expand All @@ -611,7 +614,7 @@ def get_features(self):
"DTCS->Tone",
"->Tone",
"DTCS->DTCS"]
rf.valid_power_levels = POWER_LEVELS
rf.valid_power_levels = self.POWER_LEVELS
rf.valid_characters = VALID_CHARS
rf.valid_skips = SKIP_VALUES
rf.valid_dtcs_codes = DTCS_CODES
Expand Down Expand Up @@ -654,6 +657,7 @@ def _prep_data(self):

for k, v in data.iteritems():
# possible bad data
print("k%s: , v:%s" % (k, v))
if k == 0:
k = 1
raise errors.InvalidValueError(
Expand Down Expand Up @@ -872,10 +876,13 @@ def get_memory(self, number):
mem.name = str(_chs_names.name).rstrip(" ")[:self._name_chars + 1]

# power (0 = high, 1 = low)
mem.power = POWER_LEVELS[int(_mem.power)]
mem.power = self.POWER_LEVELS[int(_mem.power)]

# wide/narrow
mem.mode = MODES[int(_mem.wide)]
if self.MODEL == "TK-690" and _mem.wide == 1:
LOG.debug("Invalid bandwidth mode entry found for TK-690. Fixing")
_mem.wide = 0
mem.mode = self.MODES[int(_mem.wide)]

# skip
mem.skip = SKIP_VALUES[int(_mem.add)]
Expand Down Expand Up @@ -921,7 +928,7 @@ def set_memory(self, mem):

# the name tag
for byte in _ch_name.name:
byte.set_raw("\xFF")
byte.set_raw(b"\xFF")

# delete it from the banks
self._del_channel_from_bank(mem.number)
Expand All @@ -939,8 +946,10 @@ def set_memory(self, mem):
elif mem.duplex == "off":
for byte in _mem.txfreq:
byte.set_raw(b"\xFF")
_mem.txdisable = 1
else:
_mem.txfreq = mem.freq / 10
_mem.txdisable = 0

# tone data
((txmode, txtone, txpol), (rxmode, rxtone, rxpol)) = \
Expand All @@ -952,16 +961,19 @@ def set_memory(self, mem):
_ch_name.name = str(mem.name).ljust(16, " ")

# power, # default power is low (0 = high, 1 = low)
_mem.power = 0 if mem.power is None else POWER_LEVELS.index(mem.power)
if mem.power is None:
_mem.power = 0
else:
self.POWER_LEVELS.index(mem.power)

# wide/narrow
_mem.wide = MODES.index(mem.mode)
_mem.wide = self.MODES.index(mem.mode)

# scan add property
_mem.add = SKIP_VALUES.index(mem.skip)

# setting required but unknown value
_mem.nose.set_raw(b"\xFE")
_mem.valid.set_raw(b'\x00')

# extra settings
if len(mem.extra) > 0:
Expand Down Expand Up @@ -1069,6 +1081,8 @@ def _update_bank_memmap(self):

# group_belong index
gbi = 0
# sort the banks for consistient memory entries
self._banks = dict(sorted(self._banks.items()))
for bank in self._banks:
# check for empty banks
if len(self._banks[bank]) == 0:
Expand Down Expand Up @@ -1155,6 +1169,7 @@ class TK690Radio(Kenwoodx90):
"""Kenwood TK-690 """
MODEL = "TK-690"
TYPE = b"M0690"
MODES = ["NFM"]
VARIANTS = {
b"M0690\x01": (160, 28, 37, "K"), # see note below
b"M0690\x02": (160, 35, 43, "K2"),
Expand Down

0 comments on commit d844096

Please sign in to comment.