Bugfix: cycling sensors report wheel count as UINT32 - data type must be long, int is too small.

Also forgot to fix tests.

Fixes #810.
This commit is contained in:
Dennis Guse
2021-06-13 19:16:51 +02:00
parent 40188774b1
commit e9e48e4a79
4 changed files with 6 additions and 6 deletions
@@ -111,7 +111,7 @@ public class SensorDataCyclingTest {
@Test
public void compute_speed_rollOverCount() {
// given
SensorDataCycling.DistanceSpeed previous = new SensorDataCycling.DistanceSpeed("sensorAddress", "sensorName", UintUtils.UINT16_MAX - 1, 1024);
SensorDataCycling.DistanceSpeed previous = new SensorDataCycling.DistanceSpeed("sensorAddress", "sensorName", UintUtils.UINT32_MAX - 1, 1024);
SensorDataCycling.DistanceSpeed current = new SensorDataCycling.DistanceSpeed("sensorAddress", "sensorName", 0, 2048);
// when
@@ -18,6 +18,6 @@ public class UintUtilsTest {
@Test
public void realData() {
assertEquals(3, UintUtils.diff(381616, 381615, UintUtils.UINT32_MAX));
assertEquals(1, UintUtils.diff(381616, 381615, UintUtils.UINT32_MAX));
}
}
@@ -94,7 +94,7 @@ public final class SensorDataCycling {
public static class DistanceSpeed extends SensorData<DistanceSpeed.Data> {
private final Integer wheelRevolutionsCount; // UINT32
private final Long wheelRevolutionsCount; // UINT32
private final Integer wheelRevolutionsTime; // UINT16; 1/1024s
public DistanceSpeed(String sensorAddress) {
@@ -103,7 +103,7 @@ public final class SensorDataCycling {
this.wheelRevolutionsTime = null;
}
public DistanceSpeed(String sensorAddress, String sensorName, int wheelRevolutionsCount, int wheelRevolutionsTime) {
public DistanceSpeed(String sensorAddress, String sensorName, long wheelRevolutionsCount, int wheelRevolutionsTime) {
super(sensorAddress, sensorName);
this.wheelRevolutionsCount = wheelRevolutionsCount;
this.wheelRevolutionsTime = wheelRevolutionsTime;
@@ -113,7 +113,7 @@ public final class SensorDataCycling {
return wheelRevolutionsCount != null && wheelRevolutionsTime != null;
}
public int getWheelRevolutionsCount() {
public long getWheelRevolutionsCount() {
return wheelRevolutionsCount;
}
@@ -18,7 +18,7 @@ public class UintUtils {
throw new RuntimeException("a or b cannot be less than zero.");
}
if (a > UINT_MAX || b > UINT_MAX) {
throw new RuntimeException("a or b are outside of the allowed range." + a + " " + b);
throw new RuntimeException("a or b are outside of the allowed range.");
}
if (a >= b) {