Mercurial > public > ostc4
comparison Discovery/Src/logbook.c @ 273:5fe136480a47
Merged in janlmulder/ostc4/write-from-sim (pull request #20)
Cleanup and debug capabilty to write logbook from simulator
author | heinrichsweikamp <bitbucket@heinrichsweikamp.com> |
---|---|
date | Sun, 28 Apr 2019 07:05:23 +0000 |
parents | 2e58a4094770 |
children | 54d14bc2083c |
comparison
equal
deleted
inserted
replaced
267:cf6ad20380fb | 273:5fe136480a47 |
---|---|
88 /* Private function prototypes -----------------------------------------------*/ | 88 /* Private function prototypes -----------------------------------------------*/ |
89 static void clear_divisor(void); | 89 static void clear_divisor(void); |
90 static void logbook_SetAverageDepth(float average_depth_meter); | 90 static void logbook_SetAverageDepth(float average_depth_meter); |
91 static void logbook_SetMinTemperature(float min_temperature_celsius); | 91 static void logbook_SetMinTemperature(float min_temperature_celsius); |
92 static void logbook_SetMaxCNS(float max_cns_percentage); | 92 static void logbook_SetMaxCNS(float max_cns_percentage); |
93 static void logbook_SetCompartmentDesaturation(void); | 93 static void logbook_SetCompartmentDesaturation(const SDiveState * pStateReal); |
94 static void logbook_SetLastStop(float last_stop_depth_bar); | 94 static void logbook_SetLastStop(float last_stop_depth_bar); |
95 static void logbook_writedata(void * data, int length_byte); | 95 static void logbook_writedata(void * data, int length_byte); |
96 static void logbook_UpdateHeader(void); | 96 static void logbook_UpdateHeader(const SDiveState * pStateReal); |
97 | 97 |
98 /* Exported functions --------------------------------------------------------*/ | 98 /* Exported functions --------------------------------------------------------*/ |
99 | 99 |
100 void logbook_EndDive(void) | 100 void logbook_EndDive(void) |
101 { | 101 { |
265 } | 265 } |
266 | 266 |
267 memcpy(header.n2Compartments, pInfo->lifeData.tissue_nitrogen_bar, 64); | 267 memcpy(header.n2Compartments, pInfo->lifeData.tissue_nitrogen_bar, 64); |
268 memcpy(header.heCompartments, pInfo->lifeData.tissue_helium_bar, 64); | 268 memcpy(header.heCompartments, pInfo->lifeData.tissue_helium_bar, 64); |
269 | 269 |
270 logbook_SetCompartmentDesaturation(); | 270 logbook_SetCompartmentDesaturation(pInfo); |
271 | 271 |
272 ext_flash_start_new_dive_log_and_set_actualPointerSample((uint8_t*)&header); | 272 ext_flash_start_new_dive_log_and_set_actualPointerSample((uint8_t*)&header); |
273 | 273 |
274 smallHeader.profileLength[0] = 0xFF; | 274 smallHeader.profileLength[0] = 0xFF; |
275 smallHeader.profileLength[1] = 0xFF; | 275 smallHeader.profileLength[1] = 0xFF; |
369 ****************************************************************************** | 369 ****************************************************************************** |
370 * | 370 * |
371 * @param SDiveState state: | 371 * @param SDiveState state: |
372 */ | 372 */ |
373 | 373 |
374 void logbook_writeSample(SDiveState state) | 374 void logbook_writeSample(const SDiveState *state) |
375 { | 375 { |
376 uint8_t sample[256]; | 376 uint8_t sample[256]; |
377 // int position = 0; | 377 // int position = 0; |
378 int length = 0; | 378 int length = 0; |
379 // _Bool bEvent = 0; | 379 // _Bool bEvent = 0; |
383 bit8_Type eventByte1, eventByte2; | 383 bit8_Type eventByte1, eventByte2; |
384 bit8_Type profileByteFlag; | 384 bit8_Type profileByteFlag; |
385 int i = 0; | 385 int i = 0; |
386 for(i = 0; i <256 ;i++) | 386 for(i = 0; i <256 ;i++) |
387 sample[i] = 0; | 387 sample[i] = 0; |
388 addU16(sample, (uint16_t)(state.lifeData.depth_meter * 100)); | 388 addU16(sample, (uint16_t)(state->lifeData.depth_meter * 100)); |
389 length += 2; | 389 length += 2; |
390 sample[2] = 0; | 390 sample[2] = 0; |
391 length++; | 391 length++; |
392 eventByte1.uw = 0; | 392 eventByte1.uw = 0; |
393 eventByte2.uw = 0; | 393 eventByte2.uw = 0; |
394 //uint16_t tmpU16 = 0; | 394 //uint16_t tmpU16 = 0; |
395 const SDecoinfo * pDecoinfo; // new hw 160620 | 395 const SDecoinfo * pDecoinfo; // new hw 160620 |
396 | 396 |
397 //BuildEevntyte 1 | 397 //BuildEevntyte 1 |
398 // sub old 0-3 only one at a time | 398 // sub old 0-3 only one at a time |
399 if(state.events.manualMarker) | 399 if(state->events.manualMarker) |
400 { | 400 { |
401 eventByte1.uw = 6; | 401 eventByte1.uw = 6; |
402 } | 402 } |
403 else | 403 else |
404 if(state.warnings.decoMissed) | 404 if(state->warnings.decoMissed) |
405 { | 405 { |
406 eventByte1.uw = 2; | 406 eventByte1.uw = 2; |
407 } | 407 } |
408 else | 408 else |
409 if(state.warnings.ppO2Low) | 409 if(state->warnings.ppO2Low) |
410 { | 410 { |
411 eventByte1.uw = 4; | 411 eventByte1.uw = 4; |
412 } | 412 } |
413 else | 413 else |
414 if(state.warnings.ppO2High) | 414 if(state->warnings.ppO2High) |
415 { | 415 { |
416 eventByte1.uw = 5; | 416 eventByte1.uw = 5; |
417 } | 417 } |
418 else | 418 else |
419 if(state.warnings.lowBattery) | 419 if(state->warnings.lowBattery) |
420 { | 420 { |
421 eventByte1.uw = 7; | 421 eventByte1.uw = 7; |
422 } | 422 } |
423 else | 423 else |
424 if(state.warnings.slowWarning) | 424 if(state->warnings.slowWarning) |
425 { | 425 { |
426 eventByte1.uw = 1; | 426 eventByte1.uw = 1; |
427 } | 427 } |
428 // sub bit 4 to 7 | 428 // sub bit 4 to 7 |
429 if(state.events.manuelGasSet) | 429 if(state->events.manuelGasSet) |
430 { | 430 { |
431 eventByte1.ub.bit4 = 1; | 431 eventByte1.ub.bit4 = 1; |
432 } | 432 } |
433 if(state.events.gasChange) | 433 if(state->events.gasChange) |
434 { | 434 { |
435 eventByte1.ub.bit5 = 1; | 435 eventByte1.ub.bit5 = 1; |
436 } | 436 } |
437 if(state.events.setpointChange) | 437 if(state->events.setpointChange) |
438 { | 438 { |
439 eventByte1.ub.bit6 = 1; | 439 eventByte1.ub.bit6 = 1; |
440 } | 440 } |
441 // sub bit 7 + eventbyte2 | 441 // sub bit 7 + eventbyte2 |
442 if(state.events.bailout) | 442 if(state->events.bailout) |
443 { | 443 { |
444 eventByte1.ub.bit7 = 1; | 444 eventByte1.ub.bit7 = 1; |
445 eventByte2.ub.bit0 = 1; | 445 eventByte2.ub.bit0 = 1; |
446 } | 446 } |
447 //Add EventByte 1 | 447 //Add EventByte 1 |
454 { | 454 { |
455 sample[length] = eventByte2.uw; | 455 sample[length] = eventByte2.uw; |
456 length++; | 456 length++; |
457 } | 457 } |
458 //Add EventInfos | 458 //Add EventInfos |
459 if(state.events.manuelGasSet) | 459 if(state->events.manuelGasSet) |
460 { | 460 { |
461 //manual gas in %O2 & %He | 461 //manual gas in %O2 & %He |
462 sample[length] = state.events.info_manuelGasSetO2; | 462 sample[length] = state->events.info_manuelGasSetO2; |
463 length += 1; | 463 length += 1; |
464 sample[length] = state.events.info_manuelGasSetHe; | 464 sample[length] = state->events.info_manuelGasSetHe; |
465 length += 1; | 465 length += 1; |
466 } | 466 } |
467 if(state.events.gasChange) | 467 if(state->events.gasChange) |
468 { | 468 { |
469 //Current gas (gasid) | 469 //Current gas (gasid) |
470 sample[length] = state.events.info_GasChange; | 470 sample[length] = state->events.info_GasChange; |
471 length += 1; | 471 length += 1; |
472 } | 472 } |
473 if(state.events.setpointChange) | 473 if(state->events.setpointChange) |
474 { | 474 { |
475 //New setpoint in cbar | 475 //New setpoint in cbar |
476 sample[length] = state.events.info_SetpointChange; | 476 sample[length] = state->events.info_SetpointChange; |
477 length += 1; | 477 length += 1; |
478 } | 478 } |
479 if(state.events.bailout) | 479 if(state->events.bailout) |
480 { | 480 { |
481 //bailout gas in % O2 & %He | 481 //bailout gas in % O2 & %He |
482 sample[length] = state.events.info_bailoutO2; | 482 sample[length] = state->events.info_bailoutO2; |
483 length += 1; | 483 length += 1; |
484 sample[length] = state.events.info_bailoutHe; | 484 sample[length] = state->events.info_bailoutHe; |
485 length += 1; | 485 length += 1; |
486 } | 486 } |
487 | 487 |
488 | 488 |
489 if(divisor.temperature == 0) | 489 if(divisor.temperature == 0) |
490 { | 490 { |
491 divisor.temperature = smallHeader.tempDivisor - 1; | 491 divisor.temperature = smallHeader.tempDivisor - 1; |
492 addS16(&sample[length], (int16_t)((state.lifeData.temperature_celsius * 10.0f) + 0.5f)); | 492 addS16(&sample[length], (int16_t)((state->lifeData.temperature_celsius * 10.0f) + 0.5f)); |
493 length += 2; | 493 length += 2; |
494 } | 494 } |
495 else | 495 else |
496 { | 496 { |
497 divisor.temperature--; | 497 divisor.temperature--; |
554 { | 554 { |
555 divisor.ppo2 = smallHeader.ppo2Divisor - 1; | 555 divisor.ppo2 = smallHeader.ppo2Divisor - 1; |
556 | 556 |
557 for(int i = 0; i <3; i++) | 557 for(int i = 0; i <3; i++) |
558 { | 558 { |
559 sample[length] = (uint8_t)(state.lifeData.ppO2Sensor_bar[i] * 100.0f + 0.5f); | 559 sample[length] = (uint8_t)(state->lifeData.ppO2Sensor_bar[i] * 100.0f + 0.5f); |
560 length += 1; | 560 length += 1; |
561 addU16(&sample[length], (uint16_t)(state.lifeData.sensorVoltage_mV[i] * 10.0f + 0.5f)); | 561 addU16(&sample[length], (uint16_t)(state->lifeData.sensorVoltage_mV[i] * 10.0f + 0.5f)); |
562 length += 2; | 562 length += 2; |
563 } | 563 } |
564 } | 564 } |
565 else | 565 else |
566 { | 566 { |
572 if(smallHeader.decoplanDivisor) | 572 if(smallHeader.decoplanDivisor) |
573 { | 573 { |
574 if(divisor.decoplan == 0) | 574 if(divisor.decoplan == 0) |
575 { | 575 { |
576 divisor.decoplan = smallHeader.decoplanDivisor - 1; | 576 divisor.decoplan = smallHeader.decoplanDivisor - 1; |
577 if(state.diveSettings.deco_type.ub.standard == VPM_MODE) | 577 if(state->diveSettings.deco_type.ub.standard == VPM_MODE) |
578 { | 578 { |
579 for(int i = 0; i <15; i++) | 579 for(int i = 0; i <15; i++) |
580 { | 580 { |
581 sample[length] = state.decolistVPM.output_stop_length_seconds[i] / 60; | 581 sample[length] = state->decolistVPM.output_stop_length_seconds[i] / 60; |
582 length += 1; | 582 length += 1; |
583 } | 583 } |
584 } | 584 } |
585 else if(state.diveSettings.deco_type.ub.standard == GF_MODE) | 585 else if(state->diveSettings.deco_type.ub.standard == GF_MODE) |
586 { | 586 { |
587 for(int i = 0; i <15; i++) | 587 for(int i = 0; i <15; i++) |
588 { | 588 { |
589 sample[length] = state.decolistBuehlmann.output_stop_length_seconds[i] / 60; | 589 sample[length] = state->decolistBuehlmann.output_stop_length_seconds[i] / 60; |
590 length += 1; | 590 length += 1; |
591 } | 591 } |
592 } | 592 } |
593 else | 593 else |
594 { | 594 { |
607 } | 607 } |
608 } | 608 } |
609 if(divisor.cns == 0) | 609 if(divisor.cns == 0) |
610 { | 610 { |
611 divisor.cns = smallHeader.cnsDivisor - 1; | 611 divisor.cns = smallHeader.cnsDivisor - 1; |
612 addU16(&sample[length], (uint16_t)state.lifeData.cns); | 612 addU16(&sample[length], (uint16_t)state->lifeData.cns); |
613 length += 2; | 613 length += 2; |
614 } | 614 } |
615 else | 615 else |
616 { | 616 { |
617 divisor.cns--; | 617 divisor.cns--; |
1130 * Automatically Initializes logbook at beginning of dive, | 1130 * Automatically Initializes logbook at beginning of dive, |
1131 * write samples every 2 seconds | 1131 * write samples every 2 seconds |
1132 * and finishes logbook after end of dive | 1132 * and finishes logbook after end of dive |
1133 *********************************************************************************/ | 1133 *********************************************************************************/ |
1134 | 1134 |
1135 void logbook_InitAndWrite(void) | 1135 void logbook_InitAndWrite(const SDiveState *pStateReal) |
1136 { | 1136 { |
1137 SSettings *pSettings = settingsGetPointer(); | 1137 SSettings *pSettings = settingsGetPointer(); |
1138 static uint8_t bDiveMode = 0; | 1138 static uint8_t bDiveMode = 0; |
1139 static uint32_t tickstart = 0; | 1139 static uint32_t tickstart = 0; |
1140 uint32_t ticksdiff = 0; | 1140 uint32_t ticksdiff = 0; |
1141 uint32_t lasttick = 0; | 1141 uint32_t lasttick = 0; |
1142 static float min_temperature_float_celsius = 0; | 1142 static float min_temperature_float_celsius = 0; |
1143 | |
1144 const SDiveState * pStateReal = stateRealGetPointer(); | |
1145 | 1143 |
1146 if(!bDiveMode) | 1144 if(!bDiveMode) |
1147 { | 1145 { |
1148 if((pStateReal->mode == MODE_DIVE) && (pStateReal->diveSettings.diveMode != DIVEMODE_Apnea) && (pStateReal->lifeData.dive_time_seconds >= 5)) | 1146 if((pStateReal->mode == MODE_DIVE) && (pStateReal->diveSettings.diveMode != DIVEMODE_Apnea) && (pStateReal->lifeData.dive_time_seconds >= 5)) |
1149 { | 1147 { |
1150 //InitdiveProfile | 1148 //InitdiveProfile |
1151 pSettings->totalDiveCounter++; | 1149 pSettings->totalDiveCounter++; |
1152 logbook_initNewdiveProfile(pStateReal,settingsGetPointer()); | 1150 logbook_initNewdiveProfile(pStateReal,settingsGetPointer()); |
1153 min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius; | 1151 min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius; |
1154 //Write logbook sample | 1152 //Write logbook sample |
1155 logbook_writeSample(*pStateReal); | 1153 logbook_writeSample(pStateReal); |
1156 resetEvents(); | 1154 resetEvents(pStateReal); |
1157 tickstart = HAL_GetTick(); | 1155 tickstart = HAL_GetTick(); |
1158 bDiveMode = 1; | 1156 bDiveMode = 1; |
1159 } | 1157 } |
1160 } | 1158 } |
1161 else if((pStateReal->mode == MODE_DIVE) && (pStateReal->diveSettings.diveMode != DIVEMODE_Apnea)) | 1159 else if((pStateReal->mode == MODE_DIVE) && (pStateReal->diveSettings.diveMode != DIVEMODE_Apnea)) |
1164 ticksdiff = time_elapsed_ms(tickstart,lasttick); | 1162 ticksdiff = time_elapsed_ms(tickstart,lasttick); |
1165 // | 1163 // |
1166 if(ticksdiff >= 2000) | 1164 if(ticksdiff >= 2000) |
1167 { | 1165 { |
1168 //Write logbook sample | 1166 //Write logbook sample |
1169 logbook_writeSample(*pStateReal); | 1167 logbook_writeSample(pStateReal); |
1170 resetEvents(); | 1168 resetEvents(pStateReal); |
1171 if(min_temperature_float_celsius > pStateReal->lifeData.temperature_celsius) | 1169 if(min_temperature_float_celsius > pStateReal->lifeData.temperature_celsius) |
1172 min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius; | 1170 min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius; |
1173 tickstart = lasttick; | 1171 tickstart = lasttick; |
1174 if((bDiveMode == 1) && (pStateReal->lifeData.dive_time_seconds >= pSettings->divetimeToCreateLogbook)) | 1172 if((bDiveMode == 1) && (pStateReal->lifeData.dive_time_seconds >= pSettings->divetimeToCreateLogbook)) |
1175 { | 1173 { |
1185 ext_flash_write_settings(); | 1183 ext_flash_write_settings(); |
1186 ext_flash_disable_protection_for_logbook(); | 1184 ext_flash_disable_protection_for_logbook(); |
1187 bDiveMode = 3; | 1185 bDiveMode = 3; |
1188 } | 1186 } |
1189 if(bDiveMode == 3) | 1187 if(bDiveMode == 3) |
1190 logbook_UpdateHeader(); | 1188 logbook_UpdateHeader(pStateReal); |
1191 } | 1189 } |
1192 } | 1190 } |
1193 else if(bDiveMode == 3) | 1191 else if(bDiveMode == 3) |
1194 { | 1192 { |
1195 //End of Dive | 1193 //End of Dive |
1196 logbook_SetAverageDepth(pStateReal->lifeData.average_depth_meter); | 1194 logbook_SetAverageDepth(pStateReal->lifeData.average_depth_meter); |
1197 logbook_SetMinTemperature(min_temperature_float_celsius); | 1195 logbook_SetMinTemperature(min_temperature_float_celsius); |
1198 logbook_SetMaxCNS(pStateReal->lifeData.cns); | 1196 logbook_SetMaxCNS(pStateReal->lifeData.cns); |
1199 logbook_SetCompartmentDesaturation(); | 1197 logbook_SetCompartmentDesaturation(pStateReal); |
1200 logbook_SetLastStop(pStateReal->diveSettings.last_stop_depth_bar); | 1198 logbook_SetLastStop(pStateReal->diveSettings.last_stop_depth_bar); |
1201 logbook_EndDive(); | 1199 logbook_EndDive(); |
1202 bDiveMode = 0; | 1200 bDiveMode = 0; |
1203 } else | 1201 } else |
1204 { | 1202 { |
1216 ext_flash_close_new_dive_log() in externLogbookFlash.c | 1214 ext_flash_close_new_dive_log() in externLogbookFlash.c |
1217 * @author heinrichs weikamp gmbh | 1215 * @author heinrichs weikamp gmbh |
1218 * @version V0.0.1 | 1216 * @version V0.0.1 |
1219 * @date 27-Nov-2014 | 1217 * @date 27-Nov-2014 |
1220 *********************************************************************************/ | 1218 *********************************************************************************/ |
1221 static void logbook_UpdateHeader(void) | 1219 static void logbook_UpdateHeader(const SDiveState *pStateReal) |
1222 { | 1220 { |
1223 const SDiveState * pStateReal = stateRealGetPointer(); | |
1224 | |
1225 // uint16_t secondsAtShallow = 0; | 1221 // uint16_t secondsAtShallow = 0; |
1226 RTC_DateTypeDef Sdate; | 1222 RTC_DateTypeDef Sdate; |
1227 RTC_TimeTypeDef Stime; | 1223 RTC_TimeTypeDef Stime; |
1228 uint32_t time1_u32, time2_u32; | 1224 uint32_t time1_u32, time2_u32; |
1229 uint32_t divetimeHelper; | 1225 uint32_t divetimeHelper; |
1337 else | 1333 else |
1338 header.maxCNS = 9999; | 1334 header.maxCNS = 9999; |
1339 } | 1335 } |
1340 | 1336 |
1341 | 1337 |
1342 static void logbook_SetCompartmentDesaturation(void) | 1338 static void logbook_SetCompartmentDesaturation(const SDiveState * pStateReal) |
1343 { | 1339 { |
1344 const SDiveState * pStateReal = stateRealGetPointer(); | |
1345 SLifeData2 secondaryInformation = { 0 }; | 1340 SLifeData2 secondaryInformation = { 0 }; |
1346 | 1341 |
1347 decom_tissues_desaturation_time(&pStateReal->lifeData, &secondaryInformation); | 1342 decom_tissues_desaturation_time(&pStateReal->lifeData, &secondaryInformation); |
1348 for(int i=0;i<16;i++) | 1343 for(int i=0;i<16;i++) |
1349 { | 1344 { |