-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- currently only parsing POS (not sure if there's others) - refactored H1 Helper to pull up common methods - fixed H1 to stop parsing when message type isn't known - fixed route generation for /PS
- Loading branch information
Showing
6 changed files
with
308 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { decode } from 'punycode'; | ||
import { MessageDecoder } from '../MessageDecoder'; | ||
import { Label_H1_Slash } from './Label_H1_Slash'; | ||
|
||
describe('Label H1 /', () => { | ||
let plugin: Label_H1_Slash; | ||
|
||
beforeEach(() => { | ||
const decoder = new MessageDecoder(); | ||
plugin = new Label_H1_Slash(decoder); | ||
}); | ||
|
||
test('matches qualifiers', () => { | ||
expect(plugin.decode).toBeDefined(); | ||
expect(plugin.name).toBe('label-h1-slash'); | ||
expect(plugin.qualifiers).toBeDefined(); | ||
expect(plugin.qualifiers()).toEqual({ | ||
labels: ['H1'], | ||
preambles: ['/'], | ||
}); | ||
}); | ||
|
||
test('decodes variant 1', () => { | ||
// https://app.airframes.io/messages/2500488708 | ||
const text = '/.POS/TS100316,210324/PSS35333W058220,,100316,250,S37131W059150,101916,S39387W060377,M23,27282,241,780,MANUAL,0,813E711'; | ||
const decodeResult = plugin.decode({ text: text }); | ||
|
||
expect(decodeResult.decoded).toBe(true); | ||
expect(decodeResult.decoder.decodeLevel).toBe('partial'); | ||
expect(decodeResult.formatted.description).toBe('Position Report'); | ||
expect(decodeResult.raw.message_timestamp).toBe(1711015396); | ||
expect(decodeResult.formatted.items.length).toBe(5); | ||
expect(decodeResult.formatted.items[0].label).toBe('Aircraft Position'); | ||
expect(decodeResult.formatted.items[0].value).toBe('35.555 S, 58.367 W'); | ||
expect(decodeResult.formatted.items[1].label).toBe('Altitude'); | ||
expect(decodeResult.formatted.items[1].value).toBe('25000 feet'); | ||
expect(decodeResult.formatted.items[2].label).toBe('Aircraft Route'); | ||
expect(decodeResult.formatted.items[2].value).toBe('@10:03:16 > (37.218 S, 59.250 W)@10:19:16 > (39.645 S, 60.628 W)'); | ||
expect(decodeResult.formatted.items[3].label).toBe('Outside Air Temperature (C)'); | ||
expect(decodeResult.formatted.items[3].value).toBe('-23 degrees'); | ||
expect(decodeResult.formatted.items[4].label).toBe('Message Checksum'); | ||
expect(decodeResult.formatted.items[4].value).toBe('0xe711'); | ||
expect(decodeResult.remaining.text).toBe('27282,241,780,MANUAL,0,813'); | ||
}); | ||
|
||
test('decodes variant 2', () => { | ||
const text = '/HDQDLUA.POSN38332W080082,RONZZ,135753,320,LEVII,140454,WISTA,M45,20967,194/GAHDQDLUA/CA/TS135753,1411240721'; | ||
const decodeResult = plugin.decode({ text: text }); | ||
|
||
expect(decodeResult.decoded).toBe(true); | ||
expect(decodeResult.decoder.decodeLevel).toBe('partial'); | ||
expect(decodeResult.formatted.description).toBe('Position Report'); | ||
expect(decodeResult.raw.message_timestamp).toBe(1731592673); | ||
expect(decodeResult.formatted.items.length).toBe(5); | ||
expect(decodeResult.formatted.items[0].label).toBe('Aircraft Position'); | ||
expect(decodeResult.formatted.items[0].value).toBe('38.553 N, 80.137 W'); | ||
expect(decodeResult.formatted.items[1].label).toBe('Altitude'); | ||
expect(decodeResult.formatted.items[1].value).toBe('32000 feet'); | ||
expect(decodeResult.formatted.items[2].label).toBe('Aircraft Route'); | ||
expect(decodeResult.formatted.items[2].value).toBe('RONZZ@13:57:53 > LEVII@14:04:54 > WISTA'); | ||
expect(decodeResult.formatted.items[3].label).toBe('Outside Air Temperature (C)'); | ||
expect(decodeResult.formatted.items[3].value).toBe('-45 degrees'); | ||
expect(decodeResult.formatted.items[4].label).toBe('Message Checksum'); | ||
expect(decodeResult.formatted.items[4].value).toBe('0x0721'); | ||
expect(decodeResult.remaining.text).toBe('HDQDLUA,20967,194/GAHDQDLUA/CA'); | ||
}); | ||
|
||
test('decodes variant 3', () => { | ||
const text = '/.POS/TS140122,141124N38321W078003,,140122,450,,140122,,M56,24739,127,8306763'; | ||
const decodeResult = plugin.decode({ text: text }); | ||
|
||
expect(decodeResult.decoded).toBe(true); | ||
expect(decodeResult.decoder.decodeLevel).toBe('partial'); | ||
expect(decodeResult.formatted.description).toBe('Position Report'); | ||
expect(decodeResult.raw.message_timestamp).toBe(1731592882); | ||
expect(decodeResult.formatted.items.length).toBe(5); | ||
expect(decodeResult.formatted.items[0].label).toBe('Aircraft Position'); | ||
expect(decodeResult.formatted.items[0].value).toBe('38.535 N, 78.005 W'); | ||
expect(decodeResult.formatted.items[1].label).toBe('Altitude'); | ||
expect(decodeResult.formatted.items[1].value).toBe('45000 feet'); | ||
expect(decodeResult.formatted.items[2].label).toBe('Aircraft Route'); | ||
expect(decodeResult.formatted.items[2].value).toBe('@14:01:22 > @14:01:22 > ?'); | ||
expect(decodeResult.formatted.items[3].label).toBe('Outside Air Temperature (C)'); | ||
expect(decodeResult.formatted.items[3].value).toBe('-56 degrees'); | ||
expect(decodeResult.formatted.items[4].label).toBe('Message Checksum'); | ||
expect(decodeResult.formatted.items[4].value).toBe('0x6763'); | ||
expect(decodeResult.remaining.text).toBe('24739,127'); | ||
}); | ||
|
||
test('does not decode invalid', () => { | ||
|
||
const text = '/.POS Bogus message'; | ||
const decodeResult = plugin.decode({ text: text }); | ||
|
||
expect(decodeResult.decoded).toBe(false); | ||
expect(decodeResult.decoder.decodeLevel).toBe('none'); | ||
expect(decodeResult.message.text).toBe(text); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { DateTimeUtils } from '../DateTimeUtils'; | ||
import { DecoderPlugin } from '../DecoderPlugin'; | ||
import { DecodeResult, Message, Options } from '../DecoderPluginInterface'; | ||
import { Waypoint } from '../types/waypoint'; | ||
import { CoordinateUtils } from '../utils/coordinate_utils'; | ||
import { H1Helper } from '../utils/h1_helper'; | ||
import { ResultFormatter } from '../utils/result_formatter'; | ||
import { RouteUtils } from '../utils/route_utils'; | ||
|
||
export class Label_H1_Slash extends DecoderPlugin { | ||
name = 'label-h1-slash'; | ||
qualifiers() { // eslint-disable-line class-methods-use-this | ||
return { | ||
labels: ['H1'], | ||
preambles: ['/'] | ||
}; | ||
} | ||
|
||
decode(message: Message, options: Options = {}) : DecodeResult { | ||
let decodeResult = this.defaultResult(); | ||
decodeResult.decoder.name = this.name; | ||
decodeResult.formatted.description = 'Position Report'; | ||
decodeResult.message = message; | ||
|
||
const checksum = message.text.slice(-4); | ||
const data = message.text.slice(0, message.text.length - 4); | ||
|
||
const fields = data.split('/'); | ||
|
||
if(fields[0] !== '') { | ||
ResultFormatter.unknown(decodeResult, message.text); | ||
decodeResult.decoded = false; | ||
decodeResult.decoder.decodeLevel = 'none'; | ||
return decodeResult; | ||
} | ||
|
||
const headerData = fields[1].split('.'); | ||
ResultFormatter.unknown(decodeResult, headerData[0]); | ||
if(headerData[1] === 'POS' && fields[2].startsWith('TS') && fields[2].length > 15) { | ||
// variant 3 hack | ||
// rip out the timestamp and process the rest | ||
H1Helper.processPosition(decodeResult, fields[2].substring(15).split(',')); | ||
} else if(headerData[1] === 'POS') { | ||
// do nothing | ||
} else if(headerData[1].startsWith('POS')) { | ||
H1Helper.processPosition(decodeResult, headerData[1].substring(3).split(',')); | ||
} else { | ||
ResultFormatter.unknown(decodeResult, headerData[1], '.'); | ||
} | ||
|
||
for(let i=2; i<fields.length; i++) { | ||
const field = fields[i]; | ||
if(field.startsWith('TS')) { | ||
H1Helper.processTS(decodeResult, field.substring(2,15).split(',')); | ||
} else if(field.startsWith('PS')) { | ||
H1Helper.processPS(decodeResult, field.substring(2).split(',')); | ||
} else { | ||
ResultFormatter.unknown(decodeResult, field, '/'); | ||
} | ||
} | ||
|
||
if (decodeResult.formatted.items.length === 0) { | ||
if (options.debug) { | ||
console.log(`Decoder: Unknown H1 message: ${message.text}`); | ||
} | ||
ResultFormatter.unknown(decodeResult, message.text); | ||
decodeResult.decoded = false; | ||
decodeResult.decoder.decodeLevel = 'none'; | ||
return decodeResult; | ||
} | ||
|
||
ResultFormatter.checksum(decodeResult, checksum); | ||
decodeResult.decoded = true; | ||
decodeResult.decoder.decodeLevel = !decodeResult.remaining.text ? 'full' : 'partial'; | ||
return decodeResult; | ||
} | ||
} | ||
|
||
export default {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.