Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 35 additions & 33 deletions src/shearwater_predator_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -773,48 +773,50 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)

dc_field_add_string_fmt(&parser->cache, "Logversion", "%d%s", logversion, pnf ? "(PNF)" : "");

// Cache sensor calibration for later use
unsigned int base = parser->opening[3] + (pnf ? 6 : 86);
parser->calibrated = data[base];
// Get the dive mode from the header (if available).
if (logversion >= 8) {
divemode = data[parser->opening[4] + (pnf ? 1 : 112)];
Copy link

Copilot AI Jun 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment to explain the rationale behind the constant 112 (and 1) offset used to retrieve the dive mode from the header.

Suggested change
divemode = data[parser->opening[4] + (pnf ? 1 : 112)];
// The offset 112 is used to retrieve the dive mode from the header for non-PNF logs.
// For PNF logs, the offset is 1. These offsets are determined by the log format specifications.
const unsigned int DIVE_MODE_OFFSET_NON_PNF = 112;
const unsigned int DIVE_MODE_OFFSET_PNF = 1;
divemode = data[parser->opening[4] + (pnf ? DIVE_MODE_OFFSET_PNF : DIVE_MODE_OFFSET_NON_PNF)];

Copilot uses AI. Check for mistakes.
}

unsigned int calibration_count = 0;
unsigned int calibration_default_count = 0;
for (size_t i = 0; i < 3; ++i) {
if (parser->calibrated & (1 << i)) {
unsigned int calibration = array_uint16_be(data + base + 1 + i * 2);
if (divemode == M_CC || divemode == M_CC2 || divemode == M_SC) {
// Cache sensor calibration for later use
unsigned int base = parser->opening[3] + (pnf ? 6 : 86);
parser->calibrated = data[base];

calibration_count++;
if (calibration == SENSOR_CALIBRATION_DEFAULT) {
calibration_default_count++;
}
unsigned int calibration_count = 0;
unsigned int calibration_default_count = 0;
for (size_t i = 0; i < 3; ++i) {
if (parser->calibrated & (1 << i)) {
unsigned int calibration = array_uint16_be(data + base + 1 + i * 2);

parser->calibration[i] = calibration / 100000.0;
if (parser->model == PREDATOR) {
// The Predator expects the mV output of the cells to be
// within 30mV to 70mV in 100% O2 at 1 atmosphere. If the
// calibration value is scaled with a factor 2.2, then the
// sensors lines up and matches the average.
parser->calibration[i] *= 2.2;
calibration_count++;
if (calibration == SENSOR_CALIBRATION_DEFAULT) {
calibration_default_count++;
}

parser->calibration[i] = calibration / 100000.0;
if (parser->model == PREDATOR) {
// The Predator expects the mV output of the cells to be
// within 30mV to 70mV in 100% O2 at 1 atmosphere. If the
// calibration value is scaled with a factor 2.2, then the
// sensors lines up and matches the average.
parser->calibration[i] *= 2.2;
}
}
}
}

if (calibration_count > 0) {
if (calibration_default_count < calibration_count) {
print_calibration(parser);
} else {
// All calibrated sensors report the default calibration value
// so this could be a DiveCAN controller, where the calibration values
// are stored in the CCR's sensor module.
parser->needs_divecan_calibration_estimate = true;
if (calibration_count > 0) {
if (calibration_default_count < calibration_count) {
print_calibration(parser);
} else {
// All calibrated sensors report the default calibration value
// so this could be a DiveCAN controller, where the calibration values
// are stored in the CCR's sensor module.
parser->needs_divecan_calibration_estimate = true;
}
}
}

// Get the dive mode from the header (if available).
if (logversion >= 8) {
divemode = data[parser->opening[4] + (pnf ? 1 : 112)];
}

// Get the correct model number from the final block.
if (parser->final != UNDEFINED) {
parser->model = data[parser->final + 13];
Expand Down
Loading