only:reducing code duplication in CAN connectors
This commit is contained in:
parent
1b77158bfc
commit
6c7066d45f
|
@ -42,15 +42,9 @@ public class PCanIoStream extends AbstractIoStream {
|
||||||
|
|
||||||
private final IsoTpConnector isoTpConnector = new IsoTpConnector() {
|
private final IsoTpConnector isoTpConnector = new IsoTpConnector() {
|
||||||
@Override
|
@Override
|
||||||
public void sendCanData(byte[] hdr, byte[] data, int dataOffset, int dataLength) {
|
public void sendCanData(byte[] total) {
|
||||||
byte[] total = combineArrays(hdr, data, dataOffset, dataLength);
|
|
||||||
|
|
||||||
sendCanPacket(total);
|
sendCanPacket(total);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void receiveData() {
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
private int logSkipRate;
|
private int logSkipRate;
|
||||||
|
|
||||||
|
|
|
@ -39,15 +39,9 @@ public class SocketCANIoStream extends AbstractIoStream {
|
||||||
|
|
||||||
private final IsoTpConnector isoTpConnector = new IsoTpConnector() {
|
private final IsoTpConnector isoTpConnector = new IsoTpConnector() {
|
||||||
@Override
|
@Override
|
||||||
public void sendCanData(byte[] hdr, byte[] data, int dataOffset, int dataLength) {
|
public void sendCanData(byte[] total) {
|
||||||
byte[] total = combineArrays(hdr, data, dataOffset, dataLength);
|
|
||||||
|
|
||||||
sendCanPacket(total);
|
sendCanPacket(total);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void receiveData() {
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private void sendCanPacket(byte[] total) {
|
private void sendCanPacket(byte[] total) {
|
||||||
|
|
|
@ -154,8 +154,7 @@ public class Elm327Connector implements Closeable {
|
||||||
|
|
||||||
private final IsoTpConnector connector = new IsoTpConnector() {
|
private final IsoTpConnector connector = new IsoTpConnector() {
|
||||||
@Override
|
@Override
|
||||||
public void sendCanData(byte[] hdr, byte[] data, int dataOffset, int dataLength) {
|
public void sendCanData(byte[] total) {
|
||||||
byte[] total = combineArrays(hdr, data, dataOffset, dataLength);
|
|
||||||
Elm327Connector.this.sendCanData(total);
|
Elm327Connector.this.sendCanData(total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.rusefi.io.can.elm;
|
||||||
import com.opensr5.io.DataListener;
|
import com.opensr5.io.DataListener;
|
||||||
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||||
import com.rusefi.binaryprotocol.IoHelper;
|
import com.rusefi.binaryprotocol.IoHelper;
|
||||||
|
import com.rusefi.io.can.isotp.IsoTpCanDecoder;
|
||||||
import com.rusefi.io.serial.AbstractIoStream;
|
import com.rusefi.io.serial.AbstractIoStream;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,13 @@ public abstract class IsoTpConnector {
|
||||||
sendCanData(new byte[]{(byte) hdr0, (byte) hdr1}, data, dataOffset, dataLength);
|
sendCanData(new byte[]{(byte) hdr0, (byte) hdr1}, data, dataOffset, dataLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void sendCanData(byte[] hdr, byte[] data, int dataOffset, int dataLength);
|
public void sendCanData(byte[] hdr, byte[] data, int dataOffset, int dataLength) {
|
||||||
|
byte[] total = combineArrays(hdr, data, dataOffset, dataLength);
|
||||||
|
sendCanData(total);
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void receiveData();
|
public abstract void sendCanData(byte[] total);
|
||||||
|
|
||||||
|
public void receiveData() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,16 +19,10 @@ public class IsoTpConnectorTest {
|
||||||
|
|
||||||
IsoTpConnector testConnector = new IsoTpConnector() {
|
IsoTpConnector testConnector = new IsoTpConnector() {
|
||||||
@Override
|
@Override
|
||||||
public void sendCanData(byte[] hdr, byte[] data, int dataOffset, int dataLength) {
|
public void sendCanData(byte[] total) {
|
||||||
byte[] total = combineArrays(hdr, data, dataOffset, dataLength);
|
|
||||||
|
|
||||||
String packetAsString = HexBinary.printHexBinary(total);
|
String packetAsString = HexBinary.printHexBinary(total);
|
||||||
packets.add(packetAsString);
|
packets.add(packetAsString);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void receiveData() {
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
IsoTpConnector.sendStrategy(crcWrappedCrcRequest, testConnector);
|
IsoTpConnector.sendStrategy(crcWrappedCrcRequest, testConnector);
|
||||||
|
|
Loading…
Reference in New Issue