-
-
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
Adding H1 *POS parsing #183
Merged
makrsmark
merged 1 commit into
airframesio:master
from
makrsmark:feature/label-h1-star-pos
Oct 30, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { MessageDecoder } from '../MessageDecoder'; | ||
import { Label_H1_StarPOS } from './Label_H1_StarPOS'; | ||
|
||
describe('Label H1 *POS', () => { | ||
|
||
let plugin: Label_H1_StarPOS; | ||
|
||
beforeEach(() => { | ||
const decoder = new MessageDecoder(); | ||
plugin = new Label_H1_StarPOS(decoder); | ||
}); | ||
|
||
test('decodes variant 1', () => { | ||
|
||
const text = '*POS10300950N3954W07759363312045802M5230175'; | ||
const decodeResult = plugin.decode({ text: text }); | ||
|
||
expect(decodeResult.decoded).toBe(true); | ||
expect(decodeResult.decoder.decodeLevel).toBe('partial'); | ||
expect(decodeResult.message.text).toBe(text); | ||
expect(decodeResult.raw.day_of_month).toBe(30); | ||
expect(decodeResult.raw.month).toBe(10); | ||
expect(decodeResult.raw.time_of_day).toBe(35400); | ||
expect(decodeResult.raw.position.latitude).toBe(39.900000); | ||
expect(decodeResult.raw.position.longitude).toBe(-77.98333333333333); | ||
expect(decodeResult.raw.altitude).toBe(36331); | ||
expect(decodeResult.formatted.items.length).toBe(3); | ||
expect(decodeResult.formatted.items[0].label).toBe('Message Timestamp'); | ||
expect(decodeResult.formatted.items[0].value).toBe('09:50:00'); | ||
expect(decodeResult.formatted.items[1].label).toBe('Aircraft Position'); | ||
expect(decodeResult.formatted.items[1].value).toBe('39.900 N, 77.983 W'); | ||
expect(decodeResult.formatted.items[2].label).toBe('Altitude'); | ||
expect(decodeResult.formatted.items[2].value).toBe('36331 feet'); | ||
|
||
expect(decodeResult.remaining.text).toBe('2045802M5230175'); | ||
}); | ||
|
||
|
||
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.formatted.description).toBe('Position Report'); | ||
expect(decodeResult.formatted.items.length).toBe(0); | ||
}); | ||
}); |
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,49 @@ | ||
import { DateTimeUtils } from '../DateTimeUtils'; | ||
import { DecoderPlugin } from '../DecoderPlugin'; | ||
import { DecodeResult, Message, Options } from '../DecoderPluginInterface'; | ||
import { CoordinateUtils } from '../utils/coordinate_utils'; | ||
import { ResultFormatter } from '../utils/result_formatter'; | ||
|
||
export class Label_H1_StarPOS extends DecoderPlugin { | ||
name = 'label-h1-star-pos'; | ||
qualifiers() { // eslint-disable-line class-methods-use-this | ||
return { | ||
labels: ['H1'], | ||
preambles: ['*POS'], | ||
}; | ||
} | ||
|
||
decode(message: Message, options: Options = {}) : DecodeResult { | ||
let decodeResult = this.defaultResult(); | ||
decodeResult.decoder.name = this.name; | ||
decodeResult.formatted.description = 'Position Report'; | ||
decodeResult.message = message; | ||
|
||
const msg = message.text; | ||
// assuming fixed length until other variants found | ||
if (msg.length !== 43 || !msg.startsWith('*POS')) { | ||
if (options.debug) { | ||
console.log(`Decoder: Unknown H1 message: ${msg}`); | ||
} | ||
ResultFormatter.unknown(decodeResult, msg); | ||
decodeResult.decoded = false; | ||
decodeResult.decoder.decodeLevel = 'none'; | ||
return decodeResult; | ||
} | ||
|
||
decodeResult.raw.month = Number(msg.substring(4, 6)); | ||
decodeResult.raw.day_of_month = Number(msg.substring(6, 8)); | ||
ResultFormatter.time_of_day(decodeResult, DateTimeUtils.convertHHMMSSToTod(msg.substring(8, 12) + '00')); | ||
ResultFormatter.position(decodeResult, { // Deg Min, no sec | ||
latitude: CoordinateUtils.getDirection(msg.substring(12,13)) * (Number(msg.substring(13, 15)) + Number(msg.substring(15, 17))/60), | ||
longitude: CoordinateUtils.getDirection(msg.substring(17,18)) * (Number(msg.substring(18, 21)) + Number(msg.substring(21, 23))/60) | ||
}); | ||
ResultFormatter.altitude(decodeResult, Number(msg.substring(23, 28))); | ||
ResultFormatter.unknown(decodeResult, msg.substring(28)); | ||
decodeResult.decoded = true; | ||
decodeResult.decoder.decodeLevel = '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
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.
using
day_of_month
to be consistent - thinking of refactoring so they're all justday
- do we want these as a formatted result too? or is it good as-is?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.
going to leave as-is - we can come back making all messages more consistent