rusEFI console bug while Lua with simulator fix #3387
This commit is contained in:
parent
478a25d0b4
commit
3fe486e191
|
@ -467,7 +467,7 @@ public class BinaryProtocol {
|
|||
if (isClosed)
|
||||
return null;
|
||||
try {
|
||||
LinkManager.assertCommunicationThread();
|
||||
linkManager.assertCommunicationThread();
|
||||
dropPending();
|
||||
|
||||
sendPacket(packet);
|
||||
|
|
|
@ -53,8 +53,20 @@ public class LinkManager implements Closeable {
|
|||
System.out.println(source + ": " + message);
|
||||
}
|
||||
};
|
||||
private Thread communicationThread;
|
||||
|
||||
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() {
|
||||
@Override
|
||||
public void beforeLine(String fullLine) {
|
||||
|
@ -162,32 +174,12 @@ public class LinkManager implements Closeable {
|
|||
COMMUNICATION_QUEUE,
|
||||
new NamedThreadFactory("communication executor"));
|
||||
|
||||
static {
|
||||
/*
|
||||
Future future = submit(new Runnable() {
|
||||
@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 void assertCommunicationThread() {
|
||||
if (Thread.currentThread() != communicationThread)
|
||||
throw new IllegalStateException("Communication on wrong thread");
|
||||
}
|
||||
|
||||
public static void assertCommunicationThread() {
|
||||
// if (Thread.currentThread() != COMMUNICATION_THREAD)
|
||||
// throw new IllegalStateException("Communication on wrong thread");
|
||||
}
|
||||
|
||||
private EngineState engineState;
|
||||
private final EngineState engineState;
|
||||
|
||||
public EngineState getEngineState() {
|
||||
return engineState;
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.net.URL;
|
|||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
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 long classBuildTimeMillis() {
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.rusefi.ui.lua;
|
|||
import com.opensr5.ConfigurationImage;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.io.LinkManager;
|
||||
import com.rusefi.ui.MessagesPanel;
|
||||
import com.rusefi.ui.UIContext;
|
||||
import com.rusefi.ui.storage.Node;
|
||||
|
@ -120,32 +121,36 @@ public class LuaScriptPanel {
|
|||
}
|
||||
|
||||
void write() {
|
||||
BinaryProtocol bp = this.context.getLinkManager().getCurrentStreamState();
|
||||
|
||||
String script = scriptText.getText();
|
||||
|
||||
byte[] paddedScript = new byte[Fields.LUA_SCRIPT_SIZE];
|
||||
byte[] scriptBytes = script.getBytes(StandardCharsets.US_ASCII);
|
||||
System.arraycopy(scriptBytes, 0, paddedScript, 0, scriptBytes.length);
|
||||
LinkManager linkManager = context.getLinkManager();
|
||||
|
||||
int idx = 0;
|
||||
int remaining;
|
||||
linkManager.submit(() -> {
|
||||
BinaryProtocol bp = linkManager.getCurrentStreamState();
|
||||
|
||||
do {
|
||||
remaining = paddedScript.length - idx;
|
||||
int thisWrite = Math.min(remaining, Fields.BLOCKING_FACTOR);
|
||||
byte[] paddedScript = new byte[Fields.LUA_SCRIPT_SIZE];
|
||||
byte[] scriptBytes = script.getBytes(StandardCharsets.US_ASCII);
|
||||
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;
|
||||
} while (remaining > 0);
|
||||
bp.writeData(paddedScript, idx, Fields.luaScript_offset + idx, thisWrite);
|
||||
|
||||
bp.burn();
|
||||
idx += thisWrite;
|
||||
|
||||
// Burning doesn't reload lua script, so we have to do it manually
|
||||
resetLua();
|
||||
remaining -= thisWrite;
|
||||
} while (remaining > 0);
|
||||
|
||||
bp.burn();
|
||||
|
||||
// Burning doesn't reload lua script, so we have to do it manually
|
||||
resetLua();
|
||||
});
|
||||
}
|
||||
|
||||
void resetLua() {
|
||||
|
|
Loading…
Reference in New Issue