hard requirement for console version match #4187

This commit is contained in:
rusefillc 2022-06-01 11:07:37 -04:00
parent fc81ef9ce5
commit a908d7bb79
10 changed files with 56 additions and 24 deletions

View File

@ -15,6 +15,7 @@ import com.rusefi.core.SensorCentral;
import com.rusefi.io.*;
import com.rusefi.io.commands.GetOutputsCommand;
import com.rusefi.io.commands.HelloCommand;
import com.rusefi.shared.FileUtil;
import com.rusefi.tune.xml.Msq;
import com.rusefi.ui.livedocs.LiveDocsRegistry;
import org.jetbrains.annotations.Nullable;
@ -164,21 +165,47 @@ public class BinaryProtocol {
*
* @return true if everything fine
*/
public boolean connectAndReadConfiguration(Arguments arguments, DataListener listener) {
public String connectAndReadConfiguration(Arguments arguments, DataListener listener) {
try {
signature = getSignature(stream);
log.info("Got " + signature + " signature");
SignatureHelper.downloadIfNotAvailable(SignatureHelper.getUrl(signature));
} catch (IOException e) {
return false;
return "Failed to read signature " + e;
}
String errorMessage = validateConfigVersion();
if (errorMessage != null)
return errorMessage;
readImage(arguments, Fields.TOTAL_CONFIG_SIZE);
if (isClosed)
return false;
return "Failed to read calibration";
startPullThread(listener);
binaryProtocolLogger.start();
return true;
return null;
}
/**
* @return null if everything is good, error message otherwise
*/
private String validateConfigVersion() {
int requestSize = 4;
byte[] packet = GetOutputsCommand.createRequest(TS_FILE_VERSION_OFFSET, requestSize);
String msg = "load TS_CONFIG_VERSION";
byte[] response = executeCommand(Fields.TS_OUTPUT_COMMAND, packet, msg);
if (!checkResponseCode(response, (byte) Fields.TS_RESPONSE_OK) || response.length != requestSize + 1) {
close();
return "Failed to " + msg;
}
int actualVersion = FileUtil.littleEndianWrap(response, 1, requestSize).getInt();
if (actualVersion != TS_FILE_VERSION) {
log.error("Got TS_CONFIG_VERSION " + actualVersion);
return "Incompatible firmware format=" + actualVersion + " while format " + TS_FILE_VERSION + " expected";
}
return null;
}
private void startPullThread(final DataListener textListener) {
@ -310,6 +337,7 @@ public class BinaryProtocol {
String code = (response == null || response.length == 0) ? "empty" : "ERROR_CODE=" + getCode(response);
String info = response == null ? "NO RESPONSE" : (code + " length=" + response.length);
log.info("readImage: ERROR UNEXPECTED Something is wrong, retrying... " + info);
// todo: looks like forever retry? that's weird
continue;
}

View File

@ -6,6 +6,6 @@ public class AbstractConnectionStateListener implements ConnectionStateListener
}
@Override
public void onConnectionFailed() {
public void onConnectionFailed(String s) {
}
}

View File

@ -1,5 +1,5 @@
package com.rusefi.io;
public interface ConnectionFailedListener {
void onConnectionFailed();
void onConnectionFailed(String s);
}

View File

@ -95,7 +95,7 @@ public class LinkManager implements Closeable {
startAndConnect(port, new ConnectionStateListener() {
@Override
public void onConnectionFailed() {
public void onConnectionFailed(String s) {
IoUtils.exit("CONNECTION FAILED, did you specify the right port name?", -1);
}
@ -246,7 +246,7 @@ public class LinkManager implements Closeable {
try {
return TcpIoStream.open(port);
} catch (Throwable e) {
stateListener.onConnectionFailed();
stateListener.onConnectionFailed("Error " + e);
return null;
}
}

View File

@ -40,26 +40,28 @@ public class PortHolder {
this.ioStreamFactory = ioStreamFactory;
}
boolean connectAndReadConfiguration(BinaryProtocol.Arguments arguments) {
/**
* @return true if OK, false if error
*/
void connectAndReadConfiguration(BinaryProtocol.Arguments arguments) {
IoStream stream = ioStreamFactory.call();
if (stream == null) {
// error already reported
return false;
return;
}
synchronized (portLock) {
bp = new BinaryProtocol(linkManager, stream);
portLock.notifyAll();
}
boolean result = bp.connectAndReadConfiguration( arguments, dataListener);
String errorMessage = bp.connectAndReadConfiguration(arguments, dataListener);
if (listener != null) {
if (result) {
if (errorMessage == null) {
listener.onConnectionEstablished();
} else {
listener.onConnectionFailed();
listener.onConnectionFailed(errorMessage);
}
}
return result;
}
public void close() {

View File

@ -48,7 +48,7 @@ public class SandboxCommon {
}
@Override
public void onConnectionFailed() {
public void onConnectionFailed(String s) {
log.info("onConnectionFailed");
}
});

View File

@ -263,7 +263,7 @@ public class ConsoleTools {
}
@Override
public void onConnectionFailed() {
public void onConnectionFailed(String s) {
}
});

View File

@ -57,7 +57,7 @@ public class MainFrame {
this.consoleUI = Objects.requireNonNull(consoleUI);
this.tabbedPane = tabbedPane;
listener = () -> {
listener = (String s) -> {
};
}
@ -78,7 +78,11 @@ public class MainFrame {
final LinkManager linkManager = consoleUI.uiContext.getLinkManager();
linkManager.getConnector().connectAndReadConfiguration(new BinaryProtocol.Arguments(true), new ConnectionStateListener() {
@Override
public void onConnectionFailed() {
public void onConnectionFailed(String errorMessage) {
log.error("onConnectionFailed " + errorMessage);
String message = "This copy of rusEFI console is not compatible with this version of firmware\r\n" +
errorMessage;
JOptionPane.showMessageDialog(frame.getFrame(), message);
}
@Override

View File

@ -25,7 +25,6 @@ import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static com.devexperts.logging.Logging.getLogging;
import static com.rusefi.TestHelper.*;
@ -141,7 +140,7 @@ public class FullServerTest {
}
@Override
public void onConnectionFailed() {
public void onConnectionFailed(String s) {
System.out.println("Failed");
}
});

View File

@ -1,7 +1,6 @@
package com.rusefi.io;
import com.opensr5.ConfigurationImage;
import com.opensr5.Logger;
import com.opensr5.ini.field.ScalarIniField;
import com.rusefi.TestHelper;
import com.rusefi.binaryprotocol.BinaryProtocol;
@ -35,7 +34,7 @@ public class TcpCommunicationIntegrationTest {
}
@Override
public void onConnectionFailed() {
public void onConnectionFailed(String s) {
System.out.println("onConnectionFailed");
failedCountDownLatch.countDown();
}
@ -65,7 +64,7 @@ public class TcpCommunicationIntegrationTest {
}
@Override
public void onConnectionFailed() {
public void onConnectionFailed(String s) {
System.out.println("Failed");
}
});
@ -108,7 +107,7 @@ public class TcpCommunicationIntegrationTest {
}
@Override
public void onConnectionFailed() {
public void onConnectionFailed(String s) {
System.out.println("Failed");
}
});