mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 10:04:33 +02:00
bug fixes and tests with network connection
This commit is contained in:
parent
b4f822ea6f
commit
dbdac3ee35
62
gui/main.js
62
gui/main.js
|
@ -1,9 +1,6 @@
|
|||
const { app, BrowserWindow, ipcMain } = require('electron')
|
||||
const path = require('path')
|
||||
|
||||
//require('@electron/remote/main').initialize()
|
||||
|
||||
|
||||
let win = null;
|
||||
let data = null;
|
||||
|
||||
|
@ -16,7 +13,7 @@ function createWindow () {
|
|||
webPreferences: {
|
||||
//preload: path.join(__dirname, 'preload-main.js'),
|
||||
preload: require.resolve('./preload-main.js'),
|
||||
nodeIntegration: true,
|
||||
nodeIntegration: false,
|
||||
contextIsolation: false,
|
||||
enableRemoteModule: false, //https://stackoverflow.com/questions/53390798/opening-new-window-electron/53393655 https://github.com/electron/remote
|
||||
}
|
||||
|
@ -36,8 +33,15 @@ function createWindow () {
|
|||
parent: win,
|
||||
webPreferences: {
|
||||
preload: require.resolve('./preload-data.js'),
|
||||
nodeIntegration: false,
|
||||
|
||||
}
|
||||
})
|
||||
//open dev tools
|
||||
data.webContents.openDevTools({
|
||||
mode : 'undocked',
|
||||
activate: true,
|
||||
})
|
||||
data.loadFile('src/data-module.html')
|
||||
data.hide()
|
||||
|
||||
|
@ -115,7 +119,7 @@ app.on('window-all-closed', () => {
|
|||
|
||||
|
||||
|
||||
|
||||
// IPC HANDLER
|
||||
ipcMain.on('show-data-window', (event, arg) => {
|
||||
data.show()
|
||||
});
|
||||
|
@ -134,3 +138,51 @@ ipcMain.on('request-update-daemon-connection', (event, arg) => {
|
|||
win.webContents.send('action-update-daemon-connection', 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,5 +1,10 @@
|
|||
const sock = require('./sock.js')
|
||||
const daemon = require('./daemon.js')
|
||||
|
||||
setInterval(daemon.getDaemonState, 1000)
|
||||
setInterval(sock.getTncState, 250)
|
||||
|
||||
|
||||
const { ipcRenderer } = require('electron');
|
||||
|
||||
|
||||
|
@ -7,9 +12,19 @@ const { ipcRenderer } = require('electron');
|
|||
|
||||
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
/*
|
||||
globals.tnc_host = document.getElementById("tnc_adress").value
|
||||
globals.tnc_port = document.getElementById("tnc_port").value
|
||||
console.log(globals.tnc_host)
|
||||
console.log(globals.tnc_port)
|
||||
setInterval(sock.connectTNC, 500)
|
||||
*/
|
||||
//setInterval( function() { sock.connectTNC(tnc_host, tnc_port); }, 500 );
|
||||
|
||||
|
||||
setInterval(sock.getTncState, 1000)
|
||||
setInterval(daemon.getDaemonState, 250)
|
||||
//setInterval(sock.getTncState, 500)
|
||||
//setInterval(daemon.getDaemonState, 500)
|
||||
//setInterval(uiMain.updateFFT, 250)
|
||||
|
||||
|
||||
|
@ -27,17 +42,60 @@ setInterval(daemon.getDaemonState, 250)
|
|||
document.getElementById("saveMyCall").addEventListener("click", () => {
|
||||
callsign = document.getElementById("myCall").value
|
||||
sock.saveMyCall(callsign)
|
||||
//uiMain.getTncState()
|
||||
/*
|
||||
let Data = {
|
||||
command: "saveMyCall",
|
||||
callsign: document.getElementById("myCall").value
|
||||
};
|
||||
ipcRenderer.send('run-tnc-command', Data);
|
||||
|
||||
*/
|
||||
|
||||
|
||||
})
|
||||
|
||||
// saveMyGrid button clicked
|
||||
document.getElementById("saveMyGrid").addEventListener("click", () => {
|
||||
grid = document.getElementById("myGrid").value
|
||||
sock.saveMyGrid(grid)
|
||||
//uiMain.getTncState()
|
||||
/*
|
||||
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
|
||||
|
@ -47,11 +105,29 @@ setInterval(daemon.getDaemonState, 250)
|
|||
var ptt = document.getElementById("hamlib_ptt").value
|
||||
|
||||
daemon.startTNC(rx_audio, tx_audio, deviceid, deviceport, ptt)
|
||||
/*
|
||||
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);
|
||||
*/
|
||||
|
||||
|
||||
})
|
||||
|
||||
// stopTNC button clicked
|
||||
document.getElementById("stopTNC").addEventListener("click", () => {
|
||||
daemon.stopTNC()
|
||||
/* let Data = {
|
||||
command: "stopTNC",
|
||||
};
|
||||
ipcRenderer.send('run-daemon-command', Data);
|
||||
*/
|
||||
})
|
||||
|
||||
// openDataModule button clicked
|
||||
|
@ -81,6 +157,8 @@ ipcRenderer.on('action-update-tnc-state', (event, arg) => {
|
|||
// PTT STATE
|
||||
if(arg.ptt_state == 'True'){
|
||||
document.getElementById("ptt_state").className = "btn btn-danger";
|
||||
console.log("PTT TRUE!!!")
|
||||
|
||||
} else if(arg.ptt_state == 'False'){
|
||||
document.getElementById("ptt_state").className = "btn btn-success";
|
||||
} else {
|
||||
|
@ -215,4 +293,38 @@ ipcRenderer.on('action-update-daemon-connection', (event, arg) => {
|
|||
document.getElementById("daemon_connection_state").className = "btn btn-danger";
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ipcRenderer.on('run-tnc-command', (event, 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)
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
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()
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
54
gui/sock.js
54
gui/sock.js
|
@ -1,24 +1,31 @@
|
|||
var net = require('net');
|
||||
//const globals = require('./globals.js')
|
||||
|
||||
const { ipcRenderer } = require('electron');
|
||||
|
||||
//var client = new net.Socket();
|
||||
var client = new net.Socket();
|
||||
var msg = ''; // Current message, per connection.
|
||||
|
||||
setTimeout(connectTNC, 3000)
|
||||
|
||||
|
||||
|
||||
setTimeout(connectTNC, 500)
|
||||
|
||||
function connectTNC(){
|
||||
//exports.connectTNC = function(){
|
||||
|
||||
console.log('connecting to TNC...')
|
||||
|
||||
//clear message buffer after reconnecting or inital connection
|
||||
msg = '';
|
||||
|
||||
tnc_host = document.getElementById("tnc_adress").value
|
||||
tnc_port = document.getElementById("tnc_port").value
|
||||
client.connect(tnc_port, tnc_host)
|
||||
// tnc_host = document.getElementById("tnc_adress").value
|
||||
//tnc_port = document.getElementById("tnc_port").value
|
||||
|
||||
tnc_host = '192.168.178.163'
|
||||
tnc_port = 3000
|
||||
client.connect(tnc_port, tnc_host)
|
||||
//client.setTimeout(5000);
|
||||
}
|
||||
|
||||
|
@ -43,6 +50,8 @@ client.on('error', function(data) {
|
|||
ipcRenderer.send('request-update-tnc-state', Data);
|
||||
|
||||
setTimeout(connectTNC, 2000)
|
||||
// setTimeout( function() { exports.connectTNC(tnc_host, tnc_port); }, 2000 );
|
||||
|
||||
});
|
||||
|
||||
/*
|
||||
|
@ -54,7 +63,11 @@ client.on('close', function(data) {
|
|||
|
||||
client.on('end', function(data) {
|
||||
console.log('TNC connection ended');
|
||||
setTimeout(connectTNC, 2000)
|
||||
//setTimeout(connectTNC, 2000)
|
||||
setTimeout(connectTNC, 0)
|
||||
|
||||
// setTimeout( function() { exports.connectTNC(tnc_host, tnc_port); }, 2000 );
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
@ -71,10 +84,13 @@ client.on('end', function(data) {
|
|||
|
||||
if(client.readyState == 'closed'){
|
||||
//uiMain.setTNCconnection('closed')
|
||||
console.log("CLOSED!!!!!")
|
||||
}
|
||||
|
||||
if(client.readyState == 'opening'){
|
||||
//uiMain.setTNCconnection('opening')
|
||||
console.log("OPENING!!!!!")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -146,6 +162,7 @@ stackoverflow.com questions 9070700 nodejs-net-createserver-large-amount-of-data
|
|||
rms_level : (data['AUDIO_RMS']/1000)*100
|
||||
|
||||
};
|
||||
console.log(Data)
|
||||
ipcRenderer.send('request-update-tnc-state', Data);
|
||||
|
||||
|
||||
|
@ -176,18 +193,43 @@ function hexToBytes(hex) {
|
|||
|
||||
|
||||
|
||||
//Save callsign
|
||||
//Save myCall
|
||||
exports.saveMyCall = function(callsign){
|
||||
command = '{"type" : "SET", "command": "MYCALLSIGN" , "parameter": "'+ callsign +'" }'
|
||||
writeTncCommand(command)
|
||||
}
|
||||
|
||||
// Save myGrid
|
||||
exports.saveMyGrid = function(grid){
|
||||
command = '{"type" : "SET", "command": "MYGRID" , "parameter": "'+ grid +'" }'
|
||||
writeTncCommand(command)
|
||||
}
|
||||
|
||||
//Get TNC State
|
||||
exports.getTncState = function(){
|
||||
command = '{"type" : "GET", "command": "TNC_STATE"}';
|
||||
writeTncCommand(command)
|
||||
}
|
||||
|
||||
// Send Ping
|
||||
exports.sendPing = function(dxcallsign){
|
||||
command = '{"type" : "PING", "command" : "PING", "dxcallsign" : "' + dxcallsign + '"}'
|
||||
writeTncCommand(command)
|
||||
}
|
||||
|
||||
// Send CQ
|
||||
exports.sendCQ = function(){
|
||||
command = '{"type" : "CQ", "command" : "CQCQCQ"}'
|
||||
|
||||
writeTncCommand(command)
|
||||
console.log("COMMAND WURDE GESCHRIEBEN UND AUSGEFIEHT!!!!")
|
||||
|
||||
tnc_host = '192.168.178.163'
|
||||
tnc_port = 3000
|
||||
var testclient = new net.Socket();
|
||||
|
||||
//testclient.connect(tnc_port, tnc_host)
|
||||
//testclient.write(command + '\n');
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue