REO progress
This commit is contained in:
parent
2c0db8e970
commit
a59f865e59
|
@ -7,6 +7,7 @@ import com.opensr5.io.ConfigurationImageFile;
|
|||
import com.opensr5.io.DataListener;
|
||||
import com.rusefi.ConfigurationImageDiff;
|
||||
import com.rusefi.NamedThreadFactory;
|
||||
import com.rusefi.SignatureHelper;
|
||||
import com.rusefi.Timeouts;
|
||||
import com.rusefi.composite.CompositeEvent;
|
||||
import com.rusefi.composite.CompositeParser;
|
||||
|
@ -17,6 +18,7 @@ import com.rusefi.core.Sensor;
|
|||
import com.rusefi.core.SensorCentral;
|
||||
import com.rusefi.io.*;
|
||||
import com.rusefi.io.commands.GetOutputsCommand;
|
||||
import com.rusefi.io.commands.HelloCommand;
|
||||
import com.rusefi.stream.LogicdataStreamFile;
|
||||
import com.rusefi.stream.StreamFile;
|
||||
import com.rusefi.stream.TSHighSpeedLog;
|
||||
|
@ -228,6 +230,14 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
|||
* @return true if everything fine
|
||||
*/
|
||||
public boolean connectAndReadConfiguration(DataListener listener) {
|
||||
try {
|
||||
HelloCommand.send(stream);
|
||||
String response = HelloCommand.getHelloResponse(incomingData);
|
||||
System.out.println("Got " + response);
|
||||
SignatureHelper.downloadIfNotAvailable(SignatureHelper.getUrl(response));
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
// switchToBinaryProtocol();
|
||||
readImage(Fields.TOTAL_CONFIG_SIZE);
|
||||
if (isClosed)
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.net.URL;
|
|||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class rusEFIVersion {
|
||||
public static final int CONSOLE_VERSION = 20200928;
|
||||
public static final int CONSOLE_VERSION = 20201001;
|
||||
public static AtomicReference<String> firmwareVersion = new AtomicReference<>("N/A");
|
||||
|
||||
public static long classBuildTimeMillis() {
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.rusefi.core.Pair;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import static com.rusefi.shared.FileUtil.RUSEFI_SETTINGS_FOLDER;
|
||||
|
||||
public class SignatureHelper {
|
||||
private final static String LOCAL_INI = RUSEFI_SETTINGS_FOLDER + File.separator + "ini_database";
|
||||
|
||||
public static final String PREFIX = "rusEFI ";
|
||||
public static final char SLASH = '/';
|
||||
|
||||
public static Pair<String, String> getUrl(String signature) {
|
||||
if (!signature.startsWith(PREFIX))
|
||||
return null;
|
||||
signature = signature.substring(PREFIX.length()).trim();
|
||||
String[] elements = signature.split("\\.");
|
||||
if (elements.length != 5)
|
||||
return null;
|
||||
|
||||
String year = elements[0];
|
||||
String month = elements[1];
|
||||
String day = elements[2];
|
||||
String bundle = elements[3];
|
||||
String hash = elements[4];
|
||||
|
||||
String fileName = hash + ".ini";
|
||||
return new Pair("https://rusefi.com/online/ini/rusefi/" + year + SLASH + month + SLASH + day + SLASH + bundle + SLASH + fileName, fileName);
|
||||
}
|
||||
|
||||
public static void downloadIfNotAvailable(Pair<String, String> p) {
|
||||
new File(LOCAL_INI).mkdirs();
|
||||
String localIniFile = LOCAL_INI + File.separator + p.second;
|
||||
File file = new File(localIniFile);
|
||||
if (file.exists() && file.length() > 10000)
|
||||
return;
|
||||
try (BufferedInputStream in = new BufferedInputStream(new URL(p.first).openStream());
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(localIniFile)) {
|
||||
byte[] dataBuffer = new byte[32 * 1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = in.read(dataBuffer, 0, dataBuffer.length)) != -1) {
|
||||
fileOutputStream.write(dataBuffer, 0, bytesRead);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.rusefi.core.Pair;
|
||||
|
||||
public class SignatureHelper {
|
||||
|
||||
public static final String PREFIX = "rusEFI ";
|
||||
public static final char SLASH = '/';
|
||||
|
||||
public static Pair<String, String> getUrl(String signature) {
|
||||
if (!signature.startsWith(PREFIX))
|
||||
return null;
|
||||
signature = signature.substring(PREFIX.length()).trim();
|
||||
String[] elements = signature.split("\\.");
|
||||
if (elements.length != 5)
|
||||
return null;
|
||||
|
||||
String year = elements[0];
|
||||
String month = elements[1];
|
||||
String day = elements[2];
|
||||
String bundle = elements[3];
|
||||
String hash = elements[4];
|
||||
|
||||
String fileName = hash + ".ini";
|
||||
return new Pair("https://rusefi.com/online/ini/rusefi/" + year + SLASH + month + SLASH + day + SLASH + bundle + SLASH + fileName, fileName);
|
||||
}
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
package com.rusefi.server;
|
||||
|
||||
import com.devexperts.logging.Logging;
|
||||
import com.rusefi.SignatureHelper;
|
||||
import com.rusefi.auth.AuthTokenUtil;
|
||||
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.core.Pair;
|
||||
import com.rusefi.core.SensorsHolder;
|
||||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.commands.GetOutputsCommand;
|
||||
|
@ -101,6 +103,9 @@ public class ControllerConnectionState {
|
|||
if (userDetails == null) {
|
||||
throw new IOException("Unable to resolve " + sessionDetails.getAuthToken());
|
||||
}
|
||||
Pair<String, String> p = SignatureHelper.getUrl(sessionDetails.getControllerInfo().getSignature());
|
||||
SignatureHelper.downloadIfNotAvailable(p);
|
||||
|
||||
controllerKey = new ControllerKey(userDetails.getUserId(), sessionDetails.getControllerInfo());
|
||||
log.info("User " + userDetails);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue