[chirp_devel] [PATCH] [btech] Add support for 5 Tone-settings. Part of #4051

Michael Wagner (OE4AMW)
Thu Nov 3 09:51:40 PDT 2016


# HG changeset patch
# User Michael Wagner <michael.wagner at gmx.at>
# Date 1478191827 -3600
#      Thu Nov 03 17:50:27 2016 +0100
# Node ID 012141ebcd3a0f70c4f35cd93538c515f7c79fa5
# Parent  c386ef4dc431e5065266de2b163260e6f5637b27
[btech] Add support for 5 Tone-settings. Part of #4051
Improved version of the last patch: Restricted 5-Tones only to KT8900R, better checking indices before accessing lists, better grouping on the HMI.

diff -r c386ef4dc431 -r 012141ebcd3a chirp/drivers/btech.py
--- a/chirp/drivers/btech.py	Tue Nov 01 18:42:18 2016 -0700
+++ b/chirp/drivers/btech.py	Thu Nov 03 17:50:27 2016 +0100
@@ -155,6 +155,44 @@
   u8 unknown1[10];
 } names[200];
 
+#seekto 0x2400;
+struct {
+  u8 period; // one out of LIST_5TONE_STANDARD_PERIODS
+  u8 group_tone;
+  u8 repeat_tone;
+  u8 unused[13];
+} _5tone_std_settings[15];
+
+#seekto 0x2500;
+struct {
+  u8 frame1[5];
+  u8 frame2[5];
+  u8 frame3[5];
+  u8 standard;   // one out of LIST_5TONE_STANDARDS
+} _5tone_codes[15];
+
+#seekto 0x25F0;
+struct {
+  u8 _5tone_delay1; // * 10ms
+  u8 _5tone_delay2; // * 10ms
+  u8 _5tone_delay3; // * 10ms
+  u8 _5tone_first_digit_ext_length;
+  u8 unknown1;
+  u8 unknown2;
+  u8 unknown3;
+  u8 unknown4;
+  u8 decode_standard;
+  u8 unknown5:5,
+     _5tone_decode_call_frame3:1,
+     _5tone_decode_call_frame2:1,
+     _5tone_decode_call_frame1:1;
+  u8 unknown6:5,
+     _5tone_decode_disp_frame3:1,
+     _5tone_decode_disp_frame2:1,
+     _5tone_decode_disp_frame1:1;
+  u8 decode_reset_time; // * 100 + 100ms
+} _5tone_settings;
+
 #seekto 0x3000;
 struct {
   u8 freq[8];
@@ -237,6 +275,20 @@
 LIST_WIDE = ["Wide", "Narrow"]
 STEPS = [2.5, 5.0, 6.25, 10.0, 12.5, 25.0]
 LIST_STEP = [str(x) for x in STEPS]
+LIST_5TONE_STANDARDS = ["CCIR1", "CCIR2", "PCCIR", "ZVEI1", "ZVEI2", "ZVEI3",
+                        "PZVEI", "DZVEI", "PDZVEI", "EEA", "EIA", "EURO",
+                        "CCITT", "NATEL", "MODAT", "none"]
+LIST_5TONE_STANDARDS_without_none = ["CCIR1", "CCIR2", "PCCIR", "ZVEI1",
+                                     "ZVEI2", "ZVEI3",
+                                     "PZVEI", "DZVEI", "PDZVEI", "EEA", "EIA",
+                                     "EURO", "CCITT", "NATEL", "MODAT"]
+LIST_5TONE_STANDARD_PERIODS = ["20", "30", "40", "50", "60", "70", "80", "90",
+                               "100", "110", "120", "130", "140", "150", "160",
+                               "170", "180", "190", "200"]
+LIST_5TONE_DIGITS = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A",
+                     "B", "C", "D", "E", "F"]
+LIST_5TONE_DELAY = ["%s ms" % x for x in range(0, 1010, 10)]
+LIST_5TONE_RESET = ["%s ms" % x for x in range(100, 8100, 100)]
 
 # This is a general serial timeout for all serial read functions.
 # Practice has show that about 0.7 sec will be enough to cover all radios.
