mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
updated ptt
This commit is contained in:
parent
e803137f72
commit
c5d15017f2
3 changed files with 41 additions and 52 deletions
|
@ -20,8 +20,6 @@ import static
|
||||||
import psutil
|
import psutil
|
||||||
import sys
|
import sys
|
||||||
import serial.tools.list_ports
|
import serial.tools.list_ports
|
||||||
import atexit
|
|
||||||
|
|
||||||
#PORT = 3001
|
#PORT = 3001
|
||||||
#TNCPROCESS = 0
|
#TNCPROCESS = 0
|
||||||
#TNCSTARTED = False
|
#TNCSTARTED = False
|
||||||
|
@ -45,14 +43,10 @@ def start_daemon():
|
||||||
daemon = socketserver.TCPServer(('0.0.0.0', PORT), CMDTCPRequestHandler)
|
daemon = socketserver.TCPServer(('0.0.0.0', PORT), CMDTCPRequestHandler)
|
||||||
daemon.serve_forever()
|
daemon.serve_forever()
|
||||||
|
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
daemon.server_close()
|
daemon.server_close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
|
|
||||||
def handle(self):
|
def handle(self):
|
||||||
|
@ -122,37 +116,39 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
deviceid = received_json["parameter"][0]["deviceid"]
|
deviceid = received_json["parameter"][0]["deviceid"]
|
||||||
deviceport = received_json["parameter"][0]["deviceport"]
|
deviceport = received_json["parameter"][0]["deviceport"]
|
||||||
serialspeed = received_json["parameter"][0]["serialspeed"]
|
serialspeed = received_json["parameter"][0]["serialspeed"]
|
||||||
ptt = received_json["parameter"][0]["ptt"]
|
pttprotocol = received_json["parameter"][0]["pttprotocol"]
|
||||||
|
pttport = received_json["parameter"][0]["pttport"]
|
||||||
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")
|
||||||
|
|
||||||
|
|
||||||
# Start RIGCTLD
|
# Start RIGCTLD
|
||||||
|
|
||||||
if ptt == "RTS":
|
if pttprotocol == "RTS":
|
||||||
|
dtr_state = "OFF"
|
||||||
|
elif pttprotocol == "DTR":
|
||||||
dtr_state = "OFF"
|
dtr_state = "OFF"
|
||||||
else:
|
else:
|
||||||
dtr_state = "NONE"
|
dtr_state = "OFF"
|
||||||
|
|
||||||
|
|
||||||
if sys.platform == "linux":
|
if sys.platform == "linux":
|
||||||
# we need to make sure we have execution privileges
|
# we need to make sure we have execution privileges
|
||||||
#try:
|
p = subprocess.Popen("chmod +x ./hamlib/linux/rigctld", shell=True)
|
||||||
# p = subprocess.Popen("chmod +x ./hamlib/linux/rigctld", shell=True)
|
#run hamlib rigctld network service
|
||||||
#except:
|
command = "exec ./hamlib/linux/rigctld -r " + str(deviceport) + \
|
||||||
# print("rigctld not started...")
|
" -s "+ str(serialspeed) + \
|
||||||
##run hamlib rigctld network service
|
" -P "+ str(pttprotocol) + \
|
||||||
#command = "exec ./hamlib/linux/rigctld -r " + str(deviceport) + \
|
" -m "+ str(deviceid) + \
|
||||||
#" -s "+ str(serialspeed) + \
|
" --set-conf=dtr_state=" + dtr_state
|
||||||
#" -P "+ str(ptt) + \
|
try:
|
||||||
#" -m "+ str(deviceid) + \
|
p = subprocess.Popen(command, shell=True)
|
||||||
#" --set-conf=dtr_state=" + dtr_state
|
time.sleep(0.3)
|
||||||
#try:
|
except:
|
||||||
# p = subprocess.Popen(command, shell=True)
|
print("hamlib not started")
|
||||||
# time.sleep(0.3)
|
sys.exit()
|
||||||
#except:
|
|
||||||
# print("hamlib not started")
|
|
||||||
# sys.exit()
|
|
||||||
pass
|
|
||||||
elif sys.platform == "darwin":
|
elif sys.platform == "darwin":
|
||||||
print("platform not yet supported")
|
print("platform not yet supported")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
@ -170,14 +166,10 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
|
|
||||||
|
|
||||||
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) + " --pttprotocol "+ str(pttprotocol) + " --pttport "+ str(pttport), shell=True)
|
||||||
process = 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)
|
|
||||||
atexit.register(process.terminate)
|
|
||||||
else:
|
else:
|
||||||
process = subprocess.Popen("exec ./tnc --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 ./tnc --rx "+ str(rx_audio) +" --tx "+ str(tx_audio) +" --deviceport "+ str(deviceport) +" --deviceid "+ str(deviceid) + " --serialspeed "+ str(serialspeed) + " --pttprotocol "+ str(pttprotocol) + " --pttport "+ str(pttport), shell=True)
|
||||||
atexit.register(process.terminate)
|
static.TNCPROCESS = p#.pid
|
||||||
|
|
||||||
static.TNCPROCESS = process#.pid
|
|
||||||
static.TNCSTARTED = True
|
static.TNCSTARTED = True
|
||||||
|
|
||||||
if received_json["type"] == 'SET' and received_json["command"] == 'STOPTNC':
|
if received_json["type"] == 'SET' and received_json["command"] == 'STOPTNC':
|
||||||
|
@ -198,7 +190,6 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
|
|
||||||
# UPDATE LIST OF AUDIO DEVICES
|
# UPDATE LIST OF AUDIO DEVICES
|
||||||
p = pyaudio.PyAudio()
|
p = pyaudio.PyAudio()
|
||||||
atexit.register(p.terminate)
|
|
||||||
for i in range(0, p.get_device_count()):
|
for i in range(0, p.get_device_count()):
|
||||||
|
|
||||||
maxInputChannels = p.get_device_info_by_host_api_device_index(0,i).get('maxInputChannels')
|
maxInputChannels = p.get_device_info_by_host_api_device_index(0,i).get('maxInputChannels')
|
||||||
|
@ -223,15 +214,12 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
|
|
||||||
#exception, if JSON cant be decoded
|
#exception, if JSON cant be decoded
|
||||||
#except Exception as e:
|
#except Exception as e:
|
||||||
except:
|
except ValueError as e:
|
||||||
print("############ START OF ERROR #####################")
|
print("############ START OF ERROR #####################")
|
||||||
print('DAEMON PROGRAM ERROR: %s' %str(e))
|
print('DAEMON PROGRAM ERROR: %s' %str(e))
|
||||||
print("Wrong command")
|
print("Wrong command")
|
||||||
print(data)
|
print(data)
|
||||||
e = sys.exc_info()[0]
|
print(e)
|
||||||
print(e)
|
|
||||||
|
|
||||||
|
|
||||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||||
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
||||||
print(exc_type, fname, exc_tb.tb_lineno)
|
print(exc_type, fname, exc_tb.tb_lineno)
|
||||||
|
@ -241,7 +229,8 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
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)
|
||||||
|
@ -255,7 +244,6 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
DAEMON_THREAD = threading.Thread(target=start_daemon, name="daemon")
|
DAEMON_THREAD = threading.Thread(target=start_daemon, name="daemon")
|
||||||
DAEMON_THREAD.start()
|
DAEMON_THREAD.start()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,10 @@ 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('--pttprotocol', dest="hamlib_ptt_type", default='RTS', help="PTT Type", type=str)
|
||||||
|
PARSER.add_argument('--pttport', dest="hamlib_ptt_port", default="/dev/ttyUSB0", help="PTT Port", type=str)
|
||||||
|
|
||||||
ARGS = PARSER.parse_args()
|
ARGS = PARSER.parse_args()
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ if __name__ == '__main__':
|
||||||
static.HAMLIB_DEVICE_ID = ARGS.hamlib_device_id
|
static.HAMLIB_DEVICE_ID = ARGS.hamlib_device_id
|
||||||
static.HAMLIB_DEVICE_PORT = ARGS.hamlib_device_port
|
static.HAMLIB_DEVICE_PORT = ARGS.hamlib_device_port
|
||||||
static.HAMLIB_PTT_TYPE = ARGS.hamlib_ptt_type
|
static.HAMLIB_PTT_TYPE = ARGS.hamlib_ptt_type
|
||||||
|
HAMLIB_PTT_PORT = ARGS.hamlib_ptt_port
|
||||||
static.HAMLIB_SERIAL_SPEED = ARGS.hamlib_serialspeed
|
static.HAMLIB_SERIAL_SPEED = ARGS.hamlib_serialspeed
|
||||||
|
|
||||||
# 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
|
||||||
|
|
16
tnc/modem.py
16
tnc/modem.py
|
@ -23,8 +23,9 @@ import static
|
||||||
import data_handler
|
import data_handler
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
sys.path.append("hamlib/linux")
|
#sys.path.append("hamlib/linux")
|
||||||
import Hamlib
|
#import Hamlib
|
||||||
|
from hamlib.linux import Hamlib
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
#import rigctld
|
#import rigctld
|
||||||
|
@ -110,15 +111,14 @@ class RF():
|
||||||
|
|
||||||
# --------------------------------------------CONFIGURE HAMLIB
|
# --------------------------------------------CONFIGURE HAMLIB
|
||||||
|
|
||||||
|
print(static.HAMLIB_PTT_TYPE)
|
||||||
|
print(static.HAMLIB_DEVICE_ID)
|
||||||
|
print(static.HAMLIB_DEVICE_PORT)
|
||||||
# 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)
|
||||||
|
self.my_rig = Hamlib.Rig(int(static.HAMLIB_DEVICE_ID))
|
||||||
self.my_rig = Hamlib.Rig(static.HAMLIB_DEVICE_ID)
|
|
||||||
self.my_rig.set_conf("rig_pathname", static.HAMLIB_DEVICE_PORT)
|
self.my_rig.set_conf("rig_pathname", static.HAMLIB_DEVICE_PORT)
|
||||||
|
|
||||||
self.my_rig.set_conf("retry", "5")
|
self.my_rig.set_conf("retry", "5")
|
||||||
self.my_rig.set_conf("serial_speed", static.HAMLIB_SERIAL_SPEED)
|
self.my_rig.set_conf("serial_speed", static.HAMLIB_SERIAL_SPEED)
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ class RF():
|
||||||
#my_rig.set_conf("rts_state", "OFF")
|
#my_rig.set_conf("rts_state", "OFF")
|
||||||
#self.my_rig.set_conf("ptt_type", "RTS")
|
#self.my_rig.set_conf("ptt_type", "RTS")
|
||||||
#my_rig.set_conf("ptt_type", "RIG_PTT_SERIAL_RTS")
|
#my_rig.set_conf("ptt_type", "RIG_PTT_SERIAL_RTS")
|
||||||
|
|
||||||
self.my_rig.set_conf("serial_handshake", "None")
|
self.my_rig.set_conf("serial_handshake", "None")
|
||||||
self.my_rig.set_conf("stop_bits", "1")
|
self.my_rig.set_conf("stop_bits", "1")
|
||||||
self.my_rig.set_conf("data_bits", "8")
|
self.my_rig.set_conf("data_bits", "8")
|
||||||
|
|
Loading…
Reference in a new issue