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"
|
|
|
|
|
|
|
|
#include <AP_UAVCAN/AP_UAVCAN.h>
|
|
|
|
|
2018-07-20 08:18:00 -03:00
|
|
|
class MagCb;
|
|
|
|
class Mag2Cb;
|
|
|
|
|
2017-04-02 11:56:15 -03:00
|
|
|
class AP_Compass_UAVCAN : public AP_Compass_Backend {
|
|
|
|
public:
|
2020-07-20 18:25:08 -03:00
|
|
|
AP_Compass_UAVCAN(AP_UAVCAN* ap_uavcan, 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;
|
|
|
|
|
2018-07-20 08:18:00 -03:00
|
|
|
static void subscribe_msgs(AP_UAVCAN* ap_uavcan);
|
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; }
|
2018-07-20 08:18:00 -03:00
|
|
|
static void handle_magnetic_field(AP_UAVCAN* ap_uavcan, uint8_t node_id, const MagCb &cb);
|
|
|
|
static void handle_magnetic_field_2(AP_UAVCAN* ap_uavcan, uint8_t node_id, const Mag2Cb &cb);
|
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
|
|
|
|
2018-07-20 08:18:00 -03:00
|
|
|
// callback for UAVCAN messages
|
|
|
|
void handle_mag_msg(const Vector3f &mag);
|
|
|
|
|
|
|
|
static AP_Compass_UAVCAN* get_uavcan_backend(AP_UAVCAN* ap_uavcan, 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
|
|
|
|
|
|
|
AP_UAVCAN* _ap_uavcan;
|
|
|
|
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 {
|
|
|
|
AP_UAVCAN* ap_uavcan;
|
|
|
|
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
|