Mbed OS Reference
Loading...
Searching...
No Matches
ESP32Stack.h
1/* ESP32 implementation of NetworkInterfaceAPI
2 * Copyright (c) 2015 ARM Limited
3 * Copyright (c) 2017 Renesas Electronics Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef ESP32_STACK_H
19#define ESP32_STACK_H
20
21
22#include "ESP32.h"
25#include "netsocket/nsapi_types.h"
27
28/** ESP32Stack class
29 * Implementation of the NetworkStack for the ESP32
30 */
31class ESP32Stack : public NetworkStack {
32protected:
33 /** ESP32Stack lifetime
34 * @param en EN pin
35 * @param io0 IO0 pin
36 * @param tx TX pin
37 * @param rx RX pin
38 * @param debug Enable debugging
39 * @param rts RTS pin
40 * @param cts CTS pin
41 * @param baudrate The baudrate of the serial port.
42 * @param is_ap 0:Terminal 1:Access point.
43 */
44 ESP32Stack(PinName en, PinName io0, PinName tx, PinName rx, bool debug,
45 PinName rts, PinName cts, int baudrate, int is_ap);
46
47protected:
48 int socket_open(void **handle, nsapi_protocol_t proto) override;
49
50 int socket_close(void *handle) override;
51
52 int socket_bind(void *handle, const SocketAddress &address) override;
53
54 int socket_listen(void *handle, int backlog) override;
55
56 int socket_connect(void *handle, const SocketAddress &address) override;
57
58 int socket_accept(void *handle, void **socket, SocketAddress *address) override;
59
60 int socket_send(void *handle, const void *data, unsigned size) override;
61
62 int socket_recv(void *handle, void *data, unsigned size) override;
63
64 int socket_sendto(void *handle, const SocketAddress &address, const void *data, unsigned size) override;
65
66 int socket_recvfrom(void *handle, SocketAddress *address, void *buffer, unsigned size) override;
67
68 void socket_attach(void *handle, void (*callback)(void *), void *data) override;
69
71 int optname, const void *optval, unsigned optlen) override;
72
74 int optname, void *optval, unsigned *optlen) override;
75
76protected:
77 ESP32 *_esp;
78 uint16_t _local_ports[ESP32::SOCKET_COUNT];
79 int _is_ap;
80};
81
82#endif
Network Interface base class.
NetworkStack class.
Common interface between Wi-Fi devices.
ESP32Stack class Implementation of the NetworkStack for the ESP32.
Definition ESP32Stack.h:31
int socket_bind(void *handle, const SocketAddress &address) override
Bind a specific address to a socket.
int socket_open(void **handle, nsapi_protocol_t proto) override
Opens a socket.
void socket_attach(void *handle, void(*callback)(void *), void *data) override
Register a callback on state change of the socket.
int socket_close(void *handle) override
Close the socket.
int socket_accept(void *handle, void **socket, SocketAddress *address) override
Accepts a connection on a TCP socket.
nsapi_error_t setsockopt(nsapi_socket_t handle, int level, int optname, const void *optval, unsigned optlen) override
Set stack-specific socket options.
nsapi_error_t getsockopt(nsapi_socket_t handle, int level, int optname, void *optval, unsigned *optlen) override
Get stack-specific socket options.
ESP32Stack(PinName en, PinName io0, PinName tx, PinName rx, bool debug, PinName rts, PinName cts, int baudrate, int is_ap)
ESP32Stack lifetime.
int socket_listen(void *handle, int backlog) override
Listen for connections on a TCP socket.
int socket_connect(void *handle, const SocketAddress &address) override
Connects TCP socket to a remote host.
NetworkStack class.
SocketAddress class.
signed int nsapi_error_t
Type used to represent error codes.
void * nsapi_socket_t
Opaque handle for network sockets.