more test code

This commit is contained in:
rusefillc 2022-05-28 17:49:44 -04:00
parent 71fe722b31
commit d239ef2167
1 changed files with 19 additions and 1 deletions

View File

@ -9,12 +9,19 @@ import com.rusefi.io.commands.HelloCommand;
import com.rusefi.io.tcp.BinaryProtocolServer;
import com.rusefi.io.tcp.TcpIoStream;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.net.Socket;
import static com.rusefi.binaryprotocol.IoHelper.swap16;
import static com.rusefi.config.generated.Fields.TS_PROTOCOL;
import static com.rusefi.io.tcp.BinaryProtocolServer.TS_OK;
/**
* Fully self-contained fake TCP-IP 'ECU' side of TS protocol
* does not have checkCrc32 command implementation so you have to remove it from .ini if you want to connect to this ECU
*/
public class TcpServerSandbox {
public static void main(String[] args) throws IOException {
BinaryProtocolServer.tcpServerSocket(29001,
@ -30,7 +37,7 @@ public class TcpServerSandbox {
System.out.println("Run server socket: " + socket);
try {
IoStream stream = new TcpIoStream("gauge", socket);
IoStream stream = new TcpIoStream(TcpServerSandbox.class.getSimpleName(), socket);
IncomingDataBuffer in = stream.getDataBuffer();
while (!socket.isClosed()) {
@ -45,6 +52,17 @@ public class TcpServerSandbox {
new HelloCommand(Fields.TS_SIGNATURE).handle(stream);
} else if (command == Fields.TS_GET_PROTOCOL_VERSION_COMMAND_F) {
stream.sendPacket((TS_OK + TS_PROTOCOL).getBytes());
} else if (command == Fields.TS_PAGE_COMMAND) {
stream.sendPacket(TS_OK.getBytes());
} else if (command == Fields.TS_READ_COMMAND) {
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(payload, 1, payload.length - 1));
int offset = swap16(dis.readShort());
int count = swap16(dis.readShort());
byte[] response = new byte[1 + count];
response[0] = (byte) TS_OK.charAt(0);
stream.sendPacket(response);
} else if (command == Fields.TS_GET_FIRMWARE_VERSION) {
stream.sendPacket((TS_OK + "rusEFI proxy").getBytes());
} else
throw new UnsupportedOperationException("Unsupported command " + command);
}