@@ -61,6 +61,7 @@ AT_CellularNetwork::~AT_CellularNetwork()
61
61
}
62
62
63
63
_at.remove_urc_handler (" NO CARRIER" , callback (this , &AT_CellularNetwork::urc_no_carrier));
64
+ _at.remove_urc_handler (" +CGEV:" , callback (this , &AT_CellularNetwork::urc_cgev));
64
65
free_credentials ();
65
66
}
66
67
@@ -105,6 +106,36 @@ void AT_CellularNetwork::urc_no_carrier()
105
106
call_network_cb (NSAPI_STATUS_DISCONNECTED);
106
107
}
107
108
109
+ void AT_CellularNetwork::urc_cgev ()
110
+ {
111
+ char buf[13 ];
112
+ if (_at.read_string (buf, 13 ) < 8 ) { // smallest string length we wan't to compare is 8
113
+ return ;
114
+ }
115
+ tr_debug (" urc_cgev: %s" , buf);
116
+
117
+ bool call_cb = false ;
118
+ // NOTE! If in future there will be 2 or more active contexts we might wan't to read context id also but not for now.
119
+
120
+ if (memcmp (buf, " NW DETACH" , 9 ) == 0 ) { // The network has forced a PS detach
121
+ call_cb = true ;
122
+ } else if (memcmp (buf, " ME DETACH" , 9 ) == 0 ) {// The mobile termination has forced a PS detach.
123
+ call_cb = true ;
124
+ } else if (memcmp (buf, " NW DEACT" , 8 ) == 0 ) {// The network has forced a context deactivation
125
+ call_cb = true ;
126
+ } else if (memcmp (buf, " ME DEACT" , 8 ) == 0 ) {// The mobile termination has forced a context deactivation
127
+ call_cb = true ;
128
+ } else if (memcmp (buf, " NW PDN DEACT" , 12 ) == 0 ) {// The network has deactivated a context
129
+ call_cb = true ;
130
+ } else if (memcmp (buf, " ME PDN DEACT" , 12 ) == 0 ) {// The mobile termination has deactivated a context.
131
+ call_cb = true ;
132
+ }
133
+
134
+ if (call_cb) {
135
+ call_network_cb (NSAPI_STATUS_DISCONNECTED);
136
+ }
137
+ }
138
+
108
139
void AT_CellularNetwork::read_reg_params_and_compare (RegistrationType type)
109
140
{
110
141
RegistrationStatus reg_status = NotRegistered;
@@ -329,6 +360,17 @@ nsapi_error_t AT_CellularNetwork::connect()
329
360
return err;
330
361
}
331
362
#else
363
+ // additional urc to get better disconnect info for application. Not critical so not returning an error in case of failure
364
+ err = _at.set_urc_handler (" +CGEV:" , callback (this , &AT_CellularNetwork::urc_cgev));
365
+ if (err == NSAPI_ERROR_OK) {
366
+ _at.lock ();
367
+ _at.cmd_start (" AT+CGEREP=1" );
368
+ _at.cmd_stop ();
369
+ _at.resp_start ();
370
+ _at.resp_stop ();
371
+ _at.unlock ();
372
+ }
373
+
332
374
call_network_cb (NSAPI_STATUS_GLOBAL_UP);
333
375
#endif
334
376
@@ -386,6 +428,7 @@ nsapi_error_t AT_CellularNetwork::disconnect()
386
428
_at.resp_stop ();
387
429
_at.restore_at_timeout ();
388
430
431
+ _at.remove_urc_handler (" +CGEV:" , callback (this , &AT_CellularNetwork::urc_cgev));
389
432
call_network_cb (NSAPI_STATUS_DISCONNECTED);
390
433
391
434
return _at.unlock_return_error ();
0 commit comments