mod out locking state

an attempt with a locking state for the mod_out queue so we can process audio only, if we finished filling our mod_out queue. Possibly this solves the problems #99 #127
This commit is contained in:
dj2ls 2022-01-23 07:10:04 +01:00
parent 2c57923c11
commit 77adabf450
5 changed files with 41 additions and 5 deletions

View file

@ -34,23 +34,41 @@ function connectDAEMON() {
daemon.on('connect', function(data) {
console.log('DAEMON connection established')
let Data = {
daemon_connection: daemon.readyState,
};
ipcRenderer.send('request-update-daemon-connection', Data);
})
daemon.on('error', function(data) {
console.log('DAEMON connection error');
setTimeout(connectDAEMON, 2000)
let Data = {
daemon_connection: daemon.readyState,
};
ipcRenderer.send('request-update-daemon-connection', Data);
});
/*
client.on('close', function(data) {
console.log(' TNC connection closed');
setTimeout(connectTNC, 2000)
let Data = {
daemon_connection: daemon.readyState,
};
ipcRenderer.send('request-update-daemon-connection', Data);
});
*/
daemon.on('end', function(data) {
console.log('DAEMON connection ended');
setTimeout(connectDAEMON, 2000)
let Data = {
daemon_connection: daemon.readyState,
};
ipcRenderer.send('request-update-daemon-connection', Data);
});
//exports.writeCommand = function(command){

View file

@ -20,7 +20,7 @@ var configPath = path.join(configFolder, 'config.json')
const config = require(configPath);
// START INTERVALL COMMAND EXECUTION FOR STATES
setInterval(daemon.getDaemonState, 1000)
//setInterval(daemon.getDaemonState, 1000)
//setInterval(sock.getTncState, 150)
setInterval(sock.getRxBuffer, 1000)
setInterval(sock.getMsgRxBuffer, 1000)

View file

@ -30,6 +30,10 @@ import sock
class DAEMON():
def __init__(self):
# load crc engine
self.crc_algorithm = crcengine.new('crc16-ccitt-false') # load crc8 library
self.daemon_queue = sock.DAEMON_QUEUE
update_audio_devices = threading.Thread(target=self.update_audio_devices, name="UPDATE_AUDIO_DEVICES")
update_audio_devices.start()
@ -53,7 +57,7 @@ class DAEMON():
for port, desc, hwid in ports:
# calculate hex of hwid if we have unique names
crc_hwid = crc_algorithm(bytes(hwid, encoding='utf-8'))
crc_hwid = self.crc_algorithm(bytes(hwid, encoding='utf-8'))
crc_hwid = crc_hwid.to_bytes(2, byteorder='big')
crc_hwid = crc_hwid.hex()
description = desc + ' [' + crc_hwid + ']'

View file

@ -66,6 +66,11 @@ class RF():
self.AUDIO_CHUNKS = 48 #8 * (self.AUDIO_SAMPLE_RATE_RX/self.MODEM_SAMPLE_RATE) #48
self.AUDIO_CHANNELS = 1
# locking state for mod out so buffer will be filled before we can use it
# https://github.com/DJ2LS/FreeDATA/issues/127
# https://github.com/DJ2LS/FreeDATA/issues/99
self.mod_out_locked = True
# make sure our resampler will work
assert (self.AUDIO_SAMPLE_RATE_RX / self.MODEM_SAMPLE_RATE) == codec2.api.FDMDV_OS_48
@ -215,7 +220,7 @@ class RF():
else:
static.BUFFER_OVERFLOW_COUNTER[2] += 1
if self.modoutqueue.empty():
if self.modoutqueue.empty() or self.mod_out_locked:
data_out48k = bytes(self.AUDIO_FRAMES_PER_BUFFER_TX*2)
self.fft_data = bytes(x)
else:
@ -300,6 +305,9 @@ class RF():
x = np.frombuffer(txbuffer, dtype=np.int16)
txbuffer_48k = self.resampler.resample8_to_48(x)
# explicitly lock our usage of mod_out_queue
self.mod_out_locked = True
# split modualted audio to chunks
#https://newbedev.com/how-to-split-a-byte-string-into-separate-bytes-in-python
txbuffer_48k = bytes(txbuffer_48k)
@ -314,12 +322,18 @@ class RF():
structlog.get_logger("structlog").debug("[TNC] mod out shorter than audio buffer", delta=len(delta))
self.modoutqueue.put(c)
# Release our mod_out_lock so we can use the queue
self.mod_out_locked = False
# maybe we need to toggle PTT before craeting modulation because of queue processing
#static.PTT_STATE = self.hamlib.set_ptt(True)
while not self.modoutqueue.empty():
pass
static.PTT_STATE = self.hamlib.set_ptt(False)
# after processing we want to set the locking state back to true to be prepared for next transmission
self.mod_out_locked = True
self.c_lib.freedv_close(freedv)
self.modem_transmit_queue.task_done()
static.TRANSMITTING = False

View file

@ -85,7 +85,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
data += chunk
if chunk == b'':
print("connection broken. Closing...")
#print("connection broken. Closing...")
self.connection_alive = False
if data.startswith(b'{"type"') and data.endswith(b'}\n'):