@@ -9,6 +9,7 @@ let powerSaveBlockerId;
9
9
let tray ;
10
10
let s_mainWindow ;
11
11
let msgbacklog = [ ] ;
12
+ let httpServer ;
12
13
var WServer ;
13
14
14
15
const DemoAdif = '<call:5>DJ7NT <gridsquare:4>JO30 <mode:3>FT8 <rst_sent:3>-15 <rst_rcvd:2>33 <qso_date:8>20240110 <time_on:6>051855 <qso_date_off:8>20240110 <time_off:6>051855 <band:3>40m <freq:8>7.155783 <station_callsign:5>TE1ST <my_gridsquare:6>JO30OO <eor>' ;
@@ -21,7 +22,7 @@ var q={};
21
22
var defaultcfg = {
22
23
wavelog_url : "https://log.jo30.de/index.php" ,
23
24
wavelog_key : "mykey" ,
24
- wavelog_id : 0 ,
25
+ wavelog_id : "0" ,
25
26
wavelog_radioname : 'WLGate' ,
26
27
wavelog_pmode : true ,
27
28
flrig_host : '127.0.0.1' ,
@@ -144,7 +145,7 @@ ipcMain.on("quit", async (event,arg) => {
144
145
function show_noti ( arg ) {
145
146
try {
146
147
const notification = new Notification ( {
147
- title : 'Waevlog ' ,
148
+ title : 'Wavelog ' ,
148
149
body : arg
149
150
} ) ;
150
151
notification . show ( ) ;
@@ -175,9 +176,23 @@ ipcMain.on("test", async (event,arg) => {
175
176
} ) ;
176
177
177
178
app . on ( 'before-quit' , ( ) => {
178
- if ( tray ) {
179
- tray . destroy ( ) ;
180
- }
179
+ console . log ( 'Shutting down servers...' ) ;
180
+ if ( WServer ) {
181
+ WServer . close ( ) ;
182
+ }
183
+ if ( httpServer ) {
184
+ httpServer . close ( ) ;
185
+ }
186
+ if ( tray ) {
187
+ tray . destroy ( ) ;
188
+ }
189
+ } ) ;
190
+
191
+ process . on ( 'SIGINT' , ( ) => {
192
+ console . log ( 'SIGINT received, closing servers...' ) ;
193
+ if ( WServer ) WServer . close ( ) ;
194
+ if ( httpServer ) httpServer . close ( ) ;
195
+ process . exit ( 0 ) ;
181
196
} ) ;
182
197
183
198
app . on ( 'will-quit' , ( ) => {
@@ -237,15 +252,50 @@ app.on('window-all-closed', function () {
237
252
app . quit ( ) ;
238
253
} )
239
254
255
+ function normalizeTxPwr ( adifdata ) {
256
+ return adifdata . replace ( / < T X _ P W R : ( \d + ) > ( [ ^ < ] + ) / gi, ( match , length , value ) => {
257
+ const cleanValue = value . trim ( ) . toLowerCase ( ) ;
258
+
259
+ const numMatch = cleanValue . match ( / ^ ( \d + (?: \. \d + ) ? ) / ) ;
260
+ if ( ! numMatch ) return match ; // not a valid number, return original match
261
+
262
+ let watts = parseFloat ( numMatch [ 1 ] ) ;
263
+
264
+ // get the unit if present
265
+ if ( cleanValue . includes ( 'kw' ) ) {
266
+ watts *= 1000 ;
267
+ } else if ( cleanValue . includes ( 'mw' ) ) {
268
+ watts *= 0.001 ;
269
+ }
270
+ // if it's just 'w' we assume it's already in watts
271
+ // would be equal to
272
+ // } else if (cleanValue.includes('w')) {
273
+ // watts *= 1;
274
+ // }
275
+
276
+ // get the new length and return the new TX_PWR tag
277
+ const newValue = watts . toString ( ) ;
278
+ return `<TX_PWR:${ newValue . length } >${ newValue } ` ;
279
+ } ) ;
280
+ }
281
+
282
+ function manipulateAdifData ( adifdata ) {
283
+ adifdata = normalizeTxPwr ( adifdata ) ;
284
+ // add more manipulation if necessary here
285
+ // ...
286
+ return adifdata ;
287
+ }
288
+
240
289
function parseADIF ( adifdata ) {
241
290
const { ADIF } = require ( "tcadif" ) ;
242
- var adiReader = ADIF . parse ( adifdata ) ;
291
+ const normalizedData = manipulateAdifData ( adifdata ) ;
292
+ const adiReader = ADIF . parse ( normalizedData ) ;
243
293
return adiReader . toObject ( ) ;
244
294
}
245
295
246
296
function writeADIF ( adifObject ) {
247
297
const { ADIF } = require ( "tcadif" ) ;
248
- var adiWriter = new ADIF ( adifObject ) ;
298
+ const adiWriter = new ADIF ( adifObject ) ;
249
299
return adiWriter ;
250
300
}
251
301
@@ -407,7 +457,7 @@ ports.forEach(port => {
407
457
s_mainWindow . webContents . send ( 'updateTX' , adobject ) ;
408
458
tomsg ( '' ) ;
409
459
} else {
410
- tomsg ( '<div class="alert alert-danger" role="alert">Set ONLY Secondary UDP-Server to Port 2333 at WSTJ -X</div>' ) ;
460
+ tomsg ( '<div class="alert alert-danger" role="alert">Set ONLY Secondary UDP-Server to Port 2333 at WSJT -X</div>' ) ;
411
461
}
412
462
} ) ;
413
463
WServer . bind ( port ) ;
@@ -424,27 +474,33 @@ function tomsg(msg) {
424
474
function startserver ( ) {
425
475
try {
426
476
tomsg ( 'Waiting for QSO / Listening on UDP 2333' ) ;
427
- http . createServer ( function ( req , res ) {
477
+ httpServer = http . createServer ( function ( req , res ) {
428
478
res . setHeader ( 'Access-Control-Allow-Origin' , '*' ) ;
429
479
res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ;
430
480
res . end ( '' ) ;
431
- let qrg = req . url . substr ( 1 ) ;
481
+ let parts = req . url . substr ( 1 ) . split ( '/' ) ;
482
+ let qrg = parts [ 0 ] ;
483
+ let mode = parts [ 1 ] || '' ;
432
484
if ( Number . isInteger ( Number . parseInt ( qrg ) ) ) {
433
- settrx ( qrg ) ;
485
+ settrx ( qrg , mode ) ;
434
486
}
435
487
} ) . listen ( 54321 ) ;
436
488
} catch ( e ) {
437
489
tomsg ( 'Some other Tool blocks Port 2333 or 54321. Stop it, and restart this' ) ;
438
490
}
439
491
}
440
492
441
- async function settrx ( qrg ) {
493
+ async function settrx ( qrg , mode = '' ) {
442
494
let to = { } ;
443
495
to . qrg = qrg ;
444
- if ( ( to . qrg ) < 7999000 ) {
445
- to . mode = 'LSB ' ;
496
+ if ( mode == 'cw' ) {
497
+ to . mode = 'CW ' ;
446
498
} else {
447
- to . mode = 'USB' ;
499
+ if ( ( to . qrg ) < 7999000 ) {
500
+ to . mode = 'LSB' ;
501
+ } else {
502
+ to . mode = 'USB' ;
503
+ }
448
504
}
449
505
if ( defaultcfg . profiles [ defaultcfg . profile ?? 0 ] . flrig_ena ) {
450
506
postData = '<?xml version="1.0"?>' ;
0 commit comments