Mercurial > public > ostc4
annotate Discovery/Src/logbook.c @ 384:427ae9f8e28e MotionDetection
Consider number of available t3 views in sector handling:
Before chande the number of sectors were taken from t7 view only causing t3 view to be shown inconsistent in case t7 view count were not 6. => added function to count views.
author | ideenmodellierer |
---|---|
date | Thu, 17 Oct 2019 23:09:17 +0200 |
parents | 8e62f4701676 |
children | e908b894f107 |
rev | line source |
---|---|
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() | |
59 | |
60 /* Private types -------------------------------------------------------------*/ | |
61 | |
62 #define NUM_GASES 5 | |
63 | |
64 #define LOGBOOK_VERSION (0x30) | |
65 #define LOGBOOK_VERSION_OSTC3 (0x24) | |
66 | |
67 typedef struct /* don't forget to adjust void clear_divisor(void) */ | |
68 { | |
69 uint8_t temperature; | |
70 uint8_t deco_ndl; | |
71 uint8_t gradientFactor; | |
72 uint8_t ppo2; | |
73 uint8_t decoplan; | |
74 uint8_t cns; | |
75 uint8_t tank; | |
76 } SDivisor; | |
77 | |
78 /* Exported variables --------------------------------------------------------*/ | |
79 | |
80 /* Private variables ---------------------------------------------------------*/ | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
81 static SLogbookHeader header; |
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
82 static SLogbookHeaderOSTC3 headerOSTC3; |
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
83 static SLogbookHeaderOSTC3compact headerOSTC3compact; |
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
84 static SSmallHeader smallHeader; |
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
85 static SDivisor divisor; |
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
86 static SDivisor divisorBackup; |
38 | 87 |
88 /* Private function prototypes -----------------------------------------------*/ | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
89 static void clear_divisor(void); |
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
90 static void logbook_SetAverageDepth(float average_depth_meter); |
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
91 static void logbook_SetMinTemperature(float min_temperature_celsius); |
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
92 static void logbook_SetMaxCNS(float max_cns_percentage); |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
93 static void logbook_SetCompartmentDesaturation(const SDiveState * pStateReal); |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
94 static void logbook_SetLastStop(float last_stop_depth_bar); |
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
95 static void logbook_writedata(void * data, int length_byte); |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
96 static void logbook_UpdateHeader(const SDiveState * pStateReal); |
38 | 97 |
98 /* Exported functions --------------------------------------------------------*/ | |
99 | |
100 void logbook_EndDive(void) | |
101 { | |
102 ext_flash_close_new_dive_log((uint8_t*) &header); | |
103 } | |
104 | |
105 | |
106 // =============================================================================== | |
107 // logbook_last_totalDiveCount | |
108 /// @brief Fix setting issues | |
109 /// @date 04-April-2016 | |
110 /// | |
111 /// @return diveNumber (totalDiveCounter) of latest log entry, 0 if not a valid header | |
112 // =============================================================================== | |
113 uint16_t logbook_lastDive_diveNumber(void) | |
114 { | |
115 SLogbookHeader tempLogbookHeader; | |
116 if(logbook_getHeader(0, &tempLogbookHeader)) | |
117 { | |
118 return tempLogbookHeader.diveNumber; | |
119 } | |
120 else | |
121 { | |
122 return 0; | |
123 } | |
124 } | |
125 | |
126 | |
127 /** | |
128 ****************************************************************************** | |
129 * @brief logbook_getCurrentHeader. / | |
281 | 130 * @author heinrichs weikamp |
38 | 131 * @version V0.0.1 |
132 * @date 22-April-2014 | |
133 ****************************************************************************** | |
134 * | |
135 * @return SLogbookHeader*: | |
136 */ | |
137 SLogbookHeader* logbook_getCurrentHeader(void) | |
138 { | |
139 return &header; | |
140 } | |
141 | |
142 /** | |
143 ****************************************************************************** | |
144 * @brief logbook_getNumberOfHeaders. / | |
145 * @author heinrichs weikamp gmbh | |
146 * @version V0.0.1 | |
147 * @date 18-May-2016 | |
148 ****************************************************************************** | |
149 * | |
150 * @return uint8_t : number of valid headers (0xFAFA) found. | |
151 */ | |
152 uint8_t logbook_getNumberOfHeaders(void) | |
153 { | |
154 return ext_flash_count_dive_headers(); | |
155 } | |
156 | |
157 | |
158 /** | |
159 ****************************************************************************** | |
160 * @brief logbook_getHeader. / | |
281 | 161 * @author heinrichs weikamp |
38 | 162 * @version V0.0.1 |
163 * @date 22-April-2014 | |
164 ****************************************************************************** | |
165 * | |
166 * @param StepBackwards : 0 Last lokbook entry, 1 second to last entry, etc. | |
167 * @param SSLogbookHeader* pLogbookHeader: Output found LogbookHeader | |
168 * @return uint8_t : 1 = success | |
169 */ | |
170 uint8_t logbook_getHeader(uint8_t StepBackwards,SLogbookHeader* pLogbookHeader) | |
171 { | |
172 ext_flash_read_dive_header((uint8_t *)pLogbookHeader, StepBackwards); | |
173 if(pLogbookHeader->diveHeaderStart != 0xFAFA) | |
174 return 0; | |
175 else | |
176 return 1; | |
177 } | |
178 | |
179 /** | |
180 ****************************************************************************** | |
181 * @brief logbook_initNewdiveProfile. / | |
182 * creates header and smallHeader from diveState and global Settings | |
183 * and writes new lookboock entry on flash device | |
184 * diveState | |
281 | 185 * @author heinrichs weikamp |
38 | 186 * @version V0.0.1 |
187 * @date 22-April-2014 | |
188 ****************************************************************************** | |
189 * | |
190 * @param SDiveState* pInfo: Input | |
191 * @param SSettings* pSettings: Input | |
192 */ | |
193 | |
194 void logbook_initNewdiveProfile(const SDiveState* pInfo, SSettings* pSettings) | |
195 { | |
196 RTC_DateTypeDef Sdate; | |
197 RTC_TimeTypeDef Stime; | |
198 | |
199 for(int i = 0; i < sizeof(SLogbookHeader); i++) | |
200 { | |
201 ((uint8_t*)(&header))[i] = 0; | |
202 } | |
203 header.diveHeaderStart = 0xFAFA; | |
204 header.diveHeaderEnd = 0xFBFB; | |
205 header.samplingRate = 2; | |
206 if(pInfo->diveSettings.diveMode == DIVEMODE_OC) | |
207 { | |
208 for(int i = 0; i < 5; i++) | |
209 { | |
210 header.gasordil[i].oxygen_percentage = pSettings->gas[i+1].oxygen_percentage; | |
211 header.gasordil[i].helium_percentage = pSettings->gas[i+1].helium_percentage; | |
212 header.gasordil[i].note.uw = pSettings->gas[i+1].note.uw; | |
213 header.gasordil[i].depth_meter = pSettings->gas[i+1].depth_meter; | |
214 } | |
215 } | |
216 else | |
217 { | |
218 for(int i = 0; i < 5; i++) | |
219 { | |
220 header.gasordil[i].oxygen_percentage = pSettings->gas[i+6].oxygen_percentage; | |
221 header.gasordil[i].helium_percentage = pSettings->gas[i+6].helium_percentage; | |
222 header.gasordil[i].note.uw = pSettings->gas[i+6].note.uw; | |
223 header.gasordil[i].depth_meter = pSettings->gas[i+6].depth_meter; | |
224 } | |
225 | |
226 for(int i = 0; i < 5; i++) | |
227 { | |
228 header.setpoint[i].setpoint_cbar = pSettings->setpoint[i+1].setpoint_cbar; | |
229 header.setpoint[i].depth_meter = pSettings->setpoint[i+1].depth_meter; | |
230 } | |
231 } | |
232 // header.gasordil[pInfo->lifeData.actualGas.GasIdInSettings].depth_meter = 0; | |
233 | |
234 translateDate(pInfo->lifeData.dateBinaryFormat, &Sdate); | |
235 translateTime(pInfo->lifeData.timeBinaryFormat, &Stime); | |
236 header.dateYear = Sdate.Year; | |
237 header.dateMonth = Sdate.Month; | |
238 header.dateDay = Sdate.Date; | |
239 header.timeHour = Stime.Hours; | |
240 header.timeMinute = Stime.Minutes; | |
199
ac58a9fb92ac
Bugfix: fix initial CNS data in the logbook header
Jan Mulder <jlmulder@xs4all.nl>
parents:
194
diff
changeset
|
241 header.cnsAtBeginning = (uint16_t)pInfo->lifeData.cns; |
38 | 242 header.surfacePressure_mbar = (uint16_t)(pInfo->lifeData.pressure_surface_bar * 1000); |
243 header.firmwareVersionHigh = firmwareVersion_16bit_high(); | |
244 header.firmwareVersionLow = firmwareVersion_16bit_low(); | |
245 header.logbookProfileVersion = LOGBOOK_VERSION; | |
246 header.salinity = pSettings->salinity; | |
247 header.diveNumber = pSettings->totalDiveCounter; | |
248 header.personalDiveCount = pSettings->personalDiveCount; | |
249 | |
250 header.diveMode = pInfo->diveSettings.diveMode; | |
251 header.CCRmode = pInfo->diveSettings.CCR_Mode; | |
252 header.lastDecostop_m = pSettings->last_stop_depth_meter; | |
253 | |
254 if(pInfo->diveSettings.deco_type.ub.standard == GF_MODE) | |
255 { | |
256 header.decoModel = 1; | |
257 header.gfLow_or_Vpm_conservatism = pInfo->diveSettings.gf_low; | |
258 header.gfHigh = pInfo->diveSettings.gf_high; | |
259 } | |
260 else | |
261 { | |
262 header.decoModel = 2; | |
263 header.gfLow_or_Vpm_conservatism = pInfo->diveSettings.vpm_conservatism; | |
264 header.gfHigh = 0; | |
265 } | |
266 | |
267 memcpy(header.n2Compartments, pInfo->lifeData.tissue_nitrogen_bar, 64); | |
268 memcpy(header.heCompartments, pInfo->lifeData.tissue_helium_bar, 64); | |
269 | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
270 logbook_SetCompartmentDesaturation(pInfo); |
38 | 271 |
272 ext_flash_start_new_dive_log_and_set_actualPointerSample((uint8_t*)&header); | |
273 | |
274 smallHeader.profileLength[0] = 0xFF; | |
275 smallHeader.profileLength[1] = 0xFF; | |
276 smallHeader.profileLength[2] = 0xFF; | |
277 smallHeader.samplingRate_seconds = 2; | |
278 smallHeader.numDivisors = 7; | |
279 | |
280 smallHeader.tempType = 0; | |
281 smallHeader.tempLength = 2; | |
282 smallHeader.tempDivisor = 6; | |
283 | |
284 smallHeader.deco_ndlType = 1; | |
285 smallHeader.deco_ndlLength = 2; | |
286 smallHeader.deco_ndlDivisor = 6; //= 6; | |
287 | |
288 /* GF in % at actual position */ | |
289 smallHeader.gfType = 2; | |
290 smallHeader.gfLength = 1; | |
291 smallHeader.gfDivisor = 0; //12; | |
292 | |
293 /* 3 Sensors: 8bit ppO2 in 0.01bar, 16bit voltage in 0,1mV */ | |
294 smallHeader.ppo2Type = 3; | |
295 smallHeader.ppo2Length = 9; | |
296 smallHeader.ppo2Divisor = 2; //2 | |
297 | |
298 /* last 15 stops in minutes (last, second_to_last, ... */ | |
299 /* last stop depth is defined in header */ | |
300 smallHeader.decoplanType = 4; | |
301 smallHeader.decoplanLength = 15; | |
302 smallHeader.decoplanDivisor = 12;//12; | |
303 | |
304 smallHeader.cnsType = 5; | |
305 smallHeader.cnsLength = 2; | |
306 smallHeader.cnsDivisor = 12; | |
307 | |
308 smallHeader.tankType = 6; | |
309 smallHeader.tankLength = 0; | |
310 smallHeader.tankDivisor = 0; | |
311 | |
312 logbook_writedata((void *) &smallHeader,sizeof(smallHeader)); | |
313 | |
314 clear_divisor(); | |
315 } | |
316 | |
317 /** | |
318 ****************************************************************************** | |
319 * @brief clear_divisor / clears divisor struct | |
281 | 320 * @author heinrichs weikamp |
38 | 321 * @version V0.0.1 |
322 * @date 22-April-2014 | |
323 ****************************************************************************** | |
324 * | |
325 */ | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
326 static void clear_divisor(void) |
38 | 327 { |
328 divisor.cns = smallHeader.cnsDivisor - 1; | |
329 divisor.decoplan = smallHeader.decoplanDivisor - 1; | |
330 divisor.deco_ndl = smallHeader.deco_ndlDivisor - 1; | |
331 divisor.gradientFactor = smallHeader.gfDivisor -1 ; | |
332 divisor.ppo2 = smallHeader.ppo2Divisor - 1; | |
333 divisor.tank = smallHeader.tankDivisor - 1; | |
334 divisor.temperature = smallHeader.tempDivisor - 1; | |
335 } | |
336 | |
337 | |
338 /** | |
339 ****************************************************************************** | |
340 * @brief add16. / adds 16 bit variable to 8 bit array | |
281 | 341 * @author heinrichs weikamp |
38 | 342 * @version V0.0.1 |
343 * @date 22-April-2014 | |
344 ****************************************************************************** | |
345 * | |
346 * @param uint8_t *pos: Output 8 bit array | |
347 * @param uint16_t var: 16 bit variable | |
348 */ | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
349 static void addU16(uint8_t *pos, uint16_t var) |
38 | 350 { |
351 *((uint16_t*)pos) = var; | |
352 } | |
353 | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
354 static void addS16(uint8_t *pos, int16_t var) |
38 | 355 { |
356 *((int16_t*)pos) = var; | |
357 } | |
358 | |
359 /** | |
360 ****************************************************************************** | |
361 * @brief logbook_writeSample. / Writes one logbook sampl | |
281 | 362 * @author heinrichs weikamp |
38 | 363 * @date 22-April-2014 |
364 * @version V0.0.2 | |
365 * @since 20-June-2016 | |
366 * @bug Deco/NDL Status fixed in V0.0.2 | |
367 | |
368 | |
369 ****************************************************************************** | |
370 * | |
371 * @param SDiveState state: | |
372 */ | |
373 | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
374 void logbook_writeSample(const SDiveState *state) |
38 | 375 { |
376 uint8_t sample[256]; | |
377 // int position = 0; | |
378 int length = 0; | |
379 // _Bool bEvent = 0; | |
380 uint8_t nextstopDepthMeter = 0; | |
381 uint16_t nextstopLengthSeconds = 0; | |
382 uint8_t nextstopLengthMinutes = 0; | |
383 bit8_Type eventByte1, eventByte2; | |
384 bit8_Type profileByteFlag; | |
385 int i = 0; | |
386 for(i = 0; i <256 ;i++) | |
387 sample[i] = 0; | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
388 addU16(sample, (uint16_t)(state->lifeData.depth_meter * 100)); |
38 | 389 length += 2; |
390 sample[2] = 0; | |
391 length++; | |
392 eventByte1.uw = 0; | |
393 eventByte2.uw = 0; | |
394 //uint16_t tmpU16 = 0; | |
130
b7689d9e888a
Minor changes to improved code quality and to eliminate warnings
Ideenmodellierer
parents:
38
diff
changeset
|
395 const SDecoinfo * pDecoinfo; // new hw 160620 |
38 | 396 |
397 //BuildEevntyte 1 | |
398 // sub old 0-3 only one at a time | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
399 if(state->events.manualMarker) |
38 | 400 { |
401 eventByte1.uw = 6; | |
402 } | |
403 else | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
404 if(state->warnings.decoMissed) |
38 | 405 { |
406 eventByte1.uw = 2; | |
407 } | |
408 else | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
409 if(state->warnings.ppO2Low) |
38 | 410 { |
411 eventByte1.uw = 4; | |
412 } | |
413 else | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
414 if(state->warnings.ppO2High) |
38 | 415 { |
416 eventByte1.uw = 5; | |
417 } | |
418 else | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
419 if(state->warnings.lowBattery) |
38 | 420 { |
421 eventByte1.uw = 7; | |
422 } | |
423 else | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
424 if(state->warnings.slowWarning) |
38 | 425 { |
426 eventByte1.uw = 1; | |
427 } | |
428 // sub bit 4 to 7 | |
281 | 429 if(state->events.manualGasSet) |
38 | 430 { |
431 eventByte1.ub.bit4 = 1; | |
432 } | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
433 if(state->events.gasChange) |
38 | 434 { |
435 eventByte1.ub.bit5 = 1; | |
436 } | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
437 if(state->events.setpointChange) |
38 | 438 { |
439 eventByte1.ub.bit6 = 1; | |
440 } | |
441 // sub bit 7 + eventbyte2 | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
442 if(state->events.bailout) |
38 | 443 { |
444 eventByte1.ub.bit7 = 1; | |
445 eventByte2.ub.bit0 = 1; | |
446 } | |
447 //Add EventByte 1 | |
448 if(eventByte1.uw > 0) | |
449 { | |
450 sample[length] = eventByte1.uw; | |
451 length++; | |
452 } | |
453 if(eventByte2.uw > 0) | |
454 { | |
455 sample[length] = eventByte2.uw; | |
456 length++; | |
457 } | |
458 //Add EventInfos | |
281 | 459 if(state->events.manualGasSet) |
38 | 460 { |
461 //manual gas in %O2 & %He | |
281 | 462 sample[length] = state->events.info_manualGasSetO2; |
38 | 463 length += 1; |
281 | 464 sample[length] = state->events.info_manualGasSetHe; |
38 | 465 length += 1; |
466 } | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
467 if(state->events.gasChange) |
38 | 468 { |
469 //Current gas (gasid) | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
470 sample[length] = state->events.info_GasChange; |
38 | 471 length += 1; |
472 } | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
473 if(state->events.setpointChange) |
38 | 474 { |
475 //New setpoint in cbar | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
476 sample[length] = state->events.info_SetpointChange; |
38 | 477 length += 1; |
478 } | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
479 if(state->events.bailout) |
38 | 480 { |
481 //bailout gas in % O2 & %He | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
482 sample[length] = state->events.info_bailoutO2; |
38 | 483 length += 1; |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
484 sample[length] = state->events.info_bailoutHe; |
38 | 485 length += 1; |
486 } | |
487 | |
488 | |
489 if(divisor.temperature == 0) | |
490 { | |
491 divisor.temperature = smallHeader.tempDivisor - 1; | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
492 addS16(&sample[length], (int16_t)((state->lifeData.temperature_celsius * 10.0f) + 0.5f)); |
38 | 493 length += 2; |
494 } | |
495 else | |
496 { | |
497 divisor.temperature--; | |
498 } | |
499 | |
500 | |
501 if(smallHeader.deco_ndlDivisor > 0) | |
502 { | |
503 if(divisor.deco_ndl == 0) | |
504 { | |
505 divisor.deco_ndl = smallHeader.deco_ndlDivisor - 1; | |
506 | |
507 if(stateUsed->diveSettings.deco_type.ub.standard == GF_MODE) | |
508 pDecoinfo = &stateUsed->decolistBuehlmann; | |
509 else if(stateUsed->diveSettings.deco_type.ub.standard == VPM_MODE) | |
510 pDecoinfo = &stateUsed->decolistVPM; | |
511 else // should not happen as only GF and VPM at the moment | |
512 { | |
513 sample[length] = 0; | |
514 length += 1; | |
515 sample[length] = 0; | |
516 length += 1; | |
517 } | |
518 | |
519 if(pDecoinfo->output_ndl_seconds > 0) | |
520 { | |
521 sample[length] = 0; | |
522 length += 1; | |
283
04cdeff80254
Bugfix: write NDL in logbook correctly
Jan Mulder <jlmulder@xs4all.nl>
parents:
281
diff
changeset
|
523 sample[length] = (uint8_t)(pDecoinfo->output_ndl_seconds / 60); |
281 | 524 |
525 // Limit stored sample within 0 to 240 mins (Since it's 8bit UINT only) | |
526 if ((pDecoinfo->output_ndl_seconds / 60) > 240) sample[length] = 240; | |
527 if ((pDecoinfo->output_ndl_seconds / 60) < 0) sample[length] = 0; | |
528 | |
38 | 529 length += 1; |
530 } | |
531 else if(pDecoinfo->output_time_to_surface_seconds) | |
532 { | |
533 tHome_findNextStop(pDecoinfo->output_stop_length_seconds, &nextstopDepthMeter, &nextstopLengthSeconds); | |
534 nextstopLengthMinutes = (nextstopLengthSeconds +59 ) / 60; | |
535 | |
536 sample[length] = nextstopDepthMeter; | |
537 length += 1; | |
538 sample[length] = nextstopLengthMinutes; | |
539 length += 1; | |
540 } | |
541 else | |
542 { | |
543 sample[length] = 0; | |
544 length += 1; | |
545 sample[length] = 0; | |
546 length += 1; | |
547 } | |
548 } | |
549 else | |
550 { | |
551 divisor.deco_ndl --; | |
552 } | |
553 } | |
554 | |
555 | |
556 if(smallHeader.ppo2Divisor) | |
557 { | |
558 if(divisor.ppo2 == 0) | |
559 { | |
560 divisor.ppo2 = smallHeader.ppo2Divisor - 1; | |
561 | |
562 for(int i = 0; i <3; i++) | |
563 { | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
564 sample[length] = (uint8_t)(state->lifeData.ppO2Sensor_bar[i] * 100.0f + 0.5f); |
38 | 565 length += 1; |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
566 addU16(&sample[length], (uint16_t)(state->lifeData.sensorVoltage_mV[i] * 10.0f + 0.5f)); |
38 | 567 length += 2; |
568 } | |
569 } | |
570 else | |
571 { | |
572 divisor.ppo2--; | |
573 } | |
574 } | |
575 | |
576 | |
577 if(smallHeader.decoplanDivisor) | |
578 { | |
579 if(divisor.decoplan == 0) | |
580 { | |
581 divisor.decoplan = smallHeader.decoplanDivisor - 1; | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
582 if(state->diveSettings.deco_type.ub.standard == VPM_MODE) |
38 | 583 { |
584 for(int i = 0; i <15; i++) | |
585 { | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
586 sample[length] = state->decolistVPM.output_stop_length_seconds[i] / 60; |
38 | 587 length += 1; |
588 } | |
589 } | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
590 else if(state->diveSettings.deco_type.ub.standard == GF_MODE) |
38 | 591 { |
592 for(int i = 0; i <15; i++) | |
593 { | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
594 sample[length] = state->decolistBuehlmann.output_stop_length_seconds[i] / 60; |
38 | 595 length += 1; |
596 } | |
597 } | |
598 else | |
599 { | |
600 for(int i = 0; i <15; i++) | |
601 { | |
602 sample[length] = 0; | |
603 length += 1; | |
604 } | |
605 } | |
606 // add16(&sample[length], state.temperature); | |
607 //length += 2; | |
608 } | |
609 else | |
610 { | |
611 divisor.decoplan --; | |
612 } | |
613 } | |
614 if(divisor.cns == 0) | |
615 { | |
616 divisor.cns = smallHeader.cnsDivisor - 1; | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
617 addU16(&sample[length], (uint16_t)state->lifeData.cns); |
38 | 618 length += 2; |
619 } | |
620 else | |
621 { | |
622 divisor.cns--; | |
623 } | |
624 | |
625 profileByteFlag.uw = length - 3; | |
626 if(eventByte1.uw) | |
627 { | |
628 profileByteFlag.ub.bit7 = 1; | |
629 } | |
630 sample[2] = profileByteFlag.uw; | |
631 logbook_writedata((void *) sample,length); | |
632 | |
633 } | |
634 | |
635 /** | |
636 ****************************************************************************** | |
637 * @brief readSample. / Reads data of one logbook sample | |
281 | 638 * @author heinrichs weikamp |
38 | 639 * @version V0.0.1 |
640 * @date 22-April-2014 | |
641 ****************************************************************************** | |
642 * | |
643 * @param int32_t* depth: output Value | |
644 * @param int16_t * gasid: output Value | |
645 * @param int32_t* temperature: output Value | |
646 * @param int32_t* sensor1, sensor2, sensor3: output Value | |
647 * @param int32_t* cns: output Value | |
648 * @return bytes read / 0 = reading Error | |
649 */ | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
650 static uint16_t readSample(int32_t* depth, int16_t * gasid, int16_t* setpoint_cbar, int32_t* temperature, int32_t* sensor1, int32_t* sensor2, int32_t* sensor3, int32_t* cns, SManualGas* manualGas, int16_t* bailout, int16_t* decostopDepth) |
38 | 651 { |
652 int length = 0; | |
653 _Bool bEvent = 0; | |
654 bit8_Type eventByte1, eventByte2; | |
655 bit8_Type profileByteFlag; | |
656 | |
657 eventByte1.uw = 0; | |
658 eventByte2.uw = 0; | |
659 uint8_t tempU8 = 0; | |
660 uint16_t temp = 0; | |
661 uint16_t bytesRead = 0; | |
662 | |
663 if(gasid) | |
664 *gasid = -1; | |
665 if(temperature) | |
666 *temperature = -1000; | |
667 if(sensor1) | |
668 *sensor1 = -1; | |
669 if(sensor2) | |
670 *sensor2 = -1; | |
671 if(sensor3) | |
672 *sensor3 = -1; | |
673 if(cns) | |
674 *cns = -1; | |
675 if(setpoint_cbar) | |
676 *setpoint_cbar = -1; | |
677 if(bailout) | |
678 *bailout = -1; | |
679 if(manualGas) | |
680 { | |
681 manualGas->percentageO2 =-1; | |
682 manualGas->percentageHe =-1; | |
683 } | |
684 if(decostopDepth) | |
685 *decostopDepth = -1; | |
686 | |
687 ext_flash_read_next_sample_part( (uint8_t*)&temp, 2); | |
688 if(depth) | |
689 *depth = (int32_t)temp; | |
690 bytesRead += 2; | |
691 | |
692 ext_flash_read_next_sample_part( &profileByteFlag.uw, 1); | |
693 bytesRead ++; | |
694 | |
695 bEvent = profileByteFlag.ub.bit7; | |
696 profileByteFlag.ub.bit7 = 0; | |
697 length = profileByteFlag.uw; | |
698 | |
699 if(bEvent) | |
700 { | |
701 ext_flash_read_next_sample_part( &eventByte1.uw, 1); | |
702 bytesRead ++; | |
703 | |
704 length--; | |
705 | |
706 //second event byte | |
707 if(eventByte1.ub.bit7) | |
708 { | |
709 ext_flash_read_next_sample_part( &eventByte2.uw, 1); | |
710 bytesRead ++; | |
711 length--; | |
712 } | |
713 else | |
714 { | |
715 eventByte2.uw = 0; | |
716 } | |
717 | |
718 //manual Gas Set | |
719 if( eventByte1.ub.bit4) | |
720 { | |
721 //Evaluate manual Gas | |
722 ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1); | |
723 bytesRead +=1; | |
724 length -= 1; | |
725 manualGas->percentageO2 = tempU8; | |
726 ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1); | |
727 bytesRead +=1; | |
728 length -= 1; | |
729 manualGas->percentageHe = tempU8; | |
730 if(gasid) | |
731 *gasid = 0; | |
732 } | |
733 //gas change | |
734 if( eventByte1.ub.bit5) | |
735 { | |
736 ext_flash_read_next_sample_part( &tempU8, 1); | |
737 bytesRead +=1; | |
738 length -= 1; | |
739 if(gasid) | |
740 *gasid = (uint16_t)tempU8; | |
741 } | |
742 //SetpointChange | |
743 if( eventByte1.ub.bit6) | |
744 { | |
745 ext_flash_read_next_sample_part( &tempU8, 1); | |
746 *setpoint_cbar = tempU8; | |
747 bytesRead +=1; | |
748 length -= 1; | |
749 } | |
750 | |
751 // second event Byte | |
752 //bailout | |
298
50c26a4442af
Bugfix: fix drawing of CCR bailout profile
Jan Mulder <jlmulder@xs4all.nl>
parents:
283
diff
changeset
|
753 if(eventByte2.ub.bit0) |
38 | 754 { |
755 //evaluate bailout gas Gas | |
756 *bailout = 1; | |
757 | |
758 ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1); | |
759 bytesRead +=1; | |
760 length -= 1; | |
761 manualGas->percentageO2 = tempU8; | |
762 ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1); | |
763 bytesRead +=1; | |
764 length -= 1; | |
765 manualGas->percentageHe = tempU8; | |
766 | |
767 if(gasid) | |
768 *gasid = 0; | |
769 } | |
770 } | |
771 | |
772 if(divisor.temperature == 0) | |
773 { | |
774 divisor.temperature = smallHeader.tempDivisor - 1; | |
775 ext_flash_read_next_sample_part( (uint8_t*)&temp, 2); | |
776 bytesRead +=2; | |
777 length -= 2; | |
778 if(temperature) | |
779 { | |
780 *temperature = (int32_t)temp; | |
781 } | |
782 } | |
783 else | |
784 { | |
785 divisor.temperature--; | |
786 } | |
787 | |
788 if(smallHeader.deco_ndlDivisor > 0) | |
789 { | |
790 if(divisor.deco_ndl == 0) | |
791 { | |
792 divisor.deco_ndl = smallHeader.deco_ndlDivisor - 1; | |
793 ext_flash_read_next_sample_part( &tempU8, 1); | |
794 if(decostopDepth) | |
795 { | |
796 *decostopDepth = tempU8 * 100; | |
797 } | |
798 ext_flash_read_next_sample_part( &tempU8, 1); | |
799 bytesRead += 2; | |
800 length -= 2; | |
801 } | |
802 else | |
803 { | |
804 divisor.deco_ndl--; | |
805 } | |
806 } | |
807 | |
808 if(divisor.ppo2 == 0) | |
809 { | |
810 int32_t ppO2Tmp = 0; | |
811 divisor.ppo2 = smallHeader.ppo2Divisor -1; | |
812 for(int i = 0; i <3 ; i++) | |
813 { | |
814 ext_flash_read_next_sample_part( &tempU8, 1); | |
815 ppO2Tmp += tempU8; | |
816 bytesRead +=1; | |
817 length -= 1; | |
818 ext_flash_read_next_sample_part( (uint8_t*)&temp, 2); | |
819 bytesRead +=2; | |
820 length -= 2; | |
821 if(sensor1 && (i==0)) | |
822 *sensor1 = (((int32_t)tempU8) * 0xFFFF) + temp; | |
823 if(sensor2 && (i==1)) | |
824 *sensor2 = (((int32_t)tempU8) * 0xFFFF) + temp; | |
825 if(sensor3 && (i==2)) | |
826 *sensor3 = (((int32_t)tempU8) * 0xFFFF) + temp; | |
827 } | |
828 } | |
829 else | |
830 { | |
831 divisor.ppo2--; | |
832 } | |
833 | |
834 if(smallHeader.decoplanDivisor > 0) | |
835 { | |
836 if(divisor.decoplan == 0) | |
837 { | |
838 divisor.decoplan = smallHeader.decoplanDivisor - 1; | |
839 for(int i = 0; i <15; i++) | |
840 ext_flash_read_next_sample_part( &tempU8, 1); | |
841 bytesRead += 15; | |
842 length -= 15; | |
843 } | |
844 else | |
845 { | |
846 divisor.decoplan--; | |
847 } | |
848 } | |
849 | |
850 | |
851 | |
852 if(divisor.cns == 0) | |
853 { | |
854 divisor.cns = smallHeader.cnsDivisor - 1; | |
855 | |
856 ext_flash_read_next_sample_part( (uint8_t*)&temp, 2); | |
857 bytesRead +=2; | |
858 length -= 2; | |
859 if(cns) | |
860 { | |
861 *cns = (int32_t)temp; | |
862 } | |
863 } | |
864 else | |
865 { | |
866 divisor.cns--; | |
867 } | |
868 | |
869 if (length != 0) | |
870 return 0; | |
871 | |
872 return bytesRead; | |
873 } | |
874 /** | |
875 ****************************************************************************** | |
876 * @brief logbook_readSampleData. / Reads sample data of whole logbook entry | |
281 | 877 * @author heinrichs weikamp |
38 | 878 * @version V0.0.1 |
879 * @date 22-April-2014 | |
880 ****************************************************************************** | |
881 * | |
882 * @param uint8_t StepBackwards: witch lookbook entry? | |
883 * @param uint16_t length : maxlength of output arrays | |
884 * @param int32_t* depth : output array | |
885 * @param int16_t * gasid : output array | |
886 * @param int32_t* temperature : output array | |
887 * @param int32_t* ppo2 : output array | |
888 * @param int32_t* cns : output array | |
889 * @return length of output | |
890 */ | |
891 uint16_t logbook_readSampleData(uint8_t StepBackwards, uint16_t length,uint16_t* depth, uint8_t* gasid, int16_t* temperature, uint16_t* ppo2, uint16_t* setpoint, uint16_t* sensor1, uint16_t* sensor2, uint16_t* sensor3, uint16_t* cns, uint8_t* bailout, uint16_t* decostopDepth) | |
892 { | |
893 //Test read | |
894 //SLogbookHeader header; | |
895 | |
896 //logbook_getHeader(&header); | |
897 SLogbookHeader header; | |
898 int iNum; | |
899 int firstgasid = 0; | |
900 int retVal = 0; | |
901 int compression = 0; | |
902 int i; | |
903 // uint32_t diveTime_seconds; | |
904 int32_t depthVal = 0; | |
905 int16_t gasidVal = 0; | |
906 int16_t setPointVal = 0; | |
907 int16_t bailoutVal = 0; | |
908 int16_t bailoutLast = 0; | |
909 uint16_t setPointLast = 0; | |
910 int32_t temperatureVal = 0; | |
911 int32_t sensor1Val = 0; | |
912 int32_t sensor2Val = 0; | |
913 int32_t sensor3Val = 0; | |
914 int32_t sensor1Last = 0; | |
915 int32_t sensor2Last = 0; | |
916 int32_t sensor3Last = 0; | |
917 int32_t cnsVal = 0; | |
918 int32_t depthLast = 0; | |
919 int16_t gasidLast = 0; | |
920 int32_t temperatureLast = 0; | |
921 int32_t temperatureFirst = 0; | |
922 int32_t cnsLast = 0; | |
923 int16_t decostepDepthVal = 0; | |
924 int16_t decostepDepthLast = 0; | |
925 | |
926 SManualGas manualGasVal; | |
927 SManualGas manualGasLast; | |
928 manualGasLast.percentageO2 = 0; | |
929 manualGasLast.percentageHe = 0; | |
930 | |
931 float ambiant_pressure_bar = 0; | |
932 float ppO2 = 0; | |
933 ext_flash_read_dive_header((uint8_t*)&header, StepBackwards); | |
934 for(i = 0;i< 5;i++) | |
935 { | |
936 if(header.gasordil[i].note.ub.first) | |
937 break; | |
938 } | |
939 firstgasid = i + 1; | |
940 if(header.diveMode == DIVEMODE_CCR) | |
941 setPointLast = header.setpoint[0].setpoint_cbar; | |
942 else | |
943 setPointLast = 0; | |
944 //diveTime_seconds = header.diveTime_seconds ; | |
945 for(compression = 1; compression < 100; compression ++) | |
946 { | |
947 if((header.total_diveTime_seconds / header.samplingRate)/compression <= length) | |
948 break; | |
949 } | |
950 | |
951 | |
952 for(i = 0;i< length;i++) | |
953 { | |
954 if(depth) | |
955 depth[i] = 0; | |
956 if(temperature) | |
957 temperature[i] = 0; | |
958 if(gasid) | |
959 gasid[i] = 0; | |
960 if(ppo2) | |
961 ppo2[i] = 0; | |
962 if(setpoint) | |
963 setpoint[i] = 0; | |
964 if(sensor1) | |
965 sensor1[i] = 0; | |
966 if(sensor2) | |
967 sensor2[i] = 0; | |
968 if(sensor3) | |
969 sensor3[i] = 0; | |
970 if(cns) | |
971 cns[i] = 0; | |
972 } | |
973 //We start with fist gasid | |
974 gasidLast = firstgasid; | |
975 | |
976 | |
977 //uint16_t* ppo2, uint16_t* cns# | |
978 uint32_t totalNumberOfBytes = 0; | |
979 uint32_t bytesRead = 0; | |
980 ext_flash_open_read_sample( StepBackwards,&totalNumberOfBytes); | |
981 ext_flash_read_next_sample_part((uint8_t*)&smallHeader, sizeof(SSmallHeader)); | |
982 bytesRead += sizeof(SSmallHeader); | |
983 | |
984 clear_divisor(); | |
985 | |
986 iNum = 0; | |
987 int counter = 0; | |
988 temperatureLast = -1000; | |
989 while ((bytesRead < totalNumberOfBytes) && (iNum < length)) | |
990 { | |
991 ext_flash_set_entry_point(); | |
992 divisorBackup = divisor; | |
993 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, &decostepDepthVal); | |
994 | |
995 if(retVal == 0) | |
996 { | |
997 //Error try to read again!!! | |
998 ext_flash_reopen_read_sample_at_entry_point(); | |
999 divisor = divisorBackup; | |
1000 retVal = readSample(&depthVal,&gasidVal,&setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, &decostepDepthVal); | |
1001 | |
1002 if(retVal == 0) | |
1003 break; | |
1004 } | |
1005 bytesRead +=retVal; | |
1006 | |
1007 //if for some variable no new value is in the sample for (z.B. gasidVal = -1), we take the last value | |
1008 if(depthVal == -1) | |
1009 depthVal = depthLast; | |
1010 else | |
1011 depthLast = depthVal; | |
1012 | |
1013 if(gasidVal == -1) | |
1014 gasidVal = gasidLast; | |
1015 else | |
1016 gasidLast = gasidVal; | |
1017 | |
1018 if(temperatureVal == -1000) | |
1019 temperatureVal = temperatureLast; | |
1020 else | |
1021 { | |
1022 if(temperatureLast == -1000) | |
1023 temperatureFirst = temperatureVal; | |
1024 temperatureLast = temperatureVal; | |
1025 } | |
1026 | |
1027 if(setPointVal == -1) | |
1028 setPointVal = setPointLast; | |
1029 else | |
1030 setPointLast = setPointVal; | |
1031 | |
1032 if(sensor1Val == -1) | |
1033 sensor1Val = sensor1Last; | |
1034 else | |
1035 sensor1Last = sensor1Val; | |
1036 | |
1037 if(sensor2Val == -1) | |
1038 sensor2Val = sensor2Last; | |
1039 else | |
1040 sensor2Last = sensor2Val; | |
1041 | |
1042 if(sensor3Val == -1) | |
1043 sensor3Val = sensor3Last; | |
1044 else | |
1045 sensor3Last = sensor3Val; | |
1046 | |
1047 if(cnsVal == -1) | |
1048 cnsVal = cnsLast; | |
1049 else | |
1050 cnsLast = cnsVal; | |
1051 | |
1052 if(manualGasVal.percentageO2 == -1) | |
1053 manualGasVal = manualGasLast; | |
1054 else | |
1055 manualGasLast = manualGasVal; | |
1056 | |
1057 if(bailoutVal == -1) | |
1058 bailoutVal = bailoutLast; | |
1059 else | |
1060 bailoutLast = bailoutVal; | |
1061 | |
1062 if(decostepDepthVal == -1) | |
1063 decostepDepthVal = decostepDepthLast; | |
1064 else | |
1065 decostepDepthLast = decostepDepthVal; | |
1066 | |
1067 counter++; | |
1068 // Heed compression | |
1069 // Write here to arrays | |
1070 if(counter == compression) | |
1071 { | |
1072 if(depth) | |
1073 depth[iNum] = depthVal; | |
1074 if(gasid) | |
1075 gasid[iNum] = gasidVal; | |
1076 if(temperature) | |
1077 temperature[iNum] = temperatureVal; | |
1078 if(cns) | |
1079 cns[iNum] = cnsVal; | |
1080 if(bailout) | |
1081 bailout[iNum] = bailoutVal; | |
1082 if(decostopDepth) | |
1083 decostopDepth[iNum] = decostepDepthVal; | |
1084 | |
1085 if(ppo2) | |
1086 { | |
1087 //Calc ppo2 - Values | |
1088 SGas gas; | |
1089 gas.setPoint_cbar = setPointVal; | |
1090 if(gasidVal > 0) | |
1091 { | |
1092 gas.helium_percentage = header.gasordil[gasidVal - 1].helium_percentage; | |
1093 gas.nitrogen_percentage = 100 - gas.helium_percentage - header.gasordil[gasidVal - 1].oxygen_percentage; | |
1094 } | |
1095 else | |
1096 { | |
1097 gas.helium_percentage = manualGasVal.percentageHe; | |
1098 gas.nitrogen_percentage = 100 - gas.helium_percentage - manualGasVal.percentageO2; | |
1099 } | |
1100 ambiant_pressure_bar =((float)(depthVal + header.surfacePressure_mbar))/1000; | |
1101 ppO2 = decom_calc_ppO2(ambiant_pressure_bar, &gas ); | |
1102 ppo2[iNum] = (uint16_t) ( ppO2 * 100); | |
1103 } | |
1104 | |
1105 if(setpoint) | |
1106 setpoint[iNum] = setPointVal; | |
1107 | |
1108 if(sensor1) | |
1109 sensor1[iNum] = (sensor1Val / 0xFFFF) & 0xFF; | |
1110 if(sensor2) | |
1111 sensor2[iNum] = (sensor2Val / 0xFFFF) & 0xFF; | |
1112 if(sensor3) | |
1113 sensor3[iNum] = (sensor3Val / 0xFFFF) & 0xFF; | |
1114 iNum++; | |
1115 counter = 0; | |
1116 } | |
1117 } | |
1118 | |
1119 // Fix first Temperature Entries 150930 hw | |
1120 if(temperature) | |
1121 { | |
1122 int i = 0; | |
1123 while((temperature[i] == -1000) && (i < iNum)) | |
1124 temperature[i++] = temperatureFirst; | |
1125 } | |
1126 | |
1127 ext_flash_close_read_sample(); | |
1128 return iNum; | |
1129 } | |
1130 | |
1131 | |
1132 /******************************************************************************** | |
1133 * @brief logbook_InitAndWrite. / Controls writing of logbook | |
1134 * Should be called ten times per second | |
1135 * Automatically Initializes logbook at beginning of dive, | |
1136 * write samples every 2 seconds | |
1137 * and finishes logbook after end of dive | |
1138 *********************************************************************************/ | |
1139 | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1140 void logbook_InitAndWrite(const SDiveState *pStateReal) |
38 | 1141 { |
1142 SSettings *pSettings = settingsGetPointer(); | |
1143 static uint8_t bDiveMode = 0; | |
1144 static uint32_t tickstart = 0; | |
1145 uint32_t ticksdiff = 0; | |
1146 uint32_t lasttick = 0; | |
1147 static float min_temperature_float_celsius = 0; | |
1148 | |
1149 if(!bDiveMode) | |
1150 { | |
1151 if((pStateReal->mode == MODE_DIVE) && (pStateReal->diveSettings.diveMode != DIVEMODE_Apnea) && (pStateReal->lifeData.dive_time_seconds >= 5)) | |
1152 { | |
1153 //InitdiveProfile | |
1154 pSettings->totalDiveCounter++; | |
1155 logbook_initNewdiveProfile(pStateReal,settingsGetPointer()); | |
1156 min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius; | |
1157 //Write logbook sample | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1158 logbook_writeSample(pStateReal); |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1159 resetEvents(pStateReal); |
38 | 1160 tickstart = HAL_GetTick(); |
1161 bDiveMode = 1; | |
1162 } | |
1163 } | |
1164 else if((pStateReal->mode == MODE_DIVE) && (pStateReal->diveSettings.diveMode != DIVEMODE_Apnea)) | |
1165 { | |
1166 lasttick = HAL_GetTick(); | |
1167 ticksdiff = time_elapsed_ms(tickstart,lasttick); | |
1168 // | |
1169 if(ticksdiff >= 2000) | |
1170 { | |
1171 //Write logbook sample | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1172 logbook_writeSample(pStateReal); |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1173 resetEvents(pStateReal); |
38 | 1174 if(min_temperature_float_celsius > pStateReal->lifeData.temperature_celsius) |
1175 min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius; | |
1176 tickstart = lasttick; | |
1177 if((bDiveMode == 1) && (pStateReal->lifeData.dive_time_seconds >= pSettings->divetimeToCreateLogbook)) | |
1178 { | |
1179 ext_flash_create_new_dive_log((uint8_t*)&header); | |
1180 /** save settings | |
1181 * with new lastDiveLogId and time and day | |
1182 */ | |
1183 pSettings->personalDiveCount++; | |
1184 if(pSettings->logbookOffset) | |
1185 { | |
1186 pSettings->logbookOffset++; | |
1187 } | |
1188 ext_flash_write_settings(); | |
1189 ext_flash_disable_protection_for_logbook(); | |
1190 bDiveMode = 3; | |
1191 } | |
1192 if(bDiveMode == 3) | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1193 logbook_UpdateHeader(pStateReal); |
38 | 1194 } |
1195 } | |
1196 else if(bDiveMode == 3) | |
1197 { | |
1198 //End of Dive | |
1199 logbook_SetAverageDepth(pStateReal->lifeData.average_depth_meter); | |
1200 logbook_SetMinTemperature(min_temperature_float_celsius); | |
1201 logbook_SetMaxCNS(pStateReal->lifeData.cns); | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1202 logbook_SetCompartmentDesaturation(pStateReal); |
38 | 1203 logbook_SetLastStop(pStateReal->diveSettings.last_stop_depth_bar); |
325
8e62f4701676
bugfix: implement battery at end in dive header
Jan Mulder <jlmulder@xs4all.nl>
parents:
298
diff
changeset
|
1204 header.batteryVoltage = pStateReal->lifeData.battery_voltage * 1000; |
38 | 1205 logbook_EndDive(); |
1206 bDiveMode = 0; | |
1207 } else | |
1208 { | |
1209 ext_flash_enable_protection(); | |
1210 } | |
1211 } | |
1212 | |
1213 | |
1214 /* Private functions ---------------------------------------------------------*/ | |
1215 | |
1216 /******************************************************************************** | |
1217 * @brief logbook_UpdateHeader. / | |
1218 * set date, time, max depth. etc. pp. | |
1219 * the internal pointer to the end of profile and length will be set by | |
1220 ext_flash_close_new_dive_log() in externLogbookFlash.c | |
1221 * @author heinrichs weikamp gmbh | |
1222 * @version V0.0.1 | |
1223 * @date 27-Nov-2014 | |
1224 *********************************************************************************/ | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1225 static void logbook_UpdateHeader(const SDiveState *pStateReal) |
38 | 1226 { |
1227 // uint16_t secondsAtShallow = 0; | |
1228 RTC_DateTypeDef Sdate; | |
1229 RTC_TimeTypeDef Stime; | |
1230 uint32_t time1_u32, time2_u32; | |
1231 uint32_t divetimeHelper; | |
1232 | |
1233 /* time and day */ | |
1234 /* don't update CHANGE 160224 hw, maybe save actual time and date at other place | |
1235 translateDate(pStateReal->lifeData.dateBinaryFormat, &Sdate); | |
1236 translateTime(pStateReal->lifeData.timeBinaryFormat, &Stime); | |
1237 | |
1238 header.dateYear = Sdate.Year; | |
1239 header.dateMonth = Sdate.Month; | |
1240 header.dateDay = Sdate.Date; | |
1241 header.timeHour = Stime.Hours; | |
1242 header.timeMinute = Stime.Minutes; | |
1243 */ | |
1244 /// 160315 Quick fix for empty date problem | |
1245 if((!(header.dateYear)) || (!(header.dateMonth)) || (!(header.dateDay))) | |
1246 { | |
1247 translateDate(pStateReal->lifeData.dateBinaryFormat, &Sdate); | |
1248 translateTime(pStateReal->lifeData.timeBinaryFormat, &Stime); | |
1249 | |
1250 header.dateYear = Sdate.Year; | |
1251 header.dateMonth = Sdate.Month; | |
1252 header.dateDay = Sdate.Date; | |
1253 | |
1254 time1_u32 = (uint32_t)header.timeMinute + (uint32_t)(header.timeHour * 60); | |
1255 time2_u32 = (uint32_t)Stime.Minutes + (uint32_t)(Stime.Hours * 60); | |
1256 if(time2_u32 < time1_u32) | |
1257 { | |
1258 if(header.dateDay > 1) | |
1259 { | |
1260 header.dateDay -= 1; | |
1261 } | |
1262 else | |
1263 { | |
1264 header.dateMonth --; | |
1265 if(!header.dateMonth) | |
1266 { | |
1267 header.dateYear--; | |
1268 header.dateMonth = 12; | |
1269 header.dateDay = 31; | |
1270 } | |
1271 else | |
1272 { | |
1273 if(header.dateMonth == 2) | |
1274 header.dateDay = 28; | |
1275 else | |
1276 if((header.dateMonth == 4) || (header.dateMonth == 6) || (header.dateMonth == 9) || (header.dateMonth == 11)) | |
1277 header.dateDay = 30; | |
1278 else | |
1279 header.dateDay = 31; | |
1280 } | |
1281 } | |
1282 } | |
1283 } | |
1284 | |
1285 /* duration */ | |
1286 header.total_diveTime_seconds = pStateReal->lifeData.dive_time_seconds; | |
1287 header.maxDepth = pStateReal->lifeData.max_depth_meter * 100; | |
1288 | |
1289 /* old: | |
1290 | |
1291 secondsAtShallow = pSettings->timeoutDiveReachedZeroDepth; | |
1292 if(pStateReal->lifeData.dive_time_seconds <= secondsAtShallow) | |
1293 secondsAtShallow = 0; | |
1294 header.diveTimeMinutes = (header.total_diveTime_seconds - secondsAtShallow )/ 60; | |
1295 header.diveTimeSeconds = header.total_diveTime_seconds - secondsAtShallow - (header.diveTimeMinutes * 60); | |
1296 */ | |
1297 divetimeHelper = pStateReal->lifeData.dive_time_seconds_without_surface_time; | |
1298 header.diveTimeMinutes = (uint16_t)(divetimeHelper/60); | |
1299 divetimeHelper -= 60 * (uint32_t)header.diveTimeMinutes; | |
1300 header.diveTimeSeconds = (uint16_t)divetimeHelper; | |
1301 | |
1302 /* deco algorithm (final) */ | |
1303 if(pStateReal->diveSettings.deco_type.ub.standard == GF_MODE) | |
1304 { | |
1305 header.decoModel = 1; | |
1306 header.gfLow_or_Vpm_conservatism = pStateReal->diveSettings.gf_low; | |
1307 header.gfHigh = pStateReal->diveSettings.gf_high; | |
1308 } | |
1309 else | |
1310 { | |
1311 header.decoModel = 2; | |
1312 header.gfLow_or_Vpm_conservatism = pStateReal->diveSettings.vpm_conservatism; | |
1313 header.gfHigh = 0; | |
1314 } | |
1315 | |
1316 /* tissue load */ | |
1317 memcpy(header.n2Compartments, pStateReal->lifeData.tissue_nitrogen_bar, 64); | |
1318 memcpy(header.heCompartments, pStateReal->lifeData.tissue_helium_bar, 64); | |
1319 | |
1320 } | |
1321 | |
1322 | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
1323 static void logbook_SetAverageDepth(float average_depth_meter) |
38 | 1324 { |
1325 header.averageDepth_mbar = (uint16_t)(average_depth_meter * 100); | |
1326 } | |
1327 | |
1328 | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
1329 static void logbook_SetMinTemperature(float min_temperature_celsius) |
38 | 1330 { |
1331 header.minTemp = (int16_t)((min_temperature_celsius * 10.0f) + 0.5f); | |
1332 } | |
1333 | |
1334 | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
1335 static void logbook_SetMaxCNS(float max_cns_percentage) |
38 | 1336 { |
1337 if(max_cns_percentage < 9999) | |
1338 header.maxCNS = (uint16_t)(max_cns_percentage); | |
1339 else | |
1340 header.maxCNS = 9999; | |
1341 } | |
1342 | |
1343 | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1344 static void logbook_SetCompartmentDesaturation(const SDiveState * pStateReal) |
38 | 1345 { |
225
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
199
diff
changeset
|
1346 SLifeData2 secondaryInformation = { 0 }; |
38 | 1347 |
1348 decom_tissues_desaturation_time(&pStateReal->lifeData, &secondaryInformation); | |
1349 for(int i=0;i<16;i++) | |
1350 { | |
1351 if(secondaryInformation.tissue_nitrogen_desaturation_time_minutes[i] <= (15 * 255)) | |
1352 header.n2CompartDesatTime_min[i] = (uint8_t)((secondaryInformation.tissue_nitrogen_desaturation_time_minutes[i] + 14) / 15); | |
1353 else | |
1354 header.n2CompartDesatTime_min[i] = 255; | |
1355 if(secondaryInformation.tissue_helium_desaturation_time_minutes[i] <= (15 * 255)) | |
1356 header.heCompartDesatTime_min[i] = (uint8_t)((secondaryInformation.tissue_helium_desaturation_time_minutes[i] + 14 )/ 15); | |
1357 else | |
1358 header.heCompartDesatTime_min[i] = 255; | |
1359 } | |
1360 } | |
1361 | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
1362 static void logbook_SetLastStop(float last_stop_depth_bar) |
38 | 1363 { |
1364 header.lastDecostop_m = (uint8_t)(last_stop_depth_bar / 10.0f); | |
1365 } | |
1366 | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
1367 static void logbook_writedata(void * data, int length_byte) |
38 | 1368 { |
1369 ext_flash_write_sample(data, length_byte); | |
1370 } | |
1371 | |
1372 | |
1373 /******************************************************************************** | |
1374 * @brief logbook_build_ostc3header. / | |
1375 * @author heinrichs weikamp gmbh | |
1376 * @version V0.0.2 | |
1377 * @date 27-Nov-2014 | |
1378 *********************************************************************************/ | |
1379 SLogbookHeaderOSTC3 * logbook_build_ostc3header(SLogbookHeader* pHead) | |
1380 { | |
1381 convert_Type data; | |
1382 | |
1383 memcpy(headerOSTC3.diveHeaderStart, &pHead->diveHeaderStart, 2); | |
1384 memcpy(headerOSTC3.pBeginProfileData, &pHead->pBeginProfileData, 3); | |
1385 memcpy(headerOSTC3.pEndProfileData, &pHead->pEndProfileData, 3); | |
1386 | |
1387 data.u8bit.byteHigh = 0; | |
1388 data.u8bit.byteLow = pHead->profileLength[0]; | |
1389 data.u8bit.byteMidLow = pHead->profileLength[1]; | |
1390 data.u8bit.byteMidHigh = pHead->profileLength[2]; | |
1391 | |
1392 if(data.u32bit != 0xFFFFFF) | |
1393 data.u32bit += 3; | |
1394 | |
1395 headerOSTC3.profileLength[0] = data.u8bit.byteLow; | |
1396 headerOSTC3.profileLength[1] = data.u8bit.byteMidLow; | |
1397 headerOSTC3.profileLength[2] = data.u8bit.byteMidHigh; | |
1398 | |
1399 memcpy(headerOSTC3.gasordil, pHead->gasordil, 20); | |
1400 | |
1401 if(pHead->logbookProfileVersion == LOGBOOK_VERSION) | |
1402 { | |
1403 headerOSTC3.logbookProfileVersion = LOGBOOK_VERSION_OSTC3; | |
1404 memcpy(headerOSTC3.personalDiveCount, &pHead->personalDiveCount, 2); | |
1405 headerOSTC3.safetyDistance_10cm = 0; | |
1406 | |
1407 for(int i=0;i<5;i++) | |
1408 { | |
1409 if(!pHead->gasordil[i].note.ub.active) | |
1410 headerOSTC3.gasordil[3 + (i*4)] = 0; | |
1411 else if(pHead->gasordil[i].note.ub.first) | |
1412 { | |
1413 /* depth = 0, note = 1 */ | |
1414 headerOSTC3.gasordil[2 + (i*4)] = 0; | |
1415 headerOSTC3.gasordil[3 + (i*4)] = 1; | |
1416 } | |
1417 else if( pHead->gasordil[i].depth_meter) | |
1418 { | |
1419 /* note = 3 */ | |
1420 headerOSTC3.gasordil[3 + (i*4)] = 3; | |
1421 } | |
1422 } | |
1423 } | |
1424 else | |
1425 { | |
1426 headerOSTC3.logbookProfileVersion = 0xFF; | |
1427 headerOSTC3.personalDiveCount[0] = 0xFF; | |
1428 headerOSTC3.personalDiveCount[1] = 0xFF; | |
1429 headerOSTC3.safetyDistance_10cm = 0xFF; | |
1430 } | |
1431 | |
1432 headerOSTC3.dateYear = pHead->dateYear; | |
1433 headerOSTC3.dateMonth = pHead->dateMonth; | |
1434 headerOSTC3.dateDay = pHead->dateDay; | |
1435 headerOSTC3.timeHour = pHead->timeHour; | |
1436 headerOSTC3.timeMinute = pHead->timeMinute; | |
1437 | |
1438 | |
1439 memcpy(headerOSTC3.maxDepth, &pHead->maxDepth, 2); | |
1440 memcpy(headerOSTC3.diveTimeMinutes, &pHead->diveTimeMinutes, 2); | |
1441 | |
1442 headerOSTC3.diveTimeSeconds = pHead->diveTimeSeconds; | |
1443 | |
1444 memcpy(headerOSTC3.minTemp, &pHead->minTemp, 2); | |
1445 memcpy(headerOSTC3.surfacePressure_mbar,&pHead->surfacePressure_mbar, 2); | |
1446 memcpy(headerOSTC3.desaturationTime, &pHead->desaturationTime, 2); | |
1447 | |
1448 headerOSTC3.firmwareVersionHigh = pHead->firmwareVersionHigh; | |
1449 headerOSTC3.firmwareVersionLow = pHead->firmwareVersionLow; | |
1450 | |
1451 memcpy(headerOSTC3.batteryVoltage, &pHead->batteryVoltage, 2); | |
1452 | |
1453 headerOSTC3.samplingRate = pHead->samplingRate; | |
1454 | |
1455 memcpy(headerOSTC3.cnsAtBeginning, &pHead->cnsAtBeginning, 2); | |
1456 | |
1457 headerOSTC3.gfAtBeginning = pHead->gfAtBeginning; | |
1458 headerOSTC3.gfAtEnd = pHead->gfAtEnd; | |
1459 | |
1460 memcpy(headerOSTC3.setpoint, pHead->setpoint, 10); | |
1461 | |
1462 headerOSTC3.salinity = pHead->salinity; | |
1463 | |
1464 memcpy(headerOSTC3.maxCNS, &pHead->maxCNS, 2); | |
1465 memcpy(headerOSTC3.averageDepth_mbar, &pHead->averageDepth_mbar, 2); | |
1466 memcpy(headerOSTC3.total_diveTime_seconds,&pHead->total_diveTime_seconds, 2); | |
1467 | |
1468 headerOSTC3.gfLow_or_Vpm_conservatism = pHead->gfLow_or_Vpm_conservatism; | |
1469 headerOSTC3.gfHigh = pHead->gfHigh; | |
1470 headerOSTC3.decoModel = pHead->decoModel; | |
1471 | |
1472 memcpy(headerOSTC3.diveNumber, &pHead->diveNumber, 2); | |
1473 | |
1474 headerOSTC3.diveMode = pHead->diveMode; | |
1475 headerOSTC3.CCRmode = pHead->CCRmode; | |
1476 | |
1477 memcpy(headerOSTC3.n2CompartDesatTime_min,pHead->n2CompartDesatTime_min, 16); | |
1478 memcpy(headerOSTC3.n2Compartments, pHead->n2Compartments, 64); | |
1479 memcpy(headerOSTC3.heCompartDesatTime_min,pHead->heCompartDesatTime_min, 16); | |
1480 memcpy(headerOSTC3.heCompartments, pHead->heCompartments, 64); | |
1481 | |
1482 headerOSTC3.lastDecostop_m = pHead->lastDecostop_m; | |
1483 | |
1484 memcpy(headerOSTC3.hwHudBattery_mV, &pHead->hwHudBattery_mV, 2); | |
1485 | |
1486 headerOSTC3.hwHudLastStatus = pHead->hwHudLastStatus; | |
1487 | |
1488 memcpy(headerOSTC3.batteryGaugeRegisters,&pHead->batteryGaugeRegisters, 6); | |
1489 | |
1490 | |
1491 memcpy(headerOSTC3.diveHeaderEnd, &pHead->diveHeaderEnd, 2); | |
1492 | |
1493 return &headerOSTC3; | |
1494 } | |
1495 | |
1496 | |
1497 /******************************************************************************** | |
1498 * @brief logbook_build_ostc3header_compact. / | |
1499 * @author heinrichs weikamp gmbh | |
1500 * @version V0.0.1 | |
1501 * @date 31-Juli-2015 | |
1502 *********************************************************************************/ | |
1503 SLogbookHeaderOSTC3compact * logbook_build_ostc3header_compact(SLogbookHeader* pHead) | |
1504 { | |
1505 convert_Type data; | |
1506 | |
1507 data.u8bit.byteHigh = 0; | |
1508 data.u8bit.byteLow = pHead->profileLength[0]; | |
1509 data.u8bit.byteMidLow = pHead->profileLength[1]; | |
1510 data.u8bit.byteMidHigh = pHead->profileLength[2]; | |
1511 | |
1512 if(data.u32bit != 0xFFFFFF) | |
1513 { | |
1514 data.u32bit += 3; | |
1515 | |
1516 headerOSTC3compact.profileLength[0] = data.u8bit.byteLow; | |
1517 headerOSTC3compact.profileLength[1] = data.u8bit.byteMidLow; | |
1518 headerOSTC3compact.profileLength[2] = data.u8bit.byteMidHigh; | |
1519 | |
1520 headerOSTC3compact.dateYear = pHead->dateYear; | |
1521 headerOSTC3compact.dateMonth = pHead->dateMonth; | |
1522 headerOSTC3compact.dateDay = pHead->dateDay; | |
1523 headerOSTC3compact.timeHour = pHead->timeHour; | |
1524 headerOSTC3compact.timeMinute = pHead->timeMinute; | |
1525 | |
1526 memcpy(headerOSTC3compact.maxDepth, &pHead->maxDepth, 2); | |
1527 memcpy(headerOSTC3compact.diveTimeMinutes, &pHead->diveTimeMinutes, 2); | |
1528 | |
1529 headerOSTC3compact.diveTimeSeconds = pHead->diveTimeSeconds; | |
1530 | |
1531 | |
1532 headerOSTC3compact.totalDiveNumberLow = pHead->diveNumber & 0xFF; | |
1533 headerOSTC3compact.totalDiveNumberHigh = (uint8_t)(pHead->diveNumber/256); | |
1534 headerOSTC3compact.profileVersion = 0x24; // Logbook-Profile version, 0x24 = date and time is start not end | |
1535 } | |
1536 else | |
1537 { | |
1538 memset(&headerOSTC3compact, 0xFF, sizeof(SLogbookHeaderOSTC3compact)); | |
1539 } | |
1540 return &headerOSTC3compact; | |
1541 } | |
1542 | |
1543 | |
1544 /** | |
1545 ****************************************************************************** | |
1546 * @brief logbook_readSampleData. / Reads sample data of whole logbook entry | |
281 | 1547 * @author heinrichs weikamp |
38 | 1548 * @version V0.0.1 |
1549 * @date 22-April-2014 | |
1550 ****************************************************************************** | |
1551 * | |
1552 * @param uint8_t StepBackwards: witch lookbook entry? | |
1553 * @param uint16_t length : maxlength of output arrays | |
1554 * @param int32_t* depth : output array | |
1555 * @param int16_t * gasid : output array | |
1556 * @param int32_t* temperature : output array | |
1557 * @param int32_t* ppo2 : output array | |
1558 * @param int32_t* cns : output array | |
1559 * @return length of output | |
1560 */ | |
1561 void logbook_recover_brokenlog(uint8_t headerId) | |
1562 { | |
1563 int16_t retVal; | |
1564 int32_t depthVal = 0; | |
1565 int16_t gasidVal = 0; | |
1566 int16_t setPointVal = 0; | |
1567 int16_t bailoutVal = 0; | |
1568 int32_t temperatureVal = 0; | |
1569 int32_t sensor1Val = 0; | |
1570 int32_t sensor2Val = 0; | |
1571 int32_t sensor3Val = 0; | |
1572 int32_t cnsVal = 0; | |
1573 SManualGas manualGasVal; | |
1574 | |
1575 //uint16_t* ppo2, uint16_t* cns# | |
1576 uint32_t bytesRead = 0; | |
1577 | |
1578 ext_flash_read_block_start(); | |
1579 ext_flash_read_next_sample_part((uint8_t*)&smallHeader, sizeof(SSmallHeader)); | |
1580 bytesRead += sizeof(SSmallHeader); | |
1581 | |
1582 clear_divisor(); | |
1583 | |
1584 | |
1585 int sampleCounter = 0; | |
1586 int maxdepth = 0; | |
1587 uint32_t avrdepth = 0; | |
1588 while (true) | |
1589 { | |
1590 | |
1591 ext_flash_set_entry_point(); | |
1592 divisorBackup = divisor; | |
1593 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL); | |
1594 if(retVal == 0) | |
1595 { | |
1596 //Error try to read again!!! | |
1597 ext_flash_reopen_read_sample_at_entry_point(); | |
1598 divisor = divisorBackup; | |
1599 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL); | |
1600 | |
1601 if(retVal == 0) | |
1602 { | |
1603 //Error try to read again!!! | |
1604 ext_flash_reopen_read_sample_at_entry_point(); | |
1605 divisor = divisorBackup; | |
1606 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL); | |
1607 | |
1608 if(retVal == 0) | |
1609 { | |
1610 ext_flash_reopen_read_sample_at_entry_point(); | |
1611 break; | |
1612 } | |
1613 | |
1614 } | |
1615 } | |
1616 if(depthVal > maxdepth) | |
1617 maxdepth = depthVal; | |
1618 avrdepth += depthVal; | |
1619 sampleCounter++; | |
1620 bytesRead +=retVal; | |
1621 } | |
1622 avrdepth/= sampleCounter; | |
1623 ext_flash_close_read_sample(); | |
1624 SLogbookHeader header; | |
1625 | |
1626 ext_flash_read_dive_header2((uint8_t*) &header, headerId, false); | |
1627 header.total_diveTime_seconds = sampleCounter * header.samplingRate; | |
1628 header.diveTimeMinutes = header.total_diveTime_seconds /60; | |
1629 header.diveTimeSeconds = header.total_diveTime_seconds - header.diveTimeMinutes * 60; | |
1630 header.maxDepth = maxdepth; | |
1631 header.averageDepth_mbar = avrdepth; | |
1632 SSettings * settings = settingsGetPointer(); | |
1633 settings->lastDiveLogId = headerId; | |
1634 ext_flash_close_new_dive_log((uint8_t *)&header); | |
1635 } | |
1636 | |
1637 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |