From 1ce9ea6214ba8eed6c3a6fdffb5f6bdea34773c4 Mon Sep 17 00:00:00 2001 From: mbridak Date: Tue, 21 May 2024 09:53:19 -0700 Subject: [PATCH] Add sending CW via rigctld. --- fdlogger/__main__.py | 78 +++++++++++++++++++++++++++++------ fdlogger/data/settings.ui | 59 +++++++++++++++----------- fdlogger/lib/cat_interface.py | 29 +++++++++++++ fdlogger/lib/settings.py | 5 +++ 4 files changed, 136 insertions(+), 35 deletions(-) diff --git a/fdlogger/__main__.py b/fdlogger/__main__.py index 70b7115..605ce09 100644 --- a/fdlogger/__main__.py +++ b/fdlogger/__main__.py @@ -1215,7 +1215,11 @@ def sendf1(self): self.infoline.setText(f"Sending {self.process_macro(self.F1.toolTip())}") if self.preference.get("send_n1mm_packets"): self.n1mm.radio_info["FunctionKeyCaption"] = self.F1.text() - self.cw.sendcw(f"{self.process_macro(self.F1.toolTip())} ") + if self.cw.servertype == 3: + if self.cat_control is not None: + self.cat_control.sendcw(f"{self.process_macro(self.F1.toolTip())} ") + else: + self.cw.sendcw(f"{self.process_macro(self.F1.toolTip())} ") def sendf2(self): """send f2""" @@ -1223,7 +1227,11 @@ def sendf2(self): self.infoline.setText(f"Sending {self.process_macro(self.F2.toolTip())}") if self.preference.get("send_n1mm_packets"): self.n1mm.radio_info["FunctionKeyCaption"] = self.F2.text() - self.cw.sendcw(f"{self.process_macro(self.F2.toolTip())} ") + if self.cw.servertype == 3: + if self.cat_control is not None: + self.cat_control.sendcw(f"{self.process_macro(self.F2.toolTip())} ") + else: + self.cw.sendcw(f"{self.process_macro(self.F2.toolTip())} ") def sendf3(self): """send f3""" @@ -1231,7 +1239,11 @@ def sendf3(self): self.infoline.setText(f"Sending {self.process_macro(self.F3.toolTip())}") if self.preference.get("send_n1mm_packets"): self.n1mm.radio_info["FunctionKeyCaption"] = self.F3.text() - self.cw.sendcw(f"{self.process_macro(self.F3.toolTip())} ") + if self.cw.servertype == 3: + if self.cat_control is not None: + self.cat_control.sendcw(f"{self.process_macro(self.F3.toolTip())} ") + else: + self.cw.sendcw(f"{self.process_macro(self.F3.toolTip())} ") def sendf4(self): """send f4""" @@ -1239,7 +1251,11 @@ def sendf4(self): self.infoline.setText(f"Sending {self.process_macro(self.F4.toolTip())}") if self.preference.get("send_n1mm_packets"): self.n1mm.radio_info["FunctionKeyCaption"] = self.F4.text() - self.cw.sendcw(f"{self.process_macro(self.F4.toolTip())} ") + if self.cw.servertype == 3: + if self.cat_control is not None: + self.cat_control.sendcw(f"{self.process_macro(self.F4.toolTip())} ") + else: + self.cw.sendcw(f"{self.process_macro(self.F4.toolTip())} ") def sendf5(self): """send f5""" @@ -1247,7 +1263,11 @@ def sendf5(self): self.infoline.setText(f"Sending {self.process_macro(self.F5.toolTip())}") if self.preference.get("send_n1mm_packets"): self.n1mm.radio_info["FunctionKeyCaption"] = self.F5.text() - self.cw.sendcw(f"{self.process_macro(self.F5.toolTip())} ") + if self.cw.servertype == 3: + if self.cat_control is not None: + self.cat_control.sendcw(f"{self.process_macro(self.F5.toolTip())} ") + else: + self.cw.sendcw(f"{self.process_macro(self.F5.toolTip())} ") def sendf6(self): """send f6""" @@ -1255,7 +1275,11 @@ def sendf6(self): self.infoline.setText(f"Sending {self.process_macro(self.F6.toolTip())}") if self.preference.get("send_n1mm_packets"): self.n1mm.radio_info["FunctionKeyCaption"] = self.F6.text() - self.cw.sendcw(f"{self.process_macro(self.F6.toolTip())} ") + if self.cw.servertype == 3: + if self.cat_control is not None: + self.cat_control.sendcw(f"{self.process_macro(self.F6.toolTip())} ") + else: + self.cw.sendcw(f"{self.process_macro(self.F6.toolTip())} ") def sendf7(self): """send f7""" @@ -1263,7 +1287,11 @@ def sendf7(self): self.infoline.setText(f"Sending {self.process_macro(self.F7.toolTip())}") if self.preference.get("send_n1mm_packets"): self.n1mm.radio_info["FunctionKeyCaption"] = self.F7.text() - self.cw.sendcw(f"{self.process_macro(self.F7.toolTip())} ") + if self.cw.servertype == 3: + if self.cat_control is not None: + self.cat_control.sendcw(f"{self.process_macro(self.F7.toolTip())} ") + else: + self.cw.sendcw(f"{self.process_macro(self.F7.toolTip())} ") def sendf8(self): """send f8""" @@ -1271,7 +1299,11 @@ def sendf8(self): self.infoline.setText(f"Sending {self.process_macro(self.F8.toolTip())}") if self.preference.get("send_n1mm_packets"): self.n1mm.radio_info["FunctionKeyCaption"] = self.F8.text() - self.cw.sendcw(f"{self.process_macro(self.F8.toolTip())} ") + if self.cw.servertype == 3: + if self.cat_control is not None: + self.cat_control.sendcw(f"{self.process_macro(self.F8.toolTip())} ") + else: + self.cw.sendcw(f"{self.process_macro(self.F8.toolTip())} ") def sendf9(self): """send f9""" @@ -1279,7 +1311,11 @@ def sendf9(self): self.infoline.setText(f"Sending {self.process_macro(self.F9.toolTip())}") if self.preference.get("send_n1mm_packets"): self.n1mm.radio_info["FunctionKeyCaption"] = self.F9.text() - self.cw.sendcw(f"{self.process_macro(self.F9.toolTip())} ") + if self.cw.servertype == 3: + if self.cat_control is not None: + self.cat_control.sendcw(f"{self.process_macro(self.F9.toolTip())} ") + else: + self.cw.sendcw(f"{self.process_macro(self.F9.toolTip())} ") def sendf10(self): """send f10""" @@ -1287,7 +1323,13 @@ def sendf10(self): self.infoline.setText(f"Sending {self.process_macro(self.F10.toolTip())}") if self.preference.get("send_n1mm_packets"): self.n1mm.radio_info["FunctionKeyCaption"] = self.F10.text() - self.cw.sendcw(f"{self.process_macro(self.F10.toolTip())} ") + if self.cw.servertype == 3: + if self.cat_control is not None: + self.cat_control.sendcw( + f"{self.process_macro(self.F10.toolTip())} " + ) + else: + self.cw.sendcw(f"{self.process_macro(self.F10.toolTip())} ") def sendf11(self): """send f11""" @@ -1295,7 +1337,13 @@ def sendf11(self): self.infoline.setText(f"Sending {self.process_macro(self.F11.toolTip())}") if self.preference.get("send_n1mm_packets"): self.n1mm.radio_info["FunctionKeyCaption"] = self.F11.text() - self.cw.sendcw(f"{self.process_macro(self.F11.toolTip())} ") + if self.cw.servertype == 3: + if self.cat_control is not None: + self.cat_control.sendcw( + f"{self.process_macro(self.F11.toolTip())} " + ) + else: + self.cw.sendcw(f"{self.process_macro(self.F11.toolTip())} ") def sendf12(self): """send f12""" @@ -1303,7 +1351,13 @@ def sendf12(self): self.infoline.setText(f"Sending {self.process_macro(self.F12.toolTip())}") if self.preference.get("send_n1mm_packets"): self.n1mm.radio_info["FunctionKeyCaption"] = self.F12.text() - self.cw.sendcw(f"{self.process_macro(self.F12.toolTip())} ") + if self.cw.servertype == 3: + if self.cat_control is not None: + self.cat_control.sendcw( + f"{self.process_macro(self.F12.toolTip())} " + ) + else: + self.cw.sendcw(f"{self.process_macro(self.F12.toolTip())} ") def clearinputs(self): """clear text entry fields""" diff --git a/fdlogger/data/settings.ui b/fdlogger/data/settings.ui index 0823fe9..f749dbf 100644 --- a/fdlogger/data/settings.ui +++ b/fdlogger/data/settings.ui @@ -520,8 +520,8 @@ color: rgb(211, 215, 207); CW - - + + JetBrains Mono @@ -529,15 +529,15 @@ color: rgb(211, 215, 207); - CW_Address: + CW_Port: Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + JetBrains Mono @@ -545,23 +545,23 @@ color: rgb(211, 215, 207); - CW_Port: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + localhost - - + + JetBrains Mono 12 + + Qt::ImhDigitsOnly + - cwdaemon + 6789 @@ -578,8 +578,8 @@ color: rgb(211, 215, 207); - - + + JetBrains Mono @@ -587,28 +587,41 @@ color: rgb(211, 215, 207); - None + cwdaemon - - + + JetBrains Mono 12 - - Qt::ImhDigitsOnly + + CW_Address: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + JetBrains Mono + 12 + - 6789 + None - - + + JetBrains Mono @@ -616,7 +629,7 @@ color: rgb(211, 215, 207); - localhost + CAT diff --git a/fdlogger/lib/cat_interface.py b/fdlogger/lib/cat_interface.py index 614aa71..43ac214 100644 --- a/fdlogger/lib/cat_interface.py +++ b/fdlogger/lib/cat_interface.py @@ -1,4 +1,5 @@ """CAT interface abstraction""" + import logging import socket import xmlrpc.client @@ -64,6 +65,34 @@ def __initialize_rigctrld(self): self.online = False self.logger.debug("%s", exception) + def sendcw(self, texttosend): + """...""" + self.logger.debug(f"{texttosend=} {self.interface=}") + if self.interface == "flrig": + ... + return + if self.interface == "rigctld": + self.sendcwrigctl(texttosend) + + def sendcwrigctl(self, texttosend): + """...""" + if self.rigctrlsocket: + try: + self.online = True + self.rigctrlsocket.send(bytes(f"b{texttosend}\n", "utf-8")) + _ = self.rigctrlsocket.recv(1024).decode().strip() + return True + except socket.error as exception: + self.online = False + self.logger.debug("setvfo_rigctld: %s", f"{exception}") + self.rigctrlsocket = None + return False + self.__initialize_rigctrld() + return False + + def sendcwxmlrpc(self, texttosend): + """...""" + def get_vfo(self) -> str: """Poll the radio for current vfo using the interface""" vfo = "" diff --git a/fdlogger/lib/settings.py b/fdlogger/lib/settings.py index 876658a..201b37a 100644 --- a/fdlogger/lib/settings.py +++ b/fdlogger/lib/settings.py @@ -60,6 +60,9 @@ def setup(self): self.usepywinkeyer_radioButton.setChecked( bool(self.preference.get("cwtype") == 2) ) + self.usecat4cw_radioButton.setChecked( + bool(self.preference.get("cwtype") == 3) + ) self.connect_to_server.setChecked(bool(self.preference.get("useserver"))) self.multicast_group.setText( str(self.preference.get("multicast_group", "")) @@ -110,6 +113,8 @@ def save_changes(self): self.preference["cwtype"] = 1 if self.usepywinkeyer_radioButton.isChecked(): self.preference["cwtype"] = 2 + if self.usecat4cw_radioButton.isChecked(): + self.preference["cwtype"] = 3 self.preference["useserver"] = self.connect_to_server.isChecked() self.preference["multicast_group"] = self.multicast_group.text() self.preference["multicast_port"] = self.multicast_port.text()