-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Label 24 / Parsing #166
Merged
makrsmark
merged 4 commits into
airframesio:master
from
makrsmark:feature/normalize-eta-airports
Oct 22, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,55 @@ | ||
import { MessageDecoder } from '../MessageDecoder'; | ||
import { Label_24_Slash } from './Label_24_Slash'; | ||
|
||
describe('Label_24_Slash', () => { | ||
let plugin: Label_24_Slash; | ||
|
||
beforeEach(() => { | ||
const decoder = new MessageDecoder(); | ||
plugin = new Label_24_Slash(decoder); | ||
}); | ||
|
||
test('matches qualifiers', () => { | ||
expect(plugin.decode).toBeDefined(); | ||
expect(plugin.name).toBe('label-24-slash'); | ||
expect(plugin.qualifiers).toBeDefined(); | ||
expect(plugin.qualifiers()).toEqual({ | ||
labels: ['24'], | ||
preambles: ['/'], | ||
}); | ||
}); | ||
|
||
|
||
test('valid', () => { | ||
// https://app.airframes.io/messages/3439806391 | ||
const text = '/241710/1021/04WM/34962/N53.13/E001.33/3374/1056/'; | ||
const decodeResult = plugin.decode({ text: text }); | ||
expect(decodeResult.decoded).toBe(true); | ||
expect(decodeResult.decoder.decodeLevel).toBe('partial'); | ||
expect(decodeResult.raw.message_timestamp).toBe(1729160460); | ||
expect(decodeResult.raw.flight_number).toBe('04WM'); | ||
expect(decodeResult.raw.altitude).toBe(34962); | ||
expect(decodeResult.raw.position.latitude).toBe(53.13); | ||
expect(decodeResult.raw.position.longitude).toBe(1.33); | ||
expect(decodeResult.raw.eta_time).toBe(39360); | ||
expect(decodeResult.formatted.items.length).toBe(3); | ||
expect(decodeResult.formatted.items[0].label).toBe('Altitude'); | ||
expect(decodeResult.formatted.items[0].value).toBe('34962 feet'); | ||
expect(decodeResult.formatted.items[1].label).toBe('Aircraft Position'); | ||
expect(decodeResult.formatted.items[1].value).toBe('53.130 N, 1.330 E'); | ||
expect(decodeResult.formatted.items[2].label).toBe('Estimated Time of Arrival'); | ||
expect(decodeResult.formatted.items[2].value).toBe('10:56:00'); | ||
|
||
expect(decodeResult.remaining.text).toBe('3374'); | ||
}); | ||
|
||
test('does not decode invalid', () => { | ||
|
||
const text = '/ 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,56 @@ | ||
import { DateTimeUtils } from '../DateTimeUtils'; | ||
import { DecoderPlugin } from '../DecoderPlugin'; | ||
import { DecodeResult, Message, Options } from '../DecoderPluginInterface'; | ||
import { ResultFormatter } from '../utils/result_formatter'; | ||
|
||
// Position Report | ||
export class Label_24_Slash extends DecoderPlugin { | ||
name = 'label-24-slash'; | ||
|
||
qualifiers() { // eslint-disable-line class-methods-use-this | ||
return { | ||
labels: ['24'], | ||
preambles: ['/'], | ||
}; | ||
} | ||
|
||
decode(message: Message, options: Options = {}) : DecodeResult { | ||
const decodeResult = this.defaultResult(); | ||
decodeResult.decoder.name = this.name; | ||
decodeResult.formatted.description = 'Position Report'; | ||
decodeResult.message = message; | ||
|
||
const fields = message.text.split('/'); | ||
|
||
if (fields.length == 10 && fields[0] == '' && fields[9] == '') { // begin and ends with `/` | ||
const mmddyy = fields[1].substring(4,6) + fields[1].substring(2,4) + fields[1].substring(0,2); // YYDDMM | ||
const hhmmss = fields[2] + '00'; | ||
decodeResult.raw.message_timestamp = DateTimeUtils.convertDateTimeToEpoch(hhmmss,mmddyy); | ||
ResultFormatter.flightNumber(decodeResult, fields[3]); | ||
ResultFormatter.altitude(decodeResult, Number(fields[4])); | ||
const lat = fields[5]; | ||
const lon = fields[6]; | ||
const position = { | ||
latitude: (lat[0] === 'N' ? 1 : -1) * Number(lat.substring(1)), | ||
longitude: (lon[0] === 'E' ? 1 : -1) * Number(lon.substring(1)), | ||
}; | ||
ResultFormatter.position(decodeResult, position); | ||
ResultFormatter.eta(decodeResult, DateTimeUtils.convertHHMMSSToTod(fields[8]+'00')); | ||
decodeResult.remaining.text = fields[7]; | ||
|
||
decodeResult.decoded = true; | ||
decodeResult.decoder.decodeLevel = 'partial'; | ||
} else { | ||
// Unknown! | ||
if(options.debug) { | ||
console.log(`DEBUG: ${this.name}: Unknown variation. Field count: ${fields.length}. Message: ${message.text}`); | ||
} | ||
decodeResult.decoded = false; | ||
decodeResult.decoder.decodeLevel = 'none'; | ||
} | ||
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we not instead do destination_icao?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so i'm trying to make the item as follows
type - kind of thing it is - time of day, time since epoch, icao code, etc
code - unique identifier for what it is
label - display of what it is
value - display of the actual value
so in this case it's
type: icao (4-character airport code)
code: DST
label: Destination Airport
value: KUZA
Open to suggestions. will keep this open to discuss
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right here. Maybe we need an additional element called name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmmm - i see the label as the "human name" and code as the "computer name" and the type as a "units". IDK, it's gotten messy and i tried to commandeer type because 3 variations of "destination" or any other value seemed excessive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i wrote this and then there's also the raw value. sigh