mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
fix(t1000-e): fix extended uptime failures in GPS and sensor code
- Fix millis() wraparound (49-day) in T1000SensorManager::loop() and MicroNMEALocationProvider::loop() by switching from absolute comparison (millis() > next_*) to elapsed-time arithmetic ((uint32_t)(millis() - last_*) >= interval) with uint32_t timestamps; previous pattern could stall GPS updates and time sync for up to ~24 days after wraparound - Fix division-by-zero crash in get_heater_temperature() when ntc_volt == 0 (open circuit or bad ADC read); now returns 0.0f safely - Fix out-of-bounds array access in get_heater_temperature(): loop exit at i == 0 caused ntc_res2[i-1] / ntc_temp2[i-1] at index -1; loop exhaustion at i == 136 caused ntc_res2[136] one-past-end read; clamped i to [1, 135] with early-exit returns for edge temperatures and guarded interpolation denominator against zero
This commit is contained in:
parent
792f299986
commit
a8b3fc5ce3
3 changed files with 23 additions and 12 deletions
|
|
@ -32,11 +32,12 @@ static char ntc_temp2[136] = {
|
|||
};
|
||||
|
||||
static float get_heater_temperature(unsigned int vcc_volt, unsigned int ntc_volt) {
|
||||
if (ntc_volt == 0) {
|
||||
return 0.0f; // avoid division by zero on open circuit / sensor fault
|
||||
}
|
||||
int i = 0;
|
||||
float Vout = 0, Rt = 0, temp = 0;
|
||||
Vout = ntc_volt;
|
||||
|
||||
Rt = (HEATER_NTC_RP * vcc_volt) / Vout - HEATER_NTC_RP;
|
||||
float Rt = 0, temp = 0;
|
||||
Rt = (HEATER_NTC_RP * (float)vcc_volt) / ntc_volt - HEATER_NTC_RP;
|
||||
|
||||
for (i = 0; i < 136; i++) {
|
||||
if (Rt >= ntc_res2[i]) {
|
||||
|
|
@ -44,7 +45,17 @@ static float get_heater_temperature(unsigned int vcc_volt, unsigned int ntc_volt
|
|||
}
|
||||
}
|
||||
|
||||
temp = ntc_temp2[i - 1] + 1 * (ntc_res2[i - 1] - Rt) / (float)(ntc_res2[i - 1] - ntc_res2[i]);
|
||||
if (i <= 0) {
|
||||
return (float)ntc_temp2[0];
|
||||
}
|
||||
if (i >= 136) {
|
||||
return (float)ntc_temp2[135];
|
||||
}
|
||||
int denom = ntc_res2[i - 1] - ntc_res2[i];
|
||||
if (denom == 0) {
|
||||
return (float)ntc_temp2[i - 1];
|
||||
}
|
||||
temp = ntc_temp2[i - 1] + 1 * (ntc_res2[i - 1] - Rt) / (float)denom;
|
||||
|
||||
temp = (temp * 100 + 5) / 100;
|
||||
return temp;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue