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
200
gui/daemon.js
200
gui/daemon.js
|
@ -5,33 +5,29 @@ var config = require('./config.json');
|
||||||
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');
|
const {
|
||||||
|
ipcRenderer
|
||||||
|
} = require('electron');
|
||||||
|
|
||||||
|
|
||||||
setTimeout(connectDAEMON, 500)
|
setTimeout(connectDAEMON, 500)
|
||||||
|
|
||||||
function connectDAEMON(){
|
function connectDAEMON() {
|
||||||
|
|
||||||
console.log('connecting to DAEMON...')
|
console.log('connecting to DAEMON...')
|
||||||
|
|
||||||
//clear message buffer after reconnecting or inital connection
|
//clear message buffer after reconnecting or inital connection
|
||||||
msg = '';
|
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)
|
daemon.connect(config.daemon_port, config.daemon_host)
|
||||||
//client.setTimeout(5000);
|
//client.setTimeout(5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
daemon.on('connect', function(data) {
|
daemon.on('connect', function(data) {
|
||||||
console.log('DAEMON connection established')
|
console.log('DAEMON connection established')
|
||||||
})
|
})
|
||||||
|
|
||||||
daemon.on('error', function(data) {
|
daemon.on('error', function(data) {
|
||||||
console.log('DAEMON connection error');
|
console.log('DAEMON connection error');
|
||||||
setTimeout(connectDAEMON, 2000)
|
setTimeout(connectDAEMON, 2000)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -43,154 +39,120 @@ client.on('close', function(data) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
daemon.on('end', function(data) {
|
daemon.on('end', function(data) {
|
||||||
console.log('DAEMON connection ended');
|
console.log('DAEMON connection ended');
|
||||||
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') {
|
||||||
//uiMain.setDAEMONconnection('open')
|
//uiMain.setDAEMONconnection('open')
|
||||||
console.log(command)
|
console.log(command)
|
||||||
daemon.write(command + '\n');
|
daemon.write(command + '\n');
|
||||||
}
|
|
||||||
|
|
||||||
if(daemon.readyState == 'closed'){
|
|
||||||
//uiMain.setDAEMONconnection('closed')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(daemon.readyState == 'opening'){
|
if (daemon.readyState == 'closed') {
|
||||||
//uiMain.setDAEMONconnection('opening')
|
//uiMain.setDAEMONconnection('closed')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (daemon.readyState == 'opening') {
|
||||||
|
//uiMain.setDAEMONconnection('opening')
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
let Data = {
|
let Data = {
|
||||||
daemon_connection: daemon.readyState,
|
daemon_connection: daemon.readyState,
|
||||||
};
|
};
|
||||||
ipcRenderer.send('request-update-daemon-connection', Data);
|
ipcRenderer.send('request-update-daemon-connection', Data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// "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)*/
|
||||||
try {
|
try {
|
||||||
/*console.log(msg)*/
|
/*console.log(msg)*/
|
||||||
data = JSON.parse(msg)
|
data = JSON.parse(msg)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e); /* "SyntaxError */
|
console.log(e); /* "SyntaxError */
|
||||||
}
|
}
|
||||||
msg = '';
|
msg = '';
|
||||||
/*console.log("EOF detected!")*/
|
/*console.log("EOF detected!")*/
|
||||||
|
|
||||||
if(data['COMMAND'] == 'DAEMON_STATE'){
|
|
||||||
let Data = {
|
|
||||||
input_devices: data['INPUT_DEVICES'],
|
|
||||||
output_devices: data['OUTPUT_DEVICES'],
|
|
||||||
tnc_running_state: data['DAEMON_STATE'][0]['STATUS']
|
|
||||||
|
|
||||||
};
|
if (data['COMMAND'] == 'DAEMON_STATE') {
|
||||||
ipcRenderer.send('request-update-daemon-state', Data);
|
let Data = {
|
||||||
|
input_devices: data['INPUT_DEVICES'],
|
||||||
|
output_devices: data['OUTPUT_DEVICES'],
|
||||||
//input_devices = data['INPUT_DEVICES']
|
tnc_running_state: data['DAEMON_STATE'][0]['STATUS']
|
||||||
//uiMain.updateAudioInput(input_devices)
|
|
||||||
|
|
||||||
//output_devices = data['OUTPUT_DEVICES']
|
};
|
||||||
//uiMain.updateAudioOutput(output_devices)
|
ipcRenderer.send('request-update-daemon-state', Data);
|
||||||
|
|
||||||
//daemon_state = data['DAEMON_STATE'][0]['STATUS']
|
|
||||||
//uiMain.updateTncRunningState(daemon_state)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
////// check if EOF ...
|
////// check if EOF ...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function hexToBytes(hex) {
|
function hexToBytes(hex) {
|
||||||
for (var bytes = [], c = 0; c < hex.length; c += 2)
|
for (var bytes = [], c = 0; c < hex.length; c += 2)
|
||||||
bytes.push(parseInt(hex.substr(c, 2), 16));
|
bytes.push(parseInt(hex.substr(c, 2), 16));
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.getDaemonState = function() {
|
||||||
|
//function getDaemonState(){
|
||||||
|
command = '{"type" : "GET", "command": "DAEMON_STATE"}'
|
||||||
|
writeDaemonCommand(command)
|
||||||
|
|
||||||
exports.getDaemonState = function(){
|
|
||||||
//function getDaemonState(){
|
|
||||||
command = '{"type" : "GET", "command": "DAEMON_STATE"}'
|
|
||||||
writeDaemonCommand(command)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// START TNC
|
// START TNC
|
||||||
// ` `== multi line string
|
// ` `== multi line string
|
||||||
|
|
||||||
|
|
||||||
exports.startTNC = function(rx_audio, tx_audio, deviceid, deviceport, ptt){
|
exports.startTNC = function(rx_audio, tx_audio, deviceid, deviceport, ptt) {
|
||||||
var json_command = JSON.stringify({
|
var json_command = JSON.stringify({
|
||||||
type: 'SET',
|
type: 'SET',
|
||||||
command: 'STARTTNC',
|
command: 'STARTTNC',
|
||||||
parameter: [{
|
parameter: [{
|
||||||
rx_audio: rx_audio,
|
rx_audio: rx_audio,
|
||||||
tx_audio: tx_audio,
|
tx_audio: tx_audio,
|
||||||
deviceid: deviceid,
|
deviceid: deviceid,
|
||||||
deviceport: deviceport,
|
deviceport: deviceport,
|
||||||
ptt: ptt
|
ptt: ptt
|
||||||
}]
|
}]
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//console.log(json_command)
|
//console.log(json_command)
|
||||||
writeDaemonCommand(json_command)
|
writeDaemonCommand(json_command)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// STOP TNC
|
// STOP TNC
|
||||||
exports.stopTNC = function(){
|
exports.stopTNC = function() {
|
||||||
command = '{"type" : "SET", "command": "STOPTNC" , "parameter": "---" }'
|
command = '{"type" : "SET", "command": "STOPTNC" , "parameter": "---" }'
|
||||||
writeDaemonCommand(command)
|
writeDaemonCommand(command)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
203
gui/main.js
203
gui/main.js
|
@ -1,67 +1,49 @@
|
||||||
const { app, BrowserWindow, ipcMain } = require('electron')
|
const {app,BrowserWindow,ipcMain} = require('electron')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
var config = require('./config.json');
|
var config = require('./config.json');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let win = null;
|
let win = null;
|
||||||
let data = null;
|
let data = null;
|
||||||
|
|
||||||
|
function createWindow() {
|
||||||
|
win = new BrowserWindow({
|
||||||
|
width: 1220,
|
||||||
|
height: 920,
|
||||||
|
webPreferences: {
|
||||||
function createWindow () {
|
//preload: path.join(__dirname, 'preload-main.js'),
|
||||||
|
preload: require.resolve('./preload-main.js'),
|
||||||
|
nodeIntegration: true,
|
||||||
win = new BrowserWindow({
|
contextIsolation: false,
|
||||||
width: 1220,
|
enableRemoteModule: false, //https://stackoverflow.com/questions/53390798/opening-new-window-electron/53393655 https://github.com/electron/remote
|
||||||
height: 900,
|
}
|
||||||
webPreferences: {
|
})
|
||||||
//preload: path.join(__dirname, 'preload-main.js'),
|
|
||||||
preload: require.resolve('./preload-main.js'),
|
|
||||||
nodeIntegration: true,
|
|
||||||
contextIsolation: false,
|
|
||||||
enableRemoteModule: false, //https://stackoverflow.com/questions/53390798/opening-new-window-electron/53393655 https://github.com/electron/remote
|
|
||||||
}
|
|
||||||
})
|
|
||||||
//open dev tools
|
|
||||||
win.webContents.openDevTools({
|
|
||||||
mode : 'undocked',
|
|
||||||
activate: true,
|
|
||||||
})
|
|
||||||
win.loadFile('src/index.html')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
data = new BrowserWindow({
|
|
||||||
height: 900,
|
|
||||||
width: 600,
|
|
||||||
parent: win,
|
|
||||||
webPreferences: {
|
|
||||||
preload: require.resolve('./preload-data.js'),
|
|
||||||
nodeIntegration: true,
|
|
||||||
|
|
||||||
}
|
|
||||||
})
|
|
||||||
//open dev tools
|
//open dev tools
|
||||||
data.webContents.openDevTools({
|
win.webContents.openDevTools({
|
||||||
mode : 'undocked',
|
mode: 'undocked',
|
||||||
activate: true,
|
activate: true,
|
||||||
})
|
})
|
||||||
data.loadFile('src/data-module.html')
|
win.loadFile('src/index.html')
|
||||||
data.hide()
|
data = new BrowserWindow({
|
||||||
|
height: 900,
|
||||||
|
width: 600,
|
||||||
|
parent: win,
|
||||||
|
webPreferences: {
|
||||||
|
preload: require.resolve('./preload-data.js'),
|
||||||
|
nodeIntegration: true,
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
//open dev tools
|
||||||
|
data.webContents.openDevTools({
|
||||||
|
mode: 'undocked',
|
||||||
|
activate: true,
|
||||||
|
})
|
||||||
|
data.loadFile('src/data-module.html')
|
||||||
|
data.hide()
|
||||||
|
|
||||||
|
|
||||||
// Emitted when the window is closed.
|
// Emitted when the window is closed.
|
||||||
win.on('closed', function () {
|
win.on('closed', function() {
|
||||||
// Dereference the window object, usually you would store windows
|
// Dereference the window object, usually you would store windows
|
||||||
// in an array if your app supports multi windows, this is the time
|
// in an array if your app supports multi windows, this is the time
|
||||||
// when you should delete the corresponding element.
|
// when you should delete the corresponding element.
|
||||||
|
@ -69,71 +51,46 @@ function createWindow () {
|
||||||
data = null;
|
data = null;
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
data.on('closed', function () {
|
data.on('closed', function () {
|
||||||
// Dereference the window object, usually you would store windows
|
// Dereference the window object, usually you would store windows
|
||||||
// in an array if your app supports multi windows, this is the time
|
// in an array if your app supports multi windows, this is the time
|
||||||
// when you should delete the corresponding element.
|
// when you should delete the corresponding element.
|
||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/44258831/only-hide-the-window-when-closing-it-electron
|
|
||||||
data.on('close', function (evt) {
|
|
||||||
evt.preventDefault();
|
|
||||||
data.hide()
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// https://stackoverflow.com/questions/44258831/only-hide-the-window-when-closing-it-electron
|
||||||
|
data.on('close', function(evt) {
|
||||||
|
evt.preventDefault();
|
||||||
|
data.hide()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.whenReady().then(() => {
|
app.whenReady().then(() => {
|
||||||
createWindow()
|
createWindow()
|
||||||
|
|
||||||
app.on('activate', () => {
|
app.on('activate', () => {
|
||||||
if (BrowserWindow.getAllWindows().length === 0) {
|
if (BrowserWindow.getAllWindows().length === 0) {
|
||||||
createWindow()
|
createWindow()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
app.on('window-all-closed', () => {
|
app.on('window-all-closed', () => {
|
||||||
|
|
||||||
if (process.platform !== 'darwin') {
|
if (process.platform !== 'darwin') {
|
||||||
app.quit()
|
app.quit()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// IPC HANDLER
|
// IPC HANDLER
|
||||||
ipcMain.on('show-data-window', (event, arg) => {
|
ipcMain.on('show-data-window', (event, arg) => {
|
||||||
data.show()
|
data.show()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
ipcMain.on('request-update-tnc-state', (event, arg) => {
|
ipcMain.on('request-update-tnc-state', (event, arg) => {
|
||||||
win.webContents.send('action-update-tnc-state', arg);
|
win.webContents.send('action-update-tnc-state', arg);
|
||||||
data.webContents.send('action-update-tnc-state', arg);
|
data.webContents.send('action-update-tnc-state', arg);
|
||||||
|
@ -157,50 +114,6 @@ ipcMain.on('request-update-daemon-connection', (event, arg) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.on('run-tnc-command', (event, arg) => {
|
ipcMain.on('run-tnc-command', (event, arg) => {
|
||||||
win.webContents.send('run-tnc-command', 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,38 +1,31 @@
|
||||||
|
const {
|
||||||
const { ipcRenderer } = require('electron');
|
ipcRenderer
|
||||||
|
} = require('electron');
|
||||||
var config = require('./config.json');
|
var config = require('./config.json');
|
||||||
|
|
||||||
//const sock = require('./sock.js')
|
|
||||||
//const globals = require('./globals.js')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
window.addEventListener('DOMContentLoaded', () => {
|
window.addEventListener('DOMContentLoaded', () => {
|
||||||
const replaceText = (selector, text) => {
|
const replaceText = (selector, text) => {
|
||||||
const element = document.getElementById(selector)
|
const element = document.getElementById(selector)
|
||||||
if (element) element.innerText = text
|
if (element) element.innerText = text
|
||||||
}
|
}
|
||||||
|
|
||||||
// sendPing button clicked
|
// sendPing button clicked
|
||||||
document.getElementById("sendPing").addEventListener("click", () => {
|
document.getElementById("sendPing").addEventListener("click", () => {
|
||||||
dxcallsign = document.getElementById("dxCall").value
|
dxcallsign = document.getElementById("dxCall").value
|
||||||
//sock.sendPing(dxcallsign)
|
//sock.sendPing(dxcallsign)
|
||||||
|
|
||||||
let Data = {
|
let Data = {
|
||||||
command: "ping",
|
command: "ping",
|
||||||
dxcallsign: document.getElementById("dxCall").value
|
dxcallsign: document.getElementById("dxCall").value
|
||||||
};
|
};
|
||||||
ipcRenderer.send('run-tnc-command', Data);
|
ipcRenderer.send('run-tnc-command', Data);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
document.getElementById("startTransmission").addEventListener("click", () => {
|
document.getElementById("startTransmission").addEventListener("click", () => {
|
||||||
alert("HALLO ")
|
alert("HALLO ")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,58 +33,58 @@ window.addEventListener('DOMContentLoaded', () => {
|
||||||
|
|
||||||
ipcRenderer.on('action-update-tnc-state', (event, arg) => {
|
ipcRenderer.on('action-update-tnc-state', (event, arg) => {
|
||||||
|
|
||||||
// PTT STATE
|
// PTT STATE
|
||||||
if(arg.ptt_state == 'True'){
|
if (arg.ptt_state == 'True') {
|
||||||
document.getElementById("ptt_state").className = "btn btn-danger";
|
document.getElementById("ptt_state").className = "btn btn-danger";
|
||||||
} else if(arg.ptt_state == 'False'){
|
} else if (arg.ptt_state == 'False') {
|
||||||
document.getElementById("ptt_state").className = "btn btn-success";
|
document.getElementById("ptt_state").className = "btn btn-success";
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("ptt_state").className = "btn btn-secondary"
|
document.getElementById("ptt_state").className = "btn btn-secondary"
|
||||||
}
|
}
|
||||||
|
|
||||||
// BUSY STATE
|
// BUSY STATE
|
||||||
if(arg.busy_state == 'BUSY'){
|
if (arg.busy_state == 'BUSY') {
|
||||||
document.getElementById("busy_state").className = "btn btn-danger";
|
document.getElementById("busy_state").className = "btn btn-danger";
|
||||||
} else if(arg.busy_state == 'IDLE'){
|
} else if (arg.busy_state == 'IDLE') {
|
||||||
document.getElementById("busy_state").className = "btn btn-success";
|
document.getElementById("busy_state").className = "btn btn-success";
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("busy_state").className = "btn btn-secondary"
|
document.getElementById("busy_state").className = "btn btn-secondary"
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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"
|
|
||||||
}
|
|
||||||
|
|
||||||
// CHANNEL STATE
|
|
||||||
if(arg.channel_state == 'RECEIVING_SIGNALLING'){
|
|
||||||
document.getElementById("signalling_state").className = "btn btn-success";
|
|
||||||
document.getElementById("data_state").className = "btn btn-secondary";
|
|
||||||
|
|
||||||
} else if(arg.channel_state == 'SENDING_SIGNALLING'){
|
|
||||||
document.getElementById("signalling_state").className = "btn btn-danger";
|
|
||||||
document.getElementById("data_state").className = "btn btn-secondary";
|
|
||||||
|
|
||||||
} else if(arg.channel_state == 'RECEIVING_DATA'){
|
// ARQ STATE
|
||||||
document.getElementById("signalling_state").className = "btn btn-secondary";
|
if (arg.arq_state == 'DATA') {
|
||||||
document.getElementById("data_state").className = "btn btn-success";
|
document.getElementById("arq_state").className = "btn btn-warning";
|
||||||
|
} else if (arg.arq_state == 'IDLE') {
|
||||||
} else if(arg.channel_state == 'SENDING_DATA'){
|
document.getElementById("arq_state").className = "btn btn-secondary";
|
||||||
document.getElementById("signalling_state").className = "btn btn-secondary";
|
} else {
|
||||||
document.getElementById("data_state").className = "btn btn-danger";
|
document.getElementById("arq_state").className = "btn btn-secondary"
|
||||||
} else {
|
}
|
||||||
document.getElementById("signalling_state").className = "btn btn-secondary"
|
|
||||||
document.getElementById("busy_state").className = "btn btn-secondary"
|
|
||||||
|
|
||||||
}
|
// CHANNEL STATE
|
||||||
|
if (arg.channel_state == 'RECEIVING_SIGNALLING') {
|
||||||
});
|
document.getElementById("signalling_state").className = "btn btn-success";
|
||||||
|
document.getElementById("data_state").className = "btn btn-secondary";
|
||||||
|
|
||||||
ipcRenderer.on('action-update-data-state', (event, arg) => {
|
|
||||||
|
|
||||||
});
|
} else if (arg.channel_state == 'SENDING_SIGNALLING') {
|
||||||
|
document.getElementById("signalling_state").className = "btn btn-danger";
|
||||||
|
document.getElementById("data_state").className = "btn btn-secondary";
|
||||||
|
|
||||||
|
} 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"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
ipcRenderer.on('action-update-data-state', (event, arg) => {
|
||||||
|
|
||||||
|
});
|
|
@ -2,284 +2,197 @@ const sock = require('./sock.js')
|
||||||
const daemon = require('./daemon.js')
|
const daemon = require('./daemon.js')
|
||||||
const configPath = './config.json'
|
const configPath = './config.json'
|
||||||
const config = require(configPath);
|
const config = require(configPath);
|
||||||
const { ipcRenderer } = require('electron');
|
const {
|
||||||
|
ipcRenderer
|
||||||
|
} = require('electron');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 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.getDataState, 500)
|
setInterval(sock.getDataState, 500)
|
||||||
setInterval(sock.getHeardStations, 500)
|
setInterval(sock.getHeardStations, 500)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// UPDATE FFT DEMO
|
// UPDATE FFT DEMO
|
||||||
|
|
||||||
updateFFT = function(fft){
|
updateFFT = function(fft) {
|
||||||
var fft = Array.from({length: 2048}, () => Math.floor(Math.random() * 10));
|
var fft = Array.from({
|
||||||
spectrum.addData(fft);
|
length: 2048
|
||||||
|
}, () => Math.floor(Math.random() * 10));
|
||||||
|
spectrum.addData(fft);
|
||||||
}
|
}
|
||||||
setInterval(updateFFT, 250)
|
setInterval(updateFFT, 250)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// WINDOW LISTENER
|
||||||
window.addEventListener('DOMContentLoaded', () => {
|
window.addEventListener('DOMContentLoaded', () => {
|
||||||
// LOAD SETTINGS
|
// LOAD SETTINGS
|
||||||
document.getElementById("tnc_adress").value = config.tnc_host
|
document.getElementById("tnc_adress").value = config.tnc_host
|
||||||
document.getElementById("tnc_port").value = config.tnc_port
|
document.getElementById("tnc_port").value = config.tnc_port
|
||||||
document.getElementById("myCall").value = config.mycall
|
document.getElementById("myCall").value = config.mycall
|
||||||
document.getElementById("myGrid").value = config.mygrid
|
document.getElementById("myGrid").value = config.mygrid
|
||||||
|
|
||||||
|
// 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
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// 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)
|
||||||
config.tnc_host = document.getElementById("tnc_adress").value
|
config.tnc_host = document.getElementById("tnc_adress").value
|
||||||
config.daemon_host = document.getElementById("tnc_adress").value
|
config.daemon_host = document.getElementById("tnc_adress").value
|
||||||
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("tnc_port").addEventListener("change", () => {
|
document.getElementById("tnc_port").addEventListener("change", () => {
|
||||||
config.tnc_port = document.getElementById("tnc_port").value
|
config.tnc_port = document.getElementById("tnc_port").value
|
||||||
config.daemon_port = document.getElementById("tnc_port").value + 1
|
config.daemon_port = document.getElementById("tnc_port").value + 1
|
||||||
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// saveMyCall button clicked
|
||||||
// tnc_host = document.getElementById("tnc_adress").value
|
document.getElementById("saveMyCall").addEventListener("click", () => {
|
||||||
//tnc_port = document.getElementById("tnc_port").value
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// saveMyCall button clicked
|
|
||||||
document.getElementById("saveMyCall").addEventListener("click", () => {
|
|
||||||
callsign = document.getElementById("myCall").value
|
callsign = document.getElementById("myCall").value
|
||||||
config.mycall = callsign
|
config.mycall = callsign
|
||||||
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
||||||
|
|
||||||
sock.saveMyCall(callsign)
|
sock.saveMyCall(callsign)
|
||||||
/*
|
});
|
||||||
let Data = {
|
|
||||||
command: "saveMyCall",
|
|
||||||
callsign: document.getElementById("myCall").value
|
|
||||||
};
|
|
||||||
ipcRenderer.send('run-tnc-command', Data);
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
// saveMyGrid button clicked
|
// saveMyGrid button clicked
|
||||||
document.getElementById("saveMyGrid").addEventListener("click", () => {
|
document.getElementById("saveMyGrid").addEventListener("click", () => {
|
||||||
grid = document.getElementById("myGrid").value
|
grid = document.getElementById("myGrid").value
|
||||||
config.mygrid = grid
|
config.mygrid = grid
|
||||||
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
||||||
|
|
||||||
sock.saveMyGrid(grid)
|
sock.saveMyGrid(grid)
|
||||||
/*
|
|
||||||
let Data = {
|
|
||||||
command: "saveMyGrid",
|
|
||||||
grid: document.getElementById("myGrid").value
|
|
||||||
};
|
|
||||||
ipcRenderer.send('run-tnc-command', Data);
|
|
||||||
*/
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// startPing button clicked
|
// startPing button clicked
|
||||||
document.getElementById("sendPing").addEventListener("click", () => {
|
document.getElementById("sendPing").addEventListener("click", () => {
|
||||||
dxcallsign = document.getElementById("dxCall").value
|
dxcallsign = document.getElementById("dxCall").value
|
||||||
sock.sendPing(dxcallsign)
|
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()
|
|
||||||
|
|
||||||
|
// sendCQ button clicked
|
||||||
|
document.getElementById("sendCQ").addEventListener("click", () => {
|
||||||
});
|
sock.sendCQ()
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// startTNC button clicked
|
// startTNC button clicked
|
||||||
document.getElementById("startTNC").addEventListener("click", () => {
|
document.getElementById("startTNC").addEventListener("click", () => {
|
||||||
var rx_audio = document.getElementById("audio_input_selectbox").value
|
var rx_audio = document.getElementById("audio_input_selectbox").value
|
||||||
var tx_audio = document.getElementById("audio_output_selectbox").value
|
var tx_audio = document.getElementById("audio_output_selectbox").value
|
||||||
var deviceid = document.getElementById("hamlib_deviceid").value
|
var deviceid = document.getElementById("hamlib_deviceid").value
|
||||||
var deviceport = document.getElementById("hamlib_deviceport").value
|
var deviceport = document.getElementById("hamlib_deviceport").value
|
||||||
var ptt = document.getElementById("hamlib_ptt").value
|
var ptt = document.getElementById("hamlib_ptt").value
|
||||||
|
|
||||||
daemon.startTNC(rx_audio, tx_audio, deviceid, deviceport, ptt)
|
daemon.startTNC(rx_audio, tx_audio, deviceid, deviceport, ptt)
|
||||||
setTimeout( function() { sock.saveMyCall(config.mycall); }, 5000 );
|
setTimeout(function() {
|
||||||
setTimeout( function() { sock.saveMyGrid(config.mygrid); }, 5000 );
|
sock.saveMyCall(config.mycall);
|
||||||
|
}, 5000);
|
||||||
|
setTimeout(function() {
|
||||||
|
sock.saveMyGrid(config.mygrid);
|
||||||
|
}, 5000);
|
||||||
|
})
|
||||||
|
|
||||||
/*
|
// stopTNC button clicked
|
||||||
let Data = {
|
document.getElementById("stopTNC").addEventListener("click", () => {
|
||||||
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);
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
// stopTNC button clicked
|
|
||||||
document.getElementById("stopTNC").addEventListener("click", () => {
|
|
||||||
daemon.stopTNC()
|
daemon.stopTNC()
|
||||||
/* let Data = {
|
})
|
||||||
command: "stopTNC",
|
|
||||||
|
// openDataModule button clicked
|
||||||
|
document.getElementById("openDataModule").addEventListener("click", () => {
|
||||||
|
//data.show()
|
||||||
|
let Data = {
|
||||||
|
message: "Hello World !"
|
||||||
};
|
};
|
||||||
ipcRenderer.send('run-daemon-command', Data);
|
ipcRenderer.send('show-data-window', Data);
|
||||||
*/
|
})
|
||||||
})
|
|
||||||
|
|
||||||
// openDataModule button clicked
|
|
||||||
document.getElementById("openDataModule").addEventListener("click", () => {
|
|
||||||
//data.show()
|
|
||||||
let Data = {
|
|
||||||
message: "Hello World !"
|
|
||||||
};
|
|
||||||
ipcRenderer.send('show-data-window', Data);
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ipcRenderer.on('action-update-tnc-state', (event, arg) => {
|
ipcRenderer.on('action-update-tnc-state', (event, arg) => {
|
||||||
|
|
||||||
// PTT STATE
|
// PTT STATE
|
||||||
if(arg.ptt_state == 'True'){
|
if (arg.ptt_state == 'True') {
|
||||||
document.getElementById("ptt_state").className = "btn btn-danger";
|
document.getElementById("ptt_state").className = "btn btn-danger";
|
||||||
console.log("PTT TRUE!!!")
|
console.log("PTT TRUE!!!")
|
||||||
|
|
||||||
} else if(arg.ptt_state == 'False'){
|
} else if (arg.ptt_state == 'False') {
|
||||||
document.getElementById("ptt_state").className = "btn btn-success";
|
document.getElementById("ptt_state").className = "btn btn-success";
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("ptt_state").className = "btn btn-secondary"
|
document.getElementById("ptt_state").className = "btn btn-secondary"
|
||||||
}
|
}
|
||||||
|
|
||||||
// BUSY STATE
|
// BUSY STATE
|
||||||
if(arg.busy_state == 'BUSY'){
|
if (arg.busy_state == 'BUSY') {
|
||||||
document.getElementById("busy_state").className = "btn btn-danger";
|
document.getElementById("busy_state").className = "btn btn-danger";
|
||||||
} else if(arg.busy_state == 'IDLE'){
|
} else if (arg.busy_state == 'IDLE') {
|
||||||
document.getElementById("busy_state").className = "btn btn-success";
|
document.getElementById("busy_state").className = "btn btn-success";
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("busy_state").className = "btn btn-secondary"
|
document.getElementById("busy_state").className = "btn btn-secondary"
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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"
|
|
||||||
}
|
|
||||||
|
|
||||||
// RMS
|
|
||||||
document.getElementById("rms_level").setAttribute("aria-valuenow", arg.rms_level)
|
|
||||||
document.getElementById("rms_level").setAttribute("style", "width:" + arg.rms_level + "%;")
|
|
||||||
|
|
||||||
// CHANNEL STATE
|
|
||||||
if(arg.channel_state == 'RECEIVING_SIGNALLING'){
|
|
||||||
document.getElementById("signalling_state").className = "btn btn-success";
|
|
||||||
document.getElementById("data_state").className = "btn btn-secondary";
|
|
||||||
|
|
||||||
} else if(arg.channel_state == 'SENDING_SIGNALLING'){
|
|
||||||
document.getElementById("signalling_state").className = "btn btn-danger";
|
|
||||||
document.getElementById("data_state").className = "btn btn-secondary";
|
|
||||||
|
|
||||||
} else if(arg.channel_state == 'RECEIVING_DATA'){
|
// ARQ STATE
|
||||||
document.getElementById("signalling_state").className = "btn btn-secondary";
|
if (arg.arq_state == 'DATA') {
|
||||||
document.getElementById("data_state").className = "btn btn-success";
|
document.getElementById("arq_state").className = "btn btn-warning";
|
||||||
|
} else if (arg.arq_state == 'IDLE') {
|
||||||
} else if(arg.channel_state == 'SENDING_DATA'){
|
document.getElementById("arq_state").className = "btn btn-secondary";
|
||||||
document.getElementById("signalling_state").className = "btn btn-secondary";
|
} else {
|
||||||
document.getElementById("data_state").className = "btn btn-danger";
|
document.getElementById("arq_state").className = "btn btn-secondary"
|
||||||
} else {
|
}
|
||||||
document.getElementById("signalling_state").className = "btn btn-secondary"
|
|
||||||
document.getElementById("busy_state").className = "btn btn-secondary"
|
|
||||||
|
|
||||||
}
|
// RMS
|
||||||
|
document.getElementById("rms_level").setAttribute("aria-valuenow", arg.rms_level)
|
||||||
// SET FREQUENCY
|
document.getElementById("rms_level").setAttribute("style", "width:" + arg.rms_level + "%;")
|
||||||
document.getElementById("frequency").value = arg.frequency
|
|
||||||
|
|
||||||
// SET MODE
|
// CHANNEL STATE
|
||||||
document.getElementById("mode").value = arg.mode
|
if (arg.channel_state == 'RECEIVING_SIGNALLING') {
|
||||||
|
document.getElementById("signalling_state").className = "btn btn-success";
|
||||||
|
document.getElementById("data_state").className = "btn btn-secondary";
|
||||||
|
|
||||||
// SET BANDWITH
|
} else if (arg.channel_state == 'SENDING_SIGNALLING') {
|
||||||
document.getElementById("bandwith").value = arg.bandwith
|
document.getElementById("signalling_state").className = "btn btn-danger";
|
||||||
});
|
document.getElementById("data_state").className = "btn btn-secondary";
|
||||||
|
|
||||||
|
} 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").value = arg.frequency
|
||||||
|
|
||||||
|
// SET MODE
|
||||||
|
document.getElementById("mode").value = arg.mode
|
||||||
|
|
||||||
|
// SET BANDWITH
|
||||||
|
document.getElementById("bandwith").value = arg.bandwith
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ipcRenderer.on('action-update-daemon-state', (event, arg) => {
|
ipcRenderer.on('action-update-daemon-state', (event, arg) => {
|
||||||
// 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) {
|
||||||
document.getElementById("audio_input_selectbox").innerHTML = ""
|
document.getElementById("audio_input_selectbox").innerHTML = ""
|
||||||
for (i = 0; i < arg.input_devices.length; i++) {
|
for (i = 0; i < arg.input_devices.length; i++) {
|
||||||
var option = document.createElement("option");
|
var option = document.createElement("option");
|
||||||
option.text = arg.input_devices[i]['NAME'];
|
option.text = arg.input_devices[i]['NAME'];
|
||||||
option.value = arg.input_devices[i]['ID'];
|
option.value = arg.input_devices[i]['ID'];
|
||||||
|
@ -289,94 +202,71 @@ ipcRenderer.on('action-update-daemon-state', (event, arg) => {
|
||||||
}
|
}
|
||||||
// UPDATE AUDIO OUTPUT
|
// UPDATE AUDIO OUTPUT
|
||||||
|
|
||||||
if(document.getElementById("audio_output_selectbox").length != arg.output_devices.length){
|
if (document.getElementById("audio_output_selectbox").length != arg.output_devices.length) {
|
||||||
document.getElementById("audio_output_selectbox").innerHTML = ""
|
document.getElementById("audio_output_selectbox").innerHTML = ""
|
||||||
for (i = 0; i < arg.output_devices.length; i++) {
|
for (i = 0; i < arg.output_devices.length; i++) {
|
||||||
var option = document.createElement("option");
|
var option = document.createElement("option");
|
||||||
option.text = arg.output_devices[i]['NAME'];
|
option.text = arg.output_devices[i]['NAME'];
|
||||||
option.value = arg.output_devices[i]['ID'];
|
option.value = arg.output_devices[i]['ID'];
|
||||||
document.getElementById("audio_output_selectbox").add(option);
|
document.getElementById("audio_output_selectbox").add(option);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TNC RUNNING STATE
|
// TNC RUNNING STATE
|
||||||
document.getElementById("tnc_running_state").innerHTML = arg.tnc_running_state;
|
document.getElementById("tnc_running_state").innerHTML = arg.tnc_running_state;
|
||||||
if(arg.tnc_running_state == "running"){
|
if (arg.tnc_running_state == "running") {
|
||||||
document.getElementById('hamlib_deviceid').disabled = true
|
document.getElementById('hamlib_deviceid').disabled = true
|
||||||
document.getElementById('hamlib_deviceport').disabled = true
|
document.getElementById('hamlib_deviceport').disabled = true
|
||||||
document.getElementById('hamlib_ptt').disabled = true
|
document.getElementById('hamlib_ptt').disabled = true
|
||||||
document.getElementById('audio_input_selectbox').disabled = true
|
document.getElementById('audio_input_selectbox').disabled = true
|
||||||
document.getElementById('audio_output_selectbox').disabled = true
|
document.getElementById('audio_output_selectbox').disabled = true
|
||||||
document.getElementById('stopTNC').disabled = false
|
document.getElementById('stopTNC').disabled = false
|
||||||
document.getElementById('startTNC').disabled = true
|
document.getElementById('startTNC').disabled = true
|
||||||
document.getElementById('myCall').disabled = false
|
document.getElementById('myCall').disabled = false
|
||||||
document.getElementById('saveMyCall').disabled = false
|
document.getElementById('saveMyCall').disabled = false
|
||||||
document.getElementById('myGrid').disabled = false
|
document.getElementById('myGrid').disabled = false
|
||||||
document.getElementById('saveMyGrid').disabled = false
|
document.getElementById('saveMyGrid').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
|
||||||
document.getElementById('hamlib_ptt').disabled = false
|
document.getElementById('hamlib_ptt').disabled = false
|
||||||
document.getElementById('audio_input_selectbox').disabled = false
|
document.getElementById('audio_input_selectbox').disabled = false
|
||||||
document.getElementById('audio_output_selectbox').disabled = false
|
document.getElementById('audio_output_selectbox').disabled = false
|
||||||
document.getElementById('stopTNC').disabled = true
|
document.getElementById('stopTNC').disabled = true
|
||||||
document.getElementById('startTNC').disabled = false
|
document.getElementById('startTNC').disabled = false
|
||||||
document.getElementById('myCall').disabled = true
|
document.getElementById('myCall').disabled = true
|
||||||
document.getElementById('saveMyCall').disabled = true
|
document.getElementById('saveMyCall').disabled = true
|
||||||
document.getElementById('myGrid').disabled = true
|
document.getElementById('myGrid').disabled = true
|
||||||
document.getElementById('saveMyGrid').disabled = true
|
document.getElementById('saveMyGrid').disabled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
});
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
ipcRenderer.on('action-update-daemon-connection', (event, arg) => {
|
ipcRenderer.on('action-update-daemon-connection', (event, arg) => {
|
||||||
|
|
||||||
|
if (arg.daemon_connection == 'open') {
|
||||||
|
document.getElementById("daemon_connection_state").className = "btn btn-success";
|
||||||
|
}
|
||||||
|
if (arg.daemon_connection == 'opening') {
|
||||||
|
document.getElementById("daemon_connection_state").className = "btn btn-warning";
|
||||||
|
}
|
||||||
|
if (arg.daemon_connection == 'closed') {
|
||||||
|
document.getElementById("daemon_connection_state").className = "btn btn-danger";
|
||||||
|
}
|
||||||
|
|
||||||
if(arg.daemon_connection == 'open'){
|
});
|
||||||
document.getElementById("daemon_connection_state").className = "btn btn-success";
|
|
||||||
}
|
|
||||||
if(arg.daemon_connection == 'opening'){
|
|
||||||
document.getElementById("daemon_connection_state").className = "btn btn-warning";
|
|
||||||
}
|
|
||||||
if(arg.daemon_connection == 'closed'){
|
|
||||||
document.getElementById("daemon_connection_state").className = "btn btn-danger";
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
ipcRenderer.on('run-tnc-command', (event, arg) => {
|
||||||
|
if (arg.command == 'saveMyCall') {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ipcRenderer.on('run-tnc-command', (event, arg) => {
|
|
||||||
if (arg.command == 'saveMyCall'){
|
|
||||||
sock.saveMyCall(arg.callsign)
|
sock.saveMyCall(arg.callsign)
|
||||||
}
|
}
|
||||||
if (arg.command == 'saveMyGrid'){
|
if (arg.command == 'saveMyGrid') {
|
||||||
sock.saveMyGrid(arg.grid)
|
sock.saveMyGrid(arg.grid)
|
||||||
}
|
}
|
||||||
if (arg.command == 'ping'){
|
if (arg.command == 'ping') {
|
||||||
sock.sendPing(arg.dxcallsign)
|
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()
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
287
gui/sock.js
287
gui/sock.js
|
@ -1,55 +1,45 @@
|
||||||
var net = require('net');
|
var net = require('net');
|
||||||
var config = require('./config.json');
|
var config = require('./config.json');
|
||||||
|
const {
|
||||||
|
ipcRenderer
|
||||||
|
} = require('electron');
|
||||||
|
|
||||||
const { ipcRenderer } = require('electron');
|
|
||||||
|
|
||||||
//var client = new net.Socket();
|
|
||||||
var client = new net.Socket();
|
var client = new net.Socket();
|
||||||
var msg = ''; // Current message, per connection.
|
var msg = ''; // Current message, per connection.
|
||||||
|
|
||||||
setTimeout(connectTNC, 3000)
|
setTimeout(connectTNC, 3000)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function connectTNC(){
|
|
||||||
//exports.connectTNC = function(){
|
|
||||||
|
|
||||||
|
function connectTNC() {
|
||||||
|
//exports.connectTNC = function(){
|
||||||
console.log('connecting to TNC...')
|
console.log('connecting to TNC...')
|
||||||
|
|
||||||
//clear message buffer after reconnecting or inital connection
|
//clear message buffer after reconnecting or inital connection
|
||||||
msg = '';
|
msg = '';
|
||||||
|
client.connect(config.tnc_port, config.tnc_host)
|
||||||
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) {
|
client.on('connect', function(data) {
|
||||||
console.log('TNC connection established')
|
console.log('TNC connection established')
|
||||||
})
|
})
|
||||||
|
|
||||||
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: "-",
|
||||||
channel_state: "-",
|
channel_state: "-",
|
||||||
frequency : "-",
|
frequency: "-",
|
||||||
mode: "-",
|
mode: "-",
|
||||||
bandwith: "-",
|
bandwith: "-",
|
||||||
rms_level : 0
|
rms_level: 0
|
||||||
|
|
||||||
|
};
|
||||||
|
ipcRenderer.send('request-update-tnc-state', Data);
|
||||||
|
|
||||||
};
|
|
||||||
ipcRenderer.send('request-update-tnc-state', Data);
|
|
||||||
|
|
||||||
setTimeout(connectTNC, 2000)
|
setTimeout(connectTNC, 2000)
|
||||||
// setTimeout( function() { exports.connectTNC(tnc_host, tnc_port); }, 2000 );
|
// setTimeout( function() { exports.connectTNC(tnc_host, tnc_port); }, 2000 );
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -61,184 +51,159 @@ client.on('close', function(data) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
client.on('end', function(data) {
|
client.on('end', function(data) {
|
||||||
console.log('TNC connection ended');
|
console.log('TNC connection ended');
|
||||||
//setTimeout(connectTNC, 2000)
|
//setTimeout(connectTNC, 2000)
|
||||||
setTimeout(connectTNC, 0)
|
setTimeout(connectTNC, 0)
|
||||||
|
|
||||||
// setTimeout( function() { exports.connectTNC(tnc_host, tnc_port); }, 2000 );
|
// setTimeout( function() { exports.connectTNC(tnc_host, tnc_port); }, 2000 );
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//exports.writeTncCommand = function(command){
|
//exports.writeTncCommand = function(command){
|
||||||
writeTncCommand = function(command){
|
writeTncCommand = function(command) {
|
||||||
|
|
||||||
console.log(command)
|
console.log(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(client.readyState == 'open'){
|
if (client.readyState == 'open') {
|
||||||
//uiMain.setTNCconnection('open')
|
//uiMain.setTNCconnection('open')
|
||||||
client.write(command + '\n');
|
client.write(command + '\n');
|
||||||
}
|
|
||||||
|
|
||||||
if(client.readyState == 'closed'){
|
|
||||||
//uiMain.setTNCconnection('closed')
|
|
||||||
console.log("CLOSED!!!!!")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(client.readyState == 'opening'){
|
if (client.readyState == 'closed') {
|
||||||
//uiMain.setTNCconnection('opening')
|
//uiMain.setTNCconnection('closed')
|
||||||
console.log("OPENING!!!!!")
|
console.log("CLOSED!!!!!")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
if (client.readyState == 'opening') {
|
||||||
|
//uiMain.setTNCconnection('opening')
|
||||||
|
console.log("OPENING!!!!!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
client.on('data', function(data) {
|
client.on('data', function(data) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
stackoverflow.com questions 9070700 nodejs-net-createserver-large-amount-of-data-coming-in
|
stackoverflow.com questions 9070700 nodejs-net-createserver-large-amount-of-data-coming-in
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
/*
|
|
||||||
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)
|
|
||||||
try {
|
|
||||||
//console.log(msg)
|
|
||||||
data = JSON.parse(msg)
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e); /* "SyntaxError*/
|
|
||||||
}
|
|
||||||
msg = '';
|
|
||||||
/* console.log("EOF detected!") */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(data['COMMAND'] == 'TNC_STATE'){
|
|
||||||
let Data = {
|
|
||||||
ptt_state: data['PTT_STATE'],
|
|
||||||
busy_state: data['TNC_STATE'],
|
|
||||||
arq_state: data['ARQ_STATE'],
|
|
||||||
channel_state: data['CHANNEL_STATE'],
|
|
||||||
frequency : data['FREQUENCY'],
|
|
||||||
mode: data['MODE'],
|
|
||||||
bandwith: data['BANDWITH'],
|
|
||||||
rms_level : (data['AUDIO_RMS']/1000)*100
|
|
||||||
};
|
|
||||||
console.log(Data)
|
|
||||||
ipcRenderer.send('request-update-tnc-state', 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'){
|
// check if we reached an EOF, if true, clear buffer and parse JSON data
|
||||||
let Data = {
|
if (data.endsWith('}')) {
|
||||||
dxcallsign: data['DXCALLSIGN'],
|
//console.log(msg)
|
||||||
dxgrid: data['DXGRID'],
|
try {
|
||||||
timestamp: data['TIMESTAMP'],
|
//console.log(msg)
|
||||||
datatype: data['DATATYPE'],
|
data = JSON.parse(msg)
|
||||||
};
|
} catch (e) {
|
||||||
console.log(Data)
|
console.log(e); /* "SyntaxError*/
|
||||||
ipcRenderer.send('request-update-heard-stations', Data);
|
}
|
||||||
}
|
msg = '';
|
||||||
|
/* console.log("EOF detected!") */
|
||||||
|
|
||||||
|
|
||||||
// check if EOF ...
|
if (data['COMMAND'] == 'TNC_STATE') {
|
||||||
|
let Data = {
|
||||||
|
ptt_state: data['PTT_STATE'],
|
||||||
|
busy_state: data['TNC_STATE'],
|
||||||
|
arq_state: data['ARQ_STATE'],
|
||||||
|
channel_state: data['CHANNEL_STATE'],
|
||||||
|
frequency: data['FREQUENCY'],
|
||||||
|
mode: data['MODE'],
|
||||||
|
bandwith: data['BANDWITH'],
|
||||||
|
rms_level: (data['AUDIO_RMS'] / 1000) * 100
|
||||||
|
};
|
||||||
|
console.log(Data)
|
||||||
|
ipcRenderer.send('request-update-tnc-state', 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') {
|
||||||
|
let Data = {
|
||||||
|
dxcallsign: data['DXCALLSIGN'],
|
||||||
|
dxgrid: data['DXGRID'],
|
||||||
|
timestamp: data['TIMESTAMP'],
|
||||||
|
datatype: data['DATATYPE'],
|
||||||
|
};
|
||||||
|
console.log(Data)
|
||||||
|
ipcRenderer.send('request-update-heard-stations', Data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// check if EOF ...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function hexToBytes(hex) {
|
function hexToBytes(hex) {
|
||||||
for (var bytes = [], c = 0; c < hex.length; c += 2)
|
for (var bytes = [], c = 0; c < hex.length; c += 2)
|
||||||
bytes.push(parseInt(hex.substr(c, 2), 16));
|
bytes.push(parseInt(hex.substr(c, 2), 16));
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Save myCall
|
//Save myCall
|
||||||
exports.saveMyCall = function(callsign){
|
exports.saveMyCall = function(callsign) {
|
||||||
command = '{"type" : "SET", "command": "MYCALLSIGN" , "parameter": "'+ callsign +'" }'
|
command = '{"type" : "SET", "command": "MYCALLSIGN" , "parameter": "' + callsign + '" }'
|
||||||
writeTncCommand(command)
|
writeTncCommand(command)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save myGrid
|
// Save myGrid
|
||||||
exports.saveMyGrid = function(grid){
|
exports.saveMyGrid = function(grid) {
|
||||||
command = '{"type" : "SET", "command": "MYGRID" , "parameter": "'+ grid +'" }'
|
command = '{"type" : "SET", "command": "MYGRID" , "parameter": "' + grid + '" }'
|
||||||
writeTncCommand(command)
|
writeTncCommand(command)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get TNC State
|
//Get TNC State
|
||||||
exports.getTncState = function(){
|
exports.getTncState = function() {
|
||||||
command = '{"type" : "GET", "command": "TNC_STATE"}';
|
command = '{"type" : "GET", "command": "TNC_STATE"}';
|
||||||
writeTncCommand(command)
|
writeTncCommand(command)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get DATA State
|
//Get DATA State
|
||||||
exports.getDataState = function(){
|
exports.getDataState = function() {
|
||||||
command = '{"type" : "GET", "command": "DATA_STATE"}';
|
command = '{"type" : "GET", "command": "DATA_STATE"}';
|
||||||
writeTncCommand(command)
|
writeTncCommand(command)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get Heard Stations
|
//Get Heard Stations
|
||||||
exports.getHeardStations = function(){
|
exports.getHeardStations = function() {
|
||||||
command = '{"type" : "GET", "command": "HEARD_STATIONS"}';
|
command = '{"type" : "GET", "command": "HEARD_STATIONS"}';
|
||||||
writeTncCommand(command)
|
writeTncCommand(command)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Send Ping
|
// Send Ping
|
||||||
exports.sendPing = function(dxcallsign){
|
exports.sendPing = function(dxcallsign) {
|
||||||
command = '{"type" : "PING", "command" : "PING", "dxcallsign" : "' + dxcallsign + '"}'
|
command = '{"type" : "PING", "command" : "PING", "dxcallsign" : "' + dxcallsign + '"}'
|
||||||
writeTncCommand(command)
|
writeTncCommand(command)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send CQ
|
// Send CQ
|
||||||
exports.sendCQ = function(){
|
exports.sendCQ = function() {
|
||||||
command = '{"type" : "CQ", "command" : "CQCQCQ"}'
|
command = '{"type" : "CQ", "command" : "CQCQCQ"}'
|
||||||
writeTncCommand(command)
|
writeTncCommand(command)
|
||||||
}
|
}
|
Loading…
Reference in a new issue