LCOV - code coverage report
Current view: top level - AP_RSSI - AP_RSSI.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 1 1 100.0 %
Date: 2026-09-09 11:02:08 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :    This program is free software: you can redistribute it and/or modify
       3             :    it under the terms of the GNU General Public License as published by
       4             :    the Free Software Foundation, either version 3 of the License, or
       5             :    (at your option) any later version.
       6             : 
       7             :    This program is distributed in the hope that it will be useful,
       8             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
       9             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      10             :    GNU General Public License for more details.
      11             : 
      12             :    You should have received a copy of the GNU General Public License
      13             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      14             :  */
      15             : #pragma once
      16             : 
      17             : #include "AP_RSSI_config.h"
      18             : 
      19             : #if AP_RSSI_ENABLED
      20             : 
      21             : #include <AP_HAL/AP_HAL.h>
      22             : #include <AP_Param/AP_Param.h>
      23             : #include <AP_Math/AP_Math.h>
      24             : 
      25             : class AP_RSSI
      26             : {
      27             : public:
      28             :     enum class RssiType {
      29             :         TYPE_DISABLED      = 0,
      30             :         ANALOG_PIN         = 1,
      31             :         RC_CHANNEL_VALUE   = 2,
      32             :         RECEIVER           = 3,
      33             :         PWM_PIN            = 4,
      34             :         TELEMETRY_RADIO_RSSI = 5,
      35             :     };
      36             : 
      37             :     AP_RSSI();
      38             : 
      39             :     /* Do not allow copies */
      40             :     CLASS_NO_COPY(AP_RSSI);
      41             : 
      42             :     // destructor
      43             :     ~AP_RSSI(void);
      44             : 
      45             :     static AP_RSSI *get_singleton();
      46             : 
      47             :     // Initialize the rssi object and prepare it for use
      48             :     void init();
      49             : 
      50             :     // return true if rssi reading is enabled
      51     3250937 :     bool enabled() const { return RssiType(rssi_type.get()) != RssiType::TYPE_DISABLED; }
      52             : 
      53             :     // Read the receiver RSSI value as a float 0.0f - 1.0f.
      54             :     // 0.0 represents weakest signal, 1.0 represents maximum signal.
      55             :     float read_receiver_rssi();
      56             :     float read_receiver_link_quality();
      57             :     // Read the receiver RSSI value as an 8-bit integer
      58             :     // 0 represents weakest signal, 255 represents maximum signal.
      59             :     uint8_t read_receiver_rssi_uint8();   
      60             : 
      61             :     // parameter block
      62             :     static const struct AP_Param::GroupInfo var_info[];
      63             : 
      64             : private:
      65             : 
      66             :     static AP_RSSI *_singleton;
      67             : 
      68             :     // RSSI parameters
      69             :     AP_Int8         rssi_type;                              // Type of RSSI being used
      70             :     AP_Int8         rssi_analog_pin;                        // Analog pin RSSI value found on
      71             :     AP_Float        rssi_analog_pin_range_low;              // Voltage value for weakest rssi signal
      72             :     AP_Float        rssi_analog_pin_range_high;             // Voltage value for strongest rssi signal
      73             :     AP_Int8         rssi_channel;                           // allows rssi to be read from given channel as PWM value
      74             :     AP_Int16        rssi_channel_low_pwm_value;             // PWM value for weakest rssi signal
      75             :     AP_Int16        rssi_channel_high_pwm_value;            // PWM value for strongest rssi signal
      76             : 
      77             :     // Analog Inputs
      78             :     // a pin for reading the receiver RSSI voltage. 
      79             :     AP_HAL::AnalogSource *rssi_analog_source;
      80             : 
      81             :     // PWM input
      82             :     struct PWMState {
      83             :         int8_t last_warn_pin; // last pin used for reading pwm (used to recognise change failure in pin assignment)
      84             :         uint32_t last_reading_ms;      // system time of last read (used for health reporting)
      85             :         float rssi_value;              // last calculated RSSI value
      86             :         // the following two members are updated by the interrupt handler
      87             :         AP_HAL::PWMSource pwm_source;
      88             :     } pwm_state;
      89             : 
      90             :     // read the RSSI value from an analog pin - returns float in range 0.0 to 1.0
      91             :     float read_pin_rssi();
      92             : 
      93             :     // read the RSSI value from a PWM value on a RC channel
      94             :     float read_channel_rssi();
      95             : 
      96             :     // read the PWM value from a pin
      97             :     float read_pwm_pin_rssi();
      98             : 
      99             :     // read the (RC) RSSI value from telemetry radio RSSI (e.g. rfd900x pass-through)
     100             :     float read_telemetry_radio_rssi();
     101             : 
     102             :     // Scale and constrain a float rssi value to 0.0 to 1.0 range
     103             :     float scale_and_constrain_float_rssi(float current_rssi_value, float low_rssi_range, float high_rssi_range);
     104             : };
     105             : 
     106             : namespace AP {
     107             :     AP_RSSI *rssi();
     108             : };
     109             : 
     110             : #endif  // AP_RSSI_ENABLED

Generated by: LCOV version 1.14