@@ -252,15 +252,50 @@ app.on('window-all-closed', function () {
252252 app . quit ( ) ;
253253} )
254254
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+
255289function parseADIF ( adifdata ) {
256290 const { ADIF } = require ( "tcadif" ) ;
257- var adiReader = ADIF . parse ( adifdata ) ;
291+ const normalizedData = manipulateAdifData ( adifdata ) ;
292+ const adiReader = ADIF . parse ( normalizedData ) ;
258293 return adiReader . toObject ( ) ;
259294}
260295
261296function writeADIF ( adifObject ) {
262297 const { ADIF } = require ( "tcadif" ) ;
263- var adiWriter = new ADIF ( adifObject ) ;
298+ const adiWriter = new ADIF ( adifObject ) ;
264299 return adiWriter ;
265300}
266301
0 commit comments