Mercurial > public > ostc4
comparison Discovery/Src/buehlmann.c @ 254:a17f7fb3b2b5 bm-3
Buehlmann: cleanup, remove global pDecolistBuehlmann
Yes, I hate global data, and a simple renaming of a pointer almost
qualifies for participation in the Obfuscated C Code Contest :-)
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Fri, 12 Apr 2019 14:46:48 +0200 |
parents | 1663b3b204d7 |
children | dcf7a3435fe1 |
comparison
equal
deleted
inserted
replaced
253:1663b3b204d7 | 254:a17f7fb3b2b5 |
---|---|
54 static float gGF_value; | 54 static float gGF_value; |
55 static float gCNS; | 55 static float gCNS; |
56 static int gNDL; | 56 static int gNDL; |
57 | 57 |
58 SDiveSettings *pBuDiveSettings; | 58 SDiveSettings *pBuDiveSettings; |
59 SDecoinfo* pDecolistBuehlmann; | |
60 float gGF_low_depth_bar; | 59 float gGF_low_depth_bar; |
61 SStop gStop; | 60 SStop gStop; |
62 | 61 |
63 void buehlmann_init(void) | 62 void buehlmann_init(void) |
64 { | 63 { |
125 pDecoInfo->output_stop_length_seconds[i] = 0; | 124 pDecoInfo->output_stop_length_seconds[i] = 0; |
126 } | 125 } |
127 /* make input available global*/ | 126 /* make input available global*/ |
128 pBuDiveSettings = pDiveSettings; | 127 pBuDiveSettings = pDiveSettings; |
129 | 128 |
130 pDecolistBuehlmann = pDecoInfo; | |
131 /* internal copying */ | 129 /* internal copying */ |
132 gSurface_pressure_bar = pLifeData->pressure_surface_bar; | 130 gSurface_pressure_bar = pLifeData->pressure_surface_bar; |
133 | 131 |
134 gPressure = pLifeData->pressure_ambient_bar; | 132 gPressure = pLifeData->pressure_ambient_bar; |
135 gGas_id = 0; | 133 gGas_id = 0; |
136 memcpy(gTissue_nitrogen_bar, pLifeData->tissue_nitrogen_bar, (4*16)); | 134 memcpy(gTissue_nitrogen_bar, pLifeData->tissue_nitrogen_bar, (4*16)); |
137 memcpy(gTissue_helium_bar, pLifeData->tissue_helium_bar, (4*16)); | 135 memcpy(gTissue_helium_bar, pLifeData->tissue_helium_bar, (4*16)); |
138 gGF_value = ((float)pBuDiveSettings->gf_low) / 100.0f; | 136 gGF_value = ((float)pBuDiveSettings->gf_low) / 100.0f; |
139 | 137 |
140 // | 138 // |
141 memcpy(&gDecotable, pDecolistBuehlmann, sizeof(SDecoinfo)); | 139 memcpy(&gDecotable, pDecoInfo, sizeof(SDecoinfo)); |
142 stoplist = gDecotable.output_stop_length_seconds; | 140 stoplist = gDecotable.output_stop_length_seconds; |
143 | 141 |
144 if(pLifeData->dive_time_seconds < 60) | 142 if(pLifeData->dive_time_seconds < 60) |
145 return; | 143 return; |
146 | 144 |
159 buehlmann_backup_and_restore(true); // includes backup for gGF_value | 157 buehlmann_backup_and_restore(true); // includes backup for gGF_value |
160 if(!dive1_check_deco() ) | 158 if(!dive1_check_deco() ) |
161 { | 159 { |
162 buehlmann_backup_and_restore(false); | 160 buehlmann_backup_and_restore(false); |
163 // no deco | 161 // no deco |
164 pDecolistBuehlmann->output_time_to_surface_seconds = 0; | 162 pDecoInfo->output_time_to_surface_seconds = 0; |
165 for(i = 0; i < DECOINFO_STRUCT_MAX_STOPS; i++) | 163 for(i = 0; i < DECOINFO_STRUCT_MAX_STOPS; i++) |
166 pDecolistBuehlmann->output_stop_length_seconds[i] = 0; | 164 pDecoInfo->output_stop_length_seconds[i] = 0; |
167 // calc NDL | 165 // calc NDL |
168 buehlmann_calc_ndl(); | 166 buehlmann_calc_ndl(); |
169 pDecolistBuehlmann->output_ndl_seconds = gNDL; | 167 pDecoInfo->output_ndl_seconds = gNDL; |
170 return; | 168 return; |
171 } | 169 } |
172 buehlmann_backup_and_restore(false); | 170 buehlmann_backup_and_restore(false); |
173 pDecolistBuehlmann->output_ndl_seconds = 0; | 171 pDecoInfo->output_ndl_seconds = 0; |
174 | 172 |
175 gGF_value = get_gf_at_pressure(gPressure); | 173 gGF_value = get_gf_at_pressure(gPressure); |
176 //current ceiling at actual position | 174 //current ceiling at actual position |
177 ceiling = tissue_tolerance(); | 175 ceiling = tissue_tolerance(); |
178 ambient_bar_to_deco_stop_depth_bar(ceiling); | 176 ambient_bar_to_deco_stop_depth_bar(ceiling); |
190 ascend_time = ascend_with_all_gaschanges(PRESSURE_TEN_METER); | 188 ascend_time = ascend_with_all_gaschanges(PRESSURE_TEN_METER); |
191 tts_seconds += ascend_time; | 189 tts_seconds += ascend_time; |
192 ceiling = tissue_tolerance(); | 190 ceiling = tissue_tolerance(); |
193 if(tts_seconds > DECO_STOPS_MAX_TTS_CALCULATON_IN_SECONDS) | 191 if(tts_seconds > DECO_STOPS_MAX_TTS_CALCULATON_IN_SECONDS) |
194 { | 192 { |
195 /* pInput == pBuehlmann */ | 193 pDecoInfo->output_time_to_surface_seconds = NINETY_NINE_MINUTES_IN_SECONDS; |
196 pDecolistBuehlmann->output_time_to_surface_seconds = NINETY_NINE_MINUTES_IN_SECONDS; | |
197 return;// NINETY_NINE_MINUTES_IN_SECONDS; | 194 return;// NINETY_NINE_MINUTES_IN_SECONDS; |
198 } | 195 } |
199 } while ((ascend_time > 0 ) && ((gPressure - PRESSURE_TEN_METER ) > gSurface_pressure_bar) && (ceiling < (gPressure - PRESSURE_TEN_METER))); | 196 } while ((ascend_time > 0 ) && ((gPressure - PRESSURE_TEN_METER ) > gSurface_pressure_bar) && (ceiling < (gPressure - PRESSURE_TEN_METER))); |
200 } | 197 } |
201 do { | 198 do { |
203 ascend_time = ascend_with_all_gaschanges(PRESSURE_THREE_METER); | 200 ascend_time = ascend_with_all_gaschanges(PRESSURE_THREE_METER); |
204 tts_seconds += ascend_time; | 201 tts_seconds += ascend_time; |
205 ceiling = tissue_tolerance(); | 202 ceiling = tissue_tolerance(); |
206 if(tts_seconds > DECO_STOPS_MAX_TTS_CALCULATON_IN_SECONDS) | 203 if(tts_seconds > DECO_STOPS_MAX_TTS_CALCULATON_IN_SECONDS) |
207 { | 204 { |
208 /* pInput == pBuehlmann */ | 205 pDecoInfo->output_time_to_surface_seconds = NINETY_NINE_MINUTES_IN_SECONDS; |
209 pDecolistBuehlmann->output_time_to_surface_seconds = NINETY_NINE_MINUTES_IN_SECONDS; | |
210 return;// NINETY_NINE_MINUTES_IN_SECONDS; | 206 return;// NINETY_NINE_MINUTES_IN_SECONDS; |
211 } | 207 } |
212 ambient_bar_to_deco_stop_depth_bar(ceiling); | 208 ambient_bar_to_deco_stop_depth_bar(ceiling); |
213 } while ((ascend_time > 0 ) && ((gStop.depth + gSurface_pressure_bar) < gPressure)); | 209 } while ((ascend_time > 0 ) && ((gStop.depth + gSurface_pressure_bar) < gPressure)); |
214 | 210 |
235 tts_seconds += ascend_with_all_gaschanges(pressure_delta); | 231 tts_seconds += ascend_with_all_gaschanges(pressure_delta); |
236 } | 232 } |
237 // NDL check | 233 // NDL check |
238 if(ceiling <= gSurface_pressure_bar) | 234 if(ceiling <= gSurface_pressure_bar) |
239 { | 235 { |
240 /* pInput == pBuehlmann same pointer*/ | |
241 // NDL with GF_low | 236 // NDL with GF_low |
242 pDecolistBuehlmann->output_time_to_surface_seconds = 0; | 237 pDecoInfo->output_time_to_surface_seconds = 0; |
243 return; | 238 return; |
244 } | 239 } |
245 if (ceiling > pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero) | 240 if (ceiling > pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero) |
246 pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = ceiling; | 241 pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero = ceiling; |
247 | 242 |
296 } | 291 } |
297 gStop.id--; | 292 gStop.id--; |
298 } | 293 } |
299 | 294 |
300 gDecotable.output_time_to_surface_seconds = tts_seconds; | 295 gDecotable.output_time_to_surface_seconds = tts_seconds; |
301 memcpy(pDecolistBuehlmann, &gDecotable, sizeof(SDecoinfo)); | 296 memcpy(pDecoInfo, &gDecotable, sizeof(SDecoinfo)); |
302 } | 297 } |
303 | 298 |
304 | 299 |
305 static float tissue_tolerance(void) | 300 static float tissue_tolerance(void) |
306 { | 301 { |