2017-04-02 11:56:15 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AP_Compass.h"
|
2022-10-26 06:21:36 -03:00
|
|
|
|
|
|
|
#if AP_COMPASS_UAVCAN_ENABLED
|
|
|
|
|
2017-04-02 11:56:15 -03:00
|
|
|
#include "AP_Compass_Backend.h"
|
|
|
|
|
2023-04-06 21:18:01 -03:00
|
|
|
#include <AP_DroneCAN/AP_DroneCAN.h>
|
2017-04-02 11:56:15 -03:00
|
|
|
|
|
|
|
class AP_Compass_UAVCAN : public AP_Compass_Backend {
|
|
|
|
public:
|
2023-04-06 21:18:01 -03:00
|
|
|
AP_Compass_UAVCAN(AP_DroneCAN* ap_dronecan, uint8_t node_id, uint8_t sensor_id, uint32_t devid);
|
2018-07-20 08:18:00 -03:00
|
|
|
|
2017-04-02 11:56:15 -03:00
|
|
|
void read(void) override;
|
|
|
|
|
2023-04-06 21:18:01 -03:00
|
|
|
static void subscribe_msgs(AP_DroneCAN* ap_dronecan);
|
2019-11-20 03:18:10 -04:00
|
|
|
static AP_Compass_Backend* probe(uint8_t index);
|
2020-07-20 18:25:08 -03:00
|
|
|
static uint32_t get_detected_devid(uint8_t index) { return _detected_modules[index].devid; }
|
2023-04-06 21:18:01 -03:00
|
|
|
static void handle_magnetic_field(AP_DroneCAN *ap_dronecan, const CanardRxTransfer& transfer, const uavcan_equipment_ahrs_MagneticFieldStrength& msg);
|
|
|
|
static void handle_magnetic_field_2(AP_DroneCAN *ap_dronecan, const CanardRxTransfer& transfer, const uavcan_equipment_ahrs_MagneticFieldStrength2 &msg);
|
2017-05-06 06:13:19 -03:00
|
|
|
|
2018-07-20 08:18:00 -03:00
|
|
|
private:
|
2019-11-20 03:18:10 -04:00
|
|
|
bool init();
|
2017-05-06 06:13:19 -03:00
|
|
|
|
2023-01-03 22:04:50 -04:00
|
|
|
// callback for DroneCAN messages
|
2018-07-20 08:18:00 -03:00
|
|
|
void handle_mag_msg(const Vector3f &mag);
|
|
|
|
|
2023-04-06 21:18:01 -03:00
|
|
|
static AP_Compass_UAVCAN* get_uavcan_backend(AP_DroneCAN* ap_dronecan, uint8_t node_id, uint8_t sensor_id);
|
2017-04-02 11:56:15 -03:00
|
|
|
|
|
|
|
uint8_t _instance;
|
2018-07-20 08:18:00 -03:00
|
|
|
|
2023-04-06 21:18:01 -03:00
|
|
|
AP_DroneCAN* _ap_dronecan;
|
2018-07-20 08:18:00 -03:00
|
|
|
uint8_t _node_id;
|
|
|
|
uint8_t _sensor_id;
|
2020-07-20 18:25:08 -03:00
|
|
|
uint32_t _devid;
|
2018-07-20 08:18:00 -03:00
|
|
|
|
|
|
|
// Module Detection Registry
|
|
|
|
static struct DetectedModules {
|
2023-04-06 21:18:01 -03:00
|
|
|
AP_DroneCAN* ap_dronecan;
|
2018-07-20 08:18:00 -03:00
|
|
|
uint8_t node_id;
|
|
|
|
uint8_t sensor_id;
|
|
|
|
AP_Compass_UAVCAN *driver;
|
2020-07-20 18:25:08 -03:00
|
|
|
uint32_t devid;
|
2018-07-20 08:18:00 -03:00
|
|
|
} _detected_modules[COMPASS_MAX_BACKEND];
|
2017-05-06 06:13:19 -03:00
|
|
|
|
2018-10-11 20:35:03 -03:00
|
|
|
static HAL_Semaphore _sem_registry;
|
2017-04-02 11:56:15 -03:00
|
|
|
};
|
2022-10-26 06:21:36 -03:00
|
|
|
|
|
|
|
#endif // AP_COMPASS_UAVCAN_ENABLED
|