Cellular: Change CellularNonIPSocket to poll before timeout

pull/12065/head
Ari Parkkila 2019-12-09 04:36:29 -08:00
parent f4158ca00e
commit 033402d597
6 changed files with 46 additions and 8 deletions

View File

@ -42,7 +42,7 @@ static const intptr_t cellular_properties[AT_CellularDevice::PROPERTY_MAX] = {
1, // PROPERTY_IPV4_STACK
1, // PROPERTY_IPV6_STACK
0, // PROPERTY_IPV4V6_STACK
0, // PROPERTY_NON_IP_PDP_TYPE
1, // PROPERTY_NON_IP_PDP_TYPE
0, // PROPERTY_AT_CGEREP,
0, // PROPERTY_AT_COPS_FALLBACK_AUTO
};
@ -89,11 +89,18 @@ nsapi_error_t QUECTEL_BC95::init()
_at->lock();
_at->flush();
_at->at_cmd_discard("", ""); //Send AT
_at->at_cmd_discard("+CMEE", "=1"); // verbose responses
return _at->unlock_return_error();
nsapi_error_t err = _at->at_cmd_discard("", ""); //Send AT
if (!err) {
err = _at->at_cmd_discard("+CMEE", "=1"); // verbose responses
}
if (!err) {
err = _at->at_cmd_discard("+CFUN", "=", "%d", 1);
}
if (!err) {
err = _at->get_last_error();
}
_at->unlock();
return err;
}
nsapi_error_t QUECTEL_BC95::set_baud_rate_impl(int baud_rate)

View File

@ -44,4 +44,9 @@ NetworkStack *QUECTEL_BC95_CellularContext::get_stack()
}
#endif // #if !NSAPI_PPP_AVAILABLE
const char* QUECTEL_BC95_CellularContext::get_nonip_context_type_str()
{
return "NONIP";
}
} /* namespace mbed */

View File

@ -30,6 +30,7 @@ protected:
#if !NSAPI_PPP_AVAILABLE
virtual NetworkStack *get_stack();
#endif // #if !NSAPI_PPP_AVAILABLE
virtual const char* get_nonip_context_type_str();
};
} /* namespace mbed */

View File

@ -38,3 +38,26 @@ nsapi_error_t QUECTEL_BC95_CellularNetwork::set_access_technology_impl(RadioAcce
return NSAPI_ERROR_OK;
}
nsapi_error_t QUECTEL_BC95_CellularNetwork::clear()
{
nsapi_error_t err = AT_CellularNetwork::clear();
#if MBED_CONF_CELLULAR_CONTROL_PLANE_OPT
if (!err) {
err = _at.at_cmd_discard("+CGDCONT", "=", "%d", 0);
#ifdef MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN
err = _at.at_cmd_discard("+CGDCONT", "=", "%d%s%s", 1, "NONIP", MBED_CONF_NSAPI_DEFAULT_CELLULAR_APN);
#endif
if (!err) {
err = _at.at_cmd_discard("+CIPCA", "=", "%d%d", 3, 1); // EPS Attach without PDN connection
}
if (!err) {
_at.lock();
_at.cmd_start("AT+NCONFIG=\"AUTOCONNECT\",\"TRUE\""); // disable auto connect to IP context
_at.cmd_stop_read_resp();
err = _at.unlock_return_error();
}
}
#endif
return err;
}

View File

@ -29,6 +29,7 @@ public:
protected:
virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology opRat);
virtual nsapi_error_t clear();
};
} // namespace mbed
#endif // QUECTEL_BC95_CELLULAR_NETWORK_H_

View File

@ -145,13 +145,12 @@ nsapi_size_or_error_t CellularNonIPSocket::send(const void *data, nsapi_size_t s
nsapi_size_or_error_t CellularNonIPSocket::recv(void *buffer, nsapi_size_t size)
{
_lock.lock();
nsapi_size_or_error_t ret;
nsapi_size_or_error_t ret = NSAPI_ERROR_NO_SOCKET;
_readers++;
while (true) {
if (!_opened) {
ret = NSAPI_ERROR_NO_SOCKET;
break;
}
@ -173,6 +172,8 @@ nsapi_size_or_error_t CellularNonIPSocket::recv(void *buffer, nsapi_size_t size)
if (flag & osFlagsError) {
// Timeout break
// Poll once more for a possibly missed data received indication
ret = _cp_netif->recv(buffer, size);
break;
}
}