Mbed OS Reference
Loading...
Searching...
No Matches
CellularStateMachine Class Reference

CellularStateMachine class. More...

#include <CellularStateMachine.h>

Public Types

enum  CellularState
 Cellular connection states. More...
 

Public Member Functions

 CellularStateMachine (CellularDevice &device, events::EventQueue &queue, CellularNetwork &nw)
 Constructor. More...
 
void set_cellular_callback (mbed::Callback< void(nsapi_event_t, intptr_t)> status_cb)
 Register cellular specific for status changes. More...
 
nsapi_error_t start_dispatch ()
 Start event queue dispatching. More...
 
void stop ()
 Stop event queue dispatching and close cellular interfaces. More...
 
nsapi_error_t run_to_state (CellularState state)
 Runs state machine to connected state unless callback method set with set_state_callback return false to stop. More...
 
void set_sim_pin (const char *sim_pin)
 Set cellular device SIM PIN code. More...
 
void set_retry_timeout_array (const uint16_t timeout[], int array_len)
 Sets the timeout array for network rejects. More...
 
void set_plmn (const char *plmn)
 Sets the operator plmn which is used when registering to a network specified by plmn. More...
 
const char * get_state_string (CellularState state) const
 returns readable format of the given state. More...
 
bool get_current_status (CellularStateMachine::CellularState &current_state, CellularStateMachine::CellularState &target_state)
 Get the current status of the state machine. More...
 
void cellular_event_changed (nsapi_event_t ev, intptr_t ptr)
 CellularDevice updates about network events and cellular events. More...
 
void reset ()
 Reset the state machine to init state. More...
 
void get_retry_timeout_array (uint16_t *timeout, int &array_len) const
 Get retry timeout array. More...
 
void set_timeout (std::chrono::duration< int, std::milli > timeout)
 Change all cellular state timeouts. More...
 

Detailed Description

CellularStateMachine class.

Finite State Machine for attaching to cellular network. Used by CellularDevice.

Definition at line 33 of file CellularStateMachine.h.

Member Enumeration Documentation

◆ CellularState

Cellular connection states.

Definition at line 48 of file CellularStateMachine.h.

Constructor & Destructor Documentation

◆ CellularStateMachine()

Constructor.

Parameters
devicereference to CellularDevice
queuereference to queue used in state transitions
nwreference to CellularNetwork

Member Function Documentation

◆ set_cellular_callback()

void set_cellular_callback ( mbed::Callback< void(nsapi_event_t, intptr_t)>  status_cb)

Register cellular specific for status changes.

The specified status callback function will be called on device status changes. The parameters on the callback are the event type and event-type dependent reason parameter.

Parameters
status_cbThe callback for status changes

◆ start_dispatch()

nsapi_error_t start_dispatch ( )

Start event queue dispatching.

Returns
see nsapi_error_t, 0 on success

◆ stop()

void stop ( )

Stop event queue dispatching and close cellular interfaces.

◆ run_to_state()

nsapi_error_t run_to_state ( CellularState  state)

Runs state machine to connected state unless callback method set with set_state_callback return false to stop.

Returns
see nsapi_error_t, 0 on success

◆ set_sim_pin()

void set_sim_pin ( const char *  sim_pin)

Set cellular device SIM PIN code.

Parameters
sim_pinPIN code

◆ set_retry_timeout_array()

void set_retry_timeout_array ( const uint16_t  timeout[],
int  array_len 
)

Sets the timeout array for network rejects.

After reject next item is tried and after all items are waited and still fails then current network event will fail.

Parameters
timeouttimeout array using seconds
array_lenlength of the array

◆ set_plmn()

void set_plmn ( const char *  plmn)

Sets the operator plmn which is used when registering to a network specified by plmn.

If plmn is not set then automatic registering is used when registering to a cellular network. Does not start any operations.

Parameters
plmnoperator in numeric format. See more from 3GPP TS 27.007 chapter 7.3.

◆ get_state_string()

const char * get_state_string ( CellularState  state) const

returns readable format of the given state.

Used for printing states while debugging.

Parameters
statestate which is returned in string format
Returns
string format of the given state

◆ get_current_status()

bool get_current_status ( CellularStateMachine::CellularState current_state,
CellularStateMachine::CellularState target_state 
)

Get the current status of the state machine.

Thread safe.

Parameters
current_state
target_state
Returns
true if state machine is running, false is not

◆ cellular_event_changed()

void cellular_event_changed ( nsapi_event_t  ev,
intptr_t  ptr 
)

CellularDevice updates about network events and cellular events.

Parameters
evEvent type
ptrEvent type specific data

◆ reset()

void reset ( )

Reset the state machine to init state.

After reset state machine can be used again to run to wanted state.

◆ get_retry_timeout_array()

void get_retry_timeout_array ( uint16_t *  timeout,
int &  array_len 
) const

Get retry timeout array.

Parameters
timeoutPointer to timeout array
array_lenMax lenght of the array

◆ set_timeout()

void set_timeout ( std::chrono::duration< int, std::milli >  timeout)

Change all cellular state timeouts.

Parameters
timeoutTimeout value (milliseconds)