LCOV - code coverage report
Current view: top level - AP_GPS - AP_GPS_ExternalAHRS.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 38 40 95.0 %
Date: 2026-09-09 11:02:08 Functions: 3 3 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             : //
      17             : //  ExternalAHRS GPS driver
      18             : //
      19             : #include <AP_ExternalAHRS/AP_ExternalAHRS.h>
      20             : #include "AP_GPS_ExternalAHRS.h"
      21             : 
      22             : #if AP_EXTERNAL_AHRS_ENABLED
      23             : 
      24             : // Reading does nothing in this class; we simply return whether or not
      25             : // the latest reading has been consumed.  By calling this function we assume
      26             : // the caller is consuming the new data;
      27       51297 : bool AP_GPS_ExternalAHRS::read(void)
      28             : {
      29       51297 :     if (new_data) {
      30       14288 :         new_data = false;
      31       14288 :         return true;
      32             :     }
      33       37009 :     return false;
      34             : }
      35             : 
      36             : // handles an incoming ExternalAHRS message and sets
      37             : // corresponding gps data appropriately;
      38       15139 : void AP_GPS_ExternalAHRS::handle_external(const AP_ExternalAHRS::gps_data_message_t &pkt)
      39             : {
      40       15139 :     check_new_itow(pkt.ms_tow, sizeof(pkt));
      41             : 
      42       15139 :     state.time_week = pkt.gps_week;
      43       15139 :     state.time_week_ms = pkt.ms_tow;
      44       15139 :     if (pkt.fix_type == AP_GPS_FixType::NO_GPS) {
      45           0 :         state.status = AP_GPS_FixType::NONE;
      46             :     } else {
      47       15139 :         state.status = (AP_GPS_FixType)pkt.fix_type;
      48             :     }
      49       15139 :     state.num_sats = pkt.satellites_in_view;
      50             : 
      51             :     const Location loc {
      52       15139 :         pkt.latitude,
      53       15139 :         pkt.longitude,
      54       15139 :         pkt.msl_altitude,
      55             :         Location::AltFrame::ABSOLUTE
      56       15139 :     };
      57             : #if CONFIG_HAL_BOARD == HAL_BOARD_SITL
      58       15139 :     if (!loc.initialised() && state.status >= AP_GPS_FixType::FIX_2D) {
      59           0 :         AP_HAL::panic("Invalid location passed to AP_GPS_ExternalAHRS");
      60             :     }
      61             : #endif
      62             : 
      63       15139 :     state.location = loc;
      64       15139 :     state.hdop = pkt.hdop;
      65       15139 :     state.vdop = pkt.vdop;
      66             : 
      67       15139 :     state.have_vertical_velocity = true;
      68       15139 :     state.velocity.x = pkt.ned_vel_north;
      69       15139 :     state.velocity.y = pkt.ned_vel_east;
      70       15139 :     state.velocity.z = pkt.ned_vel_down;
      71             : 
      72       15139 :     velocity_to_speed_course(state);
      73             : 
      74       15139 :     state.have_speed_accuracy = true;
      75       15139 :     state.have_horizontal_accuracy = true;
      76       15139 :     state.have_vertical_accuracy = true;
      77       15139 :     state.have_vertical_velocity = true;
      78             : 
      79       15139 :     state.horizontal_accuracy = pkt.horizontal_pos_accuracy;
      80       15139 :     state.vertical_accuracy = pkt.vertical_pos_accuracy;
      81       15139 :     state.speed_accuracy = pkt.horizontal_vel_accuracy;
      82             : 
      83       15139 :     state.last_gps_time_ms = AP_HAL::millis();
      84             : 
      85       15139 :     new_data = true;
      86       15139 : }
      87             : 
      88             : /*
      89             :   return velocity lag in seconds
      90             :  */
      91      114092 : bool AP_GPS_ExternalAHRS::get_lag(float &lag_sec) const
      92             : {
      93             :     // fixed assumed lag
      94      114092 :     lag_sec = 0.11;
      95      114092 :     return true;
      96             : }
      97             : 
      98             : #endif // AP_EXTERNAL_AHRS_ENABLED
      99             : 

Generated by: LCOV version 1.14