comparison Discovery/Src/logbook.c @ 270:2e58a4094770 write-from-sim

feature, debug: make simulator write a logbook entry When compiling the code with -DSIM_WRITES_LOGBOOK, the simulator writes to the logbook. This is for debug purpose only. This commit does *not* define this SIM_WRITES_LOGBOOK, so when compiled, things are functionally unchanged. Caveat 1: a simulator generated log cannot be advanced with +5 min. It needs to run in real time. Caveat 2: The generated log is currently not "complete". For example, CCR setpoint switches are not logged. There are likely more small events not logged. This means that a sim generated log is not a full replacement for real dive testing. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Wed, 24 Apr 2019 17:10:51 +0200
parents 6e78137952af
children 54d14bc2083c
comparison
equal deleted inserted replaced
269:6e78137952af 270:2e58a4094770
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;
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 {
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))
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 {