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