@@ -25,6 +25,17 @@ using namespace std;
25
25
using namespace mbed_cellular_util ;
26
26
using namespace mbed ;
27
27
28
+ struct at_reg_t {
29
+ const CellularNetwork::RegistrationType type;
30
+ const char *const cmd;
31
+ };
32
+
33
+ static const at_reg_t at_reg[] = {
34
+ { CellularNetwork::C_EREG, " AT+CEREG" },
35
+ { CellularNetwork::C_GREG, " AT+CGREG" },
36
+ { CellularNetwork::C_REG, " AT+CREG" },
37
+ };
38
+
28
39
AT_CellularNetwork::AT_CellularNetwork (ATHandler &atHandler) : AT_CellularBase(atHandler),
29
40
_stack(NULL ), _uname(NULL ), _pwd(NULL ), _ip_stack_type_requested(DEFAULT_STACK), _ip_stack_type(DEFAULT_STACK), _cid(-1 ),
30
41
_connection_status_cb(NULL ), _op_act(operator_t ::RAT_UNKNOWN), _authentication_type(CHAP), _last_reg_type(C_REG),
@@ -65,7 +76,7 @@ nsapi_error_t AT_CellularNetwork::set_credentials(const char *apn,
65
76
}
66
77
67
78
nsapi_error_t AT_CellularNetwork::set_credentials (const char *apn,
68
- AuthenticationType type, const char *username, const char *password)
79
+ AuthenticationType type, const char *username, const char *password)
69
80
{
70
81
strncpy (_apn, apn, MAX_ACCESSPOINT_NAME_LENGTH);
71
82
_uname = username;
@@ -319,7 +330,7 @@ bool AT_CellularNetwork::set_new_context(nsapi_ip_stack_t stack, int cid)
319
330
_cid = cid;
320
331
}
321
332
322
- return success;
333
+ return success;
323
334
}
324
335
325
336
bool AT_CellularNetwork::get_context (nsapi_ip_stack_t requested_stack)
@@ -409,17 +420,16 @@ nsapi_ip_stack_t AT_CellularNetwork::string_to_stack_type(const char* pdp_type)
409
420
410
421
nsapi_error_t AT_CellularNetwork::set_registration_urc (bool urc_on)
411
422
{
412
- RegistrationType reg_types[] = {C_EREG, C_GREG, C_REG};
413
- const char *cmd_on[] = {" AT+CEREG=2" , " AT+CGREG=2" , " AT+CREG=2" };
414
- const char *cmd_off[] = {" AT+CEREG=0" , " AT+CGREG=0" , " AT+CREG=0" };
415
- for (uint8_t i=0 ; i<sizeof (reg_types)/sizeof (reg_types[0 ]); i++) {
416
- if (has_registration (reg_types[i])) {
417
- _last_reg_type = reg_types[i];
423
+ for (int i = 0 ; i < sizeof (at_reg)/sizeof (at_reg[0 ]); i++) {
424
+ if (has_registration (at_reg[i].type )) {
425
+ _last_reg_type = at_reg[i].type ;
418
426
if (urc_on) {
419
- _at.cmd_start (cmd_on[i]);
427
+ _at.cmd_start (at_reg[i].cmd );
428
+ _at.write_string (" =2" , false );
420
429
_at.cmd_stop ();
421
430
} else {
422
- _at.cmd_start (cmd_off[i]);
431
+ _at.cmd_start (at_reg[i].cmd );
432
+ _at.write_string (" =0" , false );
423
433
_at.cmd_stop ();
424
434
}
425
435
@@ -463,8 +473,6 @@ nsapi_error_t AT_CellularNetwork::get_registration_status(RegistrationType type,
463
473
int i = (int )type;
464
474
MBED_ASSERT (i >= 0 && i < C_MAX);
465
475
466
- RegistrationType reg_types[] = { C_EREG, C_GREG, C_REG};
467
- const char *cmd[] = { " AT+CEREG" , " AT+CGREG" , " AT+CREG" };
468
476
const char *rsp[] = { " +CEREG:" , " +CGREG:" , " +CREG:" };
469
477
470
478
const int LAC_LENGTH = 5 , CELL_ID_LENGTH = 9 ;
@@ -474,20 +482,20 @@ nsapi_error_t AT_CellularNetwork::get_registration_status(RegistrationType type,
474
482
_cell_id = -1 ;
475
483
_lac = -1 ;
476
484
477
- _at.lock ();
485
+ _at.lock ();
478
486
479
- if (!has_registration (reg_types [i])) {
487
+ if (!has_registration (at_reg [i]. type )) {
480
488
_at.unlock ();
481
489
return NSAPI_ERROR_UNSUPPORTED;
482
490
}
483
491
484
- _at.cmd_start (cmd [i]);
492
+ _at.cmd_start (at_reg [i]. cmd );
485
493
_at.write_string (" =2" , false );
486
494
_at.cmd_stop ();
487
495
_at.resp_start ();
488
496
_at.resp_stop ();
489
497
490
- _at.cmd_start (cmd [i]);
498
+ _at.cmd_start (at_reg [i]. cmd );
491
499
_at.write_string (" ?" , false );
492
500
493
501
_at.cmd_stop ();
@@ -507,7 +515,7 @@ nsapi_error_t AT_CellularNetwork::get_registration_status(RegistrationType type,
507
515
508
516
_at.resp_stop ();
509
517
510
- _at.cmd_start (cmd [i]);
518
+ _at.cmd_start (at_reg [i]. cmd );
511
519
_at.write_string (" =0" , false );
512
520
_at.cmd_stop ();
513
521
_at.resp_start ();
@@ -699,7 +707,7 @@ nsapi_error_t AT_CellularNetwork::scan_plmn(operList_t &operators, int &opsCount
699
707
op->op_rat = (ret == error_code) ? operator_t ::RAT_UNKNOWN:(operator_t ::RadioAccessTechnology)ret;
700
708
701
709
if ((_op_act == operator_t ::RAT_UNKNOWN) ||
702
- ((op->op_rat != operator_t ::RAT_UNKNOWN) && (op->op_rat == _op_act))) {
710
+ ((op->op_rat != operator_t ::RAT_UNKNOWN) && (op->op_rat == _op_act))) {
703
711
idx++;
704
712
} else {
705
713
operators.delete_last ();
@@ -714,7 +722,7 @@ nsapi_error_t AT_CellularNetwork::scan_plmn(operList_t &operators, int &opsCount
714
722
}
715
723
716
724
nsapi_error_t AT_CellularNetwork::set_ciot_optimization_config (Supported_UE_Opt supported_opt,
717
- Preferred_UE_Opt preferred_opt)
725
+ Preferred_UE_Opt preferred_opt)
718
726
{
719
727
_at.lock ();
720
728
@@ -731,7 +739,7 @@ nsapi_error_t AT_CellularNetwork::set_ciot_optimization_config(Supported_UE_Opt
731
739
}
732
740
733
741
nsapi_error_t AT_CellularNetwork::get_ciot_optimization_config (Supported_UE_Opt& supported_opt,
734
- Preferred_UE_Opt& preferred_opt)
742
+ Preferred_UE_Opt& preferred_opt)
735
743
{
736
744
_at.lock ();
737
745
@@ -751,8 +759,8 @@ nsapi_error_t AT_CellularNetwork::get_ciot_optimization_config(Supported_UE_Opt&
751
759
}
752
760
753
761
nsapi_error_t AT_CellularNetwork::get_rate_control (
754
- CellularNetwork::RateControlExceptionReports &reports,
755
- CellularNetwork::RateControlUplinkTimeUnit &timeUnit, int &uplinkRate)
762
+ CellularNetwork::RateControlExceptionReports &reports,
763
+ CellularNetwork::RateControlUplinkTimeUnit &timeUnit, int &uplinkRate)
756
764
{
757
765
758
766
_at.lock ();
0 commit comments