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