process rigctld response only if needed

This commit is contained in:
DJ2LS 2022-12-27 17:48:06 +01:00
parent d572772df3
commit 281731d890

View file

@ -101,7 +101,7 @@ class radio:
self.sock.close()
self.connected = False
def send_command(self, command) -> bytes:
def send_command(self, command, expect_answer) -> bytes:
"""Send a command to the connected rotctld instance,
and return the return value.
@ -122,7 +122,12 @@ class radio:
self.connected = False
try:
return self.connection.recv(16)
# recv seems to be blocking so in case of ptt we dont need the response
# maybe this speeds things up and avoids blocking states
if expect_answer:
return self.connection.recv(16)
else:
return True
except Exception:
self.log.warning(
"[RIGCTLD] No command response!",
@ -146,7 +151,7 @@ class radio:
def get_mode(self):
""" """
try:
data = self.send_command(b"m")
data = self.send_command(b"m", True)
data = data.split(b"\n")
data = data[0].decode("utf-8")
if 'RPRT' not in data:
@ -159,7 +164,7 @@ class radio:
def get_bandwidth(self):
""" """
try:
data = self.send_command(b"m")
data = self.send_command(b"m", True)
data = data.split(b"\n")
data = data[1].decode("utf-8")
@ -172,7 +177,7 @@ class radio:
def get_frequency(self):
""" """
try:
data = self.send_command(b"f")
data = self.send_command(b"f", True)
data = data.decode("utf-8")
if 'RPRT' not in data:
self.frequency = data
@ -184,7 +189,7 @@ class radio:
def get_ptt(self):
""" """
try:
return self.send_command(b"t")
return self.send_command(b"t", True)
except Exception:
return False
@ -199,9 +204,9 @@ class radio:
"""
try:
if state:
self.send_command(b"T 1")
self.send_command(b"T 1", False)
else:
self.send_command(b"T 0")
self.send_command(b"T 0", False)
return state
except Exception:
return False