Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 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
3 changes: 3 additions & 0 deletions locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,9 @@
"firmwareUpgradeRequired": {
"message": "The firmware on this device needs upgrading to a newer version. Use CLI for backup before flashing. CLI backup/restore procedure is in the documentation.<br />Alternatively download and use an old version of the app if you are not ready to upgrade."
},
"firmwareVersionNotYetSupported": {
"message": "This firmware version ($1) is <span class=\"message-negative\">not yet supported</span>."
},
"resetToCustomDefaultsDialog": {
"message": "There are custom defaults for this board available. Normally, a board will not work properly unless custom defaults are applied.<br />Do you want to apply the custom defaults for this board?"
},
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_48,

connectionValid: false,
connectionValidCliOnly: false,
Expand Down
141 changes: 60 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,18 @@ 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("firmwareVersionNotYetSupported", [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 +367,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 +467,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 +609,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