different changes

network fixes, chat fixes, gui fixes...
This commit is contained in:
dj2ls 2022-03-12 15:06:49 +01:00
parent cbcb17870e
commit f5f7060672
9 changed files with 133 additions and 102 deletions

View file

@ -1,6 +1,6 @@
{
"name": "FreeDATA",
"version": "0.1.0-alpha.2",
"version": "0.1.2-alpha",
"description": "FreeDATA ",
"main": "main.js",
"scripts": {

View file

@ -58,11 +58,9 @@ db.allDocs({
// WINDOW LISTENER
window.addEventListener('DOMContentLoaded', () => {
// SEND MSG
document.getElementById("sendMessage").addEventListener("click", () => {
var dxcallsign = document.getElementById('chatModuleDxCall').value
dxcallsign = dxcallsign.toUpperCase()
message = document.getElementById('chatModuleMessage').value
@ -106,8 +104,12 @@ window.addEventListener('DOMContentLoaded', () => {
console.log(err);
});
// scroll to bottom
var element = document.getElementById("message-container");
element.scrollTo(0,element.scrollHeight);
// clear input
document.getElementById('chatModuleMessage').value = ''
@ -121,11 +123,11 @@ window.addEventListener('DOMContentLoaded', () => {
});
ipcRenderer.on('action-new-msg-received', (event, arg) => {
//console.log(arg.data)
console.log(arg.data)
var new_msg = arg.data
new_msg.forEach(function(item) {
//console.log(item)
console.log(item)
//for (i = 0; i < arg.data.length; i++) {
let obj = new Object();
@ -178,13 +180,15 @@ ipcRenderer.on('action-new-msg-received', (event, arg) => {
db.get(item.uuid).then(function (doc) {
// handle doc
// timestamp
update_chat(doc)
}).catch(function (err) {
console.log(err);
});
console.log("...................................")
return
@ -238,6 +242,11 @@ update_chat = function(obj) {
// create eventlistener for listening on clicking on a callsign
document.getElementById('chat-' + dxcallsign + '-list').addEventListener('click', function() {
document.getElementById('chatModuleDxCall').value = dxcallsign;
// scroll to bottom
var element = document.getElementById("message-container");
element.scrollTo(0,element.scrollHeight);
});
}
@ -250,11 +259,13 @@ update_chat = function(obj) {
if(!(document.getElementById('msg-' + obj._id))){
if (obj.type == 'received'){
var new_message = `
<div class="card border-light mb-3 w-75" id="msg-${obj._id}">
<div class="card-body">
<p class="text-small mb-0 text-muted text-break">${timestamp}</p>
<p class="card-text">${obj.msg}</p>
</div>
<div class="mt-3 mb-0 w-75" id="msg-${obj._id}">
<p class="font-monospace text-small mb-0 text-muted text-break">${timestamp}</p>
<div class="card border-light bg-light" id="msg-${obj._id}">
<div class="card-body">
<p class="card-text text-break text-wrap">${obj.msg}</p>
</div>
</div>
</div>
`;
}
@ -263,28 +274,22 @@ update_chat = function(obj) {
var new_message = `
<div class="card text-right border-primary ml-auto mb-3 w-75" style="margin-left: auto;"id="msg-${obj._id}">
<div class="card-body">
<p class="text-small mb-0 text-muted text-break">${timestamp}</p>
<p class="card-text">${obj.msg}</p>
</div>
<div class="ml-auto mt-3 mb-0 w-75" style="margin-left: auto;">
<p class="font-monospace text-right mb-0 text-muted" style="text-align: right;">${timestamp}</p>
<div class="card text-right border-primary bg-primary" id="msg-${obj._id}">
<div class="card-body">
<p class="card-text text-white text-break text-wrap">${obj.msg}</p>
</div>
</div>
</div>
`;
}
var id = "chat-" + obj.dxcallsign
document.getElementById(id).insertAdjacentHTML("beforeend", new_message);
var element = document.getElementById("message-container");
element.scrollTo(0,element.scrollHeight);
}
}

View file

@ -22,8 +22,8 @@ var configPath = path.join(configFolder, 'config.json');
const config = require(configPath);
// START INTERVALL COMMAND EXECUTION FOR STATES
setInterval(sock.getRxBuffer, 1000);
setInterval(sock.getMsgRxBuffer, 1000);
//setInterval(sock.getRxBuffer, 1000);
// WINDOW LISTENER
window.addEventListener('DOMContentLoaded', () => {

View file

@ -104,6 +104,9 @@ writeTncCommand = function(command) {
//socketLog.info(command)
// we use the writingCommand function to update our TCPIP state because we are calling this function a lot
// if socket openend, we are able to run commands
if (client.readyState == 'open') {
client.write(command + '\n');
@ -216,21 +219,24 @@ client.on('data', function(socketdata) {
}
/* A TEST WITH STREAMING DATA .... */
// if we received data through network stream, we get a single data item
if (data['arq'] == 'received') {
dataArray = []
messageArray = []
if(data['data'][0]['dt'] == 'f'){
socketLog.info(data)
// we need to encode here to do a deep check for checking if file or message
var encoded_data = atob(data['data'])
var splitted_data = encoded_data.split(split_char)
if(splitted_data[0] == 'f'){
dataArray.push(data)
}
if(data['data'][0]['dt'] == 'm'){
if(splitted_data[0] == 'm'){
messageArray.push(data)
}
rxBufferLengthGui = dataArray.length
let Files = {
@ -242,19 +248,21 @@ client.on('data', function(socketdata) {
let Messages = {
data: messageArray,
};
ipcRenderer.send('request-update-rx-msg-buffer', Messages);
//ipcRenderer.send('request-update-rx-msg-buffer', Messages);
ipcRenderer.send('request-new-msg-received', Messages);
}
// if we manually checking for the rx buffer we are getting an array of multiple data
if (data['command'] == 'rx_buffer') {
socketLog.info(data)
// iterate through buffer list and sort it to file or message array
dataArray = []
messageArray = []
for (i = 0; i < data['data-array'].length; i++) {
try{
// we need to encode here to do a deep check for checking if file or message
var encoded_data = atob(data['data-array'][i]['data'])
var splitted_data = encoded_data.split(split_char)
@ -274,7 +282,6 @@ client.on('data', function(socketdata) {
}
}
socketLog.info(dataArray)
rxBufferLengthGui = dataArray.length
@ -287,7 +294,9 @@ client.on('data', function(socketdata) {
let Messages = {
data: messageArray,
};
ipcRenderer.send('request-update-rx-msg-buffer', Messages);
//ipcRenderer.send('request-update-rx-msg-buffer', Messages);
ipcRenderer.send('request-new-msg-received', Messages);
}
@ -361,6 +370,8 @@ exports.sendMessage = function(dxcallsign, mode, frames, data, checksum) {
//command = '{"type" : "arq", "command" : "send_message", "parameter" : [{ "dxcallsign" : "' + dxcallsign + '", "mode" : "' + mode + '", "n_frames" : "' + frames + '", "data" : "' + data + '" , "checksum" : "' + checksum + '"}]}'
command = '{"type" : "arq", "command" : "send_raw", "parameter" : [{"dxcallsign" : "' + dxcallsign + '", "mode" : "' + mode + '", "n_frames" : "' + frames + '", "data" : "' + data + '"}]}'
socketLog.info(command)
socketLog.info("-------------------------------------")
writeTncCommand(command)
}

View file

@ -7,7 +7,9 @@
<meta http-equiv="Content-Security-Policy" content="script-src 'self';">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="../node_modules/bootstrap-icons/font/bootstrap-icons.css">
<!-- Custom CSS -->
<link rel="stylesheet" type="text/css" href="styles.css" />
<title>FreeDATA - CHAT</title>
</head>
<body>
@ -18,36 +20,61 @@
<script src="../node_modules/chart.js/dist/chart.min.js"></script>
<script src="../node_modules/chartjs-plugin-annotation/dist/chartjs-plugin-annotation.min.js"></script>
<div class="input-group m-1">
<input class="form-control" maxlength="6" style="max-width: 6rem; text-transform:uppercase" id="chatModuleDxCall" placeholder="DX CALL"></input>
<input class="form-control" id="chatModuleMessage" placeholder="Message"></input>
<button class="btn btn-sm btn-primary me-2" id="sendMessage" type="button">SEND MSG</button>
<div class="container-fluid">
<div class="row h-100">
<div class="col-4 p-0">
<! ------Chats area ---------------------------------------------------------------------->
<div class="list-group rounded-0" id="list-tab" role="tablist">
</div>
</div>
<div class="col-8 border vh-100 ">
<! ------messages area ---------------------------------------------------------------------->
<div class="container overflow-auto" id="message-container" style="height: 90%">
<div class="tab-content" id="nav-tabContent">
</div>
<!--<div class="container position-absolute bottom-0">-->
</div>
<!-- </div>-->
</div>
</div>
<nav class="navbar fixed-bottom navbar-light bg-light">
<div class="container-fluid">
<div class="input-group bottom-0 w-100">
<input class="form-control" maxlength="8" style="max-width: 6rem; text-transform:uppercase" id="chatModuleDxCall" placeholder="DX CALL"></input>
<input class="form-control" id="chatModuleMessage" placeholder="Message"></input>
<button class="btn btn-sm btn-primary me-2" id="sendMessage" type="button"><i class="bi bi-send" style="font-size: 1.2rem; color: white;"></i></button>
</div>
</div>
</nav>
</div>
<table class="table">
<thead>
<tr>
<th scope="col">Time</th>
<th scope="col">DXCall</th>
<!--<th scope="col">DXGrid</th>
<th scope="col">Distance</th>-->
<th scope="col">Message</th>
<!--<th scope="col">SNR</th>-->
</tr>
</thead>
<tbody id="rx-msg-data">
<!--
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
-->
</tbody>
</table>
</body>
</html>

View file

@ -602,6 +602,7 @@
</span>
<select class="form-select form-select-sm" aria-label=".form-select-sm" id="hamlib_ptt_protocol" style="width: 0.5rem">
<option value="NONE">NONE</option>
<option value="RIG">RIG</option>
<option value="USB">USB</option>
<option value="RTS">Serial RTS</option>

View file

@ -546,33 +546,15 @@ class DATA():
static.ARQ_COMPRESSION_FACTOR = len(data_frame_decompressed) / len(data_frame)
data_frame = data_frame_decompressed
# decode to utf-8 string
#data_frame = data_frame.decode("utf-8")
# decode json objects from data frame to inspect if we received a file or message
#rawdata = json.loads(data_frame)
'''
if datatype is a file, we append to RX_BUFFER, which contains files only
dt = datatype
--> f = file
--> m = message
fn = filename
ft = filetype
d = data
crc = checksum
'''
#if rawdata["dt"] == "f" or rawdata["dt"] == "m":
# datatype = rawdata["dt"]
#else:
# datatype = "raw"
uniqueid = str(uuid.uuid4())
timestamp = int(time.time())
base64_data = base64.b64encode(data_frame)
base64_data = base64_data.decode("utf-8")
static.RX_BUFFER.append([uniqueid, int(time.time()), static.DXCALLSIGN,static.DXGRID, base64_data])
jsondata = {"arq":"received", "uuid" : static.RX_BUFFER[i][0], "timestamp": static.RX_BUFFER[i][1], "dxcallsign": str(static.RX_BUFFER[i][2], 'utf-8'), "dxgrid": str(static.RX_BUFFER[i][3], 'utf-8'), "data": base64_data}
static.RX_BUFFER.append([uniqueid, timestamp, static.DXCALLSIGN, static.DXGRID, base64_data])
jsondata = {"arq":"received", "uuid" : uniqueid, "timestamp": timestamp, "dxcallsign": str(static.DXCALLSIGN, 'utf-8'), "dxgrid": str(static.DXGRID, 'utf-8'), "data": base64_data}
data_out = json.dumps(jsondata)
print(data_out)
sock.SOCKET_QUEUE.put(data_out)
static.INFO.append("ARQ;RECEIVING;SUCCESS")

View file

@ -234,9 +234,7 @@ class RF():
x = self.resampler.resample48_to_8(x)
length_x = len(x)
time_buffer_start = time.time()
# avoid decoding when transmitting to reduce CPU
if not static.TRANSMITTING:
# avoid buffer overflow by filling only if buffer not full
@ -266,7 +264,7 @@ class RF():
else:
data_out48k = self.modoutqueue.popleft()
self.fft_data = bytes(data_out48k)
return (data_out48k, audio.pyaudio.paContinue)
# --------------------------------------------------------------------------------------------------------
@ -365,7 +363,7 @@ class RF():
c = np.append(c, delta_zeros)
#structlog.get_logger("structlog").debug("[TNC] mod out shorter than audio buffer", delta=delta)
self.modoutqueue.append(c)
# Release our mod_out_lock so we can use the queue
self.mod_out_locked = False

View file

@ -93,8 +93,10 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
for client in CONNECTED_CLIENTS:
try:
client.send(sock_data)
except:
except Exception as e:
print("connection lost...")
print(e)
self.connection_alive = False
# we want to transmit scatter data only once to reduce network traffic
static.SCATTER = []
@ -114,9 +116,11 @@ class ThreadedTCPRequestHandler(socketserver.StreamRequestHandler):
chunk = self.request.recv(1024)
data += chunk
print(data)
if chunk == b'':
#print("connection broken. Closing...")
self.connection_alive = False
if data.startswith(b'{') and data.endswith(b'}\n'):
# split data by \n if we have multiple commands in socket buffer
@ -274,6 +278,9 @@ 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: