Skip to content

Commit 76a1473

Browse files
committed
Implemented support for MSP jumbo frames, switched dataflash reading to be using jumbo frames.
Set default serial speed to 500000 kbps.
1 parent e61ef7b commit 76a1473

File tree

7 files changed

+86
-25
lines changed

7 files changed

+86
-25
lines changed

js/msp.js

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ var MSP = {
1010
message_buffer: null,
1111
message_buffer_uint8_view: null,
1212
message_checksum: 0,
13+
messageIsJumboFrame: false,
1314

1415
callbacks: [],
1516
packet_error: 0,
1617
unsupported: 0,
1718

1819
last_received_timestamp: null,
1920
listeners: [],
21+
22+
JUMBO_FRAME_SIZE_LIMIT: 255,
2023

2124
read: function (readInfo) {
2225
var data = new Uint8Array(readInfo.data);
@@ -50,13 +53,12 @@ var MSP = {
5053
break;
5154
case 3:
5255
this.message_length_expected = data[i];
56+
if (this.message_length_expected === this.JUMBO_FRAME_SIZE_LIMIT) {
57+
this.messageIsJumboFrame = true;
58+
}
5359

5460
this.message_checksum = data[i];
5561

56-
// setup arraybuffer
57-
this.message_buffer = new ArrayBuffer(this.message_length_expected);
58-
this.message_buffer_uint8_view = new Uint8Array(this.message_buffer);
59-
6062
this.state++;
6163
break;
6264
case 4:
@@ -65,13 +67,39 @@ var MSP = {
6567

6668
if (this.message_length_expected > 0) {
6769
// process payload
68-
this.state++;
70+
if (this.messageIsJumboFrame) {
71+
this.state++;
72+
} else {
73+
this.state = this.state + 3;
74+
}
6975
} else {
7076
// no payload
71-
this.state += 2;
77+
this.state += 5;
7278
}
7379
break;
74-
case 5: // payload
80+
case 5:
81+
this.message_length_expected = data[i];
82+
83+
this.message_checksum ^= data[i];
84+
85+
this.state++;
86+
87+
break;
88+
case 6:
89+
this.message_length_expected = this.message_length_expected + 256 * data[i];
90+
91+
this.message_checksum ^= data[i];
92+
93+
this.state++;
94+
95+
break;
96+
case 7:
97+
// setup arraybuffer
98+
this.message_buffer = new ArrayBuffer(this.message_length_expected);
99+
this.message_buffer_uint8_view = new Uint8Array(this.message_buffer);
100+
101+
this.state++;
102+
case 8: // payload
75103
this.message_buffer_uint8_view[this.message_length_received] = data[i];
76104
this.message_checksum ^= data[i];
77105
this.message_length_received++;
@@ -80,7 +108,7 @@ var MSP = {
80108
this.state++;
81109
}
82110
break;
83-
case 6:
111+
case 9:
84112
if (this.message_checksum == data[i]) {
85113
// message received, store dataview
86114
this.dataView = new DataView(this.message_buffer, 0, this.message_length_expected);
@@ -92,6 +120,7 @@ var MSP = {
92120
// Reset variables
93121
this.message_length_received = 0;
94122
this.state = 0;
123+
this.messageIsJumboFrame = false;
95124
this.notify();
96125
break;
97126

@@ -210,4 +239,4 @@ var MSP = {
210239

211240
this.callbacks_cleanup();
212241
}
213-
};
242+
};

js/msp/MSPHelper.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,8 @@ MspHelper.prototype.process_data = function(dataHandler) {
446446
'115200',
447447
'230400',
448448
'250000',
449+
'500000',
450+
'1000000'
449451
];
450452
if (semver.lt(CONFIG.apiVersion, "1.6.0")) {
451453
SERIAL_CONFIG.ports = [];
@@ -1046,6 +1048,8 @@ MspHelper.prototype.crunch = function(code) {
10461048
'115200',
10471049
'230400',
10481050
'250000',
1051+
'500000',
1052+
'1000000'
10491053
]; //TODO, instead of lookuptable, this should be sent as uint32
10501054
var serialPortFunctions = {
10511055
'MSP': 0,
@@ -1205,17 +1209,29 @@ MspHelper.prototype.setRawRx = function(channels) {
12051209
* Send a request to read a block of data from the dataflash at the given address and pass that address and a dataview
12061210
* of the returned data to the given callback (or null for the data if an error occured).
12071211
*/
1208-
MspHelper.prototype.dataflashRead = function(address, onDataCallback) {
1209-
MSP.send_message(MSPCodes.MSP_DATAFLASH_READ, [address & 0xFF, (address >> 8) & 0xFF, (address >> 16) & 0xFF, (address >> 24) & 0xFF],
1210-
false, function(response) {
1212+
MspHelper.prototype.dataflashRead = function(address, blockSize, onDataCallback) {
1213+
var outData = [address & 0xFF, (address >> 8) & 0xFF, (address >> 16) & 0xFF, (address >> 24) & 0xFF];
1214+
1215+
if (semver.gte(CONFIG.flightControllerVersion, "3.1.0")) {
1216+
outData = outData.concat([blockSize & 0xFF, (blockSize >> 8) & 0xFF]);
1217+
}
1218+
1219+
MSP.send_message(MSPCodes.MSP_DATAFLASH_READ, outData, false, function(response) {
12111220
var chunkAddress = response.data.readU32();
1212-
1221+
1222+
var headerSize = 4;
1223+
var dataSize = response.data.buffer.byteLength - headerSize;
1224+
if (semver.gte(CONFIG.flightControllerVersion, "3.1.0")) {
1225+
headerSize = headerSize + 2;
1226+
dataSize = response.data.readU16();
1227+
}
1228+
12131229
// Verify that the address of the memory returned matches what the caller asked for
12141230
if (chunkAddress == address) {
12151231
/* Strip that address off the front of the reply and deliver it separately so the caller doesn't have to
12161232
* figure out the reply format:
12171233
*/
1218-
onDataCallback(address, new DataView(response.data.buffer, response.data.byteOffset + 4, response.data.buffer.byteLength - 4));
1234+
onDataCallback(address, new DataView(response.data.buffer, response.data.byteOffset + headerSize, dataSize));
12191235
} else {
12201236
// Report error
12211237
onDataCallback(address, null);

js/serial_backend.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ $(document).ready(function () {
110110
$('input.auto_connect').prop('checked', true);
111111
$('input.auto_connect, span.auto_connect').prop('title', chrome.i18n.getMessage('autoConnectEnabled'));
112112

113-
$('select#baud').val(115200).prop('disabled', true);
113+
$('select#baud').val(500000).prop('disabled', true);
114114
} else {
115115
// disabled by user
116116
GUI.auto_connect = false;
@@ -127,7 +127,7 @@ $(document).ready(function () {
127127
if (GUI.auto_connect) {
128128
$('input.auto_connect, span.auto_connect').prop('title', chrome.i18n.getMessage('autoConnectEnabled'));
129129

130-
$('select#baud').val(115200).prop('disabled', true);
130+
$('select#baud').val(500000).prop('disabled', true);
131131
} else {
132132
$('input.auto_connect, span.auto_connect').prop('title', chrome.i18n.getMessage('autoConnectDisabled'));
133133

main.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@
116116
</div>
117117
<div class="dropdown dropdown-dark">
118118
<select class="dropdown-select" id="baud" title="Baud Rate">
119-
<option value="115200" selected="selected">115200</option>
119+
<option value="1000000">1000000</option>
120+
<option value="500000" selected="selected">500000</option>
121+
<option value="250000">250000</option>
122+
<option value="115200">115200</option>
120123
<option value="57600">57600</option>
121124
<option value="38400">38400</option>
122125
<option value="28800">28800</option>

tabs/firmware_flasher.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ TABS.firmware_flasher.initialize = function (callback) {
117117
chrome.storage.local.get('selected_board', function (result) {
118118
if (result.selected_board) {
119119
$('select[name="board"]').val(result.selected_board);
120+
$('select[name="board"]').trigger("change");
120121
}
121122
});
122123
};

tabs/onboard_logging.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ var
44
sdcardTimer;
55

66
TABS.onboard_logging = {
7-
available: false
7+
available: false,
8+
BLOCK_SIZE: 4096
89
};
910
TABS.onboard_logging.initialize = function (callback) {
1011
var
@@ -313,7 +314,12 @@ TABS.onboard_logging.initialize = function (callback) {
313314
$(".dataflash-saving")[0].close();
314315
}
315316

316-
function mark_saving_dialog_done() {
317+
function mark_saving_dialog_done(startTime, totalBytes) {
318+
var totalTime = (new Date().getTime() - startTime) / 1000;
319+
console.log('Received ' + totalBytes + ' bytes in ' + totalTime.toFixed(2) + 's ('
320+
+ (totalBytes / totalTime / 1024).toFixed(2) + 'kB / s) with block size ' + self.BLOCK_SIZE + '.');
321+
322+
317323
$(".dataflash-saving").addClass("done");
318324
}
319325

@@ -356,26 +362,27 @@ TABS.onboard_logging.initialize = function (callback) {
356362
if (saveCancelled) {
357363
dismiss_saving_dialog();
358364
} else {
359-
mark_saving_dialog_done();
365+
mark_saving_dialog_done(startTime, nextAddress);
360366
}
361367
} else {
362-
mspHelper.dataflashRead(nextAddress, onChunkRead);
368+
mspHelper.dataflashRead(nextAddress, self.BLOCK_SIZE, onChunkRead);
363369
}
364370
};
365371

366372
fileWriter.write(blob);
367373
} else {
368374
// A zero-byte block indicates end-of-file, so we're done
369-
mark_saving_dialog_done();
375+
mark_saving_dialog_done(startTime, nextAddress);
370376
}
371377
} else {
372378
// There was an error with the received block (address didn't match the one we asked for), retry
373-
mspHelper.dataflashRead(nextAddress, onChunkRead);
379+
mspHelper.dataflashRead(nextAddress, self.BLOCK_SIZE, onChunkRead);
374380
}
375381
}
376382

383+
var startTime = new Date().getTime();
377384
// Fetch the initial block
378-
mspHelper.dataflashRead(nextAddress, onChunkRead);
385+
mspHelper.dataflashRead(nextAddress, self.BLOCK_SIZE, onChunkRead);
379386
});
380387
});
381388
}

tabs/ports.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ TABS.ports.initialize = function (callback, scrollPosition) {
3939
'19200',
4040
'38400',
4141
'57600',
42-
'115200'
42+
'115200',
43+
'230400',
44+
'250000',
45+
'500000',
46+
'1000000'
47+
4348
];
4449

4550
var gpsBaudRates = [

0 commit comments

Comments
 (0)