Skip to content

Commit

Permalink
AP_Networking: support UDP server, TCP client and TCP server
Browse files Browse the repository at this point in the history
and implement mavlink packetisation and flow control return
  • Loading branch information
tridge committed Nov 26, 2023
1 parent 132c768 commit 9ff469d
Show file tree
Hide file tree
Showing 2 changed files with 292 additions and 22 deletions.
24 changes: 24 additions & 0 deletions libraries/AP_Networking/AP_Networking.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ class AP_Networking
enum class NetworkPortType {
NONE = 0,
UDP_CLIENT = 1,
UDP_SERVER = 2,
TCP_CLIENT = 3,
TCP_SERVER = 4,
};

// class for NET_Pn_* parameters
Expand All @@ -199,6 +202,7 @@ class AP_Networking
AP_Networking_IPV4 ip {"0.0.0.0"};
AP_Int32 port;
SocketAPM *sock;
SocketAPM *listen_sock;

bool is_initialized() override {
return true;
Expand All @@ -208,7 +212,16 @@ class AP_Networking
}

void udp_client_init(const uint32_t size_rx, const uint32_t size_tx);
void udp_server_init(const uint32_t size_rx, const uint32_t size_tx);
void tcp_server_init(const uint32_t size_rx, const uint32_t size_tx);
void tcp_client_init(const uint32_t size_rx, const uint32_t size_tx);

void udp_client_loop(void);
void udp_server_loop(void);
void tcp_client_loop(void);
void tcp_server_loop(void);

bool send_receive(void);

private:
bool init_buffers(const uint32_t size_rx, const uint32_t size_tx);
Expand All @@ -222,10 +235,21 @@ class AP_Networking
void _flush() override {}
bool _discard_input() override;

enum flow_control get_flow_control(void) override;

uint32_t bw_in_bytes_per_second() const override {
return 1000000UL;
}

ByteBuffer *readbuffer;
ByteBuffer *writebuffer;
uint32_t last_size_tx;
uint32_t last_size_rx;
bool packetise;
bool connected;
bool have_received;
bool close_on_recv_error;

HAL_Semaphore sem;
};

Expand Down
Loading

0 comments on commit 9ff469d

Please sign in to comment.