mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 10:04:33 +02:00
another adjustments to cli tools
This commit is contained in:
parent
e672218594
commit
12d1477c36
|
@ -430,9 +430,9 @@ class DATA:
|
|||
# add mycallsign and dxcallsign to network message if they not exist
|
||||
# and make sure we are not overwrite them if they exist
|
||||
try:
|
||||
if not "mycallsign" in jsondata:
|
||||
if "mycallsign" not in jsondata:
|
||||
jsondata["mycallsign"] = str(self.mycallsign, "UTF-8")
|
||||
if not "dxcallsign" in jsondata:
|
||||
if "dxcallsign" not in jsondata:
|
||||
jsondata["dxcallsign"] = str(static.DXCALLSIGN, "UTF-8")
|
||||
except Exception as e:
|
||||
self.log.debug("[TNC] error adding callsigns to network message", e=e)
|
||||
|
|
14
tnc/modem.py
14
tnc/modem.py
|
@ -329,11 +329,7 @@ class RF:
|
|||
threading.Event().wait(0.01)
|
||||
|
||||
# -----write
|
||||
if len(self.modoutqueue) <= 0 or self.mod_out_locked:
|
||||
# data_out48k = np.zeros(self.AUDIO_FRAMES_PER_BUFFER_RX, dtype=np.int16)
|
||||
pass
|
||||
|
||||
else:
|
||||
if len(self.modoutqueue) > 0 and not self.mod_out_locked:
|
||||
data_out48k = self.modoutqueue.popleft()
|
||||
# print(len(data_out48k))
|
||||
|
||||
|
@ -417,13 +413,11 @@ class RF:
|
|||
fsk_ldpc_0 = 200
|
||||
fsk_ldpc_1 = 201
|
||||
"""
|
||||
if mode == int(14):
|
||||
if mode == 14:
|
||||
freedv = self.freedv_datac0_tx
|
||||
elif mode == int(14):
|
||||
freedv = self.freedv_datac0_tx
|
||||
elif mode == int(10):
|
||||
elif mode == 10:
|
||||
freedv = self.freedv_datac1_tx
|
||||
elif mode == int(12):
|
||||
elif mode == 12:
|
||||
freedv = self.freedv_datac3_tx
|
||||
else:
|
||||
return False
|
||||
|
|
|
@ -90,6 +90,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
|
|||
client.send(sock_data)
|
||||
except Exception as err:
|
||||
self.log.info("[SCK] Connection lost", e=err)
|
||||
# TODO: Check if we really should set connection alive to false. This might disconnect all other clients as well...
|
||||
self.connection_alive = False
|
||||
except Exception as err:
|
||||
self.log.debug("[SCK] catch harmless RuntimeError: Set changed size during iteration", e=err)
|
||||
|
|
|
@ -20,6 +20,10 @@ parser.add_argument('--host', dest="socket_host", default='localhost', help="Set
|
|||
args = parser.parse_args()
|
||||
HOST, PORT = args.socket_host, args.socket_port
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
# Connect to server
|
||||
sock.connect((HOST, PORT))
|
||||
|
||||
|
||||
def main_menu():
|
||||
while True:
|
||||
|
@ -49,11 +53,10 @@ def main_menu():
|
|||
if option == '----- BACK -----':
|
||||
main_menu()
|
||||
elif option == 'STOP BEACON':
|
||||
run_network_command(HOST, PORT, {"type": "broadcast", "command": "stop_beacon"})
|
||||
run_network_command({"type": "broadcast", "command": "stop_beacon"})
|
||||
|
||||
else:
|
||||
run_network_command(HOST, PORT, {"type": "broadcast", "command": "start_beacon", "parameter": str(option)})
|
||||
|
||||
run_network_command({"type": "broadcast", "command": "start_beacon", "parameter": str(option)})
|
||||
|
||||
elif option == 'PING':
|
||||
pass
|
||||
|
@ -65,9 +68,9 @@ def main_menu():
|
|||
if option == '----- BACK -----':
|
||||
main_menu()
|
||||
elif option == 'GET RX BUFFER':
|
||||
run_network_command(HOST, PORT, {"type": "get", "command": "rx_buffer"})
|
||||
run_network_command({"type": "get", "command": "rx_buffer"})
|
||||
else:
|
||||
run_network_command(HOST, PORT,{"type": "arq", "command": "disconnect"})
|
||||
run_network_command({"type": "arq", "command": "disconnect"})
|
||||
|
||||
elif option == 'LIST AUDIO DEVICES':
|
||||
|
||||
|
@ -88,16 +91,14 @@ def main_menu():
|
|||
main_menu()
|
||||
|
||||
else:
|
||||
pass
|
||||
print("no menu point found...")
|
||||
|
||||
|
||||
def run_network_command(host, port, command):
|
||||
def run_network_command(command):
|
||||
command = json.dumps(command)
|
||||
command = bytes(command + "\n", 'utf-8')
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
||||
# Connect to server and send data
|
||||
sock.connect((host, port))
|
||||
sock.sendall(command)
|
||||
sock.sendall(command)
|
||||
|
||||
|
||||
main_menu()
|
||||
if __name__ == "__main__":
|
||||
main_menu()
|
|
@ -18,6 +18,7 @@ import structlog
|
|||
import queue
|
||||
import json
|
||||
import base64
|
||||
import os
|
||||
|
||||
log = structlog.get_logger("CLIENT")
|
||||
|
||||
|
@ -35,8 +36,8 @@ connected = True
|
|||
data = bytes()
|
||||
|
||||
|
||||
def decode_and_save_data(data):
|
||||
decoded_data = base64.b64decode(data)
|
||||
def decode_and_save_data(encoded_data):
|
||||
decoded_data = base64.b64decode(encoded_data)
|
||||
decoded_data = decoded_data.split(split_char)
|
||||
|
||||
if decoded_data[0] == b'm':
|
||||
|
@ -48,11 +49,17 @@ def decode_and_save_data(data):
|
|||
log.info(f"{jsondata.get('mycallsign')} <<< {jsondata.get('dxcallsign')}", data=decoded_data[7])
|
||||
|
||||
try:
|
||||
folderpath = "received"
|
||||
if not os.path.exists(folderpath):
|
||||
os.makedirs(folderpath)
|
||||
filename = decoded_data[8].decode("utf-8") + "_" + decoded_data[5].decode("utf-8")
|
||||
|
||||
file = open(filename, "wb")
|
||||
file.write(decoded_data[7])
|
||||
file.close()
|
||||
with open(f"{folderpath}/{filename}", "wb") as file:
|
||||
file.write(decoded_data[7])
|
||||
|
||||
with open(f"{folderpath}/{decoded_data[8].decode('utf-8')}_msg.txt", "wb") as file:
|
||||
file.write(decoded_data[4])
|
||||
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
@ -67,7 +74,7 @@ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
|||
chunk = sock.recv(2)
|
||||
data += chunk
|
||||
|
||||
if data.endswith(b'\n'):
|
||||
if data.startswith(b'{') and data.endswith(b'}\n'):
|
||||
|
||||
jsondata = json.loads(data.split(b'\n')[0])
|
||||
data = bytes()
|
||||
|
@ -92,4 +99,6 @@ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
|||
if jsondata.get('status') == 'received':
|
||||
decode_and_save_data(jsondata["data"])
|
||||
|
||||
# clear data buffer as soon as data has been read
|
||||
data = bytes()
|
||||
|
||||
|
|
Loading…
Reference in a new issue