ublox-cellular-base_R4_PR
UbloxCellularBase.h@14:e420232ee4e7, 2018-01-09 (annotated)
- Committer:
- RobMeades
- Date:
- Tue Jan 09 13:20:15 2018 +0000
- Revision:
- 14:e420232ee4e7
- Parent:
- 12:aa3cbc3f88c5
- Child:
- 20:31d5e048fbfa
Add methods to return IMEI, MEID, IMSI, ICCID and RSSI.
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 | |
RobMeades | 0:5cffef3371f6 | 177 | protected: |
RobMeades | 0:5cffef3371f6 | 178 | |
RobMeades | 0:5cffef3371f6 | 179 | #define OUTPUT_ENTER_KEY "\r" |
RobMeades | 0:5cffef3371f6 | 180 | |
RobMeades | 0:5cffef3371f6 | 181 | #if MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_BUFFER_SIZE |
RobMeades | 0:5cffef3371f6 | 182 | #define AT_PARSER_BUFFER_SIZE MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_BUFFER_SIZE |
RobMeades | 0:5cffef3371f6 | 183 | #else |
RobMeades | 0:5cffef3371f6 | 184 | #define AT_PARSER_BUFFER_SIZE 256 |
RobMeades | 0:5cffef3371f6 | 185 | #endif |
RobMeades | 0:5cffef3371f6 | 186 | |
RobMeades | 0:5cffef3371f6 | 187 | #if MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_TIMEOUT |
RobMeades | 0:5cffef3371f6 | 188 | #define AT_PARSER_TIMEOUT MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_TIMEOUT |
RobMeades | 0:5cffef3371f6 | 189 | #else |
RobMeades | 0:5cffef3371f6 | 190 | #define AT_PARSER_TIMEOUT 8*1000 // Milliseconds |
RobMeades | 0:5cffef3371f6 | 191 | #endif |
RobMeades | 0:5cffef3371f6 | 192 | |
RobMeades | 0:5cffef3371f6 | 193 | /** A string that would not normally be sent by the modem on the AT interface. |
RobMeades | 0:5cffef3371f6 | 194 | */ |
RobMeades | 0:5cffef3371f6 | 195 | #define UNNATURAL_STRING "\x01" |
RobMeades | 0:5cffef3371f6 | 196 | |
RobMeades | 0:5cffef3371f6 | 197 | /** Supported u-blox modem variants. |
RobMeades | 0:5cffef3371f6 | 198 | */ |
RobMeades | 0:5cffef3371f6 | 199 | typedef enum { |
RobMeades | 0:5cffef3371f6 | 200 | DEV_TYPE_NONE = 0, |
RobMeades | 0:5cffef3371f6 | 201 | DEV_SARA_G35, |
RobMeades | 0:5cffef3371f6 | 202 | DEV_LISA_U2, |
RobMeades | 0:5cffef3371f6 | 203 | DEV_LISA_U2_03S, |
RobMeades | 0:5cffef3371f6 | 204 | DEV_SARA_U2, |
fahim alavi |
11:57f64bc518c0 | 205 | DEV_SARA_R4, |
RobMeades | 0:5cffef3371f6 | 206 | DEV_LEON_G2, |
RobMeades | 0:5cffef3371f6 | 207 | DEV_TOBY_L2, |
RobMeades | 0:5cffef3371f6 | 208 | DEV_MPCI_L2 |
RobMeades | 0:5cffef3371f6 | 209 | } DeviceType; |
RobMeades | 0:5cffef3371f6 | 210 | |
RobMeades | 0:5cffef3371f6 | 211 | /** Network registration status. |
RobMeades | 0:5cffef3371f6 | 212 | * UBX-13001820 - AT Commands Example Application Note (Section 4.1.4.5). |
RobMeades | 0:5cffef3371f6 | 213 | */ |
RobMeades | 0:5cffef3371f6 | 214 | typedef enum { |
RobMeades | 0:5cffef3371f6 | 215 | GSM = 0, |
RobMeades | 0:5cffef3371f6 | 216 | COMPACT_GSM = 1, |
RobMeades | 0:5cffef3371f6 | 217 | UTRAN = 2, |
RobMeades | 0:5cffef3371f6 | 218 | EDGE = 3, |
RobMeades | 0:5cffef3371f6 | 219 | HSDPA = 4, |
RobMeades | 0:5cffef3371f6 | 220 | HSUPA = 5, |
RobMeades | 0:5cffef3371f6 | 221 | HSDPA_HSUPA = 6, |
fahimalavi | 10:c4281fa79b8f | 222 | LTE = 7, |
fahim alavi |
12:aa3cbc3f88c5 | 223 | EC_GSM_IoT = 8, |
fahim alavi |
12:aa3cbc3f88c5 | 224 | E_UTRAN_NB_S1 = 9 |
RobMeades | 0:5cffef3371f6 | 225 | } RadioAccessNetworkType; |
RobMeades | 0:5cffef3371f6 | 226 | |
RobMeades | 0:5cffef3371f6 | 227 | /** Info about the modem. |
RobMeades | 0:5cffef3371f6 | 228 | */ |
RobMeades | 0:5cffef3371f6 | 229 | typedef struct { |
RobMeades | 0:5cffef3371f6 | 230 | DeviceType dev; |
RobMeades | 0:5cffef3371f6 | 231 | char iccid[20 + 1]; //!< Integrated Circuit Card ID. |
RobMeades | 0:5cffef3371f6 | 232 | char imsi[15 + 1]; //!< International Mobile Station Identity. |
RobMeades | 0:5cffef3371f6 | 233 | char imei[15 + 1]; //!< International Mobile Equipment Identity. |
RobMeades | 0:5cffef3371f6 | 234 | char meid[18 + 1]; //!< Mobile Equipment IDentifier. |
RobMeades | 0:5cffef3371f6 | 235 | volatile RadioAccessNetworkType rat; //!< Type of network (e.g. 2G, 3G, LTE). |
RobMeades | 0:5cffef3371f6 | 236 | volatile NetworkRegistrationStatusCsd reg_status_csd; //!< Circuit switched attach status. |
RobMeades | 0:5cffef3371f6 | 237 | volatile NetworkRegistrationStatusPsd reg_status_psd; //!< Packet switched attach status. |
RobMeades | 0:5cffef3371f6 | 238 | volatile NetworkRegistrationStatusEps reg_status_eps; //!< Evolved Packet Switched (e.g. LTE) attach status. |
RobMeades | 0:5cffef3371f6 | 239 | } DeviceInfo; |
RobMeades | 0:5cffef3371f6 | 240 | |
RobMeades | 0:5cffef3371f6 | 241 | /* IMPORTANT: the variables below are available to |
RobMeades | 0:5cffef3371f6 | 242 | * classes that inherit this in order to keep things |
RobMeades | 0:5cffef3371f6 | 243 | * simple. However, ONLY this class should free |
RobMeades | 0:5cffef3371f6 | 244 | * any of the pointers, or there will be havoc. |
RobMeades | 0:5cffef3371f6 | 245 | */ |
RobMeades | 0:5cffef3371f6 | 246 | |
RobMeades | 0:5cffef3371f6 | 247 | /** Point to the instance of the AT parser in use. |
RobMeades | 0:5cffef3371f6 | 248 | */ |
RobMeades | 0:5cffef3371f6 | 249 | ATCmdParser *_at; |
RobMeades | 0:5cffef3371f6 | 250 | |
RobMeades | 0:5cffef3371f6 | 251 | /** The current AT parser timeout value. |
RobMeades | 0:5cffef3371f6 | 252 | */ |
RobMeades | 0:5cffef3371f6 | 253 | int _at_timeout; |
RobMeades | 0:5cffef3371f6 | 254 | |
RobMeades | 0:5cffef3371f6 | 255 | /** File handle used by the AT parser. |
RobMeades | 0:5cffef3371f6 | 256 | */ |
RobMeades | 0:5cffef3371f6 | 257 | FileHandle *_fh; |
RobMeades | 0:5cffef3371f6 | 258 | |
RobMeades | 0:5cffef3371f6 | 259 | /** The mutex resource. |
RobMeades | 0:5cffef3371f6 | 260 | */ |
RobMeades | 0:5cffef3371f6 | 261 | Mutex _mtx; |
RobMeades | 0:5cffef3371f6 | 262 | |
RobMeades | 0:5cffef3371f6 | 263 | /** General info about the modem as a device. |
RobMeades | 0:5cffef3371f6 | 264 | */ |
RobMeades | 0:5cffef3371f6 | 265 | DeviceInfo _dev_info; |
RobMeades | 0:5cffef3371f6 | 266 | |
RobMeades | 0:5cffef3371f6 | 267 | /** The SIM PIN to use. |
RobMeades | 0:5cffef3371f6 | 268 | */ |
RobMeades | 0:5cffef3371f6 | 269 | const char *_pin; |
RobMeades | 0:5cffef3371f6 | 270 | |
RobMeades | 0:5cffef3371f6 | 271 | /** Set to true to spit out debug traces. |
RobMeades | 0:5cffef3371f6 | 272 | */ |
RobMeades | 0:5cffef3371f6 | 273 | bool _debug_trace_on; |
rob.meades@u-blox.com | 4:2e640a101db1 | 274 | |
rob.meades@u-blox.com | 4:2e640a101db1 | 275 | /** The baud rate to the modem. |
rob.meades@u-blox.com | 4:2e640a101db1 | 276 | */ |
rob.meades@u-blox.com | 4:2e640a101db1 | 277 | int _baud; |
RobMeades | 0:5cffef3371f6 | 278 | |
RobMeades | 0:5cffef3371f6 | 279 | /** True if the modem is ready register to the network, |
RobMeades | 0:5cffef3371f6 | 280 | * otherwise false. |
RobMeades | 0:5cffef3371f6 | 281 | */ |
RobMeades | 0:5cffef3371f6 | 282 | bool _modem_initialised; |
RobMeades | 0:5cffef3371f6 | 283 | |
RobMeades | 0:5cffef3371f6 | 284 | /** True it the SIM requires a PIN, otherwise false. |
RobMeades | 0:5cffef3371f6 | 285 | */ |
RobMeades | 0:5cffef3371f6 | 286 | bool _sim_pin_check_enabled; |
RobMeades | 0:5cffef3371f6 | 287 | |
RobMeades | 0:5cffef3371f6 | 288 | /** Sets the modem up for powering on |
RobMeades | 0:5cffef3371f6 | 289 | * |
RobMeades | 0:5cffef3371f6 | 290 | * modem_init() is equivalent to plugging in the device, e.g., attaching power and serial port. |
RobMeades | 0:5cffef3371f6 | 291 | * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target. |
RobMeades | 0:5cffef3371f6 | 292 | */ |
RobMeades | 0:5cffef3371f6 | 293 | virtual void modem_init(); |
RobMeades | 0:5cffef3371f6 | 294 | |
RobMeades | 0:5cffef3371f6 | 295 | /** Sets the modem in unplugged state |
RobMeades | 0:5cffef3371f6 | 296 | * |
RobMeades | 0:5cffef3371f6 | 297 | * modem_deinit() will be equivalent to pulling the plug off of the device, i.e., detaching power |
RobMeades | 0:5cffef3371f6 | 298 | * and serial port. This puts the modem in lowest power state. |
RobMeades | 0:5cffef3371f6 | 299 | * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target. |
RobMeades | 0:5cffef3371f6 | 300 | */ |
RobMeades | 0:5cffef3371f6 | 301 | virtual void modem_deinit(); |
RobMeades | 0:5cffef3371f6 | 302 | |
RobMeades | 0:5cffef3371f6 | 303 | /** Powers up the modem |
RobMeades | 0:5cffef3371f6 | 304 | * |
RobMeades | 0:5cffef3371f6 | 305 | * modem_power_up() is equivalent to pressing the soft power button. |
RobMeades | 0:5cffef3371f6 | 306 | * The driver may repeat this if the modem is not responsive to AT commands. |
RobMeades | 0:5cffef3371f6 | 307 | * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target. |
RobMeades | 0:5cffef3371f6 | 308 | */ |
RobMeades | 0:5cffef3371f6 | 309 | virtual void modem_power_up(); |
RobMeades | 0:5cffef3371f6 | 310 | |
RobMeades | 0:5cffef3371f6 | 311 | /** Powers down the modem |
RobMeades | 0:5cffef3371f6 | 312 | * |
RobMeades | 0:5cffef3371f6 | 313 | * modem_power_down() is equivalent to turning off the modem by button press. |
RobMeades | 0:5cffef3371f6 | 314 | * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target. |
RobMeades | 0:5cffef3371f6 | 315 | */ |
RobMeades | 0:5cffef3371f6 | 316 | virtual void modem_power_down(); |
RobMeades | 0:5cffef3371f6 | 317 | |
RobMeades | 0:5cffef3371f6 | 318 | /* Note: constructor and destructor protected so that this |
RobMeades | 0:5cffef3371f6 | 319 | * class can only ever be inherited, never used directly. |
RobMeades | 0:5cffef3371f6 | 320 | */ |
RobMeades | 0:5cffef3371f6 | 321 | UbloxCellularBase(); |
RobMeades | 0:5cffef3371f6 | 322 | ~UbloxCellularBase(); |
RobMeades | 0:5cffef3371f6 | 323 | |
RobMeades | 0:5cffef3371f6 | 324 | /** Initialise this class. |
RobMeades | 0:5cffef3371f6 | 325 | * |
RobMeades | 0:5cffef3371f6 | 326 | * @param tx the UART TX data pin to which the modem is attached. |
RobMeades | 0:5cffef3371f6 | 327 | * @param rx the UART RX data pin to which the modem is attached. |
RobMeades | 0:5cffef3371f6 | 328 | * @param baud the UART baud rate. |
RobMeades | 0:5cffef3371f6 | 329 | * @param debug_on true to switch AT interface debug on, otherwise false. |
RobMeades | 0:5cffef3371f6 | 330 | * |
RobMeades | 0:5cffef3371f6 | 331 | * Note: it would be more natural to do this in the constructor |
RobMeades | 0:5cffef3371f6 | 332 | * however, to avoid the diamond of death, this class is only |
RobMeades | 0:5cffef3371f6 | 333 | * every inherited virtually. Classes that are inherited virtually |
RobMeades | 0:5cffef3371f6 | 334 | * do not get passed parameters in their constructor and hence |
RobMeades | 0:5cffef3371f6 | 335 | * classInit() must be called separately by the first one to wake |
RobMeades | 0:5cffef3371f6 | 336 | * the beast. |
RobMeades | 0:5cffef3371f6 | 337 | */ |
RobMeades | 0:5cffef3371f6 | 338 | void baseClassInit(PinName tx = MDMTXD, |
RobMeades | 0:5cffef3371f6 | 339 | PinName rx = MDMRXD, |
RobMeades | 0:5cffef3371f6 | 340 | int baud = MBED_CONF_UBLOX_CELL_BAUD_RATE, |
RobMeades | 0:5cffef3371f6 | 341 | bool debug_on = false); |
RobMeades | 0:5cffef3371f6 | 342 | |
RobMeades | 0:5cffef3371f6 | 343 | /** Set the AT parser timeout. |
RobMeades | 0:5cffef3371f6 | 344 | */ |
RobMeades | 0:5cffef3371f6 | 345 | void at_set_timeout(int timeout); |
RobMeades | 0:5cffef3371f6 | 346 | |
RobMeades | 0:5cffef3371f6 | 347 | /** Read up to size characters from buf |
RobMeades | 0:5cffef3371f6 | 348 | * or until the character "end" is reached, overwriting |
RobMeades | 0:5cffef3371f6 | 349 | * the newline with 0 and ensuring a terminator |
RobMeades | 0:5cffef3371f6 | 350 | * in all cases. |
RobMeades | 0:5cffef3371f6 | 351 | * |
RobMeades | 0:5cffef3371f6 | 352 | * @param buf the buffer to write to. |
RobMeades | 0:5cffef3371f6 | 353 | * @param size the size of the buffer. |
RobMeades | 0:5cffef3371f6 | 354 | * @param end the character to stop at. |
RobMeades | 0:5cffef3371f6 | 355 | * @return the number of characters read, |
RobMeades | 0:5cffef3371f6 | 356 | * not including the terminator. |
RobMeades | 0:5cffef3371f6 | 357 | */ |
RobMeades | 0:5cffef3371f6 | 358 | int read_at_to_char(char * buf, int size, char end); |
RobMeades | 0:5cffef3371f6 | 359 | |
RobMeades | 0:5cffef3371f6 | 360 | /** Powers up the modem. |
RobMeades | 0:5cffef3371f6 | 361 | * |
RobMeades | 0:5cffef3371f6 | 362 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 363 | */ |
RobMeades | 0:5cffef3371f6 | 364 | bool power_up(); |
RobMeades | 0:5cffef3371f6 | 365 | |
RobMeades | 0:5cffef3371f6 | 366 | /** Power down the modem. |
RobMeades | 0:5cffef3371f6 | 367 | */ |
RobMeades | 0:5cffef3371f6 | 368 | void power_down(); |
RobMeades | 0:5cffef3371f6 | 369 | |
RobMeades | 0:5cffef3371f6 | 370 | /** Lock a mutex when accessing the modem. |
RobMeades | 0:5cffef3371f6 | 371 | */ |
RobMeades | 0:5cffef3371f6 | 372 | void lock(void) { _mtx.lock(); } |
RobMeades | 0:5cffef3371f6 | 373 | |
RobMeades | 0:5cffef3371f6 | 374 | /** Helper to make sure that lock unlock pair is always balanced |
RobMeades | 0:5cffef3371f6 | 375 | */ |
RobMeades | 0:5cffef3371f6 | 376 | #define LOCK() { lock() |
RobMeades | 0:5cffef3371f6 | 377 | |
RobMeades | 0:5cffef3371f6 | 378 | /** Unlock the modem when done accessing it. |
RobMeades | 0:5cffef3371f6 | 379 | */ |
RobMeades | 0:5cffef3371f6 | 380 | void unlock(void) { _mtx.unlock(); } |
RobMeades | 0:5cffef3371f6 | 381 | |
RobMeades | 0:5cffef3371f6 | 382 | /** Helper to make sure that lock unlock pair is always balanced |
RobMeades | 0:5cffef3371f6 | 383 | */ |
RobMeades | 0:5cffef3371f6 | 384 | #define UNLOCK() } unlock() |
RobMeades | 0:5cffef3371f6 | 385 | |
RobMeades | 0:5cffef3371f6 | 386 | /** Set the device identity in _dev_info |
RobMeades | 0:5cffef3371f6 | 387 | * based on the ATI string returned by |
RobMeades | 0:5cffef3371f6 | 388 | * the module. |
RobMeades | 0:5cffef3371f6 | 389 | * |
RobMeades | 0:5cffef3371f6 | 390 | * @return true if dev is a known value, |
RobMeades | 0:5cffef3371f6 | 391 | * otherwise false. |
RobMeades | 0:5cffef3371f6 | 392 | */ |
RobMeades | 0:5cffef3371f6 | 393 | bool set_device_identity(DeviceType *dev); |
RobMeades | 0:5cffef3371f6 | 394 | |
RobMeades | 0:5cffef3371f6 | 395 | /** Perform any modem initialisation that is |
RobMeades | 0:5cffef3371f6 | 396 | * specialised by device type. |
RobMeades | 0:5cffef3371f6 | 397 | * |
RobMeades | 0:5cffef3371f6 | 398 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 399 | */ |
RobMeades | 0:5cffef3371f6 | 400 | bool device_init(DeviceType dev); |
RobMeades | 0:5cffef3371f6 | 401 | |
RobMeades | 0:5cffef3371f6 | 402 | /** Set up the SIM. |
RobMeades | 0:5cffef3371f6 | 403 | * |
RobMeades | 0:5cffef3371f6 | 404 | * @return true if successful, otherwiss false. |
RobMeades | 0:5cffef3371f6 | 405 | */ |
RobMeades | 0:5cffef3371f6 | 406 | bool initialise_sim_card(); |
RobMeades | 0:5cffef3371f6 | 407 | |
RobMeades | 0:5cffef3371f6 | 408 | private: |
RobMeades | 0:5cffef3371f6 | 409 | |
RobMeades | 0:5cffef3371f6 | 410 | void set_nwk_reg_status_csd(int status); |
RobMeades | 0:5cffef3371f6 | 411 | void set_nwk_reg_status_psd(int status); |
RobMeades | 0:5cffef3371f6 | 412 | void set_nwk_reg_status_eps(int status); |
RobMeades | 0:5cffef3371f6 | 413 | void set_rat(int AcTStatus); |
RobMeades | 0:5cffef3371f6 | 414 | bool get_iccid(); |
RobMeades | 0:5cffef3371f6 | 415 | bool get_imsi(); |
RobMeades | 0:5cffef3371f6 | 416 | bool get_imei(); |
RobMeades | 0:5cffef3371f6 | 417 | bool get_meid(); |
RobMeades | 0:5cffef3371f6 | 418 | bool set_sms(); |
RobMeades | 0:5cffef3371f6 | 419 | void parser_abort_cb(); |
RobMeades | 0:5cffef3371f6 | 420 | void CMX_ERROR_URC(); |
RobMeades | 0:5cffef3371f6 | 421 | void CREG_URC(); |
RobMeades | 0:5cffef3371f6 | 422 | void CGREG_URC(); |
RobMeades | 0:5cffef3371f6 | 423 | void CEREG_URC(); |
RobMeades | 0:5cffef3371f6 | 424 | void UMWI_URC(); |
RobMeades | 0:5cffef3371f6 | 425 | }; |
RobMeades | 0:5cffef3371f6 | 426 | |
rob.meades@u-blox.com | 1:5aaecf2572dc | 427 | #endif // _UBLOX_CELLULAR_BASE_ |
RobMeades | 0:5cffef3371f6 | 428 |