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.rusefi.io.ConnectionStateListener;
|
||||||
import com.opensr5.io.DataListener;
|
import com.opensr5.io.DataListener;
|
||||||
import com.rusefi.io.IoStream;
|
import com.rusefi.io.IoStream;
|
||||||
|
import com.rusefi.io.LinkManager;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
@ -19,6 +20,8 @@ import java.awt.*;
|
||||||
* (c) Andrey Belomutskiy
|
* (c) Andrey Belomutskiy
|
||||||
*/
|
*/
|
||||||
public class PortHolder {
|
public class PortHolder {
|
||||||
|
private static final DataListener dataListener = freshData -> LinkManager.engineState.processNewData(new String(freshData), LinkManager.ENCODER);
|
||||||
|
|
||||||
public ConnectionStateListener listener;
|
public ConnectionStateListener listener;
|
||||||
private static PortHolder instance = new PortHolder();
|
private static PortHolder instance = new PortHolder();
|
||||||
private final Object portLock = new Object();
|
private final Object portLock = new Object();
|
||||||
|
@ -31,11 +34,13 @@ public class PortHolder {
|
||||||
@Nullable
|
@Nullable
|
||||||
private IoStream serialPort;
|
private IoStream serialPort;
|
||||||
|
|
||||||
boolean connectAndReadConfiguration(String port, DataListener dataListener) {
|
public String port;
|
||||||
|
|
||||||
|
boolean connectAndReadConfiguration() {
|
||||||
if (port == null)
|
if (port == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
CommunicationLoggingHolder.communicationLoggingListener.onPortHolderMessage(SerialManager.class, "Opening port: " + port);
|
CommunicationLoggingHolder.communicationLoggingListener.onPortHolderMessage(getClass(), "Opening port: " + port);
|
||||||
|
|
||||||
IoStream stream = SerialIoStreamJSerialComm.openPort(port);
|
IoStream stream = SerialIoStreamJSerialComm.openPort(port);
|
||||||
synchronized (portLock) {
|
synchronized (portLock) {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.rusefi.core.MessagesCentral;
|
||||||
import com.rusefi.io.ConnectionStateListener;
|
import com.rusefi.io.ConnectionStateListener;
|
||||||
import com.rusefi.io.LinkConnector;
|
import com.rusefi.io.LinkConnector;
|
||||||
import com.rusefi.io.LinkManager;
|
import com.rusefi.io.LinkManager;
|
||||||
|
import com.sun.corba.se.spi.activation.ServerHolder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrey Belomutskiy
|
* @author Andrey Belomutskiy
|
||||||
|
@ -12,7 +13,7 @@ import com.rusefi.io.LinkManager;
|
||||||
*/
|
*/
|
||||||
public class SerialConnector implements LinkConnector {
|
public class SerialConnector implements LinkConnector {
|
||||||
public SerialConnector(String serialPort) {
|
public SerialConnector(String serialPort) {
|
||||||
SerialManager.port = serialPort;
|
PortHolder.getInstance().port = serialPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -24,7 +25,7 @@ public class SerialConnector implements LinkConnector {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
FileLog.MAIN.logLine("scheduleOpening>openPort");
|
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() {
|
LinkManager.COMMUNICATION_EXECUTOR.execute(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
MessagesCentral.getInstance().postMessage(SerialManager.class, "Restarting serial IO");
|
MessagesCentral.getInstance().postMessage(getClass(), "Restarting serial IO");
|
||||||
// if (closed)
|
// if (closed)
|
||||||
// return;
|
// return;
|
||||||
PortHolder.getInstance().close();
|
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