LCOV - code coverage report
Current view: top level - AP_Airspeed - AP_Airspeed_Backend.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 8 25 32.0 %
Date: 2026-09-09 11:02:08 Functions: 4 17 23.5 %

          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             : /*
      18             :   backend driver class for airspeed
      19             :  */
      20             : 
      21             : #include "AP_Airspeed_config.h"
      22             : 
      23             : #if AP_AIRSPEED_ENABLED
      24             : 
      25             : #include <AP_Common/AP_Common.h>
      26             : #include <AP_HAL/AP_HAL_Boards.h>
      27             : #include <AP_HAL/Semaphores.h>
      28             : #include "AP_Airspeed.h"
      29             : #include <AP_MSP/msp_sensors.h>
      30             : 
      31             : class AP_Airspeed_Backend {
      32             : public:
      33             :     AP_Airspeed_Backend(AP_Airspeed &frontend, uint8_t instance);
      34           0 :     virtual ~AP_Airspeed_Backend() {}
      35             : 
      36             :     // probe and initialise the sensor
      37             :     virtual bool init(void) = 0;
      38             : 
      39             :     // return the current differential_pressure in Pascal
      40           0 :     virtual bool get_differential_pressure(float &pressure) {return false;}
      41             : 
      42             :     // return the current temperature in degrees C, if available
      43             :     virtual bool get_temperature(float &temperature) = 0;
      44             : 
      45             :     // true if sensor reads airspeed directly, not via pressure
      46      578849 :     virtual bool has_airspeed() {return false;}
      47             : 
      48             :     // return airspeed in m/s if available
      49           0 :     virtual bool get_airspeed(float& airspeed) {return false;}
      50             : 
      51           0 :     virtual void handle_msp(const MSP::msp_airspeed_data_message_t &pkt) {}
      52             : #if AP_AIRSPEED_EXTERNAL_ENABLED
      53           0 :     virtual void handle_external(const AP_ExternalAHRS::airspeed_data_message_t &pkt) {}
      54             : #endif
      55             : 
      56             : #if AP_AIRSPEED_HYGROMETER_ENABLE
      57             :     // optional hygrometer support
      58     1120637 :     virtual bool get_hygrometer(uint32_t &last_sample_ms, float &temperature, float &humidity) { return false; }
      59             : #endif
      60             : 
      61             : #if AP_AIRSPEED_SCRIPTING_ENABLED
      62             :     // handle a differential pressure reading, in Pascal, from a lua script
      63           0 :     virtual bool handle_script_differential_pressure(float press_pa) { return false; }
      64             : 
      65             :     // handle an airspeed reading, in m/s, from a lua script
      66           0 :     virtual bool handle_script_airspeed(float airspeed_ms) { return false; }
      67             : 
      68             :     // handle a temperature reading, in degrees C, from a lua script
      69           0 :     virtual bool handle_script_temperature(float temperature_c) { return false; }
      70             : #endif // AP_AIRSPEED_SCRIPTING_ENABLED
      71             : 
      72             : protected:
      73             :     int8_t get_pin(void) const;
      74             :     float get_psi_range(void) const;
      75             :     uint8_t get_bus(void) const;
      76             :     bool bus_is_configured(void) const;
      77       15398 :     uint8_t get_instance(void) const {
      78       15398 :         return instance;
      79             :     }
      80             : 
      81             :     // see if voltage correction should be disabled
      82           0 :     bool disable_voltage_correction(void) const {
      83           0 :         return (frontend._options.get() & AP_Airspeed::OptionsMask::DISABLE_VOLTAGE_CORRECTION) != 0;
      84             :     }
      85             : 
      86           0 :     AP_Airspeed::pitot_tube_order get_tube_order(void) const {
      87             : #ifndef HAL_BUILD_AP_PERIPH
      88           0 :         return AP_Airspeed::pitot_tube_order(frontend.param[instance].tube_order.get());
      89             : #else
      90             :         return AP_Airspeed::pitot_tube_order::PITOT_TUBE_ORDER_AUTO;
      91             : #endif
      92             :     }
      93             : 
      94             :     // semaphore for access to shared frontend data
      95             :     HAL_Semaphore sem;
      96             : 
      97           0 :     float get_airspeed_ratio(void) const {
      98           0 :         return frontend.get_airspeed_ratio(instance);
      99             :     }
     100             : 
     101             :     // some sensors use zero offsets
     102          55 :     void set_use_zero_offset(void) {
     103          55 :         frontend.state[instance].cal.state = AP_Airspeed::CalibrationState::NOT_REQUIRED_ZERO_OFFSET;
     104             : #ifndef HAL_BUILD_AP_PERIPH
     105          55 :         frontend.param[instance].offset.set(0.0);
     106             : #endif
     107          55 :     }
     108             : 
     109             :     // set use
     110           0 :     void set_use(int8_t use) {
     111             : #ifndef HAL_BUILD_AP_PERIPH
     112           0 :         frontend.param[instance].use.set(use);
     113             : #endif
     114           0 :     }
     115             : 
     116             :     // set bus ID of this instance, for ARSPD_DEVID parameters
     117             :     void set_bus_id(uint32_t id);
     118             : 
     119             :     enum class DevType {
     120             :         SITL     = 0x01,
     121             :         MS4525   = 0x02,
     122             :         MS5525   = 0x03,
     123             :         DLVR     = 0x04,
     124             :         MSP      = 0x05,
     125             :         SDP3X    = 0x06,
     126             :         UAVCAN   = 0x07,
     127             :         ANALOG   = 0x08,
     128             :         NMEA     = 0x09,
     129             :         ASP5033  = 0x0A,
     130             :         AUAV     = 0x0B,
     131             :         SCRIPTING = 0x0C,
     132             :     };
     133             :     
     134             : private:
     135             :     AP_Airspeed &frontend;
     136             :     uint8_t instance;
     137             : };
     138             : 
     139             : #endif  // AP_AIRSPEED_ENABLED

Generated by: LCOV version 1.14