From 8aa40f1a2c3cfe560aa3c0268872e132abde5442 Mon Sep 17 00:00:00 2001 From: Bas Delfos Date: Fri, 18 Nov 2016 00:34:31 +0100 Subject: [PATCH] Added configuration of KISS ESC Telemetry --- _locales/en/messages.json | 26 +++-- js/Features.js | 3 +- js/msp/MSPHelper.js | 195 +++++++++++++++++++------------------- tabs/ports.js | 55 +++++------ 4 files changed, 144 insertions(+), 135 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 3894b26f..581f08df 100755 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -527,6 +527,9 @@ "featureBLACKBOXTip": { "message": "Configure via the BlackBox tab after enabling." }, + "featureESC_TELEMETRY": { + "message": "KISS ESC 24A telemetry support" + }, "featureCHANNEL_FORWARDING": { "message": "Forward aux channels to servo outputs" }, @@ -777,6 +780,9 @@ "portsFunction_TELEMETRY_SMARTPORT": { "message": "SmartPort" }, + "portsFunction_TELEMETRY_ESC": { + "message": "ESC telemetry" + }, "portsFunction_RX_SERIAL": { "message": "Serial RX" }, @@ -1114,7 +1120,7 @@ "adjustmentsFunction21": { "message": "RC Rate Yaw" }, - + "adjustmentsSave": { "message": "Save" }, @@ -1857,25 +1863,25 @@ "message": "Blackbox logging device" }, "onboardLoggingRateOfLogging": { - "message": "Blackbox logging rate" + "message": "Blackbox logging rate" }, "onboardLoggingSerialLogger": { - "message": "Outboard serial logging device" + "message": "Outboard serial logging device" }, "onboardLoggingFlashLogger": { - "message": "Onboard dataflash chip" + "message": "Onboard dataflash chip" }, "onboardLoggingEraseInProgress": { - "message": "Erase in progress, please wait..." + "message": "Erase in progress, please wait..." }, "onboardLoggingOnboardSDCard": { "message": "Onboard SD card" } - - - - - + + + + + diff --git a/js/Features.js b/js/Features.js index f4294948..925f9142 100644 --- a/js/Features.js +++ b/js/Features.js @@ -21,7 +21,8 @@ var Features = function (config) { {bit: 15, group: 'rssi', name: 'RSSI_ADC'}, {bit: 16, group: 'other', name: 'LED_STRIP'}, {bit: 17, group: 'other', name: 'DISPLAY'}, - {bit: 19, group: 'other', name: 'BLACKBOX', haveTip: true} + {bit: 19, group: 'other', name: 'BLACKBOX', haveTip: true}, + {bit: 27, group: 'other', name: 'ESC_TELEMETRY'} ]; if (semver.gte(config.apiVersion, "1.12.0")) { diff --git a/js/msp/MSPHelper.js b/js/msp/MSPHelper.js index e4f48f05..ed890c28 100644 --- a/js/msp/MSPHelper.js +++ b/js/msp/MSPHelper.js @@ -20,13 +20,14 @@ function MspHelper () { 'RX_SERIAL': 6, 'BLACKBOX': 7, 'TELEMETRY_MAVLINK': 8, + 'TELEMETRY_ESC': 10 }; } MspHelper.prototype.process_data = function(dataHandler) { var self = this; var data = dataHandler.dataView; // DataView (allowing us to view arrayBuffer as struct/union) - var code = dataHandler.code; + var code = dataHandler.code; if (!dataHandler.unsupported) switch (code) { case MSPCodes.MSP_STATUS: CONFIG.cycleTime = data.readU16(); @@ -60,7 +61,7 @@ MspHelper.prototype.process_data = function(dataHandler) { $('span.cycle-time').text(CONFIG.cycleTime); $('span.cpu-load').text(chrome.i18n.getMessage('statusbar_cpu_load', [CONFIG.cpuload])); break; - + case MSPCodes.MSP_RAW_IMU: // 512 for mpu6050, 256 for mma // currently we are unable to differentiate between the sensor types, so we are goign with 512 @@ -192,11 +193,11 @@ MspHelper.prototype.process_data = function(dataHandler) { MISC.gps_ubx_sbas = data.readU8(); MISC.multiwiicurrentoutput = data.readU8(); MISC.rssi_channel = data.readU8(); - MISC.placeholder2 = data.readU8(); + MISC.placeholder2 = data.readU8(); if (semver.lt(CONFIG.apiVersion, "1.18.0")) MISC.mag_declination = data.read16() / 10; // -1800-1800 else - MISC.mag_declination = data.read16() / 100; // -18000-18000 + MISC.mag_declination = data.read16() / 100; // -18000-18000 MISC.vbatscale = data.readU8(); // 10-200 MISC.vbatmincellvoltage = data.readU8() / 10; // 10-50 MISC.vbatmaxcellvoltage = data.readU8() / 10; // 10-50 @@ -289,12 +290,12 @@ MspHelper.prototype.process_data = function(dataHandler) { SERVO_CONFIG.push(arr); } } - + if (semver.eq(CONFIG.apiVersion, '1.10.0')) { // drop two unused servo configurations due to MSP rx buffer to small) while (SERVO_CONFIG.length > 8) { SERVO_CONFIG.pop(); - } + } } } break; @@ -302,7 +303,7 @@ MspHelper.prototype.process_data = function(dataHandler) { RC_deadband.deadband = data.readU8(); RC_deadband.yaw_deadband = data.readU8(); RC_deadband.alt_hold_deadband = data.readU8(); - + if (semver.gte(CONFIG.apiVersion, "1.17.0")) { _3D.deadband3d_throttle = data.readU16(); } @@ -403,7 +404,7 @@ MspHelper.prototype.process_data = function(dataHandler) { break; case MSPCodes.MSP_API_VERSION: - CONFIG.mspProtocolVersion = data.readU8(); + CONFIG.mspProtocolVersion = data.readU8(); CONFIG.apiVersion = data.readU8() + '.' + data.readU8() + '.0'; break; @@ -426,7 +427,7 @@ MspHelper.prototype.process_data = function(dataHandler) { buff.push(data.readU8()); } buff.push(32); // ascii space - + var timeLength = 8; for (var i = 0; i < timeLength; i++) { buff.push(data.readU8()); @@ -464,7 +465,7 @@ MspHelper.prototype.process_data = function(dataHandler) { identifier: data.readU8(), scenario: data.readU8() } - SERIAL_CONFIG.ports.push(serialPort); + SERIAL_CONFIG.ports.push(serialPort); } SERIAL_CONFIG.mspBaudRate = data.readU32(); SERIAL_CONFIG.cliBaudRate = data.readU32(); @@ -474,7 +475,7 @@ MspHelper.prototype.process_data = function(dataHandler) { SERIAL_CONFIG.ports = []; var bytesPerPort = 1 + 2 + (1 * 4); var serialPortCount = data.byteLength / bytesPerPort; - + for (var i = 0; i < serialPortCount; i++) { var serialPort = { identifier: data.readU8(), @@ -484,7 +485,7 @@ MspHelper.prototype.process_data = function(dataHandler) { telemetry_baudrate: self.BAUD_RATES[data.readU8()], blackbox_baudrate: self.BAUD_RATES[data.readU8()] } - + SERIAL_CONFIG.ports.push(serialPort); } } @@ -498,7 +499,7 @@ MspHelper.prototype.process_data = function(dataHandler) { MODE_RANGES = []; // empty the array as new data is coming in var modeRangeCount = data.byteLength / 4; // 4 bytes per item. - + for (var i = 0; i < modeRangeCount; i++) { var modeRange = { id: data.readU8(), @@ -516,7 +517,7 @@ MspHelper.prototype.process_data = function(dataHandler) { ADJUSTMENT_RANGES = []; // empty the array as new data is coming in var adjustmentRangeCount = data.byteLength / 6; // 6 bytes per item. - + for (var i = 0; i < adjustmentRangeCount; i++) { var adjustmentRange = { slotIndex: data.readU8(), @@ -644,25 +645,25 @@ MspHelper.prototype.process_data = function(dataHandler) { SENSOR_CONFIG.baro_hardware = data.readU8(); SENSOR_CONFIG.mag_hardware = data.readU8(); break; - + case MSPCodes.MSP_LED_STRIP_CONFIG: LED_STRIP = []; - + var ledDirectionLetters = ['n', 'e', 's', 'w', 'u', 'd']; // in LSB bit order var ledFunctionLetters = ['i', 'w', 'f', 'a', 't', 'r', 'c', 'g', 's', 'b', 'l']; // in LSB bit order - var ledBaseFunctionLetters = ['c', 'f', 'a', 'l', 's', 'g', 'r']; // in LSB bit - var ledOverlayLetters = ['t', 'o', 'b', 'n', 'i', 'w']; // in LSB bit + var ledBaseFunctionLetters = ['c', 'f', 'a', 'l', 's', 'g', 'r']; // in LSB bit + var ledOverlayLetters = ['t', 'o', 'b', 'n', 'i', 'w']; // in LSB bit + - var ledCount = data.byteLength / 7; // v1.4.0 and below incorrectly reported 4 bytes per led. if (semver.gte(CONFIG.apiVersion, "1.20.0")) ledCount = data.byteLength / 4; - + for (var i = 0; i < ledCount; i++) { if (semver.lt(CONFIG.apiVersion, "1.20.0")) { var directionMask = data.readU16(); - + var directions = []; for (var directionLetterIndex = 0; directionLetterIndex < ledDirectionLetters.length; directionLetterIndex++) { if (bit_check(directionMask, directionLetterIndex)) { @@ -671,14 +672,14 @@ MspHelper.prototype.process_data = function(dataHandler) { } var functionMask = data.readU16(); - + var functions = []; for (var functionLetterIndex = 0; functionLetterIndex < ledFunctionLetters.length; functionLetterIndex++) { if (bit_check(functionMask, functionLetterIndex)) { functions.push(ledFunctionLetters[functionLetterIndex]); } } - + var led = { directions: directions, functions: functions, @@ -686,11 +687,11 @@ MspHelper.prototype.process_data = function(dataHandler) { y: data.readU8(), color: data.readU8() }; - + LED_STRIP.push(led); } else { var mask = data.readU32(); - + var functionId = (mask >> 8) & 0xF; var functions = []; for (var baseFunctionLetterIndex = 0; baseFunctionLetterIndex < ledBaseFunctionLetters.length; baseFunctionLetterIndex++) { @@ -699,14 +700,14 @@ MspHelper.prototype.process_data = function(dataHandler) { break; } } - + var overlayMask = (mask >> 12) & 0x3F; for (var overlayLetterIndex = 0; overlayLetterIndex < ledOverlayLetters.length; overlayLetterIndex++) { if (bit_check(overlayMask, overlayLetterIndex)) { functions.push(ledOverlayLetters[overlayLetterIndex]); } } - + var directionMask = (mask >> 22) & 0x3F; var directions = []; for (var directionLetterIndex = 0; directionLetterIndex < ledDirectionLetters.length; directionLetterIndex++) { @@ -722,7 +723,7 @@ MspHelper.prototype.process_data = function(dataHandler) { directions: directions, parameters: (mask >> 28) & 0xF }; - + LED_STRIP.push(led); } } @@ -731,11 +732,11 @@ MspHelper.prototype.process_data = function(dataHandler) { console.log('Led strip config saved'); break; case MSPCodes.MSP_LED_COLORS: - + LED_COLORS = []; - + var colorCount = data.byteLength / 4; - + for (var i = 0; i < colorCount; i++) { var color = { @@ -745,7 +746,7 @@ MspHelper.prototype.process_data = function(dataHandler) { }; LED_COLORS.push(color); } - + break; case MSPCodes.MSP_SET_LED_COLORS: console.log('Led strip colors saved'); @@ -754,9 +755,9 @@ MspHelper.prototype.process_data = function(dataHandler) { if (semver.gte(CONFIG.apiVersion, "1.19.0")) { LED_MODE_COLORS = []; - + var colorCount = data.byteLength / 3; - + for (var i = 0; i < colorCount; i++) { var mode_color = { @@ -797,8 +798,8 @@ MspHelper.prototype.process_data = function(dataHandler) { console.log("Data flash erase begun..."); break; case MSPCodes.MSP_SDCARD_SUMMARY: - var flags = data.readU8(); - + var flags = data.readU8(); + SDCARD.supported = (flags & 0x01) != 0; SDCARD.state = data.readU8(); SDCARD.filesystemLastError = data.readU8(); @@ -817,7 +818,7 @@ MspHelper.prototype.process_data = function(dataHandler) { case MSPCodes.MSP_TRANSPONDER_CONFIG: TRANSPONDER.supported = (data.readU8() & 1) != 0; TRANSPONDER.data = []; - var bytesRemaining = data.byteLength - 1; + var bytesRemaining = data.byteLength - 1; for (var i = 0; i < bytesRemaining; i++) { TRANSPONDER.data.push(data.readU8()); } @@ -831,7 +832,7 @@ MspHelper.prototype.process_data = function(dataHandler) { case MSPCodes.MSP_SET_ADJUSTMENT_RANGE: console.log('Adjustment range saved'); break; - + case MSPCodes.MSP_PID_CONTROLLER: PID.controller = data.readU8(); break; @@ -855,7 +856,7 @@ MspHelper.prototype.process_data = function(dataHandler) { break; case MSPCodes.MSP_SET_SENSOR_ALIGNMENT: console.log('Sensor alignment saved'); - break; + break; case MSPCodes.MSP_SET_RX_CONFIG: console.log('Rx config saved'); break; @@ -997,7 +998,7 @@ MspHelper.prototype.crunch = function(code) { .push8(MISC.placeholder2); if (semver.lt(CONFIG.apiVersion, "1.18.0")) { buffer.push16(Math.round(MISC.mag_declination * 10)); - } else { + } else { buffer.push16(Math.round(MISC.mag_declination * 100)); } buffer.push8(MISC.vbatscale) @@ -1061,9 +1062,9 @@ MspHelper.prototype.crunch = function(code) { } else { for (var i = 0; i < SERIAL_CONFIG.ports.length; i++) { var serialPort = SERIAL_CONFIG.ports[i]; - + buffer.push8(serialPort.identifier); - + var functionMask = self.serialPortFunctionsToMask(serialPort.functions); buffer.push16(functionMask) .push8(self.BAUD_RATES.indexOf(serialPort.msp_baudrate)) @@ -1081,11 +1082,11 @@ MspHelper.prototype.crunch = function(code) { if (semver.lt(CONFIG.apiVersion, "1.17.0")) { buffer.push16(_3D.deadband3d_throttle); } - break; + break; case MSPCodes.MSP_SET_RC_DEADBAND: buffer.push8(RC_deadband.deadband) - .push8(RC_deadband.yaw_deadband) + .push8(RC_deadband.yaw_deadband) .push8(RC_deadband.alt_hold_deadband); if (semver.gte(CONFIG.apiVersion, "1.17.0")) { buffer.push16(_3D.deadband3d_throttle); @@ -1158,20 +1159,20 @@ MspHelper.prototype.crunch = function(code) { .push8(SENSOR_CONFIG.baro_hardware) .push8(SENSOR_CONFIG.mag_hardware); break; - + case MSPCodes.MSP_SET_NAME: var MSP_BUFFER_SIZE = 64; for (var i = 0; i= 0) { @@ -1445,19 +1446,19 @@ MspHelper.prototype.sendLedStripConfig = function(onCompleteCallback) { mask |= bit_set(mask, bitIndex + 22); } } - + mask |= (0 << 28); // parameters - - + + buffer.push32(mask); } - + // prepare for next iteration ledIndex++; if (ledIndex == LED_STRIP.length) { nextFunction = onCompleteCallback; } - + MSP.send_message(MSPCodes.MSP_SET_LED_STRIP_CONFIG, buffer, false, nextFunction); } } @@ -1467,10 +1468,10 @@ MspHelper.prototype.sendLedStripColors = function(onCompleteCallback) { onCompleteCallback(); } else { var buffer = []; - + for (var colorIndex = 0; colorIndex < LED_COLORS.length; colorIndex++) { var color = LED_COLORS[colorIndex]; - + buffer.push16(color.h) .push8(color.s) .push8(color.v); @@ -1480,21 +1481,21 @@ MspHelper.prototype.sendLedStripColors = function(onCompleteCallback) { } MspHelper.prototype.sendLedStripModeColors = function(onCompleteCallback) { - - var nextFunction = send_next_led_strip_mode_color; + + var nextFunction = send_next_led_strip_mode_color; var index = 0; - + if (LED_MODE_COLORS.length == 0) { onCompleteCallback(); } else { send_next_led_strip_mode_color(); } - + function send_next_led_strip_mode_color() { var buffer = []; - + var mode_color = LED_MODE_COLORS[index]; - + buffer.push8(mode_color.mode) .push8(mode_color.direction) .push8(mode_color.color); @@ -1527,7 +1528,7 @@ MspHelper.prototype.serialPortFunctionMaskToFunctions = function(functionMask) { MspHelper.prototype.serialPortFunctionsToMask = function(functions) { var self = this; var mask = 0; - + var keys = Object.keys(self.SERIAL_PORT_FUNCTIONS); for (var index = 0; index < functions.length; index++) { var key = functions[index]; @@ -1558,7 +1559,7 @@ MspHelper.prototype.sendRxFailConfig = function(onCompleteCallback) { buffer.push8(rxFailIndex) .push8(rxFail.mode) .push16(rxFail.value); - + // prepare for next iteration rxFailIndex++; diff --git a/tabs/ports.js b/tabs/ports.js index 52e115a2..21189b62 100644 --- a/tabs/ports.js +++ b/tabs/ports.js @@ -13,6 +13,7 @@ TABS.ports.initialize = function (callback, scrollPosition) { {name: 'TELEMETRY_FRSKY', groups: ['telemetry'], sharableWith: ['msp'], notSharableWith: ['blackbox'], maxPorts: 1}, {name: 'TELEMETRY_HOTT', groups: ['telemetry'], sharableWith: ['msp'], notSharableWith: ['blackbox'], maxPorts: 1}, {name: 'TELEMETRY_SMARTPORT', groups: ['telemetry'], maxPorts: 1}, + {name: 'TELEMETRY_ESC', groups: ['telemetry'], maxPorts: 1}, {name: 'RX_SERIAL', groups: ['rx'], maxPorts: 1}, {name: 'BLACKBOX', groups: ['logging', 'blackbox'], sharableWith: ['msp'], notSharableWith: ['telemetry'], maxPorts: 1}, ]; @@ -81,28 +82,28 @@ TABS.ports.initialize = function (callback, scrollPosition) { } load_configuration_from_fc(); - + function load_configuration_from_fc() { MSP.send_message(MSPCodes.MSP_CF_SERIAL_CONFIG, false, false, on_configuration_loaded_handler); - + function on_configuration_loaded_handler() { $('#content').load("./tabs/ports.html", on_tab_loaded_handler); - + board_definition = BOARD.find_board_definition(CONFIG.boardIdentifier); console.log('Using board definition', board_definition); } } function update_ui() { - + if (semver.lt(CONFIG.apiVersion, "1.6.0")) { - + $(".tab-ports").removeClass("supported"); return; } - + $(".tab-ports").addClass("supported"); - + var portIdentifierToNameMapping = { 0: 'UART1', 1: 'UART2', @@ -141,13 +142,13 @@ TABS.ports.initialize = function (callback, scrollPosition) { var ports_e = $('.tab-ports .ports'); var port_configuration_template_e = $('#tab-ports-templates .portConfiguration'); - + for (var portIndex = 0; portIndex < SERIAL_CONFIG.ports.length; portIndex++) { var port_configuration_e = port_configuration_template_e.clone(); var serialPort = SERIAL_CONFIG.ports[portIndex]; - + port_configuration_e.data('serialPort', serialPort); - + var msp_baudrate_e = port_configuration_e.find('select.msp_baudrate'); msp_baudrate_e.val(serialPort.msp_baudrate); @@ -161,24 +162,24 @@ TABS.ports.initialize = function (callback, scrollPosition) { blackbox_baudrate_e.val(serialPort.blackbox_baudrate); port_configuration_e.find('.identifier').text(portIdentifierToNameMapping[serialPort.identifier]) - + port_configuration_e.data('index', portIndex); port_configuration_e.data('port', serialPort); for (var columnIndex = 0; columnIndex < columns.length; columnIndex++) { var column = columns[columnIndex]; - + var functions_e = $(port_configuration_e).find('.functionsCell-' + column); - + for (var i = 0; i < functionRules.length; i++) { var functionRule = functionRules[i]; var functionName = functionRule.name; - + if (functionRule.groups.indexOf(column) == -1) { continue; } - + var select_e; if (column != 'telemetry') { var checkboxId = 'functionCheckbox-' + portIndex + '-' + columnIndex + '-' + i; @@ -188,13 +189,13 @@ TABS.ports.initialize = function (callback, scrollPosition) { var checkbox_e = functions_e.find('#' + checkboxId); checkbox_e.prop("checked", true); } - + } else { - + var selectElementName = 'function-' + column; var selectElementSelector = 'select[name=' + selectElementName + ']'; select_e = functions_e.find(selectElementSelector); - + if (select_e.size() == 0) { functions_e.prepend('