proxy progress - reading controller on connect
This commit is contained in:
parent
9e3233df92
commit
1b651a466b
|
@ -59,14 +59,10 @@ public class rusEFISSLContext {
|
|||
// }
|
||||
}
|
||||
|
||||
public static Socket getSSLSocket(String host, int port) {
|
||||
try {
|
||||
public static Socket getSSLSocket(String host, int port) throws IOException {
|
||||
if (isJenkins)
|
||||
return new Socket(host, port);
|
||||
return getSSLSocketFactory(null /*key*/, TLS).createSocket(host, port);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -129,7 +129,7 @@ public class AuthTokenPanel {
|
|||
}
|
||||
|
||||
public boolean hasToken() {
|
||||
return textField.getText().trim().length() > 0 && !textField.getText().contains(TOKEN_SUBSTRING);
|
||||
return AutoTokenUtil.isToken(textField.getText());
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package com.rusefi.tools;
|
||||
|
||||
import com.opensr5.Logger;
|
||||
import com.rusefi.auth.AutoTokenUtil;
|
||||
import com.rusefi.autodetect.PortDetector;
|
||||
import com.rusefi.io.ConnectionStateListener;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.proxy.NetworkConnector;
|
||||
import com.rusefi.server.Backend;
|
||||
import com.rusefi.ui.AuthTokenPanel;
|
||||
|
@ -11,21 +9,20 @@ import com.rusefi.ui.AuthTokenPanel;
|
|||
import java.io.IOException;
|
||||
|
||||
public class NetworkConnectorStartup {
|
||||
public static void start(String[] strings) throws IOException {
|
||||
public static void start(String[] strings) throws IOException, InterruptedException {
|
||||
String authToken = AuthTokenPanel.getAuthToken();
|
||||
if (!AutoTokenUtil.isToken(authToken)) {
|
||||
System.err.println("Please configure authentication token using 'set_auth_token' command");
|
||||
return;
|
||||
}
|
||||
|
||||
String autoDetectedPort = PortDetector.autoDetectSerial(null);
|
||||
if (autoDetectedPort == null) {
|
||||
System.err.println(ConsoleTools.RUS_EFI_NOT_DETECTED);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
LinkManager linkManager = new LinkManager(Logger.CONSOLE)
|
||||
.setCompositeLogicEnabled(false)
|
||||
.setNeedPullData(false);
|
||||
linkManager.startAndConnect(autoDetectedPort, ConnectionStateListener.VOID);
|
||||
|
||||
String authToken = AuthTokenPanel.getAuthToken();
|
||||
NetworkConnector.runNetworkConnector(Backend.SERVER_PORT_FOR_CONTROLLERS, linkManager.getConnector().getBinaryProtocol().getStream(), Logger.CONSOLE,
|
||||
authToken);
|
||||
NetworkConnector.runNetworkConnector(authToken, autoDetectedPort, Backend.SERVER_PORT_FOR_CONTROLLERS);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -190,8 +190,7 @@ public class ServerTest {
|
|||
|
||||
|
||||
// start "rusEFI network connector" to connect controller with backend since in real life controller has only local serial port it does not have network
|
||||
IoStream targetEcuSocket = TestHelper.connectToLocalhost(controllerPort, logger);
|
||||
SessionDetails deviceSessionDetails = NetworkConnector.runNetworkConnector(serverPortForControllers, targetEcuSocket, logger, MockRusEfiDevice.TEST_TOKEN_1);
|
||||
SessionDetails deviceSessionDetails = NetworkConnector.runNetworkConnector(MockRusEfiDevice.TEST_TOKEN_1, ProxyClient.LOCALHOST + ":" + controllerPort, serverPortForControllers);
|
||||
|
||||
assertTrue(controllerRegistered.await(READ_IMAGE_TIMEOUT, TimeUnit.MILLISECONDS));
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package com.rusefi.proxy;
|
||||
|
||||
import com.opensr5.Logger;
|
||||
import com.rusefi.io.ConnectionStateListener;
|
||||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.io.commands.HelloCommand;
|
||||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||
import com.rusefi.io.tcp.TcpIoStream;
|
||||
|
@ -12,17 +14,48 @@ import com.rusefi.tools.online.HttpUtil;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Connector between rusEFI ECU and rusEFI server
|
||||
*/
|
||||
public class NetworkConnector {
|
||||
public static SessionDetails runNetworkConnector(String authToken, String controllerPort, int serverPortForControllers) throws InterruptedException, IOException {
|
||||
LinkManager linkManager = new LinkManager(Logger.CONSOLE)
|
||||
.setCompositeLogicEnabled(false)
|
||||
.setNeedPullData(false);
|
||||
|
||||
CountDownLatch onConnected = new CountDownLatch(1);
|
||||
linkManager.startAndConnect(controllerPort, new ConnectionStateListener() {
|
||||
@Override
|
||||
public void onConnectionEstablished() {
|
||||
onConnected.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionFailed() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
System.out.println("Connecting to controller...");
|
||||
onConnected.await(1, TimeUnit.MINUTES);
|
||||
if (onConnected.getCount() != 0) {
|
||||
System.out.println("Connection to controller failed");
|
||||
return null;
|
||||
}
|
||||
|
||||
return runNetworkConnector(serverPortForControllers, linkManager, Logger.CONSOLE, authToken);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SessionDetails runNetworkConnector(int serverPortForControllers, IoStream targetEcuSocket, final Logger logger, String authToken) throws IOException {
|
||||
private static SessionDetails runNetworkConnector(int serverPortForControllers, LinkManager linkManager, final Logger logger, String authToken) throws IOException {
|
||||
IoStream targetEcuSocket = linkManager.getConnector().getBinaryProtocol().getStream();
|
||||
HelloCommand.send(targetEcuSocket, logger);
|
||||
String controllerSignature = HelloCommand.getHelloResponse(targetEcuSocket.getDataBuffer(), logger);
|
||||
|
||||
// Fields.VEHICLENAME.getAnyValue()
|
||||
// todo: request vehicle info from controller
|
||||
ControllerInfo ci = new ControllerInfo("vehicle", "make", "code", controllerSignature);
|
||||
|
||||
|
|
Loading…
Reference in New Issue