FreeDATA/modem/server_commands.py

96 lines
2.3 KiB
Python
Raw Normal View History

2023-11-09 09:37:45 +00:00
from queues import DATA_QUEUE_TRANSMIT
import base64
2023-11-09 14:48:10 +00:00
import structlog
import threading
from random import randrange
2023-11-09 14:48:10 +00:00
log = structlog.get_logger("COMMANDS")
2023-11-09 09:37:45 +00:00
2023-11-19 08:56:00 +00:00
def cqcqcq(data):
try:
DATA_QUEUE_TRANSMIT.put(["CQ"])
return
except Exception as err:
2023-11-19 08:56:00 +00:00
log.warning("[CMD] error while transmiting CQ", e=err, command=data)
2023-11-09 14:48:10 +00:00
def ping_ping(data):
try:
2023-11-18 17:14:23 +00:00
dxcallsign = data["dxcall"]
2023-11-09 14:48:10 +00:00
if not str(dxcallsign).strip():
return
DATA_QUEUE_TRANSMIT.put(["PING", None, dxcallsign])
except Exception as err:
log.warning(
"[CMD] PING command execution error", e=err, command=data
)
2023-11-19 04:06:03 +00:00
def beacon(data, interval=300):
beacon_state = data['enabled'] in [True]
2023-11-09 14:48:10 +00:00
log.info(
"[CMD] Changing beacon state", state=beacon_state
)
2023-11-19 04:06:03 +00:00
if (beacon_state):
DATA_QUEUE_TRANSMIT.put(["BEACON", interval, beacon_state])
else:
DATA_QUEUE_TRANSMIT.put(["BEACON", beacon_state])
def modem_send_test_frame():
log.info(
"[CMD] Send test frame"
)
DATA_QUEUE_TRANSMIT.put(["SEND_TEST_FRAME"])
def modem_arq_send_raw(data):
# wait some random time
threading.Event().wait(randrange(5, 25, 5) / 10.0)
base64data = data["data"]
# check if transmission uuid provided else set no-uuid
try:
arq_uuid = data["uuid"]
except Exception:
arq_uuid = "no-uuid"
if len(base64data) % 4:
raise TypeError
binarydata = base64.b64decode(base64data)
DATA_QUEUE_TRANSMIT.put(
["ARQ_RAW", binarydata, arq_uuid, data["mycallsign"], data["dxcallsign"]]
)
def modem_fec_transmit(data):
log.info(
"[CMD] Send fec frame"
)
mode = data["mode"]
wakeup = data["wakeup"]
base64data = data["payload"]
if len(base64data) % 4:
raise TypeError
payload = base64.b64decode(base64data)
try:
mycallsign = data["mycallsign"]
except:
mycallsign = None
DATA_QUEUE_TRANSMIT.put(["FEC", mode, wakeup, payload, mycallsign])
def modem_fec_is_writing(data):
try:
mycallsign = data["mycallsign"]
DATA_QUEUE_TRANSMIT.put(["FEC_IS_WRITING", mycallsign])
except Exception as err:
log.warning(
"[SCK] Send fec frame command execution error",
e=err,
command=data,
)