comparison Discovery/Src/data_central.c @ 300:5ca177d2df5d cleanup-4

cleanup: remove commented/unused code, make static without any functional change. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Fri, 17 May 2019 21:19:04 +0200
parents 54d14bc2083c
children eba8d1eb5bef
comparison
equal deleted inserted replaced
299:b70c26be71a0 300:5ca177d2df5d
73 73
74 static SDiveState stateReal = { 0 }; 74 static SDiveState stateReal = { 0 };
75 SDiveState stateSim = { 0 }; 75 SDiveState stateSim = { 0 };
76 SDiveState stateDeco = { 0 }; 76 SDiveState stateDeco = { 0 };
77 77
78 SDevice stateDevice = 78 static SDevice stateDevice =
79 { 79 {
80 /* max is 0x7FFFFFFF, min is 0x80000000 but also defined in stdint.h :-) */ 80 /* max is 0x7FFFFFFF, min is 0x80000000 but also defined in stdint.h :-) */
81 81
82 /* count, use 0 */ 82 /* count, use 0 */
83 .batteryChargeCompleteCycles.value_int32 = 0, 83 .batteryChargeCompleteCycles.value_int32 = 0,
92 /* min values, use max. */ 92 /* min values, use max. */
93 .temperatureMinimum.value_int32 = INT32_MAX, 93 .temperatureMinimum.value_int32 = INT32_MAX,
94 .voltageMinimum.value_int32 = INT32_MAX, 94 .voltageMinimum.value_int32 = INT32_MAX,
95 }; 95 };
96 96
97 SVpmRepetitiveData stateVPM = 97 static SVpmRepetitiveData stateVPM =
98 { 98 {
99 .repetitive_variables_not_valid = 1, 99 .repetitive_variables_not_valid = 1,
100 .is_data_from_RTE_CPU = 0, 100 .is_data_from_RTE_CPU = 0,
101 }; 101 };
102 102
173 return 0xFFFFFFFF - ticksstart + ticksnow; 173 return 0xFFFFFFFF - ticksstart + ticksnow;
174 } 174 }
175 175
176 176
177 uint8_t decoLock = DECO_CALC_undefined; 177 uint8_t decoLock = DECO_CALC_undefined;
178 int ascent_rate_meter_per_min = 12; 178
179 int descent_rate_meter_per_min = 20; 179 static int descent_rate_meter_per_min = 20;
180 int max_depth = 70; 180 static int max_depth = 70;
181 int bottom_time = 10; 181 static int bottom_time = 10;
182 182
183 _Bool vpm_crush(SDiveState* pDiveState); 183 _Bool vpm_crush(SDiveState* pDiveState);
184 void setSimulationValues(int _ascent_rate_meter_per_min, int _descent_rate_meter_per_min, int _max_depth, int _bottom_time ) 184 void setSimulationValues(int _ascent_rate_meter_per_min, int _descent_rate_meter_per_min, int _max_depth, int _bottom_time )
185 { 185 {
186 ascent_rate_meter_per_min = _ascent_rate_meter_per_min;
187 descent_rate_meter_per_min = _descent_rate_meter_per_min; 186 descent_rate_meter_per_min = _descent_rate_meter_per_min;
188 max_depth = _max_depth; 187 max_depth = _max_depth;
189 bottom_time = _bottom_time; 188 bottom_time = _bottom_time;
190 } 189 }
191 190
192
193
194 int current_second(void) { 191 int current_second(void) {
195 192
196 return HAL_GetTick() / 1000; 193 return HAL_GetTick() / 1000;
197 // printf("milliseconds: %lld\n", milliseconds); 194 }
198 //return milliseconds;
199 }
200
201
202 195
203 #define OXY_ONE_SIXTIETH_PART 0.0166667f 196 #define OXY_ONE_SIXTIETH_PART 0.0166667f
204
205 /*void oxygen_calculate_cns(float* oxygen_cns, float pressure_oxygen_real)
206 {
207 int cns_no_range = 0;
208 _Bool not_found = 1;
209 //for the cns calculation
210 const float cns_ppo2_ranges[60][2] = { {0.50, 0.00}, {0.60, 0.14}, {0.64, 0.15}, {0.66, 0.16}, {0.68, 0.17}, {0.70, 0.18},
211 {0.74, 0.19}, {0.76, 0.20}, {0.78, 0.21}, {0.80, 0.22}, {0.82, 0.23}, {0.84, 0.24},
212 {0.86, 0.25}, {0.88, 0.26}, {0.90, 0.28}, {0.92, 0.29}, {0.94, 0.30}, {0.96, 0.31},
213 {0.98, 0.32}, {1.00, 0.33}, {1.02, 0.35}, {1.04, 0.36}, {1.06, 0.38}, {1.08, 0.40},
214 {1.10, 0.42}, {1.12, 0.43}, {1.14, 0.43}, {1.16, 0.44}, {1.18, 0.46}, {1.20, 0.47},
215 {1.22, 0.48}, {1.24, 0.51}, {1.26, 0.52}, {1.28, 0.54}, {1.30, 0.56}, {1.32, 0.57},
216 {1.34, 0.60}, {1.36, 0.62}, {1.38, 0.63}, {1.40, 0.65}, {1.42, 0.68}, {1.44, 0.71},
217 {1.46, 0.74}, {1.48, 0.78}, {1.50, 0.83}, {1.52, 0.93}, {1.54, 1.04}, {1.56, 1.19},
218 {1.58, 1.47}, {1.60, 2.22}, {1.62, 5.00}, {1.65, 6.25}, {1.67, 7.69}, {1.70, 10.0},
219 {1.72,12.50}, {1.74,20.00}, {1.77,25.00}, {1.79,31.25}, {1.80,50.00}, {1.82,100.0}};
220 //find the correct cns range for the corresponding ppo2
221 cns_no_range = 58;
222 while (cns_no_range && not_found)
223 {
224 if (pressure_oxygen_real > cns_ppo2_ranges[cns_no_range][0])
225 {
226 cns_no_range++;
227 not_found = 0;
228 }
229 else
230 cns_no_range--;
231 }
232
233 //calculate cns for the actual ppo2 for 1 second
234 *oxygen_cns += OXY_ONE_SIXTIETH_PART * cns_ppo2_ranges[cns_no_range][1];
235 }*/
236 197
237 uint8_t calc_MOD(uint8_t gasId) 198 uint8_t calc_MOD(uint8_t gasId)
238 { 199 {
239 int16_t oxygen, maxppO2, result; 200 int16_t oxygen, maxppO2, result;
240 SSettings *pSettings; 201 SSettings *pSettings;
258 if(result > 255) 219 if(result > 255)
259 return 255; 220 return 255;
260 221
261 return result; 222 return result;
262 } 223 }
263
264 uint8_t calc_MinOD(uint8_t gasId)
265 {
266 int16_t oxygen, minppO2, result;
267 SSettings *pSettings;
268
269 pSettings = settingsGetPointer();
270
271 oxygen = (int16_t)(pSettings->gas[gasId].oxygen_percentage);
272 minppO2 =(int16_t)(pSettings->ppO2_min);
273 result = 10 * minppO2;
274 result += 9;
275 result /= oxygen;
276 result -= 10;
277
278 if(result < 0)
279 return 0;
280
281 if(result > 255)
282 return 255;
283
284 return result;
285 }
286 /*
287 float calc_ppO2(float input_ambient_pressure_bar, SGas* pGas)
288 {
289 float percent_N2 = 0;
290 float percent_He = 0;
291 float percent_O2 = 0;
292 decom_get_inert_gases(input_ambient_pressure_bar, pGas, &percent_N2, &percent_He);
293 percent_O2 = 1 - percent_N2 - percent_He;
294
295 return (input_ambient_pressure_bar - WATER_VAPOUR_PRESSURE) * percent_O2;
296 }*/
297 224
298 float get_ambiant_pressure_simulation(long dive_time_seconds, float surface_pressure_bar ) 225 float get_ambiant_pressure_simulation(long dive_time_seconds, float surface_pressure_bar )
299 { 226 {
300 static 227 static
301 long descent_time; 228 long descent_time;
649 stateRealGetPointerWrite()->cnsHigh_at_the_end_of_dive = 0; 576 stateRealGetPointerWrite()->cnsHigh_at_the_end_of_dive = 0;
650 stateRealGetPointerWrite()->decoMissed_at_the_end_of_dive = 0; 577 stateRealGetPointerWrite()->decoMissed_at_the_end_of_dive = 0;
651 } 578 }
652 579
653 580
654 int32_t helper_days_from_civil(int32_t y, uint32_t m, uint32_t d) 581 static int32_t helper_days_from_civil(int32_t y, uint32_t m, uint32_t d)
655 { 582 {
656 y += 2000; 583 y += 2000;
657 y -= m <= 2; 584 y -= m <= 2;
658 int32_t era = (y >= 0 ? y : y-399) / 400; 585 int32_t era = (y >= 0 ? y : y-399) / 400;
659 uint32_t yoe = (uint32_t)(y - era * 400); // [0, 399] 586 uint32_t yoe = (uint32_t)(y - era * 400); // [0, 399]
661 uint32_t doe = yoe * 365 + yoe/4 - yoe/100 + doy; // [0, 146096] 588 uint32_t doe = yoe * 365 + yoe/4 - yoe/100 + doy; // [0, 146096]
662 return era * 146097 + (int32_t)(doe) - 719468; 589 return era * 146097 + (int32_t)(doe) - 719468;
663 } 590 }
664 591
665 592
666 uint8_t helper_weekday_from_days(int32_t z) 593 static uint8_t helper_weekday_from_days(int32_t z)
667 { 594 {
668 return (uint8_t)(z >= -4 ? (z+4) % 7 : (z+5) % 7 + 6); 595 return (uint8_t)(z >= -4 ? (z+4) % 7 : (z+5) % 7 + 6);
669 } 596 }
670 597
671 598
712 sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes); 639 sTime->Minutes = (uint8_t)RTC_Bcd2ToByte(sTime->Minutes);
713 sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds); 640 sTime->Seconds = (uint8_t)RTC_Bcd2ToByte(sTime->Seconds);
714 sTime->SubSeconds = 0; 641 sTime->SubSeconds = 0;
715 } 642 }
716 643
717
718 /*
719 void initDiveState(SDiveSettings * pDiveSettings, SVpm * pVpm)
720 {
721 SSettings* pSettings = settingsGetPointer();
722 for(int i = 0; i< NUM_GASES; i++)
723 {
724 pDiveSettings->gas[i] = pSettings->gas[i];
725 pDiveSettings->gas[NUM_OFFSET_DILUENT + i] = pSettings->gas[NUM_OFFSET_DILUENT + i];
726 pDiveSettings->setpoint[i] = pSettings->setpoint[i];
727 }
728 pDiveSettings->diveMode = pSettings->dive_mode;
729
730 pDiveSettings->gf_high = pSettings->GF_high;
731 pDiveSettings->gf_low = pSettings->GF_low;
732 pDiveSettings->last_stop_depth_bar = ((float)pSettings->last_stop_depth_meter) / 10.0;
733 pDiveSettings->ascentRate_meterperminute = 10;
734 pDiveSettings->vpm_conservatism = 1;
735
736 pDiveSettings->input_next_stop_increment_depth_bar = ((float)pSettings->stop_increment_depth_meter) / 10.0f;
737
738 vpm_init(pVpm, pDiveSettings->vpm_conservatism, 0, 0);
739 }
740 */
741 _Bool deco_zone_reached(void)
742 {
743 if(stateUsed->diveSettings.deco_type.ub.standard == GF_MODE)
744 return stateUsed->lifeData.pressure_ambient_bar <= stateUsed->diveSettings.internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero;
745 else
746 return stateUsed->vpm.deco_zone_reached;
747
748 }
749
750
751 void resetEvents(const SDiveState *pStateUsed) 644 void resetEvents(const SDiveState *pStateUsed)
752 { 645 {
753 memset((void *)&pStateUsed->events, 0, sizeof(SEvents)); 646 memset((void *)&pStateUsed->events, 0, sizeof(SEvents));
754 }
755
756
757 /* This is derived from crc32b but does table lookup. First the table
758 itself is calculated, if it has not yet been set up.
759 Not counting the table setup (which would probably be a separate
760 function), when compiled to Cyclops with GCC, this function executes in
761 7 + 13n instructions, where n is the number of bytes in the input
762 message. It should be doable in 4 + 9n instructions. In any case, two
763 of the 13 or 9 instrucions are load byte.
764 This is Figure 14-7 in the text. */
765
766 /* http://www.hackersdelight.org/ i guess ;-) *hw */
767
768 uint32_t crc32c_checksum(uint8_t* message, uint16_t length, uint8_t* message2, uint16_t length2) {
769 int i, j;
770 uint32_t byte, crc, mask;
771 static unsigned int table[256] = {0};
772
773 /* Set up the table, if necessary. */
774 if (table[1] == 0) {
775 for (byte = 0; byte <= 255; byte++) {
776 crc = byte;
777 for (j = 7; j >= 0; j--) { // Do eight times.
778 mask = -(crc & 1);
779 crc = (crc >> 1) ^ (0xEDB88320 & mask);
780 }
781 table[byte] = crc;
782 }
783 }
784
785 /* Through with table setup, now calculate the CRC. */
786 i = 0;
787 crc = 0xFFFFFFFF;
788 while (length--) {
789 byte = message[i];
790 crc = (crc >> 8) ^ table[(crc ^ byte) & 0xFF];
791 i = i + 1;
792 }
793 if(length2)
794 {
795 i = 0;
796 while (length2--) {
797 byte = message2[i];
798 crc = (crc >> 8) ^ table[(crc ^ byte) & 0xFF];
799 i = i + 1;
800 }
801 }
802 return ~crc;
803 } 647 }
804 648
805 649
806 uint32_t CRC_CalcBlockCRC_moreThan768000(uint32_t *buffer1, uint32_t *buffer2, uint32_t words) 650 uint32_t CRC_CalcBlockCRC_moreThan768000(uint32_t *buffer1, uint32_t *buffer2, uint32_t words)
807 { 651 {