rusEFI console to compare current bundle against auto-DFU bundle #3266
putting signature into equation
This commit is contained in:
parent
19d2e73d84
commit
1807a6f6ce
|
@ -37,7 +37,7 @@ public class ControllerConnectorState {
|
|||
FileLog.MAIN.start();
|
||||
String port = System.getProperty("ecu.port");
|
||||
if (port == null) {
|
||||
port = PortDetector.autoDetectSerial(null);
|
||||
port = PortDetector.autoDetectSerial(null).getSerialPort();
|
||||
if (port == null)
|
||||
throw new IllegalStateException("ECU serial not detected");
|
||||
}
|
||||
|
|
|
@ -29,19 +29,24 @@ public class PortDetector {
|
|||
* @return port name on which rusEFI was detected or null if none
|
||||
*/
|
||||
@Nullable
|
||||
public static String autoDetectSerial(Function<IoStream, Void> callback) {
|
||||
public static SerialAutoChecker.AutoDetectResult autoDetectSerial(Function<IoStream, Void> callback) {
|
||||
String rusEfiAddress = System.getProperty("rusefi.address");
|
||||
if (rusEfiAddress != null)
|
||||
return rusEfiAddress;
|
||||
if (rusEfiAddress != null) {
|
||||
return getSignatureFromPorts(callback, new String[] {rusEfiAddress});
|
||||
}
|
||||
String[] serialPorts = getPortNames();
|
||||
if (serialPorts.length == 0) {
|
||||
log.error("No serial ports detected");
|
||||
return null;
|
||||
return new SerialAutoChecker.AutoDetectResult(null, null);
|
||||
}
|
||||
log.info("Trying " + Arrays.toString(serialPorts));
|
||||
return getSignatureFromPorts(callback, serialPorts);
|
||||
}
|
||||
|
||||
private static SerialAutoChecker.AutoDetectResult getSignatureFromPorts(Function<IoStream, Void> callback, String[] serialPorts) {
|
||||
List<Thread> serialFinder = new ArrayList<>();
|
||||
CountDownLatch portFound = new CountDownLatch(1);
|
||||
AtomicReference<String> result = new AtomicReference<>();
|
||||
AtomicReference<SerialAutoChecker.AutoDetectResult> result = new AtomicReference<>();
|
||||
for (String serialPort : serialPorts) {
|
||||
Thread thread = AUTO_DETECT_PORT.newThread(new SerialAutoChecker(serialPort, portFound, result, callback));
|
||||
serialFinder.add(thread);
|
||||
|
@ -67,9 +72,9 @@ public class PortDetector {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
public static String autoDetectPort(JFrame parent) {
|
||||
String autoDetectedPort = autoDetectSerial(null);
|
||||
if (autoDetectedPort == null) {
|
||||
public static SerialAutoChecker.AutoDetectResult autoDetectPort(JFrame parent) {
|
||||
SerialAutoChecker.AutoDetectResult autoDetectedPort = autoDetectSerial(null);
|
||||
if (autoDetectedPort.getSerialPort() == null) {
|
||||
JOptionPane.showMessageDialog(parent, "Failed to located device");
|
||||
return null;
|
||||
}
|
||||
|
@ -79,7 +84,7 @@ public class PortDetector {
|
|||
public static String autoDetectSerialIfNeeded(String port) {
|
||||
if (!isAutoPort(port))
|
||||
return port;
|
||||
return autoDetectSerial(null);
|
||||
return autoDetectSerial(null).getSerialPort();
|
||||
}
|
||||
|
||||
public static boolean isAutoPort(String port) {
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.rusefi.config.generated.Fields;
|
|||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.commands.HelloCommand;
|
||||
import com.rusefi.io.serial.SerialIoStreamJSerialComm;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
@ -18,18 +19,18 @@ public class SerialAutoChecker implements Runnable {
|
|||
private final static Logging log = Logging.getLogging(SerialAutoChecker.class);
|
||||
private final String serialPort;
|
||||
private final CountDownLatch portFound;
|
||||
private final AtomicReference<String> result;
|
||||
private final AtomicReference<AutoDetectResult> result;
|
||||
@Nullable
|
||||
private final Function<IoStream, Void> callback;
|
||||
public static String SIGNATURE;
|
||||
|
||||
public SerialAutoChecker(String serialPort, CountDownLatch portFound, AtomicReference<String> result, Function<IoStream, Void> callback) {
|
||||
public SerialAutoChecker(String serialPort, CountDownLatch portFound, AtomicReference<AutoDetectResult> result, Function<IoStream, Void> callback) {
|
||||
this.serialPort = serialPort;
|
||||
this.portFound = portFound;
|
||||
this.result = result;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public SerialAutoChecker(String serialPort, CountDownLatch portFound, AtomicReference<String> result) {
|
||||
public SerialAutoChecker(String serialPort, CountDownLatch portFound, AtomicReference<AutoDetectResult> result) {
|
||||
this(serialPort, portFound, result, null);
|
||||
}
|
||||
|
||||
|
@ -38,13 +39,13 @@ public class SerialAutoChecker implements Runnable {
|
|||
IoStream stream = SerialIoStreamJSerialComm.openPort(serialPort);
|
||||
IncomingDataBuffer incomingData = stream.getDataBuffer();
|
||||
boolean isPortFound = false;
|
||||
String signature;
|
||||
try {
|
||||
HelloCommand.send(stream);
|
||||
byte[] response = incomingData.getPacket("");
|
||||
byte[] response = incomingData.getPacket("auto detect");
|
||||
if (!checkResponseCode(response, (byte) Fields.TS_RESPONSE_OK))
|
||||
return;
|
||||
String signature = new String(response, 1, response.length - 1);
|
||||
SIGNATURE = signature;
|
||||
signature = new String(response, 1, response.length - 1);
|
||||
log.info("Got signature=" + signature + " from " + serialPort);
|
||||
if (signature.startsWith(Fields.PROTOCOL_SIGNATURE_PREFIX)) {
|
||||
if (callback != null) {
|
||||
|
@ -61,8 +62,27 @@ public class SerialAutoChecker implements Runnable {
|
|||
/**
|
||||
* propagating result after closing the port so that it could be used right away
|
||||
*/
|
||||
result.set(serialPort);
|
||||
result.set(new AutoDetectResult(serialPort, signature));
|
||||
portFound.countDown();
|
||||
}
|
||||
}
|
||||
|
||||
public static class AutoDetectResult {
|
||||
|
||||
private final String serialPort;
|
||||
private final String signature;
|
||||
|
||||
public AutoDetectResult(String serialPort, String signature) {
|
||||
this.serialPort = serialPort;
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public String getSerialPort() {
|
||||
return serialPort;
|
||||
}
|
||||
|
||||
public String getSignature() {
|
||||
return signature;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -220,6 +220,11 @@ public class BinaryProtocol {
|
|||
linkManager.getCommandQueue().handleConfirmationMessage(CommandQueue.CONFIRMATION_PREFIX + command);
|
||||
}
|
||||
|
||||
public String getSignature() throws IOException {
|
||||
HelloCommand.send(stream);
|
||||
return HelloCommand.getHelloResponse(incomingData);
|
||||
}
|
||||
|
||||
/**
|
||||
* this method reads configuration snapshot from controller
|
||||
*
|
||||
|
@ -227,8 +232,7 @@ public class BinaryProtocol {
|
|||
*/
|
||||
public boolean connectAndReadConfiguration(DataListener listener) {
|
||||
try {
|
||||
HelloCommand.send(stream);
|
||||
signature = HelloCommand.getHelloResponse(incomingData);
|
||||
signature = getSignature();
|
||||
System.out.println("Got " + signature);
|
||||
SignatureHelper.downloadIfNotAvailable(SignatureHelper.getUrl(signature));
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -7,6 +7,12 @@ import java.io.IOException;
|
|||
|
||||
public class DfuHelper {
|
||||
public static void sendDfuRebootCommand(IoStream stream, StringBuilder messages) {
|
||||
|
||||
|
||||
|
||||
if (1==1)
|
||||
return;
|
||||
|
||||
byte[] command = BinaryProtocol.getTextCommandBytes(Fields.CMD_REBOOT_DFU);
|
||||
try {
|
||||
stream.sendPacket(command);
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.net.URL;
|
|||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class rusEFIVersion {
|
||||
public static final int CONSOLE_VERSION = 20210918;
|
||||
public static final int CONSOLE_VERSION = 20210920;
|
||||
public static AtomicReference<String> firmwareVersion = new AtomicReference<>("N/A");
|
||||
|
||||
public static long classBuildTimeMillis() {
|
||||
|
|
|
@ -238,7 +238,7 @@ public class StartupFrame {
|
|||
BaudRateHolder.INSTANCE.baudRate = Integer.parseInt((String) comboSpeeds.getSelectedItem());
|
||||
String selectedPort = comboPorts.getSelectedItem().toString();
|
||||
if (SerialPortScanner.AUTO_SERIAL.equals(selectedPort)) {
|
||||
String autoDetectedPort = PortDetector.autoDetectPort(StartupFrame.this.frame);
|
||||
String autoDetectedPort = PortDetector.autoDetectPort(StartupFrame.this.frame).getSerialPort();
|
||||
if (autoDetectedPort == null)
|
||||
return;
|
||||
selectedPort = autoDetectedPort;
|
||||
|
|
|
@ -5,7 +5,7 @@ import com.rusefi.IoUtil;
|
|||
public class PortDetectorSandbox {
|
||||
public static void main(String[] args) {
|
||||
while (true) {
|
||||
String port = PortDetector.autoDetectSerial(null);
|
||||
String port = PortDetector.autoDetectSerial(null).getSerialPort();
|
||||
System.out.println("Detected " + port);
|
||||
|
||||
IoUtil.sleepSeconds(1);
|
||||
|
|
|
@ -62,7 +62,7 @@ public class DfuFlasher {
|
|||
port = PortDetector.autoDetectSerial(stream -> {
|
||||
DfuHelper.sendDfuRebootCommand(stream, messages);
|
||||
return null;
|
||||
});
|
||||
}).getSerialPort();
|
||||
if (port == null) {
|
||||
JOptionPane.showMessageDialog(ConsoleUI.getFrame(), "rusEFI serial port not detected");
|
||||
return;
|
||||
|
|
|
@ -239,7 +239,7 @@ public class ConsoleTools {
|
|||
|
||||
public static void startAndConnect(final Function<LinkManager, Void> onConnectionEstablished) {
|
||||
|
||||
String autoDetectedPort = PortDetector.autoDetectSerial(null);
|
||||
String autoDetectedPort = PortDetector.autoDetectSerial(null).getSerialPort();
|
||||
if (autoDetectedPort == null) {
|
||||
System.err.println(RUS_EFI_NOT_DETECTED);
|
||||
return;
|
||||
|
@ -342,7 +342,7 @@ public class ConsoleTools {
|
|||
|
||||
@Nullable
|
||||
private static String autoDetectPort() {
|
||||
String autoDetectedPort = PortDetector.autoDetectSerial(null);
|
||||
String autoDetectedPort = PortDetector.autoDetectSerial(null).getSerialPort();
|
||||
if (autoDetectedPort == null) {
|
||||
System.err.println(RUS_EFI_NOT_DETECTED);
|
||||
return null;
|
||||
|
@ -367,7 +367,8 @@ public class ConsoleTools {
|
|||
}
|
||||
|
||||
static void detect(String[] strings) throws IOException {
|
||||
String autoDetectedPort = autoDetectPort();
|
||||
SerialAutoChecker.AutoDetectResult detectResult = PortDetector.autoDetectSerial(null);
|
||||
String autoDetectedPort = detectResult.getSerialPort();
|
||||
if (autoDetectedPort == null) {
|
||||
System.out.println(RUS_EFI_NOT_DETECTED);
|
||||
return;
|
||||
|
@ -413,9 +414,9 @@ public class ConsoleTools {
|
|||
});
|
||||
responseBuffer.append(textResponse + "\r\n", LinkManager.ENCODER);
|
||||
|
||||
System.out.println("Signature: " + SerialAutoChecker.SIGNATURE);
|
||||
System.out.println("Signature: " + detectResult.getSignature());
|
||||
System.out.println("It says " + messages);
|
||||
Pair<String, String> stringPair = SignatureHelper.getUrl(SerialAutoChecker.SIGNATURE);
|
||||
Pair<String, String> stringPair = SignatureHelper.getUrl(detectResult.getSignature());
|
||||
if (stringPair != null)
|
||||
System.out.println("Ini file: " + stringPair.first);
|
||||
System.exit(0);
|
||||
|
|
|
@ -21,7 +21,7 @@ public class NetworkConnectorStartup {
|
|||
return;
|
||||
}
|
||||
|
||||
String autoDetectedPort = PortDetector.autoDetectSerial(null);
|
||||
String autoDetectedPort = PortDetector.autoDetectSerial(null).getSerialPort();
|
||||
if (autoDetectedPort == null) {
|
||||
System.err.println(ConsoleTools.RUS_EFI_NOT_DETECTED);
|
||||
return;
|
||||
|
|
|
@ -113,7 +113,7 @@ public class LightweightGUI {
|
|||
|
||||
private static String detectPortUntilDetected() {
|
||||
while (true) {
|
||||
String port = PortDetector.autoDetectSerial(null);
|
||||
String port = PortDetector.autoDetectSerial(null).getSerialPort();
|
||||
System.out.println("Detected " + port);
|
||||
if (port != null)
|
||||
return port;
|
||||
|
|
Loading…
Reference in New Issue