Skip to content

Commit e4c37f2

Browse files
author
Teppo Järvelin
committed
Cellular: plmn used when registering can be given for CellularConnectionFSM.
1 parent f73415e commit e4c37f2

File tree

5 files changed

+58
-15
lines changed

5 files changed

+58
-15
lines changed

features/cellular/easy_cellular/CellularConnectionFSM.cpp

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace mbed
4343
CellularConnectionFSM::CellularConnectionFSM() :
4444
_serial(0), _state(STATE_INIT), _next_state(_state), _status_callback(0), _event_status_cb(0), _network(0), _power(0), _sim(0),
4545
_queue(8 * EVENTS_EVENT_SIZE), _queue_thread(0), _cellularDevice(0), _retry_count(0), _event_timeout(-1),
46-
_at_queue(8 * EVENTS_EVENT_SIZE), _event_id(0)
46+
_at_queue(8 * EVENTS_EVENT_SIZE), _event_id(0), _plmn(0)
4747
{
4848
memset(_sim_pin, 0, sizeof(_sim_pin));
4949
#if MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY == 0
@@ -146,6 +146,11 @@ void CellularConnectionFSM::set_sim_pin(const char * sim_pin)
146146
_sim_pin[sizeof(_sim_pin)-1] = '\0';
147147
}
148148

149+
void CellularConnectionFSM::set_plmn(const char* plmn)
150+
{
151+
_plmn = plmn;
152+
}
153+
149154
bool CellularConnectionFSM::open_sim()
150155
{
151156
CellularSIM::SimState state = CellularSIM::SimStateUnknown;
@@ -175,11 +180,10 @@ bool CellularConnectionFSM::open_sim()
175180
return state == CellularSIM::SimStateReady;
176181
}
177182

178-
bool CellularConnectionFSM::set_network_registration(char *plmn)
183+
bool CellularConnectionFSM::set_network_registration()
179184
{
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);
185+
if (_network->set_registration(_plmn) != NSAPI_ERROR_OK) {
186+
tr_error("Failed to set network registration.");
183187
return false;
184188
}
185189
return true;
@@ -279,8 +283,12 @@ void CellularConnectionFSM::report_failure(const char* msg)
279283

280284
const char* CellularConnectionFSM::get_state_string(CellularState state)
281285
{
282-
static const char *strings[] = { "Init", "Power", "Device ready", "SIM pin", "Registering network", "Attaching network", "Activating PDP Context", "Connecting network", "Connected"};
286+
#if MBED_CONF_MBED_TRACE_ENABLE
287+
static const char *strings[] = { "Init", "Power", "Device ready", "SIM pin", "Registering network", "Attaching network", "Connecting network", "Connected"};
283288
return strings[state];
289+
#else
290+
return NULL;
291+
#endif // #if MBED_CONF_MBED_TRACE_ENABLE
284292
}
285293

286294
nsapi_error_t CellularConnectionFSM::is_automatic_registering(bool& auto_reg)
@@ -416,15 +424,26 @@ void CellularConnectionFSM::state_registering()
416424
{
417425
_cellularDevice->set_timeout(TIMEOUT_NETWORK);
418426
if (is_registered()) {
419-
// we are already registered, go to attach
420-
enter_to_state(STATE_ATTACHING_NETWORK);
421-
} else {
422-
bool auto_reg = false;
423-
nsapi_error_t err = is_automatic_registering(auto_reg);
424-
if (err == NSAPI_ERROR_OK && !auto_reg) { // when we support plmn add this : || plmn
425-
// automatic registering is not on, set registration and retry
427+
if (_plmn && _retry_count == 0) {
428+
// we don't know which network we are registered, try to register to specific network
426429
_cellularDevice->set_timeout(TIMEOUT_REGISTRATION);
427430
set_network_registration();
431+
retry_state_or_fail();
432+
} else {
433+
// we are already registered, go to attach
434+
enter_to_state(STATE_ATTACHING_NETWORK);
435+
}
436+
} else {
437+
if (_plmn) {
438+
set_network_registration();
439+
} else {
440+
bool auto_reg = false;
441+
nsapi_error_t err = is_automatic_registering(auto_reg);
442+
if (err == NSAPI_ERROR_OK && !auto_reg) {
443+
// automatic registering is not on, set registration and retry
444+
_cellularDevice->set_timeout(TIMEOUT_REGISTRATION);
445+
set_network_registration();
446+
}
428447
}
429448
retry_state_or_fail();
430449
}

features/cellular/easy_cellular/CellularConnectionFSM.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,24 @@ class CellularConnectionFSM
139139
*/
140140
void set_retry_timeout_array(uint16_t timeout[], int array_len);
141141

142+
/** Sets the operator plmn which is used when registering to a network specified by plmn. If plmn is not set then automatic
143+
* registering is used when registering to a cellular network.
144+
*
145+
* @param plmn operator in numeric format. See more from 3GPP TS 27.007 chapter 7.3.
146+
*/
147+
void set_plmn(const char* plmn);
148+
149+
/** returns readable format of the given state. Used for printing states while debugging.
150+
*
151+
* @param state state which is returned in string format
152+
* @return string format of the given state
153+
*/
142154
const char* get_state_string(CellularState state);
143155
private:
144156
bool power_on();
145157
bool open_sim();
146158
bool get_network_registration(CellularNetwork::RegistrationType type, CellularNetwork::RegistrationStatus &status, bool &is_registered);
147-
bool set_network_registration(char *plmn = 0);
159+
bool set_network_registration();
148160
bool get_attach_network(CellularNetwork::AttachStatus &status);
149161
bool set_attach_network();
150162
bool is_registered();
@@ -198,6 +210,7 @@ class CellularConnectionFSM
198210
events::EventQueue _at_queue;
199211
char _st_string[20];
200212
int _event_id;
213+
const char* _plmn;
201214
};
202215

203216
} // namespace

features/cellular/easy_cellular/EasyCellularConnection.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ void EasyCellularConnection::modem_debug_on(bool on)
280280
}
281281
}
282282

283+
void EasyCellularConnection::set_plmn(const char* plmn)
284+
{
285+
_cellularConnectionFSM.set_plmn(plmn);
286+
}
287+
283288
NetworkStack *EasyCellularConnection::get_stack()
284289
{
285290
return _cellularConnectionFSM.get_stack();

features/cellular/easy_cellular/EasyCellularConnection.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ class EasyCellularConnection: public CellularBase
131131
*/
132132
void modem_debug_on(bool on);
133133

134+
/** Sets the operator plmn which is used when registering to a network specified by plmn. If plmn is not set then automatic
135+
* registering is used when registering to a cellular network.
136+
*
137+
* @param plmn operator in numeric format. See more from 3GPP TS 27.007 chapter 7.3.
138+
*/
139+
void set_plmn(const char* plmn);
134140
protected:
135141

136142
/** Provide access to the NetworkStack object

features/cellular/framework/AT/AT_CellularNetwork.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ nsapi_error_t AT_CellularNetwork::set_registration(const char *plmn)
656656
tr_debug("Automatic network registration");
657657
_at.cmd_start("AT+COPS?");
658658
_at.cmd_stop();
659-
_at.resp_start("AT+COPS:");
659+
_at.resp_start("+COPS:");
660660
int mode = _at.read_int();
661661
_at.resp_stop();
662662
if (mode != 0) {

0 commit comments

Comments
 (0)