Skip to content

Commit 0e37923

Browse files
authored
Merge pull request ARMmbed#76 from linlingao/network_callback
Add network connection callback
2 parents 01bb991 + a6b96a3 commit 0e37923

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/CC3220SF_WiFiInterface.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ nsapi_error_t CC3220SFInterface::connect()
8181
return NSAPI_ERROR_IS_CONNECTED;
8282
}
8383

84+
_cc3200_simplelink.set_connection_status(NSAPI_STATUS_CONNECTING);
85+
8486
status = _startup(CC3200_SIMPLELINK::WIFI_ROLE_STATION);
8587
if(status != NSAPI_ERROR_OK)
8688
{
@@ -107,11 +109,16 @@ nsapi_error_t CC3220SFInterface::connect()
107109
{
108110
printf("IP address set timed out\n");
109111
}
112+
else
113+
{
114+
_cc3200_simplelink.set_connection_status(NSAPI_STATUS_GLOBAL_UP);
115+
}
110116

111117
if (!get_ip_address())
112118
{
113119
return NSAPI_ERROR_DHCP_FAILURE;
114120
}
121+
115122
return NSAPI_ERROR_OK;
116123
}
117124

@@ -168,10 +175,21 @@ nsapi_error_t CC3220SFInterface::set_channel(uint8_t channel)
168175

169176
nsapi_error_t CC3220SFInterface::disconnect()
170177
{
178+
nsapi_error_t status;
179+
171180
_started = false;
172181
_initialized = false;
173182

174-
return _cc3200_simplelink.disconnect() ? NSAPI_ERROR_OK : NSAPI_ERROR_DEVICE_ERROR;
183+
if (_cc3200_simplelink.disconnect())
184+
{
185+
status = NSAPI_ERROR_OK;
186+
_cc3200_simplelink.set_connection_status(NSAPI_STATUS_DISCONNECTED);
187+
}
188+
else
189+
{
190+
status = NSAPI_ERROR_DEVICE_ERROR;
191+
}
192+
return status;
175193
}
176194

177195
const char *CC3220SFInterface::get_ip_address()

targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/cc3200_simplelink.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,6 @@ nsapi_error_t CC3200_SIMPLELINK::connect(const char *ssid, const char *passPhras
167167

168168
strncpy(_connected_ssid, ssid, sizeof(_connected_ssid));
169169

170-
_connection_status = NSAPI_STATUS_CONNECTING;
171-
if(_connection_status_cb)
172-
{
173-
_connection_status_cb(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, _connection_status);
174-
}
175-
176170
memset((void*)&sec_params, 0, sizeof(sec_params));
177171

178172
startup(CC3200_SIMPLELINK::WIFI_ROLE_STATION);
@@ -542,6 +536,15 @@ nsapi_connection_status_t CC3200_SIMPLELINK::get_connection_status() const
542536
return _connection_status;
543537
}
544538

539+
void CC3200_SIMPLELINK::set_connection_status(nsapi_connection_status_t status)
540+
{
541+
_connection_status = status;
542+
if(_connection_status_cb)
543+
{
544+
_connection_status_cb(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, _connection_status);
545+
}
546+
}
547+
545548
void CC3200_SIMPLELINK::attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb)
546549
{
547550
_connection_status_cb = status_cb;

targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/device/cc3200_simplelink.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,12 @@ class CC3200_SIMPLELINK
290290
*/
291291
nsapi_connection_status_t get_connection_status() const;
292292

293+
/** Set the connection status
294+
*
295+
* @param status The connection status to set
296+
*/
297+
void set_connection_status(nsapi_connection_status_t status);
298+
293299
static const int8_t WIFI_ROLE_STATION = 1;
294300
static const int8_t WIFI_ROLE_AP = 2;
295301
static const int8_t WIFI_ROLE_P2P = 3;

0 commit comments

Comments
 (0)