ublox-cellular-base

Committer:
mudassar0121
Date:
Thu Apr 02 15:59:41 2020 +0500
Revision:
40:19c834eb9106
Parent:
36:2f8ef6ac16dc
Removed onboard_modem_api and UARTSerial, added UBLOX_onboard_modem_api and BufferedSerial to power up modem

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fahimalavi 26:e4e444cc7b14 1 /* Copyright (c) 2019 ARM Limited
RobMeades 0:5cffef3371f6 2 *
RobMeades 0:5cffef3371f6 3 * Licensed under the Apache License, Version 2.0 (the "License");
RobMeades 0:5cffef3371f6 4 * you may not use this file except in compliance with the License.
RobMeades 0:5cffef3371f6 5 * You may obtain a copy of the License at
RobMeades 0:5cffef3371f6 6 *
RobMeades 0:5cffef3371f6 7 * http://www.apache.org/licenses/LICENSE-2.0
RobMeades 0:5cffef3371f6 8 *
RobMeades 0:5cffef3371f6 9 * Unless required by applicable law or agreed to in writing, software
RobMeades 0:5cffef3371f6 10 * distributed under the License is distributed on an "AS IS" BASIS,
RobMeades 0:5cffef3371f6 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
RobMeades 0:5cffef3371f6 12 * See the License for the specific language governing permissions and
RobMeades 0:5cffef3371f6 13 * limitations under the License.
RobMeades 0:5cffef3371f6 14 */
RobMeades 0:5cffef3371f6 15
rob.meades@u-blox.com 1:5aaecf2572dc 16 #ifndef _UBLOX_CELLULAR_BASE_
rob.meades@u-blox.com 1:5aaecf2572dc 17 #define _UBLOX_CELLULAR_BASE_
RobMeades 0:5cffef3371f6 18
RobMeades 0:5cffef3371f6 19 #include "mbed.h"
RobMeades 14:e420232ee4e7 20 #include "mbed_toolchain.h" // for MBED_DEPRECATED
ublox 33:8e1e79259b3f 21 #include "UbloxATCmdParser.h"
RobMeades 0:5cffef3371f6 22 #include "FileHandle.h"
mudassar0121 40:19c834eb9106 23 #include "drivers/BufferedSerial.h"
mudassar0121 40:19c834eb9106 24 #include "UBLOX_onboard_modem_api.h"
RobMeades 0:5cffef3371f6 25
wajahat.abbas@u-blox.com 29:8a38f91009ad 26 #ifdef TARGET_UBLOX_C030_R410M
wajahat.abbas@u-blox.com 29:8a38f91009ad 27 #define MAX_NUM_PROFILES 12 //ref to enum MNOProfile
wajahat.abbas@u-blox.com 29:8a38f91009ad 28 #elif TARGET_UBLOX_C030_R412M
wajahat.abbas@u-blox.com 29:8a38f91009ad 29 #define MAX_NUM_PROFILES 7
wajahat.abbas@u-blox.com 29:8a38f91009ad 30 #endif
wajahat.abbas@u-blox.com 29:8a38f91009ad 31
RobMeades 0:5cffef3371f6 32 /**********************************************************************
RobMeades 0:5cffef3371f6 33 * CLASSES
RobMeades 0:5cffef3371f6 34 **********************************************************************/
RobMeades 0:5cffef3371f6 35
RobMeades 0:5cffef3371f6 36 /** UbloxCellularBase class.
RobMeades 0:5cffef3371f6 37 *
RobMeades 0:5cffef3371f6 38 * This class provides all the base support for generic u-blox modems
RobMeades 0:5cffef3371f6 39 * on C030 and C027 boards: module identification, power-up, network
RobMeades 0:5cffef3371f6 40 * registration, etc.
RobMeades 0:5cffef3371f6 41 */
RobMeades 0:5cffef3371f6 42 class UbloxCellularBase {
RobMeades 0:5cffef3371f6 43
RobMeades 0:5cffef3371f6 44 public:
RobMeades 0:5cffef3371f6 45 /** Circuit Switched network registration status (CREG Usage).
RobMeades 0:5cffef3371f6 46 * UBX-13001820 - AT Commands Example Application Note (Section 7.10.3).
RobMeades 0:5cffef3371f6 47 */
RobMeades 0:5cffef3371f6 48 typedef enum {
RobMeades 0:5cffef3371f6 49 CSD_NOT_REGISTERED_NOT_SEARCHING = 0,
RobMeades 0:5cffef3371f6 50 CSD_REGISTERED = 1,
RobMeades 0:5cffef3371f6 51 CSD_NOT_REGISTERED_SEARCHING = 2,
RobMeades 0:5cffef3371f6 52 CSD_REGISTRATION_DENIED = 3,
RobMeades 0:5cffef3371f6 53 CSD_UNKNOWN_COVERAGE = 4,
RobMeades 0:5cffef3371f6 54 CSD_REGISTERED_ROAMING = 5,
RobMeades 0:5cffef3371f6 55 CSD_SMS_ONLY = 6,
RobMeades 0:5cffef3371f6 56 CSD_SMS_ONLY_ROAMING = 7,
RobMeades 0:5cffef3371f6 57 CSD_CSFB_NOT_PREFERRED = 9
RobMeades 0:5cffef3371f6 58 } NetworkRegistrationStatusCsd;
RobMeades 0:5cffef3371f6 59
RobMeades 0:5cffef3371f6 60 /** Packet Switched network registration status (CGREG Usage).
RobMeades 0:5cffef3371f6 61 * UBX-13001820 - AT Commands Example Application Note (Section 18.27.3).
RobMeades 0:5cffef3371f6 62 */
RobMeades 0:5cffef3371f6 63 typedef enum {
RobMeades 0:5cffef3371f6 64 PSD_NOT_REGISTERED_NOT_SEARCHING = 0,
RobMeades 0:5cffef3371f6 65 PSD_REGISTERED = 1,
RobMeades 0:5cffef3371f6 66 PSD_NOT_REGISTERED_SEARCHING = 2,
RobMeades 0:5cffef3371f6 67 PSD_REGISTRATION_DENIED = 3,
RobMeades 0:5cffef3371f6 68 PSD_UNKNOWN_COVERAGE = 4,
RobMeades 0:5cffef3371f6 69 PSD_REGISTERED_ROAMING = 5,
RobMeades 0:5cffef3371f6 70 PSD_EMERGENCY_SERVICES_ONLY = 8
RobMeades 0:5cffef3371f6 71 } NetworkRegistrationStatusPsd;
RobMeades 0:5cffef3371f6 72
RobMeades 0:5cffef3371f6 73 /** EPS network registration status (CEREG Usage).
RobMeades 0:5cffef3371f6 74 * UBX-13001820 - AT Commands Example Application Note (Section 18.36.3).
RobMeades 0:5cffef3371f6 75 */
RobMeades 0:5cffef3371f6 76 typedef enum {
RobMeades 0:5cffef3371f6 77 EPS_NOT_REGISTERED_NOT_SEARCHING = 0,
RobMeades 0:5cffef3371f6 78 EPS_REGISTERED = 1,
RobMeades 0:5cffef3371f6 79 EPS_NOT_REGISTERED_SEARCHING = 2,
RobMeades 0:5cffef3371f6 80 EPS_REGISTRATION_DENIED = 3,
RobMeades 0:5cffef3371f6 81 EPS_UNKNOWN_COVERAGE = 4,
RobMeades 0:5cffef3371f6 82 EPS_REGISTERED_ROAMING = 5,
RobMeades 0:5cffef3371f6 83 EPS_EMERGENCY_SERVICES_ONLY = 8
RobMeades 0:5cffef3371f6 84 } NetworkRegistrationStatusEps;
RobMeades 0:5cffef3371f6 85
wajahat.abbas@u-blox.com 23:eaab8e812a5d 86 /** modem PSM states.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 87 *
wajahat.abbas@u-blox.com 23:eaab8e812a5d 88 */
wajahat.abbas@u-blox.com 23:eaab8e812a5d 89 typedef enum {
wajahat.abbas@u-blox.com 23:eaab8e812a5d 90 AWAKE = 0,
wajahat.abbas@u-blox.com 23:eaab8e812a5d 91 ASLEEP = 1
wajahat.abbas@u-blox.com 23:eaab8e812a5d 92 } ModemPSMState;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 93
fahimalavi 26:e4e444cc7b14 94 /**
fahimalavi 26:e4e444cc7b14 95 * edrx access technology
fahimalavi 26:e4e444cc7b14 96 */
fahimalavi 26:e4e444cc7b14 97 typedef enum {
fahimalavi 26:e4e444cc7b14 98 EDRXGSM_EC_GSM_IoT_mode = 1,
fahimalavi 26:e4e444cc7b14 99 EDRXGSM_A_Gb_mode,
fahimalavi 26:e4e444cc7b14 100 EDRXUTRAN_Iu_mode,
fahimalavi 26:e4e444cc7b14 101 EDRXEUTRAN_WB_S1_mode,
fahimalavi 26:e4e444cc7b14 102 EDRXEUTRAN_NB_S1_mode
fahimalavi 26:e4e444cc7b14 103 }tEDRXAccessTechnology;
fahimalavi 26:e4e444cc7b14 104
fahimalavi 30:38230504a646 105 #ifdef TARGET_UBLOX_C030_R41XM
fahimalavi 30:38230504a646 106 /** Supported MNO profiles for SARA-R4.
fahimalavi 30:38230504a646 107 */
fahimalavi 30:38230504a646 108 typedef enum {
fahimalavi 30:38230504a646 109 SW_DEFAULT = 0,
fahimalavi 30:38230504a646 110 SIM_ICCID = 1,
fahimalavi 30:38230504a646 111 ATT = 2,
fahimalavi 30:38230504a646 112 TMO = 5,
fahimalavi 30:38230504a646 113 VODAFONE = 19,
fahimalavi 30:38230504a646 114 DT = 31,
fahimalavi 30:38230504a646 115 STANDARD_EU = 100
fahimalavi 30:38230504a646 116 #ifdef TARGET_UBLOX_C030_R410M
fahimalavi 30:38230504a646 117 , VERIZON = 3,
fahimalavi 30:38230504a646 118 TELSTRA = 4,
fahimalavi 30:38230504a646 119 CT = 6,
fahimalavi 30:38230504a646 120 SPRINT = 8,
fahimalavi 30:38230504a646 121 TELUS = 21
fahimalavi 30:38230504a646 122 #endif
fahimalavi 30:38230504a646 123 } MNOProfile;
fahimalavi 30:38230504a646 124
fahimalavi 30:38230504a646 125 typedef enum {
fahimalavi 30:38230504a646 126 UBANDMASK_RAT_LTE_CATM1 = 0,
fahimalavi 30:38230504a646 127 UBANDMASK_RAT_LTE_CATNB1 = 1
fahimalavi 30:38230504a646 128
fahimalavi 30:38230504a646 129 } UBandmaskRAT;
fahimalavi 30:38230504a646 130 #endif
fahimalavi 30:38230504a646 131
RobMeades 0:5cffef3371f6 132 /** Initialise the modem, ready for use.
RobMeades 0:5cffef3371f6 133 *
RobMeades 0:5cffef3371f6 134 * @param pin PIN for the SIM card.
RobMeades 0:5cffef3371f6 135 * @return true if successful, otherwise false.
RobMeades 0:5cffef3371f6 136 */
RobMeades 0:5cffef3371f6 137 bool init(const char *pin = 0);
RobMeades 0:5cffef3371f6 138
RobMeades 0:5cffef3371f6 139 /** Perform registration with the network.
RobMeades 0:5cffef3371f6 140 *
RobMeades 0:5cffef3371f6 141 * @return true if successful, otherwise false.
RobMeades 0:5cffef3371f6 142 */
RobMeades 0:5cffef3371f6 143 bool nwk_registration();
RobMeades 0:5cffef3371f6 144
RobMeades 0:5cffef3371f6 145 /** True if the modem is registered for circuit
RobMeades 0:5cffef3371f6 146 * switched data, otherwise false.
RobMeades 0:5cffef3371f6 147 */
RobMeades 0:5cffef3371f6 148 bool is_registered_csd();
RobMeades 0:5cffef3371f6 149
RobMeades 0:5cffef3371f6 150 /** True if the modem is registered for packet
RobMeades 0:5cffef3371f6 151 * switched data, otherwise false.
RobMeades 0:5cffef3371f6 152 */
RobMeades 0:5cffef3371f6 153 bool is_registered_psd();
RobMeades 0:5cffef3371f6 154
RobMeades 0:5cffef3371f6 155 /** True if the modem is registered for enhanced
RobMeades 0:5cffef3371f6 156 * packet switched data (i.e. LTE and beyond),
RobMeades 0:5cffef3371f6 157 * otherwise false.
RobMeades 0:5cffef3371f6 158 */
RobMeades 0:5cffef3371f6 159 bool is_registered_eps();
RobMeades 0:5cffef3371f6 160
RobMeades 0:5cffef3371f6 161 /** Perform deregistration from the network.
RobMeades 0:5cffef3371f6 162 *
RobMeades 0:5cffef3371f6 163 * @return true if successful, otherwise false.
RobMeades 0:5cffef3371f6 164 */
RobMeades 0:5cffef3371f6 165 bool nwk_deregistration();
RobMeades 0:5cffef3371f6 166
RobMeades 0:5cffef3371f6 167 /** Put the modem into its lowest power state.
RobMeades 0:5cffef3371f6 168 */
RobMeades 0:5cffef3371f6 169 void deinit();
RobMeades 0:5cffef3371f6 170
RobMeades 0:5cffef3371f6 171 /** Set the PIN code for the SIM card.
RobMeades 0:5cffef3371f6 172 *
RobMeades 0:5cffef3371f6 173 * @param pin PIN for the SIM card.
RobMeades 0:5cffef3371f6 174 */
RobMeades 0:5cffef3371f6 175 void set_pin(const char *pin);
RobMeades 0:5cffef3371f6 176
RobMeades 0:5cffef3371f6 177 /** Enable or disable SIM pin checking.
RobMeades 0:5cffef3371f6 178 *
RobMeades 0:5cffef3371f6 179 * @param enableNotDisable true if SIM PIN checking is to be enabled,
RobMeades 0:5cffef3371f6 180 * otherwise false.
RobMeades 0:5cffef3371f6 181 * @return true if successful, otherwise false.
RobMeades 0:5cffef3371f6 182 */
RobMeades 0:5cffef3371f6 183 bool sim_pin_check_enable(bool enableNotDisable);
RobMeades 0:5cffef3371f6 184
RobMeades 0:5cffef3371f6 185 /** Change the SIM pin.
RobMeades 0:5cffef3371f6 186 *
RobMeades 0:5cffef3371f6 187 * @param new_pin the new PIN to use.
RobMeades 0:5cffef3371f6 188 * @return true if successful, otherwise false.
RobMeades 0:5cffef3371f6 189 */
RobMeades 0:5cffef3371f6 190 bool change_sim_pin(const char *new_pin);
RobMeades 0:5cffef3371f6 191
wajahat.abbas@u-blox.com 34:d239824bfb8f 192 /** Get the IMEI.
fahim alavi 11:57f64bc518c0 193 *
fahim alavi 11:57f64bc518c0 194 * @return true if successful, otherwise false.
fahim alavi 11:57f64bc518c0 195 */
RobMeades 14:e420232ee4e7 196 MBED_DEPRECATED("This method is now replaced by const char * imei(), please use that instead")
wajahat.abbas@u-blox.com 34:d239824bfb8f 197 bool get_imei(char *imei_to_send, int size);
fahim alavi 11:57f64bc518c0 198
RobMeades 14:e420232ee4e7 199 /** Get the IMEI of the module.
RobMeades 14:e420232ee4e7 200 *
RobMeades 14:e420232ee4e7 201 * @return a pointer to the IMEI as a null-terminated string.
RobMeades 14:e420232ee4e7 202 */
RobMeades 14:e420232ee4e7 203 const char *imei();
RobMeades 14:e420232ee4e7 204
RobMeades 14:e420232ee4e7 205 /** Get the Mobile Equipment ID (which may be the same as the IMEI).
RobMeades 14:e420232ee4e7 206 *
RobMeades 14:e420232ee4e7 207 * @return a pointer to the Mobile Equipment ID as a null-terminated string.
RobMeades 14:e420232ee4e7 208 */
RobMeades 14:e420232ee4e7 209 const char *meid();
RobMeades 14:e420232ee4e7 210
RobMeades 14:e420232ee4e7 211 /** Get the IMSI of the SIM.
RobMeades 14:e420232ee4e7 212 *
RobMeades 14:e420232ee4e7 213 * @return a pointer to the IMSI as a null-terminated string.
RobMeades 14:e420232ee4e7 214 */
RobMeades 14:e420232ee4e7 215 const char *imsi();
RobMeades 14:e420232ee4e7 216
RobMeades 14:e420232ee4e7 217 /** Get the ICCID of the SIM.
RobMeades 14:e420232ee4e7 218 *
RobMeades 14:e420232ee4e7 219 * @return a pointer to the ICCID as a null-terminated string.
RobMeades 14:e420232ee4e7 220 */
RobMeades 14:e420232ee4e7 221 const char *iccid();
RobMeades 14:e420232ee4e7 222
RobMeades 14:e420232ee4e7 223 /** Get the RSSI.
RobMeades 14:e420232ee4e7 224 *
RobMeades 14:e420232ee4e7 225 * @return the RSSI in dBm. If it is not possible to obtain an
RobMeades 14:e420232ee4e7 226 * RSSI reading at the time (e.g. because the modem is in
RobMeades 14:e420232ee4e7 227 * data mode rather than AT command mode) then 0 is returned.
RobMeades 14:e420232ee4e7 228 */
RobMeades 14:e420232ee4e7 229 int rssi();
RobMeades 14:e420232ee4e7 230
wajahat.abbas@u-blox.com 20:31d5e048fbfa 231 /** RAT values for +URAT command
wajahat.abbas@u-blox.com 20:31d5e048fbfa 232 * R412M only supports value 7 (CatM1), 8 (NB1), and 9 (GPRS)
wajahat.abbas@u-blox.com 20:31d5e048fbfa 233 */
wajahat.abbas@u-blox.com 20:31d5e048fbfa 234 typedef enum {
wajahat.abbas@u-blox.com 20:31d5e048fbfa 235 GSM_GPRS_EGPRS = 0,
wajahat.abbas@u-blox.com 20:31d5e048fbfa 236 GSM_UMTS = 1,
wajahat.abbas@u-blox.com 20:31d5e048fbfa 237 UMTS = 2,
wajahat.abbas@u-blox.com 20:31d5e048fbfa 238 URAT_LTE = 3,
wajahat.abbas@u-blox.com 20:31d5e048fbfa 239 GSM_UMTS_LTE = 4,
wajahat.abbas@u-blox.com 20:31d5e048fbfa 240 GSM_LTE = 5,
wajahat.abbas@u-blox.com 20:31d5e048fbfa 241 UMTS_LTE = 6,
wajahat.abbas@u-blox.com 20:31d5e048fbfa 242 LTE_CATM1 = 7,
wajahat.abbas@u-blox.com 20:31d5e048fbfa 243 LTE_CATNB1 = 8,
wajahat.abbas@u-blox.com 20:31d5e048fbfa 244 GPRS_EGPRS = 9,
wajahat.abbas@u-blox.com 22:779971811c46 245 NOT_USED = -1
wajahat.abbas@u-blox.com 20:31d5e048fbfa 246 } RAT;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 247
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 248 /** Module functionality modes. Ref to section 5.3.3 of UBX-13002752 for details.
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 249 */
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 250 typedef enum {
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 251 FUNC_MIN = 0,
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 252 FUNC_FULL = 1,
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 253 FUNC_AIRPLANE = 4,
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 254 FUNC_EN_SIM_TLKT_DEDICATED = 6,
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 255 FUNC_DS_SIM_TLKT = 7,
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 256 FUNC_EN_SIM_TLKT_RAW = 9,
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 257 FUNC_RESET = 15,
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 258 FUNC_RESET_WITH_SIM = 16,
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 259 FUNC_MIN_WITH_SIM = 19,
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 260 FUNC_HALT = 127
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 261 } FunctionalityMode;
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 262
wajahat.abbas@u-blox.com 20:31d5e048fbfa 263 #ifdef TARGET_UBLOX_C030_R41XM
wajahat.abbas@u-blox.com 34:d239824bfb8f 264 /** Set MNO profile. Profile will be applied on next boot.
wajahat.abbas@u-blox.com 34:d239824bfb8f 265 *
wajahat.abbas@u-blox.com 36:2f8ef6ac16dc 266 * User can also specify profile in mbed_app.json ("default-mno-profile": 100) and in that case profile will be applied in init().
wajahat.abbas@u-blox.com 34:d239824bfb8f 267 * Modem will also be rebooted so that profile parameters can be applied.
wajahat.abbas@u-blox.com 20:31d5e048fbfa 268 *
wajahat.abbas@u-blox.com 21:98aea8f49cd8 269 * Note: MNO profile should only be set in detached state and a reboot is required for settings to take effect
wajahat.abbas@u-blox.com 29:8a38f91009ad 270 * Note 2: ref to UBX-17003787 B.5, setting MNO profile can change other parameters such as PSM, Band mask, URAT etc.
wajahat.abbas@u-blox.com 29:8a38f91009ad 271 * Application must always set a profile first and if required, change parameters afterwards.
wajahat.abbas@u-blox.com 34:d239824bfb8f 272 * Note 3: ref to UBX-17003787 B.5, some profiles have locked parameters and modem will return ERROR if you try to change those.
wajahat.abbas@u-blox.com 34:d239824bfb8f 273 * It is suggested to switch to a profile e.g. STANDARD_EU (100) and then change the parameters as required.
wajahat.abbas@u-blox.com 21:98aea8f49cd8 274 * @param profile MNO profile to use
wajahat.abbas@u-blox.com 20:31d5e048fbfa 275 * @return true if operation was successful, false if there was an error
wajahat.abbas@u-blox.com 20:31d5e048fbfa 276 */
wajahat.abbas@u-blox.com 34:d239824bfb8f 277 bool set_mno_profile(MNOProfile profile);
wajahat.abbas@u-blox.com 20:31d5e048fbfa 278
wajahat.abbas@u-blox.com 20:31d5e048fbfa 279 /** Get current MNO profile.
wajahat.abbas@u-blox.com 20:31d5e048fbfa 280 *
wajahat.abbas@u-blox.com 20:31d5e048fbfa 281 * @param profile pointer to variable that can hold the value for returned profile
wajahat.abbas@u-blox.com 20:31d5e048fbfa 282 * @return true if operation was successful, false if there was an error
wajahat.abbas@u-blox.com 20:31d5e048fbfa 283 */
wajahat.abbas@u-blox.com 22:779971811c46 284 bool get_mno_profile(int *profile);
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 285
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 286 /** Enable or disable the UPSV Power Saving Mode.
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 287 *
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 288 * @param idle_mode_value 1: enable idle mode
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 289 * 0: disable idle mode
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 290 * @return true if successful, otherwise false.
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 291 */
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 292 bool set_idle_mode(bool enable = false);
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 293
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 294 /** Queries the modem for idle mode status.
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 295 *
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 296 * @param status pointer to variable that can hold the value for idle mode status
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 297 * 1: enabled
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 298 * 0: disabled
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 299 * @return true if successful, otherwise false.
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 300 */
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 301 bool get_idle_mode(int *status);
wajahat.abbas@u-blox.com 20:31d5e048fbfa 302 #endif
wajahat.abbas@u-blox.com 20:31d5e048fbfa 303
wajahat.abbas@u-blox.com 20:31d5e048fbfa 304 /** Set Radio Access Technology on modem.
wajahat.abbas@u-blox.com 20:31d5e048fbfa 305 *
wajahat.abbas@u-blox.com 20:31d5e048fbfa 306 * Note: RAT should only be set in detached state and a reboot is required for settings to take effect
wajahat.abbas@u-blox.com 20:31d5e048fbfa 307 *
wajahat.abbas@u-blox.com 20:31d5e048fbfa 308 * @param selected_rat Radio Access Technology to use
wajahat.abbas@u-blox.com 20:31d5e048fbfa 309 * @param preferred_rat Radio Access Technology to use if selected_rat is not available
wajahat.abbas@u-blox.com 20:31d5e048fbfa 310 * @param second_preferred_rat Radio Access Technology to use if selected_rat and preferred_rat are not available
wajahat.abbas@u-blox.com 20:31d5e048fbfa 311 *
wajahat.abbas@u-blox.com 20:31d5e048fbfa 312 * @return true if successful, otherwise false.
wajahat.abbas@u-blox.com 20:31d5e048fbfa 313 */
wajahat.abbas@u-blox.com 20:31d5e048fbfa 314 bool set_modem_rat(RAT selected_rat, RAT preferred_rat = NOT_USED, RAT second_preferred_rat = NOT_USED);
wajahat.abbas@u-blox.com 20:31d5e048fbfa 315
wajahat.abbas@u-blox.com 20:31d5e048fbfa 316 /** Get last saved values for RAT using +URAT read command. Note: The current selected RAT is indicated by DeviceInfo.rat
wajahat.abbas@u-blox.com 20:31d5e048fbfa 317 *
wajahat.abbas@u-blox.com 20:31d5e048fbfa 318 * @param selected_rat pointer to variable that can hold the value for selected_rat
wajahat.abbas@u-blox.com 20:31d5e048fbfa 319 * @param preferred_rat pointer to variable that can hold the value for preferred_rat
wajahat.abbas@u-blox.com 20:31d5e048fbfa 320 * @param second_preferred_rat pointer to variable that can hold the value for second_preferred_rat
wajahat.abbas@u-blox.com 20:31d5e048fbfa 321 *
wajahat.abbas@u-blox.com 20:31d5e048fbfa 322 * Note: NOT_USED will be returned in the variables if dual or tri modes are not enabled.
wajahat.abbas@u-blox.com 20:31d5e048fbfa 323 *
wajahat.abbas@u-blox.com 20:31d5e048fbfa 324 * @return true if successful, otherwise false.
wajahat.abbas@u-blox.com 20:31d5e048fbfa 325 */
wajahat.abbas@u-blox.com 22:779971811c46 326 bool get_modem_rat(int *selected_rat, int *preferred_rat, int *second_preferred_rat);
wajahat.abbas@u-blox.com 20:31d5e048fbfa 327
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 328 /** Sets the modem to specified functionality mode.
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 329 *
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 330 * @return true if successful, otherwise false.
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 331 */
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 332 bool set_functionality_mode(FunctionalityMode mode);
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 333
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 334 /** Get the modem functionality mode
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 335 *
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 336 * @return true if successful, otherwise false.
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 337 */
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 338 bool get_functionality_mode(int *mode);
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 339
wajahat.abbas@u-blox.com 23:eaab8e812a5d 340 /** reboot the modem using AT+CFUN=15. Application should call init() or connect() before making any other API calls.
wajahat.abbas@u-blox.com 20:31d5e048fbfa 341 *
wajahat.abbas@u-blox.com 20:31d5e048fbfa 342 * @return true if successful, otherwise false.
wajahat.abbas@u-blox.com 20:31d5e048fbfa 343 */
wajahat.abbas@u-blox.com 20:31d5e048fbfa 344 bool reboot_modem();
wajahat.abbas@u-blox.com 23:eaab8e812a5d 345
wajahat.abbas@u-blox.com 23:eaab8e812a5d 346 #ifdef TARGET_UBLOX_C030_R412M
wajahat.abbas@u-blox.com 23:eaab8e812a5d 347 /** Important: Callback function is executed in context of AT parser so a user should not issue any AT commands from inside the callback.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 348 * It is recommended to set a flag/event/signal in callback and application can use that to wake up the modem and re-initialize it
wajahat.abbas@u-blox.com 23:eaab8e812a5d 349 *
wajahat.abbas@u-blox.com 23:eaab8e812a5d 350 * application callback for modem going in to PSM sleep
wajahat.abbas@u-blox.com 23:eaab8e812a5d 351 *
wajahat.abbas@u-blox.com 23:eaab8e812a5d 352 * @param func callback function to be executed when modem is going in to PSM sleep
wajahat.abbas@u-blox.com 23:eaab8e812a5d 353 * @param param parameter to be passed to callback function.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 354 */
wajahat.abbas@u-blox.com 23:eaab8e812a5d 355 void attach_cb_psm_going_in(Callback<void(void*)> func, void *param)
wajahat.abbas@u-blox.com 23:eaab8e812a5d 356 {
wajahat.abbas@u-blox.com 23:eaab8e812a5d 357 _func_psm_going_in = func;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 358 _cb_param_psm_going_in = param;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 359 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 360
wajahat.abbas@u-blox.com 23:eaab8e812a5d 361 /** Important: Callback function is executed in context of AT parser so a user should not issue any AT commands from inside the callback.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 362 * It is recommended to set a flag/event/signal in callback and application can use that to wake up the modem and re-initialize it
wajahat.abbas@u-blox.com 23:eaab8e812a5d 363 *
wajahat.abbas@u-blox.com 23:eaab8e812a5d 364 * application callback for modem coming out of PSM sleep
wajahat.abbas@u-blox.com 23:eaab8e812a5d 365 *
wajahat.abbas@u-blox.com 23:eaab8e812a5d 366 * @param func callback function to be executed when modem is coming out of PSM sleep.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 367 * @param param parameter to be passed to callback function.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 368 */
wajahat.abbas@u-blox.com 23:eaab8e812a5d 369 void attach_cb_psm_coming_out(Callback<void(void*)> func, void *param)
wajahat.abbas@u-blox.com 23:eaab8e812a5d 370 {
wajahat.abbas@u-blox.com 23:eaab8e812a5d 371 _func_psm_coming_out = func;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 372 _cb_param_psm_coming_out = param;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 373 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 374
wajahat.abbas@u-blox.com 23:eaab8e812a5d 375 /** de-register the application callback for modem going in to PSM sleep
wajahat.abbas@u-blox.com 23:eaab8e812a5d 376 *
wajahat.abbas@u-blox.com 23:eaab8e812a5d 377 */
wajahat.abbas@u-blox.com 23:eaab8e812a5d 378 void detach_cb_psm_going_in()
wajahat.abbas@u-blox.com 23:eaab8e812a5d 379 {
wajahat.abbas@u-blox.com 23:eaab8e812a5d 380 _func_psm_going_in = NULL;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 381 _cb_param_psm_going_in = NULL;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 382 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 383
wajahat.abbas@u-blox.com 23:eaab8e812a5d 384 /** de-register application callback for modem coming out of PSM sleep
wajahat.abbas@u-blox.com 23:eaab8e812a5d 385 *
wajahat.abbas@u-blox.com 23:eaab8e812a5d 386 */
wajahat.abbas@u-blox.com 23:eaab8e812a5d 387 void detach_cb_psm_coming_out()
wajahat.abbas@u-blox.com 23:eaab8e812a5d 388 {
wajahat.abbas@u-blox.com 23:eaab8e812a5d 389 _func_psm_coming_out = NULL;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 390 _cb_param_psm_coming_out = NULL;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 391 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 392
wajahat.abbas@u-blox.com 23:eaab8e812a5d 393 /** Enable or disable the 3GPP PSM.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 394 *
wajahat.abbas@u-blox.com 23:eaab8e812a5d 395 * Note: Application should reboot the module after enabling PSM in order to enter PSM state. (reboot_modem())
wajahat.abbas@u-blox.com 23:eaab8e812a5d 396 * Note: Modem can be woken up by toggling the power-on signal. (wakeup_modem())
wajahat.abbas@u-blox.com 23:eaab8e812a5d 397 * Note: When device enters PSM, all connections(PPP, sockets) and settings that are not saved in NV memory(ATE0, CREG etc) are lost.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 398 * host application should be prepared to re-initialize the modem and re-establish the connections.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 399 * Note: PSM is disabled if both periodic_time and active_time are 0.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 400 * Note: Not all variants/firmware versions support PSM URCs and in that case function will return false.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 401 *
wajahat.abbas@u-blox.com 23:eaab8e812a5d 402 * PSM string encoding code is borrowed from AT_CellularPower.cpp
wajahat.abbas@u-blox.com 23:eaab8e812a5d 403 *
wajahat.abbas@u-blox.com 23:eaab8e812a5d 404 * @param periodic_time requested periodic TAU in seconds.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 405 * @param active_time requested active time in seconds.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 406 * @param func callback function to execute when modem goes to sleep
wajahat.abbas@u-blox.com 23:eaab8e812a5d 407 * @param ptr parameter to callback function
wajahat.abbas@u-blox.com 23:eaab8e812a5d 408 * @return True if successful, otherwise false.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 409 */
wajahat.abbas@u-blox.com 23:eaab8e812a5d 410 bool set_power_saving_mode(int periodic_tau, int active_time);
wajahat.abbas@u-blox.com 23:eaab8e812a5d 411
wajahat.abbas@u-blox.com 23:eaab8e812a5d 412 /** Reads the 3GPP PSM status (enabled or disabled) and returns assigned periodic tau and active time values.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 413 *
wajahat.abbas@u-blox.com 23:eaab8e812a5d 414 * @param status 0: PSM disabled, 1: PSM enabled
wajahat.abbas@u-blox.com 23:eaab8e812a5d 415 * @param periodic_tau assigned periodic TAU in seconds.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 416 * @param active_time assigned active time in seconds
wajahat.abbas@u-blox.com 23:eaab8e812a5d 417 * @return True if command successful, otherwise false.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 418 */
wajahat.abbas@u-blox.com 23:eaab8e812a5d 419 bool get_power_saving_mode(int *status, int *periodic_tau, int *active_time);
wajahat.abbas@u-blox.com 23:eaab8e812a5d 420
wajahat.abbas@u-blox.com 23:eaab8e812a5d 421 /** Wake up the modem from PSM. Ref to comment on set_power_saving_mode, application should call init() or connect()
wajahat.abbas@u-blox.com 23:eaab8e812a5d 422 * before making any other API calls.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 423 */
wajahat.abbas@u-blox.com 23:eaab8e812a5d 424 void wakeup_modem();
wajahat.abbas@u-blox.com 23:eaab8e812a5d 425
wajahat.abbas@u-blox.com 23:eaab8e812a5d 426 /** True if the modem is not in PSM sleep
wajahat.abbas@u-blox.com 23:eaab8e812a5d 427 * otherwise false.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 428 */
wajahat.abbas@u-blox.com 23:eaab8e812a5d 429 bool is_modem_awake();
wajahat.abbas@u-blox.com 23:eaab8e812a5d 430 #endif
wajahat.abbas@u-blox.com 23:eaab8e812a5d 431
fahimalavi 26:e4e444cc7b14 432 #ifdef TARGET_UBLOX_C030_R41XM
fahimalavi 26:e4e444cc7b14 433 /** Set discontinuous reception time on cellular device.
fahimalavi 26:e4e444cc7b14 434 * SARA-R404M / SARA-R410M-02B / SARA-R410M-52B / SARA-R412M / SARA-N4 : The <Paging_time_window> parameter cannot be set by means of the set command.
fahimalavi 26:e4e444cc7b14 435 *
fahimalavi 26:e4e444cc7b14 436 *
fahimalavi 26:e4e444cc7b14 437 * @remark See 3GPP TS 27.007 eDRX for details.
fahimalavi 26:e4e444cc7b14 438 *
fahimalavi 26:e4e444cc7b14 439 * @param mode disable or enable the use of eDRX
fahimalavi 26:e4e444cc7b14 440 * @param act_type type of access technology
fahimalavi 26:e4e444cc7b14 441 * @param edrx_value requested edxr value. Extended DRX parameters information element.
fahimalavi 26:e4e444cc7b14 442 *
fahimalavi 26:e4e444cc7b14 443 * @return 0 on success
fahimalavi 26:e4e444cc7b14 444 * 1 on failure
fahimalavi 26:e4e444cc7b14 445 */
fahimalavi 26:e4e444cc7b14 446 int set_receive_period(int mode, tEDRXAccessTechnology act_type, uint8_t edrx_value);
fahimalavi 26:e4e444cc7b14 447
fahimalavi 26:e4e444cc7b14 448 /** Set discontinuous reception time on cellular device.
fahimalavi 26:e4e444cc7b14 449 *
fahimalavi 26:e4e444cc7b14 450 * @remark See 3GPP TS 27.007 eDRX for details.
fahimalavi 26:e4e444cc7b14 451 *
fahimalavi 26:e4e444cc7b14 452 * @param mode disable or enable the use of eDRX
fahimalavi 26:e4e444cc7b14 453 * @param act_type type of access technology
fahimalavi 26:e4e444cc7b14 454 *
fahimalavi 26:e4e444cc7b14 455 * @return 0 on success
fahimalavi 26:e4e444cc7b14 456 * 1 on failure
fahimalavi 26:e4e444cc7b14 457 */
fahimalavi 26:e4e444cc7b14 458 int set_receive_period(int mode, tEDRXAccessTechnology act_type);
fahimalavi 26:e4e444cc7b14 459
fahimalavi 26:e4e444cc7b14 460 /** Set discontinuous reception time on cellular device. (Disable)
fahimalavi 26:e4e444cc7b14 461 *
fahimalavi 26:e4e444cc7b14 462 * @remark See 3GPP TS 27.007 eDRX for details.
fahimalavi 26:e4e444cc7b14 463 *
fahimalavi 26:e4e444cc7b14 464 * @param mode disable or enable the use of eDRX
fahimalavi 26:e4e444cc7b14 465 *
fahimalavi 26:e4e444cc7b14 466 * @return 0 on success
fahimalavi 26:e4e444cc7b14 467 * 1 on failure
fahimalavi 26:e4e444cc7b14 468 */
fahimalavi 26:e4e444cc7b14 469 int set_receive_period(int mode);
fahimalavi 26:e4e444cc7b14 470
fahimalavi 26:e4e444cc7b14 471 /** get discontinuous reception time on cellular device.
fahimalavi 26:e4e444cc7b14 472 *
fahimalavi 26:e4e444cc7b14 473 * @remark See 3GPP TS 27.007 eDRX for details.
fahimalavi 26:e4e444cc7b14 474 *
fahimalavi 26:e4e444cc7b14 475 * @return uint32_t
fahimalavi 26:e4e444cc7b14 476 */
fahimalavi 26:e4e444cc7b14 477 uint32_t get_receive_period();
fahimalavi 30:38230504a646 478
fahimalavi 30:38230504a646 479 /** set band select bitmask
fahimalavi 30:38230504a646 480 *
fahimalavi 30:38230504a646 481 * @param RAT RAT type
fahimalavi 30:38230504a646 482 * @param bitmask bitmask
fahimalavi 30:38230504a646 483 * @return True if successful, otherwise false.
fahimalavi 30:38230504a646 484 */
fahimalavi 30:38230504a646 485 bool set_band_bitmask(RAT rat, uint64_t bitmask);
fahimalavi 31:b0a6a610d114 486
fahimalavi 31:b0a6a610d114 487 /** get band select bitmasks
fahimalavi 31:b0a6a610d114 488 *
fahimalavi 31:b0a6a610d114 489 * @param m1_bitmask pointer to band select bitmask of M1
fahimalavi 31:b0a6a610d114 490 * @param nb1_bitmask pointer to band select bitmask of NB1
fahimalavi 31:b0a6a610d114 491 * @return True if successful, otherwise false.
fahimalavi 31:b0a6a610d114 492 */
fahimalavi 31:b0a6a610d114 493 bool get_band_bitmask(uint64_t *m1_bitmask, uint64_t *nb1_bitmask);
wajahat.abbas@u-blox.com 34:d239824bfb8f 494
wajahat.abbas@u-blox.com 34:d239824bfb8f 495 /** disables the PSM
wajahat.abbas@u-blox.com 34:d239824bfb8f 496 *
wajahat.abbas@u-blox.com 34:d239824bfb8f 497 * @return True if successful, otherwise false.
wajahat.abbas@u-blox.com 34:d239824bfb8f 498 */
wajahat.abbas@u-blox.com 36:2f8ef6ac16dc 499 bool disable_power_saving_mode();
fahimalavi 26:e4e444cc7b14 500 #endif
fahimalavi 26:e4e444cc7b14 501
RobMeades 0:5cffef3371f6 502 protected:
RobMeades 0:5cffef3371f6 503
RobMeades 0:5cffef3371f6 504 #define OUTPUT_ENTER_KEY "\r"
RobMeades 0:5cffef3371f6 505
RobMeades 0:5cffef3371f6 506 #if MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_BUFFER_SIZE
RobMeades 0:5cffef3371f6 507 #define AT_PARSER_BUFFER_SIZE MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_BUFFER_SIZE
RobMeades 0:5cffef3371f6 508 #else
RobMeades 0:5cffef3371f6 509 #define AT_PARSER_BUFFER_SIZE 256
RobMeades 0:5cffef3371f6 510 #endif
RobMeades 0:5cffef3371f6 511
RobMeades 0:5cffef3371f6 512 #if MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_TIMEOUT
RobMeades 0:5cffef3371f6 513 #define AT_PARSER_TIMEOUT MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_TIMEOUT
RobMeades 0:5cffef3371f6 514 #else
RobMeades 0:5cffef3371f6 515 #define AT_PARSER_TIMEOUT 8*1000 // Milliseconds
RobMeades 0:5cffef3371f6 516 #endif
RobMeades 0:5cffef3371f6 517
RobMeades 0:5cffef3371f6 518 /** A string that would not normally be sent by the modem on the AT interface.
RobMeades 0:5cffef3371f6 519 */
RobMeades 0:5cffef3371f6 520 #define UNNATURAL_STRING "\x01"
RobMeades 0:5cffef3371f6 521
RobMeades 0:5cffef3371f6 522 /** Supported u-blox modem variants.
RobMeades 0:5cffef3371f6 523 */
RobMeades 0:5cffef3371f6 524 typedef enum {
RobMeades 0:5cffef3371f6 525 DEV_TYPE_NONE = 0,
RobMeades 0:5cffef3371f6 526 DEV_SARA_G35,
RobMeades 0:5cffef3371f6 527 DEV_LISA_U2,
RobMeades 0:5cffef3371f6 528 DEV_LISA_U2_03S,
RobMeades 0:5cffef3371f6 529 DEV_SARA_U2,
fahim alavi 11:57f64bc518c0 530 DEV_SARA_R4,
RobMeades 0:5cffef3371f6 531 DEV_LEON_G2,
RobMeades 0:5cffef3371f6 532 DEV_TOBY_L2,
RobMeades 0:5cffef3371f6 533 DEV_MPCI_L2
RobMeades 0:5cffef3371f6 534 } DeviceType;
RobMeades 0:5cffef3371f6 535
RobMeades 0:5cffef3371f6 536 /** Network registration status.
RobMeades 0:5cffef3371f6 537 * UBX-13001820 - AT Commands Example Application Note (Section 4.1.4.5).
RobMeades 0:5cffef3371f6 538 */
RobMeades 0:5cffef3371f6 539 typedef enum {
RobMeades 0:5cffef3371f6 540 GSM = 0,
RobMeades 0:5cffef3371f6 541 COMPACT_GSM = 1,
RobMeades 0:5cffef3371f6 542 UTRAN = 2,
RobMeades 0:5cffef3371f6 543 EDGE = 3,
RobMeades 0:5cffef3371f6 544 HSDPA = 4,
RobMeades 0:5cffef3371f6 545 HSUPA = 5,
RobMeades 0:5cffef3371f6 546 HSDPA_HSUPA = 6,
fahimalavi 10:c4281fa79b8f 547 LTE = 7,
fahim alavi 12:aa3cbc3f88c5 548 EC_GSM_IoT = 8,
fahim alavi 12:aa3cbc3f88c5 549 E_UTRAN_NB_S1 = 9
RobMeades 0:5cffef3371f6 550 } RadioAccessNetworkType;
RobMeades 0:5cffef3371f6 551
RobMeades 0:5cffef3371f6 552 /** Info about the modem.
RobMeades 0:5cffef3371f6 553 */
RobMeades 0:5cffef3371f6 554 typedef struct {
RobMeades 0:5cffef3371f6 555 DeviceType dev;
RobMeades 0:5cffef3371f6 556 char iccid[20 + 1]; //!< Integrated Circuit Card ID.
RobMeades 0:5cffef3371f6 557 char imsi[15 + 1]; //!< International Mobile Station Identity.
RobMeades 0:5cffef3371f6 558 char imei[15 + 1]; //!< International Mobile Equipment Identity.
RobMeades 0:5cffef3371f6 559 char meid[18 + 1]; //!< Mobile Equipment IDentifier.
RobMeades 0:5cffef3371f6 560 volatile RadioAccessNetworkType rat; //!< Type of network (e.g. 2G, 3G, LTE).
RobMeades 0:5cffef3371f6 561 volatile NetworkRegistrationStatusCsd reg_status_csd; //!< Circuit switched attach status.
RobMeades 0:5cffef3371f6 562 volatile NetworkRegistrationStatusPsd reg_status_psd; //!< Packet switched attach status.
RobMeades 0:5cffef3371f6 563 volatile NetworkRegistrationStatusEps reg_status_eps; //!< Evolved Packet Switched (e.g. LTE) attach status.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 564 #ifdef TARGET_UBLOX_C030_R412M
wajahat.abbas@u-blox.com 23:eaab8e812a5d 565 volatile ModemPSMState modem_psm_state; //!< last known modem PSM state
wajahat.abbas@u-blox.com 23:eaab8e812a5d 566 #endif
RobMeades 0:5cffef3371f6 567 } DeviceInfo;
RobMeades 0:5cffef3371f6 568
RobMeades 0:5cffef3371f6 569 /* IMPORTANT: the variables below are available to
RobMeades 0:5cffef3371f6 570 * classes that inherit this in order to keep things
RobMeades 0:5cffef3371f6 571 * simple. However, ONLY this class should free
RobMeades 0:5cffef3371f6 572 * any of the pointers, or there will be havoc.
RobMeades 0:5cffef3371f6 573 */
RobMeades 0:5cffef3371f6 574
RobMeades 0:5cffef3371f6 575 /** Point to the instance of the AT parser in use.
RobMeades 0:5cffef3371f6 576 */
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 577 #ifdef TARGET_UBLOX_C030_R41XM
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 578 UbloxATCmdParser *_at;
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 579 #else
RobMeades 0:5cffef3371f6 580 ATCmdParser *_at;
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 581 #endif
RobMeades 0:5cffef3371f6 582
RobMeades 0:5cffef3371f6 583 /** The current AT parser timeout value.
RobMeades 0:5cffef3371f6 584 */
RobMeades 0:5cffef3371f6 585 int _at_timeout;
RobMeades 0:5cffef3371f6 586
RobMeades 0:5cffef3371f6 587 /** File handle used by the AT parser.
RobMeades 0:5cffef3371f6 588 */
RobMeades 0:5cffef3371f6 589 FileHandle *_fh;
RobMeades 0:5cffef3371f6 590
RobMeades 0:5cffef3371f6 591 /** The mutex resource.
RobMeades 0:5cffef3371f6 592 */
RobMeades 0:5cffef3371f6 593 Mutex _mtx;
RobMeades 0:5cffef3371f6 594
RobMeades 0:5cffef3371f6 595 /** General info about the modem as a device.
RobMeades 0:5cffef3371f6 596 */
RobMeades 0:5cffef3371f6 597 DeviceInfo _dev_info;
RobMeades 0:5cffef3371f6 598
RobMeades 0:5cffef3371f6 599 /** The SIM PIN to use.
RobMeades 0:5cffef3371f6 600 */
RobMeades 0:5cffef3371f6 601 const char *_pin;
RobMeades 0:5cffef3371f6 602
RobMeades 0:5cffef3371f6 603 /** Set to true to spit out debug traces.
RobMeades 0:5cffef3371f6 604 */
RobMeades 0:5cffef3371f6 605 bool _debug_trace_on;
rob.meades@u-blox.com 4:2e640a101db1 606
rob.meades@u-blox.com 4:2e640a101db1 607 /** The baud rate to the modem.
rob.meades@u-blox.com 4:2e640a101db1 608 */
rob.meades@u-blox.com 4:2e640a101db1 609 int _baud;
RobMeades 0:5cffef3371f6 610
RobMeades 0:5cffef3371f6 611 /** True if the modem is ready register to the network,
RobMeades 0:5cffef3371f6 612 * otherwise false.
RobMeades 0:5cffef3371f6 613 */
RobMeades 0:5cffef3371f6 614 bool _modem_initialised;
RobMeades 0:5cffef3371f6 615
RobMeades 0:5cffef3371f6 616 /** True it the SIM requires a PIN, otherwise false.
RobMeades 0:5cffef3371f6 617 */
RobMeades 0:5cffef3371f6 618 bool _sim_pin_check_enabled;
RobMeades 0:5cffef3371f6 619
RobMeades 0:5cffef3371f6 620 /** Sets the modem up for powering on
RobMeades 0:5cffef3371f6 621 *
RobMeades 0:5cffef3371f6 622 * modem_init() is equivalent to plugging in the device, e.g., attaching power and serial port.
RobMeades 0:5cffef3371f6 623 * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target.
RobMeades 0:5cffef3371f6 624 */
RobMeades 0:5cffef3371f6 625 virtual void modem_init();
RobMeades 0:5cffef3371f6 626
RobMeades 0:5cffef3371f6 627 /** Sets the modem in unplugged state
RobMeades 0:5cffef3371f6 628 *
RobMeades 0:5cffef3371f6 629 * modem_deinit() will be equivalent to pulling the plug off of the device, i.e., detaching power
RobMeades 0:5cffef3371f6 630 * and serial port. This puts the modem in lowest power state.
RobMeades 0:5cffef3371f6 631 * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target.
RobMeades 0:5cffef3371f6 632 */
RobMeades 0:5cffef3371f6 633 virtual void modem_deinit();
RobMeades 0:5cffef3371f6 634
RobMeades 0:5cffef3371f6 635 /** Powers up the modem
RobMeades 0:5cffef3371f6 636 *
RobMeades 0:5cffef3371f6 637 * modem_power_up() is equivalent to pressing the soft power button.
RobMeades 0:5cffef3371f6 638 * The driver may repeat this if the modem is not responsive to AT commands.
RobMeades 0:5cffef3371f6 639 * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target.
RobMeades 0:5cffef3371f6 640 */
RobMeades 0:5cffef3371f6 641 virtual void modem_power_up();
RobMeades 0:5cffef3371f6 642
RobMeades 0:5cffef3371f6 643 /** Powers down the modem
RobMeades 0:5cffef3371f6 644 *
RobMeades 0:5cffef3371f6 645 * modem_power_down() is equivalent to turning off the modem by button press.
RobMeades 0:5cffef3371f6 646 * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target.
RobMeades 0:5cffef3371f6 647 */
RobMeades 0:5cffef3371f6 648 virtual void modem_power_down();
RobMeades 0:5cffef3371f6 649
RobMeades 0:5cffef3371f6 650 /* Note: constructor and destructor protected so that this
RobMeades 0:5cffef3371f6 651 * class can only ever be inherited, never used directly.
RobMeades 0:5cffef3371f6 652 */
RobMeades 0:5cffef3371f6 653 UbloxCellularBase();
RobMeades 0:5cffef3371f6 654 ~UbloxCellularBase();
RobMeades 0:5cffef3371f6 655
RobMeades 0:5cffef3371f6 656 /** Initialise this class.
RobMeades 0:5cffef3371f6 657 *
RobMeades 0:5cffef3371f6 658 * @param tx the UART TX data pin to which the modem is attached.
RobMeades 0:5cffef3371f6 659 * @param rx the UART RX data pin to which the modem is attached.
RobMeades 0:5cffef3371f6 660 * @param baud the UART baud rate.
RobMeades 0:5cffef3371f6 661 * @param debug_on true to switch AT interface debug on, otherwise false.
RobMeades 0:5cffef3371f6 662 *
RobMeades 0:5cffef3371f6 663 * Note: it would be more natural to do this in the constructor
RobMeades 0:5cffef3371f6 664 * however, to avoid the diamond of death, this class is only
RobMeades 0:5cffef3371f6 665 * every inherited virtually. Classes that are inherited virtually
RobMeades 0:5cffef3371f6 666 * do not get passed parameters in their constructor and hence
RobMeades 0:5cffef3371f6 667 * classInit() must be called separately by the first one to wake
RobMeades 0:5cffef3371f6 668 * the beast.
RobMeades 0:5cffef3371f6 669 */
RobMeades 0:5cffef3371f6 670 void baseClassInit(PinName tx = MDMTXD,
RobMeades 0:5cffef3371f6 671 PinName rx = MDMRXD,
RobMeades 0:5cffef3371f6 672 int baud = MBED_CONF_UBLOX_CELL_BAUD_RATE,
RobMeades 0:5cffef3371f6 673 bool debug_on = false);
RobMeades 0:5cffef3371f6 674
RobMeades 0:5cffef3371f6 675 /** Set the AT parser timeout.
RobMeades 0:5cffef3371f6 676 */
RobMeades 0:5cffef3371f6 677 void at_set_timeout(int timeout);
RobMeades 0:5cffef3371f6 678
RobMeades 0:5cffef3371f6 679 /** Read up to size characters from buf
RobMeades 0:5cffef3371f6 680 * or until the character "end" is reached, overwriting
RobMeades 0:5cffef3371f6 681 * the newline with 0 and ensuring a terminator
RobMeades 0:5cffef3371f6 682 * in all cases.
RobMeades 0:5cffef3371f6 683 *
RobMeades 0:5cffef3371f6 684 * @param buf the buffer to write to.
RobMeades 0:5cffef3371f6 685 * @param size the size of the buffer.
RobMeades 0:5cffef3371f6 686 * @param end the character to stop at.
RobMeades 0:5cffef3371f6 687 * @return the number of characters read,
RobMeades 0:5cffef3371f6 688 * not including the terminator.
RobMeades 0:5cffef3371f6 689 */
RobMeades 0:5cffef3371f6 690 int read_at_to_char(char * buf, int size, char end);
RobMeades 0:5cffef3371f6 691
RobMeades 0:5cffef3371f6 692 /** Powers up the modem.
RobMeades 0:5cffef3371f6 693 *
RobMeades 0:5cffef3371f6 694 * @return true if successful, otherwise false.
RobMeades 0:5cffef3371f6 695 */
RobMeades 0:5cffef3371f6 696 bool power_up();
RobMeades 0:5cffef3371f6 697
wajahat.abbas@u-blox.com 34:d239824bfb8f 698 /** Setup the modem baudrate, echo and flow control
wajahat.abbas@u-blox.com 34:d239824bfb8f 699 *
wajahat.abbas@u-blox.com 34:d239824bfb8f 700 * @return true if successful, otherwise false.
wajahat.abbas@u-blox.com 34:d239824bfb8f 701 */
wajahat.abbas@u-blox.com 34:d239824bfb8f 702 bool setup_modem();
wajahat.abbas@u-blox.com 34:d239824bfb8f 703
wajahat.abbas@u-blox.com 34:d239824bfb8f 704 /** Check if modem is accepting AT commands
wajahat.abbas@u-blox.com 34:d239824bfb8f 705 *
wajahat.abbas@u-blox.com 34:d239824bfb8f 706 * @return true if successful, otherwise false.
wajahat.abbas@u-blox.com 34:d239824bfb8f 707 */
wajahat.abbas@u-blox.com 34:d239824bfb8f 708 bool is_modem_ready();
wajahat.abbas@u-blox.com 34:d239824bfb8f 709
wajahat.abbas@u-blox.com 34:d239824bfb8f 710 /** Powers up the modem and set it up for application use.
wajahat.abbas@u-blox.com 34:d239824bfb8f 711 *
wajahat.abbas@u-blox.com 34:d239824bfb8f 712 * @return true if successful, otherwise false.
wajahat.abbas@u-blox.com 34:d239824bfb8f 713 */
wajahat.abbas@u-blox.com 34:d239824bfb8f 714 bool initialize_modem();
wajahat.abbas@u-blox.com 34:d239824bfb8f 715
RobMeades 0:5cffef3371f6 716 /** Power down the modem.
RobMeades 0:5cffef3371f6 717 */
RobMeades 0:5cffef3371f6 718 void power_down();
RobMeades 0:5cffef3371f6 719
RobMeades 0:5cffef3371f6 720 /** Lock a mutex when accessing the modem.
RobMeades 0:5cffef3371f6 721 */
RobMeades 0:5cffef3371f6 722 void lock(void) { _mtx.lock(); }
RobMeades 0:5cffef3371f6 723
RobMeades 0:5cffef3371f6 724 /** Helper to make sure that lock unlock pair is always balanced
RobMeades 0:5cffef3371f6 725 */
RobMeades 0:5cffef3371f6 726 #define LOCK() { lock()
RobMeades 0:5cffef3371f6 727
RobMeades 0:5cffef3371f6 728 /** Unlock the modem when done accessing it.
RobMeades 0:5cffef3371f6 729 */
RobMeades 0:5cffef3371f6 730 void unlock(void) { _mtx.unlock(); }
RobMeades 0:5cffef3371f6 731
RobMeades 0:5cffef3371f6 732 /** Helper to make sure that lock unlock pair is always balanced
RobMeades 0:5cffef3371f6 733 */
RobMeades 0:5cffef3371f6 734 #define UNLOCK() } unlock()
RobMeades 0:5cffef3371f6 735
RobMeades 0:5cffef3371f6 736 /** Set the device identity in _dev_info
RobMeades 0:5cffef3371f6 737 * based on the ATI string returned by
RobMeades 0:5cffef3371f6 738 * the module.
RobMeades 0:5cffef3371f6 739 *
RobMeades 0:5cffef3371f6 740 * @return true if dev is a known value,
RobMeades 0:5cffef3371f6 741 * otherwise false.
RobMeades 0:5cffef3371f6 742 */
RobMeades 0:5cffef3371f6 743 bool set_device_identity(DeviceType *dev);
RobMeades 0:5cffef3371f6 744
RobMeades 0:5cffef3371f6 745 /** Perform any modem initialisation that is
RobMeades 0:5cffef3371f6 746 * specialised by device type.
RobMeades 0:5cffef3371f6 747 *
RobMeades 0:5cffef3371f6 748 * @return true if successful, otherwise false.
RobMeades 0:5cffef3371f6 749 */
RobMeades 0:5cffef3371f6 750 bool device_init(DeviceType dev);
RobMeades 0:5cffef3371f6 751
RobMeades 0:5cffef3371f6 752 /** Set up the SIM.
RobMeades 0:5cffef3371f6 753 *
RobMeades 0:5cffef3371f6 754 * @return true if successful, otherwiss false.
RobMeades 0:5cffef3371f6 755 */
RobMeades 0:5cffef3371f6 756 bool initialise_sim_card();
RobMeades 0:5cffef3371f6 757
wajahat.abbas@u-blox.com 29:8a38f91009ad 758 #ifdef TARGET_UBLOX_C030_R41XM
wajahat.abbas@u-blox.com 23:eaab8e812a5d 759 /** Converts the given uint to binary string. Fills the given str starting from [0] with the number of bits defined by bit_cnt
wajahat.abbas@u-blox.com 23:eaab8e812a5d 760 * For example uint_to_binary_string(9, str, 10) would fill str "0000001001"
wajahat.abbas@u-blox.com 23:eaab8e812a5d 761 * For example uint_to_binary_string(9, str, 3) would fill str "001"
wajahat.abbas@u-blox.com 23:eaab8e812a5d 762 *
wajahat.abbas@u-blox.com 23:eaab8e812a5d 763 * @param num uint to converts to binary string
wajahat.abbas@u-blox.com 23:eaab8e812a5d 764 * @param str buffer for converted binary string
wajahat.abbas@u-blox.com 23:eaab8e812a5d 765 * @param str_size size of the str buffer
wajahat.abbas@u-blox.com 23:eaab8e812a5d 766 * @param bit_cnt defines how many bits are filled to buffer started from lsb
wajahat.abbas@u-blox.com 23:eaab8e812a5d 767 */
wajahat.abbas@u-blox.com 23:eaab8e812a5d 768 void uint_to_binary_str(uint32_t num, char* str, int str_size, int bit_cnt);
fahimalavi 26:e4e444cc7b14 769
fahimalavi 26:e4e444cc7b14 770 /** Converts the given binary string to uint.
fahimalavi 26:e4e444cc7b14 771 * For example binary_str_to_uint("0000001001", 10) would return 9
fahimalavi 26:e4e444cc7b14 772 *
fahimalavi 26:e4e444cc7b14 773 * @param binary_string binary string from where chars are converted to uint
fahimalavi 26:e4e444cc7b14 774 * @param binary_string_length length of the param binary_string
fahimalavi 26:e4e444cc7b14 775 * @return uint represented by the binary string
fahimalavi 26:e4e444cc7b14 776 */
fahimalavi 26:e4e444cc7b14 777 uint32_t binary_str_to_uint(const char *binary_string, int binary_string_length);
fahimalavi 26:e4e444cc7b14 778
wajahat.abbas@u-blox.com 23:eaab8e812a5d 779 #endif
wajahat.abbas@u-blox.com 23:eaab8e812a5d 780
RobMeades 0:5cffef3371f6 781 private:
RobMeades 0:5cffef3371f6 782
RobMeades 0:5cffef3371f6 783 void set_nwk_reg_status_csd(int status);
RobMeades 0:5cffef3371f6 784 void set_nwk_reg_status_psd(int status);
RobMeades 0:5cffef3371f6 785 void set_nwk_reg_status_eps(int status);
RobMeades 0:5cffef3371f6 786 void set_rat(int AcTStatus);
RobMeades 0:5cffef3371f6 787 bool get_iccid();
RobMeades 0:5cffef3371f6 788 bool get_imsi();
RobMeades 0:5cffef3371f6 789 bool get_imei();
RobMeades 0:5cffef3371f6 790 bool get_meid();
RobMeades 0:5cffef3371f6 791 bool set_sms();
RobMeades 0:5cffef3371f6 792 void parser_abort_cb();
RobMeades 0:5cffef3371f6 793 void CMX_ERROR_URC();
RobMeades 0:5cffef3371f6 794 void CREG_URC();
RobMeades 0:5cffef3371f6 795 void CGREG_URC();
RobMeades 0:5cffef3371f6 796 void CEREG_URC();
RobMeades 0:5cffef3371f6 797 void UMWI_URC();
wajahat.abbas@u-blox.com 23:eaab8e812a5d 798 #ifdef TARGET_UBLOX_C030_R412M
wajahat.abbas@u-blox.com 34:d239824bfb8f 799 bool set_psm_urcs(bool enable);
wajahat.abbas@u-blox.com 23:eaab8e812a5d 800 void UUPSMR_URC();
wajahat.abbas@u-blox.com 23:eaab8e812a5d 801 void *_cb_param_psm_going_in;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 802 Callback<void(void*)> _func_psm_going_in; /**< Callback. */
wajahat.abbas@u-blox.com 23:eaab8e812a5d 803 void *_cb_param_psm_coming_out;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 804 Callback<void(void*)> _func_psm_coming_out; /**< Callback. */
wajahat.abbas@u-blox.com 23:eaab8e812a5d 805 void set_modem_psm_state(int state);
wajahat.abbas@u-blox.com 23:eaab8e812a5d 806 #endif
fahimalavi 26:e4e444cc7b14 807 #ifdef TARGET_UBLOX_C030_R41XM
wajahat.abbas@u-blox.com 34:d239824bfb8f 808 bool _default_profile_is_set;
wajahat.abbas@u-blox.com 36:2f8ef6ac16dc 809 typedef enum {
wajahat.abbas@u-blox.com 36:2f8ef6ac16dc 810 DISABLED = 0,
wajahat.abbas@u-blox.com 36:2f8ef6ac16dc 811 ENABLED = 1,
wajahat.abbas@u-blox.com 36:2f8ef6ac16dc 812 UNKNOWN = 2
wajahat.abbas@u-blox.com 36:2f8ef6ac16dc 813 } PSMStatus;
wajahat.abbas@u-blox.com 36:2f8ef6ac16dc 814 PSMStatus _psm_status;
fahimalavi 26:e4e444cc7b14 815 #endif
RobMeades 0:5cffef3371f6 816 };
RobMeades 0:5cffef3371f6 817
rob.meades@u-blox.com 1:5aaecf2572dc 818 #endif // _UBLOX_CELLULAR_BASE_
RobMeades 0:5cffef3371f6 819