From 5d3bb69e0a8e3b4d58956c4f032d2fd6a0c3aedf Mon Sep 17 00:00:00 2001 From: dj2ls Date: Sun, 23 Jan 2022 08:38:02 +0100 Subject: [PATCH] better rigctld error handling --- gui/src/index.html | 4 +++- tnc/rig.py | 2 +- tnc/rigctld.py | 17 ++++++++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/gui/src/index.html b/gui/src/index.html index 20302d92..857b168f 100644 --- a/gui/src/index.html +++ b/gui/src/index.html @@ -638,7 +638,9 @@
+ IP + :
@@ -1144,4 +1146,4 @@
- \ No newline at end of file + diff --git a/tnc/rig.py b/tnc/rig.py index ba4954c8..fbad9ea6 100644 --- a/tnc/rig.py +++ b/tnc/rig.py @@ -63,7 +63,7 @@ except Exception as e: hamlib_version = hamlib_version.split(' ') if hamlib_version[1] == 'Hamlib': - structlog.get_logger("structlog").warning("[RIG] Rigctl found! Start daemon with parameter --rigctl", version=hamlib_version[2]) + structlog.get_logger("structlog").warning("[RIG] Rigctl found! Please try using this", version=hamlib_version[2]) sys.exit() else: raise Exception diff --git a/tnc/rigctld.py b/tnc/rigctld.py index c90e03fe..64764314 100644 --- a/tnc/rigctld.py +++ b/tnc/rigctld.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 import socket +import structlog +import log_handler import logging # class taken from darsidelemm # rigctl - https://github.com/darksidelemm/rotctld-web-gui/blob/master/rotatorgui.py#L35 @@ -17,7 +19,7 @@ class radio(): """ Open a connection to rotctld, and test it for validity """ self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.settimeout(timeout) - + self.connected = False self.hostname = hostname self.port = port @@ -29,12 +31,20 @@ class radio(): def connect(self): """ Connect to rotctld instance """ - self.sock.connect((self.hostname,self.port)) + try: + self.sock.connect((self.hostname,self.port)) + self.connected = True + structlog.get_logger("structlog").info("[RIGCTLD] Connected to rigctld!", ip=self.hostname, port=self.port) + except: + # ConnectionRefusedError: [Errno 111] Connection refused + structlog.get_logger("structlog").critical("[RIGCTLD] Could not connect to rigctld!", ip=self.hostname, port=self.port) + ptt = self.get_ptt() if ptt == None: # Timeout! self.close() raise Exception("Timeout!") + else: return ptt @@ -47,7 +57,8 @@ class radio(): """ Send a command to the connected rotctld instance, and return the return value. """ - self.sock.sendall(command+b'\n') + if self.connected: + self.sock.sendall(command+b'\n') try: return self.sock.recv(1024) except: