parent
d80b055f7b
commit
9311417507
|
@ -51,19 +51,10 @@ public class PCanSandbox {
|
||||||
System.out.println("****************************************");
|
System.out.println("****************************************");
|
||||||
*/
|
*/
|
||||||
LinkManager linkManager = new LinkManager();
|
LinkManager linkManager = new LinkManager();
|
||||||
BinaryProtocol bp = new BinaryProtocol(linkManager, tsStream);
|
SandboxCommon.verifyCrcNoPending(tsStream, linkManager);
|
||||||
linkManager.COMMUNICATION_EXECUTOR.submit(() -> {
|
|
||||||
if (tsStream.getDataBuffer().dropPending() != 0)
|
ConfigurationImage ci = SandboxCommon.readImage(tsStream, linkManager);
|
||||||
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");
|
|
||||||
});
|
|
||||||
|
|
||||||
/*
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
package com.rusefi.binaryprotocol.test;
|
||||||
|
|
||||||
|
import com.opensr5.ConfigurationImage;
|
||||||
|
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||||
|
import com.rusefi.binaryprotocol.BinaryProtocolState;
|
||||||
|
import com.rusefi.config.generated.Fields;
|
||||||
|
import com.rusefi.io.ConnectionStateListener;
|
||||||
|
import com.rusefi.io.IoStream;
|
||||||
|
import com.rusefi.io.LinkManager;
|
||||||
|
import com.rusefi.io.serial.StreamConnector;
|
||||||
|
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
public class SandboxCommon {
|
||||||
|
static ConfigurationImage readImage(IoStream tsStream, LinkManager linkManager) throws InterruptedException {
|
||||||
|
AtomicReference<ConfigurationImage> configurationImageAtomicReference = new AtomicReference<>();
|
||||||
|
CountDownLatch imageLatch = new CountDownLatch(1);
|
||||||
|
|
||||||
|
StreamConnector streamConnector = new StreamConnector(linkManager, () -> tsStream);
|
||||||
|
linkManager.setConnector(streamConnector);
|
||||||
|
streamConnector.connectAndReadConfiguration(new BinaryProtocol.Arguments(false), 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();
|
||||||
|
configurationImageAtomicReference.set(ci);
|
||||||
|
imageLatch.countDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConnectionFailed() {
|
||||||
|
System.out.println("onConnectionFailed");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
imageLatch.await(1, TimeUnit.MINUTES);
|
||||||
|
ConfigurationImage ci = configurationImageAtomicReference.get();
|
||||||
|
System.out.println("Got ConfigurationImage " + ci + ", " + ci.getSize());
|
||||||
|
return ci;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void verifyCrcNoPending(IoStream tsStream, LinkManager 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");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,19 +2,11 @@ package com.rusefi.binaryprotocol.test;
|
||||||
|
|
||||||
import com.opensr5.ConfigurationImage;
|
import com.opensr5.ConfigurationImage;
|
||||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||||
import com.rusefi.binaryprotocol.BinaryProtocolState;
|
|
||||||
import com.rusefi.config.generated.Fields;
|
|
||||||
import com.rusefi.io.ConnectionStateListener;
|
|
||||||
import com.rusefi.io.IoStream;
|
|
||||||
import com.rusefi.io.LinkManager;
|
import com.rusefi.io.LinkManager;
|
||||||
import com.rusefi.io.serial.StreamConnector;
|
|
||||||
import com.rusefi.io.tcp.TcpIoStream;
|
import com.rusefi.io.tcp.TcpIoStream;
|
||||||
import jdk.nashorn.internal.runtime.regexp.joni.constants.Arguments;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.concurrent.CountDownLatch;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
import static com.rusefi.io.tcp.TcpConnector.DEFAULT_PORT;
|
import static com.rusefi.io.tcp.TcpConnector.DEFAULT_PORT;
|
||||||
import static com.rusefi.io.tcp.TcpConnector.LOCALHOST;
|
import static com.rusefi.io.tcp.TcpConnector.LOCALHOST;
|
||||||
|
@ -27,51 +19,11 @@ public class SimulatorTcpSandbox {
|
||||||
TcpIoStream tsStream = new TcpIoStream("sandbox", s);
|
TcpIoStream tsStream = new TcpIoStream("sandbox", s);
|
||||||
|
|
||||||
LinkManager linkManager = new LinkManager();
|
LinkManager linkManager = new LinkManager();
|
||||||
verifyCrcNoPending(tsStream, linkManager);
|
SandboxCommon.verifyCrcNoPending(tsStream, linkManager);
|
||||||
|
|
||||||
AtomicReference<ConfigurationImage> configurationImageAtomicReference = new AtomicReference<>();
|
ConfigurationImage ci = SandboxCommon.readImage(tsStream, linkManager);
|
||||||
CountDownLatch imageLatch = new CountDownLatch(1);
|
|
||||||
|
|
||||||
StreamConnector streamConnector = new StreamConnector(linkManager, () -> tsStream);
|
|
||||||
linkManager.setConnector(streamConnector);
|
|
||||||
streamConnector.connectAndReadConfiguration(new BinaryProtocol.Arguments(false), 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();
|
|
||||||
configurationImageAtomicReference.set(ci);
|
|
||||||
imageLatch.countDown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onConnectionFailed() {
|
|
||||||
System.out.println("onConnectionFailed");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
imageLatch.await();
|
|
||||||
ConfigurationImage ci = configurationImageAtomicReference.get();
|
|
||||||
System.out.println("Got ConfigurationImage " + ci + ", " + ci.getSize());
|
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void verifyCrcNoPending(IoStream tsStream, LinkManager 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");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue