Base class for the u-blox N2xx modems. Cannot be used standalone, only inherited by classes that do properly useful stuff. Or, to put it another way, if you are using any of the classes ending with 'n2xx', you will need this class also. Note: requires the N211 module firmware to be at least 06.57 A01.02.

Dependents:   example-ublox-cellular-interface HelloMQTT example-ublox-cellular-interface_r410M example-ublox-mbed-client ... more

Committer:
philware
Date:
Mon Jun 26 13:48:04 2017 +0100
Revision:
1:d4ff95ab40ae
Child:
4:8cd7a682a5ab
Base class for SARA-N2xx modules including helper functions for SARA AT commands.

Who changed what in which revision?

UserRevisionLine numberNew 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);
philware 1:d4ff95ab40ae 227
philware 1:d4ff95ab40ae 228 protected:
philware 1:d4ff95ab40ae 229
philware 1:d4ff95ab40ae 230 #define OUTPUT_ENTER_KEY "\r"
philware 1:d4ff95ab40ae 231
philware 1:d4ff95ab40ae 232 #if MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_BUFFER_SIZE
philware 1:d4ff95ab40ae 233 #define AT_PARSER_BUFFER_SIZE MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_BUFFER_SIZE
philware 1:d4ff95ab40ae 234 #else
philware 1:d4ff95ab40ae 235 #define AT_PARSER_BUFFER_SIZE 256
philware 1:d4ff95ab40ae 236 #endif
philware 1:d4ff95ab40ae 237
philware 1:d4ff95ab40ae 238 #if MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_TIMEOUT
philware 1:d4ff95ab40ae 239 #define AT_PARSER_TIMEOUT MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_TIMEOUT
philware 1:d4ff95ab40ae 240 #else
philware 1:d4ff95ab40ae 241 #define AT_PARSER_TIMEOUT 8*1000 // Milliseconds
philware 1:d4ff95ab40ae 242 #endif
philware 1:d4ff95ab40ae 243
philware 1:d4ff95ab40ae 244 /** A string that would not normally be sent by the modem on the AT interface.
philware 1:d4ff95ab40ae 245 */
philware 1:d4ff95ab40ae 246 #define UNNATURAL_STRING "\x01"
philware 1:d4ff95ab40ae 247
philware 1:d4ff95ab40ae 248 /** Supported u-blox modem variants.
philware 1:d4ff95ab40ae 249 */
philware 1:d4ff95ab40ae 250 typedef enum {
philware 1:d4ff95ab40ae 251 DEV_TYPE_NONE = 0,
philware 1:d4ff95ab40ae 252 DEV_SARA_G35,
philware 1:d4ff95ab40ae 253 DEV_LISA_U2,
philware 1:d4ff95ab40ae 254 DEV_LISA_U2_03S,
philware 1:d4ff95ab40ae 255 DEV_SARA_U2,
philware 1:d4ff95ab40ae 256 DEV_LEON_G2,
philware 1:d4ff95ab40ae 257 DEV_TOBY_L2,
philware 1:d4ff95ab40ae 258 DEV_MPCI_L2,
philware 1:d4ff95ab40ae 259 DEV_SARA_N2,
philware 1:d4ff95ab40ae 260 } DeviceType;
philware 1:d4ff95ab40ae 261
philware 1:d4ff95ab40ae 262 /** Network registration status.
philware 1:d4ff95ab40ae 263 * UBX-13001820 - AT Commands Example Application Note (Section 4.1.4.5).
philware 1:d4ff95ab40ae 264 */
philware 1:d4ff95ab40ae 265 typedef enum {
philware 1:d4ff95ab40ae 266 GSM = 0,
philware 1:d4ff95ab40ae 267 COMPACT_GSM = 1,
philware 1:d4ff95ab40ae 268 UTRAN = 2,
philware 1:d4ff95ab40ae 269 EDGE = 3,
philware 1:d4ff95ab40ae 270 HSDPA = 4,
philware 1:d4ff95ab40ae 271 HSUPA = 5,
philware 1:d4ff95ab40ae 272 HSDPA_HSUPA = 6,
philware 1:d4ff95ab40ae 273 LTE = 7
philware 1:d4ff95ab40ae 274 } RadioAccessNetworkType;
philware 1:d4ff95ab40ae 275
philware 1:d4ff95ab40ae 276 /** Info about the modem.
philware 1:d4ff95ab40ae 277 */
philware 1:d4ff95ab40ae 278 typedef struct {
philware 1:d4ff95ab40ae 279 DeviceType dev;
philware 1:d4ff95ab40ae 280 char iccid[20 + 1]; //!< Integrated Circuit Card ID.
philware 1:d4ff95ab40ae 281 char imsi[15 + 1]; //!< International Mobile Station Identity.
philware 1:d4ff95ab40ae 282 char imei[15 + 1]; //!< International Mobile Equipment Identity.
philware 1:d4ff95ab40ae 283 char meid[18 + 1]; //!< Mobile Equipment IDentifier.
philware 1:d4ff95ab40ae 284 volatile RadioAccessNetworkType rat; //!< Type of network (e.g. 2G, 3G, LTE).
philware 1:d4ff95ab40ae 285 volatile NetworkRegistrationStatusCsd reg_status_csd; //!< Circuit switched attach status.
philware 1:d4ff95ab40ae 286 volatile NetworkRegistrationStatusPsd reg_status_psd; //!< Packet switched attach status.
philware 1:d4ff95ab40ae 287 volatile NetworkRegistrationStatusEps reg_status_eps; //!< Evolved Packet Switched (e.g. LTE) attach status.
philware 1:d4ff95ab40ae 288 } DeviceInfo;
philware 1:d4ff95ab40ae 289
philware 1:d4ff95ab40ae 290 typedef struct {
philware 1:d4ff95ab40ae 291 char cgmm[32+1];
philware 1:d4ff95ab40ae 292 char cgmi[32+1];
philware 1:d4ff95ab40ae 293 char cgmr[32+1];
philware 1:d4ff95ab40ae 294 char cgsn[32+1];
philware 1:d4ff95ab40ae 295 } sara_n2xx_info;
philware 1:d4ff95ab40ae 296
philware 1:d4ff95ab40ae 297 /* IMPORTANT: the variables below are available to
philware 1:d4ff95ab40ae 298 * classes that inherit this in order to keep things
philware 1:d4ff95ab40ae 299 * simple. However, ONLY this class should free
philware 1:d4ff95ab40ae 300 * any of the pointers, or there will be havoc.
philware 1:d4ff95ab40ae 301 */
philware 1:d4ff95ab40ae 302
philware 1:d4ff95ab40ae 303 /** Point to the instance of the AT parser in use.
philware 1:d4ff95ab40ae 304 */
philware 1:d4ff95ab40ae 305 ATCmdParser *_at;
philware 1:d4ff95ab40ae 306
philware 1:d4ff95ab40ae 307 /** The current AT parser timeout value.
philware 1:d4ff95ab40ae 308 */
philware 1:d4ff95ab40ae 309 int _at_timeout;
philware 1:d4ff95ab40ae 310
philware 1:d4ff95ab40ae 311 /** File handle used by the AT parser.
philware 1:d4ff95ab40ae 312 */
philware 1:d4ff95ab40ae 313 FileHandle *_fh;
philware 1:d4ff95ab40ae 314
philware 1:d4ff95ab40ae 315 /** The mutex resource.
philware 1:d4ff95ab40ae 316 */
philware 1:d4ff95ab40ae 317 Mutex _mtx;
philware 1:d4ff95ab40ae 318
philware 1:d4ff95ab40ae 319 /** General info about the modem as a device.
philware 1:d4ff95ab40ae 320 */
philware 1:d4ff95ab40ae 321 DeviceInfo _dev_info;
philware 1:d4ff95ab40ae 322
philware 1:d4ff95ab40ae 323 /**
philware 1:d4ff95ab40ae 324 * Information about the SARA-N2xx module
philware 1:d4ff95ab40ae 325 */
philware 1:d4ff95ab40ae 326 sara_n2xx_info _sara_n2xx_info;
philware 1:d4ff95ab40ae 327
philware 1:d4ff95ab40ae 328 /** The SIM PIN to use.
philware 1:d4ff95ab40ae 329 */
philware 1:d4ff95ab40ae 330 const char *_pin;
philware 1:d4ff95ab40ae 331
philware 1:d4ff95ab40ae 332 /** Set to true to spit out debug traces.
philware 1:d4ff95ab40ae 333 */
philware 1:d4ff95ab40ae 334 bool _debug_trace_on;
philware 1:d4ff95ab40ae 335
philware 1:d4ff95ab40ae 336 /** True if the modem is ready register to the network,
philware 1:d4ff95ab40ae 337 * otherwise false.
philware 1:d4ff95ab40ae 338 */
philware 1:d4ff95ab40ae 339 bool _modem_initialised;
philware 1:d4ff95ab40ae 340
philware 1:d4ff95ab40ae 341 /** True it the SIM requires a PIN, otherwise false.
philware 1:d4ff95ab40ae 342 */
philware 1:d4ff95ab40ae 343 bool _sim_pin_check_enabled;
philware 1:d4ff95ab40ae 344
philware 1:d4ff95ab40ae 345 /** Sets the modem up for powering on
philware 1:d4ff95ab40ae 346 *
philware 1:d4ff95ab40ae 347 * modem_init() is equivalent to plugging in the device, e.g., attaching power and serial port.
philware 1:d4ff95ab40ae 348 * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target.
philware 1:d4ff95ab40ae 349 */
philware 1:d4ff95ab40ae 350 virtual void modem_init();
philware 1:d4ff95ab40ae 351
philware 1:d4ff95ab40ae 352 /** Sets the modem in unplugged state
philware 1:d4ff95ab40ae 353 *
philware 1:d4ff95ab40ae 354 * modem_deinit() will be equivalent to pulling the plug off of the device, i.e., detaching power
philware 1:d4ff95ab40ae 355 * and serial port. This puts the modem in lowest power state.
philware 1:d4ff95ab40ae 356 * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target.
philware 1:d4ff95ab40ae 357 */
philware 1:d4ff95ab40ae 358 virtual void modem_deinit();
philware 1:d4ff95ab40ae 359
philware 1:d4ff95ab40ae 360 /** Powers up the modem
philware 1:d4ff95ab40ae 361 *
philware 1:d4ff95ab40ae 362 * modem_power_up() is equivalent to pressing the soft power button.
philware 1:d4ff95ab40ae 363 * The driver may repeat this if the modem is not responsive to AT commands.
philware 1:d4ff95ab40ae 364 * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target.
philware 1:d4ff95ab40ae 365 */
philware 1:d4ff95ab40ae 366 virtual void modem_power_up();
philware 1:d4ff95ab40ae 367
philware 1:d4ff95ab40ae 368 /** Powers down the modem
philware 1:d4ff95ab40ae 369 *
philware 1:d4ff95ab40ae 370 * modem_power_down() is equivalent to turning off the modem by button press.
philware 1:d4ff95ab40ae 371 * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target.
philware 1:d4ff95ab40ae 372 */
philware 1:d4ff95ab40ae 373 virtual void modem_power_down();
philware 1:d4ff95ab40ae 374
philware 1:d4ff95ab40ae 375 /* Note: constructor and destructor protected so that this
philware 1:d4ff95ab40ae 376 * class can only ever be inherited, never used directly.
philware 1:d4ff95ab40ae 377 */
philware 1:d4ff95ab40ae 378 UbloxCellularBaseN2xx();
philware 1:d4ff95ab40ae 379 ~UbloxCellularBaseN2xx();
philware 1:d4ff95ab40ae 380
philware 1:d4ff95ab40ae 381 /** Initialise this class.
philware 1:d4ff95ab40ae 382 *
philware 1:d4ff95ab40ae 383 * @param tx the UART TX data pin to which the modem is attached.
philware 1:d4ff95ab40ae 384 * @param rx the UART RX data pin to which the modem is attached.
philware 1:d4ff95ab40ae 385 * @param baud the UART baud rate.
philware 1:d4ff95ab40ae 386 * @param debug_on true to switch AT interface debug on, otherwise false.
philware 1:d4ff95ab40ae 387 *
philware 1:d4ff95ab40ae 388 * Note: it would be more natural to do this in the constructor
philware 1:d4ff95ab40ae 389 * however, to avoid the diamond of death, this class is only
philware 1:d4ff95ab40ae 390 * every inherited virtually. Classes that are inherited virtually
philware 1:d4ff95ab40ae 391 * do not get passed parameters in their constructor and hence
philware 1:d4ff95ab40ae 392 * classInit() must be called separately by the first one to wake
philware 1:d4ff95ab40ae 393 * the beast.
philware 1:d4ff95ab40ae 394 */
philware 1:d4ff95ab40ae 395 void baseClassInit(PinName tx = MDMTXD,
philware 1:d4ff95ab40ae 396 PinName rx = MDMRXD,
philware 1:d4ff95ab40ae 397 int baud = MBED_CONF_UBLOX_CELL_BAUD_RATE,
philware 1:d4ff95ab40ae 398 bool debug_on = false);
philware 1:d4ff95ab40ae 399
philware 1:d4ff95ab40ae 400 /** Set the AT parser timeout.
philware 1:d4ff95ab40ae 401 */
philware 1:d4ff95ab40ae 402 void at_set_timeout(int timeout);
philware 1:d4ff95ab40ae 403
philware 1:d4ff95ab40ae 404 /** Read up to size characters from buf
philware 1:d4ff95ab40ae 405 * or until the character "end" is reached, overwriting
philware 1:d4ff95ab40ae 406 * the newline with 0 and ensuring a terminator
philware 1:d4ff95ab40ae 407 * in all cases.
philware 1:d4ff95ab40ae 408 *
philware 1:d4ff95ab40ae 409 * @param buf the buffer to write to.
philware 1:d4ff95ab40ae 410 * @param size the size of the buffer.
philware 1:d4ff95ab40ae 411 * @param end the character to stop at.
philware 1:d4ff95ab40ae 412 * @return the number of characters read,
philware 1:d4ff95ab40ae 413 * not including the terminator.
philware 1:d4ff95ab40ae 414 */
philware 1:d4ff95ab40ae 415 int read_at_to_char(char * buf, int size, char end);
philware 1:d4ff95ab40ae 416
philware 1:d4ff95ab40ae 417 /** Powers up the modem.
philware 1:d4ff95ab40ae 418 *
philware 1:d4ff95ab40ae 419 * @return true if successful, otherwise false.
philware 1:d4ff95ab40ae 420 */
philware 1:d4ff95ab40ae 421 bool power_up();
philware 1:d4ff95ab40ae 422
philware 1:d4ff95ab40ae 423 /** Power down the modem.
philware 1:d4ff95ab40ae 424 */
philware 1:d4ff95ab40ae 425 void power_down();
philware 1:d4ff95ab40ae 426
philware 1:d4ff95ab40ae 427 /** Lock a mutex when accessing the modem.
philware 1:d4ff95ab40ae 428 */
philware 1:d4ff95ab40ae 429 void lock(void) { _mtx.lock(); }
philware 1:d4ff95ab40ae 430
philware 1:d4ff95ab40ae 431 /** Helper to make sure that lock unlock pair is always balanced
philware 1:d4ff95ab40ae 432 */
philware 1:d4ff95ab40ae 433 #define LOCK() { lock()
philware 1:d4ff95ab40ae 434
philware 1:d4ff95ab40ae 435 /** Unlock the modem when done accessing it.
philware 1:d4ff95ab40ae 436 */
philware 1:d4ff95ab40ae 437 void unlock(void) { _mtx.unlock(); }
philware 1:d4ff95ab40ae 438
philware 1:d4ff95ab40ae 439 /** Helper to make sure that lock unlock pair is always balanced
philware 1:d4ff95ab40ae 440 */
philware 1:d4ff95ab40ae 441 #define UNLOCK() } unlock()
philware 1:d4ff95ab40ae 442
philware 1:d4ff95ab40ae 443 /** Set the device identity in _dev_info
philware 1:d4ff95ab40ae 444 * based on the ATI string returned by
philware 1:d4ff95ab40ae 445 * the module.
philware 1:d4ff95ab40ae 446 *
philware 1:d4ff95ab40ae 447 * @return true if dev is a known value,
philware 1:d4ff95ab40ae 448 * otherwise false.
philware 1:d4ff95ab40ae 449 */
philware 1:d4ff95ab40ae 450 bool set_device_identity(DeviceType *dev);
philware 1:d4ff95ab40ae 451
philware 1:d4ff95ab40ae 452 /** Perform any modem initialisation that is
philware 1:d4ff95ab40ae 453 * specialised by device type.
philware 1:d4ff95ab40ae 454 *
philware 1:d4ff95ab40ae 455 * @return true if successful, otherwise false.
philware 1:d4ff95ab40ae 456 */
philware 1:d4ff95ab40ae 457 bool device_init(DeviceType dev);
philware 1:d4ff95ab40ae 458
philware 1:d4ff95ab40ae 459 /** Set up the SIM.
philware 1:d4ff95ab40ae 460 *
philware 1:d4ff95ab40ae 461 * @return true if successful, otherwiss false.
philware 1:d4ff95ab40ae 462 */
philware 1:d4ff95ab40ae 463 bool initialise_sim_card();
philware 1:d4ff95ab40ae 464
philware 1:d4ff95ab40ae 465 int read_at_to_newline(char * buf, int size);
philware 1:d4ff95ab40ae 466
philware 1:d4ff95ab40ae 467 private:
philware 1:d4ff95ab40ae 468 void set_nwk_reg_status_csd(int status);
philware 1:d4ff95ab40ae 469 void set_nwk_reg_status_psd(int status);
philware 1:d4ff95ab40ae 470 void set_nwk_reg_status_eps(int status);
philware 1:d4ff95ab40ae 471 void set_rat(int AcTStatus);
philware 1:d4ff95ab40ae 472 bool get_iccid();
philware 1:d4ff95ab40ae 473 bool get_imsi();
philware 1:d4ff95ab40ae 474 bool get_imei();
philware 1:d4ff95ab40ae 475 bool get_meid(); // *** NOT IMPLEMENTED, returns false
philware 1:d4ff95ab40ae 476 bool set_sms(); // *** NOT IMPLEMENTED, returns false
philware 1:d4ff95ab40ae 477 void parser_abort_cb();
philware 1:d4ff95ab40ae 478 void CMX_ERROR_URC();
philware 1:d4ff95ab40ae 479 void CEREG_URC();
philware 1:d4ff95ab40ae 480
philware 1:d4ff95ab40ae 481 bool get_sara_n2xx_info();
philware 1:d4ff95ab40ae 482 bool cereg(int n);
philware 1:d4ff95ab40ae 483 nsapi_error_t get_cereg();
philware 1:d4ff95ab40ae 484 nsapi_error_t get_cscon();
philware 1:d4ff95ab40ae 485 nsapi_error_t get_csq();
philware 1:d4ff95ab40ae 486
philware 1:d4ff95ab40ae 487 bool at_send(const char *cmd);
philware 1:d4ff95ab40ae 488 bool at_send(const char *cmd, int n);
philware 1:d4ff95ab40ae 489 bool at_send(const char *cmd, const char *arg);
philware 1:d4ff95ab40ae 490
philware 1:d4ff95ab40ae 491 bool at_req(const char *cmd, const char *recvFormat, const char *response);
philware 1:d4ff95ab40ae 492 bool at_req(const char *cmd, const char *recvFormat, int *response);
philware 1:d4ff95ab40ae 493 };
philware 1:d4ff95ab40ae 494
philware 1:d4ff95ab40ae 495 #endif // _UBLOX_CELLULAR_BASE_
philware 1:d4ff95ab40ae 496