annotate Discovery/Src/logbook.c @ 196:2885628ab3ba div-fixes-cleaup-2

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