mirror of https://github.com/rusefi/rusefi-1.git
more test code
This commit is contained in:
parent
71fe722b31
commit
d239ef2167
|
@ -9,12 +9,19 @@ import com.rusefi.io.commands.HelloCommand;
|
||||||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||||
import com.rusefi.io.tcp.TcpIoStream;
|
import com.rusefi.io.tcp.TcpIoStream;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
|
import static com.rusefi.binaryprotocol.IoHelper.swap16;
|
||||||
import static com.rusefi.config.generated.Fields.TS_PROTOCOL;
|
import static com.rusefi.config.generated.Fields.TS_PROTOCOL;
|
||||||
import static com.rusefi.io.tcp.BinaryProtocolServer.TS_OK;
|
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 class TcpServerSandbox {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
BinaryProtocolServer.tcpServerSocket(29001,
|
BinaryProtocolServer.tcpServerSocket(29001,
|
||||||
|
@ -30,7 +37,7 @@ public class TcpServerSandbox {
|
||||||
System.out.println("Run server socket: " + socket);
|
System.out.println("Run server socket: " + socket);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IoStream stream = new TcpIoStream("gauge", socket);
|
IoStream stream = new TcpIoStream(TcpServerSandbox.class.getSimpleName(), socket);
|
||||||
IncomingDataBuffer in = stream.getDataBuffer();
|
IncomingDataBuffer in = stream.getDataBuffer();
|
||||||
|
|
||||||
while (!socket.isClosed()) {
|
while (!socket.isClosed()) {
|
||||||
|
@ -45,6 +52,17 @@ public class TcpServerSandbox {
|
||||||
new HelloCommand(Fields.TS_SIGNATURE).handle(stream);
|
new HelloCommand(Fields.TS_SIGNATURE).handle(stream);
|
||||||
} else if (command == Fields.TS_GET_PROTOCOL_VERSION_COMMAND_F) {
|
} else if (command == Fields.TS_GET_PROTOCOL_VERSION_COMMAND_F) {
|
||||||
stream.sendPacket((TS_OK + TS_PROTOCOL).getBytes());
|
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
|
} else
|
||||||
throw new UnsupportedOperationException("Unsupported command " + command);
|
throw new UnsupportedOperationException("Unsupported command " + command);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue