ublox-cellular-base-n2xx
UbloxCellularBaseN2xx.h@11:e9b490d21afb, 2020-01-06 (annotated)
- Committer:
- mudassar0121
- Date:
- Mon Jan 06 14:50:14 2020 +0500
- Revision:
- 11:e9b490d21afb
- Parent:
- 10:1afe5ed24f0c
Replaced depreciated wait_ms with ThisThread::sleep_for
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
philware | 1:d4ff95ab40ae | 1 | /* Copyright (c) 2017 ARM Limited |
philware | 1:d4ff95ab40ae | 2 | * |
philware | 1:d4ff95ab40ae | 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
philware | 1:d4ff95ab40ae | 4 | * you may not use this file except in compliance with the License. |
philware | 1:d4ff95ab40ae | 5 | * You may obtain a copy of the License at |
philware | 1:d4ff95ab40ae | 6 | * |
philware | 1:d4ff95ab40ae | 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
philware | 1:d4ff95ab40ae | 8 | * |
philware | 1:d4ff95ab40ae | 9 | * Unless required by applicable law or agreed to in writing, software |
philware | 1:d4ff95ab40ae | 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
philware | 1:d4ff95ab40ae | 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
philware | 1:d4ff95ab40ae | 12 | * See the License for the specific language governing permissions and |
philware | 1:d4ff95ab40ae | 13 | * limitations under the License. |
philware | 1:d4ff95ab40ae | 14 | */ |
philware | 1:d4ff95ab40ae | 15 | |
philware | 1:d4ff95ab40ae | 16 | #ifndef _UBLOX_CELLULAR_BASE_N2XX_ |
philware | 1:d4ff95ab40ae | 17 | #define _UBLOX_CELLULAR_BASE_N2XX_ |
philware | 1:d4ff95ab40ae | 18 | |
philware | 1:d4ff95ab40ae | 19 | #include "mbed.h" |
philware | 1:d4ff95ab40ae | 20 | #include "ATCmdParser.h" |
philware | 1:d4ff95ab40ae | 21 | #include "FileHandle.h" |
philware | 1:d4ff95ab40ae | 22 | |
philware | 1:d4ff95ab40ae | 23 | /********************************************************************** |
philware | 1:d4ff95ab40ae | 24 | * CLASSES |
philware | 1:d4ff95ab40ae | 25 | **********************************************************************/ |
philware | 1:d4ff95ab40ae | 26 | |
philware | 1:d4ff95ab40ae | 27 | /** UbloxCellularBase class. |
philware | 1:d4ff95ab40ae | 28 | * |
philware | 1:d4ff95ab40ae | 29 | * This class provides all the base support for generic u-blox modems |
philware | 1:d4ff95ab40ae | 30 | * on C030 and C027 boards: module identification, power-up, network |
philware | 1:d4ff95ab40ae | 31 | * registration, etc. |
philware | 1:d4ff95ab40ae | 32 | */ |
philware | 1:d4ff95ab40ae | 33 | class UbloxCellularBaseN2xx { |
philware | 1:d4ff95ab40ae | 34 | |
philware | 1:d4ff95ab40ae | 35 | public: |
philware | 1:d4ff95ab40ae | 36 | /** Circuit Switched network registration status (CREG Usage). |
philware | 1:d4ff95ab40ae | 37 | * UBX-13001820 - AT Commands Example Application Note (Section 7.10.3). |
philware | 1:d4ff95ab40ae | 38 | */ |
philware | 1:d4ff95ab40ae | 39 | typedef enum { |
philware | 1:d4ff95ab40ae | 40 | CSD_NOT_REGISTERED_NOT_SEARCHING = 0, |
philware | 1:d4ff95ab40ae | 41 | CSD_REGISTERED = 1, |
philware | 1:d4ff95ab40ae | 42 | CSD_NOT_REGISTERED_SEARCHING = 2, |
philware | 1:d4ff95ab40ae | 43 | CSD_REGISTRATION_DENIED = 3, |
philware | 1:d4ff95ab40ae | 44 | CSD_UNKNOWN_COVERAGE = 4, |
philware | 1:d4ff95ab40ae | 45 | CSD_REGISTERED_ROAMING = 5, |
philware | 1:d4ff95ab40ae | 46 | CSD_SMS_ONLY = 6, |
philware | 1:d4ff95ab40ae | 47 | CSD_SMS_ONLY_ROAMING = 7, |
philware | 1:d4ff95ab40ae | 48 | CSD_CSFB_NOT_PREFERRED = 9 |
philware | 1:d4ff95ab40ae | 49 | } NetworkRegistrationStatusCsd; |
philware | 1:d4ff95ab40ae | 50 | |
philware | 1:d4ff95ab40ae | 51 | /** Packet Switched network registration status (CGREG Usage). |
philware | 1:d4ff95ab40ae | 52 | * UBX-13001820 - AT Commands Example Application Note (Section 18.27.3). |
philware | 1:d4ff95ab40ae | 53 | */ |
philware | 1:d4ff95ab40ae | 54 | typedef enum { |
philware | 1:d4ff95ab40ae | 55 | PSD_NOT_REGISTERED_NOT_SEARCHING = 0, |
philware | 1:d4ff95ab40ae | 56 | PSD_REGISTERED = 1, |
philware | 1:d4ff95ab40ae | 57 | PSD_NOT_REGISTERED_SEARCHING = 2, |
philware | 1:d4ff95ab40ae | 58 | PSD_REGISTRATION_DENIED = 3, |
philware | 1:d4ff95ab40ae | 59 | PSD_UNKNOWN_COVERAGE = 4, |
philware | 1:d4ff95ab40ae | 60 | PSD_REGISTERED_ROAMING = 5, |
philware | 1:d4ff95ab40ae | 61 | PSD_EMERGENCY_SERVICES_ONLY = 8 |
philware | 1:d4ff95ab40ae | 62 | } NetworkRegistrationStatusPsd; |
philware | 1:d4ff95ab40ae | 63 | |
philware | 1:d4ff95ab40ae | 64 | /** EPS network registration status (CEREG Usage). |
philware | 1:d4ff95ab40ae | 65 | * UBX-13001820 - AT Commands Example Application Note (Section 18.36.3). |
philware | 1:d4ff95ab40ae | 66 | */ |
philware | 1:d4ff95ab40ae | 67 | typedef enum { |
philware | 1:d4ff95ab40ae | 68 | EPS_NOT_REGISTERED_NOT_SEARCHING = 0, |
philware | 1:d4ff95ab40ae | 69 | EPS_REGISTERED = 1, |
philware | 1:d4ff95ab40ae | 70 | EPS_NOT_REGISTERED_SEARCHING = 2, |
philware | 1:d4ff95ab40ae | 71 | EPS_REGISTRATION_DENIED = 3, |
philware | 1:d4ff95ab40ae | 72 | EPS_UNKNOWN_COVERAGE = 4, |
philware | 1:d4ff95ab40ae | 73 | EPS_REGISTERED_ROAMING = 5, |
philware | 1:d4ff95ab40ae | 74 | EPS_EMERGENCY_SERVICES_ONLY = 8 |
philware | 1:d4ff95ab40ae | 75 | } NetworkRegistrationStatusEps; |
philware | 1:d4ff95ab40ae | 76 | |
philware | 1:d4ff95ab40ae | 77 | /** Initialise the modem, ready for use. |
philware | 1:d4ff95ab40ae | 78 | * |
philware | 1:d4ff95ab40ae | 79 | * @param pin PIN for the SIM card. |
philware | 1:d4ff95ab40ae | 80 | * @return true if successful, otherwise false. |
philware | 1:d4ff95ab40ae | 81 | */ |
philware | 1:d4ff95ab40ae | 82 | bool init(const char *pin = 0); |
philware | 1:d4ff95ab40ae | 83 | |
philware | 1:d4ff95ab40ae | 84 | /** Perform registration with the network. |
philware | 1:d4ff95ab40ae | 85 | * |
philware | 1:d4ff95ab40ae | 86 | * @return true if successful, otherwise false. |
philware | 1:d4ff95ab40ae | 87 | */ |
philware | 1:d4ff95ab40ae | 88 | bool nwk_registration(); |
philware | 1:d4ff95ab40ae | 89 | |
philware | 1:d4ff95ab40ae | 90 | /** True if the modem is registered for circuit |
philware | 1:d4ff95ab40ae | 91 | * switched data, otherwise false. |
philware | 1:d4ff95ab40ae | 92 | */ |
philware | 1:d4ff95ab40ae | 93 | bool is_registered_csd(); |
philware | 1:d4ff95ab40ae | 94 | |
philware | 1:d4ff95ab40ae | 95 | /** True if the modem is registered for packet |
philware | 1:d4ff95ab40ae | 96 | * switched data, otherwise false. |
philware | 1:d4ff95ab40ae | 97 | */ |
philware | 1:d4ff95ab40ae | 98 | bool is_registered_psd(); |
philware | 1:d4ff95ab40ae | 99 | |
philware | 1:d4ff95ab40ae | 100 | /** True if the modem is registered for enhanced |
philware | 1:d4ff95ab40ae | 101 | * packet switched data (i.e. LTE and beyond), |
philware | 1:d4ff95ab40ae | 102 | * otherwise false. |
philware | 1:d4ff95ab40ae | 103 | */ |
philware | 1:d4ff95ab40ae | 104 | bool is_registered_eps(); |
philware | 1:d4ff95ab40ae | 105 | |
philware | 1:d4ff95ab40ae | 106 | /** Perform deregistration from the network. |
philware | 1:d4ff95ab40ae | 107 | * |
philware | 1:d4ff95ab40ae | 108 | * @return true if successful, otherwise false. |
philware | 1:d4ff95ab40ae | 109 | */ |
philware | 1:d4ff95ab40ae | 110 | bool nwk_deregistration(); |
philware | 1:d4ff95ab40ae | 111 | |
philware | 1:d4ff95ab40ae | 112 | /** Put the modem into its lowest power state. |
philware | 1:d4ff95ab40ae | 113 | */ |
philware | 1:d4ff95ab40ae | 114 | void deinit(); |
philware | 1:d4ff95ab40ae | 115 | |
philware | 1:d4ff95ab40ae | 116 | /** Set the PIN code for the SIM card. |
philware | 1:d4ff95ab40ae | 117 | * |
philware | 1:d4ff95ab40ae | 118 | * @param pin PIN for the SIM card. |
philware | 1:d4ff95ab40ae | 119 | */ |
philware | 1:d4ff95ab40ae | 120 | void set_pin(const char *pin); |
philware | 1:d4ff95ab40ae | 121 | |
philware | 1:d4ff95ab40ae | 122 | /** Enable or disable SIM pin checking. |
philware | 1:d4ff95ab40ae | 123 | * |
philware | 1:d4ff95ab40ae | 124 | * @param enableNotDisable true if SIM PIN checking is to be enabled, |
philware | 1:d4ff95ab40ae | 125 | * otherwise false. |
philware | 1:d4ff95ab40ae | 126 | * @return true if successful, otherwise false. |
philware | 1:d4ff95ab40ae | 127 | */ |
philware | 1:d4ff95ab40ae | 128 | bool sim_pin_check_enable(bool enableNotDisable); |
philware | 1:d4ff95ab40ae | 129 | |
philware | 1:d4ff95ab40ae | 130 | /** Change the SIM pin. |
philware | 1:d4ff95ab40ae | 131 | * |
philware | 1:d4ff95ab40ae | 132 | * @param new_pin the new PIN to use. |
philware | 1:d4ff95ab40ae | 133 | * @return true if successful, otherwise false. |
philware | 1:d4ff95ab40ae | 134 | */ |
philware | 1:d4ff95ab40ae | 135 | bool change_sim_pin(const char *new_pin); |
philware | 1:d4ff95ab40ae | 136 | |
philware | 1:d4ff95ab40ae | 137 | /** get the Manufacturer Info |
philware | 1:d4ff95ab40ae | 138 | * |
philware | 1:d4ff95ab40ae | 139 | * @param response the manufacturer |
philware | 1:d4ff95ab40ae | 140 | * @return ture if successful, otherwise false. |
philware | 1:d4ff95ab40ae | 141 | */ |
philware | 1:d4ff95ab40ae | 142 | bool cgmi(const char *response); |
philware | 1:d4ff95ab40ae | 143 | |
philware | 1:d4ff95ab40ae | 144 | /** get the Module name |
philware | 1:d4ff95ab40ae | 145 | * |
philware | 1:d4ff95ab40ae | 146 | * @param response the module name |
philware | 1:d4ff95ab40ae | 147 | * @return ture if successful, otherwise false. |
philware | 1:d4ff95ab40ae | 148 | */ |
philware | 1:d4ff95ab40ae | 149 | bool cgmm(const char *response); |
philware | 1:d4ff95ab40ae | 150 | |
philware | 1:d4ff95ab40ae | 151 | /** get International Module Subscriber Information |
philware | 1:d4ff95ab40ae | 152 | * |
philware | 1:d4ff95ab40ae | 153 | * @param response the IMSI |
philware | 1:d4ff95ab40ae | 154 | * @return ture if successful, otherwise false. |
philware | 1:d4ff95ab40ae | 155 | */ |
philware | 1:d4ff95ab40ae | 156 | bool cimi(const char *response); |
philware | 1:d4ff95ab40ae | 157 | |
philware | 1:d4ff95ab40ae | 158 | /** get the serial number |
philware | 1:d4ff95ab40ae | 159 | * |
philware | 1:d4ff95ab40ae | 160 | * @param response the serial number |
philware | 1:d4ff95ab40ae | 161 | * @return ture if successful, otherwise false. |
philware | 1:d4ff95ab40ae | 162 | */ |
philware | 1:d4ff95ab40ae | 163 | bool ccid(const char *response); |
philware | 1:d4ff95ab40ae | 164 | |
philware | 1:d4ff95ab40ae | 165 | /** get the firmware version |
philware | 1:d4ff95ab40ae | 166 | * |
philware | 1:d4ff95ab40ae | 167 | * @param response the firmware version |
philware | 1:d4ff95ab40ae | 168 | * @return ture if successful, otherwise false. |
philware | 1:d4ff95ab40ae | 169 | */ |
philware | 1:d4ff95ab40ae | 170 | bool cgmr(const char *response); |
philware | 1:d4ff95ab40ae | 171 | |
philware | 1:d4ff95ab40ae | 172 | /** get the IMEI |
philware | 1:d4ff95ab40ae | 173 | * |
philware | 1:d4ff95ab40ae | 174 | * @param response the IMEI |
philware | 1:d4ff95ab40ae | 175 | * @return ture if successful, otherwise false. |
philware | 1:d4ff95ab40ae | 176 | */ |
philware | 1:d4ff95ab40ae | 177 | bool cgsn(int snt, const char *response); |
philware | 1:d4ff95ab40ae | 178 | |
philware | 1:d4ff95ab40ae | 179 | /** Connect to the specified PLMN |
philware | 1:d4ff95ab40ae | 180 | * |
philware | 1:d4ff95ab40ae | 181 | * @param plmn the PLMN to register on |
philware | 1:d4ff95ab40ae | 182 | * @return ture if successful, otherwise false. |
philware | 1:d4ff95ab40ae | 183 | */ |
philware | 1:d4ff95ab40ae | 184 | bool cops(const char*plmn); |
philware | 1:d4ff95ab40ae | 185 | |
philware | 1:d4ff95ab40ae | 186 | /** Set the mode of operation for registering |
philware | 1:d4ff95ab40ae | 187 | * |
philware | 1:d4ff95ab40ae | 188 | * @param mode 0=Auto, 1=Manual, 2=Deregister |
philware | 1:d4ff95ab40ae | 189 | * @return ture if successful, otherwise false. |
philware | 1:d4ff95ab40ae | 190 | */ |
philware | 1:d4ff95ab40ae | 191 | bool cops(int mode); |
philware | 1:d4ff95ab40ae | 192 | |
philware | 1:d4ff95ab40ae | 193 | /** Gets the COPS mode of operation |
philware | 1:d4ff95ab40ae | 194 | * |
philware | 1:d4ff95ab40ae | 195 | * @param status returns the mode |
philware | 1:d4ff95ab40ae | 196 | * @return ture if successful, otherwise false. |
philware | 1:d4ff95ab40ae | 197 | */ |
philware | 1:d4ff95ab40ae | 198 | bool get_cops(int *status); |
philware | 1:d4ff95ab40ae | 199 | |
philware | 1:d4ff95ab40ae | 200 | /** Enable or Disable the Radio/Modem |
philware | 1:d4ff95ab40ae | 201 | * |
philware | 1:d4ff95ab40ae | 202 | * @param mode 0=disable, 1=enable |
philware | 1:d4ff95ab40ae | 203 | * @return ture if successful, otherwise false. |
philware | 1:d4ff95ab40ae | 204 | */ |
philware | 1:d4ff95ab40ae | 205 | bool cfun(int mode); |
philware | 1:d4ff95ab40ae | 206 | |
philware | 1:d4ff95ab40ae | 207 | /** Reboot the SARA-N2xx module |
philware | 1:d4ff95ab40ae | 208 | * |
philware | 1:d4ff95ab40ae | 209 | * @return ture if successful, otherwise false. |
philware | 1:d4ff95ab40ae | 210 | */ |
philware | 1:d4ff95ab40ae | 211 | bool reboot(); |
philware | 1:d4ff95ab40ae | 212 | |
philware | 1:d4ff95ab40ae | 213 | /** Sets the AUTOCONNECT feature of SARA-N2xx module |
philware | 1:d4ff95ab40ae | 214 | * |
philware | 1:d4ff95ab40ae | 215 | * @param state true to enable, false to disable |
philware | 1:d4ff95ab40ae | 216 | * @return ture if successful, otherwise false. |
philware | 1:d4ff95ab40ae | 217 | */ |
philware | 1:d4ff95ab40ae | 218 | bool auto_connect(bool state); |
philware | 1:d4ff95ab40ae | 219 | |
philware | 1:d4ff95ab40ae | 220 | /** Set the specified NCONFIG parameter |
philware | 1:d4ff95ab40ae | 221 | * |
philware | 1:d4ff95ab40ae | 222 | * @param name name of the NCONFIG parameter to enable/disable |
philware | 1:d4ff95ab40ae | 223 | * @param state true to enable, false to disable |
philware | 1:d4ff95ab40ae | 224 | * @return ture if successful, otherwise false. |
philware | 1:d4ff95ab40ae | 225 | */ |
philware | 1:d4ff95ab40ae | 226 | bool nconfig(const char *name, bool state); |
mudassar0121 | 7:f1c3373e4ff5 | 227 | |
mudassar0121 | 7:f1c3373e4ff5 | 228 | |
mudassar0121 | 7:f1c3373e4ff5 | 229 | /** Get the IMEI. |
mudassar0121 | 7:f1c3373e4ff5 | 230 | * |
mudassar0121 | 7:f1c3373e4ff5 | 231 | * @return true if successful, otherwise false. |
mudassar0121 | 7:f1c3373e4ff5 | 232 | */ |
philware | 10:1afe5ed24f0c | 233 | MBED_DEPRECATED("This method is now replaced by const char * imei(), please use that instead") |
fahim alavi |
8:72412b28c93f | 234 | bool get_imei(char *buffer, int size); |
philware | 10:1afe5ed24f0c | 235 | |
philware | 10:1afe5ed24f0c | 236 | /** Get the IMEI of the module. |
philware | 10:1afe5ed24f0c | 237 | * |
philware | 10:1afe5ed24f0c | 238 | * @return a pointer to the IMEI as a null-terminated string. |
philware | 10:1afe5ed24f0c | 239 | */ |
philware | 10:1afe5ed24f0c | 240 | const char *imei(); |
philware | 10:1afe5ed24f0c | 241 | |
philware | 10:1afe5ed24f0c | 242 | /** Get the Mobile Equipment ID (which may be the same as the IMEI). |
philware | 10:1afe5ed24f0c | 243 | * |
philware | 10:1afe5ed24f0c | 244 | * @return a pointer to the Mobile Equipment ID as a null-terminated string. |
philware | 10:1afe5ed24f0c | 245 | */ |
philware | 10:1afe5ed24f0c | 246 | const char *meid(); |
philware | 10:1afe5ed24f0c | 247 | |
philware | 10:1afe5ed24f0c | 248 | /** Get the IMSI of the SIM. |
philware | 10:1afe5ed24f0c | 249 | * |
philware | 10:1afe5ed24f0c | 250 | * @return a pointer to the IMSI as a null-terminated string. |
philware | 10:1afe5ed24f0c | 251 | */ |
philware | 10:1afe5ed24f0c | 252 | const char *imsi(); |
philware | 10:1afe5ed24f0c | 253 | |
philware | 10:1afe5ed24f0c | 254 | /** Get the ICCID of the SIM. |
philware | 10:1afe5ed24f0c | 255 | * |
philware | 10:1afe5ed24f0c | 256 | * @return a pointer to the ICCID as a null-terminated string. |
philware | 10:1afe5ed24f0c | 257 | */ |
philware | 10:1afe5ed24f0c | 258 | const char *iccid(); |
philware | 10:1afe5ed24f0c | 259 | |
philware | 10:1afe5ed24f0c | 260 | /** Get the RSSI. |
philware | 10:1afe5ed24f0c | 261 | * |
philware | 10:1afe5ed24f0c | 262 | * @return the RSSI in dBm. If it is not possible to obtain an |
philware | 10:1afe5ed24f0c | 263 | * RSSI reading at the time (e.g. because the modem is in |
philware | 10:1afe5ed24f0c | 264 | * data mode rather than AT command mode) then 0 is returned. |
philware | 10:1afe5ed24f0c | 265 | */ |
philware | 10:1afe5ed24f0c | 266 | int rssi(); |
philware | 1:d4ff95ab40ae | 267 | |
philware | 1:d4ff95ab40ae | 268 | protected: |
philware | 1:d4ff95ab40ae | 269 | |
philware | 1:d4ff95ab40ae | 270 | #define OUTPUT_ENTER_KEY "\r" |
philware | 1:d4ff95ab40ae | 271 | |
philware | 1:d4ff95ab40ae | 272 | #if MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_BUFFER_SIZE |
philware | 1:d4ff95ab40ae | 273 | #define AT_PARSER_BUFFER_SIZE MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_BUFFER_SIZE |
philware | 1:d4ff95ab40ae | 274 | #else |
philware | 1:d4ff95ab40ae | 275 | #define AT_PARSER_BUFFER_SIZE 256 |
philware | 1:d4ff95ab40ae | 276 | #endif |
philware | 1:d4ff95ab40ae | 277 | |
philware | 1:d4ff95ab40ae | 278 | #if MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_TIMEOUT |
philware | 1:d4ff95ab40ae | 279 | #define AT_PARSER_TIMEOUT MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_TIMEOUT |
philware | 1:d4ff95ab40ae | 280 | #else |
philware | 1:d4ff95ab40ae | 281 | #define AT_PARSER_TIMEOUT 8*1000 // Milliseconds |
philware | 1:d4ff95ab40ae | 282 | #endif |
philware | 1:d4ff95ab40ae | 283 | |
philware | 1:d4ff95ab40ae | 284 | /** A string that would not normally be sent by the modem on the AT interface. |
philware | 1:d4ff95ab40ae | 285 | */ |
philware | 1:d4ff95ab40ae | 286 | #define UNNATURAL_STRING "\x01" |
philware | 1:d4ff95ab40ae | 287 | |
philware | 1:d4ff95ab40ae | 288 | /** Supported u-blox modem variants. |
philware | 1:d4ff95ab40ae | 289 | */ |
philware | 1:d4ff95ab40ae | 290 | typedef enum { |
philware | 1:d4ff95ab40ae | 291 | DEV_TYPE_NONE = 0, |
philware | 1:d4ff95ab40ae | 292 | DEV_SARA_G35, |
philware | 1:d4ff95ab40ae | 293 | DEV_LISA_U2, |
philware | 1:d4ff95ab40ae | 294 | DEV_LISA_U2_03S, |
philware | 1:d4ff95ab40ae | 295 | DEV_SARA_U2, |
philware | 1:d4ff95ab40ae | 296 | DEV_LEON_G2, |
philware | 1:d4ff95ab40ae | 297 | DEV_TOBY_L2, |
philware | 1:d4ff95ab40ae | 298 | DEV_MPCI_L2, |
philware | 1:d4ff95ab40ae | 299 | DEV_SARA_N2, |
philware | 1:d4ff95ab40ae | 300 | } DeviceType; |
philware | 1:d4ff95ab40ae | 301 | |
philware | 1:d4ff95ab40ae | 302 | /** Network registration status. |
philware | 1:d4ff95ab40ae | 303 | * UBX-13001820 - AT Commands Example Application Note (Section 4.1.4.5). |
philware | 1:d4ff95ab40ae | 304 | */ |
philware | 1:d4ff95ab40ae | 305 | typedef enum { |
philware | 1:d4ff95ab40ae | 306 | GSM = 0, |
philware | 1:d4ff95ab40ae | 307 | COMPACT_GSM = 1, |
philware | 1:d4ff95ab40ae | 308 | UTRAN = 2, |
philware | 1:d4ff95ab40ae | 309 | EDGE = 3, |
philware | 1:d4ff95ab40ae | 310 | HSDPA = 4, |
philware | 1:d4ff95ab40ae | 311 | HSUPA = 5, |
philware | 1:d4ff95ab40ae | 312 | HSDPA_HSUPA = 6, |
philware | 1:d4ff95ab40ae | 313 | LTE = 7 |
philware | 1:d4ff95ab40ae | 314 | } RadioAccessNetworkType; |
philware | 1:d4ff95ab40ae | 315 | |
philware | 1:d4ff95ab40ae | 316 | /** Info about the modem. |
philware | 1:d4ff95ab40ae | 317 | */ |
philware | 1:d4ff95ab40ae | 318 | typedef struct { |
philware | 1:d4ff95ab40ae | 319 | DeviceType dev; |
philware | 1:d4ff95ab40ae | 320 | char iccid[20 + 1]; //!< Integrated Circuit Card ID. |
philware | 1:d4ff95ab40ae | 321 | char imsi[15 + 1]; //!< International Mobile Station Identity. |
philware | 1:d4ff95ab40ae | 322 | char imei[15 + 1]; //!< International Mobile Equipment Identity. |
philware | 1:d4ff95ab40ae | 323 | char meid[18 + 1]; //!< Mobile Equipment IDentifier. |
philware | 1:d4ff95ab40ae | 324 | volatile RadioAccessNetworkType rat; //!< Type of network (e.g. 2G, 3G, LTE). |
philware | 1:d4ff95ab40ae | 325 | volatile NetworkRegistrationStatusCsd reg_status_csd; //!< Circuit switched attach status. |
philware | 1:d4ff95ab40ae | 326 | volatile NetworkRegistrationStatusPsd reg_status_psd; //!< Packet switched attach status. |
philware | 1:d4ff95ab40ae | 327 | volatile NetworkRegistrationStatusEps reg_status_eps; //!< Evolved Packet Switched (e.g. LTE) attach status. |
philware | 1:d4ff95ab40ae | 328 | } DeviceInfo; |
philware | 1:d4ff95ab40ae | 329 | |
philware | 1:d4ff95ab40ae | 330 | typedef struct { |
philware | 1:d4ff95ab40ae | 331 | char cgmm[32+1]; |
philware | 1:d4ff95ab40ae | 332 | char cgmi[32+1]; |
philware | 1:d4ff95ab40ae | 333 | char cgmr[32+1]; |
philware | 1:d4ff95ab40ae | 334 | char cgsn[32+1]; |
philware | 1:d4ff95ab40ae | 335 | } sara_n2xx_info; |
philware | 1:d4ff95ab40ae | 336 | |
philware | 1:d4ff95ab40ae | 337 | /* IMPORTANT: the variables below are available to |
philware | 1:d4ff95ab40ae | 338 | * classes that inherit this in order to keep things |
philware | 1:d4ff95ab40ae | 339 | * simple. However, ONLY this class should free |
philware | 1:d4ff95ab40ae | 340 | * any of the pointers, or there will be havoc. |
philware | 1:d4ff95ab40ae | 341 | */ |
philware | 1:d4ff95ab40ae | 342 | |
philware | 1:d4ff95ab40ae | 343 | /** Point to the instance of the AT parser in use. |
philware | 1:d4ff95ab40ae | 344 | */ |
philware | 1:d4ff95ab40ae | 345 | ATCmdParser *_at; |
philware | 1:d4ff95ab40ae | 346 | |
philware | 1:d4ff95ab40ae | 347 | /** The current AT parser timeout value. |
philware | 1:d4ff95ab40ae | 348 | */ |
philware | 1:d4ff95ab40ae | 349 | int _at_timeout; |
philware | 1:d4ff95ab40ae | 350 | |
philware | 1:d4ff95ab40ae | 351 | /** File handle used by the AT parser. |
philware | 1:d4ff95ab40ae | 352 | */ |
philware | 1:d4ff95ab40ae | 353 | FileHandle *_fh; |
philware | 1:d4ff95ab40ae | 354 | |
philware | 1:d4ff95ab40ae | 355 | /** The mutex resource. |
philware | 1:d4ff95ab40ae | 356 | */ |
philware | 1:d4ff95ab40ae | 357 | Mutex _mtx; |
philware | 1:d4ff95ab40ae | 358 | |
philware | 1:d4ff95ab40ae | 359 | /** General info about the modem as a device. |
philware | 1:d4ff95ab40ae | 360 | */ |
philware | 1:d4ff95ab40ae | 361 | DeviceInfo _dev_info; |
philware | 1:d4ff95ab40ae | 362 | |
philware | 1:d4ff95ab40ae | 363 | /** |
philware | 1:d4ff95ab40ae | 364 | * Information about the SARA-N2xx module |
philware | 1:d4ff95ab40ae | 365 | */ |
philware | 1:d4ff95ab40ae | 366 | sara_n2xx_info _sara_n2xx_info; |
philware | 1:d4ff95ab40ae | 367 | |
philware | 1:d4ff95ab40ae | 368 | /** The SIM PIN to use. |
philware | 1:d4ff95ab40ae | 369 | */ |
philware | 1:d4ff95ab40ae | 370 | const char *_pin; |
philware | 1:d4ff95ab40ae | 371 | |
philware | 1:d4ff95ab40ae | 372 | /** Set to true to spit out debug traces. |
philware | 1:d4ff95ab40ae | 373 | */ |
philware | 1:d4ff95ab40ae | 374 | bool _debug_trace_on; |
philware | 1:d4ff95ab40ae | 375 | |
philware | 1:d4ff95ab40ae | 376 | /** True if the modem is ready register to the network, |
philware | 1:d4ff95ab40ae | 377 | * otherwise false. |
philware | 1:d4ff95ab40ae | 378 | */ |
philware | 1:d4ff95ab40ae | 379 | bool _modem_initialised; |
philware | 1:d4ff95ab40ae | 380 | |
philware | 1:d4ff95ab40ae | 381 | /** True it the SIM requires a PIN, otherwise false. |
philware | 1:d4ff95ab40ae | 382 | */ |
philware | 1:d4ff95ab40ae | 383 | bool _sim_pin_check_enabled; |
philware | 1:d4ff95ab40ae | 384 | |
philware | 1:d4ff95ab40ae | 385 | /** Sets the modem up for powering on |
philware | 1:d4ff95ab40ae | 386 | * |
philware | 1:d4ff95ab40ae | 387 | * modem_init() is equivalent to plugging in the device, e.g., attaching power and serial port. |
philware | 1:d4ff95ab40ae | 388 | * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target. |
philware | 1:d4ff95ab40ae | 389 | */ |
philware | 1:d4ff95ab40ae | 390 | virtual void modem_init(); |
philware | 1:d4ff95ab40ae | 391 | |
philware | 1:d4ff95ab40ae | 392 | /** Sets the modem in unplugged state |
philware | 1:d4ff95ab40ae | 393 | * |
philware | 1:d4ff95ab40ae | 394 | * modem_deinit() will be equivalent to pulling the plug off of the device, i.e., detaching power |
philware | 1:d4ff95ab40ae | 395 | * and serial port. This puts the modem in lowest power state. |
philware | 1:d4ff95ab40ae | 396 | * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target. |
philware | 1:d4ff95ab40ae | 397 | */ |
philware | 1:d4ff95ab40ae | 398 | virtual void modem_deinit(); |
philware | 1:d4ff95ab40ae | 399 | |
philware | 1:d4ff95ab40ae | 400 | /** Powers up the modem |
philware | 1:d4ff95ab40ae | 401 | * |
philware | 1:d4ff95ab40ae | 402 | * modem_power_up() is equivalent to pressing the soft power button. |
philware | 1:d4ff95ab40ae | 403 | * The driver may repeat this if the modem is not responsive to AT commands. |
philware | 1:d4ff95ab40ae | 404 | * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target. |
philware | 1:d4ff95ab40ae | 405 | */ |
philware | 1:d4ff95ab40ae | 406 | virtual void modem_power_up(); |
philware | 1:d4ff95ab40ae | 407 | |
philware | 1:d4ff95ab40ae | 408 | /** Powers down the modem |
philware | 1:d4ff95ab40ae | 409 | * |
philware | 1:d4ff95ab40ae | 410 | * modem_power_down() is equivalent to turning off the modem by button press. |
philware | 1:d4ff95ab40ae | 411 | * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target. |
philware | 1:d4ff95ab40ae | 412 | */ |
philware | 1:d4ff95ab40ae | 413 | virtual void modem_power_down(); |
philware | 1:d4ff95ab40ae | 414 | |
philware | 1:d4ff95ab40ae | 415 | /* Note: constructor and destructor protected so that this |
philware | 1:d4ff95ab40ae | 416 | * class can only ever be inherited, never used directly. |
philware | 1:d4ff95ab40ae | 417 | */ |
philware | 1:d4ff95ab40ae | 418 | UbloxCellularBaseN2xx(); |
philware | 1:d4ff95ab40ae | 419 | ~UbloxCellularBaseN2xx(); |
philware | 1:d4ff95ab40ae | 420 | |
philware | 1:d4ff95ab40ae | 421 | /** Initialise this class. |
philware | 1:d4ff95ab40ae | 422 | * |
philware | 1:d4ff95ab40ae | 423 | * @param tx the UART TX data pin to which the modem is attached. |
philware | 1:d4ff95ab40ae | 424 | * @param rx the UART RX data pin to which the modem is attached. |
philware | 1:d4ff95ab40ae | 425 | * @param baud the UART baud rate. |
philware | 1:d4ff95ab40ae | 426 | * @param debug_on true to switch AT interface debug on, otherwise false. |
philware | 1:d4ff95ab40ae | 427 | * |
philware | 1:d4ff95ab40ae | 428 | * Note: it would be more natural to do this in the constructor |
philware | 1:d4ff95ab40ae | 429 | * however, to avoid the diamond of death, this class is only |
philware | 1:d4ff95ab40ae | 430 | * every inherited virtually. Classes that are inherited virtually |
philware | 1:d4ff95ab40ae | 431 | * do not get passed parameters in their constructor and hence |
philware | 1:d4ff95ab40ae | 432 | * classInit() must be called separately by the first one to wake |
philware | 1:d4ff95ab40ae | 433 | * the beast. |
philware | 1:d4ff95ab40ae | 434 | */ |
philware | 1:d4ff95ab40ae | 435 | void baseClassInit(PinName tx = MDMTXD, |
philware | 1:d4ff95ab40ae | 436 | PinName rx = MDMRXD, |
philware | 4:8cd7a682a5ab | 437 | int baud = MBED_CONF_UBLOX_CELL_N2XX_BAUD_RATE, |
philware | 1:d4ff95ab40ae | 438 | bool debug_on = false); |
philware | 1:d4ff95ab40ae | 439 | |
philware | 1:d4ff95ab40ae | 440 | /** Set the AT parser timeout. |
philware | 1:d4ff95ab40ae | 441 | */ |
philware | 1:d4ff95ab40ae | 442 | void at_set_timeout(int timeout); |
philware | 1:d4ff95ab40ae | 443 | |
philware | 1:d4ff95ab40ae | 444 | /** Read up to size characters from buf |
philware | 1:d4ff95ab40ae | 445 | * or until the character "end" is reached, overwriting |
philware | 1:d4ff95ab40ae | 446 | * the newline with 0 and ensuring a terminator |
philware | 1:d4ff95ab40ae | 447 | * in all cases. |
philware | 1:d4ff95ab40ae | 448 | * |
philware | 1:d4ff95ab40ae | 449 | * @param buf the buffer to write to. |
philware | 1:d4ff95ab40ae | 450 | * @param size the size of the buffer. |
philware | 1:d4ff95ab40ae | 451 | * @param end the character to stop at. |
philware | 1:d4ff95ab40ae | 452 | * @return the number of characters read, |
philware | 1:d4ff95ab40ae | 453 | * not including the terminator. |
philware | 1:d4ff95ab40ae | 454 | */ |
philware | 1:d4ff95ab40ae | 455 | int read_at_to_char(char * buf, int size, char end); |
philware | 1:d4ff95ab40ae | 456 | |
philware | 1:d4ff95ab40ae | 457 | /** Powers up the modem. |
philware | 1:d4ff95ab40ae | 458 | * |
philware | 1:d4ff95ab40ae | 459 | * @return true if successful, otherwise false. |
philware | 1:d4ff95ab40ae | 460 | */ |
philware | 1:d4ff95ab40ae | 461 | bool power_up(); |
philware | 1:d4ff95ab40ae | 462 | |
philware | 1:d4ff95ab40ae | 463 | /** Power down the modem. |
philware | 1:d4ff95ab40ae | 464 | */ |
philware | 1:d4ff95ab40ae | 465 | void power_down(); |
philware | 1:d4ff95ab40ae | 466 | |
philware | 1:d4ff95ab40ae | 467 | /** Lock a mutex when accessing the modem. |
philware | 1:d4ff95ab40ae | 468 | */ |
philware | 1:d4ff95ab40ae | 469 | void lock(void) { _mtx.lock(); } |
philware | 1:d4ff95ab40ae | 470 | |
philware | 1:d4ff95ab40ae | 471 | /** Helper to make sure that lock unlock pair is always balanced |
philware | 1:d4ff95ab40ae | 472 | */ |
philware | 1:d4ff95ab40ae | 473 | #define LOCK() { lock() |
philware | 1:d4ff95ab40ae | 474 | |
philware | 1:d4ff95ab40ae | 475 | /** Unlock the modem when done accessing it. |
philware | 1:d4ff95ab40ae | 476 | */ |
philware | 1:d4ff95ab40ae | 477 | void unlock(void) { _mtx.unlock(); } |
philware | 1:d4ff95ab40ae | 478 | |
philware | 1:d4ff95ab40ae | 479 | /** Helper to make sure that lock unlock pair is always balanced |
philware | 1:d4ff95ab40ae | 480 | */ |
philware | 1:d4ff95ab40ae | 481 | #define UNLOCK() } unlock() |
philware | 1:d4ff95ab40ae | 482 | |
philware | 1:d4ff95ab40ae | 483 | /** Set the device identity in _dev_info |
philware | 1:d4ff95ab40ae | 484 | * based on the ATI string returned by |
philware | 1:d4ff95ab40ae | 485 | * the module. |
philware | 1:d4ff95ab40ae | 486 | * |
philware | 1:d4ff95ab40ae | 487 | * @return true if dev is a known value, |
philware | 1:d4ff95ab40ae | 488 | * otherwise false. |
philware | 1:d4ff95ab40ae | 489 | */ |
philware | 1:d4ff95ab40ae | 490 | bool set_device_identity(DeviceType *dev); |
philware | 1:d4ff95ab40ae | 491 | |
philware | 1:d4ff95ab40ae | 492 | /** Perform any modem initialisation that is |
philware | 1:d4ff95ab40ae | 493 | * specialised by device type. |
philware | 1:d4ff95ab40ae | 494 | * |
philware | 1:d4ff95ab40ae | 495 | * @return true if successful, otherwise false. |
philware | 1:d4ff95ab40ae | 496 | */ |
philware | 1:d4ff95ab40ae | 497 | bool device_init(DeviceType dev); |
philware | 1:d4ff95ab40ae | 498 | |
philware | 1:d4ff95ab40ae | 499 | /** Set up the SIM. |
philware | 1:d4ff95ab40ae | 500 | * |
philware | 1:d4ff95ab40ae | 501 | * @return true if successful, otherwiss false. |
philware | 1:d4ff95ab40ae | 502 | */ |
philware | 1:d4ff95ab40ae | 503 | bool initialise_sim_card(); |
philware | 1:d4ff95ab40ae | 504 | |
philware | 1:d4ff95ab40ae | 505 | int read_at_to_newline(char * buf, int size); |
philware | 1:d4ff95ab40ae | 506 | |
philware | 1:d4ff95ab40ae | 507 | private: |
philware | 1:d4ff95ab40ae | 508 | void set_nwk_reg_status_csd(int status); |
philware | 1:d4ff95ab40ae | 509 | void set_nwk_reg_status_psd(int status); |
philware | 1:d4ff95ab40ae | 510 | void set_nwk_reg_status_eps(int status); |
philware | 1:d4ff95ab40ae | 511 | void set_rat(int AcTStatus); |
philware | 1:d4ff95ab40ae | 512 | bool get_iccid(); |
philware | 1:d4ff95ab40ae | 513 | bool get_imsi(); |
philware | 1:d4ff95ab40ae | 514 | bool get_imei(); |
philware | 1:d4ff95ab40ae | 515 | bool get_meid(); // *** NOT IMPLEMENTED, returns false |
philware | 1:d4ff95ab40ae | 516 | bool set_sms(); // *** NOT IMPLEMENTED, returns false |
philware | 1:d4ff95ab40ae | 517 | void parser_abort_cb(); |
philware | 1:d4ff95ab40ae | 518 | void CMX_ERROR_URC(); |
philware | 1:d4ff95ab40ae | 519 | void CEREG_URC(); |
philware | 1:d4ff95ab40ae | 520 | |
philware | 1:d4ff95ab40ae | 521 | bool get_sara_n2xx_info(); |
philware | 1:d4ff95ab40ae | 522 | bool cereg(int n); |
philware | 1:d4ff95ab40ae | 523 | nsapi_error_t get_cereg(); |
philware | 1:d4ff95ab40ae | 524 | nsapi_error_t get_cscon(); |
philware | 1:d4ff95ab40ae | 525 | nsapi_error_t get_csq(); |
philware | 1:d4ff95ab40ae | 526 | |
philware | 1:d4ff95ab40ae | 527 | bool at_send(const char *cmd); |
philware | 1:d4ff95ab40ae | 528 | bool at_send(const char *cmd, int n); |
philware | 1:d4ff95ab40ae | 529 | bool at_send(const char *cmd, const char *arg); |
philware | 1:d4ff95ab40ae | 530 | |
philware | 1:d4ff95ab40ae | 531 | bool at_req(const char *cmd, const char *recvFormat, const char *response); |
philware | 1:d4ff95ab40ae | 532 | bool at_req(const char *cmd, const char *recvFormat, int *response); |
philware | 1:d4ff95ab40ae | 533 | }; |
philware | 1:d4ff95ab40ae | 534 | |
philware | 1:d4ff95ab40ae | 535 | #endif // _UBLOX_CELLULAR_BASE_ |
philware | 1:d4ff95ab40ae | 536 |