Mercurial > public > ostc4
view Discovery/Inc/logbook.h @ 471:73da921869d9 fix-bat-2
bugfix: implement battery charge percentage in dive header
This commit is (much) less trivial than the related 919e5cb51c92.
First, rename the CCRmode attribute (corresponding to byte Ox59) of
the SLogbookHeaderOSTC3. This byte (according to the hwOS interface
document) does not contain any CCR related value, but it contains
"battery information". Already since 2017, this byte is used from
libdivecomputer to interface the charge percentage. So, its
renamed from CCRmode to batteryCharge, to reflect its true purpose.
Now, simply add a batteryCharge attribute to the SLogbookHeader
(and see below why that is possible, without breaking things).
The remaining changes are trivial to implement battery charge
percentage in dive header.
Caveat: do not get confused by the exact role of the individual
logbook header types. SLogbookHeaderOSTC3 is the formal type of
the logbook format that the OSTC4 produces. This format is
supposed to identical to the format, as is used in hwOS for the
series of small OSTCs. Only some values of attributes are different.
For example, the OSTC4 supports VPM, so byte 0x79 (deco model used
for this dive) also has a value for VPM. But the SLogbookHeader
type, despite its name and structure, is *not* a true logbook
header, as it includes attributes that are not available in the
SLogbookHeaderOSTC3 formal header type.
Signed-off-by: Jan Mulder <jan@jlmulder.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Wed, 22 Apr 2020 13:08:57 +0200 |
parents | 5dd996ed8611 |
children | 3db9eba89e3c |
line wrap: on
line source
/////////////////////////////////////////////////////////////////////////////// /// -*- coding: UTF-8 -*- /// /// \file Discovery/Inc/logbook.h /// \brief /// \author Heinrichs Weikamp /// \date 2018 /// /// $Id$ /////////////////////////////////////////////////////////////////////////////// /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh /// /// This program is free software: you can redistribute it and/or modify /// it under the terms of the GNU General Public License as published by /// the Free Software Foundation, either version 3 of the License, or /// (at your option) any later version. /// /// This program is distributed in the hope that it will be useful, /// but WITHOUT ANY WARRANTY; without even the implied warranty of /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /// GNU General Public License for more details. /// /// You should have received a copy of the GNU General Public License /// along with this program. If not, see <http://www.gnu.org/licenses/>. ////////////////////////////////////////////////////////////////////////////// #ifndef LOGBOOK_H #define LOGBOOK_H #include "data_central.h" #include "settings.h" #define NUM_GAS (5) /* number of selectable gases */ typedef struct { uint8_t setpoint_cbar; uint8_t depth_meter; } SSetpointLog; typedef struct { uint8_t oxygen_percentage; uint8_t helium_percentage; uint8_t depth_meter; gasbit8_Type note; } SGasListLog; //Logbook typedef struct { uint16_t diveHeaderStart; uint8_t pBeginProfileData[3]; uint8_t pEndProfileData[3]; uint8_t profileLength[3]; uint8_t logbookProfileVersion; uint8_t dateYear; uint8_t dateMonth; uint8_t dateDay; uint8_t timeHour; uint8_t timeMinute; uint8_t extraPagesWithData; /* from here on: changes in order with respect to OSTC3 */ uint16_t maxDepth; uint16_t diveTimeMinutes; uint8_t diveTimeSeconds; uint8_t samplingRate; int16_t minTemp; uint16_t surfacePressure_mbar; uint16_t desaturationTime; SGasListLog gasordil[NUM_GAS]; uint8_t firmwareVersionLow; uint8_t firmwareVersionHigh; uint16_t batteryVoltage; uint16_t cnsAtBeginning; uint8_t gfAtBeginning; uint8_t gfAtEnd; uint16_t personalDiveCount; uint8_t batteryCharge; SSetpointLog setpoint[NUM_GAS]; uint16_t maxCNS; uint16_t averageDepth_mbar; uint16_t total_diveTime_seconds; uint8_t salinity; uint8_t gfLow_or_Vpm_conservatism; uint8_t gfHigh; uint8_t decoModel; float n2Compartments[16]; float heCompartments[16]; uint8_t n2CompartDesatTime_min[16]; uint8_t heCompartDesatTime_min[16]; uint16_t diveNumber; uint8_t lastDecostop_m; uint8_t CCRmode; uint8_t diveMode; uint8_t hwHudLastStatus; /* from here on identical to OSTC3 again */ uint16_t hwHudBattery_mV; uint8_t batteryGaugeRegisters[6]; uint16_t diveHeaderEnd; } SLogbookHeader; //Logbook OSTC3 typedef struct { uint8_t diveHeaderStart[2]; uint8_t pBeginProfileData[3]; uint8_t pEndProfileData[3]; uint8_t logbookProfileVersion; uint8_t profileLength[3]; uint8_t dateYear; uint8_t dateMonth; uint8_t dateDay; uint8_t timeHour; uint8_t timeMinute; uint8_t maxDepth[2]; uint8_t diveTimeMinutes[2]; uint8_t diveTimeSeconds; uint8_t minTemp[2]; uint8_t surfacePressure_mbar[2]; uint8_t desaturationTime[2]; uint8_t gasordil[NUM_GAS*4]; uint8_t firmwareVersionLow; uint8_t firmwareVersionHigh; uint8_t batteryVoltage[2]; uint8_t samplingRate; uint8_t cnsAtBeginning[2]; uint8_t gfAtBeginning; uint8_t gfAtEnd; uint8_t personalDiveCount[2]; uint8_t batteryCharge; uint8_t setpoint[5*2]; uint8_t salinity; uint8_t maxCNS[2]; uint8_t averageDepth_mbar[2]; uint8_t total_diveTime_seconds[2]; uint8_t gfLow_or_Vpm_conservatism; uint8_t gfHigh; uint8_t decoModel; uint8_t diveNumber[2]; uint8_t diveMode; uint8_t n2CompartDesatTime_min[16]; uint8_t n2Compartments[16*4]; uint8_t heCompartDesatTime_min[16]; uint8_t heCompartments[16*4]; uint8_t lastDecostop_m; uint8_t safetyDistance_10cm; uint8_t hwHudBattery_mV[2]; uint8_t hwHudLastStatus; uint8_t batteryGaugeRegisters[6]; uint8_t diveHeaderEnd[2]; } SLogbookHeaderOSTC3; //Logbook OSTC3 typedef struct { uint8_t profileLength[3]; uint8_t dateYear; uint8_t dateMonth; uint8_t dateDay; uint8_t timeHour; uint8_t timeMinute; uint8_t maxDepth[2]; uint8_t diveTimeMinutes[2]; uint8_t diveTimeSeconds; uint8_t totalDiveNumberLow; uint8_t totalDiveNumberHigh; uint8_t profileVersion; } SLogbookHeaderOSTC3compact; typedef struct { uint8_t profileLength[3]; uint8_t samplingRate_seconds; uint8_t numDivisors; uint8_t tempType; uint8_t tempLength; uint8_t tempDivisor; uint8_t deco_ndlType; uint8_t deco_ndlLength; uint8_t deco_ndlDivisor; uint8_t gfType; uint8_t gfLength; uint8_t gfDivisor; uint8_t ppo2Type; uint8_t ppo2Length; uint8_t ppo2Divisor; uint8_t decoplanType; uint8_t decoplanLength; uint8_t decoplanDivisor; uint8_t cnsType; uint8_t cnsLength; uint8_t cnsDivisor; uint8_t tankType; uint8_t tankLength; uint8_t tankDivisor; } SSmallHeader; typedef struct { int8_t percentageO2; int8_t percentageHe; } SManualGas; void logbook_writeSample(const SDiveState *state); void logbook_initNewdiveProfile(const SDiveState* pInfo, SSettings* pSettings); void logbook_EndDive(void); SLogbookHeader* logbook_getCurrentHeader(void); SLogbookHeaderOSTC3 * logbook_build_ostc3header(SLogbookHeader* pLogbookHeader); SLogbookHeaderOSTC3compact * logbook_build_ostc3header_compact(SLogbookHeader* pHead); uint8_t logbook_getNumberOfHeaders(void); uint8_t logbook_getHeader(uint8_t StepBackwards,SLogbookHeader* pLogbookHeader); uint16_t logbook_readSampleData(uint8_t StepBackwards, uint16_t length,uint16_t* depth, uint8_t* gasid, int16_t* temperature, uint16_t* ppo2, uint16_t* setpoint, uint16_t* sensor1, uint16_t* sensor2, uint16_t* sensor3, uint16_t* cns, uint8_t* bailout, uint16_t* decostopDepth, uint16_t* tank); void logbook_test(void); void logbook_InitAndWrite(const SDiveState* pStateReal); void logbook_recover_brokenlog(uint8_t headerId); uint16_t logbook_lastDive_diveNumber(void); uint16_t logbook_fillDummySampleBuffer(SLogbookHeader* pHeader); void logbook_readDummySamples(uint8_t* pTarget, uint16_t length); #endif /* LOGBOOK_H */