mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 14:38:30 -04:00
AP_UAVCAN: add Callback API to link UAVCAN backend callbacks
This commit is contained in:
parent
c79650a8d8
commit
f01cc254d3
@ -45,6 +45,18 @@
|
||||
|
||||
#define AP_UAVCAN_MAX_LED_DEVICES 4
|
||||
|
||||
/*
|
||||
Frontend Backend-Registry Binder: Whenever a message of said DataType_ from new node is received,
|
||||
the Callback will invoke registery to register the node as separate backend.
|
||||
*/
|
||||
#define UC_REGISTRY_BINDER(ClassName_, DataType_) \
|
||||
class ClassName_ : public AP_UAVCAN::RegistryBinder<DataType_> { \
|
||||
public: \
|
||||
ClassName_() : RegistryBinder() {} \
|
||||
ClassName_(AP_UAVCAN* uc, void (*ffunc)(AP_UAVCAN*, uint8_t, const ClassName_&)) : \
|
||||
RegistryBinder(uc, (Registry)ffunc) {} \
|
||||
}
|
||||
|
||||
class AP_UAVCAN : public AP_HAL::CANProtocol {
|
||||
public:
|
||||
AP_UAVCAN();
|
||||
@ -57,6 +69,9 @@ public:
|
||||
|
||||
void init(uint8_t driver_index) override;
|
||||
|
||||
uavcan::Node<0>* get_node() { return _node; }
|
||||
uint8_t get_driver_index() { return _driver_index; }
|
||||
|
||||
|
||||
///// SRV output /////
|
||||
void SRV_push_servos(void);
|
||||
@ -133,6 +148,33 @@ public:
|
||||
BatteryInfo_Info *find_bi_id(uint8_t id);
|
||||
void update_bi_state(uint8_t id);
|
||||
|
||||
|
||||
template <typename DataType_>
|
||||
class RegistryBinder {
|
||||
protected:
|
||||
typedef void* (*Registry)(AP_UAVCAN* _ap_uavcan, uint8_t _node_id, const RegistryBinder& _cb);
|
||||
AP_UAVCAN* _uc;
|
||||
Registry _ffunc;
|
||||
|
||||
public:
|
||||
RegistryBinder() :
|
||||
_uc(),
|
||||
_ffunc(),
|
||||
msg() {}
|
||||
|
||||
RegistryBinder(AP_UAVCAN* uc, Registry ffunc) :
|
||||
_uc(uc),
|
||||
_ffunc(ffunc),
|
||||
msg(nullptr) {}
|
||||
|
||||
void operator()(const uavcan::ReceivedDataStructure<DataType_>& _msg) {
|
||||
msg = &_msg;
|
||||
_ffunc(_uc, _msg.getSrcNodeID().get(), *this);
|
||||
}
|
||||
|
||||
const uavcan::ReceivedDataStructure<DataType_> *msg;
|
||||
};
|
||||
|
||||
private:
|
||||
class SystemClock: public uavcan::ISystemClock, uavcan::Noncopyable {
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user