improved logging and chat

This commit is contained in:
dj2ls 2022-04-02 18:40:12 +02:00
parent 04f6c49ac5
commit 8f3f046655
9 changed files with 83 additions and 36 deletions

View file

@ -1,6 +1,6 @@
{
"name": "FreeDATA",
"version": "0.3.1-alpha.1",
"version": "0.3.2-alpha.1",
"description": "FreeDATA ",
"main": "main.js",
"scripts": {

View file

@ -26,6 +26,12 @@ const dateFormatShort = new Intl.DateTimeFormat('en-GB', {
second: 'numeric',
hour12: false,
});
const dateFormatHours = new Intl.DateTimeFormat('en-GB', {
hour: 'numeric',
minute: 'numeric',
hour12: false,
});
// split character
const split_char = '\0;'
// global for our selected file we want to transmit
@ -146,10 +152,10 @@ db.post({
timestamp: Math.floor(Date.now() / 1000),
dxcallsign: dxcallsign.toUpperCase(),
dxgrid: '---',
msg: 'NULL',
checksum: 'NULL',
msg: 'null',
checksum: 'null',
type: 'newchat',
status: 'NULL',
status: 'null',
uuid: uuid
}).then(function(response) {
@ -198,9 +204,9 @@ db.post({
_id: uuid,
timestamp: Math.floor(Date.now() / 1000),
dxcallsign: dxcallsign,
dxgrid: 'NULL',
dxgrid: 'null',
msg: chatmessage,
checksum: 'NULL',
checksum: 'null',
type: "transmit",
status: 'transmit',
uuid: uuid,
@ -425,7 +431,21 @@ update_chat = function(obj) {
var dxcallsign = obj.dxcallsign;
var timestamp = dateFormat.format(obj.timestamp * 1000);
var timestampShort = dateFormatShort.format(obj.timestamp * 1000);
var timestampHours = dateFormatHours.format(obj.timestamp * 1000);
var dxgrid = obj.dxgrid;
// define shortmessage
if (obj.msg == 'null' || obj.msg == 'NULL'){
var shortmsg = obj.type;
} else {
var shortmsg = obj.msg;
var maxlength = 45;
var shortmsg = shortmsg.length > maxlength ? shortmsg.substring(0, maxlength - 3) + "..." : shortmsg;
}
try {
console.log(Object.keys(obj._attachments)[0].length)
if (typeof(obj._attachments) !== 'undefined' && Object.keys(obj._attachments)[0].length > 0) {
@ -459,6 +479,12 @@ update_chat = function(obj) {
//document.getElementById('chatModuleDxCall').value = dxcallsign;
selected_callsign = dxcallsign;
}
var new_callsign = `
<a class="list-group-item list-group-item-action rounded-4 rounded-top rounded-bottom border-1 mb-2 ${callsign_selected}" id="chat-${dxcallsign}-list" data-bs-toggle="list" href="#chat-${dxcallsign}" role="tab" aria-controls="chat-${dxcallsign}">
@ -468,10 +494,13 @@ update_chat = function(obj) {
<div class="rounded-circle p-0">
<i class="bi bi-person-circle p-1" style="font-size:2rem;"></i>
</div>
<h5 class="mb-1">${dxcallsign}</h5>
<small>${dxgrid}</small>
<span class="badge bg-secondary text-white p-1 h-100" id="chat-${dxcallsign}-list-dxgrid"><small>${dxgrid}</small></span>
<span style="font-size:0.8rem;" id="chat-${dxcallsign}-list-time">${timestampHours}</span>
<span class="position-absolute m-2 bottom-0 end-0" style="font-size:0.8rem;" id="chat-${dxcallsign}-list-shortmsg">${shortmsg}</span>
</div>
<!--<p class="mb-1">JN48ea</p>-->
</a>
`;
@ -488,6 +517,20 @@ update_chat = function(obj) {
var element = document.getElementById("message-container");
element.scrollTo(0, element.scrollHeight);
});
// if callsign entry already exists - update
} else {
// gridsquare - update only on receive
if (obj.type !== 'transmit'){
document.getElementById('chat-' + dxcallsign +'-list-dxgrid').innerHTML = dxgrid;
}
// time
document.getElementById('chat-' + dxcallsign +'-list-time').innerHTML = timestampHours;
// short message
document.getElementById('chat-' + dxcallsign +'-list-shortmsg').innerHTML = shortmsg;
}
// APPEND MESSAGES TO CALLSIGN
if (obj.status == 'transmit') {
@ -640,9 +683,9 @@ function getObjByID(id) {
{
"timestamp": 1648139683,
"dxcallsign": "DN2LS-0",
"dxgrid": "NULL",
"dxgrid": "null",
"msg": "",
"checksum": "NULL",
"checksum": "null",
"type": "transmit",
"status": "transmit",
"uuid": "5b72a46c-49cf-40d6-8936-a64c95bc3da7",

View file

@ -84,7 +84,7 @@
<hr class="m-0">
<! ------messages area ---------------------------------------------------------------------->
<div class="container overflow-auto" id="message-container" style="height: calc(100% - 105px);">
<div class="container overflow-auto" id="message-container" style="height: calc(100% - 115px);">
@ -107,9 +107,11 @@
<div class="input-group bottom-0 w-100">
<!--<input class="form-control" maxlength="8" style="max-width: 6rem; text-transform:uppercase; display:none" id="chatModuleDxCall" placeholder="DX CALL"></input>-->
<!--<button class="btn btn-sm btn-primary me-2" id="emojipickerbutton" type="button">-->
<i id="emojipickerbutton" class="bi bi-emoji-smile m-1" style="font-size: 1.5rem; color: grey;"></i></button>
<input class="form-control" id="chatModuleMessage" placeholder="Message"></input>
<button class="btn btn-sm btn-primary me-2" id="emojipickerbutton" type="button"><i class="bi bi-emoji-smile"></i></button>
<!--<input class="form-control" type="file" id="selectFiles" style="display: none;">-->
<button class="btn btn-sm btn-primary me-2" style="width: 3rem" id="selectFilesButton" type="button"><i class="bi bi-paperclip" style="font-size: 1.2rem; color: white;"></i></button>

View file

@ -185,11 +185,11 @@ H_1024_2048_4f rate 0.50 (2048,1024) BPF: 128 working
# --------------- 2 FSK H_128_256_5, 16 bytes
api.FREEDV_MODE_FSK_LDPC_0_ADV = ADVANCED()
api.FREEDV_MODE_FSK_LDPC_0_ADV.interleave_frames = 0
api.FREEDV_MODE_FSK_LDPC_0_ADV.M = 2
api.FREEDV_MODE_FSK_LDPC_0_ADV.M = 4
api.FREEDV_MODE_FSK_LDPC_0_ADV.Rs = 100
api.FREEDV_MODE_FSK_LDPC_0_ADV.Fs = 8000
api.FREEDV_MODE_FSK_LDPC_0_ADV.first_tone = 1500
api.FREEDV_MODE_FSK_LDPC_0_ADV.tone_spacing = 200
api.FREEDV_MODE_FSK_LDPC_0_ADV.first_tone = 1150 # 1250 4fsk, 1500 2fsk
api.FREEDV_MODE_FSK_LDPC_0_ADV.tone_spacing = 100 #200
api.FREEDV_MODE_FSK_LDPC_0_ADV.codename = 'H_128_256_5'.encode('utf-8') # code word
# --------------- 4 H_256_512_4, 7 bytes
@ -198,7 +198,7 @@ api.FREEDV_MODE_FSK_LDPC_1_ADV.interleave_frames = 0
api.FREEDV_MODE_FSK_LDPC_1_ADV.M = 4
api.FREEDV_MODE_FSK_LDPC_1_ADV.Rs = 100
api.FREEDV_MODE_FSK_LDPC_1_ADV.Fs = 8000
api.FREEDV_MODE_FSK_LDPC_1_ADV.first_tone = 1250
api.FREEDV_MODE_FSK_LDPC_1_ADV.first_tone = 1250 # 1250 4fsk, 1500 2fsk
api.FREEDV_MODE_FSK_LDPC_1_ADV.tone_spacing = 200
api.FREEDV_MODE_FSK_LDPC_1_ADV.codename = 'H_256_512_4'.encode('utf-8') # code word

View file

@ -1433,6 +1433,7 @@ class DATA():
txbuffer = [ping_frame]
static.TRANSMITTING = True
structlog.get_logger("structlog").info("ENABLE FSK", state=static.ENABLE_FSK)
if static.ENABLE_FSK:
modem.MODEM_TRANSMIT_QUEUE.put(['FSK_LDPC_0',1,0,txbuffer])
else:
@ -1473,7 +1474,7 @@ class DATA():
txbuffer = [ping_frame]
static.TRANSMITTING = True
structlog.get_logger("structlog").info("ENABLE FSK", state=static.ENABLE_FSK)
if static.ENABLE_FSK:
modem.MODEM_TRANSMIT_QUEUE.put(['FSK_LDPC_0',1,0,txbuffer])
else:
@ -1566,7 +1567,7 @@ class DATA():
txbuffer = [beacon_frame]
static.TRANSMITTING = True
structlog.get_logger("structlog").info("ENABLE FSK", state=static.ENABLE_FSK)
if static.ENABLE_FSK:
modem.MODEM_TRANSMIT_QUEUE.put(['FSK_LDPC_0',1,0,txbuffer])
else:
@ -1622,7 +1623,7 @@ class DATA():
txbuffer = [cq_frame]
print(txbuffer)
static.TRANSMITTING = True
structlog.get_logger("structlog").info("ENABLE FSK", state=static.ENABLE_FSK)
if static.ENABLE_FSK:
modem.MODEM_TRANSMIT_QUEUE.put(['FSK_LDPC_0',2,500,txbuffer])
else:

View file

@ -84,7 +84,6 @@ if __name__ == '__main__':
mycallsign = helpers.callsign_to_bytes(mycallsign)
static.MYCALLSIGN = helpers.bytes_to_callsign(mycallsign)
static.MYCALLSIGN_CRC = helpers.get_crc_16(static.MYCALLSIGN)
print(static.MYCALLSIGN)
static.SSID_LIST = ARGS.ssid_list
@ -111,7 +110,6 @@ if __name__ == '__main__':
static.TUNING_RANGE_FMAX = ARGS.tuning_range_fmax
static.TX_AUDIO_LEVEL = ARGS.tx_audio_level
# we need to wait until we got all parameters from argparse first before we can load the other modules
import sock

View file

@ -328,7 +328,6 @@ class RF():
# open codec2 instance
self.MODE = mode
print(self.MODE)
if self.MODE == 'FSK_LDPC_0' or self.MODE == 200:
freedv = cast(codec2.api.freedv_open_advanced(codec2.api.FREEDV_MODE_FSK_LDPC, ctypes.byref(codec2.api.FREEDV_MODE_FSK_LDPC_0_ADV)), c_void_p)
elif self.MODE == 'FSK_LDPC_1' or self.MODE == 201:
@ -342,7 +341,6 @@ class RF():
# get number of bytes per frame for mode
bytes_per_frame = int(codec2.api.freedv_get_bits_per_modem_frame(freedv)/8)
payload_bytes_per_frame = bytes_per_frame -2
print(bytes_per_frame)
# init buffer for data
n_tx_modem_samples = codec2.api.freedv_get_n_tx_modem_samples(freedv)
mod_out = create_string_buffer(n_tx_modem_samples * 2)
@ -360,12 +358,16 @@ class RF():
data_delay = int(self.MODEM_SAMPLE_RATE*(data_delay_mseconds/1000))
mod_out_silence = create_string_buffer(data_delay*2)
txbuffer = bytes(mod_out_silence)
structlog.get_logger("structlog").debug("TRANSMIT", mode=self.MODE, payload=payload_bytes_per_frame)
for i in range(1,repeats+1):
# write preamble to txbuffer
codec2.api.freedv_rawdatapreambletx(freedv, mod_out_preamble)
txbuffer += bytes(mod_out_preamble)
# codec2 fsk preamble may be broken - at least it sounds like that so we are disabling it for testing
if not self.MODE == 'FSK_LDPC_0' or self.MODE == 200 or self.MODE == 'FSK_LDPC_1' or self.MODE == 201:
# write preamble to txbuffer
codec2.api.freedv_rawdatapreambletx(freedv, mod_out_preamble)
txbuffer += bytes(mod_out_preamble)
# create modulaton for n frames in list
for n in range(0,len(frames)):

View file

@ -116,7 +116,6 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
chunk = self.request.recv(1024)
data += chunk
print(data)
if chunk == b'':
#print("connection broken. Closing...")
self.connection_alive = False
@ -175,7 +174,7 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
try:
CONNECTED_CLIENTS.remove(self.request)
except:
print("client connection already removed from client list")
structlog.get_logger("structlog").warning("[SCK] client connection already removed from client list", client=self.request)
def process_tnc_commands(data):
@ -193,6 +192,7 @@ def process_tnc_commands(data):
# convert data to json object
received_json = json.loads(data)
structlog.get_logger("structlog").debug("[SCK] CMD", command=received_json)
# SET TX AUDIO LEVEL -----------------------------------------------------
if received_json["type"] == "set" and received_json["command"] == "tx_audio_level":
try:
@ -297,10 +297,7 @@ def process_tnc_commands(data):
# TRANSMIT RAW DATA -------------------------------------------
if received_json["type"] == 'arq' and received_json["command"] == "send_raw":
print(received_json)
static.BEACON_PAUSE = True
try:
if not static.ARQ_SESSION:
@ -454,7 +451,7 @@ def process_daemon_commands(data):
"""
# convert data to json object
received_json = json.loads(data)
structlog.get_logger("structlog").debug("[SCK] CMD", command=received_json)
if received_json["type"] == 'set' and received_json["command"] == 'mycallsign':
try:
callsign = received_json["parameter"]
@ -514,6 +511,10 @@ def process_daemon_commands(data):
tuning_range_fmax = str(received_json["parameter"][0]["tuning_range_fmax"])
tx_audio_level = str(received_json["parameter"][0]["tx_audio_level"])
# print some debugging parameters
for item in received_json["parameter"][0]:
structlog.get_logger("structlog").debug("[DMN] TNC Startup Config : " + item, value=received_json["parameter"][0][item])
DAEMON_QUEUE.put(['STARTTNC', \
mycall, \
mygrid, \
@ -620,7 +621,7 @@ def send_daemon_state():
return jsondata
except Exception as e:
print(e)
structlog.get_logger("structlog").warning("[SCK] error", e=e)
return None
def command_response(command, status):

View file

@ -8,7 +8,7 @@ Here we are saving application wide variables and stats, which have to be access
Not nice, suggestions are appreciated :-)
"""
VERSION = '0.3.0-alpha'
VERSION = '0.3.2-alpha'
# DAEMON
DAEMONPORT = 3001