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