Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AT_CellularDevice.h Source File

AT_CellularDevice.h

00001 /*
00002  * Copyright (c) 2017, Arm Limited and affiliates.
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #ifndef AT_CELLULAR_DEVICE_H_
00019 #define AT_CELLULAR_DEVICE_H_
00020 
00021 #include "CellularDevice.h"
00022 
00023 namespace mbed {
00024 
00025 class ATHandler;
00026 class AT_CellularInformation;
00027 class AT_CellularNetwork;
00028 class AT_CellularSMS;
00029 class AT_CellularContext;
00030 
00031 /**
00032  *  Class AT_CellularDevice
00033  *
00034  *  A class defines opening and closing of cellular interfaces.
00035  *  Deleting/Closing of opened interfaces can be done only through this class.
00036  */
00037 class AT_CellularDevice : public CellularDevice {
00038 public:
00039     /* Supported features by the modem
00040      *
00041      * NOTE! These are used as index to feature table, so the only allowed modification to this is appending
00042      *       to the end (just before PROPERTY_MAX). Do not modify any of the existing fields.
00043      */
00044     enum CellularProperty {
00045         PROPERTY_C_EREG,            // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type.
00046         PROPERTY_C_GREG,            // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type.
00047         PROPERTY_C_REG,             // AT_CellularNetwork::RegistrationMode. What support modem has for this registration type.
00048         PROPERTY_AT_CGSN_WITH_TYPE, // 0 = not supported, 1 = supported. AT+CGSN without type is likely always supported similar to AT+GSN.
00049         PROPERTY_AT_CGDATA,         // 0 = not supported, 1 = supported. Alternative is to support only ATD*99***<cid>#
00050         PROPERTY_AT_CGAUTH,         // 0 = not supported, 1 = supported. APN authentication AT commands supported
00051         PROPERTY_AT_CNMI,           // 0 = not supported, 1 = supported. New message (SMS) indication AT command
00052         PROPERTY_AT_CSMP,           // 0 = not supported, 1 = supported. Set text mode AT command
00053         PROPERTY_AT_CMGF,           // 0 = not supported, 1 = supported. Set preferred message format AT command
00054         PROPERTY_AT_CSDH,           // 0 = not supported, 1 = supported. Show text mode AT command
00055         PROPERTY_IPV4_PDP_TYPE,     // 0 = not supported, 1 = supported. Does modem support IPV4?
00056         PROPERTY_IPV6_PDP_TYPE,     // 0 = not supported, 1 = supported. Does modem support IPV6?
00057         PROPERTY_IPV4V6_PDP_TYPE,   // 0 = not supported, 1 = supported. Does modem support IPV4 and IPV6 simultaneously?
00058         PROPERTY_NON_IP_PDP_TYPE,   // 0 = not supported, 1 = supported. Does modem support Non-IP?
00059         PROPERTY_AT_CGEREP,         // 0 = not supported, 1 = supported. Does modem support AT command AT+CGEREP.
00060 
00061         PROPERTY_MAX
00062     };
00063 
00064 public:
00065     AT_CellularDevice(FileHandle *fh);
00066     virtual ~AT_CellularDevice();
00067 
00068     virtual nsapi_error_t clear();
00069 
00070     virtual nsapi_error_t hard_power_on();
00071 
00072     virtual nsapi_error_t hard_power_off();
00073 
00074     virtual nsapi_error_t soft_power_on();
00075 
00076     virtual nsapi_error_t soft_power_off();
00077 
00078     virtual nsapi_error_t set_pin(const char *sim_pin);
00079 
00080     virtual nsapi_error_t get_sim_state(SimState &state);
00081 
00082     virtual CellularContext *create_context(FileHandle *fh = NULL, const char *apn = NULL, bool cp_req = false, bool nonip_req = false);
00083 
00084 #if (DEVICE_SERIAL && DEVICE_INTERRUPTIN) || defined(DOXYGEN_ONLY)
00085     virtual CellularContext *create_context(UARTSerial *serial, const char *const apn, PinName dcd_pin = NC, bool active_high = false, bool cp_req = false, bool nonip_req = false);
00086 #endif // #if DEVICE_SERIAL
00087 
00088     virtual void delete_context(CellularContext *context);
00089 
00090     virtual CellularNetwork *open_network(FileHandle *fh = NULL);
00091 
00092     virtual CellularInformation *open_information(FileHandle *fh = NULL);
00093 
00094     virtual void close_network();
00095 
00096     virtual void close_information();
00097 
00098     virtual void set_timeout(int timeout);
00099 
00100     virtual uint16_t get_send_delay() const;
00101 
00102     virtual void modem_debug_on(bool on);
00103 
00104     virtual nsapi_error_t init();
00105 
00106     virtual nsapi_error_t shutdown();
00107 
00108     virtual nsapi_error_t is_ready();
00109 
00110     virtual void set_ready_cb(Callback<void()> callback);
00111 
00112     virtual nsapi_error_t set_power_save_mode(int periodic_time, int active_time = 0);
00113 
00114 
00115     virtual ATHandler *get_at_handler(FileHandle *fh);
00116 
00117     virtual ATHandler *get_at_handler();
00118 
00119     /** Releases the given at_handler. If last reference to at_hander then it's deleted.
00120      *
00121      *  @param at_handler
00122      *  @return NSAPI_ERROR_OK on success, NSAPI_ERROR_PARAMETER on failure
00123      */
00124     virtual nsapi_error_t release_at_handler(ATHandler *at_handler);
00125 
00126     /** Creates new instance of AT_CellularContext or if overridden, modem specific implementation.
00127      *
00128      *  @param at           ATHandler reference for communication with the modem.
00129      *  @param apn          access point to use with context
00130      *  @param cp_req       flag indicating if control plane EPS optimization needs to be setup
00131      *  @param nonip_req    flag indicating if PDP context needs to be Non-IP
00132      *  @return             new instance of class AT_CellularContext
00133      *
00134      */
00135     virtual AT_CellularContext *create_context_impl(ATHandler &at, const char *apn, bool cp_req = false, bool nonip_req = false);
00136 
00137     /** Create new instance of AT_CellularNetwork or if overridden, modem specific implementation.
00138      *
00139      *  @param at   ATHandler reference for communication with the modem.
00140      *  @return new instance of class AT_CellularNetwork
00141      */
00142     virtual AT_CellularNetwork *open_network_impl(ATHandler &at);
00143 
00144     /** Create new instance of AT_CellularInformation or if overridden, modem specific implementation.
00145      *
00146      *  @param at   ATHandler reference for communication with the modem.
00147      *  @return new instance of class AT_CellularInformation
00148      */
00149     virtual AT_CellularInformation *open_information_impl(ATHandler &at);
00150 
00151     virtual CellularContext *get_context_list() const;
00152 
00153     virtual nsapi_error_t set_baud_rate(int baud_rate);
00154 
00155 #if MBED_CONF_CELLULAR_USE_SMS
00156     virtual CellularSMS *open_sms(FileHandle *fh = NULL);
00157 
00158     virtual void close_sms();
00159 
00160     /** Create new instance of AT_CellularSMS or if overridden, modem specific implementation.
00161      *
00162      *  @param at   ATHandler reference for communication with the modem.
00163      *  @return new instance of class AT_CellularSMS
00164      */
00165     virtual AT_CellularSMS *open_sms_impl(ATHandler &at);
00166 
00167     AT_CellularSMS *_sms;
00168 
00169 #endif // MBED_CONF_CELLULAR_USE_SMS
00170 
00171 public:
00172     /** Get value for the given key.
00173      *
00174      *  @param key  key for value to be fetched
00175      *  @return     property value for the given key. Value type is defined in enum CellularProperty
00176      */
00177     intptr_t get_property(CellularProperty key);
00178 
00179     /** Cellular module need to define an array of cellular properties which defines module supported property values.
00180      *
00181      *  @param property_array array of module properties
00182      */
00183     void set_cellular_properties(const intptr_t *property_array);
00184 
00185 public: //Member variables
00186     AT_CellularNetwork *_network;
00187 
00188     AT_CellularInformation *_information;
00189     AT_CellularContext *_context_list;
00190     int _default_timeout;
00191     bool _modem_debug_on;
00192     ATHandler *_at;
00193 
00194 protected:
00195     virtual void cellular_callback(nsapi_event_t ev, intptr_t ptr, CellularContext *ctx = NULL);
00196     void send_disconnect_to_context(int cid);
00197     // Sets commonly used URCs
00198     void set_at_urcs();
00199     // To be used for setting target specific URCs
00200     virtual void set_at_urcs_impl();
00201     // Sets up parameters for AT handler, for now only the send delay and URCs.
00202     // This kind of routine is needed for initialisation routines that are virtual and therefore cannot be called from constructor.
00203     void setup_at_handler();
00204     virtual nsapi_error_t set_baud_rate_impl(int baud_rate);
00205 
00206 private:
00207     void urc_nw_deact();
00208     void urc_pdn_deact();
00209 
00210 private:
00211     const intptr_t *_property_array;
00212 };
00213 
00214 } // namespace mbed
00215 #endif // AT_CELLULAR_DEVICE_H_