@@ -1613,7 +1665,267 @@
             fm_presets.append(fmfreq)
             
             i = i + 1
+
+        # 5 Tone Settings
+        if self.MODEL == "KT8900R":
+            LOG.debug("This is a " + self.MODEL + ". Adding 5 Tone settings" )
+
+            stds_5tone = RadioSettingGroup ("stds_5tone", "Standards")
+            codes_5tone = RadioSettingGroup ("codes_5tone", "Codes")
             
+            group_5tone = RadioSettingGroup ("group_5tone", "5 Tone Settings")
+            group_5tone.append(stds_5tone)
+            group_5tone.append(codes_5tone)
+            
+            top.append(group_5tone)
+
+            def apply_list_value(setting, obj):
+                options = setting.value.get_options()
+                obj.set_value ( options.index(str(setting.value)) )
+        
+            _5tone_standards = self._memobj._5tone_std_settings
+            i = 0
+            for standard in _5tone_standards:
+                std_5tone = RadioSettingGroup ("std_5tone_" + str(i), 
+                                               LIST_5TONE_STANDARDS[i])
+                stds_5tone.append(std_5tone)
+                if standard.period <= len( LIST_5TONE_STANDARD_PERIODS ):
+                    line = RadioSetting(
+                        "_5tone_std_settings_" + str(i) + "_period",
+                        "Period (ms)", RadioSettingValueList
+                        (LIST_5TONE_STANDARD_PERIODS,
+                         LIST_5TONE_STANDARD_PERIODS[standard.period]))
+                    line.set_apply_callback(apply_list_value, standard.period)
+                    std_5tone.append(line)
+                else:
+                    LOG.debug("Invalid value for 5tone period! Disabling.")
+                if standard.group_tone <= len( LIST_5TONE_DIGITS ):
+                    line = RadioSetting(
+                        "_5tone_std_settings_" + str(i) + "_grouptone",
+                        "Group Tone",
+                        RadioSettingValueList(LIST_5TONE_DIGITS,
+                                              LIST_5TONE_DIGITS[
+                                                  standard.group_tone]))
+                    line.set_apply_callback(apply_list_value,
+                                            standard.group_tone)
+                    std_5tone.append(line)
+                else:
+                    LOG.debug("Invalid value for 5tone digit! Disabling.")
+                if standard.repeat_tone <= len( LIST_5TONE_DIGITS ):
+                    line = RadioSetting(
+                        "_5tone_std_settings_" + str(i) + "_repttone",
+                        "Repeat Tone",
+                        RadioSettingValueList(LIST_5TONE_DIGITS,
+                                              LIST_5TONE_DIGITS[
+                                                  standard.repeat_tone]))
+                    line.set_apply_callback(apply_list_value,
+                                            standard.repeat_tone)
+                    std_5tone.append(line)
+                else:
+                    LOG.debug("Invalid value for 5tone digit! Disabling.")
+                i = i + 1
+
+            def my_apply_5tonestdlist_value(setting, obj):
+                if LIST_5TONE_STANDARDS.index(str(setting.value)) == 15:
+                    obj.set_value(0xFF)
+                else:
+                    obj.set_value( LIST_5TONE_STANDARDS.
+                                  index(str(setting.value)) )
+
+            def apply_5tone_frame(setting, obj):
+                LOG.debug("Setting 5 Tone: " + str(setting.value) )
+                valstring = str(setting.value)
+                if len(valstring) == 0:
+                    for i in range(0,5):
+                        obj[i] = 255
+                else:
+                    validFrame = True
+                    for i in range(0,5):
+                        currentChar = valstring[i].upper()
+                        if currentChar in LIST_5TONE_DIGITS:
+                            obj[i] = LIST_5TONE_DIGITS.index(currentChar)
+                        else:
+                            validFrame = False
+                            LOG.debug("invalid char: " + str(currentChar))
+                    if not validFrame:
+                        LOG.debug("setting whole frame to FF" )
+                        for i in range(0,5):
+                            obj[i] = 255
+
+            def validate_5tone_frame(value):
+                if (len(str(value)) != 5) and (len(str(value)) != 0) :
+                    msg = ("5 Tone must have 5 digits or 0 digits")
+                    raise InvalidValueError(msg)
+                for digit in str(value):
+                    if digit.upper() not in LIST_5TONE_DIGITS:
+                        msg = (str(digit) + " is not a valid digit for 5tones")
+                        raise InvalidValueError(msg)
+                return value
+
+            def frame2string(frame):
+                frameString = ""
+                for digit in frame:
+                    if digit != 255:
+                        frameString = frameString + LIST_5TONE_DIGITS[digit]
+                return frameString
+
+            _5tone_codes = self._memobj._5tone_codes
+            i = 1
+            for code in _5tone_codes:
+                code_5tone = RadioSettingGroup ("code_5tone_" + str(i),
+                                                "5 Tone code " + str(i))
+                codes_5tone.append(code_5tone)
+                if (code.standard == 255 ):
+                    currentVal = 15
+                else:
+                    currentVal = code.standard
+                line = RadioSetting("_5tone_code_" + str(i) + "_std", 
+                                    " Standard",
+                                    RadioSettingValueList(LIST_5TONE_STANDARDS,
+                                                          LIST_5TONE_STANDARDS[
+                                                              currentVal]) )
+                line.set_apply_callback(my_apply_5tonestdlist_value,
+                                        code.standard)
+                code_5tone.append(line)
+            
+                val = RadioSettingValueString(0, 6,
+                                              frame2string(code.frame1), False)
+                line = RadioSetting("_5tone_code_" + str(i) + "_frame1", 
+                                    " Frame 1", val)
+                val.set_validate_callback(validate_5tone_frame)
+                line.set_apply_callback(apply_5tone_frame, code.frame1)
+                code_5tone.append(line)
+            
+                val = RadioSettingValueString(0, 6,
+                                              frame2string(code.frame2), False)
+                line = RadioSetting("_5tone_code_" + str(i) + "_frame2",
+                                    " Frame 2", val)
+                val.set_validate_callback(validate_5tone_frame)
+                line.set_apply_callback(apply_5tone_frame, code.frame2)
+                code_5tone.append(line)
+
+                val = RadioSettingValueString(0, 6,
+                                              frame2string(code.frame3), False)
+                line = RadioSetting("_5tone_code_" + str(i) + "_frame3",
+                                    " Frame 3", val)
+                val.set_validate_callback(validate_5tone_frame)
+                line.set_apply_callback(apply_5tone_frame, code.frame3)
+                code_5tone.append(line)
+                i = i + 1
+
+            _5_tone_decode1 = RadioSetting(
+                "_5tone_settings._5tone_decode_call_frame1",
+                "5 Tone decode call Frame 1",
+                RadioSettingValueBoolean(
+                    _mem._5tone_settings._5tone_decode_call_frame1))
+            group_5tone.append(_5_tone_decode1)
+        
+            _5_tone_decode2 = RadioSetting(
+                "_5tone_settings._5tone_decode_call_frame2",
+                "5 Tone decode call Frame 2",
+                RadioSettingValueBoolean(
+                    _mem._5tone_settings._5tone_decode_call_frame2))
+            group_5tone.append(_5_tone_decode2)
+
+            _5_tone_decode3 = RadioSetting(
+                "_5tone_settings._5tone_decode_call_frame3",
+                "5 Tone decode call Frame 3",
+                RadioSettingValueBoolean(
+                    _mem._5tone_settings._5tone_decode_call_frame3))
+            group_5tone.append(_5_tone_decode3)
+
+            _5_tone_decode_disp1 = RadioSetting(
+                "_5tone_settings._5tone_decode_disp_frame1",
+                "5 Tone decode disp Frame 1",
+                RadioSettingValueBoolean(
+                    _mem._5tone_settings._5tone_decode_disp_frame1))
+            group_5tone.append(_5_tone_decode_disp1)
+
+            _5_tone_decode_disp2 = RadioSetting(
+                "_5tone_settings._5tone_decode_disp_frame2",
+                "5 Tone decode disp Frame 2",
+                RadioSettingValueBoolean(
+                    _mem._5tone_settings._5tone_decode_disp_frame2))
+            group_5tone.append(_5_tone_decode_disp2)
+
+            _5_tone_decode_disp3 = RadioSetting(
+                "_5tone_settings._5tone_decode_disp_frame3",
+                "5 Tone decode disp Frame 3",
+                RadioSettingValueBoolean(
+                    _mem._5tone_settings._5tone_decode_disp_frame3))
+            group_5tone.append(_5_tone_decode_disp3)
+        
+            if _mem._5tone_settings.decode_standard != 255 :
+                line = RadioSetting("_5tone_settings.decode_standard", 
+                                    "5 Tone-decode Standard",
+                                    RadioSettingValueList(
+                                        LIST_5TONE_STANDARDS_without_none,
+                                        LIST_5TONE_STANDARDS_without_none[
+                                            _mem.
+                                            _5tone_settings.decode_standard]))
+                group_5tone.append(line)
+
+            if _mem._5tone_settings._5tone_delay1 <= len( LIST_5TONE_DELAY ):
+                list = RadioSettingValueList(LIST_5TONE_DELAY, 
+                                             LIST_5TONE_DELAY[
+                                                 _mem._5tone_settings.
+                                                 _5tone_delay1])
+                line = RadioSetting("_5tone_settings._5tone_delay1",
+                                    "5 Tone Delay Frame 1", list)
+                group_5tone.append(line)
+            else:
+                LOG.debug("Invalid value for 5tone delay! Disabling.")
+
+            if _mem._5tone_settings._5tone_delay2 <= len( LIST_5TONE_DELAY ):
+                list = RadioSettingValueList(LIST_5TONE_DELAY,
+                                             LIST_5TONE_DELAY[
+                                                 _mem._5tone_settings.
+                                                 _5tone_delay2])
+                line = RadioSetting("_5tone_settings._5tone_delay2",
+                                    "5 Tone Delay Frame 2", list)
+                group_5tone.append(line)
+            else:
+                LOG.debug("Invalid value for 5tone delay! Disabling.")
+
+            if _mem._5tone_settings._5tone_delay2 <= len( LIST_5TONE_DELAY ):
+                list = RadioSettingValueList(LIST_5TONE_DELAY,
+                                             LIST_5TONE_DELAY[
+                                                 _mem._5tone_settings.
+                                                 _5tone_delay3])
+                line = RadioSetting("_5tone_settings._5tone_delay3",
+                                    "5 Tone Delay Frame 3", list )
+                group_5tone.append(line)
+            else:
+                LOG.debug("Invalid value for 5tone delay! Disabling.")
+        
+            if _mem._5tone_settings._5tone_first_digit_ext_length <= len(
+                LIST_5TONE_DELAY ):
+                list = RadioSettingValueList(
+                    LIST_5TONE_DELAY, 
+                    LIST_5TONE_DELAY[
+                        _mem._5tone_settings._5tone_first_digit_ext_length])
+                line = RadioSetting(
+                    "_5tone_settings._5tone_first_digit_ext_length",
+                    "First digit extend length", list)
+                group_5tone.append(line)
+            else:
+                LOG.debug("Invalid value for 5tone ext length! Disabling.")
+        
+            if _mem._5tone_settings.decode_reset_time <= len(LIST_5TONE_RESET):
+                list = RadioSettingValueList(
+                    LIST_5TONE_RESET,
+                    LIST_5TONE_RESET[
+                        _mem._5tone_settings.decode_reset_time])
+                line = RadioSetting("_5tone_settings.decode_reset_time",
+                                    "Decode reset time", list)
+                group_5tone.append(line)
+            else:
+                LOG.debug("Invalid value decode reset time! Disabling.")
+        else:
+            LOG.debug("Not adding 5 Tone settings for this model (" 
+                + self.MODEL + "). If your model supports 5 Tone signalling,"
+                + "add more information to #4051")
+
         return top
 
     def set_settings(self, settings):



More information about the chirp_devel mailing list