parent
43bc0fee81
commit
0674a2d5de
|
@ -1,6 +1,5 @@
|
|||
package com.rusefi.ldmp;
|
||||
|
||||
import com.rusefi.OutputChannel;
|
||||
import com.rusefi.config.Field;
|
||||
import com.rusefi.config.generated.*;
|
||||
import com.rusefi.enums.live_data_e;
|
||||
|
@ -50,6 +49,20 @@ public enum StateDictionary {
|
|||
}
|
||||
}
|
||||
|
||||
static int getSize(Field[] values) {
|
||||
Field last = values[values.length - 1];
|
||||
return last.getOffset() + last.getType().getStorageSize();
|
||||
}
|
||||
|
||||
public int getOffset(live_data_e live_data_e) {
|
||||
int result = 0;
|
||||
for (live_data_e index : live_data_e.values()) {
|
||||
if (index.ordinal() < live_data_e.ordinal())
|
||||
result += getSize(getFields(index));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void register(live_data_e ldsIndex, Field[] values, String fileName) {
|
||||
map.put(ldsIndex, values);
|
||||
fileNames.put(ldsIndex, fileName);
|
||||
|
|
|
@ -1,12 +1,29 @@
|
|||
package com.rusefi.ldmp;
|
||||
|
||||
import com.rusefi.config.generated.TsOutputs;
|
||||
import com.rusefi.enums.live_data_e;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class StateDictionaryTest {
|
||||
|
||||
private static final int OUTPUTS_SIZE = 612;
|
||||
|
||||
@Test
|
||||
public void testStateDictionaryIsComplete() {
|
||||
// we assert that this does not fail
|
||||
StateDictionary.INSTANCE.getFields(live_data_e.LDS_ac_control);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStructSize() {
|
||||
// todo: do we have this struct size anywhere?
|
||||
assertEquals(OUTPUTS_SIZE, StateDictionary.getSize(TsOutputs.VALUES));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOffset() {
|
||||
assertEquals(OUTPUTS_SIZE, StateDictionary.INSTANCE.getOffset(live_data_e.LDS_knock_controller));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,14 +19,25 @@ public class SensorCentral implements ISensorCentral {
|
|||
private final SensorsHolder sensorsHolder = new SensorsHolder();
|
||||
|
||||
private final Map<Sensor, List<SensorListener>> allListeners = new EnumMap<>(Sensor.class);
|
||||
private byte[] response;
|
||||
|
||||
public static ISensorCentral getInstance() {
|
||||
public static SensorCentral getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private SensorCentral() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void grabSensorValues(byte[] response) {
|
||||
this.response = response;
|
||||
ISensorCentral.super.grabSensorValues(response);
|
||||
}
|
||||
|
||||
public byte[] getResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getValue(Sensor sensor) {
|
||||
return sensorsHolder.getValue(sensor);
|
||||
|
|
Loading…
Reference in New Issue