FreeDATA/tools/freedata_cli_tools.py

104 lines
3.3 KiB
Python
Raw Normal View History

2022-12-10 09:52:03 +00:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: DJ2LS
"""
import argparse
import socket
import base64
import json
from pick import pick
import time
import sounddevice as sd
# --------------------------------------------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='localhost', help="Set the host, the socket is listening on.", type=str)
args = parser.parse_args()
HOST, PORT = args.socket_host, args.socket_port
2022-12-16 16:09:48 +00:00
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect to server
sock.connect((HOST, PORT))
2022-12-10 09:52:03 +00:00
def main_menu():
while True:
time.sleep(0.1)
title = 'Please select a command you want to run: '
options = ['BEACON', 'PING', 'ARQ', 'LIST AUDIO DEVICES']
option, index = pick(options, title)
# BEACON AREA
if option == 'BEACON':
option, index = pick(['5',
'10',
'15',
'30',
'45',
'60',
'90',
'120',
'300',
'600',
'900',
'1800',
'3600',
'STOP BEACON',
'----- BACK -----'], "Select beacon interval [seconds]")
if option == '----- BACK -----':
main_menu()
elif option == 'STOP BEACON':
2022-12-16 16:09:48 +00:00
run_network_command({"type": "broadcast", "command": "stop_beacon"})
2022-12-15 16:14:34 +00:00
2022-12-10 09:52:03 +00:00
else:
2022-12-16 16:09:48 +00:00
run_network_command({"type": "broadcast", "command": "start_beacon", "parameter": str(option)})
2022-12-10 09:52:03 +00:00
elif option == 'PING':
pass
elif option == 'ARQ':
2022-12-15 16:14:34 +00:00
option, index = pick(['GET RX BUFFER', 'DISCONNECT', '----- BACK -----'], "Select ARQ command")
2022-12-10 09:52:03 +00:00
if option == '----- BACK -----':
main_menu()
2022-12-15 16:14:34 +00:00
elif option == 'GET RX BUFFER':
2022-12-16 16:09:48 +00:00
run_network_command({"type": "get", "command": "rx_buffer"})
2022-12-10 09:52:03 +00:00
else:
2022-12-16 16:09:48 +00:00
run_network_command({"type": "arq", "command": "disconnect"})
2022-12-10 09:52:03 +00:00
elif option == 'LIST AUDIO DEVICES':
devices = sd.query_devices(device=None, kind=None)
device_list = []
for device in devices:
device_list.append(
f"{device['index']} - "
f"{sd.query_hostapis(device['hostapi'])['name']} - "
f"Channels (In/Out):{device['max_input_channels']}/{device['max_output_channels']} - "
f"{device['name']}")
device_list.append('----- BACK -----')
option, index = pick(device_list, "Audio devices")
if option == '----- BACK -----':
main_menu()
else:
2022-12-16 16:09:48 +00:00
print("no menu point found...")
2022-12-10 09:52:03 +00:00
2022-12-16 16:09:48 +00:00
def run_network_command(command):
2022-12-10 09:52:03 +00:00
command = json.dumps(command)
command = bytes(command + "\n", 'utf-8')
2022-12-16 16:09:48 +00:00
sock.sendall(command)
2022-12-10 09:52:03 +00:00
2022-12-16 16:09:48 +00:00
if __name__ == "__main__":
main_menu()