mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
code cleanup
This commit is contained in:
parent
19cd2959c9
commit
da535d6636
|
@ -5,7 +5,9 @@ var config = require('./config.json');
|
|||
var daemon = new net.Socket();
|
||||
var msg = ''; // Current message, per connection.
|
||||
|
||||
const { ipcRenderer } = require('electron');
|
||||
const {
|
||||
ipcRenderer
|
||||
} = require('electron');
|
||||
|
||||
|
||||
setTimeout(connectDAEMON, 500)
|
||||
|
@ -16,12 +18,6 @@ function connectDAEMON(){
|
|||
|
||||
//clear message buffer after reconnecting or inital connection
|
||||
msg = '';
|
||||
|
||||
//daemon_host = document.getElementById("daemon_adress").value
|
||||
//daemon_port = document.getElementById("daemon_port").value
|
||||
//daemon_host = '192.168.178.163'
|
||||
//daemon_port = 3001
|
||||
|
||||
daemon.connect(config.daemon_port, config.daemon_host)
|
||||
//client.setTimeout(5000);
|
||||
}
|
||||
|
@ -75,8 +71,6 @@ writeDaemonCommand = function(command){
|
|||
ipcRenderer.send('request-update-daemon-connection', Data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// "https://stackoverflow.com/questions/9070700/nodejs-net-createserver-large-amount-of-data-coming-in"
|
||||
|
||||
|
||||
|
@ -108,21 +102,8 @@ daemon.on('data', function(data) {
|
|||
};
|
||||
ipcRenderer.send('request-update-daemon-state', Data);
|
||||
|
||||
|
||||
//input_devices = data['INPUT_DEVICES']
|
||||
//uiMain.updateAudioInput(input_devices)
|
||||
|
||||
//output_devices = data['OUTPUT_DEVICES']
|
||||
//uiMain.updateAudioOutput(output_devices)
|
||||
|
||||
//daemon_state = data['DAEMON_STATE'][0]['STATUS']
|
||||
//uiMain.updateTncRunningState(daemon_state)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////// check if EOF ...
|
||||
}
|
||||
|
||||
|
@ -136,11 +117,6 @@ function hexToBytes(hex) {
|
|||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
exports.getDaemonState = function() {
|
||||
//function getDaemonState(){
|
||||
command = '{"type" : "GET", "command": "DAEMON_STATE"}'
|
||||
|
@ -150,14 +126,6 @@ function hexToBytes(hex) {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// START TNC
|
||||
// ` `== multi line string
|
||||
|
||||
|
@ -188,9 +156,3 @@ exports.stopTNC = function(){
|
|||
command = '{"type" : "SET", "command": "STOPTNC" , "parameter": "---" }'
|
||||
writeDaemonCommand(command)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
89
gui/main.js
89
gui/main.js
|
@ -2,23 +2,13 @@ const { app, BrowserWindow, ipcMain } = require('electron')
|
|||
const path = require('path')
|
||||
var config = require('./config.json');
|
||||
|
||||
|
||||
|
||||
|
||||
let win = null;
|
||||
let data = null;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function createWindow() {
|
||||
|
||||
|
||||
win = new BrowserWindow({
|
||||
width: 1220,
|
||||
height: 900,
|
||||
height: 920,
|
||||
webPreferences: {
|
||||
//preload: path.join(__dirname, 'preload-main.js'),
|
||||
preload: require.resolve('./preload-main.js'),
|
||||
|
@ -33,9 +23,6 @@ function createWindow () {
|
|||
activate: true,
|
||||
})
|
||||
win.loadFile('src/index.html')
|
||||
|
||||
|
||||
|
||||
data = new BrowserWindow({
|
||||
height: 900,
|
||||
width: 600,
|
||||
|
@ -55,11 +42,6 @@ function createWindow () {
|
|||
data.hide()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Emitted when the window is closed.
|
||||
win.on('closed', function() {
|
||||
// Dereference the window object, usually you would store windows
|
||||
|
@ -83,23 +65,9 @@ data.on('close', function (evt) {
|
|||
evt.preventDefault();
|
||||
data.hide()
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
app.whenReady().then(() => {
|
||||
createWindow()
|
||||
|
||||
|
@ -118,22 +86,11 @@ app.on('window-all-closed', () => {
|
|||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// IPC HANDLER
|
||||
ipcMain.on('show-data-window', (event, arg) => {
|
||||
data.show()
|
||||
});
|
||||
|
||||
|
||||
ipcMain.on('request-update-tnc-state', (event, arg) => {
|
||||
win.webContents.send('action-update-tnc-state', arg);
|
||||
data.webContents.send('action-update-tnc-state', arg);
|
||||
|
@ -158,49 +115,5 @@ ipcMain.on('request-update-daemon-connection', (event, arg) => {
|
|||
|
||||
ipcMain.on('run-tnc-command', (event, arg) => {
|
||||
win.webContents.send('run-tnc-command', arg);
|
||||
|
||||
/*
|
||||
if (arg.command == 'saveMyCall'){
|
||||
sock.saveMyCall(arg.callsign)
|
||||
}
|
||||
if (arg.command == 'saveMyGrid'){
|
||||
sock.saveMyGrid(arg.grid)
|
||||
}
|
||||
if (arg.command == 'ping'){
|
||||
sock.sendPing(arg.dxcallsign)
|
||||
}
|
||||
*/
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
ipcMain.on('run-daemon-command', (event, arg) => {
|
||||
win.webContents.send('run-daemon-command', arg);
|
||||
*/
|
||||
/*
|
||||
if (arg.command == 'startTNC'){
|
||||
daemon.startTNC(arg.rx_audio, arg.tx_audio, arg.deviceid, arg.deviceport, arg.ptt)
|
||||
|
||||
}
|
||||
if (arg.command == 'stopTNC'){
|
||||
daemon.stopTNC()
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
*/
|
||||
|
||||
|
||||
//setInterval(sock.getTncState, 500)
|
||||
//setInterval(daemon.getDaemonState, 500)
|
||||
/*
|
||||
setInterval(function(){
|
||||
sock.getTncState();
|
||||
}, 1000);
|
||||
*/
|
||||
/*
|
||||
setInterval(function(){
|
||||
daemon.getDaemonState();
|
||||
}, 1000);
|
||||
*/
|
||||
|
|
@ -1,12 +1,8 @@
|
|||
|
||||
const { ipcRenderer } = require('electron');
|
||||
const {
|
||||
ipcRenderer
|
||||
} = require('electron');
|
||||
var config = require('./config.json');
|
||||
|
||||
//const sock = require('./sock.js')
|
||||
//const globals = require('./globals.js')
|
||||
|
||||
|
||||
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
const replaceText = (selector, text) => {
|
||||
const element = document.getElementById(selector)
|
||||
|
@ -30,9 +26,6 @@ window.addEventListener('DOMContentLoaded', () => {
|
|||
alert("HALLO ")
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
|
|
@ -2,19 +2,12 @@ const sock = require('./sock.js')
|
|||
const daemon = require('./daemon.js')
|
||||
const configPath = './config.json'
|
||||
const config = require(configPath);
|
||||
const { ipcRenderer } = require('electron');
|
||||
const {
|
||||
ipcRenderer
|
||||
} = require('electron');
|
||||
const fs = require('fs');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// START INTERVALL COMMAND EXECUTION FOR STATES
|
||||
setInterval(daemon.getDaemonState, 1000)
|
||||
setInterval(sock.getTncState, 250)
|
||||
|
@ -22,25 +15,17 @@ setInterval(sock.getDataState, 500)
|
|||
setInterval(sock.getHeardStations, 500)
|
||||
|
||||
|
||||
|
||||
// UPDATE FFT DEMO
|
||||
|
||||
updateFFT = function(fft) {
|
||||
var fft = Array.from({length: 2048}, () => Math.floor(Math.random() * 10));
|
||||
var fft = Array.from({
|
||||
length: 2048
|
||||
}, () => Math.floor(Math.random() * 10));
|
||||
spectrum.addData(fft);
|
||||
}
|
||||
setInterval(updateFFT, 250)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// WINDOW LISTENER
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
// LOAD SETTINGS
|
||||
document.getElementById("tnc_adress").value = config.tnc_host
|
||||
|
@ -48,9 +33,6 @@ document.getElementById("tnc_port").value = config.tnc_port
|
|||
document.getElementById("myCall").value = config.mycall
|
||||
document.getElementById("myGrid").value = config.mygrid
|
||||
|
||||
|
||||
|
||||
|
||||
// Create spectrum object on canvas with ID "waterfall"
|
||||
global.spectrum = new Spectrum(
|
||||
"waterfall", {
|
||||
|
@ -75,29 +57,12 @@ document.getElementById("myGrid").value = config.mygrid
|
|||
|
||||
});
|
||||
|
||||
|
||||
// tnc_host = document.getElementById("tnc_adress").value
|
||||
//tnc_port = document.getElementById("tnc_port").value
|
||||
|
||||
|
||||
|
||||
// saveMyCall button clicked
|
||||
document.getElementById("saveMyCall").addEventListener("click", () => {
|
||||
callsign = document.getElementById("myCall").value
|
||||
config.mycall = callsign
|
||||
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
||||
|
||||
sock.saveMyCall(callsign)
|
||||
/*
|
||||
let Data = {
|
||||
command: "saveMyCall",
|
||||
callsign: document.getElementById("myCall").value
|
||||
};
|
||||
ipcRenderer.send('run-tnc-command', Data);
|
||||
|
||||
*/
|
||||
|
||||
|
||||
});
|
||||
|
||||
// saveMyGrid button clicked
|
||||
|
@ -105,46 +70,21 @@ document.getElementById("myGrid").value = config.mygrid
|
|||
grid = document.getElementById("myGrid").value
|
||||
config.mygrid = grid
|
||||
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
||||
|
||||
sock.saveMyGrid(grid)
|
||||
/*
|
||||
let Data = {
|
||||
command: "saveMyGrid",
|
||||
grid: document.getElementById("myGrid").value
|
||||
};
|
||||
ipcRenderer.send('run-tnc-command', Data);
|
||||
*/
|
||||
|
||||
});
|
||||
|
||||
// startPing button clicked
|
||||
document.getElementById("sendPing").addEventListener("click", () => {
|
||||
dxcallsign = document.getElementById("dxCall").value
|
||||
sock.sendPing(dxcallsign)
|
||||
/*
|
||||
let Data = {
|
||||
command: "saveMyCall",
|
||||
callsign: document.getElementById("myCall").value
|
||||
};
|
||||
ipcRenderer.send('run-tnc-command', Data);
|
||||
|
||||
*/
|
||||
|
||||
|
||||
});
|
||||
|
||||
// sendCQ button clicked
|
||||
document.getElementById("sendCQ").addEventListener("click", () => {
|
||||
sock.sendCQ()
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// startTNC button clicked
|
||||
document.getElementById("startTNC").addEventListener("click", () => {
|
||||
var rx_audio = document.getElementById("audio_input_selectbox").value
|
||||
|
@ -154,32 +94,17 @@ document.getElementById("myGrid").value = config.mygrid
|
|||
var ptt = document.getElementById("hamlib_ptt").value
|
||||
|
||||
daemon.startTNC(rx_audio, tx_audio, deviceid, deviceport, ptt)
|
||||
setTimeout( function() { sock.saveMyCall(config.mycall); }, 5000 );
|
||||
setTimeout( function() { sock.saveMyGrid(config.mygrid); }, 5000 );
|
||||
|
||||
/*
|
||||
let Data = {
|
||||
command: "startTNC",
|
||||
rx_audio : document.getElementById("audio_input_selectbox").value,
|
||||
tx_audio : document.getElementById("audio_output_selectbox").value,
|
||||
deviceid : document.getElementById("hamlib_deviceid").value,
|
||||
deviceport : document.getElementById("hamlib_deviceport").value,
|
||||
ptt : document.getElementById("hamlib_ptt").value,
|
||||
};
|
||||
ipcRenderer.send('run-daemon-command', Data);
|
||||
*/
|
||||
|
||||
|
||||
setTimeout(function() {
|
||||
sock.saveMyCall(config.mycall);
|
||||
}, 5000);
|
||||
setTimeout(function() {
|
||||
sock.saveMyGrid(config.mygrid);
|
||||
}, 5000);
|
||||
})
|
||||
|
||||
// stopTNC button clicked
|
||||
document.getElementById("stopTNC").addEventListener("click", () => {
|
||||
daemon.stopTNC()
|
||||
/* let Data = {
|
||||
command: "stopTNC",
|
||||
};
|
||||
ipcRenderer.send('run-daemon-command', Data);
|
||||
*/
|
||||
})
|
||||
|
||||
// openDataModule button clicked
|
||||
|
@ -190,20 +115,8 @@ document.getElementById("myGrid").value = config.mygrid
|
|||
};
|
||||
ipcRenderer.send('show-data-window', Data);
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ipcRenderer.on('action-update-tnc-state', (event, arg) => {
|
||||
|
||||
// PTT STATE
|
||||
|
@ -328,13 +241,11 @@ document.getElementById("tnc_running_state").innerHTML = arg.tnc_running_state;
|
|||
document.getElementById('saveMyGrid').disabled = true
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
ipcRenderer.on('action-update-daemon-connection', (event, arg) => {
|
||||
|
||||
|
||||
if (arg.daemon_connection == 'open') {
|
||||
document.getElementById("daemon_connection_state").className = "btn btn-success";
|
||||
}
|
||||
|
@ -348,9 +259,6 @@ ipcRenderer.on('action-update-daemon-connection', (event, arg) => {
|
|||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ipcRenderer.on('run-tnc-command', (event, arg) => {
|
||||
if (arg.command == 'saveMyCall') {
|
||||
sock.saveMyCall(arg.callsign)
|
||||
|
@ -362,21 +270,3 @@ ipcRenderer.on('action-update-daemon-connection', (event, arg) => {
|
|||
sock.sendPing(arg.dxcallsign)
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
ipcRenderer.on('run-daemon-command', (event, arg) => {
|
||||
if (arg.command == 'startTNC'){
|
||||
daemon.startTNC(arg.rx_audio, arg.tx_audio, arg.deviceid, arg.deviceport, arg.ptt)
|
||||
|
||||
}
|
||||
if (arg.command == 'stopTNC'){
|
||||
daemon.stopTNC()
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
41
gui/sock.js
41
gui/sock.js
|
@ -1,31 +1,21 @@
|
|||
var net = require('net');
|
||||
var config = require('./config.json');
|
||||
const {
|
||||
ipcRenderer
|
||||
} = require('electron');
|
||||
|
||||
const { ipcRenderer } = require('electron');
|
||||
|
||||
//var client = new net.Socket();
|
||||
var client = new net.Socket();
|
||||
var msg = ''; // Current message, per connection.
|
||||
|
||||
setTimeout(connectTNC, 3000)
|
||||
|
||||
|
||||
|
||||
|
||||
function connectTNC() {
|
||||
//exports.connectTNC = function(){
|
||||
|
||||
console.log('connecting to TNC...')
|
||||
|
||||
//clear message buffer after reconnecting or inital connection
|
||||
msg = '';
|
||||
|
||||
console.log(exports)
|
||||
|
||||
//tnc_host = '192.168.178.163'
|
||||
//tnc_port = 3000
|
||||
client.connect(config.tnc_port, config.tnc_host)
|
||||
//client.setTimeout(5000);
|
||||
}
|
||||
|
||||
client.on('connect', function(data) {
|
||||
|
@ -89,7 +79,6 @@ client.on('end', function(data) {
|
|||
if (client.readyState == 'opening') {
|
||||
//uiMain.setTNCconnection('opening')
|
||||
console.log("OPENING!!!!!")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,22 +93,6 @@ stackoverflow.com questions 9070700 nodejs-net-createserver-large-amount-of-data
|
|||
data = data.toString('utf8'); // convert data to string
|
||||
msg += data.toString('utf8'); // append data to buffer so we can stick long data together
|
||||
|
||||
/*
|
||||
if (msg.charCodeAt(msg.length - 1) == 0) {
|
||||
client.emit('message', msg.substring(0, msg.length - 1));
|
||||
msg = '';
|
||||
console.log("END OF FILE")
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
if (msg.startsWith('{"COMMAND":')) {
|
||||
msg = '';
|
||||
msg += data.toString('utf8');
|
||||
console.log("BOF detected!")
|
||||
}
|
||||
*/
|
||||
|
||||
// check if we reached an EOF, if true, clear buffer and parse JSON data
|
||||
if (data.endsWith('}')) {
|
||||
//console.log(msg)
|
||||
|
@ -133,9 +106,6 @@ stackoverflow.com questions 9070700 nodejs-net-createserver-large-amount-of-data
|
|||
/* console.log("EOF detected!") */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (data['COMMAND'] == 'TNC_STATE') {
|
||||
let Data = {
|
||||
ptt_state: data['PTT_STATE'],
|
||||
|
@ -179,7 +149,6 @@ stackoverflow.com questions 9070700 nodejs-net-createserver-large-amount-of-data
|
|||
}
|
||||
|
||||
|
||||
|
||||
// check if EOF ...
|
||||
}
|
||||
|
||||
|
@ -196,10 +165,6 @@ function hexToBytes(hex) {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//Save myCall
|
||||
exports.saveMyCall = function(callsign) {
|
||||
command = '{"type" : "SET", "command": "MYCALLSIGN" , "parameter": "' + callsign + '" }'
|
||||
|
|
Loading…
Reference in a new issue