Line data Source code
1 : #pragma once 2 : 3 : #include "AP_RangeFinder_config.h" 4 : 5 : #if AP_RANGEFINDER_DRONECAN_ENABLED 6 : 7 : #include "AP_RangeFinder_Backend.h" 8 : #include <AP_DroneCAN/AP_DroneCAN.h> 9 : 10 : class MeasurementCb; 11 : 12 : class AP_RangeFinder_DroneCAN : public AP_RangeFinder_Backend { 13 : public: 14 : //constructor - registers instance at top RangeFinder driver 15 : using AP_RangeFinder_Backend::AP_RangeFinder_Backend; 16 : 17 : void update() override; 18 : 19 : static bool subscribe_msgs(AP_DroneCAN* ap_dronecan); 20 : static AP_RangeFinder_DroneCAN* get_dronecan_backend(AP_DroneCAN* ap_dronecan, uint8_t node_id, uint8_t address, bool create_new); 21 : static AP_RangeFinder_Backend* detect(RangeFinder::RangeFinder_State &_state, AP_RangeFinder_Params &_params); 22 : 23 : static void handle_measurement(AP_DroneCAN *ap_dronecan, const CanardRxTransfer& transfer, const uavcan_equipment_range_sensor_Measurement &msg); 24 : 25 : protected: 26 0 : virtual MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const override { 27 0 : return _sensor_type; 28 : } 29 : private: 30 : uint8_t _instance; 31 : // _status is the state received from the peripheral - or "NoData" in case of timeout 32 : RangeFinder::Status _status; 33 : float _distance_m; 34 : uint32_t _last_reading_ms; 35 : AP_DroneCAN* _ap_dronecan; 36 : uint8_t _node_id; 37 : bool new_data; 38 : MAV_DISTANCE_SENSOR _sensor_type; 39 : }; 40 : #endif // AP_RANGEFINDER_DRONECAN_ENABLED