Skip to content

Commit 9ec4cb8

Browse files
author
Ari Parkkila
committed
Added static const to AT_CellularNetwork.cpp
1 parent 8a96a28 commit 9ec4cb8

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

features/cellular/framework/AT/AT_CellularNetwork.cpp

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ using namespace std;
2525
using namespace mbed_cellular_util;
2626
using namespace mbed;
2727

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+
2839
AT_CellularNetwork::AT_CellularNetwork(ATHandler &atHandler) : AT_CellularBase(atHandler),
2940
_stack(NULL), _uname(NULL), _pwd(NULL), _ip_stack_type_requested(DEFAULT_STACK), _ip_stack_type(DEFAULT_STACK), _cid(-1),
3041
_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,
6576
}
6677

6778
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)
6980
{
7081
strncpy(_apn, apn, MAX_ACCESSPOINT_NAME_LENGTH);
7182
_uname = username;
@@ -319,7 +330,7 @@ bool AT_CellularNetwork::set_new_context(nsapi_ip_stack_t stack, int cid)
319330
_cid = cid;
320331
}
321332

322-
return success;
333+
return success;
323334
}
324335

325336
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)
409420

410421
nsapi_error_t AT_CellularNetwork::set_registration_urc(bool urc_on)
411422
{
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;
418426
if (urc_on) {
419-
_at.cmd_start(cmd_on[i]);
427+
_at.cmd_start(at_reg[i].cmd);
428+
_at.write_string("=2", false);
420429
_at.cmd_stop();
421430
} else {
422-
_at.cmd_start(cmd_off[i]);
431+
_at.cmd_start(at_reg[i].cmd);
432+
_at.write_string("=0", false);
423433
_at.cmd_stop();
424434
}
425435

@@ -463,8 +473,6 @@ nsapi_error_t AT_CellularNetwork::get_registration_status(RegistrationType type,
463473
int i = (int)type;
464474
MBED_ASSERT(i >= 0 && i < C_MAX);
465475

466-
RegistrationType reg_types[] = { C_EREG, C_GREG, C_REG};
467-
const char *cmd[] = { "AT+CEREG", "AT+CGREG", "AT+CREG"};
468476
const char *rsp[] = { "+CEREG:", "+CGREG:", "+CREG:"};
469477

470478
const int LAC_LENGTH = 5, CELL_ID_LENGTH = 9;
@@ -474,20 +482,20 @@ nsapi_error_t AT_CellularNetwork::get_registration_status(RegistrationType type,
474482
_cell_id = -1;
475483
_lac = -1;
476484

477-
_at.lock();
485+
_at.lock();
478486

479-
if (!has_registration(reg_types[i])) {
487+
if (!has_registration(at_reg[i].type)) {
480488
_at.unlock();
481489
return NSAPI_ERROR_UNSUPPORTED;
482490
}
483491

484-
_at.cmd_start(cmd[i]);
492+
_at.cmd_start(at_reg[i].cmd);
485493
_at.write_string("=2", false);
486494
_at.cmd_stop();
487495
_at.resp_start();
488496
_at.resp_stop();
489497

490-
_at.cmd_start(cmd[i]);
498+
_at.cmd_start(at_reg[i].cmd);
491499
_at.write_string("?", false);
492500

493501
_at.cmd_stop();
@@ -507,7 +515,7 @@ nsapi_error_t AT_CellularNetwork::get_registration_status(RegistrationType type,
507515

508516
_at.resp_stop();
509517

510-
_at.cmd_start(cmd[i]);
518+
_at.cmd_start(at_reg[i].cmd);
511519
_at.write_string("=0", false);
512520
_at.cmd_stop();
513521
_at.resp_start();
@@ -699,7 +707,7 @@ nsapi_error_t AT_CellularNetwork::scan_plmn(operList_t &operators, int &opsCount
699707
op->op_rat = (ret == error_code) ? operator_t::RAT_UNKNOWN:(operator_t::RadioAccessTechnology)ret;
700708

701709
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))) {
703711
idx++;
704712
} else {
705713
operators.delete_last();
@@ -714,7 +722,7 @@ nsapi_error_t AT_CellularNetwork::scan_plmn(operList_t &operators, int &opsCount
714722
}
715723

716724
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)
718726
{
719727
_at.lock();
720728

@@ -731,7 +739,7 @@ nsapi_error_t AT_CellularNetwork::set_ciot_optimization_config(Supported_UE_Opt
731739
}
732740

733741
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)
735743
{
736744
_at.lock();
737745

@@ -751,8 +759,8 @@ nsapi_error_t AT_CellularNetwork::get_ciot_optimization_config(Supported_UE_Opt&
751759
}
752760

753761
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)
756764
{
757765

758766
_at.lock();

0 commit comments

Comments
 (0)