Skip to content

Commit 33072a1

Browse files
committed
libraries/WiFi: Write function.
Signed-off-by: IFX-Anusha <[email protected]>
1 parent 2fc25db commit 33072a1

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

libraries/WiFi/src/WiFiUdp.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,26 @@ int WiFiUDP::beginPacket(const char *host, uint16_t port) {
5959
}
6060

6161
int WiFiUDP::endPacket() {
62+
return 0;
6263
}
6364

64-
size_t WiFiUDP::write(uint8_t) {
65+
size_t WiFiUDP::write(uint8_t byte) {
6566
return write(&byte, 1);
6667
}
6768

6869
size_t WiFiUDP::write(const uint8_t *buffer, size_t size) {
69-
if (size == 0) {
70-
return 0;
71-
}
72-
cy_socket_sockaddr_t addr = {
73-
.port = _port,
74-
.ip_address = {
75-
.version = CY_SOCKET_IP_VER_V4,
76-
.ip = { .v4 = (uint32_t)remote_ip }
70+
size_t bytesStored = 0;
71+
72+
for (size_t i = 0; i < size; i++) {
73+
if (!txBuffer.isFull()) { // Check if the buffer is not full
74+
txBuffer.store_char(buffer[i]);
75+
bytesStored++;
76+
} else {
77+
break; // Stop if the buffer is full
7778
}
78-
};
79-
size_t bytes_written = socket.send(buffer, size, &addr);
80-
if (bytes_written != size) {
81-
_status = SOCKET_STATUS_ERROR;
82-
return 0;
8379
}
84-
return bytes_written;
80+
81+
return bytesStored; // Return the number of bytes successfully stored
8582
}
8683

8784
int WiFiUDP::parsePacket() {

libraries/WiFi/src/WiFiUdp.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
class WiFiUDP: public arduino::UDP {
1313
public:
14+
15+
static const size_t WIFI_UDP_BUFFER_SIZE = 256;
16+
1417
WiFiUDP();
1518
uint8_t begin(uint16_t);
1619

@@ -19,9 +22,8 @@ class WiFiUDP: public arduino::UDP {
1922
int beginPacket(IPAddress ip, uint16_t port);
2023
int beginPacket(const char *host, uint16_t port);
2124
int endPacket();
22-
size_t write(uint8_t);
25+
size_t write(uint8_t byte);
2326
size_t write(const uint8_t *buffer, size_t size);
24-
2527
using Print::write;
2628
int parsePacket();
2729
int available();
@@ -44,6 +46,8 @@ class WiFiUDP: public arduino::UDP {
4446
IPAddress remote_ip;
4547
uint16_t _port;
4648

49+
arduino::RingBufferN < WIFI_UDP_BUFFER_SIZE > txBuffer;
50+
4751
};
4852

4953
#endif /* WIFI_UDP_H */

0 commit comments

Comments
 (0)