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_CellularNetwork.h Source File

AT_CellularNetwork.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_NETWORK_H_
00019 #define AT_CELLULAR_NETWORK_H_
00020 
00021 #include "CellularNetwork.h"
00022 #include "ATHandler.h"
00023 #include "AT_CellularDevice.h"
00024 
00025 namespace mbed {
00026 
00027 #define AT_NETWORK_TRIALS 5
00028 #define TIMER_UNIT_LENGTH 3
00029 #define TWO_BYTES_HEX 4
00030 #define FOUR_BYTES_HEX 8
00031 #define ONE_BYTE_BINARY 8
00032 
00033 /**
00034  *  Class AT_CellularNetwork
00035  *
00036  *  Class for attaching to a network and getting information from it.
00037  */
00038 class AT_CellularNetwork : public CellularNetwork {
00039 
00040 public:
00041 
00042     AT_CellularNetwork(ATHandler &atHandler, AT_CellularDevice &device);
00043     virtual ~AT_CellularNetwork();
00044     // declare friend so it can access stack
00045     friend class AT_CellularDevice;
00046 
00047     enum RegistrationMode {
00048         RegistrationModeDisable = 0,
00049         RegistrationModeEnable, // <stat>
00050         RegistrationModeLAC, // <stat>[,<[lac>,]<[ci>],[<AcT>],[<rac>]]
00051     };
00052 
00053 public: // CellularNetwork
00054 
00055     virtual nsapi_error_t set_registration(const char *plmn = 0);
00056 
00057     virtual nsapi_error_t get_network_registering_mode(NWRegisteringMode &mode);
00058 
00059     virtual nsapi_error_t set_attach();
00060 
00061     virtual nsapi_error_t get_attach(AttachStatus &status);
00062 
00063     virtual nsapi_error_t detach();
00064 
00065     virtual void attach(Callback<void(nsapi_event_t, intptr_t)> status_cb);
00066 
00067     virtual nsapi_error_t set_access_technology(RadioAccessTechnology rat);
00068 
00069     virtual nsapi_error_t scan_plmn(operList_t &operators, int &ops_count);
00070 
00071     virtual nsapi_error_t set_ciot_optimization_config(CIoT_Supported_Opt supported_opt,
00072                                                        CIoT_Preferred_UE_Opt preferred_opt,
00073                                                        Callback<void(CIoT_Supported_Opt)> network_support_cb);
00074 
00075     virtual nsapi_error_t get_ciot_ue_optimization_config(CIoT_Supported_Opt &supported_opt,
00076                                                           CIoT_Preferred_UE_Opt &preferred_opt);
00077 
00078     virtual nsapi_error_t get_ciot_network_optimization_config(CIoT_Supported_Opt &supported_network_opt);
00079 
00080     virtual nsapi_error_t get_signal_quality(int &rssi, int *ber = NULL);
00081 
00082     virtual int get_3gpp_error();
00083 
00084     virtual nsapi_error_t get_operator_params(int &format, operator_t &operator_params);
00085 
00086     virtual nsapi_error_t set_registration_urc(RegistrationType type, bool on);
00087 
00088     virtual nsapi_error_t get_operator_names(operator_names_list &op_names);
00089 
00090     virtual bool is_active_context(int *number_of_active_contexts = NULL, int cid = -1);
00091 
00092     virtual nsapi_error_t get_registration_params(registration_params_t &reg_params);
00093 
00094     virtual nsapi_error_t get_registration_params(RegistrationType type, registration_params_t &reg_params);
00095 
00096     virtual nsapi_error_t set_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value);
00097 
00098     virtual nsapi_error_t set_packet_domain_event_reporting(bool on);
00099 
00100 public:
00101     ATHandler &get_at_handler();
00102 
00103 protected:
00104 
00105     /** Sets access technology to be scanned. Modem specific implementation.
00106      *
00107      *  @param op_rat Access technology
00108      *
00109      *  @return       zero on success
00110      */
00111     virtual nsapi_error_t set_access_technology_impl(RadioAccessTechnology op_rat);
00112 
00113     /** Sends a command to query the active state of the PDP contexts.
00114      *  Can be overridden by the target class.
00115      */
00116     virtual void get_context_state_command();
00117 
00118     /** Clear the network and contexts to a known default state
00119      *
00120      *  @return         NSAPI_ERROR_OK on success
00121      */
00122     nsapi_error_t clear();
00123 
00124 private:
00125     void urc_creg();
00126     void urc_cereg();
00127     void urc_cgreg();
00128     void urc_cgev();
00129     void urc_cciotopti();
00130 
00131     void read_reg_params_and_compare(RegistrationType type);
00132     void read_reg_params(RegistrationType type, registration_params_t &reg_params);
00133 
00134     // Returns active time(Table 10.5.163/3GPP TS 24.008: GPRS Timer 2 information element) in seconds
00135     int calculate_active_time(const char *active_time_string, int active_time_length);
00136     // Returns periodic tau(Table 10.5.163a/3GPP TS 24.008: GPRS Timer 3 information element) in seconds
00137     int calculate_periodic_tau(const char *periodic_tau_string, int periodic_tau_length);
00138 
00139     // calls network callback only if status was changed, updates local connection status
00140     void call_network_cb(nsapi_connection_status_t status);
00141 
00142 protected:
00143 
00144     Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
00145     Callback<void(CIoT_Supported_Opt)> _ciotopt_network_support_cb;
00146     RadioAccessTechnology _op_act;
00147     nsapi_connection_status_t _connect_status;
00148     CIoT_Supported_Opt _supported_network_opt;
00149 
00150     registration_params_t _reg_params;
00151     mbed::Callback<void()> _urc_funcs[C_MAX];
00152 
00153 protected:
00154     ATHandler &_at;
00155 
00156     AT_CellularDevice &_device;
00157 };
00158 
00159 } // namespace mbed
00160 
00161 #endif // AT_CELLULAR_NETWORK_H_