Line data Source code
1 : #pragma once 2 : 3 : // AP_Stats is used to collect and put to permanent storage data about 4 : // the vehicle's autopilot 5 : 6 : #include <AP_Common/AP_Common.h> 7 : #include <AP_Param/AP_Param.h> 8 : #include <AP_Common/Location.h> 9 : 10 : class AP_Stats 11 : { 12 : public: 13 : // constructor 14 : AP_Stats(); 15 : 16 : // these variables are periodically written into the actual 17 : // parameters. If you add a variable here, make sure to update 18 : // init() to set initial values from the parameters! 19 : uint32_t flttime; // seconds in flight (or driving) 20 : uint32_t runtime; // total wallclock time spent running ArduPilot (seconds) 21 : uint32_t reset; // last time AP_Stats parameters were reset (in seconds since AP_Stats Jan 1st 2016) 22 : uint32_t flttime_boot; // seconds in flight (or driving), at boot 23 : uint32_t fltcount; // total number of takeoffs 24 : float distance_flown_m; // total distance flown in meters 25 : 26 : void init(); 27 : 28 : // copy state into underlying parameters: 29 : void flush(); 30 : 31 : // periodic update function (e.g. put our values to permanent storage): 32 : // call at least 1Hz 33 : void update(); 34 : 35 : void set_flying(bool b); 36 : 37 : // accessor for is_flying 38 : bool get_is_flying(void) const { 39 : return _flying_ms != 0; 40 : } 41 : 42 : // accessor for flighttime. Returns 0 if not flying, otherwise 43 : // total time flying since boot in seconds 44 : uint32_t get_flight_time_s(void); 45 : 46 : // get singleton 47 294970 : static AP_Stats *get_singleton(void) { 48 294970 : return _singleton; 49 : } 50 : 51 : static const struct AP_Param::GroupInfo var_info[]; 52 : 53 : private: 54 : static AP_Stats *_singleton; 55 : 56 : struct { 57 : AP_Int16 bootcount; 58 : AP_Int32 flttime; 59 : AP_Int32 runtime; 60 : AP_Int32 reset; 61 : AP_Int32 fltcount; 62 : AP_Float distance_flown_m; 63 : } params; 64 : 65 : void copy_variables_from_parameters(); 66 : 67 : uint64_t last_flush_ms; // in terms of system uptime 68 : static constexpr uint16_t flush_interval_ms = 30000; 69 : 70 : uint64_t _flying_ms; 71 : uint64_t _last_runtime_ms; 72 : 73 : Location _last_position; 74 : bool _last_position_valid; 75 : uint32_t _last_distance_update_ms; 76 : 77 : void update_flighttime(); 78 : void update_runtime(); 79 : void update_distance_flown(); 80 : HAL_Semaphore sem; 81 : }; 82 : 83 : namespace AP { 84 : AP_Stats *stats(); 85 : };