Mercurial > public > ostc4
annotate Discovery/Src/logbook.c @ 293:02d10d955be2 div-fixes-6
bugfix, consistency: show deco, NDL after 1 minute
1 letter fix. VPM showed NDL data after 10 seconds, and Buehlmann after 60
seconds. And as this type of data is fully irrelevant during the first minute
(at least), make VPM and Buehlmann consistent and display NDL after 60 seconds.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Thu, 02 May 2019 10:05:28 +0200 |
parents | 04cdeff80254 |
children | 50c26a4442af |
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 | |
753 if(eventByte2.ub.bit1) | |
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); |
1204 logbook_EndDive(); | |
1205 bDiveMode = 0; | |
1206 } else | |
1207 { | |
1208 ext_flash_enable_protection(); | |
1209 } | |
1210 } | |
1211 | |
1212 | |
1213 /* Private functions ---------------------------------------------------------*/ | |
1214 | |
1215 /******************************************************************************** | |
1216 * @brief logbook_UpdateHeader. / | |
1217 * set date, time, max depth. etc. pp. | |
1218 * the internal pointer to the end of profile and length will be set by | |
1219 ext_flash_close_new_dive_log() in externLogbookFlash.c | |
1220 * @author heinrichs weikamp gmbh | |
1221 * @version V0.0.1 | |
1222 * @date 27-Nov-2014 | |
1223 *********************************************************************************/ | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1224 static void logbook_UpdateHeader(const SDiveState *pStateReal) |
38 | 1225 { |
1226 // uint16_t secondsAtShallow = 0; | |
1227 RTC_DateTypeDef Sdate; | |
1228 RTC_TimeTypeDef Stime; | |
1229 uint32_t time1_u32, time2_u32; | |
1230 uint32_t divetimeHelper; | |
1231 | |
1232 /* time and day */ | |
1233 /* don't update CHANGE 160224 hw, maybe save actual time and date at other place | |
1234 translateDate(pStateReal->lifeData.dateBinaryFormat, &Sdate); | |
1235 translateTime(pStateReal->lifeData.timeBinaryFormat, &Stime); | |
1236 | |
1237 header.dateYear = Sdate.Year; | |
1238 header.dateMonth = Sdate.Month; | |
1239 header.dateDay = Sdate.Date; | |
1240 header.timeHour = Stime.Hours; | |
1241 header.timeMinute = Stime.Minutes; | |
1242 */ | |
1243 /// 160315 Quick fix for empty date problem | |
1244 if((!(header.dateYear)) || (!(header.dateMonth)) || (!(header.dateDay))) | |
1245 { | |
1246 translateDate(pStateReal->lifeData.dateBinaryFormat, &Sdate); | |
1247 translateTime(pStateReal->lifeData.timeBinaryFormat, &Stime); | |
1248 | |
1249 header.dateYear = Sdate.Year; | |
1250 header.dateMonth = Sdate.Month; | |
1251 header.dateDay = Sdate.Date; | |
1252 | |
1253 time1_u32 = (uint32_t)header.timeMinute + (uint32_t)(header.timeHour * 60); | |
1254 time2_u32 = (uint32_t)Stime.Minutes + (uint32_t)(Stime.Hours * 60); | |
1255 if(time2_u32 < time1_u32) | |
1256 { | |
1257 if(header.dateDay > 1) | |
1258 { | |
1259 header.dateDay -= 1; | |
1260 } | |
1261 else | |
1262 { | |
1263 header.dateMonth --; | |
1264 if(!header.dateMonth) | |
1265 { | |
1266 header.dateYear--; | |
1267 header.dateMonth = 12; | |
1268 header.dateDay = 31; | |
1269 } | |
1270 else | |
1271 { | |
1272 if(header.dateMonth == 2) | |
1273 header.dateDay = 28; | |
1274 else | |
1275 if((header.dateMonth == 4) || (header.dateMonth == 6) || (header.dateMonth == 9) || (header.dateMonth == 11)) | |
1276 header.dateDay = 30; | |
1277 else | |
1278 header.dateDay = 31; | |
1279 } | |
1280 } | |
1281 } | |
1282 } | |
1283 | |
1284 /* duration */ | |
1285 header.total_diveTime_seconds = pStateReal->lifeData.dive_time_seconds; | |
1286 header.maxDepth = pStateReal->lifeData.max_depth_meter * 100; | |
1287 | |
1288 /* old: | |
1289 | |
1290 secondsAtShallow = pSettings->timeoutDiveReachedZeroDepth; | |
1291 if(pStateReal->lifeData.dive_time_seconds <= secondsAtShallow) | |
1292 secondsAtShallow = 0; | |
1293 header.diveTimeMinutes = (header.total_diveTime_seconds - secondsAtShallow )/ 60; | |
1294 header.diveTimeSeconds = header.total_diveTime_seconds - secondsAtShallow - (header.diveTimeMinutes * 60); | |
1295 */ | |
1296 divetimeHelper = pStateReal->lifeData.dive_time_seconds_without_surface_time; | |
1297 header.diveTimeMinutes = (uint16_t)(divetimeHelper/60); | |
1298 divetimeHelper -= 60 * (uint32_t)header.diveTimeMinutes; | |
1299 header.diveTimeSeconds = (uint16_t)divetimeHelper; | |
1300 | |
1301 /* deco algorithm (final) */ | |
1302 if(pStateReal->diveSettings.deco_type.ub.standard == GF_MODE) | |
1303 { | |
1304 header.decoModel = 1; | |
1305 header.gfLow_or_Vpm_conservatism = pStateReal->diveSettings.gf_low; | |
1306 header.gfHigh = pStateReal->diveSettings.gf_high; | |
1307 } | |
1308 else | |
1309 { | |
1310 header.decoModel = 2; | |
1311 header.gfLow_or_Vpm_conservatism = pStateReal->diveSettings.vpm_conservatism; | |
1312 header.gfHigh = 0; | |
1313 } | |
1314 | |
1315 /* tissue load */ | |
1316 memcpy(header.n2Compartments, pStateReal->lifeData.tissue_nitrogen_bar, 64); | |
1317 memcpy(header.heCompartments, pStateReal->lifeData.tissue_helium_bar, 64); | |
1318 | |
1319 } | |
1320 | |
1321 | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
1322 static void logbook_SetAverageDepth(float average_depth_meter) |
38 | 1323 { |
1324 header.averageDepth_mbar = (uint16_t)(average_depth_meter * 100); | |
1325 } | |
1326 | |
1327 | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
1328 static void logbook_SetMinTemperature(float min_temperature_celsius) |
38 | 1329 { |
1330 header.minTemp = (int16_t)((min_temperature_celsius * 10.0f) + 0.5f); | |
1331 } | |
1332 | |
1333 | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
1334 static void logbook_SetMaxCNS(float max_cns_percentage) |
38 | 1335 { |
1336 if(max_cns_percentage < 9999) | |
1337 header.maxCNS = (uint16_t)(max_cns_percentage); | |
1338 else | |
1339 header.maxCNS = 9999; | |
1340 } | |
1341 | |
1342 | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1343 static void logbook_SetCompartmentDesaturation(const SDiveState * pStateReal) |
38 | 1344 { |
225
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
199
diff
changeset
|
1345 SLifeData2 secondaryInformation = { 0 }; |
38 | 1346 |
1347 decom_tissues_desaturation_time(&pStateReal->lifeData, &secondaryInformation); | |
1348 for(int i=0;i<16;i++) | |
1349 { | |
1350 if(secondaryInformation.tissue_nitrogen_desaturation_time_minutes[i] <= (15 * 255)) | |
1351 header.n2CompartDesatTime_min[i] = (uint8_t)((secondaryInformation.tissue_nitrogen_desaturation_time_minutes[i] + 14) / 15); | |
1352 else | |
1353 header.n2CompartDesatTime_min[i] = 255; | |
1354 if(secondaryInformation.tissue_helium_desaturation_time_minutes[i] <= (15 * 255)) | |
1355 header.heCompartDesatTime_min[i] = (uint8_t)((secondaryInformation.tissue_helium_desaturation_time_minutes[i] + 14 )/ 15); | |
1356 else | |
1357 header.heCompartDesatTime_min[i] = 255; | |
1358 } | |
1359 } | |
1360 | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
1361 static void logbook_SetLastStop(float last_stop_depth_bar) |
38 | 1362 { |
1363 header.lastDecostop_m = (uint8_t)(last_stop_depth_bar / 10.0f); | |
1364 } | |
1365 | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
1366 static void logbook_writedata(void * data, int length_byte) |
38 | 1367 { |
1368 ext_flash_write_sample(data, length_byte); | |
1369 } | |
1370 | |
1371 | |
1372 /******************************************************************************** | |
1373 * @brief logbook_build_ostc3header. / | |
1374 * @author heinrichs weikamp gmbh | |
1375 * @version V0.0.2 | |
1376 * @date 27-Nov-2014 | |
1377 *********************************************************************************/ | |
1378 SLogbookHeaderOSTC3 * logbook_build_ostc3header(SLogbookHeader* pHead) | |
1379 { | |
1380 convert_Type data; | |
1381 | |
1382 memcpy(headerOSTC3.diveHeaderStart, &pHead->diveHeaderStart, 2); | |
1383 memcpy(headerOSTC3.pBeginProfileData, &pHead->pBeginProfileData, 3); | |
1384 memcpy(headerOSTC3.pEndProfileData, &pHead->pEndProfileData, 3); | |
1385 | |
1386 data.u8bit.byteHigh = 0; | |
1387 data.u8bit.byteLow = pHead->profileLength[0]; | |
1388 data.u8bit.byteMidLow = pHead->profileLength[1]; | |
1389 data.u8bit.byteMidHigh = pHead->profileLength[2]; | |
1390 | |
1391 if(data.u32bit != 0xFFFFFF) | |
1392 data.u32bit += 3; | |
1393 | |
1394 headerOSTC3.profileLength[0] = data.u8bit.byteLow; | |
1395 headerOSTC3.profileLength[1] = data.u8bit.byteMidLow; | |
1396 headerOSTC3.profileLength[2] = data.u8bit.byteMidHigh; | |
1397 | |
1398 memcpy(headerOSTC3.gasordil, pHead->gasordil, 20); | |
1399 | |
1400 if(pHead->logbookProfileVersion == LOGBOOK_VERSION) | |
1401 { | |
1402 headerOSTC3.logbookProfileVersion = LOGBOOK_VERSION_OSTC3; | |
1403 memcpy(headerOSTC3.personalDiveCount, &pHead->personalDiveCount, 2); | |
1404 headerOSTC3.safetyDistance_10cm = 0; | |
1405 | |
1406 for(int i=0;i<5;i++) | |
1407 { | |
1408 if(!pHead->gasordil[i].note.ub.active) | |
1409 headerOSTC3.gasordil[3 + (i*4)] = 0; | |
1410 else if(pHead->gasordil[i].note.ub.first) | |
1411 { | |
1412 /* depth = 0, note = 1 */ | |
1413 headerOSTC3.gasordil[2 + (i*4)] = 0; | |
1414 headerOSTC3.gasordil[3 + (i*4)] = 1; | |
1415 } | |
1416 else if( pHead->gasordil[i].depth_meter) | |
1417 { | |
1418 /* note = 3 */ | |
1419 headerOSTC3.gasordil[3 + (i*4)] = 3; | |
1420 } | |
1421 } | |
1422 } | |
1423 else | |
1424 { | |
1425 headerOSTC3.logbookProfileVersion = 0xFF; | |
1426 headerOSTC3.personalDiveCount[0] = 0xFF; | |
1427 headerOSTC3.personalDiveCount[1] = 0xFF; | |
1428 headerOSTC3.safetyDistance_10cm = 0xFF; | |
1429 } | |
1430 | |
1431 headerOSTC3.dateYear = pHead->dateYear; | |
1432 headerOSTC3.dateMonth = pHead->dateMonth; | |
1433 headerOSTC3.dateDay = pHead->dateDay; | |
1434 headerOSTC3.timeHour = pHead->timeHour; | |
1435 headerOSTC3.timeMinute = pHead->timeMinute; | |
1436 | |
1437 | |
1438 memcpy(headerOSTC3.maxDepth, &pHead->maxDepth, 2); | |
1439 memcpy(headerOSTC3.diveTimeMinutes, &pHead->diveTimeMinutes, 2); | |
1440 | |
1441 headerOSTC3.diveTimeSeconds = pHead->diveTimeSeconds; | |
1442 | |
1443 memcpy(headerOSTC3.minTemp, &pHead->minTemp, 2); | |
1444 memcpy(headerOSTC3.surfacePressure_mbar,&pHead->surfacePressure_mbar, 2); | |
1445 memcpy(headerOSTC3.desaturationTime, &pHead->desaturationTime, 2); | |
1446 | |
1447 headerOSTC3.firmwareVersionHigh = pHead->firmwareVersionHigh; | |
1448 headerOSTC3.firmwareVersionLow = pHead->firmwareVersionLow; | |
1449 | |
1450 memcpy(headerOSTC3.batteryVoltage, &pHead->batteryVoltage, 2); | |
1451 | |
1452 headerOSTC3.samplingRate = pHead->samplingRate; | |
1453 | |
1454 memcpy(headerOSTC3.cnsAtBeginning, &pHead->cnsAtBeginning, 2); | |
1455 | |
1456 headerOSTC3.gfAtBeginning = pHead->gfAtBeginning; | |
1457 headerOSTC3.gfAtEnd = pHead->gfAtEnd; | |
1458 | |
1459 memcpy(headerOSTC3.setpoint, pHead->setpoint, 10); | |
1460 | |
1461 headerOSTC3.salinity = pHead->salinity; | |
1462 | |
1463 memcpy(headerOSTC3.maxCNS, &pHead->maxCNS, 2); | |
1464 memcpy(headerOSTC3.averageDepth_mbar, &pHead->averageDepth_mbar, 2); | |
1465 memcpy(headerOSTC3.total_diveTime_seconds,&pHead->total_diveTime_seconds, 2); | |
1466 | |
1467 headerOSTC3.gfLow_or_Vpm_conservatism = pHead->gfLow_or_Vpm_conservatism; | |
1468 headerOSTC3.gfHigh = pHead->gfHigh; | |
1469 headerOSTC3.decoModel = pHead->decoModel; | |
1470 | |
1471 memcpy(headerOSTC3.diveNumber, &pHead->diveNumber, 2); | |
1472 | |
1473 headerOSTC3.diveMode = pHead->diveMode; | |
1474 headerOSTC3.CCRmode = pHead->CCRmode; | |
1475 | |
1476 memcpy(headerOSTC3.n2CompartDesatTime_min,pHead->n2CompartDesatTime_min, 16); | |
1477 memcpy(headerOSTC3.n2Compartments, pHead->n2Compartments, 64); | |
1478 memcpy(headerOSTC3.heCompartDesatTime_min,pHead->heCompartDesatTime_min, 16); | |
1479 memcpy(headerOSTC3.heCompartments, pHead->heCompartments, 64); | |
1480 | |
1481 headerOSTC3.lastDecostop_m = pHead->lastDecostop_m; | |
1482 | |
1483 memcpy(headerOSTC3.hwHudBattery_mV, &pHead->hwHudBattery_mV, 2); | |
1484 | |
1485 headerOSTC3.hwHudLastStatus = pHead->hwHudLastStatus; | |
1486 | |
1487 memcpy(headerOSTC3.batteryGaugeRegisters,&pHead->batteryGaugeRegisters, 6); | |
1488 | |
1489 | |
1490 memcpy(headerOSTC3.diveHeaderEnd, &pHead->diveHeaderEnd, 2); | |
1491 | |
1492 return &headerOSTC3; | |
1493 } | |
1494 | |
1495 | |
1496 /******************************************************************************** | |
1497 * @brief logbook_build_ostc3header_compact. / | |
1498 * @author heinrichs weikamp gmbh | |
1499 * @version V0.0.1 | |
1500 * @date 31-Juli-2015 | |
1501 *********************************************************************************/ | |
1502 SLogbookHeaderOSTC3compact * logbook_build_ostc3header_compact(SLogbookHeader* pHead) | |
1503 { | |
1504 convert_Type data; | |
1505 | |
1506 data.u8bit.byteHigh = 0; | |
1507 data.u8bit.byteLow = pHead->profileLength[0]; | |
1508 data.u8bit.byteMidLow = pHead->profileLength[1]; | |
1509 data.u8bit.byteMidHigh = pHead->profileLength[2]; | |
1510 | |
1511 if(data.u32bit != 0xFFFFFF) | |
1512 { | |
1513 data.u32bit += 3; | |
1514 | |
1515 headerOSTC3compact.profileLength[0] = data.u8bit.byteLow; | |
1516 headerOSTC3compact.profileLength[1] = data.u8bit.byteMidLow; | |
1517 headerOSTC3compact.profileLength[2] = data.u8bit.byteMidHigh; | |
1518 | |
1519 headerOSTC3compact.dateYear = pHead->dateYear; | |
1520 headerOSTC3compact.dateMonth = pHead->dateMonth; | |
1521 headerOSTC3compact.dateDay = pHead->dateDay; | |
1522 headerOSTC3compact.timeHour = pHead->timeHour; | |
1523 headerOSTC3compact.timeMinute = pHead->timeMinute; | |
1524 | |
1525 memcpy(headerOSTC3compact.maxDepth, &pHead->maxDepth, 2); | |
1526 memcpy(headerOSTC3compact.diveTimeMinutes, &pHead->diveTimeMinutes, 2); | |
1527 | |
1528 headerOSTC3compact.diveTimeSeconds = pHead->diveTimeSeconds; | |
1529 | |
1530 | |
1531 headerOSTC3compact.totalDiveNumberLow = pHead->diveNumber & 0xFF; | |
1532 headerOSTC3compact.totalDiveNumberHigh = (uint8_t)(pHead->diveNumber/256); | |
1533 headerOSTC3compact.profileVersion = 0x24; // Logbook-Profile version, 0x24 = date and time is start not end | |
1534 } | |
1535 else | |
1536 { | |
1537 memset(&headerOSTC3compact, 0xFF, sizeof(SLogbookHeaderOSTC3compact)); | |
1538 } | |
1539 return &headerOSTC3compact; | |
1540 } | |
1541 | |
1542 | |
1543 /** | |
1544 ****************************************************************************** | |
1545 * @brief logbook_readSampleData. / Reads sample data of whole logbook entry | |
281 | 1546 * @author heinrichs weikamp |
38 | 1547 * @version V0.0.1 |
1548 * @date 22-April-2014 | |
1549 ****************************************************************************** | |
1550 * | |
1551 * @param uint8_t StepBackwards: witch lookbook entry? | |
1552 * @param uint16_t length : maxlength of output arrays | |
1553 * @param int32_t* depth : output array | |
1554 * @param int16_t * gasid : output array | |
1555 * @param int32_t* temperature : output array | |
1556 * @param int32_t* ppo2 : output array | |
1557 * @param int32_t* cns : output array | |
1558 * @return length of output | |
1559 */ | |
1560 void logbook_recover_brokenlog(uint8_t headerId) | |
1561 { | |
1562 int16_t retVal; | |
1563 int32_t depthVal = 0; | |
1564 int16_t gasidVal = 0; | |
1565 int16_t setPointVal = 0; | |
1566 int16_t bailoutVal = 0; | |
1567 int32_t temperatureVal = 0; | |
1568 int32_t sensor1Val = 0; | |
1569 int32_t sensor2Val = 0; | |
1570 int32_t sensor3Val = 0; | |
1571 int32_t cnsVal = 0; | |
1572 SManualGas manualGasVal; | |
1573 | |
1574 //uint16_t* ppo2, uint16_t* cns# | |
1575 uint32_t bytesRead = 0; | |
1576 | |
1577 ext_flash_read_block_start(); | |
1578 ext_flash_read_next_sample_part((uint8_t*)&smallHeader, sizeof(SSmallHeader)); | |
1579 bytesRead += sizeof(SSmallHeader); | |
1580 | |
1581 clear_divisor(); | |
1582 | |
1583 | |
1584 int sampleCounter = 0; | |
1585 int maxdepth = 0; | |
1586 uint32_t avrdepth = 0; | |
1587 while (true) | |
1588 { | |
1589 | |
1590 ext_flash_set_entry_point(); | |
1591 divisorBackup = divisor; | |
1592 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL); | |
1593 if(retVal == 0) | |
1594 { | |
1595 //Error try to read again!!! | |
1596 ext_flash_reopen_read_sample_at_entry_point(); | |
1597 divisor = divisorBackup; | |
1598 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL); | |
1599 | |
1600 if(retVal == 0) | |
1601 { | |
1602 //Error try to read again!!! | |
1603 ext_flash_reopen_read_sample_at_entry_point(); | |
1604 divisor = divisorBackup; | |
1605 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL); | |
1606 | |
1607 if(retVal == 0) | |
1608 { | |
1609 ext_flash_reopen_read_sample_at_entry_point(); | |
1610 break; | |
1611 } | |
1612 | |
1613 } | |
1614 } | |
1615 if(depthVal > maxdepth) | |
1616 maxdepth = depthVal; | |
1617 avrdepth += depthVal; | |
1618 sampleCounter++; | |
1619 bytesRead +=retVal; | |
1620 } | |
1621 avrdepth/= sampleCounter; | |
1622 ext_flash_close_read_sample(); | |
1623 SLogbookHeader header; | |
1624 | |
1625 ext_flash_read_dive_header2((uint8_t*) &header, headerId, false); | |
1626 header.total_diveTime_seconds = sampleCounter * header.samplingRate; | |
1627 header.diveTimeMinutes = header.total_diveTime_seconds /60; | |
1628 header.diveTimeSeconds = header.total_diveTime_seconds - header.diveTimeMinutes * 60; | |
1629 header.maxDepth = maxdepth; | |
1630 header.averageDepth_mbar = avrdepth; | |
1631 SSettings * settings = settingsGetPointer(); | |
1632 settings->lastDiveLogId = headerId; | |
1633 ext_flash_close_new_dive_log((uint8_t *)&header); | |
1634 } | |
1635 | |
1636 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |