REO progress

This commit is contained in:
rusefi 2020-08-14 23:46:31 -04:00
parent 0dbf3c142c
commit b9550a3846
7 changed files with 63 additions and 45 deletions

View File

@ -33,7 +33,8 @@ import static com.rusefi.binaryprotocol.BinaryProtocol.sleep;
* see NetworkConnectorStartup
*/
public class NetworkConnector implements Closeable {
public static final byte REBOOT = 15;
public static final byte UPDATE_CONNECTOR_SOFTWARE = 15;
public static final byte UPDATE_FIRMWARE = 16;
private final static Logging log = Logging.getLogging(NetworkConnector.class);
private boolean isClosed;
@ -125,7 +126,7 @@ public class NetworkConnector implements Closeable {
if (command == Fields.TS_ONLINE_PROTOCOL) {
byte connectorCommand = packet.getPacket()[1];
log.info("Got connector command " + packet.getPacket());
if (connectorCommand == NetworkConnector.REBOOT) {
if (connectorCommand == NetworkConnector.UPDATE_CONNECTOR_SOFTWARE) {
context.onConnectorSoftwareUpdateRequest();
}
return;

View File

@ -14,9 +14,19 @@ import com.rusefi.server.ApplicationRequest;
import com.rusefi.server.rusEFISSLContext;
import com.rusefi.tools.online.HttpUtil;
import com.rusefi.tools.online.ProxyClient;
import org.apache.http.Consts;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
@ -37,6 +47,19 @@ public class LocalApplicationProxy implements Closeable {
this.authenticatorToProxyStream = authenticatorToProxyStream;
}
public static HttpResponse requestSoftwareUpdate(int httpPort, ApplicationRequest applicationRequest) throws IOException {
HttpPost httpPost = new HttpPost(ProxyClient.getHttpAddress(httpPort) + ProxyClient.UPDATE_CONNECTOR_SOFTWARE);
List<NameValuePair> form = new ArrayList<>();
form.add(new BasicNameValuePair(ProxyClient.JSON, applicationRequest.toJson()));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(form, Consts.UTF_8);
httpPost.setEntity(entity);
HttpClient httpclient = new DefaultHttpClient();
return httpclient.execute(httpPost);
}
public ApplicationRequest getApplicationRequest() {
return applicationRequest;
}

View File

@ -28,6 +28,7 @@ public class ProxyClient {
* @see LocalApplicationProxy#SERVER_PORT_FOR_APPLICATIONS
*/
public static final int SERVER_PORT_FOR_CONTROLLERS = getIntProperty("controllers.port", 8003);
public static final String JSON = "json";
public static List<PublicSession> getOnlineApplications(int httpPort) throws IOException {
return getOnlineApplications(getHttpAddress(httpPort) + LIST_CONTROLLERS_PATH);

View File

@ -15,24 +15,12 @@ import com.rusefi.proxy.client.LocalApplicationProxy;
import com.rusefi.proxy.client.LocalApplicationProxyContext;
import com.rusefi.server.*;
import com.rusefi.tools.online.HttpUtil;
import com.rusefi.tools.online.ProxyClient;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@ -168,20 +156,12 @@ public class FullServerTest {
assertEquals("applications size", 0, backend.getApplications().size());
HttpPost httpPost = new HttpPost(ProxyClient.getHttpAddress(httpPort) + ProxyClient.UPDATE_CONNECTOR_SOFTWARE);
List<NameValuePair> form = new ArrayList<>();
form.add(new BasicNameValuePair("json", applicationRequest.toJson()));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(form, Consts.UTF_8);
httpPost.setEntity(entity);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httpPost);
HttpResponse response = LocalApplicationProxy.requestSoftwareUpdate(httpPort, applicationRequest);
log.info(response.toString());
assertTrue("update requested", softwareUpdateRequest.await(3 * applicationTimeout, TimeUnit.MILLISECONDS));
}
}
}

View File

@ -148,7 +148,7 @@ public class ControllerConnectionState {
public void requestConnectorSoftwareUpdate() throws IOException {
byte[] packet = new byte[2];
packet[0] = Fields.TS_ONLINE_PROTOCOL;
packet[1] = NetworkConnector.REBOOT;
packet[1] = NetworkConnector.UPDATE_CONNECTOR_SOFTWARE;
stream.sendPacket(packet);
}
}

View File

@ -1,6 +1,7 @@
package com.rusefi.server;
import com.devexperts.logging.Logging;
import com.rusefi.tools.online.ProxyClient;
import org.takes.Request;
import org.takes.Response;
import org.takes.Take;
@ -30,12 +31,9 @@ public class UpdateRequestHandler implements Take {
try {
RqForm rqForm = new RqFormBase(req);
String json = rqForm.param("json").iterator().next();
String json = rqForm.param(ProxyClient.JSON).iterator().next();
ApplicationRequest applicationRequest = ApplicationRequest.valueOf(json);
UserDetails tuner = backend.getUserDetailsResolver().apply(applicationRequest.getSessionDetails().getAuthToken());
ControllerKey key = new ControllerKey(applicationRequest.getVehicleOwner().getUserId(), applicationRequest.getSessionDetails().getControllerInfo());
@ -45,14 +43,11 @@ public class UpdateRequestHandler implements Take {
throw new IOException("Not acquired " + tuner);
// should controller communication happen on http thread or not?
new Thread(new Runnable() {
@Override
public void run() {
try {
state.requestConnectorSoftwareUpdate();
} catch (IOException e) {
throw new IllegalStateException(e);
}
new Thread(() -> {
try {
state.requestConnectorSoftwareUpdate();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}).start();
@ -65,8 +60,4 @@ public class UpdateRequestHandler implements Take {
objectBuilder.add("result", "OK");
return new RsJson(objectBuilder.build());
}
private String get(RqForm rqForm, String name) throws IOException {
return rqForm.param(name).iterator().next();
}
}

View File

@ -19,6 +19,7 @@ import com.rusefi.tools.online.ProxyClient;
import com.rusefi.tools.online.PublicSession;
import com.rusefi.ui.AuthTokenPanel;
import com.rusefi.ui.util.URLLabel;
import org.jetbrains.annotations.NotNull;
import org.putgemin.VerticalFlowLayout;
import javax.swing.*;
@ -171,6 +172,21 @@ public class RemoteTab {
JButton connect = new JButton("Connect to " + publicSession.getVehicleOwner().getUserName());
connect.addActionListener(event -> connectToProxy(publicSession));
bottomPanel.add(connect);
JButton updateSoftware = new JButton("Update Connector");
updateSoftware.addActionListener(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
try {
LocalApplicationProxy.requestSoftwareUpdate(HttpUtil.PROXY_JSON_API_HTTP_PORT,
getApplicationRequest(publicSession));
} catch (IOException ioException) {
ioException.printStackTrace();
}
}
});
bottomPanel.add(updateSoftware);
}
JPanel userPanel = new JPanel(new BorderLayout());
@ -225,10 +241,7 @@ public class RemoteTab {
}
private void runAuthenticator(PublicSession publicSession, LocalApplicationProxy.ConnectionListener connectionListener) {
SessionDetails sessionDetails = new SessionDetails(publicSession.getControllerInfo(), AuthTokenPanel.getAuthToken(),
Integer.parseInt(oneTimePasswordControl.getText()), rusEFIVersion.CONSOLE_VERSION);
ApplicationRequest applicationRequest = new ApplicationRequest(sessionDetails, publicSession.getVehicleOwner());
ApplicationRequest applicationRequest = getApplicationRequest(publicSession);
try {
AtomicReference<ServerSocketReference> serverHolderAtomicReference = new AtomicReference<>();
@ -258,6 +271,15 @@ public class RemoteTab {
}
}
@NotNull
private ApplicationRequest getApplicationRequest(PublicSession publicSession) {
SessionDetails sessionDetails = new SessionDetails(publicSession.getControllerInfo(), AuthTokenPanel.getAuthToken(),
Integer.parseInt(oneTimePasswordControl.getText()), rusEFIVersion.CONSOLE_VERSION);
ApplicationRequest applicationRequest = new ApplicationRequest(sessionDetails, publicSession.getVehicleOwner());
return applicationRequest;
}
public JComponent getContent() {
return content;
}