Skip to content

Commit 9c63ffb

Browse files
committed
Revert "Binary without staxk traces"
This reverts commit 3e469d7a612405642e616d6af165f4573b416e3f.
1 parent 771ef14 commit 9c63ffb

28 files changed

+3886
-0
lines changed

WiFi/WiFi.cpp

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
#include "wifi_drv.h"
2+
#include "WiFi.h"
3+
4+
extern "C" {
5+
#include "utility/wl_definitions.h"
6+
#include "utility/wl_types.h"
7+
#include "debug.h"
8+
}
9+
10+
// XXX: don't make assumptions about the value of MAX_SOCK_NUM.
11+
int16_t WiFiClass::_state[MAX_SOCK_NUM] = { 0, 0, 0, 0 };
12+
uint16_t WiFiClass::_server_port[MAX_SOCK_NUM] = { 0, 0, 0, 0 };
13+
14+
WiFiClass::WiFiClass()
15+
{
16+
// Driver initialization
17+
init();
18+
}
19+
20+
void WiFiClass::init()
21+
{
22+
WiFiDrv::wifiDriverInit();
23+
}
24+
25+
uint8_t WiFiClass::getSocket()
26+
{
27+
for (uint8_t i = 0; i < MAX_SOCK_NUM; ++i)
28+
{
29+
if (WiFiClass::_server_port[i] == 0)
30+
{
31+
return i;
32+
}
33+
}
34+
return NO_SOCKET_AVAIL;
35+
}
36+
37+
int WiFiClass::begin(char* ssid)
38+
{
39+
uint8_t status = WL_IDLE_STATUS;
40+
uint8_t attempts = WL_MAX_ATTEMPT_CONNECTION;
41+
42+
if (WiFiDrv::wifiSetNetwork(ssid, strlen(ssid)) != WL_FAILURE)
43+
{
44+
do
45+
{
46+
delay(WL_DELAY_START_CONNECTION);
47+
status = WiFiDrv::getConnectionStatus();
48+
}
49+
while ((( status == WL_IDLE_STATUS)||(status == WL_SCAN_COMPLETED))&&(--attempts>0));
50+
}else
51+
{
52+
status = WL_CONNECT_FAILED;
53+
}
54+
return status;
55+
}
56+
57+
int WiFiClass::begin(char* ssid, uint8_t key_idx, const char *key)
58+
{
59+
uint8_t status = WL_IDLE_STATUS;
60+
uint8_t attempts = WL_MAX_ATTEMPT_CONNECTION;
61+
62+
// set encryption key
63+
if (WiFiDrv::wifiSetKey(ssid, strlen(ssid), key_idx, key, strlen(key)) != WL_FAILURE)
64+
{
65+
do
66+
{
67+
delay(WL_DELAY_START_CONNECTION);
68+
status = WiFiDrv::getConnectionStatus();
69+
}
70+
while ((( status == WL_IDLE_STATUS)||(status == WL_SCAN_COMPLETED))&&(--attempts>0));
71+
}else{
72+
status = WL_CONNECT_FAILED;
73+
}
74+
return status;
75+
}
76+
77+
int WiFiClass::begin(char* ssid, const char *passphrase)
78+
{
79+
uint8_t status = WL_IDLE_STATUS;
80+
uint8_t attempts = WL_MAX_ATTEMPT_CONNECTION;
81+
82+
// set passphrase
83+
if (WiFiDrv::wifiSetPassphrase(ssid, strlen(ssid), passphrase, strlen(passphrase))!= WL_FAILURE)
84+
{
85+
do
86+
{
87+
delay(WL_DELAY_START_CONNECTION);
88+
status = WiFiDrv::getConnectionStatus();
89+
}
90+
while ((( status == WL_IDLE_STATUS)||(status == WL_SCAN_COMPLETED))&&(--attempts>0));
91+
}else{
92+
status = WL_CONNECT_FAILED;
93+
}
94+
return status;
95+
}
96+
97+
int WiFiClass::disconnect()
98+
{
99+
return WiFiDrv::disconnect();
100+
}
101+
102+
uint8_t* WiFiClass::macAddress(uint8_t* mac)
103+
{
104+
uint8_t* _mac = WiFiDrv::getMacAddress();
105+
memcpy(mac, _mac, WL_MAC_ADDR_LENGTH);
106+
return mac;
107+
}
108+
109+
IPAddress WiFiClass::localIP()
110+
{
111+
IPAddress ret;
112+
WiFiDrv::getIpAddress(ret);
113+
return ret;
114+
}
115+
116+
IPAddress WiFiClass::subnetMask()
117+
{
118+
IPAddress ret;
119+
WiFiDrv::getSubnetMask(ret);
120+
return ret;
121+
}
122+
123+
IPAddress WiFiClass::gatewayIP()
124+
{
125+
IPAddress ret;
126+
WiFiDrv::getGatewayIP(ret);
127+
return ret;
128+
}
129+
130+
char* WiFiClass::SSID()
131+
{
132+
return WiFiDrv::getCurrentSSID();
133+
}
134+
135+
uint8_t* WiFiClass::BSSID(uint8_t* bssid)
136+
{
137+
uint8_t* _bssid = WiFiDrv::getCurrentBSSID();
138+
memcpy(bssid, _bssid, WL_MAC_ADDR_LENGTH);
139+
return bssid;
140+
}
141+
142+
int32_t WiFiClass::RSSI()
143+
{
144+
return WiFiDrv::getCurrentRSSI();
145+
}
146+
147+
uint8_t WiFiClass::encryptionType()
148+
{
149+
return WiFiDrv::getCurrentEncryptionType();
150+
}
151+
152+
153+
int8_t WiFiClass::scanNetworks()
154+
{
155+
uint8_t attempts = 10;
156+
uint8_t numOfNetworks = 0;
157+
158+
if (WiFiDrv::startScanNetworks() == WL_FAILURE)
159+
return WL_FAILURE;
160+
do
161+
{
162+
delay(2000);
163+
numOfNetworks = WiFiDrv::getScanNetworks();
164+
}
165+
while (( numOfNetworks == 0)&&(--attempts>0));
166+
return numOfNetworks;
167+
}
168+
169+
char* WiFiClass::SSID(uint8_t networkItem)
170+
{
171+
return WiFiDrv::getSSIDNetoworks(networkItem);
172+
}
173+
174+
int32_t WiFiClass::RSSI(uint8_t networkItem)
175+
{
176+
return WiFiDrv::getRSSINetoworks(networkItem);
177+
}
178+
179+
uint8_t WiFiClass::encryptionType(uint8_t networkItem)
180+
{
181+
return WiFiDrv::getEncTypeNetowrks(networkItem);
182+
}
183+
184+
uint8_t WiFiClass::status()
185+
{
186+
return WiFiDrv::getConnectionStatus();
187+
}
188+
189+
int WiFiClass::hostByName(const char* aHostname, IPAddress& aResult)
190+
{
191+
return WiFiDrv::getHostByName(aHostname, aResult);
192+
}
193+
194+
WiFiClass WiFi;

