Skip to content

Commit

Permalink
Expose Cloud Build Options
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis committed Feb 9, 2023
1 parent 309bd43 commit 339367e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/js/BuildApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ export default class BuildApi {
});
}

requestBuildOptions(key, onSuccess, onFailure) {
const url = `${this._url}/api/builds/${key}/json`;
$.get(url, function (data) {
onSuccess(data);
}).fail(xhr => {
if (onFailure !== undefined) {
onFailure();
}
});
}

loadOptions(onSuccess, onFailure) {

const url = `${this._url}/api/options`;
Expand Down
3 changes: 3 additions & 0 deletions src/js/fc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const INITIAL_CONFIG = {
flightControllerVersion: '',
version: 0,
buildInfo: '',
BuildFlags: [],
BuildOptions: [],
BuildConfig: [],
multiType: 0,
msp_version: 0, // not specified using semantic versioning
capability: 0,
Expand Down
1 change: 1 addition & 0 deletions src/js/msp/MSPCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ const MSPCodes = {
CRAFT_NAME: 2,
PID_PROFILE_NAME: 3,
RATE_PROFILE_NAME: 4,
BUILD_KEY: 5,
};

export default MSPCodes;
3 changes: 3 additions & 0 deletions src/js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,9 @@ MspHelper.prototype.process_data = function(dataHandler) {
case MSPCodes.RATE_PROFILE_NAME:
FC.CONFIG.rateProfileNames[FC.CONFIG.rateProfile] = self.getText(data);
break;
case MSPCodes.BUILD_KEY:
FC.CONFIG.buildKey = self.getText(data);
break;
default:
console.log('Unsupport text type');
break;
Expand Down
23 changes: 23 additions & 0 deletions src/js/serial_backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { get as getConfig, set as setConfig } from "./ConfigStorage";
import { tracking } from "./Analytics";
import semver from 'semver';
import CryptoES from "crypto-es";
import BuildApi from "./BuildApi";

let mspHelper;
let connectionTimestamp;
Expand Down Expand Up @@ -362,6 +363,26 @@ function abortConnect() {
clicks = false;
}

async function processBuildConfiguration() {
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
const buildOptions = new BuildApi();

function onLoadCloudBuild(options) {
FC.CONFIG.BuildFlags = options.Config.BuildFlags;
FC.CONFIG.BuildOptions = options.Request.Options;
FC.CONFIG.BuildConfig = options.Config.Configuration;
}

function onLoadFailed() {
console.log('Failed to retrieve Build Configuration');
}

await MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.BUILD_KEY));

buildOptions.requestBuildOptions(FC.CONFIG.buildKey, onLoadCloudBuild, onLoadFailed);
}
}

function processBoardInfo() {
tracking.setFlightControllerData(tracking.DATA.BOARD_TYPE, FC.CONFIG.boardIdentifier);
tracking.setFlightControllerData(tracking.DATA.TARGET_NAME, FC.CONFIG.targetName);
Expand All @@ -371,6 +392,8 @@ function processBoardInfo() {

gui_log(i18n.getMessage('boardInfoReceived', [FC.getHardwareName(), FC.CONFIG.boardVersion]));

processBuildConfiguration();

if (bit_check(FC.CONFIG.targetCapabilities, FC.TARGET_CAPABILITIES_FLAGS.SUPPORTS_CUSTOM_DEFAULTS) && bit_check(FC.CONFIG.targetCapabilities, FC.TARGET_CAPABILITIES_FLAGS.HAS_CUSTOM_DEFAULTS) && FC.CONFIG.configurationState === FC.CONFIGURATION_STATES.DEFAULTS_BARE) {
const dialog = $('#dialogResetToCustomDefaults')[0];

Expand Down

0 comments on commit 339367e

Please sign in to comment.