2022-01-18 18:38:05 +00:00
|
|
|
# Intially created by Franco Spinelli, IW2DHW, 01/2022
|
|
|
|
# Updated by DJ2LS
|
|
|
|
#
|
2021-12-28 16:05:48 +00:00
|
|
|
# versione mia di rig.py per gestire Ft897D tramite rigctl e senza
|
|
|
|
# fare alcun riferimento alla configurazione
|
|
|
|
#
|
|
|
|
# e' una pezza clamorosa ma serve per poter provare on-air il modem
|
|
|
|
#
|
2022-05-11 22:10:59 +00:00
|
|
|
import os
|
2021-12-28 16:05:48 +00:00
|
|
|
import subprocess
|
2022-01-07 16:42:11 +00:00
|
|
|
import sys
|
2022-05-11 22:10:59 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
import structlog
|
|
|
|
|
2021-12-28 16:05:48 +00:00
|
|
|
# for rig_model -> rig_number only
|
|
|
|
|
2022-01-18 18:38:05 +00:00
|
|
|
# set global hamlib version
|
|
|
|
hamlib_version = 0
|
2022-05-09 00:41:49 +00:00
|
|
|
|
2022-05-09 01:27:24 +00:00
|
|
|
|
2021-12-28 16:05:48 +00:00
|
|
|
class radio:
|
2022-03-04 15:50:32 +00:00
|
|
|
""" """
|
2022-05-26 01:23:30 +00:00
|
|
|
|
2022-06-01 00:35:35 +00:00
|
|
|
log = structlog.get_logger("radio (rigctl)")
|
2022-05-26 01:23:30 +00:00
|
|
|
|
2021-12-28 16:05:48 +00:00
|
|
|
def __init__(self):
|
2022-05-26 01:23:30 +00:00
|
|
|
self.devicename = ""
|
|
|
|
self.devicenumber = ""
|
|
|
|
self.deviceport = ""
|
|
|
|
self.serialspeed = ""
|
|
|
|
self.hamlib_ptt_type = ""
|
|
|
|
self.my_rig = ""
|
|
|
|
self.pttport = ""
|
|
|
|
self.data_bits = ""
|
|
|
|
self.stop_bits = ""
|
|
|
|
self.handshake = ""
|
|
|
|
self.cmd = ""
|
|
|
|
|
|
|
|
def open_rig(
|
|
|
|
self,
|
|
|
|
devicename,
|
|
|
|
deviceport,
|
|
|
|
hamlib_ptt_type,
|
|
|
|
serialspeed,
|
|
|
|
pttport,
|
|
|
|
data_bits,
|
|
|
|
stop_bits,
|
|
|
|
handshake,
|
|
|
|
rigctld_ip,
|
|
|
|
rigctld_port,
|
|
|
|
):
|
2022-03-04 15:50:32 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
Args:
|
2022-05-09 00:41:49 +00:00
|
|
|
devicename:
|
|
|
|
deviceport:
|
|
|
|
hamlib_ptt_type:
|
|
|
|
serialspeed:
|
|
|
|
pttport:
|
|
|
|
data_bits:
|
|
|
|
stop_bits:
|
|
|
|
handshake:
|
|
|
|
rigctld_ip:
|
|
|
|
rigctld_port:
|
2022-03-04 15:50:32 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
2021-12-28 16:05:48 +00:00
|
|
|
self.devicename = devicename
|
|
|
|
self.deviceport = deviceport
|
2022-05-26 01:23:30 +00:00
|
|
|
# we need to ensure this is a str, otherwise set_conf functions are crashing
|
|
|
|
self.serialspeed = str(serialspeed)
|
2021-12-28 16:05:48 +00:00
|
|
|
self.hamlib_ptt_type = hamlib_ptt_type
|
|
|
|
self.pttport = pttport
|
|
|
|
self.data_bits = data_bits
|
|
|
|
self.stop_bits = stop_bits
|
|
|
|
self.handshake = handshake
|
2022-05-09 00:41:49 +00:00
|
|
|
|
2022-05-26 01:23:30 +00:00
|
|
|
# check if we are running in a pyinstaller environment
|
2022-05-11 22:10:59 +00:00
|
|
|
if hasattr(sys, "_MEIPASS"):
|
|
|
|
sys.path.append(getattr(sys, "_MEIPASS"))
|
|
|
|
else:
|
|
|
|
sys.path.append(os.path.abspath("."))
|
2022-05-09 00:41:49 +00:00
|
|
|
|
2021-12-28 16:05:48 +00:00
|
|
|
# get devicenumber by looking for deviceobject in Hamlib module
|
|
|
|
try:
|
|
|
|
import Hamlib
|
2022-05-26 01:23:30 +00:00
|
|
|
|
2021-12-28 16:05:48 +00:00
|
|
|
self.devicenumber = int(getattr(Hamlib, self.devicename))
|
2022-05-26 01:23:30 +00:00
|
|
|
except Exception as err:
|
2021-12-28 16:05:48 +00:00
|
|
|
if int(self.devicename):
|
|
|
|
self.devicenumber = int(self.devicename)
|
|
|
|
else:
|
2022-05-26 01:23:30 +00:00
|
|
|
self.devicenumber = 6 # dummy
|
|
|
|
self.log.warning("[RIGCTL] Radio not found. Using DUMMY!", error=err)
|
2022-05-09 00:41:49 +00:00
|
|
|
|
2022-01-18 18:38:05 +00:00
|
|
|
# set deviceport to dummy port, if we selected dummy model
|
2022-05-26 01:23:30 +00:00
|
|
|
if self.devicenumber in {1, 6}:
|
|
|
|
self.deviceport = "/dev/ttyUSB0"
|
2022-05-09 00:41:49 +00:00
|
|
|
|
2022-04-11 09:03:54 +00:00
|
|
|
print(self.devicenumber, self.deviceport, self.serialspeed)
|
2022-01-12 06:27:42 +00:00
|
|
|
|
2022-01-07 16:42:11 +00:00
|
|
|
# select precompiled executable for win32/win64 rigctl
|
|
|
|
# this is really a hack...somewhen we need a native hamlib integration for windows
|
2022-05-26 01:23:30 +00:00
|
|
|
if sys.platform in ["win32", "win64"]:
|
|
|
|
self.cmd = (
|
|
|
|
app_path
|
|
|
|
+ "lib\\hamlib\\"
|
|
|
|
+ sys.platform
|
|
|
|
+ (
|
|
|
|
f"\\rigctl -m {self.devicenumber} "
|
|
|
|
f"-r {self.deviceport} "
|
|
|
|
f"-s {int(self.serialspeed)} "
|
|
|
|
)
|
|
|
|
)
|
2022-05-09 00:41:49 +00:00
|
|
|
|
2022-01-07 16:42:11 +00:00
|
|
|
else:
|
2022-05-26 01:23:30 +00:00
|
|
|
self.cmd = "rigctl -m %d -r %s -s %d " % (
|
|
|
|
self.devicenumber,
|
|
|
|
self.deviceport,
|
|
|
|
int(self.serialspeed),
|
|
|
|
)
|
2021-12-28 16:05:48 +00:00
|
|
|
|
|
|
|
# eseguo semplicemente rigctl con il solo comando T 1 o T 0 per
|
2022-05-09 00:41:49 +00:00
|
|
|
# il set e t per il get
|
2021-12-28 16:05:48 +00:00
|
|
|
|
|
|
|
# set ptt to false if ptt is stuck for some reason
|
|
|
|
self.set_ptt(False)
|
|
|
|
return True
|
2022-05-09 00:41:49 +00:00
|
|
|
|
2021-12-28 16:05:48 +00:00
|
|
|
def get_frequency(self):
|
2022-03-04 15:50:32 +00:00
|
|
|
""" """
|
2022-05-26 01:23:30 +00:00
|
|
|
cmd = f"{self.cmd} f"
|
|
|
|
sw_proc = subprocess.Popen(
|
|
|
|
cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True
|
|
|
|
)
|
2021-12-28 20:37:38 +00:00
|
|
|
time.sleep(0.5)
|
|
|
|
freq = sw_proc.communicate()[0]
|
2022-05-26 01:23:30 +00:00
|
|
|
# print("get_frequency", freq, sw_proc.communicate())
|
2022-02-24 09:13:00 +00:00
|
|
|
try:
|
|
|
|
return int(freq)
|
2022-05-26 01:23:30 +00:00
|
|
|
except Exception:
|
2022-02-24 09:13:00 +00:00
|
|
|
return False
|
|
|
|
|
2021-12-28 16:05:48 +00:00
|
|
|
def get_mode(self):
|
2022-03-04 15:50:32 +00:00
|
|
|
""" """
|
2022-05-28 12:08:33 +00:00
|
|
|
# (hamlib_mode, bandwidth) = self.my_rig.get_mode()
|
2022-05-26 01:23:30 +00:00
|
|
|
# return Hamlib.rig_strrmode(hamlib_mode)
|
2022-02-24 09:13:00 +00:00
|
|
|
try:
|
2022-05-26 01:23:30 +00:00
|
|
|
return "PKTUSB"
|
|
|
|
except Exception:
|
2022-02-24 09:13:00 +00:00
|
|
|
return False
|
|
|
|
|
2022-05-28 12:08:33 +00:00
|
|
|
def get_bandwidth(self):
|
2022-03-04 15:50:32 +00:00
|
|
|
""" """
|
2022-05-28 12:08:33 +00:00
|
|
|
# (hamlib_mode, bandwidth) = self.my_rig.get_mode()
|
2022-05-25 22:27:33 +00:00
|
|
|
bandwidth = 2700
|
2022-02-24 09:13:00 +00:00
|
|
|
|
|
|
|
try:
|
2022-05-25 22:27:33 +00:00
|
|
|
return bandwidth
|
2022-05-26 01:23:30 +00:00
|
|
|
except Exception:
|
2022-02-24 09:13:00 +00:00
|
|
|
return False
|
2021-12-28 16:05:48 +00:00
|
|
|
|
|
|
|
def set_mode(self, mode):
|
2022-03-04 15:50:32 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
Args:
|
2022-05-09 00:41:49 +00:00
|
|
|
mode:
|
2022-03-04 15:50:32 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
2021-12-28 16:05:48 +00:00
|
|
|
# non usata
|
|
|
|
return 0
|
2022-05-09 00:41:49 +00:00
|
|
|
|
2021-12-28 16:05:48 +00:00
|
|
|
def get_ptt(self):
|
2022-03-04 15:50:32 +00:00
|
|
|
""" """
|
2022-05-26 01:23:30 +00:00
|
|
|
cmd = f"{self.cmd} t"
|
|
|
|
sw_proc = subprocess.Popen(
|
|
|
|
cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True
|
|
|
|
)
|
2021-12-28 20:37:38 +00:00
|
|
|
time.sleep(0.5)
|
|
|
|
status = sw_proc.communicate()[0]
|
2022-02-24 09:13:00 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
return status
|
2022-05-26 01:23:30 +00:00
|
|
|
except Exception:
|
2022-02-24 09:13:00 +00:00
|
|
|
return False
|
2022-05-09 00:41:49 +00:00
|
|
|
|
2021-12-28 16:05:48 +00:00
|
|
|
def set_ptt(self, state):
|
2022-03-04 15:50:32 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
Args:
|
2022-05-09 00:41:49 +00:00
|
|
|
state:
|
2022-03-04 15:50:32 +00:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
"""
|
2022-05-26 01:23:30 +00:00
|
|
|
cmd = f"{self.cmd} T "
|
|
|
|
print("set_ptt", state)
|
|
|
|
cmd = f"{cmd}1" if state else f"{cmd}0"
|
|
|
|
print("set_ptt", cmd)
|
2021-12-28 16:05:48 +00:00
|
|
|
|
2022-05-09 00:41:49 +00:00
|
|
|
sw_proc = subprocess.Popen(cmd, shell=True, text=True)
|
2022-02-24 09:13:00 +00:00
|
|
|
try:
|
|
|
|
return state
|
2022-05-26 01:23:30 +00:00
|
|
|
except Exception:
|
2022-02-24 09:13:00 +00:00
|
|
|
return False
|
2022-05-09 00:41:49 +00:00
|
|
|
|
2021-12-28 16:05:48 +00:00
|
|
|
def close_rig(self):
|
2022-03-04 15:50:32 +00:00
|
|
|
""" """
|
2022-05-26 01:23:30 +00:00
|
|
|
# self.my_rig.close()
|
2021-12-28 16:05:48 +00:00
|
|
|
return
|