mirror of https://github.com/rusefi/rusefi-1.git
proxy progress
This commit is contained in:
parent
99fce91744
commit
063da572e7
|
@ -6,6 +6,8 @@ import com.opensr5.io.WriteStream;
|
|||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||
import com.rusefi.binaryprotocol.IoHelper;
|
||||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
|
@ -31,6 +33,18 @@ public interface IoStream extends WriteStream {
|
|||
return r.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
default BinaryProtocolServer.Packet readPacket() throws IOException {
|
||||
short length = readShort();
|
||||
return BinaryProtocolServer.readPromisedBytes(getDataBuffer(), length);
|
||||
}
|
||||
|
||||
default void sendPacket(BinaryProtocolServer.Packet packet) throws IOException {
|
||||
writeShort(packet.getPacket().length);
|
||||
write(packet.getPacket());
|
||||
writeInt(packet.getCrc());
|
||||
}
|
||||
|
||||
default void sendPacket(byte[] plainPacket, Logger logger) throws IOException {
|
||||
byte[] packet;
|
||||
if (BinaryProtocol.PLAIN_PROTOCOL) {
|
||||
|
|
|
@ -52,12 +52,12 @@ public class BinaryProtocolProxy {
|
|||
}
|
||||
}
|
||||
|
||||
private static void proxyControllerResponseToClient(IoStream targetInputStream, DataOutputStream clientOutputStream) throws IOException {
|
||||
short length = targetInputStream.readShort();
|
||||
BinaryProtocolServer.Packet packet = BinaryProtocolServer.readPromisedBytes(targetInputStream.getDataBuffer(), length);
|
||||
public static void proxyControllerResponseToClient(IoStream targetInputStream, DataOutputStream clientOutputStream) throws IOException {
|
||||
BinaryProtocolServer.Packet packet = targetInputStream.readPacket();
|
||||
|
||||
System.out.println("Relaying controller response length=" + length);
|
||||
clientOutputStream.writeShort(length);
|
||||
System.out.println("Relaying controller response length=" + packet.getPacket().length);
|
||||
// todo: replace with IoStream#sendPacket?
|
||||
clientOutputStream.writeShort(packet.getPacket().length);
|
||||
clientOutputStream.write(packet.getPacket());
|
||||
clientOutputStream.writeInt(packet.getCrc());
|
||||
clientOutputStream.flush();
|
||||
|
@ -73,9 +73,7 @@ public class BinaryProtocolProxy {
|
|||
byte command = (byte) dis.read();
|
||||
|
||||
System.out.println("Relaying client command " + BinaryProtocol.findCommand(command));
|
||||
// sending proxies packet to controller
|
||||
targetOutputStream.writeShort(length);
|
||||
targetOutputStream.write(packet.getPacket());
|
||||
targetOutputStream.writeInt(packet.getCrc());
|
||||
// sending proxied packet to controller
|
||||
targetOutputStream.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue