refactoring
This commit is contained in:
parent
8d808c7b95
commit
6f01260206
|
@ -64,8 +64,6 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
|||
this.logger = logger;
|
||||
this.stream = stream;
|
||||
|
||||
BinaryProtocolHolder.instance = this;
|
||||
|
||||
incomingData = new IncomingDataBuffer(logger);
|
||||
DataListener streamDataListener = new DataListener() {
|
||||
@Override
|
||||
|
@ -76,10 +74,6 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
|||
stream.setInputListener(streamDataListener);
|
||||
}
|
||||
|
||||
public BinaryProtocol(Logger logger, SerialPort serialPort) {
|
||||
this(logger, new SerialIoStream(serialPort, logger));
|
||||
}
|
||||
|
||||
private static void sleep() {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package com.rusefi.binaryprotocol;
|
||||
|
||||
import com.opensr5.Logger;
|
||||
import com.rusefi.io.IoStream;
|
||||
|
||||
/**
|
||||
* (c) Andrey Belomutskiy
|
||||
* 6/21/2017.
|
||||
|
@ -7,9 +10,8 @@ package com.rusefi.binaryprotocol;
|
|||
public enum BinaryProtocolHolder {
|
||||
INSTANCE;
|
||||
|
||||
// todo: fix this, this is HORRIBLE!
|
||||
@Deprecated
|
||||
public static BinaryProtocol instance;
|
||||
// todo: fix this? less horrible but still weird!
|
||||
private BinaryProtocol instance;
|
||||
|
||||
public static BinaryProtocolHolder getInstance() {
|
||||
return INSTANCE;
|
||||
|
@ -18,4 +20,10 @@ public enum BinaryProtocolHolder {
|
|||
public BinaryProtocol get() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static BinaryProtocol create(final Logger logger, IoStream stream) {
|
||||
BinaryProtocol result = new BinaryProtocol(logger, stream);
|
||||
getInstance().instance = result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ 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;
|
||||
|
@ -73,7 +74,7 @@ public class PortHolder {
|
|||
portLock.notifyAll();
|
||||
}
|
||||
|
||||
bp = new BinaryProtocol(FileLog.LOGGER, new SerialIoStream(serialPort, FileLog.LOGGER));
|
||||
bp = BinaryProtocolHolder.create(FileLog.LOGGER, new SerialIoStream(serialPort, FileLog.LOGGER));
|
||||
|
||||
return bp.connectAndReadConfiguration(listener);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ 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.*;
|
||||
|
||||
|
@ -109,7 +110,7 @@ public class TcpConnector implements LinkConnector {
|
|||
};
|
||||
// ioStream.setInputListener(listener1);
|
||||
|
||||
bp = new BinaryProtocol(FileLog.LOGGER, new TcpIoStream(stream, os));
|
||||
bp = BinaryProtocolHolder.create(FileLog.LOGGER, new TcpIoStream(stream, os));
|
||||
|
||||
boolean result = bp.connectAndReadConfiguration(listener1);
|
||||
if (result) {
|
||||
|
|
|
@ -14,8 +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 = new BinaryProtocol(FileLog.LOGGER, stream);
|
||||
BinaryProtocolHolder.instance = bp;
|
||||
BinaryProtocol bp = BinaryProtocolHolder.create(FileLog.LOGGER, stream);
|
||||
bp.setController(new ConfigurationImage(new byte[14008]));
|
||||
bp.currentOutputs = new byte[1 + Fields.TS_OUTPUT_SIZE];
|
||||
BinaryProtocolServer.start();
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.opensr5.io.ConfigurationImageFile;
|
|||
import com.rusefi.binaryprotocol.BinaryProtocolHolder;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.io.serial.PortHolder;
|
||||
import com.rusefi.io.serial.SerialIoStream;
|
||||
import com.rusefi.ui.RecentCommands;
|
||||
import com.rusefi.ui.SettingsTab;
|
||||
import com.rusefi.ui.StatusWindow;
|
||||
|
@ -73,7 +74,7 @@ public class UploadChanges {
|
|||
|
||||
final ConfigurationImage ci2 = ConfigurationImageFile.readFromFile("rusefi_configuration.bin");
|
||||
|
||||
final BinaryProtocol bp = new BinaryProtocol(logger, serialPort);
|
||||
final BinaryProtocol bp = BinaryProtocolHolder.create(logger, new SerialIoStream(serialPort, logger));
|
||||
bp.setController(ci1);
|
||||
|
||||
scheduleUpload(ci2);
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.rusefi.RomRaiderWrapper;
|
|||
import com.rusefi.TsPageSize;
|
||||
import com.rusefi.UploadChanges;
|
||||
import com.rusefi.io.serial.PortHolder;
|
||||
import com.rusefi.io.serial.SerialIoStream;
|
||||
import jssc.SerialPort;
|
||||
|
||||
/**
|
||||
|
@ -32,7 +33,7 @@ public class BinaryProtocolCmdSandbox {
|
|||
if (!opened) {
|
||||
logger.error("failed to open " + port);
|
||||
}
|
||||
BinaryProtocol bp = new BinaryProtocol(logger, serialPort);
|
||||
BinaryProtocol bp = BinaryProtocolHolder.create(logger, new SerialIoStream(serialPort, logger));
|
||||
|
||||
PortHolder.setupPort(serialPort, 38400);
|
||||
logger.info("Binary looks good!");
|
||||
|
|
Loading…
Reference in New Issue