dynamic view of serial devices

This commit is contained in:
DJ2LS 2021-09-04 22:13:15 +02:00 committed by GitHub
parent d1a4b6d39a
commit d0e07c0458
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,6 +19,7 @@ import os
import static import static
import psutil import psutil
import sys import sys
import serial.tools.list_ports
#PORT = 3001 #PORT = 3001
#TNCPROCESS = 0 #TNCPROCESS = 0
#TNCSTARTED = False #TNCSTARTED = False
@ -173,13 +174,14 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
if received_json["type"] == 'GET' and received_json["command"] == 'DAEMON_STATE': if received_json["type"] == 'GET' and received_json["command"] == 'DAEMON_STATE':
data = {'COMMAND' : 'DAEMON_STATE', 'DAEMON_STATE' : [], 'INPUT_DEVICES': [], 'OUTPUT_DEVICES': [],"CPU": str(psutil.cpu_percent()),"RAM": str(psutil.virtual_memory().percent), "VERSION": "0.1-prototype"} data = {'COMMAND' : 'DAEMON_STATE', 'DAEMON_STATE' : [], 'INPUT_DEVICES': [], 'OUTPUT_DEVICES': [], 'SERIAL_DEVICES': [], "CPU": str(psutil.cpu_percent()),"RAM": str(psutil.virtual_memory().percent), "VERSION": "0.1-prototype"}
if static.TNCSTARTED: if static.TNCSTARTED:
data["DAEMON_STATE"].append({"STATUS": "running"}) data["DAEMON_STATE"].append({"STATUS": "running"})
else: else:
data["DAEMON_STATE"].append({"STATUS": "stopped"}) data["DAEMON_STATE"].append({"STATUS": "stopped"})
# UPDATE LIST OF AUDIO DEVICES
p = pyaudio.PyAudio() p = pyaudio.PyAudio()
for i in range(0, p.get_device_count()): for i in range(0, p.get_device_count()):
@ -192,7 +194,10 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
if maxOutputChannels > 0: if maxOutputChannels > 0:
data["OUTPUT_DEVICES"].append({"ID": i, "NAME" : str(name)}) data["OUTPUT_DEVICES"].append({"ID": i, "NAME" : str(name)})
# UPDATE LIST OF SERIAL DEVICES
ports = serial.tools.list_ports.comports()
for port, desc, hwid in ports:
data["SERIAL_DEVICES"].append({"PORT": str(port), "DESCRIPTION" : str(desc)})
#print(data) #print(data)
jsondata = json.dumps(data) jsondata = json.dumps(data)