mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
hotfix for rigctld
fixing wrong ip and improved error handling so rigctld is hopefully not crashing for the early testers out there
This commit is contained in:
parent
5bdd6c569e
commit
43aa469633
|
@ -74,7 +74,9 @@ class DATA():
|
||||||
if data[0] == 'CQ':
|
if data[0] == 'CQ':
|
||||||
# [0] CQ
|
# [0] CQ
|
||||||
self.transmit_cq()
|
self.transmit_cq()
|
||||||
|
|
||||||
elif data[0] == 'STOP':
|
elif data[0] == 'STOP':
|
||||||
|
# [0] STOP
|
||||||
self.stop_transmission()
|
self.stop_transmission()
|
||||||
|
|
||||||
elif data[0] == 'PING':
|
elif data[0] == 'PING':
|
||||||
|
|
128
tnc/rigctld.py
128
tnc/rigctld.py
|
@ -3,6 +3,7 @@ import socket
|
||||||
import structlog
|
import structlog
|
||||||
import log_handler
|
import log_handler
|
||||||
import logging
|
import logging
|
||||||
|
import time
|
||||||
# class taken from darsidelemm
|
# class taken from darsidelemm
|
||||||
# rigctl - https://github.com/darksidelemm/rotctld-web-gui/blob/master/rotatorgui.py#L35
|
# rigctl - https://github.com/darksidelemm/rotctld-web-gui/blob/master/rotatorgui.py#L35
|
||||||
#
|
#
|
||||||
|
@ -22,35 +23,38 @@ class radio():
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self.hostname = hostname
|
self.hostname = hostname
|
||||||
self.port = port
|
self.port = port
|
||||||
|
self.connection_attempts = 5
|
||||||
|
|
||||||
def open_rig(self, devicename, deviceport, hamlib_ptt_type, serialspeed, pttport, data_bits, stop_bits, handshake, rigctld_ip, rigctld_port):
|
def open_rig(self, devicename, deviceport, hamlib_ptt_type, serialspeed, pttport, data_bits, stop_bits, handshake, rigctld_ip, rigctld_port):
|
||||||
self.connect()
|
self.hostname = rigctld_ip
|
||||||
logging.debug(f"Rigctl intialized")
|
self.ip = rigctld_port
|
||||||
return True
|
|
||||||
|
|
||||||
|
if self.connect():
|
||||||
|
logging.debug(f"Rigctl intialized")
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
structlog.get_logger("structlog").error("[RIGCTLD] Can't connect to rigctld!", ip=self.hostname, port=self.port)
|
||||||
|
return False
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
""" Connect to rotctld instance """
|
""" Connect to rotctld instance """
|
||||||
try:
|
for a in range(0,self.connection_attempts):
|
||||||
self.sock.connect((self.hostname,self.port))
|
try:
|
||||||
self.connected = True
|
self.sock.connect((self.hostname,self.port))
|
||||||
structlog.get_logger("structlog").info("[RIGCTLD] Connected to rigctld!", ip=self.hostname, port=self.port)
|
self.connected = True
|
||||||
except:
|
structlog.get_logger("structlog").info("[RIGCTLD] Connected to rigctld!", attempt=a+1, ip=self.hostname, port=self.port)
|
||||||
# ConnectionRefusedError: [Errno 111] Connection refused
|
return True
|
||||||
structlog.get_logger("structlog").critical("[RIGCTLD] Could not connect to rigctld!", ip=self.hostname, port=self.port)
|
except:
|
||||||
|
# ConnectionRefusedError: [Errno 111] Connection refused
|
||||||
|
self.connected = False
|
||||||
|
structlog.get_logger("structlog").warning("[RIGCTLD] Re-Trying to establish a connection to rigctld!", attempt=a+1, ip=self.hostname, port=self.port)
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
ptt = self.get_ptt()
|
|
||||||
if ptt == None:
|
|
||||||
# Timeout!
|
|
||||||
self.close()
|
|
||||||
raise Exception("Timeout!")
|
|
||||||
|
|
||||||
else:
|
|
||||||
return ptt
|
|
||||||
|
|
||||||
|
|
||||||
def close_rig(self):
|
def close_rig(self):
|
||||||
self.sock.close()
|
self.sock.close()
|
||||||
|
self.connected = False
|
||||||
|
|
||||||
|
|
||||||
def send_command(self, command):
|
def send_command(self, command):
|
||||||
|
@ -58,35 +62,57 @@ class radio():
|
||||||
and return the return value.
|
and return the return value.
|
||||||
"""
|
"""
|
||||||
if self.connected:
|
if self.connected:
|
||||||
self.sock.sendall(command+b'\n')
|
try:
|
||||||
try:
|
self.sock.sendall(command+b'\n')
|
||||||
return self.sock.recv(1024)
|
except:
|
||||||
except:
|
structlog.get_logger("structlog").warning("[RIGCTLD] Command not executed!", command=command, ip=self.hostname, port=self.port)
|
||||||
return None
|
self.connected = False
|
||||||
|
|
||||||
def get_mode(self):
|
try:
|
||||||
data = self.send_command(b"m")
|
return self.sock.recv(1024)
|
||||||
data = data.split(b'\n')
|
except:
|
||||||
mode = data[0]
|
structlog.get_logger("structlog").warning("[RIGCTLD] No command response!", command=command, ip=self.hostname, port=self.port)
|
||||||
return mode.decode("utf-8")
|
self.connected = False
|
||||||
|
|
||||||
def get_bandwith(self):
|
|
||||||
data = self.send_command(b"m")
|
|
||||||
data = data.split(b'\n')
|
|
||||||
bandwith = data[1]
|
|
||||||
return bandwith.decode("utf-8")
|
|
||||||
|
|
||||||
def get_frequency(self):
|
|
||||||
frequency = self.send_command(b"f")
|
|
||||||
return frequency.decode("utf-8")
|
|
||||||
|
|
||||||
def get_ptt(self):
|
|
||||||
return self.send_command(b"t")
|
|
||||||
|
|
||||||
def set_ptt(self, state):
|
|
||||||
if state:
|
|
||||||
self.send_command(b"T 1")
|
|
||||||
else:
|
else:
|
||||||
self.send_command(b"T 0")
|
structlog.get_logger("structlog").error("[RIGCTLD] No connection to rigctl!", ip=self.hostname, port=self.port)
|
||||||
return state
|
self.connect()
|
||||||
|
|
||||||
|
def get_mode(self):
|
||||||
|
try:
|
||||||
|
data = self.send_command(b"m")
|
||||||
|
data = data.split(b'\n')
|
||||||
|
mode = data[0]
|
||||||
|
return mode.decode("utf-8")
|
||||||
|
except:
|
||||||
|
0
|
||||||
|
def get_bandwith(self):
|
||||||
|
try:
|
||||||
|
data = self.send_command(b"m")
|
||||||
|
data = data.split(b'\n')
|
||||||
|
bandwith = data[1]
|
||||||
|
return bandwith.decode("utf-8")
|
||||||
|
except:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def get_frequency(self):
|
||||||
|
try:
|
||||||
|
frequency = self.send_command(b"f")
|
||||||
|
return frequency.decode("utf-8")
|
||||||
|
except:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def get_ptt(self):
|
||||||
|
try:
|
||||||
|
return self.send_command(b"t")
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def set_ptt(self, state):
|
||||||
|
try:
|
||||||
|
if state:
|
||||||
|
self.send_command(b"T 1")
|
||||||
|
else:
|
||||||
|
self.send_command(b"T 0")
|
||||||
|
return state
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
|
@ -94,6 +94,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
|
||||||
|
|
||||||
if data.startswith(b'{"type"') and data.endswith(b'}\n'):
|
if data.startswith(b'{"type"') and data.endswith(b'}\n'):
|
||||||
data = data[:-1] # remove b'\n'
|
data = data[:-1] # remove b'\n'
|
||||||
|
print(data)
|
||||||
if self.server.server_address[1] == static.PORT:
|
if self.server.server_address[1] == static.PORT:
|
||||||
process_tnc_commands(data)
|
process_tnc_commands(data)
|
||||||
else:
|
else:
|
||||||
|
@ -145,7 +146,7 @@ def process_tnc_commands(data):
|
||||||
if received_json["command"] == "STOP_BEACON":
|
if received_json["command"] == "STOP_BEACON":
|
||||||
static.BEACON_STATE = False
|
static.BEACON_STATE = False
|
||||||
structlog.get_logger("structlog").warning("[TNC] Stopping beacon!")
|
structlog.get_logger("structlog").warning("[TNC] Stopping beacon!")
|
||||||
data_handler.DATA_QUEUE_TRANSMIT.put(['BEACON', interval, False])
|
data_handler.DATA_QUEUE_TRANSMIT.put(['BEACON', None, False])
|
||||||
|
|
||||||
|
|
||||||
# PING ----------------------------------------------------------
|
# PING ----------------------------------------------------------
|
||||||
|
@ -404,7 +405,6 @@ def send_daemon_state():
|
||||||
|
|
||||||
python_version = str(sys.version_info[0]) + "." + str(sys.version_info[1])
|
python_version = str(sys.version_info[0]) + "." + str(sys.version_info[1])
|
||||||
|
|
||||||
|
|
||||||
output = {
|
output = {
|
||||||
'COMMAND': 'DAEMON_STATE',
|
'COMMAND': 'DAEMON_STATE',
|
||||||
'DAEMON_STATE': [],
|
'DAEMON_STATE': [],
|
||||||
|
|
Loading…
Reference in a new issue