Skip to content

Commit 7f9e69d

Browse files
author
Cruz Monrreal
authored
Merge pull request #6632 from TeemuKultala/error_messages
cellular: Error messages
2 parents b2704f5 + 0caef1b commit 7f9e69d

File tree

4 files changed

+62
-37
lines changed

4 files changed

+62
-37
lines changed

features/cellular/easy_cellular/CellularConnectionFSM.cpp

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ bool CellularConnectionFSM::power_on()
133133
tr_warn("Cellular start failed. Power off/on.");
134134
err = _power->off();
135135
if (err != NSAPI_ERROR_OK && err != NSAPI_ERROR_UNSUPPORTED) {
136-
tr_error("Cellular power down failed!");
136+
tr_error("Cellular power down failing after failed power up attempt!");
137137
}
138138
return false;
139139
}
@@ -156,31 +156,16 @@ bool CellularConnectionFSM::open_sim()
156156
return false;
157157
}
158158

159-
switch (state) {
160-
case CellularSIM::SimStateReady:
161-
tr_info("SIM Ready");
162-
break;
163-
case CellularSIM::SimStatePinNeeded: {
164-
if (strlen(_sim_pin)) {
165-
tr_info("SIM pin required, entering pin: %s", _sim_pin);
166-
nsapi_error_t err = _sim->set_pin(_sim_pin);
167-
if (err) {
168-
tr_error("SIM pin set failed with: %d, bailing out...", err);
169-
}
170-
} else {
171-
tr_warn("PIN required but No SIM pin provided.");
172-
}
159+
if (state == CellularSIM::SimStatePinNeeded) {
160+
if (strlen(_sim_pin)) {
161+
tr_info("SIM pin required, entering pin: %s", _sim_pin);
162+
nsapi_error_t err = _sim->set_pin(_sim_pin);
163+
if (err) {
164+
tr_error("SIM pin set failed with: %d, bailing out...", err);
165+
}
166+
} else {
167+
tr_warn("PIN required but No SIM pin provided.");
173168
}
174-
break;
175-
case CellularSIM::SimStatePukNeeded:
176-
tr_info("SIM PUK code needed...");
177-
break;
178-
case CellularSIM::SimStateUnknown:
179-
tr_info("SIM, unknown state...");
180-
break;
181-
default:
182-
MBED_ASSERT(1);
183-
break;
184169
}
185170

186171
if (_event_status_cb) {
@@ -192,8 +177,9 @@ bool CellularConnectionFSM::open_sim()
192177

193178
bool CellularConnectionFSM::set_network_registration(char *plmn)
194179
{
195-
if (_network->set_registration(plmn) != NSAPI_ERROR_OK) {
196-
tr_error("Failed to set network registration.");
180+
nsapi_error_t error = _network->set_registration(plmn);
181+
if (error != NSAPI_ERROR_OK) {
182+
tr_error("Set network registration mode failing (%d)", error);
197183
return false;
198184
}
199185
return true;

features/cellular/easy_cellular/EasyCellularConnection.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ void EasyCellularConnection::set_credentials(const char *apn, const char *uname,
118118
}
119119
#endif // #if USE_APN_LOOKUP
120120
} else {
121-
tr_error("NO Network...");
121+
//if get_network() returns NULL it means there was not enough memory for
122+
//an AT_CellularNetwork element during CellularConnectionFSM initialization
123+
tr_error("There was not enough memory during CellularConnectionFSM initialization");
122124
}
123125
}
124126
}
@@ -199,7 +201,7 @@ nsapi_error_t EasyCellularConnection::connect()
199201
}
200202
}
201203
if (err) {
202-
tr_info("APN lookup failed");
204+
tr_error("APN lookup failed");
203205
return err;
204206
}
205207
}

features/cellular/framework/AT/AT_CellularNetwork.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ void AT_CellularNetwork::free_credentials()
8585

