diff --git a/gui/daemon.js b/gui/daemon.js index 6fbf1088..82649f52 100644 --- a/gui/daemon.js +++ b/gui/daemon.js @@ -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){ diff --git a/gui/preload-main.js b/gui/preload-main.js index 1abcb8fd..df59a415 100644 --- a/gui/preload-main.js +++ b/gui/preload-main.js @@ -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) diff --git a/tnc/daemon.py b/tnc/daemon.py index 0f53c106..88f74352 100644 --- a/tnc/daemon.py +++ b/tnc/daemon.py @@ -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 + ']' diff --git a/tnc/modem.py b/tnc/modem.py index b708ac44..360dca74 100644 --- a/tnc/modem.py +++ b/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_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 diff --git a/tnc/sock.py b/tnc/sock.py index 6f84796c..a43c99e1 100644 --- a/tnc/sock.py +++ b/tnc/sock.py @@ -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'):