remote firmware request
This commit is contained in:
parent
d034a12998
commit
ea569d5a84
|
@ -49,11 +49,12 @@ public class LocalApplicationProxy implements Closeable {
|
|||
this.authenticatorToProxyStream = authenticatorToProxyStream;
|
||||
}
|
||||
|
||||
public static HttpResponse requestSoftwareUpdate(int httpPort, ApplicationRequest applicationRequest) throws IOException {
|
||||
public static HttpResponse requestSoftwareUpdate(int httpPort, ApplicationRequest applicationRequest, UpdateType type) 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()));
|
||||
form.add(new BasicNameValuePair(ProxyClient.UPDATE_TYPE, type.name()));
|
||||
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(form, Consts.UTF_8);
|
||||
|
||||
httpPost.setEntity(entity);
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package com.rusefi.proxy.client;
|
||||
|
||||
public enum UpdateType {
|
||||
CONTROLLER,
|
||||
FIRMWARE
|
||||
}
|
|
@ -21,7 +21,7 @@ public class ProxyClient {
|
|||
public static final String LIST_APPLICATIONS_PATH = "/list_applications";
|
||||
public static final String VERSION_PATH = "/version";
|
||||
public static final String UPDATE_CONNECTOR_SOFTWARE = "/update_connector_software";
|
||||
public static final String BACKEND_VERSION = "0.0002";
|
||||
public static final String BACKEND_VERSION = "0.0003";
|
||||
public static final String IS_USED = "isUsed";
|
||||
public static final String OWNER = "owner";
|
||||
/**
|
||||
|
@ -30,6 +30,7 @@ public class ProxyClient {
|
|||
*/
|
||||
public static final int SERVER_PORT_FOR_CONTROLLERS = getIntProperty("controllers.port", 8003);
|
||||
public static final String JSON = "json";
|
||||
public static final String UPDATE_TYPE = "type";
|
||||
|
||||
public static List<PublicSession> getOnlineApplications(int httpPort) throws IOException {
|
||||
return getOnlineApplications(getHttpAddress(httpPort) + LIST_CONTROLLERS_PATH);
|
||||
|
|
|
@ -13,6 +13,7 @@ import com.rusefi.proxy.NetworkConnector;
|
|||
import com.rusefi.proxy.NetworkConnectorContext;
|
||||
import com.rusefi.proxy.client.LocalApplicationProxy;
|
||||
import com.rusefi.proxy.client.LocalApplicationProxyContext;
|
||||
import com.rusefi.proxy.client.UpdateType;
|
||||
import com.rusefi.server.*;
|
||||
import com.rusefi.tools.online.HttpUtil;
|
||||
import org.apache.http.HttpResponse;
|
||||
|
@ -157,7 +158,7 @@ public class FullServerTest {
|
|||
assertEquals("applications size", 0, backend.getApplications().size());
|
||||
|
||||
|
||||
HttpResponse response = LocalApplicationProxy.requestSoftwareUpdate(httpPort, applicationRequest);
|
||||
HttpResponse response = LocalApplicationProxy.requestSoftwareUpdate(httpPort, applicationRequest, UpdateType.CONTROLLER);
|
||||
log.info(response.toString());
|
||||
|
||||
assertTrue("update requested", softwareUpdateRequest.await(3 * applicationTimeout, TimeUnit.MILLISECONDS));
|
||||
|
|
|
@ -9,7 +9,6 @@ import com.rusefi.io.IoStream;
|
|||
import com.rusefi.io.commands.GetOutputsCommand;
|
||||
import com.rusefi.io.commands.HelloCommand;
|
||||
import com.rusefi.io.tcp.TcpIoStream;
|
||||
import com.rusefi.proxy.NetworkConnector;
|
||||
import com.rusefi.shared.FileUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -148,10 +147,10 @@ public class ControllerConnectionState {
|
|||
}
|
||||
}
|
||||
|
||||
public void requestConnectorSoftwareUpdate() throws IOException {
|
||||
public void invokeOnlineCommand(byte command) throws IOException {
|
||||
byte[] packet = new byte[2];
|
||||
packet[0] = Fields.TS_ONLINE_PROTOCOL;
|
||||
packet[1] = NetworkConnector.UPDATE_CONNECTOR_SOFTWARE;
|
||||
packet[1] = command;
|
||||
stream.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.rusefi.server;
|
||||
|
||||
import com.devexperts.logging.Logging;
|
||||
import com.rusefi.proxy.NetworkConnector;
|
||||
import com.rusefi.proxy.client.UpdateType;
|
||||
import com.rusefi.tools.online.ProxyClient;
|
||||
import org.takes.Request;
|
||||
import org.takes.Response;
|
||||
|
@ -32,11 +34,13 @@ public class UpdateRequestHandler implements Take {
|
|||
RqForm rqForm = new RqFormBase(req);
|
||||
|
||||
String json = rqForm.param(ProxyClient.JSON).iterator().next();
|
||||
String type = rqForm.param(ProxyClient.UPDATE_TYPE).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());
|
||||
log.info("Online Request for " + key + ": " + type);
|
||||
|
||||
ControllerConnectionState state = backend.acquire(key, tuner);
|
||||
if (state == null)
|
||||
|
@ -45,7 +49,11 @@ public class UpdateRequestHandler implements Take {
|
|||
// should controller communication happen on http thread or not?
|
||||
new Thread(() -> {
|
||||
try {
|
||||
state.requestConnectorSoftwareUpdate();
|
||||
if (type.equals(UpdateType.FIRMWARE.name())) {
|
||||
state.invokeOnlineCommand(NetworkConnector.UPDATE_FIRMWARE);
|
||||
} else {
|
||||
state.invokeOnlineCommand(NetworkConnector.UPDATE_CONNECTOR_SOFTWARE);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
} finally {
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.rusefi.io.tcp.TcpIoStream;
|
|||
import com.rusefi.proxy.NetworkConnector;
|
||||
import com.rusefi.proxy.client.LocalApplicationProxy;
|
||||
import com.rusefi.proxy.client.LocalApplicationProxyContextImpl;
|
||||
import com.rusefi.proxy.client.UpdateType;
|
||||
import com.rusefi.rusEFIVersion;
|
||||
import com.rusefi.server.ApplicationRequest;
|
||||
import com.rusefi.server.ControllerInfo;
|
||||
|
@ -168,7 +169,7 @@ public class RemoteTab {
|
|||
topLine.add(new JLabel(publicSession.getVehicleOwner().getUserName()));
|
||||
topLine.add(new JLabel(controllerInfo.getVehicleName() + " " + controllerInfo.getEngineMake() + " " + controllerInfo.getEngineCode()));
|
||||
|
||||
JPanel bottomPanel = new JPanel(new FlowLayout());
|
||||
JPanel bottomPanel = new JPanel(new VerticalFlowLayout());
|
||||
|
||||
if (publicSession.isUsed()) {
|
||||
bottomPanel.add(new JLabel(" Used by " + publicSession.getTunerName()));
|
||||
|
@ -185,17 +186,19 @@ public class RemoteTab {
|
|||
updateSoftware.addActionListener(new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
LocalApplicationProxy.requestSoftwareUpdate(HttpUtil.PROXY_JSON_API_HTTP_PORT,
|
||||
getApplicationRequest(publicSession));
|
||||
updateSoftware.setText("Update requested");
|
||||
} catch (IOException ioException) {
|
||||
ioException.printStackTrace();
|
||||
}
|
||||
requestUpdate(publicSession, updateSoftware, UpdateType.CONTROLLER);
|
||||
}
|
||||
});
|
||||
bottomPanel.add(updateSoftware);
|
||||
}
|
||||
|
||||
JButton updateFirmware = new JButton("Update ECU firmware");
|
||||
updateFirmware.addActionListener(new AbstractAction() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
requestUpdate(publicSession, updateFirmware, UpdateType.FIRMWARE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -214,6 +217,16 @@ public class RemoteTab {
|
|||
return userPanel;
|
||||
}
|
||||
|
||||
private void requestUpdate(PublicSession publicSession, JButton updateSoftware, UpdateType type) {
|
||||
try {
|
||||
LocalApplicationProxy.requestSoftwareUpdate(HttpUtil.PROXY_JSON_API_HTTP_PORT,
|
||||
getApplicationRequest(publicSession), type);
|
||||
updateSoftware.setText("Update requested");
|
||||
} catch (IOException ioException) {
|
||||
ioException.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private URLLabel getSignatureDownload(ControllerInfo controllerInfo) {
|
||||
Pair<String, String> url = SignatureHelper.getUrl(controllerInfo.getSignature());
|
||||
|
|
Loading…
Reference in New Issue