mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
updated network listener
This commit is contained in:
parent
1b1bb18bb2
commit
51d7c681a6
|
@ -17,10 +17,12 @@ import socket
|
|||
import structlog
|
||||
import queue
|
||||
import json
|
||||
|
||||
import base64
|
||||
|
||||
log = structlog.get_logger("CLIENT")
|
||||
|
||||
|
||||
split_char = b"\x00;"
|
||||
# --------------------------------------------GET PARAMETER INPUTS
|
||||
parser = argparse.ArgumentParser(description='Simons TEST TNC')
|
||||
parser.add_argument('--port', dest="socket_port", default=3000, help="Set the port, the socket is listening on.", type=int)
|
||||
|
@ -50,3 +52,31 @@ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
|||
|
||||
if jsondata.get('freedata') == "tnc-message":
|
||||
log.info(jsondata)
|
||||
|
||||
if jsondata.get('status') == 'receiving':
|
||||
log.info(jsondata)
|
||||
|
||||
if jsondata.get('status') == 'received':
|
||||
decoded_data = base64.b64decode(jsondata["data"])
|
||||
decoded_data = decoded_data.split(split_char)
|
||||
|
||||
if decoded_data[0] == b'm':
|
||||
print(jsondata)
|
||||
log.info(f"{jsondata.get('mycallsign')} <<< {jsondata.get('dxcallsign')}", uuid=decoded_data[3])
|
||||
log.info(f"{jsondata.get('mycallsign')} <<< {jsondata.get('dxcallsign')}", message=decoded_data[4])
|
||||
log.info(f"{jsondata.get('mycallsign')} <<< {jsondata.get('dxcallsign')}", filename=decoded_data[5])
|
||||
log.info(f"{jsondata.get('mycallsign')} <<< {jsondata.get('dxcallsign')}", filetype=decoded_data[6])
|
||||
log.info(f"{jsondata.get('mycallsign')} <<< {jsondata.get('dxcallsign')}", data=decoded_data[7])
|
||||
|
||||
try:
|
||||
filename = decoded_data[8].decode("utf-8") + "_" + decoded_data[5].decode("utf-8")
|
||||
|
||||
file = open(filename , "wb")
|
||||
file.write(decoded_data[7])
|
||||
file.close()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
else:
|
||||
print(decoded_data)
|
||||
|
||||
|
|
Loading…
Reference in a new issue