FreeDATA/gui/preload-main.js

741 lines
26 KiB
JavaScript
Raw Normal View History

2021-08-28 16:46:49 +00:00
const path = require('path')
const configPath = path.join(__dirname, 'config.json');
2021-07-23 15:40:44 +00:00
const config = require(configPath);
2021-08-28 16:46:49 +00:00
const sock = require('./sock.js');
const daemon = require('./daemon.js');
2021-07-24 07:06:22 +00:00
const {
ipcRenderer
} = require('electron');
2021-07-23 15:40:44 +00:00
const fs = require('fs');
2021-08-08 17:29:18 +00:00
const { locatorToLatLng, distance, bearingDistance, latLngToLocator } = require('qth-locator');
2021-07-23 15:40:44 +00:00
// START INTERVALL COMMAND EXECUTION FOR STATES
2021-07-24 07:06:22 +00:00
setInterval(daemon.getDaemonState, 1000)
2021-08-08 09:43:50 +00:00
setInterval(sock.getTncState, 250)
2021-08-23 14:24:49 +00:00
setInterval(sock.getRxBuffer, 1000)
2021-08-23 13:36:14 +00:00
2021-07-23 15:40:44 +00:00
// UPDATE FFT DEMO
2021-07-24 07:06:22 +00:00
updateFFT = function(fft) {
var fft = Array.from({
length: 2048
}, () => Math.floor(Math.random() * 10));
spectrum.addData(fft);
2021-07-23 15:40:44 +00:00
}
2021-07-24 07:06:22 +00:00
setInterval(updateFFT, 250)
2021-07-23 15:40:44 +00:00
2021-07-24 07:06:22 +00:00
// WINDOW LISTENER
2021-07-23 15:40:44 +00:00
window.addEventListener('DOMContentLoaded', () => {
2021-07-24 07:06:22 +00:00
// LOAD SETTINGS
document.getElementById("tnc_adress").value = config.tnc_host
document.getElementById("tnc_port").value = config.tnc_port
document.getElementById("myCall").value = config.mycall
document.getElementById("myGrid").value = config.mygrid
2021-08-07 08:54:34 +00:00
document.getElementById('hamlib_deviceid').value = config.deviceid
2021-07-25 16:19:51 +00:00
document.getElementById('hamlib_deviceport').value = config.deviceport
document.getElementById('hamlib_serialspeed').value = config.serialspeed
document.getElementById('hamlib_ptt').value = config.ptt
2021-08-07 08:54:34 +00:00
if (config.spectrum == 'waterfall') {
document.getElementById("waterfall-scatter-switch1").checked = true
document.getElementById("waterfall-scatter-switch2").checked = false
document.getElementById("scatter").style.visibility = 'hidden';
document.getElementById("waterfall").style.visibility = 'visible';
document.getElementById("waterfall").style.height = '350px';
} else {
2021-07-25 16:19:51 +00:00
2021-08-07 08:54:34 +00:00
document.getElementById("waterfall-scatter-switch1").checked = false
document.getElementById("waterfall-scatter-switch2").checked = true
document.getElementById("scatter").style.visibility = 'visible';
document.getElementById("waterfall").style.visibility = 'hidden';
document.getElementById("waterfall").style.height = '0px';
}
2021-07-25 16:19:51 +00:00
2021-08-07 08:54:34 +00:00
// Create spectrum object on canvas with ID "waterfall"
global.spectrum = new Spectrum(
"waterfall", {
spectrumPercent: 20
});
2021-08-07 08:54:34 +00:00
// SETUP OF SCATTER DIAGRAM
global.data = {
2021-08-07 08:54:34 +00:00
datasets: [{
label: 'Scatter Dataset',
data: [{
x: 0,
y: 0
}],
backgroundColor: 'rgb(255, 99, 132)'
}],
};
2021-08-07 08:54:34 +00:00
var ctx = document.getElementById('scatter').getContext('2d');
global.myChart = new Chart(ctx, {
type: 'scatter',
data: data,
options: {
animation: false,
legend: {
display: false
},
scales: {
display: false,
grid: {
display: false
},
x: {
type: 'linear',
position: 'bottom',
display: false
},
y: {
display: false
}
}
}
});
2021-08-07 08:54:34 +00:00
// on click waterfall scatter toggle view
// waterfall
document.getElementById("waterfall-scatter-switch1").addEventListener("click", () => {
document.getElementById("scatter").style.visibility = 'hidden';
document.getElementById("waterfall").style.visibility = 'visible';
document.getElementById("waterfall").style.height = '350px';
config.spectrum = 'waterfall'
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
});
// scatter
document.getElementById("waterfall-scatter-switch2").addEventListener("click", () => {
document.getElementById("scatter").style.visibility = 'visible';
document.getElementById("waterfall").style.visibility = 'hidden';
document.getElementById("waterfall").style.height = '0px';
config.spectrum = 'scatter'
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
});
2021-07-17 07:03:40 +00:00
2021-07-24 07:06:22 +00:00
// on change port and host
document.getElementById("tnc_adress").addEventListener("change", () => {
console.log(document.getElementById("tnc_adress").value)
config.tnc_host = document.getElementById("tnc_adress").value
config.daemon_host = document.getElementById("tnc_adress").value
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
2021-07-23 15:40:44 +00:00
});
2021-07-24 07:06:22 +00:00
document.getElementById("tnc_port").addEventListener("change", () => {
config.tnc_port = document.getElementById("tnc_port").value
config.daemon_port = parseInt(document.getElementById("tnc_port").value) + 1
2021-07-24 07:06:22 +00:00
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
2021-07-17 07:03:40 +00:00
2021-07-24 07:06:22 +00:00
});
2021-07-17 07:03:40 +00:00
2021-07-24 07:06:22 +00:00
// saveMyCall button clicked
document.getElementById("saveMyCall").addEventListener("click", () => {
2021-07-17 07:03:40 +00:00
callsign = document.getElementById("myCall").value
2021-07-23 15:40:44 +00:00
config.mycall = callsign
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
2021-07-17 07:03:40 +00:00
sock.saveMyCall(callsign)
2021-07-24 07:06:22 +00:00
});
// saveMyGrid button clicked
document.getElementById("saveMyGrid").addEventListener("click", () => {
2021-07-17 07:03:40 +00:00
grid = document.getElementById("myGrid").value
2021-07-23 15:40:44 +00:00
config.mygrid = grid
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
2021-07-17 07:03:40 +00:00
sock.saveMyGrid(grid)
2021-07-24 07:06:22 +00:00
2021-07-23 15:40:44 +00:00
});
2021-07-24 07:06:22 +00:00
// startPing button clicked
2021-07-24 07:06:22 +00:00
document.getElementById("sendPing").addEventListener("click", () => {
2021-08-15 14:48:48 +00:00
var dxcallsign = document.getElementById("dxCall").value
sock.sendPing(dxcallsign)
});
// dataModalstartPing button clicked
document.getElementById("dataModalSendPing").addEventListener("click", () => {
var dxcallsign = document.getElementById("dataModalDxCall").value
sock.sendPing(dxcallsign)
2021-07-24 07:06:22 +00:00
});
// sendCQ button clicked
document.getElementById("sendCQ").addEventListener("click", () => {
sock.sendCQ()
});
// startTNC button clicked
document.getElementById("startTNC").addEventListener("click", () => {
2021-07-17 07:03:40 +00:00
var rx_audio = document.getElementById("audio_input_selectbox").value
2021-07-24 07:06:22 +00:00
var tx_audio = document.getElementById("audio_output_selectbox").value
2021-07-17 07:03:40 +00:00
var deviceid = document.getElementById("hamlib_deviceid").value
var deviceport = document.getElementById("hamlib_deviceport").value
2021-07-25 14:35:50 +00:00
var serialspeed = document.getElementById("hamlib_serialspeed").value
2021-07-17 07:03:40 +00:00
var ptt = document.getElementById("hamlib_ptt").value
2021-07-25 16:19:51 +00:00
config.deviceid = deviceid
config.deviceport = deviceport
config.serialspeed = serialspeed
config.ptt = ptt
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
2021-07-25 14:35:50 +00:00
daemon.startTNC(rx_audio, tx_audio, deviceid, deviceport, ptt, serialspeed)
2021-07-24 07:06:22 +00:00
setTimeout(function() {
sock.saveMyCall(config.mycall);
}, 5000);
setTimeout(function() {
sock.saveMyGrid(config.mygrid);
}, 6000);
2021-07-24 07:06:22 +00:00
})
// stopTNC button clicked
document.getElementById("stopTNC").addEventListener("click", () => {
2021-07-17 07:03:40 +00:00
daemon.stopTNC()
2021-07-24 07:06:22 +00:00
})
// openDataModule button clicked
document.getElementById("openDataModule").addEventListener("click", () => {
if(document.getElementById("mySidebar").style.width == "40%"){
document.getElementById("mySidebar").style.width = "0px";
} else {
document.getElementById("mySidebar").style.width = "40%";
}
})
2021-08-11 20:22:55 +00:00
// START TRANSMISSION
2021-08-15 14:48:48 +00:00
document.getElementById("startTransmission").addEventListener("click", () => {
var fileList = document.getElementById("dataModalFile").files;
2021-08-23 14:24:49 +00:00
2021-08-15 14:48:48 +00:00
var reader = new FileReader();
2021-08-16 17:39:20 +00:00
//reader.readAsBinaryString(fileList[0]);
reader.readAsDataURL(fileList[0]);
2021-08-15 14:48:48 +00:00
reader.onload = function(e) {
// binary data
2021-08-23 14:24:49 +00:00
2021-08-16 17:39:20 +00:00
var data = e.target.result
console.log(data)
2021-08-15 14:48:48 +00:00
2021-08-11 20:22:55 +00:00
let Data = {
command: "sendFile",
2021-08-15 14:48:48 +00:00
dxcallsign: document.getElementById("dataModalDxCall").value,
2021-08-11 20:22:55 +00:00
mode: document.getElementById("datamode").value,
frames: document.getElementById("framesperburst").value,
2021-08-15 14:48:48 +00:00
filetype: fileList[0].type,
filename: fileList[0].name,
2021-08-16 17:39:20 +00:00
data: data,
2021-08-11 20:22:55 +00:00
checksum: '123123123',
};
ipcRenderer.send('run-tnc-command', Data);
2021-08-15 14:48:48 +00:00
};
reader.onerror = function(e) {
// error occurred
console.log('Error : ' + e.type);
};
2021-08-11 20:22:55 +00:00
})
2021-08-15 14:48:48 +00:00
2021-08-23 14:24:49 +00:00
2021-08-15 14:48:48 +00:00
2021-07-17 07:03:40 +00:00
})
2021-07-24 07:06:22 +00:00
ipcRenderer.on('action-update-tnc-state', (event, arg) => {
2021-08-08 09:43:50 +00:00
// TOE TIME OF EXECUTION --> How many time needs a command to be executed until data arrives
if (typeof(arg.toe) == 'undefined'){
var toe = 0
} else {
var toe = arg.toe
}
document.getElementById("toe").innerHTML = toe + ' ms'
2021-08-23 13:36:14 +00:00
// DATA STATE
global.rxBufferLengthTnc = arg.rx_buffer_length
2021-08-08 09:43:50 +00:00
2021-08-07 08:54:34 +00:00
// SCATTER DIAGRAM PLOTTING
//global.myChart.destroy();
//console.log(arg.scatter.length)
2021-08-07 08:54:34 +00:00
var data = arg.scatter
var newdata = {
2021-08-07 08:54:34 +00:00
datasets: [{
label: 'constellation diagram',
2021-08-07 08:54:34 +00:00
data: data,
backgroundColor: 'rgb(255, 99, 132)'
}],
};
if (typeof(arg.scatter) == 'undefined'){
var scatterSize = 0
} else {
var scatterSize = arg.scatter.length
}
if (global.data != newdata && scatterSize > 0){
try {
global.myChart.destroy();
} catch (e) {
// myChart not yet created
}
global.data = newdata
2021-08-07 08:54:34 +00:00
var ctx = document.getElementById('scatter').getContext('2d');
global.myChart = new Chart(ctx, {
type: 'scatter',
data: global.data,
2021-08-07 08:54:34 +00:00
options: {
animation: false,
legend: {
2021-08-07 08:54:34 +00:00
display: false,
tooltips: {
enabled: false,
},
},
scales: {
display: false,
grid: {
display: false
},
x: {
type: 'linear',
position: 'bottom',
display: false
},
y: {
display: false
}
}
},
2021-08-07 08:54:34 +00:00
});
}
2021-07-24 07:06:22 +00:00
// PTT STATE
if (arg.ptt_state == 'True') {
document.getElementById("ptt_state").className = "btn btn-danger";
} else if (arg.ptt_state == 'False') {
document.getElementById("ptt_state").className = "btn btn-success";
} else {
document.getElementById("ptt_state").className = "btn btn-secondary"
}
2021-07-17 07:03:40 +00:00
2021-07-24 07:06:22 +00:00
// BUSY STATE
if (arg.busy_state == 'BUSY') {
document.getElementById("busy_state").className = "btn btn-danger";
2021-08-28 16:46:49 +00:00
document.getElementById("startTransmission").disabled = true
2021-07-24 07:06:22 +00:00
} else if (arg.busy_state == 'IDLE') {
document.getElementById("busy_state").className = "btn btn-success";
2021-08-28 16:46:49 +00:00
document.getElementById("startTransmission").disabled = false
2021-07-24 07:06:22 +00:00
} else {
document.getElementById("busy_state").className = "btn btn-secondary"
2021-08-28 16:46:49 +00:00
document.getElementById("startTransmission").disabled = true
2021-07-24 07:06:22 +00:00
}
2021-07-17 07:03:40 +00:00
2021-07-24 07:06:22 +00:00
// ARQ STATE
if (arg.arq_state == 'DATA') {
document.getElementById("arq_state").className = "btn btn-warning";
} else if (arg.arq_state == 'IDLE') {
document.getElementById("arq_state").className = "btn btn-secondary";
} else {
document.getElementById("arq_state").className = "btn btn-secondary"
}
2021-07-17 07:03:40 +00:00
2021-07-24 07:06:22 +00:00
// RMS
document.getElementById("rms_level").setAttribute("aria-valuenow", arg.rms_level)
document.getElementById("rms_level").setAttribute("style", "width:" + arg.rms_level + "%;")
2021-08-07 08:54:34 +00:00
2021-08-08 09:43:50 +00:00
2021-07-24 07:06:22 +00:00
// CHANNEL STATE
if (arg.channel_state == 'RECEIVING_SIGNALLING') {
document.getElementById("signalling_state").className = "btn btn-success";
document.getElementById("data_state").className = "btn btn-secondary";
2021-07-17 07:03:40 +00:00
2021-07-24 07:06:22 +00:00
} else if (arg.channel_state == 'SENDING_SIGNALLING') {
document.getElementById("signalling_state").className = "btn btn-danger";
document.getElementById("data_state").className = "btn btn-secondary";
2021-07-17 07:03:40 +00:00
2021-07-24 07:06:22 +00:00
} else if (arg.channel_state == 'RECEIVING_DATA') {
document.getElementById("signalling_state").className = "btn btn-secondary";
document.getElementById("data_state").className = "btn btn-success";
} else if (arg.channel_state == 'SENDING_DATA') {
document.getElementById("signalling_state").className = "btn btn-secondary";
document.getElementById("data_state").className = "btn btn-danger";
} else {
document.getElementById("signalling_state").className = "btn btn-secondary"
document.getElementById("busy_state").className = "btn btn-secondary"
}
// SET FREQUENCY
document.getElementById("frequency").innerHTML = arg.frequency
2021-07-24 07:06:22 +00:00
// SET MODE
document.getElementById("mode").innerHTML = arg.mode
2021-07-24 07:06:22 +00:00
// SET BANDWITH
document.getElementById("bandwith").innerHTML = arg.bandwith
2021-08-07 18:57:36 +00:00
2021-08-15 14:48:48 +00:00
// SET BYTES PER MINUTE
if (typeof(arg.arq_bytes_per_minute) == 'undefined'){
var arq_bytes_per_minute = 0
} else {
var arq_bytes_per_minute = arg.arq_bytes_per_minute
}
document.getElementById("bytes_per_min").innerHTML = arq_bytes_per_minute
// SET TOTAL BYTES
if (typeof(arg.total_bytes) == 'undefined'){
var total_bytes = 0
} else {
var total_bytes = arg.total_bytes
}
document.getElementById("total_bytes").innerHTML = total_bytes
2021-08-28 16:46:49 +00:00
document.getElementById("transmission_progress").setAttribute("aria-valuenow", arg.arq_transmission_percent)
document.getElementById("transmission_progress").setAttribute("style", "width:" + arg.arq_transmission_percent + "%;")
2021-08-07 18:57:36 +00:00
2021-08-15 14:48:48 +00:00
// UPDATE HEARD STATIONS
2021-08-07 18:57:36 +00:00
var tbl = document.getElementById("heardstations");
document.getElementById("heardstations").innerHTML = ''
2021-08-08 09:09:18 +00:00
if (typeof(arg.stations) == 'undefined'){
var heardStationsLength = 0
} else {
var heardStationsLength = arg.stations.length
}
for (i = 0; i < heardStationsLength; i++) {
2021-08-07 18:57:36 +00:00
// first we update the PING window
console.log(document.getElementById("dxCall").value)
if (arg.stations[i]['DXCALLSIGN'] == document.getElementById("dxCall").value) {
2021-08-08 17:29:18 +00:00
var dxGrid = arg.stations[i]['DXGRID']
var myGrid = document.getElementById("myGrid").value
2021-08-23 13:36:14 +00:00
try {
var dist = parseInt(distance(myGrid, dxGrid)) + ' km';
document.getElementById("pingDistance").innerHTML = dist
document.getElementById("dataModalPingDistance").innerHTML = dist
2021-08-08 17:29:18 +00:00
} catch {
2021-08-23 13:36:14 +00:00
document.getElementById("pingDistance").innerHTML = '---'
document.getElementById("dataModalPingDistance").innerHTML = '---'
2021-08-08 17:29:18 +00:00
}
2021-08-23 13:36:14 +00:00
document.getElementById("pingDB").innerHTML = arg.stations[i]['SNR']
document.getElementById("dataModalPingDB").innerHTML = arg.stations[i]['SNR']
2021-08-07 18:57:36 +00:00
}
// now we update the heard stations list
var row = document.createElement("tr");
//https://stackoverflow.com/q/51421470
//https://stackoverflow.com/a/847196
timestampRaw = arg.stations[i]['TIMESTAMP']
var date = new Date(timestampRaw * 1000);
var hours = date.getHours();
var minutes = "0" + date.getMinutes();
var seconds = "0" + date.getSeconds();
var datetime = hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
var timestamp = document.createElement("td");
var timestampText = document.createElement('span');
timestampText.innerText = datetime
timestamp.appendChild(timestampText);
var dxCall = document.createElement("td");
var dxCallText = document.createElement('span');
dxCallText.innerText = arg.stations[i]['DXCALLSIGN']
dxCall.appendChild(dxCallText);
var dxGrid = document.createElement("td");
var dxGridText = document.createElement('span');
dxGridText.innerText = arg.stations[i]['DXGRID']
dxGrid.appendChild(dxGridText);
2021-08-08 17:29:18 +00:00
var gridDistance = document.createElement("td");
var gridDistanceText = document.createElement('span');
try{
gridDistanceText.innerText = parseInt(distance(document.getElementById("myGrid").value, arg.stations[i]['DXGRID'])) + ' km';
} catch {
2021-08-23 13:36:14 +00:00
gridDistanceText.innerText = '---'
2021-08-08 17:29:18 +00:00
}
gridDistance.appendChild(gridDistanceText);
2021-08-07 18:57:36 +00:00
var dataType = document.createElement("td");
var dataTypeText = document.createElement('span');
dataTypeText.innerText = arg.stations[i]['DATATYPE']
dataType.appendChild(dataTypeText);
2021-08-16 17:39:20 +00:00
2021-08-07 18:57:36 +00:00
if(dataTypeText.innerText == 'CQ CQ CQ'){
row.classList.add("table-success");
}
if(dataTypeText.innerText == 'DATA-CHANNEL'){
row.classList.add("table-warning");
}
if(dataTypeText.innerText == 'BEACON'){
row.classList.add("table-light");
}
if(dataTypeText.innerText == 'PING'){
row.classList.add("table-info");
}
if(dataTypeText.innerText == 'PING-ACK'){
row.classList.add("table-primary");
}
var snr = document.createElement("td");
var snrText = document.createElement('span');
snrText.innerText = arg.stations[i]['SNR']
snr.appendChild(snrText);
2021-08-08 17:29:18 +00:00
2021-08-07 18:57:36 +00:00
row.appendChild(timestamp);
row.appendChild(dxCall);
row.appendChild(dxGrid);
2021-08-08 17:29:18 +00:00
row.appendChild(gridDistance);
2021-08-07 18:57:36 +00:00
row.appendChild(dataType);
row.appendChild(snr);
tbl.appendChild(row);
}
2021-08-23 13:36:14 +00:00
2021-07-24 07:06:22 +00:00
});
2021-07-17 07:03:40 +00:00
ipcRenderer.on('action-update-daemon-state', (event, arg) => {
2021-07-25 14:18:29 +00:00
// RAM
document.getElementById("progressbar_ram").setAttribute("aria-valuenow", arg.ram_usage)
document.getElementById("progressbar_ram").setAttribute("style", "width:" + arg.ram_usage + "%;")
document.getElementById("progressbar_ram_value").innerHTML = arg.ram_usage + "%"
2021-08-07 08:54:34 +00:00
2021-07-25 14:18:29 +00:00
// CPU
document.getElementById("progressbar_cpu").setAttribute("aria-valuenow", arg.cpu_usage)
document.getElementById("progressbar_cpu").setAttribute("style", "width:" + arg.cpu_usage + "%;")
document.getElementById("progressbar_cpu_value").innerHTML = arg.cpu_usage + "%"
2021-08-07 08:54:34 +00:00
2021-07-24 07:06:22 +00:00
// UPDATE AUDIO INPUT
2021-07-17 07:03:40 +00:00
2021-07-24 07:06:22 +00:00
if (document.getElementById("audio_input_selectbox").length != arg.input_devices.length) {
2021-07-17 07:03:40 +00:00
document.getElementById("audio_input_selectbox").innerHTML = ""
2021-07-24 07:06:22 +00:00
for (i = 0; i < arg.input_devices.length; i++) {
2021-07-17 07:03:40 +00:00
var option = document.createElement("option");
option.text = arg.input_devices[i]['NAME'];
option.value = arg.input_devices[i]['ID'];
document.getElementById("audio_input_selectbox").add(option);
}
}
// UPDATE AUDIO OUTPUT
2021-07-24 07:06:22 +00:00
if (document.getElementById("audio_output_selectbox").length != arg.output_devices.length) {
2021-07-17 07:03:40 +00:00
document.getElementById("audio_output_selectbox").innerHTML = ""
2021-07-24 07:06:22 +00:00
for (i = 0; i < arg.output_devices.length; i++) {
2021-07-17 07:03:40 +00:00
var option = document.createElement("option");
option.text = arg.output_devices[i]['NAME'];
option.value = arg.output_devices[i]['ID'];
document.getElementById("audio_output_selectbox").add(option);
}
}
2021-07-24 07:06:22 +00:00
// TNC RUNNING STATE
document.getElementById("tnc_running_state").innerHTML = arg.tnc_running_state;
if (arg.tnc_running_state == "running") {
document.getElementById('hamlib_deviceid').disabled = true
document.getElementById('hamlib_deviceport').disabled = true
document.getElementById('hamlib_ptt').disabled = true
document.getElementById('audio_input_selectbox').disabled = true
document.getElementById('audio_output_selectbox').disabled = true
document.getElementById('stopTNC').disabled = false
document.getElementById('startTNC').disabled = true
document.getElementById('myCall').disabled = false
2021-07-26 16:09:04 +00:00
document.getElementById('dxCall').disabled = false
2021-07-24 07:06:22 +00:00
document.getElementById('saveMyCall').disabled = false
document.getElementById('myGrid').disabled = false
document.getElementById('saveMyGrid').disabled = false
2021-08-07 08:54:34 +00:00
document.getElementById("hamlib_serialspeed").disabled = true
2021-08-28 16:46:49 +00:00
document.getElementById("startTransmission").disabled = false
2021-07-24 07:06:22 +00:00
2021-07-17 07:03:40 +00:00
} else {
2021-07-24 07:06:22 +00:00
document.getElementById('hamlib_deviceid').disabled = false
document.getElementById('hamlib_deviceport').disabled = false
document.getElementById('hamlib_ptt').disabled = false
document.getElementById('audio_input_selectbox').disabled = false
document.getElementById('audio_output_selectbox').disabled = false
document.getElementById('stopTNC').disabled = true
document.getElementById('startTNC').disabled = false
document.getElementById('myCall').disabled = true
2021-07-26 16:09:04 +00:00
document.getElementById('dxCall').disabled = true
2021-07-24 07:06:22 +00:00
document.getElementById('saveMyCall').disabled = true
document.getElementById('myGrid').disabled = true
document.getElementById('saveMyGrid').disabled = true
2021-08-07 08:54:34 +00:00
document.getElementById("hamlib_serialspeed").disabled = false
2021-08-28 16:46:49 +00:00
document.getElementById("startTransmission").disabled = true
2021-07-25 14:35:50 +00:00
2021-07-17 07:03:40 +00:00
}
2021-07-24 07:06:22 +00:00
});
2021-07-17 07:03:40 +00:00
ipcRenderer.on('action-update-daemon-connection', (event, arg) => {
2021-07-24 07:06:22 +00:00
if (arg.daemon_connection == 'open') {
document.getElementById("daemon_connection_state").className = "btn btn-success";
2021-08-28 16:46:49 +00:00
document.getElementById("blurdiv").style.webkitFilter = "blur(0px)";
}
2021-07-24 07:06:22 +00:00
if (arg.daemon_connection == 'opening') {
document.getElementById("daemon_connection_state").className = "btn btn-warning";
2021-08-28 16:46:49 +00:00
document.getElementById("blurdiv").style.webkitFilter = "blur(10px)";
2021-07-24 07:06:22 +00:00
}
if (arg.daemon_connection == 'closed') {
document.getElementById("daemon_connection_state").className = "btn btn-danger";
2021-08-28 16:46:49 +00:00
document.getElementById("blurdiv").style.webkitFilter = "blur(10px)";
}
2021-07-24 07:06:22 +00:00
});
2021-08-07 18:57:36 +00:00
2021-08-22 15:00:18 +00:00
ipcRenderer.on('action-update-rx-buffer', (event, arg) => {
var data = arg.data["DATA"]
var tbl = document.getElementById("rx-data");
document.getElementById("rx-data").innerHTML = ''
2021-08-22 15:32:56 +00:00
2021-08-23 14:24:49 +00:00
for (i = 0; i < arg.data.length; i++) {
2021-08-22 15:32:56 +00:00
2021-08-07 08:54:34 +00:00
// first we update the PING window
2021-08-22 15:00:18 +00:00
if (arg.data[i]['DXCALLSIGN'] == document.getElementById("dxCall").value) {
2021-08-07 08:54:34 +00:00
document.getElementById("pingDistance").innerHTML = arg.stations[i]['DXGRID']
document.getElementById("pingDB").innerHTML = arg.stations[i]['SNR']
2021-07-28 16:44:10 +00:00
2021-08-07 08:54:34 +00:00
}
2021-07-28 16:44:10 +00:00
2021-08-07 08:54:34 +00:00
// now we update the heard stations list
2021-08-07 08:54:34 +00:00
var row = document.createElement("tr");
//https://stackoverflow.com/q/51421470
2021-07-25 16:19:51 +00:00
2021-08-07 08:54:34 +00:00
//https://stackoverflow.com/a/847196
2021-08-22 15:00:18 +00:00
timestampRaw = arg.data[i]['TIMESTAMP']
2021-08-07 08:54:34 +00:00
var date = new Date(timestampRaw * 1000);
var hours = date.getHours();
var minutes = "0" + date.getMinutes();
var seconds = "0" + date.getSeconds();
var datetime = hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
2021-07-25 16:19:51 +00:00
2021-08-07 08:54:34 +00:00
var timestamp = document.createElement("td");
var timestampText = document.createElement('span');
timestampText.innerText = datetime
timestamp.appendChild(timestampText);
2021-07-25 16:19:51 +00:00
2021-08-07 08:54:34 +00:00
var dxCall = document.createElement("td");
var dxCallText = document.createElement('span');
2021-08-22 15:00:18 +00:00
dxCallText.innerText = arg.data[i]['DXCALLSIGN']
2021-08-07 08:54:34 +00:00
dxCall.appendChild(dxCallText);
2021-07-25 16:19:51 +00:00
2021-08-22 15:23:36 +00:00
/*
2021-08-07 08:54:34 +00:00
var dxGrid = document.createElement("td");
var dxGridText = document.createElement('span');
2021-08-22 15:00:18 +00:00
dxGridText.innerText = arg.data[i]['DXGRID']
2021-08-07 08:54:34 +00:00
dxGrid.appendChild(dxGridText);
2021-08-22 15:00:18 +00:00
*/
2021-08-07 08:54:34 +00:00
2021-08-22 15:23:36 +00:00
var fileName = document.createElement("td");
var fileNameText = document.createElement('span');
2021-08-22 15:32:56 +00:00
fileNameText.innerText = arg.data[i]['RXDATA'][0]['filename']
2021-08-22 15:23:36 +00:00
fileName.appendChild(fileNameText);
2021-08-07 08:54:34 +00:00
row.appendChild(timestamp);
row.appendChild(dxCall);
2021-08-22 15:23:36 +00:00
// row.appendChild(dxGrid);
row.appendChild(fileName);
2021-08-07 08:54:34 +00:00
tbl.appendChild(row);
2021-08-22 15:23:36 +00:00
2021-08-22 16:04:49 +00:00
// Creates rxdata folder if not exists
2021-08-23 13:36:14 +00:00
// https://stackoverflow.com/a/13544465
fs.mkdir('rxdata', { recursive: true }, function(err) {
console.log(err);
2021-08-22 16:04:49 +00:00
});
2021-08-23 13:36:14 +00:00
// write file to rxdata folder
var base64String = arg.data[i]['RXDATA'][0]['data']
2021-08-23 13:36:14 +00:00
// remove header from base64 String
// https://www.codeblocq.com/2016/04/Convert-a-base64-string-to-a-file-in-Node/
var base64Data = base64String.split(';base64,').pop()
//write data to file
2021-08-22 16:04:49 +00:00
require("fs").writeFile('rxdata/' + arg.data[i]['RXDATA'][0]['filename'], base64Data, 'base64', function(err) {
console.log(err);
2021-08-23 13:36:14 +00:00
});
2021-08-07 08:54:34 +00:00
}
});
2021-08-22 15:00:18 +00:00
2021-07-25 16:19:51 +00:00
2021-07-24 07:06:22 +00:00
ipcRenderer.on('run-tnc-command', (event, arg) => {
if (arg.command == 'saveMyCall') {
sock.saveMyCall(arg.callsign)
}
2021-07-24 07:06:22 +00:00
if (arg.command == 'saveMyGrid') {
sock.saveMyGrid(arg.grid)
}
2021-07-24 07:06:22 +00:00
if (arg.command == 'ping') {
sock.sendPing(arg.dxcallsign)
}
2021-08-07 08:54:34 +00:00
if (arg.command == 'sendFile') {
2021-07-26 16:09:04 +00:00
sock.sendFile(arg.dxcallsign, arg.mode, arg.frames, arg.filename, arg.filetype, arg.data, arg.checksum)
}
2021-08-07 08:54:34 +00:00
if (arg.command == 'sendMessage') {
2021-07-26 16:09:04 +00:00
sock.sendMessage(arg.dxcallsign, arg.mode, arg.frames, arg.data, arg.checksum)
2021-08-07 08:54:34 +00:00
}
2021-08-22 15:32:56 +00:00
});