Mercurial > public > ostc4
annotate Discovery/Src/logbook.c @ 271:1303747b5ba2 write-from-sim
cleanup: also write gas and setpoint changes in simulator mode
This is related to the previous commit. There is all kinds of logic around
that distinguishes real diving mode and simulator mode. This is valid in certain
cases. For example, we do not want a simulator session to act as a repetitive dive
for subsequent real dives.
What is simply wrong, is skipping relevant logic, like gas switches to act
differently in the simulator and in a real dive. The main advantage of this
commit is code simplicity. Normal users will never see the difference, as
simulator dives are not logged (unless compiled in by a developer).
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Sat, 27 Apr 2019 09:32:16 +0200 |
parents | 2e58a4094770 |
children | 54d14bc2083c |
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. / | |
130 * @author Peter Ryser | |
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. / | |
161 * @author Peter Ryser | |
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 | |
185 * @author Peter Ryser | |
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 | |
320 * @author Peter Ryser | |
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 | |
341 * @author Peter Ryser | |
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 | |
362 * @author Peter Ryser | |
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 | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
429 if(state->events.manuelGasSet) |
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 | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
459 if(state->events.manuelGasSet) |
38 | 460 { |
461 //manual gas in %O2 & %He | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
462 sample[length] = state->events.info_manuelGasSetO2; |
38 | 463 length += 1; |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
464 sample[length] = state->events.info_manuelGasSetHe; |
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; | |
523 sample[length] = (uint8_t)pDecoinfo->output_ndl_seconds / 60; | |
524 length += 1; | |
525 } | |
526 else if(pDecoinfo->output_time_to_surface_seconds) | |
527 { | |
528 tHome_findNextStop(pDecoinfo->output_stop_length_seconds, &nextstopDepthMeter, &nextstopLengthSeconds); | |
529 nextstopLengthMinutes = (nextstopLengthSeconds +59 ) / 60; | |
530 | |
531 sample[length] = nextstopDepthMeter; | |
532 length += 1; | |
533 sample[length] = nextstopLengthMinutes; | |
534 length += 1; | |
535 } | |
536 else | |
537 { | |
538 sample[length] = 0; | |
539 length += 1; | |
540 sample[length] = 0; | |
541 length += 1; | |
542 } | |
543 } | |
544 else | |
545 { | |
546 divisor.deco_ndl --; | |
547 } | |
548 } | |
549 | |
550 | |
551 if(smallHeader.ppo2Divisor) | |
552 { | |
553 if(divisor.ppo2 == 0) | |
554 { | |
555 divisor.ppo2 = smallHeader.ppo2Divisor - 1; | |
556 | |
557 for(int i = 0; i <3; i++) | |
558 { | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
559 sample[length] = (uint8_t)(state->lifeData.ppO2Sensor_bar[i] * 100.0f + 0.5f); |
38 | 560 length += 1; |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
561 addU16(&sample[length], (uint16_t)(state->lifeData.sensorVoltage_mV[i] * 10.0f + 0.5f)); |
38 | 562 length += 2; |
563 } | |
564 } | |
565 else | |
566 { | |
567 divisor.ppo2--; | |
568 } | |
569 } | |
570 | |
571 | |
572 if(smallHeader.decoplanDivisor) | |
573 { | |
574 if(divisor.decoplan == 0) | |
575 { | |
576 divisor.decoplan = smallHeader.decoplanDivisor - 1; | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
577 if(state->diveSettings.deco_type.ub.standard == VPM_MODE) |
38 | 578 { |
579 for(int i = 0; i <15; i++) | |
580 { | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
581 sample[length] = state->decolistVPM.output_stop_length_seconds[i] / 60; |
38 | 582 length += 1; |
583 } | |
584 } | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
585 else if(state->diveSettings.deco_type.ub.standard == GF_MODE) |
38 | 586 { |
587 for(int i = 0; i <15; i++) | |
588 { | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
589 sample[length] = state->decolistBuehlmann.output_stop_length_seconds[i] / 60; |
38 | 590 length += 1; |
591 } | |
592 } | |
593 else | |
594 { | |
595 for(int i = 0; i <15; i++) | |
596 { | |
597 sample[length] = 0; | |
598 length += 1; | |
599 } | |
600 } | |
601 // add16(&sample[length], state.temperature); | |
602 //length += 2; | |
603 } | |
604 else | |
605 { | |
606 divisor.decoplan --; | |
607 } | |
608 } | |
609 if(divisor.cns == 0) | |
610 { | |
611 divisor.cns = smallHeader.cnsDivisor - 1; | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
612 addU16(&sample[length], (uint16_t)state->lifeData.cns); |
38 | 613 length += 2; |
614 } | |
615 else | |
616 { | |
617 divisor.cns--; | |
618 } | |
619 | |
620 profileByteFlag.uw = length - 3; | |
621 if(eventByte1.uw) | |
622 { | |
623 profileByteFlag.ub.bit7 = 1; | |
624 } | |
625 sample[2] = profileByteFlag.uw; | |
626 logbook_writedata((void *) sample,length); | |
627 | |
628 } | |
629 | |
630 /** | |
631 ****************************************************************************** | |
632 * @brief readSample. / Reads data of one logbook sample | |
633 * @author Peter Ryser | |
634 * @version V0.0.1 | |
635 * @date 22-April-2014 | |
636 ****************************************************************************** | |
637 * | |
638 * @param int32_t* depth: output Value | |
639 * @param int16_t * gasid: output Value | |
640 * @param int32_t* temperature: output Value | |
641 * @param int32_t* sensor1, sensor2, sensor3: output Value | |
642 * @param int32_t* cns: output Value | |
643 * @return bytes read / 0 = reading Error | |
644 */ | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
645 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 | 646 { |
647 int length = 0; | |
648 _Bool bEvent = 0; | |
649 bit8_Type eventByte1, eventByte2; | |
650 bit8_Type profileByteFlag; | |
651 | |
652 eventByte1.uw = 0; | |
653 eventByte2.uw = 0; | |
654 uint8_t tempU8 = 0; | |
655 uint16_t temp = 0; | |
656 uint16_t bytesRead = 0; | |
657 | |
658 if(gasid) | |
659 *gasid = -1; | |
660 if(temperature) | |
661 *temperature = -1000; | |
662 if(sensor1) | |
663 *sensor1 = -1; | |
664 if(sensor2) | |
665 *sensor2 = -1; | |
666 if(sensor3) | |
667 *sensor3 = -1; | |
668 if(cns) | |
669 *cns = -1; | |
670 if(setpoint_cbar) | |
671 *setpoint_cbar = -1; | |
672 if(bailout) | |
673 *bailout = -1; | |
674 if(manualGas) | |
675 { | |
676 manualGas->percentageO2 =-1; | |
677 manualGas->percentageHe =-1; | |
678 } | |
679 if(decostopDepth) | |
680 *decostopDepth = -1; | |
681 | |
682 ext_flash_read_next_sample_part( (uint8_t*)&temp, 2); | |
683 if(depth) | |
684 *depth = (int32_t)temp; | |
685 bytesRead += 2; | |
686 | |
687 ext_flash_read_next_sample_part( &profileByteFlag.uw, 1); | |
688 bytesRead ++; | |
689 | |
690 bEvent = profileByteFlag.ub.bit7; | |
691 profileByteFlag.ub.bit7 = 0; | |
692 length = profileByteFlag.uw; | |
693 | |
694 if(bEvent) | |
695 { | |
696 ext_flash_read_next_sample_part( &eventByte1.uw, 1); | |
697 bytesRead ++; | |
698 | |
699 length--; | |
700 | |
701 //second event byte | |
702 if(eventByte1.ub.bit7) | |
703 { | |
704 ext_flash_read_next_sample_part( &eventByte2.uw, 1); | |
705 bytesRead ++; | |
706 length--; | |
707 } | |
708 else | |
709 { | |
710 eventByte2.uw = 0; | |
711 } | |
712 | |
713 //manual Gas Set | |
714 if( eventByte1.ub.bit4) | |
715 { | |
716 //Evaluate manual Gas | |
717 ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1); | |
718 bytesRead +=1; | |
719 length -= 1; | |
720 manualGas->percentageO2 = tempU8; | |
721 ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1); | |
722 bytesRead +=1; | |
723 length -= 1; | |
724 manualGas->percentageHe = tempU8; | |
725 if(gasid) | |
726 *gasid = 0; | |
727 } | |
728 //gas change | |
729 if( eventByte1.ub.bit5) | |
730 { | |
731 ext_flash_read_next_sample_part( &tempU8, 1); | |
732 bytesRead +=1; | |
733 length -= 1; | |
734 if(gasid) | |
735 *gasid = (uint16_t)tempU8; | |
736 } | |
737 //SetpointChange | |
738 if( eventByte1.ub.bit6) | |
739 { | |
740 ext_flash_read_next_sample_part( &tempU8, 1); | |
741 *setpoint_cbar = tempU8; | |
742 bytesRead +=1; | |
743 length -= 1; | |
744 } | |
745 | |
746 // second event Byte | |
747 //bailout | |
748 if(eventByte2.ub.bit1) | |
749 { | |
750 //evaluate bailout gas Gas | |
751 *bailout = 1; | |
752 | |
753 ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1); | |
754 bytesRead +=1; | |
755 length -= 1; | |
756 manualGas->percentageO2 = tempU8; | |
757 ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1); | |
758 bytesRead +=1; | |
759 length -= 1; | |
760 manualGas->percentageHe = tempU8; | |
761 | |
762 if(gasid) | |
763 *gasid = 0; | |
764 } | |
765 } | |
766 | |
767 if(divisor.temperature == 0) | |
768 { | |
769 divisor.temperature = smallHeader.tempDivisor - 1; | |
770 ext_flash_read_next_sample_part( (uint8_t*)&temp, 2); | |
771 bytesRead +=2; | |
772 length -= 2; | |
773 if(temperature) | |
774 { | |
775 *temperature = (int32_t)temp; | |
776 } | |
777 } | |
778 else | |
779 { | |
780 divisor.temperature--; | |
781 } | |
782 | |
783 if(smallHeader.deco_ndlDivisor > 0) | |
784 { | |
785 if(divisor.deco_ndl == 0) | |
786 { | |
787 divisor.deco_ndl = smallHeader.deco_ndlDivisor - 1; | |
788 ext_flash_read_next_sample_part( &tempU8, 1); | |
789 if(decostopDepth) | |
790 { | |
791 *decostopDepth = tempU8 * 100; | |
792 } | |
793 ext_flash_read_next_sample_part( &tempU8, 1); | |
794 bytesRead += 2; | |
795 length -= 2; | |
796 } | |
797 else | |
798 { | |
799 divisor.deco_ndl--; | |
800 } | |
801 } | |
802 | |
803 if(divisor.ppo2 == 0) | |
804 { | |
805 int32_t ppO2Tmp = 0; | |
806 divisor.ppo2 = smallHeader.ppo2Divisor -1; | |
807 for(int i = 0; i <3 ; i++) | |
808 { | |
809 ext_flash_read_next_sample_part( &tempU8, 1); | |
810 ppO2Tmp += tempU8; | |
811 bytesRead +=1; | |
812 length -= 1; | |
813 ext_flash_read_next_sample_part( (uint8_t*)&temp, 2); | |
814 bytesRead +=2; | |
815 length -= 2; | |
816 if(sensor1 && (i==0)) | |
817 *sensor1 = (((int32_t)tempU8) * 0xFFFF) + temp; | |
818 if(sensor2 && (i==1)) | |
819 *sensor2 = (((int32_t)tempU8) * 0xFFFF) + temp; | |
820 if(sensor3 && (i==2)) | |
821 *sensor3 = (((int32_t)tempU8) * 0xFFFF) + temp; | |
822 } | |
823 } | |
824 else | |
825 { | |
826 divisor.ppo2--; | |
827 } | |
828 | |
829 if(smallHeader.decoplanDivisor > 0) | |
830 { | |
831 if(divisor.decoplan == 0) | |
832 { | |
833 divisor.decoplan = smallHeader.decoplanDivisor - 1; | |
834 for(int i = 0; i <15; i++) | |
835 ext_flash_read_next_sample_part( &tempU8, 1); | |
836 bytesRead += 15; | |
837 length -= 15; | |
838 } | |
839 else | |
840 { | |
841 divisor.decoplan--; | |
842 } | |
843 } | |
844 | |
845 | |
846 | |
847 if(divisor.cns == 0) | |
848 { | |
849 divisor.cns = smallHeader.cnsDivisor - 1; | |
850 | |
851 ext_flash_read_next_sample_part( (uint8_t*)&temp, 2); | |
852 bytesRead +=2; | |
853 length -= 2; | |
854 if(cns) | |
855 { | |
856 *cns = (int32_t)temp; | |
857 } | |
858 } | |
859 else | |
860 { | |
861 divisor.cns--; | |
862 } | |
863 | |
864 if (length != 0) | |
865 return 0; | |
866 | |
867 return bytesRead; | |
868 } | |
869 /** | |
870 ****************************************************************************** | |
871 * @brief logbook_readSampleData. / Reads sample data of whole logbook entry | |
872 * @author Peter Ryser | |
873 * @version V0.0.1 | |
874 * @date 22-April-2014 | |
875 ****************************************************************************** | |
876 * | |
877 * @param uint8_t StepBackwards: witch lookbook entry? | |
878 * @param uint16_t length : maxlength of output arrays | |
879 * @param int32_t* depth : output array | |
880 * @param int16_t * gasid : output array | |
881 * @param int32_t* temperature : output array | |
882 * @param int32_t* ppo2 : output array | |
883 * @param int32_t* cns : output array | |
884 * @return length of output | |
885 */ | |
886 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) | |
887 { | |
888 //Test read | |
889 //SLogbookHeader header; | |
890 | |
891 //logbook_getHeader(&header); | |
892 SLogbookHeader header; | |
893 int iNum; | |
894 int firstgasid = 0; | |
895 int retVal = 0; | |
896 int compression = 0; | |
897 int i; | |
898 // uint32_t diveTime_seconds; | |
899 int32_t depthVal = 0; | |
900 int16_t gasidVal = 0; | |
901 int16_t setPointVal = 0; | |
902 int16_t bailoutVal = 0; | |
903 int16_t bailoutLast = 0; | |
904 uint16_t setPointLast = 0; | |
905 int32_t temperatureVal = 0; | |
906 int32_t sensor1Val = 0; | |
907 int32_t sensor2Val = 0; | |
908 int32_t sensor3Val = 0; | |
909 int32_t sensor1Last = 0; | |
910 int32_t sensor2Last = 0; | |
911 int32_t sensor3Last = 0; | |
912 int32_t cnsVal = 0; | |
913 int32_t depthLast = 0; | |
914 int16_t gasidLast = 0; | |
915 int32_t temperatureLast = 0; | |
916 int32_t temperatureFirst = 0; | |
917 int32_t cnsLast = 0; | |
918 int16_t decostepDepthVal = 0; | |
919 int16_t decostepDepthLast = 0; | |
920 | |
921 SManualGas manualGasVal; | |
922 SManualGas manualGasLast; | |
923 manualGasLast.percentageO2 = 0; | |
924 manualGasLast.percentageHe = 0; | |
925 | |
926 float ambiant_pressure_bar = 0; | |
927 float ppO2 = 0; | |
928 ext_flash_read_dive_header((uint8_t*)&header, StepBackwards); | |
929 for(i = 0;i< 5;i++) | |
930 { | |
931 if(header.gasordil[i].note.ub.first) | |
932 break; | |
933 } | |
934 firstgasid = i + 1; | |
935 if(header.diveMode == DIVEMODE_CCR) | |
936 setPointLast = header.setpoint[0].setpoint_cbar; | |
937 else | |
938 setPointLast = 0; | |
939 //diveTime_seconds = header.diveTime_seconds ; | |
940 for(compression = 1; compression < 100; compression ++) | |
941 { | |
942 if((header.total_diveTime_seconds / header.samplingRate)/compression <= length) | |
943 break; | |
944 } | |
945 | |
946 | |
947 for(i = 0;i< length;i++) | |
948 { | |
949 if(depth) | |
950 depth[i] = 0; | |
951 if(temperature) | |
952 temperature[i] = 0; | |
953 if(gasid) | |
954 gasid[i] = 0; | |
955 if(ppo2) | |
956 ppo2[i] = 0; | |
957 if(setpoint) | |
958 setpoint[i] = 0; | |
959 if(sensor1) | |
960 sensor1[i] = 0; | |
961 if(sensor2) | |
962 sensor2[i] = 0; | |
963 if(sensor3) | |
964 sensor3[i] = 0; | |
965 if(cns) | |
966 cns[i] = 0; | |
967 } | |
968 //We start with fist gasid | |
969 gasidLast = firstgasid; | |
970 | |
971 | |
972 //uint16_t* ppo2, uint16_t* cns# | |
973 uint32_t totalNumberOfBytes = 0; | |
974 uint32_t bytesRead = 0; | |
975 ext_flash_open_read_sample( StepBackwards,&totalNumberOfBytes); | |
976 ext_flash_read_next_sample_part((uint8_t*)&smallHeader, sizeof(SSmallHeader)); | |
977 bytesRead += sizeof(SSmallHeader); | |
978 | |
979 clear_divisor(); | |
980 | |
981 iNum = 0; | |
982 int counter = 0; | |
983 temperatureLast = -1000; | |
984 while ((bytesRead < totalNumberOfBytes) && (iNum < length)) | |
985 { | |
986 ext_flash_set_entry_point(); | |
987 divisorBackup = divisor; | |
988 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, &decostepDepthVal); | |
989 | |
990 if(retVal == 0) | |
991 { | |
992 //Error try to read again!!! | |
993 ext_flash_reopen_read_sample_at_entry_point(); | |
994 divisor = divisorBackup; | |
995 retVal = readSample(&depthVal,&gasidVal,&setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, &decostepDepthVal); | |
996 | |
997 if(retVal == 0) | |
998 break; | |
999 } | |
1000 bytesRead +=retVal; | |
1001 | |
1002 //if for some variable no new value is in the sample for (z.B. gasidVal = -1), we take the last value | |
1003 if(depthVal == -1) | |
1004 depthVal = depthLast; | |
1005 else | |
1006 depthLast = depthVal; | |
1007 | |
1008 if(gasidVal == -1) | |
1009 gasidVal = gasidLast; | |
1010 else | |
1011 gasidLast = gasidVal; | |
1012 | |
1013 if(temperatureVal == -1000) | |
1014 temperatureVal = temperatureLast; | |
1015 else | |
1016 { | |
1017 if(temperatureLast == -1000) | |
1018 temperatureFirst = temperatureVal; | |
1019 temperatureLast = temperatureVal; | |
1020 } | |
1021 | |
1022 if(setPointVal == -1) | |
1023 setPointVal = setPointLast; | |
1024 else | |
1025 setPointLast = setPointVal; | |
1026 | |
1027 if(sensor1Val == -1) | |
1028 sensor1Val = sensor1Last; | |
1029 else | |
1030 sensor1Last = sensor1Val; | |
1031 | |
1032 if(sensor2Val == -1) | |
1033 sensor2Val = sensor2Last; | |
1034 else | |
1035 sensor2Last = sensor2Val; | |
1036 | |
1037 if(sensor3Val == -1) | |
1038 sensor3Val = sensor3Last; | |
1039 else | |
1040 sensor3Last = sensor3Val; | |
1041 | |
1042 if(cnsVal == -1) | |
1043 cnsVal = cnsLast; | |
1044 else | |
1045 cnsLast = cnsVal; | |
1046 | |
1047 if(manualGasVal.percentageO2 == -1) | |
1048 manualGasVal = manualGasLast; | |
1049 else | |
1050 manualGasLast = manualGasVal; | |
1051 | |
1052 if(bailoutVal == -1) | |
1053 bailoutVal = bailoutLast; | |
1054 else | |
1055 bailoutLast = bailoutVal; | |
1056 | |
1057 if(decostepDepthVal == -1) | |
1058 decostepDepthVal = decostepDepthLast; | |
1059 else | |
1060 decostepDepthLast = decostepDepthVal; | |
1061 | |
1062 counter++; | |
1063 // Heed compression | |
1064 // Write here to arrays | |
1065 if(counter == compression) | |
1066 { | |
1067 if(depth) | |
1068 depth[iNum] = depthVal; | |
1069 if(gasid) | |
1070 gasid[iNum] = gasidVal; | |
1071 if(temperature) | |
1072 temperature[iNum] = temperatureVal; | |
1073 if(cns) | |
1074 cns[iNum] = cnsVal; | |
1075 if(bailout) | |
1076 bailout[iNum] = bailoutVal; | |
1077 if(decostopDepth) | |
1078 decostopDepth[iNum] = decostepDepthVal; | |
1079 | |
1080 if(ppo2) | |
1081 { | |
1082 //Calc ppo2 - Values | |
1083 SGas gas; | |
1084 gas.setPoint_cbar = setPointVal; | |
1085 if(gasidVal > 0) | |
1086 { | |
1087 gas.helium_percentage = header.gasordil[gasidVal - 1].helium_percentage; | |
1088 gas.nitrogen_percentage = 100 - gas.helium_percentage - header.gasordil[gasidVal - 1].oxygen_percentage; | |
1089 } | |
1090 else | |
1091 { | |
1092 gas.helium_percentage = manualGasVal.percentageHe; | |
1093 gas.nitrogen_percentage = 100 - gas.helium_percentage - manualGasVal.percentageO2; | |
1094 } | |
1095 ambiant_pressure_bar =((float)(depthVal + header.surfacePressure_mbar))/1000; | |
1096 ppO2 = decom_calc_ppO2(ambiant_pressure_bar, &gas ); | |
1097 ppo2[iNum] = (uint16_t) ( ppO2 * 100); | |
1098 } | |
1099 | |
1100 if(setpoint) | |
1101 setpoint[iNum] = setPointVal; | |
1102 | |
1103 if(sensor1) | |
1104 sensor1[iNum] = (sensor1Val / 0xFFFF) & 0xFF; | |
1105 if(sensor2) | |
1106 sensor2[iNum] = (sensor2Val / 0xFFFF) & 0xFF; | |
1107 if(sensor3) | |
1108 sensor3[iNum] = (sensor3Val / 0xFFFF) & 0xFF; | |
1109 iNum++; | |
1110 counter = 0; | |
1111 } | |
1112 } | |
1113 | |
1114 // Fix first Temperature Entries 150930 hw | |
1115 if(temperature) | |
1116 { | |
1117 int i = 0; | |
1118 while((temperature[i] == -1000) && (i < iNum)) | |
1119 temperature[i++] = temperatureFirst; | |
1120 } | |
1121 | |
1122 ext_flash_close_read_sample(); | |
1123 return iNum; | |
1124 } | |
1125 | |
1126 | |
1127 /******************************************************************************** | |
1128 * @brief logbook_InitAndWrite. / Controls writing of logbook | |
1129 * Should be called ten times per second | |
1130 * Automatically Initializes logbook at beginning of dive, | |
1131 * write samples every 2 seconds | |
1132 * and finishes logbook after end of dive | |
1133 *********************************************************************************/ | |
1134 | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1135 void logbook_InitAndWrite(const SDiveState *pStateReal) |
38 | 1136 { |
1137 SSettings *pSettings = settingsGetPointer(); | |
1138 static uint8_t bDiveMode = 0; | |
1139 static uint32_t tickstart = 0; | |
1140 uint32_t ticksdiff = 0; | |
1141 uint32_t lasttick = 0; | |
1142 static float min_temperature_float_celsius = 0; | |
1143 | |
1144 if(!bDiveMode) | |
1145 { | |
1146 if((pStateReal->mode == MODE_DIVE) && (pStateReal->diveSettings.diveMode != DIVEMODE_Apnea) && (pStateReal->lifeData.dive_time_seconds >= 5)) | |
1147 { | |
1148 //InitdiveProfile | |
1149 pSettings->totalDiveCounter++; | |
1150 logbook_initNewdiveProfile(pStateReal,settingsGetPointer()); | |
1151 min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius; | |
1152 //Write logbook sample | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1153 logbook_writeSample(pStateReal); |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1154 resetEvents(pStateReal); |
38 | 1155 tickstart = HAL_GetTick(); |
1156 bDiveMode = 1; | |
1157 } | |
1158 } | |
1159 else if((pStateReal->mode == MODE_DIVE) && (pStateReal->diveSettings.diveMode != DIVEMODE_Apnea)) | |
1160 { | |
1161 lasttick = HAL_GetTick(); | |
1162 ticksdiff = time_elapsed_ms(tickstart,lasttick); | |
1163 // | |
1164 if(ticksdiff >= 2000) | |
1165 { | |
1166 //Write logbook sample | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1167 logbook_writeSample(pStateReal); |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1168 resetEvents(pStateReal); |
38 | 1169 if(min_temperature_float_celsius > pStateReal->lifeData.temperature_celsius) |
1170 min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius; | |
1171 tickstart = lasttick; | |
1172 if((bDiveMode == 1) && (pStateReal->lifeData.dive_time_seconds >= pSettings->divetimeToCreateLogbook)) | |
1173 { | |
1174 ext_flash_create_new_dive_log((uint8_t*)&header); | |
1175 /** save settings | |
1176 * with new lastDiveLogId and time and day | |
1177 */ | |
1178 pSettings->personalDiveCount++; | |
1179 if(pSettings->logbookOffset) | |
1180 { | |
1181 pSettings->logbookOffset++; | |
1182 } | |
1183 ext_flash_write_settings(); | |
1184 ext_flash_disable_protection_for_logbook(); | |
1185 bDiveMode = 3; | |
1186 } | |
1187 if(bDiveMode == 3) | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1188 logbook_UpdateHeader(pStateReal); |
38 | 1189 } |
1190 } | |
1191 else if(bDiveMode == 3) | |
1192 { | |
1193 //End of Dive | |
1194 logbook_SetAverageDepth(pStateReal->lifeData.average_depth_meter); | |
1195 logbook_SetMinTemperature(min_temperature_float_celsius); | |
1196 logbook_SetMaxCNS(pStateReal->lifeData.cns); | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1197 logbook_SetCompartmentDesaturation(pStateReal); |
38 | 1198 logbook_SetLastStop(pStateReal->diveSettings.last_stop_depth_bar); |
1199 logbook_EndDive(); | |
1200 bDiveMode = 0; | |
1201 } else | |
1202 { | |
1203 ext_flash_enable_protection(); | |
1204 } | |
1205 } | |
1206 | |
1207 | |
1208 /* Private functions ---------------------------------------------------------*/ | |
1209 | |
1210 /******************************************************************************** | |
1211 * @brief logbook_UpdateHeader. / | |
1212 * set date, time, max depth. etc. pp. | |
1213 * the internal pointer to the end of profile and length will be set by | |
1214 ext_flash_close_new_dive_log() in externLogbookFlash.c | |
1215 * @author heinrichs weikamp gmbh | |
1216 * @version V0.0.1 | |
1217 * @date 27-Nov-2014 | |
1218 *********************************************************************************/ | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1219 static void logbook_UpdateHeader(const SDiveState *pStateReal) |
38 | 1220 { |
1221 // uint16_t secondsAtShallow = 0; | |
1222 RTC_DateTypeDef Sdate; | |
1223 RTC_TimeTypeDef Stime; | |
1224 uint32_t time1_u32, time2_u32; | |
1225 uint32_t divetimeHelper; | |
1226 | |
1227 /* time and day */ | |
1228 /* don't update CHANGE 160224 hw, maybe save actual time and date at other place | |
1229 translateDate(pStateReal->lifeData.dateBinaryFormat, &Sdate); | |
1230 translateTime(pStateReal->lifeData.timeBinaryFormat, &Stime); | |
1231 | |
1232 header.dateYear = Sdate.Year; | |
1233 header.dateMonth = Sdate.Month; | |
1234 header.dateDay = Sdate.Date; | |
1235 header.timeHour = Stime.Hours; | |
1236 header.timeMinute = Stime.Minutes; | |
1237 */ | |
1238 /// 160315 Quick fix for empty date problem | |
1239 if((!(header.dateYear)) || (!(header.dateMonth)) || (!(header.dateDay))) | |
1240 { | |
1241 translateDate(pStateReal->lifeData.dateBinaryFormat, &Sdate); | |
1242 translateTime(pStateReal->lifeData.timeBinaryFormat, &Stime); | |
1243 | |
1244 header.dateYear = Sdate.Year; | |
1245 header.dateMonth = Sdate.Month; | |
1246 header.dateDay = Sdate.Date; | |
1247 | |
1248 time1_u32 = (uint32_t)header.timeMinute + (uint32_t)(header.timeHour * 60); | |
1249 time2_u32 = (uint32_t)Stime.Minutes + (uint32_t)(Stime.Hours * 60); | |
1250 if(time2_u32 < time1_u32) | |
1251 { | |
1252 if(header.dateDay > 1) | |
1253 { | |
1254 header.dateDay -= 1; | |
1255 } | |
1256 else | |
1257 { | |
1258 header.dateMonth --; | |
1259 if(!header.dateMonth) | |
1260 { | |
1261 header.dateYear--; | |
1262 header.dateMonth = 12; | |
1263 header.dateDay = 31; | |
1264 } | |
1265 else | |
1266 { | |
1267 if(header.dateMonth == 2) | |
1268 header.dateDay = 28; | |
1269 else | |
1270 if((header.dateMonth == 4) || (header.dateMonth == 6) || (header.dateMonth == 9) || (header.dateMonth == 11)) | |
1271 header.dateDay = 30; | |
1272 else | |
1273 header.dateDay = 31; | |
1274 } | |
1275 } | |
1276 } | |
1277 } | |
1278 | |
1279 /* duration */ | |
1280 header.total_diveTime_seconds = pStateReal->lifeData.dive_time_seconds; | |
1281 header.maxDepth = pStateReal->lifeData.max_depth_meter * 100; | |
1282 | |
1283 /* old: | |
1284 | |
1285 secondsAtShallow = pSettings->timeoutDiveReachedZeroDepth; | |
1286 if(pStateReal->lifeData.dive_time_seconds <= secondsAtShallow) | |
1287 secondsAtShallow = 0; | |
1288 header.diveTimeMinutes = (header.total_diveTime_seconds - secondsAtShallow )/ 60; | |
1289 header.diveTimeSeconds = header.total_diveTime_seconds - secondsAtShallow - (header.diveTimeMinutes * 60); | |
1290 */ | |
1291 divetimeHelper = pStateReal->lifeData.dive_time_seconds_without_surface_time; | |
1292 header.diveTimeMinutes = (uint16_t)(divetimeHelper/60); | |
1293 divetimeHelper -= 60 * (uint32_t)header.diveTimeMinutes; | |
1294 header.diveTimeSeconds = (uint16_t)divetimeHelper; | |
1295 | |
1296 /* deco algorithm (final) */ | |
1297 if(pStateReal->diveSettings.deco_type.ub.standard == GF_MODE) | |
1298 { | |
1299 header.decoModel = 1; | |
1300 header.gfLow_or_Vpm_conservatism = pStateReal->diveSettings.gf_low; | |
1301 header.gfHigh = pStateReal->diveSettings.gf_high; | |
1302 } | |
1303 else | |
1304 { | |
1305 header.decoModel = 2; | |
1306 header.gfLow_or_Vpm_conservatism = pStateReal->diveSettings.vpm_conservatism; | |
1307 header.gfHigh = 0; | |
1308 } | |
1309 | |
1310 /* tissue load */ | |
1311 memcpy(header.n2Compartments, pStateReal->lifeData.tissue_nitrogen_bar, 64); | |
1312 memcpy(header.heCompartments, pStateReal->lifeData.tissue_helium_bar, 64); | |
1313 | |
1314 } | |
1315 | |
1316 | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
1317 static void logbook_SetAverageDepth(float average_depth_meter) |
38 | 1318 { |
1319 header.averageDepth_mbar = (uint16_t)(average_depth_meter * 100); | |
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_SetMinTemperature(float min_temperature_celsius) |
38 | 1324 { |
1325 header.minTemp = (int16_t)((min_temperature_celsius * 10.0f) + 0.5f); | |
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_SetMaxCNS(float max_cns_percentage) |
38 | 1330 { |
1331 if(max_cns_percentage < 9999) | |
1332 header.maxCNS = (uint16_t)(max_cns_percentage); | |
1333 else | |
1334 header.maxCNS = 9999; | |
1335 } | |
1336 | |
1337 | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1338 static void logbook_SetCompartmentDesaturation(const SDiveState * pStateReal) |
38 | 1339 { |
225
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
199
diff
changeset
|
1340 SLifeData2 secondaryInformation = { 0 }; |
38 | 1341 |
1342 decom_tissues_desaturation_time(&pStateReal->lifeData, &secondaryInformation); | |
1343 for(int i=0;i<16;i++) | |
1344 { | |
1345 if(secondaryInformation.tissue_nitrogen_desaturation_time_minutes[i] <= (15 * 255)) | |
1346 header.n2CompartDesatTime_min[i] = (uint8_t)((secondaryInformation.tissue_nitrogen_desaturation_time_minutes[i] + 14) / 15); | |
1347 else | |
1348 header.n2CompartDesatTime_min[i] = 255; | |
1349 if(secondaryInformation.tissue_helium_desaturation_time_minutes[i] <= (15 * 255)) | |
1350 header.heCompartDesatTime_min[i] = (uint8_t)((secondaryInformation.tissue_helium_desaturation_time_minutes[i] + 14 )/ 15); | |
1351 else | |
1352 header.heCompartDesatTime_min[i] = 255; | |
1353 } | |
1354 } | |
1355 | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
1356 static void logbook_SetLastStop(float last_stop_depth_bar) |
38 | 1357 { |
1358 header.lastDecostop_m = (uint8_t)(last_stop_depth_bar / 10.0f); | |
1359 } | |
1360 | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
1361 static void logbook_writedata(void * data, int length_byte) |
38 | 1362 { |
1363 ext_flash_write_sample(data, length_byte); | |
1364 } | |
1365 | |
1366 | |
1367 /******************************************************************************** | |
1368 * @brief logbook_build_ostc3header. / | |
1369 * @author heinrichs weikamp gmbh | |
1370 * @version V0.0.2 | |
1371 * @date 27-Nov-2014 | |
1372 *********************************************************************************/ | |
1373 SLogbookHeaderOSTC3 * logbook_build_ostc3header(SLogbookHeader* pHead) | |
1374 { | |
1375 convert_Type data; | |
1376 | |
1377 memcpy(headerOSTC3.diveHeaderStart, &pHead->diveHeaderStart, 2); | |
1378 memcpy(headerOSTC3.pBeginProfileData, &pHead->pBeginProfileData, 3); | |
1379 memcpy(headerOSTC3.pEndProfileData, &pHead->pEndProfileData, 3); | |
1380 | |
1381 data.u8bit.byteHigh = 0; | |
1382 data.u8bit.byteLow = pHead->profileLength[0]; | |
1383 data.u8bit.byteMidLow = pHead->profileLength[1]; | |
1384 data.u8bit.byteMidHigh = pHead->profileLength[2]; | |
1385 | |
1386 if(data.u32bit != 0xFFFFFF) | |
1387 data.u32bit += 3; | |
1388 | |
1389 headerOSTC3.profileLength[0] = data.u8bit.byteLow; | |
1390 headerOSTC3.profileLength[1] = data.u8bit.byteMidLow; | |
1391 headerOSTC3.profileLength[2] = data.u8bit.byteMidHigh; | |
1392 | |
1393 memcpy(headerOSTC3.gasordil, pHead->gasordil, 20); | |
1394 | |
1395 if(pHead->logbookProfileVersion == LOGBOOK_VERSION) | |
1396 { | |
1397 headerOSTC3.logbookProfileVersion = LOGBOOK_VERSION_OSTC3; | |
1398 memcpy(headerOSTC3.personalDiveCount, &pHead->personalDiveCount, 2); | |
1399 headerOSTC3.safetyDistance_10cm = 0; | |
1400 | |
1401 for(int i=0;i<5;i++) | |
1402 { | |
1403 if(!pHead->gasordil[i].note.ub.active) | |
1404 headerOSTC3.gasordil[3 + (i*4)] = 0; | |
1405 else if(pHead->gasordil[i].note.ub.first) | |
1406 { | |
1407 /* depth = 0, note = 1 */ | |
1408 headerOSTC3.gasordil[2 + (i*4)] = 0; | |
1409 headerOSTC3.gasordil[3 + (i*4)] = 1; | |
1410 } | |
1411 else if( pHead->gasordil[i].depth_meter) | |
1412 { | |
1413 /* note = 3 */ | |
1414 headerOSTC3.gasordil[3 + (i*4)] = 3; | |
1415 } | |
1416 } | |
1417 } | |
1418 else | |
1419 { | |
1420 headerOSTC3.logbookProfileVersion = 0xFF; | |
1421 headerOSTC3.personalDiveCount[0] = 0xFF; | |
1422 headerOSTC3.personalDiveCount[1] = 0xFF; | |
1423 headerOSTC3.safetyDistance_10cm = 0xFF; | |
1424 } | |
1425 | |
1426 headerOSTC3.dateYear = pHead->dateYear; | |
1427 headerOSTC3.dateMonth = pHead->dateMonth; | |
1428 headerOSTC3.dateDay = pHead->dateDay; | |
1429 headerOSTC3.timeHour = pHead->timeHour; | |
1430 headerOSTC3.timeMinute = pHead->timeMinute; | |
1431 | |
1432 | |
1433 memcpy(headerOSTC3.maxDepth, &pHead->maxDepth, 2); | |
1434 memcpy(headerOSTC3.diveTimeMinutes, &pHead->diveTimeMinutes, 2); | |
1435 | |
1436 headerOSTC3.diveTimeSeconds = pHead->diveTimeSeconds; | |
1437 | |
1438 memcpy(headerOSTC3.minTemp, &pHead->minTemp, 2); | |
1439 memcpy(headerOSTC3.surfacePressure_mbar,&pHead->surfacePressure_mbar, 2); | |
1440 memcpy(headerOSTC3.desaturationTime, &pHead->desaturationTime, 2); | |
1441 | |
1442 headerOSTC3.firmwareVersionHigh = pHead->firmwareVersionHigh; | |
1443 headerOSTC3.firmwareVersionLow = pHead->firmwareVersionLow; | |
1444 | |
1445 memcpy(headerOSTC3.batteryVoltage, &pHead->batteryVoltage, 2); | |
1446 | |
1447 headerOSTC3.samplingRate = pHead->samplingRate; | |
1448 | |
1449 memcpy(headerOSTC3.cnsAtBeginning, &pHead->cnsAtBeginning, 2); | |
1450 | |
1451 headerOSTC3.gfAtBeginning = pHead->gfAtBeginning; | |
1452 headerOSTC3.gfAtEnd = pHead->gfAtEnd; | |
1453 | |
1454 memcpy(headerOSTC3.setpoint, pHead->setpoint, 10); | |
1455 | |
1456 headerOSTC3.salinity = pHead->salinity; | |
1457 | |
1458 memcpy(headerOSTC3.maxCNS, &pHead->maxCNS, 2); | |
1459 memcpy(headerOSTC3.averageDepth_mbar, &pHead->averageDepth_mbar, 2); | |
1460 memcpy(headerOSTC3.total_diveTime_seconds,&pHead->total_diveTime_seconds, 2); | |
1461 | |
1462 headerOSTC3.gfLow_or_Vpm_conservatism = pHead->gfLow_or_Vpm_conservatism; | |
1463 headerOSTC3.gfHigh = pHead->gfHigh; | |
1464 headerOSTC3.decoModel = pHead->decoModel; | |
1465 | |
1466 memcpy(headerOSTC3.diveNumber, &pHead->diveNumber, 2); | |
1467 | |
1468 headerOSTC3.diveMode = pHead->diveMode; | |
1469 headerOSTC3.CCRmode = pHead->CCRmode; | |
1470 | |
1471 memcpy(headerOSTC3.n2CompartDesatTime_min,pHead->n2CompartDesatTime_min, 16); | |
1472 memcpy(headerOSTC3.n2Compartments, pHead->n2Compartments, 64); | |
1473 memcpy(headerOSTC3.heCompartDesatTime_min,pHead->heCompartDesatTime_min, 16); | |
1474 memcpy(headerOSTC3.heCompartments, pHead->heCompartments, 64); | |
1475 | |
1476 headerOSTC3.lastDecostop_m = pHead->lastDecostop_m; | |
1477 | |
1478 memcpy(headerOSTC3.hwHudBattery_mV, &pHead->hwHudBattery_mV, 2); | |
1479 | |
1480 headerOSTC3.hwHudLastStatus = pHead->hwHudLastStatus; | |
1481 | |
1482 memcpy(headerOSTC3.batteryGaugeRegisters,&pHead->batteryGaugeRegisters, 6); | |
1483 | |
1484 | |
1485 memcpy(headerOSTC3.diveHeaderEnd, &pHead->diveHeaderEnd, 2); | |
1486 | |
1487 return &headerOSTC3; | |
1488 } | |
1489 | |
1490 | |
1491 /******************************************************************************** | |
1492 * @brief logbook_build_ostc3header_compact. / | |
1493 * @author heinrichs weikamp gmbh | |
1494 * @version V0.0.1 | |
1495 * @date 31-Juli-2015 | |
1496 *********************************************************************************/ | |
1497 SLogbookHeaderOSTC3compact * logbook_build_ostc3header_compact(SLogbookHeader* pHead) | |
1498 { | |
1499 convert_Type data; | |
1500 | |
1501 data.u8bit.byteHigh = 0; | |
1502 data.u8bit.byteLow = pHead->profileLength[0]; | |
1503 data.u8bit.byteMidLow = pHead->profileLength[1]; | |
1504 data.u8bit.byteMidHigh = pHead->profileLength[2]; | |
1505 | |
1506 if(data.u32bit != 0xFFFFFF) | |
1507 { | |
1508 data.u32bit += 3; | |
1509 | |
1510 headerOSTC3compact.profileLength[0] = data.u8bit.byteLow; | |
1511 headerOSTC3compact.profileLength[1] = data.u8bit.byteMidLow; | |
1512 headerOSTC3compact.profileLength[2] = data.u8bit.byteMidHigh; | |
1513 | |
1514 headerOSTC3compact.dateYear = pHead->dateYear; | |
1515 headerOSTC3compact.dateMonth = pHead->dateMonth; | |
1516 headerOSTC3compact.dateDay = pHead->dateDay; | |
1517 headerOSTC3compact.timeHour = pHead->timeHour; | |
1518 headerOSTC3compact.timeMinute = pHead->timeMinute; | |
1519 | |
1520 memcpy(headerOSTC3compact.maxDepth, &pHead->maxDepth, 2); | |
1521 memcpy(headerOSTC3compact.diveTimeMinutes, &pHead->diveTimeMinutes, 2); | |
1522 | |
1523 headerOSTC3compact.diveTimeSeconds = pHead->diveTimeSeconds; | |
1524 | |
1525 | |
1526 headerOSTC3compact.totalDiveNumberLow = pHead->diveNumber & 0xFF; | |
1527 headerOSTC3compact.totalDiveNumberHigh = (uint8_t)(pHead->diveNumber/256); | |
1528 headerOSTC3compact.profileVersion = 0x24; // Logbook-Profile version, 0x24 = date and time is start not end | |
1529 } | |
1530 else | |
1531 { | |
1532 memset(&headerOSTC3compact, 0xFF, sizeof(SLogbookHeaderOSTC3compact)); | |
1533 } | |
1534 return &headerOSTC3compact; | |
1535 } | |
1536 | |
1537 | |
1538 /** | |
1539 ****************************************************************************** | |
1540 * @brief logbook_readSampleData. / Reads sample data of whole logbook entry | |
1541 * @author Peter Ryser | |
1542 * @version V0.0.1 | |
1543 * @date 22-April-2014 | |
1544 ****************************************************************************** | |
1545 * | |
1546 * @param uint8_t StepBackwards: witch lookbook entry? | |
1547 * @param uint16_t length : maxlength of output arrays | |
1548 * @param int32_t* depth : output array | |
1549 * @param int16_t * gasid : output array | |
1550 * @param int32_t* temperature : output array | |
1551 * @param int32_t* ppo2 : output array | |
1552 * @param int32_t* cns : output array | |
1553 * @return length of output | |
1554 */ | |
1555 void logbook_recover_brokenlog(uint8_t headerId) | |
1556 { | |
1557 int16_t retVal; | |
1558 int32_t depthVal = 0; | |
1559 int16_t gasidVal = 0; | |
1560 int16_t setPointVal = 0; | |
1561 int16_t bailoutVal = 0; | |
1562 int32_t temperatureVal = 0; | |
1563 int32_t sensor1Val = 0; | |
1564 int32_t sensor2Val = 0; | |
1565 int32_t sensor3Val = 0; | |
1566 int32_t cnsVal = 0; | |
1567 SManualGas manualGasVal; | |
1568 | |
1569 //uint16_t* ppo2, uint16_t* cns# | |
1570 uint32_t bytesRead = 0; | |
1571 | |
1572 ext_flash_read_block_start(); | |
1573 ext_flash_read_next_sample_part((uint8_t*)&smallHeader, sizeof(SSmallHeader)); | |
1574 bytesRead += sizeof(SSmallHeader); | |
1575 | |
1576 clear_divisor(); | |
1577 | |
1578 | |
1579 int sampleCounter = 0; | |
1580 int maxdepth = 0; | |
1581 uint32_t avrdepth = 0; | |
1582 while (true) | |
1583 { | |
1584 | |
1585 ext_flash_set_entry_point(); | |
1586 divisorBackup = divisor; | |
1587 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL); | |
1588 if(retVal == 0) | |
1589 { | |
1590 //Error try to read again!!! | |
1591 ext_flash_reopen_read_sample_at_entry_point(); | |
1592 divisor = divisorBackup; | |
1593 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL); | |
1594 | |
1595 if(retVal == 0) | |
1596 { | |
1597 //Error try to read again!!! | |
1598 ext_flash_reopen_read_sample_at_entry_point(); | |
1599 divisor = divisorBackup; | |
1600 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL); | |
1601 | |
1602 if(retVal == 0) | |
1603 { | |
1604 ext_flash_reopen_read_sample_at_entry_point(); | |
1605 break; | |
1606 } | |
1607 | |
1608 } | |
1609 } | |
1610 if(depthVal > maxdepth) | |
1611 maxdepth = depthVal; | |
1612 avrdepth += depthVal; | |
1613 sampleCounter++; | |
1614 bytesRead +=retVal; | |
1615 } | |
1616 avrdepth/= sampleCounter; | |
1617 ext_flash_close_read_sample(); | |
1618 SLogbookHeader header; | |
1619 | |
1620 ext_flash_read_dive_header2((uint8_t*) &header, headerId, false); | |
1621 header.total_diveTime_seconds = sampleCounter * header.samplingRate; | |
1622 header.diveTimeMinutes = header.total_diveTime_seconds /60; | |
1623 header.diveTimeSeconds = header.total_diveTime_seconds - header.diveTimeMinutes * 60; | |
1624 header.maxDepth = maxdepth; | |
1625 header.averageDepth_mbar = avrdepth; | |
1626 SSettings * settings = settingsGetPointer(); | |
1627 settings->lastDiveLogId = headerId; | |
1628 ext_flash_close_new_dive_log((uint8_t *)&header); | |
1629 } | |
1630 | |
1631 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |