-
-
Notifications
You must be signed in to change notification settings - Fork 15
Adding Label 16 Decoders #232
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
Conversation
WalkthroughThis update integrates two new plugins into the message decoding process. The Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant MD as MessageDecoder
participant P1 as Label_16_POSA1 Plugin
participant P2 as Label_16_TOD Plugin
U->>MD: Send message for decoding
MD->>MD: Initialize and register plugins (P1 and P2)
alt Message matches POSA1 criteria
MD->>P1: Call decode(message)
P1-->>MD: Return decode result
else Message matches TOD criteria
MD->>P2: Call decode(message)
P2-->>MD: Return decode result
end
MD-->>U: Return aggregated decode result
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 2
🧹 Nitpick comments (7)
lib/plugins/Label_16_POSA1.ts (1)
23-32: Consider adding input validation for empty or malformed messages.The validation checks for the number of fields and preamble, but it might be worth adding checks for:
- Empty message text
- Malformed field values
decode(message: Message, options: Options = {}) : DecodeResult { const decodeResult = this.defaultResult(); decodeResult.decoder.name = this.name; decodeResult.formatted.description = 'Position Report'; decodeResult.message = message; + if (!message.text?.trim()) { + if (options.debug) { + console.log('Decoder: Empty message text'); + } + decodeResult.remaining.text = message.text || ''; + decodeResult.decoded = false; + decodeResult.decoder.decodeLevel = 'none'; + return decodeResult; + } const fields = message.text.split(',');lib/plugins/Label_16_TOD.ts (1)
22-32: Consider adding input validation for empty or malformed messages.Similar to the POSA1 decoder, consider adding validation for:
- Empty message text
- Malformed field values
decode(message: Message, options: Options = {}) : DecodeResult { const decodeResult = this.defaultResult(); decodeResult.decoder.name = this.name; decodeResult.formatted.description = 'Position Report'; decodeResult.message = message; + if (!message.text?.trim()) { + if (options.debug) { + console.log('Decoder: Empty message text'); + } + decodeResult.remaining.text = message.text || ''; + decodeResult.decoded = false; + decodeResult.decoder.decodeLevel = 'none'; + return decodeResult; + } const fields = message.text.split(',');lib/plugins/Label_16_POSA1.test.ts (1)
22-39: Consider adding edge case tests.While the current tests cover valid and redacted cases well, consider adding tests for:
- Empty message text
- Malformed coordinates
- Invalid numeric values
- Missing fields
test('handles empty message', () => { const text = ''; const decodeResult = plugin.decode({ text }); expect(decodeResult.decoded).toBe(false); expect(decodeResult.decoder.decodeLevel).toBe('none'); }); test('handles malformed coordinates', () => { const text = 'POSA1INVALID,GEARS,221626,370,BBOBO,222053,,-61,139,1174,829'; const decodeResult = plugin.decode({ text }); expect(decodeResult.decoded).toBe(false); expect(decodeResult.decoder.decodeLevel).toBe('none'); });Also applies to: 41-58
lib/plugins/Label_16_TOD.test.ts (3)
26-26: Remove debug console.log statement.The
console.logstatement should be removed as it's not needed for testing and could clutter test output.- console.log(decodeResult.formatted.items);
22-43: Add test case for remaining text validation.The test verifies the decoding of variant 1 but doesn't validate the content of
remaining.text. While line 42 checks that it equals' 97', there's no explanation of what this value represents or why it's important.Consider adding a comment explaining the significance of the remaining text:
+ // Verify remaining text contains the ground speed value expect(decodeResult.remaining.text).toBe(' 97');
45-67: Enhance test coverage with edge cases.The test suite covers basic scenarios but could benefit from additional edge cases:
- Messages with invalid timestamps
- Messages with out-of-range altitudes
- Messages with malformed coordinates
Would you like me to generate additional test cases for these scenarios?
Also applies to: 70-86, 88-97
lib/MessageDecoder.ts (1)
11-75: Consider refactoring plugin registration.The constructor contains a long list of plugin registrations which could be better organized. Consider grouping plugins by label or functionality and moving the registration logic to a separate method.
Example refactor:
private registerDefaultPlugins(): void { const pluginGroups = { label10: [ new Plugins.Label_10_LDR(this), new Plugins.Label_10_POS(this), new Plugins.Label_10_Slash(this), ], label16: [ new Plugins.Label_16_N_Space(this), new Plugins.Label_16_POSA1(this), new Plugins.Label_16_TOD(this), ], // ... other groups }; Object.values(pluginGroups).flat().forEach(plugin => this.registerPlugin(plugin)); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
lib/MessageDecoder.ts(1 hunks)lib/plugins/Label_16_POSA1.test.ts(1 hunks)lib/plugins/Label_16_POSA1.ts(1 hunks)lib/plugins/Label_16_TOD.test.ts(1 hunks)lib/plugins/Label_16_TOD.ts(1 hunks)lib/plugins/official.ts(1 hunks)
🔇 Additional comments (9)
lib/plugins/official.ts (1)
11-12: LGTM!The new exports are correctly placed in alphabetical order.
lib/plugins/Label_16_POSA1.ts (3)
7-15: LGTM!The class declaration and qualifiers are well-defined. The plugin correctly specifies its name and the expected labels and preambles.
17-22: LGTM!The decode method initialization follows the standard pattern, properly setting up the decode result with default values and message metadata.
46-50: LGTM!The result finalization is correct, properly setting the decode status and level.
lib/plugins/Label_16_TOD.ts (2)
50-54: LGTM!The result finalization is correct, properly setting the decode status and level.
7-14:Details
❓ Verification inconclusive
Consider adding preambles to qualifiers.
The qualifiers only specify labels but not preambles. This might lead to false positives if other Label 16 messages have different preambles.
🏁 Script executed:
#!/bin/bash # Search for other Label 16 decoders to check their preambles ast-grep --pattern $'class Label_16_$_ extends DecoderPlugin { $$$ qualifiers() { $$$ } $$$ }'Length of output: 107
Revisit Qualifiers Implementation in Label_16_TOD
The current implementation of the qualifiers in
lib/plugins/Label_16_TOD.tsonly returns a labels array without including a preamble, which may lead to potential false positives when matching messages. The automated search for similar Label 16 decoders (using the AST pattern) did not return any results, so it’s unclear whether this omission is an isolated case or part of a broader pattern in the codebase.Please manually verify if other Label 16 decoder plugins are expected to include a
preamble—and if they do, consider adding a preamble to the qualifiers in this file to ensure consistency and avoid ambiguity.lib/plugins/Label_16_POSA1.test.ts (2)
13-21: LGTM!The qualifiers test is thorough, checking all essential plugin properties.
60-69: LGTM!The invalid input test case is well-defined and verifies the expected behavior.
lib/MessageDecoder.ts (1)
27-28: LGTM! Plugin registration order is logical.The new Label 16 plugins are registered after other Label 16 plugins and before Label 1L plugins, maintaining a consistent ordering pattern.
| ResultFormatter.position(decodeResult, CoordinateUtils.decodeStringCoordinates(fields[0].substring(5))); // strip 'POSA1' | ||
| const waypoint = fields[1].trim(); | ||
| const time = DateTimeUtils.convertHHMMSSToTod(fields[2]); | ||
| ResultFormatter.altitude(decodeResult, Number(fields[3])*100); | ||
| const nextWaypoint = fields[4].trim(); | ||
| const nextTime = DateTimeUtils.convertHHMMSSToTod(fields[5]); | ||
| ResultFormatter.unknownArr(decodeResult, fields.slice(6), ','); | ||
| ResultFormatter.route(decodeResult, {waypoints: [ | ||
| {name: waypoint, time: time, timeFormat: 'tod'}, | ||
| {name: nextWaypoint, time: nextTime, timeFormat: 'tod'} | ||
| ]}); | ||
| decodeResult.decoded = true; |
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.
🛠️ Refactor suggestion
Consider adding error handling for numeric conversions.
The code assumes that numeric conversions will succeed. Consider adding error handling for:
- Altitude conversion at line 37
- Time conversions at lines 36 and 39
- ResultFormatter.altitude(decodeResult, Number(fields[3])*100);
+ const altitude = Number(fields[3]);
+ if (!Number.isNaN(altitude)) {
+ ResultFormatter.altitude(decodeResult, altitude * 100);
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ResultFormatter.position(decodeResult, CoordinateUtils.decodeStringCoordinates(fields[0].substring(5))); // strip 'POSA1' | |
| const waypoint = fields[1].trim(); | |
| const time = DateTimeUtils.convertHHMMSSToTod(fields[2]); | |
| ResultFormatter.altitude(decodeResult, Number(fields[3])*100); | |
| const nextWaypoint = fields[4].trim(); | |
| const nextTime = DateTimeUtils.convertHHMMSSToTod(fields[5]); | |
| ResultFormatter.unknownArr(decodeResult, fields.slice(6), ','); | |
| ResultFormatter.route(decodeResult, {waypoints: [ | |
| {name: waypoint, time: time, timeFormat: 'tod'}, | |
| {name: nextWaypoint, time: nextTime, timeFormat: 'tod'} | |
| ]}); | |
| decodeResult.decoded = true; | |
| ResultFormatter.position(decodeResult, CoordinateUtils.decodeStringCoordinates(fields[0].substring(5))); // strip 'POSA1' | |
| const waypoint = fields[1].trim(); | |
| const time = DateTimeUtils.convertHHMMSSToTod(fields[2]); | |
| const altitude = Number(fields[3]); | |
| if (!Number.isNaN(altitude)) { | |
| ResultFormatter.altitude(decodeResult, altitude * 100); | |
| } | |
| const nextWaypoint = fields[4].trim(); | |
| const nextTime = DateTimeUtils.convertHHMMSSToTod(fields[5]); | |
| ResultFormatter.unknownArr(decodeResult, fields.slice(6), ','); | |
| ResultFormatter.route(decodeResult, {waypoints: [ | |
| {name: waypoint, time: time, timeFormat: 'tod'}, | |
| {name: nextWaypoint, time: nextTime, timeFormat: 'tod'} | |
| ]}); | |
| decodeResult.decoded = true; |
| ResultFormatter.time_of_day(decodeResult, time); | ||
| if(fields[1] !== '') { | ||
| ResultFormatter.altitude(decodeResult, Number(fields[1])); | ||
| } | ||
| ResultFormatter.eta(decodeResult, DateTimeUtils.convertHHMMSSToTod(fields[2])); | ||
| ResultFormatter.unknown(decodeResult, fields[3]); | ||
| const temp = fields[4].split('/'); | ||
| const posFields = temp[0].split(' '); | ||
| ResultFormatter.position(decodeResult, { | ||
| latitude: CoordinateUtils.getDirection(posFields[0]) * Number(posFields[1]), | ||
| longitude: CoordinateUtils.getDirection(posFields[2]) * Number(posFields[3]), | ||
| }); | ||
|
|
||
| if(temp.length > 1) { | ||
| ResultFormatter.flightNumber(decodeResult, temp[1]); | ||
| } |
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.
🛠️ Refactor suggestion
Add error handling for numeric conversions and array access.
The code makes several assumptions:
- Numeric conversions will succeed
- Array indices will exist
- Split operations will yield expected results
Consider adding error handling:
- const posFields = temp[0].split(' ');
- ResultFormatter.position(decodeResult, {
- latitude: CoordinateUtils.getDirection(posFields[0]) * Number(posFields[1]),
- longitude: CoordinateUtils.getDirection(posFields[2]) * Number(posFields[3]),
- });
+ const posFields = temp[0]?.split(' ') || [];
+ if (posFields.length >= 4) {
+ const lat = Number(posFields[1]);
+ const lon = Number(posFields[3]);
+ if (!Number.isNaN(lat) && !Number.isNaN(lon)) {
+ ResultFormatter.position(decodeResult, {
+ latitude: CoordinateUtils.getDirection(posFields[0]) * lat,
+ longitude: CoordinateUtils.getDirection(posFields[2]) * lon,
+ });
+ }
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ResultFormatter.time_of_day(decodeResult, time); | |
| if(fields[1] !== '') { | |
| ResultFormatter.altitude(decodeResult, Number(fields[1])); | |
| } | |
| ResultFormatter.eta(decodeResult, DateTimeUtils.convertHHMMSSToTod(fields[2])); | |
| ResultFormatter.unknown(decodeResult, fields[3]); | |
| const temp = fields[4].split('/'); | |
| const posFields = temp[0].split(' '); | |
| ResultFormatter.position(decodeResult, { | |
| latitude: CoordinateUtils.getDirection(posFields[0]) * Number(posFields[1]), | |
| longitude: CoordinateUtils.getDirection(posFields[2]) * Number(posFields[3]), | |
| }); | |
| if(temp.length > 1) { | |
| ResultFormatter.flightNumber(decodeResult, temp[1]); | |
| } | |
| ResultFormatter.time_of_day(decodeResult, time); | |
| if(fields[1] !== '') { | |
| ResultFormatter.altitude(decodeResult, Number(fields[1])); | |
| } | |
| ResultFormatter.eta(decodeResult, DateTimeUtils.convertHHMMSSToTod(fields[2])); | |
| ResultFormatter.unknown(decodeResult, fields[3]); | |
| const temp = fields[4].split('/'); | |
| const posFields = temp[0]?.split(' ') || []; | |
| if (posFields.length >= 4) { | |
| const lat = Number(posFields[1]); | |
| const lon = Number(posFields[3]); | |
| if (!Number.isNaN(lat) && !Number.isNaN(lon)) { | |
| ResultFormatter.position(decodeResult, { | |
| latitude: CoordinateUtils.getDirection(posFields[0]) * lat, | |
| longitude: CoordinateUtils.getDirection(posFields[2]) * lon, | |
| }); | |
| } | |
| } | |
| if(temp.length > 1) { | |
| ResultFormatter.flightNumber(decodeResult, temp[1]); | |
| } |
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.
Actionable comments posted: 0
🧹 Nitpick comments (4)
lib/plugins/Label_16_TOD.test.ts (4)
22-41: Add assertions for remaining text format.While the test case is comprehensive in validating the decoded fields, consider adding assertions to verify the format of the remaining text (e.g., length, numeric content).
expect(decodeResult.formatted.items[3].value).toBe('38.364 N, 75.226 W'); expect(decodeResult.remaining.text).toBe(' 97'); + expect(decodeResult.remaining.text.trim()).toMatch(/^\d+$/);
43-65: Add assertions for remaining text format.Similar to variant 1, consider adding assertions to verify the format of the remaining text. Additionally, the test case effectively uses a real-world example, which is good practice.
expect(decodeResult.formatted.items[4].value).toBe('SXS7SL'); expect(decodeResult.remaining.text).toBe(' 51'); + expect(decodeResult.remaining.text.trim()).toMatch(/^\d+$/);
68-84: Add assertions for remaining text format.Similar to previous variants, consider adding assertions to verify the format of the remaining text. The test case effectively handles missing position data.
expect(decodeResult.formatted.items[1].value).toBe('12:06:00'); expect(decodeResult.remaining.text).toBe(' 92'); + expect(decodeResult.remaining.text.trim()).toMatch(/^\d+$/);
86-95: Add assertion for empty formatted items.For invalid messages, verify that no formatted items are present to ensure complete validation of the error case.
expect(decodeResult.decoder.name).toBe('label-16-tod'); expect(decodeResult.formatted.description).toBe('Position Report'); expect(decodeResult.message.text).toBe(text); + expect(decodeResult.formatted.items.length).toBe(0);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
lib/plugins/Label_16_TOD.test.ts(1 hunks)lib/utils/result_formatter.ts(1 hunks)
🔇 Additional comments (2)
lib/plugins/Label_16_TOD.test.ts (1)
13-20: LGTM! Test case verifies essential plugin properties.The test case thoroughly validates the plugin's interface by checking the existence of required methods and properties.
lib/utils/result_formatter.ts (1)
77-79: LGTM! Added NaN check for altitude values.The change prevents invalid altitude values from being processed, which is consistent with similar checks in other methods (e.g.,
position,temperature).
altitude no longer persisted as it was blank/NaN
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
lib/plugins/Label_4A.ts (1)
41-44: Consider refactoring altitude handling for consistency.The current implementation has several areas for improvement:
- Using hardcoded positions (48, 51) is brittle and differs from the field-based approach used elsewhere
- Altitude handling is inconsistent across variants (compare with lines 55 and 69)
Consider refactoring to use the fields array and standardizing altitude handling across all variants:
- const alt = text.substring(48, 51); - if(alt !== '') { - ResultFormatter.altitude(decodeResult, Number(alt) * 100); - } + const alt = fields[6]; // Adjust index based on your field structure + if (alt && alt.trim() !== '') { + ResultFormatter.altitude(decodeResult, Number(alt) * 100); + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
lib/plugins/Label_4A.test.ts(2 hunks)lib/plugins/Label_4A.ts(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- lib/plugins/Label_4A.test.ts
🔇 Additional comments (1)
lib/plugins/Label_4A.ts (1)
41-44: LGTM! Good defensive programming.The addition of the empty string check before processing the altitude value is a good defensive programming practice that prevents potential NaN propagation.
Summary by CodeRabbit