adjustments to cli tools

This commit is contained in:
DJ2LS 2022-12-15 17:14:34 +01:00
parent 9c8237f505
commit e672218594
3 changed files with 41 additions and 29 deletions

View file

@ -50,19 +50,22 @@ def main_menu():
main_menu()
elif option == 'STOP BEACON':
run_network_command(HOST, PORT, {"type": "broadcast", "command": "stop_beacon"})
return
else:
run_network_command(HOST, PORT, {"type": "broadcast", "command": "start_beacon", "parameter": str(option)})
return
elif option == 'PING':
pass
elif option == 'ARQ':
option, index = pick(['DISCONNECT', '----- BACK -----'], "Select ARQ command")
option, index = pick(['GET RX BUFFER', 'DISCONNECT', '----- BACK -----'], "Select ARQ command")
if option == '----- BACK -----':
main_menu()
elif option == 'GET RX BUFFER':
run_network_command(HOST, PORT, {"type": "get", "command": "rx_buffer"})
else:
run_network_command(HOST, PORT,{"type": "arq", "command": "disconnect"})

View file

@ -31,11 +31,35 @@ parser.add_argument('--host', dest="socket_host", default='localhost', help="Set
args = parser.parse_args()
ip, port = args.socket_host, args.socket_port
connected = True
data = bytes()
def decode_and_save_data(data):
decoded_data = base64.b64decode(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)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.connect((ip, port))
@ -59,28 +83,13 @@ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
if jsondata.get('status') == 'receiving':
log.info(jsondata)
if jsondata.get('command') == 'rx_buffer':
for rxdata in jsondata["data-array"]:
log.info(f"rx buffer {rxdata.get('uuid')}")
decode_and_save_data(rxdata.get('data'))
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])
decode_and_save_data(jsondata["data"])
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)

View file

@ -17,7 +17,7 @@ import time
# --------------------------------------------GET PARAMETER INPUTS
parser = argparse.ArgumentParser(description='Simons TEST TNC')
parser.add_argument('--port', dest="socket_port", default=3000, help="Set socket listening port.", type=int)
parser.add_argument('--host', dest="socket_host", default='192.168.178.86', help="Set the host, the socket is listening on.", type=str)
parser.add_argument('--host', dest="socket_host", default='localhost', help="Set the host, the socket is listening on.", type=str)
parser.add_argument('--file', dest="filename", default='', help="Select the file we want to send", type=str)
parser.add_argument('--msg', dest="chatmessage", default='file from cli tool', help="Additional text message appended to file", type=str)