new command line tool: write_tune
This commit is contained in:
parent
7e646d74d9
commit
0da161f83e
|
@ -1,7 +1,6 @@
|
|||
package com.rusefi;
|
||||
|
||||
|
||||
import com.opensr5.Logger;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.config.generated.Fields;
|
||||
import com.rusefi.core.MessagesCentral;
|
||||
|
@ -55,7 +54,7 @@ public class AutoTest {
|
|||
|
||||
BinaryProtocol bp = linkManager.getCurrentStreamState();
|
||||
// let's make sure 'burn' command works since sometimes it does not
|
||||
bp.burn(Logger.CONSOLE);
|
||||
bp.burn();
|
||||
|
||||
sendCommand(getDisableCommand(Fields.CMD_TRIGGER_HW_INPUT));
|
||||
sendCommand(getEnableCommand(Fields.CMD_FUNCTIONAL_TEST_MODE));
|
||||
|
|
|
@ -13,5 +13,6 @@
|
|||
<orderEntry type="module" module-name="autoupdate" exported="" />
|
||||
<orderEntry type="library" exported="" name="annotations" level="project" />
|
||||
<orderEntry type="module" module-name="shared_io" exported="" />
|
||||
<orderEntry type="module" module-name="logging-api" />
|
||||
</component>
|
||||
</module>
|
|
@ -1,5 +1,6 @@
|
|||
package com.rusefi.tune.xml;
|
||||
|
||||
import com.devexperts.logging.Logging;
|
||||
import com.opensr5.ConfigurationImage;
|
||||
import com.opensr5.ini.IniFileModel;
|
||||
import com.opensr5.ini.field.IniField;
|
||||
|
@ -15,6 +16,7 @@ import java.util.Objects;
|
|||
|
||||
@XmlRootElement
|
||||
public class Msq {
|
||||
private static final Logging log = Logging.getLogging(Msq.class);
|
||||
|
||||
public List<Page> page = new ArrayList<>();
|
||||
|
||||
|
@ -56,7 +58,7 @@ public class Msq {
|
|||
}
|
||||
IniField field = instance.allIniFields.get(constant.getName());
|
||||
Objects.requireNonNull(field, "Field for " + constant.getName());
|
||||
System.out.println("Setting " + field);
|
||||
log.debug("Setting " + field);
|
||||
field.setValue(ci, constant);
|
||||
}
|
||||
return ci;
|
||||
|
|
|
@ -287,7 +287,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
|||
}
|
||||
}
|
||||
|
||||
public void uploadChanges(ConfigurationImage newVersion, Logger logger) throws InterruptedException, EOFException {
|
||||
public void uploadChanges(ConfigurationImage newVersion) {
|
||||
ConfigurationImage current = getControllerConfiguration();
|
||||
// let's have our own copy which no one would be able to change
|
||||
newVersion = newVersion.clone();
|
||||
|
@ -297,18 +297,18 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
|||
if (range == null)
|
||||
break;
|
||||
int size = range.second - range.first;
|
||||
logger.info("Need to patch: " + range + ", size=" + size);
|
||||
log.info("Need to patch: " + range + ", size=" + size);
|
||||
byte[] oldBytes = current.getRange(range.first, size);
|
||||
logger.info("old " + Arrays.toString(oldBytes));
|
||||
log.info("old " + Arrays.toString(oldBytes));
|
||||
|
||||
byte[] newBytes = newVersion.getRange(range.first, size);
|
||||
logger.info("new " + Arrays.toString(newBytes));
|
||||
log.info("new " + Arrays.toString(newBytes));
|
||||
|
||||
writeData(newVersion.getContent(), range.first, size, logger);
|
||||
writeData(newVersion.getContent(), range.first, size);
|
||||
|
||||
offset = range.second;
|
||||
}
|
||||
burn(logger);
|
||||
burn();
|
||||
setController(newVersion);
|
||||
}
|
||||
|
||||
|
@ -451,10 +451,10 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
|||
Runtime.getRuntime().removeShutdownHook(hook);
|
||||
}
|
||||
|
||||
public void writeData(byte[] content, Integer offset, int size, Logger logger) {
|
||||
public void writeData(byte[] content, Integer offset, int size) {
|
||||
if (size > BLOCKING_FACTOR) {
|
||||
writeData(content, offset, BLOCKING_FACTOR, logger);
|
||||
writeData(content, offset + BLOCKING_FACTOR, size - BLOCKING_FACTOR, logger);
|
||||
writeData(content, offset, BLOCKING_FACTOR);
|
||||
writeData(content, offset + BLOCKING_FACTOR, size - BLOCKING_FACTOR);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -472,17 +472,17 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
|||
while (!isClosed && (System.currentTimeMillis() - start < Timeouts.BINARY_IO_TIMEOUT)) {
|
||||
byte[] response = executeCommand(packet, "writeImage");
|
||||
if (!checkResponseCode(response, RESPONSE_OK) || response.length != 1) {
|
||||
logger.error("writeData: Something is wrong, retrying...");
|
||||
log.error("writeData: Something is wrong, retrying...");
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void burn(Logger logger) {
|
||||
public void burn() {
|
||||
if (!isBurnPending)
|
||||
return;
|
||||
logger.info("Need to burn");
|
||||
log.info("Need to burn");
|
||||
|
||||
while (true) {
|
||||
if (isClosed)
|
||||
|
@ -493,7 +493,7 @@ public class BinaryProtocol implements BinaryProtocolCommands {
|
|||
}
|
||||
break;
|
||||
}
|
||||
logger.info("DONE");
|
||||
log.info("DONE");
|
||||
isBurnPending = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
package com.rusefi;
|
||||
|
||||
import com.opensr5.ConfigurationImage;
|
||||
import com.opensr5.Logger;
|
||||
import com.rusefi.ui.StatusWindow;
|
||||
import com.rusefi.ui.UIContext;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
|
@ -80,20 +78,14 @@ public class UploadChanges {
|
|||
public static void scheduleUpload(UIContext uiContext, final ConfigurationImage newVersion, final Runnable afterUpload) {
|
||||
if (1 == 1)
|
||||
throw new UnsupportedOperationException("disabled");
|
||||
Logger logger = null;
|
||||
JFrame frame = null;//wnd.getFrame();
|
||||
frame.setVisible(true);
|
||||
uiContext.getLinkManager().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
uiContext.getLinkManager().getCurrentStreamState().uploadChanges(newVersion, logger);
|
||||
if (afterUpload != null)
|
||||
afterUpload.run();
|
||||
} catch (InterruptedException | EOFException e) {
|
||||
logger.error("Error: " + e);
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
uiContext.getLinkManager().getCurrentStreamState().uploadChanges(newVersion);
|
||||
if (afterUpload != null)
|
||||
afterUpload.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -68,7 +68,8 @@ public class ConsoleTools {
|
|||
registerTool(SET_AUTH_TOKEN, ConsoleTools::setAuthToken, "Set rusEFI authentication token.");
|
||||
registerTool("upload_tune", ConsoleTools::uploadTune, "Upload specified tune file to rusEFI Online using auth token from settings");
|
||||
|
||||
registerTool("read_tune", strings1 -> readTune(), "Read tune from controller");
|
||||
registerTool("read_tune", args -> readTune(), "Read tune from controller");
|
||||
registerTool("write_tune", ConsoleTools::writeTune, "Write specified XML tune into controller");
|
||||
|
||||
registerTool("version", ConsoleTools::version, "Only print version");
|
||||
|
||||
|
@ -238,6 +239,25 @@ public class ConsoleTools {
|
|||
});
|
||||
}
|
||||
|
||||
private static void writeTune(String[] args) throws Exception {
|
||||
if (args.length < 2) {
|
||||
System.out.println("No tune file name specified");
|
||||
return;
|
||||
}
|
||||
|
||||
String fileName = args[1];
|
||||
Msq msq = Msq.readTune(fileName);
|
||||
|
||||
startAndConnect(linkManager -> {
|
||||
ConfigurationImage ci = msq.asImage(IniFileModel.getInstance(), Fields.TOTAL_CONFIG_SIZE);
|
||||
linkManager.getConnector().getBinaryProtocol().uploadChanges(ci);
|
||||
|
||||
//System.exit(0);
|
||||
return null;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private static void invokeCallback(String callback) {
|
||||
if (callback == null)
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue