Pcan combo box (#4906)
* better parameter name * auto-detect PCAN #4849 * auto-detect PCAN #4849
This commit is contained in:
parent
24e359dad8
commit
9efbdd0379
|
@ -1,7 +1,6 @@
|
|||
package com.rusefi.ui;
|
||||
|
||||
import com.devexperts.logging.Logging;
|
||||
import com.rusefi.binaryprotocol.IncomingDataBuffer;
|
||||
|
||||
import static com.devexperts.logging.Logging.getLogging;
|
||||
|
||||
|
@ -15,5 +14,5 @@ public interface StatusConsumer {
|
|||
StatusConsumer VOID = s -> {
|
||||
};
|
||||
|
||||
void append(String s);
|
||||
void append(String status);
|
||||
}
|
||||
|
|
|
@ -19,14 +19,13 @@ public enum SerialPortScanner {
|
|||
|
||||
private volatile boolean isRunning = true;
|
||||
|
||||
private static final boolean SHOW_PCAN = false;// todo: reimplement with wmic Boolean.parseBoolean(System.getenv().get("RUSEFI_PCAN"));
|
||||
private static final boolean SHOW_SOCKETCAN = isLinux();
|
||||
|
||||
static final String AUTO_SERIAL = "Auto Serial";
|
||||
|
||||
private final Object lock = new Object();
|
||||
@NotNull
|
||||
private AvailableHardware knownHardware = new AvailableHardware(Collections.emptyList(), false, false);
|
||||
private AvailableHardware knownHardware = new AvailableHardware(Collections.emptyList(), false, false, false);
|
||||
|
||||
private final List<Listener> listeners = new CopyOnWriteArrayList<>();
|
||||
|
||||
|
@ -40,31 +39,34 @@ public enum SerialPortScanner {
|
|||
/**
|
||||
* Find all available serial ports and checks if simulator local TCP port is available
|
||||
*/
|
||||
private void findAllAvailablePorts(boolean includeSlowTcpLookup) {
|
||||
private void findAllAvailablePorts(boolean includeSlowLookup) {
|
||||
List<String> ports = new ArrayList<>();
|
||||
boolean dfuConnected;
|
||||
boolean stLinkConnected;
|
||||
boolean PCANConnected;
|
||||
|
||||
String[] serialPorts = LinkManager.getCommPorts();
|
||||
if (serialPorts.length > 0)
|
||||
ports.add(AUTO_SERIAL);
|
||||
ports.addAll(Arrays.asList(serialPorts));
|
||||
|
||||
if (includeSlowTcpLookup) {
|
||||
if (includeSlowLookup) {
|
||||
ports.addAll(TcpConnector.getAvailablePorts());
|
||||
dfuConnected = DfuFlasher.detectSTM32BootloaderDriverState(StatusConsumer.VOID);
|
||||
stLinkConnected = DfuFlasher.detectStLink(StatusConsumer.VOID);
|
||||
PCANConnected = DfuFlasher.detectPcan(StatusConsumer.VOID);
|
||||
} else {
|
||||
dfuConnected = false;
|
||||
stLinkConnected = false;
|
||||
PCANConnected = false;
|
||||
}
|
||||
if (SHOW_PCAN)
|
||||
if (PCANConnected)
|
||||
ports.add(LinkManager.PCAN);
|
||||
if (SHOW_SOCKETCAN)
|
||||
ports.add(LinkManager.SOCKET_CAN);
|
||||
|
||||
boolean isListUpdated;
|
||||
AvailableHardware currentHardware = new AvailableHardware(ports, dfuConnected, stLinkConnected);
|
||||
AvailableHardware currentHardware = new AvailableHardware(ports, dfuConnected, stLinkConnected, PCANConnected);
|
||||
synchronized (lock) {
|
||||
isListUpdated = !knownHardware.equals(currentHardware);
|
||||
knownHardware = currentHardware;
|
||||
|
@ -106,36 +108,35 @@ public enum SerialPortScanner {
|
|||
private final List<String> ports;
|
||||
private final boolean dfuFound;
|
||||
private final boolean stLinkConnected;
|
||||
private final boolean PCANConnected;
|
||||
|
||||
public <T> AvailableHardware(List<String> ports, boolean dfuFound, boolean stLinkConnected) {
|
||||
public <T> AvailableHardware(List<String> ports, boolean dfuFound, boolean stLinkConnected, boolean PCANConnected) {
|
||||
this.ports = ports;
|
||||
this.dfuFound = dfuFound;
|
||||
this.stLinkConnected = stLinkConnected;
|
||||
this.PCANConnected = PCANConnected;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<String> getKnownPorts() {
|
||||
return new ArrayList<>(ports);
|
||||
}
|
||||
public List<String> getKnownPorts() {return new ArrayList<>(ports);}
|
||||
|
||||
public boolean isDfuFound() {
|
||||
return dfuFound;
|
||||
}
|
||||
|
||||
public boolean isStLinkConnected() {
|
||||
return stLinkConnected;
|
||||
}
|
||||
public boolean isStLinkConnected() {return stLinkConnected;}
|
||||
public boolean isPCANConnected(){return PCANConnected;}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
AvailableHardware that = (AvailableHardware) o;
|
||||
return dfuFound == that.dfuFound && stLinkConnected == that.stLinkConnected && ports.equals(that.ports);
|
||||
return dfuFound == that.dfuFound && stLinkConnected == that.stLinkConnected && PCANConnected == that.PCANConnected && ports.equals(that.ports);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return !dfuFound && !stLinkConnected && ports.isEmpty();
|
||||
return !dfuFound && !stLinkConnected && !PCANConnected && ports.isEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ public class DfuFlasher {
|
|||
private static final String DFU_BINARY = "STM32_Programmer_CLI.exe";
|
||||
private static final String WMIC_DFU_QUERY_COMMAND = "wmic path win32_pnpentity where \"Caption like '%STM32%' and Caption like '%Bootloader%'\" get Caption,ConfigManagerErrorCode /format:list";
|
||||
private static final String WMIC_STLINK_QUERY_COMMAND = "wmic path win32_pnpentity where \"Caption like '%STLink%'\" get Caption,ConfigManagerErrorCode /format:list";
|
||||
private static final String WMIC_PCAN_QUERY_COMMAND = "wmic path win32_pnpentity where \"Caption like '%PCAN-USB%'\" get Caption,ConfigManagerErrorCode /format:list";
|
||||
|
||||
public static void doAutoDfu(Object selectedItem, JComponent parent) {
|
||||
if (selectedItem == null) {
|
||||
|
@ -178,6 +179,9 @@ public class DfuFlasher {
|
|||
public static boolean detectStLink(StatusConsumer wnd) {
|
||||
return detectDevice(wnd, WMIC_STLINK_QUERY_COMMAND, "STLink");
|
||||
}
|
||||
public static boolean detectPcan(StatusConsumer wnd) {
|
||||
return detectDevice(wnd, WMIC_PCAN_QUERY_COMMAND, "PCAN");
|
||||
}
|
||||
|
||||
private static boolean detectDevice(StatusConsumer wnd, String queryCommand, String pattern) {
|
||||
// long now = System.currentTimeMillis();
|
||||
|
|
|
@ -49,7 +49,7 @@ public class ProgramSelector {
|
|||
controls.add(mode);
|
||||
|
||||
String persistedMode = getConfig().getRoot().getProperty(getClass().getSimpleName());
|
||||
if (Arrays.asList(AUTO_DFU, MANUAL_DFU, ST_LINK, DFU_ERASE, DFU_SWITCH).contains(persistedMode))
|
||||
if (Arrays.asList(AUTO_DFU, MANUAL_DFU, ST_LINK, OPENBLT_CAN , DFU_ERASE, DFU_SWITCH).contains(persistedMode))
|
||||
mode.setSelectedItem(persistedMode);
|
||||
|
||||
JButton updateFirmware = new JButton("Update Firmware",
|
||||
|
@ -131,6 +131,8 @@ public class ProgramSelector {
|
|||
}
|
||||
if (currentHardware.isStLinkConnected())
|
||||
mode.addItem(ST_LINK);
|
||||
if (currentHardware.isPCANConnected())
|
||||
mode.addItem(OPENBLT_CAN);
|
||||
// todo: detect PCAN mode.addItem(OPENBLT_CAN);
|
||||
}
|
||||
if (!currentHardware.getKnownPorts().isEmpty())
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package com.rusefi.maintenance;
|
||||
|
||||
import com.rusefi.ui.StatusConsumer;
|
||||
|
||||
import static com.rusefi.maintenance.DfuFlasher.detectPcan;
|
||||
import static com.rusefi.maintenance.DfuFlasher.detectStLink;
|
||||
|
||||
public class DfuFlasherSandbox {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("detectStLink " + detectStLink(StatusConsumer.VOID));
|
||||
System.out.println("detectPcan " + detectPcan(StatusConsumer.VOID));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue