Skip to content

Commit

Permalink
Cellular: Added WISE-1570 handling for socket closing URC
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirela Chirica committed Apr 26, 2019
1 parent 46603f8 commit 948f8b5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Expand Up @@ -27,10 +27,13 @@ using namespace mbed_cellular_util;
QUECTEL_BC95_CellularStack::QUECTEL_BC95_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type) : AT_CellularStack(atHandler, cid, stack_type)
{
_at.set_urc_handler("+NSONMI:", mbed::Callback<void()>(this, &QUECTEL_BC95_CellularStack::urc_nsonmi));
_at.set_urc_handler("+NSOCLI:", mbed::Callback<void()>(this, &QUECTEL_BC95_CellularStack::urc_nsocli));
}

QUECTEL_BC95_CellularStack::~QUECTEL_BC95_CellularStack()
{
_at.set_urc_handler("+NSONMI:", NULL);
_at.set_urc_handler("+NSOCLI:", NULL);
}

nsapi_error_t QUECTEL_BC95_CellularStack::socket_listen(nsapi_socket_t handle, int backlog)
Expand Down Expand Up @@ -88,6 +91,28 @@ void QUECTEL_BC95_CellularStack::urc_nsonmi()
}
}

void QUECTEL_BC95_CellularStack::urc_nsocli()
{
int sock_id = _at.read_int();

const nsapi_error_t err = _at.get_last_error();

if (err != NSAPI_ERROR_OK) {
return;
}

CellularSocket *sock = find_socket(sock_id);

if (sock) {
sock->closed = true;
if (sock->_cb) {
sock->_cb(sock->_data);
}
tr_info("Socket closed %d", sock_id);
}
}


int QUECTEL_BC95_CellularStack::get_max_socket_count()
{
return BC95_SOCKET_MAX;
Expand All @@ -100,6 +125,11 @@ bool QUECTEL_BC95_CellularStack::is_protocol_supported(nsapi_protocol_t protocol

nsapi_error_t QUECTEL_BC95_CellularStack::socket_close_impl(int sock_id)
{
CellularSocket *sock = find_socket(sock_id);

if (sock && sock->closed) {
return NSAPI_ERROR_OK;
}
_at.cmd_start("AT+NSOCL=");
_at.write_int(sock_id);
_at.cmd_stop_read_resp();
Expand Down
Expand Up @@ -57,6 +57,7 @@ class QUECTEL_BC95_CellularStack : public AT_CellularStack {
private:
// URC handlers
void urc_nsonmi();
void urc_nsocli();
};
} // namespace mbed
#endif /* QUECTEL_BC95_CELLULARSTACK_H_ */

0 comments on commit 948f8b5

Please sign in to comment.