From e069b7c9d4791efb5eb39c30e5f9678597fe0441 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Sun, 1 Sep 2024 14:06:53 -0700 Subject: [PATCH] ga510: Add airband for SenhaiX 8800 Fixes #11516 --- chirp/chirp_common.py | 8 ++++++++ chirp/drivers/ga510.py | 28 ++++++++++++++++++++++++++++ chirp/drivers/tdh8.py | 20 +++++++------------- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/chirp/chirp_common.py b/chirp/chirp_common.py index 65a99b05..3ec4f371 100644 --- a/chirp/chirp_common.py +++ b/chirp/chirp_common.py @@ -2063,3 +2063,11 @@ def mem_to_text(mem): elif mode == 'DTCS': pieces.append('D%03i' % tone) return '[%s]' % '/'.join(pieces) + + +def in_range(freq, ranges): + """Check if freq is in any of the provided ranges""" + for lo, hi in ranges: + if lo <= freq <= hi: + return True + return False diff --git a/chirp/drivers/ga510.py b/chirp/drivers/ga510.py index e16385d8..9e10102e 100644 --- a/chirp/drivers/ga510.py +++ b/chirp/drivers/ga510.py @@ -35,6 +35,7 @@ DTCS_CODES = tuple(sorted(chirp_common.DTCS_CODES + (645,))) DTMFCHARS = '0123456789ABCD*#' +AIRBAND = (108000000, 136000000) def reset(radio): @@ -1046,6 +1047,33 @@ class Senhaix8800Radio(RadioddityGA510Radio): _mem_format = MODEL_SHX8800_FORMAT _magic = b'PROGROMSHXU' + def get_features(self): + rf = super().get_features() + rf.valid_bands = rf.valid_bands + [AIRBAND] + rf.valid_modes = rf.valid_modes + ['AM'] + return rf + + def get_memory(self, number): + m = super().get_memory(number) + if chirp_common.in_range(m.freq, [AIRBAND]): + m.mode = 'AM' + return m + + def validate_memory(self, mem): + msgs = [] + if chirp_common.in_range(mem.freq, [AIRBAND]): + if not mem.mode == 'AM': + msgs.append(chirp_common.ValidationWarning( + _('Frequency in this range requires AM mode'))) + if mem.duplex or mem.tmode: + msgs.append(chirp_common.ValidationError( + _('AM mode does not allow duplex or tone'))) + elif not chirp_common.in_range( + mem.freq, [AIRBAND]) and mem.mode == 'AM': + msgs.append(chirp_common.ValidationWarning( + _('Frequency in this range must not be AM mode'))) + return msgs + super().validate_memory(mem) + @directory.register class RadioddityGS5BRadio(Senhaix8800Radio): diff --git a/chirp/drivers/tdh8.py b/chirp/drivers/tdh8.py index 53a6af07..2dd48677 100644 --- a/chirp/drivers/tdh8.py +++ b/chirp/drivers/tdh8.py @@ -811,13 +811,6 @@ RT_730 = b"\x50\x47\x4F\x4A\x48\xC3\x44" -def in_range(freq, ranges): - for lo, hi in ranges: - if lo <= freq <= hi: - return True - return False - - def _do_status(radio, block): status = chirp_common.Status() status.msg = "Cloning" @@ -1259,9 +1252,9 @@ def get_memory(self, number): FREQHOP_VALUES, FREQHOP_VALUES[_mem.freqhop])) mem.extra.append(rs) - if in_range(mem.freq, self._rxbands): + if chirp_common.in_range(mem.freq, self._rxbands): mem.duplex = 'off' - if in_range(mem.freq, [AIRBAND]): + if chirp_common.in_range(mem.freq, [AIRBAND]): mem.mode = 'AM' return mem @@ -1328,7 +1321,7 @@ def set_memory(self, mem): else: _mem.txfreq = mem.freq / 10 - if in_range(mem.freq, self._rxbands): + if chirp_common.in_range(mem.freq, self._rxbands): _mem.txfreq.fill_raw(b'\xFF') _mem.rxfreq = mem.freq / 10 @@ -2463,13 +2456,14 @@ def _set_fm_preset(self, settings): def validate_memory(self, mem): msgs = [] - if in_range(mem.freq, [AIRBAND]) and not mem.mode == 'AM': + if chirp_common.in_range(mem.freq, [AIRBAND]) and not mem.mode == 'AM': msgs.append(chirp_common.ValidationWarning( _('Frequency in this range requires AM mode'))) - if not in_range(mem.freq, [AIRBAND]) and mem.mode == 'AM': + if not chirp_common.in_range(mem.freq, [AIRBAND]) and mem.mode == 'AM': msgs.append(chirp_common.ValidationWarning( _('Frequency in this range must not be AM mode'))) - if not in_range(mem.freq, self._txbands) and mem.duplex != 'off': + if (not chirp_common.in_range(mem.freq, self._txbands) and + mem.duplex != 'off'): msgs.append(chirp_common.ValidationWarning( _('Frequency outside TX bands must be duplex=off'))) return msgs + super().validate_memory(mem)