This commit is contained in:
rusefillc 2022-06-20 21:49:31 -04:00
parent 58baac6d3f
commit bc0700d0dc
2 changed files with 15 additions and 1 deletions

View File

@ -1,5 +1,7 @@
package com.rusefi.can.reader.dbc;
import com.rusefi.can.CANPacket;
public class DbcField {
private final String name;
private final int startOffset;
@ -42,11 +44,15 @@ public class DbcField {
public static int getBitIndex(byte[] data, int bitIndex, int bitWidth) {
int byteIndex = bitIndex >> 3;
int shift = bitIndex - byteIndex * 8;
int value = data[byteIndex];
int value = data[byteIndex] & 0xff;
if (shift + bitWidth > 8) {
value = value + data[1 + byteIndex] * 256;
}
int mask = (1 << bitWidth) - 1;
return (value >> shift) & mask;
}
public double getValue(CANPacket packet) {
return getBitIndex(packet.getData(), startOffset, length) * mult;
}
}

View File

@ -13,6 +13,9 @@ import static com.rusefi.can.reader.impl.ParseDBC.VAG_MOTOR_1;
import static org.junit.Assert.assertEquals;
public class GetValueFromTrc {
public static final double EPS = 0.01;
@Test
public void test() throws IOException {
DbcFile dbc = new DbcFile();
@ -28,6 +31,7 @@ public class GetValueFromTrc {
assertEquals(8, packet.getData().length);
assertEquals(640, packet.getId());
assertEquals(0x12DF, DbcField.getBitIndex(packet.getData(), 16, 16));
assertEquals(0xDF1D, DbcField.getBitIndex(packet.getData(), 8, 16));
assertEquals(1, DbcField.getBitIndex(packet.getData(), 0, 3));
@ -36,6 +40,10 @@ public class GetValueFromTrc {
assertEquals(13 , DbcField.getBitIndex(packet.getData(), 8, 4));
DbcField bf = dbc.packets.get(0).find("rpm");
assertEquals(1207.75, bf.getValue(packet), EPS);
System.out.println(packet);
}
}