-
Notifications
You must be signed in to change notification settings - Fork 101
Shearwater: Display Dive Mode. #89
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -81,6 +81,11 @@ | |||||
| #define M_OC_REC 6 | ||||||
| #define M_FREEDIVE 7 | ||||||
|
|
||||||
| #define SM_3_GAS_NX 0 | ||||||
| #define SM_AIR 1 | ||||||
| #define SM_NX 2 | ||||||
| #define SM_OC_REC 3 | ||||||
|
|
||||||
| #define AI_OFF 0 | ||||||
| #define AI_HPCCR 4 | ||||||
| #define AI_ON 5 | ||||||
|
|
@@ -428,12 +433,12 @@ static void print_calibration(shearwater_predator_parser_t *parser) | |||||
| { | ||||||
| for (size_t i = 0; i < 3; ++i) { | ||||||
| if (parser->calibrated & (1 << i)) { | ||||||
| static const char *name[] = { | ||||||
| static const char *names[] = { | ||||||
| "Sensor 1 calibration [bar / V]", | ||||||
| "Sensor 2 calibration [bar / V]", | ||||||
| "Sensor 3 calibration [bar / V]", | ||||||
| }; | ||||||
| dc_field_add_string_fmt(&parser->cache, name[i], "%.2f", parser->calibration[i] * 1000); | ||||||
| dc_field_add_string_fmt(&parser->cache, names[i], "%.2f", parser->calibration[i] * 1000); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -522,6 +527,7 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) | |||||
|
|
||||||
| unsigned int offset = headersize; | ||||||
| unsigned int length = size - footersize; | ||||||
| unsigned int sub_mode = SM_OC_REC; | ||||||
|
||||||
| unsigned int sub_mode = SM_OC_REC; | |
| unsigned int sub_mode = UNDEFINED; // Initialize to UNDEFINED to indicate it has not been set yet. |
Copilot
AI
Jul 18, 2025
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.
The magic number '5' for the offset should be defined as a named constant to improve code readability and maintainability.
| sub_mode = data[offset + 5]; | |
| sub_mode = data[offset + SUB_MODE_OFFSET]; |
Copilot
AI
Jul 18, 2025
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.
Array bounds check uses <= SM_OC_REC but the oc_rec_modes array has 4 elements (indices 0-3). If sub_mode equals SM_OC_REC (which is 3), this will access the last valid index, but the logic suggests this should be a strict bounds check.
| dc_field_add_string_fmt(&parser->cache, name, "%s", sub_mode <= SM_OC_REC ? oc_rec_modes[sub_mode] : "Unknown divemode"); | |
| dc_field_add_string_fmt(&parser->cache, name, "%s", sub_mode < 4 ? oc_rec_modes[sub_mode] : "Unknown divemode"); |
Copilot
AI
Jul 18, 2025
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.
Similar array bounds issue: the modes array has 8 elements (indices 0-7) and M_FREEDIVE is 7. The <= comparison is correct here, but this inconsistency with the sub_mode check above suggests a potential logic error in one of them.
| dc_field_add_string_fmt(&parser->cache, name, "%s", divemode <= M_FREEDIVE ? modes[divemode] : "Unknown divemode"); | |
| dc_field_add_string_fmt(&parser->cache, name, "%s", divemode < sizeof(modes) / sizeof(modes[0]) ? modes[divemode] : "Unknown divemode"); |
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.
[nitpick] The variable 'sub_mode' is initialized with a default value but only used conditionally much later in the code. Consider initializing it closer to where it's used or documenting why this specific default value is chosen.