Skip to content

Commit ac12c30

Browse files
committed
add doxygen documentation
1 parent 3b50386 commit ac12c30

11 files changed

+416
-18
lines changed

src/Arduino_NetworkConfigurator.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,20 @@ bool NetworkConfiguratorClass::begin() {
4848
if(_state != NetworkConfiguratorStates::END) {
4949
return true;
5050
}
51+
/*
52+
* If the board is zero touch capable, starts with zero touch configuration mode
53+
* In this state the board will try to connect to the network using a set of
54+
* default network settings ex. Ethernet with DHCP
55+
* This mode will fail if the provided ConnectionHandler is not GenericConnectionHandler type
56+
* falling back to read the network settings from the storage
57+
*/
58+
5159
#if ZERO_TOUCH_ENABLED
5260
_state = NetworkConfiguratorStates::ZERO_TOUCH_CONFIG;
5361
#else
5462
_state = NetworkConfiguratorStates::READ_STORED_CONFIG;
5563
#endif
64+
5665
memset(&_networkSetting, 0x00, sizeof(models::NetworkSetting));
5766
_ledFeedback->begin();
5867
#ifdef BOARD_HAS_WIFI
@@ -62,7 +71,7 @@ bool NetworkConfiguratorClass::begin() {
6271
}
6372
_agentsManager->addRequestHandler(RequestType::SCAN, scanReqHandler);
6473
#endif
65-
74+
// Register callbacks to agentsManager
6675
_agentsManager->addRequestHandler(RequestType::CONNECT, connectReqHandler);
6776

6877
_agentsManager->addReturnNetworkSettingsCallback(setNetworkSettingsHandler);
@@ -164,6 +173,7 @@ bool NetworkConfiguratorClass::end() {
164173
}
165174

166175
bool NetworkConfiguratorClass::scanNetworkOptions() {
176+
// If board has Wifi scan for networks
167177
#ifdef BOARD_HAS_WIFI
168178
sendStatus(StatusMessage::SCANNING); //Notify before scan
169179

@@ -175,7 +185,7 @@ bool NetworkConfiguratorClass::scanNetworkOptions() {
175185
}
176186

177187
NetworkOptions netOption = { NetworkOptionsClass::WIFI, wifiOptObj };
178-
#else
188+
#else // Send an empty network options message
179189
NetworkOptions netOption = { NetworkOptionsClass::NONE };
180190
#endif
181191
ProvisioningOutputMessage netOptionMsg = { MessageOutputType::NETWORK_OPTIONS };

src/Arduino_NetworkConfigurator.h

+20-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@
1919
#include "Utility/ResetInput/ResetInput.h"
2020
#include "Utility/LEDFeedback/LEDFeedback.h"
2121

22+
/**
23+
* @enum NetworkConfiguratorStates
24+
* @brief Represents the various states of the NetworkConfiguratorClass.
25+
*
26+
* - ZERO_TOUCH_CONFIG: Automatically configures the network settings without user intervention.
27+
* - READ_STORED_CONFIG: Reads the stored network configuration from persistent storage and loads to the ConnectionHandler.
28+
* - WAITING_FOR_CONFIG: Waits for the user to provide network configuration settings.
29+
* - CONNECTING: Attempts to connect to the network using the provided configuration.
30+
* - CONFIGURED: Indicates that the ConnectionHanlder has been successfully configured.
31+
* - UPDATING_CONFIG: Updates the network configuration.
32+
* - ERROR: Represents an error state during the configuration process.
33+
* - END: Marks the end of the network configuration process.
34+
*/
2235
enum class NetworkConfiguratorStates { ZERO_TOUCH_CONFIG,
2336
READ_STORED_CONFIG,
2437
WAITING_FOR_CONFIG,
@@ -146,10 +159,14 @@ class NetworkConfiguratorClass {
146159
bool _connectionHandlerIstantiated;
147160
ResetInput *_resetInput;
148161
LEDFeedbackClass *_ledFeedback;
162+
/* Timeout instances */
163+
// Timeout for connection attempt
149164
TimedAttempt _connectionTimeout;
165+
// Timeout for retrying to connect using the provided credentials
150166
TimedAttempt _connectionRetryTimer;
167+
// Timeout for updating the network options ex. periodically scanning for new WiFi networks
151168
TimedAttempt _optionUpdateTimer;
152-
169+
/* List of events the NetworkConfigurator can handle from the AgentsManager */
153170
enum class NetworkConfiguratorEvents { NONE,
154171
SCAN_REQ,
155172
CONNECT_REQ,
@@ -164,6 +181,7 @@ class NetworkConfiguratorClass {
164181
KVStore *_kvstore;
165182
AgentsManagerClass *_agentsManager;
166183

184+
/* FSM handler functions */
167185
#if ZERO_TOUCH_ENABLED
168186
NetworkConfiguratorStates handleZeroTouchConfig();
169187
#endif
@@ -190,6 +208,7 @@ class NetworkConfiguratorClass {
190208
bool scanWiFiNetworks(WiFiOption &wifiOptObj);
191209
bool insertWiFiAP(WiFiOption &wifiOptObj, char *ssid, int rssi);
192210
#endif
211+
/* Callback for agentsManager */
193212
static void scanReqHandler();
194213
static void connectReqHandler();
195214
static void setNetworkSettingsHandler(models::NetworkSetting *netSetting);

src/ConfiguratorAgents/AgentsManager.h

+152-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,32 @@
1212
#include "agents/ConfiguratorAgent.h"
1313
#include "MessagesDefinitions.h"
1414

15+
/**
16+
* @enum AgentsManagerStates
17+
* @brief Represents the various states of the AgentsManager.
18+
*
19+
* States:
20+
* - INIT:
21+
* The initial state where the AgentsManager is polling all the handled
22+
* agents waiting for a connected user client.
23+
*
24+
* - SEND_INITIAL_STATUS:
25+
* In this state, the AgentsManager sends an initial status message
26+
* to inform about errors or current state.
27+
*
28+
* - SEND_NETWORK_OPTIONS:
29+
* This state is responsible for sending network configuration options
30+
* to the connected agent. These options may include the list of available WiFi Networks
31+
*
32+
* - CONFIG_IN_PROGRESS:
33+
* Indicates that a configuration process is currently in progress.
34+
* The AgentsManager is actively handling commands or data related to
35+
* network configuration orprovisioning.
36+
*
37+
* - END:
38+
* The final state where the AgentsManager concludes its operations.
39+
* This may involve cleaning up resources and stopping agents
40+
*/
1541
enum class AgentsManagerStates { INIT,
1642
SEND_INITIAL_STATUS,
1743
SEND_NETWORK_OPTIONS,
@@ -30,27 +56,152 @@ enum class RequestType: int { NONE = -1,
3056
GET_WIFI_FW_VERSION = 4,
3157
GET_BLE_MAC_ADDRESS = 5 };
3258

59+
/**
60+
* @class AgentsManagerClass
61+
* @brief Manages the lifecycle, communication, and state of multiple configurator agents.
62+
*
63+
* The AgentsManagerClass is a singleton class responsible for coordinating multiple
64+
* configurator agents. It provides methods to initialize, terminate, enable, disable,
65+
* and interact with agents. The agents handle a communication interface for configuring
66+
* network credentials and handle the claiming cloud process. The interfaces could be: BLE,
67+
* Serial and other.
68+
* The class also handles communication with agents, manages
69+
* their states, and provides callback mechanisms for handling requests and returning
70+
* data such as timestamps and network settings.
71+
*
72+
* Key functionalities include:
73+
* - Managing the state of the agents.
74+
* - Sending and receiving messages to/from agents.
75+
* - Adding and removing agents dynamically.
76+
* - Handling requests and callbacks for specific operations.
77+
* - Monitoring the progress of the execution of received commands.
78+
*
79+
*/
3380
class AgentsManagerClass {
3481
public:
82+
/**
83+
* @brief Get the singleton instance of the AgentsManagerClass.
84+
* @return Reference to the singleton instance.
85+
*/
3586
static AgentsManagerClass &getInstance();
87+
88+
/**
89+
* @brief Initialize the AgentsManager, and starts the agents.
90+
* @return True if initialization is successful, false otherwise.
91+
*/
3692
bool begin();
93+
94+
/**
95+
* @brief Terminate the AgentsManager.
96+
* @return True if termination is successful, false otherwise.
97+
*/
3798
bool end();
99+
100+
/**
101+
* @brief Disconnect the currently connected agent.
102+
*/
38103
void disconnect();
104+
105+
/**
106+
* @brief Update the state of the AgentsManager.
107+
* @return The current state of the AgentsManager.
108+
*/
39109
AgentsManagerStates update();
110+
111+
/**
112+
* @brief Enable or disable a specific agent.
113+
* The agent will be automatically started or stopped
114+
* based on the enable parameter.
115+
* @param type The type of agent to enable or disable.
116+
* @param enable True to enable, false to disable.
117+
*/
40118
void enableAgent(ConfiguratorAgent::AgentTypes type, bool enable);
119+
120+
/**
121+
* @brief Check if a specific agent is enabled.
122+
* @param type The type of agent to check.
123+
* @return True if the agent is enabled, false otherwise.
124+
*/
41125
bool isAgentEnabled(ConfiguratorAgent::AgentTypes type);
42-
// Force starting agent even if disabled
126+
127+
/**
128+
* @brief Force start an agent even if it is disabled.
129+
* @param type The type of agent to start.
130+
* @return True if the agent is found in the list, false otherwise.
131+
*/
43132
bool startAgent(ConfiguratorAgent::AgentTypes type);
133+
134+
/**
135+
* @brief Stop a specific agent.
136+
* @param type The type of agent to stop.
137+
* @return True if the agent is found in the list, false otherwise.
138+
*/
44139
bool stopAgent(ConfiguratorAgent::AgentTypes type);
140+
141+
/**
142+
* @brief Get the currently connected agent.
143+
* @return Pointer to the connected agent, or nullptr if no agent is connected.
144+
*/
45145
ConfiguratorAgent *getConnectedAgent();
146+
147+
/**
148+
* @brief Send a message to the connected agent or queue a message
149+
* if no agent is connected.
150+
* @param msg The message to send.
151+
* @return True if the message is successfully sent, false otherwise.
152+
*/
46153
bool sendMsg(ProvisioningOutputMessage &msg);
154+
155+
/**
156+
* @brief Add an agent to be managed to the list.
157+
* @param agent The agent to add.
158+
* @return True if the agent is successfully added, false otherwise.
159+
*/
47160
bool addAgent(ConfiguratorAgent &agent);
161+
162+
/**
163+
* @brief Add an handler callback for a specific request type.
164+
* The callback is fired when the properly request is received
165+
* @param type The type of request to handle.
166+
* @param callback The callback function to handle the request.
167+
* @return True if the handler is successfully added, false otherwise.
168+
*/
48169
bool addRequestHandler(RequestType type, ConfiguratorRequestHandler callback);
170+
171+
/**
172+
* @brief Remove the handler callback for a specific request type.
173+
* @param type The type of request to remove the handler for.
174+
*/
49175
void removeRequestHandler(RequestType type);
176+
177+
/**
178+
* @brief Add a callback to be fired when the timestamp is received from the agent.
179+
* @param callback The callback function to return the timestamp.
180+
* @return True if the callback is successfully added, false otherwise.
181+
*/
50182
bool addReturnTimestampCallback(ReturnTimestamp callback);
183+
184+
/**
185+
* @brief Remove the callback for returning a timestamp.
186+
*/
51187
void removeReturnTimestampCallback();
188+
189+
/**
190+
* @brief Add a callback to return network settings received from the agent.
191+
* @param callback The callback function to return the network settings.
192+
* @return True if the callback is successfully added, false otherwise.
193+
*/
52194
bool addReturnNetworkSettingsCallback(ReturnNetworkSettings callback);
195+
196+
/**
197+
* @brief Remove the callback for returning network settings.
198+
*/
53199
void removeReturnNetworkSettingsCallback();
200+
201+
/**
202+
* @brief Check if a configuration process is in progress.
203+
* @return True if a configuration process is in progress, false otherwise.
204+
*/
54205
bool isConfigInProgress();
55206

56207
private:

src/ConfiguratorAgents/MessagesDefinitions.h

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define MAX_UHWID_SIZE 32
1515
#define MAX_JWT_SIZE 269
1616

17+
/* Status codes */
1718
enum class StatusMessage {
1819
NONE = 0,
1920
CONNECTING = 1,
@@ -40,6 +41,7 @@ enum class StatusMessage {
4041
ERROR = -255
4142
};
4243

44+
/* Commands codes */
4345
enum class RemoteCommands { CONNECT = 1,
4446
GET_ID = 2,
4547
GET_BLE_MAC_ADDRESS = 3,
@@ -48,6 +50,7 @@ enum class RemoteCommands { CONNECT = 1,
4850
GET_WIFI_FW_VERSION = 101
4951
};
5052

53+
/* Types of outgoing messages */
5154
enum class MessageOutputType { STATUS,
5255
NETWORK_OPTIONS,
5356
UHWID,
@@ -56,12 +59,18 @@ enum class MessageOutputType { STATUS,
5659
WIFI_FW_VERSION
5760
};
5861

62+
/* Types of ingoing messages */
5963
enum class MessageInputType {
6064
COMMANDS,
6165
NETWORK_SETTINGS,
6266
TIMESTAMP
6367
};
6468

69+
/* Message structure for outgoing messages
70+
* The payload is a union of different types
71+
* pointers, no copy of object is required no
72+
* memory is allocated
73+
*/
6574
struct ProvisioningOutputMessage {
6675
MessageOutputType type;
6776
union {
@@ -74,6 +83,9 @@ struct ProvisioningOutputMessage {
7483
} m;
7584
};
7685

86+
/*
87+
* Message structure for ingoing messages
88+
*/
7789
struct ProvisioningInputMessage {
7890
MessageInputType type;
7991
union {

src/ConfiguratorAgents/NetworkOptionsDefinitions.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#include "Arduino.h"
1111
#define MAX_WIFI_NETWORKS 20
1212

13+
/*
14+
* Structures for storing the available network options
15+
*/
16+
1317
enum class NetworkOptionsClass { NONE,
1418
WIFI };
1519

@@ -25,7 +29,6 @@ struct WiFiOption {
2529
int numDiscoveredWiFiNetworks = 0;
2630
};
2731

28-
2932
struct NetworkOptions {
3033
NetworkOptionsClass type;
3134
union {

src/ConfiguratorAgents/agents/BLE/BLEAgent.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@
4444
#else
4545
#error "Board not supported for BLE configuration"
4646
#endif
47-
47+
/**
48+
* @class BLEAgentClass
49+
* @brief This class is responsible for managing BLE communication with a peer device/client for board configuration purposes.
50+
* It extends the ConfiguratorAgent class and implements the BoardConfigurationProtocol interface to handle
51+
* communication, message exchange, and connection management over a Bluetooth Low Energy interface.
52+
*/
4853
class BLEAgentClass : public ConfiguratorAgent, private BoardConfigurationProtocol {
4954
public:
5055
BLEAgentClass();

0 commit comments

Comments
 (0)