1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 16:25:31 +03:00

reorganization of several MSP methods, small optimizations

This commit is contained in:
cTn 2014-09-21 20:31:57 +02:00
parent 47135e2bb8
commit a0ed27c161

View file

@ -73,23 +73,7 @@ var MSP = {
callbacks: [],
packet_error: 0,
callbacks_cleanup: function () {
for (var i = 0; i < this.callbacks.length; i++) {
clearInterval(this.callbacks[i].timer);
}
this.callbacks = [];
},
disconnect_cleanup: function () {
this.state = 0; // reset packet state for "clean" initial entry (this is only required if user hot-disconnects)
this.packet_error = 0; // reset CRC packet error counter for next session
this.callbacks_cleanup();
}
};
MSP.read = function (readInfo) {
read: function (readInfo) {
var data = new Uint8Array(readInfo.data);
for (var i = 0; i < data.length; i++) {
@ -130,9 +114,11 @@ MSP.read = function (readInfo) {
this.code = data[i];
this.message_checksum ^= data[i];
if (this.message_length_expected != 0) { // standard message
if (this.message_length_expected > 0) {
// process payload
this.state++;
} else { // MSP_ACC_CALIBRATION, etc...
} else {
// no payload
this.state += 2;
}
break;
@ -162,9 +148,8 @@ MSP.read = function (readInfo) {
break;
}
}
};
MSP.process_data = function(code, message_buffer, message_length) {
},
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) {
@ -492,16 +477,15 @@ MSP.process_data = function(code, message_buffer, message_length) {
if (callback) callback({'command': code, 'data': data, 'length': message_length});
}
}
};
MSP.send_message = function(code, data, callback_sent, callback_msp) {
var bufferOut;
var bufView;
},
send_message: function (code, data, callback_sent, callback_msp) {
var bufferOut,
bufView;
// always reserve 6 bytes for protocol overhead !
if (data) {
var size = data.length + 6;
var checksum = 0;
var size = data.length + 6,
checksum = 0;
bufferOut = new ArrayBuffer(size);
bufView = new Uint8Array(bufferOut);
@ -557,6 +541,20 @@ MSP.send_message = function(code, data, callback_sent, callback_msp) {
});
return true;
},
callbacks_cleanup: function () {
for (var i = 0; i < this.callbacks.length; i++) {
clearInterval(this.callbacks[i].timer);
}
this.callbacks = [];
},
disconnect_cleanup: function () {
this.state = 0; // reset packet state for "clean" initial entry (this is only required if user hot-disconnects)
this.packet_error = 0; // reset CRC packet error counter for next session
this.callbacks_cleanup();
}
};
MSP.crunch = function (code) {