2023-04-08 00:53:24 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AP_Compass.h"
|
|
|
|
|
2023-04-08 00:58:13 -03:00
|
|
|
#if AP_COMPASS_DRONECAN_ENABLED
|
2023-04-08 00:53:24 -03:00
|
|
|
|
|
|
|
#include "AP_Compass_Backend.h"
|
|
|
|
|
|
|
|
#include <AP_DroneCAN/AP_DroneCAN.h>
|
|
|
|
|
2023-04-08 01:09:10 -03:00
|
|
|
class AP_Compass_DroneCAN : public AP_Compass_Backend {
|
2023-04-08 00:53:24 -03:00
|
|
|
public:
|
2023-04-08 01:09:10 -03:00
|
|
|
AP_Compass_DroneCAN(AP_DroneCAN* ap_dronecan, uint8_t node_id, uint8_t sensor_id, uint32_t devid);
|
2023-04-08 00:53:24 -03:00
|
|
|
|
|
|
|
void read(void) override;
|
|
|
|
|
|
|
|
static void subscribe_msgs(AP_DroneCAN* ap_dronecan);
|
|
|
|
static AP_Compass_Backend* probe(uint8_t index);
|
|
|
|
static uint32_t get_detected_devid(uint8_t index) { return _detected_modules[index].devid; }
|
|
|
|
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);
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool init();
|
|
|
|
|
|
|
|
// callback for DroneCAN messages
|
|
|
|
void handle_mag_msg(const Vector3f &mag);
|
|
|
|
|
2023-04-08 01:27:51 -03:00
|
|
|
static AP_Compass_DroneCAN* get_dronecan_backend(AP_DroneCAN* ap_dronecan, uint8_t node_id, uint8_t sensor_id);
|
2023-04-08 00:53:24 -03:00
|
|
|
|
|
|
|
uint8_t _instance;
|
|
|
|
|
|
|
|
AP_DroneCAN* _ap_dronecan;
|
|
|
|
uint8_t _node_id;
|
|
|
|
uint8_t _sensor_id;
|
|
|
|
uint32_t _devid;
|
|
|
|
|
|
|
|
// Module Detection Registry
|
|
|
|
static struct DetectedModules {
|
|
|
|
AP_DroneCAN* ap_dronecan;
|
|
|
|
uint8_t node_id;
|
|
|
|
uint8_t sensor_id;
|
2023-04-08 01:09:10 -03:00
|
|
|
AP_Compass_DroneCAN *driver;
|
2023-04-08 00:53:24 -03:00
|
|
|
uint32_t devid;
|
|
|
|
} _detected_modules[COMPASS_MAX_BACKEND];
|
|
|
|
|
|
|
|
static HAL_Semaphore _sem_registry;
|
|
|
|
};
|
|
|
|
|
2023-04-08 00:58:13 -03:00
|
|
|
#endif // AP_COMPASS_DRONECAN_ENABLED
|