reducing complexity
This commit is contained in:
parent
0416f12aa3
commit
9dc2216bb2
|
@ -7,6 +7,7 @@ import com.rusefi.io.CommunicationLoggingHolder;
|
|||
import com.rusefi.io.ConnectionStateListener;
|
||||
import com.opensr5.io.DataListener;
|
||||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
|
@ -19,6 +20,8 @@ import java.awt.*;
|
|||
* (c) Andrey Belomutskiy
|
||||
*/
|
||||
public class PortHolder {
|
||||
private static final DataListener dataListener = freshData -> LinkManager.engineState.processNewData(new String(freshData), LinkManager.ENCODER);
|
||||
|
||||
public ConnectionStateListener listener;
|
||||
private static PortHolder instance = new PortHolder();
|
||||
private final Object portLock = new Object();
|
||||
|
@ -31,11 +34,13 @@ public class PortHolder {
|
|||
@Nullable
|
||||
private IoStream serialPort;
|
||||
|
||||
boolean connectAndReadConfiguration(String port, DataListener dataListener) {
|
||||
public String port;
|
||||
|
||||
boolean connectAndReadConfiguration() {
|
||||
if (port == null)
|
||||
return false;
|
||||
|
||||
CommunicationLoggingHolder.communicationLoggingListener.onPortHolderMessage(SerialManager.class, "Opening port: " + port);
|
||||
CommunicationLoggingHolder.communicationLoggingListener.onPortHolderMessage(getClass(), "Opening port: " + port);
|
||||
|
||||
IoStream stream = SerialIoStreamJSerialComm.openPort(port);
|
||||
synchronized (portLock) {
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.rusefi.core.MessagesCentral;
|
|||
import com.rusefi.io.ConnectionStateListener;
|
||||
import com.rusefi.io.LinkConnector;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.sun.corba.se.spi.activation.ServerHolder;
|
||||
|
||||
/**
|
||||
* @author Andrey Belomutskiy
|
||||
|
@ -12,7 +13,7 @@ import com.rusefi.io.LinkManager;
|
|||
*/
|
||||
public class SerialConnector implements LinkConnector {
|
||||
public SerialConnector(String serialPort) {
|
||||
SerialManager.port = serialPort;
|
||||
PortHolder.getInstance().port = serialPort;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,7 +25,7 @@ public class SerialConnector implements LinkConnector {
|
|||
@Override
|
||||
public void run() {
|
||||
FileLog.MAIN.logLine("scheduleOpening>openPort");
|
||||
PortHolder.getInstance().connectAndReadConfiguration(SerialManager.port, SerialManager.dataListener);
|
||||
PortHolder.getInstance().connectAndReadConfiguration();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -34,11 +35,11 @@ public class SerialConnector implements LinkConnector {
|
|||
LinkManager.COMMUNICATION_EXECUTOR.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MessagesCentral.getInstance().postMessage(SerialManager.class, "Restarting serial IO");
|
||||
MessagesCentral.getInstance().postMessage(getClass(), "Restarting serial IO");
|
||||
// if (closed)
|
||||
// return;
|
||||
PortHolder.getInstance().close();
|
||||
PortHolder.getInstance().connectAndReadConfiguration(SerialManager.port, SerialManager.dataListener);
|
||||
PortHolder.getInstance().connectAndReadConfiguration();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
package com.rusefi.io.serial;
|
||||
|
||||
import com.rusefi.io.ConnectionStateListener;
|
||||
import com.opensr5.io.DataListener;
|
||||
import com.rusefi.io.LinkManager;
|
||||
|
||||
/**
|
||||
* 7/9/13
|
||||
* (c) Andrey Belomutskiy
|
||||
*/
|
||||
class SerialManager {
|
||||
public static String port;
|
||||
|
||||
static DataListener dataListener = new DataListener() {
|
||||
public void onDataArrived(byte freshData[]) {
|
||||
LinkManager.engineState.processNewData(new String(freshData), LinkManager.ENCODER);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in New Issue