@@ -769,48 +769,50 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
769769
770770 dc_field_add_string_fmt (& parser -> cache , "Logversion" , "%d%s" , logversion , pnf ? "(PNF)" : "" );
771771
772- // Cache sensor calibration for later use
773- unsigned int base = parser -> opening [3 ] + (pnf ? 6 : 86 );
774- parser -> calibrated = data [base ];
772+ // Get the dive mode from the header (if available).
773+ if (logversion >= 8 ) {
774+ divemode = data [parser -> opening [4 ] + (pnf ? 1 : 112 )];
775+ }
775776
776- unsigned int calibration_count = 0 ;
777- unsigned int calibration_default_count = 0 ;
778- for (size_t i = 0 ; i < 3 ; ++ i ) {
779- if (parser -> calibrated & (1 << i )) {
780- unsigned int calibration = array_uint16_be (data + base + 1 + i * 2 );
777+ if (divemode == M_CC || divemode == M_CC2 || divemode == M_SC ) {
778+ // Cache sensor calibration for later use
779+ unsigned int base = parser -> opening [3 ] + (pnf ? 6 : 86 );
780+ parser -> calibrated = data [base ];
781781
782- calibration_count ++ ;
783- if (calibration == SENSOR_CALIBRATION_DEFAULT ) {
784- calibration_default_count ++ ;
785- }
782+ unsigned int calibration_count = 0 ;
783+ unsigned int calibration_default_count = 0 ;
784+ for (size_t i = 0 ; i < 3 ; ++ i ) {
785+ if (parser -> calibrated & (1 << i )) {
786+ unsigned int calibration = array_uint16_be (data + base + 1 + i * 2 );
786787
787- parser -> calibration [i ] = calibration / 100000.0 ;
788- if (parser -> model == PREDATOR ) {
789- // The Predator expects the mV output of the cells to be
790- // within 30mV to 70mV in 100% O2 at 1 atmosphere. If the
791- // calibration value is scaled with a factor 2.2, then the
792- // sensors lines up and matches the average.
793- parser -> calibration [i ] *= 2.2 ;
788+ calibration_count ++ ;
789+ if (calibration == SENSOR_CALIBRATION_DEFAULT ) {
790+ calibration_default_count ++ ;
791+ }
792+
793+ parser -> calibration [i ] = calibration / 100000.0 ;
794+ if (parser -> model == PREDATOR ) {
795+ // The Predator expects the mV output of the cells to be
796+ // within 30mV to 70mV in 100% O2 at 1 atmosphere. If the
797+ // calibration value is scaled with a factor 2.2, then the
798+ // sensors lines up and matches the average.
799+ parser -> calibration [i ] *= 2.2 ;
800+ }
794801 }
795802 }
796- }
797803
798- if (calibration_count > 0 ) {
799- if (calibration_default_count < calibration_count ) {
800- print_calibration (parser );
801- } else {
802- // All calibrated sensors report the default calibration value
803- // so this could be a DiveCAN controller, where the calibration values
804- // are stored in the CCR's sensor module.
805- parser -> needs_divecan_calibration_estimate = true;
804+ if (calibration_count > 0 ) {
805+ if (calibration_default_count < calibration_count ) {
806+ print_calibration (parser );
807+ } else {
808+ // All calibrated sensors report the default calibration value
809+ // so this could be a DiveCAN controller, where the calibration values
810+ // are stored in the CCR's sensor module.
811+ parser -> needs_divecan_calibration_estimate = true;
812+ }
806813 }
807814 }
808815
809- // Get the dive mode from the header (if available).
810- if (logversion >= 8 ) {
811- divemode = data [parser -> opening [4 ] + (pnf ? 1 : 112 )];
812- }
813-
814816 // Get the correct model number from the final block.
815817 if (parser -> final != UNDEFINED ) {
816818 parser -> model = data [parser -> final + 13 ];
0 commit comments