better rigctld error handling

This commit is contained in:
dj2ls 2022-01-23 08:38:02 +01:00
parent 77adabf450
commit 5d3bb69e0a
3 changed files with 18 additions and 5 deletions

View file

@ -638,7 +638,9 @@
</div>
<div id="radio-control-rigctld">
<div class="input-group input-group-sm mb-1">
<span class="input-group-text" id="basic-addon1">IP</span>
<input type="text" class="form-control" placeholder="rigctld IP" id="hamlib_rigctld_ip" aria-label="Device IP" aria-describedby="basic-addon1">
<span class="input-group-text" id="basic-addon1">:</span>
<input type="text" class="form-control" placeholder="rigctld port" id="hamlib_rigctld_port" aria-label="Device Port" aria-describedby="basic-addon1">
</div>
@ -1144,4 +1146,4 @@
</div>
</body>
</html>
</html>

View file

@ -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

View file

@ -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: