LCOV - code coverage report
Current view: top level - AP_ESC_Telem - AP_ESC_Telem_Backend.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 16 17 94.1 %
Date: 2026-09-09 11:02:08 Functions: 5 5 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             : 
      16             : #include "AP_ESC_Telem_Backend.h"
      17             : #include "AP_ESC_Telem.h"
      18             : #include <AP_HAL/AP_HAL.h>
      19             : 
      20             : #if HAL_WITH_ESC_TELEM
      21             : 
      22             : #include <AP_Math/AP_Math.h>
      23             : #include <AP_Vehicle/AP_Vehicle_Type.h>
      24             : 
      25             : extern const AP_HAL::HAL& hal;
      26             : 
      27        6355 : AP_ESC_Telem_Backend::AP_ESC_Telem_Backend() {
      28        6355 :     _frontend = AP_ESC_Telem::_singleton;
      29             : #if !APM_BUILD_TYPE(APM_BUILD_UNKNOWN)
      30             :     // we allow for no frontend in example fw and tools to make it
      31             :     // possible to run them on hardware with IOMCU
      32        6355 :     if (_frontend == nullptr) {
      33           0 :         AP_HAL::panic("No ESC frontend");
      34             :     }
      35             : #endif
      36        6355 : }
      37             : 
      38             : // callback to update the rpm in the frontend, should be called by the driver when new data is available
      39   140860545 : void AP_ESC_Telem_Backend::update_rpm(const uint8_t esc_index, const float new_rpm, const float error_rate) {
      40   140860545 :     _frontend->update_rpm(esc_index, new_rpm, error_rate);
      41   140860545 : }
      42             : 
      43             : // callback to update the data in the frontend, should be called by the driver when new data is available
      44   140860545 : void AP_ESC_Telem_Backend::update_telem_data(const uint8_t esc_index, const TelemetryData& new_data, const uint16_t data_present_mask) {
      45   140860545 :     _frontend->update_telem_data(esc_index, new_data, data_present_mask);
      46   140860545 : }
      47             : 
      48             : /*
      49             :   return true if the data is stale
      50             :  */
      51    25430489 : bool AP_ESC_Telem_Backend::TelemetryData::stale() const volatile
      52             : {
      53    25430489 :     return last_update_ms == 0 || !any_data_valid;
      54             : }
      55             : 
      56             : /*
      57             :   return true if the requested types of data are available and not stale
      58             :  */
      59        1344 : bool AP_ESC_Telem_Backend::TelemetryData::valid(const uint16_t type_mask) const volatile
      60             : {
      61        1344 :     if ((types & type_mask) == 0) {
      62             :         // Requested type not available
      63        1313 :         return false;
      64             :     }
      65          31 :     return !stale();
      66             : }
      67             : 
      68             : #endif

Generated by: LCOV version 1.14