Update MSP2TEXT command (#3096)

Fix constants for MSP2TEXT command
10.9-maintenance
haslinghuis 2022-12-02 02:40:46 +01:00 committed by GitHub
parent b7d0bd5df1
commit 09355c25d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 78 additions and 72 deletions

View File

@ -196,11 +196,11 @@ function configuration_backup(callback) {
return MSP.promise(MSPCodes.MSP_SENSOR_CONFIG);
}).then(function() {
return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)
? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.MSP2TEXT_CRAFT_NAME))
? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.CRAFT_NAME))
: MSP.promise(MSPCodes.MSP_NAME);
}).then(function() {
return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)
? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.MSP2TEXT_PILOT_NAME)) : Promise.resolve(true);
? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.PILOT_NAME)) : Promise.resolve(true);
}).then(function() {
return MSP.promise(MSPCodes.MSP_BOARD_ALIGNMENT_CONFIG);
}).then(function() {
@ -812,8 +812,8 @@ function configuration_restore(callback) {
function update_unique_data_list() {
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
uniqueData.push([MSPCodes.MSP2_SET_TEXT, MSPCodes.MSP2TEXT_CRAFT_NAME]);
uniqueData.push([MSPCodes.MSP2_SET_TEXT, MSPCodes.MSP2TEXT_PILOT_NAME]);
uniqueData.push([MSPCodes.MSP2_SET_TEXT, MSPCodes.CRAFT_NAME]);
uniqueData.push([MSPCodes.MSP2_SET_TEXT, MSPCodes.PILOT_NAME]);
} else {
uniqueData.push(MSPCodes.MSP_SET_NAME);
}

View File

@ -21,6 +21,8 @@ const INITIAL_CONFIG = {
craftName: '',
displayName: '', // present for backwards compatibility before MSP v1.45
pilotName: '',
pidProfileNames: ["", "", "", ""],
rateProfileNames: ["", "", "", ""],
numProfiles: 3,
rateProfile: 0,
boardType: 0,

View File

@ -195,10 +195,13 @@ const MSPCodes = {
MSP2_SET_MOTOR_OUTPUT_REORDERING: 0x3002,
MSP2_SEND_DSHOT_COMMAND: 0x3003,
MSP2_GET_VTX_DEVICE_STATUS: 0x3004,
MSP2_GET_OSD_WARNINGS: 0x3005,
MSP2_GET_TEXT: 0x3006,
MSP2_SET_TEXT: 0x3007,
// MSP2_GET_TEXT and MSP2_SET_TEXT variable types
MSP2TEXT_PILOT_NAME: 1,
MSP2TEXT_CRAFT_NAME: 2,
PILOT_NAME: 1,
CRAFT_NAME: 2,
PID_PROFILE_NAME: 3,
RATE_PROFILE_NAME: 4,
};

View File

@ -1,6 +1,5 @@
'use strict';
// Used for LED_STRIP
const ledDirectionLetters = ['n', 'e', 's', 'w', 'u', 'd']; // in LSB bit order
const ledFunctionLetters = ['i', 'w', 'f', 'a', 't', 'r', 'c', 'g', 's', 'b', 'l']; // in LSB bit order
@ -52,6 +51,31 @@ function MspHelper() {
self.SIGNATURE_LENGTH = 32;
self.mspMultipleCache = [];
self.setText = function(buffer, type, config, length) {
// type byte
buffer.push8(type);
const size = Math.min(length, config.length);
// length byte followed by the actual characters
buffer.push8(size);
for (let i = 0; i < size; i++) {
buffer.push8(config.charCodeAt(i));
}
};
self.getText = function(data) {
// length byte followed by the actual characters
const size = data.readU8() || 0;
let str = '';
for (let i = 0; i < size; i++) {
str += String.fromCharCode(data.readU8());
}
return str;
};
}
@ -922,20 +946,25 @@ MspHelper.prototype.process_data = function(dataHandler) {
case MSPCodes.MSP2_GET_TEXT:
// type byte
const textType = data.readU8();
// length byte followed by the actual characters
const textLength = data.readU8() || 0;
if (textType === MSPCodes.MSP2TEXT_PILOT_NAME) {
FC.CONFIG.pilotName = '';
for (let i = 0; i < textLength; i++) {
FC.CONFIG.pilotName += String.fromCharCode(data.readU8());
}
} else if (textType === MSPCodes.MSP2TEXT_CRAFT_NAME) {
FC.CONFIG.craftName = '';
for (let i = 0; i < textLength; i++) {
FC.CONFIG.craftName += String.fromCharCode(data.readU8());
}
switch(textType) {
case MSPCodes.PILOT_NAME:
FC.CONFIG.pilotName = self.getText(data);
break;
case MSPCodes.CRAFT_NAME:
FC.CONFIG.craftName = self.getText(data);
break;
case MSPCodes.PID_PROFILE_NAME:
FC.CONFIG.pidProfileNames[FC.CONFIG.profile] = self.getText(data);
break;
case MSPCodes.RATE_PROFILE_NAME:
FC.CONFIG.rateProfileNames[FC.CONFIG.rateProfile] = self.getText(data);
break;
default:
console.log('Unsupport text type');
break;
}
break;
case MSPCodes.MSP_SET_CHANNEL_FORWARDING:
@ -2352,40 +2381,26 @@ MspHelper.prototype.crunch = function(code, modifierCode = undefined) {
break;
case MSPCodes.MSP2_GET_TEXT:
if (modifierCode === MSPCodes.MSP2TEXT_PILOT_NAME) {
// type byte
buffer.push8(MSPCodes.MSP2TEXT_PILOT_NAME);
} else if (modifierCode === MSPCodes.MSP2TEXT_CRAFT_NAME) {
// type byte
buffer.push8(MSPCodes.MSP2TEXT_CRAFT_NAME);
}
buffer.push8(modifierCode);
break;
case MSPCodes.MSP2_SET_TEXT:
if (modifierCode === MSPCodes.MSP2TEXT_PILOT_NAME) {
// type byte
buffer.push8(MSPCodes.MSP2TEXT_PILOT_NAME);
const MAX_NAME_LENGTH = 16;
const pilotNameLength = Math.min(MAX_NAME_LENGTH, FC.CONFIG.pilotName.length);
// length byte followed by the actual characters
buffer.push8(pilotNameLength);
for (let i = 0; i < pilotNameLength; i++) {
buffer.push8(FC.CONFIG.pilotName.charCodeAt(i));
}
} else if (modifierCode === MSPCodes.MSP2TEXT_CRAFT_NAME) {
// type byte
buffer.push8(MSPCodes.MSP2TEXT_CRAFT_NAME);
const MAX_NAME_LENGTH = 16;
const craftNameLength = Math.min(MAX_NAME_LENGTH, FC.CONFIG.craftName.length);
// length byte followed by the actual characters
buffer.push8(craftNameLength);
for (let i = 0; i < craftNameLength; i++) {
buffer.push8(FC.CONFIG.craftName.charCodeAt(i));
}
switch (modifierCode) {
case MSPCodes.PILOT_NAME:
self.setText(buffer, modifierCode, FC.CONFIG.pilotName, 16);
break;
case MSPCodes.CRAFT_NAME:
self.setText(buffer, modifierCode, FC.CONFIG.craftName, 16);
break;
case MSPCodes.PID_PROFILE_NAME:
self.setText(buffer, modifierCode, FC.CONFIG.pidProfileNames[FC.CONFIG.profile], 8);
break;
case MSPCodes.RATE_PROFILE_NAME:
self.setText(buffer, modifierCode, FC.CONFIG.pidProfileNames[FC.CONFIG.rateProfile], 8);
break;
default:
console.log('Unsupport text type');
break;
}
break;

View File

@ -454,24 +454,15 @@ function processUid() {
async function processCraftName() {
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
await MSP.promise(
MSPCodes.MSP2_GET_TEXT,
mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.MSP2TEXT_CRAFT_NAME),
);
await MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.CRAFT_NAME));
} else {
await MSP.promise(MSPCodes.MSP_NAME);
}
GUI.log(i18n.getMessage('craftNameReceived', semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)
? [FC.CONFIG.craftName]
: [FC.CONFIG.name],
));
GUI.log(i18n.getMessage('craftNameReceived', semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) ? [FC.CONFIG.craftName] : [FC.CONFIG.name]));
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
await MSP.promise(
MSPCodes.MSP2_GET_TEXT,
mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.MSP2TEXT_PILOT_NAME),
);
await MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.PILOT_NAME));
}
FC.CONFIG.armingDisabled = false;

