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_DroneCAN_serial.h
Views: 1798
1
#pragma once
2
3
#include <AP_SerialManager/AP_SerialManager.h>
4
5
#ifndef AP_DRONECAN_SERIAL_NUM_PORTS
6
#define AP_DRONECAN_SERIAL_NUM_PORTS 3
7
#endif
8
9
class AP_DroneCAN;
10
11
class AP_DroneCAN_Serial
12
{
13
public:
14
/* Do not allow copies */
15
CLASS_NO_COPY(AP_DroneCAN_Serial);
16
17
AP_DroneCAN_Serial() {}
18
19
AP_Int8 enable;
20
21
void init(AP_DroneCAN *dronecan);
22
void update(void);
23
24
public:
25
class Port : public AP_SerialManager::RegisteredPort {
26
public:
27
friend class AP_DroneCAN_Serial;
28
void init(void);
29
30
AP_Int8 node;
31
AP_Int8 idx;
32
33
private:
34
bool is_initialized() override {
35
return true;
36
}
37
bool tx_pending() override {
38
return false;
39
}
40
41
bool init_buffers(const uint32_t size_rx, const uint32_t size_tx);
42
43
uint32_t txspace() override;
44
void _begin(uint32_t b, uint16_t rxS, uint16_t txS) override;
45
size_t _write(const uint8_t *buffer, size_t size) override;
46
ssize_t _read(uint8_t *buffer, uint16_t count) override;
47
uint32_t _available() override;
48
void _end() override {}
49
void _flush() override {}
50
bool _discard_input() override;
51
uint64_t receive_time_constraint_us(uint16_t nbytes) override;
52
53
ByteBuffer *readbuffer;
54
ByteBuffer *writebuffer;
55
uint32_t baudrate;
56
uint32_t last_send_ms;
57
uint32_t last_size_tx;
58
uint32_t last_size_rx;
59
uint64_t last_recv_us;
60
61
HAL_Semaphore sem;
62
};
63
64
Port ports[AP_DRONECAN_SERIAL_NUM_PORTS];
65
66
private:
67
AP_DroneCAN *dronecan;
68
69
Canard::Publisher<uavcan_tunnel_Targetted> *targetted;
70
static void handle_tunnel_targetted(AP_DroneCAN *dronecan,
71
const CanardRxTransfer& transfer,
72
const uavcan_tunnel_Targetted &msg);
73
74
static AP_DroneCAN_Serial *serial[HAL_MAX_CAN_PROTOCOL_DRIVERS];
75
};
76
77