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