Skip to content

Commit 13081a2

Browse files
authored
Merge pull request #10808 from mirelachirica/bg96_pdpdeact
Cellular: Added handling for BG96 network PDP context deactivation
2 parents 15b5b5d + 0339ffd commit 13081a2

File tree

5 files changed

+46
-23
lines changed

5 files changed

+46
-23
lines changed

features/cellular/framework/AT/AT_CellularDevice.h

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ class AT_CellularDevice : public CellularDevice {
143143

144144
protected:
145145
virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx = NULL);
146+
void send_disconnect_to_context(int cid);
146147

147148
private:
148149
void urc_nw_deact();
149150
void urc_pdn_deact();
150-
void send_disconnect_to_context(int cid);
151151
};
152152

153153
} // namespace mbed

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ QUECTEL_BG96::QUECTEL_BG96(FileHandle *fh, PinName pwr, bool active_high, PinNam
6969
_pwr(pwr, !_active_high),
7070
_rst(rst, !_active_high)
7171
{
72+
_at->set_urc_handler("+QIURC: \"pdpde", mbed::Callback<void()>(this, &QUECTEL_BG96::urc_pdpdeact));
73+
7274
AT_CellularBase::set_cellular_properties(cellular_properties);
7375
}
7476

@@ -199,3 +201,16 @@ CellularDevice *CellularDevice::get_default_instance()
199201
return &device;
200202
}
201203
#endif
204+
205+
void QUECTEL_BG96::urc_pdpdeact()
206+
{
207+
_at->lock();
208+
_at->skip_param();
209+
int cid = _at->read_int();
210+
const nsapi_error_t err = _at->unlock_return_error();
211+
212+
if (err != NSAPI_ERROR_OK) {
213+
return;
214+
}
215+
send_disconnect_to_context(cid);
216+
}

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class QUECTEL_BG96 : public AT_CellularDevice {
5454
bool _active_high;
5555
DigitalOut _pwr;
5656
DigitalOut _rst;
57+
void urc_pdpdeact();
5758
};
5859
} // namespace mbed
5960
#endif // QUECTEL_BG96_H_

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularStack.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,10 @@
2020

2121
using namespace mbed;
2222

23-
const char *QIURC_RECV = "recv";
24-
const uint8_t QIURC_RECV_LENGTH = 4;
25-
const char *QIURC_CLOSED = "closed";
26-
const uint8_t QIURC_CLOSED_LENGTH = 6;
27-
const uint8_t MAX_QIURC_LENGTH = QIURC_CLOSED_LENGTH;
28-
2923
QUECTEL_BG96_CellularStack::QUECTEL_BG96_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type) : AT_CellularStack(atHandler, cid, stack_type)
3024
{
31-
_at.set_urc_handler("+QIURC:", mbed::Callback<void()>(this, &QUECTEL_BG96_CellularStack::urc_qiurc));
25+
_at.set_urc_handler("+QIURC: \"recv", mbed::Callback<void()>(this, &QUECTEL_BG96_CellularStack::urc_qiurc_recv));
26+
_at.set_urc_handler("+QIURC: \"close", mbed::Callback<void()>(this, &QUECTEL_BG96_CellularStack::urc_qiurc_closed));
3227
}
3328

3429
QUECTEL_BG96_CellularStack::~QUECTEL_BG96_CellularStack()
@@ -97,32 +92,35 @@ nsapi_error_t QUECTEL_BG96_CellularStack::socket_connect(nsapi_socket_t handle,
9792
return NSAPI_ERROR_NO_CONNECTION;
9893
}
9994

100-
void QUECTEL_BG96_CellularStack::urc_qiurc()
95+
void QUECTEL_BG96_CellularStack::urc_qiurc_recv()
96+
{
97+
urc_qiurc(URC_RECV);
98+
}
99+
100+
void QUECTEL_BG96_CellularStack::urc_qiurc_closed()
101+
{
102+
urc_qiurc(URC_CLOSED);
103+
}
104+
105+
void QUECTEL_BG96_CellularStack::urc_qiurc(urc_type_t urc_type)
101106
{
102-
char urc_string[MAX_QIURC_LENGTH + 1];
103107
_at.lock();
104-
(void)_at.read_string(urc_string, sizeof(urc_string));
108+
_at.skip_param();
105109
const int sock_id = _at.read_int();
106110
const nsapi_error_t err = _at.unlock_return_error();
107111

108112
if (err != NSAPI_ERROR_OK) {
109113
return;
110114
}
111115

112-
bool recv = strcmp(urc_string, "recv") == 0;
113-
bool closed = strcmp(urc_string, "closed") == 0;
114-
115116
CellularSocket *sock = find_socket(sock_id);
116117
if (sock) {
117-
if (closed) {
118-
tr_error("Socket closed %d", sock_id);
118+
if (urc_type == URC_CLOSED) {
119+
tr_info("Socket closed %d", sock_id);
119120
sock->closed = true;
120121
}
121-
122-
if (recv || closed) {
123-
if (sock->_cb) {
124-
sock->_cb(sock->_data);
125-
}
122+
if (sock->_cb) {
123+
sock->_cb(sock->_data);
126124
}
127125
}
128126
}

features/cellular/framework/targets/QUECTEL/BG96/QUECTEL_BG96_CellularStack.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ namespace mbed {
2929
#define BG96_MAX_SEND_SIZE 1460
3030
#define BG96_SOCKET_BIND_FAIL 556
3131

32+
typedef enum {
33+
URC_RECV,
34+
URC_CLOSED,
35+
} urc_type_t;
36+
3237
class QUECTEL_BG96_CellularStack : public AT_CellularStack {
3338
public:
3439
QUECTEL_BG96_CellularStack(ATHandler &atHandler, int cid, nsapi_ip_stack_t stack_type);
@@ -60,8 +65,12 @@ class QUECTEL_BG96_CellularStack : public AT_CellularStack {
6065
void *buffer, nsapi_size_t size);
6166

6267
private:
63-
// URC handlers
64-
void urc_qiurc();
68+
// URC handler
69+
void urc_qiurc(urc_type_t urc_type);
70+
// URC handler for socket data being received
71+
void urc_qiurc_recv();
72+
// URC handler for socket being closed
73+
void urc_qiurc_closed();
6574

6675
void handle_open_socket_response(int &modem_connect_id, int &err);
6776
};

0 commit comments

Comments
 (0)