mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
preparation for ARQ test
added a directory 003_highsnr_stdio_arq for working on ARQ tests
This commit is contained in:
parent
8b8678853d
commit
72b653b188
22
test/003_highsnr_stdio_arq/test_arq_tx.py
Normal file
22
test/003_highsnr_stdio_arq/test_arq_tx.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
Created on Wed Dec 23 07:04:24 2020
|
||||||
|
|
||||||
|
@author: DJ2LS
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sys
|
||||||
|
sys.path.insert(0,'../..')
|
||||||
|
sys.path.insert(0,'../../tnc')
|
||||||
|
import data_handler
|
||||||
|
|
||||||
|
|
||||||
|
teststring = b'HELLO WORLD'
|
||||||
|
|
||||||
|
data_handler.arq_transmit(teststring, 10, 1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,7 @@ import sys
|
||||||
import pathlib
|
import pathlib
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
#print("loading codec2 module", file=sys.stderr)
|
||||||
print("loading codec2 module", file=sys.stderr)
|
|
||||||
|
|
||||||
|
|
||||||
# Enum for codec2 modes
|
# Enum for codec2 modes
|
||||||
|
@ -17,12 +16,37 @@ class FREEDV_MODE(Enum):
|
||||||
datac1 = 10
|
datac1 = 10
|
||||||
datac3 = 12
|
datac3 = 12
|
||||||
|
|
||||||
def FREEDV_GET_MODE(mode):
|
def freedv_get_mode(mode):
|
||||||
return FREEDV_MODE[mode].value
|
return FREEDV_MODE[mode].value
|
||||||
|
|
||||||
# LOAD FREEDV
|
# -------------------------------------------- LOAD FREEDV
|
||||||
libname = "libcodec2.so"
|
# codec2 search pathes in descending order
|
||||||
api = ctypes.CDLL(libname)
|
# libcodec2.so ctests
|
||||||
|
# pathlib.Path("codec2/build_linux/src/libcodec2.so.1.0") manual build
|
||||||
|
# pathlib.Path("lib/codec2/linux/libcodec2.so.1.0") precompiled
|
||||||
|
# pathlib.Path("../../tnc/codec2/build_linux/src/libcodec2.so.1.0") external loading manual build
|
||||||
|
# pathlib.Path("../../tnc/lib/codec2/linux/libcodec2.so.1.0") external loading precompiled
|
||||||
|
libname = ["libcodec2.so", \
|
||||||
|
pathlib.Path("codec2/build_linux/src/libcodec2.so.1.0"), \
|
||||||
|
pathlib.Path("lib/codec2/linux/libcodec2.so.1.0"), \
|
||||||
|
pathlib.Path("../../tnc/codec2/build_linux/src/libcodec2.so.1.0"), \
|
||||||
|
pathlib.Path("../../tnc/lib/codec2/linux/libcodec2.so.1.0"), \
|
||||||
|
]
|
||||||
|
# iterate through codec2 search pathes
|
||||||
|
for i in libname:
|
||||||
|
try:
|
||||||
|
api = ctypes.CDLL(i)
|
||||||
|
print(f"[C2 ] Codec2 library found - {i}", file=sys.stderr)
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
print(f"[C2 ] Codec2 library not found - {i}", file=sys.stderr)
|
||||||
|
pass
|
||||||
|
# quit module if codec2 cant be loaded
|
||||||
|
if not 'api' in locals():
|
||||||
|
print(f"[C2 ] Loading Codec2 library failed", file=sys.stderr)
|
||||||
|
quit()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ctypes function init
|
# ctypes function init
|
||||||
|
|
|
@ -5,14 +5,13 @@ Created on Sun Dec 27 20:43:40 2020
|
||||||
|
|
||||||
@author: DJ2LS
|
@author: DJ2LS
|
||||||
"""
|
"""
|
||||||
|
import sys
|
||||||
|
|
||||||
import logging, structlog, log_handler
|
import logging, structlog, log_handler
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from random import randrange
|
from random import randrange
|
||||||
import asyncio
|
import asyncio
|
||||||
import sys
|
|
||||||
import ujson as json
|
import ujson as json
|
||||||
|
|
||||||
import static
|
import static
|
||||||
|
|
34
tnc/modem.py
34
tnc/modem.py
|
@ -21,6 +21,8 @@ import static
|
||||||
import data_handler
|
import data_handler
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
import codec2
|
||||||
|
|
||||||
# option for testing miniaudio instead of audioop for sample rate conversion
|
# option for testing miniaudio instead of audioop for sample rate conversion
|
||||||
#import miniaudio
|
#import miniaudio
|
||||||
|
|
||||||
|
@ -109,7 +111,11 @@ class RF():
|
||||||
self.AUDIO_CHUNKS = 48 #8 * (self.AUDIO_SAMPLE_RATE_RX/self.MODEM_SAMPLE_RATE) #48
|
self.AUDIO_CHUNKS = 48 #8 * (self.AUDIO_SAMPLE_RATE_RX/self.MODEM_SAMPLE_RATE) #48
|
||||||
self.AUDIO_CHANNELS = 1
|
self.AUDIO_CHANNELS = 1
|
||||||
|
|
||||||
|
# small hack for initializing codec2 via codec2.py module
|
||||||
|
# TODO: we need to change the entire modem module to integrate codec2 module
|
||||||
|
self.c_lib = codec2.api
|
||||||
|
|
||||||
|
'''
|
||||||
# -------------------------------------------- LOAD FREEDV
|
# -------------------------------------------- LOAD FREEDV
|
||||||
try:
|
try:
|
||||||
# we check at first for libcodec2 compiled from source
|
# we check at first for libcodec2 compiled from source
|
||||||
|
@ -132,8 +138,8 @@ class RF():
|
||||||
structlog.get_logger("structlog").info("[TNC] Codec2 found", path=libname, origin="precompiled")
|
structlog.get_logger("structlog").info("[TNC] Codec2 found", path=libname, origin="precompiled")
|
||||||
else:
|
else:
|
||||||
structlog.get_logger("structlog").critical("[TNC] Codec2 not found")
|
structlog.get_logger("structlog").critical("[TNC] Codec2 not found")
|
||||||
|
'''
|
||||||
|
'''
|
||||||
# --------------------------------------------CTYPES FUNCTION INIT
|
# --------------------------------------------CTYPES FUNCTION INIT
|
||||||
# TODO: WE STILL HAVE SOME MISSING FUNCTIONS!
|
# TODO: WE STILL HAVE SOME MISSING FUNCTIONS!
|
||||||
|
|
||||||
|
@ -154,8 +160,7 @@ class RF():
|
||||||
|
|
||||||
self.c_lib.freedv_set_frames_per_burst.argtype = [c_void_p, c_int]
|
self.c_lib.freedv_set_frames_per_burst.argtype = [c_void_p, c_int]
|
||||||
self.c_lib.freedv_set_frames_per_burst.restype = c_int
|
self.c_lib.freedv_set_frames_per_burst.restype = c_int
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------CREATE PYAUDIO INSTANCE
|
# --------------------------------------------CREATE PYAUDIO INSTANCE
|
||||||
try:
|
try:
|
||||||
|
@ -168,6 +173,17 @@ class RF():
|
||||||
self.p = pyaudio.PyAudio()
|
self.p = pyaudio.PyAudio()
|
||||||
atexit.register(self.p.terminate)
|
atexit.register(self.p.terminate)
|
||||||
# --------------------------------------------OPEN AUDIO CHANNEL RX
|
# --------------------------------------------OPEN AUDIO CHANNEL RX
|
||||||
|
# optional auto selection of loopback device if using in testmode
|
||||||
|
if static.AUDIO_INPUT_DEVICE == -2:
|
||||||
|
loopback_list = []
|
||||||
|
for dev in range(0,self.p.get_device_count()):
|
||||||
|
if 'Loopback: PCM' in self.p.get_device_info_by_index(dev)["name"]:
|
||||||
|
loopback_list.append(dev)
|
||||||
|
if len(loopback_list) >= 2:
|
||||||
|
AUDIO_INPUT_DEVICE = loopback_list[0] #0 = RX 1 = TX
|
||||||
|
print(f"loopback_list rx: {loopback_list}", file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
self.stream_rx = self.p.open(format=pyaudio.paInt16,
|
self.stream_rx = self.p.open(format=pyaudio.paInt16,
|
||||||
channels=self.AUDIO_CHANNELS,
|
channels=self.AUDIO_CHANNELS,
|
||||||
rate=self.AUDIO_SAMPLE_RATE_RX,
|
rate=self.AUDIO_SAMPLE_RATE_RX,
|
||||||
|
@ -176,6 +192,16 @@ class RF():
|
||||||
input_device_index=static.AUDIO_INPUT_DEVICE
|
input_device_index=static.AUDIO_INPUT_DEVICE
|
||||||
)
|
)
|
||||||
# --------------------------------------------OPEN AUDIO CHANNEL TX
|
# --------------------------------------------OPEN AUDIO CHANNEL TX
|
||||||
|
# optional auto selection of loopback device if using in testmode
|
||||||
|
if static.AUDIO_OUTPUT_DEVICE == -2:
|
||||||
|
loopback_list = []
|
||||||
|
for dev in range(0,self.p.get_device_count()):
|
||||||
|
if 'Loopback: PCM' in self.p.get_device_info_by_index(dev)["name"]:
|
||||||
|
loopback_list.append(dev)
|
||||||
|
if len(loopback_list) >= 2:
|
||||||
|
static.AUDIO_OUTPUT_DEVICE = loopback_list[1] #0 = RX 1 = TX
|
||||||
|
print(f"loopback_list tx: {loopback_list}", file=sys.stderr)
|
||||||
|
|
||||||
self.stream_tx = self.p.open(format=pyaudio.paInt16,
|
self.stream_tx = self.p.open(format=pyaudio.paInt16,
|
||||||
channels=self.AUDIO_CHANNELS,
|
channels=self.AUDIO_CHANNELS,
|
||||||
rate=self.AUDIO_SAMPLE_RATE_TX,
|
rate=self.AUDIO_SAMPLE_RATE_TX,
|
||||||
|
|
|
@ -36,7 +36,7 @@ SOCKET_TIMEOUT = 3 # seconds
|
||||||
HAMLIB_PTT_TYPE = 'RTS'
|
HAMLIB_PTT_TYPE = 'RTS'
|
||||||
PTT_STATE = False
|
PTT_STATE = False
|
||||||
|
|
||||||
HAMLIB_DEVICE_ID = 0
|
HAMLIB_DEVICE_ID = 'RIG_MODEL_DUMMY_NOVFO'
|
||||||
HAMLIB_DEVICE_PORT = '/dev/ttyUSB0'
|
HAMLIB_DEVICE_PORT = '/dev/ttyUSB0'
|
||||||
HAMLIB_SERIAL_SPEED = '9600'
|
HAMLIB_SERIAL_SPEED = '9600'
|
||||||
|
|
||||||
|
@ -54,8 +54,8 @@ SCATTER = []
|
||||||
# ---------------------------------
|
# ---------------------------------
|
||||||
|
|
||||||
# Audio Defaults
|
# Audio Defaults
|
||||||
AUDIO_INPUT_DEVICE = 1
|
AUDIO_INPUT_DEVICE = -2
|
||||||
AUDIO_OUTPUT_DEVICE = 1
|
AUDIO_OUTPUT_DEVICE = -2
|
||||||
|
|
||||||
|
|
||||||
AUDIO_RMS = 0
|
AUDIO_RMS = 0
|
||||||
|
|
Loading…
Reference in a new issue