Skip to content

Commit

Permalink
ga510: Add airband for SenhaiX 8800
Browse files Browse the repository at this point in the history
Fixes #11516
  • Loading branch information
kk7ds committed Sep 1, 2024
1 parent fddaaa0 commit e069b7c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
8 changes: 8 additions & 0 deletions chirp/chirp_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 28 additions & 0 deletions chirp/drivers/ga510.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
DTCS_CODES = tuple(sorted(chirp_common.DTCS_CODES + (645,)))

DTMFCHARS = '0123456789ABCD*#'
AIRBAND = (108000000, 136000000)


def reset(radio):
Expand Down Expand Up @@ -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):
Expand Down
20 changes: 7 additions & 13 deletions chirp/drivers/tdh8.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e069b7c

Please sign in to comment.