everyone loves a good NPE!
This commit is contained in:
parent
7bef26344e
commit
cc381d111a
|
@ -3,6 +3,7 @@ package com.rusefi.autodetect;
|
||||||
import com.devexperts.logging.Logging;
|
import com.devexperts.logging.Logging;
|
||||||
import com.rusefi.NamedThreadFactory;
|
import com.rusefi.NamedThreadFactory;
|
||||||
import com.rusefi.io.LinkManager;
|
import com.rusefi.io.LinkManager;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
@ -27,7 +28,7 @@ public class PortDetector {
|
||||||
* @param callback
|
* @param callback
|
||||||
* @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
|
@NotNull
|
||||||
public static SerialAutoChecker.AutoDetectResult autoDetectSerial(Function<SerialAutoChecker.CallbackContext, Void> callback) {
|
public static SerialAutoChecker.AutoDetectResult autoDetectSerial(Function<SerialAutoChecker.CallbackContext, Void> callback) {
|
||||||
String rusEfiAddress = System.getProperty("rusefi.address");
|
String rusEfiAddress = System.getProperty("rusefi.address");
|
||||||
if (rusEfiAddress != null) {
|
if (rusEfiAddress != null) {
|
||||||
|
@ -42,6 +43,7 @@ public class PortDetector {
|
||||||
return getSignatureFromPorts(callback, serialPorts);
|
return getSignatureFromPorts(callback, serialPorts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
private static SerialAutoChecker.AutoDetectResult getSignatureFromPorts(Function<SerialAutoChecker.CallbackContext, Void> callback, String[] serialPorts) {
|
private static SerialAutoChecker.AutoDetectResult getSignatureFromPorts(Function<SerialAutoChecker.CallbackContext, Void> callback, String[] serialPorts) {
|
||||||
List<Thread> serialFinder = new ArrayList<>();
|
List<Thread> serialFinder = new ArrayList<>();
|
||||||
CountDownLatch portFound = new CountDownLatch(1);
|
CountDownLatch portFound = new CountDownLatch(1);
|
||||||
|
@ -61,11 +63,15 @@ public class PortDetector {
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
log.debug("Found " + result.get() + " now stopping threads");
|
|
||||||
for (Thread thread : serialFinder)
|
for (Thread thread : serialFinder)
|
||||||
thread.interrupt();
|
thread.interrupt();
|
||||||
|
|
||||||
|
SerialAutoChecker.AutoDetectResult autoDetectResult = result.get();
|
||||||
|
if (autoDetectResult == null)
|
||||||
|
autoDetectResult = new SerialAutoChecker.AutoDetectResult(null, null);
|
||||||
|
log.debug("Found " + autoDetectResult + " now stopping threads");
|
||||||
// FileLog.MAIN.logLine("Returning " + result.get());
|
// FileLog.MAIN.logLine("Returning " + result.get());
|
||||||
return result.get();
|
return autoDetectResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String[] getPortNames() {
|
private static String[] getPortNames() {
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -87,10 +88,12 @@ public class SerialAutoChecker {
|
||||||
this.signature = signature;
|
this.signature = signature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public String getSerialPort() {
|
public String getSerialPort() {
|
||||||
return serialPort;
|
return serialPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public String getSignature() {
|
public String getSignature() {
|
||||||
return signature;
|
return signature;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue