isolating issue with unconsumed data
This commit is contained in:
parent
b820a9c49c
commit
59d2322b60
|
@ -144,7 +144,7 @@ public class BinaryProtocol {
|
|||
|
||||
private final Thread hook = new Thread(() -> closeComposites(), "BinaryProtocol::hook");
|
||||
|
||||
public BinaryProtocol(LinkManager linkManager, IoStream stream, IncomingDataBuffer dataBuffer) {
|
||||
public BinaryProtocol(LinkManager linkManager, IoStream stream) {
|
||||
this.linkManager = linkManager;
|
||||
this.stream = stream;
|
||||
|
||||
|
@ -155,7 +155,7 @@ public class BinaryProtocol {
|
|||
}
|
||||
};
|
||||
|
||||
incomingData = dataBuffer;
|
||||
incomingData = stream.getDataBuffer();
|
||||
Runtime.getRuntime().addShutdownHook(hook);
|
||||
needCompositeLogger = linkManager.getCompositeLogicEnabled();
|
||||
rpmListener = value -> {
|
||||
|
@ -432,25 +432,34 @@ public class BinaryProtocol {
|
|||
int crcOfLocallyCachedConfiguration = IoHelper.getCrc32(localCached.getContent());
|
||||
log.info(String.format(CONFIGURATION_RUSEFI_BINARY + " Local cache CRC %x\n", crcOfLocallyCachedConfiguration));
|
||||
|
||||
byte[] packet = createCrcCommand(localCached.getSize());
|
||||
byte[] response = executeCommand(packet, "get CRC32");
|
||||
int crcFromController = getCrcFromController(localCached.getSize());
|
||||
|
||||
if (checkResponseCode(response, (byte) Fields.TS_RESPONSE_OK) && response.length == 5) {
|
||||
ByteBuffer bb = ByteBuffer.wrap(response, 1, 4);
|
||||
// that's unusual - most of the protocol is LITTLE_ENDIAN
|
||||
bb.order(ByteOrder.BIG_ENDIAN);
|
||||
int crcFromController = bb.getInt();
|
||||
log.info(String.format("rusEFI says tune CRC32 0x%x %d\n", crcFromController, crcFromController));
|
||||
short crc16FromController = (short) crcFromController;
|
||||
log.info(String.format("rusEFI says tune CRC16 0x%x %d\n", crc16FromController, crc16FromController));
|
||||
if (crcOfLocallyCachedConfiguration == crcFromController) {
|
||||
return localCached;
|
||||
}
|
||||
if (crcOfLocallyCachedConfiguration == crcFromController) {
|
||||
return localCached;
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getCrcFromController(int configSize) {
|
||||
byte[] packet = createCrcCommand(configSize);
|
||||
byte[] response = executeCommand(packet, "get CRC32");
|
||||
|
||||
if (checkResponseCode(response, (byte) Fields.TS_RESPONSE_OK) && response.length == 5) {
|
||||
ByteBuffer bb = ByteBuffer.wrap(response, 1, 4);
|
||||
// that's unusual - most of the protocol is LITTLE_ENDIAN
|
||||
bb.order(ByteOrder.BIG_ENDIAN);
|
||||
int crcFromController = bb.getInt();
|
||||
log.info(String.format("rusEFI says tune CRC32 0x%x %d\n", crcFromController, crcFromController));
|
||||
short crc16FromController = (short) crcFromController;
|
||||
log.info(String.format("rusEFI says tune CRC16 0x%x %d\n", crc16FromController, crc16FromController));
|
||||
return crcFromController;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] createCrcCommand(int size) {
|
||||
byte[] packet = new byte[5];
|
||||
packet[0] = Fields.TS_CRC_CHECK_COMMAND;
|
||||
|
|
|
@ -10,7 +10,6 @@ import net.jcip.annotations.ThreadSafe;
|
|||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.devexperts.logging.Logging.getLogging;
|
||||
|
@ -151,7 +150,7 @@ public class IncomingDataBuffer {
|
|||
}
|
||||
}
|
||||
|
||||
public void dropPending() {
|
||||
public int dropPending() {
|
||||
// todo: when exactly do we need this logic?
|
||||
synchronized (cbb) {
|
||||
int pending = cbb.length();
|
||||
|
@ -161,6 +160,7 @@ public class IncomingDataBuffer {
|
|||
cbb.get(bytes);
|
||||
log.error("DROPPED FROM BUFFER: " + IoStream.printByteArray(bytes));
|
||||
}
|
||||
return pending;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ public class PortHolder {
|
|||
return false;
|
||||
}
|
||||
synchronized (portLock) {
|
||||
bp = new BinaryProtocol(linkManager, stream, stream.getDataBuffer());
|
||||
bp = new BinaryProtocol(linkManager, stream);
|
||||
portLock.notifyAll();
|
||||
}
|
||||
|
||||
|
|
|
@ -51,12 +51,34 @@ public class PCanSandbox {
|
|||
System.out.println("****************************************");
|
||||
*/
|
||||
LinkManager linkManager = new LinkManager();
|
||||
BinaryProtocol bp = new BinaryProtocol(linkManager, tsStream);
|
||||
linkManager.COMMUNICATION_EXECUTOR.submit(() -> {
|
||||
if (tsStream.getDataBuffer().dropPending() != 0)
|
||||
System.out.println("ERROR Extra data before CRC");
|
||||
bp.getCrcFromController(Fields.TOTAL_CONFIG_SIZE);
|
||||
// bp.getCrcFromController(Fields.TOTAL_CONFIG_SIZE);
|
||||
// bp.getCrcFromController(Fields.TOTAL_CONFIG_SIZE);
|
||||
if (tsStream.getDataBuffer().dropPending() != 0)
|
||||
System.out.println("ERROR Extra data after CRC");
|
||||
});
|
||||
|
||||
/*
|
||||
StreamConnector streamConnector = new StreamConnector(linkManager, () -> tsStream);
|
||||
linkManager.setConnector(streamConnector);
|
||||
streamConnector.connectAndReadConfiguration(new ConnectionStateListener() {
|
||||
@Override
|
||||
public void onConnectionEstablished() {
|
||||
System.out.println("onConnectionEstablished");
|
||||
|
||||
BinaryProtocol currentStreamState = linkManager.getCurrentStreamState();
|
||||
if (currentStreamState == null) {
|
||||
System.out.println("No BinaryProtocol");
|
||||
} else {
|
||||
BinaryProtocolState binaryProtocolState = currentStreamState.getBinaryProtocolState();
|
||||
ConfigurationImage ci = binaryProtocolState.getControllerConfiguration();
|
||||
System.out.println("Got ConfigurationImage " + ci);
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -64,14 +86,8 @@ public class PCanSandbox {
|
|||
System.out.println("onConnectionFailed");
|
||||
}
|
||||
});
|
||||
BinaryProtocol currentStreamState = linkManager.getCurrentStreamState();
|
||||
if (currentStreamState == null) {
|
||||
System.out.println("No BinaryProtocol");
|
||||
} else {
|
||||
BinaryProtocolState binaryProtocolState = currentStreamState.getBinaryProtocolState();
|
||||
ConfigurationImage ci = binaryProtocolState.getControllerConfiguration();
|
||||
System.out.println("Got ConfigurationImage " + ci);
|
||||
System.exit(0);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue