only:reducing code duplication in CAN connectors

This commit is contained in:
rusefillc 2023-07-09 17:30:39 -04:00
parent 1b77158bfc
commit 6c7066d45f
6 changed files with 13 additions and 25 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -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);
} }

View File

@ -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;

View File

@ -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() {
}
} }

View File

@ -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);