Mistake on this page?
Report an issue in GitHub or email us
AT_CellularDevice.h
1 /*
2  * Copyright (c) 2017, Arm Limited and affiliates.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef AT_CELLULAR_DEVICE_H_
19 #define AT_CELLULAR_DEVICE_H_
20 
21 #include "CellularDevice.h"
22 #include "ATHandler.h"
23 
24 namespace mbed {
25 
26 class AT_CellularInformation;
27 class AT_CellularNetwork;
28 class AT_CellularSMS;
29 class AT_CellularContext;
30 class FileHandle;
31 
32 /**
33  * Class AT_CellularDevice
34  *
35  * A class defines opening and closing of cellular interfaces.
36  * Deleting/Closing of opened interfaces can be done only through this class.
37  */
39 public:
40  /* Supported features by the modem
41  *
42  * NOTE! These are used as index to feature table, so the only allowed modification to this is appending
43  * to the end (just before PROPERTY_MAX). Do not modify any of the existing fields.
44  */
45  enum CellularProperty {
46  PROPERTY_C_EREG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type.
47  PROPERTY_C_GREG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type.
48  PROPERTY_C_REG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type.
49  PROPERTY_AT_CGSN_WITH_TYPE, // 0 = not supported, 1 = supported. AT+CGSN without type is likely always supported similar to AT+GSN.
50  PROPERTY_AT_CGDATA, // 0 = not supported, 1 = supported. Alternative is to support only ATD*99***<cid>#
51  PROPERTY_AT_CGAUTH, // 0 = not supported, 1 = supported. APN authentication AT commands supported
52  PROPERTY_AT_CNMI, // 0 = not supported, 1 = supported. New message (SMS) indication AT command
53  PROPERTY_AT_CSMP, // 0 = not supported, 1 = supported. Set text mode AT command
54  PROPERTY_AT_CMGF, // 0 = not supported, 1 = supported. Set preferred message format AT command
55  PROPERTY_AT_CSDH, // 0 = not supported, 1 = supported. Show text mode AT command
56  PROPERTY_IPV4_PDP_TYPE, // 0 = not supported, 1 = supported. Does modem support IPV4?
57  PROPERTY_IPV6_PDP_TYPE, // 0 = not supported, 1 = supported. Does modem support IPV6?
58  PROPERTY_IPV4V6_PDP_TYPE, // 0 = not supported, 1 = supported. Does modem support IPV4 and IPV6 simultaneously?
59  PROPERTY_NON_IP_PDP_TYPE, // 0 = not supported, 1 = supported. Does modem support Non-IP?
60  PROPERTY_AT_CGEREP, // 0 = not supported, 1 = supported. Does modem support AT command AT+CGEREP.
61  PROPERTY_AT_COPS_FALLBACK_AUTO, // 0 = not supported, 1 = supported. Does modem support mode 4 of AT+COPS= ?
62  PROPERTY_SOCKET_COUNT, // The number of sockets of modem IP stack
63  PROPERTY_IP_TCP, // 0 = not supported, 1 = supported. Modem IP stack has support for TCP
64  PROPERTY_IP_UDP, // 0 = not supported, 1 = supported. Modem IP stack has support for TCP
65  PROPERTY_AT_SEND_DELAY, // Sending delay between AT commands in ms
66  PROPERTY_MAX
67  };
68 
69 public:
70  AT_CellularDevice(FileHandle *fh, char *delim = "\r");
71  virtual ~AT_CellularDevice();
72 
73  virtual nsapi_error_t clear();
74 
75  virtual nsapi_error_t hard_power_on();
76 
77  virtual nsapi_error_t hard_power_off();
78 
79  virtual nsapi_error_t soft_power_on();
80 
81  virtual nsapi_error_t soft_power_off();
82 
83  virtual nsapi_error_t set_pin(const char *sim_pin);
84 
85  virtual nsapi_error_t get_sim_state(SimState &state);
86 
87  virtual CellularContext *create_context(const char *apn = NULL, bool cp_req = false, bool nonip_req = false);
88 
89  virtual void delete_context(CellularContext *context);
90 
91  virtual CellularNetwork *open_network();
92 
94 
95  virtual void close_network();
96 
97  virtual void close_information();
98 
99  virtual void set_timeout(int timeout);
100 
101  virtual void modem_debug_on(bool on);
102 
103  virtual nsapi_error_t init();
104 
105  virtual nsapi_error_t shutdown();
106 
107  virtual nsapi_error_t is_ready();
108 
109  virtual void set_ready_cb(Callback<void()> callback);
110 
111  virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0);
112 
113  virtual ATHandler *get_at_handler();
114 
115  virtual CellularContext *get_context_list() const;
116 
117  virtual nsapi_error_t set_baud_rate(int baud_rate);
118 
119 #if MBED_CONF_CELLULAR_USE_SMS
120  virtual CellularSMS *open_sms();
121 
122  virtual void close_sms();
123 #endif
124 
125  /** Get value for the given key.
126  *
127  * @param key key for value to be fetched
128  * @return property value for the given key. Value type is defined in enum CellularProperty
129  */
130  intptr_t get_property(CellularProperty key);
131 
132  /** Cellular module need to define an array of cellular properties which defines module supported property values.
133  *
134  * @param property_array array of module properties
135  */
136  void set_cellular_properties(const intptr_t *property_array);
137 
138 protected:
139  /** Creates new instance of AT_CellularContext or if overridden, modem specific implementation.
140  *
141  * @param at ATHandler reference for communication with the modem.
142  * @param apn access point to use with context
143  * @param cp_req flag indicating if control plane EPS optimization needs to be setup
144  * @param nonip_req flag indicating if PDP context needs to be Non-IP
145  * @return new instance of class AT_CellularContext
146  *
147  */
148  virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
149 
150  /** Create new instance of AT_CellularNetwork or if overridden, modem specific implementation.
151  *
152  * @param at ATHandler reference for communication with the modem.
153  * @return new instance of class AT_CellularNetwork
154  */
156 
157  /** Create new instance of AT_CellularInformation or if overridden, modem specific implementation.
158  *
159  * @param at ATHandler reference for communication with the modem.
160  * @return new instance of class AT_CellularInformation
161  */
163 
164 #if MBED_CONF_CELLULAR_USE_SMS
165  /** Create new instance of AT_CellularSMS or if overridden, modem specific implementation.
166  *
167  * @param at ATHandler reference for communication with the modem.
168  * @return new instance of class AT_CellularSMS
169  */
170  virtual AT_CellularSMS *open_sms_impl(ATHandler &at);
171 #endif // MBED_CONF_CELLULAR_USE_SMS
172 
173  virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx = NULL);
174  void send_disconnect_to_context(int cid);
175  // Sets commonly used URCs
176  void set_at_urcs();
177  // To be used for setting target specific URCs
178  virtual void set_at_urcs_impl();
179  // Sets up parameters for AT handler, for now only the send delay and URCs.
180  // This kind of routine is needed for initialisation routines that are virtual and therefore cannot be called from constructor.
181  void setup_at_handler();
182  virtual nsapi_error_t set_baud_rate_impl(int baud_rate);
183 
184 private:
185  void urc_nw_deact();
186  void urc_pdn_deact();
187 
188 protected:
189  ATHandler _at;
190 
191 private:
192 #if MBED_CONF_CELLULAR_USE_SMS
193  AT_CellularSMS *_sms;
194 #endif // MBED_CONF_CELLULAR_USE_SMS
195 
196  AT_CellularNetwork *_network;
197  AT_CellularInformation *_information;
198  AT_CellularContext *_context_list;
199 
200  std::chrono::duration<int, std::milli> _default_timeout;
201  bool _modem_debug_on;
202  const intptr_t *_property_array;
203 };
204 
205 } // namespace mbed
206 #endif // AT_CELLULAR_DEVICE_H_
virtual nsapi_error_t get_sim_state(SimState &state)
Get SIM card&#39;s state.
virtual CellularNetwork * open_network()
Create new CellularNetwork interface.
virtual AT_CellularContext * create_context_impl(ATHandler &at, const char *apn, bool cp_req=false, bool nonip_req=false)
Creates new instance of AT_CellularContext or if overridden, modem specific implementation.
virtual void close_information()
Closes the opened CellularInformation by deleting the CellularInformation instance.
virtual void set_ready_cb(Callback< void()> callback)
Set callback function to listen when device is ready.
virtual CellularInformation * open_information()
Create new CellularInformation interface.
virtual nsapi_error_t set_baud_rate(int baud_rate)
Sets cellular modem to given baud rate.
virtual void close_sms()=0
Closes the opened CellularSMS by deleting the CellularSMS instance.
intptr_t get_property(CellularProperty key)
Get value for the given key.
CellularContext is CellularInterface/NetworkInterface with extensions for cellular connectivity...
Class CellularDevice.
virtual nsapi_error_t is_ready()
Check whether the device is ready to accept commands.
virtual nsapi_error_t set_pin(const char *sim_pin)
Open the SIM card by setting the pin code for SIM.
void set_cellular_properties(const intptr_t *property_array)
Cellular module need to define an array of cellular properties which defines module supported propert...
signed int nsapi_error_t
Type used to represent error codes.
Definition: nsapi_types.h:142
Class FileHandle.
Definition: FileHandle.h:46
virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx=NULL)
Cellular callback to be attached to Network and CellularStateMachine classes.
virtual nsapi_error_t soft_power_on()
Powers up the modem.
virtual ATHandler * get_at_handler()
Get the current ATHandler instance in use for debug purposes etc.
virtual nsapi_error_t soft_power_off()
Powers down the modem.
virtual CellularContext * get_context_list() const
Get the linked list of CellularContext instances.
Callback< R(ArgTs...)> callback(R(*func)(ArgTs...)=nullptr) noexcept
Create a callback class with type inferred from the arguments.
Definition: Callback.h:678
Class CellularDevice.
virtual nsapi_error_t shutdown()
Shutdown cellular device to minimum functionality.
virtual void close_network()
Closes the opened CellularNetwork by deleting the CellularNetwork instance.
virtual AT_CellularNetwork * open_network_impl(ATHandler &at)
Create new instance of AT_CellularNetwork or if overridden, modem specific implementation.
virtual AT_CellularInformation * open_information_impl(ATHandler &at)
Create new instance of AT_CellularInformation or if overridden, modem specific implementation.
An abstract interface for connecting to a network and getting information from it.
Class CellularInformation.
virtual nsapi_error_t init()
Initialize cellular device must be called right after the module is ready.
Class AT_CellularInformation.
virtual nsapi_error_t hard_power_on()
Sets the modem up for powering on This is equivalent to plugging in the device, i.e., attaching power and serial port.
virtual nsapi_error_t hard_power_off()
Sets the modem in unplugged state.
virtual CellularContext * create_context(const char *apn=NULL, bool cp_req=false, bool nonip_req=false)
Creates a new CellularContext interface.
virtual nsapi_error_t clear()
Clear modem to a default initial state.
virtual void delete_context(CellularContext *context)
Deletes the given CellularContext instance.
Class AT_CellularDevice.
virtual void set_timeout(int timeout)
Set the default response timeout.
virtual void modem_debug_on(bool on)
Turn modem debug traces on.
Class AT_CellularNetwork.
virtual CellularSMS * open_sms()=0
Create new CellularSMS interface.
virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time=0)
Set power save mode.
Callback class based on template specialization.
Definition: Callback.h:53
Definition: ATHandler.h:46
Class for sending AT commands and parsing AT responses.
Definition: ATHandler.h:68
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.