FreeDATA/modem/server_commands.py

70 lines
1.7 KiB
Python
Raw Normal View History

2023-11-09 09:37:45 +00:00
from queues import DATA_QUEUE_TRANSMIT
import base64
import helpers
2023-11-09 14:48:10 +00:00
import structlog
log = structlog.get_logger("COMMANDS")
2023-11-09 09:37:45 +00:00
2023-11-09 17:00:12 +00:00
def cqcqcq():
try:
DATA_QUEUE_TRANSMIT.put(["CQ"])
except Exception as err:
log.warning("[CMD] error while transmiting CQ", e=err)
2023-11-09 14:48:10 +00:00
def ping_ping(data):
try:
dxcallsign = data["dxcallsign"]
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
)
def beacon(data):
2023-11-09 17:00:12 +00:00
beacon_state = data['enabled'] in ['True']
2023-11-09 14:48:10 +00:00
#Beacon.beacon_state = beacon_state
log.info(
"[CMD] Changing beacon state", state=beacon_state
)
2023-11-09 21:11:53 +00:00
DATA_QUEUE_TRANSMIT.put(["BEACON", 300, beacon_state])
def modem_send_test_frame():
log.info(
"[CMD] Send test frame"
)
DATA_QUEUE_TRANSMIT.put(["SEND_TEST_FRAME"])
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,
)