/**************************************************************************** * * Copyright (c) 2012-2022 PX4 Development Team. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. Neither the name PX4 nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************/ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "crsf_telemetry.h" #include "ghst_telemetry.hpp" #ifdef HRT_PPM_CHANNEL # include #endif class RCInput : public ModuleBase, public ModuleParams, public px4::ScheduledWorkItem { public: static Descriptor desc; RCInput(const char *device); virtual ~RCInput(); /** @see ModuleBase */ static int task_spawn(int argc, char *argv[]); /** @see ModuleBase */ static int custom_command(int argc, char *argv[]); /** @see ModuleBase */ static int print_usage(const char *reason = nullptr); /** @see ModuleBase::print_status() */ int print_status() override; int init(); private: enum RC_SCAN { RC_SCAN_NONE = 0, RC_SCAN_PPM = 1, RC_SCAN_SBUS = 2, RC_SCAN_DSM = 3, RC_SCAN_ST24 = 5, RC_SCAN_SUMD = 4, RC_SCAN_CRSF = 6, RC_SCAN_GHST = 7, } _rc_scan_state{RC_SCAN_SBUS}; static constexpr char const *RC_SCAN_STRING[] { "None", "PPM", "SBUS", "DSM", "ST24", "SUMD", "CRSF", "GHST" }; void Run() override; #if defined(SPEKTRUM_POWER) bool bind_spektrum(int arg = DSMX8_BIND_PULSES) const; #endif // SPEKTRUM_POWER int32_t fill_rc_in(uint16_t raw_rc_count_local, uint16_t raw_rc_values_local[input_rc_s::RC_INPUT_MAX_CHANNELS], hrt_abstime now, bool frame_drop, bool failsafe, unsigned frame_drops, int rssi); void set_rc_scan_state(RC_SCAN _rc_scan_state); void rc_io_invert(bool invert); void swap_rx_tx(void); input_rc_s _input_rc{}; hrt_abstime _rc_scan_begin{0}; bool _initialized{false}; bool _rc_scan_locked{false}; static constexpr unsigned _current_update_interval{4000}; // 250 Hz uORB::SubscriptionInterval _parameter_update_sub{ORB_ID(parameter_update), 1_s}; uORB::Subscription _adc_report_sub{ORB_ID(adc_report)}; uORB::Subscription _vehicle_cmd_sub{ORB_ID(vehicle_command)}; uORB::Subscription _vehicle_status_sub{ORB_ID(vehicle_status)}; uORB::PublicationMulti _input_rc_pub{ORB_ID(input_rc)}; float _analog_rc_rssi_volt{-1.0f}; bool _analog_rc_rssi_stable{false}; bool _armed{false}; int _rcs_fd{-1}; char _device[20] {}; ///< device / serial port path static constexpr size_t RC_MAX_BUFFER_SIZE{SBUS_BUFFER_SIZE}; uint8_t _rcs_buf[RC_MAX_BUFFER_SIZE] {}; uint16_t _raw_rc_values[input_rc_s::RC_INPUT_MAX_CHANNELS] {}; uint16_t _raw_rc_count{}; CRSFTelemetry *_crsf_telemetry{nullptr}; GHSTTelemetry *_ghst_telemetry{nullptr}; perf_counter_t _cycle_perf; perf_counter_t _publish_interval_perf; uint32_t _bytes_rx{0}; DEFINE_PARAMETERS( (ParamInt) _param_rc_rssi_pwm_chan, (ParamInt) _param_rc_rssi_pwm_min, (ParamInt) _param_rc_rssi_pwm_max, (ParamInt) _param_rc_input_proto ) };