refactoring: better dependency control
This commit is contained in:
parent
64c065fd72
commit
713d8cbd81
|
@ -3,12 +3,12 @@ package com.rusefi;
|
|||
|
||||
import com.opensr5.Logger;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.core.MessagesCentral;
|
||||
import com.rusefi.core.Sensor;
|
||||
import com.rusefi.core.SensorCentral;
|
||||
import com.rusefi.io.CommandQueue;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.waves.EngineChart;
|
||||
import com.rusefi.waves.EngineReport;
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class AutoTest {
|
|||
}
|
||||
});
|
||||
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
BinaryProtocol bp = LinkManager.getCurrentStreamState();
|
||||
// let's make sure 'burn' command works since sometimes it does not
|
||||
bp.burn(Logger.CONSOLE);
|
||||
|
||||
|
|
|
@ -45,7 +45,6 @@ import static com.rusefi.binaryprotocol.IoHelper.*;
|
|||
*
|
||||
* Andrey Belomutskiy, (c) 2013-2020
|
||||
* 3/6/2015
|
||||
* @see BinaryProtocolHolder
|
||||
*/
|
||||
public class BinaryProtocol implements BinaryProtocolCommands {
|
||||
|
||||
|
@ -111,7 +110,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
|||
|
||||
private final Thread hook = new Thread(() -> closeComposites());
|
||||
|
||||
protected BinaryProtocol(final Logger logger, IoStream stream) {
|
||||
public BinaryProtocol(final Logger logger, IoStream stream) {
|
||||
this.logger = logger;
|
||||
this.stream = stream;
|
||||
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
package com.rusefi.binaryprotocol;
|
||||
|
||||
import com.opensr5.Logger;
|
||||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.LinkManager;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* At any given moment of time JVM manages one communication stream
|
||||
*
|
||||
* TODO: remove this dead class?
|
||||
*
|
||||
* Andrey Belomutskiy, (c) 2013-2020
|
||||
* 6/21/2017.
|
||||
*/
|
||||
public enum BinaryProtocolHolder {
|
||||
INSTANCE;
|
||||
|
||||
public static BinaryProtocolHolder getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static BinaryProtocol create(final Logger logger, IoStream stream) {
|
||||
return new BinaryProtocol(logger, stream);
|
||||
}
|
||||
|
||||
public static BinaryProtocol getCurrentStreamState() {
|
||||
Objects.requireNonNull(LinkManager.connector, "connector");
|
||||
return LinkManager.connector.getBinaryProtocol();
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package com.rusefi.io;
|
|||
import com.fazecast.jSerialComm.SerialPort;
|
||||
import com.rusefi.FileLog;
|
||||
import com.rusefi.NamedThreadFactory;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.core.EngineState;
|
||||
import com.rusefi.io.serial.SerialConnector;
|
||||
import com.rusefi.io.tcp.TcpConnector;
|
||||
|
@ -56,6 +57,11 @@ public class LinkManager {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static BinaryProtocol getCurrentStreamState() {
|
||||
Objects.requireNonNull(connector, "connector");
|
||||
return connector.getBinaryProtocol();
|
||||
}
|
||||
|
||||
public enum LogLevel {
|
||||
INFO,
|
||||
DEBUG,
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.rusefi.io.serial;
|
|||
|
||||
import com.rusefi.FileLog;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
|
||||
import com.rusefi.io.CommunicationLoggingHolder;
|
||||
import com.rusefi.io.ConnectionStateListener;
|
||||
import com.opensr5.io.DataListener;
|
||||
|
@ -41,7 +40,7 @@ public class PortHolder {
|
|||
|
||||
IoStream stream = SerialIoStreamJSerialComm.openPort(port);
|
||||
synchronized (portLock) {
|
||||
bp = BinaryProtocolHolder.getInstance().create(FileLog.LOGGER, stream);
|
||||
bp = new BinaryProtocol(FileLog.LOGGER, stream);
|
||||
portLock.notifyAll();
|
||||
}
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@ package com.rusefi.io.tcp;
|
|||
import com.rusefi.FileLog;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolCommands;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
|
||||
import com.rusefi.binaryprotocol.IoHelper;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.LinkManager;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.ServerSocket;
|
||||
|
@ -126,7 +126,7 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
|||
|
||||
byte[] response = new byte[1 + count];
|
||||
response[0] = (byte) TS_OK.charAt(0);
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
BinaryProtocol bp = LinkManager.getCurrentStreamState();
|
||||
byte[] currentOutputs = bp.currentOutputs;
|
||||
if (currentOutputs != null)
|
||||
System.arraycopy(currentOutputs, 1 + offset , response, 1, count);
|
||||
|
@ -143,7 +143,7 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
|||
int offset = swap16(dis.readShort());
|
||||
int count = swap16(dis.readShort());
|
||||
FileLog.MAIN.logLine("TS_CHUNK_WRITE_COMMAND: offset=" + offset + " count=" + count);
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
BinaryProtocol bp = LinkManager.getCurrentStreamState();
|
||||
bp.setRange(packet, 7, offset, count);
|
||||
stream.sendPacket(TS_OK.getBytes(), FileLog.LOGGER);
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
|||
FileLog.MAIN.logLine("Error: negative read request " + offset + "/" + count);
|
||||
} else {
|
||||
System.out.println("read " + page + "/" + offset + "/" + count);
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
BinaryProtocol bp = LinkManager.getCurrentStreamState();
|
||||
byte[] response = new byte[1 + count];
|
||||
response[0] = (byte) TS_OK.charAt(0);
|
||||
System.arraycopy(bp.getControllerConfiguration().getContent(), offset, response, 1, count);
|
||||
|
@ -166,7 +166,7 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
|||
|
||||
private static void handleCrc(TcpIoStream stream) throws IOException {
|
||||
System.out.println("CRC check");
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
BinaryProtocol bp = LinkManager.getCurrentStreamState();
|
||||
byte[] content = bp.getControllerConfiguration().getContent();
|
||||
int result = IoHelper.getCrc32(content);
|
||||
ByteArrayOutputStream response = new ByteArrayOutputStream();
|
||||
|
|
|
@ -3,9 +3,9 @@ package com.rusefi.io.tcp;
|
|||
import com.opensr5.io.DataListener;
|
||||
import com.rusefi.FileLog;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
|
||||
import com.rusefi.core.ResponseBuffer;
|
||||
import com.rusefi.io.ConnectionStateListener;
|
||||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.LinkConnector;
|
||||
import com.rusefi.io.LinkManager;
|
||||
|
||||
|
@ -122,7 +122,7 @@ public class TcpConnector implements LinkConnector {
|
|||
};
|
||||
// ioStream.setInputListener(listener1);
|
||||
|
||||
bp = BinaryProtocolHolder.getInstance().create(FileLog.LOGGER, new TcpIoStream(stream, os));
|
||||
bp = new BinaryProtocol(FileLog.LOGGER, (IoStream) new TcpIoStream(stream, os));
|
||||
|
||||
boolean result = bp.connectAndReadConfiguration(listener1);
|
||||
if (result) {
|
||||
|
|
|
@ -3,9 +3,9 @@ package com.rusefi.io.tcp.test;
|
|||
import com.opensr5.ConfigurationImage;
|
||||
import com.rusefi.FileLog;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.ConnectionStateListener;
|
||||
import com.rusefi.io.IoStream;
|
||||
import com.rusefi.io.LinkConnector;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||
|
@ -17,7 +17,7 @@ import java.io.ByteArrayOutputStream;
|
|||
class BinaryProtocolServerSandbox {
|
||||
public static void main(String[] args) {
|
||||
TcpIoStream stream = new TcpIoStream(new ByteArrayInputStream(new byte[0]), new ByteArrayOutputStream());
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().create(FileLog.LOGGER, stream);
|
||||
BinaryProtocol bp = new BinaryProtocol(FileLog.LOGGER, (IoStream) stream);
|
||||
LinkManager.setConnector(new LinkConnector() {
|
||||
@Override
|
||||
public void connectAndReadConfiguration(ConnectionStateListener listener) {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.tracing.Entry;
|
||||
import com.rusefi.tracing.JsonOutput;
|
||||
import com.rusefi.ui.MessagesView;
|
||||
|
@ -57,7 +57,7 @@ public class BenchTestPane {
|
|||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
BinaryProtocol bp = BinaryProtocolHolder.INSTANCE.getCurrentStreamState();
|
||||
BinaryProtocol bp = LinkManager.getCurrentStreamState();
|
||||
bp.executeCommand(new byte[]{Fields.TS_PERF_TRACE_BEGIN}, "begin trace");
|
||||
|
||||
try {
|
||||
|
|
|
@ -5,7 +5,7 @@ import com.romraider.editor.ecu.ECUEditor;
|
|||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolCmd;
|
||||
import com.opensr5.io.ConfigurationImageFile;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.ui.util.UiUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
|
@ -32,7 +32,7 @@ public class TableEditorPane extends JPanel {
|
|||
|
||||
add(editor.getContent());
|
||||
|
||||
BinaryProtocol instance = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
BinaryProtocol instance = LinkManager.getCurrentStreamState();
|
||||
if (instance == null)
|
||||
throw new NullPointerException("instance");
|
||||
ConfigurationImage image = instance.getControllerConfiguration();
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.rusefi;
|
|||
|
||||
import com.opensr5.ConfigurationImage;
|
||||
import com.opensr5.Logger;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.ui.RecentCommands;
|
||||
|
@ -88,7 +87,7 @@ public class UploadChanges {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
BinaryProtocolHolder.getInstance().getCurrentStreamState().uploadChanges(newVersion, logger);
|
||||
LinkManager.getCurrentStreamState().uploadChanges(newVersion, logger);
|
||||
if (afterUpload != null)
|
||||
afterUpload.run();
|
||||
} catch (InterruptedException | EOFException e) {
|
||||
|
|
|
@ -31,7 +31,7 @@ public class BinaryProtocolCmdSandbox {
|
|||
// if (!opened) {
|
||||
// logger.error("failed to open " + port);
|
||||
// }
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().create(logger, SerialIoStreamJSerialComm.openPort(port));
|
||||
BinaryProtocol bp = new BinaryProtocol(logger, SerialIoStreamJSerialComm.openPort(port));
|
||||
|
||||
//SerialIoStreamJSSC.setupPort(serialPort, 38400);
|
||||
logger.info("Binary looks good!");
|
||||
|
|
|
@ -4,10 +4,10 @@ import com.opensr5.ConfigurationImage;
|
|||
import com.rusefi.FileLog;
|
||||
import com.rusefi.Launcher;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.core.Sensor;
|
||||
import com.rusefi.core.SensorCentral;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.ui.config.ConfigField;
|
||||
|
||||
import java.io.FileWriter;
|
||||
|
@ -45,7 +45,7 @@ public class PlainTextSensorLog implements SensorLog {
|
|||
logFile.write("Captured " + FileLog.getDate() + "\r\n");
|
||||
|
||||
int debugMode = -1;
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
BinaryProtocol bp = LinkManager.getCurrentStreamState();
|
||||
if (bp != null) {
|
||||
ConfigurationImage ci = bp.getControllerConfiguration();
|
||||
if (ci != null) {
|
||||
|
|
|
@ -3,10 +3,10 @@ package com.rusefi.ui;
|
|||
import com.opensr5.ConfigurationImage;
|
||||
import com.rusefi.FileLog;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.core.Sensor;
|
||||
import com.rusefi.core.SensorCentral;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.ui.config.ConfigField;
|
||||
import com.rusefi.ui.livedocs.LiveDocPanel;
|
||||
import com.rusefi.ui.util.UiUtils;
|
||||
|
@ -107,7 +107,7 @@ public class FormulasPane {
|
|||
}
|
||||
|
||||
private void updateFormula() {
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
BinaryProtocol bp = LinkManager.getCurrentStreamState();
|
||||
if (bp == null)
|
||||
return;
|
||||
ConfigurationImage ci = bp.getControllerConfiguration();
|
||||
|
|
|
@ -13,11 +13,11 @@ import com.rusefi.autotune.FuelAutoTune;
|
|||
import com.rusefi.autotune.Result;
|
||||
import com.rusefi.autotune.AfrDataPoint;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.core.ISensorCentral;
|
||||
import com.rusefi.core.Sensor;
|
||||
import com.rusefi.core.SensorCentral;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.ui.storage.Node;
|
||||
|
||||
import javax.swing.*;
|
||||
|
@ -136,7 +136,7 @@ public class FuelTunePane {
|
|||
|
||||
private void uploadCurrentResult() {
|
||||
byte[] newVeMap = FuelTunePane.this.newVeMap;
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
BinaryProtocol bp = LinkManager.getCurrentStreamState();
|
||||
if (newVeMap == null || bp == null)
|
||||
return;
|
||||
ConfigurationImage ci = bp.getControllerConfiguration().clone();
|
||||
|
@ -313,7 +313,7 @@ public class FuelTunePane {
|
|||
}
|
||||
|
||||
private byte[] reloadVeTable() {
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
BinaryProtocol bp = LinkManager.getCurrentStreamState();
|
||||
|
||||
byte[] content = bp.getControllerConfiguration().getContent();
|
||||
loadData(veTable.getXAxis(), content, veRpmOffset);
|
||||
|
@ -329,7 +329,7 @@ public class FuelTunePane {
|
|||
}
|
||||
|
||||
private void loadArray(double[] array, int offset) {
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
BinaryProtocol bp = LinkManager.getCurrentStreamState();
|
||||
if (bp == null) {
|
||||
FileLog.MAIN.logLine("bp not ready");
|
||||
return;
|
||||
|
|
|
@ -3,10 +3,10 @@ package com.rusefi.ui.config;
|
|||
import com.opensr5.ConfigurationImage;
|
||||
import com.rusefi.FileLog;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
|
||||
import com.rusefi.config.Field;
|
||||
import com.rusefi.io.CommandQueue;
|
||||
import com.rusefi.io.ConnectionStatusLogic;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
@ -28,7 +28,7 @@ public abstract class BaseConfigField {
|
|||
}
|
||||
|
||||
private void processInitialValue(Field field) {
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
BinaryProtocol bp = LinkManager.getCurrentStreamState();
|
||||
if (bp == null)
|
||||
return;
|
||||
ConfigurationImage ci = bp.getControllerConfiguration();
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.rusefi.ui.console;
|
|||
|
||||
import com.rusefi.*;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.core.EngineState;
|
||||
import com.rusefi.io.*;
|
||||
|
@ -113,7 +112,7 @@ public class MainFrame {
|
|||
root.setProperty(ConsoleUI.TAB_INDEX, tabbedPane.tabbedPane.getSelectedIndex());
|
||||
GaugesPanel.DetachedRepository.INSTANCE.saveConfig();
|
||||
getConfig().save();
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
BinaryProtocol bp = LinkManager.getCurrentStreamState();
|
||||
if (bp != null && !bp.isClosed)
|
||||
bp.close(); // it could be that serial driver wants to be closed explicitly
|
||||
System.exit(0);
|
||||
|
|
Loading…
Reference in New Issue