Skip to content

Commit

Permalink
Add buildOptions from MSP
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis committed Feb 1, 2024
1 parent da3a732 commit f23bab8
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 5 deletions.
69 changes: 69 additions & 0 deletions src/js/fc.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,59 @@ const INITIAL_BATTERY_CONFIG = {
currentMeterSource: 0,
};

const FIRMWARE_BUILD_OPTIONS = {
// Radio Protocols
USE_SERIALRX_CRSF: 4097,
USE_SERIALRX_FPORT: 4098,
USE_SERIALRX_GHST: 4099,
USE_SERIALRX_IBUS: 4100,
USE_SERIALRX_JETIEXBUS: 4101,
USE_RX_PPM: 4102,
USE_SERIALRX_SBUS: 4103,
USE_SERIALRX_SPEKTRUM: 4104,
USE_SERIALRX_SRXL2: 4105,
USE_SERIALRX_SUMD: 4106,
USE_SERIALRX_SUMH: 4107,
USE_SERIALRX_XBUS: 4108,

// Motor Protocols
USE_BRUSHED: 8230,
USE_DSHOT: 8231,
USE_MULTISHOT: 8232,
USE_ONESHOT: 8233,
USE_PROSHOT: 8234,
USE_PWM_OUTPUT: 8235,

// Telemetry Protocols
USE_TELEMETRY_FRSKY_HUB: 12301,
USE_TELEMETRY_HOTT: 12302,
USE_TELEMETRY_IBUS_EXTENDED:12303,
USE_TELEMETRY_LTM: 12304,
USE_TELEMETRY_MAVLINK: 12305,
USE_TELEMETRY_SMARTPORT: 12306,
USE_TELEMETRY_SRXL: 12307,

// General Options
USE_ACRO_TRAINER: 16404,
USE_AKK_SMARTAUDIO: 16405,
USE_BATTERY_CONTINUE: 16406,
USE_CAMERA_CONTROL: 16407,
USE_DASHBOARD: 16408,
USE_EMFAT_TOOLS: 16409,
USE_ESCSERIAL_SIMONK: 16410,
USE_FRSKYOSD: 16411,
USE_GPS: 16412,
USE_LED_STRIP: 16413,
USE_LED_STRIP_64: 16414,
USE_MAG: 16415,
USE_OSD_SD: 16416,
USE_OSD_HD: 16417,
USE_PINIO: 16418,
USE_RACE_PRO: 16419,
USE_SERVOS: 16420,
USE_VTX: 16421,
};

const FC = {

// define all the global variables that are uses to hold FC state
Expand All @@ -87,6 +140,7 @@ const FC = {
// Shallow copy of original config and added getter
// getter allows this to be used with simple dot notation
// and bridges the vue and rest of the code
BUILD_OPTIONS: {...FIRMWARE_BUILD_OPTIONS},
CONFIG: {
...INITIAL_CONFIG,
get hardwareName() {
Expand Down Expand Up @@ -823,6 +877,21 @@ const FC = {
MOTOR_PROTOCOL_DISABLED: 1,
},

processBuildOptions() {
const buildOptions = [];

for (const [key, value] of Object.entries(FIRMWARE_BUILD_OPTIONS)) {
for (const option of this.CONFIG.buildOptions) {
if (option === value) {
buildOptions.push(key);
break;
}
}
}

this.CONFIG.buildOptions = buildOptions;
},

boardHasVcp() {
return bit_check(this.CONFIG.targetCapabilities, this.TARGET_CAPABILITIES_FLAGS.HAS_VCP);
},
Expand Down
19 changes: 18 additions & 1 deletion src/js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ MspHelper.prototype.process_data = function(dataHandler) {
FC.CONFIG.flightControllerVersion = `${data.readU8()}.${data.readU8()}.${data.readU8()}`;
break;

case MSPCodes.MSP_BUILD_INFO:
case MSPCodes.MSP_BUILD_INFO: {
const dateLength = 11;
buff = [];

Expand All @@ -782,7 +782,24 @@ MspHelper.prototype.process_data = function(dataHandler) {
buff.push(data.readU8());
}
FC.CONFIG.buildInfo = String.fromCharCode.apply(null, buff);

const gitRevisionLength = 7;
buff = [];
for (let i = 0; i < gitRevisionLength; i++) {
buff.push(data.readU8());
}
console.log("Fw git rev:", String.fromCharCode.apply(null, buff));

if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
let option = data.readU16();
while (option) {
FC.CONFIG.buildOptions.push(option);
option = data.readU16();
}
}

break;
}

case MSPCodes.MSP_BOARD_INFO:
FC.CONFIG.boardIdentifier = '';
Expand Down
3 changes: 2 additions & 1 deletion src/js/serial_backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ function processBoardInfo() {
gui_log(i18n.getMessage('boardInfoReceived', [FC.getHardwareName(), FC.CONFIG.boardVersion]));

if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
FC.processBuildOptions();
checkReportProblems();
} else {
processCustomDefaults();
Expand Down Expand Up @@ -548,7 +549,7 @@ async function processUid() {

gui_log(i18n.getMessage('uniqueDeviceIdReceived', FC.CONFIG.deviceIdentifier));

if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
if (semver.eq(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
processBuildConfiguration();
} else {
processCraftName();
Expand Down
11 changes: 8 additions & 3 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 } 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 @@ -1298,7 +1298,12 @@ firmware_flasher.verifyBoard = function() {
}

function getBoardInfo() {
MSP.send_message(MSPCodes.MSP_BOARD_INFO, false, false, onFinish);
MSP.send_message(MSPCodes.MSP_BOARD_INFO, false, false, function() {
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_46)) {
FC.processBuildOptions();
}
onFinish();
});
}

function getCloudBuildOptions(options) {
Expand All @@ -1309,7 +1314,7 @@ firmware_flasher.verifyBoard = function() {
}

function getBuildInfo() {
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) && navigator.onLine && FC.CONFIG.flightControllerIdentifier === 'BTFL') {
if (semver.eq(FC.CONFIG.apiVersion, API_VERSION_1_45) && navigator.onLine && 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
Expand Down

0 comments on commit f23bab8

Please sign in to comment.