Skip to content

Commit 1268679

Browse files
committed
libraries/WiFi: WiFiUDP Class added.
Signed-off-by: IFX-Anusha <[email protected]>
1 parent fd81506 commit 1268679

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed

libraries/WiFi/src/WiFiUdp.cpp

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#include "WiFiUdp.h"
2+
3+
#define udp_assert(cy_ret) if (cy_ret != CY_RSLT_SUCCESS) { \
4+
_status = SOCKET_STATUS_ERROR; \
5+
return; \
6+
}
7+
8+
#define udp_assert_raise(cy_ret) if (cy_ret != CY_RSLT_SUCCESS) { \
9+
return cy_ret; \
10+
}
11+
12+
WiFiUDP::WiFiUDP() :
13+
client_handle(nullptr),
14+
_status(SOCKET_STATUS_UNINITED),
15+
_last_error(CY_RSLT_SUCCESS) {
16+
}
17+
18+
uint8_t WiFiUDP::begin(uint16_t port) {
19+
_last_error = WiFiUDP::global_sockets_init();
20+
udp_assert_raise(_last_error);
21+
22+
/* Create a UDP socket */
23+
_last_error = cy_socket_create(CY_SOCKET_DOMAIN_AF_INET, CY_SOCKET_TYPE_DGRAM, CY_SOCKET_IPPROTO_UDP, &client_handle);
24+
udp_assert_raise(_last_error);
25+
26+
_status = SOCKET_STATUS_CREATED;
27+
return 1;
28+
}
29+
30+
31+
void WiFiUDP::stop() {
32+
33+
}
34+
35+
int WiFiUDP::beginPacket(IPAddress ip, uint16_t port) {
36+
return 0;
37+
}
38+
39+
int WiFiUDP::beginPacket(const char *host, uint16_t port) {
40+
return 0;
41+
}
42+
43+
int WiFiUDP::endPacket() {
44+
return 0;
45+
}
46+
47+
size_t WiFiUDP::write(uint8_t) {
48+
return 0;
49+
}
50+
51+
size_t WiFiUDP::write(const uint8_t *buffer, size_t size) {
52+
return 0;
53+
}
54+
55+
int WiFiUDP::parsePacket() {
56+
return 0;
57+
}
58+
59+
int WiFiUDP::available() {
60+
return 0;
61+
}
62+
63+
int WiFiUDP::read() {
64+
return 0;
65+
}
66+
67+
int WiFiUDP::read(unsigned char *buffer, size_t len) {
68+
return 0;
69+
}
70+
71+
int WiFiUDP::read(char *buffer, size_t len) {
72+
return 0;
73+
}
74+
75+
int WiFiUDP::peek() {
76+
return 0;
77+
}
78+
79+
void WiFiUDP::flush() {
80+
return;
81+
}
82+
83+
IPAddress WiFiUDP::remoteIP() {
84+
return IPAddress();
85+
}
86+
87+
uint16_t WiFiUDP::remotePort() {
88+
return 0;
89+
}
90+
91+
bool WiFiUDP::global_socket_initialized = false;
92+
uint32_t WiFiUDP::global_socket_count = 0;
93+
94+
cy_rslt_t WiFiUDP::global_sockets_init() {
95+
if (!WiFiUDP::global_socket_initialized) {
96+
cy_rslt_t ret = cy_socket_init();
97+
if (ret != CY_RSLT_SUCCESS) {
98+
return ret;
99+
}
100+
WiFiUDP::global_socket_initialized = true;
101+
}
102+
WiFiUDP::global_socket_count++;
103+
return CY_RSLT_SUCCESS;
104+
}

libraries/WiFi/src/WiFiUdp.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#ifndef WIFI_UDP_H
2+
#define WIFI_UDP_H
3+
4+
#include <stdint.h>
5+
#include <string.h>
6+
#include <api/Udp.h>
7+
#include "WiFiClient.h"
8+
#include "WiFi.h"
9+
#include "WiFiServer.h"
10+
#include "SecSocket.h"
11+
12+
class WiFiUDP: public arduino::UDP {
13+
public:
14+
WiFiUDP();
15+
uint8_t begin(uint16_t);
16+
17+
// yet to implement these functions
18+
void stop();
19+
int beginPacket(IPAddress ip, uint16_t port);
20+
int beginPacket(const char *host, uint16_t port);
21+
int endPacket();
22+
size_t write(uint8_t);
23+
size_t write(const uint8_t *buffer, size_t size);
24+
25+
using Print::write;
26+
int parsePacket();
27+
int available();
28+
int read();
29+
int read(unsigned char *buffer, size_t len);
30+
int read(char *buffer, size_t len);
31+
int peek();
32+
void flush();
33+
IPAddress remoteIP();
34+
uint16_t remotePort();
35+
36+
37+
38+
private:
39+
cy_socket_t client_handle;
40+
socket_status_t _status;
41+
cy_rslt_t _last_error;
42+
43+
static bool global_socket_initialized;
44+
static uint32_t global_socket_count;
45+
cy_rslt_t global_sockets_init();
46+
cy_rslt_t global_sockets_deinit();
47+
};
48+
49+
#endif /* WIFI_UDP_H */

0 commit comments

Comments
 (0)