8686
void AT_CellularNetwork::urc_no_carrier()
8787
{
88+
tr_error("Data call failed: no carrier");
8889
_connect_status = NSAPI_STATUS_DISCONNECTED;
8990
if (_connection_status_cb) {
9091
_connection_status_cb(NSAPI_EVENT_CONNECTION_STATUS_CHANGE, NSAPI_STATUS_DISCONNECTED);
@@ -98,6 +99,22 @@ void AT_CellularNetwork::read_reg_params_and_compare(RegistrationType type)
9899

99100
read_reg_params(type, reg_status, lac, cell_id, act);
100101

102+
#if MBED_CONF_MBED_TRACE_ENABLE
103+
switch (reg_status) {
104+
case NotRegistered:
105+
tr_error("not registered");
106+
break;
107+
case RegistrationDenied:
108+
tr_error("registration denied");
109+
break;
110+
case Unknown:
111+
tr_error("registration status unknown");
112+
break;
113+
default:
114+
break;
115+
}
116+
#endif
117+
101118
if (_at.get_last_error() == NSAPI_ERROR_OK && _connection_status_cb) {
102119
tr_debug("stat: %d, lac: %d, cellID: %d, act: %d", reg_status, lac, cell_id, act);
103120
if (act != -1 && (RadioAccessTechnology)act != _current_act) {
@@ -216,7 +233,7 @@ nsapi_error_t AT_CellularNetwork::activate_context()
216233
nsapi_error_t err = set_context_to_be_activated();
217234
if (err != NSAPI_ERROR_OK) {
218235
_at.unlock();
219-
tr_error("Failed to activate network context!");
236+
tr_error("Failed to activate network context! (%d)", err);
220237

221238
_connect_status = NSAPI_STATUS_DISCONNECTED;
222239
if (_connection_status_cb) {
@@ -229,7 +246,8 @@ nsapi_error_t AT_CellularNetwork::activate_context()
229246
// do check for stack to validate that we have support for stack
230247
_stack = get_stack();
231248
if (!_stack) {
232-
return err;
249+
tr_error("No cellular stack!");
250+
return NSAPI_ERROR_UNSUPPORTED;
233251
}
234252

235253
_is_context_active = false;
@@ -246,7 +264,7 @@ nsapi_error_t AT_CellularNetwork::activate_context()
246264
_at.resp_stop();
247265

248266
if (!_is_context_active) {
249-
tr_info("Activate PDP context");
267+
tr_info("Activate PDP context %d",_cid);
250268
_at.cmd_start("AT+CGACT=1,");
251269
_at.write_int(_cid);
252270
_at.cmd_stop();
@@ -794,11 +812,11 @@ nsapi_error_t AT_CellularNetwork::get_apn_backoff_timer(int &backoff_timer)
794812

795813
NetworkStack *AT_CellularNetwork::get_stack()
796814
{
797-
// use lwIP/PPP if modem does not have IP stack
798815
#if NSAPI_PPP_AVAILABLE
799-
_stack = nsapi_ppp_get_stack();
800-
#else
801-
_stack = NULL;
816+
// use lwIP/PPP if modem does not have IP stack
817+
if (!_stack) {
818+
_stack = nsapi_ppp_get_stack();
819+
}
802820
#endif
803821
return _stack;
804822
}

features/cellular/framework/AT/AT_CellularSIM.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,28 @@ nsapi_error_t AT_CellularSIM::get_sim_state(SimState &state)
5656
state = SimStateUnknown; // SIM may not be ready yet or +CPIN may be unsupported command
5757
}
5858
_at.resp_stop();
59-
return _at.unlock_return_error();
59+
nsapi_error_t error = _at.get_last_error();
60+
_at.unlock();
61+
#if MBED_CONF_MBED_TRACE_ENABLE
62+
switch (state) {
63+
case SimStatePinNeeded:
64+
tr_error("SIM PIN required");
65+
break;
66+
case SimStatePukNeeded:
67+
tr_error("SIM PUK required");
68+
break;
69+
case SimStateUnknown:
70+
tr_error("SIM state unknown");
71+
break;
72+
default:
73+
tr_info("SIM is ready");
74+
break;
75+
}
76+
#endif
77+
return error;
6078
}
6179

80+
6281
nsapi_error_t AT_CellularSIM::set_pin(const char *sim_pin)
6382
{
6483
// if SIM is already in ready state then settings the PIN

0 commit comments

Comments
 (0)