view Discovery/Inc/logbook.h @ 250:822416168585 bm-2

Buelmann: new implementation for ceiling Since my first functional fix in the ceiling computation in commit ceecabfddb57, I noticed that the computation used a linear search, that became rather computational expensive after that commit. The simple question is: why not a binary search? So, this commit implements the binary search. But there is a long story attached to this. Comparing ceiling results from hwOS and this OSTC4 code were very different. Basically, the original OSTC4 algorithm computed the ceiling using the same GFlow to GFhigh slope, in such a way, that the ceiling was in sync with the presented deco stops, where the hwOS code presents a GFhigh based ceiling. This said, it is more logical when the OSTC4 and hwOS code give similar results. This new recursive algorithm gives very similar results for the ceiling compared to hwOS. To be complete here, the Buelmann ceiling is the depth to which you can ascend, so that the leading tissue reaches GFhigh. This also explains why the deepest deco stop is normally deeper than the ceiling (unless one dives with GF like 80/80). The code implemented here is rather straightforward recursion. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Thu, 11 Apr 2019 17:48:48 +0200
parents f23b9055436f
children 6e78137952af
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"

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[5];
    uint8_t  firmwareVersionLow;
    uint8_t  firmwareVersionHigh;
    uint16_t batteryVoltage;
    uint16_t cnsAtBeginning;
    uint8_t  gfAtBeginning;
    uint8_t  gfAtEnd;
    uint16_t personalDiveCount;
    SSetpointLog setpoint[5];
    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[5*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 CCRmode;
    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(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);
void logbook_test(void);
void logbook_InitAndWrite(void);
void logbook_recover_brokenlog(uint8_t headerId);

uint16_t logbook_lastDive_diveNumber(void);

#endif /* LOGBOOK_H */