Class CellularDevice. More...
#include <CellularDevice.h>
Public Member Functions | |
CellularDevice (FileHandle *fh) | |
Default constructor. More... | |
virtual | ~CellularDevice () |
virtual Destructor More... | |
virtual nsapi_error_t | clear () |
Clear modem to a default initial state. More... | |
virtual nsapi_error_t | hard_power_on ()=0 |
Sets the modem up for powering on This is equivalent to plugging in the device, i.e., attaching power and serial port. More... | |
virtual nsapi_error_t | hard_power_off ()=0 |
Sets the modem in unplugged state. More... | |
virtual nsapi_error_t | soft_power_on ()=0 |
Powers up the modem. More... | |
virtual nsapi_error_t | soft_power_off ()=0 |
Powers down the modem. More... | |
virtual nsapi_error_t | set_pin (const char *sim_pin)=0 |
Open the SIM card by setting the pin code for SIM. More... | |
virtual nsapi_error_t | get_sim_state (SimState &state)=0 |
Get SIM card's state. More... | |
virtual CellularContext * | create_context (FileHandle *fh=NULL, const char *apn=NULL, bool cp_req=false, bool nonip_req=false)=0 |
Creates a new CellularContext interface. More... | |
virtual CellularContext * | create_context (UARTSerial *serial, const char *apn, PinName dcd_pin=NC, bool active_high=false, bool cp_req=false, bool nonip_req=false)=0 |
Creates a new CellularContext interface. More... | |
virtual void | delete_context (CellularContext *context)=0 |
Deletes the given CellularContext instance. More... | |
void | stop () |
Stop the current operation. More... | |
FileHandle & | get_file_handle () const |
Get the current FileHandle item used when communicating with the modem. More... | |
virtual events::EventQueue * | get_queue () |
Get event queue that can be chained to main event queue. More... | |
void | set_sim_pin (const char *sim_pin) |
Set the pin code for SIM card. More... | |
void | set_plmn (const char *plmn) |
Plmn to use when registering to cellular network. More... | |
nsapi_error_t | set_device_ready () |
Start the interface. More... | |
nsapi_error_t | set_sim_ready () |
Start the interface. More... | |
nsapi_error_t | register_to_network () |
Start the interface. More... | |
nsapi_error_t | attach_to_network () |
Start the interface. More... | |
void | attach (Callback< void(nsapi_event_t, intptr_t)> status_cb) |
Register callback for status reporting. More... | |
virtual CellularNetwork * | open_network (FileHandle *fh=NULL)=0 |
Create new CellularNetwork interface. More... | |
virtual CellularSMS * | open_sms (FileHandle *fh=NULL)=0 |
Create new CellularSMS interface. More... | |
virtual void | close_sms ()=0 |
Closes the opened CellularSMS by deleting the CellularSMS instance. More... | |
virtual CellularInformation * | open_information (FileHandle *fh=NULL)=0 |
Create new CellularInformation interface. More... | |
virtual void | close_network ()=0 |
Closes the opened CellularNetwork by deleting the CellularNetwork instance. More... | |
virtual void | close_information ()=0 |
Closes the opened CellularInformation by deleting the CellularInformation instance. More... | |
virtual void | set_timeout (int timeout)=0 |
Set the default response timeout. More... | |
void | set_retry_timeout_array (const uint16_t timeout[], int array_len) |
Set an array of timeouts to wait before CellularStateMachine retries after failure. More... | |
virtual void | modem_debug_on (bool on)=0 |
Turn modem debug traces on. More... | |
virtual nsapi_error_t | init ()=0 |
Initialize cellular device must be called right after the module is ready. More... | |
virtual nsapi_error_t | shutdown () |
Shutdown cellular device to minimum functionality. More... | |
virtual nsapi_error_t | is_ready ()=0 |
Check whether the device is ready to accept commands. More... | |
virtual void | set_ready_cb (Callback< void()> callback)=0 |
Set callback function to listen when device is ready. More... | |
virtual nsapi_error_t | set_power_save_mode (int periodic_time, int active_time=0)=0 |
Set power save mode. More... | |
virtual CellularContext * | get_context_list () const |
Get the linked list of CellularContext instances. More... | |
virtual ATHandler * | get_at_handler ()=0 |
Get the current ATHandler instance in use for debug purposes etc. More... | |
virtual nsapi_error_t | release_at_handler (ATHandler *at_handler)=0 |
Release the ATHandler taken into use with get_at_handler() More... | |
virtual nsapi_error_t | set_baud_rate (int baud_rate)=0 |
Sets cellular modem to given baud rate. More... | |
Static Public Member Functions | |
static CellularDevice * | get_default_instance () |
Returns singleton instance of CellularDevice, if Mbed target board has a supported onboard modem, or provide-default is defined for a cellular driver in JSON configuration files. More... | |
static CellularDevice * | get_target_default_instance () |
Return target onboard instance of CellularDevice. More... | |
Protected Member Functions | |
void | get_retry_timeout_array (uint16_t *timeout, int &array_len) const |
Get the retry array from the CellularStateMachine. More... | |
virtual void | cellular_callback (nsapi_event_t ev, intptr_t ptr, CellularContext *ctx=NULL) |
Cellular callback to be attached to Network and CellularStateMachine classes. More... | |
Class CellularDevice.
An abstract interface that defines opening and closing of cellular interfaces. You can delete or close opened interfaces only through this class.
Definition at line 55 of file CellularDevice.h.
CellularDevice | ( | FileHandle * | fh | ) |
Default constructor.
fh | File handle used in communication with the modem. |
|
virtual |
virtual Destructor
void attach | ( | Callback< void(nsapi_event_t, intptr_t)> | status_cb | ) |
Register callback for status reporting.
The specified status callback function will be called on the network and cellular device status changes. The parameters on the callback are the event type and event-type dependent reason parameter.
status_cb | The callback for status changes. |
nsapi_error_t attach_to_network | ( | ) |
Start the interface.
Attempts to attach the device to cellular network. API is asynchronous. Application can get results from CellularContext callback, which is set with attach(...), or callback, which is set by attach(...), in this class.
|
protectedvirtual |
Cellular callback to be attached to Network and CellularStateMachine classes.
CellularContext calls this when in PPP mode to provide network changes. This method will broadcast to every interested classes: CellularContext (might be many) and CellularStateMachine if available.
Reimplemented in AT_CellularDevice.
|
virtual |
Clear modem to a default initial state.
Clear persistent user data from the modem, such as PDP contexts.
cellular.clear-on-connect: true
.Reimplemented in AT_CellularDevice.
|
pure virtual |
Closes the opened CellularInformation by deleting the CellularInformation instance.
Implemented in AT_CellularDevice.
|
pure virtual |
Closes the opened CellularNetwork by deleting the CellularNetwork instance.
Implemented in AT_CellularDevice.
|
pure virtual |
Closes the opened CellularSMS by deleting the CellularSMS instance.
|
pure virtual |
Creates a new CellularContext interface.
fh | file handle used in communication to modem. This can be, for example, UART handle. If null, then the default file handle is used. |
apn | access point to use with context, can be null. |
cp_req | flag indicating if EPS control plane optimization is required |
nonip_req | flag indicating if this context is required to be Non-IP |
Implemented in AT_CellularDevice.
|
pure virtual |
Creates a new CellularContext interface.
This API should be used if serial is UART and PPP mode used. CellularContext created will use data carrier detect to be able to detect disconnection much faster in PPP mode. UARTSerial usually is the same which was given for the CellularDevice.
serial | UARTSerial used in communication to modem. If null then the default file handle is used. |
apn | access point to use with context, can be null. |
dcd_pin | Pin used to set data carrier detect on/off for the given UART |
active_high | a boolean set to true if DCD polarity is active low |
cp_req | Flag indicating if EPS control plane optimization is required |
nonip_req | Flag indicating if this context is required to be Non-IP |
Implemented in AT_CellularDevice.
|
pure virtual |
Deletes the given CellularContext instance.
context | CellularContext to delete |
Implemented in AT_CellularDevice.
|
pure virtual |
Get the current ATHandler instance in use for debug purposes etc.
Once use has been finished call to release_at_handler() has to be made
Implemented in AT_CellularDevice.
|
virtual |
Get the linked list of CellularContext instances.
Reimplemented in AT_CellularDevice.
|
static |
Returns singleton instance of CellularDevice, if Mbed target board has a supported onboard modem, or provide-default is defined for a cellular driver in JSON configuration files.
Otherwise returns NULL. See NetworkInterface::get_default_instance for details.
FileHandle& get_file_handle | ( | ) | const |
Get the current FileHandle item used when communicating with the modem.
|
virtual |
Get event queue that can be chained to main event queue.
|
protected |
Get the retry array from the CellularStateMachine.
Array is used in retry logic. Array contains seconds and retry logic uses those second to wait before trying again.
timeout | timeout array containing seconds for retry logic. Must have space for CELLULAR_RETRY_ARRAY_SIZE (defined in CellularCommon.h) |
array_len | length of the timeout array on return |
|
pure virtual |
Get SIM card's state.
state | current state of SIM |
Implemented in AT_CellularDevice.
|
static |
Return target onboard instance of CellularDevice.
|
pure virtual |
Sets the modem in unplugged state.
This is equivalent to pulling the plug off of the device, i.e., detaching power and serial port.
This puts the modem in the lowest power state.
Implemented in AT_CellularDevice.
|
pure virtual |
Sets the modem up for powering on This is equivalent to plugging in the device, i.e., attaching power and serial port.
In general, hard_power_on and soft_power_on provides a simple hardware abstraction layer on top of the modem drivers written for Mbed OS; they can be overridden in a derived class to perform custom power controls in a particular board configuration. In many boards this will be a no-op if there is no separate power supply control circuitry.
Implemented in AT_CellularDevice.
|
pure virtual |
Initialize cellular device must be called right after the module is ready.
For example, when multiple cellular modules are supported in a single driver this function detects and adapts to an actual module at runtime.
Implemented in AT_CellularDevice.
|
pure virtual |
Check whether the device is ready to accept commands.
Implemented in AT_CellularDevice.
|
pure virtual |
Turn modem debug traces on.
on | set true to enable debug traces |
Implemented in AT_CellularDevice.
|
pure virtual |
Create new CellularInformation interface.
fh | file handle used in communication to modem. This can be, for example, UART handle. If null, then the default file handle is used. |
Implemented in AT_CellularDevice.
|
pure virtual |
Create new CellularNetwork interface.
fh | file handle used in communication to modem. This can be, for example, UART handle. If null, then the default file handle is used. |
Implemented in AT_CellularDevice.
|
pure virtual |
Create new CellularSMS interface.
fh | file handle used in communication to modem. This can be, for example, UART handle. If null, then the default file handle is used. |
nsapi_error_t register_to_network | ( | ) |
Start the interface.
Attempts to register the device to cellular network. API is asynchronous. Application can get results from CellularContext callback, which is set with attach(...), or callback, which is set by attach(...), in this class.
|
pure virtual |
Release the ATHandler taken into use with get_at_handler()
at_handler |
Implemented in AT_CellularDevice.
|
pure virtual |
Sets cellular modem to given baud rate.
baud_rate |
Implemented in AT_CellularDevice.
nsapi_error_t set_device_ready | ( | ) |
Start the interface.
Initializes the modem for communication. API is asynchronous. Application can get results from CellularContext callback, which is set with attach(...), or callback, which is set by attach(...), in this class.
|
pure virtual |
Open the SIM card by setting the pin code for SIM.
sim_pin | PIN for the SIM card |
Implemented in AT_CellularDevice.
void set_plmn | ( | const char * | plmn | ) |
Plmn to use when registering to cellular network.
If plmn is set, then registering is forced to this plmn. If plmn is not set, then automatic registering is used when registering to a cellular network. It doesn't start any operations.
plmn | plmn used when registering to cellular network |
|
pure virtual |
Set power save mode.
periodic_time | in seconds to enable power save, or zero to disable |
active_time | in seconds to wait before entering power save mode |
Implemented in AT_CellularDevice.
|
pure virtual |
Set callback function to listen when device is ready.
callback | function to call on device ready, or NULL to remove callback. |
Implemented in AT_CellularDevice.
void set_retry_timeout_array | ( | const uint16_t | timeout[], |
int | array_len | ||
) |
Set an array of timeouts to wait before CellularStateMachine retries after failure.
To disable retry behavior completely use set_retry_timeout_array(NULL, 0)
. CellularContext callback event cell_callback_data_t.final_try
indicates true when all retries have failed.
set_retry_timeout_array
for CellularStateMachine to wait before it retries again after failure, this is useful to send repetitive requests when don't know exactly when modem is ready to accept requests. Use set_timeout
for timeout how long to wait for a response from modem for each request, this is useful if modem can accept requests but processing takes long time before sending response.timeout | timeout array using seconds |
array_len | length of the array |
void set_sim_pin | ( | const char * | sim_pin | ) |
Set the pin code for SIM card.
sim_pin | PIN for the SIM card |
nsapi_error_t set_sim_ready | ( | ) |
Start the interface.
Attempts to open the sim. API is asynchronous. Application can get results from CellularContext callback, which is set with attach(...), or callback, which is set by attach(...), in this class.
|
pure virtual |
Set the default response timeout.
timeout
.timeout | milliseconds to wait response from modem |
Implemented in AT_CellularDevice.
|
virtual |
Shutdown cellular device to minimum functionality.
Actual functionality is modem specific, for example UART may is not be responsive without explicit wakeup signal (such as RTS) after shutdown.
Reimplemented in AT_CellularDevice.
|
pure virtual |
Powers down the modem.
This is equivalent to turning off the modem by button press.
Implemented in AT_CellularDevice.
|
pure virtual |
Powers up the modem.
This is equivalent to pressing the "power button" to activate or reset the modem and usually implemented as a short pulse on a dedicated GPIO signal. It is expected to be present to make it possible to reset the modem. The driver may repeat this if the modem is not responsive to AT commands.
Implemented in AT_CellularDevice.
void stop | ( | ) |
Stop the current operation.
Operations: set_device_ready, set_sim_ready, register_to_network, attach_to_network