38
+ − 1 /**
+ − 2 ******************************************************************************
+ − 3 * @copyright heinrichs weikamp
+ − 4 * @file logbook.c
+ − 5 * @author heinrichs weikamp gmbh and heinrichs weikamp gmbh
+ − 6 * @date 22-Apr-2014
+ − 7 * @version V0.0.3
+ − 8 * @since 03-Feb-2016
+ − 9 * @brief Everything about creating and evaluating the logbook
+ − 10 * without the flash part which is included in externLogbookFlash.c
+ − 11 * and the USB/Bluetooth part in tComm.c
+ − 12 * CHANGE V0.0.3 hw: ppO2 sensor values
+ − 13 * CHANGE V0.0.4 hw: fix event bytes according to hwos_interface.odt dated 160610 in bitbucket hwOS
+ − 14 * @bug
+ − 15 * @warning
+ − 16 @verbatim
+ − 17 ==============================================================================
+ − 18 ##### Header #####
+ − 19 ==============================================================================
+ − 20 [..] SLogbookHeader
+ − 21 The order has changed in comparsion to OSTC3 for perfect alignment
+ − 22 with 16bit and 32bit. The header is 256kB as well.
+ − 23 DO NOT rearrange anything but add new data to a second page
+ − 24 beyond diveHeaderEnd. Use extraPagesWithData to indicate that there is
+ − 25 data available that was not available in the OSTC3 256KB
+ − 26 This data will be behind the diveHeaderEnd. DO NOT delete diveHeaderEnd.
+ − 27
+ − 28 [..] SLogbookHeaderOSTC3
+ − 29 is the format used by the OSTC3.
+ − 30 logbook_getHeaderOSTC3() does the job using the global headers in logbook.c
+ − 31
+ − 32 [..] SSmallHeader
+ − 33 - is the format used by the OSTC3
+ − 34
+ − 35 [..] Summary
+ − 36 The header format is not perfect and might be optimized prior to
+ − 37 releasing the diving computer. For now it is good to be compatible
+ − 38 with PC software available for checking the content of the logbook
+ − 39
+ − 40
+ − 41 @endverbatim
+ − 42 ******************************************************************************
+ − 43 * @attention
+ − 44 *
+ − 45 * <h2><center>© COPYRIGHT(c) 2014 heinrichs weikamp</center></h2>
+ − 46 *
+ − 47 ******************************************************************************
+ − 48 */
+ − 49
+ − 50 /* Includes ------------------------------------------------------------------*/
+ − 51 #include <stdint.h>
+ − 52 #include <string.h>
+ − 53 #include "logbook.h"
+ − 54 //#include "test_vpm.h"
+ − 55 #include "externLogbookFlash.h"
+ − 56 #include "data_exchange.h"
+ − 57 #include "decom.h"
+ − 58 #include "tHome.h" // for tHome_findNextStop()
445
+ − 59 #include "settings.h"
455
+ − 60 #include "configuration.h"
38
+ − 61
+ − 62 /* Private types -------------------------------------------------------------*/
+ − 63
+ − 64 #define LOGBOOK_VERSION (0x30)
+ − 65 #define LOGBOOK_VERSION_OSTC3 (0x24)
+ − 66
411
+ − 67 #define DEFAULT_SAMPLES (100) /* Number of sample data bytes in case of an broken header information */
455
+ − 68 #define DUMMY_SAMPLES (1000) /* Maximum number of samples profided by a dummy dive profile */
411
+ − 69
38
+ − 70 typedef struct /* don't forget to adjust void clear_divisor(void) */
+ − 71 {
+ − 72 uint8_t temperature;
+ − 73 uint8_t deco_ndl;
+ − 74 uint8_t gradientFactor;
+ − 75 uint8_t ppo2;
+ − 76 uint8_t decoplan;
+ − 77 uint8_t cns;
+ − 78 uint8_t tank;
+ − 79 } SDivisor;
+ − 80
+ − 81 /* Exported variables --------------------------------------------------------*/
+ − 82
+ − 83 /* Private variables ---------------------------------------------------------*/
411
+ − 84 static SLogbookHeader gheader;
194
+ − 85 static SLogbookHeaderOSTC3 headerOSTC3;
+ − 86 static SLogbookHeaderOSTC3compact headerOSTC3compact;
+ − 87 static SSmallHeader smallHeader;
+ − 88 static SDivisor divisor;
+ − 89 static SDivisor divisorBackup;
38
+ − 90
455
+ − 91 static SSmallHeader smallDummyHeader;
+ − 92 static uint16_t dummyWriteIdx;
+ − 93 static uint16_t dummyReadIdx;
465
+ − 94 static uint8_t dummyMemoryBuffer[5000];
455
+ − 95
+ − 96
38
+ − 97 /* Private function prototypes -----------------------------------------------*/
194
+ − 98 static void clear_divisor(void);
+ − 99 static void logbook_SetAverageDepth(float average_depth_meter);
+ − 100 static void logbook_SetMinTemperature(float min_temperature_celsius);
+ − 101 static void logbook_SetMaxCNS(float max_cns_percentage);
270
+ − 102 static void logbook_SetCompartmentDesaturation(const SDiveState * pStateReal);
194
+ − 103 static void logbook_SetLastStop(float last_stop_depth_bar);
+ − 104 static void logbook_writedata(void * data, int length_byte);
270
+ − 105 static void logbook_UpdateHeader(const SDiveState * pStateReal);
458
+ − 106 static void logbook_createDummyProfile(SLogbookHeader* pHeader, uint16_t length, uint16_t* depth, int16_t* temperature, uint16_t* ppo2);
38
+ − 107
+ − 108 /* Exported functions --------------------------------------------------------*/
+ − 109
+ − 110 void logbook_EndDive(void)
+ − 111 {
411
+ − 112 ext_flash_close_new_dive_log((uint8_t*) &gheader);
38
+ − 113 }
+ − 114
+ − 115
+ − 116 // ===============================================================================
+ − 117 // logbook_last_totalDiveCount
+ − 118 /// @brief Fix setting issues
+ − 119 /// @date 04-April-2016
+ − 120 ///
+ − 121 /// @return diveNumber (totalDiveCounter) of latest log entry, 0 if not a valid header
+ − 122 // ===============================================================================
+ − 123 uint16_t logbook_lastDive_diveNumber(void)
+ − 124 {
+ − 125 SLogbookHeader tempLogbookHeader;
+ − 126 if(logbook_getHeader(0, &tempLogbookHeader))
+ − 127 {
+ − 128 return tempLogbookHeader.diveNumber;
+ − 129 }
+ − 130 else
+ − 131 {
+ − 132 return 0;
+ − 133 }
+ − 134 }
+ − 135
+ − 136
+ − 137 /**
+ − 138 ******************************************************************************
+ − 139 * @brief logbook_getCurrentHeader. /
281
+ − 140 * @author heinrichs weikamp
38
+ − 141 * @version V0.0.1
+ − 142 * @date 22-April-2014
+ − 143 ******************************************************************************
+ − 144 *
+ − 145 * @return SLogbookHeader*:
+ − 146 */
+ − 147 SLogbookHeader* logbook_getCurrentHeader(void)
+ − 148 {
411
+ − 149 return &gheader;
38
+ − 150 }
+ − 151
+ − 152 /**
+ − 153 ******************************************************************************
+ − 154 * @brief logbook_getNumberOfHeaders. /
+ − 155 * @author heinrichs weikamp gmbh
+ − 156 * @version V0.0.1
+ − 157 * @date 18-May-2016
+ − 158 ******************************************************************************
+ − 159 *
+ − 160 * @return uint8_t : number of valid headers (0xFAFA) found.
+ − 161 */
+ − 162 uint8_t logbook_getNumberOfHeaders(void)
+ − 163 {
+ − 164 return ext_flash_count_dive_headers();
+ − 165 }
+ − 166
+ − 167
+ − 168 /**
+ − 169 ******************************************************************************
+ − 170 * @brief logbook_getHeader. /
281
+ − 171 * @author heinrichs weikamp
38
+ − 172 * @version V0.0.1
+ − 173 * @date 22-April-2014
+ − 174 ******************************************************************************
+ − 175 *
+ − 176 * @param StepBackwards : 0 Last lokbook entry, 1 second to last entry, etc.
+ − 177 * @param SSLogbookHeader* pLogbookHeader: Output found LogbookHeader
+ − 178 * @return uint8_t : 1 = success
+ − 179 */
+ − 180 uint8_t logbook_getHeader(uint8_t StepBackwards,SLogbookHeader* pLogbookHeader)
+ − 181 {
+ − 182 ext_flash_read_dive_header((uint8_t *)pLogbookHeader, StepBackwards);
+ − 183 if(pLogbookHeader->diveHeaderStart != 0xFAFA)
+ − 184 return 0;
+ − 185 else
+ − 186 return 1;
+ − 187 }
+ − 188
+ − 189 /**
+ − 190 ******************************************************************************
+ − 191 * @brief logbook_initNewdiveProfile. /
+ − 192 * creates header and smallHeader from diveState and global Settings
+ − 193 * and writes new lookboock entry on flash device
+ − 194 * diveState
281
+ − 195 * @author heinrichs weikamp
38
+ − 196 * @version V0.0.1
+ − 197 * @date 22-April-2014
+ − 198 ******************************************************************************
+ − 199 *
+ − 200 * @param SDiveState* pInfo: Input
+ − 201 * @param SSettings* pSettings: Input
+ − 202 */
+ − 203
+ − 204 void logbook_initNewdiveProfile(const SDiveState* pInfo, SSettings* pSettings)
+ − 205 {
+ − 206 RTC_DateTypeDef Sdate;
+ − 207 RTC_TimeTypeDef Stime;
+ − 208
+ − 209 for(int i = 0; i < sizeof(SLogbookHeader); i++)
+ − 210 {
411
+ − 211 ((uint8_t*)(&gheader))[i] = 0;
38
+ − 212 }
411
+ − 213 gheader.diveHeaderStart = 0xFAFA;
+ − 214 gheader.diveHeaderEnd = 0xFBFB;
+ − 215 gheader.samplingRate = 2;
38
+ − 216 if(pInfo->diveSettings.diveMode == DIVEMODE_OC)
+ − 217 {
+ − 218 for(int i = 0; i < 5; i++)
+ − 219 {
411
+ − 220 gheader.gasordil[i].oxygen_percentage = pSettings->gas[i+1].oxygen_percentage;
+ − 221 gheader.gasordil[i].helium_percentage = pSettings->gas[i+1].helium_percentage;
+ − 222 gheader.gasordil[i].note.uw = pSettings->gas[i+1].note.uw;
+ − 223 gheader.gasordil[i].depth_meter = pSettings->gas[i+1].depth_meter;
38
+ − 224 }
+ − 225 }
+ − 226 else
+ − 227 {
+ − 228 for(int i = 0; i < 5; i++)
+ − 229 {
411
+ − 230 gheader.gasordil[i].oxygen_percentage = pSettings->gas[i+6].oxygen_percentage;
+ − 231 gheader.gasordil[i].helium_percentage = pSettings->gas[i+6].helium_percentage;
+ − 232 gheader.gasordil[i].note.uw = pSettings->gas[i+6].note.uw;
+ − 233 gheader.gasordil[i].depth_meter = pSettings->gas[i+6].depth_meter;
38
+ − 234 }
+ − 235
+ − 236 for(int i = 0; i < 5; i++)
+ − 237 {
411
+ − 238 gheader.setpoint[i].setpoint_cbar = pSettings->setpoint[i+1].setpoint_cbar;
+ − 239 gheader.setpoint[i].depth_meter = pSettings->setpoint[i+1].depth_meter;
38
+ − 240 }
+ − 241 }
+ − 242 // header.gasordil[pInfo->lifeData.actualGas.GasIdInSettings].depth_meter = 0;
+ − 243
+ − 244 translateDate(pInfo->lifeData.dateBinaryFormat, &Sdate);
+ − 245 translateTime(pInfo->lifeData.timeBinaryFormat, &Stime);
411
+ − 246 gheader.dateYear = Sdate.Year;
+ − 247 gheader.dateMonth = Sdate.Month;
+ − 248 gheader.dateDay = Sdate.Date;
+ − 249 gheader.timeHour = Stime.Hours;
+ − 250 gheader.timeMinute = Stime.Minutes;
+ − 251 gheader.cnsAtBeginning = (uint16_t)pInfo->lifeData.cns;
+ − 252 gheader.surfacePressure_mbar = (uint16_t)(pInfo->lifeData.pressure_surface_bar * 1000);
+ − 253 gheader.firmwareVersionHigh = firmwareVersion_16bit_high();
+ − 254 gheader.firmwareVersionLow = firmwareVersion_16bit_low();
+ − 255 gheader.logbookProfileVersion = LOGBOOK_VERSION;
+ − 256 gheader.salinity = pSettings->salinity;
+ − 257 gheader.diveNumber = pSettings->totalDiveCounter;
+ − 258 gheader.personalDiveCount = pSettings->personalDiveCount;
38
+ − 259
411
+ − 260 gheader.diveMode = pInfo->diveSettings.diveMode;
+ − 261 gheader.CCRmode = pInfo->diveSettings.CCR_Mode;
+ − 262 gheader.lastDecostop_m = pSettings->last_stop_depth_meter;
38
+ − 263
+ − 264 if(pInfo->diveSettings.deco_type.ub.standard == GF_MODE)
+ − 265 {
411
+ − 266 gheader.decoModel = 1;
+ − 267 gheader.gfLow_or_Vpm_conservatism = pInfo->diveSettings.gf_low;
+ − 268 gheader.gfHigh = pInfo->diveSettings.gf_high;
38
+ − 269 }
+ − 270 else
+ − 271 {
411
+ − 272 gheader.decoModel = 2;
+ − 273 gheader.gfLow_or_Vpm_conservatism = pInfo->diveSettings.vpm_conservatism;
+ − 274 gheader.gfHigh = 0;
38
+ − 275 }
+ − 276
411
+ − 277 memcpy(gheader.n2Compartments, pInfo->lifeData.tissue_nitrogen_bar, 64);
+ − 278 memcpy(gheader.heCompartments, pInfo->lifeData.tissue_helium_bar, 64);
38
+ − 279
270
+ − 280 logbook_SetCompartmentDesaturation(pInfo);
38
+ − 281
411
+ − 282 ext_flash_start_new_dive_log_and_set_actualPointerSample((uint8_t*)&gheader);
38
+ − 283
+ − 284 smallHeader.profileLength[0] = 0xFF;
+ − 285 smallHeader.profileLength[1] = 0xFF;
+ − 286 smallHeader.profileLength[2] = 0xFF;
+ − 287 smallHeader.samplingRate_seconds = 2;
+ − 288 smallHeader.numDivisors = 7;
+ − 289
+ − 290 smallHeader.tempType = 0;
+ − 291 smallHeader.tempLength = 2;
+ − 292 smallHeader.tempDivisor = 6;
+ − 293
+ − 294 smallHeader.deco_ndlType = 1;
+ − 295 smallHeader.deco_ndlLength = 2;
+ − 296 smallHeader.deco_ndlDivisor = 6; //= 6;
+ − 297
+ − 298 /* GF in % at actual position */
+ − 299 smallHeader.gfType = 2;
+ − 300 smallHeader.gfLength = 1;
+ − 301 smallHeader.gfDivisor = 0; //12;
+ − 302
+ − 303 /* 3 Sensors: 8bit ppO2 in 0.01bar, 16bit voltage in 0,1mV */
+ − 304 smallHeader.ppo2Type = 3;
+ − 305 smallHeader.ppo2Length = 9;
+ − 306 smallHeader.ppo2Divisor = 2; //2
+ − 307
+ − 308 /* last 15 stops in minutes (last, second_to_last, ... */
+ − 309 /* last stop depth is defined in header */
+ − 310 smallHeader.decoplanType = 4;
+ − 311 smallHeader.decoplanLength = 15;
+ − 312 smallHeader.decoplanDivisor = 12;//12;
+ − 313
+ − 314 smallHeader.cnsType = 5;
+ − 315 smallHeader.cnsLength = 2;
+ − 316 smallHeader.cnsDivisor = 12;
+ − 317
+ − 318 smallHeader.tankType = 6;
455
+ − 319 #ifdef ENABLE_BOTTLE_SENSOR
+ − 320 smallHeader.tankLength = 2;
+ − 321 smallHeader.tankDivisor = 30; /* log tank data once a minute */
+ − 322 #else
38
+ − 323 smallHeader.tankLength = 0;
+ − 324 smallHeader.tankDivisor = 0;
455
+ − 325 #endif
38
+ − 326 logbook_writedata((void *) &smallHeader,sizeof(smallHeader));
+ − 327
+ − 328 clear_divisor();
+ − 329 }
+ − 330
+ − 331 /**
+ − 332 ******************************************************************************
+ − 333 * @brief clear_divisor / clears divisor struct
281
+ − 334 * @author heinrichs weikamp
38
+ − 335 * @version V0.0.1
+ − 336 * @date 22-April-2014
+ − 337 ******************************************************************************
+ − 338 *
+ − 339 */
194
+ − 340 static void clear_divisor(void)
38
+ − 341 {
+ − 342 divisor.cns = smallHeader.cnsDivisor - 1;
+ − 343 divisor.decoplan = smallHeader.decoplanDivisor - 1;
+ − 344 divisor.deco_ndl = smallHeader.deco_ndlDivisor - 1;
+ − 345 divisor.gradientFactor = smallHeader.gfDivisor -1 ;
+ − 346 divisor.ppo2 = smallHeader.ppo2Divisor - 1;
+ − 347 divisor.tank = smallHeader.tankDivisor - 1;
+ − 348 divisor.temperature = smallHeader.tempDivisor - 1;
+ − 349 }
+ − 350
+ − 351
+ − 352 /**
+ − 353 ******************************************************************************
+ − 354 * @brief add16. / adds 16 bit variable to 8 bit array
281
+ − 355 * @author heinrichs weikamp
38
+ − 356 * @version V0.0.1
+ − 357 * @date 22-April-2014
+ − 358 ******************************************************************************
+ − 359 *
+ − 360 * @param uint8_t *pos: Output 8 bit array
+ − 361 * @param uint16_t var: 16 bit variable
+ − 362 */
194
+ − 363 static void addU16(uint8_t *pos, uint16_t var)
38
+ − 364 {
+ − 365 *((uint16_t*)pos) = var;
+ − 366 }
+ − 367
194
+ − 368 static void addS16(uint8_t *pos, int16_t var)
38
+ − 369 {
+ − 370 *((int16_t*)pos) = var;
+ − 371 }
+ − 372
+ − 373 /**
+ − 374 ******************************************************************************
+ − 375 * @brief logbook_writeSample. / Writes one logbook sampl
281
+ − 376 * @author heinrichs weikamp
38
+ − 377 * @date 22-April-2014
+ − 378 * @version V0.0.2
+ − 379 * @since 20-June-2016
+ − 380 * @bug Deco/NDL Status fixed in V0.0.2
+ − 381
+ − 382
+ − 383 ******************************************************************************
+ − 384 *
+ − 385 * @param SDiveState state:
+ − 386 */
+ − 387
270
+ − 388 void logbook_writeSample(const SDiveState *state)
38
+ − 389 {
+ − 390 uint8_t sample[256];
+ − 391 // int position = 0;
+ − 392 int length = 0;
+ − 393 // _Bool bEvent = 0;
+ − 394 uint8_t nextstopDepthMeter = 0;
+ − 395 uint16_t nextstopLengthSeconds = 0;
+ − 396 uint8_t nextstopLengthMinutes = 0;
+ − 397 bit8_Type eventByte1, eventByte2;
+ − 398 bit8_Type profileByteFlag;
+ − 399 int i = 0;
+ − 400 for(i = 0; i <256 ;i++)
+ − 401 sample[i] = 0;
269
+ − 402 addU16(sample, (uint16_t)(state->lifeData.depth_meter * 100));
38
+ − 403 length += 2;
+ − 404 sample[2] = 0;
+ − 405 length++;
+ − 406 eventByte1.uw = 0;
+ − 407 eventByte2.uw = 0;
941
+ − 408 uint8_t* pdata;
38
+ − 409 //uint16_t tmpU16 = 0;
130
+ − 410 const SDecoinfo * pDecoinfo; // new hw 160620
38
+ − 411
+ − 412 //BuildEevntyte 1
+ − 413 // sub old 0-3 only one at a time
269
+ − 414 if(state->events.manualMarker)
38
+ − 415 {
+ − 416 eventByte1.uw = 6;
+ − 417 }
+ − 418 else
269
+ − 419 if(state->warnings.decoMissed)
38
+ − 420 {
+ − 421 eventByte1.uw = 2;
+ − 422 }
+ − 423 else
269
+ − 424 if(state->warnings.ppO2Low)
38
+ − 425 {
+ − 426 eventByte1.uw = 4;
+ − 427 }
+ − 428 else
269
+ − 429 if(state->warnings.ppO2High)
38
+ − 430 {
+ − 431 eventByte1.uw = 5;
+ − 432 }
+ − 433 else
269
+ − 434 if(state->warnings.lowBattery)
38
+ − 435 {
+ − 436 eventByte1.uw = 7;
+ − 437 }
+ − 438 else
269
+ − 439 if(state->warnings.slowWarning)
38
+ − 440 {
+ − 441 eventByte1.uw = 1;
+ − 442 }
+ − 443 // sub bit 4 to 7
281
+ − 444 if(state->events.manualGasSet)
38
+ − 445 {
+ − 446 eventByte1.ub.bit4 = 1;
+ − 447 }
269
+ − 448 if(state->events.gasChange)
38
+ − 449 {
+ − 450 eventByte1.ub.bit5 = 1;
+ − 451 }
269
+ − 452 if(state->events.setpointChange)
38
+ − 453 {
+ − 454 eventByte1.ub.bit6 = 1;
+ − 455 }
+ − 456 // sub bit 7 + eventbyte2
269
+ − 457 if(state->events.bailout)
38
+ − 458 {
+ − 459 eventByte1.ub.bit7 = 1;
+ − 460 eventByte2.ub.bit0 = 1;
+ − 461 }
929
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
diff
changeset
+ − 462 if (state->events.compassHeadingUpdate) {
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
diff
changeset
+ − 463 eventByte1.ub.bit7 = 1;
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
diff
changeset
+ − 464 eventByte2.ub.bit1 = 1;
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
diff
changeset
+ − 465 }
941
+ − 466 if (state->events.gnssPositionUpdate) {
+ − 467 eventByte1.ub.bit7 = 1;
+ − 468 eventByte2.ub.bit2 = 1;
+ − 469 }
+ − 470
38
+ − 471 //Add EventByte 1
+ − 472 if(eventByte1.uw > 0)
+ − 473 {
+ − 474 sample[length] = eventByte1.uw;
+ − 475 length++;
+ − 476 }
+ − 477 if(eventByte2.uw > 0)
+ − 478 {
+ − 479 sample[length] = eventByte2.uw;
+ − 480 length++;
+ − 481 }
+ − 482 //Add EventInfos
281
+ − 483 if(state->events.manualGasSet)
38
+ − 484 {
+ − 485 //manual gas in %O2 & %He
281
+ − 486 sample[length] = state->events.info_manualGasSetO2;
38
+ − 487 length += 1;
281
+ − 488 sample[length] = state->events.info_manualGasSetHe;
38
+ − 489 length += 1;
+ − 490 }
269
+ − 491 if(state->events.gasChange)
38
+ − 492 {
+ − 493 //Current gas (gasid)
269
+ − 494 sample[length] = state->events.info_GasChange;
38
+ − 495 length += 1;
+ − 496 }
269
+ − 497 if(state->events.setpointChange)
38
+ − 498 {
+ − 499 //New setpoint in cbar
269
+ − 500 sample[length] = state->events.info_SetpointChange;
38
+ − 501 length += 1;
+ − 502 }
269
+ − 503 if(state->events.bailout)
38
+ − 504 {
+ − 505 //bailout gas in % O2 & %He
269
+ − 506 sample[length] = state->events.info_bailoutO2;
38
+ − 507 length += 1;
269
+ − 508 sample[length] = state->events.info_bailoutHe;
38
+ − 509 length += 1;
+ − 510 }
929
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
diff
changeset
+ − 511 if (state->events.compassHeadingUpdate) {
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
diff
changeset
+ − 512 // New heading and type of heading
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
diff
changeset
+ − 513 sample[length++] = state->events.info_compassHeadingUpdate & 0xFF;
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
diff
changeset
+ − 514 sample[length++] = (state->events.info_compassHeadingUpdate & 0xFF00) >> 8;
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
diff
changeset
+ − 515 }
941
+ − 516 if (state->events.gnssPositionUpdate) {
+ − 517 pdata = (uint8_t*)&state->events.info_gnssPosition.fLon;
+ − 518 sample[length++] = *pdata++;
+ − 519 sample[length++] = *pdata++;
+ − 520 sample[length++] = *pdata++;
+ − 521 sample[length++] = *pdata++;
+ − 522 pdata = (uint8_t*)&state->events.info_gnssPosition.fLat;
+ − 523 sample[length++] = *pdata++;
+ − 524 sample[length++] = *pdata++;
+ − 525 sample[length++] = *pdata++;
+ − 526 sample[length++] = *pdata++;
+ − 527 }
38
+ − 528
+ − 529 if(divisor.temperature == 0)
+ − 530 {
+ − 531 divisor.temperature = smallHeader.tempDivisor - 1;
269
+ − 532 addS16(&sample[length], (int16_t)((state->lifeData.temperature_celsius * 10.0f) + 0.5f));
38
+ − 533 length += 2;
+ − 534 }
+ − 535 else
+ − 536 {
+ − 537 divisor.temperature--;
+ − 538 }
+ − 539
+ − 540
+ − 541 if(smallHeader.deco_ndlDivisor > 0)
+ − 542 {
+ − 543 if(divisor.deco_ndl == 0)
+ − 544 {
+ − 545 divisor.deco_ndl = smallHeader.deco_ndlDivisor - 1;
+ − 546
+ − 547 if(stateUsed->diveSettings.deco_type.ub.standard == GF_MODE)
+ − 548 pDecoinfo = &stateUsed->decolistBuehlmann;
+ − 549 else if(stateUsed->diveSettings.deco_type.ub.standard == VPM_MODE)
+ − 550 pDecoinfo = &stateUsed->decolistVPM;
+ − 551 else // should not happen as only GF and VPM at the moment
+ − 552 {
+ − 553 sample[length] = 0;
+ − 554 length += 1;
+ − 555 sample[length] = 0;
+ − 556 length += 1;
458
+ − 557 pDecoinfo = &stateUsed->decolistBuehlmann; /* use GF per default if something went wrong */
38
+ − 558 }
+ − 559
+ − 560 if(pDecoinfo->output_ndl_seconds > 0)
+ − 561 {
+ − 562 sample[length] = 0;
+ − 563 length += 1;
283
+ − 564 sample[length] = (uint8_t)(pDecoinfo->output_ndl_seconds / 60);
281
+ − 565
+ − 566 // Limit stored sample within 0 to 240 mins (Since it's 8bit UINT only)
+ − 567 if ((pDecoinfo->output_ndl_seconds / 60) > 240) sample[length] = 240;
+ − 568 if ((pDecoinfo->output_ndl_seconds / 60) < 0) sample[length] = 0;
+ − 569
38
+ − 570 length += 1;
+ − 571 }
+ − 572 else if(pDecoinfo->output_time_to_surface_seconds)
+ − 573 {
+ − 574 tHome_findNextStop(pDecoinfo->output_stop_length_seconds, &nextstopDepthMeter, &nextstopLengthSeconds);
+ − 575 nextstopLengthMinutes = (nextstopLengthSeconds +59 ) / 60;
+ − 576
+ − 577 sample[length] = nextstopDepthMeter;
+ − 578 length += 1;
+ − 579 sample[length] = nextstopLengthMinutes;
+ − 580 length += 1;
+ − 581 }
+ − 582 else
+ − 583 {
+ − 584 sample[length] = 0;
+ − 585 length += 1;
+ − 586 sample[length] = 0;
+ − 587 length += 1;
+ − 588 }
+ − 589 }
+ − 590 else
+ − 591 {
+ − 592 divisor.deco_ndl --;
+ − 593 }
+ − 594 }
+ − 595
+ − 596
+ − 597 if(smallHeader.ppo2Divisor)
+ − 598 {
+ − 599 if(divisor.ppo2 == 0)
+ − 600 {
+ − 601 divisor.ppo2 = smallHeader.ppo2Divisor - 1;
+ − 602
+ − 603 for(int i = 0; i <3; i++)
+ − 604 {
269
+ − 605 sample[length] = (uint8_t)(state->lifeData.ppO2Sensor_bar[i] * 100.0f + 0.5f);
38
+ − 606 length += 1;
269
+ − 607 addU16(&sample[length], (uint16_t)(state->lifeData.sensorVoltage_mV[i] * 10.0f + 0.5f));
38
+ − 608 length += 2;
+ − 609 }
+ − 610 }
+ − 611 else
+ − 612 {
+ − 613 divisor.ppo2--;
+ − 614 }
+ − 615 }
+ − 616
+ − 617
+ − 618 if(smallHeader.decoplanDivisor)
+ − 619 {
+ − 620 if(divisor.decoplan == 0)
+ − 621 {
+ − 622 divisor.decoplan = smallHeader.decoplanDivisor - 1;
269
+ − 623 if(state->diveSettings.deco_type.ub.standard == VPM_MODE)
38
+ − 624 {
+ − 625 for(int i = 0; i <15; i++)
+ − 626 {
269
+ − 627 sample[length] = state->decolistVPM.output_stop_length_seconds[i] / 60;
38
+ − 628 length += 1;
+ − 629 }
+ − 630 }
269
+ − 631 else if(state->diveSettings.deco_type.ub.standard == GF_MODE)
38
+ − 632 {
+ − 633 for(int i = 0; i <15; i++)
+ − 634 {
269
+ − 635 sample[length] = state->decolistBuehlmann.output_stop_length_seconds[i] / 60;
38
+ − 636 length += 1;
+ − 637 }
+ − 638 }
+ − 639 else
+ − 640 {
+ − 641 for(int i = 0; i <15; i++)
+ − 642 {
+ − 643 sample[length] = 0;
+ − 644 length += 1;
+ − 645 }
+ − 646 }
+ − 647 // add16(&sample[length], state.temperature);
+ − 648 //length += 2;
+ − 649 }
+ − 650 else
+ − 651 {
+ − 652 divisor.decoplan --;
+ − 653 }
+ − 654 }
+ − 655 if(divisor.cns == 0)
+ − 656 {
+ − 657 divisor.cns = smallHeader.cnsDivisor - 1;
269
+ − 658 addU16(&sample[length], (uint16_t)state->lifeData.cns);
38
+ − 659 length += 2;
+ − 660 }
+ − 661 else
+ − 662 {
+ − 663 divisor.cns--;
+ − 664 }
+ − 665
455
+ − 666 #ifdef ENABLE_BOTTLE_SENSOR
+ − 667 if(smallHeader.tankDivisor)
+ − 668 {
+ − 669 if(divisor.tank == 0)
+ − 670 {
+ − 671 divisor.tank = smallHeader.tankDivisor - 1;
+ − 672 addS16(&sample[length], ((state->lifeData.bottle_bar[state->lifeData.actualGas.GasIdInSettings])));
+ − 673 length += smallHeader.tankLength;
+ − 674 }
+ − 675 else
+ − 676 {
+ − 677 divisor.tank--;
+ − 678 }
+ − 679 }
+ − 680 #endif
+ − 681
38
+ − 682 profileByteFlag.uw = length - 3;
+ − 683 if(eventByte1.uw)
+ − 684 {
+ − 685 profileByteFlag.ub.bit7 = 1;
+ − 686 }
+ − 687 sample[2] = profileByteFlag.uw;
+ − 688 logbook_writedata((void *) sample,length);
+ − 689
+ − 690 }
+ − 691
+ − 692 /**
+ − 693 ******************************************************************************
+ − 694 * @brief readSample. / Reads data of one logbook sample
281
+ − 695 * @author heinrichs weikamp
38
+ − 696 * @version V0.0.1
+ − 697 * @date 22-April-2014
+ − 698 ******************************************************************************
+ − 699 *
+ − 700 * @param int32_t* depth: output Value
+ − 701 * @param int16_t * gasid: output Value
+ − 702 * @param int32_t* temperature: output Value
+ − 703 * @param int32_t* sensor1, sensor2, sensor3: output Value
+ − 704 * @param int32_t* cns: output Value
+ − 705 * @return bytes read / 0 = reading Error
+ − 706 */
455
+ − 707 static uint16_t readSample(int32_t* depth, int16_t * gasid, int16_t* setpoint_cbar, int32_t* temperature, int32_t* sensor1, int32_t* sensor2,
941
+ − 708 int32_t* sensor3, int32_t* cns, SManualGas* manualGas, int16_t* bailout, int16_t* decostopDepth, uint16_t* tank,
+ − 709 SGnssCoord* pPosition, uint8_t* event)
38
+ − 710 {
+ − 711 int length = 0;
+ − 712 _Bool bEvent = 0;
+ − 713 bit8_Type eventByte1, eventByte2;
+ − 714 bit8_Type profileByteFlag;
+ − 715
+ − 716 eventByte1.uw = 0;
+ − 717 eventByte2.uw = 0;
+ − 718 uint8_t tempU8 = 0;
+ − 719 uint16_t temp = 0;
+ − 720 uint16_t bytesRead = 0;
941
+ − 721 uint32_t tempU32 = 0;
+ − 722 uint8_t index = 0;
38
+ − 723
+ − 724 if(gasid)
+ − 725 *gasid = -1;
+ − 726 if(temperature)
+ − 727 *temperature = -1000;
+ − 728 if(sensor1)
+ − 729 *sensor1 = -1;
+ − 730 if(sensor2)
+ − 731 *sensor2 = -1;
+ − 732 if(sensor3)
+ − 733 *sensor3 = -1;
+ − 734 if(cns)
+ − 735 *cns = -1;
+ − 736 if(setpoint_cbar)
+ − 737 *setpoint_cbar = -1;
+ − 738 if(bailout)
+ − 739 *bailout = -1;
455
+ − 740 if(tank)
+ − 741 *tank = 0;
+ − 742
38
+ − 743 if(manualGas)
+ − 744 {
+ − 745 manualGas->percentageO2 =-1;
+ − 746 manualGas->percentageHe =-1;
+ − 747 }
+ − 748 if(decostopDepth)
+ − 749 *decostopDepth = -1;
+ − 750
+ − 751 ext_flash_read_next_sample_part( (uint8_t*)&temp, 2);
+ − 752 if(depth)
+ − 753 *depth = (int32_t)temp;
+ − 754 bytesRead += 2;
+ − 755
+ − 756 ext_flash_read_next_sample_part( &profileByteFlag.uw, 1);
+ − 757 bytesRead ++;
+ − 758
+ − 759 bEvent = profileByteFlag.ub.bit7;
+ − 760 profileByteFlag.ub.bit7 = 0;
+ − 761 length = profileByteFlag.uw;
+ − 762
+ − 763 if(bEvent)
+ − 764 {
+ − 765 ext_flash_read_next_sample_part( &eventByte1.uw, 1);
+ − 766 bytesRead ++;
+ − 767
+ − 768 length--;
+ − 769
610
+ − 770 /* marker */
617
+ − 771 if((eventByte1.ub.bit1 && eventByte1.ub.bit2 && !eventByte1.ub.bit0) && (event != NULL)) /* 3 lsb low bit means battery low */
610
+ − 772 {
+ − 773 *event = 1;
+ − 774 }
+ − 775
38
+ − 776 //second event byte
+ − 777 if(eventByte1.ub.bit7)
610
+ − 778 {
+ − 779 ext_flash_read_next_sample_part( &eventByte2.uw, 1);
+ − 780 bytesRead ++;
+ − 781 length--;
+ − 782 }
38
+ − 783 else
+ − 784 {
+ − 785 eventByte2.uw = 0;
+ − 786 }
+ − 787
+ − 788 //manual Gas Set
610
+ − 789 if( eventByte1.ub.bit4)
38
+ − 790 {
+ − 791 //Evaluate manual Gas
610
+ − 792 ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1);
+ − 793 bytesRead +=1;
+ − 794 length -= 1;
+ − 795 manualGas->percentageO2 = tempU8;
+ − 796 ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1);
+ − 797 bytesRead +=1;
+ − 798 length -= 1;
+ − 799 manualGas->percentageHe = tempU8;
+ − 800 if(gasid) *gasid = 0;
38
+ − 801 }
+ − 802 //gas change
+ − 803 if( eventByte1.ub.bit5)
+ − 804 {
+ − 805 ext_flash_read_next_sample_part( &tempU8, 1);
+ − 806 bytesRead +=1;
+ − 807 length -= 1;
+ − 808 if(gasid)
+ − 809 *gasid = (uint16_t)tempU8;
+ − 810 }
+ − 811 //SetpointChange
+ − 812 if( eventByte1.ub.bit6)
+ − 813 {
+ − 814 ext_flash_read_next_sample_part( &tempU8, 1);
+ − 815 *setpoint_cbar = tempU8;
+ − 816 bytesRead +=1;
+ − 817 length -= 1;
+ − 818 }
+ − 819
+ − 820 // second event Byte
+ − 821 //bailout
298
+ − 822 if(eventByte2.ub.bit0)
38
+ − 823 {
+ − 824 //evaluate bailout gas Gas
+ − 825 *bailout = 1;
+ − 826
+ − 827 ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1);
+ − 828 bytesRead +=1;
+ − 829 length -= 1;
+ − 830 manualGas->percentageO2 = tempU8;
+ − 831 ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1);
+ − 832 bytesRead +=1;
+ − 833 length -= 1;
+ − 834 manualGas->percentageHe = tempU8;
+ − 835
+ − 836 if(gasid)
+ − 837 *gasid = 0;
+ − 838 }
941
+ − 839 /* gnss position start dive */
+ − 840 if(eventByte2.ub.bit2)
+ − 841 {
+ − 842 tempU32 = 0;
+ − 843 for(index = 0; index < 4; index++)
+ − 844 {
+ − 845 ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1);
+ − 846 bytesRead +=1;
+ − 847 length -= 1;
+ − 848 tempU32 |= (tempU8 << (index * 8));
+ − 849 }
+ − 850 if(tempU32 != 0xffffffff)
+ − 851 {
+ − 852 memcpy(&pPosition->fLon, &tempU32, 4);
+ − 853 }
+ − 854 tempU32 = 0;
+ − 855 for(index = 0; index < 4; index++)
+ − 856 {
+ − 857 ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1);
+ − 858 bytesRead +=1;
+ − 859 length -= 1;
+ − 860 tempU32 |= (tempU8 << (index * 8));
+ − 861 }
+ − 862 if(tempU32 != 0xffffffff)
+ − 863 {
+ − 864 memcpy(&pPosition->fLat, &tempU32, 4);
+ − 865 }
+ − 866 }
38
+ − 867 }
+ − 868
+ − 869 if(divisor.temperature == 0)
+ − 870 {
+ − 871 divisor.temperature = smallHeader.tempDivisor - 1;
+ − 872 ext_flash_read_next_sample_part( (uint8_t*)&temp, 2);
+ − 873 bytesRead +=2;
+ − 874 length -= 2;
+ − 875 if(temperature)
+ − 876 {
+ − 877 *temperature = (int32_t)temp;
+ − 878 }
+ − 879 }
+ − 880 else
+ − 881 {
+ − 882 divisor.temperature--;
+ − 883 }
+ − 884
+ − 885 if(smallHeader.deco_ndlDivisor > 0)
+ − 886 {
+ − 887 if(divisor.deco_ndl == 0)
+ − 888 {
+ − 889 divisor.deco_ndl = smallHeader.deco_ndlDivisor - 1;
+ − 890 ext_flash_read_next_sample_part( &tempU8, 1);
+ − 891 if(decostopDepth)
+ − 892 {
+ − 893 *decostopDepth = tempU8 * 100;
+ − 894 }
+ − 895 ext_flash_read_next_sample_part( &tempU8, 1);
+ − 896 bytesRead += 2;
+ − 897 length -= 2;
+ − 898 }
+ − 899 else
+ − 900 {
+ − 901 divisor.deco_ndl--;
+ − 902 }
+ − 903 }
+ − 904
+ − 905 if(divisor.ppo2 == 0)
+ − 906 {
+ − 907 int32_t ppO2Tmp = 0;
+ − 908 divisor.ppo2 = smallHeader.ppo2Divisor -1;
+ − 909 for(int i = 0; i <3 ; i++)
+ − 910 {
+ − 911 ext_flash_read_next_sample_part( &tempU8, 1);
+ − 912 ppO2Tmp += tempU8;
+ − 913 bytesRead +=1;
+ − 914 length -= 1;
+ − 915 ext_flash_read_next_sample_part( (uint8_t*)&temp, 2);
+ − 916 bytesRead +=2;
+ − 917 length -= 2;
+ − 918 if(sensor1 && (i==0))
+ − 919 *sensor1 = (((int32_t)tempU8) * 0xFFFF) + temp;
+ − 920 if(sensor2 && (i==1))
+ − 921 *sensor2 = (((int32_t)tempU8) * 0xFFFF) + temp;
+ − 922 if(sensor3 && (i==2))
+ − 923 *sensor3 = (((int32_t)tempU8) * 0xFFFF) + temp;
+ − 924 }
+ − 925 }
+ − 926 else
+ − 927 {
+ − 928 divisor.ppo2--;
+ − 929 }
+ − 930
+ − 931 if(smallHeader.decoplanDivisor > 0)
+ − 932 {
+ − 933 if(divisor.decoplan == 0)
+ − 934 {
+ − 935 divisor.decoplan = smallHeader.decoplanDivisor - 1;
+ − 936 for(int i = 0; i <15; i++)
+ − 937 ext_flash_read_next_sample_part( &tempU8, 1);
+ − 938 bytesRead += 15;
+ − 939 length -= 15;
+ − 940 }
+ − 941 else
+ − 942 {
+ − 943 divisor.decoplan--;
+ − 944 }
+ − 945 }
+ − 946
+ − 947
+ − 948
+ − 949 if(divisor.cns == 0)
+ − 950 {
+ − 951 divisor.cns = smallHeader.cnsDivisor - 1;
+ − 952
+ − 953 ext_flash_read_next_sample_part( (uint8_t*)&temp, 2);
+ − 954 bytesRead +=2;
+ − 955 length -= 2;
+ − 956 if(cns)
+ − 957 {
+ − 958 *cns = (int32_t)temp;
+ − 959 }
+ − 960 }
+ − 961 else
+ − 962 {
+ − 963 divisor.cns--;
+ − 964 }
+ − 965
455
+ − 966 if(smallHeader.tankDivisor)
+ − 967 {
+ − 968 if(divisor.tank == 0)
+ − 969 {
+ − 970 divisor.tank = smallHeader.tankDivisor - 1;
+ − 971 ext_flash_read_next_sample_part( (uint8_t*)&temp, 2);
+ − 972 bytesRead +=2;
+ − 973 length -= 2;
+ − 974 if(tank)
+ − 975 {
+ − 976 *tank = (uint16_t)temp;
+ − 977 }
+ − 978 }
+ − 979 else
+ − 980 {
+ − 981 divisor.tank--;
+ − 982 }
+ − 983 }
+ − 984
38
+ − 985 if (length != 0)
+ − 986 return 0;
+ − 987
+ − 988 return bytesRead;
+ − 989 }
+ − 990 /**
+ − 991 ******************************************************************************
+ − 992 * @brief logbook_readSampleData. / Reads sample data of whole logbook entry
281
+ − 993 * @author heinrichs weikamp
38
+ − 994 * @version V0.0.1
+ − 995 * @date 22-April-2014
+ − 996 ******************************************************************************
+ − 997 *
+ − 998 * @param uint8_t StepBackwards: witch lookbook entry?
+ − 999 * @param uint16_t length : maxlength of output arrays
+ − 1000 * @param int32_t* depth : output array
+ − 1001 * @param int16_t * gasid : output array
+ − 1002 * @param int32_t* temperature : output array
+ − 1003 * @param int32_t* ppo2 : output array
+ − 1004 * @param int32_t* cns : output array
+ − 1005 * @return length of output
+ − 1006 */
455
+ − 1007 uint16_t logbook_readSampleData(uint8_t StepBackwards, uint16_t length,uint16_t* depth, uint8_t* gasid, int16_t* temperature, uint16_t* ppo2,
+ − 1008 uint16_t* setpoint, uint16_t* sensor1, uint16_t* sensor2, uint16_t* sensor3, uint16_t* cns, uint8_t* bailout,
941
+ − 1009 uint16_t* decostopDepth, uint16_t* tank, SGnssCoord* pPosition, uint8_t* event)
38
+ − 1010 {
+ − 1011 //Test read
+ − 1012 //SLogbookHeader header;
+ − 1013
+ − 1014 //logbook_getHeader(&header);
+ − 1015 SLogbookHeader header;
458
+ − 1016 int16_t iNum;
+ − 1017 int16_t firstgasid = 0;
+ − 1018 uint16_t retVal = 0;
+ − 1019 int16_t compression = 0;
+ − 1020 int16_t i;
38
+ − 1021 // uint32_t diveTime_seconds;
+ − 1022 int32_t depthVal = 0;
+ − 1023 int16_t gasidVal = 0;
+ − 1024 int16_t setPointVal = 0;
+ − 1025 int16_t bailoutVal = 0;
+ − 1026 int16_t bailoutLast = 0;
+ − 1027 uint16_t setPointLast = 0;
+ − 1028 int32_t temperatureVal = 0;
+ − 1029 int32_t sensor1Val = 0;
+ − 1030 int32_t sensor2Val = 0;
+ − 1031 int32_t sensor3Val = 0;
+ − 1032 int32_t sensor1Last = 0;
+ − 1033 int32_t sensor2Last = 0;
+ − 1034 int32_t sensor3Last = 0;
+ − 1035 int32_t cnsVal = 0;
+ − 1036 int32_t depthLast = 0;
+ − 1037 int16_t gasidLast = 0;
+ − 1038 int32_t temperatureLast = 0;
+ − 1039 int32_t temperatureFirst = 0;
+ − 1040 int32_t cnsLast = 0;
455
+ − 1041 int16_t decostepDepthVal = 0;
+ − 1042 int16_t decostepDepthLast = 0;
457
+ − 1043 uint16_t tankVal = 0;
465
+ − 1044 uint32_t small_profileLength = 0;
610
+ − 1045 uint8_t eventdata;
941
+ − 1046 SGnssCoord posCoord;
+ − 1047 posCoord.fLat = 0.0;
+ − 1048 posCoord.fLon = 0.0;
38
+ − 1049
+ − 1050 SManualGas manualGasVal;
+ − 1051 SManualGas manualGasLast;
+ − 1052 manualGasLast.percentageO2 = 0;
+ − 1053 manualGasLast.percentageHe = 0;
455
+ − 1054 uint16_t numSamples = 0;
38
+ − 1055
+ − 1056 float ambiant_pressure_bar = 0;
+ − 1057 float ppO2 = 0;
+ − 1058 ext_flash_read_dive_header((uint8_t*)&header, StepBackwards);
+ − 1059 for(i = 0;i< 5;i++)
+ − 1060 {
+ − 1061 if(header.gasordil[i].note.ub.first)
+ − 1062 break;
+ − 1063 }
+ − 1064 firstgasid = i + 1;
662
+ − 1065 if(isLoopMode(header.diveMode))
38
+ − 1066 setPointLast = header.setpoint[0].setpoint_cbar;
+ − 1067 else
+ − 1068 setPointLast = 0;
+ − 1069 //diveTime_seconds = header.diveTime_seconds ;
+ − 1070 for(compression = 1; compression < 100; compression ++)
+ − 1071 {
455
+ − 1072 numSamples = (header.total_diveTime_seconds / header.samplingRate)/compression;
+ − 1073 if(numSamples <= length)
+ − 1074 {
+ − 1075 break;
+ − 1076 }
38
+ − 1077 }
+ − 1078
+ − 1079
+ − 1080 for(i = 0;i< length;i++)
+ − 1081 {
+ − 1082 if(depth)
+ − 1083 depth[i] = 0;
+ − 1084 if(temperature)
+ − 1085 temperature[i] = 0;
+ − 1086 if(gasid)
+ − 1087 gasid[i] = 0;
+ − 1088 if(ppo2)
+ − 1089 ppo2[i] = 0;
+ − 1090 if(setpoint)
+ − 1091 setpoint[i] = 0;
+ − 1092 if(sensor1)
+ − 1093 sensor1[i] = 0;
+ − 1094 if(sensor2)
+ − 1095 sensor2[i] = 0;
+ − 1096 if(sensor3)
+ − 1097 sensor3[i] = 0;
+ − 1098 if(cns)
+ − 1099 cns[i] = 0;
455
+ − 1100 if(tank)
+ − 1101 tank[i] = 0;
38
+ − 1102 }
+ − 1103 //We start with fist gasid
+ − 1104 gasidLast = firstgasid;
+ − 1105
+ − 1106
+ − 1107 //uint16_t* ppo2, uint16_t* cns#
465
+ − 1108 uint32_t totalNumberOfBytes = 0;
+ − 1109 uint32_t bytesRead = 0;
38
+ − 1110 ext_flash_open_read_sample( StepBackwards,&totalNumberOfBytes);
+ − 1111 ext_flash_read_next_sample_part((uint8_t*)&smallHeader, sizeof(SSmallHeader));
+ − 1112 bytesRead += sizeof(SSmallHeader);
+ − 1113
+ − 1114 clear_divisor();
+ − 1115
+ − 1116 iNum = 0;
+ − 1117 int counter = 0;
+ − 1118 temperatureLast = -1000;
465
+ − 1119
+ − 1120 small_profileLength = (smallHeader.profileLength[2] << 16) + (smallHeader.profileLength[1] << 8) + smallHeader.profileLength[0];
+ − 1121
+ − 1122 if(totalNumberOfBytes == small_profileLength) /* sizes provided by header and small header are the same => real data */
455
+ − 1123 {
+ − 1124 while ((bytesRead < totalNumberOfBytes) && (iNum < length))
+ − 1125 {
+ − 1126 ext_flash_set_entry_point();
+ − 1127 divisorBackup = divisor;
+ − 1128 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal,
941
+ − 1129 &bailoutVal, &decostepDepthVal, &tankVal, &posCoord, &eventdata);
38
+ − 1130
455
+ − 1131 if(retVal == 0)
+ − 1132 {
+ − 1133 //Error try to read again!!!
+ − 1134 ext_flash_reopen_read_sample_at_entry_point();
+ − 1135 divisor = divisorBackup;
+ − 1136 retVal = readSample(&depthVal,&gasidVal,&setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal,
941
+ − 1137 &manualGasVal, &bailoutVal, &decostepDepthVal, &tankVal, &posCoord, &eventdata);
38
+ − 1138
455
+ − 1139 if(retVal == 0)
+ − 1140 break;
+ − 1141 }
+ − 1142 bytesRead +=retVal;
38
+ − 1143
455
+ − 1144 //if for some variable no new value is in the sample for (z.B. gasidVal = -1), we take the last value
+ − 1145 if(depthVal == -1)
+ − 1146 depthVal = depthLast;
+ − 1147 else
+ − 1148 depthLast = depthVal;
38
+ − 1149
455
+ − 1150 if(gasidVal == -1)
+ − 1151 gasidVal = gasidLast;
+ − 1152 else
+ − 1153 gasidLast = gasidVal;
+ − 1154
+ − 1155 if(temperatureVal == -1000)
+ − 1156 temperatureVal = temperatureLast;
+ − 1157 else
38
+ − 1158 {
455
+ − 1159 if(temperatureLast == -1000)
+ − 1160 temperatureFirst = temperatureVal;
+ − 1161 temperatureLast = temperatureVal;
38
+ − 1162 }
+ − 1163
455
+ − 1164 if(setPointVal == -1)
+ − 1165 setPointVal = setPointLast;
+ − 1166 else
+ − 1167 setPointLast = setPointVal;
+ − 1168
+ − 1169 if(sensor1Val == -1)
+ − 1170 sensor1Val = sensor1Last;
+ − 1171 else
+ − 1172 sensor1Last = sensor1Val;
+ − 1173
+ − 1174 if(sensor2Val == -1)
+ − 1175 sensor2Val = sensor2Last;
+ − 1176 else
+ − 1177 sensor2Last = sensor2Val;
+ − 1178
+ − 1179 if(sensor3Val == -1)
+ − 1180 sensor3Val = sensor3Last;
+ − 1181 else
+ − 1182 sensor3Last = sensor3Val;
+ − 1183
+ − 1184 if(cnsVal == -1)
+ − 1185 cnsVal = cnsLast;
+ − 1186 else
+ − 1187 cnsLast = cnsVal;
+ − 1188
+ − 1189 if(manualGasVal.percentageO2 == -1)
+ − 1190 manualGasVal = manualGasLast;
+ − 1191 else
+ − 1192 manualGasLast = manualGasVal;
+ − 1193
+ − 1194 if(bailoutVal == -1)
+ − 1195 bailoutVal = bailoutLast;
+ − 1196 else
+ − 1197 bailoutLast = bailoutVal;
+ − 1198
+ − 1199 if(decostepDepthVal == -1)
+ − 1200 decostepDepthVal = decostepDepthLast;
+ − 1201 else
+ − 1202 decostepDepthLast = decostepDepthVal;
38
+ − 1203
455
+ − 1204 counter++;
+ − 1205 // Heed compression
+ − 1206 // Write here to arrays
+ − 1207 if(counter == compression)
+ − 1208 {
+ − 1209 if(depth)
+ − 1210 depth[iNum] = depthVal;
+ − 1211 if(gasid)
+ − 1212 gasid[iNum] = gasidVal;
+ − 1213 if(temperature)
+ − 1214 temperature[iNum] = temperatureVal;
+ − 1215 if(cns)
+ − 1216 cns[iNum] = cnsVal;
+ − 1217 if(bailout)
+ − 1218 bailout[iNum] = bailoutVal;
+ − 1219 if(decostopDepth)
+ − 1220 decostopDepth[iNum] = decostepDepthVal;
+ − 1221
+ − 1222 if(ppo2)
+ − 1223 {
+ − 1224 //Calc ppo2 - Values
+ − 1225 SGas gas;
+ − 1226 gas.setPoint_cbar = setPointVal;
+ − 1227 if(gasidVal > 0)
+ − 1228 {
662
+ − 1229 if((gasidVal >= NUM_GASES) && (header.diveMode == DIVEMODE_PSCR)) /* in case gas switches the absolute gas ID is used => map to the 0..NUM_GASES index used in header */
+ − 1230 {
+ − 1231 gasidVal -= NUM_GASES;
+ − 1232 }
455
+ − 1233 gas.helium_percentage = header.gasordil[gasidVal - 1].helium_percentage;
+ − 1234 gas.nitrogen_percentage = 100 - gas.helium_percentage - header.gasordil[gasidVal - 1].oxygen_percentage;
+ − 1235 }
+ − 1236 else
+ − 1237 {
+ − 1238 gas.helium_percentage = manualGasVal.percentageHe;
+ − 1239 gas.nitrogen_percentage = 100 - gas.helium_percentage - manualGasVal.percentageO2;
+ − 1240 }
+ − 1241 ambiant_pressure_bar =((float)(depthVal + header.surfacePressure_mbar))/1000;
662
+ − 1242
+ − 1243 if(header.diveMode == DIVEMODE_PSCR)
+ − 1244 {
+ − 1245 ppO2 = decom_calc_SimppO2(ambiant_pressure_bar, &gas);
+ − 1246 }
+ − 1247 else /* open circuit calculation */
+ − 1248 {
+ − 1249 ppO2 = decom_calc_ppO2(ambiant_pressure_bar, &gas);
+ − 1250 }
455
+ − 1251 ppo2[iNum] = (uint16_t) ( ppO2 * 100);
+ − 1252 }
+ − 1253
+ − 1254 if(tank)
+ − 1255 {
+ − 1256 tank[iNum] = tankVal;
+ − 1257 }
+ − 1258 if(setpoint)
+ − 1259 setpoint[iNum] = setPointVal;
+ − 1260
+ − 1261 if(sensor1)
+ − 1262 sensor1[iNum] = (sensor1Val / 0xFFFF) & 0xFF;
+ − 1263 if(sensor2)
+ − 1264 sensor2[iNum] = (sensor2Val / 0xFFFF) & 0xFF;
+ − 1265 if(sensor3)
+ − 1266 sensor3[iNum] = (sensor3Val / 0xFFFF) & 0xFF;
+ − 1267 iNum++;
+ − 1268 counter = 0;
610
+ − 1269
+ − 1270 if(event)
+ − 1271 {
+ − 1272 event[iNum] = eventdata;
+ − 1273 eventdata = 0;
+ − 1274 }
455
+ − 1275 }
+ − 1276 }
941
+ − 1277 if(pPosition)
+ − 1278 {
+ − 1279 memcpy(pPosition, &posCoord, sizeof(posCoord));
+ − 1280 }
455
+ − 1281 }
+ − 1282 else
+ − 1283 {
458
+ − 1284 logbook_createDummyProfile(&header, numSamples, depth, temperature, ppo2);
455
+ − 1285 iNum = numSamples;
+ − 1286 }
38
+ − 1287
+ − 1288 // Fix first Temperature Entries 150930 hw
+ − 1289 if(temperature)
+ − 1290 {
+ − 1291 int i = 0;
+ − 1292 while((temperature[i] == -1000) && (i < iNum))
+ − 1293 temperature[i++] = temperatureFirst;
+ − 1294 }
+ − 1295
+ − 1296 ext_flash_close_read_sample();
+ − 1297 return iNum;
+ − 1298 }
+ − 1299
+ − 1300
+ − 1301 /********************************************************************************
+ − 1302 * @brief logbook_InitAndWrite. / Controls writing of logbook
+ − 1303 * Should be called ten times per second
+ − 1304 * Automatically Initializes logbook at beginning of dive,
+ − 1305 * write samples every 2 seconds
+ − 1306 * and finishes logbook after end of dive
+ − 1307 *********************************************************************************/
+ − 1308
941
+ − 1309 void logbook_InitAndWrite(SDiveState *pStateReal)
38
+ − 1310 {
+ − 1311 SSettings *pSettings = settingsGetPointer();
+ − 1312 static uint8_t bDiveMode = 0;
+ − 1313 static uint32_t tickstart = 0;
+ − 1314 uint32_t ticksdiff = 0;
+ − 1315 uint32_t lasttick = 0;
+ − 1316 static float min_temperature_float_celsius = 0;
+ − 1317
+ − 1318 if(!bDiveMode)
+ − 1319 {
+ − 1320 if((pStateReal->mode == MODE_DIVE) && (pStateReal->diveSettings.diveMode != DIVEMODE_Apnea) && (pStateReal->lifeData.dive_time_seconds >= 5))
+ − 1321 {
+ − 1322 //InitdiveProfile
+ − 1323 pSettings->totalDiveCounter++;
+ − 1324 logbook_initNewdiveProfile(pStateReal,settingsGetPointer());
+ − 1325 min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius;
941
+ − 1326
38
+ − 1327 //Write logbook sample
269
+ − 1328 logbook_writeSample(pStateReal);
270
+ − 1329 resetEvents(pStateReal);
38
+ − 1330 tickstart = HAL_GetTick();
+ − 1331 bDiveMode = 1;
+ − 1332 }
+ − 1333 }
+ − 1334 else if((pStateReal->mode == MODE_DIVE) && (pStateReal->diveSettings.diveMode != DIVEMODE_Apnea))
+ − 1335 {
+ − 1336 lasttick = HAL_GetTick();
+ − 1337 ticksdiff = time_elapsed_ms(tickstart,lasttick);
+ − 1338 //
+ − 1339 if(ticksdiff >= 2000)
+ − 1340 {
+ − 1341 //Write logbook sample
269
+ − 1342 logbook_writeSample(pStateReal);
270
+ − 1343 resetEvents(pStateReal);
38
+ − 1344 if(min_temperature_float_celsius > pStateReal->lifeData.temperature_celsius)
+ − 1345 min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius;
+ − 1346 tickstart = lasttick;
+ − 1347 if((bDiveMode == 1) && (pStateReal->lifeData.dive_time_seconds >= pSettings->divetimeToCreateLogbook))
+ − 1348 {
411
+ − 1349 ext_flash_create_new_dive_log((uint8_t*)&gheader);
38
+ − 1350 /** save settings
+ − 1351 * with new lastDiveLogId and time and day
+ − 1352 */
+ − 1353 pSettings->personalDiveCount++;
+ − 1354 if(pSettings->logbookOffset)
+ − 1355 {
+ − 1356 pSettings->logbookOffset++;
+ − 1357 }
427
+ − 1358 ext_flash_write_settings(0);
38
+ − 1359 ext_flash_disable_protection_for_logbook();
426
+ − 1360
+ − 1361 ext_flash_CloseSector(); /* this is just a repair function which invalidates a not used sector in case a log maintenance was called before dive */
38
+ − 1362 bDiveMode = 3;
941
+ − 1363
+ − 1364 #if defined ENABLE_GNSS_SUPPORT || defined ENABLE_GPIO_V2
+ − 1365 pStateReal->events.gnssPositionUpdate = 1;
955
+ − 1366
+ − 1367 if(pStateReal->lifeData.gnssData.alive & GNSS_ALIVE_BACKUP_POS)
+ − 1368 {
+ − 1369 pStateReal->events.info_gnssPosition = pStateReal->lifeData.gnssData.coord;
+ − 1370 }
+ − 1371 else /* no pos => define dummy */
941
+ − 1372 {
+ − 1373 pStateReal->events.info_gnssPosition.fLon = 47.77;
+ − 1374 pStateReal->events.info_gnssPosition.fLat = 8.99;
+ − 1375 }
+ − 1376 #endif
+ − 1377
38
+ − 1378 }
+ − 1379 if(bDiveMode == 3)
270
+ − 1380 logbook_UpdateHeader(pStateReal);
38
+ − 1381 }
+ − 1382 }
+ − 1383 else if(bDiveMode == 3)
+ − 1384 {
+ − 1385 //End of Dive
+ − 1386 logbook_SetAverageDepth(pStateReal->lifeData.average_depth_meter);
+ − 1387 logbook_SetMinTemperature(min_temperature_float_celsius);
+ − 1388 logbook_SetMaxCNS(pStateReal->lifeData.cns);
270
+ − 1389 logbook_SetCompartmentDesaturation(pStateReal);
38
+ − 1390 logbook_SetLastStop(pStateReal->diveSettings.last_stop_depth_bar);
411
+ − 1391 gheader.batteryVoltage = pStateReal->lifeData.battery_voltage * 1000;
671
+ − 1392 if(pStateReal->lifeData.battery_charge > 0.0)
+ − 1393 {
+ − 1394 gheader.batteryCharge = pStateReal->lifeData.battery_charge;
+ − 1395 }
+ − 1396 else
+ − 1397 {
+ − 1398 gheader.batteryCharge = 0.0;
+ − 1399 }
38
+ − 1400 logbook_EndDive();
+ − 1401 bDiveMode = 0;
+ − 1402 } else
+ − 1403 {
+ − 1404 ext_flash_enable_protection();
+ − 1405 }
+ − 1406 }
+ − 1407
+ − 1408
+ − 1409 /* Private functions ---------------------------------------------------------*/
+ − 1410
+ − 1411 /********************************************************************************
+ − 1412 * @brief logbook_UpdateHeader. /
+ − 1413 * set date, time, max depth. etc. pp.
+ − 1414 * the internal pointer to the end of profile and length will be set by
+ − 1415 ext_flash_close_new_dive_log() in externLogbookFlash.c
+ − 1416 * @author heinrichs weikamp gmbh
+ − 1417 * @version V0.0.1
+ − 1418 * @date 27-Nov-2014
+ − 1419 *********************************************************************************/
270
+ − 1420 static void logbook_UpdateHeader(const SDiveState *pStateReal)
38
+ − 1421 {
+ − 1422 // uint16_t secondsAtShallow = 0;
+ − 1423 RTC_DateTypeDef Sdate;
+ − 1424 RTC_TimeTypeDef Stime;
+ − 1425 uint32_t time1_u32, time2_u32;
+ − 1426 uint32_t divetimeHelper;
+ − 1427
+ − 1428 /* time and day */
+ − 1429 /* don't update CHANGE 160224 hw, maybe save actual time and date at other place
+ − 1430 translateDate(pStateReal->lifeData.dateBinaryFormat, &Sdate);
+ − 1431 translateTime(pStateReal->lifeData.timeBinaryFormat, &Stime);
+ − 1432
+ − 1433 header.dateYear = Sdate.Year;
+ − 1434 header.dateMonth = Sdate.Month;
+ − 1435 header.dateDay = Sdate.Date;
+ − 1436 header.timeHour = Stime.Hours;
+ − 1437 header.timeMinute = Stime.Minutes;
+ − 1438 */
+ − 1439 /// 160315 Quick fix for empty date problem
411
+ − 1440 if((!(gheader.dateYear)) || (!(gheader.dateMonth)) || (!(gheader.dateDay)))
38
+ − 1441 {
+ − 1442 translateDate(pStateReal->lifeData.dateBinaryFormat, &Sdate);
+ − 1443 translateTime(pStateReal->lifeData.timeBinaryFormat, &Stime);
+ − 1444
411
+ − 1445 gheader.dateYear = Sdate.Year;
+ − 1446 gheader.dateMonth = Sdate.Month;
+ − 1447 gheader.dateDay = Sdate.Date;
38
+ − 1448
411
+ − 1449 time1_u32 = (uint32_t)gheader.timeMinute + (uint32_t)(gheader.timeHour * 60);
38
+ − 1450 time2_u32 = (uint32_t)Stime.Minutes + (uint32_t)(Stime.Hours * 60);
+ − 1451 if(time2_u32 < time1_u32)
+ − 1452 {
411
+ − 1453 if(gheader.dateDay > 1)
38
+ − 1454 {
411
+ − 1455 gheader.dateDay -= 1;
38
+ − 1456 }
+ − 1457 else
+ − 1458 {
411
+ − 1459 gheader.dateMonth --;
+ − 1460 if(!gheader.dateMonth)
38
+ − 1461 {
411
+ − 1462 gheader.dateYear--;
+ − 1463 gheader.dateMonth = 12;
+ − 1464 gheader.dateDay = 31;
38
+ − 1465 }
+ − 1466 else
+ − 1467 {
411
+ − 1468 if(gheader.dateMonth == 2)
+ − 1469 gheader.dateDay = 28;
38
+ − 1470 else
411
+ − 1471 if((gheader.dateMonth == 4) || (gheader.dateMonth == 6) || (gheader.dateMonth == 9) || (gheader.dateMonth == 11))
+ − 1472 gheader.dateDay = 30;
38
+ − 1473 else
411
+ − 1474 gheader.dateDay = 31;
38
+ − 1475 }
+ − 1476 }
+ − 1477 }
+ − 1478 }
+ − 1479
+ − 1480 /* duration */
411
+ − 1481 gheader.total_diveTime_seconds = pStateReal->lifeData.dive_time_seconds;
+ − 1482 gheader.maxDepth = pStateReal->lifeData.max_depth_meter * 100;
38
+ − 1483
+ − 1484 /* old:
+ − 1485
+ − 1486 secondsAtShallow = pSettings->timeoutDiveReachedZeroDepth;
+ − 1487 if(pStateReal->lifeData.dive_time_seconds <= secondsAtShallow)
+ − 1488 secondsAtShallow = 0;
+ − 1489 header.diveTimeMinutes = (header.total_diveTime_seconds - secondsAtShallow )/ 60;
+ − 1490 header.diveTimeSeconds = header.total_diveTime_seconds - secondsAtShallow - (header.diveTimeMinutes * 60);
+ − 1491 */
+ − 1492 divetimeHelper = pStateReal->lifeData.dive_time_seconds_without_surface_time;
411
+ − 1493 gheader.diveTimeMinutes = (uint16_t)(divetimeHelper/60);
+ − 1494 divetimeHelper -= 60 * (uint32_t)gheader.diveTimeMinutes;
+ − 1495 gheader.diveTimeSeconds = (uint16_t)divetimeHelper;
38
+ − 1496
+ − 1497 /* deco algorithm (final) */
+ − 1498 if(pStateReal->diveSettings.deco_type.ub.standard == GF_MODE)
+ − 1499 {
411
+ − 1500 gheader.decoModel = 1;
+ − 1501 gheader.gfLow_or_Vpm_conservatism = pStateReal->diveSettings.gf_low;
+ − 1502 gheader.gfHigh = pStateReal->diveSettings.gf_high;
38
+ − 1503 }
+ − 1504 else
+ − 1505 {
411
+ − 1506 gheader.decoModel = 2;
+ − 1507 gheader.gfLow_or_Vpm_conservatism = pStateReal->diveSettings.vpm_conservatism;
+ − 1508 gheader.gfHigh = 0;
38
+ − 1509 }
+ − 1510
+ − 1511 /* tissue load */
411
+ − 1512 memcpy(gheader.n2Compartments, pStateReal->lifeData.tissue_nitrogen_bar, 64);
+ − 1513 memcpy(gheader.heCompartments, pStateReal->lifeData.tissue_helium_bar, 64);
38
+ − 1514
+ − 1515 }
+ − 1516
+ − 1517
194
+ − 1518 static void logbook_SetAverageDepth(float average_depth_meter)
38
+ − 1519 {
411
+ − 1520 gheader.averageDepth_mbar = (uint16_t)(average_depth_meter * 100);
38
+ − 1521 }
+ − 1522
+ − 1523
194
+ − 1524 static void logbook_SetMinTemperature(float min_temperature_celsius)
38
+ − 1525 {
411
+ − 1526 gheader.minTemp = (int16_t)((min_temperature_celsius * 10.0f) + 0.5f);
38
+ − 1527 }
+ − 1528
+ − 1529
194
+ − 1530 static void logbook_SetMaxCNS(float max_cns_percentage)
38
+ − 1531 {
+ − 1532 if(max_cns_percentage < 9999)
411
+ − 1533 gheader.maxCNS = (uint16_t)(max_cns_percentage);
38
+ − 1534 else
411
+ − 1535 gheader.maxCNS = 9999;
38
+ − 1536 }
+ − 1537
+ − 1538
270
+ − 1539 static void logbook_SetCompartmentDesaturation(const SDiveState * pStateReal)
38
+ − 1540 {
225
+ − 1541 SLifeData2 secondaryInformation = { 0 };
38
+ − 1542
+ − 1543 decom_tissues_desaturation_time(&pStateReal->lifeData, &secondaryInformation);
+ − 1544 for(int i=0;i<16;i++)
+ − 1545 {
+ − 1546 if(secondaryInformation.tissue_nitrogen_desaturation_time_minutes[i] <= (15 * 255))
411
+ − 1547 gheader.n2CompartDesatTime_min[i] = (uint8_t)((secondaryInformation.tissue_nitrogen_desaturation_time_minutes[i] + 14) / 15);
38
+ − 1548 else
411
+ − 1549 gheader.n2CompartDesatTime_min[i] = 255;
38
+ − 1550 if(secondaryInformation.tissue_helium_desaturation_time_minutes[i] <= (15 * 255))
411
+ − 1551 gheader.heCompartDesatTime_min[i] = (uint8_t)((secondaryInformation.tissue_helium_desaturation_time_minutes[i] + 14 )/ 15);
38
+ − 1552 else
411
+ − 1553 gheader.heCompartDesatTime_min[i] = 255;
38
+ − 1554 }
+ − 1555 }
+ − 1556
194
+ − 1557 static void logbook_SetLastStop(float last_stop_depth_bar)
38
+ − 1558 {
411
+ − 1559 gheader.lastDecostop_m = (uint8_t)(last_stop_depth_bar / 10.0f);
38
+ − 1560 }
+ − 1561
194
+ − 1562 static void logbook_writedata(void * data, int length_byte)
38
+ − 1563 {
+ − 1564 ext_flash_write_sample(data, length_byte);
+ − 1565 }
+ − 1566
+ − 1567 /********************************************************************************
+ − 1568 * @brief logbook_build_ostc3header. /
+ − 1569 * @author heinrichs weikamp gmbh
+ − 1570 * @version V0.0.2
+ − 1571 * @date 27-Nov-2014
+ − 1572 *********************************************************************************/
+ − 1573 SLogbookHeaderOSTC3 * logbook_build_ostc3header(SLogbookHeader* pHead)
+ − 1574 {
411
+ − 1575 convert_Type data,data2;
455
+ − 1576 uint16_t dummyLength = 0;
465
+ − 1577 uint8_t returnEmptyHeader = 0;
38
+ − 1578
465
+ − 1579 uint32_t headerProfileLength, sampleProfileLength, sampleProfileStart;
38
+ − 1580
411
+ − 1581
465
+ − 1582 if(pHead->diveHeaderStart != 0xFAFA)
411
+ − 1583 {
465
+ − 1584 returnEmptyHeader = 1;
411
+ − 1585 }
+ − 1586 else
+ − 1587 {
465
+ − 1588 memcpy(headerOSTC3.diveHeaderStart, &pHead->diveHeaderStart, 2);
+ − 1589 memcpy(headerOSTC3.pBeginProfileData, &pHead->pBeginProfileData, 3);
+ − 1590 memcpy(headerOSTC3.pEndProfileData, &pHead->pEndProfileData, 3);
+ − 1591
+ − 1592 data.u8bit.byteHigh = 0;
+ − 1593 data.u8bit.byteLow = pHead->pBeginProfileData[0];
+ − 1594 data.u8bit.byteMidLow = pHead->pBeginProfileData[1];
+ − 1595 data.u8bit.byteMidHigh = pHead->pBeginProfileData[2];
+ − 1596
+ − 1597 sampleProfileStart = data.u32bit;
+ − 1598
+ − 1599 data2.u8bit.byteHigh = 0;
+ − 1600 data2.u8bit.byteLow = pHead->pEndProfileData[0];
+ − 1601 data2.u8bit.byteMidLow = pHead->pEndProfileData[1];
+ − 1602 data2.u8bit.byteMidHigh = pHead->pEndProfileData[2];
+ − 1603
+ − 1604 data.u8bit.byteHigh = 0;
+ − 1605 data.u8bit.byteLow = pHead->profileLength[0];
+ − 1606 data.u8bit.byteMidLow = pHead->profileLength[1];
+ − 1607 data.u8bit.byteMidHigh = pHead->profileLength[2];
+ − 1608
+ − 1609 if(data.u32bit != 0xFFFFFF) /* if the profile in use ? */
455
+ − 1610 {
465
+ − 1611 if(data2.u32bit < sampleProfileStart) /* Wrap around of sample ring detected */
+ − 1612 {
+ − 1613 if(ext_flash_SampleOverrunValid() == 0) /* Wrap around does not seem to be valid => fallback */
+ − 1614 {
+ − 1615 sampleProfileStart = 0;
+ − 1616 }
+ − 1617 }
+ − 1618 if( sampleProfileStart == 0) /* should never happen unless OSTC with older debug version is in use (or invalid overrun) */
+ − 1619 {
+ − 1620 sampleProfileLength = 1;
+ − 1621 headerProfileLength = 2;
+ − 1622 }
+ − 1623 else
+ − 1624 {
+ − 1625 headerProfileLength = (pHead->profileLength[2] << 16) + (pHead->profileLength[1] << 8) + pHead->profileLength[0];
+ − 1626 sampleProfileLength = ext_flash_read_profilelength_small_header(sampleProfileStart);
+ − 1627 }
+ − 1628
+ − 1629 if(sampleProfileLength != headerProfileLength)
+ − 1630 {
+ − 1631 dummyLength = logbook_fillDummySampleBuffer(pHead);
+ − 1632
+ − 1633 data2.u32bit = sampleProfileStart + dummyLength; /* calc new end address (which is equal to dummyLength) */
+ − 1634 data.u32bit = dummyLength; /* data is used below to represent the length */
+ − 1635 }
+ − 1636
+ − 1637 data.u32bit += 3;
+ − 1638 headerOSTC3.profileLength[0] = data.u8bit.byteLow;
+ − 1639 headerOSTC3.profileLength[1] = data.u8bit.byteMidLow;
+ − 1640 headerOSTC3.profileLength[2] = data.u8bit.byteMidHigh;
+ − 1641
+ − 1642 memcpy(headerOSTC3.gasordil, pHead->gasordil, 20);
+ − 1643
+ − 1644 if(pHead->logbookProfileVersion == LOGBOOK_VERSION)
+ − 1645 {
+ − 1646 headerOSTC3.logbookProfileVersion = LOGBOOK_VERSION_OSTC3;
+ − 1647 memcpy(headerOSTC3.personalDiveCount, &pHead->personalDiveCount, 2);
+ − 1648 headerOSTC3.safetyDistance_10cm = 0;
+ − 1649
+ − 1650 for(int i=0;i<5;i++)
+ − 1651 {
+ − 1652 if(!pHead->gasordil[i].note.ub.active)
+ − 1653 headerOSTC3.gasordil[3 + (i*4)] = 0;
+ − 1654 else if(pHead->gasordil[i].note.ub.first)
+ − 1655 {
+ − 1656 /* depth = 0, note = 1 */
+ − 1657 headerOSTC3.gasordil[2 + (i*4)] = 0;
+ − 1658 headerOSTC3.gasordil[3 + (i*4)] = 1;
+ − 1659 }
+ − 1660 else if( pHead->gasordil[i].depth_meter)
+ − 1661 {
+ − 1662 /* note = 3 */
+ − 1663 headerOSTC3.gasordil[3 + (i*4)] = 3;
+ − 1664 }
+ − 1665 }
+ − 1666 }
+ − 1667 else
+ − 1668 {
+ − 1669 headerOSTC3.logbookProfileVersion = 0xFF;
+ − 1670 headerOSTC3.personalDiveCount[0] = 0xFF;
+ − 1671 headerOSTC3.personalDiveCount[1] = 0xFF;
+ − 1672 headerOSTC3.safetyDistance_10cm = 0xFF;
+ − 1673 }
+ − 1674
+ − 1675 headerOSTC3.dateYear = pHead->dateYear;
+ − 1676 headerOSTC3.dateMonth = pHead->dateMonth;
+ − 1677 headerOSTC3.dateDay = pHead->dateDay;
+ − 1678 headerOSTC3.timeHour = pHead->timeHour;
+ − 1679 headerOSTC3.timeMinute = pHead->timeMinute;
+ − 1680
+ − 1681 memcpy(headerOSTC3.maxDepth, &pHead->maxDepth, 2);
+ − 1682 memcpy(headerOSTC3.diveTimeMinutes, &pHead->diveTimeMinutes, 2);
+ − 1683
+ − 1684 headerOSTC3.diveTimeSeconds = pHead->diveTimeSeconds;
+ − 1685
+ − 1686 memcpy(headerOSTC3.minTemp, &pHead->minTemp, 2);
+ − 1687 memcpy(headerOSTC3.surfacePressure_mbar,&pHead->surfacePressure_mbar, 2);
+ − 1688 memcpy(headerOSTC3.desaturationTime, &pHead->desaturationTime, 2);
+ − 1689
+ − 1690 headerOSTC3.firmwareVersionHigh = pHead->firmwareVersionHigh;
+ − 1691 headerOSTC3.firmwareVersionLow = pHead->firmwareVersionLow;
+ − 1692
+ − 1693 memcpy(headerOSTC3.batteryVoltage, &pHead->batteryVoltage, 2);
+ − 1694
+ − 1695 headerOSTC3.samplingRate = pHead->samplingRate;
+ − 1696
+ − 1697 memcpy(headerOSTC3.cnsAtBeginning, &pHead->cnsAtBeginning, 2);
+ − 1698
+ − 1699 headerOSTC3.gfAtBeginning = pHead->gfAtBeginning;
+ − 1700 headerOSTC3.gfAtEnd = pHead->gfAtEnd;
+ − 1701
+ − 1702 memcpy(headerOSTC3.setpoint, pHead->setpoint, 10);
+ − 1703
+ − 1704 headerOSTC3.salinity = pHead->salinity;
+ − 1705
+ − 1706 memcpy(headerOSTC3.maxCNS, &pHead->maxCNS, 2);
+ − 1707 memcpy(headerOSTC3.averageDepth_mbar, &pHead->averageDepth_mbar, 2);
+ − 1708 memcpy(headerOSTC3.total_diveTime_seconds, &pHead->total_diveTime_seconds, 2);
+ − 1709
+ − 1710 headerOSTC3.gfLow_or_Vpm_conservatism = pHead->gfLow_or_Vpm_conservatism;
+ − 1711 headerOSTC3.gfHigh = pHead->gfHigh;
+ − 1712 headerOSTC3.decoModel = pHead->decoModel;
+ − 1713
+ − 1714 memcpy(headerOSTC3.diveNumber, &pHead->diveNumber, 2);
+ − 1715
+ − 1716 headerOSTC3.diveMode = pHead->diveMode;
471
+ − 1717 headerOSTC3.batteryCharge = pHead->batteryCharge;
465
+ − 1718
+ − 1719 memcpy(headerOSTC3.n2CompartDesatTime_min,pHead->n2CompartDesatTime_min, 16);
+ − 1720 memcpy(headerOSTC3.n2Compartments, pHead->n2Compartments, 64);
+ − 1721 memcpy(headerOSTC3.heCompartDesatTime_min,pHead->heCompartDesatTime_min, 16);
+ − 1722 memcpy(headerOSTC3.heCompartments, pHead->heCompartments, 64);
+ − 1723
+ − 1724 headerOSTC3.lastDecostop_m = pHead->lastDecostop_m;
+ − 1725
+ − 1726 memcpy(headerOSTC3.hwHudBattery_mV, &pHead->hwHudBattery_mV, 2);
+ − 1727
+ − 1728 headerOSTC3.hwHudLastStatus = pHead->hwHudLastStatus;
+ − 1729
483
+ − 1730 memset(headerOSTC3.batteryGaugeRegisters, 0x00, 6); /* The battery registers are not evaluated => Set to zero */
465
+ − 1731
+ − 1732 memcpy(headerOSTC3.diveHeaderEnd, &pHead->diveHeaderEnd, 2);
455
+ − 1733 }
+ − 1734 else
+ − 1735 {
465
+ − 1736 returnEmptyHeader = 1;
38
+ − 1737 }
+ − 1738 }
465
+ − 1739 if(returnEmptyHeader) /* profile not in use => return array full of 0xFF */
38
+ − 1740 {
465
+ − 1741 memset(&headerOSTC3, 0xFF, sizeof(headerOSTC3));
38
+ − 1742 }
+ − 1743
+ − 1744 return &headerOSTC3;
+ − 1745 }
+ − 1746
+ − 1747
+ − 1748 /********************************************************************************
+ − 1749 * @brief logbook_build_ostc3header_compact. /
+ − 1750 * @author heinrichs weikamp gmbh
+ − 1751 * @version V0.0.1
+ − 1752 * @date 31-Juli-2015
+ − 1753 *********************************************************************************/
+ − 1754 SLogbookHeaderOSTC3compact * logbook_build_ostc3header_compact(SLogbookHeader* pHead)
+ − 1755 {
465
+ − 1756 uint8_t returnEmptyHeader = 0;
411
+ − 1757 convert_Type data, data2;
455
+ − 1758 uint32_t dummyLength = 0;
465
+ − 1759 uint32_t headerProfileLength, sampleProfileLength, sampleProfileStart;
411
+ − 1760
465
+ − 1761 if(pHead->diveHeaderStart != 0xFAFA)
411
+ − 1762 {
465
+ − 1763 returnEmptyHeader = 1;
411
+ − 1764 }
+ − 1765 else
+ − 1766 {
465
+ − 1767 data.u8bit.byteHigh = 0;
+ − 1768 data.u8bit.byteLow = pHead->pBeginProfileData[0];
+ − 1769 data.u8bit.byteMidLow = pHead->pBeginProfileData[1];
+ − 1770 data.u8bit.byteMidHigh = pHead->pBeginProfileData[2];
+ − 1771
+ − 1772 sampleProfileStart = data.u32bit;
+ − 1773
+ − 1774 data2.u8bit.byteHigh = 0;
+ − 1775 data2.u8bit.byteLow = pHead->pEndProfileData[0];
+ − 1776 data2.u8bit.byteMidLow = pHead->pEndProfileData[1];
+ − 1777 data2.u8bit.byteMidHigh = pHead->pEndProfileData[2];
+ − 1778
+ − 1779 data.u8bit.byteHigh = 0;
+ − 1780 data.u8bit.byteLow = pHead->profileLength[0];
+ − 1781 data.u8bit.byteMidLow = pHead->profileLength[1];
+ − 1782 data.u8bit.byteMidHigh = pHead->profileLength[2];
+ − 1783
+ − 1784 if(data.u32bit != 0xFFFFFF)
455
+ − 1785 {
465
+ − 1786 if(data2.u32bit < sampleProfileStart) /* Wrap around of sample ring detected */
+ − 1787 {
+ − 1788 if(ext_flash_SampleOverrunValid() == 0) /* Wrap around does not seem to be valid => fallback */
+ − 1789 {
+ − 1790 sampleProfileStart = 0;
+ − 1791 }
+ − 1792 }
+ − 1793
+ − 1794 if( sampleProfileStart == 0) /* no sample data available => use dummy */
+ − 1795 {
+ − 1796 sampleProfileLength = 1;
+ − 1797 headerProfileLength = 2;
+ − 1798 }
+ − 1799 else
+ − 1800 {
+ − 1801 headerProfileLength = (pHead->profileLength[2] << 16) + (pHead->profileLength[1] << 8) + pHead->profileLength[0];
+ − 1802 sampleProfileLength = ext_flash_read_profilelength_small_header(sampleProfileStart);
+ − 1803 }
+ − 1804 if(sampleProfileLength != headerProfileLength)
+ − 1805 {
+ − 1806 dummyLength = logbook_fillDummySampleBuffer(pHead);
+ − 1807
+ − 1808 data2.u32bit = sampleProfileStart + dummyLength; /* calc new end address (which is equal to dummyLength) */
+ − 1809 data.u32bit = dummyLength; /* data is used below to represent the length */
+ − 1810 }
+ − 1811 data.u32bit += 3;
+ − 1812 headerOSTC3compact.profileLength[0] = data.u8bit.byteLow;
+ − 1813 headerOSTC3compact.profileLength[1] = data.u8bit.byteMidLow;
+ − 1814 headerOSTC3compact.profileLength[2] = data.u8bit.byteMidHigh;
+ − 1815
+ − 1816 headerOSTC3compact.dateYear = pHead->dateYear;
+ − 1817 headerOSTC3compact.dateMonth = pHead->dateMonth;
+ − 1818 headerOSTC3compact.dateDay = pHead->dateDay;
+ − 1819 headerOSTC3compact.timeHour = pHead->timeHour;
+ − 1820 headerOSTC3compact.timeMinute = pHead->timeMinute;
+ − 1821
+ − 1822 memcpy(headerOSTC3compact.maxDepth, &pHead->maxDepth, 2);
+ − 1823 memcpy(headerOSTC3compact.diveTimeMinutes, &pHead->diveTimeMinutes, 2);
+ − 1824
+ − 1825 headerOSTC3compact.diveTimeSeconds = pHead->diveTimeSeconds;
+ − 1826 headerOSTC3compact.totalDiveNumberLow = pHead->diveNumber & 0xFF;
+ − 1827 headerOSTC3compact.totalDiveNumberHigh = (uint8_t)(pHead->diveNumber/256);
+ − 1828 headerOSTC3compact.profileVersion = 0x24; // Logbook-Profile version, 0x24 = date and time is start not end
455
+ − 1829 }
+ − 1830 else
+ − 1831 {
465
+ − 1832 returnEmptyHeader = 1;
455
+ − 1833 }
411
+ − 1834 }
465
+ − 1835 if(returnEmptyHeader)
38
+ − 1836 {
+ − 1837 memset(&headerOSTC3compact, 0xFF, sizeof(SLogbookHeaderOSTC3compact));
+ − 1838 }
+ − 1839 return &headerOSTC3compact;
+ − 1840 }
+ − 1841
+ − 1842
+ − 1843 /**
+ − 1844 ******************************************************************************
+ − 1845 * @brief logbook_readSampleData. / Reads sample data of whole logbook entry
281
+ − 1846 * @author heinrichs weikamp
38
+ − 1847 * @version V0.0.1
+ − 1848 * @date 22-April-2014
+ − 1849 ******************************************************************************
+ − 1850 *
+ − 1851 * @param uint8_t StepBackwards: witch lookbook entry?
+ − 1852 * @param uint16_t length : maxlength of output arrays
+ − 1853 * @param int32_t* depth : output array
+ − 1854 * @param int16_t * gasid : output array
+ − 1855 * @param int32_t* temperature : output array
+ − 1856 * @param int32_t* ppo2 : output array
+ − 1857 * @param int32_t* cns : output array
+ − 1858 * @return length of output
+ − 1859 */
+ − 1860 void logbook_recover_brokenlog(uint8_t headerId)
+ − 1861 {
+ − 1862 int16_t retVal;
+ − 1863 int32_t depthVal = 0;
+ − 1864 int16_t gasidVal = 0;
+ − 1865 int16_t setPointVal = 0;
+ − 1866 int16_t bailoutVal = 0;
+ − 1867 int32_t temperatureVal = 0;
+ − 1868 int32_t sensor1Val = 0;
+ − 1869 int32_t sensor2Val = 0;
+ − 1870 int32_t sensor3Val = 0;
+ − 1871 int32_t cnsVal = 0;
941
+ − 1872 SManualGas manualGasVal;
+ − 1873 int16_t decostepDepthVal = 0;
+ − 1874 uint16_t tankVal = 0;
+ − 1875 uint8_t eventdata;
+ − 1876 SGnssCoord posCoord;
38
+ − 1877
+ − 1878 //uint16_t* ppo2, uint16_t* cns#
+ − 1879 uint32_t bytesRead = 0;
+ − 1880
+ − 1881 ext_flash_read_block_start();
+ − 1882 ext_flash_read_next_sample_part((uint8_t*)&smallHeader, sizeof(SSmallHeader));
+ − 1883 bytesRead += sizeof(SSmallHeader);
+ − 1884
+ − 1885 clear_divisor();
+ − 1886
+ − 1887
+ − 1888 int sampleCounter = 0;
+ − 1889 int maxdepth = 0;
+ − 1890 uint32_t avrdepth = 0;
+ − 1891 while (true)
+ − 1892 {
+ − 1893
+ − 1894 ext_flash_set_entry_point();
+ − 1895 divisorBackup = divisor;
941
+ − 1896 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal,
+ − 1897 &bailoutVal, &decostepDepthVal,&tankVal, &posCoord, &eventdata);
38
+ − 1898 if(retVal == 0)
+ − 1899 {
+ − 1900 //Error try to read again!!!
+ − 1901 ext_flash_reopen_read_sample_at_entry_point();
+ − 1902 divisor = divisorBackup;
941
+ − 1903 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal,
+ − 1904 &bailoutVal, &decostepDepthVal, &tankVal, &posCoord, &eventdata);
38
+ − 1905 if(retVal == 0)
+ − 1906 {
+ − 1907 //Error try to read again!!!
+ − 1908 ext_flash_reopen_read_sample_at_entry_point();
+ − 1909 divisor = divisorBackup;
941
+ − 1910 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal,
+ − 1911 &bailoutVal, &decostepDepthVal,&tankVal, &posCoord, &eventdata);
38
+ − 1912 if(retVal == 0)
+ − 1913 {
+ − 1914 ext_flash_reopen_read_sample_at_entry_point();
+ − 1915 break;
+ − 1916 }
+ − 1917
+ − 1918 }
+ − 1919 }
+ − 1920 if(depthVal > maxdepth)
+ − 1921 maxdepth = depthVal;
+ − 1922 avrdepth += depthVal;
+ − 1923 sampleCounter++;
+ − 1924 bytesRead +=retVal;
+ − 1925 }
+ − 1926 avrdepth/= sampleCounter;
+ − 1927 ext_flash_close_read_sample();
+ − 1928 SLogbookHeader header;
+ − 1929
+ − 1930 ext_flash_read_dive_header2((uint8_t*) &header, headerId, false);
+ − 1931 header.total_diveTime_seconds = sampleCounter * header.samplingRate;
+ − 1932 header.diveTimeMinutes = header.total_diveTime_seconds /60;
+ − 1933 header.diveTimeSeconds = header.total_diveTime_seconds - header.diveTimeMinutes * 60;
+ − 1934 header.maxDepth = maxdepth;
+ − 1935 header.averageDepth_mbar = avrdepth;
+ − 1936 SSettings * settings = settingsGetPointer();
+ − 1937 settings->lastDiveLogId = headerId;
+ − 1938 ext_flash_close_new_dive_log((uint8_t *)&header);
+ − 1939 }
+ − 1940
458
+ − 1941 void logbook_createDummyProfile(SLogbookHeader* pHeader, uint16_t length, uint16_t* depth, int16_t* temperature, uint16_t* ppo2)
455
+ − 1942 {
+ − 1943 uint8_t drawDeco = 1;
+ − 1944 uint16_t index = 0;
+ − 1945 uint16_t indexDescenStop = 0;
+ − 1946 uint16_t indexAscendStart = 0;
+ − 1947 uint16_t simDecentDepth = 0;
+ − 1948 uint16_t simDecentStep = 0;
+ − 1949 uint16_t simAcentDepth = 0;
+ − 1950 uint16_t simAcentStep = 0;
458
+ − 1951 float ambiant_pressure_bar = 0;
455
+ − 1952
458
+ − 1953 simDecentStep = pHeader->maxDepth / (length / 6); /* first 1/6 for descend */
+ − 1954 simAcentStep = pHeader->maxDepth / (length / 3); /* first 1/3 for ascend */
+ − 1955
+ − 1956 SGas gas;
+ − 1957
455
+ − 1958
458
+ − 1959 if(ppo2)
+ − 1960 {
+ − 1961 /* find first gas ID */
524
+ − 1962 for(index = 0; index < NUM_GASES; index++)
458
+ − 1963 {
+ − 1964 if(pHeader->gasordil[index].note.ub.first)
+ − 1965 break;
+ − 1966 }
524
+ − 1967 if(index != NUM_GASES)
458
+ − 1968 {
+ − 1969 gas.helium_percentage = pHeader->gasordil[index].helium_percentage;
+ − 1970 gas.nitrogen_percentage = 100 - gas.helium_percentage - pHeader->gasordil[index].oxygen_percentage;
+ − 1971 }
+ − 1972 }
+ − 1973
+ − 1974 while((index < length) && (simDecentDepth < pHeader->maxDepth)) /* draw decent */
455
+ − 1975 {
+ − 1976 depth[index] = simDecentDepth;
458
+ − 1977 temperature[index] = pHeader->minTemp;
+ − 1978 if(ppo2)
+ − 1979 {
+ − 1980 ambiant_pressure_bar =((float)(depth[index] + pHeader->surfacePressure_mbar))/1000;
+ − 1981 ppo2[index] = (uint16_t) ((decom_calc_ppO2(ambiant_pressure_bar, &gas )) * 100);
+ − 1982 }
455
+ − 1983 index++;
+ − 1984 simDecentDepth += simDecentStep;
+ − 1985 }
+ − 1986 indexDescenStop = index;
+ − 1987 index = length -1;
458
+ − 1988 while((index > indexDescenStop) && (simAcentDepth < pHeader->maxDepth)) /* draw ascend including max deco stop */
455
+ − 1989 {
+ − 1990 depth[index] = simAcentDepth;
458
+ − 1991 temperature[index] = pHeader->minTemp;
+ − 1992 if(ppo2)
+ − 1993 {
+ − 1994 ambiant_pressure_bar =((float)(depth[index] + pHeader->surfacePressure_mbar))/1000;
+ − 1995 ppo2[index] = (uint16_t) ((decom_calc_ppO2(ambiant_pressure_bar, &gas )) * 100);
+ − 1996 }
+ − 1997 if((drawDeco) && (simAcentDepth < pHeader->lastDecostop_m)) /* draw deco step */
455
+ − 1998 {
+ − 1999 drawDeco = length / 10;
458
+ − 2000 while(drawDeco)
455
+ − 2001 {
+ − 2002 index--;
+ − 2003 depth[index] = simAcentDepth;
458
+ − 2004 temperature[index] = pHeader->minTemp;
+ − 2005 if(ppo2)
+ − 2006 {
+ − 2007 ambiant_pressure_bar =((float)(depth[index] + pHeader->surfacePressure_mbar))/1000;
+ − 2008 ppo2[index] = (uint16_t) ((decom_calc_ppO2(ambiant_pressure_bar, &gas )) * 100);
+ − 2009 }
+ − 2010 drawDeco--;
455
+ − 2011 }
+ − 2012 }
+ − 2013 index--;
+ − 2014 simAcentDepth += simAcentStep;
+ − 2015 }
+ − 2016 indexAscendStart = index;
+ − 2017 index = indexDescenStop;
+ − 2018 while(index <= indexAscendStart) /* draw isobar dive phase */
+ − 2019 {
458
+ − 2020 depth[index] = pHeader->maxDepth;
+ − 2021 temperature[index] = pHeader->minTemp;
+ − 2022 if(ppo2)
+ − 2023 {
+ − 2024 ambiant_pressure_bar =((float)(depth[index] + pHeader->surfacePressure_mbar))/1000;
+ − 2025 ppo2[index] = (uint16_t) ((decom_calc_ppO2(ambiant_pressure_bar, &gas )) * 100);
+ − 2026 }
455
+ − 2027 index++;
+ − 2028 }
+ − 2029 }
+ − 2030
+ − 2031 void logbook_resetDummy()
+ − 2032 {
+ − 2033 dummyWriteIdx = 0;
+ − 2034 dummyReadIdx = 0;
+ − 2035 }
+ − 2036
+ − 2037 void logbook_writeDummy(void* data, uint16_t length)
+ − 2038 {
+ − 2039 memcpy(&dummyMemoryBuffer[dummyWriteIdx],(uint8_t *)data, length);
+ − 2040 dummyWriteIdx += length;
+ − 2041 }
+ − 2042 void logbook_writeDummySample(uint16_t depth, int16_t temperature)
+ − 2043 {
+ − 2044 uint8_t sample[10];
+ − 2045 int length = 0;
+ − 2046
+ − 2047 int i = 0;
+ − 2048 for(i = 0; i <10 ;i++) sample[i] = 0;
+ − 2049 addU16(sample, depth);
+ − 2050 length += 2;
+ − 2051 sample[2] = 0;
+ − 2052 length++;
+ − 2053
+ − 2054 if(divisor.temperature == 0)
+ − 2055 {
+ − 2056 divisor.temperature = smallHeader.tempDivisor - 1;
+ − 2057 addS16(&sample[length], temperature);
+ − 2058 length += 2;
+ − 2059 }
+ − 2060 else
+ − 2061 {
+ − 2062 divisor.temperature--;
+ − 2063 }
+ − 2064
465
+ − 2065 logbook_writeDummy((void *) sample,length);
455
+ − 2066 }
+ − 2067
+ − 2068
458
+ − 2069 uint16_t logbook_fillDummySampleBuffer(SLogbookHeader* pHeader)
455
+ − 2070 {
+ − 2071 uint16_t depthArray[DUMMY_SAMPLES];
+ − 2072 int16_t temperatureArray[DUMMY_SAMPLES];
458
+ − 2073 uint16_t ppo2Array[DUMMY_SAMPLES];
455
+ − 2074
+ − 2075 uint16_t index = 0;
+ − 2076 uint16_t dummyBufferSize = 0;
+ − 2077 uint16_t dummyProfileLength = 0;
458
+ − 2078 uint32_t overallSecond = pHeader->diveTimeMinutes * 60 + pHeader->diveTimeSeconds;
455
+ − 2079
+ − 2080 logbook_resetDummy();
+ − 2081 clear_divisor();
+ − 2082
+ − 2083 smallDummyHeader.profileLength[0] = 0xFF;
+ − 2084 smallDummyHeader.profileLength[1] = 0xFF;
+ − 2085 smallDummyHeader.profileLength[2] = 0xFF;
+ − 2086 smallDummyHeader.samplingRate_seconds = 2;
+ − 2087 smallDummyHeader.numDivisors = 7;
+ − 2088
+ − 2089 smallDummyHeader.tempType = 0;
+ − 2090 smallDummyHeader.tempLength = 2;
+ − 2091 smallDummyHeader.tempDivisor = 6;
+ − 2092
+ − 2093 smallDummyHeader.deco_ndlType = 1;
+ − 2094 smallDummyHeader.deco_ndlLength = 2;
+ − 2095 smallDummyHeader.deco_ndlDivisor = 0;
+ − 2096
+ − 2097 /* GF in % at actual position */
+ − 2098 smallDummyHeader.gfType = 2;
+ − 2099 smallDummyHeader.gfLength = 1;
+ − 2100 smallDummyHeader.gfDivisor = 0;
+ − 2101
+ − 2102 /* 3 Sensors: 8bit ppO2 in 0.01bar, 16bit voltage in 0,1mV */
+ − 2103 smallDummyHeader.ppo2Type = 3;
+ − 2104 smallDummyHeader.ppo2Length = 9;
+ − 2105 smallDummyHeader.ppo2Divisor = 0;
+ − 2106
+ − 2107 /* last 15 stops in minutes (last, second_to_last, ... */
+ − 2108 /* last stop depth is defined in header */
+ − 2109 smallDummyHeader.decoplanType = 4;
+ − 2110 smallDummyHeader.decoplanLength = 15;
+ − 2111 smallDummyHeader.decoplanDivisor = 0;
+ − 2112
+ − 2113 smallDummyHeader.cnsType = 5;
+ − 2114 smallDummyHeader.cnsLength = 2;
+ − 2115 smallDummyHeader.cnsDivisor = 0;
+ − 2116
+ − 2117 smallDummyHeader.tankType = 6;
+ − 2118 smallDummyHeader.tankLength = 2;
+ − 2119 smallDummyHeader.tankDivisor = 0;
+ − 2120
+ − 2121 if((overallSecond / smallDummyHeader.samplingRate_seconds) > DUMMY_SAMPLES) /* reduce sample interval to keep buffer size */
+ − 2122 {
+ − 2123 smallDummyHeader.samplingRate_seconds = overallSecond / DUMMY_SAMPLES;
+ − 2124 dummyProfileLength = DUMMY_SAMPLES;
+ − 2125 }
+ − 2126 else
+ − 2127 {
+ − 2128 dummyProfileLength = overallSecond / smallDummyHeader.samplingRate_seconds;
+ − 2129 }
+ − 2130 logbook_writeDummy((void *) &smallDummyHeader,sizeof(smallDummyHeader));
458
+ − 2131 logbook_createDummyProfile(pHeader,dummyProfileLength, depthArray, temperatureArray, ppo2Array );
455
+ − 2132
+ − 2133 for (index = 0; index < dummyProfileLength; index++)
+ − 2134 {
+ − 2135 logbook_writeDummySample(depthArray[index], temperatureArray[index]);
+ − 2136 }
+ − 2137
+ − 2138 dummyBufferSize = dummyWriteIdx;
+ − 2139
+ − 2140 return dummyBufferSize; /* return size of dummy buffer */
+ − 2141 }
+ − 2142
+ − 2143 void logbook_readDummySamples(uint8_t* pTarget, uint16_t length)
+ − 2144 {
+ − 2145 memcpy(pTarget,&dummyMemoryBuffer[dummyReadIdx],length);
+ − 2146 dummyReadIdx += length;
+ − 2147 }
+ − 2148
+ − 2149
38
+ − 2150 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/