rusEFI console does not stay alive #3912

test infrastructure progress
This commit is contained in:
rusefillc 2022-02-11 09:15:32 -05:00
parent a605d319ba
commit d05a6d3362
4 changed files with 51 additions and 12 deletions

View File

@ -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,12 +204,16 @@ public class BinaryProtocol {
if (requestOutputChannels()) if (requestOutputChannels())
HeartBeatListeners.onDataArrived(); HeartBeatListeners.onDataArrived();
binaryProtocolLogger.compositeLogic(BinaryProtocol.this); binaryProtocolLogger.compositeLogic(BinaryProtocol.this);
if (linkManager.isNeedPullText()) {
String text = requestPendingMessages(); String text = requestPendingMessages();
if (text != null) if (text != null)
textListener.onDataArrived((text + "\r\n").getBytes()); textListener.onDataArrived((text + "\r\n").getBytes());
}
if (linkManager.isNeedPullLiveData()) {
LiveDocsRegistry.LiveDataProvider liveDataProvider = LiveDocsRegistry.getLiveDataProvider(BinaryProtocol.this); LiveDocsRegistry.LiveDataProvider liveDataProvider = LiveDocsRegistry.getLiveDataProvider(BinaryProtocol.this);
LiveDocsRegistry.INSTANCE.refresh(liveDataProvider); LiveDocsRegistry.INSTANCE.refresh(liveDataProvider);
} }
}
}); });
} }
sleep(Timeouts.TEXT_PULL_PERIOD); sleep(Timeouts.TEXT_PULL_PERIOD);
@ -546,14 +553,15 @@ 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);
if (tsOutputSize == Fields.TS_OUTPUT_SIZE) // do not care about sensor values in test mode
SensorCentral.getInstance().grabSensorValues(response); SensorCentral.getInstance().grabSensorValues(response);
return true; return true;
} }

View File

@ -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,

View File

@ -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;
} }

View File

@ -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");
} }
} }