@@ -9,6 +9,7 @@ let powerSaveBlockerId;
99let tray ;
1010let s_mainWindow ;
1111let msgbacklog = [ ] ;
12+ let httpServer ;
1213var WServer ;
1314
1415const 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={};
2122var defaultcfg = {
2223 wavelog_url : "https://log.jo30.de/index.php" ,
2324 wavelog_key : "mykey" ,
24- wavelog_id : 0 ,
25+ wavelog_id : "0" ,
2526 wavelog_radioname : 'WLGate' ,
2627 wavelog_pmode : true ,
2728 flrig_host : '127.0.0.1' ,
@@ -144,7 +145,7 @@ ipcMain.on("quit", async (event,arg) => {
144145function show_noti ( arg ) {
145146 try {
146147 const notification = new Notification ( {
147- title : 'Waevlog ' ,
148+ title : 'Wavelog ' ,
148149 body : arg
149150 } ) ;
150151 notification . show ( ) ;
@@ -175,9 +176,23 @@ ipcMain.on("test", async (event,arg) => {
175176} ) ;
176177
177178app . 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 ) ;
181196} ) ;
182197
183198app . on ( 'will-quit' , ( ) => {
@@ -237,15 +252,50 @@ app.on('window-all-closed', function () {
237252 app . quit ( ) ;
238253} )
239254
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+
240289function parseADIF ( adifdata ) {
241290 const { ADIF } = require ( "tcadif" ) ;
242- var adiReader = ADIF . parse ( adifdata ) ;
291+ const normalizedData = manipulateAdifData ( adifdata ) ;
292+ const adiReader = ADIF . parse ( normalizedData ) ;
243293 return adiReader . toObject ( ) ;
244294}
245295
246296function writeADIF ( adifObject ) {
247297 const { ADIF } = require ( "tcadif" ) ;
248- var adiWriter = new ADIF ( adifObject ) ;
298+ const adiWriter = new ADIF ( adifObject ) ;
249299 return adiWriter ;
250300}
251301
@@ -407,7 +457,7 @@ ports.forEach(port => {
407457 s_mainWindow . webContents . send ( 'updateTX' , adobject ) ;
408458 tomsg ( '' ) ;
409459 } 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>' ) ;
411461 }
412462 } ) ;
413463 WServer . bind ( port ) ;
@@ -424,27 +474,33 @@ function tomsg(msg) {
424474function startserver ( ) {
425475 try {
426476 tomsg ( 'Waiting for QSO / Listening on UDP 2333' ) ;
427- http . createServer ( function ( req , res ) {
477+ httpServer = http . createServer ( function ( req , res ) {
428478 res . setHeader ( 'Access-Control-Allow-Origin' , '*' ) ;
429479 res . writeHead ( 200 , { 'Content-Type' : 'text/plain' } ) ;
430480 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 ] || '' ;
432484 if ( Number . isInteger ( Number . parseInt ( qrg ) ) ) {
433- settrx ( qrg ) ;
485+ settrx ( qrg , mode ) ;
434486 }
435487 } ) . listen ( 54321 ) ;
436488 } catch ( e ) {
437489 tomsg ( 'Some other Tool blocks Port 2333 or 54321. Stop it, and restart this' ) ;
438490 }
439491}
440492
441- async function settrx ( qrg ) {
493+ async function settrx ( qrg , mode = '' ) {
442494 let to = { } ;
443495 to . qrg = qrg ;
444- if ( ( to . qrg ) < 7999000 ) {
445- to . mode = 'LSB ' ;
496+ if ( mode == 'cw' ) {
497+ to . mode = 'CW ' ;
446498 } else {
447- to . mode = 'USB' ;
499+ if ( ( to . qrg ) < 7999000 ) {
500+ to . mode = 'LSB' ;
501+ } else {
502+ to . mode = 'USB' ;
503+ }
448504 }
449505 if ( defaultcfg . profiles [ defaultcfg . profile ?? 0 ] . flrig_ena ) {
450506 postData = '<?xml version="1.0"?>' ;
0 commit comments