Skip to content

Commit c72b95b

Browse files
committed
Added 2nd port (16020)
1 parent 56fe392 commit c72b95b

File tree

1 file changed

+78
-74
lines changed

1 file changed

+78
-74
lines changed

main.js

Lines changed: 78 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -251,85 +251,90 @@ function send2wavelog(o_cfg,adif, dryrun = false) {
251251

252252
}
253253

254-
WServer = udp.createSocket('udp4');
255-
WServer.on('error', function(err) {
256-
tomsg('Some other Tool blocks Port 2333. Stop it, and restart this');
257-
});
254+
const ports = [2333, 16020]; // Liste der Ports, an die Sie binden möchten
258255

259-
WServer.on('message',async function(msg,info){
260-
parsedXML={};
261-
adobject={};
262-
if (msg.toString().includes("xml")) { // detect if incoming String is XML
263-
try {
264-
xml.parseString(msg.toString(), function (err,dat) {
265-
parsedXML=dat;
266-
});
267-
let qsodatum = new Date(Date.parse(parsedXML.contactinfo.timestamp[0]+"Z")); // Added Z to make it UTC
268-
qsodat=fmt(qsodatum);
269-
if (parsedXML.contactinfo.mode[0] == 'USB' || parsedXML.contactinfo.mode[0] == 'LSB') { // TCADIF lib is not capable of using USB/LSB
270-
parsedXML.contactinfo.mode[0]='SSB';
256+
ports.forEach(port => {
257+
WServer = udp.createSocket('udp4');
258+
WServer.on('error', function(err) {
259+
tomsg('Some other Tool blocks Port '+port+'. Stop it, and restart this');
260+
});
261+
262+
WServer.on('message',async function(msg,info){
263+
parsedXML={};
264+
adobject={};
265+
if (msg.toString().includes("xml")) { // detect if incoming String is XML
266+
try {
267+
xml.parseString(msg.toString(), function (err,dat) {
268+
parsedXML=dat;
269+
});
270+
let qsodatum = new Date(Date.parse(parsedXML.contactinfo.timestamp[0]+"Z")); // Added Z to make it UTC
271+
qsodat=fmt(qsodatum);
272+
if (parsedXML.contactinfo.mode[0] == 'USB' || parsedXML.contactinfo.mode[0] == 'LSB') { // TCADIF lib is not capable of using USB/LSB
273+
parsedXML.contactinfo.mode[0]='SSB';
274+
}
275+
adobject = { qsos: [
276+
{
277+
CALL: parsedXML.contactinfo.call[0],
278+
MODE: parsedXML.contactinfo.mode[0],
279+
QSO_DATE_OFF: qsodat.d,
280+
QSO_DATE: qsodat.d,
281+
TIME_OFF: qsodat.t,
282+
TIME_ON: qsodat.t,
283+
RST_RCVD: parsedXML.contactinfo.rcv[0],
284+
RST_SENT: parsedXML.contactinfo.snt[0],
285+
FREQ: ((1*parseInt(parsedXML.contactinfo.txfreq[0]))/100000).toString(),
286+
FREQ_RX: ((1*parseInt(parsedXML.contactinfo.rxfreq[0]))/100000).toString(),
287+
OPERATOR: parsedXML.contactinfo.operator[0],
288+
COMMENT: parsedXML.contactinfo.comment[0],
289+
POWER: parsedXML.contactinfo.power[0],
290+
STX: parsedXML.contactinfo.sntnr[0],
291+
RTX: parsedXML.contactinfo.rcvnr[0],
292+
MYCALL: parsedXML.contactinfo.mycall[0],
293+
GRIDSQUARE: parsedXML.contactinfo.gridsquare[0],
294+
STATION_CALLSIGN: parsedXML.contactinfo.mycall[0]
295+
} ]};
296+
} catch (e) {}
297+
} else {
298+
try {
299+
adobject=parseADIF(msg.toString());
300+
} catch(e) {
301+
tomsg('<div class="alert alert-danger" role="alert">Received broken ADIF</div>');
302+
return;
271303
}
272-
adobject = { qsos: [
273-
{
274-
CALL: parsedXML.contactinfo.call[0],
275-
MODE: parsedXML.contactinfo.mode[0],
276-
QSO_DATE_OFF: qsodat.d,
277-
QSO_DATE: qsodat.d,
278-
TIME_OFF: qsodat.t,
279-
TIME_ON: qsodat.t,
280-
RST_RCVD: parsedXML.contactinfo.rcv[0],
281-
RST_SENT: parsedXML.contactinfo.snt[0],
282-
FREQ: ((1*parseInt(parsedXML.contactinfo.txfreq[0]))/100000).toString(),
283-
FREQ_RX: ((1*parseInt(parsedXML.contactinfo.rxfreq[0]))/100000).toString(),
284-
OPERATOR: parsedXML.contactinfo.operator[0],
285-
COMMENT: parsedXML.contactinfo.comment[0],
286-
POWER: parsedXML.contactinfo.power[0],
287-
STX: parsedXML.contactinfo.sntnr[0],
288-
RTX: parsedXML.contactinfo.rcvnr[0],
289-
MYCALL: parsedXML.contactinfo.mycall[0],
290-
GRIDSQUARE: parsedXML.contactinfo.gridsquare[0],
291-
STATION_CALLSIGN: parsedXML.contactinfo.mycall[0]
292-
} ]};
293-
} catch (e) {}
294-
} else {
295-
try {
296-
adobject=parseADIF(msg.toString());
297-
} catch(e) {
298-
tomsg('<div class="alert alert-danger" role="alert">Received broken ADIF</div>');
299-
return;
300304
}
301-
}
302-
var plainret='';
303-
if (adobject.qsos.length>0) {
304-
let x={};
305-
try {
306-
outadif=writeADIF(adobject);
307-
plainret=await send2wavelog(defaultcfg,outadif.stringify());
308-
x.state=plainret.statusCode;
309-
x.payload = JSON.parse(plainret.resString);
310-
} catch(e) {
305+
var plainret='';
306+
if (adobject.qsos.length>0) {
307+
let x={};
311308
try {
312-
x.payload=JSON.parse(e.resString);
313-
} catch (ee) {
314-
x.state=e.statusCode;
315-
x.payload={};
316-
x.payload.string=e.resString;
317-
x.payload.status='bug';
318-
} finally {
319-
x.payload.status='bug';
309+
outadif=writeADIF(adobject);
310+
plainret=await send2wavelog(defaultcfg,outadif.stringify());
311+
x.state=plainret.statusCode;
312+
x.payload = JSON.parse(plainret.resString);
313+
} catch(e) {
314+
try {
315+
x.payload=JSON.parse(e.resString);
316+
} catch (ee) {
317+
x.state=e.statusCode;
318+
x.payload={};
319+
x.payload.string=e.resString;
320+
x.payload.status='bug';
321+
} finally {
322+
x.payload.status='bug';
323+
}
320324
}
321-
}
322-
if (x.payload.status == 'created') {
323-
adobject.created=true;
325+
if (x.payload.status == 'created') {
326+
adobject.created=true;
327+
} else {
328+
adobject.created=false;
329+
adobject.fail=x;
330+
}
331+
s_mainWindow.webContents.send('updateTX', adobject);
332+
tomsg('');
324333
} else {
325-
adobject.created=false;
326-
adobject.fail=x;
334+
tomsg('<div class="alert alert-danger" role="alert">Set ONLY Secondary UDP-Server to Port 2333 at WSTJ-X</div>');
327335
}
328-
s_mainWindow.webContents.send('updateTX', adobject);
329-
tomsg('');
330-
} else {
331-
tomsg('<div class="alert alert-danger" role="alert">Set ONLY Secondary UDP-Server to Port 2333 at WSTJ-X</div>');
332-
}
336+
});
337+
WServer.bind(port);
333338
});
334339

335340
function tomsg(msg) {
@@ -342,8 +347,7 @@ function tomsg(msg) {
342347

343348
function startserver() {
344349
try {
345-
WServer.bind(2333);
346-
tomsg('Waiting for QSO / Listening on UDP 2333');
350+
tomsg('Waiting for QSO / Listening on UDP 2333/16020');
347351
http.createServer(function (req, res) {
348352
res.setHeader('Access-Control-Allow-Origin', '*');
349353
res.writeHead(200, {'Content-Type': 'text/plain'});

0 commit comments

Comments
 (0)