rusEFI console bug while Lua with simulator fix #3387

This commit is contained in:
rusefillc 2021-10-22 11:12:55 -04:00
parent 478a25d0b4
commit 3fe486e191
4 changed files with 40 additions and 43 deletions

View File

@ -467,7 +467,7 @@ public class BinaryProtocol {
if (isClosed) if (isClosed)
return null; return null;
try { try {
LinkManager.assertCommunicationThread(); linkManager.assertCommunicationThread();
dropPending(); dropPending();
sendPacket(packet); sendPacket(packet);

View File

@ -53,8 +53,20 @@ public class LinkManager implements Closeable {
System.out.println(source + ": " + message); System.out.println(source + ": " + message);
} }
}; };
private Thread communicationThread;
public LinkManager() { public LinkManager() {
Future<?> future = submit(() -> {
communicationThread = Thread.currentThread();
System.out.println("communicationThread lookup DONE");
});
try {
// let's wait for the above trivial task to finish
future.get();
} catch (InterruptedException | ExecutionException e) {
throw new IllegalStateException(e);
}
engineState = new EngineState(new EngineState.EngineStateListenerImpl() { engineState = new EngineState(new EngineState.EngineStateListenerImpl() {
@Override @Override
public void beforeLine(String fullLine) { public void beforeLine(String fullLine) {
@ -162,32 +174,12 @@ public class LinkManager implements Closeable {
COMMUNICATION_QUEUE, COMMUNICATION_QUEUE,
new NamedThreadFactory("communication executor")); new NamedThreadFactory("communication executor"));
static { public void assertCommunicationThread() {
/* if (Thread.currentThread() != communicationThread)
Future future = submit(new Runnable() { throw new IllegalStateException("Communication on wrong thread");
@Override
public void run() {
// WAT? this is hanging?!
COMMUNICATION_THREAD = Thread.currentThread();
System.out.println("Done");
}
});
try {
// let's wait for the above trivial task to finish
future.get();
System.out.println("Done2");
} catch (InterruptedException | ExecutionException e) {
throw new IllegalStateException(e);
}
*/
} }
public static void assertCommunicationThread() { private final EngineState engineState;
// if (Thread.currentThread() != COMMUNICATION_THREAD)
// throw new IllegalStateException("Communication on wrong thread");
}
private EngineState engineState;
public EngineState getEngineState() { public EngineState getEngineState() {
return engineState; return engineState;

View File

@ -6,7 +6,7 @@ import java.net.URL;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
public class rusEFIVersion { public class rusEFIVersion {
public static final int CONSOLE_VERSION = 20211021; public static final int CONSOLE_VERSION = 20211022;
public static AtomicReference<String> firmwareVersion = new AtomicReference<>("N/A"); public static AtomicReference<String> firmwareVersion = new AtomicReference<>("N/A");
public static long classBuildTimeMillis() { public static long classBuildTimeMillis() {

View File

@ -3,6 +3,7 @@ package com.rusefi.ui.lua;
import com.opensr5.ConfigurationImage; import com.opensr5.ConfigurationImage;
import com.rusefi.binaryprotocol.BinaryProtocol; import com.rusefi.binaryprotocol.BinaryProtocol;
import com.rusefi.config.generated.Fields; import com.rusefi.config.generated.Fields;
import com.rusefi.io.LinkManager;
import com.rusefi.ui.MessagesPanel; import com.rusefi.ui.MessagesPanel;
import com.rusefi.ui.UIContext; import com.rusefi.ui.UIContext;
import com.rusefi.ui.storage.Node; import com.rusefi.ui.storage.Node;
@ -120,32 +121,36 @@ public class LuaScriptPanel {
} }
void write() { void write() {
BinaryProtocol bp = this.context.getLinkManager().getCurrentStreamState();
String script = scriptText.getText(); String script = scriptText.getText();
byte[] paddedScript = new byte[Fields.LUA_SCRIPT_SIZE]; LinkManager linkManager = context.getLinkManager();
byte[] scriptBytes = script.getBytes(StandardCharsets.US_ASCII);
System.arraycopy(scriptBytes, 0, paddedScript, 0, scriptBytes.length);
int idx = 0; linkManager.submit(() -> {
int remaining; BinaryProtocol bp = linkManager.getCurrentStreamState();
do { byte[] paddedScript = new byte[Fields.LUA_SCRIPT_SIZE];
remaining = paddedScript.length - idx; byte[] scriptBytes = script.getBytes(StandardCharsets.US_ASCII);
int thisWrite = Math.min(remaining, Fields.BLOCKING_FACTOR); System.arraycopy(scriptBytes, 0, paddedScript, 0, scriptBytes.length);
bp.writeData(paddedScript, idx, Fields.luaScript_offset + idx, thisWrite); int idx = 0;
int remaining;
idx += thisWrite; do {
remaining = paddedScript.length - idx;
int thisWrite = Math.min(remaining, Fields.BLOCKING_FACTOR);
remaining -= thisWrite; bp.writeData(paddedScript, idx, Fields.luaScript_offset + idx, thisWrite);
} while (remaining > 0);
bp.burn(); idx += thisWrite;
// Burning doesn't reload lua script, so we have to do it manually remaining -= thisWrite;
resetLua(); } while (remaining > 0);
bp.burn();
// Burning doesn't reload lua script, so we have to do it manually
resetLua();
});
} }
void resetLua() { void resetLua() {