refactoring
This commit is contained in:
parent
6169f25679
commit
6484632233
|
@ -75,9 +75,6 @@ public class BinaryProtocol {
|
|||
private final Object imageLock = new Object();
|
||||
private ConfigurationImage controller;
|
||||
|
||||
// todo: fix this, this is HORRIBLE!
|
||||
@Deprecated
|
||||
public static BinaryProtocol instance;
|
||||
public boolean isClosed;
|
||||
// todo: make a singleton?
|
||||
public static byte[] currentOutputs;
|
||||
|
@ -86,7 +83,7 @@ public class BinaryProtocol {
|
|||
this.logger = logger;
|
||||
this.stream = stream;
|
||||
|
||||
instance = this;
|
||||
BinaryProtocolHolder.instance = this;
|
||||
|
||||
incomingData = new IncomingDataBuffer(logger);
|
||||
DataListener streamDataListener = new DataListener() {
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package com.rusefi.binaryprotocol;
|
||||
|
||||
/**
|
||||
* (c) Andrey Belomutskiy
|
||||
* 6/21/2017.
|
||||
*/
|
||||
public enum BinaryProtocolHolder {
|
||||
INSTANCE;
|
||||
|
||||
// todo: fix this, this is HORRIBLE!
|
||||
@Deprecated
|
||||
public static BinaryProtocol instance;
|
||||
|
||||
public static BinaryProtocolHolder getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public BinaryProtocol get() {
|
||||
return instance;
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.rusefi.io.tcp;
|
|||
|
||||
import com.rusefi.FileLog;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
|
||||
import com.rusefi.binaryprotocol.IoHelper;
|
||||
import com.rusefi.config.Fields;
|
||||
|
||||
|
@ -99,7 +100,7 @@ public class BinaryProtocolServer {
|
|||
short offset = dis.readShort();
|
||||
short count = dis.readShort(); // no swap here? interesting!
|
||||
System.out.println("CRC check " + page + "/" + offset + "/" + count);
|
||||
BinaryProtocol bp = BinaryProtocol.instance;
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().get();
|
||||
int result = IoHelper.getCrc32(bp.getController().getContent(), offset, count);
|
||||
ByteArrayOutputStream response = new ByteArrayOutputStream();
|
||||
response.write(TS_OK.charAt(0));
|
||||
|
@ -115,7 +116,7 @@ public class BinaryProtocolServer {
|
|||
FileLog.MAIN.logLine("Error: negative read request " + offset + "/" + count);
|
||||
} else {
|
||||
System.out.println("read " + page + "/" + offset + "/" + count);
|
||||
BinaryProtocol bp = BinaryProtocol.instance;
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().get();
|
||||
byte[] response = new byte[1 + count];
|
||||
response[0] = (byte) TS_OK.charAt(0);
|
||||
System.arraycopy(bp.getController().getContent(), offset, response, 1, count);
|
||||
|
|
|
@ -3,6 +3,7 @@ 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.Fields;
|
||||
import com.rusefi.io.tcp.BinaryProtocolServer;
|
||||
import com.rusefi.io.tcp.TcpIoStream;
|
||||
|
@ -13,8 +14,8 @@ import java.io.ByteArrayOutputStream;
|
|||
class BinaryProtocolServerSandbox {
|
||||
public static void main(String[] args) {
|
||||
TcpIoStream stream = new TcpIoStream(new ByteArrayInputStream(new byte[0]), new ByteArrayOutputStream());
|
||||
BinaryProtocol.instance = new BinaryProtocol(FileLog.LOGGER, stream);
|
||||
BinaryProtocol.instance.setController(new ConfigurationImage(new byte[14008]));
|
||||
BinaryProtocolHolder.instance = new BinaryProtocol(FileLog.LOGGER, stream);
|
||||
BinaryProtocolHolder.getInstance().get().setController(new ConfigurationImage(new byte[14008]));
|
||||
BinaryProtocol.currentOutputs = new byte[1 + Fields.TS_OUTPUT_SIZE];
|
||||
BinaryProtocolServer.start();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
|
||||
import com.rusefi.config.Fields;
|
||||
import com.rusefi.core.EngineState;
|
||||
import com.rusefi.core.MessagesCentral;
|
||||
|
@ -277,7 +278,7 @@ public class Launcher {
|
|||
root.setProperty(TAB_INDEX, tabbedPane.getSelectedIndex());
|
||||
GaugesPanel.DetachedRepository.INSTANCE.saveConfig();
|
||||
getConfig().save();
|
||||
BinaryProtocol bp = BinaryProtocol.instance;
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().get();
|
||||
if (bp != null && !bp.isClosed)
|
||||
bp.close(); // it could be that serial driver wants to be closed explicitly
|
||||
System.exit(0);
|
||||
|
|
|
@ -5,6 +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.ui.util.UiUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
|
@ -31,7 +32,7 @@ public class TableEditorPane extends JPanel {
|
|||
|
||||
add(editor.getContent());
|
||||
|
||||
BinaryProtocol instance = BinaryProtocol.instance;
|
||||
BinaryProtocol instance = BinaryProtocolHolder.getInstance().get();
|
||||
if (instance == null)
|
||||
throw new NullPointerException("instance");
|
||||
ConfigurationImage image = instance.getController();
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.opensr5.ConfigurationImage;
|
|||
import com.opensr5.Logger;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.opensr5.io.ConfigurationImageFile;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.io.serial.PortHolder;
|
||||
import com.rusefi.ui.RecentCommands;
|
||||
|
@ -89,7 +90,7 @@ public class UploadChanges {
|
|||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
BinaryProtocol.instance.uploadChanges(newVersion, logger);
|
||||
BinaryProtocolHolder.getInstance().get().uploadChanges(newVersion, logger);
|
||||
if (afterUpload != null)
|
||||
afterUpload.run();
|
||||
} catch (InterruptedException | EOFException | SerialPortException e) {
|
||||
|
|
|
@ -3,6 +3,7 @@ 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.Fields;
|
||||
import com.rusefi.core.Sensor;
|
||||
import com.rusefi.core.SensorCentral;
|
||||
|
@ -81,7 +82,7 @@ public class FormulasPane {
|
|||
}
|
||||
|
||||
private void updateFormula() {
|
||||
BinaryProtocol bp = BinaryProtocol.instance;
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().get();
|
||||
if (bp == null)
|
||||
return;
|
||||
ConfigurationImage ci = bp.getController();
|
||||
|
|
|
@ -13,6 +13,7 @@ import com.rusefi.autotune.FuelAutoTune;
|
|||
import com.rusefi.autotune.Result;
|
||||
import com.rusefi.autotune.stDataOnline;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
|
||||
import com.rusefi.config.Fields;
|
||||
import com.rusefi.core.Sensor;
|
||||
import com.rusefi.core.SensorCentral;
|
||||
|
@ -66,7 +67,7 @@ public class FuelTunePane {
|
|||
upload.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
uploadCurrentResukt();
|
||||
uploadCurrentResult();
|
||||
}
|
||||
});
|
||||
clean.addActionListener(new ActionListener() {
|
||||
|
@ -93,7 +94,7 @@ public class FuelTunePane {
|
|||
}
|
||||
if (runJob) {
|
||||
doJob();
|
||||
uploadCurrentResukt();
|
||||
uploadCurrentResult();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -133,9 +134,9 @@ public class FuelTunePane {
|
|||
initTable(changeMap);
|
||||
}
|
||||
|
||||
private void uploadCurrentResukt() {
|
||||
private void uploadCurrentResult() {
|
||||
byte[] newVeMap = FuelTunePane.this.newVeMap;
|
||||
BinaryProtocol bp = BinaryProtocol.instance;
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().get();
|
||||
if (newVeMap == null || bp == null)
|
||||
return;
|
||||
ConfigurationImage ci = bp.getController().clone();
|
||||
|
@ -312,7 +313,7 @@ public class FuelTunePane {
|
|||
}
|
||||
|
||||
private byte[] reloadVeTable() {
|
||||
BinaryProtocol bp = BinaryProtocol.instance;
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().get();
|
||||
|
||||
byte[] content = bp.getController().getContent();
|
||||
loadData(veTable.getXAxis(), content, veRpmOffset);
|
||||
|
@ -328,7 +329,7 @@ public class FuelTunePane {
|
|||
}
|
||||
|
||||
private void loadArray(float[] array, int offset) {
|
||||
BinaryProtocol bp = BinaryProtocol.instance;
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().get();
|
||||
if (bp == null) {
|
||||
FileLog.MAIN.logLine("bp not ready");
|
||||
return;
|
||||
|
|
|
@ -3,6 +3,7 @@ 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.ConnectionStatus;
|
||||
|
@ -41,7 +42,7 @@ public abstract class BaseConfigField {
|
|||
}
|
||||
|
||||
private void processInitialValue(Field field) {
|
||||
BinaryProtocol bp = BinaryProtocol.instance;
|
||||
BinaryProtocol bp = BinaryProtocolHolder.getInstance().get();
|
||||
if (bp == null)
|
||||
return;
|
||||
ConfigurationImage ci = bp.getController();
|
||||
|
|
Loading…
Reference in New Issue