Skip to content

Commit 0339ffd

Browse files
author
Mirela Chirica
committed
Cellular: Added handling for BG96 network PDP context deactivation
1 parent 09ea361 commit 0339ffd

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()
@@ -115,32 +110,35 @@ nsapi_error_t QUECTEL_BG96_CellularStack::socket_connect(nsapi_socket_t handle,
115110
return NSAPI_ERROR_NO_CONNECTION;
116111
}
117112

118-
void QUECTEL_BG96_CellularStack::urc_qiurc()
113+
void QUECTEL_BG96_CellularStack::urc_qiurc_recv()
114+
{
115+
urc_qiurc(URC_RECV);
116+
}
117+
118+
void QUECTEL_BG96_CellularStack::urc_qiurc_closed()
119+
{
120+
urc_qiurc(URC_CLOSED);
121+
}
122+
123+
void QUECTEL_BG96_CellularStack::urc_qiurc(urc_type_t urc_type)
119124
{
120-
char urc_string[MAX_QIURC_LENGTH + 1];
121125
_at.lock();
122-
(void)_at.read_string(urc_string, sizeof(urc_string));
126+
_at.skip_param();
123127
const int sock_id = _at.read_int();
124128
const nsapi_error_t err = _at.unlock_return_error();
125129

126130
if (err != NSAPI_ERROR_OK) {
127131
return;
128132
}
129133

130-
bool recv = strcmp(urc_string, "recv") == 0;
131-
bool closed = strcmp(urc_string, "closed") == 0;
132-
133134
CellularSocket *sock = find_socket(sock_id);
134135
if (sock) {
135-
if (closed) {
136-
tr_error("Socket closed %d", sock_id);
136+
if (urc_type == URC_CLOSED) {
137+
tr_info("Socket closed %d", sock_id);
137138
sock->closed = true;
138139
}
139-
140-
if (recv || closed) {
141-
if (sock->_cb) {
142-
sock->_cb(sock->_data);
143-
}
140+
if (sock->_cb) {
141+
sock->_cb(sock->_data);
144142
}
145143
}
146144
}

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)