FreeDATA/tools/custom_mode_tests/create_custom_ofdm_mod.py

97 lines
2.6 KiB
Python
Raw Normal View History

2024-04-06 16:03:00 +00:00
"""
2024-04-17 20:49:08 +00:00
FreeDATA % python3.11 tools/custom_mode_tests/create_custom_ofdm_mod.py | ./freedata-server/lib/codec2/build_osx/src/freedv_data_raw_rx --vv --framesperburst 1 DATAC1 - /dev/null
2024-04-06 16:03:00 +00:00
"""
import sys
2024-04-17 20:49:08 +00:00
sys.path.append('freedata-server')
2024-04-06 16:03:00 +00:00
import numpy as np
2024-04-17 20:49:08 +00:00
modem_path = '/../../freedata-server'
2024-04-06 16:03:00 +00:00
if modem_path not in sys.path:
sys.path.append(modem_path)
2024-04-17 20:49:08 +00:00
#import freedata-server.codec2 as codec2
2024-04-06 16:03:00 +00:00
from codec2 import *
2024-04-08 13:23:32 +00:00
import threading
2024-04-06 16:03:00 +00:00
import modulator as modulator
2024-04-08 13:23:32 +00:00
import demodulator as demodulator
2024-04-06 16:03:00 +00:00
import config as config
2024-04-08 13:23:32 +00:00
def demod(txbuffer):
c2instance = open_instance(FREEDV_MODE.datac3.value)
# get bytes per frame
bytes_per_frame = int(
api.freedv_get_bits_per_modem_frame(c2instance) / 8
)
# create byte out buffer
bytes_out = ctypes.create_string_buffer(bytes_per_frame)
# set initial frames per burst
api.freedv_set_frames_per_burst(c2instance, 1)
# init audio buffer
audiobuffer = audio_buffer(len(txbuffer))
# get initial nin
nin = api.freedv_nin(c2instance)
audiobuffer.push(txbuffer)
threading.Event().wait(0.01)
while audiobuffer.nbuffer >= nin:
# demodulate audio
nbytes = api.freedv_rawdatarx(
freedv, bytes_out, audiobuffer.buffer.ctypes
)
2024-04-17 20:49:08 +00:00
# get current freedata-server states and write to list
2024-04-08 13:23:32 +00:00
# 1 trial
# 2 sync
# 3 trial sync
# 6 decoded
# 10 error decoding == NACK
rx_status = api.freedv_get_rx_status(freedv)
print(rx_status)
# decrement codec traffic counter for making state smoother
audiobuffer.pop(nin)
nin = api.freedv_nin(freedv)
if nbytes == bytes_per_frame:
print("DECODED!!!!")
print("ENDED")
print(nin)
print(audiobuffer.nbuffer)
2024-04-06 16:03:00 +00:00
config = config.CONFIG('config.ini')
modulator = modulator.Modulator(config.read())
#freedv = open_instance(FREEDV_MODE.data_ofdm_2438.value)
2024-04-07 13:09:25 +00:00
#freedv = open_instance(FREEDV_MODE.datac14.value)
#freedv = open_instance(FREEDV_MODE.datac1.value)
freedv = open_instance(FREEDV_MODE.datac3.value)
#freedv = open_instance(FREEDV_MODE.data_ofdm_500.value)
2024-04-06 19:14:36 +00:00
#freedv = open_instance(FREEDV_MODE.qam16c2.value)
2024-04-06 16:03:00 +00:00
2024-04-06 19:14:36 +00:00
2024-04-08 13:23:32 +00:00
frames = 2
2024-04-06 16:03:00 +00:00
txbuffer = bytearray()
for frame in range(0,frames):
2024-04-06 19:14:36 +00:00
#txbuffer = modulator.transmit_add_silence(txbuffer, 1000)
2024-04-06 16:03:00 +00:00
txbuffer = modulator.transmit_add_preamble(txbuffer, freedv)
txbuffer = modulator.transmit_create_frame(txbuffer, freedv, b'123')
txbuffer = modulator.transmit_add_postamble(txbuffer, freedv)
txbuffer = modulator.transmit_add_silence(txbuffer, 1000)
2024-04-08 13:23:32 +00:00
#sys.stdout.buffer.flush()
#sys.stdout.buffer.write(txbuffer)
#sys.stdout.buffer.flush()
demod(txbuffer)