From c423aaf44d38fa2a03c0a4f43b86fd884c640580 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Fri, 27 Feb 2015 01:15:37 +0000 Subject: [PATCH] work-in-progress changes to go with the corresponding serial-cleanup firmware branch. --- _locales/en/messages.json | 2 +- js/msp.js | 110 +++++++++++++++++++++++++------------- tabs/configuration.js | 36 +++++++++---- tabs/ports.css | 8 +++ tabs/ports.html | 27 ++++++++-- tabs/ports.js | 106 +++++++++++++++++++++++++++--------- 6 files changed, 213 insertions(+), 76 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 969a1a0a..001ae687 100755 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -507,7 +507,7 @@ }, "portsHelp": { - "message": "Configure serial ports. Note: that not all ports support all scenarios and not all combinations of scenarios are valid. When the flight controller firmware detects this the serial port configuration will be reset." + "message": "Configure serial ports. Note: not all combinations are valid. When the flight controller firmware detects this the serial port configuration will be reset." }, "portsButtonSave": { "message": "Save and Reboot" diff --git a/js/msp.js b/js/msp.js index 1fea8bb3..355af7cc 100644 --- a/js/msp.js +++ b/js/msp.js @@ -102,6 +102,15 @@ var MSP = { ledDirectionLetters: ['n', 'e', 's', 'w', 'u', 'd'], // in LSB bit order ledFunctionLetters: ['i', 'w', 'f', 'a', 't', 'r', 'c'], // in LSB bit order + supportedBaudRates: [ // 0 based index. + 'AUTO', + '9600', + '19200', + '38400', + '57600', + '115200' + ], + read: function (readInfo) { var data = new Uint8Array(readInfo.data); @@ -557,24 +566,46 @@ var MSP = { break; case MSP_codes.MSP_CF_SERIAL_CONFIG: - SERIAL_CONFIG.ports = []; - var offset = 0; - var serialPortCount = (data.byteLength - (4 * 4)) / 2; - for (var i = 0; i < serialPortCount; i++) { - var serialPort = { - identifier: data.getUint8(offset++, 1), - scenario: data.getUint8(offset++, 1) + + if (CONFIG.apiVersion < 1.6) { + SERIAL_CONFIG.ports = []; + var offset = 0; + var serialPortCount = (data.byteLength - (4 * 4)) / 2; + for (var i = 0; i < serialPortCount; i++) { + var serialPort = { + identifier: data.getUint8(offset++, 1), + scenario: data.getUint8(offset++, 1) + } + SERIAL_CONFIG.ports.push(serialPort); + } + SERIAL_CONFIG.mspBaudRate = data.getUint32(offset, 1); + offset+= 4; + SERIAL_CONFIG.cliBaudRate = data.getUint32(offset, 1); + offset+= 4; + SERIAL_CONFIG.gpsBaudRate = data.getUint32(offset, 1); + offset+= 4; + SERIAL_CONFIG.gpsPassthroughBaudRate = data.getUint32(offset, 1); + offset+= 4; + } else { + SERIAL_CONFIG.ports = []; + var offset = 0; + var bytesPerPort = 1 + 2 + (1 * 4); + var serialPortCount = data.byteLength / bytesPerPort; + + for (var i = 0; i < serialPortCount; i++) { + var serialPort = { + identifier: data.getUint8(offset, 1), + functionMask: data.getUint16(offset + 1, 1), + msp_baudrate: MSP.supportedBaudRates[data.getUint8(offset + 3, 1)], + gps_baudrate: MSP.supportedBaudRates[data.getUint8(offset + 4, 1)], + telemetry_baudrate: MSP.supportedBaudRates[data.getUint8(offset + 5, 1)], + blackbox_baudrate: MSP.supportedBaudRates[data.getUint8(offset + 6, 1)] + } + + offset += bytesPerPort; + SERIAL_CONFIG.ports.push(serialPort); } - SERIAL_CONFIG.ports.push(serialPort); } - SERIAL_CONFIG.mspBaudRate = data.getUint32(offset, 1); - offset+= 4; - SERIAL_CONFIG.cliBaudRate = data.getUint32(offset, 1); - offset+= 4; - SERIAL_CONFIG.gpsBaudRate = data.getUint32(offset, 1); - offset+= 4; - SERIAL_CONFIG.gpsPassthroughBaudRate = data.getUint32(offset, 1); - offset+= 4; break; case MSP_codes.MSP_SET_CF_SERIAL_CONFIG: @@ -952,28 +983,33 @@ MSP.crunch = function (code) { } break; case MSP_codes.MSP_SET_CF_SERIAL_CONFIG: - for (var i = 0; i < SERIAL_CONFIG.ports.length; i++) { - buffer.push(SERIAL_CONFIG.ports[i].scenario); + if (CONFIG.apiVersion < 1.6) { + + for (var i = 0; i < SERIAL_CONFIG.ports.length; i++) { + buffer.push(SERIAL_CONFIG.ports[i].scenario); + } + buffer.push(specificByte(SERIAL_CONFIG.mspBaudRate, 0)); + buffer.push(specificByte(SERIAL_CONFIG.mspBaudRate, 1)); + buffer.push(specificByte(SERIAL_CONFIG.mspBaudRate, 2)); + buffer.push(specificByte(SERIAL_CONFIG.mspBaudRate, 3)); + + buffer.push(specificByte(SERIAL_CONFIG.cliBaudRate, 0)); + buffer.push(specificByte(SERIAL_CONFIG.cliBaudRate, 1)); + buffer.push(specificByte(SERIAL_CONFIG.cliBaudRate, 2)); + buffer.push(specificByte(SERIAL_CONFIG.cliBaudRate, 3)); + + buffer.push(specificByte(SERIAL_CONFIG.gpsBaudRate, 0)); + buffer.push(specificByte(SERIAL_CONFIG.gpsBaudRate, 1)); + buffer.push(specificByte(SERIAL_CONFIG.gpsBaudRate, 2)); + buffer.push(specificByte(SERIAL_CONFIG.gpsBaudRate, 3)); + + buffer.push(specificByte(SERIAL_CONFIG.gpsPassthroughBaudRate, 0)); + buffer.push(specificByte(SERIAL_CONFIG.gpsPassthroughBaudRate, 1)); + buffer.push(specificByte(SERIAL_CONFIG.gpsPassthroughBaudRate, 2)); + buffer.push(specificByte(SERIAL_CONFIG.gpsPassthroughBaudRate, 3)); + } else { + console.log('unsupported'); } - buffer.push(specificByte(SERIAL_CONFIG.mspBaudRate, 0)); - buffer.push(specificByte(SERIAL_CONFIG.mspBaudRate, 1)); - buffer.push(specificByte(SERIAL_CONFIG.mspBaudRate, 2)); - buffer.push(specificByte(SERIAL_CONFIG.mspBaudRate, 3)); - - buffer.push(specificByte(SERIAL_CONFIG.cliBaudRate, 0)); - buffer.push(specificByte(SERIAL_CONFIG.cliBaudRate, 1)); - buffer.push(specificByte(SERIAL_CONFIG.cliBaudRate, 2)); - buffer.push(specificByte(SERIAL_CONFIG.cliBaudRate, 3)); - - buffer.push(specificByte(SERIAL_CONFIG.gpsBaudRate, 0)); - buffer.push(specificByte(SERIAL_CONFIG.gpsBaudRate, 1)); - buffer.push(specificByte(SERIAL_CONFIG.gpsBaudRate, 2)); - buffer.push(specificByte(SERIAL_CONFIG.gpsBaudRate, 3)); - - buffer.push(specificByte(SERIAL_CONFIG.gpsPassthroughBaudRate, 0)); - buffer.push(specificByte(SERIAL_CONFIG.gpsPassthroughBaudRate, 1)); - buffer.push(specificByte(SERIAL_CONFIG.gpsPassthroughBaudRate, 2)); - buffer.push(specificByte(SERIAL_CONFIG.gpsPassthroughBaudRate, 3)); break; default: diff --git a/tabs/configuration.js b/tabs/configuration.js index 19ac62ef..2bbaea16 100644 --- a/tabs/configuration.js +++ b/tabs/configuration.js @@ -15,7 +15,11 @@ TABS.configuration.initialize = function (callback, scrollPosition) { } function load_serial_config() { - MSP.send_message(MSP_codes.MSP_CF_SERIAL_CONFIG, false, false, load_rc_map); + if (CONFIG.apiVersion < 1.6) { + MSP.send_message(MSP_codes.MSP_CF_SERIAL_CONFIG, false, false, load_rc_map); + } else { + load_rc_map(); + } } function load_rc_map() { @@ -148,15 +152,25 @@ TABS.configuration.initialize = function (callback, scrollPosition) { MISC.gps_type = parseInt($(this).val()); }); + gps_protocol_e.val(MISC.gps_type); + + var gps_baudrate_e = $('select.gps_baudrate'); for (var i = 0; i < gpsBaudRates.length; i++) { gps_baudrate_e.append(''); } - - gps_baudrate_e.change(function () { - SERIAL_CONFIG.gpsBaudRate = parseInt($(this).val()); - }); - + + if (CONFIG.apiVersion < 1.6) { + gps_baudrate_e.change(function () { + SERIAL_CONFIG.gpsBaudRate = parseInt($(this).val()); + }); + gps_baudrate_e.val(SERIAL_CONFIG.gpsBaudRate); + } else { + gps_baudrate_e.prop("disabled", true); + gps_baudrate_e.parent().hide(); + } + + var gps_ubx_sbas_e = $('select.gps_ubx_sbas'); for (var i = 0; i < gpsSbas.length; i++) { gps_ubx_sbas_e.append(''); @@ -166,11 +180,9 @@ TABS.configuration.initialize = function (callback, scrollPosition) { MISC.gps_ubx_sbas = parseInt($(this).val()); }); - // select current gps configuration - gps_protocol_e.val(MISC.gps_type); - gps_baudrate_e.val(SERIAL_CONFIG.gpsBaudRate); gps_ubx_sbas_e.val(MISC.gps_ubx_sbas); + // generate serial RX var serialRXtypes = [ 'SPEKTRUM1024', @@ -290,7 +302,11 @@ TABS.configuration.initialize = function (callback, scrollPosition) { MISC.multiwiicurrentoutput = ~~$('input[name="multiwiicurrentoutput"]').is(':checked'); // ~~ boolean to decimal conversion function save_serial_config() { - MSP.send_message(MSP_codes.MSP_SET_CF_SERIAL_CONFIG, MSP.crunch(MSP_codes.MSP_SET_CF_SERIAL_CONFIG), false, save_misc); + if (CONFIG.apiVersion < 1.6) { + MSP.send_message(MSP_codes.MSP_SET_CF_SERIAL_CONFIG, MSP.crunch(MSP_codes.MSP_SET_CF_SERIAL_CONFIG), false, save_misc); + } else { + save_misc(); + } } function save_misc() { diff --git a/tabs/ports.css b/tabs/ports.css index b841ce8f..ab0c4204 100644 --- a/tabs/ports.css +++ b/tabs/ports.css @@ -35,6 +35,14 @@ background-color: #ececec; } +.tab-ports .function input { + vertical-align: -2px; +} + +.tab-ports .function label { + margin-right: 5px; +} + .tab-ports select { border: 1px solid silver; } diff --git a/tabs/ports.html b/tabs/ports.html index f2804468..8989fe89 100644 --- a/tabs/ports.html +++ b/tabs/ports.html @@ -7,7 +7,11 @@ Identifier - Scenario + Data + Logging + Telemetry + RX + GPS @@ -28,8 +32,25 @@

- - + + + + + + + + + + + + + diff --git a/tabs/ports.js b/tabs/ports.js index 45d9632f..cbbaa6fd 100644 --- a/tabs/ports.js +++ b/tabs/ports.js @@ -6,7 +6,49 @@ TABS.ports.initialize = function (callback, scrollPosition) { var self = this; var board_definition = {}; - + + var functionRules = [ + {name: 'MSP', groups: ['data', 'msp'], maxPorts: 2}, + {name: 'GPS', groups: ['gps'], maxPorts: 1}, + {name: 'FrSky', groups: ['telemetry'], sharableWith: ['msp'], notSharableWith: ['blackbox'], maxPorts: 1}, + {name: 'HoTT', groups: ['telemetry'], sharableWith: ['msp'], notSharableWith: ['blackbox'], maxPorts: 1}, + {name: 'MSP', groups: ['telemetry'], sharableWith: ['msp'], notSharableWith: ['blackbox'], maxPorts: 1}, + {name: 'SmartPort', groups: ['telemetry'], maxPorts: 1}, + {name: 'Serial RX', groups: ['rx'], maxPorts: 1}, + {name: 'Blackbox', groups: ['logging', 'blackbox'], sharableWith: ['msp'], notSharableWith: ['telemetry'], maxPorts: 1}, + ]; + + var mspBaudRates = [ + '9600', + '19200', + '38400', + '57600', + '115200' + ]; + + var gpsBaudRates = [ + '9600', + '19200', + '38400', + '57600', + '115200' + ]; + + var telemetryBaudRates = [ + 'AUTO', + '9600', + '19200', + '38400', + '57600', + '115200' + ]; + + var blackboxBaudRates = [ + '115200' + ]; + + var columns = ['data', 'logging', 'gps', 'telemetry', 'rx']; + if (GUI.active_tab != 'ports') { GUI.active_tab = 'ports'; googleAnalytics.sendAppView('Ports'); @@ -25,22 +67,8 @@ TABS.ports.initialize = function (callback, scrollPosition) { } } - function addSerialPortScenarios() { + function update_ui() { - var scenarioNames = [ - 'Unused', - 'MSP, CLI, Telemetry (when armed), GPS Passthrough', - 'GPS', - 'Serial RX', - 'Telemetry', - 'MSP, CLI, GPS Passthrough', - 'CLI', - 'GPS Passthrough', - 'MSP', - 'SmartPort Telemetry', - 'Blackbox', - 'MSP, CLI, Blackbox (when armed), GPS Passthrough' - ]; var portIdentifierToNameMapping = { 0: 'UART1', @@ -51,13 +79,40 @@ TABS.ports.initialize = function (callback, scrollPosition) { 30: 'SOFTSERIAL1', 31: 'SOFTSERIAL2' }; - - var scenario_e = $('#tab-ports-templates select.scenario'); - - for (var i = 0; i < scenarioNames.length; i++) { - scenario_e.append(''); + + var gps_baudrate_e = $('select.gps_baudrate'); + for (var i = 0; i < gpsBaudRates.length; i++) { + gps_baudrate_e.append(''); } - + + var msp_baudrate_e = $('select.msp_baudrate'); + for (var i = 0; i < mspBaudRates.length; i++) { + msp_baudrate_e.append(''); + } + + var telemetry_baudrate_e = $('select.telemetry_baudrate'); + for (var i = 0; i < telemetryBaudRates.length; i++) { + telemetry_baudrate_e.append(''); + } + + var blackbox_baudrate_e = $('select.blackbox_baudrate'); + for (var i = 0; i < blackboxBaudRates.length; i++) { + blackbox_baudrate_e.append(''); + } + + for (var columnIndex = 0; columnIndex < columns.length; columnIndex++) { + var column = columns[columnIndex]; + + var functions_e = $('#tab-ports-templates .functionsCell-' + column); + + for (var i = 0; i < functionRules.length; i++) { + if (functionRules[i].groups.indexOf(column) >= 0) { + functions_e.prepend(''); + } + + } + } + var ports_e = $('.tab-ports .ports'); var port_configuration_template_e = $('#tab-ports-templates .portConfiguration'); @@ -65,8 +120,9 @@ TABS.ports.initialize = function (callback, scrollPosition) { var port_configuration_e = port_configuration_template_e.clone(); var serialPort = SERIAL_CONFIG.ports[portIndex]; - - port_configuration_e.find('select').val(serialPort.scenario); + + // TODO check functions + // TODO set baudrate port_configuration_e.find('.identifier').text(portIdentifierToNameMapping[serialPort.identifier]) port_configuration_e.data('index', portIndex); @@ -80,7 +136,7 @@ TABS.ports.initialize = function (callback, scrollPosition) { localize(); - addSerialPortScenarios(); + update_ui(); $('a.save').click(on_save_handler);