ublox-cellular-base
UbloxCellularBase.h@25:e67d3d9d2e7e, 2019-05-29 (annotated)
- Committer:
- wajahat.abbas@u-blox.com
- Date:
- Wed May 29 12:39:28 2019 +0500
- Revision:
- 25:e67d3d9d2e7e
- Parent:
- 24:e26a6ab0dd75
- Child:
- 26:e4e444cc7b14
Added support for +UPSV (idle mode) for C030_R412M
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RobMeades | 0:5cffef3371f6 | 1 | /* Copyright (c) 2017 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 |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 21 | #include "ubloxATCmdParser.h" |
RobMeades | 0:5cffef3371f6 | 22 | #include "FileHandle.h" |
RobMeades | 0:5cffef3371f6 | 23 | |
RobMeades | 0:5cffef3371f6 | 24 | /********************************************************************** |
RobMeades | 0:5cffef3371f6 | 25 | * CLASSES |
RobMeades | 0:5cffef3371f6 | 26 | **********************************************************************/ |
RobMeades | 0:5cffef3371f6 | 27 | |
RobMeades | 0:5cffef3371f6 | 28 | /** UbloxCellularBase class. |
RobMeades | 0:5cffef3371f6 | 29 | * |
RobMeades | 0:5cffef3371f6 | 30 | * This class provides all the base support for generic u-blox modems |
RobMeades | 0:5cffef3371f6 | 31 | * on C030 and C027 boards: module identification, power-up, network |
RobMeades | 0:5cffef3371f6 | 32 | * registration, etc. |
RobMeades | 0:5cffef3371f6 | 33 | */ |
RobMeades | 0:5cffef3371f6 | 34 | class UbloxCellularBase { |
RobMeades | 0:5cffef3371f6 | 35 | |
RobMeades | 0:5cffef3371f6 | 36 | public: |
RobMeades | 0:5cffef3371f6 | 37 | /** Circuit Switched network registration status (CREG Usage). |
RobMeades | 0:5cffef3371f6 | 38 | * UBX-13001820 - AT Commands Example Application Note (Section 7.10.3). |
RobMeades | 0:5cffef3371f6 | 39 | */ |
RobMeades | 0:5cffef3371f6 | 40 | typedef enum { |
RobMeades | 0:5cffef3371f6 | 41 | CSD_NOT_REGISTERED_NOT_SEARCHING = 0, |
RobMeades | 0:5cffef3371f6 | 42 | CSD_REGISTERED = 1, |
RobMeades | 0:5cffef3371f6 | 43 | CSD_NOT_REGISTERED_SEARCHING = 2, |
RobMeades | 0:5cffef3371f6 | 44 | CSD_REGISTRATION_DENIED = 3, |
RobMeades | 0:5cffef3371f6 | 45 | CSD_UNKNOWN_COVERAGE = 4, |
RobMeades | 0:5cffef3371f6 | 46 | CSD_REGISTERED_ROAMING = 5, |
RobMeades | 0:5cffef3371f6 | 47 | CSD_SMS_ONLY = 6, |
RobMeades | 0:5cffef3371f6 | 48 | CSD_SMS_ONLY_ROAMING = 7, |
RobMeades | 0:5cffef3371f6 | 49 | CSD_CSFB_NOT_PREFERRED = 9 |
RobMeades | 0:5cffef3371f6 | 50 | } NetworkRegistrationStatusCsd; |
RobMeades | 0:5cffef3371f6 | 51 | |
RobMeades | 0:5cffef3371f6 | 52 | /** Packet Switched network registration status (CGREG Usage). |
RobMeades | 0:5cffef3371f6 | 53 | * UBX-13001820 - AT Commands Example Application Note (Section 18.27.3). |
RobMeades | 0:5cffef3371f6 | 54 | */ |
RobMeades | 0:5cffef3371f6 | 55 | typedef enum { |
RobMeades | 0:5cffef3371f6 | 56 | PSD_NOT_REGISTERED_NOT_SEARCHING = 0, |
RobMeades | 0:5cffef3371f6 | 57 | PSD_REGISTERED = 1, |
RobMeades | 0:5cffef3371f6 | 58 | PSD_NOT_REGISTERED_SEARCHING = 2, |
RobMeades | 0:5cffef3371f6 | 59 | PSD_REGISTRATION_DENIED = 3, |
RobMeades | 0:5cffef3371f6 | 60 | PSD_UNKNOWN_COVERAGE = 4, |
RobMeades | 0:5cffef3371f6 | 61 | PSD_REGISTERED_ROAMING = 5, |
RobMeades | 0:5cffef3371f6 | 62 | PSD_EMERGENCY_SERVICES_ONLY = 8 |
RobMeades | 0:5cffef3371f6 | 63 | } NetworkRegistrationStatusPsd; |
RobMeades | 0:5cffef3371f6 | 64 | |
RobMeades | 0:5cffef3371f6 | 65 | /** EPS network registration status (CEREG Usage). |
RobMeades | 0:5cffef3371f6 | 66 | * UBX-13001820 - AT Commands Example Application Note (Section 18.36.3). |
RobMeades | 0:5cffef3371f6 | 67 | */ |
RobMeades | 0:5cffef3371f6 | 68 | typedef enum { |
RobMeades | 0:5cffef3371f6 | 69 | EPS_NOT_REGISTERED_NOT_SEARCHING = 0, |
RobMeades | 0:5cffef3371f6 | 70 | EPS_REGISTERED = 1, |
RobMeades | 0:5cffef3371f6 | 71 | EPS_NOT_REGISTERED_SEARCHING = 2, |
RobMeades | 0:5cffef3371f6 | 72 | EPS_REGISTRATION_DENIED = 3, |
RobMeades | 0:5cffef3371f6 | 73 | EPS_UNKNOWN_COVERAGE = 4, |
RobMeades | 0:5cffef3371f6 | 74 | EPS_REGISTERED_ROAMING = 5, |
RobMeades | 0:5cffef3371f6 | 75 | EPS_EMERGENCY_SERVICES_ONLY = 8 |
RobMeades | 0:5cffef3371f6 | 76 | } NetworkRegistrationStatusEps; |
RobMeades | 0:5cffef3371f6 | 77 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 78 | /** modem PSM states. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 79 | * |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 80 | */ |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 81 | typedef enum { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 82 | AWAKE = 0, |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 83 | ASLEEP = 1 |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 84 | } ModemPSMState; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 85 | |
RobMeades | 0:5cffef3371f6 | 86 | /** Initialise the modem, ready for use. |
RobMeades | 0:5cffef3371f6 | 87 | * |
RobMeades | 0:5cffef3371f6 | 88 | * @param pin PIN for the SIM card. |
RobMeades | 0:5cffef3371f6 | 89 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 90 | */ |
RobMeades | 0:5cffef3371f6 | 91 | bool init(const char *pin = 0); |
RobMeades | 0:5cffef3371f6 | 92 | |
RobMeades | 0:5cffef3371f6 | 93 | /** Perform registration with the network. |
RobMeades | 0:5cffef3371f6 | 94 | * |
RobMeades | 0:5cffef3371f6 | 95 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 96 | */ |
RobMeades | 0:5cffef3371f6 | 97 | bool nwk_registration(); |
RobMeades | 0:5cffef3371f6 | 98 | |
RobMeades | 0:5cffef3371f6 | 99 | /** True if the modem is registered for circuit |
RobMeades | 0:5cffef3371f6 | 100 | * switched data, otherwise false. |
RobMeades | 0:5cffef3371f6 | 101 | */ |
RobMeades | 0:5cffef3371f6 | 102 | bool is_registered_csd(); |
RobMeades | 0:5cffef3371f6 | 103 | |
RobMeades | 0:5cffef3371f6 | 104 | /** True if the modem is registered for packet |
RobMeades | 0:5cffef3371f6 | 105 | * switched data, otherwise false. |
RobMeades | 0:5cffef3371f6 | 106 | */ |
RobMeades | 0:5cffef3371f6 | 107 | bool is_registered_psd(); |
RobMeades | 0:5cffef3371f6 | 108 | |
RobMeades | 0:5cffef3371f6 | 109 | /** True if the modem is registered for enhanced |
RobMeades | 0:5cffef3371f6 | 110 | * packet switched data (i.e. LTE and beyond), |
RobMeades | 0:5cffef3371f6 | 111 | * otherwise false. |
RobMeades | 0:5cffef3371f6 | 112 | */ |
RobMeades | 0:5cffef3371f6 | 113 | bool is_registered_eps(); |
RobMeades | 0:5cffef3371f6 | 114 | |
RobMeades | 0:5cffef3371f6 | 115 | /** Perform deregistration from the network. |
RobMeades | 0:5cffef3371f6 | 116 | * |
RobMeades | 0:5cffef3371f6 | 117 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 118 | */ |
RobMeades | 0:5cffef3371f6 | 119 | bool nwk_deregistration(); |
RobMeades | 0:5cffef3371f6 | 120 | |
RobMeades | 0:5cffef3371f6 | 121 | /** Put the modem into its lowest power state. |
RobMeades | 0:5cffef3371f6 | 122 | */ |
RobMeades | 0:5cffef3371f6 | 123 | void deinit(); |
RobMeades | 0:5cffef3371f6 | 124 | |
RobMeades | 0:5cffef3371f6 | 125 | /** Set the PIN code for the SIM card. |
RobMeades | 0:5cffef3371f6 | 126 | * |
RobMeades | 0:5cffef3371f6 | 127 | * @param pin PIN for the SIM card. |
RobMeades | 0:5cffef3371f6 | 128 | */ |
RobMeades | 0:5cffef3371f6 | 129 | void set_pin(const char *pin); |
RobMeades | 0:5cffef3371f6 | 130 | |
RobMeades | 0:5cffef3371f6 | 131 | /** Enable or disable SIM pin checking. |
RobMeades | 0:5cffef3371f6 | 132 | * |
RobMeades | 0:5cffef3371f6 | 133 | * @param enableNotDisable true if SIM PIN checking is to be enabled, |
RobMeades | 0:5cffef3371f6 | 134 | * otherwise false. |
RobMeades | 0:5cffef3371f6 | 135 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 136 | */ |
RobMeades | 0:5cffef3371f6 | 137 | bool sim_pin_check_enable(bool enableNotDisable); |
RobMeades | 0:5cffef3371f6 | 138 | |
RobMeades | 0:5cffef3371f6 | 139 | /** Change the SIM pin. |
RobMeades | 0:5cffef3371f6 | 140 | * |
RobMeades | 0:5cffef3371f6 | 141 | * @param new_pin the new PIN to use. |
RobMeades | 0:5cffef3371f6 | 142 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 143 | */ |
RobMeades | 0:5cffef3371f6 | 144 | bool change_sim_pin(const char *new_pin); |
RobMeades | 0:5cffef3371f6 | 145 | |
fahim alavi |
11:57f64bc518c0 | 146 | /** Get the IMEI. |
fahim alavi |
11:57f64bc518c0 | 147 | * |
fahim alavi |
11:57f64bc518c0 | 148 | * @return true if successful, otherwise false. |
fahim alavi |
11:57f64bc518c0 | 149 | */ |
RobMeades | 14:e420232ee4e7 | 150 | MBED_DEPRECATED("This method is now replaced by const char * imei(), please use that instead") |
fahim alavi |
12:aa3cbc3f88c5 | 151 | bool get_imei(char *imei_to_send, int size); |
fahim alavi |
11:57f64bc518c0 | 152 | |
RobMeades | 14:e420232ee4e7 | 153 | /** Get the IMEI of the module. |
RobMeades | 14:e420232ee4e7 | 154 | * |
RobMeades | 14:e420232ee4e7 | 155 | * @return a pointer to the IMEI as a null-terminated string. |
RobMeades | 14:e420232ee4e7 | 156 | */ |
RobMeades | 14:e420232ee4e7 | 157 | const char *imei(); |
RobMeades | 14:e420232ee4e7 | 158 | |
RobMeades | 14:e420232ee4e7 | 159 | /** Get the Mobile Equipment ID (which may be the same as the IMEI). |
RobMeades | 14:e420232ee4e7 | 160 | * |
RobMeades | 14:e420232ee4e7 | 161 | * @return a pointer to the Mobile Equipment ID as a null-terminated string. |
RobMeades | 14:e420232ee4e7 | 162 | */ |
RobMeades | 14:e420232ee4e7 | 163 | const char *meid(); |
RobMeades | 14:e420232ee4e7 | 164 | |
RobMeades | 14:e420232ee4e7 | 165 | /** Get the IMSI of the SIM. |
RobMeades | 14:e420232ee4e7 | 166 | * |
RobMeades | 14:e420232ee4e7 | 167 | * @return a pointer to the IMSI as a null-terminated string. |
RobMeades | 14:e420232ee4e7 | 168 | */ |
RobMeades | 14:e420232ee4e7 | 169 | const char *imsi(); |
RobMeades | 14:e420232ee4e7 | 170 | |
RobMeades | 14:e420232ee4e7 | 171 | /** Get the ICCID of the SIM. |
RobMeades | 14:e420232ee4e7 | 172 | * |
RobMeades | 14:e420232ee4e7 | 173 | * @return a pointer to the ICCID as a null-terminated string. |
RobMeades | 14:e420232ee4e7 | 174 | */ |
RobMeades | 14:e420232ee4e7 | 175 | const char *iccid(); |
RobMeades | 14:e420232ee4e7 | 176 | |
RobMeades | 14:e420232ee4e7 | 177 | /** Get the RSSI. |
RobMeades | 14:e420232ee4e7 | 178 | * |
RobMeades | 14:e420232ee4e7 | 179 | * @return the RSSI in dBm. If it is not possible to obtain an |
RobMeades | 14:e420232ee4e7 | 180 | * RSSI reading at the time (e.g. because the modem is in |
RobMeades | 14:e420232ee4e7 | 181 | * data mode rather than AT command mode) then 0 is returned. |
RobMeades | 14:e420232ee4e7 | 182 | */ |
RobMeades | 14:e420232ee4e7 | 183 | int rssi(); |
RobMeades | 14:e420232ee4e7 | 184 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 185 | /** RAT values for +URAT command |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 186 | * R412M only supports value 7 (CatM1), 8 (NB1), and 9 (GPRS) |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 187 | */ |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 188 | typedef enum { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 189 | GSM_GPRS_EGPRS = 0, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 190 | GSM_UMTS = 1, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 191 | UMTS = 2, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 192 | URAT_LTE = 3, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 193 | GSM_UMTS_LTE = 4, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 194 | GSM_LTE = 5, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 195 | UMTS_LTE = 6, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 196 | LTE_CATM1 = 7, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 197 | LTE_CATNB1 = 8, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 198 | GPRS_EGPRS = 9, |
wajahat.abbas@u-blox.com | 22:779971811c46 | 199 | NOT_USED = -1 |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 200 | } RAT; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 201 | |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 202 | /** Module functionality modes. Ref to section 5.3.3 of UBX-13002752 for details. |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 203 | */ |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 204 | typedef enum { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 205 | FUNC_MIN = 0, |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 206 | FUNC_FULL = 1, |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 207 | FUNC_AIRPLANE = 4, |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 208 | FUNC_EN_SIM_TLKT_DEDICATED = 6, |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 209 | FUNC_DS_SIM_TLKT = 7, |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 210 | FUNC_EN_SIM_TLKT_RAW = 9, |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 211 | FUNC_RESET = 15, |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 212 | FUNC_RESET_WITH_SIM = 16, |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 213 | FUNC_MIN_WITH_SIM = 19, |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 214 | FUNC_HALT = 127 |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 215 | } FunctionalityMode; |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 216 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 217 | #ifdef TARGET_UBLOX_C030_R41XM |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 218 | /** Supported MNO profiles for SARA-R4. |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 219 | */ |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 220 | typedef enum { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 221 | SW_DEFAULT = 0, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 222 | SIM_ICCID = 1, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 223 | ATT = 2, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 224 | VERIZON = 3, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 225 | TELSTRA = 4, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 226 | TMO = 5, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 227 | CT = 6, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 228 | VODAFONE = 19, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 229 | TELUS = 21, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 230 | DT = 31, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 231 | STANDARD_EU = 100 |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 232 | } MNOProfile; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 233 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 234 | #if MBED_CONF_UBLOX_CELL_DEFAULT_MNO_PROFILE |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 235 | #define DEFAULT_MNO_PROFILE (MNOProfile)MBED_CONF_UBLOX_CELL_DEFAULT_MNO_PROFILE |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 236 | #else |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 237 | #define DEFAULT_MNO_PROFILE SW_DEFAULT |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 238 | #endif |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 239 | |
wajahat.abbas@u-blox.com | 21:98aea8f49cd8 | 240 | /** Reads the current MNO profile from modem and sets it to user specified profile. |
wajahat.abbas@u-blox.com | 21:98aea8f49cd8 | 241 | * User can also specify profile in mbed_lib.json file and call set_mno_profile without any arguments. |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 242 | * |
wajahat.abbas@u-blox.com | 21:98aea8f49cd8 | 243 | * 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 | 21:98aea8f49cd8 | 244 | * |
wajahat.abbas@u-blox.com | 21:98aea8f49cd8 | 245 | * @param profile MNO profile to use |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 246 | * @return true if operation was successful, false if there was an error |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 247 | */ |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 248 | bool set_mno_profile(MNOProfile profile = DEFAULT_MNO_PROFILE); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 249 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 250 | /** Get current MNO profile. |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 251 | * |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 252 | * @param profile pointer to variable that can hold the value for returned profile |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 253 | * @return true if operation was successful, false if there was an error |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 254 | */ |
wajahat.abbas@u-blox.com | 22:779971811c46 | 255 | bool get_mno_profile(int *profile); |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 256 | |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 257 | /** Enable or disable the UPSV Power Saving Mode. |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 258 | * |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 259 | * @param idle_mode_value 1: enable idle mode |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 260 | * 0: disable idle mode |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 261 | * @return true if successful, otherwise false. |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 262 | */ |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 263 | bool set_idle_mode(bool enable = false); |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 264 | |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 265 | /** Queries the modem for idle mode status. |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 266 | * |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 267 | * @param status pointer to variable that can hold the value for idle mode status |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 268 | * 1: enabled |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 269 | * 0: disabled |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 270 | * @return true if successful, otherwise false. |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 271 | */ |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 272 | bool get_idle_mode(int *status); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 273 | #endif |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 274 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 275 | /** Set Radio Access Technology on modem. |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 276 | * |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 277 | * 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 | 278 | * |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 279 | * @param selected_rat Radio Access Technology to use |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 280 | * @param preferred_rat Radio Access Technology to use if selected_rat is not available |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 281 | * @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 | 282 | * |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 283 | * @return true if successful, otherwise false. |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 284 | */ |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 285 | 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 | 286 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 287 | /** 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 | 288 | * |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 289 | * @param selected_rat pointer to variable that can hold the value for selected_rat |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 290 | * @param preferred_rat pointer to variable that can hold the value for preferred_rat |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 291 | * @param second_preferred_rat pointer to variable that can hold the value for second_preferred_rat |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 292 | * |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 293 | * Note: NOT_USED will be returned in the variables if dual or tri modes are not enabled. |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 294 | * |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 295 | * @return true if successful, otherwise false. |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 296 | */ |
wajahat.abbas@u-blox.com | 22:779971811c46 | 297 | bool get_modem_rat(int *selected_rat, int *preferred_rat, int *second_preferred_rat); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 298 | |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 299 | /** Sets the modem to specified functionality mode. |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 300 | * |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 301 | * @return true if successful, otherwise false. |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 302 | */ |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 303 | bool set_functionality_mode(FunctionalityMode mode); |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 304 | |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 305 | /** Get the modem functionality mode |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 306 | * |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 307 | * @return true if successful, otherwise false. |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 308 | */ |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 309 | bool get_functionality_mode(int *mode); |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 310 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 311 | /** 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 | 312 | * |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 313 | * @return true if successful, otherwise false. |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 314 | */ |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 315 | bool reboot_modem(); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 316 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 317 | #ifdef TARGET_UBLOX_C030_R412M |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 318 | /** 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 | 319 | * 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 | 320 | * |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 321 | * application callback for modem going in to PSM sleep |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 322 | * |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 323 | * @param func callback function to be executed when modem is going in to PSM sleep |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 324 | * @param param parameter to be passed to callback function. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 325 | */ |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 326 | void attach_cb_psm_going_in(Callback<void(void*)> func, void *param) |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 327 | { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 328 | _func_psm_going_in = func; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 329 | _cb_param_psm_going_in = param; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 330 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 331 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 332 | /** 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 | 333 | * 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 | 334 | * |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 335 | * application callback for modem coming out of PSM sleep |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 336 | * |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 337 | * @param func callback function to be executed when modem is coming out of PSM sleep. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 338 | * @param param parameter to be passed to callback function. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 339 | */ |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 340 | void attach_cb_psm_coming_out(Callback<void(void*)> func, void *param) |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 341 | { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 342 | _func_psm_coming_out = func; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 343 | _cb_param_psm_coming_out = param; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 344 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 345 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 346 | /** de-register the application callback for modem going in to PSM sleep |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 347 | * |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 348 | */ |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 349 | void detach_cb_psm_going_in() |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 350 | { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 351 | _func_psm_going_in = NULL; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 352 | _cb_param_psm_going_in = NULL; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 353 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 354 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 355 | /** de-register application callback for modem coming out of PSM sleep |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 356 | * |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 357 | */ |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 358 | void detach_cb_psm_coming_out() |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 359 | { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 360 | _func_psm_coming_out = NULL; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 361 | _cb_param_psm_coming_out = NULL; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 362 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 363 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 364 | /** Enable or disable the 3GPP PSM. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 365 | * |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 366 | * Note: Application should reboot the module after enabling PSM in order to enter PSM state. (reboot_modem()) |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 367 | * Note: Modem can be woken up by toggling the power-on signal. (wakeup_modem()) |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 368 | * 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 | 369 | * host application should be prepared to re-initialize the modem and re-establish the connections. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 370 | * Note: PSM is disabled if both periodic_time and active_time are 0. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 371 | * Note: Not all variants/firmware versions support PSM URCs and in that case function will return false. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 372 | * |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 373 | * PSM string encoding code is borrowed from AT_CellularPower.cpp |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 374 | * |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 375 | * @param periodic_time requested periodic TAU in seconds. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 376 | * @param active_time requested active time in seconds. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 377 | * @param func callback function to execute when modem goes to sleep |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 378 | * @param ptr parameter to callback function |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 379 | * @return True if successful, otherwise false. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 380 | */ |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 381 | bool set_power_saving_mode(int periodic_tau, int active_time); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 382 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 383 | /** Reads the 3GPP PSM status (enabled or disabled) and returns assigned periodic tau and active time values. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 384 | * |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 385 | * @param status 0: PSM disabled, 1: PSM enabled |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 386 | * @param periodic_tau assigned periodic TAU in seconds. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 387 | * @param active_time assigned active time in seconds |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 388 | * @return True if command successful, otherwise false. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 389 | */ |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 390 | bool get_power_saving_mode(int *status, int *periodic_tau, int *active_time); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 391 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 392 | /** 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 | 393 | * before making any other API calls. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 394 | */ |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 395 | void wakeup_modem(); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 396 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 397 | /** True if the modem is not in PSM sleep |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 398 | * otherwise false. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 399 | */ |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 400 | bool is_modem_awake(); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 401 | #endif |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 402 | |
RobMeades | 0:5cffef3371f6 | 403 | protected: |
RobMeades | 0:5cffef3371f6 | 404 | |
RobMeades | 0:5cffef3371f6 | 405 | #define OUTPUT_ENTER_KEY "\r" |
RobMeades | 0:5cffef3371f6 | 406 | |
RobMeades | 0:5cffef3371f6 | 407 | #if MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_BUFFER_SIZE |
RobMeades | 0:5cffef3371f6 | 408 | #define AT_PARSER_BUFFER_SIZE MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_BUFFER_SIZE |
RobMeades | 0:5cffef3371f6 | 409 | #else |
RobMeades | 0:5cffef3371f6 | 410 | #define AT_PARSER_BUFFER_SIZE 256 |
RobMeades | 0:5cffef3371f6 | 411 | #endif |
RobMeades | 0:5cffef3371f6 | 412 | |
RobMeades | 0:5cffef3371f6 | 413 | #if MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_TIMEOUT |
RobMeades | 0:5cffef3371f6 | 414 | #define AT_PARSER_TIMEOUT MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_TIMEOUT |
RobMeades | 0:5cffef3371f6 | 415 | #else |
RobMeades | 0:5cffef3371f6 | 416 | #define AT_PARSER_TIMEOUT 8*1000 // Milliseconds |
RobMeades | 0:5cffef3371f6 | 417 | #endif |
RobMeades | 0:5cffef3371f6 | 418 | |
RobMeades | 0:5cffef3371f6 | 419 | /** A string that would not normally be sent by the modem on the AT interface. |
RobMeades | 0:5cffef3371f6 | 420 | */ |
RobMeades | 0:5cffef3371f6 | 421 | #define UNNATURAL_STRING "\x01" |
RobMeades | 0:5cffef3371f6 | 422 | |
RobMeades | 0:5cffef3371f6 | 423 | /** Supported u-blox modem variants. |
RobMeades | 0:5cffef3371f6 | 424 | */ |
RobMeades | 0:5cffef3371f6 | 425 | typedef enum { |
RobMeades | 0:5cffef3371f6 | 426 | DEV_TYPE_NONE = 0, |
RobMeades | 0:5cffef3371f6 | 427 | DEV_SARA_G35, |
RobMeades | 0:5cffef3371f6 | 428 | DEV_LISA_U2, |
RobMeades | 0:5cffef3371f6 | 429 | DEV_LISA_U2_03S, |
RobMeades | 0:5cffef3371f6 | 430 | DEV_SARA_U2, |
fahim alavi |
11:57f64bc518c0 | 431 | DEV_SARA_R4, |
RobMeades | 0:5cffef3371f6 | 432 | DEV_LEON_G2, |
RobMeades | 0:5cffef3371f6 | 433 | DEV_TOBY_L2, |
RobMeades | 0:5cffef3371f6 | 434 | DEV_MPCI_L2 |
RobMeades | 0:5cffef3371f6 | 435 | } DeviceType; |
RobMeades | 0:5cffef3371f6 | 436 | |
RobMeades | 0:5cffef3371f6 | 437 | /** Network registration status. |
RobMeades | 0:5cffef3371f6 | 438 | * UBX-13001820 - AT Commands Example Application Note (Section 4.1.4.5). |
RobMeades | 0:5cffef3371f6 | 439 | */ |
RobMeades | 0:5cffef3371f6 | 440 | typedef enum { |
RobMeades | 0:5cffef3371f6 | 441 | GSM = 0, |
RobMeades | 0:5cffef3371f6 | 442 | COMPACT_GSM = 1, |
RobMeades | 0:5cffef3371f6 | 443 | UTRAN = 2, |
RobMeades | 0:5cffef3371f6 | 444 | EDGE = 3, |
RobMeades | 0:5cffef3371f6 | 445 | HSDPA = 4, |
RobMeades | 0:5cffef3371f6 | 446 | HSUPA = 5, |
RobMeades | 0:5cffef3371f6 | 447 | HSDPA_HSUPA = 6, |
fahimalavi | 10:c4281fa79b8f | 448 | LTE = 7, |
fahim alavi |
12:aa3cbc3f88c5 | 449 | EC_GSM_IoT = 8, |
fahim alavi |
12:aa3cbc3f88c5 | 450 | E_UTRAN_NB_S1 = 9 |
RobMeades | 0:5cffef3371f6 | 451 | } RadioAccessNetworkType; |
RobMeades | 0:5cffef3371f6 | 452 | |
RobMeades | 0:5cffef3371f6 | 453 | /** Info about the modem. |
RobMeades | 0:5cffef3371f6 | 454 | */ |
RobMeades | 0:5cffef3371f6 | 455 | typedef struct { |
RobMeades | 0:5cffef3371f6 | 456 | DeviceType dev; |
RobMeades | 0:5cffef3371f6 | 457 | char iccid[20 + 1]; //!< Integrated Circuit Card ID. |
RobMeades | 0:5cffef3371f6 | 458 | char imsi[15 + 1]; //!< International Mobile Station Identity. |
RobMeades | 0:5cffef3371f6 | 459 | char imei[15 + 1]; //!< International Mobile Equipment Identity. |
RobMeades | 0:5cffef3371f6 | 460 | char meid[18 + 1]; //!< Mobile Equipment IDentifier. |
RobMeades | 0:5cffef3371f6 | 461 | volatile RadioAccessNetworkType rat; //!< Type of network (e.g. 2G, 3G, LTE). |
RobMeades | 0:5cffef3371f6 | 462 | volatile NetworkRegistrationStatusCsd reg_status_csd; //!< Circuit switched attach status. |
RobMeades | 0:5cffef3371f6 | 463 | volatile NetworkRegistrationStatusPsd reg_status_psd; //!< Packet switched attach status. |
RobMeades | 0:5cffef3371f6 | 464 | volatile NetworkRegistrationStatusEps reg_status_eps; //!< Evolved Packet Switched (e.g. LTE) attach status. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 465 | #ifdef TARGET_UBLOX_C030_R412M |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 466 | volatile ModemPSMState modem_psm_state; //!< last known modem PSM state |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 467 | #endif |
RobMeades | 0:5cffef3371f6 | 468 | } DeviceInfo; |
RobMeades | 0:5cffef3371f6 | 469 | |
RobMeades | 0:5cffef3371f6 | 470 | /* IMPORTANT: the variables below are available to |
RobMeades | 0:5cffef3371f6 | 471 | * classes that inherit this in order to keep things |
RobMeades | 0:5cffef3371f6 | 472 | * simple. However, ONLY this class should free |
RobMeades | 0:5cffef3371f6 | 473 | * any of the pointers, or there will be havoc. |
RobMeades | 0:5cffef3371f6 | 474 | */ |
RobMeades | 0:5cffef3371f6 | 475 | |
RobMeades | 0:5cffef3371f6 | 476 | /** Point to the instance of the AT parser in use. |
RobMeades | 0:5cffef3371f6 | 477 | */ |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 478 | #ifdef TARGET_UBLOX_C030_R41XM |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 479 | UbloxATCmdParser *_at; |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 480 | #else |
RobMeades | 0:5cffef3371f6 | 481 | ATCmdParser *_at; |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 482 | #endif |
RobMeades | 0:5cffef3371f6 | 483 | |
RobMeades | 0:5cffef3371f6 | 484 | /** The current AT parser timeout value. |
RobMeades | 0:5cffef3371f6 | 485 | */ |
RobMeades | 0:5cffef3371f6 | 486 | int _at_timeout; |
RobMeades | 0:5cffef3371f6 | 487 | |
RobMeades | 0:5cffef3371f6 | 488 | /** File handle used by the AT parser. |
RobMeades | 0:5cffef3371f6 | 489 | */ |
RobMeades | 0:5cffef3371f6 | 490 | FileHandle *_fh; |
RobMeades | 0:5cffef3371f6 | 491 | |
RobMeades | 0:5cffef3371f6 | 492 | /** The mutex resource. |
RobMeades | 0:5cffef3371f6 | 493 | */ |
RobMeades | 0:5cffef3371f6 | 494 | Mutex _mtx; |
RobMeades | 0:5cffef3371f6 | 495 | |
RobMeades | 0:5cffef3371f6 | 496 | /** General info about the modem as a device. |
RobMeades | 0:5cffef3371f6 | 497 | */ |
RobMeades | 0:5cffef3371f6 | 498 | DeviceInfo _dev_info; |
RobMeades | 0:5cffef3371f6 | 499 | |
RobMeades | 0:5cffef3371f6 | 500 | /** The SIM PIN to use. |
RobMeades | 0:5cffef3371f6 | 501 | */ |
RobMeades | 0:5cffef3371f6 | 502 | const char *_pin; |
RobMeades | 0:5cffef3371f6 | 503 | |
RobMeades | 0:5cffef3371f6 | 504 | /** Set to true to spit out debug traces. |
RobMeades | 0:5cffef3371f6 | 505 | */ |
RobMeades | 0:5cffef3371f6 | 506 | bool _debug_trace_on; |
rob.meades@u-blox.com | 4:2e640a101db1 | 507 | |
rob.meades@u-blox.com | 4:2e640a101db1 | 508 | /** The baud rate to the modem. |
rob.meades@u-blox.com | 4:2e640a101db1 | 509 | */ |
rob.meades@u-blox.com | 4:2e640a101db1 | 510 | int _baud; |
RobMeades | 0:5cffef3371f6 | 511 | |
RobMeades | 0:5cffef3371f6 | 512 | /** True if the modem is ready register to the network, |
RobMeades | 0:5cffef3371f6 | 513 | * otherwise false. |
RobMeades | 0:5cffef3371f6 | 514 | */ |
RobMeades | 0:5cffef3371f6 | 515 | bool _modem_initialised; |
RobMeades | 0:5cffef3371f6 | 516 | |
RobMeades | 0:5cffef3371f6 | 517 | /** True it the SIM requires a PIN, otherwise false. |
RobMeades | 0:5cffef3371f6 | 518 | */ |
RobMeades | 0:5cffef3371f6 | 519 | bool _sim_pin_check_enabled; |
RobMeades | 0:5cffef3371f6 | 520 | |
RobMeades | 0:5cffef3371f6 | 521 | /** Sets the modem up for powering on |
RobMeades | 0:5cffef3371f6 | 522 | * |
RobMeades | 0:5cffef3371f6 | 523 | * modem_init() is equivalent to plugging in the device, e.g., attaching power and serial port. |
RobMeades | 0:5cffef3371f6 | 524 | * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target. |
RobMeades | 0:5cffef3371f6 | 525 | */ |
RobMeades | 0:5cffef3371f6 | 526 | virtual void modem_init(); |
RobMeades | 0:5cffef3371f6 | 527 | |
RobMeades | 0:5cffef3371f6 | 528 | /** Sets the modem in unplugged state |
RobMeades | 0:5cffef3371f6 | 529 | * |
RobMeades | 0:5cffef3371f6 | 530 | * modem_deinit() will be equivalent to pulling the plug off of the device, i.e., detaching power |
RobMeades | 0:5cffef3371f6 | 531 | * and serial port. This puts the modem in lowest power state. |
RobMeades | 0:5cffef3371f6 | 532 | * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target. |
RobMeades | 0:5cffef3371f6 | 533 | */ |
RobMeades | 0:5cffef3371f6 | 534 | virtual void modem_deinit(); |
RobMeades | 0:5cffef3371f6 | 535 | |
RobMeades | 0:5cffef3371f6 | 536 | /** Powers up the modem |
RobMeades | 0:5cffef3371f6 | 537 | * |
RobMeades | 0:5cffef3371f6 | 538 | * modem_power_up() is equivalent to pressing the soft power button. |
RobMeades | 0:5cffef3371f6 | 539 | * The driver may repeat this if the modem is not responsive to AT commands. |
RobMeades | 0:5cffef3371f6 | 540 | * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target. |
RobMeades | 0:5cffef3371f6 | 541 | */ |
RobMeades | 0:5cffef3371f6 | 542 | virtual void modem_power_up(); |
RobMeades | 0:5cffef3371f6 | 543 | |
RobMeades | 0:5cffef3371f6 | 544 | /** Powers down the modem |
RobMeades | 0:5cffef3371f6 | 545 | * |
RobMeades | 0:5cffef3371f6 | 546 | * modem_power_down() is equivalent to turning off the modem by button press. |
RobMeades | 0:5cffef3371f6 | 547 | * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target. |
RobMeades | 0:5cffef3371f6 | 548 | */ |
RobMeades | 0:5cffef3371f6 | 549 | virtual void modem_power_down(); |
RobMeades | 0:5cffef3371f6 | 550 | |
RobMeades | 0:5cffef3371f6 | 551 | /* Note: constructor and destructor protected so that this |
RobMeades | 0:5cffef3371f6 | 552 | * class can only ever be inherited, never used directly. |
RobMeades | 0:5cffef3371f6 | 553 | */ |
RobMeades | 0:5cffef3371f6 | 554 | UbloxCellularBase(); |
RobMeades | 0:5cffef3371f6 | 555 | ~UbloxCellularBase(); |
RobMeades | 0:5cffef3371f6 | 556 | |
RobMeades | 0:5cffef3371f6 | 557 | /** Initialise this class. |
RobMeades | 0:5cffef3371f6 | 558 | * |
RobMeades | 0:5cffef3371f6 | 559 | * @param tx the UART TX data pin to which the modem is attached. |
RobMeades | 0:5cffef3371f6 | 560 | * @param rx the UART RX data pin to which the modem is attached. |
RobMeades | 0:5cffef3371f6 | 561 | * @param baud the UART baud rate. |
RobMeades | 0:5cffef3371f6 | 562 | * @param debug_on true to switch AT interface debug on, otherwise false. |
RobMeades | 0:5cffef3371f6 | 563 | * |
RobMeades | 0:5cffef3371f6 | 564 | * Note: it would be more natural to do this in the constructor |
RobMeades | 0:5cffef3371f6 | 565 | * however, to avoid the diamond of death, this class is only |
RobMeades | 0:5cffef3371f6 | 566 | * every inherited virtually. Classes that are inherited virtually |
RobMeades | 0:5cffef3371f6 | 567 | * do not get passed parameters in their constructor and hence |
RobMeades | 0:5cffef3371f6 | 568 | * classInit() must be called separately by the first one to wake |
RobMeades | 0:5cffef3371f6 | 569 | * the beast. |
RobMeades | 0:5cffef3371f6 | 570 | */ |
RobMeades | 0:5cffef3371f6 | 571 | void baseClassInit(PinName tx = MDMTXD, |
RobMeades | 0:5cffef3371f6 | 572 | PinName rx = MDMRXD, |
RobMeades | 0:5cffef3371f6 | 573 | int baud = MBED_CONF_UBLOX_CELL_BAUD_RATE, |
RobMeades | 0:5cffef3371f6 | 574 | bool debug_on = false); |
RobMeades | 0:5cffef3371f6 | 575 | |
RobMeades | 0:5cffef3371f6 | 576 | /** Set the AT parser timeout. |
RobMeades | 0:5cffef3371f6 | 577 | */ |
RobMeades | 0:5cffef3371f6 | 578 | void at_set_timeout(int timeout); |
RobMeades | 0:5cffef3371f6 | 579 | |
RobMeades | 0:5cffef3371f6 | 580 | /** Read up to size characters from buf |
RobMeades | 0:5cffef3371f6 | 581 | * or until the character "end" is reached, overwriting |
RobMeades | 0:5cffef3371f6 | 582 | * the newline with 0 and ensuring a terminator |
RobMeades | 0:5cffef3371f6 | 583 | * in all cases. |
RobMeades | 0:5cffef3371f6 | 584 | * |
RobMeades | 0:5cffef3371f6 | 585 | * @param buf the buffer to write to. |
RobMeades | 0:5cffef3371f6 | 586 | * @param size the size of the buffer. |
RobMeades | 0:5cffef3371f6 | 587 | * @param end the character to stop at. |
RobMeades | 0:5cffef3371f6 | 588 | * @return the number of characters read, |
RobMeades | 0:5cffef3371f6 | 589 | * not including the terminator. |
RobMeades | 0:5cffef3371f6 | 590 | */ |
RobMeades | 0:5cffef3371f6 | 591 | int read_at_to_char(char * buf, int size, char end); |
RobMeades | 0:5cffef3371f6 | 592 | |
RobMeades | 0:5cffef3371f6 | 593 | /** Powers up the modem. |
RobMeades | 0:5cffef3371f6 | 594 | * |
RobMeades | 0:5cffef3371f6 | 595 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 596 | */ |
RobMeades | 0:5cffef3371f6 | 597 | bool power_up(); |
RobMeades | 0:5cffef3371f6 | 598 | |
RobMeades | 0:5cffef3371f6 | 599 | /** Power down the modem. |
RobMeades | 0:5cffef3371f6 | 600 | */ |
RobMeades | 0:5cffef3371f6 | 601 | void power_down(); |
RobMeades | 0:5cffef3371f6 | 602 | |
RobMeades | 0:5cffef3371f6 | 603 | /** Lock a mutex when accessing the modem. |
RobMeades | 0:5cffef3371f6 | 604 | */ |
RobMeades | 0:5cffef3371f6 | 605 | void lock(void) { _mtx.lock(); } |
RobMeades | 0:5cffef3371f6 | 606 | |
RobMeades | 0:5cffef3371f6 | 607 | /** Helper to make sure that lock unlock pair is always balanced |
RobMeades | 0:5cffef3371f6 | 608 | */ |
RobMeades | 0:5cffef3371f6 | 609 | #define LOCK() { lock() |
RobMeades | 0:5cffef3371f6 | 610 | |
RobMeades | 0:5cffef3371f6 | 611 | /** Unlock the modem when done accessing it. |
RobMeades | 0:5cffef3371f6 | 612 | */ |
RobMeades | 0:5cffef3371f6 | 613 | void unlock(void) { _mtx.unlock(); } |
RobMeades | 0:5cffef3371f6 | 614 | |
RobMeades | 0:5cffef3371f6 | 615 | /** Helper to make sure that lock unlock pair is always balanced |
RobMeades | 0:5cffef3371f6 | 616 | */ |
RobMeades | 0:5cffef3371f6 | 617 | #define UNLOCK() } unlock() |
RobMeades | 0:5cffef3371f6 | 618 | |
RobMeades | 0:5cffef3371f6 | 619 | /** Set the device identity in _dev_info |
RobMeades | 0:5cffef3371f6 | 620 | * based on the ATI string returned by |
RobMeades | 0:5cffef3371f6 | 621 | * the module. |
RobMeades | 0:5cffef3371f6 | 622 | * |
RobMeades | 0:5cffef3371f6 | 623 | * @return true if dev is a known value, |
RobMeades | 0:5cffef3371f6 | 624 | * otherwise false. |
RobMeades | 0:5cffef3371f6 | 625 | */ |
RobMeades | 0:5cffef3371f6 | 626 | bool set_device_identity(DeviceType *dev); |
RobMeades | 0:5cffef3371f6 | 627 | |
RobMeades | 0:5cffef3371f6 | 628 | /** Perform any modem initialisation that is |
RobMeades | 0:5cffef3371f6 | 629 | * specialised by device type. |
RobMeades | 0:5cffef3371f6 | 630 | * |
RobMeades | 0:5cffef3371f6 | 631 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 632 | */ |
RobMeades | 0:5cffef3371f6 | 633 | bool device_init(DeviceType dev); |
RobMeades | 0:5cffef3371f6 | 634 | |
RobMeades | 0:5cffef3371f6 | 635 | /** Set up the SIM. |
RobMeades | 0:5cffef3371f6 | 636 | * |
RobMeades | 0:5cffef3371f6 | 637 | * @return true if successful, otherwiss false. |
RobMeades | 0:5cffef3371f6 | 638 | */ |
RobMeades | 0:5cffef3371f6 | 639 | bool initialise_sim_card(); |
RobMeades | 0:5cffef3371f6 | 640 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 641 | #ifdef TARGET_UBLOX_C030_R412M |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 642 | /** 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 | 643 | * For example uint_to_binary_string(9, str, 10) would fill str "0000001001" |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 644 | * For example uint_to_binary_string(9, str, 3) would fill str "001" |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 645 | * |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 646 | * @param num uint to converts to binary string |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 647 | * @param str buffer for converted binary string |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 648 | * @param str_size size of the str buffer |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 649 | * @param bit_cnt defines how many bits are filled to buffer started from lsb |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 650 | */ |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 651 | void uint_to_binary_str(uint32_t num, char* str, int str_size, int bit_cnt); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 652 | #endif |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 653 | |
RobMeades | 0:5cffef3371f6 | 654 | private: |
RobMeades | 0:5cffef3371f6 | 655 | |
RobMeades | 0:5cffef3371f6 | 656 | void set_nwk_reg_status_csd(int status); |
RobMeades | 0:5cffef3371f6 | 657 | void set_nwk_reg_status_psd(int status); |
RobMeades | 0:5cffef3371f6 | 658 | void set_nwk_reg_status_eps(int status); |
RobMeades | 0:5cffef3371f6 | 659 | void set_rat(int AcTStatus); |
RobMeades | 0:5cffef3371f6 | 660 | bool get_iccid(); |
RobMeades | 0:5cffef3371f6 | 661 | bool get_imsi(); |
RobMeades | 0:5cffef3371f6 | 662 | bool get_imei(); |
RobMeades | 0:5cffef3371f6 | 663 | bool get_meid(); |
RobMeades | 0:5cffef3371f6 | 664 | bool set_sms(); |
RobMeades | 0:5cffef3371f6 | 665 | void parser_abort_cb(); |
RobMeades | 0:5cffef3371f6 | 666 | void CMX_ERROR_URC(); |
RobMeades | 0:5cffef3371f6 | 667 | void CREG_URC(); |
RobMeades | 0:5cffef3371f6 | 668 | void CGREG_URC(); |
RobMeades | 0:5cffef3371f6 | 669 | void CEREG_URC(); |
RobMeades | 0:5cffef3371f6 | 670 | void UMWI_URC(); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 671 | #ifdef TARGET_UBLOX_C030_R412M |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 672 | void UUPSMR_URC(); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 673 | bool _psm_status; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 674 | void *_cb_param_psm_going_in; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 675 | Callback<void(void*)> _func_psm_going_in; /**< Callback. */ |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 676 | void *_cb_param_psm_coming_out; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 677 | Callback<void(void*)> _func_psm_coming_out; /**< Callback. */ |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 678 | void set_modem_psm_state(int state); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 679 | #endif |
RobMeades | 0:5cffef3371f6 | 680 | }; |
RobMeades | 0:5cffef3371f6 | 681 | |
rob.meades@u-blox.com | 1:5aaecf2572dc | 682 | #endif // _UBLOX_CELLULAR_BASE_ |
RobMeades | 0:5cffef3371f6 | 683 |