<div dir="ltr"><div>CHIRP Radio Images (*.img) file for testing attached.</div><div><br></div><div>Jim KC9HI<br></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">---------- Forwarded message ---------<br>From: <b class="gmail_sendername" dir="auto">Jim Unroe</b> <span dir="auto"><<a href="mailto:kc9hi@comcast.net" target="_blank">kc9hi@comcast.net</a>></span><br>Date: Sat, Jul 3, 2021 at 2:25 PM<br>Subject: [PATCH] [RT98] Add support for Retevis RT98 Single Band Mini Mobile Radios<br>To: <<a href="mailto:Rock.Unroe@gmail.com" target="_blank">Rock.Unroe@gmail.com</a>><br></div><br><br># HG changeset patch<br>
# User Jim Unroe <<a href="mailto:rock.unroe@gmail.com" target="_blank">rock.unroe@gmail.com</a>><br>
# Date 1625336015 14400<br>
# Sat Jul 03 14:13:35 2021 -0400<br>
# Node ID 0eab8146b294ef686ca4a49c17ea38abde54c7ab<br>
# Parent f586574bc8786fd6bef1e5d54d08d381c81edd47<br>
[RT98] Add support for Retevis RT98 Single Band Mini Mobile Radios<br>
<br>
This patch adds support for the various Retevis RT98 mobile radio models/modes.<br>
VHF FreeNet<br>
VHF COM<br>
VHF COMII<br>
UHF PMR<br>
UHF COM<br>
UHF COMII<br>
<br>
#9181<br>
<br>
diff -r f586574bc878 -r 0eab8146b294 chirp/drivers/retevis_rt98.py<br>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000<br>
+++ b/chirp/drivers/retevis_rt98.py Sat Jul 03 14:13:35 2021 -0400<br>
@@ -0,0 +1,1364 @@<br>
+# Copyright 2021 Jim Unroe <<a href="mailto:rock.unroe@gmail.com" target="_blank">rock.unroe@gmail.com</a>><br>
+#<br>
+# This program is free software: you can redistribute it and/or modify<br>
+# it under the terms of the GNU General Public License as published by<br>
+# the Free Software Foundation, either version 2 of the License, or<br>
+# (at your option) any later version.<br>
+#<br>
+# This program is distributed in the hope that it will be useful,<br>
+# but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>
+# GNU General Public License for more details.<br>
+#<br>
+# You should have received a copy of the GNU General Public License<br>
+# along with this program. If not, see <<a href="http://www.gnu.org/licenses/" rel="noreferrer" target="_blank">http://www.gnu.org/licenses/</a>>.<br>
+<br>
+import os<br>
+import struct<br>
+import time<br>
+import logging<br>
+<br>
+from chirp import bitwise<br>
+from chirp import chirp_common<br>
+from chirp import directory<br>
+from chirp import errors<br>
+from chirp import memmap<br>
+from chirp import util<br>
+from chirp.settings import RadioSettingGroup, RadioSetting, RadioSettings, \<br>
+ RadioSettingValueList, RadioSettingValueString, RadioSettingValueBoolean, \<br>
+ RadioSettingValueInteger, RadioSettingValueString, \<br>
+ RadioSettingValueFloat, InvalidValueError<br>
+<br>
+LOG = logging.getLogger(__name__)<br>
+<br>
+#<br>
+# Chirp Driver for Retevis RT98 models: RT98V (136-174 Mhz)<br>
+# RT98U (400-490 Mhz)<br>
+#<br>
+#<br>
+#<br>
+# Global Parameters<br>
+#<br>
+TONES = [62.5] + list(chirp_common.TONES)<br>
+TMODES = ['', 'Tone', 'DTCS']<br>
+DUPLEXES = ['', '+', '-']<br>
+<br>
+TXPOWER_LOW = 0x00<br>
+TXPOWER_MED = 0x01<br>
+TXPOWER_HIGH = 0x02<br>
+<br>
+DUPLEX_NOSPLIT = 0x00<br>
+DUPLEX_POSSPLIT = 0x01<br>
+DUPLEX_NEGSPLIT = 0x02<br>
+<br>
+CHANNEL_WIDTH_12d5kHz = 0x00<br>
+CHANNEL_WIDTH_20kHz = 0x01<br>
+CHANNEL_WIDTH_25kHz = 0x02<br>
+<br>
+TUNING_STEPS = [2.5, 5.0, 6.25, 10.0, 12.5, 20.0, 25.0, 30.0, 50.0]<br>
+<br>
+POWER_LEVELS = [chirp_common.PowerLevel("Low", watts=5),<br>
+ chirp_common.PowerLevel("Mid", watts=10),<br>
+ chirp_common.PowerLevel("High", watts=15)]<br>
+<br>
+PMR_POWER_LEVELS = [chirp_common.PowerLevel("Low", watts=0.5), ]<br>
+<br>
+FREENET_POWER_LEVELS = [chirp_common.PowerLevel("Low", watts=1), ]<br>
+<br>
+PMR_FREQS = [446.00625, 446.01875, 446.03125, 446.04375,<br>
+ 446.05625, 446.06875, 446.08125, 446.09375,<br>
+ 446.10625, 446.11875, 446.13125, 446.14375,<br>
+ 446.15625, 446.16875, 446.18125, 446.19375]<br>
+<br>
+FREENET_FREQS = [149.02500, 149.03750, 149.05000,<br>
+ 149.08750, 149.10000, 149.11250]<br>
+<br>
+CROSS_MODES = ["Tone->Tone", "DTCS->", "->DTCS", "Tone->DTCS", "DTCS->Tone",<br>
+ "->Tone", "DTCS->DTCS"]<br>
+<br>
+LIST_STEP = [str(x) for x in TUNING_STEPS]<br>
+LIST_TIMEOUT = ["Off"] + ["%s min" % x for x in range(1, 31)]<br>
+LIST_APO = ["Off", "30 min", "1 hr", "2 hrs"]<br>
+LIST_SQUELCH = ["Off"] + ["Level %s" % x for x in range(1, 10)]<br>
+LIST_DISPLAY_MODE = ["Channel", "Frequency", "Name"]<br>
+LIST_AOP = ["Manual", "Auto"]<br>
+LIST_STE_TYPE = ["Off", "Silent", "120 Degree", "180 Degree", "240 Degree"]<br>
+LIST_STE_FREQ = ["Off", "55.2 Hz", "259.2 Hz"]<br>
+<br>
+LIST_PRIORITY_CH = ["Off", "Priority Channel 1", "Priority Channel 2",<br>
+ "Priority Channel 1 + Priority Channel 2"]<br>
+<br>
+LIST_REVERT_CH = ["Selected", "Selected + TalkBack", "Priority Channel 1",<br>
+ "Priority Channel 2", "Last Called", "Last Used",<br>
+ "Priority Channel 1 + TalkBack",<br>
+ "Priority Channel 2 + TalkBack"]<br>
+<br>
+LIST_TIME50 = ["0.1", "0.2", "0.3", "0.4", "0.5",<br>
+ "0.6", "0.7", "0.8", "0.9", "1.0",<br>
+ "1.1", "1.2", "1.3", "1.4", "1.5",<br>
+ "1.6", "1.7", "1.8", "1.9", "2.0",<br>
+ "2.1", "3.2", "2.3", "2.4", "2.5",<br>
+ "2.6", "2.7", "2.8", "2.9", "3.0",<br>
+ "3.1", "3.2", "3.3", "3.4", "3.5",<br>
+ "3.6", "3.7", "3.8", "3.9", "4.0",<br>
+ "4.1", "4.2", "4.3", "4.4", "4.5",<br>
+ "4.6", "4.7", "4.8", "4.9", "5.0"]<br>
+LIST_TIME46 = LIST_TIME50[4:]<br>
+<br>
+LIST_RT98V_MODES = ["FreeNet", "COM", "COMII"]<br>
+LIST_RT98U_MODES = ["PMR", "COM", "COMII"]<br>
+<br>
+LIST_RT98V_FREQS = ["Rx(149 - 149.2 MHz) Tx(149 - 149.2 MHz)",<br>
+ "Rx(136 - 174 MHz) Tx(136 - 174 MHz)",<br>
+ "Rx(147 - 174 MHz) Tx(147 - 174 MHz)"]<br>
+<br>
+LIST_RT98U_FREQS = ["Rx(446 - 446.2 MHz) Tx(446 - 446.2 MHz)",<br>
+ "Rx(400 - 470 MHz) Tx(400 - 470 MHz)",<br>
+ "Rx(450 - 470 MHz) Tx(450 - 470 MHz)"]<br>
+<br>
+SETTING_LISTS = {<br>
+ "tuning_step": LIST_STEP,<br>
+ "timeout_timer": LIST_TIMEOUT,<br>
+ "auto_power_off": LIST_APO,<br>
+ "squelch": LIST_SQUELCH,<br>
+ "display_mode": LIST_DISPLAY_MODE,<br>
+ "auto_power_on": LIST_AOP,<br>
+ "ste_type": LIST_STE_TYPE,<br>
+ "ste_frequency": LIST_STE_FREQ,<br>
+ "priority_ch": LIST_PRIORITY_CH,<br>
+ "revert_ch": LIST_REVERT_CH,<br>
+ "settings2.dropout_delay_time": LIST_TIME50,<br>
+ "settings2.dwell_time": LIST_TIME50,<br>
+ "settings2.look_back_time_a": LIST_TIME46,<br>
+ "settings2.look_back_time_b": LIST_TIME46<br>
+}<br>
+<br>
+# RT98 memory map<br>
+# section: 1 Channel Bank<br>
+# description of channel bank (199 channels , range 1-199)<br>
+# Each 32 Byte (0x20 hex) record:<br>
+# bytes:bit type description<br>
+# ---------------------------------------------------------------------------<br>
+# 4 bbcd freq[4] receive frequency in packed binary coded<br>
+# decimal<br>
+# 4 bbcd offset[4] transceive offset in packed binary coded<br>
+# decimal (note: +/- direction set by<br>
+# 'duplex' field)<br>
+# 1 u8 unknown0<br>
+# 1 u8<br>
+# :1 reverse:1 reverse flag, 0=off, 1=on (reverses<br>
+# transmit and receive freqencies)<br>
+# :1 txoff:1 transmitt off flag, 0=transmit, 1=do not<br>
+# transmit<br>
+# :2 power:2 transmit power setting, value range 0-2,<br>
+# 0=low, 1=middle, 2=high<br>
+# :2 duplex:2 duplex settings, 0=simplex, 1=plus (+)<br>
+# offset, 2=minus(-) offset (see offset field)<br>
+# :2 channel_width:2 channel spacing, 0=12.5kHz, 1=20kHz, 2=25kHz<br>
+# 1 u8<br>
+# :2 unknown1:2<br>
+# :1 talkaround:1 talkaround flag, 0=off, 1=on<br>
+# (bypasses repeater)<br>
+# :1 squelch_mode:1 squelch mode flag, 0=carrier, 1=ctcss/dcs<br>
+# :1 rxdcsextra:1 use with rxcode for index of rx DCS to use<br>
+# :1 rxinv:1 inverse DCS rx polarity flag, 0=N, 1=I<br>
+# :1 txdcsextra:1 use with txcode for index of tx DCS to use<br>
+# :1 txinv:1 inverse DCS tx polarity flag, 0=N, 1=I<br>
+# 1 u8<br>
+# :4 unknown2:4<br>
+# :2 rxtmode:2 rx tone mode, value range 0-2, 0=none,<br>
+# 1=CTCSS, 2=DCS (ctcss tone in field rxtone)<br>
+# :2 txtmode:2 tx tone mode, value range 0-2, 0=none,<br>
+# 1=CTCSS, 3=DCS (ctcss tone in field txtone)<br>
+# 1 u8<br>
+# :2 unknown3:2<br>
+# :6 txtone:6 tx ctcss tone, menu index<br>
+# 1 u8<br>
+# :2 unknown4:2<br>
+# :6 rxtone:6 rx ctcss tone, menu index<br>
+# 1 u8 txcode ?, not used for ctcss<br>
+# 1 u8 rxcode ?, not used for ctcss<br>
+# 1 u8<br>
+# :6 unknown5:6<br>
+# :1 busychannellockout:1 busy channel lockout flag, 0=off, 1=enabled<br>
+# :1 unknown6:1<br>
+# 6 char name[6] 6 byte char string for channel name<br>
+# 9 u8 unknown7[9]<br>
+#<br>
+MEM_FORMAT = """<br>
+#seekto 0x0000;<br>
+struct {<br>
+ bbcd freq[4];<br>
+ bbcd offset[4];<br>
+ u8 unknown0;<br>
+ u8 reverse:1,<br>
+ tx_off:1,<br>
+ txpower:2,<br>
+ duplex:2,<br>
+ channel_width:2;<br>
+ u8 unknown1:2,<br>
+ talkaround:1,<br>
+ squelch_mode:1,<br>
+ rxdcsextra:1,<br>
+ rxinv:1,<br>
+ txdcsextra:1,<br>
+ txinv:1;<br>
+ u8 unknown2:4,<br>
+ rxtmode:2,<br>
+ txtmode:2;<br>
+ u8 unknown3:2,<br>
+ txtone:6;<br>
+ u8 unknown4:2,<br>
+ rxtone:6;<br>
+ u8 txcode;<br>
+ u8 rxcode;<br>
+ u8 unknown5:6,<br>
+ busychannellockout:1,<br>
+ unknown6:1;<br>
+ char name[6];<br>
+ u8 unknown7[9];<br>
+} memory[199];<br>
+"""<br>
+<br>
+# RT98 memory map<br>
+# section: 2 and 3 Channel Set/Skip Flags<br>
+#<br>
+# Channel Set (starts 0x3240) : Channel Set bit is value 0 if a memory<br>
+# location in the channel bank is active.<br>
+# Channel Skip (starts 0x3260): Channel Skip bit is value 0 if a memory<br>
+# location in the channel bank is active.<br>
+#<br>
+# Both flag maps are a total 24 bytes in length, aligned on 32 byte records.<br>
+# bit = 0 channel not set/skip, 1 is channel set/no skip<br>
+#<br>
+# to index a channel:<br>
+# cbyte = channel / 8 ;<br>
+# cbit = channel % 8 ;<br>
+# setflag = csetflag[cbyte].c[cbit] ;<br>
+# skipflag = cskipflag[cbyte].c[cbit] ;<br>
+#<br>
+# channel range is 1-199, range is 32 bytes (last 7 unknown)<br>
+#<br>
+MEM_FORMAT = MEM_FORMAT + """<br>
+#seekto 0x3240;<br>
+struct {<br>
+ bit c[8];<br>
+} csetflag[32];<br>
+<br>
+#seekto 0x3260;<br>
+struct {<br>
+ bit c[8];<br>
+} cskipflag[32];<br>
+<br>
+"""<br>
+<br>
+# RT98 memory map<br>
+# section: 4 Startup Label<br>
+#<br>
+# bytes:bit type description<br>
+# ---------------------------------------------------------------------------<br>
+# 6 char start_label[6] label displayed at startup (usually<br>
+# your call sign)<br>
+#<br>
+MEM_FORMAT = MEM_FORMAT + """<br>
+#seekto 0x3300;<br>
+struct {<br>
+ char startname[6];<br>
+} slabel;<br>
+"""<br>
+<br>
+# RT98 memory map<br>
+# section: 5, 6 and 7 Radio Options<br>
+# used to set a number of radio options<br>
+#<br>
+# description of function setup options, starting at 0x3310 (settings3)<br>
+#<br>
+# bytes:bit type description<br>
+# ---------------------------------------------------------------------------<br>
+# 1 u8<br>
+# :6 unknown:6<br>
+# :2 bandlimit_3310:2 frequency ranges, range 0-2,<br>
+# 0=freenet(vhf) or pmr(uhf), 1=com, 2=comii<br>
+# rt98v - 00 FreeNet Rx(149 - 149.2 MHz) Tx(149 - 149.2 MHz)<br>
+# 01 COM Rx(136 - 174 MHz) Tx(136 - 174 MHz)<br>
+# 02 COMII Rx(147 - 174 MHz) Tx(147 - 174 MHz)<br>
+# rt98u - 00 PMR Rx(446 - 446.2 MHz) Tx(446 - 446.2 MHz)<br>
+# 01 COM Rx(400 - 470 MHz) Tx(400 - 470 MHz)<br>
+# 02 COMII Rx(450 - 470 MHz) Tx(450 - 470 MHz)<br>
+# 1 u8 ch_number; channel number, range 1-199<br>
+#<br>
+# description of function setup options, starting at 0x3340 (settings)<br>
+#<br>
+# bytes:bit type description<br>
+# ---------------------------------------------------------------------------<br>
+# 1 u8<br>
+# :4 unknown_3340:4<br>
+# :4 tuning_step:4 tuning step, menu index value from 0-8<br>
+# 2.5, 5, 6.25, 10, 12.5, 20, 25, 30, 50<br>
+# 1 u8<br>
+# :7 unknown_3341:7<br>
+# :1 beep:1 beep mode, range 0-1, 0=off, 1=on<br>
+# 1 u8<br>
+# :3 unknown_3342:3<br>
+# :5 timeout_timer:5 timeout timer, range off (no timeout),<br>
+# 1-30 minutes<br>
+# 1 u8<br>
+# :6 unknown_3343:6<br>
+# :2 auto_power_off:2 auto power off, range 0-3, off, 30min,<br>
+# 1hr, 2hr<br>
+# 1 u8<br>
+# :4 unknown_3344:4<br>
+# :4 squelch:4 squelch level, range off, 1-9<br>
+# 1 u8<br>
+# :3 unknown_3345:3<br>
+# :5 volume:5 volume level, range 1-30 (no zero)<br>
+# 1 u8 unknown_3346<br>
+# 1 u8 unknown_3347<br>
+# 1 u8 0x3348 [12]<br>
+# :6 unknown_3348:6<br>
+# :2 display_mode display mode, range 0-2, 0=channel,<br>
+# 1=frequency, 2=name<br>
+# 1 u8<br>
+# :7 unknown_3349:7<br>
+# :1 auto_power_on:1 auto power on, range 0-1, 0=manual,<br>
+# 1=auto<br>
+# 1 u8<br>
+# :3 unknown_334A:3<br>
+# :5 mic_gain:5 mic gain, range 1-30 (no zero)<br>
+# 1 u8<br>
+# :5 unknown_334C:5<br>
+# :3 ste_type:3 ste type, range 0-4, 0=off, 1=silent,<br>
+# 2=120degree, 3=180degree, 4=240degree<br>
+# 1 u8<br>
+# :7 unknown_334D:7<br>
+# :1 ste_frequency:1 ste frequency, range 0-2, 0=off,<br>
+# 1=55.2Hz, 2=259.2Hz<br>
+# 1 u8<br>
+# :2 unknown_0x334E:2<br>
+# :1 forbid_setting:1 forbid setting(optional function),<br>
+# range 0-1, 0=disabled, 1=enabled<br>
+# :1 forbid_initialize:1 forbid initialize operate, range 0-1,<br>
+# 0=enabled, 1=disabled (inverted)<br>
+# :1 save_chan_param:1 save channel parameters, range 0-1,<br>
+# 0=disabled, 1=enabled<br>
+# :1 forbid_chan_menu:1 forbid channel menu, range 0-1,<br>
+# 0=disabled, 1=enabled<br>
+# :1 sql_key_function:1 sql key function, range 0-1,<br>
+# 0=squelch off momentary, 1=squelch off<br>
+# :1 unknown:1<br>
+#<br>
+# description of function setup options, starting at 0x3380 (settings2)<br>
+#<br>
+# bytes:bit type description<br>
+# ---------------------------------------------------------------------------<br>
+# 1 u8<br>
+# :7 unknown_3380:7<br>
+# :1 scan_mode:1 scan mode, range 0-1, 0=off, 1=on<br>
+# 1 u8<br>
+# :6 unknown_3381:6<br>
+# :2 priority_ch:2 priority channel, range 0-3, 0=off,<br>
+# 1=priority channel 1,<br>
+# 2=priority channel 2,<br>
+# 3=priority channel 1 + priority channel 2<br>
+# 1 u8 priority_ch1 priority channel 1 number, range 1-199<br>
+# 1 u8 priority_ch2 priority channel 2 number, range 1-199<br>
+# 1 u8<br>
+# :4 unknown_3384:4<br>
+# :4 revert_ch:4 revert channel, range 0-3, 0=selected,<br>
+# 1=selected + talkback, 2=last called,<br>
+# 3=last used<br>
+# 1 u8 look_back_time_a look back time a, range 0-45<br>
+# 1 u8 look_back_time_b look back time b, range 0-45<br>
+# 1 u8 dropout_delay_time dropout delay time, range 0-49<br>
+# 1 u8 dwell_time dwell time, range 0-49<br>
+#<br>
+MEM_FORMAT = MEM_FORMAT + """<br>
+#seekto 0x3310;<br>
+struct {<br>
+ u8 bandlimit;<br>
+ u8 ch_number;<br>
+} settings3;<br>
+"""<br>
+<br>
+MEM_FORMAT = MEM_FORMAT + """<br>
+#seekto 0x3340;<br>
+struct {<br>
+ u8 unknown_3340:4,<br>
+ tuning_step:4;<br>
+ u8 unknown_3341:7,<br>
+ beep:1;<br>
+ u8 unknown_3342:3,<br>
+ timeout_timer:5;<br>
+ u8 unknown_3343:6,<br>
+ auto_power_off:2;<br>
+ u8 unknown_3344:4,<br>
+ squelch:4;<br>
+ u8 unknown_3345:3,<br>
+ volume:5;<br>
+ u8 unknown_3346;<br>
+ u8 unknown_3347;<br>
+ u8 unknown_3348:6,<br>
+ display_mode:2;<br>
+ u8 unknown_3349:7,<br>
+ auto_power_on:1;<br>
+ u8 unknown_334A:3,<br>
+ mic_gain:5;<br>
+ u8 unknown_334B;<br>
+ u8 unknown_334C:5,<br>
+ ste_type:3;<br>
+ u8 unknown_334D:6,<br>
+ ste_frequency:2;<br>
+ u8 unknown_334E:1,<br>
+ forbid_setting:1,<br>
+ unknown1:1,<br>
+ forbid_initialize:1,<br>
+ save_chan_param:1,<br>
+ forbid_chan_menu:1,<br>
+ sql_key_function:1,<br>
+ unknown2:1;<br>
+} settings;<br>
+"""<br>
+<br>
+MEM_FORMAT = MEM_FORMAT + """<br>
+#seekto 0x3380;<br>
+struct {<br>
+ u8 unknown_3380:7,<br>
+ scan_mode:1;<br>
+ u8 unknown_3381:6,<br>
+ priority_ch:2;<br>
+ u8 priority_ch1;<br>
+ u8 priority_ch2;<br>
+ u8 unknown_3384:4,<br>
+ revert_ch:4;<br>
+ u8 look_back_time_a;<br>
+ u8 look_back_time_b;<br>
+ u8 dropout_delay_time;<br>
+ u8 dwell_time;<br>
+} settings2;<br>
+"""<br>
+<br>
+# RT98 memory map<br>
+# section: 8 Embedded Messages<br>
+#<br>
+# bytes:bit type description<br>
+# ---------------------------------------------------------------------------<br>
+# 6 char radio_type[5] radio type, vhf=rt98v, uhf=rt98u<br>
+# 2 u8 unknown1[2]<br>
+# 4 char mcu_version[4] mcu version, [x.xx]<br>
+# 2 u8 unknown2[2]<br>
+# 1 u8 mode rt98u mode: 0=pmr, 1=com, 2=comii<br>
+# rt98v mode: 0=freenet, 1=com, 2=comii<br>
+# 1 u8 unknown3<br>
+# 10 u8 unused1[10]<br>
+# 4 u8 unknown4[4]<br>
+# 3 u8 unused2[3]<br>
+# 16 u8 unknown5[16]<br>
+# 10 char date_mfg[16] date manufactured, [yyyy-mm-dd]<br>
+#<br>
+MEM_FORMAT = MEM_FORMAT + """<br>
+#seekto 0x3D00;<br>
+struct {<br>
+char radio_type[5];<br>
+u8 unknown1[2];<br>
+char mcu_version[4];<br>
+u8 unknown2[2];<br>
+u8 mode;<br>
+u8 unknown3;<br>
+u8 unused1[10];<br>
+u8 unknown4[4];<br>
+u8 unused2[3];<br>
+u8 unknown5[16];<br>
+char date_mfg[10];<br>
+} embedded_msg;<br>
+"""<br>
+<br>
+<br>
+# Format for the version messages returned by the radio<br>
+VER_FORMAT = '''<br>
+u8 hdr;<br>
+char model[5];<br>
+u8 unknown[2];<br>
+u8 bandlimit;<br>
+char version[6];<br>
+u8 ack;<br>
+'''<br>
+<br>
+<br>
+# Radio supports upper case and symbols<br>
+CHARSET_ASCII_PLUS = chirp_common.CHARSET_UPPER_NUMERIC + '- '<br>
+<br>
+# Band limits as defined by the band byte in ver_response, defined in Hz, for<br>
+# VHF and UHF, used for RX and TX.<br>
+RT98V_BAND_LIMITS = {0x00: [(149000000, 149200000)],<br>
+ 0x01: [(136000000, 174000000)],<br>
+ 0x02: [(147000000, 174000000)]}<br>
+<br>
+RT98U_BAND_LIMITS = {0x00: [(446000000, 446200000)],<br>
+ 0x01: [(400000000, 470000000)],<br>
+ 0x02: [(450000000, 470000000)]}<br>
+<br>
+<br>
+# Get band limits from a band limit value<br>
+def get_band_limits_Hz(radio_type, limit_value):<br>
+ if radio_type == "RT98U":<br>
+ if limit_value not in RT98U_BAND_LIMITS:<br>
+ limit_value = 0x01<br>
+ LOG.warning('Unknown band limit value 0x%02x, default to 0x01')<br>
+ bandlimitfrequencies = RT98U_BAND_LIMITS[limit_value]<br>
+ elif radio_type == "RT98V":<br>
+ if limit_value not in RT98V_BAND_LIMITS:<br>
+ limit_value = 0x01<br>
+ LOG.warning('Unknown band limit value 0x%02x, default to 0x01')<br>
+ bandlimitfrequencies = RT98V_BAND_LIMITS[limit_value]<br>
+ return bandlimitfrequencies<br>
+<br>
+<br>
+def _echo_write(radio, data):<br>
+ try:<br>
+ radio.pipe.write(data)<br>
+ radio.pipe.read(len(data))<br>
+ except Exception, e:<br>
+ LOG.error("Error writing to radio: %s" % e)<br>
+ raise errors.RadioError("Unable to write to radio")<br>
+<br>
+<br>
+def _checksum(data):<br>
+ cs = 0<br>
+ for byte in data:<br>
+ cs += ord(byte)<br>
+ return cs % 256<br>
+<br>
+<br>
+def _read(radio, length):<br>
+ try:<br>
+ data = radio.pipe.read(length)<br>
+ except Exception, e:<br>
+ _finish(radio)<br>
+ LOG.error("Error reading from radio: %s" % e)<br>
+ raise errors.RadioError("Unable to read from radio")<br>
+<br>
+ if len(data) != length:<br>
+ _finish(radio)<br>
+ LOG.error("Short read from radio (%i, expected %i)" %<br>
+ (len(data), length))<br>
+ LOG.debug(util.hexprint(data))<br>
+ raise errors.RadioError("Short read from radio")<br>
+ return data<br>
+<br>
+<br>
+# strip trailing 0x00 to convert a string returned by bitwise.parse into a<br>
+# python string<br>
+def cstring_to_py_string(cstring):<br>
+ return "".join(c for c in cstring if c != '\x00')<br>
+<br>
+<br>
+# Check the radio version reported to see if it's one we support,<br>
+# returns bool version supported, and the band index<br>
+def check_ver(ver_response, allowed_types):<br>
+ ''' Check the returned radio version is one we approve of '''<br>
+<br>
+ LOG.debug('ver_response = ')<br>
+ LOG.debug(util.hexprint(ver_response))<br>
+<br>
+ resp = bitwise.parse(VER_FORMAT, ver_response)<br>
+ verok = False<br>
+<br>
+ if resp.hdr == 0x49 and resp.ack == 0x06:<br>
+ model, version = [cstring_to_py_string(bitwise.get_string(s)).strip()<br>
+ for s in (resp.model, resp.version)]<br>
+ LOG.debug('radio model: \'%s\' version: \'%s\'' %<br>
+ (model, version))<br>
+ LOG.debug('allowed_types = %s' % allowed_types)<br>
+<br>
+ if model in allowed_types:<br>
+ LOG.debug('model in allowed_types')<br>
+<br>
+ if version in allowed_types[model]:<br>
+ LOG.debug('version in allowed_types[model]')<br>
+ verok = True<br>
+ else:<br>
+ _finish(radio)<br>
+ raise errors.RadioError('Failed to parse version response')<br>
+<br>
+ return verok, str(resp.model), int(resp.bandlimit)<br>
+<br>
+<br>
+def _ident(radio):<br>
+ radio.pipe.timeout = 1<br>
+ _echo_write(radio, "PROGRAM")<br>
+ response = radio.pipe.read(3)<br>
+ if response != "QX\06":<br>
+ _finish(radio)<br>
+ LOG.debug("Response was :\n%s" % util.hexprint(response))<br>
+ raise errors.RadioError("Radio did not respond. Check connection.")<br>
+ _echo_write(radio, "\x02")<br>
+ ver_response = radio.pipe.read(16)<br>
+ LOG.debug(util.hexprint(ver_response))<br>
+<br>
+ verok, model, bandlimit = check_ver(ver_response,<br>
+ radio.ALLOWED_RADIO_TYPES)<br>
+ if not verok:<br>
+ _finish(radio)<br>
+ raise errors.RadioError(<br>
+ 'Radio version not in allowed list for %s-%s: %s' %<br>
+ (radio.VENDOR, radio.MODEL, util.hexprint(ver_response)))<br>
+<br>
+ return model, bandlimit<br>
+<br>
+<br>
+def _send(radio, cmd, addr, length, data=None):<br>
+ frame = struct.pack(">cHb", cmd, addr, length)<br>
+ if data:<br>
+ frame += data<br>
+ frame += chr(_checksum(frame[1:]))<br>
+ frame += "\x06"<br>
+ _echo_write(radio, frame)<br>
+ LOG.debug("Sent:\n%s" % util.hexprint(frame))<br>
+ if data:<br>
+ result = radio.pipe.read(1)<br>
+ if result != "\x06":<br>
+ _finish(radio)<br>
+ LOG.debug("Ack was: %s" % repr(result))<br>
+ raise errors.RadioError("Radio did not accept block at %04x"<br>
+ % addr)<br>
+ return<br>
+ result = _read(radio, length + 6)<br>
+ LOG.debug("Got:\n%s" % util.hexprint(result))<br>
+ header = result[0:4]<br>
+ data = result[4:-2]<br>
+ ack = result[-1]<br>
+ if ack != "\x06":<br>
+ _finish(radio)<br>
+ LOG.debug("Ack was: %s" % repr(ack))<br>
+ raise errors.RadioError("Radio NAK'd block at %04x" % addr)<br>
+ _cmd, _addr, _length = struct.unpack(">cHb", header)<br>
+ if _addr != addr or _length != _length:<br>
+ _finish(radio)<br>
+ LOG.debug("Expected/Received:")<br>
+ LOG.debug(" Length: %02x/%02x" % (length, _length))<br>
+ LOG.debug(" Addr: %04x/%04x" % (addr, _addr))<br>
+ raise errors.RadioError("Radio send unexpected block")<br>
+ cs = _checksum(result[1:-2])<br>
+ if cs != ord(result[-2]):<br>
+ _finish(radio)<br>
+ LOG.debug("Calculated: %02x" % cs)<br>
+ LOG.debug("Actual: %02x" % ord(result[-2]))<br>
+ raise errors.RadioError("Block at 0x%04x failed checksum" % addr)<br>
+ return data<br>
+<br>
+<br>
+def _finish(radio):<br>
+ endframe = "\x45\x4E\x44"<br>
+ _echo_write(radio, endframe)<br>
+ result = radio.pipe.read(1)<br>
+ if result != "\x06":<br>
+ LOG.error("Got:\n%s" % util.hexprint(result))<br>
+ raise errors.RadioError("Radio did not finish cleanly")<br>
+<br>
+<br>
+def do_download(radio):<br>
+<br>
+ _ident(radio)<br>
+<br>
+ _memobj = None<br>
+ data = ""<br>
+<br>
+ for addr in range(0, radio._memsize, 0x10):<br>
+ block = _send(radio, 'R', addr, 0x10)<br>
+ data += block<br>
+ status = chirp_common.Status()<br>
+ status.cur = len(data)<br>
+ status.max = radio._memsize<br>
+ status.msg = "Downloading from radio"<br>
+ radio.status_fn(status)<br>
+<br>
+ _finish(radio)<br>
+<br>
+ return memmap.MemoryMap(data)<br>
+<br>
+<br>
+def do_upload(radio):<br>
+ model, bandlimit = _ident(radio)<br>
+ _embedded = radio._memobj.embedded_msg<br>
+<br>
+ if model != str(_embedded.radio_type):<br>
+ LOG.warning('radio and image model types differ')<br>
+ LOG.warning('model type (radio): %s' % str(model))<br>
+ LOG.warning('model type (image): %s' % str(_embedded.radio_type))<br>
+<br>
+ _finish(radio)<br>
+<br>
+ msg = ("The upload was stopped because the radio type "<br>
+ "of the image (%s) does not match that "<br>
+ "of the radio (%s).")<br>
+ raise errors.RadioError(msg % (str(_embedded.radio_type), str(model)))<br>
+<br>
+ if bandlimit != int(_embedded.mode):<br>
+ if str(_embedded.radio_type) == "RT98U":<br>
+ image_band_limits = LIST_RT98U_FREQS[int(_embedded.mode)]<br>
+ if str(_embedded.radio_type) == "RT98V":<br>
+ image_band_limits = LIST_RT98V_FREQS[int(_embedded.mode)]<br>
+ if model == "RT98U":<br>
+ radio_band_limits = LIST_RT98U_FREQS[int(bandlimit)]<br>
+ if model == "RT98V":<br>
+ radio_band_limits = LIST_RT98V_FREQS[int(bandlimit)]<br>
+<br>
+ LOG.warning('radio and image band limits differ')<br>
+ LOG.warning('image band limits: %s' % image_band_limits)<br>
+ LOG.warning('radio band limits: %s' % radio_band_limits)<br>
+<br>
+ _finish(radio)<br>
+<br>
+ msg = ("The upload was stopped because the band limits "<br>
+ "of the image (%s) does not match that "<br>
+ "of the radio (%s).")<br>
+ raise errors.RadioError(msg % (image_band_limits, radio_band_limits))<br>
+<br>
+ try:<br>
+ for start, end in radio._ranges:<br>
+ for addr in range(start, end, 0x10):<br>
+ block = radio._mmap[addr:addr+0x10]<br>
+ _send(radio, 'W', addr, len(block), block)<br>
+ status = chirp_common.Status()<br>
+ status.cur = addr<br>
+ status.max = end<br>
+ status.msg = "Uploading to Radio"<br>
+ radio.status_fn(status)<br>
+ _finish(radio)<br>
+ except errors.RadioError:<br>
+ raise<br>
+ except Exception as e:<br>
+ _finish(radio)<br>
+ raise errors.RadioError('Failed to upload to radio: %s' % e)<br>
+<br>
+<br>
+#<br>
+# The base class, extended for use with other models<br>
+#<br>
+class Rt98BaseRadio(chirp_common.CloneModeRadio,<br>
+ chirp_common.ExperimentalRadio):<br>
+ """Retevis RT98 Base"""<br>
+ VENDOR = "Retevis"<br>
+ MODEL = "RT98 Base"<br>
+ BAUD_RATE = 9600<br>
+<br>
+ _memsize = 0x3E00<br>
+ _ranges = [(0x0000, 0x3310),<br>
+ (0x3320, 0x3390)]<br>
+<br>
+ @classmethod<br>
+ def get_prompts(cls):<br>
+ rp = chirp_common.RadioPrompts()<br>
+ rp.experimental = ("The Retevis RT98 driver is an beta version."<br>
+ "Proceed with Caution and backup your data")<br>
+ return rp<br>
+<br>
+ def get_features(self):<br>
+ _embedded = self._memobj.embedded_msg<br>
+ rf = chirp_common.RadioFeatures()<br>
+ rf.has_settings = True<br>
+ rf.has_bank = False<br>
+ rf.can_odd_split = True<br>
+ rf.has_name = True<br>
+ if _embedded.mode == 0: # PMR or FreeNet<br>
+ rf.has_offset = False<br>
+ else:<br>
+ rf.has_offset = True<br>
+ rf.has_ctone = True<br>
+ rf.has_cross = True<br>
+ rf.has_tuning_step = False<br>
+ rf.has_dtcs = True<br>
+ rf.has_rx_dtcs = True<br>
+ rf.has_dtcs_polarity = True<br>
+ rf.valid_skips = ["", "S"]<br>
+ rf.memory_bounds = (1, 199)<br>
+ rf.valid_name_length = 6<br>
+ if _embedded.mode == 0: # PMR or FreeNet<br>
+ rf.valid_duplexes = ['']<br>
+ else:<br>
+ rf.valid_duplexes = DUPLEXES + ['split', 'off']<br>
+ rf.valid_characters = chirp_common.CHARSET_UPPER_NUMERIC + "- "<br>
+ if _embedded.mode == 0: # PMR or FreeNet<br>
+ rf.valid_modes = ['NFM']<br>
+ else:<br>
+ rf.valid_modes = ['FM', 'NFM']<br>
+ rf.valid_tmodes = ['', 'Tone', 'TSQL', 'DTCS', 'Cross']<br>
+ rf.valid_cross_modes = CROSS_MODES<br>
+ if _embedded.mode == 0: # PMR or FreeNet<br>
+ if str(_embedded.radio_type) == "RT98U":<br>
+ rf.valid_power_levels = PMR_POWER_LEVELS<br>
+ if str(_embedded.radio_type) == "RT98V":<br>
+ rf.valid_power_levels = FREENET_POWER_LEVELS<br>
+ else:<br>
+ rf.valid_power_levels = POWER_LEVELS<br>
+ rf.valid_dtcs_codes = chirp_common.ALL_DTCS_CODES<br>
+<br>
+ try:<br>
+ rf.valid_bands = get_band_limits_Hz(<br>
+ str(_embedded.radio_type),<br>
+ int(_embedded.mode))<br>
+ except TypeError as e:<br>
+ # If we're asked without memory loaded, assume the most permissive<br>
+ rf.valid_bands = get_band_limits_Hz(str(_embedded.radio_type), 1)<br>
+ except Exception as e:<br>
+ LOG.error('Failed to get band limits for RT98: %s' % e)<br>
+ rf.valid_bands = get_band_limits_Hz(str(_embedded.radio_type), 1)<br>
+<br>
+ rf.valid_tuning_steps = TUNING_STEPS<br>
+ return rf<br>
+<br>
+ def validate_memory(self, mem):<br>
+ _embedded = self._memobj.embedded_msg<br>
+ msgs = ""<br>
+ msgs = chirp_common.CloneModeRadio.validate_memory(self, mem)<br>
+<br>
+ # FreeNet and PMR radio types<br>
+ if _embedded.mode == 0: # PMR or FreeNet<br>
+ freq = float(mem.freq) / 1000000<br>
+<br>
+ # FreeNet<br>
+ if str(_embedded.radio_type) == "RT98V":<br>
+ if freq not in FREENET_FREQS:<br>
+ _msg_freq = 'Memory location not a valid FreeNet frequency'<br>
+ # warn user invalid frequency<br>
+ msgs.append(chirp_common.ValidationError(_msg_freq))<br>
+<br>
+ # PMR<br>
+ if str(_embedded.radio_type) == "RT98U":<br>
+ if freq not in PMR_FREQS:<br>
+ _msg_freq = 'Memory location not a valid PMR frequency'<br>
+ # warn user invalid frequency<br>
+ msgs.append(chirp_common.ValidationError(_msg_freq))<br>
+<br>
+ return msgs<br>
+<br>
+ # Do a download of the radio from the serial port<br>
+ def sync_in(self):<br>
+ self._mmap = do_download(self)<br>
+ self.process_mmap()<br>
+<br>
+ # Do an upload of the radio to the serial port<br>
+ def sync_out(self):<br>
+ do_upload(self)<br>
+<br>
+ def process_mmap(self):<br>
+ self._memobj = bitwise.parse(MEM_FORMAT, self._mmap)<br>
+<br>
+ # Return a raw representation of the memory object, which<br>
+ # is very helpful for development<br>
+ def get_raw_memory(self, number):<br>
+ return repr(self._memobj.memory[number - 1])<br>
+<br>
+ def _get_dcs_index(self, _mem, which):<br>
+ base = getattr(_mem, '%scode' % which)<br>
+ extra = getattr(_mem, '%sdcsextra' % which)<br>
+ return (int(extra) << 8) | int(base)<br>
+<br>
+ def _set_dcs_index(self, _mem, which, index):<br>
+ base = getattr(_mem, '%scode' % which)<br>
+ extra = getattr(_mem, '%sdcsextra' % which)<br>
+ base.set_value(index & 0xFF)<br>
+ extra.set_value(index >> 8)<br>
+<br>
+ # Extract a high-level memory object from the low-level memory map<br>
+ # This is called to populate a memory in the UI<br>
+ def get_memory(self, number):<br>
+ _embedded = self._memobj.embedded_msg<br>
+ # Get a low-level memory object mapped to the image<br>
+ _mem = self._memobj.memory[number - 1]<br>
+<br>
+ # get flag info<br>
+ cbyte = (number - 1) / 8<br>
+ cbit = 7 - ((number - 1) % 8)<br>
+ setflag = self._memobj.csetflag[cbyte].c[cbit]<br>
+ skipflag = self._memobj.cskipflag[cbyte].c[cbit]<br>
+<br>
+ mem = chirp_common.Memory()<br>
+<br>
+ mem.number = number # Set the memory number<br>
+<br>
+ # We'll consider any blank (i.e. 0MHz frequency) to be empty<br>
+ if _mem.freq == 0:<br>
+ mem.empty = True<br>
+ return mem<br>
+<br>
+ if setflag == 0:<br>
+ mem.empty = True<br>
+ return mem<br>
+<br>
+ if _mem.get_raw()[0] == "\xFF":<br>
+ mem.empty = True<br>
+ return mem<br>
+<br>
+ # set the name<br>
+ <a href="http://mem.name" rel="noreferrer" target="_blank">mem.name</a> = str(_<a href="http://mem.name" rel="noreferrer" target="_blank">mem.name</a>).rstrip() # Set the alpha tag<br>
+<br>
+ # Convert your low-level frequency and offset to Hertz<br>
+ mem.freq = int(_mem.freq) * 10<br>
+ mem.offset = int(_mem.offset) * 10<br>
+<br>
+ # Set the duplex flags<br>
+ if _mem.duplex == DUPLEX_POSSPLIT:<br>
+ mem.duplex = '+'<br>
+ elif _mem.duplex == DUPLEX_NEGSPLIT:<br>
+ mem.duplex = '-'<br>
+ elif _mem.duplex == DUPLEX_NOSPLIT:<br>
+ mem.duplex = ''<br>
+ elif _mem.duplex == DUPLEX_ODDSPLIT:<br>
+ mem.duplex = 'split'<br>
+ else:<br>
+ LOG.error('%s: get_mem: unhandled duplex: %02x' %<br>
+ (<a href="http://mem.name" rel="noreferrer" target="_blank">mem.name</a>, _mem.duplex))<br>
+<br>
+ # handle tx off<br>
+ if _mem.tx_off:<br>
+ mem.duplex = 'off'<br>
+<br>
+ # Set the channel width<br>
+ if _mem.channel_width == CHANNEL_WIDTH_12d5kHz:<br>
+ mem.mode = 'NFM'<br>
+ elif _embedded.mode == 0: # PMR or FreeNet<br>
+ LOG.info('PMR and FreeNet channels must be Channel Width 12.5kHz')<br>
+ mem.mode = 'NFM'<br>
+ elif _mem.channel_width == CHANNEL_WIDTH_25kHz:<br>
+ mem.mode = 'FM'<br>
+ elif _mem.channel_width == CHANNEL_WIDTH_20kHz:<br>
+ LOG.info(<br>
+ '%s: get_mem: promoting 20kHz channel width to 25kHz' %<br>
+ <a href="http://mem.name" rel="noreferrer" target="_blank">mem.name</a>)<br>
+ mem.mode = 'FM'<br>
+ else:<br>
+ LOG.error('%s: get_mem: unhandled channel width: 0x%02x' %<br>
+ (<a href="http://mem.name" rel="noreferrer" target="_blank">mem.name</a>, _mem.channel_width))<br>
+<br>
+ # set the power level<br>
+ if _embedded.mode == 0: # PMR or FreeNet<br>
+ if str(_embedded.radio_type) == "RT98U":<br>
+ LOG.info('using PMR power levels')<br>
+ _levels = PMR_POWER_LEVELS<br>
+ if str(_embedded.radio_type) == "RT98V":<br>
+ LOG.info('using FreeNet power levels')<br>
+ _levels = FREENET_POWER_LEVELS<br>
+ else: # COM or COMII<br>
+ LOG.info('using general power levels')<br>
+ _levels = POWER_LEVELS<br>
+<br>
+ if _mem.txpower == TXPOWER_LOW:<br>
+ mem.power = _levels[0]<br>
+ elif _embedded.mode == 0: # PMR or FreeNet<br>
+ LOG.info('FreeNet or PMR channel is not set to TX Power Low')<br>
+ LOG.info('Setting channel to TX Power Low')<br>
+ mem.power = _levels[0]<br>
+ elif _mem.txpower == TXPOWER_MED:<br>
+ mem.power = _levels[1]<br>
+ elif _mem.txpower == TXPOWER_HIGH:<br>
+ mem.power = _levels[2]<br>
+ else:<br>
+ LOG.error('%s: get_mem: unhandled power level: 0x%02x' %<br>
+ (<a href="http://mem.name" rel="noreferrer" target="_blank">mem.name</a>, _mem.txpower))<br>
+<br>
+ # CTCSS Tones and DTCS Codes<br>
+ rxtone = txtone = None<br>
+<br>
+ rxmode = TMODES[_mem.rxtmode]<br>
+ txmode = TMODES[_mem.txtmode]<br>
+<br>
+ if rxmode == "Tone":<br>
+ rxtone = TONES[_mem.rxtone]<br>
+ elif rxmode == "DTCS":<br>
+ rxtone = chirp_common.ALL_DTCS_CODES[self._get_dcs_index(<br>
+ _mem, 'rx')]<br>
+<br>
+ if txmode == "Tone":<br>
+ txtone = TONES[_mem.txtone]<br>
+ elif txmode == "DTCS":<br>
+ txtone = chirp_common.ALL_DTCS_CODES[self._get_dcs_index(<br>
+ _mem, 'tx')]<br>
+<br>
+ rxpol = _mem.rxinv and "R" or "N"<br>
+ txpol = _mem.txinv and "R" or "N"<br>
+<br>
+ chirp_common.split_tone_decode(mem,<br>
+ (txmode, txtone, txpol),<br>
+ (rxmode, rxtone, rxpol))<br>
+<br>
+ # Check if this memory is in the scan enabled list<br>
+ mem.skip = "S" if skipflag == 0 else ""<br>
+<br>
+ # Extra<br>
+ mem.extra = RadioSettingGroup("extra", "Extra")<br>
+<br>
+ rs = RadioSettingValueBoolean(bool(_mem.busychannellockout))<br>
+ rset = RadioSetting("busychannellockout", "Busy channel lockout", rs)<br>
+ mem.extra.append(rset)<br>
+<br>
+ rs = RadioSettingValueBoolean(bool(_mem.reverse))<br>
+ rset = RadioSetting("reverse", "Reverse", rs)<br>
+ mem.extra.append(rset)<br>
+<br>
+ rs = RadioSettingValueBoolean(bool(_mem.talkaround))<br>
+ rset = RadioSetting("talkaround", "Talk around", rs)<br>
+ mem.extra.append(rset)<br>
+<br>
+ rs = RadioSettingValueBoolean(bool(_mem.squelch_mode))<br>
+ rset = RadioSetting("squelch_mode", "Squelch mode", rs)<br>
+ mem.extra.append(rset)<br>
+<br>
+ return mem<br>
+<br>
+ # Store details about a high-level memory to the memory map<br>
+ # This is called when a user edits a memory in the UI<br>
+ def set_memory(self, mem):<br>
+ _embedded = self._memobj.embedded_msg<br>
+ # Get a low-level memory object mapped to the image<br>
+<br>
+ _mem = self._memobj.memory[mem.number - 1]<br>
+<br>
+ cbyte = (mem.number - 1) / 8<br>
+ cbit = 7 - ((mem.number - 1) % 8)<br>
+<br>
+ if mem.empty:<br>
+ self._memobj.csetflag[cbyte].c[cbit] = 0<br>
+ self._memobj.cskipflag[cbyte].c[cbit] = 0<br>
+ _mem.set_raw('\xff' * (_mem.size() / 8))<br>
+ return<br>
+<br>
+ _mem.set_raw('\x00' * (_mem.size() / 8))<br>
+<br>
+ # set the occupied bitfield<br>
+ self._memobj.csetflag[cbyte].c[cbit] = 1<br>
+ # set the scan add bitfield<br>
+ self._memobj.cskipflag[cbyte].c[cbit] = 0 if (mem.skip == "S") else 1<br>
+<br>
+ _mem.freq = mem.freq / 10 # Convert to low-level frequency<br>
+ _mem.offset = mem.offset / 10 # Convert to low-level frequency<br>
+<br>
+ # Store the alpha tag<br>
+ _<a href="http://mem.name" rel="noreferrer" target="_blank">mem.name</a> = mem.name.ljust(6)[:6] # Store the alpha tag<br>
+<br>
+ # Set duplex bitfields<br>
+ if mem.duplex == '+':<br>
+ _mem.duplex = DUPLEX_POSSPLIT<br>
+ elif mem.duplex == '-':<br>
+ _mem.duplex = DUPLEX_NEGSPLIT<br>
+ elif mem.duplex == '':<br>
+ _mem.duplex = DUPLEX_NOSPLIT<br>
+ elif mem.duplex == 'split':<br>
+ diff = mem.offset - mem.freq<br>
+ _mem.duplex = DUPLEXES.index("-") \<br>
+ if diff < 0 else DUPLEXES.index("+")<br>
+ _mem.offset = abs(diff) / 10<br>
+ else:<br>
+ LOG.error('%s: set_mem: unhandled duplex: %s' %<br>
+ (<a href="http://mem.name" rel="noreferrer" target="_blank">mem.name</a>, mem.duplex))<br>
+<br>
+ # handle tx off<br>
+ _mem.tx_off = 0<br>
+ if mem.duplex == 'off':<br>
+ _mem.tx_off = 1<br>
+<br>
+ # Set the channel width - remember we promote 20kHz channels to FM<br>
+ # on import, so don't handle them here<br>
+ if mem.mode == 'FM':<br>
+ _mem.channel_width = CHANNEL_WIDTH_25kHz<br>
+ elif mem.mode == 'NFM':<br>
+ _mem.channel_width = CHANNEL_WIDTH_12d5kHz<br>
+ else:<br>
+ LOG.error('%s: set_mem: unhandled mode: %s' % (<br>
+ <a href="http://mem.name" rel="noreferrer" target="_blank">mem.name</a>, mem.mode))<br>
+<br>
+ # CTCSS Tones and DTCS Codes<br>
+ ((txmode, txtone, txpol),<br>
+ (rxmode, rxtone, rxpol)) = chirp_common.split_tone_encode(mem)<br>
+<br>
+ _mem.txtmode = TMODES.index(txmode)<br>
+<br>
+ _mem.rxtmode = TMODES.index(rxmode)<br>
+<br>
+ if txmode == "Tone":<br>
+ _mem.txtone = TONES.index(txtone)<br>
+ elif txmode == "DTCS":<br>
+ self._set_dcs_index(_mem, 'tx',<br>
+ chirp_common.ALL_DTCS_CODES.index(txtone))<br>
+<br>
+ _mem.squelch_mode = False<br>
+ if rxmode == "Tone":<br>
+ _mem.rxtone = TONES.index(rxtone)<br>
+ _mem.squelch_mode = True<br>
+ elif rxmode == "DTCS":<br>
+ self._set_dcs_index(_mem, 'rx',<br>
+ chirp_common.ALL_DTCS_CODES.index(rxtone))<br>
+ _mem.squelch_mode = True<br>
+<br>
+ _mem.txinv = txpol == "R"<br>
+ _mem.rxinv = rxpol == "R"<br>
+<br>
+ # set the power level<br>
+ if mem.power == POWER_LEVELS[0]:<br>
+ _mem.txpower = TXPOWER_LOW<br>
+ elif mem.power == POWER_LEVELS[1]:<br>
+ _mem.txpower = TXPOWER_MED<br>
+ elif mem.power == POWER_LEVELS[2]:<br>
+ _mem.txpower = TXPOWER_HIGH<br>
+ else:<br>
+ LOG.error('%s: set_mem: unhandled power level: %s' %<br>
+ (<a href="http://mem.name" rel="noreferrer" target="_blank">mem.name</a>, mem.power))<br>
+<br>
+ # extra settings<br>
+ for setting in mem.extra:<br>
+ setattr(_mem, setting.get_name(), setting.value)<br>
+<br>
+ def _get_settings(self):<br>
+ _embedded = self._memobj.embedded_msg<br>
+ _settings = self._memobj.settings<br>
+ _settings2 = self._memobj.settings2<br>
+ _settings3 = self._memobj.settings3<br>
+ _slabel = self._memobj.slabel<br>
+<br>
+ function = RadioSettingGroup("function", "Function Setup")<br>
+ group = RadioSettings(function)<br>
+<br>
+ # Function Setup<br>
+ # MODE SET<br>
+ rs = RadioSettingValueList(LIST_DISPLAY_MODE,<br>
+ LIST_DISPLAY_MODE[_settings.display_mode])<br>
+ rset = RadioSetting("display_mode", "Display Mode", rs)<br>
+ function.append(rset)<br>
+<br>
+ rs = RadioSettingValueInteger(1, 199, _settings3.ch_number + 1)<br>
+ rset = RadioSetting("settings3.ch_number", "Channel Number", rs)<br>
+ function.append(rset)<br>
+<br>
+ # DISPLAY SET<br>
+ def _filter(name):<br>
+ filtered = ""<br>
+ for char in str(name):<br>
+ if char in chirp_common.CHARSET_ASCII:<br>
+ filtered += char<br>
+ else:<br>
+ filtered += " "<br>
+ return filtered<br>
+<br>
+ val = RadioSettingValueString(0, 6, _filter(_slabel.startname))<br>
+ rs = RadioSetting("slabel.startname", "Startup Label", val)<br>
+ function.append(rs)<br>
+<br>
+ # VOL SET<br>
+ rs = RadioSettingValueBoolean(bool(_settings.beep))<br>
+ rset = RadioSetting("beep", "Beep Prompt", rs)<br>
+ function.append(rset)<br>
+<br>
+ rs = RadioSettingValueInteger(1, 30, _settings.volume)<br>
+ rset = RadioSetting("volume", "Volume Level", rs)<br>
+ function.append(rset)<br>
+<br>
+ rs = RadioSettingValueInteger(1, 16, _settings.mic_gain)<br>
+ rset = RadioSetting("mic_gain", "Mic Gain", rs)<br>
+ function.append(rset)<br>
+<br>
+ # ON/OFF SET<br>
+ rs = RadioSettingValueList(LIST_APO,<br>
+ LIST_APO[_settings.auto_power_off])<br>
+ rset = RadioSetting("auto_power_off", "Auto Power Off", rs)<br>
+ function.append(rset)<br>
+<br>
+ rs = RadioSettingValueList(LIST_AOP, LIST_AOP[_settings.auto_power_on])<br>
+ rset = RadioSetting("auto_power_on", "Power On Method", rs)<br>
+ function.append(rset)<br>
+<br>
+ # STE SET<br>
+ rs = RadioSettingValueList(LIST_STE_FREQ,<br>
+ LIST_STE_FREQ[_settings.ste_frequency])<br>
+ rset = RadioSetting("ste_frequency", "STE Frequency", rs)<br>
+ function.append(rset)<br>
+<br>
+ rs = RadioSettingValueList(LIST_STE_TYPE,<br>
+ LIST_STE_TYPE[_settings.ste_type])<br>
+ rset = RadioSetting("ste_type", "STE Type", rs)<br>
+ function.append(rset)<br>
+<br>
+ # FUNCTION SET<br>
+ rs = RadioSettingValueList(LIST_STEP, LIST_STEP[_settings.tuning_step])<br>
+ rset = RadioSetting("tuning_step", "Tuning Step", rs)<br>
+ function.append(rset)<br>
+<br>
+ rs = RadioSettingValueList(LIST_SQUELCH,<br>
+ LIST_SQUELCH[_settings.squelch])<br>
+ rset = RadioSetting("squelch", "Squelch Level", rs)<br>
+ function.append(rset)<br>
+<br>
+ rs = RadioSettingValueBoolean(bool(_settings.sql_key_function))<br>
+ rset = RadioSetting("sql_key_function", "SQL Key Function", rs)<br>
+ function.append(rset)<br>
+<br>
+ rs = RadioSettingValueList(LIST_TIMEOUT,<br>
+ LIST_TIMEOUT[_settings.timeout_timer])<br>
+ rset = RadioSetting("timeout_timer", "Timeout Timer", rs)<br>
+ function.append(rset)<br>
+<br>
+ # uncategorized<br>
+ rs = RadioSettingValueBoolean(bool(_settings.save_chan_param))<br>
+ rset = RadioSetting("save_chan_param", "Save Channel Parameters", rs)<br>
+ function.append(rset)<br>
+<br>
+ rs = RadioSettingValueBoolean(bool(_settings.forbid_chan_menu))<br>
+ rset = RadioSetting("forbid_chan_menu", "Forbid Channel Menu", rs)<br>
+ function.append(rset)<br>
+<br>
+ rs = RadioSettingValueBoolean(bool(not _settings.forbid_initialize))<br>
+ rset = RadioSetting("forbid_initialize", "Forbid Initialize", rs)<br>
+ function.append(rset)<br>
+<br>
+ rs = RadioSettingValueBoolean(bool(_settings.forbid_setting))<br>
+ rset = RadioSetting("forbid_setting", "Forbid Setting", rs)<br>
+ function.append(rset)<br>
+<br>
+ # Information Of Scanning Channel<br>
+ scanning = RadioSettingGroup("scanning", "Scanning Setup")<br>
+ group.append(scanning)<br>
+<br>
+ rs = RadioSettingValueBoolean(bool(_settings2.scan_mode))<br>
+ rset = RadioSetting("settings2.scan_mode", "Scan Mode", rs)<br>
+ scanning.append(rset)<br>
+<br>
+ rs = RadioSettingValueList(LIST_PRIORITY_CH,<br>
+ LIST_PRIORITY_CH[_settings2.priority_ch])<br>
+ rset = RadioSetting("settings2.priority_ch", "Priority Channel", rs)<br>
+ scanning.append(rset)<br>
+<br>
+ rs = RadioSettingValueInteger(1, 199, _settings2.priority_ch1 + 1)<br>
+ rset = RadioSetting("settings2.priority_ch1", "Priority Channel 1", rs)<br>
+ scanning.append(rset)<br>
+<br>
+ rs = RadioSettingValueInteger(1, 199, _settings2.priority_ch2 + 1)<br>
+ rset = RadioSetting("settings2.priority_ch2", "Priority Channel 2", rs)<br>
+ scanning.append(rset)<br>
+<br>
+ rs = RadioSettingValueList(LIST_REVERT_CH,<br>
+ LIST_REVERT_CH[_settings2.revert_ch])<br>
+ rset = RadioSetting("settings2.revert_ch", "Revert Channel", rs)<br>
+ scanning.append(rset)<br>
+<br>
+ rs = RadioSettingValueList(LIST_TIME46,<br>
+ LIST_TIME46[_settings2.look_back_time_a])<br>
+ rset = RadioSetting("settings2.look_back_time_a",<br>
+ "Look Back Time A", rs)<br>
+ scanning.append(rset)<br>
+<br>
+ rs = RadioSettingValueList(LIST_TIME46,<br>
+ LIST_TIME46[_settings2.look_back_time_b])<br>
+ rset = RadioSetting("settings2.look_back_time_b",<br>
+ "Look Back Time B", rs)<br>
+ scanning.append(rset)<br>
+<br>
+ rs = RadioSettingValueList(LIST_TIME50,<br>
+ LIST_TIME50[_settings2.dropout_delay_time])<br>
+ rset = RadioSetting("settings2.dropout_delay_time",<br>
+ "Dropout Delay Time", rs)<br>
+ scanning.append(rset)<br>
+<br>
+ rs = RadioSettingValueList(LIST_TIME50,<br>
+ LIST_TIME50[_settings2.dwell_time])<br>
+ rset = RadioSetting("settings2.dwell_time", "Dwell Time", rs)<br>
+ scanning.append(rset)<br>
+<br>
+ # Embedded Message<br>
+ embedded = RadioSettingGroup("embedded", "Embedded Message")<br>
+ group.append(embedded)<br>
+<br>
+ rs = RadioSettingValueString(0, 5, _filter(_embedded.radio_type))<br>
+ rs.set_mutable(False)<br>
+ rset = RadioSetting("embedded_msg.radio_type", "Radio Type", rs)<br>
+ embedded.append(rset)<br>
+<br>
+ if str(_embedded.radio_type) == "RT98V":<br>
+ options = LIST_RT98V_MODES<br>
+ else:<br>
+ options = LIST_RT98U_MODES<br>
+ rs = RadioSettingValueList(options, options[_embedded.mode])<br>
+ rs.set_mutable(False)<br>
+ rset = RadioSetting("embedded_msg.mode", "Mode", rs)<br>
+ embedded.append(rset)<br>
+<br>
+ # frequency<br>
+ if str(_embedded.radio_type) == "RT98V":<br>
+ options = LIST_RT98V_FREQS<br>
+ else:<br>
+ options = LIST_RT98U_FREQS<br>
+ rs = RadioSettingValueList(options, options[_settings3.bandlimit])<br>
+ rs.set_mutable(False)<br>
+ rset = RadioSetting("settings3.bandlimit", "Frequency", rs)<br>
+ embedded.append(rset)<br>
+<br>
+ rs = RadioSettingValueString(0, 10, _filter(_embedded.date_mfg))<br>
+ rs.set_mutable(False)<br>
+ rset = RadioSetting("embedded_msg.date_mfg", "Production Date", rs)<br>
+ embedded.append(rset)<br>
+<br>
+ rs = RadioSettingValueString(0, 4, _filter(_embedded.mcu_version))<br>
+ rs.set_mutable(False)<br>
+ rset = RadioSetting("embedded_msg.mcu_version", "MCU Version", rs)<br>
+ embedded.append(rset)<br>
+<br>
+ return group<br>
+<br>
+ def get_settings(self):<br>
+ try:<br>
+ return self._get_settings()<br>
+ except:<br>
+ import traceback<br>
+ LOG.error("failed to parse settings")<br>
+ traceback.print_exc()<br>
+ return None<br>
+<br>
+ def set_settings(self, settings):<br>
+ for element in settings:<br>
+ if not isinstance(element, RadioSetting):<br>
+ self.set_settings(element)<br>
+ continue<br>
+ else:<br>
+ try:<br>
+ if "." in element.get_name():<br>
+ bits = element.get_name().split(".")<br>
+ obj = self._memobj<br>
+ for bit in bits[:-1]:<br>
+ obj = getattr(obj, bit)<br>
+ setting = bits[-1]<br>
+ else:<br>
+ obj = self._memobj.settings<br>
+ setting = element.get_name()<br>
+<br>
+ if element.has_apply_callback():<br>
+ LOG.debug("using apply callback")<br>
+ element.run_apply_callback()<br>
+ elif setting == "ch_number":<br>
+ setattr(obj, setting, int(element.value) - 1)<br>
+ elif setting == "forbid_initialize":<br>
+ setattr(obj, setting, not int(element.value))<br>
+ elif setting == "priority_ch1":<br>
+ setattr(obj, setting, int(element.value) - 1)<br>
+ elif setting == "priority_ch2":<br>
+ setattr(obj, setting, int(element.value) - 1)<br>
+ elif element.value.get_mutable():<br>
+ LOG.debug("Setting %s = %s" % (setting, element.value))<br>
+ setattr(obj, setting, element.value)<br>
+ except Exception, e:<br>
+ LOG.debug(element.get_name())<br>
+ raise<br>
+<br>
+ @classmethod<br>
+ def match_model(cls, filedata, filename):<br>
+ # This radio has always been post-metadata, so never do<br>
+ # old-school detection<br>
+ return False<br>
+<br>
+<br>
+@directory.register<br>
+class Rt98Radio(Rt98BaseRadio):<br>
+ """Retevis RT98"""<br>
+ VENDOR = "Retevis"<br>
+ MODEL = "RT98"<br>
+ # Allowed radio types is a dict keyed by model of a list of version<br>
+ # strings<br>
+ ALLOWED_RADIO_TYPES = {'RT98V': ['V100'],<br>
+ 'RT98U': ['V100']}<br>
diff -r f586574bc878 -r 0eab8146b294 tools/cpep8.manifest<br>
--- a/tools/cpep8.manifest Thu Jun 17 21:57:05 2021 -0400<br>
+++ b/tools/cpep8.manifest Sat Jul 03 14:13:35 2021 -0400<br>
@@ -83,6 +83,7 @@<br>
./chirp/drivers/retevis_rt23.py<br>
./chirp/drivers/retevis_rt26.py<br>
./chirp/drivers/retevis_rt76p.py<br>
+./chirp/drivers/retevis_rt98.py<br>
./chirp/drivers/rfinder.py<br>
./chirp/drivers/tdxone_tdq8a.py<br>
./chirp/drivers/template.py<br>
</div></div></div>