Merge pull request #1010 from DJ2LS/ls-rigctld

pull/1012/head
DJ2LS 2025-09-21 15:17:03 +02:00 committed by GitHub
commit a03b749e4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 114 additions and 27 deletions

View File

@ -736,6 +736,46 @@ const settings = ref({
</select>
</div>
<!-- PTT MODE -->
<div class="input-group input-group-sm mb-1">
<label class="input-group-text w-50 text-wrap">
{{ $t('settings.radio.hamlibrigctldpttmode') }}
<button
type="button"
class="btn btn-link p-0 ms-2"
data-bs-toggle="tooltip"
:title="$t('settings.radio.hamlibrigctldpttmode')"
>
<i class="bi bi-question-circle" />
</button>
</label>
<select
id="dtrSelect"
v-model="settings.remote.RADIO.ptt_mode"
class="form-select form-select-sm w-50"
@change="onChange"
>
<option
selected
value="ignore"
>
-- ignore --
</option>
<option value="TX">
TX
</option>
<option value="TX_MIC">
TX_MIC
</option>
<option value="TX_DATA">
TX_DATA
</option>
</select>
</div>
<!-- DCD -->
<div class="input-group input-group-sm mb-1">
<label class="input-group-text w-50 text-wrap">
@ -816,6 +856,40 @@ const settings = ref({
</select>
</div>
<!-- RTS -->
<div class="input-group input-group-sm mb-1">
<label class="input-group-text w-50 text-wrap">
{{ $t('settings.radio.hamlibrigctldrts') }}
<button
type="button"
class="btn btn-link p-0 ms-2"
data-bs-toggle="tooltip"
:title="$t('settings.radio.hamlibrigctldrts_help')"
>
<i class="bi bi-question-circle" />
</button>
</label>
<select
id="rtsSelect"
v-model="settings.remote.RADIO.serial_rts"
class="form-select form-select-sm w-50"
@change="onChange"
>
<option
selected
value="ignore"
>
-- ignore --
</option>
<option value="OFF">
OFF
</option>
<option value="ON">
ON
</option>
</select>
</div>
<!-- Rigctld Command -->
<div class="input-group input-group-sm mb-1">
<label class="input-group-text w-50 text-wrap">

View File

@ -361,12 +361,16 @@
"hamlibrigctlddcd_help": "Select the Data Carrier Detect method",
"hamlibrigctlddtr": "DTR",
"hamlibrigctlddtr_help": "Set the DTR line state",
"hamlibrigctldrts": "RTS",
"hamlibrigctldrts_help": "Set the RTS line state",
"hamlibrigctldcommand": "Rigctld command",
"hamlibrigctldcommand_help": "Auto-populated command based on settings",
"hamlibrigctldcommand_placeholder": "Auto-populated from above settings",
"hamlibrigctldcustomarguments": " Rigctld custom arguments",
"hamlibrigctldcustomarguments_help": "Additional arguments for rigctld (usually not needed)",
"hamlibrigctldcustomarguments_placeholder": "Optional custom arguments",
"hamlibrigctldpttmode": "PTT Mode",
"hamlibrigctldpttmode_help": "Set the PTT Mode, for some radios it isnt default (TX)",
"flrigport": "Flrig port",
"flrigport_help": "Set the port where the flrig server is listening (Default: 12345)",
"flrighost": "Flrig host",

View File

@ -43,6 +43,7 @@ const defaultConfig = {
serial_handshake: "",
ptt_port: "",
ptt_type: "",
ptt_mode: "",
serial_dcd: "",
serial_dtr: "",
serial_rts: "",

View File

@ -42,6 +42,7 @@ data_bits = 8
stop_bits = 1
serial_handshake = ignore
ptt_port = ignore
ptt_mode = TX
ptt_type = USB
serial_dcd = NONE
serial_dtr = OFF

View File

@ -43,6 +43,7 @@ class CONFIG:
'stop_bits': int,
'serial_handshake': str,
'ptt_port': str,
'ptt_mode': str,
'ptt_type': str,
'serial_dcd': str,
'serial_dtr': str,

View File

@ -2,6 +2,14 @@ import socket
import structlog
import helpers
import threading
from enum import IntEnum
class PTTMode(IntEnum):
RX = 0
TX = 1
TX_MIC = 2
TX_DATA = 3
class radio:
"""Controls a radio using rigctld.
@ -32,6 +40,7 @@ class radio:
self.ctx = ctx
self.hostname = self.ctx.config_manager.config['RIGCTLD']['ip']
self.port = self.ctx.config_manager.config['RIGCTLD']['port']
self.ptt_mode = self.ctx.config_manager.config['RADIO']['ptt_mode']
self.timeout = 3
self.rigctld_process = None
self.max_connection_attempts = 60
@ -228,34 +237,32 @@ class radio:
return command
def set_ptt(self, state):
"""Set the PTT (Push-to-Talk) state.
Args:
state (bool): True to enable PTT, False to disable.
if not self.connected:
return False
try:
if state:
try:
ptt_mode = int(PTTMode[self.ptt_mode])
except Exception:
self.log.warning("[RIGCTLD] Invalid or unset ptt_mode, falling back to TX (1)")
ptt_mode = PTTMode.TX
else:
ptt_mode = PTTMode.RX
Returns:
bool: True if the PTT state was set successfully, False otherwise.
"""
if self.connected:
try:
command = self.insert_vfo(f"T {int(ptt_mode)}")
self.send_command(command)
if state:
command = 'T 1'
else:
command = 'T 0'
# Parameter-Update
self.parameters['ptt'] = (ptt_mode in (PTTMode.TX, PTTMode.TX_MIC, PTTMode.TX_DATA))
command = self.insert_vfo(command)
self.send_command(command)
self.parameters['ptt'] = state # Update PTT state in parameters
return True
except Exception as err:
self.log.warning(f"[RIGCTLD] Error setting PTT state: {err}")
self.connected = False
return False
self.log.info(f"[RIGCTLD] Setting PTT: {ptt_mode.name} ({int(ptt_mode)})")
return True
except Exception as err:
self.log.warning(f"[RIGCTLD] Error setting PTT: {err}")
self.connected = False
return False
def set_mode(self, mode):
"""Set the mode.
@ -693,6 +700,9 @@ class radio:
if not should_ignore(config.get('serial_dtr')):
args += ['--set-conf', f'dtr_state={config["serial_dtr"]}']
if not should_ignore(config.get('serial_rts')):
args += ['--set-conf', f'rts_state={config["serial_rts"]}']
# Handling Data Bits and Stop Bits
if not should_ignore(config.get('data_bits')):
args += ['--set-conf', f'data_bits={config["data_bits"]}']
@ -702,10 +712,6 @@ class radio:
if self.ctx.config_manager.config['RIGCTLD']['enable_vfo']:
args += ['--vfo']
# Fixme #rts_state
# if not should_ignore(config.get('rts_state')):
# args += ['--set-conf', f'stop_bits={config["rts_state"]}']
# Handle custom arguments for rigctld
# Custom args are split via ' ' so python doesn't add extranaeous quotes on windows
args += config_rigctld["arguments"].split(" ")