From 94aa6c4cfb922cd0a09bcbb4ef03b5a37d68b01b Mon Sep 17 00:00:00 2001 From: floaledm Date: Thu, 22 Sep 2016 13:54:24 -0500 Subject: [PATCH] AP_Frsky_Telem: consolidate into a single frsky.init() --- libraries/AP_Frsky_Telem/AP_Frsky_Telem.cpp | 63 ++++----------------- libraries/AP_Frsky_Telem/AP_Frsky_Telem.h | 2 - 2 files changed, 11 insertions(+), 54 deletions(-) diff --git a/libraries/AP_Frsky_Telem/AP_Frsky_Telem.cpp b/libraries/AP_Frsky_Telem/AP_Frsky_Telem.cpp index aa8c502435..7bece6af89 100644 --- a/libraries/AP_Frsky_Telem/AP_Frsky_Telem.cpp +++ b/libraries/AP_Frsky_Telem/AP_Frsky_Telem.cpp @@ -32,7 +32,6 @@ AP_Frsky_Telem::AP_Frsky_Telem(AP_AHRS &ahrs, const AP_BattMonitor &battery, con /* * init - perform required initialisation - * for Copter */ void AP_Frsky_Telem::init(const AP_SerialManager &serial_manager, const char *firmware_str, const uint8_t mav_type, AP_Float *fs_batt_voltage, AP_Float *fs_batt_mah, uint32_t *ap_value) { @@ -47,9 +46,17 @@ void AP_Frsky_Telem::init(const AP_SerialManager &serial_manager, const char *fi queue_message(MAV_SEVERITY_INFO, firmware_str); // save main parameters locally _params.mav_type = mav_type; // frame type (see MAV_TYPE in Mavlink definition file common.h) - _params.fs_batt_voltage = fs_batt_voltage; // failsafe battery voltage in volts - _params.fs_batt_mah = fs_batt_mah; // failsafe reserve capacity in mAh - _ap.value = ap_value; // ap bit-field + if (fs_batt_voltage != nullptr) { + _params.fs_batt_voltage = fs_batt_voltage; // failsafe battery voltage in volts + } + if (fs_batt_mah != nullptr) { + _params.fs_batt_mah = fs_batt_mah; // failsafe reserve capacity in mAh + } + if (ap_value != nullptr) { + _ap.value = ap_value; // ap bit-field + } else { + *_ap.value = 0; + } } if (_port != NULL) { @@ -59,54 +66,6 @@ void AP_Frsky_Telem::init(const AP_SerialManager &serial_manager, const char *fi } } -/* - * init - perform required initialisation - * for Plane - */ -void AP_Frsky_Telem::init(const AP_SerialManager &serial_manager, const char *firmware_str, const uint8_t mav_type, AP_Float *fs_batt_voltage, AP_Float *fs_batt_mah) -{ - // check for protocol configured for a serial port - only the first serial port with one of these protocols will then run (cannot have FrSky on multiple serial ports) - if ((_port = serial_manager.find_serial(AP_SerialManager::SerialProtocol_FrSky_D, 0))) { - _protocol = AP_SerialManager::SerialProtocol_FrSky_D; // FrSky D protocol (D-receivers) - } else if ((_port = serial_manager.find_serial(AP_SerialManager::SerialProtocol_FrSky_SPort, 0))) { - _protocol = AP_SerialManager::SerialProtocol_FrSky_SPort; // FrSky SPort protocol (X-receivers) - } else if ((_port = serial_manager.find_serial(AP_SerialManager::SerialProtocol_FrSky_SPort_Passthrough, 0))) { - _protocol = AP_SerialManager::SerialProtocol_FrSky_SPort_Passthrough; // FrSky SPort and SPort Passthrough (OpenTX) protocols (X-receivers) - // add firmware and frame info to message queue - queue_message(MAV_SEVERITY_INFO, firmware_str); - // save main parameters locally - _params.mav_type = mav_type; // frame type (see MAV_TYPE in Mavlink definition file common.h) - _params.fs_batt_voltage = fs_batt_voltage; // failsafe battery voltage in volts - _params.fs_batt_mah = fs_batt_mah; // failsafe reserve capacity in mAh - *_ap.value = 0; // ap bit-field - } - - if (_port != NULL) { - hal.scheduler->register_io_process(FUNCTOR_BIND_MEMBER(&AP_Frsky_Telem::tick, void)); - // we don't want flow control for either protocol - _port->set_flow_control(AP_HAL::UARTDriver::FLOW_CONTROL_DISABLE); - } -} - -/* - * init - perform required initialisation - * for Rover - */ -void AP_Frsky_Telem::init(const AP_SerialManager &serial_manager) -{ - // check for protocol configured for a serial port - only the first serial port with one of these protocols will then run (cannot have FrSky on multiple serial ports) - if ((_port = serial_manager.find_serial(AP_SerialManager::SerialProtocol_FrSky_D, 0))) { - _protocol = AP_SerialManager::SerialProtocol_FrSky_D; // FrSky D protocol (D-receivers) - } else if ((_port = serial_manager.find_serial(AP_SerialManager::SerialProtocol_FrSky_SPort, 0))) { - _protocol = AP_SerialManager::SerialProtocol_FrSky_SPort; // FrSky SPort protocol (X-receivers) - } - - if (_port != NULL) { - hal.scheduler->register_io_process(FUNCTOR_BIND_MEMBER(&AP_Frsky_Telem::tick, void)); - // we don't want flow control for either protocol - _port->set_flow_control(AP_HAL::UARTDriver::FLOW_CONTROL_DISABLE); - } -} /* * send telemetry data diff --git a/libraries/AP_Frsky_Telem/AP_Frsky_Telem.h b/libraries/AP_Frsky_Telem/AP_Frsky_Telem.h index 85ccfdcdb1..82999f186b 100644 --- a/libraries/AP_Frsky_Telem/AP_Frsky_Telem.h +++ b/libraries/AP_Frsky_Telem/AP_Frsky_Telem.h @@ -118,8 +118,6 @@ public: // init - perform required initialisation void init(const AP_SerialManager &serial_manager, const char *firmware_str, const uint8_t mav_type, AP_Float *fs_batt_voltage, AP_Float *fs_batt_mah, uint32_t *ap_value); - void init(const AP_SerialManager &serial_manager, const char *firmware_str, const uint8_t mav_type, AP_Float *fs_batt_voltage, AP_Float *fs_batt_mah); - void init(const AP_SerialManager &serial_manager); // add statustext message to FrSky lib queue. void queue_message(MAV_SEVERITY severity, const char *text);