File tree 2 files changed +18
-17
lines changed
2 files changed +18
-17
lines changed Original file line number Diff line number Diff line change @@ -59,29 +59,26 @@ int WiFiUDP::beginPacket(const char *host, uint16_t port) {
59
59
}
60
60
61
61
int WiFiUDP::endPacket () {
62
+ return 0 ;
62
63
}
63
64
64
- size_t WiFiUDP::write (uint8_t ) {
65
+ size_t WiFiUDP::write (uint8_t byte ) {
65
66
return write (&byte, 1 );
66
67
}
67
68
68
69
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
77
78
}
78
- };
79
- size_t bytes_written = socket.send (buffer, size, &addr);
80
- if (bytes_written != size) {
81
- _status = SOCKET_STATUS_ERROR;
82
- return 0 ;
83
79
}
84
- return bytes_written;
80
+
81
+ return bytesStored; // Return the number of bytes successfully stored
85
82
}
86
83
87
84
int WiFiUDP::parsePacket () {
Original file line number Diff line number Diff line change 11
11
12
12
class WiFiUDP : public arduino ::UDP {
13
13
public:
14
+
15
+ static const size_t WIFI_UDP_BUFFER_SIZE = 256 ;
16
+
14
17
WiFiUDP ();
15
18
uint8_t begin (uint16_t );
16
19
@@ -19,9 +22,8 @@ class WiFiUDP: public arduino::UDP {
19
22
int beginPacket (IPAddress ip, uint16_t port);
20
23
int beginPacket (const char *host, uint16_t port);
21
24
int endPacket ();
22
- size_t write (uint8_t );
25
+ size_t write (uint8_t byte );
23
26
size_t write (const uint8_t *buffer, size_t size);
24
-
25
27
using Print::write;
26
28
int parsePacket ();
27
29
int available ();
@@ -44,6 +46,8 @@ class WiFiUDP: public arduino::UDP {
44
46
IPAddress remote_ip;
45
47
uint16_t _port;
46
48
49
+ arduino::RingBufferN < WIFI_UDP_BUFFER_SIZE > txBuffer;
50
+
47
51
};
48
52
49
53
#endif /* WIFI_UDP_H */
You can’t perform that action at this time.
0 commit comments