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-08-26 01:12:08 -03:00
|
|
|
AP_Compass_DroneCAN(AP_DroneCAN* ap_dronecan, uint32_t devid);
|
2023-04-08 00:53:24 -03:00
|
|
|
|
|
|
|
void read(void) override;
|
|
|
|
|
2024-11-16 23:21:13 -04:00
|
|
|
static bool subscribe_msgs(AP_DroneCAN* ap_dronecan);
|
2023-04-08 00:53:24 -03:00
|
|
|
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);
|
2024-03-02 18:04:32 -04:00
|
|
|
#if AP_COMPASS_DRONECAN_HIRES_ENABLED
|
|
|
|
static void handle_magnetic_field_hires(AP_DroneCAN *ap_dronecan, const CanardRxTransfer& transfer, const dronecan_sensors_magnetometer_MagneticFieldStrengthHiRes &msg);
|
|
|
|
#endif
|
2023-04-08 00:53:24 -03:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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
|