diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 3d7b2643..97486a96 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -75,7 +75,7 @@ "serialPortClosedFail": { "message": "Failed to close serial port" }, - + "noConfigurationReceived": { "message": "No configuration received within 10 seconds, communication failed" }, @@ -85,6 +85,9 @@ "firmwareVersion": { "message": "Firmware Version: $1" }, + "apiVersionReceived": { + "message": "MultiWii API version received - $1" + }, "uniqueDeviceIdReceived": { "message": "Unique device ID received - 0x$1" }, diff --git a/js/data_storage.js b/js/data_storage.js index de98d5a1..17eb9510 100644 --- a/js/data_storage.js +++ b/js/data_storage.js @@ -10,6 +10,9 @@ var CONFIGURATOR = { }; var CONFIG = { + apiVersion: 0, + flightControllerIdentifier: '', + flightControllerVersion: '', version: 0, multiType: 0, msp_version: 0, diff --git a/js/msp.js b/js/msp.js index e81f3d2f..3dca7b92 100644 --- a/js/msp.js +++ b/js/msp.js @@ -2,6 +2,7 @@ // MSP_codes needs to be re-integrated inside MSP object var MSP_codes = { + MSP_API_VERSION: 1, // MSP commands for Cleanflight original features MSP_CHANNEL_FORWARDING: 32, @@ -169,6 +170,15 @@ MSP.process_data = function(code, message_buffer, message_length) { var data = new DataView(message_buffer, 0); // DataView (allowing us to view arrayBuffer as struct/union) switch (code) { + case MSP_codes.MSP_API_VERSION: + CONFIG.apiVersion = data.getUint8(1) + '.' + data.getUint8(2); + var identifier = ''; + for (i = 0; i < 4; i++) { + identifier += String.fromCharCode(data.getUint8(3 + i)); + } + CONFIG.flightControllerIdentifier = identifier; + CONFIG.flightControllerVersion = data.getUint8(7) + '.' + data.getUint8(8) + '.' + data.getUint8(9); + break; case MSP_codes.MSP_IDENT: CONFIG.version = parseFloat((data.getUint8(0) / 100).toFixed(2)); CONFIG.multiType = data.getUint8(1); diff --git a/js/serial_backend.js b/js/serial_backend.js index f3f778cc..0ec891cc 100644 --- a/js/serial_backend.js +++ b/js/serial_backend.js @@ -136,22 +136,25 @@ function onOpen(openInfo) { }, 10000); // request configuration data - MSP.send_message(MSP_codes.MSP_UID, false, false, function () { - GUI.log(chrome.i18n.getMessage('uniqueDeviceIdReceived', [CONFIG.uid[0].toString(16) + CONFIG.uid[1].toString(16) + CONFIG.uid[2].toString(16)])); - MSP.send_message(MSP_codes.MSP_IDENT, false, false, function () { - GUI.timeout_remove('connecting'); // kill connecting timer - - GUI.log(chrome.i18n.getMessage('firmwareVersion', [CONFIG.version])); - - if (CONFIG.version >= CONFIGURATOR.firmwareVersionAccepted) { - CONFIGURATOR.connectionValid = true; - - $('div#port-picker a.connect').text(chrome.i18n.getMessage('disconnect')).addClass('active'); - $('#tabs li a:first').click(); - } else { - GUI.log(chrome.i18n.getMessage('firmwareVersionNotSupported', [CONFIGURATOR.firmwareVersionAccepted])); - $('div#port-picker a.connect').click(); // disconnect - } + MSP.send_message(MSP_codes.MSP_API_VERSION, false, false, function () { + GUI.log(chrome.i18n.getMessage('apiVersionReceived', [CONFIG.apiVersion])); + MSP.send_message(MSP_codes.MSP_UID, false, false, function () { + GUI.log(chrome.i18n.getMessage('uniqueDeviceIdReceived', [CONFIG.uid[0].toString(16) + CONFIG.uid[1].toString(16) + CONFIG.uid[2].toString(16)])); + MSP.send_message(MSP_codes.MSP_IDENT, false, false, function () { + GUI.timeout_remove('connecting'); // kill connecting timer + + GUI.log(chrome.i18n.getMessage('firmwareVersion', [CONFIG.version])); + + if (CONFIG.version >= CONFIGURATOR.firmwareVersionAccepted) { + CONFIGURATOR.connectionValid = true; + + $('div#port-picker a.connect').text(chrome.i18n.getMessage('disconnect')).addClass('active'); + $('#tabs li a:first').click(); + } else { + GUI.log(chrome.i18n.getMessage('firmwareVersionNotSupported', [CONFIGURATOR.firmwareVersionAccepted])); + $('div#port-picker a.connect').click(); // disconnect + } + }); }); }); } else {