diff --git a/tnc/modem.py b/tnc/modem.py
index acfde2de..4dd1fb37 100644
--- a/tnc/modem.py
+++ b/tnc/modem.py
@@ -67,6 +67,7 @@ class RF:
self.AUDIO_CHANNELS = 1
self.MODE = 0
+
# 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
@@ -355,6 +356,10 @@ class RF:
x = np.frombuffer(data_in48k, dtype=np.int16)
x = self.resampler.resample48_to_8(x)
+ # audio recording for debugging purposes
+ if static.AUDIO_RECORD:
+ static.AUDIO_RECORD_FILE.write(x)
+
# Avoid decoding when transmitting to reduce CPU
# TODO: Overriding this for testing purposes
# if not static.TRANSMITTING:
diff --git a/tnc/sock.py b/tnc/sock.py
index 71a20092..2348ea34 100644
--- a/tnc/sock.py
+++ b/tnc/sock.py
@@ -227,6 +227,25 @@ def process_tnc_commands(data):
"[SCK] CQ command execution error", e=err, command=received_json
)
+ # START STOP AUDIO RECORDING -----------------------------------------------------
+ if received_json["type"] == "set" and received_json["command"] == "record_audio":
+ try:
+ if received_json["state"] in ['true', 'True', True]:
+ static.AUDIO_RECORD_FILE = open(f"{int(time.time())}_audio_recording", 'wb')
+ static.AUDIO_RECORD = True
+ else:
+ static.AUDIO_RECORD = False
+ static.AUDIO_RECORD_FILE.close()
+
+ command_response("respond_to_call", True)
+
+ except Exception as err:
+ command_response("respond_to_call", False)
+ log.warning(
+ "[SCK] CQ command execution error", e=err, command=received_json
+ )
+
+
# SET ENABLE/DISABLE RESPOND TO CALL -----------------------------------------------------
if received_json["type"] == "set" and received_json["command"] == "respond_to_call":
try:
@@ -612,6 +631,7 @@ def send_tnc_state():
"dxgrid": str(static.DXGRID, encoding),
"hamlib_status": static.HAMLIB_STATUS,
"listen": str(static.LISTEN),
+ "audio_recording": str(static.AUDIO_RECORD),
}
# add heard stations to heard stations object
diff --git a/tnc/static.py b/tnc/static.py
index bd973d24..19a9ee56 100644
--- a/tnc/static.py
+++ b/tnc/static.py
@@ -82,6 +82,8 @@ AUDIO_INPUT_DEVICES: list = []
AUDIO_OUTPUT_DEVICES: list = []
AUDIO_INPUT_DEVICE: int = -2
AUDIO_OUTPUT_DEVICE: int = -2
+AUDIO_RECORD: bool = False
+AUDIO_RECORD_FILE = ''
BUFFER_OVERFLOW_COUNTER: list = [0, 0, 0, 0, 0]
AUDIO_DBFS: int = 0
From 7691ba09ac66bdee5f9e630045af37749091a2bb Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Mon, 26 Dec 2022 12:27:13 +0100
Subject: [PATCH 19/58] record audio update
---
gui/preload-main.js | 4 +++-
gui/sock.js | 6 +++++-
tnc/sock.py | 4 ++--
3 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/gui/preload-main.js b/gui/preload-main.js
index f07f100e..ab64178c 100644
--- a/gui/preload-main.js
+++ b/gui/preload-main.js
@@ -45,7 +45,6 @@ window.addEventListener('DOMContentLoaded', () => {
let Data = {
type: "set",
command: "record_audio",
- state: "True",
};
ipcRenderer.send('run-tnc-command', Data);
@@ -2105,6 +2104,9 @@ ipcRenderer.on('run-tnc-command', (event, arg) => {
if (arg.command == 'set_tx_audio_level') {
sock.setTxAudioLevel(arg.tx_audio_level);
}
+ if (arg.command == 'record_audio') {
+ sock.record_audio();
+ }
if (arg.command == 'send_test_frame') {
sock.sendTestFrame();
}
diff --git a/gui/sock.js b/gui/sock.js
index 9bdb443d..25c52f35 100644
--- a/gui/sock.js
+++ b/gui/sock.js
@@ -586,7 +586,11 @@ exports.sendTestFrame = function() {
writeTncCommand(command)
}
-
+// RECORD AUDIO
+exports.record_audio = function() {
+ command = '{"type" : "set", "command" : "record_audio"}'
+ writeTncCommand(command)
+}
ipcRenderer.on('action-update-tnc-ip', (event, arg) => {
client.destroy();
diff --git a/tnc/sock.py b/tnc/sock.py
index 2348ea34..4e878997 100644
--- a/tnc/sock.py
+++ b/tnc/sock.py
@@ -230,8 +230,8 @@ def process_tnc_commands(data):
# START STOP AUDIO RECORDING -----------------------------------------------------
if received_json["type"] == "set" and received_json["command"] == "record_audio":
try:
- if received_json["state"] in ['true', 'True', True]:
- static.AUDIO_RECORD_FILE = open(f"{int(time.time())}_audio_recording", 'wb')
+ if not static.AUDIO_RECORD:
+ static.AUDIO_RECORD_FILE = open(f"{int(time.time())}_audio_recording.raw", 'wb')
static.AUDIO_RECORD = True
else:
static.AUDIO_RECORD = False
From 4d8b8f7f467eac9130972c9fb6e0fcbcb0aa398f Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Mon, 26 Dec 2022 12:49:01 +0100
Subject: [PATCH 20/58] accepted some sourcery suggestions
---
tnc/explorer.py | 6 +----
tnc/helpers.py | 6 +----
tnc/modem.py | 64 +++++++++++++++++++++++++++----------------------
3 files changed, 38 insertions(+), 38 deletions(-)
diff --git a/tnc/explorer.py b/tnc/explorer.py
index bed33e80..08820867 100644
--- a/tnc/explorer.py
+++ b/tnc/explorer.py
@@ -32,11 +32,7 @@ class explorer():
def push(self):
-
- if static.HAMLIB_FREQUENCY is not None:
- frequency = static.HAMLIB_FREQUENCY
- else:
- frequency = 0
+ frequency = 0 if static.HAMLIB_FREQUENCY is None else static.HAMLIB_FREQUENCY
band = "USB"
callsign = str(static.MYCALLSIGN, "utf-8")
gridsquare = str(static.MYGRID, "utf-8")
diff --git a/tnc/helpers.py b/tnc/helpers.py
index 6fff1e25..0361d908 100644
--- a/tnc/helpers.py
+++ b/tnc/helpers.py
@@ -394,11 +394,7 @@ def decode_grid(b_code_word: bytes):
int_val = int(code_word & 0b111111111)
int_first, int_sec = divmod(int_val, 18)
- # int_first = int_val // 18
- # int_sec = int_val % 18
- grid = chr(int(int_first) + 65) + chr(int(int_sec) + 65) + grid
-
- return grid
+ return chr(int(int_first) + 65) + chr(int(int_sec) + 65) + grid
def encode_call(call):
diff --git a/tnc/modem.py b/tnc/modem.py
index 4dd1fb37..4cfaaace 100644
--- a/tnc/modem.py
+++ b/tnc/modem.py
@@ -5,6 +5,7 @@ Created on Wed Dec 23 07:04:24 2020
@author: DJ2LS
"""
+
# pylint: disable=invalid-name, line-too-long, c-extension-no-member
# pylint: disable=import-outside-toplevel
@@ -17,6 +18,7 @@ import time
from collections import deque
import codec2
+import itertools
import numpy as np
import sock
import sounddevice as sd
@@ -363,23 +365,25 @@ class RF:
# Avoid decoding when transmitting to reduce CPU
# TODO: Overriding this for testing purposes
# if not static.TRANSMITTING:
- if True:
- length_x = len(x)
+ length_x = len(x)
+
+ # Avoid buffer overflow by filling only if buffer for
+ # selected datachannel mode is not full
+ for audiobuffer, receive, index in [
+ (self.sig0_datac0_buffer, RECEIVE_SIG0, 0),
+ (self.sig1_datac0_buffer, RECEIVE_SIG1, 1),
+ (self.dat0_datac1_buffer, RECEIVE_DATAC1, 2),
+ (self.dat0_datac3_buffer, RECEIVE_DATAC3, 3),
+ (self.fsk_ldpc_buffer_0, static.ENABLE_FSK, 4),
+ (self.fsk_ldpc_buffer_1, static.ENABLE_FSK, 5),
+ ]:
+ if audiobuffer.nbuffer + length_x > audiobuffer.size:
+ static.BUFFER_OVERFLOW_COUNTER[index] += 1
+ elif receive:
+ audiobuffer.push(x)
+ # end of "not static.TRANSMITTING" if block
+
- # Avoid buffer overflow by filling only if buffer for
- # selected datachannel mode is not full
- for audiobuffer, receive, index in [
- (self.sig0_datac0_buffer, RECEIVE_SIG0, 0),
- (self.sig1_datac0_buffer, RECEIVE_SIG1, 1),
- (self.dat0_datac1_buffer, RECEIVE_DATAC1, 2),
- (self.dat0_datac3_buffer, RECEIVE_DATAC3, 3),
- (self.fsk_ldpc_buffer_0, static.ENABLE_FSK, 4),
- (self.fsk_ldpc_buffer_1, static.ENABLE_FSK, 5),
- ]:
- if audiobuffer.nbuffer + length_x > audiobuffer.size:
- static.BUFFER_OVERFLOW_COUNTER[index] += 1
- elif receive:
- audiobuffer.push(x)
if len(self.modoutqueue) <= 0 or self.mod_out_locked:
# if not self.modoutqueue or self.mod_out_locked:
@@ -849,13 +853,21 @@ class RF:
)
scatterdata = []
- for i in range(codec2.MODEM_STATS_NC_MAX):
- for j in range(1, codec2.MODEM_STATS_NR_MAX, 2):
- # print(f"{modemStats.rx_symbols[i][j]} - {modemStats.rx_symbols[i][j]}")
- xsymbols = round(modemStats.rx_symbols[i][j - 1] // 1000)
- ysymbols = round(modemStats.rx_symbols[i][j] // 1000)
- if xsymbols != 0.0 and ysymbols != 0.0:
- scatterdata.append({"x": str(xsymbols), "y": str(ysymbols)})
+ # original function before itertool
+ #for i in range(codec2.MODEM_STATS_NC_MAX):
+ # for j in range(1, codec2.MODEM_STATS_NR_MAX, 2):
+ # # print(f"{modemStats.rx_symbols[i][j]} - {modemStats.rx_symbols[i][j]}")
+ # xsymbols = round(modemStats.rx_symbols[i][j - 1] // 1000)
+ # ysymbols = round(modemStats.rx_symbols[i][j] // 1000)
+ # if xsymbols != 0.0 and ysymbols != 0.0:
+ # scatterdata.append({"x": str(xsymbols), "y": str(ysymbols)})
+
+ for i, j in itertools.product(range(codec2.MODEM_STATS_NC_MAX), range(1, codec2.MODEM_STATS_NR_MAX, 2)):
+ # print(f"{modemStats.rx_symbols[i][j]} - {modemStats.rx_symbols[i][j]}")
+ xsymbols = round(modemStats.rx_symbols[i][j - 1] // 1000)
+ ysymbols = round(modemStats.rx_symbols[i][j] // 1000)
+ if xsymbols != 0.0 and ysymbols != 0.0:
+ scatterdata.append({"x": str(xsymbols), "y": str(ysymbols)})
# Send all the data if we have too-few samples, otherwise send a sampling
if 150 > len(scatterdata) > 0:
@@ -985,11 +997,7 @@ class RF:
# 3200Hz = 315
# define the area, we are detecting busy state
- if static.LOW_BANDWIDTH_MODE:
- dfft = dfft[120:176]
- else:
- dfft = dfft[65:231]
-
+ dfft = dfft[120:176] if static.LOW_BANDWIDTH_MODE else dfft[65:231]
# Check for signals higher than average by checking for "100"
# If we have a signal, increment our channel_busy delay counter
From 62309d608df94560c47de0e6a8990a394a1db1e0 Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Mon, 26 Dec 2022 17:14:23 +0100
Subject: [PATCH 21/58] improved audio callback modout queue
---
tnc/modem.py | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/tnc/modem.py b/tnc/modem.py
index 4cfaaace..93d24fe4 100644
--- a/tnc/modem.py
+++ b/tnc/modem.py
@@ -383,10 +383,7 @@ class RF:
audiobuffer.push(x)
# end of "not static.TRANSMITTING" if block
-
-
- if len(self.modoutqueue) <= 0 or self.mod_out_locked:
- # if not self.modoutqueue or self.mod_out_locked:
+ if not self.modoutqueue or self.mod_out_locked:
data_out48k = np.zeros(frames, dtype=np.int16)
self.fft_data = x
else:
From a9139d035ceb6e87e40cb0296d78cfa7faa5aef0 Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Mon, 26 Dec 2022 20:41:58 +0100
Subject: [PATCH 22/58] fixed message order bug
---
gui/preload-chat.js | 51 ++++++++++++++++++++++++++++++++-------------
1 file changed, 37 insertions(+), 14 deletions(-)
diff --git a/gui/preload-chat.js b/gui/preload-chat.js
index 7e9dc775..a3a111e2 100644
--- a/gui/preload-chat.js
+++ b/gui/preload-chat.js
@@ -61,25 +61,51 @@ try{
}
PouchDB.plugin(require('pouchdb-find'));
-var db = new PouchDB(chatDB);
-var remoteDB = new PouchDB('http://192.168.178.79:5984/chatDB')
+//PouchDB.plugin(require('pouchdb-replication'));
-db.sync(remoteDB, {
+var db = new PouchDB(chatDB);
+
+/*
+// REMOTE SYNC ATTEMPTS
+
+
+var remoteDB = new PouchDB('http://172.20.10.4:5984/chatDB')
+
+// we need express packages for running pouchdb sync "express-pouchdb"
+var express = require('express');
+var app = express();
+//app.use('/chatDB', require('express-pouchdb')(PouchDB));
+//app.listen(5984);
+
+app.use('/chatDB', require('pouchdb-express-router')(PouchDB));
+app.listen(5984);
+
+
+
+db.sync('http://172.20.10.4:5984/jojo', {
+//var sync = PouchDB.sync('chatDB', 'http://172.20.10.4:5984/chatDB', {
live: true,
- retry: true
+ retry: false
}).on('change', function (change) {
// yo, something changed!
console.log(change)
-}).on('paused', function (info) {
+}).on('paused', function (err) {
// replication was paused, usually because of a lost connection
- console.log(info)
+ console.log(err)
}).on('active', function (info) {
// replication was resumed
console.log(info)
}).on('error', function (err) {
// totally unhandled error (shouldn't happen)
- console.log(error)
+ console.log(err)
+}).on('denied', function (err) {
+ // a document failed to replicate (e.g. due to permissions)
+ console.log(err)
+}).on('complete', function (info) {
+ // handle complete;
+ console.log(info)
});
+*/
var dxcallsigns = new Set();
db.createIndex({
@@ -404,7 +430,7 @@ ipcRenderer.on('action-new-msg-received', (event, arg) => {
//handle ping
if (item.ping == 'received') {
- obj.timestamp = item.timestamp;
+ obj.timestamp = parseInt(item.timestamp);
obj.dxcallsign = item.dxcallsign;
obj.dxgrid = item.dxgrid;
obj.uuid = item.uuid;
@@ -421,12 +447,9 @@ ipcRenderer.on('action-new-msg-received', (event, arg) => {
add_obj_to_database(obj)
update_chat_obj_by_uuid(obj.uuid);
-
-
-
// handle beacon
} else if (item.beacon == 'received') {
- obj.timestamp = item.timestamp;
+ obj.timestamp = parseInt(item.timestamp);
obj.dxcallsign = item.dxcallsign;
obj.dxgrid = item.dxgrid;
obj.uuid = item.uuid;
@@ -451,7 +474,7 @@ ipcRenderer.on('action-new-msg-received', (event, arg) => {
console.log(splitted_data)
- obj.timestamp = splitted_data[8];
+ obj.timestamp = parseInt(splitted_data[8]);
obj.dxcallsign = item.dxcallsign;
obj.dxgrid = item.dxgrid;
obj.command = splitted_data[1];
@@ -939,7 +962,7 @@ update_chat_obj_by_uuid = function(uuid) {
add_obj_to_database = function(obj){
db.put({
_id: obj.uuid,
- timestamp: obj.timestamp,
+ timestamp: parseInt(obj.timestamp),
uuid: obj.uuid,
dxcallsign: obj.dxcallsign,
dxgrid: obj.dxgrid,
From f5a30e33e3d169da199668e3f0eea299f0ca0e26 Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Mon, 26 Dec 2022 21:14:23 +0100
Subject: [PATCH 23/58] publish last heard stations to explorer
---
tnc/explorer.py | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/tnc/explorer.py b/tnc/explorer.py
index 08820867..3bb135b5 100644
--- a/tnc/explorer.py
+++ b/tnc/explorer.py
@@ -43,7 +43,14 @@ class explorer():
log.info("[EXPLORER] publish", frequency=frequency, band=band, callsign=callsign, gridsquare=gridsquare, version=version, bandwidth=bandwidth)
headers = {"Content-Type": "application/json"}
- station_data = {'callsign': callsign, 'gridsquare': gridsquare, 'frequency': frequency, 'band': band, 'version': version, 'bandwidth': bandwidth, 'beacon': beacon}
+ station_data = {'callsign': callsign, 'gridsquare': gridsquare, 'frequency': frequency, 'band': band, 'version': version, 'bandwidth': bandwidth, 'beacon': beacon, "lastheard": []}
+
+ for i in static.HEARD_STATIONS:
+ callsign = str(i[0], "UTF-8")
+ grid = str(i[1], "UTF-8")
+ snr = i[4].split("/")[1]
+ station_data["lastheard"].append({"callsign": callsign, "grid": grid, "snr": snr})
+
station_data = json.dumps(station_data)
try:
response = requests.post(self.explorer_url, json=station_data, headers=headers)
From 7ed43fb3f9002dcee6e117248e7d4b76e45e6f72 Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Tue, 27 Dec 2022 09:53:21 +0100
Subject: [PATCH 24/58] moved utf8 encoding from entire data to just chat
message
---
gui/preload-chat.js | 4 +++-
gui/sock.js | 8 ++++++--
tnc/modem.py | 3 +--
3 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/gui/preload-chat.js b/gui/preload-chat.js
index a3a111e2..6747779c 100644
--- a/gui/preload-chat.js
+++ b/gui/preload-chat.js
@@ -862,7 +862,9 @@ update_chat = function(obj) {
}).then(function(){
console.log(binaryString)
- var data_with_attachment = doc.msg + split_char + filename + split_char + filetype + split_char + binaryString + split_char + doc.timestamp;
+ console.log(binaryString.length)
+
+ var data_with_attachment = utf8.encode(doc.msg) + split_char + filename + split_char + filetype + split_char + binaryString + split_char + doc.timestamp;
let Data = {
command: "send_message",
dxcallsign: doc.dxcallsign,
diff --git a/gui/sock.js b/gui/sock.js
index 25c52f35..54fa2669 100644
--- a/gui/sock.js
+++ b/gui/sock.js
@@ -518,9 +518,13 @@ exports.sendFile = function(dxcallsign, mode, frames, filename, filetype, data,
// Send Message
exports.sendMessage = function(dxcallsign, mode, frames, data, checksum, uuid, command) {
socketLog.info(data)
+
+ // Disabled this here
// convert message to plain utf8 because of unicode emojis
- data = utf8.encode(data)
- socketLog.info(data)
+ //data = utf8.encode(data)
+
+ //socketLog.info(data)
+
var datatype = "m"
data = datatype + split_char + command + split_char + checksum + split_char + uuid + split_char + data
diff --git a/tnc/modem.py b/tnc/modem.py
index 93d24fe4..e4277ed0 100644
--- a/tnc/modem.py
+++ b/tnc/modem.py
@@ -916,12 +916,11 @@ class RF:
- static.HAMLIB_BANDWIDTH
"""
while True:
- threading.Event().wait(0.5)
+ threading.Event().wait(0.25)
static.HAMLIB_FREQUENCY = self.hamlib.get_frequency()
static.HAMLIB_MODE = self.hamlib.get_mode()
static.HAMLIB_BANDWIDTH = self.hamlib.get_bandwidth()
static.HAMLIB_STATUS = self.hamlib.get_status()
-
def calculate_fft(self) -> None:
"""
Calculate an average signal strength of the channel to assess
From d78fcba4fbcf7962dbe775c1b010628bc69e5ca4 Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Tue, 27 Dec 2022 10:37:34 +0100
Subject: [PATCH 25/58] catching explorer type error
---
tnc/explorer.py | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/tnc/explorer.py b/tnc/explorer.py
index 3bb135b5..f84b69f5 100644
--- a/tnc/explorer.py
+++ b/tnc/explorer.py
@@ -46,10 +46,13 @@ class explorer():
station_data = {'callsign': callsign, 'gridsquare': gridsquare, 'frequency': frequency, 'band': band, 'version': version, 'bandwidth': bandwidth, 'beacon': beacon, "lastheard": []}
for i in static.HEARD_STATIONS:
- callsign = str(i[0], "UTF-8")
- grid = str(i[1], "UTF-8")
- snr = i[4].split("/")[1]
- station_data["lastheard"].append({"callsign": callsign, "grid": grid, "snr": snr})
+ try:
+ callsign = str(i[0], "UTF-8")
+ grid = str(i[1], "UTF-8")
+ snr = i[4].split("/")[1]
+ station_data["lastheard"].append({"callsign": callsign, "grid": grid, "snr": snr})
+ except Exception as e:
+ log.debug("[EXPLORER] not publishing station", e=e)
station_data = json.dumps(station_data)
try:
From c78fff4db1bb1dca371a9dd37c8e667fc9912349 Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Tue, 27 Dec 2022 11:29:24 +0100
Subject: [PATCH 26/58] catching explorer type error
---
gui/package.json | 3 +++
1 file changed, 3 insertions(+)
diff --git a/gui/package.json b/gui/package.json
index 1bc6cf4a..3cbaa1de 100644
--- a/gui/package.json
+++ b/gui/package.json
@@ -38,10 +38,13 @@
"electron-updater": "^5.2.1",
"emoji-picker-element": "^1.12.1",
"emoji-picker-element-data": "^1.3.0",
+ "express-pouchdb": "^4.2.0",
"mime": "^3.0.0",
"pouchdb": "^7.3.0",
"pouchdb-browser": "^7.3.0",
+ "pouchdb-express-router": "^0.0.11",
"pouchdb-find": "^7.3.0",
+ "pouchdb-replication": "^8.0.0",
"qth-locator": "^2.1.0",
"utf8": "^3.0.0",
"uuid": "^9.0.0"
From 9a4401082c5aa33f793371c802a328197b7dd9f7 Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Tue, 27 Dec 2022 11:33:16 +0100
Subject: [PATCH 27/58] catching explorer type error
---
tnc/explorer.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/tnc/explorer.py b/tnc/explorer.py
index f84b69f5..4d82d8ad 100644
--- a/tnc/explorer.py
+++ b/tnc/explorer.py
@@ -49,7 +49,10 @@ class explorer():
try:
callsign = str(i[0], "UTF-8")
grid = str(i[1], "UTF-8")
- snr = i[4].split("/")[1]
+ try:
+ snr = i[4].split("/")[1]
+ except AttributeError:
+ snr = str(i[4])
station_data["lastheard"].append({"callsign": callsign, "grid": grid, "snr": snr})
except Exception as e:
log.debug("[EXPLORER] not publishing station", e=e)
From fd402d9bc25c41e55fe718d8ae1bdf2c3bcbcd5b Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Tue, 27 Dec 2022 11:41:00 +0100
Subject: [PATCH 28/58] catch error in dbfs calculation
---
tnc/modem.py | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/tnc/modem.py b/tnc/modem.py
index e4277ed0..f13abfda 100644
--- a/tnc/modem.py
+++ b/tnc/modem.py
@@ -970,8 +970,13 @@ class RF:
# calculate RMS and then dBFS
# TODO: Need to change static.AUDIO_RMS to AUDIO_DBFS somewhen
# https://dsp.stackexchange.com/questions/8785/how-to-compute-dbfs
- rms = int(np.sqrt(np.max(d ** 2)))
- static.AUDIO_DBFS = 20 * np.log10(rms / 32768)
+ # try except for avoiding runtime errors by division/0
+ try:
+ rms = int(np.sqrt(np.max(d ** 2)))
+ static.AUDIO_DBFS = 20 * np.log10(rms / 32768)
+ except Exception as e:
+ self.log.warning(f"[MDM] fft calculation error - please check your audio setup", e=e)
+ static.AUDIO_DBFS = -100
rms_counter = 0
From cb78ed984a0ed78b39515a8fd3f13c01f9828c6c Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Tue, 27 Dec 2022 13:02:01 +0100
Subject: [PATCH 29/58] reduced rigctld connection chunk size - attempt fixing
the ptt delay problem
---
tnc/rigctld.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tnc/rigctld.py b/tnc/rigctld.py
index 76308fe5..1c400458 100644
--- a/tnc/rigctld.py
+++ b/tnc/rigctld.py
@@ -122,7 +122,7 @@ class radio:
self.connected = False
try:
- return self.connection.recv(1024)
+ return self.connection.recv(128)
except Exception:
self.log.warning(
"[RIGCTLD] No command response!",
From 9dad094e47cf9c448f1c60bafdc8d9719f19423b Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Tue, 27 Dec 2022 13:13:11 +0100
Subject: [PATCH 30/58] reduced rigctld connection chunk size - attempt fixing
the ptt delay problem
---
tnc/rigctld.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tnc/rigctld.py b/tnc/rigctld.py
index 1c400458..6a9fd928 100644
--- a/tnc/rigctld.py
+++ b/tnc/rigctld.py
@@ -122,7 +122,7 @@ class radio:
self.connected = False
try:
- return self.connection.recv(128)
+ return self.connection.recv(16)
except Exception:
self.log.warning(
"[RIGCTLD] No command response!",
From d572772df3d133eb12b021174b073c8694f93036 Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Tue, 27 Dec 2022 17:11:46 +0100
Subject: [PATCH 31/58] use busy detection while opening a channel
---
tnc/data_handler.py | 60 +++++++++++++++++++++++----------------------
1 file changed, 31 insertions(+), 29 deletions(-)
diff --git a/tnc/data_handler.py b/tnc/data_handler.py
index fd66a7f0..44552860 100644
--- a/tnc/data_handler.py
+++ b/tnc/data_handler.py
@@ -1840,36 +1840,7 @@ class DATA:
# for calculating transmission statistics
# static.ARQ_COMPRESSION_FACTOR = len(data_out) / len(lzma.compress(data_out))
- # Let's check if we have a busy channel and if we are not in a running arq session.
- if static.CHANNEL_BUSY and not static.ARQ_SESSION:
- self.log.warning("[TNC] Channel busy, waiting until free...")
- self.send_data_to_socket_queue(
- freedata="tnc-message",
- arq="transmission",
- status="waiting",
- mycallsign=str(self.mycallsign, 'UTF-8'),
- dxcallsign=str(self.dxcallsign, 'UTF-8'),
- )
- # wait while timeout not reached and our busy state is busy
- channel_busy_timeout = time.time() + 30
- while static.CHANNEL_BUSY and time.time() < channel_busy_timeout:
- threading.Event().wait(0.01)
-
- # if channel busy timeout reached, stop connecting
- if time.time() > channel_busy_timeout:
- self.log.warning("[TNC] Channel busy, try again later...")
- static.ARQ_SESSION_STATE = "failed"
- self.send_data_to_socket_queue(
- freedata="tnc-message",
- arq="transmission",
- status="failed",
- reason="busy",
- mycallsign=str(self.mycallsign, 'UTF-8'),
- dxcallsign=str(self.dxcallsign, 'UTF-8'),
- )
- static.ARQ_SESSION_STATE = "disconnected"
- return False
self.arq_open_data_channel(mode, n_frames_per_burst, mycallsign)
@@ -1945,6 +1916,37 @@ class DATA:
attempt=f"{str(attempt + 1)}/{str(self.data_channel_max_retries)}",
)
+ # Let's check if we have a busy channel and if we are not in a running arq session.
+ if static.CHANNEL_BUSY and not static.ARQ_STATE:
+ self.log.warning("[TNC] Channel busy, waiting until free...")
+ self.send_data_to_socket_queue(
+ freedata="tnc-message",
+ arq="transmission",
+ status="waiting",
+ mycallsign=str(self.mycallsign, 'UTF-8'),
+ dxcallsign=str(self.dxcallsign, 'UTF-8'),
+ )
+
+ # wait while timeout not reached and our busy state is busy
+ channel_busy_timeout = time.time() + 30
+ while static.CHANNEL_BUSY and time.time() < channel_busy_timeout:
+ threading.Event().wait(0.01)
+
+ # if channel busy timeout reached, stop connecting
+ if time.time() > channel_busy_timeout:
+ self.log.warning("[TNC] Channel busy, try again later...")
+ static.ARQ_SESSION_STATE = "failed"
+ self.send_data_to_socket_queue(
+ freedata="tnc-message",
+ arq="transmission",
+ status="failed",
+ reason="busy",
+ mycallsign=str(self.mycallsign, 'UTF-8'),
+ dxcallsign=str(self.dxcallsign, 'UTF-8'),
+ )
+ static.ARQ_SESSION_STATE = "disconnected"
+ return False
+
self.enqueue_frame_for_tx([connection_frame], c2_mode=FREEDV_MODE.datac0.value, copies=1, repeat_delay=0)
timeout = time.time() + 3
From 281731d890bb0762b9f0d0aeb7206b4ba2914dce Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Tue, 27 Dec 2022 17:48:06 +0100
Subject: [PATCH 32/58] process rigctld response only if needed
---
tnc/rigctld.py | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/tnc/rigctld.py b/tnc/rigctld.py
index 6a9fd928..c802eab9 100644
--- a/tnc/rigctld.py
+++ b/tnc/rigctld.py
@@ -101,7 +101,7 @@ class radio:
self.sock.close()
self.connected = False
- def send_command(self, command) -> bytes:
+ def send_command(self, command, expect_answer) -> bytes:
"""Send a command to the connected rotctld instance,
and return the return value.
@@ -122,7 +122,12 @@ class radio:
self.connected = False
try:
- return self.connection.recv(16)
+ # recv seems to be blocking so in case of ptt we dont need the response
+ # maybe this speeds things up and avoids blocking states
+ if expect_answer:
+ return self.connection.recv(16)
+ else:
+ return True
except Exception:
self.log.warning(
"[RIGCTLD] No command response!",
@@ -146,7 +151,7 @@ class radio:
def get_mode(self):
""" """
try:
- data = self.send_command(b"m")
+ data = self.send_command(b"m", True)
data = data.split(b"\n")
data = data[0].decode("utf-8")
if 'RPRT' not in data:
@@ -159,7 +164,7 @@ class radio:
def get_bandwidth(self):
""" """
try:
- data = self.send_command(b"m")
+ data = self.send_command(b"m", True)
data = data.split(b"\n")
data = data[1].decode("utf-8")
@@ -172,7 +177,7 @@ class radio:
def get_frequency(self):
""" """
try:
- data = self.send_command(b"f")
+ data = self.send_command(b"f", True)
data = data.decode("utf-8")
if 'RPRT' not in data:
self.frequency = data
@@ -184,7 +189,7 @@ class radio:
def get_ptt(self):
""" """
try:
- return self.send_command(b"t")
+ return self.send_command(b"t", True)
except Exception:
return False
@@ -199,9 +204,9 @@ class radio:
"""
try:
if state:
- self.send_command(b"T 1")
+ self.send_command(b"T 1", False)
else:
- self.send_command(b"T 0")
+ self.send_command(b"T 0", False)
return state
except Exception:
return False
From eaa16ed50b86196357cebdf42d53ac44d9100ccc Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Tue, 27 Dec 2022 17:49:49 +0100
Subject: [PATCH 33/58] process rigctld response only if needed
---
tnc/rigctld.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tnc/rigctld.py b/tnc/rigctld.py
index c802eab9..d8bd4775 100644
--- a/tnc/rigctld.py
+++ b/tnc/rigctld.py
@@ -155,7 +155,7 @@ class radio:
data = data.split(b"\n")
data = data[0].decode("utf-8")
if 'RPRT' not in data:
- self.mode = data
+ self.mode = str(data)
return self.mode
except Exception:
@@ -180,7 +180,7 @@ class radio:
data = self.send_command(b"f", True)
data = data.decode("utf-8")
if 'RPRT' not in data:
- self.frequency = data
+ self.frequency = int(data)
return self.frequency
except Exception:
From 5a0a766aa080cde82257f8099d34fd7779f7b9fa Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Tue, 27 Dec 2022 17:57:04 +0100
Subject: [PATCH 34/58] process rigctld response only if needed
---
tnc/rigctld.py | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/tnc/rigctld.py b/tnc/rigctld.py
index d8bd4775..c0c3e30e 100644
--- a/tnc/rigctld.py
+++ b/tnc/rigctld.py
@@ -155,7 +155,10 @@ class radio:
data = data.split(b"\n")
data = data[0].decode("utf-8")
if 'RPRT' not in data:
- self.mode = str(data)
+ try:
+ data = int(data)
+ except ValueError:
+ self.mode = str(data)
return self.mode
except Exception:
@@ -169,7 +172,10 @@ class radio:
data = data[1].decode("utf-8")
if 'RPRT' not in data:
- self.bandwidth = int(data)
+ try:
+ self.bandwidth = int(data)
+ except ValueError:
+ pass
return self.bandwidth
except Exception:
return self.bandwidth
@@ -180,7 +186,10 @@ class radio:
data = self.send_command(b"f", True)
data = data.decode("utf-8")
if 'RPRT' not in data:
- self.frequency = int(data)
+ try:
+ self.frequency = int(data)
+ except ValueError:
+ pass
return self.frequency
except Exception:
From d6df3007db87cbb6bc27d01bfd46200decc59617 Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Tue, 27 Dec 2022 18:04:29 +0100
Subject: [PATCH 35/58] process rigctld response only if needed
---
tnc/rigctld.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tnc/rigctld.py b/tnc/rigctld.py
index c0c3e30e..deff4f45 100644
--- a/tnc/rigctld.py
+++ b/tnc/rigctld.py
@@ -185,7 +185,7 @@ class radio:
try:
data = self.send_command(b"f", True)
data = data.decode("utf-8")
- if 'RPRT' not in data:
+ if 'RPRT' not in data and data not in [0, '0', '']:
try:
self.frequency = int(data)
except ValueError:
From 76522db08299896b1603a30189910b9e456abb3c Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Tue, 27 Dec 2022 18:17:12 +0100
Subject: [PATCH 36/58] process rigctld response only if needed
---
tnc/data_handler.py | 2 +-
tnc/modem.py | 5 ++++-
tnc/rigctld.py | 22 +++++++++-------------
3 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/tnc/data_handler.py b/tnc/data_handler.py
index 44552860..1be4d544 100644
--- a/tnc/data_handler.py
+++ b/tnc/data_handler.py
@@ -1534,7 +1534,7 @@ class DATA:
+ "]>>?<<["
+ str(self.dxcallsign, "UTF-8")
+ "]",
- a=str(attempt + 1) + "/" + str(self.session_connect_max_retries), # Adjust for 0-based for user display
+ a=f"{str(attempt + 1)}/{str(self.session_connect_max_retries)}",
state=static.ARQ_SESSION_STATE,
)
diff --git a/tnc/modem.py b/tnc/modem.py
index f13abfda..388938f7 100644
--- a/tnc/modem.py
+++ b/tnc/modem.py
@@ -975,7 +975,10 @@ class RF:
rms = int(np.sqrt(np.max(d ** 2)))
static.AUDIO_DBFS = 20 * np.log10(rms / 32768)
except Exception as e:
- self.log.warning(f"[MDM] fft calculation error - please check your audio setup", e=e)
+ self.log.warning(
+ "[MDM] fft calculation error - please check your audio setup",
+ e=e,
+ )
static.AUDIO_DBFS = -100
rms_counter = 0
diff --git a/tnc/rigctld.py b/tnc/rigctld.py
index deff4f45..e4ab069a 100644
--- a/tnc/rigctld.py
+++ b/tnc/rigctld.py
@@ -4,6 +4,7 @@
#
# modified and adjusted to FreeDATA needs by DJ2LS
+import contextlib
import socket
import time
import structlog
@@ -124,10 +125,7 @@ class radio:
try:
# recv seems to be blocking so in case of ptt we dont need the response
# maybe this speeds things up and avoids blocking states
- if expect_answer:
- return self.connection.recv(16)
- else:
- return True
+ return self.connection.recv(16) if expect_answer else True
except Exception:
self.log.warning(
"[RIGCTLD] No command response!",
@@ -171,11 +169,9 @@ class radio:
data = data.split(b"\n")
data = data[1].decode("utf-8")
- if 'RPRT' not in data:
- try:
+ if 'RPRT' not in data and data not in ['']:
+ with contextlib.suppress(ValueError):
self.bandwidth = int(data)
- except ValueError:
- pass
return self.bandwidth
except Exception:
return self.bandwidth
@@ -186,11 +182,11 @@ class radio:
data = self.send_command(b"f", True)
data = data.decode("utf-8")
if 'RPRT' not in data and data not in [0, '0', '']:
- try:
- self.frequency = int(data)
- except ValueError:
- pass
-
+ with contextlib.suppress(ValueError):
+ data = int(data)
+ # make sure we have a frequency and not bandwidth
+ if data >= 10000:
+ self.frequency = data
return self.frequency
except Exception:
return self.frequency
From 3dc06510c16f85db1041386ce627641e3c558463 Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Tue, 27 Dec 2022 21:13:08 +0100
Subject: [PATCH 37/58] moving from raw to wave file format
---
tnc/modem.py | 5 +++--
tnc/sock.py | 6 +++++-
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/tnc/modem.py b/tnc/modem.py
index 388938f7..c25869eb 100644
--- a/tnc/modem.py
+++ b/tnc/modem.py
@@ -16,7 +16,7 @@ import sys
import threading
import time
from collections import deque
-
+import wave
import codec2
import itertools
import numpy as np
@@ -360,7 +360,8 @@ class RF:
# audio recording for debugging purposes
if static.AUDIO_RECORD:
- static.AUDIO_RECORD_FILE.write(x)
+ #static.AUDIO_RECORD_FILE.write(x)
+ static.AUDIO_RECORD_FILE.writeframes(x)
# Avoid decoding when transmitting to reduce CPU
# TODO: Overriding this for testing purposes
diff --git a/tnc/sock.py b/tnc/sock.py
index 4e878997..82b313eb 100644
--- a/tnc/sock.py
+++ b/tnc/sock.py
@@ -24,6 +24,7 @@ import socketserver
import sys
import threading
import time
+import wave
import helpers
import static
@@ -231,7 +232,10 @@ def process_tnc_commands(data):
if received_json["type"] == "set" and received_json["command"] == "record_audio":
try:
if not static.AUDIO_RECORD:
- static.AUDIO_RECORD_FILE = open(f"{int(time.time())}_audio_recording.raw", 'wb')
+ static.AUDIO_RECORD_FILE = wave.open(f"{int(time.time())}_audio_recording.wav", 'w')
+ static.AUDIO_RECORD_FILE.setnchannels(1)
+ static.AUDIO_RECORD_FILE.setsampwidth(2)
+ static.AUDIO_RECORD_FILE.setframerate(8000)
static.AUDIO_RECORD = True
else:
static.AUDIO_RECORD = False
From b637b917bc2677ec9405bb4ce842c9ac4b397c2d Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Tue, 27 Dec 2022 22:57:54 +0100
Subject: [PATCH 38/58] first attempt with message checksum
---
gui/preload-chat.js | 10 +++++++++-
gui/sock.js | 10 +++++++++-
tnc/data_handler.py | 12 +++++++++++-
tnc/sock.py | 1 +
4 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/gui/preload-chat.js b/gui/preload-chat.js
index 6747779c..3aa3ffb0 100644
--- a/gui/preload-chat.js
+++ b/gui/preload-chat.js
@@ -323,6 +323,8 @@ db.post({
}
var timestamp = Math.floor(Date.now() / 1000);
+ var checksum = crc32(file).toString(16).toUpperCase();
+ console.log(checksum)
var data_with_attachment = chatmessage + split_char + filename + split_char + filetype + split_char + file + split_char + timestamp;
document.getElementById('selectFilesButton').innerHTML = ``;
@@ -334,7 +336,7 @@ db.post({
mode: 255,
frames: 1,
data: data_with_attachment,
- checksum: '123',
+ checksum: checksum,
uuid: uuid
};
ipcRenderer.send('run-tnc-command', Data);
@@ -994,3 +996,9 @@ function scrollMessagesToBottom() {
var messageBody = document.getElementById('message-container');
messageBody.scrollTop = messageBody.scrollHeight - messageBody.clientHeight;
}
+
+// https://stackoverflow.com/a/50579690
+// crc32 calculation
+//console.log(crc32('abc'));
+//console.log(crc32('abc').toString(16).toUpperCase()); // hex
+var crc32=function(r){for(var a,o=[],c=0;c<256;c++){a=c;for(var f=0;f<8;f++)a=1&a?3988292384^a>>>1:a>>>1;o[c]=a}for(var n=-1,t=0;t>>8^o[255&(n^r.charCodeAt(t))];return(-1^n)>>>0};
diff --git a/gui/sock.js b/gui/sock.js
index 54fa2669..9f3605b2 100644
--- a/gui/sock.js
+++ b/gui/sock.js
@@ -612,4 +612,12 @@ ipcRenderer.on('action-update-tnc-ip', (event, arg) => {
tnc_host = arg.adress;
connectTNC();
-});
\ No newline at end of file
+});
+
+
+
+// https://stackoverflow.com/a/50579690
+// crc32 calculation
+//console.log(crc32('abc'));
+//console.log(crc32('abc').toString(16).toUpperCase()); // hex
+var crc32=function(r){for(var a,o=[],c=0;c<256;c++){a=c;for(var f=0;f<8;f++)a=1&a?3988292384^a>>>1:a>>>1;o[c]=a}for(var n=-1,t=0;t>>8^o[255&(n^r.charCodeAt(t))];return(-1^n)>>>0};
diff --git a/tnc/data_handler.py b/tnc/data_handler.py
index 1be4d544..8a21b55c 100644
--- a/tnc/data_handler.py
+++ b/tnc/data_handler.py
@@ -3106,7 +3106,8 @@ class DATA:
decoded_data = data_frame.split(split_char)
if decoded_data[0] in [b'm']:
- #uuid=decoded_data[3]
+ checksum_delivered = decoded_data[2].uppercase()
+ # transmission_uuid = decoded_data[3]
message = decoded_data[4]
filename = decoded_data[5]
#filetype = decoded_data[6]
@@ -3117,6 +3118,15 @@ class DATA:
# save file to folder
if filename not in [b'', b'undefined']:
+ doing crc check
+ crc = helpers.get_crc_32(data).hex().uppercase()
+ validity = checksum_delivered == crc
+ logging.info(
+ "[TNC] ARQ | RX | checking data crc",
+ crc_delivered=checksum_delivered,
+ crc_calculated=crc,
+ valid=validity,
+ )
filename = str(filename, "UTF-8")
filename_complex = f"{timestamp}_{transmission_uuid}_{filename}"
with open(f"{folder_path}/{callsign_path}/{filename_complex}", "wb") as file:
diff --git a/tnc/sock.py b/tnc/sock.py
index 82b313eb..4cc0099b 100644
--- a/tnc/sock.py
+++ b/tnc/sock.py
@@ -888,3 +888,4 @@ def command_response(command, status):
jsondata = {"command_response": command, "status": s_status}
data_out = json.dumps(jsondata)
SOCKET_QUEUE.put(data_out)
+
From c5a9229207e12b0a22c76859fd263c24e462d56f Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Tue, 27 Dec 2022 22:58:18 +0100
Subject: [PATCH 39/58] first attempt with message checksum
---
tnc/data_handler.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tnc/data_handler.py b/tnc/data_handler.py
index 8a21b55c..fc568205 100644
--- a/tnc/data_handler.py
+++ b/tnc/data_handler.py
@@ -3118,7 +3118,7 @@ class DATA:
# save file to folder
if filename not in [b'', b'undefined']:
- doing crc check
+ # doing crc check
crc = helpers.get_crc_32(data).hex().uppercase()
validity = checksum_delivered == crc
logging.info(
From c8eb9bbf92b516c3a3bcf4683b93855d9c97eb42 Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Tue, 27 Dec 2022 23:02:52 +0100
Subject: [PATCH 40/58] fix upper lower case
---
tnc/data_handler.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tnc/data_handler.py b/tnc/data_handler.py
index fc568205..79af9630 100644
--- a/tnc/data_handler.py
+++ b/tnc/data_handler.py
@@ -3106,7 +3106,7 @@ class DATA:
decoded_data = data_frame.split(split_char)
if decoded_data[0] in [b'm']:
- checksum_delivered = decoded_data[2].uppercase()
+ checksum_delivered = decoded_data[2].lower()
# transmission_uuid = decoded_data[3]
message = decoded_data[4]
filename = decoded_data[5]
@@ -3119,7 +3119,7 @@ class DATA:
# save file to folder
if filename not in [b'', b'undefined']:
# doing crc check
- crc = helpers.get_crc_32(data).hex().uppercase()
+ crc = helpers.get_crc_32(data).hex().lower()
validity = checksum_delivered == crc
logging.info(
"[TNC] ARQ | RX | checking data crc",
From c6d99f88665ffdf1ca47b63c1c0e37682a194aee Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Tue, 27 Dec 2022 23:04:57 +0100
Subject: [PATCH 41/58] typo fix
---
tnc/data_handler.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tnc/data_handler.py b/tnc/data_handler.py
index 79af9630..02e686b3 100644
--- a/tnc/data_handler.py
+++ b/tnc/data_handler.py
@@ -3121,7 +3121,7 @@ class DATA:
# doing crc check
crc = helpers.get_crc_32(data).hex().lower()
validity = checksum_delivered == crc
- logging.info(
+ self.log.info(
"[TNC] ARQ | RX | checking data crc",
crc_delivered=checksum_delivered,
crc_calculated=crc,
From 58342b975f0e79ab78afa7b4f47f0680c2cfe8b8 Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Tue, 27 Dec 2022 23:30:15 +0100
Subject: [PATCH 42/58] more crc check improvements
---
gui/preload-chat.js | 37 ++++++++++++++++++++++++++++++++-----
gui/sock.js | 13 +++++++------
tnc/data_handler.py | 2 +-
3 files changed, 40 insertions(+), 12 deletions(-)
diff --git a/gui/preload-chat.js b/gui/preload-chat.js
index 3aa3ffb0..5adf2979 100644
--- a/gui/preload-chat.js
+++ b/gui/preload-chat.js
@@ -323,8 +323,8 @@ db.post({
}
var timestamp = Math.floor(Date.now() / 1000);
- var checksum = crc32(file).toString(16).toUpperCase();
- console.log(checksum)
+ var file_checksum = crc32(file).toString(16).toUpperCase();
+ console.log(file_checksum)
var data_with_attachment = chatmessage + split_char + filename + split_char + filetype + split_char + file + split_char + timestamp;
document.getElementById('selectFilesButton').innerHTML = ``;
@@ -336,7 +336,7 @@ db.post({
mode: 255,
frames: 1,
data: data_with_attachment,
- checksum: checksum,
+ checksum: file_checksum,
uuid: uuid
};
ipcRenderer.send('run-tnc-command', Data);
@@ -346,7 +346,7 @@ db.post({
dxcallsign: dxcallsign,
dxgrid: 'null',
msg: chatmessage,
- checksum: 'null',
+ checksum: file_checksum,
type: "transmit",
status: 'transmit',
uuid: uuid,
@@ -997,8 +997,35 @@ function scrollMessagesToBottom() {
messageBody.scrollTop = messageBody.scrollHeight - messageBody.clientHeight;
}
+
+
+// CRC CHECKSUMS
// https://stackoverflow.com/a/50579690
// crc32 calculation
//console.log(crc32('abc'));
+//var crc32=function(r){for(var a,o=[],c=0;c<256;c++){a=c;for(var f=0;f<8;f++)a=1&a?3988292384^a>>>1:a>>>1;o[c]=a}for(var n=-1,t=0;t>>8^o[255&(n^r.charCodeAt(t))];return(-1^n)>>>0};
//console.log(crc32('abc').toString(16).toUpperCase()); // hex
-var crc32=function(r){for(var a,o=[],c=0;c<256;c++){a=c;for(var f=0;f<8;f++)a=1&a?3988292384^a>>>1:a>>>1;o[c]=a}for(var n=-1,t=0;t>>8^o[255&(n^r.charCodeAt(t))];return(-1^n)>>>0};
+
+var makeCRCTable = function(){
+ var c;
+ var crcTable = [];
+ for(var n =0; n < 256; n++){
+ c = n;
+ for(var k =0; k < 8; k++){
+ c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
+ }
+ crcTable[n] = c;
+ }
+ return crcTable;
+}
+
+var crc32 = function(str) {
+ var crcTable = window.crcTable || (window.crcTable = makeCRCTable());
+ var crc = 0 ^ (-1);
+
+ for (var i = 0; i < str.length; i++ ) {
+ crc = (crc >>> 8) ^ crcTable[(crc ^ str.charCodeAt(i)) & 0xFF];
+ }
+
+ return (crc ^ (-1)) >>> 0;
+};
\ No newline at end of file
diff --git a/gui/sock.js b/gui/sock.js
index 9f3605b2..b8895702 100644
--- a/gui/sock.js
+++ b/gui/sock.js
@@ -517,7 +517,7 @@ exports.sendFile = function(dxcallsign, mode, frames, filename, filetype, data,
// Send Message
exports.sendMessage = function(dxcallsign, mode, frames, data, checksum, uuid, command) {
- socketLog.info(data)
+ //socketLog.info(data)
// Disabled this here
// convert message to plain utf8 because of unicode emojis
@@ -528,13 +528,14 @@ exports.sendMessage = function(dxcallsign, mode, frames, data, checksum, uuid, c
var datatype = "m"
data = datatype + split_char + command + split_char + checksum + split_char + uuid + split_char + data
- socketLog.info(data)
-
-
-
- socketLog.info(btoa(data))
+ //socketLog.info(data)
+ console.log(data)
+
+ console.log("CHECKSUM" + checksum)
+ //socketLog.info(btoa(data))
data = btoa(data)
+
//command = '{"type" : "arq", "command" : "send_message", "parameter" : [{ "dxcallsign" : "' + dxcallsign + '", "mode" : "' + mode + '", "n_frames" : "' + frames + '", "data" : "' + data + '" , "checksum" : "' + checksum + '"}]}'
command = '{"type" : "arq", "command" : "send_raw", "uuid" : "'+ uuid +'", "parameter" : [{"dxcallsign" : "' + dxcallsign + '", "mode" : "' + mode + '", "n_frames" : "' + frames + '", "data" : "' + data + '", "attempts": "15"}]}'
socketLog.info(command)
diff --git a/tnc/data_handler.py b/tnc/data_handler.py
index 02e686b3..a82ccc1d 100644
--- a/tnc/data_handler.py
+++ b/tnc/data_handler.py
@@ -3106,7 +3106,7 @@ class DATA:
decoded_data = data_frame.split(split_char)
if decoded_data[0] in [b'm']:
- checksum_delivered = decoded_data[2].lower()
+ checksum_delivered = str(decoded_data[2], "utf-8").lower()
# transmission_uuid = decoded_data[3]
message = decoded_data[4]
filename = decoded_data[5]
From 4cce8aec5c2ad7531c821433bd73f07becef812d Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Tue, 27 Dec 2022 23:32:52 +0100
Subject: [PATCH 43/58] added total bytes to rx message
---
tnc/data_handler.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tnc/data_handler.py b/tnc/data_handler.py
index a82ccc1d..c57070dd 100644
--- a/tnc/data_handler.py
+++ b/tnc/data_handler.py
@@ -812,7 +812,7 @@ class DATA:
# transmittion duration
duration = time.time() - self.rx_start_of_transmission
- self.log.info("[TNC] ARQ | RX | DATA FRAME SUCCESSFULLY RECEIVED", nacks=self.frame_nack_counter,bytesperminute=static.ARQ_BYTES_PER_MINUTE, duration=duration
+ self.log.info("[TNC] ARQ | RX | DATA FRAME SUCCESSFULLY RECEIVED", nacks=self.frame_nack_counter,bytesperminute=static.ARQ_BYTES_PER_MINUTE, total_bytes=static.TOTAL_BYTES, duration=duration
)
# Decompress the data frame
@@ -1216,6 +1216,7 @@ class DATA:
self.log.info(
"[TNC] ARQ | TX | DATA TRANSMITTED!",
BytesPerMinute=static.ARQ_BYTES_PER_MINUTE,
+ total_bytes=static.TOTAL_BYTES,
BitsPerSecond=static.ARQ_BITS_PER_SECOND,
overflows=static.BUFFER_OVERFLOW_COUNTER,
From 2ba8b77ea7fe3ee676bb4796eda915e0aa0336ce Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Wed, 28 Dec 2022 00:05:12 +0100
Subject: [PATCH 44/58] added crc check and sleeping time for processing bigger
data
---
tools/send_file.py | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/tools/send_file.py b/tools/send_file.py
index d714ca92..d9d97358 100755
--- a/tools/send_file.py
+++ b/tools/send_file.py
@@ -13,6 +13,7 @@ import base64
import json
import uuid
import time
+import crcengine
# --------------------------------------------GET PARAMETER INPUTS
parser = argparse.ArgumentParser(description='Simons TEST TNC')
@@ -64,9 +65,15 @@ msg_with_attachment = chatmessage + \
split_char + \
timestamp
+# calculate checksum
+crc_algorithm = crcengine.new("crc32") # load crc32 library
+crc_data = crc_algorithm(file)
+crc_data = crc_data.to_bytes(4, byteorder="big")
+
+
datatype = b"m"
command = b"send_message"
-checksum = b"123"
+checksum = bytes(crc_data.hex(), "utf-8")
uuid_4 = bytes(str(uuid.uuid4()), "utf-8")
data = datatype + \
@@ -98,9 +105,13 @@ command = {"type": "arq",
]
}
command = json.dumps(command)
+print(command)
command = bytes(command + "\n", 'utf-8')
# Create a socket (SOCK_STREAM means a TCP socket)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
# Connect to server and send data
sock.connect((HOST, PORT))
sock.sendall(command)
+ timeout = time.time() + 5
+ while time.time() < timeout:
+ pass
\ No newline at end of file
From efd92cdd7241e36e07fd37bee2aa052f4db11283 Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Wed, 28 Dec 2022 11:32:33 +0100
Subject: [PATCH 45/58] changing split char and split char order
---
gui/preload-chat.js | 6 +++---
gui/sock.js | 2 +-
tnc/data_handler.py | 7 ++++---
3 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/gui/preload-chat.js b/gui/preload-chat.js
index 5adf2979..26de8401 100644
--- a/gui/preload-chat.js
+++ b/gui/preload-chat.js
@@ -34,7 +34,7 @@ const dateFormatHours = new Intl.DateTimeFormat('en-GB', {
hour12: false,
});
// split character
-const split_char = '\0;'
+const split_char = '\0;\1;'
// global for our selected file we want to transmit
// ----------------- some chat globals
var filetype = '';
@@ -325,7 +325,7 @@ db.post({
var file_checksum = crc32(file).toString(16).toUpperCase();
console.log(file_checksum)
- var data_with_attachment = chatmessage + split_char + filename + split_char + filetype + split_char + file + split_char + timestamp;
+ var data_with_attachment = chatmessage + split_char + filename + split_char + filetype + split_char + timstamp + split_char + file;
document.getElementById('selectFilesButton').innerHTML = ``;
var uuid = uuidv4();
@@ -866,7 +866,7 @@ update_chat = function(obj) {
console.log(binaryString)
console.log(binaryString.length)
- var data_with_attachment = utf8.encode(doc.msg) + split_char + filename + split_char + filetype + split_char + binaryString + split_char + doc.timestamp;
+ var data_with_attachment = utf8.encode(doc.msg) + split_char + filename + split_char + filetype + split_char + doc.timestamp + split_char + binaryString;
let Data = {
command: "send_message",
dxcallsign: doc.dxcallsign,
diff --git a/gui/sock.js b/gui/sock.js
index b8895702..78018b93 100644
--- a/gui/sock.js
+++ b/gui/sock.js
@@ -19,7 +19,7 @@ var client = new net.Socket();
var socketchunk = ''; // Current message, per connection.
// split character
-const split_char = '\0;'
+const split_char = '\0;\1;'
// globals for getting new data only if available so we are saving bandwidth
var rxBufferLengthTnc = 0
diff --git a/tnc/data_handler.py b/tnc/data_handler.py
index c57070dd..c4bfc704 100644
--- a/tnc/data_handler.py
+++ b/tnc/data_handler.py
@@ -3103,7 +3103,7 @@ class DATA:
if not os.path.exists(f"{folder_path}/{callsign_path}"):
os.makedirs(f"{folder_path}/{callsign_path}")
- split_char = b"\x00;"
+ split_char = b"\0;\0;"
decoded_data = data_frame.split(split_char)
if decoded_data[0] in [b'm']:
@@ -3111,8 +3111,9 @@ class DATA:
# transmission_uuid = decoded_data[3]
message = decoded_data[4]
filename = decoded_data[5]
- #filetype = decoded_data[6]
- data = decoded_data[7]
+ # filetype = decoded_data[6]
+ # timestamp = decoded_data[7]
+ data = decoded_data[8]
else:
message = b''
filename = b'reveived'
From f2e5a113487121a134bf9b89d51e1d7e11a0c007 Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Wed, 28 Dec 2022 11:59:00 +0100
Subject: [PATCH 46/58] changing split char and split char order
---
tnc/data_handler.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tnc/data_handler.py b/tnc/data_handler.py
index c4bfc704..176bb8c0 100644
--- a/tnc/data_handler.py
+++ b/tnc/data_handler.py
@@ -3103,7 +3103,7 @@ class DATA:
if not os.path.exists(f"{folder_path}/{callsign_path}"):
os.makedirs(f"{folder_path}/{callsign_path}")
- split_char = b"\0;\0;"
+ split_char = b"\0;\1;"
decoded_data = data_frame.split(split_char)
if decoded_data[0] in [b'm']:
From 37267ac679c22e6f790ffbc4a5322edb7f6f37da Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Wed, 28 Dec 2022 12:27:09 +0100
Subject: [PATCH 47/58] changing split char and split char order
---
gui/preload-chat.js | 14 +++++++-------
tnc/data_handler.py | 2 +-
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/gui/preload-chat.js b/gui/preload-chat.js
index 26de8401..47f27b00 100644
--- a/gui/preload-chat.js
+++ b/gui/preload-chat.js
@@ -325,7 +325,7 @@ db.post({
var file_checksum = crc32(file).toString(16).toUpperCase();
console.log(file_checksum)
- var data_with_attachment = chatmessage + split_char + filename + split_char + filetype + split_char + timstamp + split_char + file;
+ var data_with_attachment = timestamp + split_char + chatmessage + split_char + filename + split_char + filetype + split_char + file;
document.getElementById('selectFilesButton').innerHTML = ``;
var uuid = uuidv4();
@@ -476,20 +476,20 @@ ipcRenderer.on('action-new-msg-received', (event, arg) => {
console.log(splitted_data)
- obj.timestamp = parseInt(splitted_data[8]);
+ obj.timestamp = parseInt(splitted_data[4]);
obj.dxcallsign = item.dxcallsign;
obj.dxgrid = item.dxgrid;
obj.command = splitted_data[1];
obj.checksum = splitted_data[2];
// convert message to unicode from utf8 because of emojis
obj.uuid = utf8.decode(splitted_data[3]);
- obj.msg = utf8.decode(splitted_data[4]);
+ obj.msg = utf8.decode(splitted_data[5]);
obj.status = 'null';
obj.snr = 'null';
obj.type = 'received';
- obj.filename = utf8.decode(splitted_data[5]);
- obj.filetype = utf8.decode(splitted_data[6]);
- obj.file = btoa(utf8.decode(splitted_data[7]));
+ obj.filename = utf8.decode(splitted_data[6]);
+ obj.filetype = utf8.decode(splitted_data[7]);
+ obj.file = btoa(utf8.decode(splitted_data[8]));
add_obj_to_database(obj);
update_chat_obj_by_uuid(obj.uuid);
@@ -866,7 +866,7 @@ update_chat = function(obj) {
console.log(binaryString)
console.log(binaryString.length)
- var data_with_attachment = utf8.encode(doc.msg) + split_char + filename + split_char + filetype + split_char + doc.timestamp + split_char + binaryString;
+ var data_with_attachment = doc.timestamp + split_char + utf8.encode(doc.msg) + split_char + filename + split_char + filetype + split_char + binaryString;
let Data = {
command: "send_message",
dxcallsign: doc.dxcallsign,
diff --git a/tnc/data_handler.py b/tnc/data_handler.py
index 176bb8c0..9e39090b 100644
--- a/tnc/data_handler.py
+++ b/tnc/data_handler.py
@@ -3116,7 +3116,7 @@ class DATA:
data = decoded_data[8]
else:
message = b''
- filename = b'reveived'
+ filename = b''
# save file to folder
if filename not in [b'', b'undefined']:
From 751e43eddb742110ff3375e4ee36775cd99bc22e Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Wed, 28 Dec 2022 12:40:10 +0100
Subject: [PATCH 48/58] changing split char and split char order
---
tnc/data_handler.py | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tnc/data_handler.py b/tnc/data_handler.py
index 9e39090b..ed2e47d2 100644
--- a/tnc/data_handler.py
+++ b/tnc/data_handler.py
@@ -3109,10 +3109,10 @@ class DATA:
if decoded_data[0] in [b'm']:
checksum_delivered = str(decoded_data[2], "utf-8").lower()
# transmission_uuid = decoded_data[3]
- message = decoded_data[4]
- filename = decoded_data[5]
- # filetype = decoded_data[6]
- # timestamp = decoded_data[7]
+ message = decoded_data[5]
+ filename = decoded_data[6]
+ # filetype = decoded_data[7]
+ # timestamp = decoded_data[4]
data = decoded_data[8]
else:
message = b''
From 586c02f73b45ed6fc01ab93d8cc212fb1fc843cd Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Wed, 28 Dec 2022 13:08:46 +0100
Subject: [PATCH 49/58] fix utf encoding error
---
gui/preload-chat.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gui/preload-chat.js b/gui/preload-chat.js
index 47f27b00..364b9603 100644
--- a/gui/preload-chat.js
+++ b/gui/preload-chat.js
@@ -489,7 +489,7 @@ ipcRenderer.on('action-new-msg-received', (event, arg) => {
obj.type = 'received';
obj.filename = utf8.decode(splitted_data[6]);
obj.filetype = utf8.decode(splitted_data[7]);
- obj.file = btoa(utf8.decode(splitted_data[8]));
+ obj.file = btoa(splitted_data[8]);
add_obj_to_database(obj);
update_chat_obj_by_uuid(obj.uuid);
From e30f09f4dee801fcd8100c0c237e266082bc52be Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Wed, 28 Dec 2022 13:13:56 +0100
Subject: [PATCH 50/58] fix message order
---
tools/send_file.py | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/send_file.py b/tools/send_file.py
index d9d97358..a5e7e5c8 100755
--- a/tools/send_file.py
+++ b/tools/send_file.py
@@ -55,15 +55,15 @@ timestamp = str(int(time.time()))
# timestamp = timestamp.to_bytes(4, byteorder="big")
timestamp = bytes(timestamp, "utf-8")
-msg_with_attachment = chatmessage + \
+msg_with_attachment = timestamp + \
+ split_char + \
+ chatmessage + \
split_char + \
filename + \
split_char + \
filetype + \
split_char + \
- file + \
- split_char + \
- timestamp
+ file
# calculate checksum
crc_algorithm = crcengine.new("crc32") # load crc32 library
From 47e177f39902a181927192856c81b24cbdf7f0b4 Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Wed, 28 Dec 2022 13:37:37 +0100
Subject: [PATCH 51/58] fix split_char
---
tools/send_file.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/send_file.py b/tools/send_file.py
index a5e7e5c8..671c4d55 100755
--- a/tools/send_file.py
+++ b/tools/send_file.py
@@ -48,7 +48,7 @@ else:
# convert binary data to base64
#base64_data = base64.b64encode(file).decode("UTF-8")
-split_char = b'\0;'
+split_char = b'\0;\1;'
filetype = b"unknown"
timestamp = str(int(time.time()))
From 8717629b91bdc844fa90696584b2f7a83e67d1a2 Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Wed, 28 Dec 2022 17:06:55 +0100
Subject: [PATCH 52/58] increased protocol version
---
tnc/static.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tnc/static.py b/tnc/static.py
index 19a9ee56..e2696a7b 100644
--- a/tnc/static.py
+++ b/tnc/static.py
@@ -92,7 +92,7 @@ ENABLE_FFT: bool = True
CHANNEL_BUSY: bool = False
# ARQ PROTOCOL VERSION
-ARQ_PROTOCOL_VERSION: int = 4
+ARQ_PROTOCOL_VERSION: int = 5
# ARQ statistics
ARQ_BYTES_PER_MINUTE_BURST: int = 0
From 17977b5281c6755eb0703c2831bf953b22a54832 Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Wed, 28 Dec 2022 17:22:17 +0100
Subject: [PATCH 53/58] break connection attempts when version missmatch
---
tnc/data_handler.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tnc/data_handler.py b/tnc/data_handler.py
index ed2e47d2..2afff286 100644
--- a/tnc/data_handler.py
+++ b/tnc/data_handler.py
@@ -1841,8 +1841,6 @@ class DATA:
# for calculating transmission statistics
# static.ARQ_COMPRESSION_FACTOR = len(data_out) / len(lzma.compress(data_out))
-
-
self.arq_open_data_channel(mode, n_frames_per_burst, mycallsign)
# wait until data channel is open
@@ -1956,6 +1954,8 @@ class DATA:
# Stop waiting if data channel is opened
if static.ARQ_STATE:
return True
+ if static.TNC_STATE in ["IDLE"]:
+ return False
# `data_channel_max_retries` attempts have been sent. Aborting attempt & cleaning up
From 2392ff3b530b1ded5e110920297db6cbc3e4e97b Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Wed, 28 Dec 2022 17:37:50 +0100
Subject: [PATCH 54/58] handle split char false positive
---
tnc/data_handler.py | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/tnc/data_handler.py b/tnc/data_handler.py
index 2afff286..8b5eaab1 100644
--- a/tnc/data_handler.py
+++ b/tnc/data_handler.py
@@ -3104,7 +3104,13 @@ class DATA:
os.makedirs(f"{folder_path}/{callsign_path}")
split_char = b"\0;\1;"
+ n_objects = 8
decoded_data = data_frame.split(split_char)
+ # if we have a false positive in case our split_char is available in data
+ # lets stick the data together, so we are not loosing it
+ if len(decoded_data) > n_objects:
+ file_data = b''.join(list[n_objects:])
+ decoded_data = [*decoded_data[:n_objects], file_data]
if decoded_data[0] in [b'm']:
checksum_delivered = str(decoded_data[2], "utf-8").lower()
From 00d007b9b76938f0e3b0f55cdceb5f2cc0743041 Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Wed, 28 Dec 2022 18:03:05 +0100
Subject: [PATCH 55/58] handle split char false positive
---
tnc/data_handler.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tnc/data_handler.py b/tnc/data_handler.py
index 8b5eaab1..0cbba959 100644
--- a/tnc/data_handler.py
+++ b/tnc/data_handler.py
@@ -3104,7 +3104,7 @@ class DATA:
os.makedirs(f"{folder_path}/{callsign_path}")
split_char = b"\0;\1;"
- n_objects = 8
+ n_objects = 9
decoded_data = data_frame.split(split_char)
# if we have a false positive in case our split_char is available in data
# lets stick the data together, so we are not loosing it
From 3b8236826c0d7b77844d87d1b7d8719b6f101584 Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Wed, 28 Dec 2022 23:21:39 +0100
Subject: [PATCH 56/58] fix slice crashing nuitka
---
tnc/data_handler.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/tnc/data_handler.py b/tnc/data_handler.py
index 0cbba959..501dfc72 100644
--- a/tnc/data_handler.py
+++ b/tnc/data_handler.py
@@ -3110,7 +3110,10 @@ class DATA:
# lets stick the data together, so we are not loosing it
if len(decoded_data) > n_objects:
file_data = b''.join(list[n_objects:])
- decoded_data = [*decoded_data[:n_objects], file_data]
+
+ # slice is crashing nuitka
+ # decoded_data = [*decoded_data[:n_objects], file_data]
+ decoded_data = decoded_data[:n_objects] + [file_data]
if decoded_data[0] in [b'm']:
checksum_delivered = str(decoded_data[2], "utf-8").lower()
From 4d2d0b93ac0677a25538baf024403d370554870a Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Wed, 28 Dec 2022 23:47:13 +0100
Subject: [PATCH 57/58] fix slice crashing nuitka
---
tnc/data_handler.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tnc/data_handler.py b/tnc/data_handler.py
index 501dfc72..54e9233d 100644
--- a/tnc/data_handler.py
+++ b/tnc/data_handler.py
@@ -3109,7 +3109,7 @@ class DATA:
# if we have a false positive in case our split_char is available in data
# lets stick the data together, so we are not loosing it
if len(decoded_data) > n_objects:
- file_data = b''.join(list[n_objects:])
+ file_data = b''.join(decoded_data[n_objects:])
# slice is crashing nuitka
# decoded_data = [*decoded_data[:n_objects], file_data]
From 71051fd3fa5edd29bd36226e39a418e4667f8bfd Mon Sep 17 00:00:00 2001
From: DJ2LS <75909252+DJ2LS@users.noreply.github.com>
Date: Thu, 29 Dec 2022 09:19:35 +0100
Subject: [PATCH 58/58] send disconnect frame on version missmatch
---
tnc/data_handler.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/tnc/data_handler.py b/tnc/data_handler.py
index 54e9233d..6ba90080 100644
--- a/tnc/data_handler.py
+++ b/tnc/data_handler.py
@@ -2239,6 +2239,7 @@ class DATA:
received=protocol_version,
own=static.ARQ_PROTOCOL_VERSION,
)
+ self.stop_transmission()
self.arq_cleanup()
# ---------- PING