Mbed OS Reference
Loading...
Searching...
No Matches
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
24namespace mbed {
25
26/**
27 * @addtogroup at-hayes AT/Hayes Command Set
28 * @ingroup Cellular
29 * @{
30 */
31
32class AT_CellularInformation;
33class AT_CellularNetwork;
34class AT_CellularSMS;
35class AT_CellularContext;
36class FileHandle;
37
38/**
39 * Class AT_CellularDevice
40 *
41 * A class defines opening and closing of cellular interfaces.
42 * Deleting/Closing of opened interfaces can be done only through this class.
43 */
45public:
46 /* Supported features by the modem
47 *
48 * NOTE! These are used as index to feature table, so the only allowed modification to this is appending
49 * to the end (just before PROPERTY_MAX). Do not modify any of the existing fields.
50 */
51 enum CellularProperty {
52 PROPERTY_C_EREG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type.
53 PROPERTY_C_GREG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type.
54 PROPERTY_C_REG, // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type.
55 PROPERTY_AT_CGSN_WITH_TYPE, // 0 = not supported, 1 = supported. AT+CGSN without type is likely always supported similar to AT+GSN.
56 PROPERTY_AT_CGDATA, // 0 = not supported, 1 = supported. Alternative is to support only ATD*99***<cid>#
57 PROPERTY_AT_CGAUTH, // 0 = not supported, 1 = supported. APN authentication AT commands supported
58 PROPERTY_AT_CNMI, // 0 = not supported, 1 = supported. New message (SMS) indication AT command
59 PROPERTY_AT_CSMP, // 0 = not supported, 1 = supported. Set text mode AT command
60 PROPERTY_AT_CMGF, // 0 = not supported, 1 = supported. Set preferred message format AT command
61 PROPERTY_AT_CSDH, // 0 = not supported, 1 = supported. Show text mode AT command
62 PROPERTY_IPV4_PDP_TYPE, // 0 = not supported, 1 = supported. Does modem support IPV4?
63 PROPERTY_IPV6_PDP_TYPE, // 0 = not supported, 1 = supported. Does modem support IPV6?
64 PROPERTY_IPV4V6_PDP_TYPE, // 0 = not supported, 1 = supported. Does modem support IPV4 and IPV6 simultaneously?
65 PROPERTY_NON_IP_PDP_TYPE, // 0 = not supported, 1 = supported. Does modem support Non-IP?
66 PROPERTY_AT_CGEREP, // 0 = not supported, 1 = supported. Does modem support AT command AT+CGEREP.
67 PROPERTY_AT_COPS_FALLBACK_AUTO, // 0 = not supported, 1 = supported. Does modem support mode 4 of AT+COPS= ?
68 PROPERTY_SOCKET_COUNT, // The number of sockets of modem IP stack
69 PROPERTY_IP_TCP, // 0 = not supported, 1 = supported. Modem IP stack has support for TCP
70 PROPERTY_IP_UDP, // 0 = not supported, 1 = supported. Modem IP stack has support for TCP
71 PROPERTY_AT_SEND_DELAY, // Sending delay between AT commands in ms
72 PROPERTY_MAX
73 };
74
75public:
76
77 /**
78 * Create an AT_CellularDevice.
79 *
80 * @param fh file handle used for reading AT responses and writing AT commands
81 * @param delim delimiter used when parsing at responses, "\r" should be used as output_delimiter
82 */
83 AT_CellularDevice(FileHandle *fh, char const *delim = "\r");
84
85 virtual ~AT_CellularDevice();
86
88
90
92
94
96
97 virtual nsapi_error_t set_pin(const char *sim_pin);
98
99 virtual nsapi_error_t get_sim_state(SimState &state);
100
101 virtual CellularContext *create_context(const char *apn = NULL, bool cp_req = false, bool nonip_req = false);
102
103 virtual void delete_context(CellularContext *context);
104
106
108
109 virtual void close_network();
110
111 virtual void close_information();
112
113 virtual void set_timeout(int timeout);
114
115 virtual void modem_debug_on(bool on);
116
118
120
122
123 virtual void set_ready_cb(Callback<void()> callback);
124
125 virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0);
126
128
130
131 virtual nsapi_error_t set_baud_rate(int baud_rate);
132
133#if MBED_CONF_CELLULAR_USE_SMS
134 virtual CellularSMS *open_sms();
135
136 virtual void close_sms();
137#endif
138
139 /** Get value for the given key.
140 *
141 * @param key key for value to be fetched
142 * @return property value for the given key. Value type is defined in enum CellularProperty
143 */
144 intptr_t get_property(CellularProperty key);
145
146 /** Cellular module need to define an array of cellular properties which defines module supported property values.
147 *
148 * @param property_array array of module properties
149 */
150 void set_cellular_properties(const intptr_t *property_array);
151
152protected:
153 /** Creates new instance of AT_CellularContext or if overridden, modem specific implementation.
154 *
155 * @param at ATHandler reference for communication with the modem.
156 * @param apn access point to use with context
157 * @param cp_req flag indicating if control plane EPS optimization needs to be setup
158 * @param nonip_req flag indicating if PDP context needs to be Non-IP
159 * @return new instance of class AT_CellularContext
160 *
161 */
162 virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
163
164 /** Create new instance of AT_CellularNetwork or if overridden, modem specific implementation.
165 *
166 * @param at ATHandler reference for communication with the modem.
167 * @return new instance of class AT_CellularNetwork
168 */
170
171 /** Create new instance of AT_CellularInformation or if overridden, modem specific implementation.
172 *
173 * @param at ATHandler reference for communication with the modem.
174 * @return new instance of class AT_CellularInformation
175 */
177
178#if MBED_CONF_CELLULAR_USE_SMS
179 /** Create new instance of AT_CellularSMS or if overridden, modem specific implementation.
180 *
181 * @param at ATHandler reference for communication with the modem.
182 * @return new instance of class AT_CellularSMS
183 */
184 virtual AT_CellularSMS *open_sms_impl(ATHandler &at);
185#endif // MBED_CONF_CELLULAR_USE_SMS
186
187 virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx = NULL);
188 void send_disconnect_to_context(int cid);
189 // Sets commonly used URCs
190 void set_at_urcs();
191 // To be used for setting target specific URCs
192 virtual void set_at_urcs_impl();
193 // Sets up parameters for AT handler, for now only the send delay and URCs.
194 // This kind of routine is needed for initialisation routines that are virtual and therefore cannot be called from constructor.
195 void setup_at_handler();
196 virtual nsapi_error_t set_baud_rate_impl(int baud_rate);
197
198private:
199 void urc_nw_deact();
200 void urc_pdn_deact();
201
202protected:
203 ATHandler _at;
204
205private:
206#if MBED_CONF_CELLULAR_USE_SMS
207 AT_CellularSMS *_sms;
208#endif // MBED_CONF_CELLULAR_USE_SMS
209
210 AT_CellularNetwork *_network;
211 AT_CellularInformation *_information;
212 AT_CellularContext *_context_list;
213
214 std::chrono::duration<int, std::milli> _default_timeout;
215 bool _modem_debug_on;
216 const intptr_t *_property_array;
217};
218
219/**
220 * @}
221 */
222
223} // namespace mbed
224#endif // AT_CELLULAR_DEVICE_H_
Class CellularDevice.
Class AT_CellularDevice.
virtual void close_network()
Closes the opened CellularNetwork by deleting the CellularNetwork instance.
virtual nsapi_error_t is_ready()
Check whether the device is ready to accept commands.
virtual void set_ready_cb(Callback< void()> callback)
Set callback function to listen when device is ready.
virtual void delete_context(CellularContext *context)
Deletes the given CellularContext instance.
virtual void close_information()
Closes the opened CellularInformation by deleting the CellularInformation instance.
virtual nsapi_error_t clear()
Clear modem to a default initial state.
virtual nsapi_error_t shutdown()
Shutdown cellular device to minimum functionality.
void set_cellular_properties(const intptr_t *property_array)
Cellular module need to define an array of cellular properties which defines module supported propert...
virtual nsapi_error_t hard_power_off()
Sets the modem in unplugged state.
virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time=0)
Set power save mode.
intptr_t get_property(CellularProperty key)
Get value for the given key.
virtual void modem_debug_on(bool on)
Turn modem debug traces on.
virtual nsapi_error_t soft_power_on()
Powers up the modem.
virtual CellularContext * create_context(const char *apn=NULL, bool cp_req=false, bool nonip_req=false)
Creates a new CellularContext interface.
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 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 nsapi_error_t set_pin(const char *sim_pin)
Open the SIM card by setting the pin code for SIM.
virtual CellularInformation * open_information()
Create new CellularInformation interface.
virtual AT_CellularInformation * open_information_impl(ATHandler &at)
Create new instance of AT_CellularInformation or if overridden, modem specific implementation.
virtual AT_CellularNetwork * open_network_impl(ATHandler &at)
Create new instance of AT_CellularNetwork or if overridden, modem specific implementation.
virtual void set_timeout(int timeout)
Set the default response timeout.
virtual nsapi_error_t init()
Initialize cellular device must be called right after the module is ready.
AT_CellularDevice(FileHandle *fh, char const *delim="\r")
Create an AT_CellularDevice.
virtual ATHandler * get_at_handler()
Get the current ATHandler instance in use for debug purposes etc.
virtual CellularNetwork * open_network()
Create new CellularNetwork interface.
virtual nsapi_error_t hard_power_on()
Sets the modem up for powering on This is equivalent to plugging in the device, i....
virtual nsapi_error_t soft_power_off()
Powers down the modem.
virtual CellularContext * get_context_list() const
Get the linked list of CellularContext instances.
virtual nsapi_error_t set_baud_rate(int baud_rate)
Sets cellular modem to given baud rate.
virtual nsapi_error_t get_sim_state(SimState &state)
Get SIM card's state.
Class AT_CellularInformation.
Class AT_CellularNetwork.
Class for sending AT commands and parsing AT responses.
Definition: ATHandler.h:68
Callback class based on template specialization.
Definition: Callback.h:53
CellularContext is CellularInterface/NetworkInterface with extensions for cellular connectivity.
Class CellularDevice.
virtual void close_sms()=0
Closes the opened CellularSMS by deleting the CellularSMS instance.
virtual CellularSMS * open_sms()=0
Create new CellularSMS interface.
Class CellularInformation.
An abstract interface for connecting to a network and getting information from it.
Class FileHandle.
Definition: FileHandle.h:46
signed int nsapi_error_t
Type used to represent error codes.
Definition: nsapi_types.h:142
Callback< R(ArgTs...)> callback(R(*func)(ArgTs...)=nullptr) noexcept
Create a callback class with type inferred from the arguments.
Definition: Callback.h:678