Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@
"message": "<span class=\"message-negative\"><strong>You need to fix these problems before attempting to fly your aircraft</span></strong>."
},
"reportProblemsDialogAPI_VERSION_MAX_SUPPORTED": {
"message": "<span class=\"message-negative\"><strong>The app version used ($3) does not support firmware $4</strong></span>.<br>$t(configuratorUpdateHelp.message)"
"message": "<span class=\"message-negative\"><strong>The app version used ($1) does not support firmware $2</strong></span>.<br>$t(configuratorUpdateHelp.message)"
},
"reportProblemsDialogMOTOR_PROTOCOL_DISABLED": {
"message": "<strong>there is no motor output protocol selected</strong>.<br>Please select a motor output protocol appropriate for your ESCs in '$t(configurationEscFeatures.message)' on the '$t(tabMotorTesting.message)' tab.<br>$t(escProtocolDisabledMessage.message)"
Expand Down
3 changes: 2 additions & 1 deletion src/js/data_storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_46,

connectionValid: false,
connectionValidCliOnly: false,
Expand Down
144 changes: 63 additions & 81 deletions src/js/serial_backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 () {
Expand All @@ -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") {
Expand All @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
}
Expand Down