diff --git a/locales/en/messages.json b/locales/en/messages.json index ed06eae027..03e3271bab 100755 --- a/locales/en/messages.json +++ b/locales/en/messages.json @@ -595,7 +595,7 @@ "message": "You need to fix these problems before attempting to fly your aircraft." }, "reportProblemsDialogAPI_VERSION_MAX_SUPPORTED": { - "message": "The app version used ($3) does not support firmware $4.
$t(configuratorUpdateHelp.message)" + "message": "The app version used ($1) does not support firmware $2.
$t(configuratorUpdateHelp.message)" }, "reportProblemsDialogMOTOR_PROTOCOL_DISABLED": { "message": "there is no motor output protocol selected.
Please select a motor output protocol appropriate for your ESCs in '$t(configurationEscFeatures.message)' on the '$t(tabMotorTesting.message)' tab.
$t(escProtocolDisabledMessage.message)" diff --git a/src/js/data_storage.js b/src/js/data_storage.js index 5b8cdc78e8..7f44eb903f 100644 --- a/src/js/data_storage.js +++ b/src/js/data_storage.js @@ -3,11 +3,12 @@ export const API_VERSION_1_44 = "1.44.0"; export const API_VERSION_1_45 = "1.45.0"; export const API_VERSION_1_46 = "1.46.0"; export const API_VERSION_1_47 = "1.47.0"; +export const API_VERSION_1_48 = "1.48.0"; const CONFIGURATOR = { // all versions are specified and compared using semantic versioning http://semver.org/ API_VERSION_ACCEPTED: API_VERSION_1_44, - API_VERSION_MAX_SUPPORTED: API_VERSION_1_47, + API_VERSION_MAX_SUPPORTED: API_VERSION_1_48, connectionValid: false, connectionValidCliOnly: false, diff --git a/src/js/serial_backend.js b/src/js/serial_backend.js index a737853e68..89367c8259 100644 --- a/src/js/serial_backend.js +++ b/src/js/serial_backend.js @@ -282,6 +282,18 @@ function abortConnection() { resetConnection(); } +// Centralized helper: show version mismatch warning and switch to CLI +function showVersionMismatchAndCli(message) { + const dialog = $(".dialogConnectWarning")[0]; + + $(".dialogConnectWarning-content").html(message); + $(".dialogConnectWarning-closebtn").one("click", () => dialog.close()); + + dialog.showModal(); + + connectCli(); +} + /** * purpose of this is to bridge the old and new api * when serial events are handled. @@ -314,7 +326,7 @@ function onOpen(openInfo) { FC.resetState(); mspHelper = new MspHelper(); MSP.listen(mspHelper.process_data.bind(mspHelper)); - MSP.timeout = 250; + console.log(`${logHead} Requesting configuration data`); MSP.send_message(MSPCodes.MSP_API_VERSION, false, false, function () { @@ -325,6 +337,21 @@ function onOpen(openInfo) { return; } + if ( + !semver.satisfies( + FC.CONFIG.apiVersion, + `<=${semver.major(CONFIGURATOR.API_VERSION_MAX_SUPPORTED)}.${semver.minor(CONFIGURATOR.API_VERSION_MAX_SUPPORTED)}`, + ) + ) { + showVersionMismatchAndCli( + i18n.getMessage("reportProblemsDialogAPI_VERSION_MAX_SUPPORTED", [ + CONFIGURATOR.getDisplayVersion(), + CONFIGURATOR.API_VERSION_MAX_SUPPORTED, + ]), + ); + return; + } + if (semver.gte(FC.CONFIG.apiVersion, CONFIGURATOR.API_VERSION_ACCEPTED)) { MSP.send_message(MSPCodes.MSP_FC_VARIANT, false, false, function () { if (FC.CONFIG.flightControllerIdentifier === "BTFL") { @@ -343,38 +370,13 @@ function onOpen(openInfo) { }); }); } else { - const dialog = $(".dialogConnectWarning")[0]; - - $(".dialogConnectWarning-content").html(i18n.getMessage("firmwareTypeNotSupported")); - - $(".dialogConnectWarning-closebtn").click(function () { - dialog.close(); - }); - - dialog.showModal(); - - connectCli(); + showVersionMismatchAndCli( + i18n.getMessage("firmwareTypeNotSupported", [CONFIGURATOR.API_VERSION_ACCEPTED]), + ); } }); } else { - if (!serial.connected) { - abortConnection(); - return; - } - - const dialog = $(".dialogConnectWarning")[0]; - - $(".dialogConnectWarning-content").html( - i18n.getMessage("firmwareVersionNotSupported", [CONFIGURATOR.API_VERSION_ACCEPTED]), - ); - - $(".dialogConnectWarning-closebtn").click(function () { - dialog.close(); - }); - - dialog.showModal(); - - connectCli(); + showVersionMismatchAndCli(i18n.getMessage("firmwareUpgradeRequired")); } }); } else { @@ -468,66 +470,42 @@ function checkReportProblem(problemName, problems) { return false; } -function checkReportProblems() { - const problemItemTemplate = $("#dialogReportProblems-listItemTemplate"); +async function checkReportProblems() { + await MSP.promise(MSPCodes.MSP_STATUS); - MSP.send_message(MSPCodes.MSP_STATUS, false, false, function () { - let needsProblemReportingDialog = false; - const problemDialogList = $("#dialogReportProblems-list"); - problemDialogList.empty(); + let needsProblemReportingDialog = false; + let problems = []; - let problems = []; - let abort = false; - - if (semver.minor(FC.CONFIG.apiVersion) > semver.minor(CONFIGURATOR.API_VERSION_MAX_SUPPORTED)) { - const problemName = "API_VERSION_MAX_SUPPORTED"; - problems.push({ - name: problemName, - description: i18n.getMessage(`reportProblemsDialog${problemName}`, [ - CONFIGURATOR.latestVersion, - CONFIGURATOR.latestVersionReleaseUrl, - CONFIGURATOR.getDisplayVersion(), - FC.CONFIG.flightControllerVersion, - ]), - }); - needsProblemReportingDialog = true; + // only check for more problems if we are not already aborting + needsProblemReportingDialog = + checkReportProblem("MOTOR_PROTOCOL_DISABLED", problems) || needsProblemReportingDialog; - abort = true; - GUI.timeout_remove("connecting"); // kill connecting timer - connectDisconnect(); // disconnect - } + if (have_sensor(FC.CONFIG.activeSensors, "acc")) { + needsProblemReportingDialog = + checkReportProblem("ACC_NEEDS_CALIBRATION", problems) || needsProblemReportingDialog; + } - if (!abort) { - // only check for problems if we are not already aborting - needsProblemReportingDialog = - checkReportProblem("MOTOR_PROTOCOL_DISABLED", problems) || needsProblemReportingDialog; + if (needsProblemReportingDialog) { + const problemItemTemplate = $("#dialogReportProblems-listItemTemplate"); + const problemDialogList = $("#dialogReportProblems-list"); - if (have_sensor(FC.CONFIG.activeSensors, "acc")) { - needsProblemReportingDialog = - checkReportProblem("ACC_NEEDS_CALIBRATION", problems) || needsProblemReportingDialog; - } - } + problemDialogList.empty(); - if (needsProblemReportingDialog) { - for (const problem of problems) { - problemItemTemplate.clone().html(problem.description).appendTo(problemDialogList); - } + for (const problem of problems) { + problemItemTemplate.clone().prop("id", null).html(problem.description).appendTo(problemDialogList); + } - const problemDialog = $("#dialogReportProblems")[0]; - $("#dialogReportProblems-closebtn").click(function () { - problemDialog.close(); - }); + const problemDialog = $("#dialogReportProblems")[0]; + $("#dialogReportProblems-closebtn") + .off("click") + .one("click", () => problemDialog.close()); - problemDialog.showModal(); - $("#dialogReportProblems").scrollTop(0); - $("#dialogReportProblems-closebtn").focus(); - } + problemDialog.showModal(); + $("#dialogReportProblems").scrollTop(0); + $("#dialogReportProblems-closebtn").focus(); + } - if (!abort) { - // if we are not aborting, we can continue - processUid(); - } - }); + processUid(); } async function processBuildConfiguration() { @@ -634,6 +612,10 @@ function finishOpen() { function connectCli() { CONFIGURATOR.connectionValid = true; // making it possible to open the CLI tab GUI.allowedTabs = ["cli"]; + + MSP.clearListeners(); + MSP.disconnect_cleanup(); + onConnect(); $("#tabs .tab_cli a").click(); }