Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3b280c5

Browse files
authoredMar 14, 2025··
Merge branch 'arduino:main' into useSymlink
2 parents 5a36024 + 84d44b8 commit 3b280c5

File tree

12 files changed

+2359
-165
lines changed

12 files changed

+2359
-165
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ cores/arduino/mydebug.cpp.donotuse
99
.DS_Store?
1010
/.vs
1111
/.gitignore
12+
.vscode/settings.json

‎libraries/WiFiS3/docs/api.md

+1,243
Large diffs are not rendered by default.

‎libraries/WiFiS3/src/Modem.h

+84-1
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,106 @@
1515

1616
#define DO_NOT_CHECK_CMD "NO_CMD_CHECK"
1717

18+
/**
19+
* @brief A class that provides methods to interact with a modem.
20+
*
21+
* This class is responsible for providing an interface to communicate with
22+
* a modem through serial communication. It includes methods for initialization,
23+
* sending and receiving data, and handling modem configurations.
24+
*/
1825
class ModemClass {
1926

2027
public:
28+
/**
29+
* @brief Constructor for the ModemClass, which initializes the modem with the specified transmit (TX) and receive (RX) pins.
30+
*
31+
* @param Initializes an instance of the ModemClass class with
32+
* specific transmit `tx` and receive `rx` pins for communication.
33+
*/
2134
ModemClass(int tx, int rx);
35+
36+
/**
37+
* @brief Constructor for the ModemClass, which initializes the modem with the specified UART interface.
38+
*
39+
* @param `_serial` is a pointer to the UART object that will be used for communication with the modem.
40+
*/
2241
ModemClass(UART * _serial);
42+
43+
/**
44+
* @brief Destructor for ModemClass.
45+
*/
2346
~ModemClass();
2447

48+
49+
/**
50+
* @brief Initializes the modem communication with a specified baud rate.
51+
*
52+
* @param[in] `badurate` sets the baud rate for the serial connection.
53+
*/
2554
void begin(int badurate = 115200, int retry = 3);
55+
56+
/**
57+
* @brief Ends the modem communication.
58+
*/
2659
void end();
60+
61+
62+
/**
63+
* @brief Sends a formatted command string to a device and stores the response.
64+
*
65+
* This function formats a command string using the provided format and arguments,
66+
* sends it to a device, and waits for a response, which is stored in the `str` string.
67+
*
68+
* @param `cmd` A string representing the command to be sent to the device.
69+
* @param `str` A reference to a string that will hold the device's response.
70+
* @param `fmt` A format string for constructing the command.
71+
*
72+
* @return `true` if the command was successfully sent and a response was received,
73+
* `false` otherwise.
74+
*/
2775
bool write(const std::string &cmd, std::string &str, const char * fmt, ...);
76+
77+
/**
78+
* @brief Used to send a command to the modem without waiting for a response.
79+
*
80+
* @param It takes a command string `cmd`, a string `str` where the response will be stored,
81+
* and a format string `fmt` along with additional arguments.
82+
*/
2883
void write_nowait(const std::string &cmd, std::string &str, const char * fmt, ...);
2984

85+
/**
86+
* @brief Sends binary data directly to the modem without any processing or interpretation.
87+
*
88+
* @param It takes a pointer to the binary `data` and the `size` of the data as arguments.
89+
* Used for sending raw binary commands or data to the modem for operations that
90+
* require direct communication without any additional formatting or parsing.
91+
*/
3092
bool passthrough(const uint8_t *data, size_t size);
93+
94+
/**
95+
* @brief Disables automatic trimming of results for one operation.
96+
*
97+
* This function disables the automatic trimming of results for one operation.
98+
* After it is called, the results will not be trimmed automatically until
99+
* the function is called again.
100+
*/
31101
void avoid_trim_results() {
32102
/* one shot - it works only 1 time the it is necessary to call again this
33103
funtion */
34104
trim_results = false;
35105
}
36106

107+
/**
108+
* @brief Enables a specific mode of reading where the size of the data
109+
* to be read is considered for processing.
110+
*/
37111
void read_using_size() {
38112
// read_by_size = true; // deprecated
39113
}
114+
40115
bool beginned;
41116

42-
/* calling this function with no argument will enable debug message to be printed
117+
/* Calling this function with no argument will enable debug message to be printed
43118
on Serial
44119
use first parameter UART *u to redirect debug output to a different serial
45120
@@ -54,6 +129,9 @@ class ModemClass {
54129
_debug_level = level;
55130
}
56131

132+
/**
133+
* @brief Used to disable debugging output for the modem communication.
134+
*/
57135
void noDebug() {
58136
_serial_debug = nullptr;
59137
}
@@ -63,6 +141,11 @@ class ModemClass {
63141
void debug(bool e) {enable_dbg = e;}
64142
#endif
65143

144+
/**
145+
* @brief Sets the timeout value for communication operations.
146+
*
147+
* @param Can be called with a specified timeout value in milliseconds.
148+
*/
66149
void timeout(size_t timeout_ms) {_timeout = timeout_ms;}
67150

68151
private:

‎libraries/WiFiS3/src/StringHelpers.h

+55-2
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,69 @@
55
#include <vector>
66
#include <algorithm>
77

8+
/**
9+
* @brief Trims whitespace characters from the beginning of a string.
10+
*
11+
* @param `s` is the string from which leading whitespace characters will be removed.
12+
* The function modifies this string directly.
13+
*/
814
void ltrim(std::string &s);
915

10-
// trim from end (in place)
16+
/**
17+
* @brief Trims trailing whitespace characters from a string.
18+
*
19+
* @param `s` the string from which trailing whitespace characters will be removed.
20+
* The function modifies this string directly.
21+
*/
1122
void rtrim(std::string &s);
1223

13-
// trim from both ends (in place)
24+
25+
/**
26+
* @brief Trims whitespace characters from both ends of a string.
27+
*
28+
* This function removes any leading and trailing whitespace characters (spaces,
29+
* tabs, etc.) from the given string. It modifies the string in place, erasing
30+
* whitespace from both the beginning and the end of the string.
31+
*
32+
* @param `s` is the string from which both leading and trailing whitespace characters
33+
* will be removed. The function modifies this string directly.
34+
*/
1435
void trim(std::string &s);
1536

37+
/**
38+
* @brief Takes a string and splits it into substrings.
39+
*
40+
* This function splits a string into multiple substrings, storing each substring
41+
* as an element in the `res` vector. The string is split at each occurrence of
42+
* the specified delimiter. Optionally, the function can trim whitespace from
43+
* each token before storing it in the result vector.
44+
*
45+
* @param `res` is a reference to a vector of strings where the resulting tokens
46+
* will be stored.
47+
* @param `str` is the string to be split. This string will be modified as it is
48+
* split.
49+
* @param `delimiter` is the delimiter string that separates the tokens in `str`.
50+
* @param `_trim` is a boolean flag indicating whether to trim whitespace from each
51+
* token. If true, leading and trailing whitespace will be removed from each token. Defaults to true.
52+
*/
1653
void split(std::vector<std::string> &res, std::string &str, const std::string &delimiter, bool _trim = true);
1754

55+
/**
56+
* @brief Removes a specified substring from the beginning of a string.
57+
*
58+
* This function attempts to remove the first occurrence of the specified substring
59+
* (`what`) from the beginning of the string (`str`). Before performing the removal,
60+
* it trims leading whitespace from the string. If the substring is found at the
61+
* beginning of the string, it is removed, and the function returns `true`. Otherwise the
62+
* function returns `false`.
63+
*
64+
* @param `str` is a reference to the string from which the substring will be removed.
65+
* The string is modified if the substring is removed.
66+
* @param `what` is the substring to be removed from the beginning of `str`.
67+
*
68+
* @return `true` if the substring was found and removed from the beginning of
69+
* the string, `false` otherwise.
70+
*/
1871
bool removeAtBegin(std::string &str, const std::string &what);
1972

2073
#endif

‎libraries/WiFiS3/src/WiFi.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ IPAddress CWifi::localIP() {
397397
/* -------------------------------------------------------------------------- */
398398
modem.begin();
399399
string res = "";
400-
int attempts = 0;
401400
IPAddress local_IP(0,0,0,0);
402401

403402
if(modem.write(string(PROMPT(_MODE)),res, "%s" , CMD_READ(_MODE))) {

‎libraries/WiFiS3/src/WiFi.h

+278-133
Large diffs are not rendered by default.

‎libraries/WiFiS3/src/WiFiClient.h

+178
Original file line numberDiff line numberDiff line change
@@ -30,42 +30,220 @@
3030
#include "FifoBuffer.h"
3131
#include <memory>
3232

33+
34+
/**
35+
* @brief Represents a Wi-Fi client that connects to a remote server over a Wi-Fi network.
36+
*
37+
* The WiFiClient class allows for network communication over Wi-Fi, providing methods
38+
* for establishing connections, sending and receiving data, and managing the client’s
39+
* socket state. This class is used to manage client connections in a Wi-Fi network,
40+
* either for communication or for network data transfer.
41+
*
42+
* It inherits from the Client class, providing basic socket communication functionality.
43+
*/
3344
class WiFiClient : public Client {
3445

3546
public:
47+
/**
48+
* @brief Default constructor for the WiFiClient class.
49+
*/
3650
WiFiClient();
51+
3752
/* this constructor is not intended to be called outside of the Server class */
53+
/**
54+
* @brief Constructor to initialize a WiFiClient object with a specific socket.
55+
*
56+
* @param `s` is the socket descriptor to associate with this client.
57+
*/
3858
WiFiClient(int s);
59+
60+
/**
61+
* @brief Copy constructor for the WiFiClient class.
62+
*
63+
* @param `c` is the `WiFiClient` object to copy.
64+
*/
3965
WiFiClient(const WiFiClient& c);
66+
67+
/**
68+
* @brief Destructor for the WiFiClient class.
69+
*/
4070
~WiFiClient();
71+
72+
/**
73+
* @brief Establishes a connection to a server using an IP address and port.
74+
*
75+
* @param `ip` as the IP address of the server to connect to.
76+
* @param `port` as the port number on the server to connect to.
77+
*
78+
* @return `1` on a successful connection, `0` on failure.
79+
*/
4180
virtual int connect(IPAddress ip, uint16_t port);
81+
82+
/**
83+
* @brief Establishes a connection to a server using a hostname and port.
84+
*
85+
* @param `host` is a pointer to a null-terminated string containing the hostname of the server.
86+
* @param `port` is the port number on the server to connect to.
87+
*
88+
* @return `1` if the connection was successful, `0` otherwise.
89+
*/
4290
virtual int connect(const char *host, uint16_t port);
91+
92+
/**
93+
* @brief Sends a single byte of data to the connected server.
94+
*
95+
* @param `b` being the byte of data to send.
96+
*
97+
* @return The number of bytes successfully written, which is `1` on success or `0` on failure.
98+
*/
4399
virtual size_t write(uint8_t);
100+
101+
/**
102+
* @brief Writes a buffer of data to the connected server.
103+
*
104+
* @param Takes a pointer to a buffer `buf` containing the data to be written
105+
* and the size of the buffer `size` as parameters.
106+
*
107+
* @return The number of bytes successfully written, or `0` if the write operation fails.
108+
*/
44109
virtual size_t write(const uint8_t *buf, size_t size);
110+
111+
/**
112+
* @brief Checks the number of bytes available for reading from the server.
113+
*
114+
* @return The number of bytes available to read. Returns `0` if no data is
115+
* available, or if the socket is invalid.
116+
*/
45117
virtual int available();
118+
119+
/**
120+
* @brief Reads a single byte of data from the server.
121+
*
122+
* @return The byte read as an `int` (0–255). Returns `-1` if no data is available
123+
* or if an error occurs.
124+
*/
46125
virtual int read();
126+
127+
/**
128+
* @brief Reads multiple bytes of data from the server into a buffer.
129+
*
130+
* This function retrieves data from the server's receive buffer and stores it
131+
* into the provided array. It attempts to read up to the specified number of
132+
* bytes (`size`).
133+
*
134+
* @param[out] `buf` is a pointer to the buffer where the data will be stored.
135+
* @param[in] `size` is the maximum number of bytes to read.
136+
*
137+
* @return The number of bytes successfully read into the buffer.
138+
* Returns `0` if no data is available or if the socket is invalid.
139+
*/
47140
virtual int read(uint8_t *buf, size_t size);
141+
142+
/**
143+
* @brief Peeks at the next byte of incoming data without removing it from the internal buffer.
144+
*
145+
* @return The next byte as an `int` (0–255). Returns `-1` if no data is available
146+
* or if the socket is invalid.
147+
*/
48148
virtual int peek();
149+
150+
/**
151+
* @brief Flushes the write buffer of the client.
152+
*
153+
* This function ensures that any data buffered for transmission is sent to the
154+
* connected server. If there is any pending data in the send buffer, it is
155+
* transmitted over the network.
156+
*/
49157
virtual void flush();
158+
159+
/**
160+
* @brief Closes the connection to the server and clears the receive buffer.
161+
*/
50162
virtual void stop();
163+
164+
/**
165+
* @brief Checks if the client is connected to a server.
166+
*
167+
* @return Returns 1 if the client is connected, 0 otherwise.
168+
*/
51169
virtual uint8_t connected();
170+
171+
/**
172+
* @brief Implicit conversion operator to `bool`.
173+
*
174+
* Converts the `WiFiClient` object to a `bool` value indicating whether the client
175+
* is connected or not.
176+
*
177+
* @return `true` if the client socket is open and valid, `false` otherwise.
178+
*/
52179
virtual operator bool() {
53180
return _sock != -1;
54181
}
182+
183+
/**
184+
* @brief Equality operator for comparing two `WiFiClient` objects.
185+
*
186+
* Compares the current `WiFiClient` object with another `WiFiClient` object
187+
* to determine if they represent the same socket connection.
188+
*
189+
* @param The `WiFiClient` object to compare with.
190+
* @return `true` if both `WiFiClient` objects represent the same socket,
191+
* `false` otherwise.
192+
*/
55193
virtual bool operator==(const WiFiClient&);
194+
195+
/**
196+
* @brief Inequality operator for comparing two `WiFiClient` objects.
197+
*
198+
* Compares the current `WiFiClient` object with another `WiFiClient` object
199+
* to determine if they represent different socket connections.
200+
*
201+
* @param `whs` is the `WiFiClient` object to compare with.
202+
* @return `true` if both WiFiClient objects represent different sockets,
203+
* `false` if they represent the same socket.
204+
*/
56205
virtual bool operator!=(const WiFiClient& whs)
57206
{
58207
return !this->operator==(whs);
59208
};
209+
210+
/**
211+
* @brief Retrieves the remote IP address of the server the client is connected to.
212+
*
213+
* @return The IP address of the remote server. If not connected, returns IPAddress(0, 0, 0, 0).
214+
*/
60215
virtual IPAddress remoteIP();
216+
217+
/**
218+
* @brief Retrieves the remote port number of the server the client is connected to.
219+
*
220+
* @return Returns the port number of the remote server. If not connected, returns 0.
221+
*/
61222
virtual uint16_t remotePort();
62223

224+
/**
225+
* @brief Sets the connection timeout for the client.
226+
*
227+
* @param `timeout` is the timeout value in milliseconds.
228+
*/
63229
void setConnectionTimeout(int timeout) {
64230
_connectionTimeout = timeout;
65231
}
66232

233+
/**
234+
* @brief Declares WiFiServer as a friend class.
235+
*
236+
* This allows the WiFiServer class to access private and protected members
237+
* of the WiFiClient class.
238+
*/
67239
friend class WiFiServer;
68240

241+
/**
242+
* @brief Inherits the `write` method from the `Print` class.
243+
*
244+
* This allows the WiFiSSLClient class to use the `write` method defined in the
245+
* `Print` class.
246+
*/
69247
using Print::write;
70248

71249
protected:

‎libraries/WiFiS3/src/WiFiFileSystem.h

+37
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,49 @@
2424
#include "WiFiCommands.h"
2525
#include "Modem.h"
2626

27+
/**
28+
* @brief Class that handles the WiFi file system operations.
29+
*
30+
* This class provides functionality for managing files on a WiFi-connected
31+
* device, including mounting, reading, writing, and configuring the file system.
32+
*/
2733
class WiFiFileSystem {
2834

2935
public:
36+
/**
37+
* @brief Initializes objects of the WiFiFileSystem class.
38+
*/
3039
WiFiFileSystem();
40+
41+
/**
42+
* @brief Mounts the file system and optionally formats it on failure.
43+
*
44+
* @param If `format_on_fault` is set to `true`,
45+
* the file system will be formatted if a fault occurs during mounting.
46+
*/
3147
void mount(bool format_on_fault = false);
48+
49+
/**
50+
* @brief Writes data to a file in the file system.
51+
*
52+
* @param `name` is the name of the file to which the data will be written.
53+
* A pointer `data` to the data that will be written to the file.
54+
* `size` is the number of bytes to write from the provided data buffer.
55+
* `operation` determines the type of file operation to perform (e.g., create, overwrite).
56+
*
57+
* @return Returns the number of bytes successfully written. Returns 0 if the operation fails.
58+
*/
3259
size_t writefile(const char* name, const char* data, size_t size, int operation = WIFI_FILE_WRITE);
60+
61+
/**
62+
* @brief Reads a file from the file system and prints its content.
63+
*
64+
* It sends the read request to the modem, which fetches the data. The content
65+
* is printed to the serial output in chunks, with each chunk being processed
66+
* until the entire file is read.
67+
*
68+
* @param `name` is the name of the file to be read from the file system.
69+
*/
3370
void readfile(const char* name);
3471

3572
};

‎libraries/WiFiS3/src/WiFiSSLClient.h

+178-1
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,215 @@
2525
#include "Modem.h"
2626
#include "WiFiFileSystem.h"
2727

28-
28+
/**
29+
* @brief A specialized client class for secure SSL/TLS connections.
30+
*
31+
* The WiFiSSLClient class extends the functionality of the WiFiClient class to provide secure
32+
* communication over SSL/TLS protocols. It ensures encrypted and authenticated communication
33+
* between the client and a remote server.
34+
*/
2935
class WiFiSSLClient : public WiFiClient {
3036

3137
public:
38+
/**
39+
* @brief Initializes objects of the WiFiSSLClient class.
40+
*/
3241
WiFiSSLClient();
3342
~WiFiSSLClient();
43+
44+
/**
45+
* @brief Establishes a secure SSL connection to a specified IP address and port.
46+
*
47+
* @param It takes an `IPAddress` object representing the IP address of the server
48+
* and a `uint16_t` port number as parameters.
49+
*
50+
* @return Returns a status code indicating the success or failure of the
51+
* connection.
52+
*/
3453
virtual int connect(IPAddress ip, uint16_t port);
54+
55+
/**
56+
* @brief Establishes a secure SSL connection to a specified host and port.
57+
*
58+
* @param `host` is the hostname or IP address of the server to connect to.
59+
* `port` is the port number to connect to.
60+
*
61+
* @return Returns `1` if the connection is successfully established, `0` otherwise.
62+
*/
3563
virtual int connect(const char* host, uint16_t port);
64+
65+
/**
66+
* @brief Sets the Certificate Authority (CA) for SSL/TLS verification.
67+
*
68+
* @param `root_ca` is a pointer to a null-terminated string containing the root
69+
* CA certificate in PEM format. If set to `nullptr`, the default root
70+
* CA bundle will be used.
71+
*/
3672
void setCACert(const char* root_ca);
73+
74+
/**
75+
* @brief Sets the ECC (Elliptic Curve Cryptography) key slot and
76+
* certificate for establishing secure SSL connections.
77+
*
78+
* @param `int ecc508KeySlot` specifies the ECC key slot to be used for the SSL connection.
79+
* @param `const byte cert[]` is a pointer to the certificate data in the form of an array of bytes.
80+
* @param `int certLength` specifies the length of the certificate data array.
81+
*/
3782
void setEccSlot(int ecc508KeySlot, const byte cert[], int certLength);
83+
84+
/**
85+
* @brief Writes a single byte of data to the SSL connection.
86+
*
87+
* @param `b` is the byte to be sent.
88+
*
89+
* @return The number of bytes successfully written. Returns `1` if the byte
90+
* was sent successfully, or `0` if an error occurred.
91+
*/
3892
virtual size_t write(uint8_t);
93+
94+
/**
95+
* @brief Writes a buffer of data to the SSL connection.
96+
*
97+
* @param `buf` is a pointer to the buffer containing the data to be sent.
98+
* @param `size` is the number of bytes to send from the buffer.
99+
*
100+
* @return Returns `size` if the data is successfully sent,
101+
* or `0` if the transmission fails or the socket is invalid.
102+
*/
39103
virtual size_t write(const uint8_t *buf, size_t size);
104+
105+
/**
106+
* @brief Checks the number of bytes available for reading from the SSL connection.
107+
*
108+
* @return Returns the number of bytes available to read from the SSL connection without blocking.
109+
*/
40110
virtual int available();
111+
112+
/**
113+
* @brief Reads data from the SSL connection into the receive buffer.
114+
*
115+
* @return Returns the number of bytes successfully read into the buffer. Returns
116+
* `0` if no data is received, or `-1` if the socket is invalid or an error occurs.
117+
*/
41118
virtual int read();
119+
120+
/**
121+
* @brief Reads a specified number of bytes from the SSL connection into a buffer.
122+
*
123+
* @param `buf` is a pointer to the buffer where the read data will be stored.
124+
* `size` is the maximum number of bytes to read into the buffer.
125+
*
126+
* @return The number of bytes successfully read. Returns `0` if no data is
127+
* available or an error occurs.
128+
*/
42129
virtual int read(uint8_t *buf, size_t size);
130+
131+
/**
132+
* @brief Peeks at the next byte available from the SSL connection without removing it.
133+
*
134+
* This function queries the modem to retrieve the next byte available in the
135+
* SSL/TLS connection, allowing the byte to remain in the buffer for future reads.
136+
*
137+
* @return The next byte available as an integer value (0–255), or `-1` if
138+
* the socket is invalid or no data is available.
139+
*/
43140
virtual int peek();
141+
142+
/**
143+
* @brief Flushes the write buffer of the SSL connection.
144+
*
145+
* This function clears the write buffer, ensuring that any pending data is sent
146+
* over the SSL/TLS connection. It uses the modem to handle the flush operation.
147+
*/
44148
virtual void flush();
149+
150+
/**
151+
* @brief Terminates the SSL/TLS connection and clears the receive buffer.
152+
*/
45153
virtual void stop();
154+
155+
/**
156+
* @brief Checks if the SSL/TLS connection is active.
157+
*
158+
* This function determines if the SSL/TLS client is still connected by querying
159+
* the modem for the connection status. It checks the validity of the socket
160+
* before proceeding with the query.
161+
*
162+
* @return Returns `1` if the client is connected, `0` otherwise.
163+
*/
46164
virtual uint8_t connected();
165+
166+
/**
167+
* @brief Implicit conversion operator to check if the SSL client is connected.
168+
*
169+
* @return `true` if the socket is valid (i.e., connected), `false` otherwise.
170+
*/
47171
virtual operator bool() {
48172
return _sock != -1;
49173
}
174+
175+
/**
176+
* @brief Comparison operator to check equality between two `WiFiSSLClient` objects.
177+
*
178+
* @param `WiFiSSLClient` object to compare.
179+
*
180+
* @return `true` if both WiFiSSLClient objects are equivalent (i.e., they have the same socket),
181+
* `false` otherwise.
182+
*/
50183
virtual bool operator==(const WiFiSSLClient&);
184+
185+
/**
186+
* @brief Inequality operator to compare two `WiFiSSLClient` objects.
187+
*
188+
* This operator compares the current `WiFiSSLClient` object with another `WiFiSSLClient` object
189+
* to determine if they are not equal, based on their underlying socket or connection.
190+
*
191+
* @param `whs` The WiFiSSLClient object to compare with.
192+
* @return `true` if the two WiFiSSLClient objects do not represent the same connection (i.e., have different sockets),
193+
* `false` otherwise.
194+
*/
51195
virtual bool operator!=(const WiFiSSLClient& whs)
52196
{
53197
return !this->operator==(whs);
54198
};
199+
200+
/**
201+
* @brief Retrieves the remote IP address of the WiFi SSL client.
202+
*
203+
* This function queries the modem for the remote IP address associated with
204+
* the current connection.
205+
*
206+
* @return The remote IP address of the client. Returns `0.0.0.0` if the
207+
* socket is not valid or the query fails.
208+
*/
55209
virtual IPAddress remoteIP();
210+
211+
/**
212+
* @brief Retrieves the remote port number of the WiFi SSL client.
213+
*
214+
* This function queries the modem to obtain the remote port number associated
215+
* with the current connection.
216+
*
217+
* @return Returns the remote port number of the client. Returns `0` if the socket
218+
* is not valid or the query fails.
219+
*/
56220
virtual uint16_t remotePort();
57221

222+
223+
/**
224+
* @brief Declares WiFiServer as a friend class.
225+
*
226+
* This allows the WiFiServer class to access private and protected members
227+
* of the WiFiSSLClient class.
228+
*/
58229
friend class WiFiServer;
59230

231+
/**
232+
* @brief Inherits the `write` method from the Print class.
233+
*
234+
* This allows the WiFiSSLClient class to use the `write` method defined in the
235+
* Print class.
236+
*/
60237
using Print::write;
61238

62239
private:

‎libraries/WiFiS3/src/WiFiServer.h

+117-1
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,148 @@
2626
#include "WiFiClient.h"
2727

2828

29-
29+
/**
30+
* @brief A class that provides server functionality for WiFi-based communication.
31+
*
32+
* The WiFiServer class inherits from the Server class and extends its functionality
33+
* to create and manage a server over a WiFi connection. This class allows for accepting
34+
* incoming client connections, handling data communication, and closing connections
35+
* in a networked environment.
36+
*/
3037
class WiFiServer : public Server {
3138
private:
3239
int _sock;
3340
int _port;
3441
WiFiClient client;
3542

3643
public:
44+
/**
45+
* @brief Initializes objects of the WiFiServer class.
46+
*/
3747
WiFiServer();
48+
49+
/**
50+
* @brief Constructs a WiFiServer object with the specified port.
51+
*
52+
* @param `p` The port number on which the server will listen for incoming connections.
53+
*/
3854
WiFiServer(int p);
55+
56+
/**
57+
* @brief Checks if there are any incoming client connections waiting to be accepted.
58+
*
59+
* This function queries the server to check if there is a client waiting to be
60+
* accepted. If a client is available, it returns a `WiFiClient` object representing
61+
* the client. It uses the modem to query the server for an available client
62+
* socket and accepts the connection if a valid client is found.
63+
*
64+
* @return Returns a WiFiClient object representing the next client connection that is available
65+
* for processing.
66+
*/
3967
WiFiClient available();
68+
69+
/**
70+
* @brief Accepts an incoming client connection on the server.
71+
*
72+
* @return Returns a WiFiClient object representing the accepted client.
73+
*/
4074
WiFiClient accept();
75+
76+
/**
77+
* @brief Starts the Wi-Fi server and binds it to the specified port.
78+
*
79+
* @param `port` is the port number which the server will listen to for incoming connections.
80+
*/
4181
void begin(int port);
82+
83+
/**
84+
* @brief Starts the Wi-Fi server and binds it to the default port.
85+
*
86+
* This function initializes the server and binds it to a default port.
87+
*/
4288
void begin();
89+
90+
/**
91+
* @brief Writes a single byte to all connected clients.
92+
*
93+
* @param `b` is the byte to be sent to the clients.
94+
*/
4395
virtual size_t write(uint8_t);
96+
97+
/**
98+
* @brief Writes data to all connected clients.
99+
*
100+
* This function sends a buffer of data to all clients connected to the server.
101+
* It writes the specified number of bytes to the server
102+
* socket and returns the count of successfully written bytes.
103+
*
104+
* @param `buf` is a pointer to the buffer containing the data to be sent.
105+
* `size` is the number of bytes to write from the buffer.
106+
*
107+
* @return The number of bytes successfully written. Returns 0 if the
108+
* data could not be sent.
109+
*/
44110
virtual size_t write(const uint8_t *buf, size_t size);
111+
112+
/**
113+
* @brief Ends the Wi-Fi server and closes the server socket.
114+
*
115+
* This function terminates the server by sending a command to the modem to
116+
* close the server socket. It sets the server socket variable to an invalid
117+
* state (`-1`) to indicate that the server is no longer active.
118+
*
119+
*/
45120
void end();
121+
122+
/**
123+
* @brief Converts the WiFiSSLClient object to a boolean value.
124+
*
125+
* This operator allows a WiFiSSLClient object to be implicitly or explicitly
126+
* converted to a boolean. It checks whether the client socket is valid (i.e.,
127+
* `_sock != -1`).
128+
*
129+
* @return `true` if the server socket is valid (server is running), `false` otherwise.
130+
*/
46131
explicit operator bool();
132+
133+
/**
134+
* @brief Compares two WiFiServer objects for equality.
135+
*
136+
* This virtual operator compares the underlying socket (`_sock`) of two `WiFiServer`
137+
* objects to determine if they refer to the same server connection.
138+
*
139+
* @param WiFiServer object to compare against.
140+
*
141+
* @return `true` if both WiFiServer objects have the same socket; `false` otherwise.
142+
*/
47143
virtual bool operator==(const WiFiServer&);
144+
145+
/**
146+
* @brief Compares two WiFiServer objects for inequality.
147+
*
148+
* This virtual operator compares the underlying socket (`_sock`) of two WiFiServer
149+
* objects. It returns `true` if the objects do not refer to the same server connection
150+
* (i.e., they have different socket values), and `false` otherwise.
151+
*
152+
* @param `whs` The WiFiServer object to compare against.
153+
* @return `true` if the WiFiServer objects have different sockets; `false` otherwise.
154+
*/
48155
virtual bool operator!=(const WiFiServer& whs)
49156
{
50157
return !this->operator==(whs);
51158
};
52159

160+
/**
161+
* @brief Inherits the `write` method from the `Print` class.
162+
*
163+
* This allows the WiFiSSLClient class to use the `write` method defined in the
164+
* `Print` class.
165+
*/
53166
using Print::write;
54167

168+
/**
169+
* @brief Grants WiFiClient class access to private and protected members of WiFiServer.
170+
*/
55171
friend class WiFiClient;
56172
};
57173

‎libraries/WiFiS3/src/WiFiUdp.h

+187-25
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
#include "Modem.h"
3131
#include "FifoBuffer.h"
3232

33+
/**
34+
* @brief A class for handling UDP communication over a Wi-Fi network.
35+
*
36+
* The WiFiUDP class is an extension of the UDP class that enables sending and receiving UDP packets
37+
* over a Wi-Fi network. It provides functions for initialization, packet transmission, and reception
38+
* tailored for Wi-Fi connectivity.
39+
*/
3340
class WiFiUDP : public UDP {
3441
private:
3542
int _sock;
@@ -41,57 +48,212 @@ class WiFiUDP : public UDP {
4148
virtual void read_if_needed(size_t s);
4249

4350
public:
44-
WiFiUDP(); // Constructor
45-
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+
*/
4675
virtual uint8_t begin(IPAddress a, uint16_t p);
47-
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
48-
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();
4992

50-
// 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+
*/
5199
virtual int beginMulticastPacket();
52-
// Start building up a packet to send to the remote host specific in ip and port
53-
// 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+
*/
54110
virtual int beginPacket(IPAddress ip, uint16_t port);
55-
// Start building up a packet to send to the remote host specific in host and port
56-
// 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+
*/
57121
virtual int beginPacket(const char *host, uint16_t port);
58-
// Finish off this packet and send it
59-
// 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+
*/
60129
virtual int endPacket();
61-
// 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+
*/
62139
virtual size_t write(uint8_t);
63-
// 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+
*/
64150
virtual size_t write(const uint8_t *buffer, size_t size);
65151

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+
*/
66158
using Print::write;
67159

68-
// Start processing the next available incoming packet
69-
// 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+
*/
70165
virtual int parsePacket();
71-
// 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+
*/
72172
virtual int available();
73-
// 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+
*/
74179
virtual int read();
75-
// Read up to len bytes from the current packet and place them into buffer
76-
// 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+
*/
77190
virtual int read(unsigned char* buffer, size_t len);
78-
// Read up to len characters from the current packet and place them into buffer
79-
// 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+
*/
80202
virtual int read(char* buffer, size_t len) { return read((unsigned char*)buffer, len); };
81-
// 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+
*/
82209
virtual int peek();
210+
211+
/**
212+
* @brief Finish reading the current packet
213+
*/
83214
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+
*/
84226
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+
*/
85237
virtual bool operator!=(const WiFiUDP& whs)
86238
{
87239
return !this->operator==(whs);
88240
};
89241

90-
// 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+
*/
91248
virtual IPAddress remoteIP();
92-
// 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+
*/
93256
virtual uint16_t remotePort();
94-
95257

96258
};
97259

‎platform.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-specification
44

55
name=Arduino Renesas fsp Boards
6-
version=1.4.0
6+
version=1.4.1
77

88
# Compile variables
99
# ------------------------

0 commit comments

Comments
 (0)
Please sign in to comment.