system app data path for config file

This commit is contained in:
DJ2LS 2021-09-04 20:23:58 +02:00 committed by GitHub
parent 385b775350
commit 32a70752fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 249 additions and 336 deletions

View file

@ -1,15 +1,18 @@
var net = require('net'); var net = require('net');
var config = require('./config.json'); const path = require('path')
const {
ipcRenderer
} = require('electron')
// https://stackoverflow.com/a/26227660
var appDataFolder = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME + "/.local/share")
var configFolder = path.join(appDataFolder, "codec2-FreeDATA");
var configPath = path.join(configFolder, 'config.json')
const config = require(configPath);
var daemon = new net.Socket(); var daemon = new net.Socket();
var msg = ''; // Current message, per connection. var msg = ''; // Current message, per connection.
const {
ipcRenderer
} = require('electron');
setTimeout(connectDAEMON, 500) setTimeout(connectDAEMON, 500)
function connectDAEMON() { function connectDAEMON() {
@ -20,14 +23,13 @@ function connectDAEMON() {
msg = ''; msg = '';
daemon.connect(config.daemon_port, config.daemon_host) daemon.connect(config.daemon_port, config.daemon_host)
if (config.tnclocation == 'localhost'){ if (config.tnclocation == 'localhost') {
daemon.connect(3001, '127.0.0.1') daemon.connect(3001, '127.0.0.1')
} else { } else {
daemon.connect(config.daemon_port, config.daemon_host) daemon.connect(config.daemon_port, config.daemon_host)
} }
//client.setTimeout(5000); //client.setTimeout(5000);
} }
@ -52,11 +54,9 @@ daemon.on('end', function(data) {
setTimeout(connectDAEMON, 2000) setTimeout(connectDAEMON, 2000)
}); });
//exports.writeCommand = function(command){ //exports.writeCommand = function(command){
writeDaemonCommand = function(command) { writeDaemonCommand = function(command) {
// we use the writingCommand function to update our TCPIP state because we are calling this function a lot // 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 socket openend, we are able to run commands
if (daemon.readyState == 'open') { if (daemon.readyState == 'open') {
@ -72,7 +72,6 @@ writeDaemonCommand = function(command) {
//uiMain.setDAEMONconnection('opening') //uiMain.setDAEMONconnection('opening')
} }
let Data = { let Data = {
daemon_connection: daemon.readyState, daemon_connection: daemon.readyState,
}; };
@ -81,14 +80,11 @@ writeDaemonCommand = function(command) {
// "https://stackoverflow.com/questions/9070700/nodejs-net-createserver-large-amount-of-data-coming-in" // "https://stackoverflow.com/questions/9070700/nodejs-net-createserver-large-amount-of-data-coming-in"
daemon.on('data', function(data) { daemon.on('data', function(data) {
data = data.toString('utf8'); /* convert data to string */ data = data.toString('utf8'); /* convert data to string */
msg += data.toString('utf8'); /*append data to buffer so we can stick long data together */ msg += data.toString('utf8'); /*append data to buffer so we can stick long data together */
/* check if we reached an EOF, if true, clear buffer and parse JSON data */ /* check if we reached an EOF, if true, clear buffer and parse JSON data */
if (data.endsWith('}')) { if (data.endsWith('}')) {
/*console.log(msg)*/ /*console.log(msg)*/
@ -117,8 +113,6 @@ daemon.on('data', function(data) {
////// check if EOF ... ////// check if EOF ...
} }
}); });
function hexToBytes(hex) { function hexToBytes(hex) {
@ -133,13 +127,9 @@ exports.getDaemonState = function() {
writeDaemonCommand(command) writeDaemonCommand(command)
} }
// START TNC // START TNC
// ` `== multi line string // ` `== multi line string
exports.startTNC = function(rx_audio, tx_audio, deviceid, deviceport, ptt, serialspeed) { exports.startTNC = function(rx_audio, tx_audio, deviceid, deviceport, ptt, serialspeed) {
var json_command = JSON.stringify({ var json_command = JSON.stringify({
type: 'SET', type: 'SET',
@ -155,12 +145,9 @@ exports.startTNC = function(rx_audio, tx_audio, deviceid, deviceport, ptt, seria
}] }]
}) })
//console.log(json_command) //console.log(json_command)
writeDaemonCommand(json_command) writeDaemonCommand(json_command)
} }
// STOP TNC // STOP TNC

View file

@ -1,16 +1,30 @@
const {app,BrowserWindow,ipcMain} = require('electron') const {
app,
BrowserWindow,
ipcMain
} = require('electron')
const path = require('path') const path = require('path')
const fs = require('fs')
var testpath = path.join(app.getPath ("appData"), "codec2-FreeDATA"); app.setName("codec2-FreeDATA");
console.log(testpath)
var appDataFolder = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME + "/.local/share")
var configFolder = path.join(appDataFolder, "codec2-FreeDATA");
var configPath = path.join(configFolder, 'config.json')
// create folder if not exists
if (!fs.existsSync(configFolder)) {
fs.mkdirSync(configFolder);
}
// create config file if not exists
if (!fs.existsSync(configPath)) {
fs.writeFileSync(configPath, '{}')
}
const configPath = path.join(__dirname, 'config.json');
const config = require(configPath); const config = require(configPath);
const exec = require('child_process').exec; const exec = require('child_process').exec;
console.log(configPath)
let win = null; let win = null;
let data = null; let data = null;
@ -76,7 +90,6 @@ function createWindow() {
}) })
*/ */
// https://stackoverflow.com/questions/44258831/only-hide-the-window-when-closing-it-electron // https://stackoverflow.com/questions/44258831/only-hide-the-window-when-closing-it-electron
/* /*
data.on('close', function(evt) { data.on('close', function(evt) {
@ -86,11 +99,9 @@ function createWindow() {
*/ */
} }
app.whenReady().then(() => { app.whenReady().then(() => {
createWindow() createWindow()
// start daemon // start daemon
// https://stackoverflow.com/a/5775120 // https://stackoverflow.com/a/5775120
daemonProcess = exec('./daemon', function callback(error, stdout, stderr) { daemonProcess = exec('./daemon', function callback(error, stdout, stderr) {
@ -98,8 +109,6 @@ app.whenReady().then(() => {
console.log(error) console.log(error)
}); });
app.on('activate', () => { app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) { if (BrowserWindow.getAllWindows().length === 0) {
createWindow() createWindow()
@ -116,9 +125,8 @@ app.on('window-all-closed', () => {
} }
}) })
// IPC HANDLER // IPC HANDLER
/* /*
ipcMain.on('show-data-window', (event, arg) => { ipcMain.on('show-data-window', (event, arg) => {
data.show() data.show()
}); });

View file

@ -1,29 +1,28 @@
const path = require('path') const path = require('path')
const configPath = path.join(__dirname, 'config.json');
const config = require(configPath);
const sock = require('./sock.js');
const daemon = require('./daemon.js');
const { const {
ipcRenderer ipcRenderer
} = require('electron'); } = require('electron')
const sock = require('./sock.js');
const daemon = require('./daemon.js');
const fs = require('fs'); const fs = require('fs');
const {
locatorToLatLng,
distance,
bearingDistance,
latLngToLocator
} = require('qth-locator');
const { locatorToLatLng, distance, bearingDistance, latLngToLocator } = require('qth-locator'); // https://stackoverflow.com/a/26227660
var appDataFolder = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME + "/.local/share")
var configFolder = path.join(appDataFolder, "codec2-FreeDATA");
var configPath = path.join(configFolder, 'config.json')
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, 250) setInterval(sock.getTncState, 250)
setInterval(sock.getRxBuffer, 1000) setInterval(sock.getRxBuffer, 1000)
// UPDATE FFT DEMO // UPDATE FFT DEMO
updateFFT = function(fft) { updateFFT = function(fft) {
@ -34,8 +33,6 @@ updateFFT = function(fft) {
} }
setInterval(updateFFT, 250) setInterval(updateFFT, 250)
// WINDOW LISTENER // WINDOW LISTENER
window.addEventListener('DOMContentLoaded', () => { window.addEventListener('DOMContentLoaded', () => {
// LOAD SETTINGS // LOAD SETTINGS
@ -63,7 +60,7 @@ window.addEventListener('DOMContentLoaded', () => {
document.getElementById("waterfall").style.height = '0px'; document.getElementById("waterfall").style.height = '0px';
} }
// remote tnc // remote tnc
if (config.tnclocation == 'remote') { if (config.tnclocation == 'remote') {
document.getElementById("local-remote-switch1").checked = false document.getElementById("local-remote-switch1").checked = false
document.getElementById("local-remote-switch2").checked = true document.getElementById("local-remote-switch2").checked = true
@ -74,14 +71,12 @@ window.addEventListener('DOMContentLoaded', () => {
document.getElementById("remote-tnc-field").style.visibility = 'hidden'; document.getElementById("remote-tnc-field").style.visibility = 'hidden';
} }
// Create spectrum object on canvas with ID "waterfall" // Create spectrum object on canvas with ID "waterfall"
global.spectrum = new Spectrum( global.spectrum = new Spectrum(
"waterfall", { "waterfall", {
spectrumPercent: 20 spectrumPercent: 20
}); });
// SETUP OF SCATTER DIAGRAM // SETUP OF SCATTER DIAGRAM
global.data = { global.data = {
@ -95,7 +90,6 @@ window.addEventListener('DOMContentLoaded', () => {
}], }],
}; };
var ctx = document.getElementById('scatter').getContext('2d'); var ctx = document.getElementById('scatter').getContext('2d');
global.myChart = new Chart(ctx, { global.myChart = new Chart(ctx, {
type: 'scatter', type: 'scatter',
@ -158,8 +152,6 @@ window.addEventListener('DOMContentLoaded', () => {
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
}); });
// on change port and host // on change port and host
document.getElementById("tnc_adress").addEventListener("change", () => { document.getElementById("tnc_adress").addEventListener("change", () => {
console.log(document.getElementById("tnc_adress").value) console.log(document.getElementById("tnc_adress").value)
@ -219,14 +211,12 @@ window.addEventListener('DOMContentLoaded', () => {
var serialspeed = document.getElementById("hamlib_serialspeed").value var serialspeed = document.getElementById("hamlib_serialspeed").value
var ptt = document.getElementById("hamlib_ptt").value var ptt = document.getElementById("hamlib_ptt").value
config.deviceid = deviceid config.deviceid = deviceid
config.deviceport = deviceport config.deviceport = deviceport
config.serialspeed = serialspeed config.serialspeed = serialspeed
config.ptt = ptt config.ptt = ptt
fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
daemon.startTNC(rx_audio, tx_audio, deviceid, deviceport, ptt, serialspeed) daemon.startTNC(rx_audio, tx_audio, deviceid, deviceport, ptt, serialspeed)
setTimeout(function() { setTimeout(function() {
sock.saveMyCall(config.mycall); sock.saveMyCall(config.mycall);
@ -243,14 +233,13 @@ window.addEventListener('DOMContentLoaded', () => {
// openDataModule button clicked // openDataModule button clicked
document.getElementById("openDataModule").addEventListener("click", () => { document.getElementById("openDataModule").addEventListener("click", () => {
if(document.getElementById("mySidebar").style.width == "40%"){ if (document.getElementById("mySidebar").style.width == "40%") {
document.getElementById("mySidebar").style.width = "0px"; document.getElementById("mySidebar").style.width = "0px";
} else { } else {
document.getElementById("mySidebar").style.width = "40%"; document.getElementById("mySidebar").style.width = "40%";
} }
}) })
// START TRANSMISSION // START TRANSMISSION
document.getElementById("startTransmission").addEventListener("click", () => { document.getElementById("startTransmission").addEventListener("click", () => {
@ -260,7 +249,6 @@ window.addEventListener('DOMContentLoaded', () => {
//reader.readAsBinaryString(fileList[0]); //reader.readAsBinaryString(fileList[0]);
reader.readAsDataURL(fileList[0]); reader.readAsDataURL(fileList[0]);
reader.onload = function(e) { reader.onload = function(e) {
// binary data // binary data
@ -287,17 +275,12 @@ window.addEventListener('DOMContentLoaded', () => {
}) })
}) })
ipcRenderer.on('action-update-tnc-state', (event, arg) => { ipcRenderer.on('action-update-tnc-state', (event, arg) => {
// TOE TIME OF EXECUTION --> How many time needs a command to be executed until data arrives // TOE TIME OF EXECUTION --> How many time needs a command to be executed until data arrives
if (typeof(arg.toe) == 'undefined'){ if (typeof(arg.toe) == 'undefined') {
var toe = 0 var toe = 0
} else { } else {
var toe = arg.toe var toe = arg.toe
@ -307,7 +290,6 @@ ipcRenderer.on('action-update-tnc-state', (event, arg) => {
// DATA STATE // DATA STATE
global.rxBufferLengthTnc = arg.rx_buffer_length global.rxBufferLengthTnc = arg.rx_buffer_length
// SCATTER DIAGRAM PLOTTING // SCATTER DIAGRAM PLOTTING
//global.myChart.destroy(); //global.myChart.destroy();
@ -322,12 +304,12 @@ ipcRenderer.on('action-update-tnc-state', (event, arg) => {
}], }],
}; };
if (typeof(arg.scatter) == 'undefined'){ if (typeof(arg.scatter) == 'undefined') {
var scatterSize = 0 var scatterSize = 0
} else { } else {
var scatterSize = arg.scatter.length var scatterSize = arg.scatter.length
} }
if (global.data != newdata && scatterSize > 0){ if (global.data != newdata && scatterSize > 0) {
try { try {
global.myChart.destroy(); global.myChart.destroy();
} catch (e) { } catch (e) {
@ -336,8 +318,6 @@ ipcRenderer.on('action-update-tnc-state', (event, arg) => {
global.data = newdata global.data = newdata
var ctx = document.getElementById('scatter').getContext('2d'); var ctx = document.getElementById('scatter').getContext('2d');
global.myChart = new Chart(ctx, { global.myChart = new Chart(ctx, {
type: 'scatter', type: 'scatter',
@ -402,7 +382,6 @@ ipcRenderer.on('action-update-tnc-state', (event, arg) => {
document.getElementById("rms_level").setAttribute("aria-valuenow", arg.rms_level) document.getElementById("rms_level").setAttribute("aria-valuenow", arg.rms_level)
document.getElementById("rms_level").setAttribute("style", "width:" + arg.rms_level + "%;") document.getElementById("rms_level").setAttribute("style", "width:" + arg.rms_level + "%;")
// CHANNEL STATE // CHANNEL STATE
if (arg.channel_state == 'RECEIVING_SIGNALLING') { if (arg.channel_state == 'RECEIVING_SIGNALLING') {
document.getElementById("signalling_state").className = "btn btn-success"; document.getElementById("signalling_state").className = "btn btn-success";
@ -435,7 +414,7 @@ ipcRenderer.on('action-update-tnc-state', (event, arg) => {
document.getElementById("bandwith").innerHTML = arg.bandwith document.getElementById("bandwith").innerHTML = arg.bandwith
// SET BYTES PER MINUTE // SET BYTES PER MINUTE
if (typeof(arg.arq_bytes_per_minute) == 'undefined'){ if (typeof(arg.arq_bytes_per_minute) == 'undefined') {
var arq_bytes_per_minute = 0 var arq_bytes_per_minute = 0
} else { } else {
var arq_bytes_per_minute = arg.arq_bytes_per_minute var arq_bytes_per_minute = arg.arq_bytes_per_minute
@ -443,7 +422,7 @@ ipcRenderer.on('action-update-tnc-state', (event, arg) => {
document.getElementById("bytes_per_min").innerHTML = arq_bytes_per_minute document.getElementById("bytes_per_min").innerHTML = arq_bytes_per_minute
// SET TOTAL BYTES // SET TOTAL BYTES
if (typeof(arg.total_bytes) == 'undefined'){ if (typeof(arg.total_bytes) == 'undefined') {
var total_bytes = 0 var total_bytes = 0
} else { } else {
var total_bytes = arg.total_bytes var total_bytes = arg.total_bytes
@ -452,12 +431,11 @@ ipcRenderer.on('action-update-tnc-state', (event, arg) => {
document.getElementById("transmission_progress").setAttribute("aria-valuenow", arg.arq_transmission_percent) document.getElementById("transmission_progress").setAttribute("aria-valuenow", arg.arq_transmission_percent)
document.getElementById("transmission_progress").setAttribute("style", "width:" + arg.arq_transmission_percent + "%;") document.getElementById("transmission_progress").setAttribute("style", "width:" + arg.arq_transmission_percent + "%;")
// UPDATE HEARD STATIONS // UPDATE HEARD STATIONS
var tbl = document.getElementById("heardstations"); var tbl = document.getElementById("heardstations");
document.getElementById("heardstations").innerHTML = '' document.getElementById("heardstations").innerHTML = ''
if (typeof(arg.stations) == 'undefined'){ if (typeof(arg.stations) == 'undefined') {
var heardStationsLength = 0 var heardStationsLength = 0
} else { } else {
var heardStationsLength = arg.stations.length var heardStationsLength = arg.stations.length
@ -465,7 +443,6 @@ ipcRenderer.on('action-update-tnc-state', (event, arg) => {
for (i = 0; i < heardStationsLength; i++) { for (i = 0; i < heardStationsLength; i++) {
// first we update the PING window // first we update the PING window
console.log(document.getElementById("dxCall").value) console.log(document.getElementById("dxCall").value)
if (arg.stations[i]['DXCALLSIGN'] == document.getElementById("dxCall").value) { if (arg.stations[i]['DXCALLSIGN'] == document.getElementById("dxCall").value) {
@ -483,7 +460,6 @@ ipcRenderer.on('action-update-tnc-state', (event, arg) => {
document.getElementById("dataModalPingDB").innerHTML = arg.stations[i]['SNR'] document.getElementById("dataModalPingDB").innerHTML = arg.stations[i]['SNR']
} }
// now we update the heard stations list // now we update the heard stations list
var row = document.createElement("tr"); var row = document.createElement("tr");
//https://stackoverflow.com/q/51421470 //https://stackoverflow.com/q/51421470
@ -514,7 +490,7 @@ ipcRenderer.on('action-update-tnc-state', (event, arg) => {
var gridDistance = document.createElement("td"); var gridDistance = document.createElement("td");
var gridDistanceText = document.createElement('span'); var gridDistanceText = document.createElement('span');
try{ try {
gridDistanceText.innerText = parseInt(distance(document.getElementById("myGrid").value, arg.stations[i]['DXGRID'])) + ' km'; gridDistanceText.innerText = parseInt(distance(document.getElementById("myGrid").value, arg.stations[i]['DXGRID'])) + ' km';
} catch { } catch {
gridDistanceText.innerText = '---' gridDistanceText.innerText = '---'
@ -526,27 +502,26 @@ ipcRenderer.on('action-update-tnc-state', (event, arg) => {
dataTypeText.innerText = arg.stations[i]['DATATYPE'] dataTypeText.innerText = arg.stations[i]['DATATYPE']
dataType.appendChild(dataTypeText); dataType.appendChild(dataTypeText);
if(dataTypeText.innerText == 'CQ CQ CQ'){ if (dataTypeText.innerText == 'CQ CQ CQ') {
row.classList.add("table-success"); row.classList.add("table-success");
} }
if(dataTypeText.innerText == 'DATA-CHANNEL'){ if (dataTypeText.innerText == 'DATA-CHANNEL') {
row.classList.add("table-warning"); row.classList.add("table-warning");
} }
if(dataTypeText.innerText == 'BEACON'){ if (dataTypeText.innerText == 'BEACON') {
row.classList.add("table-light"); row.classList.add("table-light");
} }
if(dataTypeText.innerText == 'PING'){ if (dataTypeText.innerText == 'PING') {
row.classList.add("table-info"); row.classList.add("table-info");
} }
if(dataTypeText.innerText == 'PING-ACK'){ if (dataTypeText.innerText == 'PING-ACK') {
row.classList.add("table-primary"); row.classList.add("table-primary");
} }
var snr = document.createElement("td"); var snr = document.createElement("td");
var snrText = document.createElement('span'); var snrText = document.createElement('span');
snrText.innerText = arg.stations[i]['SNR'] snrText.innerText = arg.stations[i]['SNR']
@ -564,12 +539,8 @@ ipcRenderer.on('action-update-tnc-state', (event, arg) => {
}); });
ipcRenderer.on('action-update-daemon-state', (event, arg) => { ipcRenderer.on('action-update-daemon-state', (event, arg) => {
// RAM // RAM
document.getElementById("progressbar_ram").setAttribute("aria-valuenow", arg.ram_usage) document.getElementById("progressbar_ram").setAttribute("aria-valuenow", arg.ram_usage)
document.getElementById("progressbar_ram").setAttribute("style", "width:" + arg.ram_usage + "%;") document.getElementById("progressbar_ram").setAttribute("style", "width:" + arg.ram_usage + "%;")
@ -580,7 +551,6 @@ ipcRenderer.on('action-update-daemon-state', (event, arg) => {
document.getElementById("progressbar_cpu").setAttribute("style", "width:" + arg.cpu_usage + "%;") document.getElementById("progressbar_cpu").setAttribute("style", "width:" + arg.cpu_usage + "%;")
document.getElementById("progressbar_cpu_value").innerHTML = arg.cpu_usage + "%" document.getElementById("progressbar_cpu_value").innerHTML = arg.cpu_usage + "%"
// UPDATE AUDIO INPUT // UPDATE AUDIO INPUT
if (document.getElementById("audio_input_selectbox").length != arg.input_devices.length) { if (document.getElementById("audio_input_selectbox").length != arg.input_devices.length) {
@ -623,7 +593,6 @@ ipcRenderer.on('action-update-daemon-state', (event, arg) => {
document.getElementById("hamlib_serialspeed").disabled = true document.getElementById("hamlib_serialspeed").disabled = true
document.getElementById("startTransmission").disabled = false document.getElementById("startTransmission").disabled = false
} else { } else {
document.getElementById('hamlib_deviceid').disabled = false document.getElementById('hamlib_deviceid').disabled = false
document.getElementById('hamlib_deviceport').disabled = false document.getElementById('hamlib_deviceport').disabled = false
@ -644,7 +613,6 @@ ipcRenderer.on('action-update-daemon-state', (event, arg) => {
}); });
ipcRenderer.on('action-update-daemon-connection', (event, arg) => { ipcRenderer.on('action-update-daemon-connection', (event, arg) => {
if (arg.daemon_connection == 'open') { if (arg.daemon_connection == 'open') {
@ -664,10 +632,9 @@ ipcRenderer.on('action-update-daemon-connection', (event, arg) => {
}); });
ipcRenderer.on('action-update-rx-buffer', (event, arg) => { ipcRenderer.on('action-update-rx-buffer', (event, arg) => {
var data = arg.data["DATA"] var data = arg.data["DATA"]
var tbl = document.getElementById("rx-data"); var tbl = document.getElementById("rx-data");
document.getElementById("rx-data").innerHTML = '' document.getElementById("rx-data").innerHTML = ''
@ -704,20 +671,18 @@ var data = arg.data["DATA"]
dxCallText.innerText = arg.data[i]['DXCALLSIGN'] dxCallText.innerText = arg.data[i]['DXCALLSIGN']
dxCall.appendChild(dxCallText); dxCall.appendChild(dxCallText);
/* /*
var dxGrid = document.createElement("td"); var dxGrid = document.createElement("td");
var dxGridText = document.createElement('span'); var dxGridText = document.createElement('span');
dxGridText.innerText = arg.data[i]['DXGRID'] dxGridText.innerText = arg.data[i]['DXGRID']
dxGrid.appendChild(dxGridText); dxGrid.appendChild(dxGridText);
*/ */
var fileName = document.createElement("td"); var fileName = document.createElement("td");
var fileNameText = document.createElement('span'); var fileNameText = document.createElement('span');
fileNameText.innerText = arg.data[i]['RXDATA'][0]['filename'] fileNameText.innerText = arg.data[i]['RXDATA'][0]['filename']
fileName.appendChild(fileNameText); fileName.appendChild(fileNameText);
row.appendChild(timestamp); row.appendChild(timestamp);
row.appendChild(dxCall); row.appendChild(dxCall);
// row.appendChild(dxGrid); // row.appendChild(dxGrid);
@ -725,11 +690,11 @@ var data = arg.data["DATA"]
tbl.appendChild(row); tbl.appendChild(row);
// Creates rxdata folder if not exists // Creates rxdata folder if not exists
// https://stackoverflow.com/a/13544465 // https://stackoverflow.com/a/13544465
fs.mkdir('rxdata', { recursive: true }, function(err) { fs.mkdir('rxdata', {
recursive: true
}, function(err) {
console.log(err); console.log(err);
}); });
@ -746,7 +711,6 @@ var data = arg.data["DATA"]
}); });
ipcRenderer.on('run-tnc-command', (event, arg) => { ipcRenderer.on('run-tnc-command', (event, arg) => {
if (arg.command == 'saveMyCall') { if (arg.command == 'saveMyCall') {
sock.saveMyCall(arg.callsign) sock.saveMyCall(arg.callsign)

View file

@ -1,8 +1,14 @@
var net = require('net'); var net = require('net');
var config = require('./config.json'); const path = require('path')
const { const {
ipcRenderer ipcRenderer
} = require('electron'); } = require('electron')
// https://stackoverflow.com/a/26227660
var appDataFolder = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME + "/.local/share")
var configFolder = path.join(appDataFolder, "codec2-FreeDATA");
var configPath = path.join(configFolder, 'config.json')
const config = require(configPath);
var client = new net.Socket(); var client = new net.Socket();
var msg = ''; // Current message, per connection. var msg = ''; // Current message, per connection.
@ -11,7 +17,6 @@ var msg = ''; // Current message, per connection.
var rxBufferLengthTnc = 0 var rxBufferLengthTnc = 0
var rxBufferLengthGui = 0 var rxBufferLengthGui = 0
// network connection Timeout // network connection Timeout
setTimeout(connectTNC, 3000) setTimeout(connectTNC, 3000)
@ -22,7 +27,7 @@ function connectTNC() {
//clear message buffer after reconnecting or inital connection //clear message buffer after reconnecting or inital connection
msg = ''; msg = '';
if (config.tnclocation == 'localhost'){ if (config.tnclocation == 'localhost') {
client.connect(3000, '127.0.0.1') client.connect(3000, '127.0.0.1')
} else { } else {
client.connect(config.tnc_port, config.tnc_host) client.connect(config.tnc_port, config.tnc_host)
@ -36,7 +41,6 @@ client.on('connect', function(data) {
client.on('error', function(data) { client.on('error', function(data) {
console.log('TNC connection error'); console.log('TNC connection error');
let Data = { let Data = {
busy_state: "-", busy_state: "-",
arq_state: "-", arq_state: "-",
@ -70,7 +74,6 @@ client.on('end', function(data) {
}); });
//exports.writeTncCommand = function(command){ //exports.writeTncCommand = function(command){
writeTncCommand = function(command) { writeTncCommand = function(command) {
@ -94,8 +97,6 @@ writeTncCommand = function(command) {
} }
} }
client.on('data', function(data) { client.on('data', function(data) {
/* /*
@ -157,60 +158,15 @@ client.on('data', function(data) {
rxBufferLengthGui = data['DATA-ARRAY'].length rxBufferLengthGui = data['DATA-ARRAY'].length
//console.log(rxBufferLengthGui) //console.log(rxBufferLengthGui)
let Data = { let Data = {
data : data['DATA-ARRAY'], data: data['DATA-ARRAY'],
}; };
//console.log(Data) //console.log(Data)
ipcRenderer.send('request-update-rx-buffer', Data); ipcRenderer.send('request-update-rx-buffer', Data);
} }
/*
if (data['COMMAND'] == 'DATA_STATE') {
let Data = {
rx_buffer_length: data['RX_BUFFER_LENGTH'],
tx_n_max_retries: data['TX_N_MAX_RETRIES'],
arq_tx_n_frames_per_burst: data['ARQ_TX_N_FRAMES_PER_BURST'],
arq_tx_n_bursts: data['ARQ_TX_N_BURSTS'],
arq_tx_n_current_arq_frame: data['ARQ_TX_N_CURRENT_ARQ_FRAME'],
arq_tx_n_total_arq_frames: data['ARQ_TX_N_TOTAL_ARQ_FRAMES'],
arq_rx_frame_n_bursts: data['ARQ_RX_FRAME_N_BURSTS'],
arq_rx_n_current_arq_frame: data['ARQ_RX_N_CURRENT_ARQ_FRAME'],
arq_n_arq_frames_per_data_frame: data['ARQ_N_ARQ_FRAMES_PER_DATA_FRAME'],
};
console.log(Data)
ipcRenderer.send('request-update-data-state', Data);
}
*/
/*
if (data['COMMAND'] == 'HEARD_STATIONS') {
//console.log(data['STATIONS'])
let Data = {
stations: data['STATIONS'],
};
//console.log(Data)
ipcRenderer.send('request-update-heard-stations', Data);
}
*/
/*
if (data['COMMAND'] == 'SCATTER') {
console.log(data['SCATTER'])
let Data = {
stations: data['STATIONS'],
};
//console.log(Data)
//ipcRenderer.send('request-update-heard-stations', Data);
}
*/
// check if EOF ... // check if EOF ...
} }
}); });
function hexToBytes(hex) { function hexToBytes(hex) {
@ -219,68 +175,66 @@ function hexToBytes(hex) {
return bytes; return bytes;
} }
//Save myCall //Save myCall
exports.saveMyCall = function(callsign) { exports.saveMyCall = function(callsign) {
command = '{"type" : "SET", "command": "MYCALLSIGN" , "parameter": "' + callsign + '", "timestamp" : '+Date.now()+'}' command = '{"type" : "SET", "command": "MYCALLSIGN" , "parameter": "' + callsign + '", "timestamp" : ' + Date.now() + '}'
writeTncCommand(command) writeTncCommand(command)
} }
// Save myGrid // Save myGrid
exports.saveMyGrid = function(grid) { exports.saveMyGrid = function(grid) {
command = '{"type" : "SET", "command": "MYGRID" , "parameter": "' + grid + '", "timestamp" : '+Date.now()+'}' command = '{"type" : "SET", "command": "MYGRID" , "parameter": "' + grid + '", "timestamp" : ' + Date.now() + '}'
writeTncCommand(command) writeTncCommand(command)
} }
//Get TNC State //Get TNC State
exports.getTncState = function() { exports.getTncState = function() {
command = '{"type" : "GET", "command" : "TNC_STATE", "timestamp" : '+Date.now()+'}'; command = '{"type" : "GET", "command" : "TNC_STATE", "timestamp" : ' + Date.now() + '}';
writeTncCommand(command) writeTncCommand(command)
} }
//Get DATA State //Get DATA State
exports.getDataState = function() { exports.getDataState = function() {
command = '{"type" : "GET", "command" : "DATA_STATE", "timestamp" : '+Date.now()+'}'; command = '{"type" : "GET", "command" : "DATA_STATE", "timestamp" : ' + Date.now() + '}';
//writeTncCommand(command) //writeTncCommand(command)
} }
//Get Heard Stations //Get Heard Stations
exports.getHeardStations = function() { exports.getHeardStations = function() {
command = '{"type" : "GET", "command" : "HEARD_STATIONS", "timestamp" : '+Date.now()+'}'; command = '{"type" : "GET", "command" : "HEARD_STATIONS", "timestamp" : ' + Date.now() + '}';
writeTncCommand(command) writeTncCommand(command)
} }
// Send Ping // Send Ping
exports.sendPing = function(dxcallsign) { exports.sendPing = function(dxcallsign) {
command = '{"type" : "PING", "command" : "PING", "dxcallsign" : "' + dxcallsign + '", "timestamp" : '+Date.now()+'}' command = '{"type" : "PING", "command" : "PING", "dxcallsign" : "' + dxcallsign + '", "timestamp" : ' + Date.now() + '}'
writeTncCommand(command) writeTncCommand(command)
} }
// Send CQ // Send CQ
exports.sendCQ = function() { exports.sendCQ = function() {
command = '{"type" : "CQ", "command" : "CQCQCQ", "timestamp" : '+Date.now()+'}' command = '{"type" : "CQ", "command" : "CQCQCQ", "timestamp" : ' + Date.now() + '}'
writeTncCommand(command) writeTncCommand(command)
} }
// Send File // Send File
exports.sendFile = function(dxcallsign, mode, frames, filename, filetype, data, checksum) { exports.sendFile = function(dxcallsign, mode, frames, filename, filetype, data, checksum) {
command = '{"type" : "ARQ", "command" : "sendFile", "dxcallsign" : "'+dxcallsign+'", "mode" : "'+mode+'", "n_frames" : "'+frames+'", "filename" : "'+filename+'", "filetype" : "'+filetype+'", "data" : "'+data+'", "checksum" : "'+checksum+'", "timestamp" : '+Date.now()+'}' command = '{"type" : "ARQ", "command" : "sendFile", "dxcallsign" : "' + dxcallsign + '", "mode" : "' + mode + '", "n_frames" : "' + frames + '", "filename" : "' + filename + '", "filetype" : "' + filetype + '", "data" : "' + data + '", "checksum" : "' + checksum + '", "timestamp" : ' + Date.now() + '}'
writeTncCommand(command) writeTncCommand(command)
} }
// Send Message // Send Message
exports.sendMessage = function(dxcallsign, mode, frames, data, checksum) { exports.sendMessage = function(dxcallsign, mode, frames, data, checksum) {
command = '{"type" : "ARQ", "command" : "sendMessage", "dxcallsign" : " '+dxcallsign+' ", "mode" : " '+mode+' ", "n_frames" : " '+frames+' ", "data" : '+data+' , "checksum" : " '+checksum+' ", "timestamp" : '+Date.now()+'}' command = '{"type" : "ARQ", "command" : "sendMessage", "dxcallsign" : " ' + dxcallsign + ' ", "mode" : " ' + mode + ' ", "n_frames" : " ' + frames + ' ", "data" : ' + data + ' , "checksum" : " ' + checksum + ' ", "timestamp" : ' + Date.now() + '}'
writeTncCommand(command) writeTncCommand(command)
} }
// Get RX BUffer // Get RX BUffer
exports.getRxBuffer = function() { exports.getRxBuffer = function() {
command = '{"type" : "GET", "command" : "RX_BUFFER", "timestamp" : '+Date.now()+'}' command = '{"type" : "GET", "command" : "RX_BUFFER", "timestamp" : ' + Date.now() + '}'
// call command only if new data arrived // call command only if new data arrived
if(rxBufferLengthGui != rxBufferLengthTnc){ if (rxBufferLengthGui != rxBufferLengthTnc) {
writeTncCommand(command) writeTncCommand(command)
} }
} }