2023-04-08 00:53:24 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AP_Baro_Backend.h"
|
|
|
|
|
2023-04-08 00:58:12 -03:00
|
|
|
#if AP_BARO_DRONECAN_ENABLED
|
2023-04-08 00:53:24 -03:00
|
|
|
|
|
|
|
#include <AP_DroneCAN/AP_DroneCAN.h>
|
|
|
|
#if AP_TEST_DRONECAN_DRIVERS
|
|
|
|
#include <SITL/SITL.h>
|
|
|
|
#endif
|
|
|
|
|
2023-04-08 01:09:10 -03:00
|
|
|
class AP_Baro_DroneCAN : public AP_Baro_Backend {
|
2023-04-08 00:53:24 -03:00
|
|
|
public:
|
2023-04-08 01:09:10 -03:00
|
|
|
AP_Baro_DroneCAN(AP_Baro &baro);
|
2023-04-08 00:53:24 -03:00
|
|
|
|
|
|
|
void update() override;
|
|
|
|
|
2024-11-16 23:21:13 -04:00
|
|
|
static bool subscribe_msgs(AP_DroneCAN* ap_dronecan);
|
2023-04-08 01:27:51 -03:00
|
|
|
static AP_Baro_DroneCAN* get_dronecan_backend(AP_DroneCAN* ap_dronecan, uint8_t node_id, bool create_new);
|
2023-04-08 00:53:24 -03:00
|
|
|
static AP_Baro_Backend* probe(AP_Baro &baro);
|
|
|
|
|
|
|
|
static void handle_pressure(AP_DroneCAN *ap_dronecan, const CanardRxTransfer& transfer, const uavcan_equipment_air_data_StaticPressure &msg);
|
|
|
|
static void handle_temperature(AP_DroneCAN *ap_dronecan, const CanardRxTransfer& transfer, const uavcan_equipment_air_data_StaticTemperature &msg);
|
|
|
|
#if AP_TEST_DRONECAN_DRIVERS
|
|
|
|
void update_healthy_flag(uint8_t instance) override { _frontend.sensors[instance].healthy = !AP::sitl()->baro[instance].disable; };
|
|
|
|
#endif
|
|
|
|
private:
|
|
|
|
|
|
|
|
static void _update_and_wrap_accumulator(float *accum, float val, uint8_t *count, const uint8_t max_count);
|
|
|
|
|
|
|
|
uint8_t _instance;
|
|
|
|
|
|
|
|
bool new_pressure;
|
|
|
|
float _pressure;
|
|
|
|
float _temperature;
|
|
|
|
uint8_t _pressure_count;
|
|
|
|
HAL_Semaphore _sem_baro;
|
|
|
|
|
|
|
|
AP_DroneCAN* _ap_dronecan;
|
|
|
|
uint8_t _node_id;
|
|
|
|
|
|
|
|
// Module Detection Registry
|
|
|
|
static struct DetectedModules {
|
|
|
|
AP_DroneCAN* ap_dronecan;
|
|
|
|
uint8_t node_id;
|
2023-04-08 01:09:10 -03:00
|
|
|
AP_Baro_DroneCAN* driver;
|
2023-04-08 00:53:24 -03:00
|
|
|
} _detected_modules[BARO_MAX_DRIVERS];
|
|
|
|
|
|
|
|
static HAL_Semaphore _sem_registry;
|
|
|
|
};
|
|
|
|
|
2023-04-08 00:58:12 -03:00
|
|
|
#endif // AP_BARO_DRONECAN_ENABLED
|