diff --git a/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocol.java b/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocol.java index 15e56f2dd8..a218578c83 100644 --- a/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocol.java +++ b/java_console/io/src/com/rusefi/binaryprotocol/BinaryProtocol.java @@ -19,7 +19,6 @@ import com.rusefi.stream.TSHighSpeedLog; import com.rusefi.stream.VcdStreamFile; import com.rusefi.tune.xml.Msq; import com.rusefi.ui.livedocs.LiveDocsRegistry; -import jssc.SerialPortException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -257,7 +256,7 @@ public class BinaryProtocol implements BinaryProtocolCommands { } } - public void uploadChanges(ConfigurationImage newVersion, Logger logger) throws InterruptedException, EOFException, SerialPortException { + public void uploadChanges(ConfigurationImage newVersion, Logger logger) throws InterruptedException, EOFException { ConfigurationImage current = getControllerConfiguration(); // let's have our own copy which no one would be able to change newVersion = newVersion.clone(); @@ -418,7 +417,7 @@ public class BinaryProtocol implements BinaryProtocolCommands { Runtime.getRuntime().removeShutdownHook(hook); } - public void writeData(byte[] content, Integer offset, int size, Logger logger) throws SerialPortException, EOFException, InterruptedException { + public void writeData(byte[] content, Integer offset, int size, Logger logger) { if (size > BLOCKING_FACTOR) { writeData(content, offset, BLOCKING_FACTOR, logger); writeData(content, offset + BLOCKING_FACTOR, size - BLOCKING_FACTOR, logger); @@ -446,7 +445,7 @@ public class BinaryProtocol implements BinaryProtocolCommands { } } - public void burn(Logger logger) throws InterruptedException, EOFException, SerialPortException { + public void burn(Logger logger) throws InterruptedException, EOFException { if (!isBurnPending) return; logger.info("Need to burn"); diff --git a/java_console/io/src/com/rusefi/io/LinkManager.java b/java_console/io/src/com/rusefi/io/LinkManager.java index 50f20b3c70..ca24307c33 100644 --- a/java_console/io/src/com/rusefi/io/LinkManager.java +++ b/java_console/io/src/com/rusefi/io/LinkManager.java @@ -1,11 +1,11 @@ package com.rusefi.io; +import com.fazecast.jSerialComm.SerialPort; import com.rusefi.FileLog; import com.rusefi.NamedThreadFactory; import com.rusefi.core.EngineState; import com.rusefi.io.serial.SerialConnector; import com.rusefi.io.tcp.TcpConnector; -import jssc.SerialPortList; import org.jetbrains.annotations.NotNull; import java.util.Arrays; @@ -47,6 +47,14 @@ public class LinkManager { return COMMUNICATION_EXECUTOR.submit(runnable); } + public static String[] getCommPorts() { + SerialPort[] ports = SerialPort.getCommPorts(); + String[] result = new String[ports.length]; + for (int i = 0; i < ports.length; i++) + result[i] = ports[i].getSystemPortName(); + return result; + } + public enum LogLevel { INFO, DEBUG, @@ -179,7 +187,7 @@ public class LinkManager { * @return null if no port located */ public static String getDefaultPort() { - String[] ports = SerialPortList.getPortNames(); + String[] ports = getCommPorts(); if (ports.length == 0) { System.out.println("Port not specified and no ports found"); return null; diff --git a/java_console/io/src/com/rusefi/io/serial/JSSCPortReader.java b/java_console/io/src/com/rusefi/io/serial/JSSCPortReader.java deleted file mode 100644 index bf462f9f03..0000000000 --- a/java_console/io/src/com/rusefi/io/serial/JSSCPortReader.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.rusefi.io.serial; - -import com.rusefi.FileLog; -import com.opensr5.io.DataListener; -import com.rusefi.io.IoStream; -import jssc.SerialPort; -import jssc.SerialPortEvent; -import jssc.SerialPortEventListener; -import jssc.SerialPortException; -import org.jetbrains.annotations.Nullable; - -/** - * Date: 12/25/12 - * (c) Andrey Belomutskiy - */ -public class JSSCPortReader { - private static final int[] SLEEP_DURATIONS = {2, 20, 50, 100}; - private final SerialPort serialPort; - private DataListener listener; - - public JSSCPortReader(final SerialPort serialPort, final DataListener listener, IoStream serialIoStreamJSSC) { - this.serialPort = serialPort; - this.listener = listener; - new Thread(new Runnable() { - @Override - public void run() { - try { - while (serialPort.isOpened()) { - byte[] data = progressiveSleepRead(serialPort); - if (data != null) - listener.onDataArrived(data); - } - } catch (SerialPortException e) { - if (!serialIoStreamJSSC.isClosed()) { - e.printStackTrace(); - } - } - } - }, "Reader_" + serialPort).start(); - } - - /** - * This method starts with shorter sleeps (which we do not know to what extent Windows handle) and then we sleep - * a bit longer - * @param serialPort port to read from - * @return fresh data or null - */ - @Nullable - private static byte[] progressiveSleepRead(SerialPort serialPort) throws SerialPortException { - for (int sleepDuration : SLEEP_DURATIONS) { - byte[] data; - synchronized (serialPort) { - data = serialPort.readBytes(); - } - if (data != null) - return data; - try { - Thread.sleep(sleepDuration); - } catch (InterruptedException e) { - throw new IllegalStateException(e); - } - } - - return null; - } - - private SerialPortEventListener serialPortEventListener = new SerialPortEventListener() { - - - public void serialEvent(SerialPortEvent spe) { - if (spe.isRXCHAR() || spe.isRXFLAG()) { -// event-based serial read implementation does not work well on Windows 10 for some reason -// https://sourceforge.net/p/rusefi/tickets/264/ -// try { -// handleRx(spe); -// } catch (SerialPortException e) { -// e.printStackTrace(System.err); -// } - } else if (spe.getEventType() != SerialPortEvent.TXEMPTY) { - FileLog.MAIN.logLine("less expected JSSCPortReader serialEvent " + spe.getEventType()); - } - } - }; - -// private void handleRx(SerialPortEvent spe) throws SerialPortException { -// if (spe.getEventValue() > 0) { -// byte[] buffer = serialPort.readBytes(spe.getEventValue()); -// listener.onDataArrived(buffer); -// // System.out.println("arrived [" + str + "]"); -// } -// } - - public void readInitial() throws SerialPortException { - int input = serialPort.getInputBufferBytesCount(); - FileLog.MAIN.logLine(input + " bytes in input buffer"); - while (serialPort.getInputBufferBytesCount() > 0) { - byte[] data = serialPort.readBytes(); - if (data != null) - listener.onDataArrived(data); - } - } - - public SerialPortEventListener getSerialPortEventListener() { - return serialPortEventListener; - } -} diff --git a/java_console/models/src/com/rusefi/rusEFIVersion.java b/java_console/models/src/com/rusefi/rusEFIVersion.java index 859f5317c1..a89d89366f 100644 --- a/java_console/models/src/com/rusefi/rusEFIVersion.java +++ b/java_console/models/src/com/rusefi/rusEFIVersion.java @@ -3,6 +3,6 @@ package com.rusefi; import java.util.concurrent.atomic.AtomicReference; public class rusEFIVersion { - public static final int CONSOLE_VERSION = 20200606; + public static final int CONSOLE_VERSION = 20200607; public static AtomicReference firmwareVersion = new AtomicReference<>("N/A"); } diff --git a/java_console/ui/src/com/rusefi/Launcher.java b/java_console/ui/src/com/rusefi/Launcher.java index 0ac9cf07de..bcd71bd645 100644 --- a/java_console/ui/src/com/rusefi/Launcher.java +++ b/java_console/ui/src/com/rusefi/Launcher.java @@ -19,7 +19,6 @@ import com.rusefi.ui.logview.LogViewer; import com.rusefi.ui.storage.PersistentConfiguration; import com.rusefi.ui.util.DefaultExceptionHandler; import com.rusefi.ui.util.JustOneInstance; -import jssc.SerialPortList; import javax.swing.*; import javax.swing.event.ChangeEvent; @@ -247,7 +246,7 @@ public class Launcher extends rusEFIVersion { if (isPortDefined) { new Launcher(port); } else { - for (String p : SerialPortList.getPortNames()) + for (String p : LinkManager.getCommPorts()) MessagesCentral.getInstance().postMessage(Launcher.class, "Available port: " + p); new StartupFrame().chooseSerialPort(); } diff --git a/java_console/ui/src/com/rusefi/SerialPortScanner.java b/java_console/ui/src/com/rusefi/SerialPortScanner.java index e1f098fe05..41f77cbe2c 100644 --- a/java_console/ui/src/com/rusefi/SerialPortScanner.java +++ b/java_console/ui/src/com/rusefi/SerialPortScanner.java @@ -1,7 +1,7 @@ package com.rusefi; +import com.rusefi.io.LinkManager; import com.rusefi.io.tcp.TcpConnector; -import jssc.SerialPortList; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -31,7 +31,7 @@ public enum SerialPortScanner { @NotNull void findAllAvailablePorts() { List ports = new ArrayList<>(); - String[] serialPorts = SerialPortList.getPortNames(); + String[] serialPorts = LinkManager.getCommPorts(); if (serialPorts.length > 0 || serialPorts.length < 15) ports.add(AUTO_SERIAL); ports.addAll(Arrays.asList(serialPorts)); diff --git a/java_console/ui/src/com/rusefi/UploadChanges.java b/java_console/ui/src/com/rusefi/UploadChanges.java index e2f3494f15..2e5ea54ac4 100644 --- a/java_console/ui/src/com/rusefi/UploadChanges.java +++ b/java_console/ui/src/com/rusefi/UploadChanges.java @@ -7,7 +7,6 @@ import com.rusefi.config.generated.Fields; import com.rusefi.io.LinkManager; import com.rusefi.ui.RecentCommands; import com.rusefi.ui.StatusWindow; -import jssc.SerialPortException; import javax.swing.*; import java.awt.*; @@ -35,7 +34,7 @@ public class UploadChanges { public static final Logger logger = createUiLogger(); - public static void main(String[] args) throws SerialPortException, InvocationTargetException, InterruptedException { + public static void main(String[] args) throws InvocationTargetException, InterruptedException { if (args.length != 1) { System.out.println("Exactly one parameter expected"); return; @@ -47,14 +46,14 @@ public class UploadChanges { public void run() { try { showUi(port); - } catch (SerialPortException | IOException | InterruptedException e) { + } catch (IOException | InterruptedException e) { throw new IllegalStateException(e); } } }); } - private static void showUi(String port) throws SerialPortException, IOException, InterruptedException { + private static void showUi(String port) throws IOException, InterruptedException { /* SerialPort serialPort; @@ -92,7 +91,7 @@ public class UploadChanges { BinaryProtocolHolder.getInstance().getCurrentStreamState().uploadChanges(newVersion, logger); if (afterUpload != null) afterUpload.run(); - } catch (InterruptedException | EOFException | SerialPortException e) { + } catch (InterruptedException | EOFException e) { logger.error("Error: " + e); throw new IllegalStateException(e); } diff --git a/java_console/ui/src/com/rusefi/autodetect/PortDetector.java b/java_console/ui/src/com/rusefi/autodetect/PortDetector.java index d0965ea775..5ba1ed03ee 100644 --- a/java_console/ui/src/com/rusefi/autodetect/PortDetector.java +++ b/java_console/ui/src/com/rusefi/autodetect/PortDetector.java @@ -2,7 +2,7 @@ package com.rusefi.autodetect; import com.rusefi.FileLog; import com.rusefi.io.IoStream; -import jssc.SerialPortList; +import com.rusefi.io.LinkManager; import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -51,7 +51,7 @@ public class PortDetector { private static String[] getPortNames() { // long now = System.currentTimeMillis(); - String[] portNames = SerialPortList.getPortNames(); + String[] portNames = LinkManager.getCommPorts(); // FileLog.MAIN.logLine("Took " + (System.currentTimeMillis() - now)); return portNames; } diff --git a/java_console/ui/src/com/rusefi/ui/light/InternetStatus.java b/java_console/ui/src/com/rusefi/ui/light/InternetStatus.java index c9df5c3ad8..a7bf5377ab 100644 --- a/java_console/ui/src/com/rusefi/ui/light/InternetStatus.java +++ b/java_console/ui/src/com/rusefi/ui/light/InternetStatus.java @@ -10,10 +10,15 @@ import java.net.HttpURLConnection; import java.net.URL; public class InternetStatus { - public static final String GOOGLE = "http://google.com"; + private static final String GOOGLE = "http://google.com"; + private final JPanel panel = new JPanel(); private final JLabel status = new JLabel(); public InternetStatus() { + panel.add(status); + Font defaultFont = status.getFont(); + status.setFont(new Font(defaultFont.getName(), defaultFont.getStyle(), 2 * defaultFont.getSize())); + new Thread(() -> { while (true) { boolean isConnected = isServerReachable(); @@ -23,10 +28,10 @@ public class InternetStatus { public void run() { if (isConnected) { status.setText("online"); - status.setForeground(Color.green); + panel.setBackground(Color.green); } else { status.setText("offline"); - status.setForeground(Color.red); + panel.setBackground(Color.red); } } }); @@ -55,6 +60,6 @@ public class InternetStatus { } public Component getContent() { - return status; + return panel; } } diff --git a/java_console/ui/ui.iml b/java_console/ui/ui.iml index 5000736827..f118903fb8 100644 --- a/java_console/ui/ui.iml +++ b/java_console/ui/ui.iml @@ -21,5 +21,6 @@ + \ No newline at end of file