mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
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:
parent
2c57923c11
commit
77adabf450
5 changed files with 41 additions and 5 deletions
|
@ -34,23 +34,41 @@ function connectDAEMON() {
|
||||||
|
|
||||||
daemon.on('connect', function(data) {
|
daemon.on('connect', function(data) {
|
||||||
console.log('DAEMON connection established')
|
console.log('DAEMON connection established')
|
||||||
|
let Data = {
|
||||||
|
daemon_connection: daemon.readyState,
|
||||||
|
};
|
||||||
|
ipcRenderer.send('request-update-daemon-connection', Data);
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
daemon.on('error', function(data) {
|
daemon.on('error', function(data) {
|
||||||
console.log('DAEMON connection error');
|
console.log('DAEMON connection error');
|
||||||
setTimeout(connectDAEMON, 2000)
|
setTimeout(connectDAEMON, 2000)
|
||||||
|
let Data = {
|
||||||
|
daemon_connection: daemon.readyState,
|
||||||
|
};
|
||||||
|
ipcRenderer.send('request-update-daemon-connection', Data);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
client.on('close', function(data) {
|
client.on('close', function(data) {
|
||||||
console.log(' TNC connection closed');
|
console.log(' TNC connection closed');
|
||||||
setTimeout(connectTNC, 2000)
|
setTimeout(connectTNC, 2000)
|
||||||
|
let Data = {
|
||||||
|
daemon_connection: daemon.readyState,
|
||||||
|
};
|
||||||
|
ipcRenderer.send('request-update-daemon-connection', Data);
|
||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
|
|
||||||
daemon.on('end', function(data) {
|
daemon.on('end', function(data) {
|
||||||
console.log('DAEMON connection ended');
|
console.log('DAEMON connection ended');
|
||||||
setTimeout(connectDAEMON, 2000)
|
setTimeout(connectDAEMON, 2000)
|
||||||
|
let Data = {
|
||||||
|
daemon_connection: daemon.readyState,
|
||||||
|
};
|
||||||
|
ipcRenderer.send('request-update-daemon-connection', Data);
|
||||||
});
|
});
|
||||||
|
|
||||||
//exports.writeCommand = function(command){
|
//exports.writeCommand = function(command){
|
||||||
|
|
|
@ -20,7 +20,7 @@ var configPath = path.join(configFolder, 'config.json')
|
||||||
const config = require(configPath);
|
const config = require(configPath);
|
||||||
|
|
||||||
// START INTERVALL COMMAND EXECUTION FOR STATES
|
// START INTERVALL COMMAND EXECUTION FOR STATES
|
||||||
setInterval(daemon.getDaemonState, 1000)
|
//setInterval(daemon.getDaemonState, 1000)
|
||||||
//setInterval(sock.getTncState, 150)
|
//setInterval(sock.getTncState, 150)
|
||||||
setInterval(sock.getRxBuffer, 1000)
|
setInterval(sock.getRxBuffer, 1000)
|
||||||
setInterval(sock.getMsgRxBuffer, 1000)
|
setInterval(sock.getMsgRxBuffer, 1000)
|
||||||
|
|
|
@ -30,6 +30,10 @@ import sock
|
||||||
|
|
||||||
class DAEMON():
|
class DAEMON():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
|
# load crc engine
|
||||||
|
self.crc_algorithm = crcengine.new('crc16-ccitt-false') # load crc8 library
|
||||||
|
|
||||||
self.daemon_queue = sock.DAEMON_QUEUE
|
self.daemon_queue = sock.DAEMON_QUEUE
|
||||||
update_audio_devices = threading.Thread(target=self.update_audio_devices, name="UPDATE_AUDIO_DEVICES")
|
update_audio_devices = threading.Thread(target=self.update_audio_devices, name="UPDATE_AUDIO_DEVICES")
|
||||||
update_audio_devices.start()
|
update_audio_devices.start()
|
||||||
|
@ -53,7 +57,7 @@ class DAEMON():
|
||||||
for port, desc, hwid in ports:
|
for port, desc, hwid in ports:
|
||||||
|
|
||||||
# calculate hex of hwid if we have unique names
|
# 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.to_bytes(2, byteorder='big')
|
||||||
crc_hwid = crc_hwid.hex()
|
crc_hwid = crc_hwid.hex()
|
||||||
description = desc + ' [' + crc_hwid + ']'
|
description = desc + ' [' + crc_hwid + ']'
|
||||||
|
|
16
tnc/modem.py
16
tnc/modem.py
|
@ -66,6 +66,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
|
||||||
|
|
||||||
|
# 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
|
# make sure our resampler will work
|
||||||
assert (self.AUDIO_SAMPLE_RATE_RX / self.MODEM_SAMPLE_RATE) == codec2.api.FDMDV_OS_48
|
assert (self.AUDIO_SAMPLE_RATE_RX / self.MODEM_SAMPLE_RATE) == codec2.api.FDMDV_OS_48
|
||||||
|
|
||||||
|
@ -215,7 +220,7 @@ class RF():
|
||||||
else:
|
else:
|
||||||
static.BUFFER_OVERFLOW_COUNTER[2] += 1
|
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)
|
data_out48k = bytes(self.AUDIO_FRAMES_PER_BUFFER_TX*2)
|
||||||
self.fft_data = bytes(x)
|
self.fft_data = bytes(x)
|
||||||
else:
|
else:
|
||||||
|
@ -300,6 +305,9 @@ class RF():
|
||||||
x = np.frombuffer(txbuffer, dtype=np.int16)
|
x = np.frombuffer(txbuffer, dtype=np.int16)
|
||||||
txbuffer_48k = self.resampler.resample8_to_48(x)
|
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
|
# split modualted audio to chunks
|
||||||
#https://newbedev.com/how-to-split-a-byte-string-into-separate-bytes-in-python
|
#https://newbedev.com/how-to-split-a-byte-string-into-separate-bytes-in-python
|
||||||
txbuffer_48k = bytes(txbuffer_48k)
|
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))
|
structlog.get_logger("structlog").debug("[TNC] mod out shorter than audio buffer", delta=len(delta))
|
||||||
self.modoutqueue.put(c)
|
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
|
# maybe we need to toggle PTT before craeting modulation because of queue processing
|
||||||
#static.PTT_STATE = self.hamlib.set_ptt(True)
|
#static.PTT_STATE = self.hamlib.set_ptt(True)
|
||||||
while not self.modoutqueue.empty():
|
while not self.modoutqueue.empty():
|
||||||
pass
|
pass
|
||||||
static.PTT_STATE = self.hamlib.set_ptt(False)
|
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.c_lib.freedv_close(freedv)
|
||||||
self.modem_transmit_queue.task_done()
|
self.modem_transmit_queue.task_done()
|
||||||
static.TRANSMITTING = False
|
static.TRANSMITTING = False
|
||||||
|
|
|
@ -85,7 +85,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
|
||||||
data += chunk
|
data += chunk
|
||||||
|
|
||||||
if chunk == b'':
|
if chunk == b'':
|
||||||
print("connection broken. Closing...")
|
#print("connection broken. Closing...")
|
||||||
self.connection_alive = False
|
self.connection_alive = False
|
||||||
|
|
||||||
if data.startswith(b'{"type"') and data.endswith(b'}\n'):
|
if data.startswith(b'{"type"') and data.endswith(b'}\n'):
|
||||||
|
|
Loading…
Reference in a new issue