mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
moved to hamlib binaries
This commit is contained in:
parent
1611886a06
commit
9061eef65a
|
@ -123,7 +123,7 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
print("STARTING TNC !!!!!")
|
print("STARTING TNC !!!!!")
|
||||||
print(received_json["parameter"][0])
|
print(received_json["parameter"][0])
|
||||||
#os.system("python3 main.py --rx 3 --tx 3 --deviceport /dev/ttyUSB0 --deviceid 2028")
|
#os.system("python3 main.py --rx 3 --tx 3 --deviceport /dev/ttyUSB0 --deviceid 2028")
|
||||||
print(DEBUG)
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
p = subprocess.Popen("exec python3 main.py --rx "+ str(rx_audio) +" --tx "+ str(tx_audio) +" --deviceport "+ str(deviceport) +" --deviceid "+ str(deviceid) + " --serialspeed "+ str(serialspeed) + " --ptt "+ str(ptt), shell=True)
|
p = subprocess.Popen("exec python3 main.py --rx "+ str(rx_audio) +" --tx "+ str(tx_audio) +" --deviceport "+ str(deviceport) +" --deviceid "+ str(deviceid) + " --serialspeed "+ str(serialspeed) + " --ptt "+ str(ptt), shell=True)
|
||||||
else:
|
else:
|
||||||
|
|
23
tnc/main.py
23
tnc/main.py
|
@ -11,7 +11,7 @@ Created on Tue Dec 22 16:58:45 2020
|
||||||
import argparse
|
import argparse
|
||||||
import threading
|
import threading
|
||||||
import static
|
import static
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -23,7 +23,7 @@ if __name__ == '__main__':
|
||||||
PARSER.add_argument('--tx', dest="audio_output_device", default=0, help="transmitting sound card", type=int)
|
PARSER.add_argument('--tx', dest="audio_output_device", default=0, help="transmitting sound card", type=int)
|
||||||
PARSER.add_argument('--port', dest="socket_port", default=3000, help="Socket port", type=int)
|
PARSER.add_argument('--port', dest="socket_port", default=3000, help="Socket port", type=int)
|
||||||
PARSER.add_argument('--deviceport', dest="hamlib_device_port", default="/dev/ttyUSB0", help="Socket port", type=str)
|
PARSER.add_argument('--deviceport', dest="hamlib_device_port", default="/dev/ttyUSB0", help="Socket port", type=str)
|
||||||
PARSER.add_argument('--deviceid', dest="hamlib_device_id", default=3011, help="Socket port", type=int)
|
PARSER.add_argument('--deviceid', dest="hamlib_device_id", default=3011, help="Socket port", type=str)
|
||||||
PARSER.add_argument('--serialspeed', dest="hamlib_serialspeed", default=9600, help="Serialspeed", type=str)
|
PARSER.add_argument('--serialspeed', dest="hamlib_serialspeed", default=9600, help="Serialspeed", type=str)
|
||||||
PARSER.add_argument('--ptt', dest="hamlib_ptt_type", default='RTS', help="PTT Type", type=str)
|
PARSER.add_argument('--ptt', dest="hamlib_ptt_type", default='RTS', help="PTT Type", type=str)
|
||||||
|
|
||||||
|
@ -54,3 +54,22 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
WATCHDOG_SERVER_THREAD = threading.Thread(target=helpers.watchdog, name="watchdog")
|
WATCHDOG_SERVER_THREAD = threading.Thread(target=helpers.watchdog, name="watchdog")
|
||||||
WATCHDOG_SERVER_THREAD.start()
|
WATCHDOG_SERVER_THREAD.start()
|
||||||
|
|
||||||
|
|
||||||
|
# Start RIGCTLD
|
||||||
|
|
||||||
|
if static.HAMLIB_PTT_TYPE == "RTS":
|
||||||
|
dtr_state = "OFF"
|
||||||
|
else:
|
||||||
|
dtr_state = "NONE"
|
||||||
|
|
||||||
|
command = "exec ./hamlib/linux/rigctld -r " + str(static.HAMLIB_DEVICE_PORT) + \
|
||||||
|
" -s "+ str(static.HAMLIB_SERIAL_SPEED) + \
|
||||||
|
" -P "+ str(static.HAMLIB_PTT_TYPE) + \
|
||||||
|
" -m "+ str(static.HAMLIB_DEVICE_ID) + \
|
||||||
|
" --set-conf=dtr_state=" + dtr_state
|
||||||
|
p = subprocess.Popen(command, shell=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
29
tnc/modem.py
29
tnc/modem.py
|
@ -21,9 +21,11 @@ import helpers
|
||||||
import static
|
import static
|
||||||
import data_handler
|
import data_handler
|
||||||
|
|
||||||
import Hamlib
|
#import Hamlib
|
||||||
|
|
||||||
|
import rigctld
|
||||||
|
|
||||||
|
rigctld = rigctld.Rigctld()
|
||||||
|
|
||||||
|
|
||||||
# test
|
# test
|
||||||
|
@ -103,7 +105,7 @@ class RF():
|
||||||
|
|
||||||
# --------------------------------------------CONFIGURE HAMLIB
|
# --------------------------------------------CONFIGURE HAMLIB
|
||||||
|
|
||||||
|
'''
|
||||||
# try to init hamlib
|
# try to init hamlib
|
||||||
try:
|
try:
|
||||||
Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE)
|
Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE)
|
||||||
|
@ -156,13 +158,14 @@ class RF():
|
||||||
except:
|
except:
|
||||||
print("can't open rig")
|
print("can't open rig")
|
||||||
|
|
||||||
|
'''
|
||||||
# --------------------------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------------------------
|
||||||
def ptt_and_wait(self, state):
|
def ptt_and_wait(self, state):
|
||||||
|
|
||||||
if state:
|
if state:
|
||||||
static.PTT_STATE = True
|
static.PTT_STATE = True
|
||||||
self.my_rig.set_ptt(self.hamlib_ptt_type, 1)
|
#self.my_rig.set_ptt(self.hamlib_ptt_type, 1)
|
||||||
|
rigctld.ptt_enable()
|
||||||
ptt_togle_timeout = time.time() + 0.1
|
ptt_togle_timeout = time.time() + 0.1
|
||||||
while time.time() < ptt_togle_timeout:
|
while time.time() < ptt_togle_timeout:
|
||||||
pass
|
pass
|
||||||
|
@ -174,8 +177,8 @@ class RF():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
static.PTT_STATE = False
|
static.PTT_STATE = False
|
||||||
self.my_rig.set_ptt(self.hamlib_ptt_type, 0)
|
#self.my_rig.set_ptt(self.hamlib_ptt_type, 0)
|
||||||
|
rigctld.ptt_disable()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -643,9 +646,17 @@ class RF():
|
||||||
static.SNR = 0
|
static.SNR = 0
|
||||||
|
|
||||||
def get_radio_stats(self):
|
def get_radio_stats(self):
|
||||||
static.HAMLIB_FREQUENCY = float(self.my_rig.get_freq()/1000)
|
#static.HAMLIB_FREQUENCY = float(self.my_rig.get_freq()/1000)
|
||||||
(hamlib_mode, static.HAMLIB_BANDWITH) = self.my_rig.get_mode()
|
#(hamlib_mode, static.HAMLIB_BANDWITH) = self.my_rig.get_mode()
|
||||||
static.HAMLIB_MODE = Hamlib.rig_strrmode(hamlib_mode)
|
#static.HAMLIB_MODE = Hamlib.rig_strrmode(hamlib_mode)
|
||||||
|
|
||||||
|
static.HAMLIB_FREQUENCY = rigctld.get_frequency()
|
||||||
|
static.HAMLIB_MODE = rigctld.get_mode()[0]
|
||||||
|
static.HAMLIB_BANDWITH = rigctld.get_mode()[1]
|
||||||
|
print(static.HAMLIB_MODE)
|
||||||
|
print(static.HAMLIB_FREQUENCY)
|
||||||
|
print(static.HAMLIB_BANDWITH)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def calculate_fft(self, data_in):
|
def calculate_fft(self, data_in):
|
||||||
|
|
85
tnc/rigctld.py
Normal file
85
tnc/rigctld.py
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import socket
|
||||||
|
import logging
|
||||||
|
|
||||||
|
# rigctl - https://github.com/darksidelemm/rotctld-web-gui/blob/master/rotatorgui.py#L35
|
||||||
|
# https://github.com/xssfox/freedv-tnc/blob/master/freedvtnc/rigctl.py
|
||||||
|
|
||||||
|
|
||||||
|
class Rigctld():
|
||||||
|
""" rotctld (hamlib) communication class """
|
||||||
|
# Note: This is a massive hack.
|
||||||
|
|
||||||
|
def __init__(self, hostname="localhost", port=4532, poll_rate=5, timeout=5):
|
||||||
|
""" Open a connection to rotctld, and test it for validity """
|
||||||
|
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
self.sock.settimeout(timeout)
|
||||||
|
|
||||||
|
self.hostname = hostname
|
||||||
|
self.port = port
|
||||||
|
self.connect()
|
||||||
|
logging.debug(f"Rigctl intialized")
|
||||||
|
|
||||||
|
def get_model(self):
|
||||||
|
""" Get the rotator model from rotctld """
|
||||||
|
model = self.send_command(b'_')
|
||||||
|
return model
|
||||||
|
|
||||||
|
def connect(self):
|
||||||
|
""" Connect to rotctld instance """
|
||||||
|
self.sock.connect((self.hostname,self.port))
|
||||||
|
model = self.get_model()
|
||||||
|
if model == None:
|
||||||
|
# Timeout!
|
||||||
|
self.close()
|
||||||
|
raise Exception("Timeout!")
|
||||||
|
else:
|
||||||
|
return model
|
||||||
|
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.sock.close()
|
||||||
|
|
||||||
|
|
||||||
|
def send_command(self, command):
|
||||||
|
""" Send a command to the connected rotctld instance,
|
||||||
|
and return the return value.
|
||||||
|
"""
|
||||||
|
self.sock.sendall(command+b'\n')
|
||||||
|
try:
|
||||||
|
return self.sock.recv(1024)
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def ptt_enable(self):
|
||||||
|
logging.debug(f"PTT enabled")
|
||||||
|
self.send_command(b"T 1")
|
||||||
|
|
||||||
|
def ptt_disable(self):
|
||||||
|
logging.debug(f"PTT disabled")
|
||||||
|
self.send_command(b"T 0")
|
||||||
|
|
||||||
|
def get_frequency(self):
|
||||||
|
data = self.send_command(b"f")
|
||||||
|
if data is not None:
|
||||||
|
data = data.split(b'\n')
|
||||||
|
try:
|
||||||
|
freq = int(data[0])
|
||||||
|
except:
|
||||||
|
freq = 0
|
||||||
|
print(data)
|
||||||
|
return freq
|
||||||
|
|
||||||
|
def get_mode(self):
|
||||||
|
data = self.send_command(b"m")
|
||||||
|
if data is not None:
|
||||||
|
data = data.split(b'\n')
|
||||||
|
try:
|
||||||
|
mode = str(data[0], "utf-8")
|
||||||
|
bandwith = int(data[1])
|
||||||
|
except:
|
||||||
|
print(data)
|
||||||
|
mode = '0'
|
||||||
|
bandwith = 0
|
||||||
|
return [mode, bandwith]
|
||||||
|
|
Loading…
Reference in a new issue