mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
moved back to python hamlib binding
This commit is contained in:
parent
7fc6872ff5
commit
4a3f10126a
|
@ -131,20 +131,23 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
|||
|
||||
if sys.platform == "linux":
|
||||
# we need to make sure we have execution privileges
|
||||
p = subprocess.Popen("chmod +x ./hamlib/linux/rigctld", shell=True)
|
||||
#run hamlib rigctld network service
|
||||
command = "exec ./hamlib/linux/rigctld -r " + str(deviceport) + \
|
||||
" -s "+ str(serialspeed) + \
|
||||
" -P "+ str(ptt) + \
|
||||
" -m "+ str(deviceid) + \
|
||||
" --set-conf=dtr_state=" + dtr_state
|
||||
try:
|
||||
p = subprocess.Popen(command, shell=True)
|
||||
time.sleep(0.3)
|
||||
except:
|
||||
print("hamlib not started")
|
||||
sys.exit()
|
||||
|
||||
#try:
|
||||
# p = subprocess.Popen("chmod +x ./hamlib/linux/rigctld", shell=True)
|
||||
#except:
|
||||
# print("rigctld not started...")
|
||||
##run hamlib rigctld network service
|
||||
#command = "exec ./hamlib/linux/rigctld -r " + str(deviceport) + \
|
||||
#" -s "+ str(serialspeed) + \
|
||||
#" -P "+ str(ptt) + \
|
||||
#" -m "+ str(deviceid) + \
|
||||
#" --set-conf=dtr_state=" + dtr_state
|
||||
#try:
|
||||
# p = subprocess.Popen(command, shell=True)
|
||||
# time.sleep(0.3)
|
||||
#except:
|
||||
# print("hamlib not started")
|
||||
# sys.exit()
|
||||
pass
|
||||
elif sys.platform == "darwin":
|
||||
print("platform not yet supported")
|
||||
sys.exit()
|
||||
|
|
|
@ -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('--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('--deviceid', dest="hamlib_device_id", default=3011, help="Socket port", type=str)
|
||||
PARSER.add_argument('--deviceid', dest="hamlib_device_id", default=3011, help="Socket port", type=int)
|
||||
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)
|
||||
|
||||
|
|
58
tnc/modem.py
58
tnc/modem.py
|
@ -21,10 +21,13 @@ import helpers
|
|||
import static
|
||||
import data_handler
|
||||
|
||||
#import Hamlib
|
||||
import sys
|
||||
sys.path.append("hamlib/linux")
|
||||
import Hamlib
|
||||
|
||||
import numpy as np
|
||||
import rigctld
|
||||
rigctld = rigctld.Rigctld()
|
||||
#import rigctld
|
||||
#rigctld = rigctld.Rigctld()
|
||||
|
||||
|
||||
MODEM_STATS_NR_MAX = 320
|
||||
|
@ -55,7 +58,15 @@ class RF():
|
|||
def __init__(self):
|
||||
|
||||
# -------------------------------------------- LOAD FREEDV
|
||||
libname = pathlib.Path().absolute() / "codec2/build_linux/src/libcodec2.so"
|
||||
try:
|
||||
# we check at first for libcodec2 in root - necessary if we want to run it inside a pyinstaller binary
|
||||
libname = pathlib.Path("libcodec2.so.1.0")
|
||||
self.c_lib = ctypes.CDLL(libname)
|
||||
except:
|
||||
# if we cant load libcodec from root, we check for subdirectory
|
||||
# this is, if we want to run it without beeing build in a dev environment
|
||||
print("running libcodec from source bild")
|
||||
libname = pathlib.Path().absolute() / "codec2/build_linux/src/libcodec2.so.1.0"
|
||||
self.c_lib = ctypes.CDLL(libname)
|
||||
# --------------------------------------------CREATE PYAUDIO INSTANCE
|
||||
self.p = pyaudio.PyAudio()
|
||||
|
@ -96,9 +107,15 @@ class RF():
|
|||
|
||||
# --------------------------------------------CONFIGURE HAMLIB
|
||||
|
||||
'''
|
||||
|
||||
# try to init hamlib
|
||||
try:
|
||||
print(static.HAMLIB_DEVICE_ID)
|
||||
print(static.HAMLIB_DEVICE_PORT)
|
||||
print(static.HAMLIB_SERIAL_SPEED)
|
||||
print(static.HAMLIB_PTT_TYPE)
|
||||
|
||||
|
||||
Hamlib.rig_set_debug(Hamlib.RIG_DEBUG_NONE)
|
||||
|
||||
self.my_rig = Hamlib.Rig(static.HAMLIB_DEVICE_ID)
|
||||
|
@ -147,16 +164,17 @@ class RF():
|
|||
self.my_rig.open()
|
||||
|
||||
except:
|
||||
print("Unexpected error:", sys.exc_info()[0])
|
||||
print("can't open rig")
|
||||
|
||||
'''
|
||||
|
||||
# --------------------------------------------------------------------------------------------------------
|
||||
def ptt_and_wait(self, state):
|
||||
|
||||
if state:
|
||||
static.PTT_STATE = True
|
||||
#self.my_rig.set_ptt(self.hamlib_ptt_type, 1)
|
||||
rigctld.ptt_enable()
|
||||
self.my_rig.set_ptt(self.hamlib_ptt_type, 1)
|
||||
#rigctld.ptt_enable()
|
||||
ptt_togle_timeout = time.time() + 0.1
|
||||
while time.time() < ptt_togle_timeout:
|
||||
pass
|
||||
|
@ -168,8 +186,8 @@ class RF():
|
|||
pass
|
||||
|
||||
static.PTT_STATE = False
|
||||
#self.my_rig.set_ptt(self.hamlib_ptt_type, 0)
|
||||
rigctld.ptt_disable()
|
||||
self.my_rig.set_ptt(self.hamlib_ptt_type, 0)
|
||||
#rigctld.ptt_disable()
|
||||
|
||||
|
||||
|
||||
|
@ -275,8 +293,6 @@ class RF():
|
|||
static.ARQ_DATA_CHANNEL_LAST_RECEIVED = int(time.time()) # we need to update our timeout timestamp
|
||||
static.ARQ_START_OF_BURST = int(time.time()) # we need to update our timeout timestamp
|
||||
|
||||
self.my_rig.set_ptt(self.hamlib_ptt_type, 1)
|
||||
|
||||
state_before_transmit = static.CHANNEL_STATE
|
||||
static.CHANNEL_STATE = 'SENDING_DATA'
|
||||
|
||||
|
@ -637,10 +653,12 @@ class RF():
|
|||
static.SNR = 0
|
||||
|
||||
def get_radio_stats(self):
|
||||
|
||||
static.HAMLIB_FREQUENCY = rigctld.get_frequency()
|
||||
static.HAMLIB_MODE = rigctld.get_mode()[0]
|
||||
static.HAMLIB_BANDWITH = rigctld.get_mode()[1]
|
||||
static.HAMLIB_FREQUENCY = int(self.my_rig.get_freq())
|
||||
(hamlib_mode, static.HAMLIB_BANDWITH) = self.my_rig.get_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]
|
||||
|
||||
|
||||
def calculate_fft(self, data_in):
|
||||
|
@ -649,11 +667,13 @@ class RF():
|
|||
audio_data = np.fromstring(data_in, np.int16)
|
||||
# Fast Fourier Transform, 10*log10(abs) is to scale it to dB
|
||||
# and make sure it's not imaginary
|
||||
# we need to try this in case of division by zero
|
||||
try:
|
||||
dfft = 10.*np.log10(abs(np.fft.rfft(audio_data)))
|
||||
|
||||
print(dfft.tolist())
|
||||
except:
|
||||
dfft = [0]
|
||||
dfftlist = dfft.tolist()
|
||||
|
||||
static.FFT = dfftlist[:400]
|
||||
|
||||
static.FFT = dfftlist[:512]
|
||||
return dfft
|
||||
|
|
Loading…
Reference in a new issue