Added static const to AT_CellularNetwork.cpp

pull/6082/head
Ari Parkkila 2018-02-19 10:30:41 +02:00
parent 0e20e49ef7
commit 0c8c41ff5f
1 changed files with 30 additions and 22 deletions

View File

@ -25,6 +25,17 @@ using namespace std;
using namespace mbed_cellular_util; using namespace mbed_cellular_util;
using namespace mbed; using namespace mbed;
struct at_reg_t {
const CellularNetwork::RegistrationType type;
const char *const cmd;
};
static const at_reg_t at_reg[] = {
{ CellularNetwork::C_EREG, "AT+CEREG" },
{ CellularNetwork::C_GREG, "AT+CGREG" },
{ CellularNetwork::C_REG, "AT+CREG" },
};
AT_CellularNetwork::AT_CellularNetwork(ATHandler &atHandler) : AT_CellularBase(atHandler), AT_CellularNetwork::AT_CellularNetwork(ATHandler &atHandler) : AT_CellularBase(atHandler),
_stack(NULL), _uname(NULL), _pwd(NULL), _ip_stack_type_requested(DEFAULT_STACK), _ip_stack_type(DEFAULT_STACK), _cid(-1), _stack(NULL), _uname(NULL), _pwd(NULL), _ip_stack_type_requested(DEFAULT_STACK), _ip_stack_type(DEFAULT_STACK), _cid(-1),
_connection_status_cb(NULL), _op_act(operator_t::RAT_UNKNOWN), _authentication_type(CHAP), _last_reg_type(C_REG), _connection_status_cb(NULL), _op_act(operator_t::RAT_UNKNOWN), _authentication_type(CHAP), _last_reg_type(C_REG),
@ -409,17 +420,16 @@ nsapi_ip_stack_t AT_CellularNetwork::string_to_stack_type(const char* pdp_type)
nsapi_error_t AT_CellularNetwork::set_registration_urc(bool urc_on) nsapi_error_t AT_CellularNetwork::set_registration_urc(bool urc_on)
{ {
RegistrationType reg_types[] = {C_EREG, C_GREG, C_REG}; for (int i = 0; i < sizeof(at_reg)/sizeof(at_reg[0]); i++) {
const char *cmd_on[] = {"AT+CEREG=2", "AT+CGREG=2", "AT+CREG=2"}; if (has_registration(at_reg[i].type)) {
const char *cmd_off[] = {"AT+CEREG=0", "AT+CGREG=0", "AT+CREG=0"}; _last_reg_type = at_reg[i].type;
for (uint8_t i=0; i<sizeof(reg_types)/sizeof(reg_types[0]); i++) {
if (has_registration(reg_types[i])) {
_last_reg_type = reg_types[i];
if (urc_on) { if (urc_on) {
_at.cmd_start(cmd_on[i]); _at.cmd_start(at_reg[i].cmd);
_at.write_string("=2", false);
_at.cmd_stop(); _at.cmd_stop();
} else { } else {
_at.cmd_start(cmd_off[i]); _at.cmd_start(at_reg[i].cmd);
_at.write_string("=0", false);
_at.cmd_stop(); _at.cmd_stop();
} }
@ -463,8 +473,6 @@ nsapi_error_t AT_CellularNetwork::get_registration_status(RegistrationType type,
int i = (int)type; int i = (int)type;
MBED_ASSERT(i >= 0 && i < C_MAX); MBED_ASSERT(i >= 0 && i < C_MAX);
RegistrationType reg_types[] = { C_EREG, C_GREG, C_REG};
const char *cmd[] = { "AT+CEREG", "AT+CGREG", "AT+CREG"};
const char *rsp[] = { "+CEREG:", "+CGREG:", "+CREG:"}; const char *rsp[] = { "+CEREG:", "+CGREG:", "+CREG:"};
const int LAC_LENGTH = 5, CELL_ID_LENGTH = 9; const int LAC_LENGTH = 5, CELL_ID_LENGTH = 9;
@ -476,18 +484,18 @@ nsapi_error_t AT_CellularNetwork::get_registration_status(RegistrationType type,
_at.lock(); _at.lock();
if (!has_registration(reg_types[i])) { if (!has_registration(at_reg[i].type)) {
_at.unlock(); _at.unlock();
return NSAPI_ERROR_UNSUPPORTED; return NSAPI_ERROR_UNSUPPORTED;
} }
_at.cmd_start(cmd[i]); _at.cmd_start(at_reg[i].cmd);
_at.write_string("=2", false); _at.write_string("=2", false);
_at.cmd_stop(); _at.cmd_stop();
_at.resp_start(); _at.resp_start();
_at.resp_stop(); _at.resp_stop();
_at.cmd_start(cmd[i]); _at.cmd_start(at_reg[i].cmd);
_at.write_string("?", false); _at.write_string("?", false);
_at.cmd_stop(); _at.cmd_stop();
@ -507,7 +515,7 @@ nsapi_error_t AT_CellularNetwork::get_registration_status(RegistrationType type,
_at.resp_stop(); _at.resp_stop();
_at.cmd_start(cmd[i]); _at.cmd_start(at_reg[i].cmd);
_at.write_string("=0", false); _at.write_string("=0", false);
_at.cmd_stop(); _at.cmd_stop();
_at.resp_start(); _at.resp_start();