Update version checking code to use semantic versioning - see

http://semver.org/

semver.js creating using browserify.

https://www.brcdn.org/?module=semver&version=4.3.4
10.3.x-maintenance
Dominic Clifton 2015-05-07 22:10:26 +01:00
parent 726c895c0a
commit 244685c9a6
11 changed files with 1251 additions and 57 deletions

View File

@ -82,7 +82,7 @@ function configuration_backup(callback) {
];
function update_unique_data_list() {
if (CONFIG.apiVersion >= 1.8) {
if (semver.gte(CONFIG.apiVersion, "1.8.0")) {
uniqueData.push(MSP_codes.MSP_LOOP_TIME);
uniqueData.push(MSP_codes.MSP_ARMING_CONFIG);
}
@ -106,7 +106,7 @@ function configuration_backup(callback) {
configuration.SERIAL_CONFIG = jQuery.extend(true, {}, SERIAL_CONFIG);
configuration.LED_STRIP = jQuery.extend(true, [], LED_STRIP);
if (CONFIG.apiVersion >= 1.8) {
if (semver.gte(CONFIG.apiVersion, "1.8.0")) {
configuration.FC_CONFIG = jQuery.extend(true, {}, FC_CONFIG);
configuration.ARMING_CONFIG = jQuery.extend(true, {}, ARMING_CONFIG);
}
@ -270,29 +270,7 @@ function configuration_restore(callback) {
if (generated == undefined) {
return false;
}
var a = generated.split('.'),
b = required.split('.');
for (var i = 0; i < a.length; ++i) {
a[i] = Number(a[i]);
}
for (var i = 0; i < b.length; ++i) {
b[i] = Number(b[i]);
}
if (a.length == 2) {
a[2] = 0;
}
if (a[0] > b[0]) return true;
if (a[0] < b[0]) return false;
if (a[1] > b[1]) return true;
if (a[1] < b[1]) return false;
if (a[2] > b[2]) return true;
if (a[2] < b[2]) return false;
return true;
return semver.gte(generated, required);
}
function migrate(configuration) {
@ -369,7 +347,17 @@ function configuration_restore(callback) {
appliedMigrationsCount++;
}
if (compareVersions(migratedVersion, '0.63.0') && !compareVersions(configuration.apiVersion, '1.7')) {
if (configuration.apiVersion == undefined) {
configuration.apiVersion = "1.0.0" // a guess that will satisfy the rest of the code
}
// apiVersion previously stored without patchlevel
if (!semver.parse(configuration.apiVersion)) {
configuration.apiVersion += ".0";
if (!semver.parse(configuration.apiVersion)) {
return false;
}
}
if (compareVersions(migratedVersion, '0.63.0') && !compareVersions(configuration.apiVersion, '1.7.0')) {
// Serial configuation redesigned, 0.63.0 saves old and new configurations.
var ports = [];
for (var portIndex = 0; portIndex < configuration.SERIAL_CONFIG.ports.length; portIndex++) {
@ -414,7 +402,7 @@ function configuration_restore(callback) {
appliedMigrationsCount++;
}
if (compareVersions(migratedVersion, '0.63.0') && !compareVersions(configuration.apiVersion, '1.8')) {
if (compareVersions(migratedVersion, '0.63.0') && !compareVersions(configuration.apiVersion, '1.8.0')) {
// api 1.8 exposes looptime and arming config
if (configuration.FC_CONFIG == undefined) {
@ -536,7 +524,7 @@ function configuration_restore(callback) {
];
function update_unique_data_list() {
if (CONFIG.apiVersion >= 1.8) {
if (semver.gte(CONFIG.apiVersion, "1.8.0")) {
uniqueData.push(MSP_codes.MSP_SET_LOOP_TIME);
uniqueData.push(MSP_codes.MSP_SET_ARMING_CONFIG);
}

View File

@ -2,10 +2,13 @@
var CONFIGURATOR = {
'releaseDate': 1429014724688, // new Date().getTime() - Tue Apr 14 2015 13:32:17 GMT+0100 (BST)
'apiVersionAccepted': 1.2,
'backupRestoreMinApiVersionAccepted': 1.5,
'pidControllerChangeMinApiVersion': 1.5,
'backupFileMinVersionAccepted': '0.55', // chrome.runtime.getManifest().version is stored as string, so does this one
// all versions are specified and compared using semantic versioning http://semver.org/
'apiVersionAccepted': '1.2.0',
'backupRestoreMinApiVersionAccepted': '1.5.0',
'pidControllerChangeMinApiVersion': '1.5.0',
'backupFileMinVersionAccepted': '0.55.0', // chrome.runtime.getManifest().version is stored as string, so does this one
'connectionValid': false,
'connectionValidCliOnly': false,
'cliActive': false,
@ -13,13 +16,13 @@ var CONFIGURATOR = {
};
var CONFIG = {
apiVersion: 0,
apiVersion: "0.0.0",
flightControllerIdentifier: '',
flightControllerVersion: '',
version: 0,
buildInfo: '',
multiType: 0,
msp_version: 0,
msp_version: 0, // not specified using semantic versioning
capability: 0,
cycleTime: 0,
i2cError: 0,

1202
js/libraries/semver.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -297,7 +297,7 @@ var MSP = {
var offset = 0;
RC_tuning.RC_RATE = parseFloat((data.getUint8(offset++) / 100).toFixed(2));
RC_tuning.RC_EXPO = parseFloat((data.getUint8(offset++) / 100).toFixed(2));
if (CONFIG.apiVersion < 1.7) {
if (semver.lt(CONFIG.apiVersion, "1.7.0")) {
RC_tuning.roll_pitch_rate = parseFloat((data.getUint8(offset++) / 100).toFixed(2));
} else {
RC_tuning.roll_rate = parseFloat((data.getUint8(offset++) / 100).toFixed(2));
@ -307,7 +307,7 @@ var MSP = {
RC_tuning.dynamic_THR_PID = parseFloat((data.getUint8(offset++) / 100).toFixed(2));
RC_tuning.throttle_MID = parseFloat((data.getUint8(offset++) / 100).toFixed(2));
RC_tuning.throttle_EXPO = parseFloat((data.getUint8(offset++) / 100).toFixed(2));
if (CONFIG.apiVersion >= 1.7) {
if (semver.gte(CONFIG.apiVersion, "1.7.0")) {
RC_tuning.dynamic_THR_breakpoint = data.getUint16(offset++, 1);
}
break;
@ -353,13 +353,13 @@ var MSP = {
break;
*/
case MSP_codes.MSP_ARMING_CONFIG:
if (CONFIG.apiVersion >= 1.8) {
if (semver.gte(CONFIG.apiVersion, "1.8.0")) {
ARMING_CONFIG.auto_disarm_delay = data.getUint8(0, 1);
ARMING_CONFIG.disarm_kill_switch = data.getUint8(1);
}
break;
case MSP_codes.MSP_LOOP_TIME:
if (CONFIG.apiVersion >= 1.8) {
if (semver.gte(CONFIG.apiVersion, "1.8.0")) {
FC_CONFIG.loopTime = data.getInt16(0, 1);
}
break;
@ -552,7 +552,7 @@ var MSP = {
case MSP_codes.MSP_API_VERSION:
var offset = 0;
CONFIG.mspProtocolVersion = data.getUint8(offset++);
CONFIG.apiVersion = data.getUint8(offset++) + '.' + data.getUint8(offset++);
CONFIG.apiVersion = data.getUint8(offset++) + '.' + data.getUint8(offset++) + '.0';
break;
case MSP_codes.MSP_FC_VARIANT:
@ -603,7 +603,7 @@ var MSP = {
case MSP_codes.MSP_CF_SERIAL_CONFIG:
if (CONFIG.apiVersion < 1.6) {
if (semver.lt(CONFIG.apiVersion, "1.6.0")) {
SERIAL_CONFIG.ports = [];
var offset = 0;
var serialPortCount = (data.byteLength - (4 * 4)) / 2;
@ -950,7 +950,7 @@ MSP.crunch = function (code) {
case MSP_codes.MSP_SET_RC_TUNING:
buffer.push(parseInt(RC_tuning.RC_RATE * 100));
buffer.push(parseInt(RC_tuning.RC_EXPO * 100));
if (CONFIG.apiVersion < 1.7) {
if (semver.lt(CONFIG.apiVersion, "1.7.0")) {
buffer.push(parseInt(RC_tuning.roll_pitch_rate * 100));
} else {
buffer.push(parseInt(RC_tuning.roll_rate * 100));
@ -960,7 +960,7 @@ MSP.crunch = function (code) {
buffer.push(parseInt(RC_tuning.dynamic_THR_PID * 100));
buffer.push(parseInt(RC_tuning.throttle_MID * 100));
buffer.push(parseInt(RC_tuning.throttle_EXPO * 100));
if (CONFIG.apiVersion >= 1.7) {
if (semver.gte(CONFIG.apiVersion, "1.7.0")) {
buffer.push(lowByte(RC_tuning.dynamic_THR_breakpoint));
buffer.push(highByte(RC_tuning.dynamic_THR_breakpoint));
}
@ -1041,7 +1041,7 @@ MSP.crunch = function (code) {
}
break;
case MSP_codes.MSP_SET_CF_SERIAL_CONFIG:
if (CONFIG.apiVersion < 1.6) {
if (semver.lt(CONFIG.apiVersion, "1.6.0")) {
for (var i = 0; i < SERIAL_CONFIG.ports.length; i++) {
buffer.push(SERIAL_CONFIG.ports[i].scenario);

View File

@ -142,7 +142,7 @@ function onOpen(openInfo) {
MSP.send_message(MSP_codes.MSP_API_VERSION, false, false, function () {
GUI.log(chrome.i18n.getMessage('apiVersionReceived', [CONFIG.apiVersion]));
if (CONFIG.apiVersion >= CONFIGURATOR.apiVersionAccepted) {
if (semver.gte(CONFIG.apiVersion, CONFIGURATOR.apiVersionAccepted)) {
MSP.send_message(MSP_codes.MSP_FC_VARIANT, false, false, function () {
@ -167,11 +167,11 @@ function onOpen(openInfo) {
// continue as usually
CONFIGURATOR.connectionValid = true;
GUI.allowedTabs = GUI.defaultAllowedTabsWhenConnected.slice();
if (CONFIG.apiVersion < 1.4) {
if (semver.lt(CONFIG.apiVersion, "1.4.0")) {
GUI.allowedTabs.splice(GUI.allowedTabs.indexOf('led_strip'), 1);
}
GUI.canChangePidController = CONFIG.apiVersion >= CONFIGURATOR.pidControllerChangeMinApiVersion;
GUI.canChangePidController = semver.gte(CONFIG.apiVersion, CONFIGURATOR.pidControllerChangeMinApiVersion);
onConnect();

View File

@ -39,6 +39,7 @@
<script type="text/javascript" src="./js/libraries/three/Projector.js"></script>
<script type="text/javascript" src="./js/libraries/three/CanvasRenderer.js"></script>
<script type="text/javascript" src="./js/libraries/jquery.flightindicators.js"></script>
<script type="text/javascript" src="./js/libraries/semver.js"></script>
<script type="text/javascript" src="./js/port_handler.js"></script>
<script type="text/javascript" src="./js/port_usage.js"></script>
<script type="text/javascript" src="./js/serial.js"></script>

View File

@ -15,7 +15,7 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
}
function load_serial_config() {
if (CONFIG.apiVersion < 1.6) {
if (semver.lt(CONFIG.apiVersion, "1.6.0")) {
MSP.send_message(MSP_codes.MSP_CF_SERIAL_CONFIG, false, false, load_rc_map);
} else {
load_rc_map();
@ -32,7 +32,7 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
function load_acc_trim() {
MSP.send_message(MSP_codes.MSP_ACC_TRIM, false, false
, CONFIG.apiVersion >= 1.8 ? load_arming_config : load_html);
, semver.gte(CONFIG.apiVersion, "1.8.0") ? load_arming_config : load_html);
}
function load_arming_config() {
@ -193,7 +193,7 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
gps_baudrate_e.append('<option value="' + gpsBaudRates[i] + '">' + gpsBaudRates[i] + '</option>');
}
if (CONFIG.apiVersion < 1.6) {
if (semver.lt(CONFIG.apiVersion, "1.6.0")) {
gps_baudrate_e.change(function () {
SERIAL_CONFIG.gpsBaudRate = parseInt($(this).val());
});
@ -257,7 +257,7 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
$('input[name="mag_declination"]').val(MISC.mag_declination);
//fill motor disarm params
if(CONFIG.apiVersion >= 1.8) {
if(semver.gte(CONFIG.apiVersion, "1.8.0")) {
$('input[name="autodisarmdelay"]').val(ARMING_CONFIG.auto_disarm_delay);
$('input[name="disarmkillswitch"]').prop('checked', ARMING_CONFIG.disarm_kill_switch);
$('div.disarm').show();
@ -335,7 +335,7 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
MISC.mag_declination = parseFloat($('input[name="mag_declination"]').val());
// motor disarm
if(CONFIG.apiVersion >= 1.8) {
if(semver.gte(CONFIG.apiVersion, "1.8.0")) {
ARMING_CONFIG.auto_disarm_delay = parseInt($('input[name="autodisarmdelay"]').val());
ARMING_CONFIG.disarm_kill_switch = ~~$('input[name="disarmkillswitch"]').is(':checked'); // ~~ boolean to decimal conversion
}
@ -356,7 +356,7 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
MISC.multiwiicurrentoutput = ~~$('input[name="multiwiicurrentoutput"]').is(':checked'); // ~~ boolean to decimal conversion
function save_serial_config() {
if (CONFIG.apiVersion < 1.6) {
if (semver.lt(CONFIG.apiVersion, "1.6.0")) {
MSP.send_message(MSP_codes.MSP_SET_CF_SERIAL_CONFIG, MSP.crunch(MSP_codes.MSP_SET_CF_SERIAL_CONFIG), false, save_misc);
} else {
save_misc();
@ -369,7 +369,7 @@ TABS.configuration.initialize = function (callback, scrollPosition) {
function save_acc_trim() {
MSP.send_message(MSP_codes.MSP_SET_ACC_TRIM, MSP.crunch(MSP_codes.MSP_SET_ACC_TRIM), false
, CONFIG.apiVersion >= 1.8 ? save_arming_config : save_to_eeprom);
, semver.gte(CONFIG.apiVersion, "1.8.0") ? save_arming_config : save_to_eeprom);
}
function save_arming_config() {

View File

@ -20,7 +20,7 @@ TABS.dataflash.initialize = function (callback) {
log_buffer = [];
if (CONFIGURATOR.connectionValid) {
TABS.dataflash.available = (CONFIG.apiVersion >= 1.6)
TABS.dataflash.available = semver.gte(CONFIG.apiVersion, "1.6.0");
if (!TABS.dataflash.available) {
load_html();

View File

@ -275,7 +275,7 @@ TABS.pid_tuning.initialize = function (callback) {
pidController_e.prop('disabled', true);
}
if (CONFIG.apiVersion < 1.7) {
if (semver.lt(CONFIG.apiVersion, "1.7.0")) {
$('.rate-tpa .tpa-breakpoint').hide();
$('.rate-tpa .roll').hide();
$('.rate-tpa .pitch').hide();

View File

@ -80,7 +80,7 @@ TABS.ports.initialize = function (callback, scrollPosition) {
function update_ui() {
if (CONFIG.apiVersion < 1.6) {
if (semver.lt(CONFIG.apiVersion, "1.6.0")) {
$(".tab-ports").removeClass("supported");
return;

View File

@ -38,7 +38,7 @@ TABS.setup.initialize = function (callback) {
// translate to user-selected language
localize();
if (CONFIG.apiVersion < CONFIGURATOR.backupRestoreMinApiVersionAccepted) {
if (semver.lt(CONFIG.apiVersion, CONFIGURATOR.backupRestoreMinApiVersionAccepted)) {
$('#content .backup').addClass('disabled');
$('#content .restore').addClass('disabled');