AP_BattMonitor_UAVCAN.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #pragma once
  2. #include "AP_BattMonitor.h"
  3. #include "AP_BattMonitor_Backend.h"
  4. #include <AP_UAVCAN/AP_UAVCAN.h>
  5. #define AP_BATTMONITOR_UAVCAN_TIMEOUT_MICROS 5000000 // sensor becomes unhealthy if no successful readings for 5 seconds
  6. class BattInfoCb;
  7. class AP_BattMonitor_UAVCAN : public AP_BattMonitor_Backend
  8. {
  9. public:
  10. enum BattMonitor_UAVCAN_Type {
  11. UAVCAN_BATTERY_INFO = 0
  12. };
  13. /// Constructor
  14. AP_BattMonitor_UAVCAN(AP_BattMonitor &mon, AP_BattMonitor::BattMonitor_State &mon_state, BattMonitor_UAVCAN_Type type, AP_BattMonitor_Params &params);
  15. void init() override {}
  16. /// Read the battery voltage and current. Should be called at 10hz
  17. void read() override;
  18. bool has_current() const override {
  19. return true;
  20. }
  21. static void subscribe_msgs(AP_UAVCAN* ap_uavcan);
  22. static AP_BattMonitor_UAVCAN* get_uavcan_backend(AP_UAVCAN* ap_uavcan, uint8_t node_id);
  23. static void handle_battery_info_trampoline(AP_UAVCAN* ap_uavcan, uint8_t node_id, const BattInfoCb &cb);
  24. private:
  25. void handle_battery_info(const BattInfoCb &cb);
  26. AP_BattMonitor::BattMonitor_State _interim_state;
  27. BattMonitor_UAVCAN_Type _type;
  28. HAL_Semaphore _sem_battmon;
  29. AP_UAVCAN* _ap_uavcan;
  30. uint8_t _node_id;
  31. };