parent
a605d319ba
commit
d05a6d3362
|
@ -64,6 +64,9 @@ public class BinaryProtocol {
|
|||
BinaryProtocolLogger binaryProtocolLogger;
|
||||
public static boolean DISABLE_LOCAL_CACHE;
|
||||
|
||||
// hack needed by
|
||||
public static int tsOutputSize = TS_OUTPUT_SIZE;
|
||||
|
||||
public static String findCommand(byte command) {
|
||||
switch (command) {
|
||||
case Fields.TS_PAGE_COMMAND:
|
||||
|
@ -201,11 +204,15 @@ public class BinaryProtocol {
|
|||
if (requestOutputChannels())
|
||||
HeartBeatListeners.onDataArrived();
|
||||
binaryProtocolLogger.compositeLogic(BinaryProtocol.this);
|
||||
String text = requestPendingMessages();
|
||||
if (text != null)
|
||||
textListener.onDataArrived((text + "\r\n").getBytes());
|
||||
LiveDocsRegistry.LiveDataProvider liveDataProvider = LiveDocsRegistry.getLiveDataProvider(BinaryProtocol.this);
|
||||
LiveDocsRegistry.INSTANCE.refresh(liveDataProvider);
|
||||
if (linkManager.isNeedPullText()) {
|
||||
String text = requestPendingMessages();
|
||||
if (text != null)
|
||||
textListener.onDataArrived((text + "\r\n").getBytes());
|
||||
}
|
||||
if (linkManager.isNeedPullLiveData()) {
|
||||
LiveDocsRegistry.LiveDataProvider liveDataProvider = LiveDocsRegistry.getLiveDataProvider(BinaryProtocol.this);
|
||||
LiveDocsRegistry.INSTANCE.refresh(liveDataProvider);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -546,15 +553,16 @@ public class BinaryProtocol {
|
|||
if (isClosed)
|
||||
return false;
|
||||
|
||||
byte[] packet = GetOutputsCommand.createRequest();
|
||||
byte[] packet = GetOutputsCommand.createRequest(tsOutputSize);
|
||||
|
||||
byte[] response = executeCommand(Fields.TS_OUTPUT_COMMAND, packet, "output channels", false);
|
||||
if (response == null || response.length != (Fields.TS_OUTPUT_SIZE + 1) || response[0] != Fields.TS_RESPONSE_OK)
|
||||
if (response == null || response.length != (tsOutputSize + 1) || response[0] != Fields.TS_RESPONSE_OK)
|
||||
return false;
|
||||
|
||||
state.setCurrentOutputs(response);
|
||||
|
||||
SensorCentral.getInstance().grabSensorValues(response);
|
||||
if (tsOutputSize == Fields.TS_OUTPUT_SIZE) // do not care about sensor values in test mode
|
||||
SensorCentral.getInstance().grabSensorValues(response);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@ public class LinkManager implements Closeable {
|
|||
private boolean isStarted;
|
||||
private boolean compositeLogicEnabled = true;
|
||||
private boolean needPullData = true;
|
||||
private boolean needPullText = true;
|
||||
private boolean needPullLiveData = true;
|
||||
public final MessagesListener messageListener = (source, message) -> System.out.println(source + ": " + message);
|
||||
private Thread communicationThread;
|
||||
|
||||
|
@ -150,11 +152,29 @@ public class LinkManager implements Closeable {
|
|||
return needPullData;
|
||||
}
|
||||
|
||||
public boolean isNeedPullText() {
|
||||
return needPullText;
|
||||
}
|
||||
|
||||
public boolean isNeedPullLiveData() {
|
||||
return needPullLiveData;
|
||||
}
|
||||
|
||||
public LinkManager setNeedPullLiveData(boolean needPullLiveData) {
|
||||
this.needPullLiveData = needPullLiveData;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LinkManager setNeedPullData(boolean needPullData) {
|
||||
this.needPullData = needPullData;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LinkManager setNeedPullText(boolean needPullText) {
|
||||
this.needPullText = needPullText;
|
||||
return this;
|
||||
}
|
||||
|
||||
public enum LogLevel {
|
||||
INFO,
|
||||
DEBUG,
|
||||
|
|
|
@ -11,9 +11,13 @@ import static com.rusefi.binaryprotocol.IoHelper.swap16;
|
|||
|
||||
public class GetOutputsCommand {
|
||||
public static byte[] createRequest() {
|
||||
return createRequest(Fields.TS_OUTPUT_SIZE);
|
||||
}
|
||||
|
||||
public static byte[] createRequest(int size) {
|
||||
byte[] packet = new byte[4];
|
||||
putShort(packet, 0, 0); // offset
|
||||
putShort(packet, 2, swap16(Fields.TS_OUTPUT_SIZE));
|
||||
putShort(packet, 2, swap16(size));
|
||||
return packet;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +1,27 @@
|
|||
package com.rusefi.binaryprotocol.test;
|
||||
|
||||
import com.rusefi.autodetect.PortDetector;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.io.HeartBeatListeners;
|
||||
import com.rusefi.io.LinkManager;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
public class SerialSandbox {
|
||||
public static void main(String[] args) {
|
||||
BinaryProtocol.tsOutputSize = 100;
|
||||
|
||||
String port = PortDetector.autoDetectSerial(callbackContext -> null).getSerialPort();
|
||||
System.out.println("Serial detected on " + port);
|
||||
|
||||
LinkManager linkManager = new LinkManager();
|
||||
HeartBeatListeners.INSTANCE.addListener(() -> System.out.println(new Date() + ": onDataArrival"));
|
||||
|
||||
LinkManager linkManager = new LinkManager()
|
||||
.setNeedPullText(false)
|
||||
.setNeedPullLiveData(false);
|
||||
CountDownLatch connected = linkManager.connect(port);
|
||||
if (connected.getCount() > 0)
|
||||
throw new IllegalStateException("Not connected in time");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue