2017-04-02 11:56:15 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AP_Compass.h"
|
|
|
|
#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:
|
2018-08-06 19:21:27 -03:00
|
|
|
AP_Compass_UAVCAN(AP_UAVCAN* ap_uavcan, uint8_t node_id, uint8_t sensor_id);
|
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);
|
2018-08-06 19:21:27 -03:00
|
|
|
static AP_Compass_Backend* probe();
|
2017-04-02 11:56:15 -03:00
|
|
|
|
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:
|
|
|
|
void 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 bool take_registry();
|
|
|
|
static void give_registry();
|
|
|
|
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
|
|
|
bool _initialized;
|
|
|
|
|
|
|
|
AP_UAVCAN* _ap_uavcan;
|
|
|
|
uint8_t _node_id;
|
|
|
|
uint8_t _sensor_id;
|
|
|
|
|
|
|
|
// Module Detection Registry
|
|
|
|
static struct DetectedModules {
|
|
|
|
AP_UAVCAN* ap_uavcan;
|
|
|
|
uint8_t node_id;
|
|
|
|
uint8_t sensor_id;
|
|
|
|
AP_Compass_UAVCAN *driver;
|
|
|
|
} _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
|
|
|
};
|