diff --git a/js/msp.js b/js/msp.js index 07b0cccd..f6a18fc7 100755 --- a/js/msp.js +++ b/js/msp.js @@ -10,6 +10,7 @@ var MSP = { message_buffer: null, message_buffer_uint8_view: null, message_checksum: 0, + messageIsJumboFrame: false, callbacks: [], packet_error: 0, @@ -17,6 +18,8 @@ var MSP = { last_received_timestamp: null, listeners: [], + + JUMBO_FRAME_SIZE_LIMIT: 255, read: function (readInfo) { var data = new Uint8Array(readInfo.data); @@ -50,13 +53,12 @@ var MSP = { break; case 3: this.message_length_expected = data[i]; + if (this.message_length_expected === this.JUMBO_FRAME_SIZE_LIMIT) { + this.messageIsJumboFrame = true; + } this.message_checksum = data[i]; - // setup arraybuffer - this.message_buffer = new ArrayBuffer(this.message_length_expected); - this.message_buffer_uint8_view = new Uint8Array(this.message_buffer); - this.state++; break; case 4: @@ -65,13 +67,39 @@ var MSP = { if (this.message_length_expected > 0) { // process payload - this.state++; + if (this.messageIsJumboFrame) { + this.state++; + } else { + this.state = this.state + 3; + } } else { // no payload - this.state += 2; + this.state += 5; } break; - case 5: // payload + case 5: + this.message_length_expected = data[i]; + + this.message_checksum ^= data[i]; + + this.state++; + + break; + case 6: + this.message_length_expected = this.message_length_expected + 256 * data[i]; + + this.message_checksum ^= data[i]; + + this.state++; + + break; + case 7: + // setup arraybuffer + this.message_buffer = new ArrayBuffer(this.message_length_expected); + this.message_buffer_uint8_view = new Uint8Array(this.message_buffer); + + this.state++; + case 8: // payload this.message_buffer_uint8_view[this.message_length_received] = data[i]; this.message_checksum ^= data[i]; this.message_length_received++; @@ -80,7 +108,7 @@ var MSP = { this.state++; } break; - case 6: + case 9: if (this.message_checksum == data[i]) { // message received, store dataview this.dataView = new DataView(this.message_buffer, 0, this.message_length_expected); @@ -92,6 +120,7 @@ var MSP = { // Reset variables this.message_length_received = 0; this.state = 0; + this.messageIsJumboFrame = false; this.notify(); break; @@ -210,4 +239,4 @@ var MSP = { this.callbacks_cleanup(); } -}; \ No newline at end of file +}; diff --git a/js/msp/MSPHelper.js b/js/msp/MSPHelper.js index 03979dc0..f4dfd505 100644 --- a/js/msp/MSPHelper.js +++ b/js/msp/MSPHelper.js @@ -446,6 +446,8 @@ MspHelper.prototype.process_data = function(dataHandler) { '115200', '230400', '250000', + '500000', + '1000000' ]; if (semver.lt(CONFIG.apiVersion, "1.6.0")) { SERIAL_CONFIG.ports = []; @@ -1046,6 +1048,8 @@ MspHelper.prototype.crunch = function(code) { '115200', '230400', '250000', + '500000', + '1000000' ]; //TODO, instead of lookuptable, this should be sent as uint32 var serialPortFunctions = { 'MSP': 0, @@ -1205,17 +1209,29 @@ MspHelper.prototype.setRawRx = function(channels) { * Send a request to read a block of data from the dataflash at the given address and pass that address and a dataview * of the returned data to the given callback (or null for the data if an error occured). */ -MspHelper.prototype.dataflashRead = function(address, onDataCallback) { - MSP.send_message(MSPCodes.MSP_DATAFLASH_READ, [address & 0xFF, (address >> 8) & 0xFF, (address >> 16) & 0xFF, (address >> 24) & 0xFF], - false, function(response) { +MspHelper.prototype.dataflashRead = function(address, blockSize, onDataCallback) { + var outData = [address & 0xFF, (address >> 8) & 0xFF, (address >> 16) & 0xFF, (address >> 24) & 0xFF]; + + if (semver.gte(CONFIG.flightControllerVersion, "3.1.0")) { + outData = outData.concat([blockSize & 0xFF, (blockSize >> 8) & 0xFF]); + } + + MSP.send_message(MSPCodes.MSP_DATAFLASH_READ, outData, false, function(response) { var chunkAddress = response.data.readU32(); - + + var headerSize = 4; + var dataSize = response.data.buffer.byteLength - headerSize; + if (semver.gte(CONFIG.flightControllerVersion, "3.1.0")) { + headerSize = headerSize + 2; + dataSize = response.data.readU16(); + } + // Verify that the address of the memory returned matches what the caller asked for if (chunkAddress == address) { /* Strip that address off the front of the reply and deliver it separately so the caller doesn't have to * figure out the reply format: */ - onDataCallback(address, new DataView(response.data.buffer, response.data.byteOffset + 4, response.data.buffer.byteLength - 4)); + onDataCallback(address, new DataView(response.data.buffer, response.data.byteOffset + headerSize, dataSize)); } else { // Report error onDataCallback(address, null); diff --git a/js/serial_backend.js b/js/serial_backend.js index 6bbbb1db..9b75924b 100755 --- a/js/serial_backend.js +++ b/js/serial_backend.js @@ -110,7 +110,7 @@ $(document).ready(function () { $('input.auto_connect').prop('checked', true); $('input.auto_connect, span.auto_connect').prop('title', chrome.i18n.getMessage('autoConnectEnabled')); - $('select#baud').val(115200).prop('disabled', true); + $('select#baud').val(500000).prop('disabled', true); } else { // disabled by user GUI.auto_connect = false; @@ -127,7 +127,7 @@ $(document).ready(function () { if (GUI.auto_connect) { $('input.auto_connect, span.auto_connect').prop('title', chrome.i18n.getMessage('autoConnectEnabled')); - $('select#baud').val(115200).prop('disabled', true); + $('select#baud').val(500000).prop('disabled', true); } else { $('input.auto_connect, span.auto_connect').prop('title', chrome.i18n.getMessage('autoConnectDisabled')); diff --git a/main.html b/main.html index 47f0fc23..00df20d7 100755 --- a/main.html +++ b/main.html @@ -116,7 +116,10 @@