Skip to content

Commit 6a4093e

Browse files
Finished API docs
1 parent fb14228 commit 6a4093e

File tree

1 file changed

+180
-25
lines changed

1 file changed

+180
-25
lines changed

libraries/WiFiS3/src/WiFiUdp.h

Lines changed: 180 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,57 +48,212 @@ class WiFiUDP : public UDP {
4848
virtual void read_if_needed(size_t s);
4949

5050
public:
51-
WiFiUDP(); // Constructor
52-
virtual uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
51+
/**
52+
* @brief Default constructor for the WiFiUDP class.
53+
*/
54+
WiFiUDP();
55+
56+
/**
57+
* @brief Starts a UDP socket on the specified local port.
58+
*
59+
* @param `uint16_t` The local port number to bind the UDP socket to.
60+
*
61+
* @return Returns `1` if the socket is successfully opened, or
62+
* `0` if the socket is already in use or could not be opened.
63+
*/
64+
virtual uint8_t begin(uint16_t);
65+
66+
/**
67+
* @brief Starts a UDP socket bound to a specific IP address and port.
68+
*
69+
* @param `a` The local IP address to bind the UDP socket to.
70+
* @param `p` The local port number to bind the UDP socket to.
71+
*
72+
* @return Returns `1` if the socket is successfully opened, or
73+
* `0` if the socket is already in use or could not be opened.
74+
*/
5375
virtual uint8_t begin(IPAddress a, uint16_t p);
54-
virtual uint8_t beginMulticast(IPAddress, uint16_t); // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 if there are no sockets available to use
55-
virtual void stop(); // Finish with the UDP socket
76+
77+
/**
78+
* @brief Starts a UDP multicast socket bound to a specific IP address and port.
79+
*
80+
* @param `IPAddress` The multicast IP address to bind the UDP socket to.
81+
* @param `uint16_t` The port number to bind the UDP socket to.
82+
*
83+
* @return Returns `1` if the socket is successfully opened, or
84+
* `0` if the socket is already in use or could not be opened.
85+
*/
86+
virtual uint8_t beginMulticast(IPAddress, uint16_t);
87+
88+
/**
89+
* @brief Stops the UDP socket and releases its resources.
90+
*/
91+
virtual void stop();
5692

57-
// Sending UDP packets
93+
/**
94+
* @brief Begins constructing a multicast UDP packet for sending.
95+
*
96+
* @return Returns `1` if the packet preparation is successful.
97+
* Or `0` if there is an error or the socket is not initialized.
98+
*/
5899
virtual int beginMulticastPacket();
59-
// Start building up a packet to send to the remote host specific in ip and port
60-
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
100+
101+
/**
102+
* @brief Begins constructing a UDP packet for sending to a specific IP address and port.
103+
*
104+
* @param `ip` The destination IP address as an `IPAddress` object.
105+
* @param `port` The destination port number.
106+
*
107+
* @return Returns `1` if the packet preparation is successful.
108+
* Or `0` if there is an error or the socket is not initialized.
109+
*/
61110
virtual int beginPacket(IPAddress ip, uint16_t port);
62-
// Start building up a packet to send to the remote host specific in host and port
63-
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
111+
112+
/**
113+
* @brief Begins constructing a UDP packet for sending to a specific hostname and port.
114+
*
115+
* @param `host` The destination hostname as a null-terminated string.
116+
* @param `port` The destination port number.
117+
*
118+
* @return Returns `1` if the packet preparation is successful.
119+
* Or `0` if there is an error or the socket is not initialized.
120+
*/
64121
virtual int beginPacket(const char *host, uint16_t port);
65-
// Finish off this packet and send it
66-
// Returns 1 if the packet was sent successfully, 0 if there was an error
122+
123+
/**
124+
* @brief Completes the construction of a UDP packet and sends it to the specified destination.
125+
*
126+
* @return Returns `1` if the packet is successfully transmitted.
127+
* Or `0` if there is an error or the socket is not initialized.
128+
*/
67129
virtual int endPacket();
68-
// Write a single byte into the packet
130+
131+
/**
132+
* @brief Sends a single byte of data to the currently opened UDP packet.
133+
*
134+
* @param `b` The byte of data to send.
135+
*
136+
* @return Returns `1` if the byte was successfully written.
137+
* Or `0` if there was an error or the packet was not properly initialized.
138+
*/
69139
virtual size_t write(uint8_t);
70-
// Write size bytes from buffer into the packet
140+
141+
/**
142+
* @brief Sends a buffer of data to the currently opened UDP packet.
143+
*
144+
* @param `buffer` A pointer to the buffer containing the data to send.
145+
* @param `size` The number of bytes from the buffer to write.
146+
*
147+
* @return Returns the number of bytes successfully written if the operation is successful.
148+
* Or `0` if the data was not successfully written, or if the packet was not properly initialized.
149+
*/
71150
virtual size_t write(const uint8_t *buffer, size_t size);
72151

152+
/**
153+
* @brief Inherits the `write` method from the `Print` class.
154+
*
155+
* This allows the `WiFiSSLClient` class to use the `write` method defined in the
156+
* `Print` class.
157+
*/
73158
using Print::write;
74159

75-
// Start processing the next available incoming packet
76-
// Returns the size of the packet in bytes, or 0 if no packets are available
160+
/**
161+
* @brief Start processing the next available incoming packet
162+
*
163+
* @return Returns the size of the incoming packet, or `0` if no packet is available.
164+
*/
77165
virtual int parsePacket();
78-
// Number of bytes remaining in the current packet
166+
167+
/**
168+
* @brief Checks if there are any available UDP packets to read.
169+
*
170+
* @return Returns the number of available bytes if packets are available, or `0` if no packets are available.
171+
*/
79172
virtual int available();
80-
// Read a single byte from the current packet
173+
174+
/**
175+
* @brief Read a single byte from the current packet
176+
*
177+
* @return Returns the number of bytes read into the buffer, or `-1` if an error occurs.
178+
*/
81179
virtual int read();
82-
// Read up to len bytes from the current packet and place them into buffer
83-
// Returns the number of bytes read, or 0 if none are available
180+
181+
/**
182+
* @brief Reads data from the UDP receive buffer into a provided buffer.
183+
*
184+
* @param `buffer` A pointer to the buffer where the received data will be stored.
185+
* @param `size` The number of bytes to read from the UDP buffer.
186+
*
187+
* @return The number of bytes successfully read into the buffer.
188+
* If less than `size` bytes are read, it indicates that the buffer was exhausted early.
189+
*/
84190
virtual int read(unsigned char* buffer, size_t len);
85-
// Read up to len characters from the current packet and place them into buffer
86-
// Returns the number of characters read, or 0 if none are available
191+
192+
193+
/**
194+
* @brief Reads data from the UDP receive buffer into a character buffer.
195+
*
196+
* @param `buffer` A pointer to the character buffer where the received data will be stored.
197+
* @param `len` The number of bytes to read from the UDP buffer.
198+
*
199+
* @return The number of bytes successfully read into the buffer.
200+
* If less than `len` bytes are read, it indicates that the buffer was exhausted early.
201+
*/
87202
virtual int read(char* buffer, size_t len) { return read((unsigned char*)buffer, len); };
88-
// Return the next byte from the current packet without moving on to the next byte
203+
204+
/**
205+
* @brief Peeks at the next byte available in the UDP buffer without moving on to the next byte.
206+
*
207+
* @return The value of the next byte in the UDP buffer, or `-1` if no data is available.
208+
*/
89209
virtual int peek();
210+
211+
/**
212+
* @brief Finish reading the current packet
213+
*/
90214
virtual void flush(); // Finish reading the current packet
215+
216+
/**
217+
* @brief Compares two WiFiUDP objects for equality.
218+
*
219+
* This function compares two `WiFiUDP` objects by checking if their associated
220+
* socket values (`_sock`) are the same.
221+
*
222+
* @param `WiFiUDP&` The WiFiUDP object to compare with the current object.
223+
*
224+
* @return `true` if the socket values are equal, `false` otherwise.
225+
*/
91226
virtual bool operator==(const WiFiUDP&);
227+
228+
/**
229+
* @brief Compares two WiFiUDP objects for inequality.
230+
*
231+
* This function compares two `WiFiUDP` objects by checking if their associated
232+
* socket values (`_sock`) are different.
233+
*
234+
* @param `whs` The WiFiUDP object to compare with the current object.
235+
* @return `true` if the socket values are different, `false` otherwise.
236+
*/
92237
virtual bool operator!=(const WiFiUDP& whs)
93238
{
94239
return !this->operator==(whs);
95240
};
96241

97-
// Return the IP address of the host who sent the current incoming packet
242+
/**
243+
* @brief Retrieves the remote IP address of the host who sent the current incoming packet.
244+
*
245+
* @return An `IPAddress` object representing the remote IP address. If the socket
246+
* is not valid or the address cannot be retrieved, it returns `IPAddress(0, 0, 0, 0)`.
247+
*/
98248
virtual IPAddress remoteIP();
99-
// Return the port of the host who sent the current incoming packet
249+
250+
/**
251+
* @brief Return the port of the host who sent the current incoming packet.
252+
*
253+
* @return The remote port number as a `uint16_t`. If the socket is not valid or
254+
* the port cannot be retrieved, it returns `0`.
255+
*/
100256
virtual uint16_t remotePort();
101-
102257

103258
};
104259

0 commit comments

Comments
 (0)