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