Mercurial > public > ostc4
annotate Discovery/Src/logbook.c @ 937:d461d9e89e3c Evo_2_23
Compile switch for RTE sleep debug:
there was already a compiler switch for enabling debugging while RTE is in sleep but the switches were distributed across the code => to make selection easier they are now part of the configuration.h
author | Ideenmodellierer |
---|---|
date | Tue, 10 Dec 2024 20:59:37 +0100 |
parents | 63c340abd70e |
children |
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" |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
60 #include "configuration.h" |
38 | 61 |
62 /* Private types -------------------------------------------------------------*/ | |
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 */ |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
68 #define DUMMY_SAMPLES (1000) /* Maximum number of samples profided by a dummy dive profile */ |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
69 |
38 | 70 typedef struct /* don't forget to adjust void clear_divisor(void) */ |
71 { | |
72 uint8_t temperature; | |
73 uint8_t deco_ndl; | |
74 uint8_t gradientFactor; | |
75 uint8_t ppo2; | |
76 uint8_t decoplan; | |
77 uint8_t cns; | |
78 uint8_t tank; | |
79 } SDivisor; | |
80 | |
81 /* Exported variables --------------------------------------------------------*/ | |
82 | |
83 /* Private variables ---------------------------------------------------------*/ | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
84 static SLogbookHeader gheader; |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
85 static SLogbookHeaderOSTC3 headerOSTC3; |
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
86 static SLogbookHeaderOSTC3compact headerOSTC3compact; |
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
87 static SSmallHeader smallHeader; |
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
88 static SDivisor divisor; |
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
89 static SDivisor divisorBackup; |
38 | 90 |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
91 static SSmallHeader smallDummyHeader; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
92 static uint16_t dummyWriteIdx; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
93 static uint16_t dummyReadIdx; |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
94 static uint8_t dummyMemoryBuffer[5000]; |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
95 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
96 |
38 | 97 /* Private function prototypes -----------------------------------------------*/ |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
98 static void clear_divisor(void); |
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 static void logbook_UpdateHeader(const SDiveState * pStateReal); |
458 | 106 static void logbook_createDummyProfile(SLogbookHeader* pHeader, uint16_t length, uint16_t* depth, int16_t* temperature, uint16_t* ppo2); |
38 | 107 |
108 /* Exported functions --------------------------------------------------------*/ | |
109 | |
110 void logbook_EndDive(void) | |
111 { | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
112 ext_flash_close_new_dive_log((uint8_t*) &gheader); |
38 | 113 } |
114 | |
115 | |
116 // =============================================================================== | |
117 // logbook_last_totalDiveCount | |
118 /// @brief Fix setting issues | |
119 /// @date 04-April-2016 | |
120 /// | |
121 /// @return diveNumber (totalDiveCounter) of latest log entry, 0 if not a valid header | |
122 // =============================================================================== | |
123 uint16_t logbook_lastDive_diveNumber(void) | |
124 { | |
125 SLogbookHeader tempLogbookHeader; | |
126 if(logbook_getHeader(0, &tempLogbookHeader)) | |
127 { | |
128 return tempLogbookHeader.diveNumber; | |
129 } | |
130 else | |
131 { | |
132 return 0; | |
133 } | |
134 } | |
135 | |
136 | |
137 /** | |
138 ****************************************************************************** | |
139 * @brief logbook_getCurrentHeader. / | |
281 | 140 * @author heinrichs weikamp |
38 | 141 * @version V0.0.1 |
142 * @date 22-April-2014 | |
143 ****************************************************************************** | |
144 * | |
145 * @return SLogbookHeader*: | |
146 */ | |
147 SLogbookHeader* logbook_getCurrentHeader(void) | |
148 { | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
149 return &gheader; |
38 | 150 } |
151 | |
152 /** | |
153 ****************************************************************************** | |
154 * @brief logbook_getNumberOfHeaders. / | |
155 * @author heinrichs weikamp gmbh | |
156 * @version V0.0.1 | |
157 * @date 18-May-2016 | |
158 ****************************************************************************** | |
159 * | |
160 * @return uint8_t : number of valid headers (0xFAFA) found. | |
161 */ | |
162 uint8_t logbook_getNumberOfHeaders(void) | |
163 { | |
164 return ext_flash_count_dive_headers(); | |
165 } | |
166 | |
167 | |
168 /** | |
169 ****************************************************************************** | |
170 * @brief logbook_getHeader. / | |
281 | 171 * @author heinrichs weikamp |
38 | 172 * @version V0.0.1 |
173 * @date 22-April-2014 | |
174 ****************************************************************************** | |
175 * | |
176 * @param StepBackwards : 0 Last lokbook entry, 1 second to last entry, etc. | |
177 * @param SSLogbookHeader* pLogbookHeader: Output found LogbookHeader | |
178 * @return uint8_t : 1 = success | |
179 */ | |
180 uint8_t logbook_getHeader(uint8_t StepBackwards,SLogbookHeader* pLogbookHeader) | |
181 { | |
182 ext_flash_read_dive_header((uint8_t *)pLogbookHeader, StepBackwards); | |
183 if(pLogbookHeader->diveHeaderStart != 0xFAFA) | |
184 return 0; | |
185 else | |
186 return 1; | |
187 } | |
188 | |
189 /** | |
190 ****************************************************************************** | |
191 * @brief logbook_initNewdiveProfile. / | |
192 * creates header and smallHeader from diveState and global Settings | |
193 * and writes new lookboock entry on flash device | |
194 * diveState | |
281 | 195 * @author heinrichs weikamp |
38 | 196 * @version V0.0.1 |
197 * @date 22-April-2014 | |
198 ****************************************************************************** | |
199 * | |
200 * @param SDiveState* pInfo: Input | |
201 * @param SSettings* pSettings: Input | |
202 */ | |
203 | |
204 void logbook_initNewdiveProfile(const SDiveState* pInfo, SSettings* pSettings) | |
205 { | |
206 RTC_DateTypeDef Sdate; | |
207 RTC_TimeTypeDef Stime; | |
208 | |
209 for(int i = 0; i < sizeof(SLogbookHeader); i++) | |
210 { | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
211 ((uint8_t*)(&gheader))[i] = 0; |
38 | 212 } |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
213 gheader.diveHeaderStart = 0xFAFA; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
214 gheader.diveHeaderEnd = 0xFBFB; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
215 gheader.samplingRate = 2; |
38 | 216 if(pInfo->diveSettings.diveMode == DIVEMODE_OC) |
217 { | |
218 for(int i = 0; i < 5; i++) | |
219 { | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
220 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
|
221 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
|
222 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
|
223 gheader.gasordil[i].depth_meter = pSettings->gas[i+1].depth_meter; |
38 | 224 } |
225 } | |
226 else | |
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.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
|
231 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
|
232 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
|
233 gheader.gasordil[i].depth_meter = pSettings->gas[i+6].depth_meter; |
38 | 234 } |
235 | |
236 for(int i = 0; i < 5; i++) | |
237 { | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
238 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
|
239 gheader.setpoint[i].depth_meter = pSettings->setpoint[i+1].depth_meter; |
38 | 240 } |
241 } | |
242 // header.gasordil[pInfo->lifeData.actualGas.GasIdInSettings].depth_meter = 0; | |
243 | |
244 translateDate(pInfo->lifeData.dateBinaryFormat, &Sdate); | |
245 translateTime(pInfo->lifeData.timeBinaryFormat, &Stime); | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
246 gheader.dateYear = Sdate.Year; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
247 gheader.dateMonth = Sdate.Month; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
248 gheader.dateDay = Sdate.Date; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
249 gheader.timeHour = Stime.Hours; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
250 gheader.timeMinute = Stime.Minutes; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
251 gheader.cnsAtBeginning = (uint16_t)pInfo->lifeData.cns; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
252 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
|
253 gheader.firmwareVersionHigh = firmwareVersion_16bit_high(); |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
254 gheader.firmwareVersionLow = firmwareVersion_16bit_low(); |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
255 gheader.logbookProfileVersion = LOGBOOK_VERSION; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
256 gheader.salinity = pSettings->salinity; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
257 gheader.diveNumber = pSettings->totalDiveCounter; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
258 gheader.personalDiveCount = pSettings->personalDiveCount; |
38 | 259 |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
260 gheader.diveMode = pInfo->diveSettings.diveMode; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
261 gheader.CCRmode = pInfo->diveSettings.CCR_Mode; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
262 gheader.lastDecostop_m = pSettings->last_stop_depth_meter; |
38 | 263 |
264 if(pInfo->diveSettings.deco_type.ub.standard == GF_MODE) | |
265 { | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
266 gheader.decoModel = 1; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
267 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
|
268 gheader.gfHigh = pInfo->diveSettings.gf_high; |
38 | 269 } |
270 else | |
271 { | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
272 gheader.decoModel = 2; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
273 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
|
274 gheader.gfHigh = 0; |
38 | 275 } |
276 | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
277 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
|
278 memcpy(gheader.heCompartments, pInfo->lifeData.tissue_helium_bar, 64); |
38 | 279 |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
280 logbook_SetCompartmentDesaturation(pInfo); |
38 | 281 |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
282 ext_flash_start_new_dive_log_and_set_actualPointerSample((uint8_t*)&gheader); |
38 | 283 |
284 smallHeader.profileLength[0] = 0xFF; | |
285 smallHeader.profileLength[1] = 0xFF; | |
286 smallHeader.profileLength[2] = 0xFF; | |
287 smallHeader.samplingRate_seconds = 2; | |
288 smallHeader.numDivisors = 7; | |
289 | |
290 smallHeader.tempType = 0; | |
291 smallHeader.tempLength = 2; | |
292 smallHeader.tempDivisor = 6; | |
293 | |
294 smallHeader.deco_ndlType = 1; | |
295 smallHeader.deco_ndlLength = 2; | |
296 smallHeader.deco_ndlDivisor = 6; //= 6; | |
297 | |
298 /* GF in % at actual position */ | |
299 smallHeader.gfType = 2; | |
300 smallHeader.gfLength = 1; | |
301 smallHeader.gfDivisor = 0; //12; | |
302 | |
303 /* 3 Sensors: 8bit ppO2 in 0.01bar, 16bit voltage in 0,1mV */ | |
304 smallHeader.ppo2Type = 3; | |
305 smallHeader.ppo2Length = 9; | |
306 smallHeader.ppo2Divisor = 2; //2 | |
307 | |
308 /* last 15 stops in minutes (last, second_to_last, ... */ | |
309 /* last stop depth is defined in header */ | |
310 smallHeader.decoplanType = 4; | |
311 smallHeader.decoplanLength = 15; | |
312 smallHeader.decoplanDivisor = 12;//12; | |
313 | |
314 smallHeader.cnsType = 5; | |
315 smallHeader.cnsLength = 2; | |
316 smallHeader.cnsDivisor = 12; | |
317 | |
318 smallHeader.tankType = 6; | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
319 #ifdef ENABLE_BOTTLE_SENSOR |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
320 smallHeader.tankLength = 2; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
321 smallHeader.tankDivisor = 30; /* log tank data once a minute */ |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
322 #else |
38 | 323 smallHeader.tankLength = 0; |
324 smallHeader.tankDivisor = 0; | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
325 #endif |
38 | 326 logbook_writedata((void *) &smallHeader,sizeof(smallHeader)); |
327 | |
328 clear_divisor(); | |
329 } | |
330 | |
331 /** | |
332 ****************************************************************************** | |
333 * @brief clear_divisor / clears divisor struct | |
281 | 334 * @author heinrichs weikamp |
38 | 335 * @version V0.0.1 |
336 * @date 22-April-2014 | |
337 ****************************************************************************** | |
338 * | |
339 */ | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
340 static void clear_divisor(void) |
38 | 341 { |
342 divisor.cns = smallHeader.cnsDivisor - 1; | |
343 divisor.decoplan = smallHeader.decoplanDivisor - 1; | |
344 divisor.deco_ndl = smallHeader.deco_ndlDivisor - 1; | |
345 divisor.gradientFactor = smallHeader.gfDivisor -1 ; | |
346 divisor.ppo2 = smallHeader.ppo2Divisor - 1; | |
347 divisor.tank = smallHeader.tankDivisor - 1; | |
348 divisor.temperature = smallHeader.tempDivisor - 1; | |
349 } | |
350 | |
351 | |
352 /** | |
353 ****************************************************************************** | |
354 * @brief add16. / adds 16 bit variable to 8 bit array | |
281 | 355 * @author heinrichs weikamp |
38 | 356 * @version V0.0.1 |
357 * @date 22-April-2014 | |
358 ****************************************************************************** | |
359 * | |
360 * @param uint8_t *pos: Output 8 bit array | |
361 * @param uint16_t var: 16 bit variable | |
362 */ | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
363 static void addU16(uint8_t *pos, uint16_t var) |
38 | 364 { |
365 *((uint16_t*)pos) = var; | |
366 } | |
367 | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
368 static void addS16(uint8_t *pos, int16_t var) |
38 | 369 { |
370 *((int16_t*)pos) = var; | |
371 } | |
372 | |
373 /** | |
374 ****************************************************************************** | |
375 * @brief logbook_writeSample. / Writes one logbook sampl | |
281 | 376 * @author heinrichs weikamp |
38 | 377 * @date 22-April-2014 |
378 * @version V0.0.2 | |
379 * @since 20-June-2016 | |
380 * @bug Deco/NDL Status fixed in V0.0.2 | |
381 | |
382 | |
383 ****************************************************************************** | |
384 * | |
385 * @param SDiveState state: | |
386 */ | |
387 | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
388 void logbook_writeSample(const SDiveState *state) |
38 | 389 { |
390 uint8_t sample[256]; | |
391 // int position = 0; | |
392 int length = 0; | |
393 // _Bool bEvent = 0; | |
394 uint8_t nextstopDepthMeter = 0; | |
395 uint16_t nextstopLengthSeconds = 0; | |
396 uint8_t nextstopLengthMinutes = 0; | |
397 bit8_Type eventByte1, eventByte2; | |
398 bit8_Type profileByteFlag; | |
399 int i = 0; | |
400 for(i = 0; i <256 ;i++) | |
401 sample[i] = 0; | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
402 addU16(sample, (uint16_t)(state->lifeData.depth_meter * 100)); |
38 | 403 length += 2; |
404 sample[2] = 0; | |
405 length++; | |
406 eventByte1.uw = 0; | |
407 eventByte2.uw = 0; | |
408 //uint16_t tmpU16 = 0; | |
130
b7689d9e888a
Minor changes to improved code quality and to eliminate warnings
Ideenmodellierer
parents:
38
diff
changeset
|
409 const SDecoinfo * pDecoinfo; // new hw 160620 |
38 | 410 |
411 //BuildEevntyte 1 | |
412 // 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
|
413 if(state->events.manualMarker) |
38 | 414 { |
415 eventByte1.uw = 6; | |
416 } | |
417 else | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
418 if(state->warnings.decoMissed) |
38 | 419 { |
420 eventByte1.uw = 2; | |
421 } | |
422 else | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
423 if(state->warnings.ppO2Low) |
38 | 424 { |
425 eventByte1.uw = 4; | |
426 } | |
427 else | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
428 if(state->warnings.ppO2High) |
38 | 429 { |
430 eventByte1.uw = 5; | |
431 } | |
432 else | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
433 if(state->warnings.lowBattery) |
38 | 434 { |
435 eventByte1.uw = 7; | |
436 } | |
437 else | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
438 if(state->warnings.slowWarning) |
38 | 439 { |
440 eventByte1.uw = 1; | |
441 } | |
442 // sub bit 4 to 7 | |
281 | 443 if(state->events.manualGasSet) |
38 | 444 { |
445 eventByte1.ub.bit4 = 1; | |
446 } | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
447 if(state->events.gasChange) |
38 | 448 { |
449 eventByte1.ub.bit5 = 1; | |
450 } | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
451 if(state->events.setpointChange) |
38 | 452 { |
453 eventByte1.ub.bit6 = 1; | |
454 } | |
455 // sub bit 7 + eventbyte2 | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
456 if(state->events.bailout) |
38 | 457 { |
458 eventByte1.ub.bit7 = 1; | |
459 eventByte2.ub.bit0 = 1; | |
460 } | |
929
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
671
diff
changeset
|
461 if (state->events.compassHeadingUpdate) { |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
671
diff
changeset
|
462 eventByte1.ub.bit7 = 1; |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
671
diff
changeset
|
463 eventByte2.ub.bit1 = 1; |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
671
diff
changeset
|
464 } |
38 | 465 //Add EventByte 1 |
466 if(eventByte1.uw > 0) | |
467 { | |
468 sample[length] = eventByte1.uw; | |
469 length++; | |
470 } | |
471 if(eventByte2.uw > 0) | |
472 { | |
473 sample[length] = eventByte2.uw; | |
474 length++; | |
475 } | |
476 //Add EventInfos | |
281 | 477 if(state->events.manualGasSet) |
38 | 478 { |
479 //manual gas in %O2 & %He | |
281 | 480 sample[length] = state->events.info_manualGasSetO2; |
38 | 481 length += 1; |
281 | 482 sample[length] = state->events.info_manualGasSetHe; |
38 | 483 length += 1; |
484 } | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
485 if(state->events.gasChange) |
38 | 486 { |
487 //Current gas (gasid) | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
488 sample[length] = state->events.info_GasChange; |
38 | 489 length += 1; |
490 } | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
491 if(state->events.setpointChange) |
38 | 492 { |
493 //New setpoint in cbar | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
494 sample[length] = state->events.info_SetpointChange; |
38 | 495 length += 1; |
496 } | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
497 if(state->events.bailout) |
38 | 498 { |
499 //bailout gas in % O2 & %He | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
500 sample[length] = state->events.info_bailoutO2; |
38 | 501 length += 1; |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
502 sample[length] = state->events.info_bailoutHe; |
38 | 503 length += 1; |
504 } | |
929
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
671
diff
changeset
|
505 if (state->events.compassHeadingUpdate) { |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
671
diff
changeset
|
506 // New heading and type of heading |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
671
diff
changeset
|
507 sample[length++] = state->events.info_compassHeadingUpdate & 0xFF; |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
671
diff
changeset
|
508 sample[length++] = (state->events.info_compassHeadingUpdate & 0xFF00) >> 8; |
63c340abd70e
Add a line to the compass heading dive menu that shows the currently set heading to enable the
heinrichsweikamp
parents:
671
diff
changeset
|
509 } |
38 | 510 |
511 | |
512 if(divisor.temperature == 0) | |
513 { | |
514 divisor.temperature = smallHeader.tempDivisor - 1; | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
515 addS16(&sample[length], (int16_t)((state->lifeData.temperature_celsius * 10.0f) + 0.5f)); |
38 | 516 length += 2; |
517 } | |
518 else | |
519 { | |
520 divisor.temperature--; | |
521 } | |
522 | |
523 | |
524 if(smallHeader.deco_ndlDivisor > 0) | |
525 { | |
526 if(divisor.deco_ndl == 0) | |
527 { | |
528 divisor.deco_ndl = smallHeader.deco_ndlDivisor - 1; | |
529 | |
530 if(stateUsed->diveSettings.deco_type.ub.standard == GF_MODE) | |
531 pDecoinfo = &stateUsed->decolistBuehlmann; | |
532 else if(stateUsed->diveSettings.deco_type.ub.standard == VPM_MODE) | |
533 pDecoinfo = &stateUsed->decolistVPM; | |
534 else // should not happen as only GF and VPM at the moment | |
535 { | |
536 sample[length] = 0; | |
537 length += 1; | |
538 sample[length] = 0; | |
539 length += 1; | |
458 | 540 pDecoinfo = &stateUsed->decolistBuehlmann; /* use GF per default if something went wrong */ |
38 | 541 } |
542 | |
543 if(pDecoinfo->output_ndl_seconds > 0) | |
544 { | |
545 sample[length] = 0; | |
546 length += 1; | |
283
04cdeff80254
Bugfix: write NDL in logbook correctly
Jan Mulder <jlmulder@xs4all.nl>
parents:
281
diff
changeset
|
547 sample[length] = (uint8_t)(pDecoinfo->output_ndl_seconds / 60); |
281 | 548 |
549 // Limit stored sample within 0 to 240 mins (Since it's 8bit UINT only) | |
550 if ((pDecoinfo->output_ndl_seconds / 60) > 240) sample[length] = 240; | |
551 if ((pDecoinfo->output_ndl_seconds / 60) < 0) sample[length] = 0; | |
552 | |
38 | 553 length += 1; |
554 } | |
555 else if(pDecoinfo->output_time_to_surface_seconds) | |
556 { | |
557 tHome_findNextStop(pDecoinfo->output_stop_length_seconds, &nextstopDepthMeter, &nextstopLengthSeconds); | |
558 nextstopLengthMinutes = (nextstopLengthSeconds +59 ) / 60; | |
559 | |
560 sample[length] = nextstopDepthMeter; | |
561 length += 1; | |
562 sample[length] = nextstopLengthMinutes; | |
563 length += 1; | |
564 } | |
565 else | |
566 { | |
567 sample[length] = 0; | |
568 length += 1; | |
569 sample[length] = 0; | |
570 length += 1; | |
571 } | |
572 } | |
573 else | |
574 { | |
575 divisor.deco_ndl --; | |
576 } | |
577 } | |
578 | |
579 | |
580 if(smallHeader.ppo2Divisor) | |
581 { | |
582 if(divisor.ppo2 == 0) | |
583 { | |
584 divisor.ppo2 = smallHeader.ppo2Divisor - 1; | |
585 | |
586 for(int i = 0; i <3; i++) | |
587 { | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
588 sample[length] = (uint8_t)(state->lifeData.ppO2Sensor_bar[i] * 100.0f + 0.5f); |
38 | 589 length += 1; |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
590 addU16(&sample[length], (uint16_t)(state->lifeData.sensorVoltage_mV[i] * 10.0f + 0.5f)); |
38 | 591 length += 2; |
592 } | |
593 } | |
594 else | |
595 { | |
596 divisor.ppo2--; | |
597 } | |
598 } | |
599 | |
600 | |
601 if(smallHeader.decoplanDivisor) | |
602 { | |
603 if(divisor.decoplan == 0) | |
604 { | |
605 divisor.decoplan = smallHeader.decoplanDivisor - 1; | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
606 if(state->diveSettings.deco_type.ub.standard == VPM_MODE) |
38 | 607 { |
608 for(int i = 0; i <15; i++) | |
609 { | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
610 sample[length] = state->decolistVPM.output_stop_length_seconds[i] / 60; |
38 | 611 length += 1; |
612 } | |
613 } | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
614 else if(state->diveSettings.deco_type.ub.standard == GF_MODE) |
38 | 615 { |
616 for(int i = 0; i <15; i++) | |
617 { | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
618 sample[length] = state->decolistBuehlmann.output_stop_length_seconds[i] / 60; |
38 | 619 length += 1; |
620 } | |
621 } | |
622 else | |
623 { | |
624 for(int i = 0; i <15; i++) | |
625 { | |
626 sample[length] = 0; | |
627 length += 1; | |
628 } | |
629 } | |
630 // add16(&sample[length], state.temperature); | |
631 //length += 2; | |
632 } | |
633 else | |
634 { | |
635 divisor.decoplan --; | |
636 } | |
637 } | |
638 if(divisor.cns == 0) | |
639 { | |
640 divisor.cns = smallHeader.cnsDivisor - 1; | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
641 addU16(&sample[length], (uint16_t)state->lifeData.cns); |
38 | 642 length += 2; |
643 } | |
644 else | |
645 { | |
646 divisor.cns--; | |
647 } | |
648 | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
649 #ifdef ENABLE_BOTTLE_SENSOR |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
650 if(smallHeader.tankDivisor) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
651 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
652 if(divisor.tank == 0) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
653 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
654 divisor.tank = smallHeader.tankDivisor - 1; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
655 addS16(&sample[length], ((state->lifeData.bottle_bar[state->lifeData.actualGas.GasIdInSettings]))); |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
656 length += smallHeader.tankLength; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
657 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
658 else |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
659 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
660 divisor.tank--; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
661 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
662 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
663 #endif |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
664 |
38 | 665 profileByteFlag.uw = length - 3; |
666 if(eventByte1.uw) | |
667 { | |
668 profileByteFlag.ub.bit7 = 1; | |
669 } | |
670 sample[2] = profileByteFlag.uw; | |
671 logbook_writedata((void *) sample,length); | |
672 | |
673 } | |
674 | |
675 /** | |
676 ****************************************************************************** | |
677 * @brief readSample. / Reads data of one logbook sample | |
281 | 678 * @author heinrichs weikamp |
38 | 679 * @version V0.0.1 |
680 * @date 22-April-2014 | |
681 ****************************************************************************** | |
682 * | |
683 * @param int32_t* depth: output Value | |
684 * @param int16_t * gasid: output Value | |
685 * @param int32_t* temperature: output Value | |
686 * @param int32_t* sensor1, sensor2, sensor3: output Value | |
687 * @param int32_t* cns: output Value | |
688 * @return bytes read / 0 = reading Error | |
689 */ | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
690 static uint16_t readSample(int32_t* depth, int16_t * gasid, int16_t* setpoint_cbar, int32_t* temperature, int32_t* sensor1, int32_t* sensor2, |
610 | 691 int32_t* sensor3, int32_t* cns, SManualGas* manualGas, int16_t* bailout, int16_t* decostopDepth, uint16_t* tank, uint8_t* event) |
38 | 692 { |
693 int length = 0; | |
694 _Bool bEvent = 0; | |
695 bit8_Type eventByte1, eventByte2; | |
696 bit8_Type profileByteFlag; | |
697 | |
698 eventByte1.uw = 0; | |
699 eventByte2.uw = 0; | |
700 uint8_t tempU8 = 0; | |
701 uint16_t temp = 0; | |
702 uint16_t bytesRead = 0; | |
703 | |
704 if(gasid) | |
705 *gasid = -1; | |
706 if(temperature) | |
707 *temperature = -1000; | |
708 if(sensor1) | |
709 *sensor1 = -1; | |
710 if(sensor2) | |
711 *sensor2 = -1; | |
712 if(sensor3) | |
713 *sensor3 = -1; | |
714 if(cns) | |
715 *cns = -1; | |
716 if(setpoint_cbar) | |
717 *setpoint_cbar = -1; | |
718 if(bailout) | |
719 *bailout = -1; | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
720 if(tank) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
721 *tank = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
722 |
38 | 723 if(manualGas) |
724 { | |
725 manualGas->percentageO2 =-1; | |
726 manualGas->percentageHe =-1; | |
727 } | |
728 if(decostopDepth) | |
729 *decostopDepth = -1; | |
730 | |
731 ext_flash_read_next_sample_part( (uint8_t*)&temp, 2); | |
732 if(depth) | |
733 *depth = (int32_t)temp; | |
734 bytesRead += 2; | |
735 | |
736 ext_flash_read_next_sample_part( &profileByteFlag.uw, 1); | |
737 bytesRead ++; | |
738 | |
739 bEvent = profileByteFlag.ub.bit7; | |
740 profileByteFlag.ub.bit7 = 0; | |
741 length = profileByteFlag.uw; | |
742 | |
743 if(bEvent) | |
744 { | |
745 ext_flash_read_next_sample_part( &eventByte1.uw, 1); | |
746 bytesRead ++; | |
747 | |
748 length--; | |
749 | |
610 | 750 /* marker */ |
617
4eba86129d35
Development bugfix: Low battery warning was interpretated as marker:
Ideenmodellierer
parents:
610
diff
changeset
|
751 if((eventByte1.ub.bit1 && eventByte1.ub.bit2 && !eventByte1.ub.bit0) && (event != NULL)) /* 3 lsb low bit means battery low */ |
610 | 752 { |
753 *event = 1; | |
754 } | |
755 | |
38 | 756 //second event byte |
757 if(eventByte1.ub.bit7) | |
610 | 758 { |
759 ext_flash_read_next_sample_part( &eventByte2.uw, 1); | |
760 bytesRead ++; | |
761 length--; | |
762 } | |
38 | 763 else |
764 { | |
765 eventByte2.uw = 0; | |
766 } | |
767 | |
768 //manual Gas Set | |
610 | 769 if( eventByte1.ub.bit4) |
38 | 770 { |
771 //Evaluate manual Gas | |
610 | 772 ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1); |
773 bytesRead +=1; | |
774 length -= 1; | |
775 manualGas->percentageO2 = tempU8; | |
776 ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1); | |
777 bytesRead +=1; | |
778 length -= 1; | |
779 manualGas->percentageHe = tempU8; | |
780 if(gasid) *gasid = 0; | |
38 | 781 } |
782 //gas change | |
783 if( eventByte1.ub.bit5) | |
784 { | |
785 ext_flash_read_next_sample_part( &tempU8, 1); | |
786 bytesRead +=1; | |
787 length -= 1; | |
788 if(gasid) | |
789 *gasid = (uint16_t)tempU8; | |
790 } | |
791 //SetpointChange | |
792 if( eventByte1.ub.bit6) | |
793 { | |
794 ext_flash_read_next_sample_part( &tempU8, 1); | |
795 *setpoint_cbar = tempU8; | |
796 bytesRead +=1; | |
797 length -= 1; | |
798 } | |
799 | |
800 // second event Byte | |
801 //bailout | |
298
50c26a4442af
Bugfix: fix drawing of CCR bailout profile
Jan Mulder <jlmulder@xs4all.nl>
parents:
283
diff
changeset
|
802 if(eventByte2.ub.bit0) |
38 | 803 { |
804 //evaluate bailout gas Gas | |
805 *bailout = 1; | |
806 | |
807 ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1); | |
808 bytesRead +=1; | |
809 length -= 1; | |
810 manualGas->percentageO2 = tempU8; | |
811 ext_flash_read_next_sample_part( (uint8_t*)&tempU8, 1); | |
812 bytesRead +=1; | |
813 length -= 1; | |
814 manualGas->percentageHe = tempU8; | |
815 | |
816 if(gasid) | |
817 *gasid = 0; | |
818 } | |
819 } | |
820 | |
821 if(divisor.temperature == 0) | |
822 { | |
823 divisor.temperature = smallHeader.tempDivisor - 1; | |
824 ext_flash_read_next_sample_part( (uint8_t*)&temp, 2); | |
825 bytesRead +=2; | |
826 length -= 2; | |
827 if(temperature) | |
828 { | |
829 *temperature = (int32_t)temp; | |
830 } | |
831 } | |
832 else | |
833 { | |
834 divisor.temperature--; | |
835 } | |
836 | |
837 if(smallHeader.deco_ndlDivisor > 0) | |
838 { | |
839 if(divisor.deco_ndl == 0) | |
840 { | |
841 divisor.deco_ndl = smallHeader.deco_ndlDivisor - 1; | |
842 ext_flash_read_next_sample_part( &tempU8, 1); | |
843 if(decostopDepth) | |
844 { | |
845 *decostopDepth = tempU8 * 100; | |
846 } | |
847 ext_flash_read_next_sample_part( &tempU8, 1); | |
848 bytesRead += 2; | |
849 length -= 2; | |
850 } | |
851 else | |
852 { | |
853 divisor.deco_ndl--; | |
854 } | |
855 } | |
856 | |
857 if(divisor.ppo2 == 0) | |
858 { | |
859 int32_t ppO2Tmp = 0; | |
860 divisor.ppo2 = smallHeader.ppo2Divisor -1; | |
861 for(int i = 0; i <3 ; i++) | |
862 { | |
863 ext_flash_read_next_sample_part( &tempU8, 1); | |
864 ppO2Tmp += tempU8; | |
865 bytesRead +=1; | |
866 length -= 1; | |
867 ext_flash_read_next_sample_part( (uint8_t*)&temp, 2); | |
868 bytesRead +=2; | |
869 length -= 2; | |
870 if(sensor1 && (i==0)) | |
871 *sensor1 = (((int32_t)tempU8) * 0xFFFF) + temp; | |
872 if(sensor2 && (i==1)) | |
873 *sensor2 = (((int32_t)tempU8) * 0xFFFF) + temp; | |
874 if(sensor3 && (i==2)) | |
875 *sensor3 = (((int32_t)tempU8) * 0xFFFF) + temp; | |
876 } | |
877 } | |
878 else | |
879 { | |
880 divisor.ppo2--; | |
881 } | |
882 | |
883 if(smallHeader.decoplanDivisor > 0) | |
884 { | |
885 if(divisor.decoplan == 0) | |
886 { | |
887 divisor.decoplan = smallHeader.decoplanDivisor - 1; | |
888 for(int i = 0; i <15; i++) | |
889 ext_flash_read_next_sample_part( &tempU8, 1); | |
890 bytesRead += 15; | |
891 length -= 15; | |
892 } | |
893 else | |
894 { | |
895 divisor.decoplan--; | |
896 } | |
897 } | |
898 | |
899 | |
900 | |
901 if(divisor.cns == 0) | |
902 { | |
903 divisor.cns = smallHeader.cnsDivisor - 1; | |
904 | |
905 ext_flash_read_next_sample_part( (uint8_t*)&temp, 2); | |
906 bytesRead +=2; | |
907 length -= 2; | |
908 if(cns) | |
909 { | |
910 *cns = (int32_t)temp; | |
911 } | |
912 } | |
913 else | |
914 { | |
915 divisor.cns--; | |
916 } | |
917 | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
918 if(smallHeader.tankDivisor) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
919 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
920 if(divisor.tank == 0) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
921 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
922 divisor.tank = smallHeader.tankDivisor - 1; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
923 ext_flash_read_next_sample_part( (uint8_t*)&temp, 2); |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
924 bytesRead +=2; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
925 length -= 2; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
926 if(tank) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
927 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
928 *tank = (uint16_t)temp; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
929 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
930 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
931 else |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
932 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
933 divisor.tank--; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
934 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
935 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
936 |
38 | 937 if (length != 0) |
938 return 0; | |
939 | |
940 return bytesRead; | |
941 } | |
942 /** | |
943 ****************************************************************************** | |
944 * @brief logbook_readSampleData. / Reads sample data of whole logbook entry | |
281 | 945 * @author heinrichs weikamp |
38 | 946 * @version V0.0.1 |
947 * @date 22-April-2014 | |
948 ****************************************************************************** | |
949 * | |
950 * @param uint8_t StepBackwards: witch lookbook entry? | |
951 * @param uint16_t length : maxlength of output arrays | |
952 * @param int32_t* depth : output array | |
953 * @param int16_t * gasid : output array | |
954 * @param int32_t* temperature : output array | |
955 * @param int32_t* ppo2 : output array | |
956 * @param int32_t* cns : output array | |
957 * @return length of output | |
958 */ | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
959 uint16_t logbook_readSampleData(uint8_t StepBackwards, uint16_t length,uint16_t* depth, uint8_t* gasid, int16_t* temperature, uint16_t* ppo2, |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
960 uint16_t* setpoint, uint16_t* sensor1, uint16_t* sensor2, uint16_t* sensor3, uint16_t* cns, uint8_t* bailout, |
610 | 961 uint16_t* decostopDepth, uint16_t* tank, uint8_t* event) |
38 | 962 { |
963 //Test read | |
964 //SLogbookHeader header; | |
965 | |
966 //logbook_getHeader(&header); | |
967 SLogbookHeader header; | |
458 | 968 int16_t iNum; |
969 int16_t firstgasid = 0; | |
970 uint16_t retVal = 0; | |
971 int16_t compression = 0; | |
972 int16_t i; | |
38 | 973 // uint32_t diveTime_seconds; |
974 int32_t depthVal = 0; | |
975 int16_t gasidVal = 0; | |
976 int16_t setPointVal = 0; | |
977 int16_t bailoutVal = 0; | |
978 int16_t bailoutLast = 0; | |
979 uint16_t setPointLast = 0; | |
980 int32_t temperatureVal = 0; | |
981 int32_t sensor1Val = 0; | |
982 int32_t sensor2Val = 0; | |
983 int32_t sensor3Val = 0; | |
984 int32_t sensor1Last = 0; | |
985 int32_t sensor2Last = 0; | |
986 int32_t sensor3Last = 0; | |
987 int32_t cnsVal = 0; | |
988 int32_t depthLast = 0; | |
989 int16_t gasidLast = 0; | |
990 int32_t temperatureLast = 0; | |
991 int32_t temperatureFirst = 0; | |
992 int32_t cnsLast = 0; | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
993 int16_t decostepDepthVal = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
994 int16_t decostepDepthLast = 0; |
457 | 995 uint16_t tankVal = 0; |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
996 uint32_t small_profileLength = 0; |
610 | 997 uint8_t eventdata; |
38 | 998 |
999 SManualGas manualGasVal; | |
1000 SManualGas manualGasLast; | |
1001 manualGasLast.percentageO2 = 0; | |
1002 manualGasLast.percentageHe = 0; | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1003 uint16_t numSamples = 0; |
38 | 1004 |
1005 float ambiant_pressure_bar = 0; | |
1006 float ppO2 = 0; | |
1007 ext_flash_read_dive_header((uint8_t*)&header, StepBackwards); | |
1008 for(i = 0;i< 5;i++) | |
1009 { | |
1010 if(header.gasordil[i].note.ub.first) | |
1011 break; | |
1012 } | |
1013 firstgasid = i + 1; | |
662 | 1014 if(isLoopMode(header.diveMode)) |
38 | 1015 setPointLast = header.setpoint[0].setpoint_cbar; |
1016 else | |
1017 setPointLast = 0; | |
1018 //diveTime_seconds = header.diveTime_seconds ; | |
1019 for(compression = 1; compression < 100; compression ++) | |
1020 { | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1021 numSamples = (header.total_diveTime_seconds / header.samplingRate)/compression; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1022 if(numSamples <= length) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1023 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1024 break; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1025 } |
38 | 1026 } |
1027 | |
1028 | |
1029 for(i = 0;i< length;i++) | |
1030 { | |
1031 if(depth) | |
1032 depth[i] = 0; | |
1033 if(temperature) | |
1034 temperature[i] = 0; | |
1035 if(gasid) | |
1036 gasid[i] = 0; | |
1037 if(ppo2) | |
1038 ppo2[i] = 0; | |
1039 if(setpoint) | |
1040 setpoint[i] = 0; | |
1041 if(sensor1) | |
1042 sensor1[i] = 0; | |
1043 if(sensor2) | |
1044 sensor2[i] = 0; | |
1045 if(sensor3) | |
1046 sensor3[i] = 0; | |
1047 if(cns) | |
1048 cns[i] = 0; | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1049 if(tank) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1050 tank[i] = 0; |
38 | 1051 } |
1052 //We start with fist gasid | |
1053 gasidLast = firstgasid; | |
1054 | |
1055 | |
1056 //uint16_t* ppo2, uint16_t* cns# | |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1057 uint32_t totalNumberOfBytes = 0; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1058 uint32_t bytesRead = 0; |
38 | 1059 ext_flash_open_read_sample( StepBackwards,&totalNumberOfBytes); |
1060 ext_flash_read_next_sample_part((uint8_t*)&smallHeader, sizeof(SSmallHeader)); | |
1061 bytesRead += sizeof(SSmallHeader); | |
1062 | |
1063 clear_divisor(); | |
1064 | |
1065 iNum = 0; | |
1066 int counter = 0; | |
1067 temperatureLast = -1000; | |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1068 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1069 small_profileLength = (smallHeader.profileLength[2] << 16) + (smallHeader.profileLength[1] << 8) + smallHeader.profileLength[0]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1070 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1071 if(totalNumberOfBytes == small_profileLength) /* sizes provided by header and small header are the same => real data */ |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1072 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1073 while ((bytesRead < totalNumberOfBytes) && (iNum < length)) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1074 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1075 ext_flash_set_entry_point(); |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1076 divisorBackup = divisor; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1077 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, |
610 | 1078 &bailoutVal, &decostepDepthVal, &tankVal, &eventdata); |
38 | 1079 |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1080 if(retVal == 0) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1081 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1082 //Error try to read again!!! |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1083 ext_flash_reopen_read_sample_at_entry_point(); |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1084 divisor = divisorBackup; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1085 retVal = readSample(&depthVal,&gasidVal,&setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, |
610 | 1086 &manualGasVal, &bailoutVal, &decostepDepthVal, &tankVal, &eventdata); |
38 | 1087 |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1088 if(retVal == 0) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1089 break; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1090 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1091 bytesRead +=retVal; |
38 | 1092 |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1093 //if for some variable no new value is in the sample for (z.B. gasidVal = -1), we take the last value |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1094 if(depthVal == -1) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1095 depthVal = depthLast; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1096 else |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1097 depthLast = depthVal; |
38 | 1098 |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1099 if(gasidVal == -1) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1100 gasidVal = gasidLast; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1101 else |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1102 gasidLast = gasidVal; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1103 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1104 if(temperatureVal == -1000) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1105 temperatureVal = temperatureLast; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1106 else |
38 | 1107 { |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1108 if(temperatureLast == -1000) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1109 temperatureFirst = temperatureVal; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1110 temperatureLast = temperatureVal; |
38 | 1111 } |
1112 | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1113 if(setPointVal == -1) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1114 setPointVal = setPointLast; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1115 else |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1116 setPointLast = setPointVal; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1117 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1118 if(sensor1Val == -1) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1119 sensor1Val = sensor1Last; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1120 else |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1121 sensor1Last = sensor1Val; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1122 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1123 if(sensor2Val == -1) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1124 sensor2Val = sensor2Last; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1125 else |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1126 sensor2Last = sensor2Val; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1127 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1128 if(sensor3Val == -1) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1129 sensor3Val = sensor3Last; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1130 else |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1131 sensor3Last = sensor3Val; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1132 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1133 if(cnsVal == -1) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1134 cnsVal = cnsLast; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1135 else |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1136 cnsLast = cnsVal; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1137 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1138 if(manualGasVal.percentageO2 == -1) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1139 manualGasVal = manualGasLast; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1140 else |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1141 manualGasLast = manualGasVal; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1142 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1143 if(bailoutVal == -1) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1144 bailoutVal = bailoutLast; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1145 else |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1146 bailoutLast = bailoutVal; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1147 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1148 if(decostepDepthVal == -1) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1149 decostepDepthVal = decostepDepthLast; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1150 else |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1151 decostepDepthLast = decostepDepthVal; |
38 | 1152 |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1153 counter++; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1154 // Heed compression |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1155 // Write here to arrays |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1156 if(counter == compression) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1157 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1158 if(depth) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1159 depth[iNum] = depthVal; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1160 if(gasid) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1161 gasid[iNum] = gasidVal; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1162 if(temperature) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1163 temperature[iNum] = temperatureVal; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1164 if(cns) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1165 cns[iNum] = cnsVal; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1166 if(bailout) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1167 bailout[iNum] = bailoutVal; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1168 if(decostopDepth) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1169 decostopDepth[iNum] = decostepDepthVal; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1170 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1171 if(ppo2) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1172 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1173 //Calc ppo2 - Values |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1174 SGas gas; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1175 gas.setPoint_cbar = setPointVal; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1176 if(gasidVal > 0) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1177 { |
662 | 1178 if((gasidVal >= NUM_GASES) && (header.diveMode == DIVEMODE_PSCR)) /* in case gas switches the absolute gas ID is used => map to the 0..NUM_GASES index used in header */ |
1179 { | |
1180 gasidVal -= NUM_GASES; | |
1181 } | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1182 gas.helium_percentage = header.gasordil[gasidVal - 1].helium_percentage; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1183 gas.nitrogen_percentage = 100 - gas.helium_percentage - header.gasordil[gasidVal - 1].oxygen_percentage; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1184 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1185 else |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1186 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1187 gas.helium_percentage = manualGasVal.percentageHe; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1188 gas.nitrogen_percentage = 100 - gas.helium_percentage - manualGasVal.percentageO2; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1189 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1190 ambiant_pressure_bar =((float)(depthVal + header.surfacePressure_mbar))/1000; |
662 | 1191 |
1192 if(header.diveMode == DIVEMODE_PSCR) | |
1193 { | |
1194 ppO2 = decom_calc_SimppO2(ambiant_pressure_bar, &gas); | |
1195 } | |
1196 else /* open circuit calculation */ | |
1197 { | |
1198 ppO2 = decom_calc_ppO2(ambiant_pressure_bar, &gas); | |
1199 } | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1200 ppo2[iNum] = (uint16_t) ( ppO2 * 100); |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1201 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1202 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1203 if(tank) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1204 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1205 tank[iNum] = tankVal; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1206 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1207 if(setpoint) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1208 setpoint[iNum] = setPointVal; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1209 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1210 if(sensor1) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1211 sensor1[iNum] = (sensor1Val / 0xFFFF) & 0xFF; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1212 if(sensor2) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1213 sensor2[iNum] = (sensor2Val / 0xFFFF) & 0xFF; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1214 if(sensor3) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1215 sensor3[iNum] = (sensor3Val / 0xFFFF) & 0xFF; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1216 iNum++; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1217 counter = 0; |
610 | 1218 |
1219 if(event) | |
1220 { | |
1221 event[iNum] = eventdata; | |
1222 eventdata = 0; | |
1223 } | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1224 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1225 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1226 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1227 else |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1228 { |
458 | 1229 logbook_createDummyProfile(&header, numSamples, depth, temperature, ppo2); |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1230 iNum = numSamples; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1231 } |
38 | 1232 |
1233 // Fix first Temperature Entries 150930 hw | |
1234 if(temperature) | |
1235 { | |
1236 int i = 0; | |
1237 while((temperature[i] == -1000) && (i < iNum)) | |
1238 temperature[i++] = temperatureFirst; | |
1239 } | |
1240 | |
1241 ext_flash_close_read_sample(); | |
1242 return iNum; | |
1243 } | |
1244 | |
1245 | |
1246 /******************************************************************************** | |
1247 * @brief logbook_InitAndWrite. / Controls writing of logbook | |
1248 * Should be called ten times per second | |
1249 * Automatically Initializes logbook at beginning of dive, | |
1250 * write samples every 2 seconds | |
1251 * and finishes logbook after end of dive | |
1252 *********************************************************************************/ | |
1253 | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1254 void logbook_InitAndWrite(const SDiveState *pStateReal) |
38 | 1255 { |
1256 SSettings *pSettings = settingsGetPointer(); | |
1257 static uint8_t bDiveMode = 0; | |
1258 static uint32_t tickstart = 0; | |
1259 uint32_t ticksdiff = 0; | |
1260 uint32_t lasttick = 0; | |
1261 static float min_temperature_float_celsius = 0; | |
1262 | |
1263 if(!bDiveMode) | |
1264 { | |
1265 if((pStateReal->mode == MODE_DIVE) && (pStateReal->diveSettings.diveMode != DIVEMODE_Apnea) && (pStateReal->lifeData.dive_time_seconds >= 5)) | |
1266 { | |
1267 //InitdiveProfile | |
1268 pSettings->totalDiveCounter++; | |
1269 logbook_initNewdiveProfile(pStateReal,settingsGetPointer()); | |
1270 min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius; | |
1271 //Write logbook sample | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1272 logbook_writeSample(pStateReal); |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1273 resetEvents(pStateReal); |
38 | 1274 tickstart = HAL_GetTick(); |
1275 bDiveMode = 1; | |
1276 } | |
1277 } | |
1278 else if((pStateReal->mode == MODE_DIVE) && (pStateReal->diveSettings.diveMode != DIVEMODE_Apnea)) | |
1279 { | |
1280 lasttick = HAL_GetTick(); | |
1281 ticksdiff = time_elapsed_ms(tickstart,lasttick); | |
1282 // | |
1283 if(ticksdiff >= 2000) | |
1284 { | |
1285 //Write logbook sample | |
269
6e78137952af
cleanup: do not pass large struct by value
Jan Mulder <jlmulder@xs4all.nl>
parents:
225
diff
changeset
|
1286 logbook_writeSample(pStateReal); |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1287 resetEvents(pStateReal); |
38 | 1288 if(min_temperature_float_celsius > pStateReal->lifeData.temperature_celsius) |
1289 min_temperature_float_celsius = pStateReal->lifeData.temperature_celsius; | |
1290 tickstart = lasttick; | |
1291 if((bDiveMode == 1) && (pStateReal->lifeData.dive_time_seconds >= pSettings->divetimeToCreateLogbook)) | |
1292 { | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1293 ext_flash_create_new_dive_log((uint8_t*)&gheader); |
38 | 1294 /** save settings |
1295 * with new lastDiveLogId and time and day | |
1296 */ | |
1297 pSettings->personalDiveCount++; | |
1298 if(pSettings->logbookOffset) | |
1299 { | |
1300 pSettings->logbookOffset++; | |
1301 } | |
427 | 1302 ext_flash_write_settings(0); |
38 | 1303 ext_flash_disable_protection_for_logbook(); |
426
514e6269256f
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
411
diff
changeset
|
1304 |
514e6269256f
Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents:
411
diff
changeset
|
1305 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 | 1306 bDiveMode = 3; |
1307 } | |
1308 if(bDiveMode == 3) | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1309 logbook_UpdateHeader(pStateReal); |
38 | 1310 } |
1311 } | |
1312 else if(bDiveMode == 3) | |
1313 { | |
1314 //End of Dive | |
1315 logbook_SetAverageDepth(pStateReal->lifeData.average_depth_meter); | |
1316 logbook_SetMinTemperature(min_temperature_float_celsius); | |
1317 logbook_SetMaxCNS(pStateReal->lifeData.cns); | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1318 logbook_SetCompartmentDesaturation(pStateReal); |
38 | 1319 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
|
1320 gheader.batteryVoltage = pStateReal->lifeData.battery_voltage * 1000; |
671
b456be1e152d
Support of unknown charging counter values:
Ideenmodellierer
parents:
662
diff
changeset
|
1321 if(pStateReal->lifeData.battery_charge > 0.0) |
b456be1e152d
Support of unknown charging counter values:
Ideenmodellierer
parents:
662
diff
changeset
|
1322 { |
b456be1e152d
Support of unknown charging counter values:
Ideenmodellierer
parents:
662
diff
changeset
|
1323 gheader.batteryCharge = pStateReal->lifeData.battery_charge; |
b456be1e152d
Support of unknown charging counter values:
Ideenmodellierer
parents:
662
diff
changeset
|
1324 } |
b456be1e152d
Support of unknown charging counter values:
Ideenmodellierer
parents:
662
diff
changeset
|
1325 else |
b456be1e152d
Support of unknown charging counter values:
Ideenmodellierer
parents:
662
diff
changeset
|
1326 { |
b456be1e152d
Support of unknown charging counter values:
Ideenmodellierer
parents:
662
diff
changeset
|
1327 gheader.batteryCharge = 0.0; |
b456be1e152d
Support of unknown charging counter values:
Ideenmodellierer
parents:
662
diff
changeset
|
1328 } |
38 | 1329 logbook_EndDive(); |
1330 bDiveMode = 0; | |
1331 } else | |
1332 { | |
1333 ext_flash_enable_protection(); | |
1334 } | |
1335 } | |
1336 | |
1337 | |
1338 /* Private functions ---------------------------------------------------------*/ | |
1339 | |
1340 /******************************************************************************** | |
1341 * @brief logbook_UpdateHeader. / | |
1342 * set date, time, max depth. etc. pp. | |
1343 * the internal pointer to the end of profile and length will be set by | |
1344 ext_flash_close_new_dive_log() in externLogbookFlash.c | |
1345 * @author heinrichs weikamp gmbh | |
1346 * @version V0.0.1 | |
1347 * @date 27-Nov-2014 | |
1348 *********************************************************************************/ | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1349 static void logbook_UpdateHeader(const SDiveState *pStateReal) |
38 | 1350 { |
1351 // uint16_t secondsAtShallow = 0; | |
1352 RTC_DateTypeDef Sdate; | |
1353 RTC_TimeTypeDef Stime; | |
1354 uint32_t time1_u32, time2_u32; | |
1355 uint32_t divetimeHelper; | |
1356 | |
1357 /* time and day */ | |
1358 /* don't update CHANGE 160224 hw, maybe save actual time and date at other place | |
1359 translateDate(pStateReal->lifeData.dateBinaryFormat, &Sdate); | |
1360 translateTime(pStateReal->lifeData.timeBinaryFormat, &Stime); | |
1361 | |
1362 header.dateYear = Sdate.Year; | |
1363 header.dateMonth = Sdate.Month; | |
1364 header.dateDay = Sdate.Date; | |
1365 header.timeHour = Stime.Hours; | |
1366 header.timeMinute = Stime.Minutes; | |
1367 */ | |
1368 /// 160315 Quick fix for empty date problem | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1369 if((!(gheader.dateYear)) || (!(gheader.dateMonth)) || (!(gheader.dateDay))) |
38 | 1370 { |
1371 translateDate(pStateReal->lifeData.dateBinaryFormat, &Sdate); | |
1372 translateTime(pStateReal->lifeData.timeBinaryFormat, &Stime); | |
1373 | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1374 gheader.dateYear = Sdate.Year; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1375 gheader.dateMonth = Sdate.Month; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1376 gheader.dateDay = Sdate.Date; |
38 | 1377 |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1378 time1_u32 = (uint32_t)gheader.timeMinute + (uint32_t)(gheader.timeHour * 60); |
38 | 1379 time2_u32 = (uint32_t)Stime.Minutes + (uint32_t)(Stime.Hours * 60); |
1380 if(time2_u32 < time1_u32) | |
1381 { | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1382 if(gheader.dateDay > 1) |
38 | 1383 { |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1384 gheader.dateDay -= 1; |
38 | 1385 } |
1386 else | |
1387 { | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1388 gheader.dateMonth --; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1389 if(!gheader.dateMonth) |
38 | 1390 { |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1391 gheader.dateYear--; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1392 gheader.dateMonth = 12; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1393 gheader.dateDay = 31; |
38 | 1394 } |
1395 else | |
1396 { | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1397 if(gheader.dateMonth == 2) |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1398 gheader.dateDay = 28; |
38 | 1399 else |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1400 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
|
1401 gheader.dateDay = 30; |
38 | 1402 else |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1403 gheader.dateDay = 31; |
38 | 1404 } |
1405 } | |
1406 } | |
1407 } | |
1408 | |
1409 /* duration */ | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1410 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
|
1411 gheader.maxDepth = pStateReal->lifeData.max_depth_meter * 100; |
38 | 1412 |
1413 /* old: | |
1414 | |
1415 secondsAtShallow = pSettings->timeoutDiveReachedZeroDepth; | |
1416 if(pStateReal->lifeData.dive_time_seconds <= secondsAtShallow) | |
1417 secondsAtShallow = 0; | |
1418 header.diveTimeMinutes = (header.total_diveTime_seconds - secondsAtShallow )/ 60; | |
1419 header.diveTimeSeconds = header.total_diveTime_seconds - secondsAtShallow - (header.diveTimeMinutes * 60); | |
1420 */ | |
1421 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
|
1422 gheader.diveTimeMinutes = (uint16_t)(divetimeHelper/60); |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1423 divetimeHelper -= 60 * (uint32_t)gheader.diveTimeMinutes; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1424 gheader.diveTimeSeconds = (uint16_t)divetimeHelper; |
38 | 1425 |
1426 /* deco algorithm (final) */ | |
1427 if(pStateReal->diveSettings.deco_type.ub.standard == GF_MODE) | |
1428 { | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1429 gheader.decoModel = 1; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1430 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
|
1431 gheader.gfHigh = pStateReal->diveSettings.gf_high; |
38 | 1432 } |
1433 else | |
1434 { | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1435 gheader.decoModel = 2; |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1436 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
|
1437 gheader.gfHigh = 0; |
38 | 1438 } |
1439 | |
1440 /* tissue load */ | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1441 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
|
1442 memcpy(gheader.heCompartments, pStateReal->lifeData.tissue_helium_bar, 64); |
38 | 1443 |
1444 } | |
1445 | |
1446 | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
1447 static void logbook_SetAverageDepth(float average_depth_meter) |
38 | 1448 { |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1449 gheader.averageDepth_mbar = (uint16_t)(average_depth_meter * 100); |
38 | 1450 } |
1451 | |
1452 | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
1453 static void logbook_SetMinTemperature(float min_temperature_celsius) |
38 | 1454 { |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1455 gheader.minTemp = (int16_t)((min_temperature_celsius * 10.0f) + 0.5f); |
38 | 1456 } |
1457 | |
1458 | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
1459 static void logbook_SetMaxCNS(float max_cns_percentage) |
38 | 1460 { |
1461 if(max_cns_percentage < 9999) | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1462 gheader.maxCNS = (uint16_t)(max_cns_percentage); |
38 | 1463 else |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1464 gheader.maxCNS = 9999; |
38 | 1465 } |
1466 | |
1467 | |
270
2e58a4094770
feature, debug: make simulator write a logbook entry
Jan Mulder <jlmulder@xs4all.nl>
parents:
269
diff
changeset
|
1468 static void logbook_SetCompartmentDesaturation(const SDiveState * pStateReal) |
38 | 1469 { |
225
2bb1db22b5f5
cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents:
199
diff
changeset
|
1470 SLifeData2 secondaryInformation = { 0 }; |
38 | 1471 |
1472 decom_tissues_desaturation_time(&pStateReal->lifeData, &secondaryInformation); | |
1473 for(int i=0;i<16;i++) | |
1474 { | |
1475 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
|
1476 gheader.n2CompartDesatTime_min[i] = (uint8_t)((secondaryInformation.tissue_nitrogen_desaturation_time_minutes[i] + 14) / 15); |
38 | 1477 else |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1478 gheader.n2CompartDesatTime_min[i] = 255; |
38 | 1479 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
|
1480 gheader.heCompartDesatTime_min[i] = (uint8_t)((secondaryInformation.tissue_helium_desaturation_time_minutes[i] + 14 )/ 15); |
38 | 1481 else |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1482 gheader.heCompartDesatTime_min[i] = 255; |
38 | 1483 } |
1484 } | |
1485 | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
1486 static void logbook_SetLastStop(float last_stop_depth_bar) |
38 | 1487 { |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1488 gheader.lastDecostop_m = (uint8_t)(last_stop_depth_bar / 10.0f); |
38 | 1489 } |
1490 | |
194
f23b9055436f
cleanup: more trivial cleanup (logbook.c/h)
Jan Mulder <jlmulder@xs4all.nl>
parents:
149
diff
changeset
|
1491 static void logbook_writedata(void * data, int length_byte) |
38 | 1492 { |
1493 ext_flash_write_sample(data, length_byte); | |
1494 } | |
1495 | |
1496 /******************************************************************************** | |
1497 * @brief logbook_build_ostc3header. / | |
1498 * @author heinrichs weikamp gmbh | |
1499 * @version V0.0.2 | |
1500 * @date 27-Nov-2014 | |
1501 *********************************************************************************/ | |
1502 SLogbookHeaderOSTC3 * logbook_build_ostc3header(SLogbookHeader* pHead) | |
1503 { | |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1504 convert_Type data,data2; |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1505 uint16_t dummyLength = 0; |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1506 uint8_t returnEmptyHeader = 0; |
38 | 1507 |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1508 uint32_t headerProfileLength, sampleProfileLength, sampleProfileStart; |
38 | 1509 |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1510 |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1511 if(pHead->diveHeaderStart != 0xFAFA) |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1512 { |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1513 returnEmptyHeader = 1; |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1514 } |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1515 else |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1516 { |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1517 memcpy(headerOSTC3.diveHeaderStart, &pHead->diveHeaderStart, 2); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1518 memcpy(headerOSTC3.pBeginProfileData, &pHead->pBeginProfileData, 3); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1519 memcpy(headerOSTC3.pEndProfileData, &pHead->pEndProfileData, 3); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1520 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1521 data.u8bit.byteHigh = 0; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1522 data.u8bit.byteLow = pHead->pBeginProfileData[0]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1523 data.u8bit.byteMidLow = pHead->pBeginProfileData[1]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1524 data.u8bit.byteMidHigh = pHead->pBeginProfileData[2]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1525 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1526 sampleProfileStart = data.u32bit; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1527 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1528 data2.u8bit.byteHigh = 0; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1529 data2.u8bit.byteLow = pHead->pEndProfileData[0]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1530 data2.u8bit.byteMidLow = pHead->pEndProfileData[1]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1531 data2.u8bit.byteMidHigh = pHead->pEndProfileData[2]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1532 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1533 data.u8bit.byteHigh = 0; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1534 data.u8bit.byteLow = pHead->profileLength[0]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1535 data.u8bit.byteMidLow = pHead->profileLength[1]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1536 data.u8bit.byteMidHigh = pHead->profileLength[2]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1537 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1538 if(data.u32bit != 0xFFFFFF) /* if the profile in use ? */ |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1539 { |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1540 if(data2.u32bit < sampleProfileStart) /* Wrap around of sample ring detected */ |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1541 { |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1542 if(ext_flash_SampleOverrunValid() == 0) /* Wrap around does not seem to be valid => fallback */ |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1543 { |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1544 sampleProfileStart = 0; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1545 } |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1546 } |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1547 if( sampleProfileStart == 0) /* should never happen unless OSTC with older debug version is in use (or invalid overrun) */ |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1548 { |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1549 sampleProfileLength = 1; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1550 headerProfileLength = 2; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1551 } |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1552 else |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1553 { |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1554 headerProfileLength = (pHead->profileLength[2] << 16) + (pHead->profileLength[1] << 8) + pHead->profileLength[0]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1555 sampleProfileLength = ext_flash_read_profilelength_small_header(sampleProfileStart); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1556 } |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1557 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1558 if(sampleProfileLength != headerProfileLength) |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1559 { |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1560 dummyLength = logbook_fillDummySampleBuffer(pHead); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1561 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1562 data2.u32bit = sampleProfileStart + dummyLength; /* calc new end address (which is equal to dummyLength) */ |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1563 data.u32bit = dummyLength; /* data is used below to represent the length */ |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1564 } |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1565 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1566 data.u32bit += 3; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1567 headerOSTC3.profileLength[0] = data.u8bit.byteLow; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1568 headerOSTC3.profileLength[1] = data.u8bit.byteMidLow; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1569 headerOSTC3.profileLength[2] = data.u8bit.byteMidHigh; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1570 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1571 memcpy(headerOSTC3.gasordil, pHead->gasordil, 20); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1572 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1573 if(pHead->logbookProfileVersion == LOGBOOK_VERSION) |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1574 { |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1575 headerOSTC3.logbookProfileVersion = LOGBOOK_VERSION_OSTC3; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1576 memcpy(headerOSTC3.personalDiveCount, &pHead->personalDiveCount, 2); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1577 headerOSTC3.safetyDistance_10cm = 0; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1578 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1579 for(int i=0;i<5;i++) |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1580 { |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1581 if(!pHead->gasordil[i].note.ub.active) |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1582 headerOSTC3.gasordil[3 + (i*4)] = 0; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1583 else if(pHead->gasordil[i].note.ub.first) |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1584 { |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1585 /* depth = 0, note = 1 */ |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1586 headerOSTC3.gasordil[2 + (i*4)] = 0; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1587 headerOSTC3.gasordil[3 + (i*4)] = 1; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1588 } |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1589 else if( pHead->gasordil[i].depth_meter) |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1590 { |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1591 /* note = 3 */ |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1592 headerOSTC3.gasordil[3 + (i*4)] = 3; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1593 } |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1594 } |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1595 } |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1596 else |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1597 { |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1598 headerOSTC3.logbookProfileVersion = 0xFF; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1599 headerOSTC3.personalDiveCount[0] = 0xFF; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1600 headerOSTC3.personalDiveCount[1] = 0xFF; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1601 headerOSTC3.safetyDistance_10cm = 0xFF; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1602 } |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1603 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1604 headerOSTC3.dateYear = pHead->dateYear; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1605 headerOSTC3.dateMonth = pHead->dateMonth; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1606 headerOSTC3.dateDay = pHead->dateDay; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1607 headerOSTC3.timeHour = pHead->timeHour; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1608 headerOSTC3.timeMinute = pHead->timeMinute; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1609 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1610 memcpy(headerOSTC3.maxDepth, &pHead->maxDepth, 2); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1611 memcpy(headerOSTC3.diveTimeMinutes, &pHead->diveTimeMinutes, 2); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1612 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1613 headerOSTC3.diveTimeSeconds = pHead->diveTimeSeconds; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1614 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1615 memcpy(headerOSTC3.minTemp, &pHead->minTemp, 2); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1616 memcpy(headerOSTC3.surfacePressure_mbar,&pHead->surfacePressure_mbar, 2); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1617 memcpy(headerOSTC3.desaturationTime, &pHead->desaturationTime, 2); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1618 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1619 headerOSTC3.firmwareVersionHigh = pHead->firmwareVersionHigh; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1620 headerOSTC3.firmwareVersionLow = pHead->firmwareVersionLow; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1621 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1622 memcpy(headerOSTC3.batteryVoltage, &pHead->batteryVoltage, 2); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1623 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1624 headerOSTC3.samplingRate = pHead->samplingRate; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1625 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1626 memcpy(headerOSTC3.cnsAtBeginning, &pHead->cnsAtBeginning, 2); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1627 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1628 headerOSTC3.gfAtBeginning = pHead->gfAtBeginning; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1629 headerOSTC3.gfAtEnd = pHead->gfAtEnd; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1630 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1631 memcpy(headerOSTC3.setpoint, pHead->setpoint, 10); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1632 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1633 headerOSTC3.salinity = pHead->salinity; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1634 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1635 memcpy(headerOSTC3.maxCNS, &pHead->maxCNS, 2); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1636 memcpy(headerOSTC3.averageDepth_mbar, &pHead->averageDepth_mbar, 2); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1637 memcpy(headerOSTC3.total_diveTime_seconds, &pHead->total_diveTime_seconds, 2); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1638 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1639 headerOSTC3.gfLow_or_Vpm_conservatism = pHead->gfLow_or_Vpm_conservatism; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1640 headerOSTC3.gfHigh = pHead->gfHigh; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1641 headerOSTC3.decoModel = pHead->decoModel; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1642 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1643 memcpy(headerOSTC3.diveNumber, &pHead->diveNumber, 2); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1644 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1645 headerOSTC3.diveMode = pHead->diveMode; |
471
73da921869d9
bugfix: implement battery charge percentage in dive header
Jan Mulder <jlmulder@xs4all.nl>
parents:
465
diff
changeset
|
1646 headerOSTC3.batteryCharge = pHead->batteryCharge; |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1647 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1648 memcpy(headerOSTC3.n2CompartDesatTime_min,pHead->n2CompartDesatTime_min, 16); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1649 memcpy(headerOSTC3.n2Compartments, pHead->n2Compartments, 64); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1650 memcpy(headerOSTC3.heCompartDesatTime_min,pHead->heCompartDesatTime_min, 16); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1651 memcpy(headerOSTC3.heCompartments, pHead->heCompartments, 64); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1652 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1653 headerOSTC3.lastDecostop_m = pHead->lastDecostop_m; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1654 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1655 memcpy(headerOSTC3.hwHudBattery_mV, &pHead->hwHudBattery_mV, 2); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1656 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1657 headerOSTC3.hwHudLastStatus = pHead->hwHudLastStatus; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1658 |
483 | 1659 memset(headerOSTC3.batteryGaugeRegisters, 0x00, 6); /* The battery registers are not evaluated => Set to zero */ |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1660 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1661 memcpy(headerOSTC3.diveHeaderEnd, &pHead->diveHeaderEnd, 2); |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1662 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1663 else |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1664 { |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1665 returnEmptyHeader = 1; |
38 | 1666 } |
1667 } | |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1668 if(returnEmptyHeader) /* profile not in use => return array full of 0xFF */ |
38 | 1669 { |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1670 memset(&headerOSTC3, 0xFF, sizeof(headerOSTC3)); |
38 | 1671 } |
1672 | |
1673 return &headerOSTC3; | |
1674 } | |
1675 | |
1676 | |
1677 /******************************************************************************** | |
1678 * @brief logbook_build_ostc3header_compact. / | |
1679 * @author heinrichs weikamp gmbh | |
1680 * @version V0.0.1 | |
1681 * @date 31-Juli-2015 | |
1682 *********************************************************************************/ | |
1683 SLogbookHeaderOSTC3compact * logbook_build_ostc3header_compact(SLogbookHeader* pHead) | |
1684 { | |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1685 uint8_t returnEmptyHeader = 0; |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1686 convert_Type data, data2; |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1687 uint32_t dummyLength = 0; |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1688 uint32_t headerProfileLength, sampleProfileLength, sampleProfileStart; |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1689 |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1690 if(pHead->diveHeaderStart != 0xFAFA) |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1691 { |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1692 returnEmptyHeader = 1; |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1693 } |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1694 else |
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1695 { |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1696 data.u8bit.byteHigh = 0; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1697 data.u8bit.byteLow = pHead->pBeginProfileData[0]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1698 data.u8bit.byteMidLow = pHead->pBeginProfileData[1]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1699 data.u8bit.byteMidHigh = pHead->pBeginProfileData[2]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1700 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1701 sampleProfileStart = data.u32bit; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1702 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1703 data2.u8bit.byteHigh = 0; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1704 data2.u8bit.byteLow = pHead->pEndProfileData[0]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1705 data2.u8bit.byteMidLow = pHead->pEndProfileData[1]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1706 data2.u8bit.byteMidHigh = pHead->pEndProfileData[2]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1707 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1708 data.u8bit.byteHigh = 0; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1709 data.u8bit.byteLow = pHead->profileLength[0]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1710 data.u8bit.byteMidLow = pHead->profileLength[1]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1711 data.u8bit.byteMidHigh = pHead->profileLength[2]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1712 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1713 if(data.u32bit != 0xFFFFFF) |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1714 { |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1715 if(data2.u32bit < sampleProfileStart) /* Wrap around of sample ring detected */ |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1716 { |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1717 if(ext_flash_SampleOverrunValid() == 0) /* Wrap around does not seem to be valid => fallback */ |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1718 { |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1719 sampleProfileStart = 0; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1720 } |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1721 } |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1722 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1723 if( sampleProfileStart == 0) /* no sample data available => use dummy */ |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1724 { |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1725 sampleProfileLength = 1; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1726 headerProfileLength = 2; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1727 } |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1728 else |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1729 { |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1730 headerProfileLength = (pHead->profileLength[2] << 16) + (pHead->profileLength[1] << 8) + pHead->profileLength[0]; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1731 sampleProfileLength = ext_flash_read_profilelength_small_header(sampleProfileStart); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1732 } |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1733 if(sampleProfileLength != headerProfileLength) |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1734 { |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1735 dummyLength = logbook_fillDummySampleBuffer(pHead); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1736 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1737 data2.u32bit = sampleProfileStart + dummyLength; /* calc new end address (which is equal to dummyLength) */ |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1738 data.u32bit = dummyLength; /* data is used below to represent the length */ |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1739 } |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1740 data.u32bit += 3; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1741 headerOSTC3compact.profileLength[0] = data.u8bit.byteLow; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1742 headerOSTC3compact.profileLength[1] = data.u8bit.byteMidLow; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1743 headerOSTC3compact.profileLength[2] = data.u8bit.byteMidHigh; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1744 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1745 headerOSTC3compact.dateYear = pHead->dateYear; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1746 headerOSTC3compact.dateMonth = pHead->dateMonth; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1747 headerOSTC3compact.dateDay = pHead->dateDay; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1748 headerOSTC3compact.timeHour = pHead->timeHour; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1749 headerOSTC3compact.timeMinute = pHead->timeMinute; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1750 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1751 memcpy(headerOSTC3compact.maxDepth, &pHead->maxDepth, 2); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1752 memcpy(headerOSTC3compact.diveTimeMinutes, &pHead->diveTimeMinutes, 2); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1753 |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1754 headerOSTC3compact.diveTimeSeconds = pHead->diveTimeSeconds; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1755 headerOSTC3compact.totalDiveNumberLow = pHead->diveNumber & 0xFF; |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1756 headerOSTC3compact.totalDiveNumberHigh = (uint8_t)(pHead->diveNumber/256); |
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1757 headerOSTC3compact.profileVersion = 0x24; // Logbook-Profile version, 0x24 = date and time is start not end |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1758 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1759 else |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1760 { |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1761 returnEmptyHeader = 1; |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1762 } |
411
e908b894f107
Bugfix: Limit log length in case of corrupted sample storage:
ideenmodellierer
parents:
325
diff
changeset
|
1763 } |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1764 if(returnEmptyHeader) |
38 | 1765 { |
1766 memset(&headerOSTC3compact, 0xFF, sizeof(SLogbookHeaderOSTC3compact)); | |
1767 } | |
1768 return &headerOSTC3compact; | |
1769 } | |
1770 | |
1771 | |
1772 /** | |
1773 ****************************************************************************** | |
1774 * @brief logbook_readSampleData. / Reads sample data of whole logbook entry | |
281 | 1775 * @author heinrichs weikamp |
38 | 1776 * @version V0.0.1 |
1777 * @date 22-April-2014 | |
1778 ****************************************************************************** | |
1779 * | |
1780 * @param uint8_t StepBackwards: witch lookbook entry? | |
1781 * @param uint16_t length : maxlength of output arrays | |
1782 * @param int32_t* depth : output array | |
1783 * @param int16_t * gasid : output array | |
1784 * @param int32_t* temperature : output array | |
1785 * @param int32_t* ppo2 : output array | |
1786 * @param int32_t* cns : output array | |
1787 * @return length of output | |
1788 */ | |
1789 void logbook_recover_brokenlog(uint8_t headerId) | |
1790 { | |
1791 int16_t retVal; | |
1792 int32_t depthVal = 0; | |
1793 int16_t gasidVal = 0; | |
1794 int16_t setPointVal = 0; | |
1795 int16_t bailoutVal = 0; | |
1796 int32_t temperatureVal = 0; | |
1797 int32_t sensor1Val = 0; | |
1798 int32_t sensor2Val = 0; | |
1799 int32_t sensor3Val = 0; | |
1800 int32_t cnsVal = 0; | |
1801 SManualGas manualGasVal; | |
1802 | |
1803 //uint16_t* ppo2, uint16_t* cns# | |
1804 uint32_t bytesRead = 0; | |
1805 | |
1806 ext_flash_read_block_start(); | |
1807 ext_flash_read_next_sample_part((uint8_t*)&smallHeader, sizeof(SSmallHeader)); | |
1808 bytesRead += sizeof(SSmallHeader); | |
1809 | |
1810 clear_divisor(); | |
1811 | |
1812 | |
1813 int sampleCounter = 0; | |
1814 int maxdepth = 0; | |
1815 uint32_t avrdepth = 0; | |
1816 while (true) | |
1817 { | |
1818 | |
1819 ext_flash_set_entry_point(); | |
1820 divisorBackup = divisor; | |
610 | 1821 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL, NULL, NULL); |
38 | 1822 if(retVal == 0) |
1823 { | |
1824 //Error try to read again!!! | |
1825 ext_flash_reopen_read_sample_at_entry_point(); | |
1826 divisor = divisorBackup; | |
610 | 1827 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL, NULL, NULL); |
38 | 1828 |
1829 if(retVal == 0) | |
1830 { | |
1831 //Error try to read again!!! | |
1832 ext_flash_reopen_read_sample_at_entry_point(); | |
1833 divisor = divisorBackup; | |
610 | 1834 retVal = readSample(&depthVal,&gasidVal, &setPointVal, &temperatureVal, &sensor1Val, &sensor2Val, &sensor3Val, &cnsVal, &manualGasVal, &bailoutVal, NULL, NULL, NULL); |
38 | 1835 |
1836 if(retVal == 0) | |
1837 { | |
1838 ext_flash_reopen_read_sample_at_entry_point(); | |
1839 break; | |
1840 } | |
1841 | |
1842 } | |
1843 } | |
1844 if(depthVal > maxdepth) | |
1845 maxdepth = depthVal; | |
1846 avrdepth += depthVal; | |
1847 sampleCounter++; | |
1848 bytesRead +=retVal; | |
1849 } | |
1850 avrdepth/= sampleCounter; | |
1851 ext_flash_close_read_sample(); | |
1852 SLogbookHeader header; | |
1853 | |
1854 ext_flash_read_dive_header2((uint8_t*) &header, headerId, false); | |
1855 header.total_diveTime_seconds = sampleCounter * header.samplingRate; | |
1856 header.diveTimeMinutes = header.total_diveTime_seconds /60; | |
1857 header.diveTimeSeconds = header.total_diveTime_seconds - header.diveTimeMinutes * 60; | |
1858 header.maxDepth = maxdepth; | |
1859 header.averageDepth_mbar = avrdepth; | |
1860 SSettings * settings = settingsGetPointer(); | |
1861 settings->lastDiveLogId = headerId; | |
1862 ext_flash_close_new_dive_log((uint8_t *)&header); | |
1863 } | |
1864 | |
458 | 1865 void logbook_createDummyProfile(SLogbookHeader* pHeader, uint16_t length, uint16_t* depth, int16_t* temperature, uint16_t* ppo2) |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1866 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1867 uint8_t drawDeco = 1; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1868 uint16_t index = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1869 uint16_t indexDescenStop = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1870 uint16_t indexAscendStart = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1871 uint16_t simDecentDepth = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1872 uint16_t simDecentStep = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1873 uint16_t simAcentDepth = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1874 uint16_t simAcentStep = 0; |
458 | 1875 float ambiant_pressure_bar = 0; |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1876 |
458 | 1877 simDecentStep = pHeader->maxDepth / (length / 6); /* first 1/6 for descend */ |
1878 simAcentStep = pHeader->maxDepth / (length / 3); /* first 1/3 for ascend */ | |
1879 | |
1880 SGas gas; | |
1881 | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1882 |
458 | 1883 if(ppo2) |
1884 { | |
1885 /* find first gas ID */ | |
524
b33a8c1c72e5
Minor: Removed duplicated definition of number of available gases
Ideenmodellierer
parents:
483
diff
changeset
|
1886 for(index = 0; index < NUM_GASES; index++) |
458 | 1887 { |
1888 if(pHeader->gasordil[index].note.ub.first) | |
1889 break; | |
1890 } | |
524
b33a8c1c72e5
Minor: Removed duplicated definition of number of available gases
Ideenmodellierer
parents:
483
diff
changeset
|
1891 if(index != NUM_GASES) |
458 | 1892 { |
1893 gas.helium_percentage = pHeader->gasordil[index].helium_percentage; | |
1894 gas.nitrogen_percentage = 100 - gas.helium_percentage - pHeader->gasordil[index].oxygen_percentage; | |
1895 } | |
1896 } | |
1897 | |
1898 while((index < length) && (simDecentDepth < pHeader->maxDepth)) /* draw decent */ | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1899 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1900 depth[index] = simDecentDepth; |
458 | 1901 temperature[index] = pHeader->minTemp; |
1902 if(ppo2) | |
1903 { | |
1904 ambiant_pressure_bar =((float)(depth[index] + pHeader->surfacePressure_mbar))/1000; | |
1905 ppo2[index] = (uint16_t) ((decom_calc_ppO2(ambiant_pressure_bar, &gas )) * 100); | |
1906 } | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1907 index++; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1908 simDecentDepth += simDecentStep; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1909 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1910 indexDescenStop = index; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1911 index = length -1; |
458 | 1912 while((index > indexDescenStop) && (simAcentDepth < pHeader->maxDepth)) /* draw ascend including max deco stop */ |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1913 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1914 depth[index] = simAcentDepth; |
458 | 1915 temperature[index] = pHeader->minTemp; |
1916 if(ppo2) | |
1917 { | |
1918 ambiant_pressure_bar =((float)(depth[index] + pHeader->surfacePressure_mbar))/1000; | |
1919 ppo2[index] = (uint16_t) ((decom_calc_ppO2(ambiant_pressure_bar, &gas )) * 100); | |
1920 } | |
1921 if((drawDeco) && (simAcentDepth < pHeader->lastDecostop_m)) /* draw deco step */ | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1922 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1923 drawDeco = length / 10; |
458 | 1924 while(drawDeco) |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1925 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1926 index--; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1927 depth[index] = simAcentDepth; |
458 | 1928 temperature[index] = pHeader->minTemp; |
1929 if(ppo2) | |
1930 { | |
1931 ambiant_pressure_bar =((float)(depth[index] + pHeader->surfacePressure_mbar))/1000; | |
1932 ppo2[index] = (uint16_t) ((decom_calc_ppO2(ambiant_pressure_bar, &gas )) * 100); | |
1933 } | |
1934 drawDeco--; | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1935 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1936 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1937 index--; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1938 simAcentDepth += simAcentStep; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1939 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1940 indexAscendStart = index; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1941 index = indexDescenStop; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1942 while(index <= indexAscendStart) /* draw isobar dive phase */ |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1943 { |
458 | 1944 depth[index] = pHeader->maxDepth; |
1945 temperature[index] = pHeader->minTemp; | |
1946 if(ppo2) | |
1947 { | |
1948 ambiant_pressure_bar =((float)(depth[index] + pHeader->surfacePressure_mbar))/1000; | |
1949 ppo2[index] = (uint16_t) ((decom_calc_ppO2(ambiant_pressure_bar, &gas )) * 100); | |
1950 } | |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1951 index++; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1952 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1953 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1954 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1955 void logbook_resetDummy() |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1956 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1957 dummyWriteIdx = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1958 dummyReadIdx = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1959 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1960 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1961 void logbook_writeDummy(void* data, uint16_t length) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1962 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1963 memcpy(&dummyMemoryBuffer[dummyWriteIdx],(uint8_t *)data, length); |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1964 dummyWriteIdx += length; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1965 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1966 void logbook_writeDummySample(uint16_t depth, int16_t temperature) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1967 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1968 uint8_t sample[10]; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1969 int length = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1970 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1971 int i = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1972 for(i = 0; i <10 ;i++) sample[i] = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1973 addU16(sample, depth); |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1974 length += 2; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1975 sample[2] = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1976 length++; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1977 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1978 if(divisor.temperature == 0) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1979 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1980 divisor.temperature = smallHeader.tempDivisor - 1; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1981 addS16(&sample[length], temperature); |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1982 length += 2; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1983 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1984 else |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1985 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1986 divisor.temperature--; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1987 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1988 |
465
2c2df051e554
Compare profile length from header and sample data to identify valid profiles
ideenmodellierer
parents:
458
diff
changeset
|
1989 logbook_writeDummy((void *) sample,length); |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1990 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1991 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1992 |
458 | 1993 uint16_t logbook_fillDummySampleBuffer(SLogbookHeader* pHeader) |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1994 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1995 uint16_t depthArray[DUMMY_SAMPLES]; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1996 int16_t temperatureArray[DUMMY_SAMPLES]; |
458 | 1997 uint16_t ppo2Array[DUMMY_SAMPLES]; |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1998 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
1999 uint16_t index = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2000 uint16_t dummyBufferSize = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2001 uint16_t dummyProfileLength = 0; |
458 | 2002 uint32_t overallSecond = pHeader->diveTimeMinutes * 60 + pHeader->diveTimeSeconds; |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2003 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2004 logbook_resetDummy(); |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2005 clear_divisor(); |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2006 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2007 smallDummyHeader.profileLength[0] = 0xFF; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2008 smallDummyHeader.profileLength[1] = 0xFF; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2009 smallDummyHeader.profileLength[2] = 0xFF; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2010 smallDummyHeader.samplingRate_seconds = 2; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2011 smallDummyHeader.numDivisors = 7; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2012 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2013 smallDummyHeader.tempType = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2014 smallDummyHeader.tempLength = 2; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2015 smallDummyHeader.tempDivisor = 6; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2016 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2017 smallDummyHeader.deco_ndlType = 1; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2018 smallDummyHeader.deco_ndlLength = 2; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2019 smallDummyHeader.deco_ndlDivisor = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2020 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2021 /* GF in % at actual position */ |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2022 smallDummyHeader.gfType = 2; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2023 smallDummyHeader.gfLength = 1; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2024 smallDummyHeader.gfDivisor = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2025 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2026 /* 3 Sensors: 8bit ppO2 in 0.01bar, 16bit voltage in 0,1mV */ |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2027 smallDummyHeader.ppo2Type = 3; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2028 smallDummyHeader.ppo2Length = 9; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2029 smallDummyHeader.ppo2Divisor = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2030 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2031 /* last 15 stops in minutes (last, second_to_last, ... */ |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2032 /* last stop depth is defined in header */ |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2033 smallDummyHeader.decoplanType = 4; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2034 smallDummyHeader.decoplanLength = 15; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2035 smallDummyHeader.decoplanDivisor = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2036 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2037 smallDummyHeader.cnsType = 5; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2038 smallDummyHeader.cnsLength = 2; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2039 smallDummyHeader.cnsDivisor = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2040 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2041 smallDummyHeader.tankType = 6; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2042 smallDummyHeader.tankLength = 2; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2043 smallDummyHeader.tankDivisor = 0; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2044 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2045 if((overallSecond / smallDummyHeader.samplingRate_seconds) > DUMMY_SAMPLES) /* reduce sample interval to keep buffer size */ |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2046 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2047 smallDummyHeader.samplingRate_seconds = overallSecond / DUMMY_SAMPLES; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2048 dummyProfileLength = DUMMY_SAMPLES; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2049 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2050 else |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2051 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2052 dummyProfileLength = overallSecond / smallDummyHeader.samplingRate_seconds; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2053 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2054 logbook_writeDummy((void *) &smallDummyHeader,sizeof(smallDummyHeader)); |
458 | 2055 logbook_createDummyProfile(pHeader,dummyProfileLength, depthArray, temperatureArray, ppo2Array ); |
455
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2056 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2057 for (index = 0; index < dummyProfileLength; index++) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2058 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2059 logbook_writeDummySample(depthArray[index], temperatureArray[index]); |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2060 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2061 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2062 dummyBufferSize = dummyWriteIdx; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2063 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2064 return dummyBufferSize; /* return size of dummy buffer */ |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2065 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2066 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2067 void logbook_readDummySamples(uint8_t* pTarget, uint16_t length) |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2068 { |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2069 memcpy(pTarget,&dummyMemoryBuffer[dummyReadIdx],length); |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2070 dummyReadIdx += length; |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2071 } |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2072 |
928a14568689
Reactivated samples for bottle pressure information:
ideenmodellierer
parents:
445
diff
changeset
|
2073 |
38 | 2074 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ |