ublox-cellular-base_R4_PR
UbloxCellularBase.h@22:779971811c46, 2019-04-10 (annotated)
- Committer:
- wajahat.abbas@u-blox.com
- Date:
- Wed Apr 10 12:05:55 2019 +0500
- Revision:
- 22:779971811c46
- Parent:
- 21:98aea8f49cd8
- Child:
- 23:eaab8e812a5d
Changed arguments type to int for get uart/mno methods
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 |
RobMeades | 0:5cffef3371f6 | 21 | #include "ATCmdParser.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 | |
RobMeades | 0:5cffef3371f6 | 78 | /** Initialise the modem, ready for use. |
RobMeades | 0:5cffef3371f6 | 79 | * |
RobMeades | 0:5cffef3371f6 | 80 | * @param pin PIN for the SIM card. |
RobMeades | 0:5cffef3371f6 | 81 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 82 | */ |
RobMeades | 0:5cffef3371f6 | 83 | bool init(const char *pin = 0); |
RobMeades | 0:5cffef3371f6 | 84 | |
RobMeades | 0:5cffef3371f6 | 85 | /** Perform registration with the network. |
RobMeades | 0:5cffef3371f6 | 86 | * |
RobMeades | 0:5cffef3371f6 | 87 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 88 | */ |
RobMeades | 0:5cffef3371f6 | 89 | bool nwk_registration(); |
RobMeades | 0:5cffef3371f6 | 90 | |
RobMeades | 0:5cffef3371f6 | 91 | /** True if the modem is registered for circuit |
RobMeades | 0:5cffef3371f6 | 92 | * switched data, otherwise false. |
RobMeades | 0:5cffef3371f6 | 93 | */ |
RobMeades | 0:5cffef3371f6 | 94 | bool is_registered_csd(); |
RobMeades | 0:5cffef3371f6 | 95 | |
RobMeades | 0:5cffef3371f6 | 96 | /** True if the modem is registered for packet |
RobMeades | 0:5cffef3371f6 | 97 | * switched data, otherwise false. |
RobMeades | 0:5cffef3371f6 | 98 | */ |
RobMeades | 0:5cffef3371f6 | 99 | bool is_registered_psd(); |
RobMeades | 0:5cffef3371f6 | 100 | |
RobMeades | 0:5cffef3371f6 | 101 | /** True if the modem is registered for enhanced |
RobMeades | 0:5cffef3371f6 | 102 | * packet switched data (i.e. LTE and beyond), |
RobMeades | 0:5cffef3371f6 | 103 | * otherwise false. |
RobMeades | 0:5cffef3371f6 | 104 | */ |
RobMeades | 0:5cffef3371f6 | 105 | bool is_registered_eps(); |
RobMeades | 0:5cffef3371f6 | 106 | |
RobMeades | 0:5cffef3371f6 | 107 | /** Perform deregistration from the network. |
RobMeades | 0:5cffef3371f6 | 108 | * |
RobMeades | 0:5cffef3371f6 | 109 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 110 | */ |
RobMeades | 0:5cffef3371f6 | 111 | bool nwk_deregistration(); |
RobMeades | 0:5cffef3371f6 | 112 | |
RobMeades | 0:5cffef3371f6 | 113 | /** Put the modem into its lowest power state. |
RobMeades | 0:5cffef3371f6 | 114 | */ |
RobMeades | 0:5cffef3371f6 | 115 | void deinit(); |
RobMeades | 0:5cffef3371f6 | 116 | |
RobMeades | 0:5cffef3371f6 | 117 | /** Set the PIN code for the SIM card. |
RobMeades | 0:5cffef3371f6 | 118 | * |
RobMeades | 0:5cffef3371f6 | 119 | * @param pin PIN for the SIM card. |
RobMeades | 0:5cffef3371f6 | 120 | */ |
RobMeades | 0:5cffef3371f6 | 121 | void set_pin(const char *pin); |
RobMeades | 0:5cffef3371f6 | 122 | |
RobMeades | 0:5cffef3371f6 | 123 | /** Enable or disable SIM pin checking. |
RobMeades | 0:5cffef3371f6 | 124 | * |
RobMeades | 0:5cffef3371f6 | 125 | * @param enableNotDisable true if SIM PIN checking is to be enabled, |
RobMeades | 0:5cffef3371f6 | 126 | * otherwise false. |
RobMeades | 0:5cffef3371f6 | 127 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 128 | */ |
RobMeades | 0:5cffef3371f6 | 129 | bool sim_pin_check_enable(bool enableNotDisable); |
RobMeades | 0:5cffef3371f6 | 130 | |
RobMeades | 0:5cffef3371f6 | 131 | /** Change the SIM pin. |
RobMeades | 0:5cffef3371f6 | 132 | * |
RobMeades | 0:5cffef3371f6 | 133 | * @param new_pin the new PIN to use. |
RobMeades | 0:5cffef3371f6 | 134 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 135 | */ |
RobMeades | 0:5cffef3371f6 | 136 | bool change_sim_pin(const char *new_pin); |
RobMeades | 0:5cffef3371f6 | 137 | |
fahim alavi |
11:57f64bc518c0 | 138 | /** Get the IMEI. |
fahim alavi |
11:57f64bc518c0 | 139 | * |
fahim alavi |
11:57f64bc518c0 | 140 | * @return true if successful, otherwise false. |
fahim alavi |
11:57f64bc518c0 | 141 | */ |
RobMeades | 14:e420232ee4e7 | 142 | MBED_DEPRECATED("This method is now replaced by const char * imei(), please use that instead") |
fahim alavi |
12:aa3cbc3f88c5 | 143 | bool get_imei(char *imei_to_send, int size); |
fahim alavi |
11:57f64bc518c0 | 144 | |
RobMeades | 14:e420232ee4e7 | 145 | /** Get the IMEI of the module. |
RobMeades | 14:e420232ee4e7 | 146 | * |
RobMeades | 14:e420232ee4e7 | 147 | * @return a pointer to the IMEI as a null-terminated string. |
RobMeades | 14:e420232ee4e7 | 148 | */ |
RobMeades | 14:e420232ee4e7 | 149 | const char *imei(); |
RobMeades | 14:e420232ee4e7 | 150 | |
RobMeades | 14:e420232ee4e7 | 151 | /** Get the Mobile Equipment ID (which may be the same as the IMEI). |
RobMeades | 14:e420232ee4e7 | 152 | * |
RobMeades | 14:e420232ee4e7 | 153 | * @return a pointer to the Mobile Equipment ID as a null-terminated string. |
RobMeades | 14:e420232ee4e7 | 154 | */ |
RobMeades | 14:e420232ee4e7 | 155 | const char *meid(); |
RobMeades | 14:e420232ee4e7 | 156 | |
RobMeades | 14:e420232ee4e7 | 157 | /** Get the IMSI of the SIM. |
RobMeades | 14:e420232ee4e7 | 158 | * |
RobMeades | 14:e420232ee4e7 | 159 | * @return a pointer to the IMSI as a null-terminated string. |
RobMeades | 14:e420232ee4e7 | 160 | */ |
RobMeades | 14:e420232ee4e7 | 161 | const char *imsi(); |
RobMeades | 14:e420232ee4e7 | 162 | |
RobMeades | 14:e420232ee4e7 | 163 | /** Get the ICCID of the SIM. |
RobMeades | 14:e420232ee4e7 | 164 | * |
RobMeades | 14:e420232ee4e7 | 165 | * @return a pointer to the ICCID as a null-terminated string. |
RobMeades | 14:e420232ee4e7 | 166 | */ |
RobMeades | 14:e420232ee4e7 | 167 | const char *iccid(); |
RobMeades | 14:e420232ee4e7 | 168 | |
RobMeades | 14:e420232ee4e7 | 169 | /** Get the RSSI. |
RobMeades | 14:e420232ee4e7 | 170 | * |
RobMeades | 14:e420232ee4e7 | 171 | * @return the RSSI in dBm. If it is not possible to obtain an |
RobMeades | 14:e420232ee4e7 | 172 | * RSSI reading at the time (e.g. because the modem is in |
RobMeades | 14:e420232ee4e7 | 173 | * data mode rather than AT command mode) then 0 is returned. |
RobMeades | 14:e420232ee4e7 | 174 | */ |
RobMeades | 14:e420232ee4e7 | 175 | int rssi(); |
RobMeades | 14:e420232ee4e7 | 176 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 177 | /** RAT values for +URAT command |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 178 | * R412M only supports value 7 (CatM1), 8 (NB1), and 9 (GPRS) |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 179 | */ |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 180 | typedef enum { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 181 | GSM_GPRS_EGPRS = 0, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 182 | GSM_UMTS = 1, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 183 | UMTS = 2, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 184 | URAT_LTE = 3, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 185 | GSM_UMTS_LTE = 4, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 186 | GSM_LTE = 5, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 187 | UMTS_LTE = 6, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 188 | LTE_CATM1 = 7, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 189 | LTE_CATNB1 = 8, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 190 | GPRS_EGPRS = 9, |
wajahat.abbas@u-blox.com | 22:779971811c46 | 191 | NOT_USED = -1 |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 192 | } RAT; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 193 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 194 | #ifdef TARGET_UBLOX_C030_R41XM |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 195 | /** Supported MNO profiles for SARA-R4. |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 196 | */ |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 197 | typedef enum { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 198 | SW_DEFAULT = 0, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 199 | SIM_ICCID = 1, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 200 | ATT = 2, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 201 | VERIZON = 3, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 202 | TELSTRA = 4, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 203 | TMO = 5, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 204 | CT = 6, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 205 | VODAFONE = 19, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 206 | TELUS = 21, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 207 | DT = 31, |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 208 | STANDARD_EU = 100 |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 209 | } MNOProfile; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 210 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 211 | #if MBED_CONF_UBLOX_CELL_DEFAULT_MNO_PROFILE |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 212 | #define DEFAULT_MNO_PROFILE (MNOProfile)MBED_CONF_UBLOX_CELL_DEFAULT_MNO_PROFILE |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 213 | #else |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 214 | #define DEFAULT_MNO_PROFILE SW_DEFAULT |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 215 | #endif |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 216 | |
wajahat.abbas@u-blox.com | 21:98aea8f49cd8 | 217 | /** Reads the current MNO profile from modem and sets it to user specified profile. |
wajahat.abbas@u-blox.com | 21:98aea8f49cd8 | 218 | * 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 | 219 | * |
wajahat.abbas@u-blox.com | 21:98aea8f49cd8 | 220 | * 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 | 221 | * |
wajahat.abbas@u-blox.com | 21:98aea8f49cd8 | 222 | * @param profile MNO profile to use |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 223 | * @return true if operation was successful, false if there was an error |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 224 | */ |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 225 | bool set_mno_profile(MNOProfile profile = DEFAULT_MNO_PROFILE); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 226 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 227 | /** Get current MNO profile. |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 228 | * |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 229 | * @param profile pointer to variable that can hold the value for returned profile |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 230 | * @return true if operation was successful, false if there was an error |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 231 | */ |
wajahat.abbas@u-blox.com | 22:779971811c46 | 232 | bool get_mno_profile(int *profile); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 233 | #endif |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 234 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 235 | /** Set Radio Access Technology on modem. |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 236 | * |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 237 | * 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 | 238 | * |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 239 | * @param selected_rat Radio Access Technology to use |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 240 | * @param preferred_rat Radio Access Technology to use if selected_rat is not available |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 241 | * @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 | 242 | * |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 243 | * @return true if successful, otherwise false. |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 244 | */ |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 245 | 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 | 246 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 247 | /** 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 | 248 | * |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 249 | * @param selected_rat pointer to variable that can hold the value for selected_rat |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 250 | * @param preferred_rat pointer to variable that can hold the value for preferred_rat |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 251 | * @param second_preferred_rat pointer to variable that can hold the value for second_preferred_rat |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 252 | * |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 253 | * Note: NOT_USED will be returned in the variables if dual or tri modes are not enabled. |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 254 | * |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 255 | * @return true if successful, otherwise false. |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 256 | */ |
wajahat.abbas@u-blox.com | 22:779971811c46 | 257 | bool get_modem_rat(int *selected_rat, int *preferred_rat, int *second_preferred_rat); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 258 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 259 | /** reboot the modem using AT+CFUN=15. |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 260 | * |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 261 | * @return true if successful, otherwise false. |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 262 | */ |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 263 | bool reboot_modem(); |
RobMeades | 0:5cffef3371f6 | 264 | protected: |
RobMeades | 0:5cffef3371f6 | 265 | |
RobMeades | 0:5cffef3371f6 | 266 | #define OUTPUT_ENTER_KEY "\r" |
RobMeades | 0:5cffef3371f6 | 267 | |
RobMeades | 0:5cffef3371f6 | 268 | #if MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_BUFFER_SIZE |
RobMeades | 0:5cffef3371f6 | 269 | #define AT_PARSER_BUFFER_SIZE MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_BUFFER_SIZE |
RobMeades | 0:5cffef3371f6 | 270 | #else |
RobMeades | 0:5cffef3371f6 | 271 | #define AT_PARSER_BUFFER_SIZE 256 |
RobMeades | 0:5cffef3371f6 | 272 | #endif |
RobMeades | 0:5cffef3371f6 | 273 | |
RobMeades | 0:5cffef3371f6 | 274 | #if MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_TIMEOUT |
RobMeades | 0:5cffef3371f6 | 275 | #define AT_PARSER_TIMEOUT MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_TIMEOUT |
RobMeades | 0:5cffef3371f6 | 276 | #else |
RobMeades | 0:5cffef3371f6 | 277 | #define AT_PARSER_TIMEOUT 8*1000 // Milliseconds |
RobMeades | 0:5cffef3371f6 | 278 | #endif |
RobMeades | 0:5cffef3371f6 | 279 | |
RobMeades | 0:5cffef3371f6 | 280 | /** A string that would not normally be sent by the modem on the AT interface. |
RobMeades | 0:5cffef3371f6 | 281 | */ |
RobMeades | 0:5cffef3371f6 | 282 | #define UNNATURAL_STRING "\x01" |
RobMeades | 0:5cffef3371f6 | 283 | |
RobMeades | 0:5cffef3371f6 | 284 | /** Supported u-blox modem variants. |
RobMeades | 0:5cffef3371f6 | 285 | */ |
RobMeades | 0:5cffef3371f6 | 286 | typedef enum { |
RobMeades | 0:5cffef3371f6 | 287 | DEV_TYPE_NONE = 0, |
RobMeades | 0:5cffef3371f6 | 288 | DEV_SARA_G35, |
RobMeades | 0:5cffef3371f6 | 289 | DEV_LISA_U2, |
RobMeades | 0:5cffef3371f6 | 290 | DEV_LISA_U2_03S, |
RobMeades | 0:5cffef3371f6 | 291 | DEV_SARA_U2, |
fahim alavi |
11:57f64bc518c0 | 292 | DEV_SARA_R4, |
RobMeades | 0:5cffef3371f6 | 293 | DEV_LEON_G2, |
RobMeades | 0:5cffef3371f6 | 294 | DEV_TOBY_L2, |
RobMeades | 0:5cffef3371f6 | 295 | DEV_MPCI_L2 |
RobMeades | 0:5cffef3371f6 | 296 | } DeviceType; |
RobMeades | 0:5cffef3371f6 | 297 | |
RobMeades | 0:5cffef3371f6 | 298 | /** Network registration status. |
RobMeades | 0:5cffef3371f6 | 299 | * UBX-13001820 - AT Commands Example Application Note (Section 4.1.4.5). |
RobMeades | 0:5cffef3371f6 | 300 | */ |
RobMeades | 0:5cffef3371f6 | 301 | typedef enum { |
RobMeades | 0:5cffef3371f6 | 302 | GSM = 0, |
RobMeades | 0:5cffef3371f6 | 303 | COMPACT_GSM = 1, |
RobMeades | 0:5cffef3371f6 | 304 | UTRAN = 2, |
RobMeades | 0:5cffef3371f6 | 305 | EDGE = 3, |
RobMeades | 0:5cffef3371f6 | 306 | HSDPA = 4, |
RobMeades | 0:5cffef3371f6 | 307 | HSUPA = 5, |
RobMeades | 0:5cffef3371f6 | 308 | HSDPA_HSUPA = 6, |
fahimalavi | 10:c4281fa79b8f | 309 | LTE = 7, |
fahim alavi |
12:aa3cbc3f88c5 | 310 | EC_GSM_IoT = 8, |
fahim alavi |
12:aa3cbc3f88c5 | 311 | E_UTRAN_NB_S1 = 9 |
RobMeades | 0:5cffef3371f6 | 312 | } RadioAccessNetworkType; |
RobMeades | 0:5cffef3371f6 | 313 | |
RobMeades | 0:5cffef3371f6 | 314 | /** Info about the modem. |
RobMeades | 0:5cffef3371f6 | 315 | */ |
RobMeades | 0:5cffef3371f6 | 316 | typedef struct { |
RobMeades | 0:5cffef3371f6 | 317 | DeviceType dev; |
RobMeades | 0:5cffef3371f6 | 318 | char iccid[20 + 1]; //!< Integrated Circuit Card ID. |
RobMeades | 0:5cffef3371f6 | 319 | char imsi[15 + 1]; //!< International Mobile Station Identity. |
RobMeades | 0:5cffef3371f6 | 320 | char imei[15 + 1]; //!< International Mobile Equipment Identity. |
RobMeades | 0:5cffef3371f6 | 321 | char meid[18 + 1]; //!< Mobile Equipment IDentifier. |
RobMeades | 0:5cffef3371f6 | 322 | volatile RadioAccessNetworkType rat; //!< Type of network (e.g. 2G, 3G, LTE). |
RobMeades | 0:5cffef3371f6 | 323 | volatile NetworkRegistrationStatusCsd reg_status_csd; //!< Circuit switched attach status. |
RobMeades | 0:5cffef3371f6 | 324 | volatile NetworkRegistrationStatusPsd reg_status_psd; //!< Packet switched attach status. |
RobMeades | 0:5cffef3371f6 | 325 | volatile NetworkRegistrationStatusEps reg_status_eps; //!< Evolved Packet Switched (e.g. LTE) attach status. |
RobMeades | 0:5cffef3371f6 | 326 | } DeviceInfo; |
RobMeades | 0:5cffef3371f6 | 327 | |
RobMeades | 0:5cffef3371f6 | 328 | /* IMPORTANT: the variables below are available to |
RobMeades | 0:5cffef3371f6 | 329 | * classes that inherit this in order to keep things |
RobMeades | 0:5cffef3371f6 | 330 | * simple. However, ONLY this class should free |
RobMeades | 0:5cffef3371f6 | 331 | * any of the pointers, or there will be havoc. |
RobMeades | 0:5cffef3371f6 | 332 | */ |
RobMeades | 0:5cffef3371f6 | 333 | |
RobMeades | 0:5cffef3371f6 | 334 | /** Point to the instance of the AT parser in use. |
RobMeades | 0:5cffef3371f6 | 335 | */ |
RobMeades | 0:5cffef3371f6 | 336 | ATCmdParser *_at; |
RobMeades | 0:5cffef3371f6 | 337 | |
RobMeades | 0:5cffef3371f6 | 338 | /** The current AT parser timeout value. |
RobMeades | 0:5cffef3371f6 | 339 | */ |
RobMeades | 0:5cffef3371f6 | 340 | int _at_timeout; |
RobMeades | 0:5cffef3371f6 | 341 | |
RobMeades | 0:5cffef3371f6 | 342 | /** File handle used by the AT parser. |
RobMeades | 0:5cffef3371f6 | 343 | */ |
RobMeades | 0:5cffef3371f6 | 344 | FileHandle *_fh; |
RobMeades | 0:5cffef3371f6 | 345 | |
RobMeades | 0:5cffef3371f6 | 346 | /** The mutex resource. |
RobMeades | 0:5cffef3371f6 | 347 | */ |
RobMeades | 0:5cffef3371f6 | 348 | Mutex _mtx; |
RobMeades | 0:5cffef3371f6 | 349 | |
RobMeades | 0:5cffef3371f6 | 350 | /** General info about the modem as a device. |
RobMeades | 0:5cffef3371f6 | 351 | */ |
RobMeades | 0:5cffef3371f6 | 352 | DeviceInfo _dev_info; |
RobMeades | 0:5cffef3371f6 | 353 | |
RobMeades | 0:5cffef3371f6 | 354 | /** The SIM PIN to use. |
RobMeades | 0:5cffef3371f6 | 355 | */ |
RobMeades | 0:5cffef3371f6 | 356 | const char *_pin; |
RobMeades | 0:5cffef3371f6 | 357 | |
RobMeades | 0:5cffef3371f6 | 358 | /** Set to true to spit out debug traces. |
RobMeades | 0:5cffef3371f6 | 359 | */ |
RobMeades | 0:5cffef3371f6 | 360 | bool _debug_trace_on; |
rob.meades@u-blox.com | 4:2e640a101db1 | 361 | |
rob.meades@u-blox.com | 4:2e640a101db1 | 362 | /** The baud rate to the modem. |
rob.meades@u-blox.com | 4:2e640a101db1 | 363 | */ |
rob.meades@u-blox.com | 4:2e640a101db1 | 364 | int _baud; |
RobMeades | 0:5cffef3371f6 | 365 | |
RobMeades | 0:5cffef3371f6 | 366 | /** True if the modem is ready register to the network, |
RobMeades | 0:5cffef3371f6 | 367 | * otherwise false. |
RobMeades | 0:5cffef3371f6 | 368 | */ |
RobMeades | 0:5cffef3371f6 | 369 | bool _modem_initialised; |
RobMeades | 0:5cffef3371f6 | 370 | |
RobMeades | 0:5cffef3371f6 | 371 | /** True it the SIM requires a PIN, otherwise false. |
RobMeades | 0:5cffef3371f6 | 372 | */ |
RobMeades | 0:5cffef3371f6 | 373 | bool _sim_pin_check_enabled; |
RobMeades | 0:5cffef3371f6 | 374 | |
RobMeades | 0:5cffef3371f6 | 375 | /** Sets the modem up for powering on |
RobMeades | 0:5cffef3371f6 | 376 | * |
RobMeades | 0:5cffef3371f6 | 377 | * modem_init() is equivalent to plugging in the device, e.g., attaching power and serial port. |
RobMeades | 0:5cffef3371f6 | 378 | * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target. |
RobMeades | 0:5cffef3371f6 | 379 | */ |
RobMeades | 0:5cffef3371f6 | 380 | virtual void modem_init(); |
RobMeades | 0:5cffef3371f6 | 381 | |
RobMeades | 0:5cffef3371f6 | 382 | /** Sets the modem in unplugged state |
RobMeades | 0:5cffef3371f6 | 383 | * |
RobMeades | 0:5cffef3371f6 | 384 | * modem_deinit() will be equivalent to pulling the plug off of the device, i.e., detaching power |
RobMeades | 0:5cffef3371f6 | 385 | * and serial port. This puts the modem in lowest power state. |
RobMeades | 0:5cffef3371f6 | 386 | * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target. |
RobMeades | 0:5cffef3371f6 | 387 | */ |
RobMeades | 0:5cffef3371f6 | 388 | virtual void modem_deinit(); |
RobMeades | 0:5cffef3371f6 | 389 | |
RobMeades | 0:5cffef3371f6 | 390 | /** Powers up the modem |
RobMeades | 0:5cffef3371f6 | 391 | * |
RobMeades | 0:5cffef3371f6 | 392 | * modem_power_up() is equivalent to pressing the soft power button. |
RobMeades | 0:5cffef3371f6 | 393 | * The driver may repeat this if the modem is not responsive to AT commands. |
RobMeades | 0:5cffef3371f6 | 394 | * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target. |
RobMeades | 0:5cffef3371f6 | 395 | */ |
RobMeades | 0:5cffef3371f6 | 396 | virtual void modem_power_up(); |
RobMeades | 0:5cffef3371f6 | 397 | |
RobMeades | 0:5cffef3371f6 | 398 | /** Powers down the modem |
RobMeades | 0:5cffef3371f6 | 399 | * |
RobMeades | 0:5cffef3371f6 | 400 | * modem_power_down() is equivalent to turning off the modem by button press. |
RobMeades | 0:5cffef3371f6 | 401 | * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target. |
RobMeades | 0:5cffef3371f6 | 402 | */ |
RobMeades | 0:5cffef3371f6 | 403 | virtual void modem_power_down(); |
RobMeades | 0:5cffef3371f6 | 404 | |
RobMeades | 0:5cffef3371f6 | 405 | /* Note: constructor and destructor protected so that this |
RobMeades | 0:5cffef3371f6 | 406 | * class can only ever be inherited, never used directly. |
RobMeades | 0:5cffef3371f6 | 407 | */ |
RobMeades | 0:5cffef3371f6 | 408 | UbloxCellularBase(); |
RobMeades | 0:5cffef3371f6 | 409 | ~UbloxCellularBase(); |
RobMeades | 0:5cffef3371f6 | 410 | |
RobMeades | 0:5cffef3371f6 | 411 | /** Initialise this class. |
RobMeades | 0:5cffef3371f6 | 412 | * |
RobMeades | 0:5cffef3371f6 | 413 | * @param tx the UART TX data pin to which the modem is attached. |
RobMeades | 0:5cffef3371f6 | 414 | * @param rx the UART RX data pin to which the modem is attached. |
RobMeades | 0:5cffef3371f6 | 415 | * @param baud the UART baud rate. |
RobMeades | 0:5cffef3371f6 | 416 | * @param debug_on true to switch AT interface debug on, otherwise false. |
RobMeades | 0:5cffef3371f6 | 417 | * |
RobMeades | 0:5cffef3371f6 | 418 | * Note: it would be more natural to do this in the constructor |
RobMeades | 0:5cffef3371f6 | 419 | * however, to avoid the diamond of death, this class is only |
RobMeades | 0:5cffef3371f6 | 420 | * every inherited virtually. Classes that are inherited virtually |
RobMeades | 0:5cffef3371f6 | 421 | * do not get passed parameters in their constructor and hence |
RobMeades | 0:5cffef3371f6 | 422 | * classInit() must be called separately by the first one to wake |
RobMeades | 0:5cffef3371f6 | 423 | * the beast. |
RobMeades | 0:5cffef3371f6 | 424 | */ |
RobMeades | 0:5cffef3371f6 | 425 | void baseClassInit(PinName tx = MDMTXD, |
RobMeades | 0:5cffef3371f6 | 426 | PinName rx = MDMRXD, |
RobMeades | 0:5cffef3371f6 | 427 | int baud = MBED_CONF_UBLOX_CELL_BAUD_RATE, |
RobMeades | 0:5cffef3371f6 | 428 | bool debug_on = false); |
RobMeades | 0:5cffef3371f6 | 429 | |
RobMeades | 0:5cffef3371f6 | 430 | /** Set the AT parser timeout. |
RobMeades | 0:5cffef3371f6 | 431 | */ |
RobMeades | 0:5cffef3371f6 | 432 | void at_set_timeout(int timeout); |
RobMeades | 0:5cffef3371f6 | 433 | |
RobMeades | 0:5cffef3371f6 | 434 | /** Read up to size characters from buf |
RobMeades | 0:5cffef3371f6 | 435 | * or until the character "end" is reached, overwriting |
RobMeades | 0:5cffef3371f6 | 436 | * the newline with 0 and ensuring a terminator |
RobMeades | 0:5cffef3371f6 | 437 | * in all cases. |
RobMeades | 0:5cffef3371f6 | 438 | * |
RobMeades | 0:5cffef3371f6 | 439 | * @param buf the buffer to write to. |
RobMeades | 0:5cffef3371f6 | 440 | * @param size the size of the buffer. |
RobMeades | 0:5cffef3371f6 | 441 | * @param end the character to stop at. |
RobMeades | 0:5cffef3371f6 | 442 | * @return the number of characters read, |
RobMeades | 0:5cffef3371f6 | 443 | * not including the terminator. |
RobMeades | 0:5cffef3371f6 | 444 | */ |
RobMeades | 0:5cffef3371f6 | 445 | int read_at_to_char(char * buf, int size, char end); |
RobMeades | 0:5cffef3371f6 | 446 | |
RobMeades | 0:5cffef3371f6 | 447 | /** Powers up the modem. |
RobMeades | 0:5cffef3371f6 | 448 | * |
RobMeades | 0:5cffef3371f6 | 449 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 450 | */ |
RobMeades | 0:5cffef3371f6 | 451 | bool power_up(); |
RobMeades | 0:5cffef3371f6 | 452 | |
RobMeades | 0:5cffef3371f6 | 453 | /** Power down the modem. |
RobMeades | 0:5cffef3371f6 | 454 | */ |
RobMeades | 0:5cffef3371f6 | 455 | void power_down(); |
RobMeades | 0:5cffef3371f6 | 456 | |
RobMeades | 0:5cffef3371f6 | 457 | /** Lock a mutex when accessing the modem. |
RobMeades | 0:5cffef3371f6 | 458 | */ |
RobMeades | 0:5cffef3371f6 | 459 | void lock(void) { _mtx.lock(); } |
RobMeades | 0:5cffef3371f6 | 460 | |
RobMeades | 0:5cffef3371f6 | 461 | /** Helper to make sure that lock unlock pair is always balanced |
RobMeades | 0:5cffef3371f6 | 462 | */ |
RobMeades | 0:5cffef3371f6 | 463 | #define LOCK() { lock() |
RobMeades | 0:5cffef3371f6 | 464 | |
RobMeades | 0:5cffef3371f6 | 465 | /** Unlock the modem when done accessing it. |
RobMeades | 0:5cffef3371f6 | 466 | */ |
RobMeades | 0:5cffef3371f6 | 467 | void unlock(void) { _mtx.unlock(); } |
RobMeades | 0:5cffef3371f6 | 468 | |
RobMeades | 0:5cffef3371f6 | 469 | /** Helper to make sure that lock unlock pair is always balanced |
RobMeades | 0:5cffef3371f6 | 470 | */ |
RobMeades | 0:5cffef3371f6 | 471 | #define UNLOCK() } unlock() |
RobMeades | 0:5cffef3371f6 | 472 | |
RobMeades | 0:5cffef3371f6 | 473 | /** Set the device identity in _dev_info |
RobMeades | 0:5cffef3371f6 | 474 | * based on the ATI string returned by |
RobMeades | 0:5cffef3371f6 | 475 | * the module. |
RobMeades | 0:5cffef3371f6 | 476 | * |
RobMeades | 0:5cffef3371f6 | 477 | * @return true if dev is a known value, |
RobMeades | 0:5cffef3371f6 | 478 | * otherwise false. |
RobMeades | 0:5cffef3371f6 | 479 | */ |
RobMeades | 0:5cffef3371f6 | 480 | bool set_device_identity(DeviceType *dev); |
RobMeades | 0:5cffef3371f6 | 481 | |
RobMeades | 0:5cffef3371f6 | 482 | /** Perform any modem initialisation that is |
RobMeades | 0:5cffef3371f6 | 483 | * specialised by device type. |
RobMeades | 0:5cffef3371f6 | 484 | * |
RobMeades | 0:5cffef3371f6 | 485 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 486 | */ |
RobMeades | 0:5cffef3371f6 | 487 | bool device_init(DeviceType dev); |
RobMeades | 0:5cffef3371f6 | 488 | |
RobMeades | 0:5cffef3371f6 | 489 | /** Set up the SIM. |
RobMeades | 0:5cffef3371f6 | 490 | * |
RobMeades | 0:5cffef3371f6 | 491 | * @return true if successful, otherwiss false. |
RobMeades | 0:5cffef3371f6 | 492 | */ |
RobMeades | 0:5cffef3371f6 | 493 | bool initialise_sim_card(); |
RobMeades | 0:5cffef3371f6 | 494 | |
RobMeades | 0:5cffef3371f6 | 495 | private: |
RobMeades | 0:5cffef3371f6 | 496 | |
RobMeades | 0:5cffef3371f6 | 497 | void set_nwk_reg_status_csd(int status); |
RobMeades | 0:5cffef3371f6 | 498 | void set_nwk_reg_status_psd(int status); |
RobMeades | 0:5cffef3371f6 | 499 | void set_nwk_reg_status_eps(int status); |
RobMeades | 0:5cffef3371f6 | 500 | void set_rat(int AcTStatus); |
RobMeades | 0:5cffef3371f6 | 501 | bool get_iccid(); |
RobMeades | 0:5cffef3371f6 | 502 | bool get_imsi(); |
RobMeades | 0:5cffef3371f6 | 503 | bool get_imei(); |
RobMeades | 0:5cffef3371f6 | 504 | bool get_meid(); |
RobMeades | 0:5cffef3371f6 | 505 | bool set_sms(); |
RobMeades | 0:5cffef3371f6 | 506 | void parser_abort_cb(); |
RobMeades | 0:5cffef3371f6 | 507 | void CMX_ERROR_URC(); |
RobMeades | 0:5cffef3371f6 | 508 | void CREG_URC(); |
RobMeades | 0:5cffef3371f6 | 509 | void CGREG_URC(); |
RobMeades | 0:5cffef3371f6 | 510 | void CEREG_URC(); |
RobMeades | 0:5cffef3371f6 | 511 | void UMWI_URC(); |
RobMeades | 0:5cffef3371f6 | 512 | }; |
RobMeades | 0:5cffef3371f6 | 513 | |
rob.meades@u-blox.com | 1:5aaecf2572dc | 514 | #endif // _UBLOX_CELLULAR_BASE_ |
RobMeades | 0:5cffef3371f6 | 515 |