only better method names, no logic change
This commit is contained in:
parent
2dac2e6cd1
commit
c0a2dc99de
|
@ -43,7 +43,7 @@ public class AutoTest {
|
|||
}
|
||||
});
|
||||
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().get();
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
// let's make sure 'burn' command works since sometimes it does not
|
||||
bp.burn(Logger.CONSOLE);
|
||||
|
||||
|
|
|
@ -4,26 +4,28 @@ import com.opensr5.Logger;
|
|||
import com.rusefi.io.IoStream;
|
||||
|
||||
/**
|
||||
* At any given moment of time JVM manages one communication stream
|
||||
*
|
||||
*
|
||||
* (c) Andrey Belomutskiy
|
||||
* 6/21/2017.
|
||||
*/
|
||||
public enum BinaryProtocolHolder {
|
||||
INSTANCE;
|
||||
|
||||
// todo: fix this? less horrible but still weird!
|
||||
private BinaryProtocol instance;
|
||||
private BinaryProtocol currentStream;
|
||||
|
||||
public static BinaryProtocolHolder getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public BinaryProtocol get() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static BinaryProtocol create(final Logger logger, IoStream stream) {
|
||||
public BinaryProtocol create(final Logger logger, IoStream stream) {
|
||||
BinaryProtocol result = new BinaryProtocol(logger, stream);
|
||||
getInstance().instance = result;
|
||||
currentStream = result;
|
||||
return result;
|
||||
}
|
||||
|
||||
public BinaryProtocol getCurrentStreamState() {
|
||||
return currentStream;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,16 +62,11 @@ public class PortHolder {
|
|||
}
|
||||
IoStream stream = establishConnection.getStream();
|
||||
|
||||
bp = BinaryProtocolHolder.create(FileLog.LOGGER, stream);
|
||||
bp = BinaryProtocolHolder.getInstance().create(FileLog.LOGGER, stream);
|
||||
|
||||
return bp.connectAndReadConfiguration(listener);
|
||||
}
|
||||
|
||||
private static boolean isWindows10() {
|
||||
// todo: this code is fragile! What about Windows 11, 12 etc!? this is a problem for the later day :(
|
||||
return System.getProperty(FileLog.OS_VERSION).startsWith("10");
|
||||
}
|
||||
|
||||
public void close() {
|
||||
synchronized (portLock) {
|
||||
if (serialPort != null) {
|
||||
|
@ -124,14 +119,6 @@ public class PortHolder {
|
|||
|
||||
public EstablishConnection invoke() {
|
||||
stream = SerialIoStreamJSerialComm.open(port, BAUD_RATE, FileLog.LOGGER);
|
||||
/*
|
||||
todo: remove dead code
|
||||
if (stream == null) {
|
||||
isConnected = false;
|
||||
return this;
|
||||
}
|
||||
*/
|
||||
|
||||
isConnected = true;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
|||
short offset = dis.readShort();
|
||||
short count = dis.readShort(); // no swap here? interesting!
|
||||
System.out.println("CRC check " + page + "/" + offset + "/" + count);
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().get();
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
int result = IoHelper.getCrc32(bp.getController().getContent(), offset, count);
|
||||
ByteArrayOutputStream response = new ByteArrayOutputStream();
|
||||
response.write(TS_OK.charAt(0));
|
||||
|
@ -127,7 +127,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().get();
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
byte[] response = new byte[1 + count];
|
||||
response[0] = (byte) TS_OK.charAt(0);
|
||||
System.arraycopy(bp.getController().getContent(), offset, response, 1, count);
|
||||
|
@ -141,7 +141,7 @@ public class BinaryProtocolServer implements BinaryProtocolCommands {
|
|||
|
||||
byte[] response = new byte[1 + Fields.TS_OUTPUT_SIZE];
|
||||
response[0] = (byte) TS_OK.charAt(0);
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().get();
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
byte[] currentOutputs = bp.currentOutputs;
|
||||
if (currentOutputs != null)
|
||||
System.arraycopy(currentOutputs, 1, response, 1, Fields.TS_OUTPUT_SIZE);
|
||||
|
|
|
@ -118,7 +118,7 @@ public class TcpConnector implements LinkConnector {
|
|||
};
|
||||
// ioStream.setInputListener(listener1);
|
||||
|
||||
bp = BinaryProtocolHolder.create(FileLog.LOGGER, new TcpIoStream(stream, os));
|
||||
bp = BinaryProtocolHolder.getInstance().create(FileLog.LOGGER, new TcpIoStream(stream, os));
|
||||
|
||||
boolean result = bp.connectAndReadConfiguration(listener1);
|
||||
if (result) {
|
||||
|
@ -130,7 +130,6 @@ public class TcpConnector implements LinkConnector {
|
|||
|
||||
@Override
|
||||
public void restart() {
|
||||
// FileLog.rlog("Restarting on " + port);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -141,7 +140,6 @@ public class TcpConnector implements LinkConnector {
|
|||
@Override
|
||||
public String unpack(String packet) {
|
||||
return packet;
|
||||
// return EngineState.unpackString(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -152,15 +150,6 @@ public class TcpConnector implements LinkConnector {
|
|||
}
|
||||
|
||||
bp.doSend(command, fireEvent);
|
||||
// String command = LinkManager.encodeCommand(text);
|
||||
// FileLog.MAIN.logLine("Writing " + command);
|
||||
// try {
|
||||
// ioStream.write((command + "\n").getBytes());
|
||||
// } catch (IOException e) {
|
||||
// withError = true;
|
||||
// System.err.println("err in send");
|
||||
// e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
// }
|
||||
}
|
||||
|
||||
public static Collection<String> getAvailablePorts() {
|
||||
|
|
|
@ -14,7 +14,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.create(FileLog.LOGGER, stream);
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().create(FileLog.LOGGER, stream);
|
||||
bp.setController(new ConfigurationImage(new byte[14008]));
|
||||
bp.currentOutputs = new byte[1 + Fields.TS_OUTPUT_SIZE];
|
||||
BinaryProtocolServer.start();
|
||||
|
|
|
@ -57,7 +57,7 @@ public class BenchTestPane {
|
|||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
BinaryProtocol bp = BinaryProtocolHolder.INSTANCE.get();
|
||||
BinaryProtocol bp = BinaryProtocolHolder.INSTANCE.getCurrentStreamState();
|
||||
bp.executeCommand(new byte[]{'r'}, "begin trace", false);
|
||||
|
||||
try {
|
||||
|
|
|
@ -149,7 +149,7 @@ public class SensorLogger {
|
|||
logFile.write("Captured " + FileLog.getDate() + "\r\n");
|
||||
|
||||
int debugMode = -1;
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().get();
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
if (bp != null) {
|
||||
ConfigurationImage ci = bp.getController();
|
||||
if (ci != null) {
|
||||
|
|
|
@ -32,7 +32,7 @@ public class TableEditorPane extends JPanel {
|
|||
|
||||
add(editor.getContent());
|
||||
|
||||
BinaryProtocol instance = BinaryProtocolHolder.getInstance().get();
|
||||
BinaryProtocol instance = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
if (instance == null)
|
||||
throw new NullPointerException("instance");
|
||||
ConfigurationImage image = instance.getController();
|
||||
|
|
|
@ -73,7 +73,7 @@ public class UploadChanges {
|
|||
|
||||
final ConfigurationImage ci2 = ConfigurationImageFile.readFromFile("rusefi_configuration.bin");
|
||||
|
||||
final BinaryProtocol bp = BinaryProtocolHolder.create(logger, new SerialIoStreamJSSC(serialPort, logger));
|
||||
final BinaryProtocol bp = BinaryProtocolHolder.getInstance().create(logger, new SerialIoStreamJSSC(serialPort, logger));
|
||||
bp.setController(ci1);
|
||||
|
||||
scheduleUpload(ci2);
|
||||
|
@ -90,7 +90,7 @@ public class UploadChanges {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
BinaryProtocolHolder.getInstance().get().uploadChanges(newVersion, logger);
|
||||
BinaryProtocolHolder.getInstance().getCurrentStreamState().uploadChanges(newVersion, logger);
|
||||
if (afterUpload != null)
|
||||
afterUpload.run();
|
||||
} catch (InterruptedException | EOFException | SerialPortException e) {
|
||||
|
|
|
@ -32,7 +32,7 @@ public class BinaryProtocolCmdSandbox {
|
|||
if (!opened) {
|
||||
logger.error("failed to open " + port);
|
||||
}
|
||||
BinaryProtocol bp = BinaryProtocolHolder.create(logger, new SerialIoStreamJSSC(serialPort, logger));
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().create(logger, new SerialIoStreamJSSC(serialPort, logger));
|
||||
|
||||
SerialIoStreamJSSC.setupPort(serialPort, 38400);
|
||||
logger.info("Binary looks good!");
|
||||
|
|
|
@ -105,7 +105,7 @@ public class FormulasPane {
|
|||
}
|
||||
|
||||
private void updateFormula() {
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().get();
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
if (bp == null)
|
||||
return;
|
||||
ConfigurationImage ci = bp.getController();
|
||||
|
|
|
@ -136,7 +136,7 @@ public class FuelTunePane {
|
|||
|
||||
private void uploadCurrentResult() {
|
||||
byte[] newVeMap = FuelTunePane.this.newVeMap;
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().get();
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
if (newVeMap == null || bp == null)
|
||||
return;
|
||||
ConfigurationImage ci = bp.getController().clone();
|
||||
|
@ -313,7 +313,7 @@ public class FuelTunePane {
|
|||
}
|
||||
|
||||
private byte[] reloadVeTable() {
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().get();
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
|
||||
byte[] content = bp.getController().getContent();
|
||||
loadData(veTable.getXAxis(), content, veRpmOffset);
|
||||
|
@ -329,7 +329,7 @@ public class FuelTunePane {
|
|||
}
|
||||
|
||||
private void loadArray(double[] array, int offset) {
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().get();
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
if (bp == null) {
|
||||
FileLog.MAIN.logLine("bp not ready");
|
||||
return;
|
||||
|
|
|
@ -28,7 +28,7 @@ public abstract class BaseConfigField {
|
|||
}
|
||||
|
||||
private void processInitialValue(Field field) {
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().get();
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().getCurrentStreamState();
|
||||
if (bp == null)
|
||||
return;
|
||||
ConfigurationImage ci = bp.getController();
|
||||
|
|
|
@ -111,7 +111,7 @@ public class MainFrame {
|
|||
root.setProperty(Launcher.TAB_INDEX, tabbedPane.tabbedPane.getSelectedIndex());
|
||||
GaugesPanel.DetachedRepository.INSTANCE.saveConfig();
|
||||
getConfig().save();
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().get();
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().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