CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_DroneCAN/AP_Canard_iface.h
Views: 1798
1
#pragma once
2
#include <AP_HAL/AP_HAL.h>
3
#if HAL_ENABLE_DRONECAN_DRIVERS
4
#include <canard/interface.h>
5
#include <dronecan_msgs.h>
6
7
class AP_DroneCAN;
8
class CANSensor;
9
10
class CanardInterface : public Canard::Interface {
11
friend class AP_DroneCAN;
12
public:
13
14
/// @brief delete copy constructor and assignment operator
15
CanardInterface(const CanardInterface&) = delete;
16
CanardInterface& operator=(const CanardInterface&) = delete;
17
18
CanardInterface(uint8_t driver_index);
19
20
void init(void* mem_arena, size_t mem_arena_size, uint8_t node_id);
21
22
/// @brief broadcast message to all listeners on Interface
23
/// @param bc_transfer
24
/// @return true if message was added to the queue
25
bool broadcast(const Canard::Transfer &bcast_transfer) override;
26
27
/// @brief request message from
28
/// @param destination_node_id
29
/// @param req_transfer
30
/// @return true if request was added to the queue
31
bool request(uint8_t destination_node_id, const Canard::Transfer &req_transfer) override;
32
33
/// @brief respond to a request
34
/// @param destination_node_id
35
/// @param res_transfer
36
/// @return true if response was added to the queue
37
bool respond(uint8_t destination_node_id, const Canard::Transfer &res_transfer) override;
38
39
void processTx(bool raw_commands_only);
40
void processRx();
41
42
void process(uint32_t duration);
43
44
static void onTransferReception(CanardInstance* ins, CanardRxTransfer* transfer);
45
static bool shouldAcceptTransfer(const CanardInstance* ins,
46
uint64_t* out_data_type_signature,
47
uint16_t data_type_id,
48
CanardTransferType transfer_type,
49
uint8_t source_node_id);
50
51
bool add_interface(AP_HAL::CANIface *can_drv);
52
53
// add an auxillary driver for 11 bit frames
54
bool add_11bit_driver(CANSensor *sensor);
55
56
// handler for outgoing frames for auxillary drivers
57
bool write_aux_frame(AP_HAL::CANFrame &out_frame, const uint32_t timeout_us);
58
59
#if AP_TEST_DRONECAN_DRIVERS
60
static CanardInterface& get_test_iface() { return test_iface; }
61
static void processTestRx();
62
#endif
63
64
void update_rx_protocol_stats(int16_t res);
65
66
uint8_t get_node_id() const override { return canard.node_id; }
67
private:
68
CanardInstance canard;
69
AP_HAL::CANIface* ifaces[HAL_NUM_CAN_IFACES];
70
#if AP_TEST_DRONECAN_DRIVERS
71
static CanardInterface* canard_ifaces[3];
72
static CanardInterface test_iface;
73
#endif
74
uint8_t num_ifaces;
75
HAL_BinarySemaphore sem_handle;
76
bool initialized;
77
HAL_Semaphore _sem_tx;
78
HAL_Semaphore _sem_rx;
79
CanardTxTransfer tx_transfer;
80
dronecan_protocol_Stats protocol_stats;
81
82
// auxillary 11 bit CANSensor
83
CANSensor *aux_11bit_driver;
84
};
85
#endif // HAL_ENABLE_DRONECAN_DRIVERS
86
87