2021-07-17 07:03:40 +00:00
|
|
|
var net = require('net');
|
2021-09-04 18:23:58 +00:00
|
|
|
const path = require('path')
|
2021-07-24 07:06:22 +00:00
|
|
|
const {
|
|
|
|
ipcRenderer
|
2021-09-04 18:23:58 +00:00
|
|
|
} = require('electron')
|
|
|
|
|
2022-02-24 09:13:00 +00:00
|
|
|
const log = require('electron-log');
|
|
|
|
const socketLog = log.scope('tnc');
|
2022-03-14 19:21:15 +00:00
|
|
|
const utf8 = require('utf8');
|
|
|
|
|
|
|
|
|
2021-09-04 18:23:58 +00:00
|
|
|
// https://stackoverflow.com/a/26227660
|
2021-09-04 19:37:56 +00:00
|
|
|
var appDataFolder = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME + "/.config")
|
2021-09-13 16:27:50 +00:00
|
|
|
var configFolder = path.join(appDataFolder, "FreeDATA");
|
2021-09-04 18:23:58 +00:00
|
|
|
var configPath = path.join(configFolder, 'config.json')
|
|
|
|
const config = require(configPath);
|
2021-07-17 07:03:40 +00:00
|
|
|
|
|
|
|
var client = new net.Socket();
|
2022-01-30 13:16:08 +00:00
|
|
|
var socketchunk = ''; // Current message, per connection.
|
2021-07-17 07:03:40 +00:00
|
|
|
|
2022-02-02 20:12:16 +00:00
|
|
|
// split character
|
2022-12-28 10:32:33 +00:00
|
|
|
const split_char = '\0;\1;'
|
2022-02-02 20:12:16 +00:00
|
|
|
|
2022-04-24 22:43:30 +00:00
|
|
|
// globals for getting new data only if available so we are saving bandwidth
|
2021-08-23 14:24:49 +00:00
|
|
|
var rxBufferLengthTnc = 0
|
|
|
|
var rxBufferLengthGui = 0
|
2021-10-17 14:59:15 +00:00
|
|
|
var rxMsgBufferLengthTnc = 0
|
|
|
|
var rxMsgBufferLengthGui = 0
|
2021-08-23 14:24:49 +00:00
|
|
|
|
2022-04-24 22:43:30 +00:00
|
|
|
// global to keep track of TNC connection error emissions
|
|
|
|
var tncShowConnectStateError = 1
|
|
|
|
|
2022-11-25 11:04:15 +00:00
|
|
|
// global for storing ip information
|
|
|
|
var tnc_port = config.tnc_port;
|
|
|
|
var tnc_host = config.tnc_host;
|
|
|
|
|
2021-08-23 14:24:49 +00:00
|
|
|
// network connection Timeout
|
2022-02-22 20:05:48 +00:00
|
|
|
setTimeout(connectTNC, 2000)
|
2021-07-17 07:03:40 +00:00
|
|
|
|
2021-07-24 07:06:22 +00:00
|
|
|
function connectTNC() {
|
|
|
|
//exports.connectTNC = function(){
|
2022-02-24 09:13:00 +00:00
|
|
|
//socketLog.info('connecting to TNC...')
|
2021-07-24 07:06:22 +00:00
|
|
|
|
2022-11-25 11:04:15 +00:00
|
|
|
//clear message buffer after reconnecting or initial connection
|
2022-01-30 13:16:08 +00:00
|
|
|
socketchunk = '';
|
2021-09-04 18:23:58 +00:00
|
|
|
|
|
|
|
if (config.tnclocation == 'localhost') {
|
|
|
|
client.connect(3000, '127.0.0.1')
|
2021-09-04 14:33:17 +00:00
|
|
|
} else {
|
2022-11-25 11:04:15 +00:00
|
|
|
client.connect(tnc_port, tnc_host)
|
2021-09-04 14:33:17 +00:00
|
|
|
}
|
2021-07-17 07:03:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
client.on('connect', function(data) {
|
2022-02-24 09:13:00 +00:00
|
|
|
socketLog.info('TNC connection established')
|
2022-02-12 15:34:47 +00:00
|
|
|
let Data = {
|
|
|
|
busy_state: "-",
|
|
|
|
arq_state: "-",
|
|
|
|
//channel_state: "-",
|
|
|
|
frequency: "-",
|
|
|
|
mode: "-",
|
2022-05-28 12:08:33 +00:00
|
|
|
bandwidth: "-",
|
2022-11-18 14:19:41 +00:00
|
|
|
dbfs_level: 0
|
2022-02-12 15:34:47 +00:00
|
|
|
};
|
|
|
|
ipcRenderer.send('request-update-tnc-state', Data);
|
|
|
|
|
|
|
|
// also update tnc connection state
|
|
|
|
ipcRenderer.send('request-update-tnc-connection', {tnc_connection : client.readyState});
|
|
|
|
|
2022-04-24 22:43:30 +00:00
|
|
|
tncShowConnectStateError = 1
|
2021-07-17 07:03:40 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
client.on('error', function(data) {
|
2022-04-24 22:43:30 +00:00
|
|
|
if (tncShowConnectStateError == 1) {
|
|
|
|
socketLog.error('TNC connection error');
|
|
|
|
socketLog.info('TNC is started by the GUI process.');
|
|
|
|
socketLog.debug(data);
|
|
|
|
// setTimeout( function() { exports.connectTNC(tnc_host, tnc_port); }, 2000 );
|
|
|
|
|
|
|
|
tncShowConnectStateError = 0
|
|
|
|
}
|
|
|
|
setTimeout(connectTNC, 500)
|
|
|
|
client.destroy();
|
2021-07-24 07:06:22 +00:00
|
|
|
let Data = {
|
2022-02-12 15:34:47 +00:00
|
|
|
tnc_connection: client.readyState,
|
2021-07-24 07:06:22 +00:00
|
|
|
busy_state: "-",
|
|
|
|
arq_state: "-",
|
2021-12-26 08:24:22 +00:00
|
|
|
//channel_state: "-",
|
2021-07-24 07:06:22 +00:00
|
|
|
frequency: "-",
|
|
|
|
mode: "-",
|
2022-05-28 12:08:33 +00:00
|
|
|
bandwidth: "-",
|
2022-11-18 14:19:41 +00:00
|
|
|
dbfs_level: 0
|
2021-07-17 07:03:40 +00:00
|
|
|
|
2021-07-24 07:06:22 +00:00
|
|
|
};
|
|
|
|
ipcRenderer.send('request-update-tnc-state', Data);
|
2022-02-12 15:34:47 +00:00
|
|
|
ipcRenderer.send('request-update-tnc-connection', {tnc_connection : client.readyState});
|
2021-07-17 07:03:40 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
client.on('close', function(data) {
|
2022-02-24 09:13:00 +00:00
|
|
|
socketLog.info(' TNC connection closed');
|
2021-09-13 16:27:50 +00:00
|
|
|
setTimeout(connectTNC, 2000)
|
2021-07-17 07:03:40 +00:00
|
|
|
});
|
|
|
|
*/
|
|
|
|
|
|
|
|
client.on('end', function(data) {
|
2022-02-24 09:13:00 +00:00
|
|
|
socketLog.info('TNC connection ended');
|
2022-02-12 15:34:47 +00:00
|
|
|
ipcRenderer.send('request-update-tnc-connection', {tnc_connection : client.readyState});
|
2022-02-08 14:27:34 +00:00
|
|
|
client.destroy();
|
2022-02-12 15:34:47 +00:00
|
|
|
|
2022-02-08 14:27:34 +00:00
|
|
|
setTimeout(connectTNC, 500)
|
2021-07-19 19:01:38 +00:00
|
|
|
|
2021-07-17 07:03:40 +00:00
|
|
|
});
|
|
|
|
|
2021-07-24 07:06:22 +00:00
|
|
|
writeTncCommand = function(command) {
|
2022-02-12 15:34:47 +00:00
|
|
|
|
2022-02-24 09:13:00 +00:00
|
|
|
//socketLog.info(command)
|
2021-07-17 07:03:40 +00:00
|
|
|
// we use the writingCommand function to update our TCPIP state because we are calling this function a lot
|
2022-04-10 17:20:58 +00:00
|
|
|
// if socket opened, we are able to run commands
|
2022-03-12 14:06:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-07-24 07:06:22 +00:00
|
|
|
if (client.readyState == 'open') {
|
|
|
|
client.write(command + '\n');
|
2022-02-12 15:34:47 +00:00
|
|
|
|
2021-07-17 07:03:40 +00:00
|
|
|
}
|
|
|
|
|
2021-07-24 07:06:22 +00:00
|
|
|
if (client.readyState == 'closed') {
|
2022-02-24 09:13:00 +00:00
|
|
|
socketLog.info("CLOSED!")
|
2022-02-12 15:34:47 +00:00
|
|
|
|
2021-07-24 07:06:22 +00:00
|
|
|
}
|
2021-07-19 19:01:38 +00:00
|
|
|
|
2021-07-24 07:06:22 +00:00
|
|
|
if (client.readyState == 'opening') {
|
2022-02-24 09:13:00 +00:00
|
|
|
socketLog.info('connecting to TNC...')
|
2022-02-12 15:34:47 +00:00
|
|
|
|
2021-07-24 07:06:22 +00:00
|
|
|
}
|
2021-07-17 07:03:40 +00:00
|
|
|
}
|
|
|
|
|
2022-01-30 13:16:08 +00:00
|
|
|
client.on('data', function(socketdata) {
|
2021-07-17 07:03:40 +00:00
|
|
|
|
2022-02-12 15:34:47 +00:00
|
|
|
ipcRenderer.send('request-update-tnc-connection', {tnc_connection : client.readyState});
|
|
|
|
|
2021-09-13 16:27:50 +00:00
|
|
|
/*
|
2022-01-30 13:16:08 +00:00
|
|
|
inspired by:
|
2021-07-24 07:06:22 +00:00
|
|
|
stackoverflow.com questions 9070700 nodejs-net-createserver-large-amount-of-data-coming-in
|
|
|
|
*/
|
|
|
|
|
2022-01-30 13:16:08 +00:00
|
|
|
socketdata = socketdata.toString('utf8'); // convert data to string
|
|
|
|
socketchunk += socketdata// append data to buffer so we can stick long data together
|
|
|
|
|
|
|
|
|
|
|
|
// check if we received begin and end of json data
|
|
|
|
if (socketchunk.startsWith('{"') && socketchunk.endsWith('"}\n')) {
|
|
|
|
|
|
|
|
var data = ''
|
|
|
|
|
|
|
|
// split data into chunks if we received multiple commands
|
|
|
|
socketchunk = socketchunk.split("\n");
|
|
|
|
data = JSON.parse(socketchunk[0])
|
|
|
|
|
|
|
|
|
|
|
|
// search for empty entries in socketchunk and remove them
|
|
|
|
for (i = 0; i < socketchunk.length; i++) {
|
|
|
|
if (socketchunk[i] === ''){
|
|
|
|
socketchunk.splice(i, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-28 19:07:39 +00:00
|
|
|
|
2022-01-30 13:16:08 +00:00
|
|
|
//iterate through socketchunks array to execute multiple commands in row
|
|
|
|
for (i = 0; i < socketchunk.length; i++) {
|
2021-09-04 18:23:58 +00:00
|
|
|
|
2022-01-30 13:16:08 +00:00
|
|
|
//check if data is not empty
|
|
|
|
if(socketchunk[i].length > 0){
|
2022-01-28 19:07:39 +00:00
|
|
|
|
2022-01-30 13:16:08 +00:00
|
|
|
//try to parse JSON
|
|
|
|
try {
|
|
|
|
|
|
|
|
data = JSON.parse(socketchunk[i])
|
|
|
|
|
|
|
|
} catch (e) {
|
2022-02-24 09:13:00 +00:00
|
|
|
socketLog.info(e); // "SyntaxError
|
|
|
|
socketLog.info(socketchunk[i])
|
2022-01-30 13:16:08 +00:00
|
|
|
socketchunk = ''
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-01-28 19:07:39 +00:00
|
|
|
|
2021-08-16 17:39:20 +00:00
|
|
|
|
2022-01-30 13:16:08 +00:00
|
|
|
if (data['command'] == 'tnc_state') {
|
2022-02-24 09:13:00 +00:00
|
|
|
//socketLog.info(data)
|
2022-01-30 13:16:08 +00:00
|
|
|
// set length of RX Buffer to global variable
|
|
|
|
rxBufferLengthTnc = data['rx_buffer_length']
|
|
|
|
rxMsgBufferLengthTnc = data['rx_msg_buffer_length']
|
|
|
|
|
|
|
|
let Data = {
|
2022-12-24 15:44:06 +00:00
|
|
|
mycallsign: data['mycallsign'],
|
2023-01-06 16:33:20 +00:00
|
|
|
mygrid: data['mygrid'],
|
2022-01-30 13:16:08 +00:00
|
|
|
ptt_state: data['ptt_state'],
|
|
|
|
busy_state: data['tnc_state'],
|
|
|
|
arq_state: data['arq_state'],
|
2022-03-04 15:50:32 +00:00
|
|
|
arq_session: data['arq_session'],
|
2022-01-30 13:16:08 +00:00
|
|
|
//channel_state: data['CHANNEL_STATE'],
|
|
|
|
frequency: data['frequency'],
|
2022-02-22 20:05:48 +00:00
|
|
|
speed_level: data['speed_level'],
|
2022-01-30 13:16:08 +00:00
|
|
|
mode: data['mode'],
|
2022-05-28 12:08:33 +00:00
|
|
|
bandwidth: data['bandwidth'],
|
2022-11-18 14:19:41 +00:00
|
|
|
dbfs_level: data['audio_dbfs'],
|
2022-01-30 13:16:08 +00:00
|
|
|
fft: data['fft'],
|
2022-02-15 17:10:14 +00:00
|
|
|
channel_busy: data['channel_busy'],
|
2022-01-30 13:16:08 +00:00
|
|
|
scatter: data['scatter'],
|
|
|
|
info: data['info'],
|
|
|
|
rx_buffer_length: data['rx_buffer_length'],
|
|
|
|
rx_msg_buffer_length: data['rx_msg_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'],
|
|
|
|
arq_bytes_per_minute: data['arq_bytes_per_minute'],
|
2022-12-31 11:59:10 +00:00
|
|
|
arq_seconds_until_finish: data['arq_seconds_until_finish'],
|
2022-01-30 13:16:08 +00:00
|
|
|
arq_compression_factor: data['arq_compression_factor'],
|
|
|
|
total_bytes: data['total_bytes'],
|
|
|
|
arq_transmission_percent: data['arq_transmission_percent'],
|
|
|
|
stations: data['stations'],
|
|
|
|
beacon_state: data['beacon_state'],
|
2022-11-18 12:08:37 +00:00
|
|
|
hamlib_status: data['hamlib_status'],
|
2022-12-26 11:11:59 +00:00
|
|
|
listen: data['listen'],
|
|
|
|
audio_recording: data['audio_recording'],
|
2023-01-12 23:14:42 +00:00
|
|
|
speed_list: data['speed_list'],
|
|
|
|
//speed_table: [{"bpm" : 5200, "snr": -3, "timestamp":1673555399},{"bpm" : 2315, "snr": 12, "timestamp":1673555500}],
|
2022-01-30 13:16:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ipcRenderer.send('request-update-tnc-state', Data);
|
|
|
|
}
|
|
|
|
|
2022-03-14 19:21:15 +00:00
|
|
|
|
2022-06-07 08:08:15 +00:00
|
|
|
// ----------- catch tnc messages START -----------
|
|
|
|
if (data['freedata'] == 'tnc-message'){
|
|
|
|
socketLog.info(data)
|
2022-03-14 19:21:15 +00:00
|
|
|
|
2022-06-07 08:08:15 +00:00
|
|
|
// update transmission status
|
2022-06-09 12:11:39 +00:00
|
|
|
/*
|
|
|
|
if (data['arq'] == 'transmission' && data['status'] == 'transmitting'){
|
2022-03-24 19:49:13 +00:00
|
|
|
|
2022-06-07 08:08:15 +00:00
|
|
|
let state = {
|
|
|
|
status: data['status'],
|
|
|
|
uuid: data['uuid'],
|
|
|
|
percent: data['percent'],
|
|
|
|
bytesperminute: data['bytesperminute'],
|
|
|
|
};
|
2022-01-28 19:07:39 +00:00
|
|
|
|
2022-06-07 08:08:15 +00:00
|
|
|
ipcRenderer.send('request-update-transmission-status', state);
|
2022-01-30 13:16:08 +00:00
|
|
|
}
|
2022-06-09 12:11:39 +00:00
|
|
|
*/
|
2022-06-07 08:08:15 +00:00
|
|
|
|
|
|
|
// CQ TRANSMITTING
|
|
|
|
if (data['cq'] == 'transmitting') {
|
|
|
|
ipcRenderer.send('request-show-cq-toast-transmitting', {data: [data]});
|
2022-01-28 19:07:39 +00:00
|
|
|
}
|
2022-01-30 13:16:08 +00:00
|
|
|
|
2022-06-07 08:08:15 +00:00
|
|
|
// CQ RECEIVED
|
|
|
|
if (data['cq'] == 'received') {
|
|
|
|
ipcRenderer.send('request-show-cq-toast-received', {data: [data]});
|
|
|
|
}
|
|
|
|
|
|
|
|
// QRV TRANSMITTING
|
|
|
|
if (data['qrv'] == 'transmitting') {
|
|
|
|
ipcRenderer.send('request-show-qrv-toast-transmitting', {data: [data]});
|
|
|
|
}
|
|
|
|
|
|
|
|
// QRV RECEIVED
|
|
|
|
if (data['qrv'] == 'received') {
|
|
|
|
ipcRenderer.send('request-show-qrv-toast-received', {data: [data]});
|
|
|
|
}
|
|
|
|
|
|
|
|
// BEACON TRANSMITTING
|
|
|
|
if (data['beacon'] == 'transmitting') {
|
|
|
|
ipcRenderer.send('request-show-beacon-toast-transmitting', {data: [data]});
|
|
|
|
}
|
|
|
|
|
|
|
|
// BEACON RECEIVED
|
|
|
|
if (data['beacon'] == 'received') {
|
|
|
|
ipcRenderer.send('request-show-beacon-toast-received', {data: [data]});
|
|
|
|
ipcRenderer.send('request-new-msg-received', {data: [data]});
|
|
|
|
}
|
|
|
|
|
|
|
|
// PING TRANSMITTING
|
|
|
|
if (data['ping'] == 'transmitting') {
|
|
|
|
ipcRenderer.send('request-show-ping-toast-transmitting', {data: [data]});
|
|
|
|
}
|
|
|
|
|
|
|
|
// PING RECEIVED
|
|
|
|
if (data['ping'] == 'received') {
|
|
|
|
ipcRenderer.send('request-show-ping-toast-received', {data: [data]});
|
|
|
|
ipcRenderer.send('request-new-msg-received', {data: [data]});
|
|
|
|
}
|
|
|
|
|
|
|
|
// PING ACKNOWLEDGE
|
|
|
|
if (data['ping'] == 'acknowledge') {
|
|
|
|
ipcRenderer.send('request-show-ping-toast-received-ack', {data: [data]});
|
|
|
|
ipcRenderer.send('request-new-msg-received', {data: [data]});
|
|
|
|
}
|
|
|
|
|
2022-06-15 08:51:19 +00:00
|
|
|
// ARQ SESSION
|
|
|
|
if (data['arq'] == 'session') {
|
|
|
|
|
|
|
|
// ARQ OPEN
|
|
|
|
if (data['status'] == 'connecting') {
|
|
|
|
ipcRenderer.send('request-show-arq-toast-session-connecting', {data: [data]});
|
|
|
|
|
|
|
|
// ARQ OPENING
|
|
|
|
} else if (data['status'] == 'connected') {
|
|
|
|
ipcRenderer.send('request-show-arq-toast-session-connected', {data: [data]});
|
|
|
|
|
2022-11-17 23:03:18 +00:00
|
|
|
// ARQ OPENING
|
|
|
|
} else if (data['status'] == 'waiting') {
|
|
|
|
ipcRenderer.send('request-show-arq-toast-session-waiting', {data: [data]});
|
|
|
|
|
2022-06-15 08:51:19 +00:00
|
|
|
// ARQ OPENING
|
|
|
|
} else if (data['status'] == 'close') {
|
|
|
|
ipcRenderer.send('request-show-arq-toast-session-close', {data: [data]});
|
|
|
|
|
|
|
|
// ARQ OPENING
|
|
|
|
} else if (data['status'] == 'failed') {
|
|
|
|
ipcRenderer.send('request-show-arq-toast-session-failed', {data: [data]});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
// ARQ TRANSMISSION
|
2022-06-07 08:08:15 +00:00
|
|
|
if (data['arq'] == 'transmission') {
|
|
|
|
|
|
|
|
// ARQ OPEN
|
2022-06-09 12:14:31 +00:00
|
|
|
if (data['status'] == 'opened') {
|
|
|
|
ipcRenderer.send('request-show-arq-toast-datachannel-opened', {data: [data]});
|
2022-06-09 12:11:39 +00:00
|
|
|
|
2022-06-07 08:08:15 +00:00
|
|
|
// ARQ OPENING
|
|
|
|
} else if (data['status'] == 'opening') {
|
|
|
|
ipcRenderer.send('request-show-arq-toast-datachannel-opening', {data: [data]});
|
|
|
|
|
2022-11-17 21:17:50 +00:00
|
|
|
// ARQ WAITING
|
|
|
|
} else if (data['status'] == 'waiting') {
|
|
|
|
ipcRenderer.send('request-show-arq-toast-datachannel-waiting', {data: [data]});
|
|
|
|
|
2022-06-09 12:11:39 +00:00
|
|
|
|
2022-06-07 08:08:15 +00:00
|
|
|
// ARQ TRANSMISSION FAILED
|
|
|
|
} else if (data['status'] == 'failed') {
|
|
|
|
ipcRenderer.send('request-show-arq-toast-transmission-failed', {data: [data]});
|
2022-06-09 12:11:39 +00:00
|
|
|
ipcRenderer.send('request-update-transmission-status', {data: [data]});
|
|
|
|
|
2022-06-07 08:08:15 +00:00
|
|
|
|
|
|
|
// ARQ TRANSMISSION RECEIVED
|
|
|
|
} else if (data['status'] == 'received') {
|
|
|
|
ipcRenderer.send('request-show-arq-toast-transmission-received', {data: [data]});
|
2022-06-09 12:54:42 +00:00
|
|
|
ipcRenderer.send('request-update-transmission-status', {data: [data]});
|
2022-06-07 08:08:15 +00:00
|
|
|
|
2022-06-09 12:11:39 +00:00
|
|
|
dataArray = []
|
|
|
|
messageArray = []
|
|
|
|
|
|
|
|
socketLog.info(data)
|
|
|
|
// we need to encode here to do a deep check for checking if file or message
|
|
|
|
var encoded_data = atob(data['data'])
|
|
|
|
var splitted_data = encoded_data.split(split_char)
|
|
|
|
|
|
|
|
if(splitted_data[0] == 'f'){
|
|
|
|
dataArray.push(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
if(splitted_data[0] == 'm'){
|
|
|
|
messageArray.push(data)
|
|
|
|
console.log(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
rxBufferLengthGui = dataArray.length
|
|
|
|
let Files = {
|
|
|
|
data: dataArray,
|
|
|
|
};
|
|
|
|
ipcRenderer.send('request-update-rx-buffer', Files);
|
|
|
|
ipcRenderer.send('request-new-msg-received', Files);
|
|
|
|
|
|
|
|
rxMsgBufferLengthGui = messageArray.length
|
|
|
|
let Messages = {
|
|
|
|
data: messageArray,
|
|
|
|
};
|
|
|
|
ipcRenderer.send('request-new-msg-received', Messages);
|
|
|
|
|
2022-06-07 08:08:15 +00:00
|
|
|
// ARQ TRANSMISSION TRANSMITTING
|
|
|
|
} else if (data['status'] == 'transmitting') {
|
|
|
|
ipcRenderer.send('request-show-arq-toast-transmission-transmitting', {data: [data]});
|
2022-06-09 12:11:39 +00:00
|
|
|
ipcRenderer.send('request-update-transmission-status', {data: [data]});
|
|
|
|
|
2022-06-07 08:08:15 +00:00
|
|
|
|
|
|
|
// ARQ TRANSMISSION TRANSMITTED
|
|
|
|
} else if (data['status'] == 'transmitted') {
|
|
|
|
ipcRenderer.send('request-show-arq-toast-transmission-transmitted', {data: [data]});
|
2022-06-09 12:11:39 +00:00
|
|
|
ipcRenderer.send('request-update-transmission-status', {data: [data]});
|
2022-06-07 08:08:15 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-30 13:16:08 +00:00
|
|
|
}
|
2022-06-09 12:11:39 +00:00
|
|
|
|
2022-06-07 08:08:15 +00:00
|
|
|
// ----------- catch tnc info messages END -----------
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-03-12 14:06:49 +00:00
|
|
|
// if we manually checking for the rx buffer we are getting an array of multiple data
|
2022-01-30 13:16:08 +00:00
|
|
|
if (data['command'] == 'rx_buffer') {
|
2022-03-12 14:06:49 +00:00
|
|
|
socketLog.info(data)
|
2022-01-30 13:16:08 +00:00
|
|
|
// iterate through buffer list and sort it to file or message array
|
|
|
|
dataArray = []
|
|
|
|
messageArray = []
|
|
|
|
|
|
|
|
for (i = 0; i < data['data-array'].length; i++) {
|
|
|
|
try{
|
2022-03-12 14:06:49 +00:00
|
|
|
// we need to encode here to do a deep check for checking if file or message
|
2022-02-02 20:12:16 +00:00
|
|
|
var encoded_data = atob(data['data-array'][i]['data'])
|
|
|
|
var splitted_data = encoded_data.split(split_char)
|
|
|
|
|
|
|
|
|
|
|
|
if(splitted_data[0] == 'f'){
|
|
|
|
dataArray.push(data['data-array'][i])
|
2022-02-08 14:27:34 +00:00
|
|
|
|
2022-01-30 13:16:08 +00:00
|
|
|
}
|
|
|
|
|
2022-02-02 20:12:16 +00:00
|
|
|
if(splitted_data[0] == 'm'){
|
2022-01-30 13:16:08 +00:00
|
|
|
messageArray.push(data['data-array'][i])
|
2022-02-08 14:27:34 +00:00
|
|
|
|
2022-01-30 13:16:08 +00:00
|
|
|
}
|
2022-02-02 20:12:16 +00:00
|
|
|
|
2022-01-30 13:16:08 +00:00
|
|
|
} catch (e) {
|
2022-02-24 09:13:00 +00:00
|
|
|
socketLog.info(e)
|
2022-01-30 13:16:08 +00:00
|
|
|
}
|
2022-01-28 19:07:39 +00:00
|
|
|
}
|
2022-01-30 13:16:08 +00:00
|
|
|
|
|
|
|
|
2022-01-28 19:07:39 +00:00
|
|
|
|
2022-01-30 13:16:08 +00:00
|
|
|
rxBufferLengthGui = dataArray.length
|
|
|
|
let Files = {
|
|
|
|
data: dataArray,
|
|
|
|
};
|
|
|
|
ipcRenderer.send('request-update-rx-buffer', Files);
|
2022-01-28 19:07:39 +00:00
|
|
|
|
2022-01-30 13:16:08 +00:00
|
|
|
rxMsgBufferLengthGui = messageArray.length
|
|
|
|
let Messages = {
|
|
|
|
data: messageArray,
|
|
|
|
};
|
2022-03-12 14:06:49 +00:00
|
|
|
//ipcRenderer.send('request-update-rx-msg-buffer', Messages);
|
|
|
|
ipcRenderer.send('request-new-msg-received', Messages);
|
|
|
|
|
2022-01-30 13:16:08 +00:00
|
|
|
|
2022-01-28 19:07:39 +00:00
|
|
|
}
|
2021-11-19 17:49:36 +00:00
|
|
|
|
2021-10-17 14:59:15 +00:00
|
|
|
}
|
2022-01-30 13:16:08 +00:00
|
|
|
|
|
|
|
//finally delete message buffer
|
|
|
|
socketchunk = '';
|
|
|
|
|
2021-07-17 07:03:40 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function hexToBytes(hex) {
|
|
|
|
for (var bytes = [], c = 0; c < hex.length; c += 2)
|
2021-07-24 07:06:22 +00:00
|
|
|
bytes.push(parseInt(hex.substr(c, 2), 16));
|
2021-07-17 07:03:40 +00:00
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-19 19:01:38 +00:00
|
|
|
//Get TNC State
|
2021-07-24 07:06:22 +00:00
|
|
|
exports.getTncState = function() {
|
2022-01-28 19:07:39 +00:00
|
|
|
command = '{"type" : "get", "command" : "tnc_state"}';
|
2021-07-24 07:06:22 +00:00
|
|
|
writeTncCommand(command)
|
2021-07-17 07:03:40 +00:00
|
|
|
}
|
2021-07-19 19:01:38 +00:00
|
|
|
|
2021-07-23 15:40:44 +00:00
|
|
|
//Get DATA State
|
2021-07-24 07:06:22 +00:00
|
|
|
exports.getDataState = function() {
|
2022-01-28 19:07:39 +00:00
|
|
|
command = '{"type" : "get", "command" : "data_state"}';
|
2021-07-25 16:19:51 +00:00
|
|
|
//writeTncCommand(command)
|
2021-07-23 15:40:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-19 19:01:38 +00:00
|
|
|
// Send Ping
|
2021-07-24 07:06:22 +00:00
|
|
|
exports.sendPing = function(dxcallsign) {
|
2022-01-28 19:07:39 +00:00
|
|
|
command = '{"type" : "ping", "command" : "ping", "dxcallsign" : "' + dxcallsign + '"}'
|
2021-07-24 07:06:22 +00:00
|
|
|
writeTncCommand(command)
|
2021-07-19 19:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Send CQ
|
2021-07-24 07:06:22 +00:00
|
|
|
exports.sendCQ = function() {
|
2022-01-28 19:07:39 +00:00
|
|
|
command = '{"type" : "broadcast", "command" : "cqcqcq"}'
|
2021-07-24 07:06:22 +00:00
|
|
|
writeTncCommand(command)
|
2021-07-26 16:09:04 +00:00
|
|
|
}
|
|
|
|
|
2022-03-31 19:13:30 +00:00
|
|
|
// Set AUDIO Level
|
|
|
|
exports.setTxAudioLevel = function(value) {
|
|
|
|
command = '{"type" : "set", "command" : "tx_audio_level", "value" : "'+ value +'"}'
|
|
|
|
writeTncCommand(command)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-07-26 16:09:04 +00:00
|
|
|
// Send File
|
|
|
|
exports.sendFile = function(dxcallsign, mode, frames, filename, filetype, data, checksum) {
|
2022-02-02 20:12:16 +00:00
|
|
|
|
2022-02-24 09:13:00 +00:00
|
|
|
socketLog.info(data)
|
|
|
|
socketLog.info(filetype)
|
|
|
|
socketLog.info(filename)
|
2022-02-02 20:12:16 +00:00
|
|
|
|
|
|
|
var datatype = "f"
|
|
|
|
|
|
|
|
data = datatype + split_char + filename + split_char + filetype + split_char + checksum + split_char + data
|
2022-02-24 09:13:00 +00:00
|
|
|
socketLog.info(data)
|
|
|
|
socketLog.info(btoa(data))
|
2022-02-02 20:12:16 +00:00
|
|
|
data = btoa(data)
|
2022-03-03 19:40:52 +00:00
|
|
|
|
2022-02-02 20:12:16 +00:00
|
|
|
command = '{"type" : "arq", "command" : "send_raw", "parameter" : [{"dxcallsign" : "' + dxcallsign + '", "mode" : "' + mode + '", "n_frames" : "' + frames + '", "data" : "' + data + '"}]}'
|
2021-07-26 16:09:04 +00:00
|
|
|
writeTncCommand(command)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send Message
|
2022-03-14 19:21:15 +00:00
|
|
|
exports.sendMessage = function(dxcallsign, mode, frames, data, checksum, uuid, command) {
|
2022-12-27 22:30:15 +00:00
|
|
|
//socketLog.info(data)
|
2022-12-27 08:53:21 +00:00
|
|
|
|
|
|
|
// Disabled this here
|
2022-03-14 19:21:15 +00:00
|
|
|
// convert message to plain utf8 because of unicode emojis
|
2022-12-27 08:53:21 +00:00
|
|
|
//data = utf8.encode(data)
|
|
|
|
|
|
|
|
//socketLog.info(data)
|
|
|
|
|
2022-03-14 19:21:15 +00:00
|
|
|
|
2022-03-03 19:40:52 +00:00
|
|
|
var datatype = "m"
|
2022-03-14 19:21:15 +00:00
|
|
|
data = datatype + split_char + command + split_char + checksum + split_char + uuid + split_char + data
|
2022-12-27 22:30:15 +00:00
|
|
|
//socketLog.info(data)
|
|
|
|
console.log(data)
|
|
|
|
|
|
|
|
console.log("CHECKSUM" + checksum)
|
|
|
|
//socketLog.info(btoa(data))
|
2022-03-03 19:40:52 +00:00
|
|
|
data = btoa(data)
|
|
|
|
|
2022-12-27 22:30:15 +00:00
|
|
|
|
2022-03-03 19:40:52 +00:00
|
|
|
//command = '{"type" : "arq", "command" : "send_message", "parameter" : [{ "dxcallsign" : "' + dxcallsign + '", "mode" : "' + mode + '", "n_frames" : "' + frames + '", "data" : "' + data + '" , "checksum" : "' + checksum + '"}]}'
|
2022-11-20 10:54:43 +00:00
|
|
|
command = '{"type" : "arq", "command" : "send_raw", "uuid" : "'+ uuid +'", "parameter" : [{"dxcallsign" : "' + dxcallsign + '", "mode" : "' + mode + '", "n_frames" : "' + frames + '", "data" : "' + data + '", "attempts": "15"}]}'
|
2022-03-12 14:06:49 +00:00
|
|
|
socketLog.info(command)
|
|
|
|
socketLog.info("-------------------------------------")
|
2021-07-26 16:09:04 +00:00
|
|
|
writeTncCommand(command)
|
2021-08-15 15:30:50 +00:00
|
|
|
}
|
|
|
|
|
2021-10-02 09:29:08 +00:00
|
|
|
|
|
|
|
//STOP TRANSMISSION
|
|
|
|
exports.stopTransmission = function() {
|
2022-01-28 19:07:39 +00:00
|
|
|
command = '{"type" : "arq", "command": "stop_transmission"}'
|
2021-10-02 09:29:08 +00:00
|
|
|
writeTncCommand(command)
|
|
|
|
}
|
|
|
|
|
2021-08-15 15:30:50 +00:00
|
|
|
// Get RX BUffer
|
|
|
|
exports.getRxBuffer = function() {
|
2022-01-28 19:07:39 +00:00
|
|
|
command = '{"type" : "get", "command" : "rx_buffer"}'
|
2021-08-23 14:24:49 +00:00
|
|
|
|
|
|
|
// call command only if new data arrived
|
2021-09-04 18:23:58 +00:00
|
|
|
if (rxBufferLengthGui != rxBufferLengthTnc) {
|
2021-08-23 14:24:49 +00:00
|
|
|
writeTncCommand(command)
|
|
|
|
}
|
2021-09-05 09:26:09 +00:00
|
|
|
}
|
2021-10-17 14:59:15 +00:00
|
|
|
|
2021-11-19 17:49:36 +00:00
|
|
|
|
2021-12-06 19:16:14 +00:00
|
|
|
// START BEACON
|
|
|
|
exports.startBeacon = function(interval) {
|
2022-01-28 19:07:39 +00:00
|
|
|
command = '{"type" : "broadcast", "command" : "start_beacon", "parameter": "' + interval + '"}'
|
2021-12-06 19:16:14 +00:00
|
|
|
writeTncCommand(command)
|
|
|
|
}
|
|
|
|
|
|
|
|
// STOP BEACON
|
|
|
|
exports.stopBeacon = function() {
|
2022-01-28 19:07:39 +00:00
|
|
|
command = '{"type" : "broadcast", "command" : "stop_beacon"}'
|
2021-12-06 19:16:14 +00:00
|
|
|
writeTncCommand(command)
|
|
|
|
}
|
2021-11-19 17:49:36 +00:00
|
|
|
|
2022-03-04 15:50:32 +00:00
|
|
|
// OPEN ARQ SESSION
|
|
|
|
exports.connectARQ = function(dxcallsign) {
|
2022-11-20 10:54:43 +00:00
|
|
|
command = '{"type" : "arq", "command" : "connect", "dxcallsign": "'+ dxcallsign + '", "attempts": "15"}'
|
2022-03-04 15:50:32 +00:00
|
|
|
writeTncCommand(command)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CLOSE ARQ SESSION
|
|
|
|
exports.disconnectARQ = function() {
|
|
|
|
command = '{"type" : "arq", "command" : "disconnect"}'
|
|
|
|
writeTncCommand(command)
|
|
|
|
}
|
2022-03-31 19:13:30 +00:00
|
|
|
|
2022-11-20 10:44:29 +00:00
|
|
|
// SEND TEST FRAME
|
2022-03-31 19:13:30 +00:00
|
|
|
exports.sendTestFrame = function() {
|
|
|
|
command = '{"type" : "set", "command" : "send_test_frame"}'
|
|
|
|
writeTncCommand(command)
|
|
|
|
}
|
2022-11-25 11:04:15 +00:00
|
|
|
|
2022-12-26 11:27:13 +00:00
|
|
|
// RECORD AUDIO
|
|
|
|
exports.record_audio = function() {
|
|
|
|
command = '{"type" : "set", "command" : "record_audio"}'
|
|
|
|
writeTncCommand(command)
|
|
|
|
}
|
2022-11-25 11:04:15 +00:00
|
|
|
|
2023-01-04 18:26:11 +00:00
|
|
|
// SET FREQUENCY
|
|
|
|
exports.set_frequency = function(frequency) {
|
|
|
|
command = '{"type" : "set", "command" : "frequency", "frequency": '+ frequency +'}'
|
|
|
|
writeTncCommand(command)
|
|
|
|
}
|
|
|
|
|
2023-01-04 19:12:03 +00:00
|
|
|
// SET MODE
|
|
|
|
exports.set_mode = function(mode) {
|
|
|
|
command = '{"type" : "set", "command" : "mode", "mode": "'+ mode +'"}'
|
|
|
|
console.log(command)
|
|
|
|
writeTncCommand(command)
|
|
|
|
}
|
|
|
|
|
2022-11-25 11:04:15 +00:00
|
|
|
ipcRenderer.on('action-update-tnc-ip', (event, arg) => {
|
|
|
|
client.destroy();
|
|
|
|
let Data = {
|
|
|
|
busy_state: "-",
|
|
|
|
arq_state: "-",
|
|
|
|
//channel_state: "-",
|
|
|
|
frequency: "-",
|
|
|
|
mode: "-",
|
|
|
|
bandwidth: "-",
|
|
|
|
dbfs_level: 0
|
|
|
|
};
|
|
|
|
ipcRenderer.send('request-update-tnc-state', Data);
|
|
|
|
tnc_port = arg.port;
|
|
|
|
tnc_host = arg.adress;
|
|
|
|
connectTNC();
|
|
|
|
|
2022-12-27 21:57:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// https://stackoverflow.com/a/50579690
|
|
|
|
// crc32 calculation
|
|
|
|
//console.log(crc32('abc'));
|
|
|
|
//console.log(crc32('abc').toString(16).toUpperCase()); // hex
|
|
|
|
var crc32=function(r){for(var a,o=[],c=0;c<256;c++){a=c;for(var f=0;f<8;f++)a=1&a?3988292384^a>>>1:a>>>1;o[c]=a}for(var n=-1,t=0;t<r.length;t++)n=n>>>8^o[255&(n^r.charCodeAt(t))];return(-1^n)>>>0};
|