Skip to content

Cellular: Add WISE-1570 handling for socket closing URC #10463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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_ */