AP_Stats.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #pragma once
  2. // AP_Stats is used to collect and put to permanent storage data about
  3. // the vehicle's autopilot
  4. #include <AP_Common/AP_Common.h>
  5. #include <AP_Param/AP_Param.h>
  6. class AP_Stats
  7. {
  8. public:
  9. // constructor
  10. AP_Stats();
  11. // these variables are periodically written into the actual
  12. // parameters. If you add a variable here, make sure to update
  13. // init() to set initial values from the parameters!
  14. uint32_t flttime; // seconds in flight (or driving)
  15. uint32_t runtime; // total wallclock time spent running ArduPilot (seconds)
  16. uint32_t reset; // last time AP_Stats parameters were reset (in seconds since AP_Stats Jan 1st 2016)
  17. uint32_t flttime_boot; // seconds in flight (or driving), at boot
  18. void init();
  19. // copy state into underlying parameters:
  20. void flush();
  21. // periodic update function (e.g. put our values to permanent storage):
  22. // call at least 1Hz
  23. void update();
  24. void set_flying(bool b);
  25. // accessor for is_flying
  26. bool get_is_flying(void) {
  27. return _flying_ms != 0;
  28. }
  29. // accessor for flighttime. Returns 0 if not flying, otherwise
  30. // total time flying since boot in seconds
  31. uint32_t get_flight_time_s(void);
  32. // get singleton
  33. static AP_Stats *get_singleton(void) {
  34. return _singleton;
  35. }
  36. static const struct AP_Param::GroupInfo var_info[];
  37. private:
  38. static AP_Stats *_singleton;
  39. struct {
  40. AP_Int16 bootcount;
  41. AP_Int32 flttime;
  42. AP_Int32 runtime;
  43. AP_Int32 reset;
  44. } params;
  45. void copy_variables_from_parameters();
  46. uint64_t last_flush_ms; // in terms of system uptime
  47. const uint16_t flush_interval_ms = 30000;
  48. uint64_t _flying_ms;
  49. uint64_t _last_runtime_ms;
  50. void update_flighttime();
  51. void update_runtime();
  52. };
  53. namespace AP {
  54. AP_Stats *stats();
  55. };