Skip to content

Commit 7b6208c

Browse files
author
Teemu Kultala
committed
cellular: error message changes
1 parent 68ebbb0 commit 7b6208c

File tree

6 files changed

+70
-42
lines changed

6 files changed

+70
-42
lines changed

features/cellular/easy_cellular/CellularConnectionFSM.cpp

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ bool CellularConnectionFSM::power_on()
129129
tr_warn("Cellular start failed. Power off/on.");
130130
err = _power->off();
131131
if (err != NSAPI_ERROR_OK && err != NSAPI_ERROR_UNSUPPORTED) {
132-
tr_error("Cellular power down failed!");
132+
tr_error("Cellular power down failing after failed power up attempt!");
133133
}
134134
return false;
135135
}
@@ -152,33 +152,6 @@ bool CellularConnectionFSM::open_sim()
152152
return false;
153153
}
154154

155-
switch (state) {
156-
case CellularSIM::SimStateReady:
157-
tr_info("SIM Ready");
158-
break;
159-
case 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.");
168-
}
169-
}
170-
break;
171-
case CellularSIM::SimStatePukNeeded:
172-
tr_info("SIM PUK code needed...");
173-
break;
174-
case CellularSIM::SimStateUnknown:
175-
tr_info("SIM, unknown state...");
176-
break;
177-
default:
178-
MBED_ASSERT(1);
179-
break;
180-
}
181-
182155
if (_event_status_cb) {
183156
_event_status_cb((nsapi_event_t)CellularSIMStatusChanged, state);
184157
}
@@ -188,8 +161,9 @@ bool CellularConnectionFSM::open_sim()
188161

189162
bool CellularConnectionFSM::set_network_registration(char *plmn)
190163
{
191-
if (_network->set_registration(plmn) != NSAPI_ERROR_OK) {
192-
tr_error("Failed to set network registration.");
164+
nsapi_error_t error = _network->set_registration(plmn);
165+
if (error != NSAPI_ERROR_OK) {
166+
tr_error("Set network registration mode failing (%d)", error);
193167
return false;
194168
}
195169
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/API/CellularSIM.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ class CellularSIM
4646
SimStateReady = 0,
4747
SimStatePinNeeded,
4848
SimStatePukNeeded,
49-
SimStateUnknown
49+
SimStateUnknown,
50+
SimStateNotChecked
5051
};
5152

5253
/** Open the SIM card by setting the pin code for SIM.

features/cellular/framework/AT/AT_CellularNetwork.cpp

Lines changed: 23 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);
@@ -97,6 +98,20 @@ void AT_CellularNetwork::read_reg_params_and_compare(RegistrationType type)
9798
int lac = -1, cell_id = -1, act = -1;
9899

99100
read_reg_params(type, reg_status, lac, cell_id, act);
101+
102+
switch (reg_status) {
103+
case NotRegistered:
104+
tr_error("not registered");
105+
break;
106+
case RegistrationDenied:
107+
tr_error("registration denied");
108+
break;
109+
case Unknown:
110+
tr_error("registration status unknown");
111+
break;
112+
default:
113+
break;
114+
}
100115

101116
if (_at.get_last_error() == NSAPI_ERROR_OK && _connection_status_cb) {
102117
tr_debug("stat: %d, lac: %d, cellID: %d, act: %d", reg_status, lac, cell_id, act);
@@ -216,7 +231,7 @@ nsapi_error_t AT_CellularNetwork::activate_context()
216231
nsapi_error_t err = set_context_to_be_activated();
217232
if (err != NSAPI_ERROR_OK) {
218233
_at.unlock();
219-
tr_error("Failed to activate network context!");
234+
tr_error("Failed to activate network context! (%d)", err);
220235

221236
_connect_status = NSAPI_STATUS_DISCONNECTED;
222237
if (_connection_status_cb) {
@@ -229,7 +244,8 @@ nsapi_error_t AT_CellularNetwork::activate_context()
229244
// do check for stack to validate that we have support for stack
230245
_stack = get_stack();
231246
if (!_stack) {
232-
return err;
247+
tr_error("No cellular stack!");
248+
return NSAPI_ERROR_UNSUPPORTED;
233249
}
234250

235251
_is_context_active = false;
@@ -246,7 +262,7 @@ nsapi_error_t AT_CellularNetwork::activate_context()
246262
_at.resp_stop();
247263

248264
if (!_is_context_active) {
249-
tr_info("Activate PDP context");
265+
tr_info("Activate PDP context %d",_cid);
250266
_at.cmd_start("AT+CGACT=1,");
251267
_at.write_int(_cid);
252268
_at.cmd_stop();
@@ -792,11 +808,11 @@ nsapi_error_t AT_CellularNetwork::get_apn_backoff_timer(int &backoff_timer)
792808

793809
NetworkStack *AT_CellularNetwork::get_stack()
794810
{
795-
// use lwIP/PPP if modem does not have IP stack
796811
#if NSAPI_PPP_AVAILABLE
797-
_stack = nsapi_ppp_get_stack();
798-
#else
799-
_stack = NULL;
812+
// use lwIP/PPP if modem does not have IP stack
813+
if (!_stack) {
814+
_stack = nsapi_ppp_get_stack();
815+
}
800816
#endif
801817
return _stack;
802818
}

features/cellular/framework/AT/AT_CellularSIM.cpp

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ using namespace mbed;
2222

2323
const int MAX_SIM_RESPONSE_LENGTH = 16;
2424

25-
AT_CellularSIM::AT_CellularSIM(ATHandler &at) : AT_CellularBase(at)
25+
AT_CellularSIM::AT_CellularSIM(ATHandler &at) : AT_CellularBase(at), _state(SimStateNotChecked)
2626
{
2727
}
2828

@@ -56,9 +56,39 @@ 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+
_state = state;
60+
nsapi_error_t error = _at.get_last_error();
61+
_at.unlock();
62+
trace_sim_errors();
63+
return error;
6064
}
6165

66+
67+
CellularSIM::SimState AT_CellularSIM::trace_sim_errors(void)
68+
{
69+
switch (_state) {
70+
case SimStatePinNeeded:
71+
tr_error("SIM PIN required");
72+
break;
73+
case SimStatePukNeeded:
74+
tr_error("SIM PUK required");
75+
break;
76+
case SimStateUnknown:
77+
tr_error("SIM state unknown");
78+
break;
79+
case SimStateNotChecked:
80+
tr_error("SIM status has not been checked");
81+
break;
82+
default:
83+
tr_info("SIM is ready");
84+
break;
85+
}
86+
87+
return _state;
88+
}
89+
90+
91+
6292
nsapi_error_t AT_CellularSIM::set_pin(const char *sim_pin)
6393
{
6494
// if SIM is already in ready state then settings the PIN

features/cellular/framework/AT/AT_CellularSIM.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class AT_CellularSIM : public CellularSIM, public AT_CellularBase
4545
virtual nsapi_error_t get_sim_state(SimState &state);
4646

4747
virtual nsapi_error_t get_imsi(char* imsi);
48+
49+
virtual SimState trace_sim_errors(void);
50+
51+
private:
52+
SimState _state;
4853
};
4954

5055
} // namespace mbed

0 commit comments

Comments
 (0)