read `MCUSERIAL` output channel from ECU
This commit is contained in:
parent
e0b961e8ca
commit
6d44596476
|
@ -0,0 +1,64 @@
|
|||
package com.rusefi.maintenance;
|
||||
|
||||
import com.devexperts.logging.Logging;
|
||||
import com.opensr5.ini.field.IniField;
|
||||
import com.rusefi.SerialPortScanner;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocol;
|
||||
import com.rusefi.core.SensorCentral;
|
||||
import com.rusefi.io.UpdateOperationCallbacks;
|
||||
import com.rusefi.panama.PanamaHelper;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static com.devexperts.logging.Logging.getLogging;
|
||||
|
||||
public class OutputChannelsHelper {
|
||||
private static final Logging log = getLogging(OutputChannelsHelper.class);
|
||||
|
||||
public static Optional<Integer> readMcuSerial(
|
||||
final SerialPortScanner.PortResult ecuPort,
|
||||
final UpdateOperationCallbacks callbacks
|
||||
) {
|
||||
return BinaryProtocolExecutor.executeWithSuspendedPortScanner(
|
||||
ecuPort.port,
|
||||
callbacks,
|
||||
(binaryProtocol) -> {
|
||||
try {
|
||||
return readMcuSerial(binaryProtocol, callbacks);
|
||||
} catch (final Exception e) {
|
||||
log.error("Reading `MCUSERIAL` output channel failed:", e);
|
||||
callbacks.logLine("Reading `MCUSERIAL` output channel failed");
|
||||
return Optional.empty();
|
||||
}
|
||||
},
|
||||
Optional.empty(),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
private static Optional<Integer> readMcuSerial(
|
||||
final BinaryProtocol binaryProtocol,
|
||||
final UpdateOperationCallbacks callbacks
|
||||
) {
|
||||
callbacks.logLine("Reading `MCUSERIAL` output channel...");
|
||||
Optional<Integer> result = Optional.empty();
|
||||
final IniField mcuSerialField = PanamaHelper.getIniField(binaryProtocol);
|
||||
if (mcuSerialField != null) {
|
||||
final AtomicInteger mcuSerial = new AtomicInteger();
|
||||
SensorCentral.getInstance().addListener(() -> {
|
||||
mcuSerial.set(PanamaHelper.getMcuSerial(mcuSerialField));
|
||||
});
|
||||
if (binaryProtocol.requestOutputChannels()) {
|
||||
callbacks.logLine(String.format("`MCUSERIAL` is %d", mcuSerial.get()));
|
||||
result = Optional.of(mcuSerial.get());
|
||||
} else {
|
||||
callbacks.logLine("Failed to request output channels...");
|
||||
}
|
||||
} else {
|
||||
callbacks.logLine("Please update firmware to use this feature...");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
package com.rusefi.maintenance;
|
||||
|
||||
import com.opensr5.ini.field.IniField;
|
||||
import com.rusefi.SerialPortScanner;
|
||||
import com.rusefi.binaryprotocol.BinaryProtocolLocalCache;
|
||||
import com.rusefi.config.generated.TsOutputs;
|
||||
import com.rusefi.io.UpdateOperationCallbacks;
|
||||
import com.rusefi.panama.PanamaClient;
|
||||
import com.rusefi.ui.basic.InstanceNameEditor;
|
||||
|
@ -39,13 +41,12 @@ public enum TuneUploader {
|
|||
return false;
|
||||
}
|
||||
|
||||
// todo!
|
||||
// IniField mcuSerialField = PanamaHelper.getIniField(linkManager);
|
||||
// if (mcuSerialField == null) {
|
||||
// addMessage("Please update firmware to use this feature");
|
||||
// return;
|
||||
// }
|
||||
int mcuSerial = 1231234; // todo
|
||||
final Optional<Integer> receivedMcuSerial = OutputChannelsHelper.readMcuSerial(ecuPort, callbacks);
|
||||
if (!receivedMcuSerial.isPresent()) {
|
||||
callbacks.logLine("Failed to read `MCUSERIAL` output channel");
|
||||
return false;
|
||||
}
|
||||
final int mcuSerial = receivedMcuSerial.get();
|
||||
|
||||
final String calibrationsToUploadFileName = CALIBRATIONS_TO_UPLOAD_FILE_NAME + ".msq";
|
||||
if (PanamaClient.uploadFile(panamaUrl,
|
||||
|
@ -54,18 +55,20 @@ public enum TuneUploader {
|
|||
mcuSerial
|
||||
)) {
|
||||
callbacks.logLine(String.format(
|
||||
"File `%s` is successfully uploaded to `%s` for `%s`",
|
||||
"File `%s` is successfully uploaded to `%s` for `%s` (MCUSERIAL=%d)",
|
||||
calibrationsToUploadFileName,
|
||||
panamaUrl,
|
||||
instanceName
|
||||
instanceName,
|
||||
mcuSerial
|
||||
));
|
||||
result = true;
|
||||
} else {
|
||||
callbacks.logLine(String.format(
|
||||
"Failed to upload file `%s` to `%s` for `%s`",
|
||||
"Failed to upload file `%s` to `%s` for `%s` (MCUSERIAL=%d)",
|
||||
calibrationsToUploadFileName,
|
||||
panamaUrl,
|
||||
instanceName
|
||||
instanceName,
|
||||
mcuSerial
|
||||
));
|
||||
}
|
||||
return result;
|
||||
|
|
Loading…
Reference in New Issue