diff --git a/pylintrc b/pylintrc index cb1985f..26f638d 100644 --- a/pylintrc +++ b/pylintrc @@ -152,9 +152,10 @@ disable=raw-checker-failed, useless-suppression, deprecated-pragma, use-symbolic-message-instead, - missing-function-docstring, - missing-class-docstring, - missing-module-docstring + missing-function-docstring, + missing-class-docstring, + missing-module-docstring, + too-many-positional-arguments # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option @@ -436,7 +437,7 @@ exclude-too-few-public-methods= ignored-parents= # Maximum number of arguments for function / method. -max-args=5 +max-args=9 # Maximum number of attributes for a class (see R0902). max-attributes=7 @@ -448,7 +449,7 @@ max-bool-expr=5 max-branches=12 # Maximum number of locals for function / method body. -max-locals=15 +max-locals=18 # Maximum number of parents for a class (see R0901). max-parents=7 diff --git a/sa818.py b/sa818.py index 6036596..929712b 100755 --- a/sa818.py +++ b/sa818.py @@ -122,51 +122,48 @@ def version(self): logger.info('Firmware %s, version: %s', version[1], '_'.join(version[2:])) return version - def set_radio(self, opts): - tone = opts.ctcss if opts.ctcss else opts.dcs + def set_radio(self, frequency, offset, bw, squelch, ctcss, dcs, tail): + tone = ctcss if ctcss else dcs if tone: # 0000 = No ctcss or dcs tone tx_tone, rx_tone = tone else: tx_tone, rx_tone = ['0000', '0000'] - if opts.offset == 0.0: - tx_freq = rx_freq = f"{opts.frequency:.4f}" + if offset == 0.0: + tx_freq = rx_freq = f"{frequency:.4f}" else: - rx_freq = f"{opts.frequency:.4f}" - tx_freq = f"{opts.frequency + opts.offset:.4f}" + rx_freq = f"{frequency:.4f}" + tx_freq = f"{frequency + offset:.4f}" - cmd = f"{self.SETGRP}={opts.bw},{tx_freq},{rx_freq},{tx_tone},{opts.squelch},{rx_tone}" + cmd = f"{self.SETGRP}={bw},{tx_freq},{rx_freq},{tx_tone},{squelch},{rx_tone}" self.send(cmd) time.sleep(1) response = self.readline() if response != '+DMOSETGROUP:0': logger.error('SA818 programming error') else: - bw_label = ['Narrow', 'Wide'][opts.bw] - if opts.ctcss: + bw_label = ['Narrow', 'Wide'][bw] + if ctcss: msg = "%s, BW: %s, Frequency (RX: %s / TX: %s), CTCSS (TX: %s / RX: %s), squelch: %s, OK" logger.info(msg, response, bw_label, rx_freq, tx_freq, - CTCSS[int(tx_tone)], CTCSS[int(rx_tone)], opts.squelch) - elif opts.dcs: + CTCSS[int(tx_tone)], CTCSS[int(rx_tone)], squelch) + elif dcs: msg = "%s, BW: %s Frequency (RX: %s / TX: %s), DCD (TX: %s / RX: %s), squelch: %s, OK" logger.info(msg, response, bw_label, rx_freq, tx_freq, - tx_tone, rx_tone, opts.squelch) + tx_tone, rx_tone, squelch) else: msg = "%s, BW: %s, RX frequency: %s, TX frequency: %s, squelch: %s, OK" - logger.info(msg, response, bw_label, rx_freq, tx_freq, opts.squelch) + logger.info(msg, response, bw_label, rx_freq, tx_freq, squelch) - if opts.tail is not None and opts.ctcss is not None: - self.tail(opts) - elif opts.tail is not None: + if tail is not None and ctcss is not None: + self.tail(tail) + elif tail is not None: logger.warning('Ignoring "--tail" specified without ctcss') - def set_filter(self, opts): - for key in ("emphasis", "highpass", "lowpass"): - if getattr(opts, key) is None: - setattr(opts, key, 1) + def set_filter(self, emphasis, highpass, lowpass): _rx = {0: 'enabled', 1: 'disabled'} # filters are pre-emphasis, high-pass, low-pass - cmd = f"{self.FILTER}={opts.emphasis},{opts.highpass},{opts.lowpass}" + cmd = f"{self.FILTER}={emphasis},{highpass},{lowpass}" self.send(cmd) time.sleep(1) response = self.readline() @@ -174,28 +171,28 @@ def set_filter(self, opts): logger.error('SA818 set filter error') else: logger.info("%s filters [Pre/De]emphasis: %s, high-pass: %s, low-pass: %s", - response, _rx[opts.emphasis], _rx[opts.highpass], _rx[opts.lowpass]) + response, _rx[emphasis], _rx[highpass], _rx[lowpass]) - def set_volume(self, opts): - cmd = f"{self.VOLUME}={opts.level:d}" + def set_volume(self, level): + cmd = f"{self.VOLUME}={level:d}" self.send(cmd) time.sleep(1) response = self.readline() if response != "+DMOSETVOLUME:0": logger.error('SA818 set volume error') else: - logger.info("%s Volume level: %d, OK", response, opts.level) + logger.info("%s Volume level: %d, OK", response, level) - def tail(self, opts): + def tail(self, tail): _oc = {True: "open", False: "close"} - cmd = f"{self.TAIL}={int(opts.tail)}" + cmd = f"{self.TAIL}={int(tail)}" self.send(cmd) time.sleep(1) response = self.readline() if response != "+DMOSETTAIL:0": logger.error('SA818 set filter error') else: - logger.info("%s tail: %s", response, _oc[opts.tail]) + logger.info("%s tail: %s", response, _oc[tail]) def type_frequency(parg): @@ -410,7 +407,15 @@ def main(): if opts.func == 'version': radio.version() elif opts.func == 'radio': - radio.set_radio(opts) + radio.set_radio( + opts.frequency, + opts.offset, + opts.bw, + opts.squelch, + opts.ctcss, + opts.dcs, + opts.tail + ) elif opts.func == 'filters': for key in ('emphasis', 'highpass', 'lowpass'): if getattr(opts, key) is not None: @@ -418,9 +423,9 @@ def main(): else: logger.error('filters need at least one argument') raise SystemExit('Argument error') from None - radio.set_filter(opts) + radio.set_filter(opts.emphasis, opts.highpass, opts.lowpass) elif opts.func == 'volume': - radio.set_volume(opts) + radio.set_volume(opts.level) if __name__ == "__main__":