Skip to content

Commit

Permalink
Add support for CTCSS or DCS on transmit or receive ONLY (#26)
Browse files Browse the repository at this point in the history
* Add None support for RX or TX CTCSS or DCS

* Improve DCS

* Update README
  • Loading branch information
armel authored Nov 20, 2024
1 parent 9fb8e0f commit 8d25c93
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ SA818: INFO: +DMOSETVOLUME:0 Volume level: 5

It is possible to specify a different CTCSS or DCS code for transmit and receive by separating the two codes by a comma (no spaces). For example, `--ctcss 100,88.5` will set the CTCSS 100Hz for transmit and 88.5Hz for receive.

> [!NOTE]
> It is also possible to specify CTCSS or DCS on transmit or receive only. For example, `--ctcss 100,None` will set the CTCSS 100Hz for transmit only (nothing for receive).
## Usage

This program has for sections:
Expand Down
55 changes: 32 additions & 23 deletions sa818.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
)

DCS_CODES = [
"None",
"023", "025", "026", "031", "032", "036", "043", "047", "051", "053", "054",
"065", "071", "072", "073", "074", "114", "115", "116", "125", "131", "132",
"134", "143", "152", "155", "156", "162", "165", "172", "174", "205", "223",
Expand Down Expand Up @@ -157,9 +158,11 @@ def set_radio(self, frequency, offset, bw, squelch, ctcss, dcs, tail):
logger.info(msg, response, bw_label, rx_freq, tx_freq,
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"
tx_tone_display = None if tx_tone == '0000' else tx_tone
rx_tone_display = None if rx_tone == '0000' else rx_tone
msg = "%s, BW: %s Frequency (RX: %s / TX: %s), DCS (TX: %s / RX: %s), squelch: %s, OK"
logger.info(msg, response, bw_label, rx_freq, tx_freq,
tx_tone, rx_tone, squelch)
tx_tone_display, rx_tone_display, 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, squelch)
Expand Down Expand Up @@ -227,15 +230,18 @@ def type_ctcss(parg):
raise argparse.ArgumentError from None

for code in codes:
try:
ctcss = str(float(code))
if ctcss not in CTCSS:
raise ValueError
ctcss = CTCSS.index(ctcss)
tone_codes.append(f"{ctcss:04d}")
except ValueError:
logger.error(err_msg)
raise argparse.ArgumentTypeError from None
if code.lower() == "none":
tone_codes.append("0000") # No CTCSS
else:
try:
ctcss = str(float(code))
if ctcss not in CTCSS:
raise ValueError
ctcss = CTCSS.index(ctcss)
tone_codes.append(f"{ctcss:04d}")
except ValueError:
logger.error(err_msg)
raise argparse.ArgumentTypeError from None

return tone_codes

Expand All @@ -251,19 +257,22 @@ def type_dcs(parg):
raise argparse.ArgumentError from None

for code in codes:
if code[-1] not in ('N', 'I'):
logger.error(err_msg)
raise argparse.ArgumentError from None

code, direction = code[:-1], code[-1]
try:
dcs = f"{int(code):03d}"
if dcs not in DCS_CODES:
if code.lower() == "none":
dcs_codes.append("0000") # No DCS
else:
if code[-1] not in ('N', 'I'):
logger.error(err_msg)
raise argparse.ArgumentError
except ValueError:
raise argparse.ArgumentTypeError from None
dcs_codes.append(dcs + direction)
raise argparse.ArgumentError from None

code, direction = code[:-1], code[-1]
try:
dcs = f"{int(code):03d}"
if dcs not in DCS_CODES:
logger.error(err_msg)
raise argparse.ArgumentError
except ValueError:
raise argparse.ArgumentTypeError from None
dcs_codes.append(dcs + direction)

return dcs_codes

Expand Down

0 comments on commit 8d25c93

Please sign in to comment.