allow tnc starting and stopping rigctld

This commit is contained in:
DJ2LS 2023-10-08 21:09:30 +02:00
parent 17d012db9d
commit 53dd156a3d
5 changed files with 188 additions and 19 deletions

View file

@ -1,6 +1,9 @@
<script setup lang="ts">
import { saveSettingsToFile } from "../js/settingsHandler";
import { startRigctld, stopRigctld } from "../js/daemon.js";
import { setActivePinia } from "pinia";
import pinia from "../store/index";
setActivePinia(pinia);
@ -154,6 +157,7 @@ alert("not yet implemented")
class="btn btn-outline-success"
type="button"
id="hamlib_rigctld_start"
@click="startRigctld"
>
Start
</button>
@ -161,6 +165,8 @@ alert("not yet implemented")
class="btn btn-outline-danger"
type="button"
id="hamlib_rigctld_stop"
@click="stopRigctld"
>
Stop
</button>

View file

@ -75,7 +75,7 @@ client.on('close', function(data) {
*/
daemon.on("end", function (data) {
daemonLog.warn("daemon connection ended");
console.log("daemon connection ended");
daemon.destroy();
setTimeout(connectDAEMON, 500);
let Data = {
@ -285,10 +285,48 @@ function testHamlib(
writeDaemonCommand(json_command);
}
export function startRigctld() {
var json_command = JSON.stringify({
type: "set",
command: "start_rigctld",
parameter: [
{
hamlib_deviceid: settings.hamlib_deviceid,
hamlib_deviceport: settings.hamlib_deviceport,
hamlib_stop_bits: settings.hamlib_stop_bits,
hamlib_data_bits: settings.hamlib_data_bits,
hamlib_handshake: settings.hamlib_handshake,
hamlib_serialspeed: settings.hamlib_serialspeed,
hamlib_dtrstate: settings.hamlib_dtrstate,
hamlib_pttprotocol: settings.hamlib_pttprotocol,
hamlib_ptt_port: settings.hamlib_ptt_port,
hamlib_dcd: settings.hamlib_dcd,
hamlbib_serialspeed_ptt: settings.hamlib_serialspeed,
hamlib_rigctld_port: settings.hamlib_rigctld_port,
hamlib_rigctld_ip: settings.hamlib_rigctld_ip,
hamlib_rigctld_path: settings.hamlib_rigctld_path,
hamlib_rigctld_server_port: settings.hamlib_rigctld_server_port,
hamlib_rigctld_custom_args: settings.hamlib_rigctld_custom_args
},
],
});
console.log(json_command);
writeDaemonCommand(json_command);
}
export function stopRigctld(){
let command = '{"type" : "set", "command": "stop_rigctld"}';
writeDaemonCommand(command);
}
//Save myCall
function saveMyCall(callsign) {
//exports.saveMyCall = function (callsign) {
command =
let command =
'{"type" : "set", "command": "mycallsign" , "parameter": "' +
callsign +
'"}';
@ -298,24 +336,9 @@ function saveMyCall(callsign) {
// Save myGrid
//exports.saveMyGrid = function (grid) {
function saveMyGrid(grid) {
command =
let command =
'{"type" : "set", "command": "mygrid" , "parameter": "' + grid + '"}';
writeDaemonCommand(command);
}
ipcRenderer.on("action-update-daemon-ip", (event, arg) => {
daemon.destroy();
let Data = {
busy_state: "-",
arq_state: "-",
//channel_state: "-",
frequency: "-",
mode: "-",
bandwidth: "-",
dbfs_level: 0,
};
ipcRenderer.send("request-update-tnc-state", Data);
daemon_port = arg.port;
daemon_host = arg.adress;
connectDAEMON();
});

View file

@ -162,6 +162,29 @@ class DAEMON:
# data[11] rigctld_port
self.test_hamlib_ptt(data)
if data[0] == "START_RIGCTLD":
"""
data[0] START_RIGCTLD,
data[1] hamlib_deviceid,
data[2] hamlib_deviceport,
data[3] hamlib_stop_bits,
data[4] hamlib_data_bits,
data[5] hamlib_handshake,
data[6] hamlib_serialspeed,
data[7] hamlib_dtrstate,
data[8] hamlib_pttprotocol,
data[9] hamlib_ptt_port,
data[10] hamlib_dcd,
data[11] hamlbib_serialspeed_ptt,
data[12] hamlib_rigctld_port,
data[13] hamlib_rigctld_ip,
data[14] hamlib_rigctld_path,
data[15] hamlib_rigctld_server_port,
data[16] hamlib_rigctld_custom_args
"""
self.start_rigctld(data)
except Exception as err1:
self.log.error("[DMN] worker: Exception: ", e=err1)
@ -214,6 +237,32 @@ class DAEMON:
jsondata = json.dumps(response)
sock.SOCKET_QUEUE.put(jsondata)
def start_rigctld(self, data):
try:
command = []
if sys.platform in ["darwin"]:
# If the application is run as a bundle, the PyInstaller bootloader
# extends the sys module by a flag frozen=True and sets the app
# path into variable _MEIPASS'.
application_path = sys._MEIPASS
command.append("rigctld")
elif sys.platform in ["linux", "darwin"]:
command.append("rigctld")
elif sys.platform in ["win32", "win64"]:
command.append("rigctld.exe")
options = ""
command += options
proc = subprocess.Popen(command)
atexit.register(proc.kill)
except Exception as err:
self.log.info("[DMN] starting rigctld: ", e=err)
Daemon.rigctldrocess = proc
Daemon.rigctldstarted = True
def start_tnc(self, data):
self.log.warning("[DMN] Starting TNC", rig=data[5], port=data[6])

View file

@ -956,6 +956,12 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
if received_json["type"] == "set" and received_json["command"] == "stop_tnc":
self.daemon_stop_tnc(received_json)
if received_json["type"] == "set" and received_json["command"] == "start_rigctld":
self.daemon_start_rigctld(received_json)
if received_json["type"] == "set" and received_json["command"] == "stop_rigctld":
self.daemon_stop_rigctld(received_json)
def daemon_set_mycallsign(self, received_json):
try:
callsign = received_json["parameter"]
@ -1107,6 +1113,88 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
command_response("test_hamlib", False)
log.warning("[SCK] command execution error", e=err, command=received_json)
def daemon_start_rigctld(self, received_json):
"""
hamlib_deviceid: settings.hamlib_deviceid,
hamlib_deviceport: settings.hamlib_deviceport,
hamlib_stop_bits: settings.hamlib_stop_bits,
hamlib_data_bits: settings.hamlib_data_bits,
hamlib_handshake: settings.hamlib_handshake,
hamlib_serialspeed: settings.hamlib_serialspeed,
hamlib_dtrstate: settings.hamlib_dtrstate,
hamlib_pttprotocol: settings.hamlib_pttprotocol,
hamlib_ptt_port: settings.hamlib_ptt_port,
hamlib_dcd: settings.hamlib_dcd,
hamlbib_serialspeed_ptt: settings.hamlib_serialspeed,
hamlib_rigctld_port: settings.hamlib_rigctld_port,
hamlib_rigctld_ip: settings.hamlib_rigctld_ip,
hamlib_rigctld_path: settings.hamlib_rigctld_path,
hamlib_rigctld_server_port: settings.hamlib_rigctld_server_port,
hamlib_rigctld_custom_args: settings.hamlib_rigctld_custom_args
"""
try:
hamlib_deviceid = str(received_json["parameter"][0]["hamlib_deviceid"])
hamlib_deviceport = str(received_json["parameter"][0]["hamlib_deviceport"])
hamlib_stop_bits = str(received_json["parameter"][0]["hamlib_stop_bits"])
hamlib_data_bits = str(received_json["parameter"][0]["hamlib_data_bits"])
hamlib_handshake = str(received_json["parameter"][0]["hamlib_handshake"])
hamlib_serialspeed = str(received_json["parameter"][0]["hamlib_serialspeed"])
hamlib_dtrstate = str(received_json["parameter"][0]["hamlib_dtrstate"])
hamlib_pttprotocol = str(received_json["parameter"][0]["hamlib_pttprotocol"])
hamlib_ptt_port = str(received_json["parameter"][0]["hamlib_ptt_port"])
hamlib_dcd = str(received_json["parameter"][0]["hamlib_dcd"])
hamlbib_serialspeed_ptt = str(received_json["parameter"][0]["hamlib_serialspeed"])
hamlib_rigctld_port = str(received_json["parameter"][0]["hamlib_rigctld_port"])
hamlib_rigctld_ip = str(received_json["parameter"][0]["hamlib_rigctld_ip"])
hamlib_rigctld_path = str(received_json["parameter"][0]["hamlib_rigctld_path"])
hamlib_rigctld_server_port = str(received_json["parameter"][0]["hamlib_rigctld_server_port"])
hamlib_rigctld_custom_args = str(received_json["parameter"][0]["hamlib_rigctld_custom_args"])
DAEMON_QUEUE.put(
[
"START_RIGCTLD",
hamlib_deviceid,
hamlib_deviceport,
hamlib_stop_bits,
hamlib_data_bits,
hamlib_handshake,
hamlib_serialspeed,
hamlib_dtrstate,
hamlib_pttprotocol,
hamlib_ptt_port,
hamlib_dcd,
hamlbib_serialspeed_ptt,
hamlib_rigctld_port,
hamlib_rigctld_ip,
hamlib_rigctld_path,
hamlib_rigctld_server_port,
hamlib_rigctld_custom_args
]
)
command_response("start_rigctld", True)
except Exception as err:
command_response("start_rigctld", False)
log.warning("[SCK] command execution error", e=err, command=received_json)
def daemon_stop_rigctld(self, received_json):
try:
log.warning("[SCK] Stopping rigctld")
Daemon.rigctldprocess.kill()
# unregister process from atexit to avoid process zombies
atexit.unregister(Daemon.rigctldprocess.kill)
Daemon.rigctldstarted = False
command_response("stop_tnc", True)
except Exception as err:
command_response("stop_tnc", False)
log.warning("[SCK] command execution error", e=err, command=received_json)
def send_daemon_state():
"""

View file

@ -36,6 +36,7 @@ class ARQ:
# ARQ PROTOCOL VERSION
# v.5 - signalling frame uses datac0
# v.6 - signalling frame uses datac13
# v.7 - adjusting ARQ timeouts, not done yet
arq_protocol_version: int = 7
total_bytes: int = 0
speed_list = []
@ -73,7 +74,9 @@ class Channel:
@dataclass
class Daemon:
tncprocess: subprocess.Popen
rigctldprocess: subprocess.Popen
tncstarted: bool = False
rigctldstarted: bool = False
port: int = 3001
serial_devices = []