Fix consumption tracking while charging

This commit is contained in:
TCFDONMEZ
2026-10-02 11:15:22 +03:00
parent ecbee4980c
commit dbbfb9f803
10 changed files with 643 additions and 119 deletions
@@ -0,0 +1,38 @@
package com.evsuite.abrp;
/**
* Neumaier–Kahan compensated summation.
*
* Consumption is integrated from thousands of sub-watt-hour slices per drive. A plain
* {@code sum += x} loses the low bits of every one of them, and the error is one-signed,
* so it accumulates rather than cancelling. Ported from DriveHub_Dort, where this is what
* keeps the lifetime counter honest over months.
*/
final class KahanSum {
private double sum;
private double compensation;
void add(double input) {
double y = input - compensation;
double t = sum + y;
compensation = (t - sum) - y;
sum = t;
}
double get() {
return sum;
}
/** Clears the total and the compensation term. */
void reset() {
sum = 0d;
compensation = 0d;
}
/** Seeds the total from persistent storage; the compensation term starts clean. */
void setTotal(double total) {
sum = total;
compensation = 0d;
}
}