mirror of https://github.com/DJ2LS/FreeDATA
'Refactored by Sourcery'
This commit is contained in:
parent
9b17a680e5
commit
7b23769b55
|
@ -7,10 +7,7 @@ for c in colormaps:
|
|||
cmap_name = c
|
||||
cmap = plt.get_cmap(cmap_name)
|
||||
|
||||
colors = []
|
||||
for i in range(256):
|
||||
colors.append([int(round(255 * x)) for x in cmap(i)[:3]])
|
||||
|
||||
colors = [[int(round(255 * x)) for x in cmap(i)[:3]] for i in range(256)]
|
||||
print(f'var {c} = {colors}')
|
||||
|
||||
print(f'var colormaps = [{", ".join(colormaps)}];')
|
||||
|
|
30
test/ping.py
30
test/ping.py
|
@ -85,11 +85,11 @@ def receive():
|
|||
bytes_out = ctypes.c_ubyte * bytes_per_frame # bytes_per_frame
|
||||
bytes_out = bytes_out() # get pointer from bytes_out
|
||||
|
||||
total_n_bytes = 0
|
||||
rx_total_frames = 0
|
||||
rx_frames = 0
|
||||
rx_bursts = 0
|
||||
receive = True
|
||||
total_n_bytes = 0
|
||||
while receive:
|
||||
time.sleep(0.01)
|
||||
|
||||
|
@ -97,7 +97,7 @@ def receive():
|
|||
nin_converted = int(nin * (AUDIO_SAMPLE_RATE_RX / MODEM_SAMPLE_RATE))
|
||||
if DEBUGGING_MODE:
|
||||
print("-----------------------------")
|
||||
print("NIN: " + str(nin) + " [ " + str(nin_converted) + " ]")
|
||||
print(f"NIN: {str(nin)} [ {nin_converted} ]")
|
||||
|
||||
data_in = stream_rx.read(nin_converted, exception_on_overflow=False)
|
||||
data_in = data_in.rstrip(b"\x00")
|
||||
|
@ -110,7 +110,7 @@ def receive():
|
|||
nbytes = c_lib.freedv_rawdatarx(freedv, bytes_out, data_in) # demodulate audio
|
||||
total_n_bytes = total_n_bytes + nbytes
|
||||
if DEBUGGING_MODE:
|
||||
print("SYNC: " + str(c_lib.freedv_get_rx_status(freedv)))
|
||||
print(f"SYNC: {str(c_lib.freedv_get_rx_status(freedv))}")
|
||||
|
||||
if nbytes == bytes_per_frame:
|
||||
rx_total_frames = rx_total_frames + 1
|
||||
|
@ -127,15 +127,7 @@ def receive():
|
|||
n_total_frame = bytes_out[3]
|
||||
|
||||
print(
|
||||
"RX | PONG | BURST ["
|
||||
+ str(burst)
|
||||
+ "/"
|
||||
+ str(n_total_burst)
|
||||
+ "] FRAME ["
|
||||
+ str(frame)
|
||||
+ "/"
|
||||
+ str(n_total_frame)
|
||||
+ "]"
|
||||
f"RX | PONG | BURST [{str(burst)}/{str(n_total_burst)}] FRAME [{str(frame)}/{str(n_total_frame)}]"
|
||||
)
|
||||
print("-----------------------------------------------------------------")
|
||||
c_lib.freedv_set_sync(freedv, 0)
|
||||
|
@ -151,7 +143,6 @@ RECEIVE.start()
|
|||
c_lib.freedv_open.restype = ctypes.POINTER(ctypes.c_ubyte)
|
||||
freedv = c_lib.freedv_open(FREEDV_TX_MODE)
|
||||
bytes_per_frame = int(c_lib.freedv_get_bits_per_modem_frame(freedv) / 8)
|
||||
payload_per_frame = bytes_per_frame - 2
|
||||
n_nom_modem_samples = c_lib.freedv_get_n_nom_modem_samples(freedv)
|
||||
n_tx_modem_samples = c_lib.freedv_get_n_tx_modem_samples(
|
||||
freedv
|
||||
|
@ -165,9 +156,10 @@ mod_out_preamble = ctypes.c_short * (
|
|||
mod_out_preamble = mod_out_preamble()
|
||||
|
||||
|
||||
print("BURSTS: " + str(N_BURSTS) + " FRAMES: " + str(N_FRAMES_PER_BURST))
|
||||
print(f"BURSTS: {str(N_BURSTS)} FRAMES: {str(N_FRAMES_PER_BURST)}")
|
||||
print("-----------------------------------------------------------------")
|
||||
|
||||
payload_per_frame = bytes_per_frame - 2
|
||||
for i in range(N_BURSTS):
|
||||
|
||||
c_lib.freedv_rawdatapreambletx(freedv, mod_out_preamble)
|
||||
|
@ -204,15 +196,7 @@ for i in range(N_BURSTS):
|
|||
txbuffer += bytes(mod_out)
|
||||
|
||||
print(
|
||||
"TX | PING | BURST ["
|
||||
+ str(i + 1)
|
||||
+ "/"
|
||||
+ str(N_BURSTS)
|
||||
+ "] FRAME ["
|
||||
+ str(n + 1)
|
||||
+ "/"
|
||||
+ str(N_FRAMES_PER_BURST)
|
||||
+ "]"
|
||||
f"TX | PING | BURST [{str(i + 1)}/{str(N_BURSTS)}] FRAME [{str(n + 1)}/{str(N_FRAMES_PER_BURST)}]"
|
||||
)
|
||||
stream_tx.write(bytes(txbuffer))
|
||||
ACK_TIMEOUT = time.time() + 3
|
||||
|
|
24
test/pong.py
24
test/pong.py
|
@ -81,7 +81,7 @@ c_lib.freedv_open.restype = ctypes.POINTER(ctypes.c_ubyte)
|
|||
def send_pong(burst,n_total_burst,frame,n_total_frame):
|
||||
|
||||
data_out = bytearray()
|
||||
data_out[0:1] = bytes([burst])
|
||||
data_out[:1] = bytes([burst])
|
||||
data_out[1:2] = bytes([n_total_burst])
|
||||
data_out[2:3] = bytes([frame])
|
||||
data_out[4:5] = bytes([n_total_frame])
|
||||
|
@ -139,7 +139,7 @@ while receive:
|
|||
nin_converted = int(nin*(AUDIO_SAMPLE_RATE_RX/MODEM_SAMPLE_RATE))
|
||||
if DEBUGGING_MODE:
|
||||
print("-----------------------------")
|
||||
print("NIN: " + str(nin) + " [ " + str(nin_converted) + " ]")
|
||||
print(f"NIN: {str(nin)} [ {nin_converted} ]")
|
||||
|
||||
data_in = stream_rx.read(nin_converted, exception_on_overflow = False)
|
||||
data_in = data_in.rstrip(b'\x00')
|
||||
|
@ -148,17 +148,19 @@ while receive:
|
|||
nbytes = c_lib.freedv_rawdatarx(freedv, bytes_out, data_in) # demodulate audio
|
||||
|
||||
if DEBUGGING_MODE:
|
||||
print("SYNC: " + str(c_lib.freedv_get_rx_status(freedv)))
|
||||
print(f"SYNC: {str(c_lib.freedv_get_rx_status(freedv))}")
|
||||
|
||||
if nbytes == bytes_per_frame:
|
||||
|
||||
burst = bytes_out[0]
|
||||
n_total_burst = bytes_out[1]
|
||||
frame = bytes_out[2]
|
||||
n_total_frame = bytes_out[3]
|
||||
print("RX | BURST [" + str(burst) + "/" + str(n_total_burst) + "] FRAME [" + str(frame) + "/" + str(n_total_frame) + "] >>> SENDING PONG")
|
||||
burst = bytes_out[0]
|
||||
n_total_burst = bytes_out[1]
|
||||
frame = bytes_out[2]
|
||||
n_total_frame = bytes_out[3]
|
||||
print(
|
||||
f"RX | BURST [{str(burst)}/{str(n_total_burst)}] FRAME [{str(frame)}/{str(n_total_frame)}] >>> SENDING PONG"
|
||||
)
|
||||
|
||||
TRANSMIT_PONG = threading.Thread(target=send_pong, args=[burst,n_total_burst,frame,n_total_frame], name="SEND PONG")
|
||||
TRANSMIT_PONG.start()
|
||||
TRANSMIT_PONG = threading.Thread(target=send_pong, args=[burst,n_total_burst,frame,n_total_frame], name="SEND PONG")
|
||||
TRANSMIT_PONG.start()
|
||||
|
||||
c_lib.freedv_set_sync(freedv,0)
|
||||
c_lib.freedv_set_sync(freedv,0)
|
||||
|
|
|
@ -77,10 +77,12 @@ class Test:
|
|||
self.p = pyaudio.PyAudio()
|
||||
# auto search for loopback devices
|
||||
if self.AUDIO_INPUT_DEVICE == -2:
|
||||
loopback_list = []
|
||||
for dev in range(self.p.get_device_count()):
|
||||
if "Loopback: PCM" in self.p.get_device_info_by_index(dev)["name"]:
|
||||
loopback_list.append(dev)
|
||||
loopback_list = [
|
||||
dev
|
||||
for dev in range(self.p.get_device_count())
|
||||
if "Loopback: PCM"
|
||||
in self.p.get_device_info_by_index(dev)["name"]
|
||||
]
|
||||
if len(loopback_list) >= 2:
|
||||
# 0 = RX 1 = TX
|
||||
self.AUDIO_INPUT_DEVICE = loopback_list[0]
|
||||
|
@ -287,7 +289,7 @@ class Test:
|
|||
|
||||
def run_audio(self):
|
||||
try:
|
||||
print(f"starting pyaudio callback", file=sys.stderr)
|
||||
print("starting pyaudio callback", file=sys.stderr)
|
||||
self.stream_rx.start_stream()
|
||||
except Exception as e:
|
||||
print(f"pyAudio error: {e}", file=sys.stderr)
|
||||
|
|
|
@ -219,7 +219,7 @@ class Test:
|
|||
|
||||
def run_audio(self):
|
||||
try:
|
||||
print(f"starting pyaudio callback", file=sys.stderr)
|
||||
print("starting pyaudio callback", file=sys.stderr)
|
||||
self.stream_rx.start_stream()
|
||||
except Exception as e:
|
||||
print(f"pyAudio error: {e}", file=sys.stderr)
|
||||
|
|
|
@ -138,7 +138,7 @@ class Test:
|
|||
|
||||
def run_audio(self):
|
||||
try:
|
||||
print(f"starting pyaudio callback", file=sys.stderr)
|
||||
print("starting pyaudio callback", file=sys.stderr)
|
||||
self.stream_tx.start_stream()
|
||||
except Exception as e:
|
||||
print(f"pyAudio error: {e}", file=sys.stderr)
|
||||
|
|
|
@ -81,10 +81,12 @@ class Test:
|
|||
self.p = pyaudio.PyAudio()
|
||||
# auto search for loopback devices
|
||||
if self.AUDIO_INPUT_DEVICE == -2:
|
||||
loopback_list = []
|
||||
for dev in range(self.p.get_device_count()):
|
||||
if "Loopback: PCM" in self.p.get_device_info_by_index(dev)["name"]:
|
||||
loopback_list.append(dev)
|
||||
loopback_list = [
|
||||
dev
|
||||
for dev in range(self.p.get_device_count())
|
||||
if "Loopback: PCM"
|
||||
in self.p.get_device_info_by_index(dev)["name"]
|
||||
]
|
||||
if len(loopback_list) >= 2:
|
||||
self.AUDIO_INPUT_DEVICE = loopback_list[0] # 0 = RX 1 = TX
|
||||
print(f"loopback_list rx: {loopback_list}", file=sys.stderr)
|
||||
|
@ -185,7 +187,7 @@ class Test:
|
|||
|
||||
def run_audio(self):
|
||||
try:
|
||||
print(f"starting pyaudio callback", file=sys.stderr)
|
||||
print("starting pyaudio callback", file=sys.stderr)
|
||||
self.stream_rx.start_stream()
|
||||
except Exception as e:
|
||||
print(f"pyAudio error: {e}", file=sys.stderr)
|
||||
|
|
|
@ -81,10 +81,12 @@ class Test:
|
|||
self.p = pyaudio.PyAudio()
|
||||
# auto search for loopback devices
|
||||
if self.AUDIO_INPUT_DEVICE == -2:
|
||||
loopback_list = []
|
||||
for dev in range(self.p.get_device_count()):
|
||||
if "Loopback: PCM" in self.p.get_device_info_by_index(dev)["name"]:
|
||||
loopback_list.append(dev)
|
||||
loopback_list = [
|
||||
dev
|
||||
for dev in range(self.p.get_device_count())
|
||||
if "Loopback: PCM"
|
||||
in self.p.get_device_info_by_index(dev)["name"]
|
||||
]
|
||||
if len(loopback_list) >= 2:
|
||||
self.AUDIO_INPUT_DEVICE = loopback_list[0] # 0 = RX 1 = TX
|
||||
print(f"loopback_list rx: {loopback_list}", file=sys.stderr)
|
||||
|
@ -147,7 +149,7 @@ class Test:
|
|||
|
||||
def run_audio(self):
|
||||
try:
|
||||
print(f"starting pyaudio callback", file=sys.stderr)
|
||||
print("starting pyaudio callback", file=sys.stderr)
|
||||
self.stream_rx.start_stream()
|
||||
except Exception as e:
|
||||
print(f"pyAudio error: {e}", file=sys.stderr)
|
||||
|
|
|
@ -87,10 +87,12 @@ class Test:
|
|||
self.p = pyaudio.PyAudio()
|
||||
# auto search for loopback devices
|
||||
if self.AUDIO_OUTPUT_DEVICE == -2:
|
||||
loopback_list = []
|
||||
for dev in range( self.p.get_device_count()):
|
||||
if "Loopback: PCM" in self.p.get_device_info_by_index(dev)["name"]:
|
||||
loopback_list.append(dev)
|
||||
loopback_list = [
|
||||
dev
|
||||
for dev in range(self.p.get_device_count())
|
||||
if "Loopback: PCM"
|
||||
in self.p.get_device_info_by_index(dev)["name"]
|
||||
]
|
||||
if len(loopback_list) >= 2:
|
||||
self.AUDIO_OUTPUT_DEVICE = loopback_list[0] # 0 = RX 1 = TX
|
||||
print(f"loopback_list rx: {loopback_list}", file=sys.stderr)
|
||||
|
@ -148,7 +150,7 @@ class Test:
|
|||
|
||||
def run_audio(self):
|
||||
try:
|
||||
print(f"starting pyaudio callback", file=sys.stderr)
|
||||
print("starting pyaudio callback", file=sys.stderr)
|
||||
self.stream_tx.start_stream()
|
||||
except Exception as e:
|
||||
print(f"pyAudio error: {e}", file=sys.stderr)
|
||||
|
|
|
@ -26,8 +26,6 @@ from tnc import codec2
|
|||
|
||||
|
||||
def test_mm_tx():
|
||||
# AUDIO PARAMETERS
|
||||
AUDIO_FRAMES_PER_BUFFER = 2400
|
||||
MODEM_SAMPLE_RATE = codec2.api.FREEDV_FS_8000
|
||||
AUDIO_SAMPLE_RATE_TX = 48000
|
||||
assert (AUDIO_SAMPLE_RATE_TX % MODEM_SAMPLE_RATE) == 0
|
||||
|
@ -72,6 +70,8 @@ def test_mm_tx():
|
|||
else:
|
||||
sys.exit()
|
||||
|
||||
# AUDIO PARAMETERS
|
||||
AUDIO_FRAMES_PER_BUFFER = 2400
|
||||
# pyaudio init
|
||||
stream_tx = p_audio.open(
|
||||
format=pyaudio.paInt16,
|
||||
|
|
154
test/util_rx.py
154
test/util_rx.py
|
@ -121,99 +121,93 @@ def util_rx():
|
|||
time_start = 0
|
||||
time_end = 0
|
||||
|
||||
# Copy received 48 kHz to a file. Listen to this file with:
|
||||
# aplay -r 48000 -f S16_LE rx48.raw
|
||||
# Corruption of this file is a good way to detect audio card issues
|
||||
frx = open("rx48.raw", mode="wb")
|
||||
with open("rx48.raw", mode="wb") as frx:
|
||||
# initial number of samples we need
|
||||
nin = codec2.api.freedv_nin(freedv)
|
||||
while receive and time.time() < timeout:
|
||||
if AUDIO_INPUT_DEVICE != -1:
|
||||
try:
|
||||
# data_in48k = stream_rx.read(AUDIO_FRAMES_PER_BUFFER, exception_on_overflow = True)
|
||||
data_in48k, overflowed = stream_rx.read(AUDIO_FRAMES_PER_BUFFER) # type: ignore
|
||||
except OSError as err:
|
||||
print(err, file=sys.stderr)
|
||||
# if str(err).find("Input overflowed") != -1:
|
||||
# nread_exceptions += 1
|
||||
# if str(err).find("Stream closed") != -1:
|
||||
# print("Ending...")
|
||||
# receive = False
|
||||
else:
|
||||
data_in48k = sys.stdin.buffer.read(AUDIO_FRAMES_PER_BUFFER * 2)
|
||||
|
||||
# initial number of samples we need
|
||||
nin = codec2.api.freedv_nin(freedv)
|
||||
while receive and time.time() < timeout:
|
||||
if AUDIO_INPUT_DEVICE != -1:
|
||||
try:
|
||||
# data_in48k = stream_rx.read(AUDIO_FRAMES_PER_BUFFER, exception_on_overflow = True)
|
||||
data_in48k, overflowed = stream_rx.read(AUDIO_FRAMES_PER_BUFFER) # type: ignore
|
||||
except OSError as err:
|
||||
print(err, file=sys.stderr)
|
||||
# if str(err).find("Input overflowed") != -1:
|
||||
# nread_exceptions += 1
|
||||
# if str(err).find("Stream closed") != -1:
|
||||
# print("Ending...")
|
||||
# receive = False
|
||||
else:
|
||||
data_in48k = sys.stdin.buffer.read(AUDIO_FRAMES_PER_BUFFER * 2)
|
||||
# insert samples in buffer
|
||||
x = np.frombuffer(data_in48k, dtype=np.int16) # type: ignore
|
||||
# print(x)
|
||||
# x = data_in48k
|
||||
x.tofile(frx)
|
||||
if len(x) != AUDIO_FRAMES_PER_BUFFER:
|
||||
receive = False
|
||||
x = resampler.resample48_to_8(x)
|
||||
audio_buffer.push(x)
|
||||
|
||||
# insert samples in buffer
|
||||
x = np.frombuffer(data_in48k, dtype=np.int16) # type: ignore
|
||||
# print(x)
|
||||
# x = data_in48k
|
||||
x.tofile(frx)
|
||||
if len(x) != AUDIO_FRAMES_PER_BUFFER:
|
||||
receive = False
|
||||
x = resampler.resample48_to_8(x)
|
||||
audio_buffer.push(x)
|
||||
|
||||
# when we have enough samples call FreeDV Rx
|
||||
while audio_buffer.nbuffer >= nin:
|
||||
# start time measurement
|
||||
time_start = time.time()
|
||||
# demodulate audio
|
||||
nbytes = codec2.api.freedv_rawdatarx(
|
||||
freedv, bytes_out, audio_buffer.buffer.ctypes
|
||||
)
|
||||
time_end = time.time()
|
||||
|
||||
audio_buffer.pop(nin)
|
||||
|
||||
# call me on every loop!
|
||||
nin = codec2.api.freedv_nin(freedv)
|
||||
|
||||
rx_status = codec2.api.freedv_get_rx_status(freedv)
|
||||
if rx_status & codec2.api.FREEDV_RX_BIT_ERRORS:
|
||||
rx_errors = rx_errors + 1
|
||||
if DEBUGGING_MODE:
|
||||
rx_status = codec2.api.rx_sync_flags_to_text[rx_status] # type: ignore
|
||||
time_needed = time_end - time_start
|
||||
|
||||
print(
|
||||
f"nin: {nin:5d} rx_status: {rx_status:4s} "
|
||||
f"naudio_buffer: {audio_buffer.nbuffer:4d} time: {time_needed:4f}",
|
||||
file=sys.stderr,
|
||||
# when we have enough samples call FreeDV Rx
|
||||
while audio_buffer.nbuffer >= nin:
|
||||
# start time measurement
|
||||
time_start = time.time()
|
||||
# demodulate audio
|
||||
nbytes = codec2.api.freedv_rawdatarx(
|
||||
freedv, bytes_out, audio_buffer.buffer.ctypes
|
||||
)
|
||||
time_end = time.time()
|
||||
|
||||
if nbytes:
|
||||
total_n_bytes += nbytes
|
||||
audio_buffer.pop(nin)
|
||||
|
||||
if nbytes == bytes_per_frame:
|
||||
rx_total_frames += 1
|
||||
rx_frames += 1
|
||||
# call me on every loop!
|
||||
nin = codec2.api.freedv_nin(freedv)
|
||||
|
||||
if rx_frames == N_FRAMES_PER_BURST:
|
||||
rx_frames = 0
|
||||
rx_bursts += 1
|
||||
rx_status = codec2.api.freedv_get_rx_status(freedv)
|
||||
if rx_status & codec2.api.FREEDV_RX_BIT_ERRORS:
|
||||
rx_errors = rx_errors + 1
|
||||
if DEBUGGING_MODE:
|
||||
rx_status = codec2.api.rx_sync_flags_to_text[rx_status] # type: ignore
|
||||
time_needed = time_end - time_start
|
||||
|
||||
if rx_bursts == N_BURSTS:
|
||||
receive = False
|
||||
print(
|
||||
f"nin: {nin:5d} rx_status: {rx_status:4s} "
|
||||
f"naudio_buffer: {audio_buffer.nbuffer:4d} time: {time_needed:4f}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
|
||||
if time.time() >= timeout:
|
||||
print("TIMEOUT REACHED")
|
||||
if nbytes:
|
||||
total_n_bytes += nbytes
|
||||
|
||||
time.sleep(0.01)
|
||||
if nbytes == bytes_per_frame:
|
||||
rx_total_frames += 1
|
||||
rx_frames += 1
|
||||
|
||||
if nread_exceptions:
|
||||
if rx_frames == N_FRAMES_PER_BURST:
|
||||
rx_frames = 0
|
||||
rx_bursts += 1
|
||||
|
||||
if rx_bursts == N_BURSTS:
|
||||
receive = False
|
||||
|
||||
if time.time() >= timeout:
|
||||
print("TIMEOUT REACHED")
|
||||
|
||||
time.sleep(0.01)
|
||||
|
||||
if nread_exceptions:
|
||||
print(
|
||||
f"nread_exceptions {nread_exceptions:d} - receive audio lost! "
|
||||
"Consider increasing Pyaudio frames_per_buffer...",
|
||||
file=sys.stderr,
|
||||
)
|
||||
print(
|
||||
f"nread_exceptions {nread_exceptions:d} - receive audio lost! "
|
||||
"Consider increasing Pyaudio frames_per_buffer...",
|
||||
f"RECEIVED BURSTS: {rx_bursts} "
|
||||
f"RECEIVED FRAMES: {rx_total_frames} "
|
||||
f"RX_ERRORS: {rx_errors}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
print(
|
||||
f"RECEIVED BURSTS: {rx_bursts} "
|
||||
f"RECEIVED FRAMES: {rx_total_frames} "
|
||||
f"RX_ERRORS: {rx_errors}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
frx.close()
|
||||
|
||||
# and at last check if we had an opened audio instance and close it
|
||||
if AUDIO_INPUT_DEVICE != -1:
|
||||
sd._terminate()
|
||||
|
|
|
@ -166,23 +166,15 @@ class DAEMON:
|
|||
self.log.warning("[DMN] Starting TNC", rig=data[5], port=data[6])
|
||||
|
||||
# list of parameters, necessary for running subprocess command as a list
|
||||
options = []
|
||||
options = ["--port", str(static.DAEMONPORT - 1)]
|
||||
|
||||
options.append("--port")
|
||||
options.append(str(static.DAEMONPORT - 1))
|
||||
# create an additional list entry for parameters not covered by gui
|
||||
data[50] = int(static.DAEMONPORT - 1)
|
||||
|
||||
options.append("--mycall")
|
||||
options.append(data[1])
|
||||
|
||||
options.append("--mygrid")
|
||||
options.append(data[2])
|
||||
|
||||
options.append("--rx")
|
||||
options.append(data[3])
|
||||
|
||||
options.append("--tx")
|
||||
options.extend((data[1], "--mygrid"))
|
||||
options.extend((data[2], "--rx"))
|
||||
options.extend((data[3], "--tx"))
|
||||
options.append(data[4])
|
||||
|
||||
# if radiocontrol != disabled
|
||||
|
@ -196,9 +188,7 @@ class DAEMON:
|
|||
|
||||
if data[5] == "rigctld":
|
||||
options.append("--rigctld_ip")
|
||||
options.append(data[6])
|
||||
|
||||
options.append("--rigctld_port")
|
||||
options.extend((data[6], "--rigctld_port"))
|
||||
options.append(data[7])
|
||||
|
||||
if data[8] == "True":
|
||||
|
@ -211,16 +201,8 @@ class DAEMON:
|
|||
options.append("--500hz")
|
||||
|
||||
options.append("--tuning_range_fmin")
|
||||
options.append(data[11])
|
||||
|
||||
options.append("--tuning_range_fmax")
|
||||
options.append(data[12])
|
||||
|
||||
# overriding FSK mode
|
||||
# if data[13] == "True":
|
||||
# options.append("--fsk")
|
||||
|
||||
options.append("--tx-audio-level")
|
||||
options.extend((data[11], "--tuning_range_fmax"))
|
||||
options.extend((data[12], "--tx-audio-level"))
|
||||
options.append(data[14])
|
||||
|
||||
if data[15] == "True":
|
||||
|
@ -233,9 +215,7 @@ class DAEMON:
|
|||
options.append("--explorer")
|
||||
|
||||
options.append("--ssid")
|
||||
for i in data[18]:
|
||||
options.append(str(i))
|
||||
|
||||
options.extend(str(i) for i in data[18])
|
||||
if data[19] == "True":
|
||||
options.append("--tune")
|
||||
|
||||
|
@ -258,14 +238,12 @@ class DAEMON:
|
|||
# extends the sys module by a flag frozen=True and sets the app
|
||||
# path into variable _MEIPASS'.
|
||||
application_path = sys._MEIPASS
|
||||
command.append(application_path + '/freedata-tnc')
|
||||
command.append(f'{application_path}/freedata-tnc')
|
||||
|
||||
else:
|
||||
|
||||
if sys.platform in ["linux", "darwin"]:
|
||||
command.append("./freedata-tnc")
|
||||
elif sys.platform in ["win32", "win64"]:
|
||||
command.append("freedata-tnc.exe")
|
||||
elif sys.platform in ["linux", "darwin"]:
|
||||
command.append("./freedata-tnc")
|
||||
elif sys.platform in ["win32", "win64"]:
|
||||
command.append("freedata-tnc.exe")
|
||||
|
||||
command += options
|
||||
proc = subprocess.Popen(command)
|
||||
|
@ -331,9 +309,7 @@ class DAEMON:
|
|||
# hamlib_version = rig.hamlib_version
|
||||
|
||||
hamlib.set_ptt(True)
|
||||
pttstate = hamlib.get_ptt()
|
||||
|
||||
if pttstate:
|
||||
if pttstate := hamlib.get_ptt():
|
||||
self.log.info("[DMN] Hamlib PTT", status="SUCCESS")
|
||||
response = {"command": "test_hamlib", "result": "SUCCESS"}
|
||||
else:
|
||||
|
|
|
@ -249,7 +249,10 @@ class DATA:
|
|||
#
|
||||
# send transmission queued information once
|
||||
if static.ARQ_STATE or static.IS_CODEC2_TRAFFIC:
|
||||
self.log.debug(f"[TNC] TX DISPATCHER - waiting with processing command ", arq_state=static.ARQ_STATE)
|
||||
self.log.debug(
|
||||
"[TNC] TX DISPATCHER - waiting with processing command ",
|
||||
arq_state=static.ARQ_STATE,
|
||||
)
|
||||
|
||||
self.send_data_to_socket_queue(
|
||||
freedata="tnc-message",
|
||||
|
|
11
tnc/sock.py
11
tnc/sock.py
|
@ -561,12 +561,12 @@ def process_tnc_commands(data):
|
|||
|
||||
if received_json["type"] == "get" and received_json["command"] == "rx_buffer":
|
||||
try:
|
||||
output = {
|
||||
"command": "rx_buffer",
|
||||
"data-array": [],
|
||||
}
|
||||
|
||||
if not RX_BUFFER.empty():
|
||||
output = {
|
||||
"command": "rx_buffer",
|
||||
"data-array": [],
|
||||
}
|
||||
|
||||
for _buffer_length in range(RX_BUFFER.qsize()):
|
||||
base64_data = RX_BUFFER.queue[_buffer_length][4]
|
||||
output["data-array"].append(
|
||||
|
@ -632,7 +632,6 @@ def process_tnc_commands(data):
|
|||
command=received_json,
|
||||
)
|
||||
|
||||
# exception, if JSON cant be decoded
|
||||
except Exception as err:
|
||||
log.error("[SCK] JSON decoding error", e=err)
|
||||
|
||||
|
|
10
tnc/stats.py
10
tnc/stats.py
|
@ -22,16 +22,10 @@ class stats():
|
|||
self.explorer_url = "https://api.freedata.app/stats.php"
|
||||
|
||||
def push(self, frame_nack_counter, status, duration):
|
||||
if status in ["crc_error"]:
|
||||
crcerror = True
|
||||
else:
|
||||
crcerror = False
|
||||
|
||||
crcerror = status in ["crc_error"]
|
||||
# get avg snr
|
||||
try:
|
||||
snr_raw = []
|
||||
for item in static.SPEED_LIST:
|
||||
snr_raw.append(item["snr"])
|
||||
snr_raw = [item["snr"] for item in static.SPEED_LIST]
|
||||
avg_snr = round(sum(snr_raw) / len(snr_raw), 2 )
|
||||
except Exception:
|
||||
avg_snr = 0
|
||||
|
|
|
@ -6,6 +6,7 @@ Created on Fri Dec 11 21:53:35 2020
|
|||
@author: parallels
|
||||
"""
|
||||
|
||||
|
||||
import socket
|
||||
import sys
|
||||
import argparse
|
||||
|
@ -13,7 +14,7 @@ import time
|
|||
|
||||
# --------------------------------------------GET PARAMETER INPUTS
|
||||
parser = argparse.ArgumentParser(description='Simons TEST TNC')
|
||||
parser.add_argument('--port', dest="socket_port", default=3000, help="Set the port, the socket is listening on.", type=int)
|
||||
parser.add_argument('--port', dest="socket_port", default=3000, help="Set the port, the socket is listening on.", type=int)
|
||||
parser.add_argument('--data', dest="data", default=False, help="data", type=str)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
@ -29,6 +30,6 @@ while True:
|
|||
sock.connect((ip, port))
|
||||
sock.sendall(bytes(message, 'utf-8') + b'\n')
|
||||
response = str(sock.recv(1024), 'utf-8')
|
||||
print("CMD: {}".format(response))
|
||||
print(f"CMD: {response}")
|
||||
False
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue