Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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: 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
166 changes: 88 additions & 78 deletions src/js/serial_backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,26 @@ function abortConnection() {
resetConnection();
}

// Centralized helper: show version mismatch warning and switch to CLI
function showVersionMismatchAndCli() {
const dialog = $(".dialogConnectWarning")[0];

$(".dialogConnectWarning-content").html(
i18n.getMessage("firmwareVersionNotSupported", [CONFIGURATOR.API_VERSION_ACCEPTED]),
);

$(".dialogConnectWarning-closebtn")
.off("click")
.on("click", function () {
dialog.close();
});

dialog.showModal();

console.log(`${logHead} Connecting to CLI`);
connectCli();
}

/**
* purpose of this is to bridge the old and new api
* when serial events are handled.
Expand Down Expand Up @@ -314,17 +334,29 @@ 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 () {
MSP.send_message(MSPCodes.MSP_API_VERSION, false, false, async function () {
gui_log(i18n.getMessage("apiVersionReceived", FC.CONFIG.apiVersion));

if (FC.CONFIG.apiVersion.includes("null")) {
abortConnection();
return;
}

// we should check for problems before proceeding
// as some problems may prevent further communication
const abort = await checkReportProblems();

// If checkReportProblems() already displayed its own dialog and indicates we should abort
// the normal flow (e.g. due to version incompatibility), do not open another modal here.
// Instead, switch to CLI to keep the app usable without double-modals.
if (abort) {
connectCli();
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,17 +375,7 @@ function onOpen(openInfo) {
});
});
} else {
const dialog = $(".dialogConnectWarning")[0];

$(".dialogConnectWarning-content").html(i18n.getMessage("firmwareTypeNotSupported"));

$(".dialogConnectWarning-closebtn").click(function () {
dialog.close();
});

dialog.showModal();

connectCli();
showVersionMismatchAndCli();
}
});
} else {
Expand All @@ -362,19 +384,7 @@ function onOpen(openInfo) {
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();
}
});
} else {
Expand Down Expand Up @@ -453,9 +463,7 @@ function processCustomDefaults() {
function processBoardInfo() {
gui_log(i18n.getMessage("boardInfoReceived", [FC.CONFIG.hardwareName, FC.CONFIG.boardVersion]));

if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
checkReportProblems();
} else {
if (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
processCustomDefaults();
}
}
Expand All @@ -468,66 +476,65 @@ function checkReportProblem(problemName, problems) {
return false;
}

function checkReportProblems() {
async function checkReportProblems() {
const problemItemTemplate = $("#dialogReportProblems-listItemTemplate");

MSP.send_message(MSPCodes.MSP_STATUS, false, false, function () {
let needsProblemReportingDialog = false;
const problemDialogList = $("#dialogReportProblems-list");
problemDialogList.empty();

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;
MSP.promise(MSPCodes.MSP_STATUS);
let needsProblemReportingDialog = false;
const problemDialogList = $("#dialogReportProblems-list");
problemDialogList.empty();

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;

abort = true;
GUI.timeout_remove("connecting"); // kill connecting timer
connectDisconnect(); // disconnect
}
abort = true;
}

if (!abort) {
// only check for problems if we are not already aborting
if (!abort) {
// only check for more problems if we are not already aborting
needsProblemReportingDialog =
checkReportProblem("MOTOR_PROTOCOL_DISABLED", problems) || needsProblemReportingDialog;

if (have_sensor(FC.CONFIG.activeSensors, "acc")) {
needsProblemReportingDialog =
checkReportProblem("MOTOR_PROTOCOL_DISABLED", problems) || needsProblemReportingDialog;
checkReportProblem("ACC_NEEDS_CALIBRATION", problems) || needsProblemReportingDialog;
}
}

if (have_sensor(FC.CONFIG.activeSensors, "acc")) {
needsProblemReportingDialog =
checkReportProblem("ACC_NEEDS_CALIBRATION", problems) || needsProblemReportingDialog;
}
if (needsProblemReportingDialog) {
for (const problem of problems) {
problemItemTemplate.clone().html(problem.description).appendTo(problemDialogList);
}

if (needsProblemReportingDialog) {
for (const problem of problems) {
problemItemTemplate.clone().html(problem.description).appendTo(problemDialogList);
}
const problemDialog = $("#dialogReportProblems")[0];
$("#dialogReportProblems-closebtn").click(function () {
problemDialog.close();
});

const problemDialog = $("#dialogReportProblems")[0];
$("#dialogReportProblems-closebtn").click(function () {
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();
}

if (!abort) {
// if we are not aborting, we can continue
processUid();
}
});
return abort;
}

async function processBuildConfiguration() {
Expand Down Expand Up @@ -634,6 +641,9 @@ function finishOpen() {
function connectCli() {
CONFIGURATOR.connectionValid = true; // making it possible to open the CLI tab
GUI.allowedTabs = ["cli"];
// do we need to cleanup MSP listeners here?
MSP.clearListeners();
MSP.disconnect_cleanup();
onConnect();
$("#tabs .tab_cli a").click();
}
Expand Down