From 0f95f4ec4c9ae96cf2625174cfdafae94fab1c14 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Thu, 7 May 2015 22:47:32 +0100 Subject: [PATCH] Improve MSP handling of servo configuration. Fixes backup of CJMCU boards. --- js/msp.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/js/msp.js b/js/msp.js index 0a593ffe..55bc0ea2 100644 --- a/js/msp.js +++ b/js/msp.js @@ -434,15 +434,17 @@ var MSP = { case MSP_codes.MSP_SERVO_CONF: SERVO_CONFIG = []; // empty the array as new data is coming in - for (var i = 0; i < 56; i += 7) { - var arr = { - 'min': data.getInt16(i, 1), - 'max': data.getInt16(i + 2, 1), - 'middle': data.getInt16(i + 4, 1), - 'rate': data.getInt8(i + 6) - }; - - SERVO_CONFIG.push(arr); + if (data.byteLength % 7 == 0) { + for (var i = 0; i < data.byteLength; i += 7) { + var arr = { + 'min': data.getInt16(i, 1), + 'max': data.getInt16(i + 2, 1), + 'middle': data.getInt16(i + 4, 1), + 'rate': data.getInt8(i + 6) + }; + + SERVO_CONFIG.push(arr); + } } break; case MSP_codes.MSP_SET_RAW_RC: @@ -688,7 +690,7 @@ var MSP = { } break; case MSP_codes.MSP_CHANNEL_FORWARDING: - for (var i = 0; i < 8; i ++) { + for (var i = 0; i < data.byteLength && i < SERVO_CONFIG.length; i ++) { var channelIndex = data.getUint8(i); if (channelIndex < 255) { SERVO_CONFIG[i].indexOfChannelToForward = channelIndex;