Skip to content

Commit cd0c0f2

Browse files
committed
Added comments
1 parent 43e38bc commit cd0c0f2

File tree

4 files changed

+205
-37
lines changed

4 files changed

+205
-37
lines changed

WiFi/WiFi.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@
44
extern "C" {
55
#include "utility/wl_definitions.h"
66
#include "utility/wl_types.h"
7-
#include "debug.h"
7+
#include "debug.h"
88
}
99

1010
// XXX: don't make assumptions about the value of MAX_SOCK_NUM.
1111
int16_t WiFiClass::_state[MAX_SOCK_NUM] = { 0, 0, 0, 0 };
1212
uint16_t WiFiClass::_server_port[MAX_SOCK_NUM] = { 0, 0, 0, 0 };
1313

14-
char WiFiClass::_ssid[] = { 0 };
15-
char WiFiClass::_key[] = { 0 };
16-
char WiFiClass::_passph[] = { 0 };
17-
wl_status_t WiFiClass::_status;
18-
19-
2014
WiFiClass::WiFiClass()
2115
{
2216
// Driver initialization

WiFi/WiFi.h

Lines changed: 80 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ extern "C" {
1515
class WiFiClass
1616
{
1717
private:
18-
// this data are stored in EEPROM and loaded at begin
19-
// The next connect overwrite these values
20-
static char _ssid[WL_SSID_MAX_LENGTH];
21-
static char _key[WL_WEP_KEY_MAX_LENGTH];
22-
static char _passph[WL_WPA_KEY_MAX_LENGTH];
23-
static wl_status_t _status;
2418

2519
static void init();
2620
public:
@@ -29,7 +23,9 @@ class WiFiClass
2923

3024
WiFiClass();
3125

32-
// Get the first socket available
26+
/*
27+
* Get the first socket available
28+
*/
3329
static uint8_t getSocket();
3430

3531
/* Start Wifi connection for OPEN networks
@@ -51,51 +47,113 @@ class WiFiClass
5147
/* Start Wifi connection with passphrase
5248
* the most secure supported mode will be automatically selected
5349
*
50+
* param ssid: Pointer to the SSID string.
5451
* param passphrase: Passphrase. Valid characters in a passphrase
5552
* must be between ASCII 32-126 (decimal).
5653
*/
5754
int begin(char* ssid, const char *passphrase);
5855

59-
// Disconnect from the network
56+
/*
57+
* Disconnect from the network
58+
*
59+
* return: one value of wl_status_t enum
60+
*/
6061
int disconnect(void);
6162

62-
//Get the interface MAC address.
63+
/*
64+
* Get the interface MAC address.
65+
*
66+
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
67+
*/
6368
uint8_t* macAddress(uint8_t* mac);
6469

65-
//Get the DHCP information related to IP
70+
/*
71+
* Get the interface IP address.
72+
*
73+
* return: Ip address value
74+
*/
6675
IPAddress localIP();
6776

68-
//Get the DHCP information related to subnetMask
77+
/*
78+
* Get the interface subnet mask address.
79+
*
80+
* return: subnet mask address value
81+
*/
6982
IPAddress subnetMask();
7083

71-
//Get the DHCP information related to gateway IP
72-
IPAddress gatewayIP();
84+
/*
85+
* Get the gateway ip address.
86+
*
87+
* return: gateway ip address value
88+
*/
89+
IPAddress gatewayIP();
7390

74-
// Return the current SSID associated with the network
91+
/*
92+
* Return the current SSID associated with the network
93+
*
94+
* return: ssid string
95+
*/
7596
char* SSID();
7697

77-
// Return the current BSSID associated with the network
98+
/*
99+
* Return the current BSSID associated with the network.
100+
* It is the MAC address of the Access Point
101+
*
102+
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
103+
*/
78104
uint8_t* BSSID(uint8_t* bssid);
79105

80-
// Return the current RSSI /Received Signal Strength in dBm) associated with the network
106+
/*
107+
* Return the current RSSI /Received Signal Strength in dBm)
108+
* associated with the network
109+
*
110+
* return: signed value
111+
*/
81112
int32_t RSSI();
82113

83-
// Return the Encryption Type associated with the network
114+
/*
115+
* Return the Encryption Type associated with the network
116+
*
117+
* return: one value of wl_enc_type enum
118+
*/
84119
uint8_t encryptionType();
85120

86-
// Start scan WiFi networks available and return the discovered number
121+
/*
122+
* Start scan WiFi networks available
123+
*
124+
* return: Number of discovered networks
125+
*/
87126
uint8_t scanNetworks();
88127

89-
// Return SSID item associated with the network identified with networkItem
128+
/*
129+
* Return the SSID discovered during the network scan.
130+
*
131+
* param networkItem: specify from which network item want to get the information
132+
*
133+
* return: ssid string of the specified item on the networks scanned list
134+
*/
90135
char* SSID(uint8_t networkItem);
91136

92-
// Return the Encryption Type associated with the network identified with networkItem
137+
/*
138+
* Return the encryption type of the networks discovered during the scanNetworks
139+
*
140+
* param networkItem: specify from which network item want to get the information
141+
*
142+
* return: encryption type (enum wl_enc_type) of the specified item on the networks scanned list
143+
*/
93144
uint8_t encryptionType(uint8_t networkItem);
94145

95-
// Return the current RSSI /Received Signal Strength in dBm) associated with the network identified with networkItem
146+
/*
147+
* Return the RSSI of the networks discovered during the scanNetworks
148+
*
149+
* param networkItem: specify from which network item want to get the information
150+
*
151+
* return: signed value of RSSI of the specified item on the networks scanned list
152+
*/
96153
int32_t RSSI(uint8_t networkItem);
97154

98-
/* Return Connection status.
155+
/*
156+
* Return Connection status.
99157
*
100158
* return: one of the value defined in wl_status_t
101159
*/

WiFi/utility/wifi_drv.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ extern "C" {
1414
#include "debug.h"
1515
}
1616

17+
// Array of data to cache the information related to the networks discovered
1718
char WiFiDrv::_networkSsid[][WL_SSID_MAX_LENGTH] = {{"1"},{"2"},{"3"},{"4"},{"5"}};
1819
int32_t WiFiDrv::_networkRssi[WL_NETWORKS_LIST_MAXNUM] = { 0 };
1920
uint8_t WiFiDrv::_networkEncr[WL_NETWORKS_LIST_MAXNUM] = { 0 };
2021

22+
// Cached values of retrieved data
2123
char WiFiDrv::_ssid[] = {0};
2224
uint8_t WiFiDrv::_bssid[] = {0};
2325
uint8_t WiFiDrv::_mac[] = {0};
@@ -57,7 +59,6 @@ void WiFiDrv::wifiDriverInit()
5759
SpiDrv::begin();
5860
}
5961

60-
// If ssid == NULL execute a wifi scan, otherwise try to connect to the network specified
6162
uint8_t WiFiDrv::wifiSetNetwork(char* ssid, uint8_t ssid_len)
6263
{
6364
WAIT_FOR_SLAVE_SELECT();
@@ -194,13 +195,12 @@ void WiFiDrv::getIpAddress(IPAddress& ip)
194195
{
195196
getNetworkData(_localIp, _subnetMask, _gatewayIp);
196197
ip = _localIp;
197-
//memcpy(ip, _localIp, WL_IPV4_LENGTH);
198198
}
199199

200-
void WiFiDrv::getSubnetMask(IPAddress& ip)
200+
void WiFiDrv::getSubnetMask(IPAddress& mask)
201201
{
202202
getNetworkData(_localIp, _subnetMask, _gatewayIp);
203-
ip = _subnetMask;
203+
mask = _subnetMask;
204204
}
205205

206206
void WiFiDrv::getGatewayIP(IPAddress& ip)

WiFi/utility/wifi_drv.h

Lines changed: 120 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
#include "wifi_spi.h"
66
#include "IPAddress.h"
77

8+
// Key index length
89
#define KEY_IDX_LEN 1
10+
// 5 secs of delay to have the connection established
911
#define WL_DELAY_START_CONNECTION 5000
10-
#define WL_DELAY_RETRY_START_CONNECTION 1000
1112

1213
class WiFiDrv
1314
{
@@ -25,44 +26,159 @@ class WiFiDrv
2526
static uint8_t _subnetMask[WL_IPV4_LENGTH];
2627
static uint8_t _gatewayIp[WL_IPV4_LENGTH];
2728

29+
/*
30+
* Get network Data information
31+
*/
2832
static void getNetworkData(uint8_t *ip, uint8_t *mask, uint8_t *gwip);
2933

3034
public:
3135

36+
/*
37+
* Driver initialization
38+
*/
3239
static void wifiDriverInit();
3340

41+
/*
42+
* Set the desired network which the connection manager should try to
43+
* connect to.
44+
*
45+
* The ssid of the desired network should be specified.
46+
*
47+
* param ssid: The ssid of the desired network.
48+
* param ssid_len: Lenght of ssid string.
49+
* return: WL_SUCCESS or WL_FAILURE
50+
*/
3451
static uint8_t wifiSetNetwork(char* ssid, uint8_t ssid_len);
3552

53+
/* Start Wifi connection with passphrase
54+
* the most secure supported mode will be automatically selected
55+
*
56+
* param ssid: Pointer to the SSID string.
57+
* param ssid_len: Lenght of ssid string.
58+
* param passphrase: Passphrase. Valid characters in a passphrase
59+
* must be between ASCII 32-126 (decimal).
60+
* param len: Lenght of passphrase string.
61+
* return: WL_SUCCESS or WL_FAILURE
62+
*/
3663
static uint8_t wifiSetPassphrase(char* ssid, uint8_t ssid_len, const char *passphrase, const uint8_t len);
3764

65+
/* Start Wifi connection with WEP encryption.
66+
* Configure a key into the device. The key type (WEP-40, WEP-104)
67+
* is determined by the size of the key (5 bytes for WEP-40, 13 bytes for WEP-104).
68+
*
69+
* param ssid: Pointer to the SSID string.
70+
* param ssid_len: Lenght of ssid string.
71+
* param key_idx: The key index to set. Valid values are 0-3.
72+
* param key: Key input buffer.
73+
* param len: Lenght of key string.
74+
* return: WL_SUCCESS or WL_FAILURE
75+
*/
3876
static uint8_t wifiSetKey(char* ssid, uint8_t ssid_len, uint8_t key_idx, const void *key, const uint8_t len);
3977

78+
/*
79+
* Disconnect from the network
80+
*
81+
* return: WL_SUCCESS or WL_FAILURE
82+
*/
4083
static uint8_t disconnect();
41-
84+
85+
/*
86+
* Disconnect from the network
87+
*
88+
* return: one value of wl_status_t enum
89+
*/
4290
static uint8_t getConnectionStatus();
4391

92+
/*
93+
* Get the interface MAC address.
94+
*
95+
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
96+
*/
4497
static uint8_t* getMacAddress();
4598

99+
/*
100+
* Get the interface IP address.
101+
*
102+
* return: copy the ip address value in IPAddress object
103+
*/
46104
static void getIpAddress(IPAddress& ip);
47105

48-
static void getSubnetMask(IPAddress& ip);
49-
106+
/*
107+
* Get the interface subnet mask address.
108+
*
109+
* return: copy the subnet mask address value in IPAddress object
110+
*/
111+
static void getSubnetMask(IPAddress& mask);
112+
113+
/*
114+
* Get the gateway ip address.
115+
*
116+
* return: copy the gateway ip address value in IPAddress object
117+
*/
50118
static void getGatewayIP(IPAddress& ip);
51119

120+
/*
121+
* Return the current SSID associated with the network
122+
*
123+
* return: ssid string
124+
*/
52125
static char* getCurrentSSID();
53126

127+
/*
128+
* Return the current BSSID associated with the network.
129+
* It is the MAC address of the Access Point
130+
*
131+
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
132+
*/
54133
static uint8_t* getCurrentBSSID();
55134

135+
/*
136+
* Return the current RSSI /Received Signal Strength in dBm)
137+
* associated with the network
138+
*
139+
* return: signed value
140+
*/
56141
static int32_t getCurrentRSSI();
57142

143+
/*
144+
* Return the Encryption Type associated with the network
145+
*
146+
* return: one value of wl_enc_type enum
147+
*/
58148
static uint8_t getCurrentEncryptionType();
59149

150+
/*
151+
* Start scan WiFi networks available
152+
*
153+
* return: Number of discovered networks
154+
*/
60155
static uint8_t scanNetworks();
61156

157+
/*
158+
* Return the SSID discovered during the network scan.
159+
*
160+
* param networkItem: specify from which network item want to get the information
161+
*
162+
* return: ssid string of the specified item on the networks scanned list
163+
*/
62164
static char* getSSIDNetoworks(uint8_t networkItem);
63165

166+
/*
167+
* Return the RSSI of the networks discovered during the scanNetworks
168+
*
169+
* param networkItem: specify from which network item want to get the information
170+
*
171+
* return: signed value of RSSI of the specified item on the networks scanned list
172+
*/
64173
static int32_t getRSSINetoworks(uint8_t networkItem);
65174

175+
/*
176+
* Return the encryption type of the networks discovered during the scanNetworks
177+
*
178+
* param networkItem: specify from which network item want to get the information
179+
*
180+
* return: encryption type (enum wl_enc_type) of the specified item on the networks scanned list
181+
*/
66182
static uint8_t getEncTypeNetowrks(uint8_t networkItem);
67183

68184
};

0 commit comments

Comments
 (0)