2018-09-05 03:45:01 -03:00
|
|
|
#pragma once
|
|
|
|
|
2022-05-04 05:13:29 -03:00
|
|
|
#include <AP_HAL/AP_HAL_Boards.h>
|
|
|
|
|
|
|
|
#ifndef AP_AIRSPEED_UAVCAN_ENABLED
|
|
|
|
#define AP_AIRSPEED_UAVCAN_ENABLED HAL_ENABLE_LIBUAVCAN_DRIVERS
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if AP_AIRSPEED_UAVCAN_ENABLED
|
|
|
|
|
2018-09-05 03:45:01 -03:00
|
|
|
#include "AP_Airspeed_Backend.h"
|
|
|
|
|
2023-04-06 21:18:01 -03:00
|
|
|
#include <AP_DroneCAN/AP_DroneCAN.h>
|
2018-09-05 03:45:01 -03:00
|
|
|
|
|
|
|
class AP_Airspeed_UAVCAN : public AP_Airspeed_Backend {
|
|
|
|
public:
|
|
|
|
AP_Airspeed_UAVCAN(AP_Airspeed &_frontend, uint8_t _instance);
|
|
|
|
|
|
|
|
bool init(void) override;
|
|
|
|
|
|
|
|
// return the current differential_pressure in Pascal
|
|
|
|
bool get_differential_pressure(float &pressure) override;
|
|
|
|
|
|
|
|
// temperature not available via analog backend
|
|
|
|
bool get_temperature(float &temperature) override;
|
|
|
|
|
2022-10-17 05:35:08 -03:00
|
|
|
#if AP_AIRSPEED_HYGROMETER_ENABLE
|
|
|
|
// get hygrometer data
|
|
|
|
bool get_hygrometer(uint32_t &last_sample_ms, float &temperature, float &humidity) override;
|
|
|
|
#endif
|
|
|
|
|
2023-04-06 21:18:01 -03:00
|
|
|
static void subscribe_msgs(AP_DroneCAN* ap_dronecan);
|
2018-09-05 03:45:01 -03:00
|
|
|
|
2022-10-06 19:28:48 -03:00
|
|
|
static AP_Airspeed_Backend* probe(AP_Airspeed &_fronted, uint8_t _instance, uint32_t previous_devid);
|
2018-09-05 03:45:01 -03:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2023-04-06 21:18:01 -03:00
|
|
|
static void handle_airspeed(AP_DroneCAN *ap_dronecan, const CanardRxTransfer& transfer, const uavcan_equipment_air_data_RawAirData &msg);
|
|
|
|
static void handle_hygrometer(AP_DroneCAN *ap_dronecan, const CanardRxTransfer& transfer, const dronecan_sensors_hygrometer_Hygrometer &msg);
|
2018-09-05 03:45:01 -03:00
|
|
|
|
2023-04-06 21:18:01 -03:00
|
|
|
static AP_Airspeed_UAVCAN* get_uavcan_backend(AP_DroneCAN* ap_dronecan, uint8_t node_id);
|
2018-09-05 03:45:01 -03:00
|
|
|
|
|
|
|
float _pressure; // Pascal
|
2018-10-28 14:38:08 -03:00
|
|
|
float _temperature; // Celcius
|
2018-09-05 03:45:01 -03:00
|
|
|
uint32_t _last_sample_time_ms;
|
|
|
|
|
2022-10-17 05:35:08 -03:00
|
|
|
// hygrometer data
|
|
|
|
struct {
|
|
|
|
float temperature;
|
|
|
|
float humidity;
|
|
|
|
uint32_t last_sample_ms;
|
|
|
|
} _hygrometer;
|
|
|
|
|
2018-09-05 03:45:01 -03:00
|
|
|
HAL_Semaphore _sem_airspeed;
|
|
|
|
|
|
|
|
// Module Detection Registry
|
|
|
|
static struct DetectedModules {
|
2023-04-06 21:18:01 -03:00
|
|
|
AP_DroneCAN* ap_dronecan;
|
2018-09-05 03:45:01 -03:00
|
|
|
uint8_t node_id;
|
|
|
|
AP_Airspeed_UAVCAN *driver;
|
|
|
|
} _detected_modules[AIRSPEED_MAX_SENSORS];
|
|
|
|
|
2018-10-11 20:35:03 -03:00
|
|
|
static HAL_Semaphore _sem_registry;
|
2019-10-03 08:02:07 -03:00
|
|
|
bool _have_temperature;
|
2018-09-05 03:45:01 -03:00
|
|
|
};
|
2022-05-04 05:13:29 -03:00
|
|
|
|
|
|
|
|
|
|
|
#endif // AP_AIRSPEED_UAVCAN_ENABLED
|