progress 0B5
This commit is contained in:
parent
600951b7b9
commit
39c846fd82
|
@ -1,8 +1,7 @@
|
|||
package com.rusefi.can;
|
||||
|
||||
import java.util.Arrays;
|
||||
import com.rusefi.can.decoders.AbstractPacketDecoder;
|
||||
|
||||
import static com.rusefi.can.Utils.bytesToHex;
|
||||
import static com.rusefi.can.Utils.bytesToHexWithSpaces;
|
||||
|
||||
public class CANPacket {
|
||||
|
@ -16,8 +15,21 @@ public class CANPacket {
|
|||
this.data = data;
|
||||
}
|
||||
|
||||
public int getTwoBytes(int index) {
|
||||
return getUnsigned(index + 1) * 256 + getUnsigned(index);
|
||||
/**
|
||||
* @param index, starting from zero
|
||||
*/
|
||||
public int getTwoBytesByByteIndex(int index) {
|
||||
return getByBitIndex(index * 8, 16);
|
||||
}
|
||||
|
||||
public int getByBitIndex(int bitIndex, int bitWidth) {
|
||||
int byteIndex = bitIndex / 8;
|
||||
int shift = bitIndex - byteIndex * 8;
|
||||
int value = getUnsigned(byteIndex);
|
||||
if (shift + bitIndex > 8) {
|
||||
value = value + getUnsigned(byteIndex + 1) * 256;
|
||||
}
|
||||
return value >> shift & AbstractPacketDecoder.mask(bitWidth);
|
||||
}
|
||||
|
||||
public double getTimeStamp() {
|
||||
|
|
|
@ -8,4 +8,6 @@ public enum SensorType {
|
|||
FUEL_AMOUNT,
|
||||
GEAR_CHANGE_REQUEST,
|
||||
GEAR,
|
||||
GEARBOX_CURRENT_TORQUE,
|
||||
GEARBOX_TORQUE_CHANGE_REQUEST,
|
||||
}
|
||||
|
|
|
@ -13,6 +13,10 @@ public abstract class AbstractPacketDecoder implements PacketDecoder {
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
public static int mask(int bitWidth) {
|
||||
return (1 << bitWidth) - 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return id;
|
||||
|
|
|
@ -16,7 +16,7 @@ public class Bmw0AA extends AbstractPacketDecoder {
|
|||
@Override
|
||||
public PacketPayload decode(CANPacket packet) {
|
||||
SensorValue pedal = new SensorValue(SensorType.PPS, packet.getUnsigned(3) * 0.39063);
|
||||
int rawRpm = packet.getTwoBytes(4);
|
||||
int rawRpm = packet.getTwoBytesByByteIndex(4);
|
||||
if (rawRpm == 0xFFFF)
|
||||
return null;
|
||||
SensorValue rpm = new SensorValue(SensorType.RPM, rawRpm * 0.25);
|
||||
|
|
|
@ -2,17 +2,24 @@ package com.rusefi.can.decoders.bmw;
|
|||
|
||||
import com.rusefi.can.CANPacket;
|
||||
import com.rusefi.can.PacketPayload;
|
||||
import com.rusefi.can.SensorType;
|
||||
import com.rusefi.can.SensorValue;
|
||||
import com.rusefi.can.decoders.AbstractPacketDecoder;
|
||||
|
||||
public class Bmw0B5 extends AbstractPacketDecoder {
|
||||
public static final int ID = 0xBA;
|
||||
public static final Bmw0B5 INSTANCE = new Bmw0B5();
|
||||
|
||||
public Bmw0B5() {
|
||||
super(ID);
|
||||
super(0xBA);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketPayload decode(CANPacket packet) {
|
||||
return null;
|
||||
int TORQ_TAR_EGS = (int) (packet.getByBitIndex(12, 12) * 0.5);
|
||||
int TORQ_TAR_ADJR_POS_EGS = packet.getByBitIndex(24, 12);
|
||||
int ST_TORQ_TAR_EGS = packet.getByBitIndex(36, 2);
|
||||
return new PacketPayload(packet.getTimeStamp(),
|
||||
new SensorValue(SensorType.GEARBOX_CURRENT_TORQUE, TORQ_TAR_EGS),
|
||||
new SensorValue(SensorType.GEARBOX_TORQUE_CHANGE_REQUEST, ST_TORQ_TAR_EGS));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ public class Bmw1D0 extends AbstractPacketDecoder {
|
|||
public PacketPayload decode(CANPacket packet) {
|
||||
SensorValue clt = new SensorValue(SensorType.CLT, packet.getUnsigned(0) - 48);
|
||||
SensorValue map = new SensorValue(SensorType.MAP, packet.getUnsigned(3) * 0.2 + 59.8);
|
||||
SensorValue fuel = new SensorValue(SensorType.FUEL_AMOUNT, packet.getTwoBytes(4));
|
||||
SensorValue fuel = new SensorValue(SensorType.FUEL_AMOUNT, packet.getTwoBytesByByteIndex(4));
|
||||
return new PacketPayload(packet.getTimeStamp(), clt, map, fuel);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.rusefi.can;
|
||||
|
||||
import com.rusefi.can.decoders.bmw.Bmw0AA;
|
||||
import com.rusefi.can.decoders.bmw.Bmw0B5;
|
||||
import com.rusefi.can.decoders.bmw.Bmw1D0;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -30,6 +31,16 @@ public class BmwE65DecoderTest {
|
|||
assertValue(SensorType.FUEL_AMOUNT, 24443, payload.getValues()[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decodeTorqueRequestEGS() {
|
||||
CANPacket packet = new CANPacket(1,
|
||||
-1, new byte[]{(byte) 0x9F, 0x01, 0x32, 0x20, 0x23, 0x30, (byte) 0xFF, 0x43});
|
||||
PacketPayload payload = Bmw0B5.INSTANCE.decode(packet);
|
||||
assertValue(SensorType.GEARBOX_CURRENT_TORQUE, 400.0, payload.getValues()[0]);
|
||||
assertValue(SensorType.GEARBOX_TORQUE_CHANGE_REQUEST, 2, payload.getValues()[1]);
|
||||
|
||||
}
|
||||
|
||||
private void assertValue(SensorType expectedType, double v, SensorValue value) {
|
||||
assertEquals(expectedType, value.getType());
|
||||
assertEquals(v, value.getValue(), 0.01);
|
||||
|
|
|
@ -12,7 +12,7 @@ public class CANoeReaderTest {
|
|||
@Test
|
||||
public void readLine() {
|
||||
String line = " 12.961970 2 1AC Rx d 4 00 10 00 00 Length = 166000 BitCount = 87 ID = 428";
|
||||
CANoeReader reader = new CANoeReader();
|
||||
CANoeReader reader = CANoeReader.INSTANCE;
|
||||
|
||||
CANPacket packet = reader.readLine(line);
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import static junit.framework.TestCase.assertEquals;
|
|||
public class PcanReaderTest {
|
||||
@Test
|
||||
public void testLine() {
|
||||
CANLineReader reader = new PcanReader();
|
||||
CANLineReader reader = PcanReader.INSTANCE;
|
||||
CANPacket packet = reader.readLine(" 15883 77333097.212 DT 0192 Rx 4 2D 04 80 F9 ");
|
||||
assertEquals(4, packet.getData().length);
|
||||
assertEquals(Bmw192.ID, packet.getId());
|
||||
|
|
Loading…
Reference in New Issue