mirror of
https://github.com/betaflight/betaflight-configurator.git
synced 2025-07-17 21:35:33 +03:00
revise limit to 255, and handle comments
This commit is contained in:
parent
96619a4b58
commit
7133001fa2
2 changed files with 29 additions and 7 deletions
|
@ -2813,7 +2813,12 @@
|
||||||
"message": "HEX file appears to be corrupted"
|
"message": "HEX file appears to be corrupted"
|
||||||
},
|
},
|
||||||
"firmwareFlasherConfigCorrupted": {
|
"firmwareFlasherConfigCorrupted": {
|
||||||
"message": "Config file appears to be corrupted, ASCII accepted (chars 0-127)"
|
"message": "Config file appears to be corrupted, ASCII accepted (chars 0-255)",
|
||||||
|
"description": "shown in the progress bar at the bottom, be brief"
|
||||||
|
},
|
||||||
|
"firmwareFlasherConfigCorruptedLogMessage": {
|
||||||
|
"message": "Config file appears to be corrupted, ASCII accepted (chars 0-255), characters outside of this range are allowed as comments",
|
||||||
|
"description": "shown in the log, more wordy"
|
||||||
},
|
},
|
||||||
"firmwareFlasherRemoteFirmwareLoaded": {
|
"firmwareFlasherRemoteFirmwareLoaded": {
|
||||||
"message": "<span class=\"message-positive\">Remote Firmware loaded, ready for flashing</span>"
|
"message": "<span class=\"message-positive\">Remote Firmware loaded, ready for flashing</span>"
|
||||||
|
|
|
@ -587,11 +587,27 @@ TABS.firmware_flasher.initialize = function (callback) {
|
||||||
self.flashingMessage(i18n.getMessage('firmwareFlasherFirmwareLocalLoaded', self.parsed_hex.bytes_total), self.FLASH_MESSAGE_TYPES.NEUTRAL);
|
self.flashingMessage(i18n.getMessage('firmwareFlasherFirmwareLocalLoaded', self.parsed_hex.bytes_total), self.FLASH_MESSAGE_TYPES.NEUTRAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function checkAsciiLimits(input) {
|
function cleanUnifiedConfigFile(input) {
|
||||||
|
let output = [];
|
||||||
|
let inComment = false;
|
||||||
for (let i=0; i < input.length; i++) {
|
for (let i=0; i < input.length; i++) {
|
||||||
if (input.charCodeAt(i) > 127) { return false; }
|
if (input.charAt(i) == "\n" || input.charAt(i) == "\r") {
|
||||||
|
inComment = false;
|
||||||
|
}
|
||||||
|
if (input.charAt(i) == "#") {
|
||||||
|
inComment = true;
|
||||||
|
}
|
||||||
|
if (!inComment && input.charCodeAt(i) > 255) {
|
||||||
|
// Note: we're not showing this error in betaflight-configurator
|
||||||
|
throw new Error('commands are limited to characters 0-255, comments have no limitation');
|
||||||
|
}
|
||||||
|
if (input.charCodeAt(i) > 255) {
|
||||||
|
output.push('_');
|
||||||
|
} else {
|
||||||
|
output.push(input.charAt(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return output.join('');
|
||||||
}
|
}
|
||||||
// UI Hooks
|
// UI Hooks
|
||||||
$('a.load_file').click(function () {
|
$('a.load_file').click(function () {
|
||||||
|
@ -647,13 +663,14 @@ TABS.firmware_flasher.initialize = function (callback) {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
clearBufferedFirmware();
|
clearBufferedFirmware();
|
||||||
if (checkAsciiLimits(e.target.result)) {
|
try {
|
||||||
self.unifiedTargetConfig = e.target.result;
|
self.unifiedTargetConfig = cleanUnifiedConfigFile(e.target.result);
|
||||||
self.unifiedTargetConfigName = file.name;
|
self.unifiedTargetConfigName = file.name;
|
||||||
self.isConfigLocal = true;
|
self.isConfigLocal = true;
|
||||||
flashingMessageLocal();
|
flashingMessageLocal();
|
||||||
} else {
|
} catch(err) {
|
||||||
self.flashingMessage('firmwareFlasherConfigCorrupted', self.FLASH_MESSAGE_TYPES.INVALID);
|
self.flashingMessage('firmwareFlasherConfigCorrupted', self.FLASH_MESSAGE_TYPES.INVALID);
|
||||||
|
GUI.log(i18n.getMessage('firmwareFlasherConfigCorruptedLogMessage'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue