From 0dd3cd463502cb869a72672fa93cf1e317000b29 Mon Sep 17 00:00:00 2001 From: DJ2LS Date: Wed, 13 Oct 2021 20:19:54 +0200 Subject: [PATCH] added crc to device names in case of a Icom IC-705 we have the behavior, that this device will be recognized as two usb devices. In this case we need to have a way to select the correct one... --- tnc/daemon.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tnc/daemon.py b/tnc/daemon.py index 04f3cc5c..8dfd2791 100755 --- a/tnc/daemon.py +++ b/tnc/daemon.py @@ -19,6 +19,9 @@ import psutil import serial.tools.list_ports import pyaudio import static +import crcengine +crc_algorithm = crcengine.new('crc16-ccitt-false') # load crc8 library + def start_daemon(): @@ -186,8 +189,15 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler): # UPDATE LIST OF SERIAL DEVICES ports = serial.tools.list_ports.comports() for port, desc, hwid in ports: + + # calculate hex of hwid if we have unique names + crc_hwid = crc_algorithm(bytes(hwid, encoding='utf-8')) + crc_hwid = crc_hwid.to_bytes(2, byteorder='big') + crc_hwid = crc_hwid.hex() + description = desc + ' [' + crc_hwid + ']' + data["SERIAL_DEVICES"].append( - {"PORT": str(port), "DESCRIPTION": str(desc)}) + {"PORT": str(port), "DESCRIPTION": str(description) }) jsondata = json.dumps(data)