removing dead code

This commit is contained in:
rusefi 2020-06-07 12:01:59 -04:00
parent 549c5e8ce3
commit 4af0cec252
10 changed files with 33 additions and 128 deletions

View File

@ -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");

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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<String> firmwareVersion = new AtomicReference<>("N/A");
}

View File

@ -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();
}

View File

@ -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<String> 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));

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -21,5 +21,6 @@
<orderEntry type="library" name="XML for 11" level="project" />
<orderEntry type="module" module-name="shared_ui" />
<orderEntry type="module" module-name="autoupdate" exported="" />
<orderEntry type="library" name="jSerialComm" level="project" />
</component>
</module>