Skip to content

Commit

Permalink
Use firmware options on introduction (#3900)
Browse files Browse the repository at this point in the history
* Use firmware options

* Enable telemetry for CRSF, GHST and FPORT

* Add supported date

* Only add telemetry when not included in firmware

* Reduce brain overload
  • Loading branch information
haslinghuis committed Apr 20, 2024
1 parent 16f70a5 commit 37fada1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
14 changes: 13 additions & 1 deletion src/js/Features.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bit_check, bit_set, bit_clear } from "./bit";
import { API_VERSION_1_44, API_VERSION_1_45 } from './data_storage';
import { API_VERSION_1_44, API_VERSION_1_45, API_VERSION_1_46 } from './data_storage';
import semver from "semver";
import { tracking } from "./Analytics";
import $ from 'jquery';
Expand Down Expand Up @@ -51,6 +51,18 @@ const Features = function (config) {
}
}

// Add TELEMETRY feature if any of the following protocols are used: CRSF, GHST, FPORT
if (semver.gte(config.apiVersion, API_VERSION_1_46)) {
let enableTelemetry = false;
if (config.buildOptions.some(opt => opt.includes('CRSF') || opt.includes('GHST') || opt.includes('FPORT'))) {
enableTelemetry = true;
}

if (enableTelemetry) {
self._features.push({bit: 10, group: 'telemetry', name: 'TELEMETRY', haveTip: true, dependsOn: 'TELEMETRY'});
}
}

self._features.sort((a, b) => a.name.localeCompare(b.name, window.navigator.language, { ignorePunctuation: true }));
self._featureMask = 0;

Expand Down
4 changes: 2 additions & 2 deletions src/js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import semver from 'semver';
import vtxDeviceStatusFactory from "../utils/VtxDeviceStatus/VtxDeviceStatusFactory";
import MSP from "../msp";
import MSPCodes from "./MSPCodes";
import { API_VERSION_1_42, API_VERSION_1_43, API_VERSION_1_44, API_VERSION_1_45, API_VERSION_1_46, API_VERSION_1_47 } from '../data_storage';
import { API_VERSION_1_42, API_VERSION_1_43, API_VERSION_1_44, API_VERSION_1_45, API_VERSION_1_46 } from '../data_storage';
import EscProtocols from "../utils/EscProtocols";
import huffmanDecodeBuf from "../huffman";
import { defaultHuffmanTree, defaultHuffmanLenIndex } from "../default_huffman_tree";
Expand Down Expand Up @@ -795,7 +795,7 @@ MspHelper.prototype.process_data = function(dataHandler) {
FC.CONFIG.gitRevision = String.fromCharCode.apply(null, buff);
console.log("Fw git rev:", FC.CONFIG.gitRevision);

if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_47)) {
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
let option = data.readU16();
while (option) {
FC.CONFIG.buildOptions.push(option);
Expand Down
6 changes: 3 additions & 3 deletions src/js/serial_backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import MSP from "./msp";
import MSPCodes from "./msp/MSPCodes";
import PortUsage from "./port_usage";
import PortHandler from "./port_handler";
import CONFIGURATOR, { API_VERSION_1_45, API_VERSION_1_46, API_VERSION_1_47 } from "./data_storage";
import CONFIGURATOR, { API_VERSION_1_45, API_VERSION_1_46 } from "./data_storage";
import UI_PHONES from "./phones_ui";
import { bit_check } from './bit.js';
import { sensor_status, have_sensor } from "./sensor_helpers";
Expand Down Expand Up @@ -353,7 +353,7 @@ function onOpen(openInfo) {
gui_log(i18n.getMessage('buildInfoReceived', [FC.CONFIG.buildInfo]));

// retrieve build options from the flight controller
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_47)) {
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
FC.processBuildOptions();
}

Expand Down Expand Up @@ -540,7 +540,7 @@ function checkReportProblems() {
}

async function processBuildOptions() {
const supported = semver.satisfies(FC.CONFIG.apiVersion, `${API_VERSION_1_45} - ${API_VERSION_1_46}`);
const supported = semver.eq(FC.CONFIG.apiVersion, API_VERSION_1_45);

// firmware 1_45 or higher is required to support cloud build options
// firmware 1_46 or higher retrieves build options from the flight controller
Expand Down
32 changes: 18 additions & 14 deletions src/js/tabs/firmware_flasher.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import FC from '../fc';
import MSP from '../msp';
import MSPCodes from '../msp/MSPCodes';
import PortHandler, { usbDevices } from '../port_handler';
import { API_VERSION_1_39, API_VERSION_1_45, API_VERSION_1_47 } from '../data_storage';
import { API_VERSION_1_39, API_VERSION_1_45, API_VERSION_1_46 } from '../data_storage';
import serial from '../serial';
import STM32DFU from '../protocols/stm32usbdfu';
import { gui_log } from '../gui_log';
Expand Down Expand Up @@ -1305,7 +1305,7 @@ firmware_flasher.verifyBoard = function() {

function getBoardInfo() {
MSP.send_message(MSPCodes.MSP_BOARD_INFO, false, false, function() {
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_47)) {
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
FC.processBuildOptions();
self.cloudBuildOptions = FC.CONFIG.buildOptions;
}
Expand All @@ -1320,20 +1320,24 @@ firmware_flasher.verifyBoard = function() {
getBoardInfo();
}

function getBuildInfo() {
async function getBuildInfo() {
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) && FC.CONFIG.flightControllerIdentifier === 'BTFL') {
MSP.send_message(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.BUILD_KEY), false, () => {
MSP.send_message(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.CRAFT_NAME), false, () => {
// store FC.CONFIG.buildKey as the object gets destroyed after disconnect
self.cloudBuildKey = FC.CONFIG.buildKey;
await MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.BUILD_KEY));
await MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.CRAFT_NAME));
await MSP.promise(MSPCodes.MSP_BUILD_INFO);

if (self.validateBuildKey() && semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_47)) {
self.buildApi.requestBuildOptions(self.cloudBuildKey, getCloudBuildOptions, getBoardInfo);
} else {
getBoardInfo();
}
});
});
// store FC.CONFIG.buildKey as the object gets destroyed after disconnect
self.cloudBuildKey = FC.CONFIG.buildKey;

// 3/21/2024 is the date when the build key was introduced
const supportedDate = new Date('3/21/2024');
const buildDate = new Date(FC.CONFIG.buildInfo);

if (self.validateBuildKey() && (semver.lt(FC.CONFIG.apiVersion, API_VERSION_1_46) || buildDate < supportedDate)) {
self.buildApi.requestBuildOptions(self.cloudBuildKey, getCloudBuildOptions, getBoardInfo);
} else {
getBoardInfo();
}
} else {
getBoardInfo();
}
Expand Down

0 comments on commit 37fada1

Please sign in to comment.