View File

@ -34,11 +34,11 @@ configuration.initialize = function (callback) {
? MSP.promise(MSPCodes.MSP_NAME)
: Promise.resolve(true); })
.then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)
? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.MSP2TEXT_CRAFT_NAME))
? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.CRAFT_NAME))
: Promise.resolve(true); })
.then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_31) ? MSP.promise(MSPCodes.MSP_RX_CONFIG) : true; })
.then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)
? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.MSP2TEXT_PILOT_NAME)) : Promise.resolve(true); })
? MSP.promise(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.PILOT_NAME)) : Promise.resolve(true); })
.then(() => { return MSP.promise(MSPCodes.MSP_ADVANCED_CONFIG); })
.then(() => { load_html(); });
}
@ -636,10 +636,10 @@ configuration.initialize = function (callback) {
.then(() => { return MSP.promise(MSPCodes.MSP_SET_ARMING_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_ARMING_CONFIG)); })
.then(() => { return MSP.promise(MSPCodes.MSP_SET_SENSOR_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_SENSOR_CONFIG)); })
.then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)
? MSP.promise(MSPCodes.MSP2_SET_TEXT, mspHelper.crunch(MSPCodes.MSP2_SET_TEXT, MSPCodes.MSP2TEXT_CRAFT_NAME))
? MSP.promise(MSPCodes.MSP2_SET_TEXT, mspHelper.crunch(MSPCodes.MSP2_SET_TEXT, MSPCodes.CRAFT_NAME))
: MSP.promise(MSPCodes.MSP_SET_NAME, mspHelper.crunch(MSPCodes.MSP_SET_NAME)); })
.then(() => { return semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45) ?
MSP.promise(MSPCodes.MSP2_SET_TEXT, mspHelper.crunch(MSPCodes.MSP2_SET_TEXT, MSPCodes.MSP2TEXT_PILOT_NAME)) : Promise.resolve(true); })
MSP.promise(MSPCodes.MSP2_SET_TEXT, mspHelper.crunch(MSPCodes.MSP2_SET_TEXT, MSPCodes.PILOT_NAME)) : Promise.resolve(true); })
.then(() => { return (semver.gte(FC.CONFIG.apiVersion, "1.20.0")) ? MSP.promise(MSPCodes.MSP_SET_RX_CONFIG, mspHelper.crunch(MSPCodes.MSP_SET_RX_CONFIG)) : true; })
.then(() => { return MSP.promise(MSPCodes.MSP_EEPROM_WRITE); })
.then(() => { reboot(); });

View File

@ -27,12 +27,7 @@ onboard_logging.initialize = function (callback) {
MSP.send_message(MSPCodes.MSP_BLACKBOX_CONFIG, false, false, function() {
MSP.send_message(MSPCodes.MSP_ADVANCED_CONFIG, false, false, function() {
if (semver.gte(FC.CONFIG.apiVersion, API_VERSION_1_45)) {
MSP.send_message(
MSPCodes.MSP2_GET_TEXT,
mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.MSP2TEXT_CRAFT_NAME),
false,
load_html,
);
MSP.send_message(MSPCodes.MSP2_GET_TEXT, mspHelper.crunch(MSPCodes.MSP2_GET_TEXT, MSPCodes.CRAFT_NAME), false, load_html);
} else {
MSP.send_message(MSPCodes.MSP_NAME, false, false, load_html);
}