WiFi/WiFi.h

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
#ifndef WiFi_h
2+
#define WiFi_h
3+
4+
#include <inttypes.h>
5+
6+
extern "C" {
7+
#include "utility/wl_definitions.h"
8+
#include "utility/wl_types.h"
9+
}
10+
11+
#include "IPAddress.h"
12+
#include "WiFiClient.h"
13+
#include "WiFiServer.h"
14+
15+
class WiFiClass
16+
{
17+
private:
18+
19+
static void init();
20+
public:
21+
static int16_t _state[MAX_SOCK_NUM];
22+
static uint16_t _server_port[MAX_SOCK_NUM];
23+
24+
WiFiClass();
25+
26+
/*
27+
* Get the first socket available
28+
*/
29+
static uint8_t getSocket();
30+
31+
/* Start Wifi connection for OPEN networks
32+
*
33+
* param ssid: Pointer to the SSID string.
34+
*/
35+
int begin(char* ssid);
36+
37+
/* Start Wifi connection with WEP encryption.
38+
* Configure a key into the device. The key type (WEP-40, WEP-104)
39+
* is determined by the size of the key (5 bytes for WEP-40, 13 bytes for WEP-104).
40+
*
41+
* param ssid: Pointer to the SSID string.
42+
* param key_idx: The key index to set. Valid values are 0-3.
43+
* param key: Key input buffer.
44+
*/
45+
int begin(char* ssid, uint8_t key_idx, const char* key);
46+
47+
/* Start Wifi connection with passphrase
48+
* the most secure supported mode will be automatically selected
49+
*
50+
* param ssid: Pointer to the SSID string.
51+
* param passphrase: Passphrase. Valid characters in a passphrase
52+
* must be between ASCII 32-126 (decimal).
53+
*/
54+
int begin(char* ssid, const char *passphrase);
55+
56+
/*
57+
* Disconnect from the network
58+
*
59+
* return: one value of wl_status_t enum
60+
*/
61+
int disconnect(void);
62+
63+
/*
64+
* Get the interface MAC address.
65+
*
66+
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
67+
*/
68+
uint8_t* macAddress(uint8_t* mac);
69+
70+
/*
71+
* Get the interface IP address.
72+
*
73+
* return: Ip address value
74+
*/
75+
IPAddress localIP();
76+
77+
/*
78+
* Get the interface subnet mask address.
79+
*
80+
* return: subnet mask address value
81+
*/
82+
IPAddress subnetMask();
83+
84+
/*
85+
* Get the gateway ip address.
86+
*
87+
* return: gateway ip address value
88+
*/
89+
IPAddress gatewayIP();
90+
91+
/*
92+
* Return the current SSID associated with the network
93+
*
94+
* return: ssid string
95+
*/
96+
char* SSID();
97+
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+
*/
104+
uint8_t* BSSID(uint8_t* bssid);
105+
106+
/*
107+
* Return the current RSSI /Received Signal Strength in dBm)
108+
* associated with the network
109+
*
110+
* return: signed value
111+
*/
112+
int32_t RSSI();
113+
114+
/*
115+
* Return the Encryption Type associated with the network
116+
*
117+
* return: one value of wl_enc_type enum
118+
*/
119+
uint8_t encryptionType();
120+
121+
/*
122+
* Start scan WiFi networks available
123+
*
124+
* return: Number of discovered networks
125+
*/
126+
int8_t scanNetworks();
127+
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+
*/
135+
char* SSID(uint8_t networkItem);
136+
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+
*/
144+
uint8_t encryptionType(uint8_t networkItem);
145+
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+
*/
153+
int32_t RSSI(uint8_t networkItem);
154+
155+
/*
156+
* Return Connection status.
157+
*
158+
* return: one of the value defined in wl_status_t
159+
*/
160+
uint8_t status();
161+
162+
/*
163+
* Resolve the given hostname to an IP address.
164+
* param aHostname: Name to be resolved
165+
* param aResult: IPAddress structure to store the returned IP address
166+
* result: 1 if aIPAddrString was successfully converted to an IP address,
167+
* else error code
168+
*/
169+
int hostByName(const char* aHostname, IPAddress& aResult);
170+
171+
friend class WiFiClient;
172+
friend class WiFiServer;
173+
};
174+
175+
extern WiFiClass WiFi;
176+
177+
#endif

0 commit comments

Comments
 (0)