Skip to content

Commit 678cff4

Browse files
author
Teppo Järvelin
committed
Cellular: review changes.
1 parent 8fa8abc commit 678cff4

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

features/cellular/easy_cellular/CellularConnectionFSM.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ bool CellularConnectionFSM::power_on()
144144
return true;
145145
}
146146

147-
void CellularConnectionFSM::set_sim_pin(const char * sim_pin)
147+
void CellularConnectionFSM::set_sim_pin(const char *sim_pin)
148148
{
149149
strncpy(_sim_pin, sim_pin, sizeof(_sim_pin));
150150
_sim_pin[sizeof(_sim_pin)-1] = '\0';
151151
}
152152

153-
void CellularConnectionFSM::set_plmn(const char* plmn)
153+
void CellularConnectionFSM::set_plmn(const char *plmn)
154154
{
155155
_plmn = plmn;
156156
}
@@ -250,15 +250,15 @@ bool CellularConnectionFSM::get_network_registration(CellularNetwork::Registrati
250250
return true;
251251
}
252252

253-
void CellularConnectionFSM::report_failure(const char* msg)
253+
void CellularConnectionFSM::report_failure(const char *msg)
254254
{
255255
tr_error("Cellular network failed: %s", msg);
256256
if (_status_callback) {
257257
_status_callback(_state, _next_state);
258258
}
259259
}
260260

261-
const char* CellularConnectionFSM::get_state_string(CellularState state)
261+
const char *CellularConnectionFSM::get_state_string(CellularState state)
262262
{
263263
#if MBED_CONF_MBED_TRACE_ENABLE
264264
static const char *strings[] = { "Init", "Power", "Device ready", "SIM pin", "Registering network", "Manual registering", "Attaching network", "Activating PDP Context", "Connecting network", "Connected"};
@@ -287,7 +287,7 @@ bool CellularConnectionFSM::is_registered_to_plmn()
287287
CellularNetwork::operator_names_list names_list;
288288
nsapi_error_t err = _network->get_operator_names(names_list);
289289
if (err == NSAPI_ERROR_OK) {
290-
CellularNetwork::operator_names_t* op_names = names_list.get_head();
290+
CellularNetwork::operator_names_t *op_names = names_list.get_head();
291291
bool found_match = false;
292292
while (op_names) {
293293
if (format == 0) {
@@ -667,17 +667,17 @@ events::EventQueue *CellularConnectionFSM::get_queue()
667667
return &_queue;
668668
}
669669

670-
CellularNetwork* CellularConnectionFSM::get_network()
670+
CellularNetwork *CellularConnectionFSM::get_network()
671671
{
672672
return _network;
673673
}
674674

675-
CellularDevice* CellularConnectionFSM::get_device()
675+
CellularDevice *CellularConnectionFSM::get_device()
676676
{
677677
return _cellularDevice;
678678
}
679679

680-
CellularSIM* CellularConnectionFSM::get_sim()
680+
CellularSIM *CellularConnectionFSM::get_sim()
681681
{
682682
return _sim;
683683
}

features/cellular/easy_cellular/CellularConnectionFSM.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class CellularConnectionFSM
9595
/** Get event queue that can be chained to main event queue (or use start_dispatch)
9696
* @return event queue
9797
*/
98-
events::EventQueue* get_queue();
98+
events::EventQueue *get_queue();
9999

100100
/** Start event queue dispatching
101101
* @return see nsapi_error_t, 0 on success
@@ -110,17 +110,17 @@ class CellularConnectionFSM
110110
/** Get cellular network interface
111111
* @return network interface, NULL on failure
112112
*/
113-
CellularNetwork* get_network();
113+
CellularNetwork *get_network();
114114

115115
/** Get cellular device interface
116116
* @return device interface, NULL on failure
117117
*/
118-
CellularDevice* get_device();
118+
CellularDevice *get_device();
119119

120120
/** Get cellular sim interface
121121
* @return sim interface, NULL on failure
122122
*/
123-
CellularSIM* get_sim();
123+
CellularSIM *get_sim();
124124

125125
/** Change cellular connection to the target state
126126
* @param state to continue. Default is to connect.
@@ -153,7 +153,7 @@ class CellularConnectionFSM
153153
* @param state state which is returned in string format
154154
* @return string format of the given state
155155
*/
156-
const char* get_state_string(CellularState state);
156+
const char *get_state_string(CellularState state);
157157

158158
private:
159159
bool power_on();
@@ -211,7 +211,7 @@ class CellularConnectionFSM
211211
events::EventQueue _at_queue;
212212
char _st_string[20];
213213
int _event_id;
214-
const char* _plmn;
214+
const char *_plmn;
215215
bool _command_success;
216216
bool _plmn_network_found;
217217
};

features/cellular/easy_cellular/EasyCellularConnection.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void EasyCellularConnection::set_credentials(const char *apn, const char *uname,
114114
if (_credentials_err) {
115115
return;
116116
}
117-
CellularNetwork * network = _cellularConnectionFSM->get_network();
117+
CellularNetwork *network = _cellularConnectionFSM->get_network();
118118
if (network) {
119119
_credentials_err = network->set_credentials(apn, uname, pwd);
120120
#if USE_APN_LOOKUP
@@ -192,12 +192,12 @@ nsapi_error_t EasyCellularConnection::connect()
192192
_target_state = CellularConnectionFSM::STATE_SIM_PIN;
193193
err = _cellularConnectionFSM->continue_to_state(_target_state);
194194
if (err == NSAPI_ERROR_OK) {
195-
int sim_wait = _cellularSemaphore.wait(60*1000); // reserve 60 seconds to access to SIM
195+
int sim_wait = _cellularSemaphore.wait(60 * 1000); // reserve 60 seconds to access to SIM
196196
if (sim_wait != 1) {
197197
tr_error("NO SIM ACCESS");
198198
err = NSAPI_ERROR_NO_CONNECTION;
199199
} else {
200-
char imsi[MAX_IMSI_LENGTH+1];
200+
char imsi[MAX_IMSI_LENGTH + 1];
201201
wait(1); // need to wait to access SIM in some modems
202202
err = _cellularConnectionFSM->get_sim()->get_imsi(imsi);
203203
if (err == NSAPI_ERROR_OK) {
@@ -313,9 +313,16 @@ void EasyCellularConnection::modem_debug_on(bool on)
313313
}
314314
}
315315

316-
void EasyCellularConnection::set_plmn(const char* plmn)
316+
void EasyCellularConnection::set_plmn(const char *plmn)
317317
{
318-
if (_cellularConnectionFSM) {
318+
if (plmn && strlen(plmn) > 0) {
319+
if (!_cellularConnectionFSM) {
320+
_credentials_err = init();
321+
322+
if (_credentials_err) {
323+
return;
324+
}
325+
}
319326
_cellularConnectionFSM->set_plmn(plmn);
320327
}
321328
}

0 commit comments

Comments
 (0)