mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
first rigctl fallback thanks Franco
This commit is contained in:
parent
9cc24a54c8
commit
e4d36e5f21
7 changed files with 177 additions and 21 deletions
|
@ -20,9 +20,9 @@ import serial.tools.list_ports
|
||||||
import static
|
import static
|
||||||
import crcengine
|
import crcengine
|
||||||
import re
|
import re
|
||||||
import rig
|
|
||||||
import logging, structlog, log_handler
|
import logging, structlog, log_handler
|
||||||
|
|
||||||
|
|
||||||
log_handler.setup_logging("daemon")
|
log_handler.setup_logging("daemon")
|
||||||
# get python version, which is needed later for determining installation path
|
# get python version, which is needed later for determining installation path
|
||||||
python_version = str(sys.version_info[0]) + "." + str(sys.version_info[1])
|
python_version = str(sys.version_info[0]) + "." + str(sys.version_info[1])
|
||||||
|
@ -198,6 +198,13 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
options.append('--handshake')
|
options.append('--handshake')
|
||||||
options.append(handshake)
|
options.append(handshake)
|
||||||
|
|
||||||
|
if HAMLIB_USE_RIGCTL:
|
||||||
|
options.append('--rigctl')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# try running tnc from binary, else run from source
|
# try running tnc from binary, else run from source
|
||||||
# this helps running the tnc in a developer environment
|
# this helps running the tnc in a developer environment
|
||||||
|
@ -351,11 +358,19 @@ if __name__ == '__main__':
|
||||||
# --------------------------------------------GET PARAMETER INPUTS
|
# --------------------------------------------GET PARAMETER INPUTS
|
||||||
PARSER = argparse.ArgumentParser(description='Simons TEST TNC')
|
PARSER = argparse.ArgumentParser(description='Simons TEST TNC')
|
||||||
PARSER.add_argument('--port', dest="socket_port",default=3001, help="Socket port", type=int)
|
PARSER.add_argument('--port', dest="socket_port",default=3001, help="Socket port", type=int)
|
||||||
|
PARSER.add_argument('--rigctl', dest="hamlib_use_rigctl",action="store_true", default=False, help="force using of rigctl")
|
||||||
|
|
||||||
ARGS = PARSER.parse_args()
|
ARGS = PARSER.parse_args()
|
||||||
PORT = ARGS.socket_port
|
PORT = ARGS.socket_port
|
||||||
|
HAMLIB_USE_RIGCTL = ARGS.hamlib_use_rigctl
|
||||||
|
if HAMLIB_USE_RIGCTL:
|
||||||
|
structlog.get_logger("structlog").warning("using rigctl....")
|
||||||
|
import rigctl as rig
|
||||||
|
else:
|
||||||
|
structlog.get_logger("structlog").warning("using rig.......")
|
||||||
|
import rig
|
||||||
# --------------------------------------------START CMD SERVER
|
# --------------------------------------------START CMD SERVER
|
||||||
|
|
||||||
DAEMON_THREAD = threading.Thread(target=start_daemon, name="daemon")
|
DAEMON_THREAD = threading.Thread(target=start_daemon, name="daemon")
|
||||||
DAEMON_THREAD.start()
|
DAEMON_THREAD.start()
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,7 @@ if __name__ == '__main__':
|
||||||
PARSER.add_argument('--data_bits', dest="hamlib_data_bits", default="8", help="Hamlib data bits", type=str)
|
PARSER.add_argument('--data_bits', dest="hamlib_data_bits", default="8", help="Hamlib data bits", type=str)
|
||||||
PARSER.add_argument('--stop_bits', dest="hamlib_stop_bits", default="1", help="Hamlib stop bits", type=str)
|
PARSER.add_argument('--stop_bits', dest="hamlib_stop_bits", default="1", help="Hamlib stop bits", type=str)
|
||||||
PARSER.add_argument('--handshake', dest="hamlib_handshake", default="None", help="Hamlib handshake", type=str)
|
PARSER.add_argument('--handshake', dest="hamlib_handshake", default="None", help="Hamlib handshake", type=str)
|
||||||
|
PARSER.add_argument('--rigctl', dest="hamlib_use_rigctl", action="store_true", default=False, help="force using of rigctl")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ARGS = PARSER.parse_args()
|
ARGS = PARSER.parse_args()
|
||||||
|
@ -53,6 +52,8 @@ if __name__ == '__main__':
|
||||||
static.HAMLIB_DATA_BITS = ARGS.hamlib_data_bits
|
static.HAMLIB_DATA_BITS = ARGS.hamlib_data_bits
|
||||||
static.HAMLIB_STOP_BITS = ARGS.hamlib_stop_bits
|
static.HAMLIB_STOP_BITS = ARGS.hamlib_stop_bits
|
||||||
static.HAMLIB_HANDSHAKE = ARGS.hamlib_handshake
|
static.HAMLIB_HANDSHAKE = ARGS.hamlib_handshake
|
||||||
|
static.HAMLIB_USE_RIGCTL = ARGS.hamlib_use_rigctl
|
||||||
|
print(ARGS.hamlib_use_rigctl)
|
||||||
|
|
||||||
# we need to wait until we got all parameters from argparse first before we can load the other modules
|
# we need to wait until we got all parameters from argparse first before we can load the other modules
|
||||||
import sock
|
import sock
|
||||||
|
|
|
@ -21,6 +21,13 @@ import data_handler
|
||||||
import re
|
import re
|
||||||
import queue
|
import queue
|
||||||
import codec2
|
import codec2
|
||||||
|
|
||||||
|
print(static.HAMLIB_USE_RIGCTL)
|
||||||
|
if static.HAMLIB_USE_RIGCTL:
|
||||||
|
structlog.get_logger("structlog").warning("using rigctl....")
|
||||||
|
import rigctl as rig
|
||||||
|
else:
|
||||||
|
structlog.get_logger("structlog").warning("using rig.......")
|
||||||
import rig
|
import rig
|
||||||
|
|
||||||
# option for testing miniaudio instead of audioop for sample rate conversion
|
# option for testing miniaudio instead of audioop for sample rate conversion
|
||||||
|
|
49
tnc/rig.py
49
tnc/rig.py
|
@ -4,6 +4,7 @@ import sys
|
||||||
import re
|
import re
|
||||||
import logging, structlog, log_handler
|
import logging, structlog, log_handler
|
||||||
import atexit
|
import atexit
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
# try importing hamlib
|
# try importing hamlib
|
||||||
|
@ -29,9 +30,23 @@ try:
|
||||||
else:
|
else:
|
||||||
structlog.get_logger("structlog").warning("[TNC] Hamlib outdated", found=hamlib_version, recommend=min_hamlib_version)
|
structlog.get_logger("structlog").warning("[TNC] Hamlib outdated", found=hamlib_version, recommend=min_hamlib_version)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
structlog.get_logger("structlog").critical("[TNC] Hamlib not found", error=e)
|
structlog.get_logger("structlog").warning("[TNC] Python Hamlib binding not found", error=e)
|
||||||
|
try:
|
||||||
|
structlog.get_logger("structlog").warning("[TNC] Trying to open rigctl", error=e)
|
||||||
|
rigctl = subprocess.Popen("rigctl -V",shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True)
|
||||||
|
hamlib_version = rigctl.stdout.readline()
|
||||||
|
hamlib_version = hamlib_version.split(' ')
|
||||||
|
print(hamlib_version[0])
|
||||||
|
print(hamlib_version[1])
|
||||||
|
print(hamlib_version[2])
|
||||||
|
if hamlib_version[1] == 'Hamlib':
|
||||||
|
rigctl = True
|
||||||
|
print(hamlib_version)
|
||||||
|
else:
|
||||||
|
rigctl = False
|
||||||
|
raise Exception
|
||||||
|
except Exception as e:
|
||||||
|
structlog.get_logger("structlog").critical("[TNC] HAMLIB NOT INSTALLED", error=e)
|
||||||
|
|
||||||
class radio:
|
class radio:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -50,13 +65,13 @@ class radio:
|
||||||
def open_rig(self, devicename, deviceport, hamlib_ptt_type, serialspeed, pttport, data_bits, stop_bits, handshake):
|
def open_rig(self, devicename, deviceport, hamlib_ptt_type, serialspeed, pttport, data_bits, stop_bits, handshake):
|
||||||
|
|
||||||
self.devicename = devicename
|
self.devicename = devicename
|
||||||
self.deviceport = deviceport
|
self.deviceport = str(deviceport)
|
||||||
self.serialspeed = str(serialspeed) # we need to ensure this is a str, otherwise set_conf functions are crashing
|
self.serialspeed = str(serialspeed) # we need to ensure this is a str, otherwise set_conf functions are crashing
|
||||||
self.hamlib_ptt_type = hamlib_ptt_type
|
self.hamlib_ptt_type = str(hamlib_ptt_type)
|
||||||
self.pttport = pttport
|
self.pttport = str(pttport)
|
||||||
self.data_bits = data_bits
|
self.data_bits = str(data_bits)
|
||||||
self.stop_bits = stop_bits
|
self.stop_bits = str(stop_bits)
|
||||||
self.handshake = handshake
|
self.handshake = str(handshake)
|
||||||
|
|
||||||
|
|
||||||
# try to init hamlib
|
# try to init hamlib
|
||||||
|
@ -66,6 +81,7 @@ class radio:
|
||||||
# get devicenumber by looking for deviceobject in Hamlib module
|
# get devicenumber by looking for deviceobject in Hamlib module
|
||||||
try:
|
try:
|
||||||
self.devicenumber = int(getattr(Hamlib, self.devicename))
|
self.devicenumber = int(getattr(Hamlib, self.devicename))
|
||||||
|
print(self.devicenumber)
|
||||||
except:
|
except:
|
||||||
structlog.get_logger("structlog").error("[DMN] Hamlib: rig not supported...")
|
structlog.get_logger("structlog").error("[DMN] Hamlib: rig not supported...")
|
||||||
self.devicenumber = 0
|
self.devicenumber = 0
|
||||||
|
@ -81,6 +97,16 @@ class radio:
|
||||||
self.my_rig.set_conf("ptt_pathname", self.pttport)
|
self.my_rig.set_conf("ptt_pathname", self.pttport)
|
||||||
|
|
||||||
|
|
||||||
|
print(self.my_rig.get_conf("rig_pathname"))
|
||||||
|
print(self.my_rig.get_conf("retry"))
|
||||||
|
print(self.my_rig.get_conf("serial_speed"))
|
||||||
|
print(self.my_rig.get_conf("serial_handshake"))
|
||||||
|
print(self.my_rig.get_conf("stop_bits"))
|
||||||
|
print(self.my_rig.get_conf("data_bits"))
|
||||||
|
print(self.my_rig.get_conf("ptt_pathname"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if self.hamlib_ptt_type == 'RIG':
|
if self.hamlib_ptt_type == 'RIG':
|
||||||
self.hamlib_ptt_type = Hamlib.RIG_PTT_RIG
|
self.hamlib_ptt_type = Hamlib.RIG_PTT_RIG
|
||||||
self.my_rig.set_conf("ptt_type", 'RIG')
|
self.my_rig.set_conf("ptt_type", 'RIG')
|
||||||
|
@ -159,8 +185,9 @@ class radio:
|
||||||
(hamlib_mode, bandwith) = self.my_rig.get_mode()
|
(hamlib_mode, bandwith) = self.my_rig.get_mode()
|
||||||
return bandwith
|
return bandwith
|
||||||
|
|
||||||
def set_mode(self, mode):
|
# not needed yet beacuse of some possible problems
|
||||||
return 0
|
#def set_mode(self, mode):
|
||||||
|
# return 0
|
||||||
|
|
||||||
def get_ptt(self):
|
def get_ptt(self):
|
||||||
return self.my_rig.get_ptt()
|
return self.my_rig.get_ptt()
|
||||||
|
|
106
tnc/rigctl.py
Normal file
106
tnc/rigctl.py
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
#
|
||||||
|
import subprocess
|
||||||
|
#
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
import logging, structlog, log_handler
|
||||||
|
import atexit
|
||||||
|
# for rig_model -> rig_number only
|
||||||
|
|
||||||
|
|
||||||
|
class radio:
|
||||||
|
def __init__(self):
|
||||||
|
|
||||||
|
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 = ''
|
||||||
|
|
||||||
|
def open_rig(self, devicename, deviceport, hamlib_ptt_type, serialspeed, pttport, data_bits, stop_bits, handshake):
|
||||||
|
|
||||||
|
self.devicename = devicename
|
||||||
|
self.deviceport = deviceport
|
||||||
|
self.serialspeed = str(serialspeed) # we need to ensure this is a str, otherwise set_conf functions are crashing
|
||||||
|
self.hamlib_ptt_type = hamlib_ptt_type
|
||||||
|
self.pttport = pttport
|
||||||
|
self.data_bits = data_bits
|
||||||
|
self.stop_bits = stop_bits
|
||||||
|
self.handshake = handshake
|
||||||
|
|
||||||
|
# get devicenumber by looking for deviceobject in Hamlib module
|
||||||
|
try:
|
||||||
|
import Hamlib
|
||||||
|
self.devicenumber = int(getattr(Hamlib, self.devicename))
|
||||||
|
except:
|
||||||
|
if int(self.devicename):
|
||||||
|
self.devicenumber = int(self.devicename)
|
||||||
|
else:
|
||||||
|
self.devicenumber = 6
|
||||||
|
structlog.get_logger("structlog").warning("[TNC] RADIO NOT FOUND USING DUMMY!", error=e)
|
||||||
|
|
||||||
|
|
||||||
|
print(self.devicenumber, self.deviceport, self.serialspeed)
|
||||||
|
self.cmd = 'rigctl -m %d -r %s -s %d ' % (int(self.devicenumber), self.deviceport, int(self.serialspeed))
|
||||||
|
|
||||||
|
# eseguo semplicemente rigctl con il solo comando T 1 o T 0 per
|
||||||
|
# il set e t per il get
|
||||||
|
|
||||||
|
# set ptt to false if ptt is stuck for some reason
|
||||||
|
self.set_ptt(False)
|
||||||
|
return True
|
||||||
|
|
||||||
|
def get_frequency(self):
|
||||||
|
cmd = self.cmd + ' f'
|
||||||
|
sw_proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True)
|
||||||
|
command_channel = sw_proc.stdout
|
||||||
|
freq = command_channel.readline()
|
||||||
|
return int(freq)
|
||||||
|
|
||||||
|
def get_mode(self):
|
||||||
|
#(hamlib_mode, bandwith) = self.my_rig.get_mode()
|
||||||
|
#return Hamlib.rig_strrmode(hamlib_mode)
|
||||||
|
return 'PKTUSB'
|
||||||
|
|
||||||
|
def get_bandwith(self):
|
||||||
|
#(hamlib_mode, bandwith) = self.my_rig.get_mode()
|
||||||
|
bandwith = 2700
|
||||||
|
return bandwith
|
||||||
|
|
||||||
|
def set_mode(self, mode):
|
||||||
|
# non usata
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def get_ptt(self):
|
||||||
|
cmd = self.cmd + ' t'
|
||||||
|
sw_proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True)
|
||||||
|
command_channel = sw_proc.stdout
|
||||||
|
status = command_channel.readline()
|
||||||
|
return status
|
||||||
|
|
||||||
|
def set_ptt(self, state):
|
||||||
|
cmd = self.cmd + ' T '
|
||||||
|
print('set_ptt', state)
|
||||||
|
if state:
|
||||||
|
cmd = cmd + '1'
|
||||||
|
else:
|
||||||
|
cmd = cmd + '0'
|
||||||
|
print('set_ptt', cmd)
|
||||||
|
|
||||||
|
sw_proc = subprocess.Popen(cmd, shell=True, text=True)
|
||||||
|
return state
|
||||||
|
|
||||||
|
def close_rig(self):
|
||||||
|
#self.my_rig.close()
|
||||||
|
return
|
|
@ -337,8 +337,7 @@ def start_cmd_socket():
|
||||||
structlog.get_logger("structlog").info("[TNC] Starting TCP/IP socket", port=static.PORT)
|
structlog.get_logger("structlog").info("[TNC] Starting TCP/IP socket", port=static.PORT)
|
||||||
# https://stackoverflow.com/a/16641793
|
# https://stackoverflow.com/a/16641793
|
||||||
socketserver.TCPServer.allow_reuse_address = True
|
socketserver.TCPServer.allow_reuse_address = True
|
||||||
cmdserver = ThreadedTCPServer(
|
cmdserver = ThreadedTCPServer((static.HOST, static.PORT), ThreadedTCPRequestHandler)
|
||||||
(static.HOST, static.PORT), ThreadedTCPRequestHandler)
|
|
||||||
server_thread = threading.Thread(target=cmdserver.serve_forever)
|
server_thread = threading.Thread(target=cmdserver.serve_forever)
|
||||||
server_thread.daemon = True
|
server_thread.daemon = True
|
||||||
server_thread.start()
|
server_thread.start()
|
||||||
|
|
|
@ -43,7 +43,8 @@ HAMLIB_SERIAL_SPEED = '9600'
|
||||||
HAMLIB_PTT_PORT = '/dev/ttyUSB0'
|
HAMLIB_PTT_PORT = '/dev/ttyUSB0'
|
||||||
HAMLIB_STOP_BITS = '1'
|
HAMLIB_STOP_BITS = '1'
|
||||||
HAMLIB_DATA_BITS = '8'
|
HAMLIB_DATA_BITS = '8'
|
||||||
HANLIB_HANDSHAKE = 'None'
|
HAMLIB_HANDSHAKE = 'None'
|
||||||
|
HAMLIB_USE_RIGCTL = False
|
||||||
|
|
||||||
HAMLIB_FREQUENCY = 0
|
HAMLIB_FREQUENCY = 0
|
||||||
HAMLIB_MODE = ''
|
HAMLIB_MODE = ''
|
||||||
|
|
Loading…
Reference in a new issue