ublox-cellular-base_R4_PR
UbloxCellularBase.h@1:5aaecf2572dc, 2017-06-12 (annotated)
- Committer:
- rob.meades@u-blox.com
- Date:
- Mon Jun 12 23:03:38 2017 +0100
- Revision:
- 1:5aaecf2572dc
- Parent:
- 0:5cffef3371f6
- Child:
- 4:2e640a101db1
Tested on C027.
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 | 0:5cffef3371f6 | 20 | #include "ATCmdParser.h" |
RobMeades | 0:5cffef3371f6 | 21 | #include "FileHandle.h" |
RobMeades | 0:5cffef3371f6 | 22 | |
RobMeades | 0:5cffef3371f6 | 23 | /********************************************************************** |
RobMeades | 0:5cffef3371f6 | 24 | * CLASSES |
RobMeades | 0:5cffef3371f6 | 25 | **********************************************************************/ |
RobMeades | 0:5cffef3371f6 | 26 | |
RobMeades | 0:5cffef3371f6 | 27 | /** UbloxCellularBase class. |
RobMeades | 0:5cffef3371f6 | 28 | * |
RobMeades | 0:5cffef3371f6 | 29 | * This class provides all the base support for generic u-blox modems |
RobMeades | 0:5cffef3371f6 | 30 | * on C030 and C027 boards: module identification, power-up, network |
RobMeades | 0:5cffef3371f6 | 31 | * registration, etc. |
RobMeades | 0:5cffef3371f6 | 32 | */ |
RobMeades | 0:5cffef3371f6 | 33 | class UbloxCellularBase { |
RobMeades | 0:5cffef3371f6 | 34 | |
RobMeades | 0:5cffef3371f6 | 35 | public: |
RobMeades | 0:5cffef3371f6 | 36 | /** Circuit Switched network registration status (CREG Usage). |
RobMeades | 0:5cffef3371f6 | 37 | * UBX-13001820 - AT Commands Example Application Note (Section 7.10.3). |
RobMeades | 0:5cffef3371f6 | 38 | */ |
RobMeades | 0:5cffef3371f6 | 39 | typedef enum { |
RobMeades | 0:5cffef3371f6 | 40 | CSD_NOT_REGISTERED_NOT_SEARCHING = 0, |
RobMeades | 0:5cffef3371f6 | 41 | CSD_REGISTERED = 1, |
RobMeades | 0:5cffef3371f6 | 42 | CSD_NOT_REGISTERED_SEARCHING = 2, |
RobMeades | 0:5cffef3371f6 | 43 | CSD_REGISTRATION_DENIED = 3, |
RobMeades | 0:5cffef3371f6 | 44 | CSD_UNKNOWN_COVERAGE = 4, |
RobMeades | 0:5cffef3371f6 | 45 | CSD_REGISTERED_ROAMING = 5, |
RobMeades | 0:5cffef3371f6 | 46 | CSD_SMS_ONLY = 6, |
RobMeades | 0:5cffef3371f6 | 47 | CSD_SMS_ONLY_ROAMING = 7, |
RobMeades | 0:5cffef3371f6 | 48 | CSD_CSFB_NOT_PREFERRED = 9 |
RobMeades | 0:5cffef3371f6 | 49 | } NetworkRegistrationStatusCsd; |
RobMeades | 0:5cffef3371f6 | 50 | |
RobMeades | 0:5cffef3371f6 | 51 | /** Packet Switched network registration status (CGREG Usage). |
RobMeades | 0:5cffef3371f6 | 52 | * UBX-13001820 - AT Commands Example Application Note (Section 18.27.3). |
RobMeades | 0:5cffef3371f6 | 53 | */ |
RobMeades | 0:5cffef3371f6 | 54 | typedef enum { |
RobMeades | 0:5cffef3371f6 | 55 | PSD_NOT_REGISTERED_NOT_SEARCHING = 0, |
RobMeades | 0:5cffef3371f6 | 56 | PSD_REGISTERED = 1, |
RobMeades | 0:5cffef3371f6 | 57 | PSD_NOT_REGISTERED_SEARCHING = 2, |
RobMeades | 0:5cffef3371f6 | 58 | PSD_REGISTRATION_DENIED = 3, |
RobMeades | 0:5cffef3371f6 | 59 | PSD_UNKNOWN_COVERAGE = 4, |
RobMeades | 0:5cffef3371f6 | 60 | PSD_REGISTERED_ROAMING = 5, |
RobMeades | 0:5cffef3371f6 | 61 | PSD_EMERGENCY_SERVICES_ONLY = 8 |
RobMeades | 0:5cffef3371f6 | 62 | } NetworkRegistrationStatusPsd; |
RobMeades | 0:5cffef3371f6 | 63 | |
RobMeades | 0:5cffef3371f6 | 64 | /** EPS network registration status (CEREG Usage). |
RobMeades | 0:5cffef3371f6 | 65 | * UBX-13001820 - AT Commands Example Application Note (Section 18.36.3). |
RobMeades | 0:5cffef3371f6 | 66 | */ |
RobMeades | 0:5cffef3371f6 | 67 | typedef enum { |
RobMeades | 0:5cffef3371f6 | 68 | EPS_NOT_REGISTERED_NOT_SEARCHING = 0, |
RobMeades | 0:5cffef3371f6 | 69 | EPS_REGISTERED = 1, |
RobMeades | 0:5cffef3371f6 | 70 | EPS_NOT_REGISTERED_SEARCHING = 2, |
RobMeades | 0:5cffef3371f6 | 71 | EPS_REGISTRATION_DENIED = 3, |
RobMeades | 0:5cffef3371f6 | 72 | EPS_UNKNOWN_COVERAGE = 4, |
RobMeades | 0:5cffef3371f6 | 73 | EPS_REGISTERED_ROAMING = 5, |
RobMeades | 0:5cffef3371f6 | 74 | EPS_EMERGENCY_SERVICES_ONLY = 8 |
RobMeades | 0:5cffef3371f6 | 75 | } NetworkRegistrationStatusEps; |
RobMeades | 0:5cffef3371f6 | 76 | |
RobMeades | 0:5cffef3371f6 | 77 | /** Initialise the modem, ready for use. |
RobMeades | 0:5cffef3371f6 | 78 | * |
RobMeades | 0:5cffef3371f6 | 79 | * @param pin PIN for the SIM card. |
RobMeades | 0:5cffef3371f6 | 80 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 81 | */ |
RobMeades | 0:5cffef3371f6 | 82 | bool init(const char *pin = 0); |
RobMeades | 0:5cffef3371f6 | 83 | |
RobMeades | 0:5cffef3371f6 | 84 | /** Perform registration with the network. |
RobMeades | 0:5cffef3371f6 | 85 | * |
RobMeades | 0:5cffef3371f6 | 86 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 87 | */ |
RobMeades | 0:5cffef3371f6 | 88 | bool nwk_registration(); |
RobMeades | 0:5cffef3371f6 | 89 | |
RobMeades | 0:5cffef3371f6 | 90 | /** True if the modem is registered for circuit |
RobMeades | 0:5cffef3371f6 | 91 | * switched data, otherwise false. |
RobMeades | 0:5cffef3371f6 | 92 | */ |
RobMeades | 0:5cffef3371f6 | 93 | bool is_registered_csd(); |
RobMeades | 0:5cffef3371f6 | 94 | |
RobMeades | 0:5cffef3371f6 | 95 | /** True if the modem is registered for packet |
RobMeades | 0:5cffef3371f6 | 96 | * switched data, otherwise false. |
RobMeades | 0:5cffef3371f6 | 97 | */ |
RobMeades | 0:5cffef3371f6 | 98 | bool is_registered_psd(); |
RobMeades | 0:5cffef3371f6 | 99 | |
RobMeades | 0:5cffef3371f6 | 100 | /** True if the modem is registered for enhanced |
RobMeades | 0:5cffef3371f6 | 101 | * packet switched data (i.e. LTE and beyond), |
RobMeades | 0:5cffef3371f6 | 102 | * otherwise false. |
RobMeades | 0:5cffef3371f6 | 103 | */ |
RobMeades | 0:5cffef3371f6 | 104 | bool is_registered_eps(); |
RobMeades | 0:5cffef3371f6 | 105 | |
RobMeades | 0:5cffef3371f6 | 106 | /** Perform deregistration from the network. |
RobMeades | 0:5cffef3371f6 | 107 | * |
RobMeades | 0:5cffef3371f6 | 108 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 109 | */ |
RobMeades | 0:5cffef3371f6 | 110 | bool nwk_deregistration(); |
RobMeades | 0:5cffef3371f6 | 111 | |
RobMeades | 0:5cffef3371f6 | 112 | /** Put the modem into its lowest power state. |
RobMeades | 0:5cffef3371f6 | 113 | */ |
RobMeades | 0:5cffef3371f6 | 114 | void deinit(); |
RobMeades | 0:5cffef3371f6 | 115 | |
RobMeades | 0:5cffef3371f6 | 116 | /** Set the PIN code for the SIM card. |
RobMeades | 0:5cffef3371f6 | 117 | * |
RobMeades | 0:5cffef3371f6 | 118 | * @param pin PIN for the SIM card. |
RobMeades | 0:5cffef3371f6 | 119 | */ |
RobMeades | 0:5cffef3371f6 | 120 | void set_pin(const char *pin); |
RobMeades | 0:5cffef3371f6 | 121 | |
RobMeades | 0:5cffef3371f6 | 122 | /** Enable or disable SIM pin checking. |
RobMeades | 0:5cffef3371f6 | 123 | * |
RobMeades | 0:5cffef3371f6 | 124 | * @param enableNotDisable true if SIM PIN checking is to be enabled, |
RobMeades | 0:5cffef3371f6 | 125 | * otherwise false. |
RobMeades | 0:5cffef3371f6 | 126 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 127 | */ |
RobMeades | 0:5cffef3371f6 | 128 | bool sim_pin_check_enable(bool enableNotDisable); |
RobMeades | 0:5cffef3371f6 | 129 | |
RobMeades | 0:5cffef3371f6 | 130 | /** Change the SIM pin. |
RobMeades | 0:5cffef3371f6 | 131 | * |
RobMeades | 0:5cffef3371f6 | 132 | * @param new_pin the new PIN to use. |
RobMeades | 0:5cffef3371f6 | 133 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 134 | */ |
RobMeades | 0:5cffef3371f6 | 135 | bool change_sim_pin(const char *new_pin); |
RobMeades | 0:5cffef3371f6 | 136 | |
RobMeades | 0:5cffef3371f6 | 137 | protected: |
RobMeades | 0:5cffef3371f6 | 138 | |
RobMeades | 0:5cffef3371f6 | 139 | #define OUTPUT_ENTER_KEY "\r" |
RobMeades | 0:5cffef3371f6 | 140 | |
RobMeades | 0:5cffef3371f6 | 141 | #if MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_BUFFER_SIZE |
RobMeades | 0:5cffef3371f6 | 142 | #define AT_PARSER_BUFFER_SIZE MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_BUFFER_SIZE |
RobMeades | 0:5cffef3371f6 | 143 | #else |
RobMeades | 0:5cffef3371f6 | 144 | #define AT_PARSER_BUFFER_SIZE 256 |
RobMeades | 0:5cffef3371f6 | 145 | #endif |
RobMeades | 0:5cffef3371f6 | 146 | |
RobMeades | 0:5cffef3371f6 | 147 | #if MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_TIMEOUT |
RobMeades | 0:5cffef3371f6 | 148 | #define AT_PARSER_TIMEOUT MBED_CONF_UBLOX_CELL_GEN_DRV_AT_PARSER_TIMEOUT |
RobMeades | 0:5cffef3371f6 | 149 | #else |
RobMeades | 0:5cffef3371f6 | 150 | #define AT_PARSER_TIMEOUT 8*1000 // Milliseconds |
RobMeades | 0:5cffef3371f6 | 151 | #endif |
RobMeades | 0:5cffef3371f6 | 152 | |
RobMeades | 0:5cffef3371f6 | 153 | /** A string that would not normally be sent by the modem on the AT interface. |
RobMeades | 0:5cffef3371f6 | 154 | */ |
RobMeades | 0:5cffef3371f6 | 155 | #define UNNATURAL_STRING "\x01" |
RobMeades | 0:5cffef3371f6 | 156 | |
RobMeades | 0:5cffef3371f6 | 157 | /** Supported u-blox modem variants. |
RobMeades | 0:5cffef3371f6 | 158 | */ |
RobMeades | 0:5cffef3371f6 | 159 | typedef enum { |
RobMeades | 0:5cffef3371f6 | 160 | DEV_TYPE_NONE = 0, |
RobMeades | 0:5cffef3371f6 | 161 | DEV_SARA_G35, |
RobMeades | 0:5cffef3371f6 | 162 | DEV_LISA_U2, |
RobMeades | 0:5cffef3371f6 | 163 | DEV_LISA_U2_03S, |
RobMeades | 0:5cffef3371f6 | 164 | DEV_SARA_U2, |
RobMeades | 0:5cffef3371f6 | 165 | DEV_LEON_G2, |
RobMeades | 0:5cffef3371f6 | 166 | DEV_TOBY_L2, |
RobMeades | 0:5cffef3371f6 | 167 | DEV_MPCI_L2 |
RobMeades | 0:5cffef3371f6 | 168 | } DeviceType; |
RobMeades | 0:5cffef3371f6 | 169 | |
RobMeades | 0:5cffef3371f6 | 170 | /** Network registration status. |
RobMeades | 0:5cffef3371f6 | 171 | * UBX-13001820 - AT Commands Example Application Note (Section 4.1.4.5). |
RobMeades | 0:5cffef3371f6 | 172 | */ |
RobMeades | 0:5cffef3371f6 | 173 | typedef enum { |
RobMeades | 0:5cffef3371f6 | 174 | GSM = 0, |
RobMeades | 0:5cffef3371f6 | 175 | COMPACT_GSM = 1, |
RobMeades | 0:5cffef3371f6 | 176 | UTRAN = 2, |
RobMeades | 0:5cffef3371f6 | 177 | EDGE = 3, |
RobMeades | 0:5cffef3371f6 | 178 | HSDPA = 4, |
RobMeades | 0:5cffef3371f6 | 179 | HSUPA = 5, |
RobMeades | 0:5cffef3371f6 | 180 | HSDPA_HSUPA = 6, |
RobMeades | 0:5cffef3371f6 | 181 | LTE = 7 |
RobMeades | 0:5cffef3371f6 | 182 | } RadioAccessNetworkType; |
RobMeades | 0:5cffef3371f6 | 183 | |
RobMeades | 0:5cffef3371f6 | 184 | /** Info about the modem. |
RobMeades | 0:5cffef3371f6 | 185 | */ |
RobMeades | 0:5cffef3371f6 | 186 | typedef struct { |
RobMeades | 0:5cffef3371f6 | 187 | DeviceType dev; |
RobMeades | 0:5cffef3371f6 | 188 | char iccid[20 + 1]; //!< Integrated Circuit Card ID. |
RobMeades | 0:5cffef3371f6 | 189 | char imsi[15 + 1]; //!< International Mobile Station Identity. |
RobMeades | 0:5cffef3371f6 | 190 | char imei[15 + 1]; //!< International Mobile Equipment Identity. |
RobMeades | 0:5cffef3371f6 | 191 | char meid[18 + 1]; //!< Mobile Equipment IDentifier. |
RobMeades | 0:5cffef3371f6 | 192 | volatile RadioAccessNetworkType rat; //!< Type of network (e.g. 2G, 3G, LTE). |
RobMeades | 0:5cffef3371f6 | 193 | volatile NetworkRegistrationStatusCsd reg_status_csd; //!< Circuit switched attach status. |
RobMeades | 0:5cffef3371f6 | 194 | volatile NetworkRegistrationStatusPsd reg_status_psd; //!< Packet switched attach status. |
RobMeades | 0:5cffef3371f6 | 195 | volatile NetworkRegistrationStatusEps reg_status_eps; //!< Evolved Packet Switched (e.g. LTE) attach status. |
RobMeades | 0:5cffef3371f6 | 196 | } DeviceInfo; |
RobMeades | 0:5cffef3371f6 | 197 | |
RobMeades | 0:5cffef3371f6 | 198 | /* IMPORTANT: the variables below are available to |
RobMeades | 0:5cffef3371f6 | 199 | * classes that inherit this in order to keep things |
RobMeades | 0:5cffef3371f6 | 200 | * simple. However, ONLY this class should free |
RobMeades | 0:5cffef3371f6 | 201 | * any of the pointers, or there will be havoc. |
RobMeades | 0:5cffef3371f6 | 202 | */ |
RobMeades | 0:5cffef3371f6 | 203 | |
RobMeades | 0:5cffef3371f6 | 204 | /** Point to the instance of the AT parser in use. |
RobMeades | 0:5cffef3371f6 | 205 | */ |
RobMeades | 0:5cffef3371f6 | 206 | ATCmdParser *_at; |
RobMeades | 0:5cffef3371f6 | 207 | |
RobMeades | 0:5cffef3371f6 | 208 | /** The current AT parser timeout value. |
RobMeades | 0:5cffef3371f6 | 209 | */ |
RobMeades | 0:5cffef3371f6 | 210 | int _at_timeout; |
RobMeades | 0:5cffef3371f6 | 211 | |
RobMeades | 0:5cffef3371f6 | 212 | /** File handle used by the AT parser. |
RobMeades | 0:5cffef3371f6 | 213 | */ |
RobMeades | 0:5cffef3371f6 | 214 | FileHandle *_fh; |
RobMeades | 0:5cffef3371f6 | 215 | |
RobMeades | 0:5cffef3371f6 | 216 | /** The mutex resource. |
RobMeades | 0:5cffef3371f6 | 217 | */ |
RobMeades | 0:5cffef3371f6 | 218 | Mutex _mtx; |
RobMeades | 0:5cffef3371f6 | 219 | |
RobMeades | 0:5cffef3371f6 | 220 | /** General info about the modem as a device. |
RobMeades | 0:5cffef3371f6 | 221 | */ |
RobMeades | 0:5cffef3371f6 | 222 | DeviceInfo _dev_info; |
RobMeades | 0:5cffef3371f6 | 223 | |
RobMeades | 0:5cffef3371f6 | 224 | /** The SIM PIN to use. |
RobMeades | 0:5cffef3371f6 | 225 | */ |
RobMeades | 0:5cffef3371f6 | 226 | const char *_pin; |
RobMeades | 0:5cffef3371f6 | 227 | |
RobMeades | 0:5cffef3371f6 | 228 | /** Set to true to spit out debug traces. |
RobMeades | 0:5cffef3371f6 | 229 | */ |
RobMeades | 0:5cffef3371f6 | 230 | bool _debug_trace_on; |
RobMeades | 0:5cffef3371f6 | 231 | |
RobMeades | 0:5cffef3371f6 | 232 | /** True if the modem is ready register to the network, |
RobMeades | 0:5cffef3371f6 | 233 | * otherwise false. |
RobMeades | 0:5cffef3371f6 | 234 | */ |
RobMeades | 0:5cffef3371f6 | 235 | bool _modem_initialised; |
RobMeades | 0:5cffef3371f6 | 236 | |
RobMeades | 0:5cffef3371f6 | 237 | /** True it the SIM requires a PIN, otherwise false. |
RobMeades | 0:5cffef3371f6 | 238 | */ |
RobMeades | 0:5cffef3371f6 | 239 | bool _sim_pin_check_enabled; |
RobMeades | 0:5cffef3371f6 | 240 | |
RobMeades | 0:5cffef3371f6 | 241 | /** Sets the modem up for powering on |
RobMeades | 0:5cffef3371f6 | 242 | * |
RobMeades | 0:5cffef3371f6 | 243 | * modem_init() is equivalent to plugging in the device, e.g., attaching power and serial port. |
RobMeades | 0:5cffef3371f6 | 244 | * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target. |
RobMeades | 0:5cffef3371f6 | 245 | */ |
RobMeades | 0:5cffef3371f6 | 246 | virtual void modem_init(); |
RobMeades | 0:5cffef3371f6 | 247 | |
RobMeades | 0:5cffef3371f6 | 248 | /** Sets the modem in unplugged state |
RobMeades | 0:5cffef3371f6 | 249 | * |
RobMeades | 0:5cffef3371f6 | 250 | * modem_deinit() will be equivalent to pulling the plug off of the device, i.e., detaching power |
RobMeades | 0:5cffef3371f6 | 251 | * and serial port. This puts the modem in lowest power state. |
RobMeades | 0:5cffef3371f6 | 252 | * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target. |
RobMeades | 0:5cffef3371f6 | 253 | */ |
RobMeades | 0:5cffef3371f6 | 254 | virtual void modem_deinit(); |
RobMeades | 0:5cffef3371f6 | 255 | |
RobMeades | 0:5cffef3371f6 | 256 | /** Powers up the modem |
RobMeades | 0:5cffef3371f6 | 257 | * |
RobMeades | 0:5cffef3371f6 | 258 | * modem_power_up() is equivalent to pressing the soft power button. |
RobMeades | 0:5cffef3371f6 | 259 | * The driver may repeat this if the modem is not responsive to AT commands. |
RobMeades | 0:5cffef3371f6 | 260 | * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target. |
RobMeades | 0:5cffef3371f6 | 261 | */ |
RobMeades | 0:5cffef3371f6 | 262 | virtual void modem_power_up(); |
RobMeades | 0:5cffef3371f6 | 263 | |
RobMeades | 0:5cffef3371f6 | 264 | /** Powers down the modem |
RobMeades | 0:5cffef3371f6 | 265 | * |
RobMeades | 0:5cffef3371f6 | 266 | * modem_power_down() is equivalent to turning off the modem by button press. |
RobMeades | 0:5cffef3371f6 | 267 | * Uses onboard_modem_api.h where the implementation of onboard_modem_api is provided by the target. |
RobMeades | 0:5cffef3371f6 | 268 | */ |
RobMeades | 0:5cffef3371f6 | 269 | virtual void modem_power_down(); |
RobMeades | 0:5cffef3371f6 | 270 | |
RobMeades | 0:5cffef3371f6 | 271 | /* Note: constructor and destructor protected so that this |
RobMeades | 0:5cffef3371f6 | 272 | * class can only ever be inherited, never used directly. |
RobMeades | 0:5cffef3371f6 | 273 | */ |
RobMeades | 0:5cffef3371f6 | 274 | UbloxCellularBase(); |
RobMeades | 0:5cffef3371f6 | 275 | ~UbloxCellularBase(); |
RobMeades | 0:5cffef3371f6 | 276 | |
RobMeades | 0:5cffef3371f6 | 277 | /** Initialise this class. |
RobMeades | 0:5cffef3371f6 | 278 | * |
RobMeades | 0:5cffef3371f6 | 279 | * @param tx the UART TX data pin to which the modem is attached. |
RobMeades | 0:5cffef3371f6 | 280 | * @param rx the UART RX data pin to which the modem is attached. |
RobMeades | 0:5cffef3371f6 | 281 | * @param baud the UART baud rate. |
RobMeades | 0:5cffef3371f6 | 282 | * @param debug_on true to switch AT interface debug on, otherwise false. |
RobMeades | 0:5cffef3371f6 | 283 | * |
RobMeades | 0:5cffef3371f6 | 284 | * Note: it would be more natural to do this in the constructor |
RobMeades | 0:5cffef3371f6 | 285 | * however, to avoid the diamond of death, this class is only |
RobMeades | 0:5cffef3371f6 | 286 | * every inherited virtually. Classes that are inherited virtually |
RobMeades | 0:5cffef3371f6 | 287 | * do not get passed parameters in their constructor and hence |
RobMeades | 0:5cffef3371f6 | 288 | * classInit() must be called separately by the first one to wake |
RobMeades | 0:5cffef3371f6 | 289 | * the beast. |
RobMeades | 0:5cffef3371f6 | 290 | */ |
RobMeades | 0:5cffef3371f6 | 291 | void baseClassInit(PinName tx = MDMTXD, |
RobMeades | 0:5cffef3371f6 | 292 | PinName rx = MDMRXD, |
RobMeades | 0:5cffef3371f6 | 293 | int baud = MBED_CONF_UBLOX_CELL_BAUD_RATE, |
RobMeades | 0:5cffef3371f6 | 294 | bool debug_on = false); |
RobMeades | 0:5cffef3371f6 | 295 | |
RobMeades | 0:5cffef3371f6 | 296 | /** Set the AT parser timeout. |
RobMeades | 0:5cffef3371f6 | 297 | */ |
RobMeades | 0:5cffef3371f6 | 298 | void at_set_timeout(int timeout); |
RobMeades | 0:5cffef3371f6 | 299 | |
RobMeades | 0:5cffef3371f6 | 300 | /** Read up to size characters from buf |
RobMeades | 0:5cffef3371f6 | 301 | * or until the character "end" is reached, overwriting |
RobMeades | 0:5cffef3371f6 | 302 | * the newline with 0 and ensuring a terminator |
RobMeades | 0:5cffef3371f6 | 303 | * in all cases. |
RobMeades | 0:5cffef3371f6 | 304 | * |
RobMeades | 0:5cffef3371f6 | 305 | * @param buf the buffer to write to. |
RobMeades | 0:5cffef3371f6 | 306 | * @param size the size of the buffer. |
RobMeades | 0:5cffef3371f6 | 307 | * @param end the character to stop at. |
RobMeades | 0:5cffef3371f6 | 308 | * @return the number of characters read, |
RobMeades | 0:5cffef3371f6 | 309 | * not including the terminator. |
RobMeades | 0:5cffef3371f6 | 310 | */ |
RobMeades | 0:5cffef3371f6 | 311 | int read_at_to_char(char * buf, int size, char end); |
RobMeades | 0:5cffef3371f6 | 312 | |
RobMeades | 0:5cffef3371f6 | 313 | /** Powers up the modem. |
RobMeades | 0:5cffef3371f6 | 314 | * |
RobMeades | 0:5cffef3371f6 | 315 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 316 | */ |
RobMeades | 0:5cffef3371f6 | 317 | bool power_up(); |
RobMeades | 0:5cffef3371f6 | 318 | |
RobMeades | 0:5cffef3371f6 | 319 | /** Power down the modem. |
RobMeades | 0:5cffef3371f6 | 320 | */ |
RobMeades | 0:5cffef3371f6 | 321 | void power_down(); |
RobMeades | 0:5cffef3371f6 | 322 | |
RobMeades | 0:5cffef3371f6 | 323 | /** Lock a mutex when accessing the modem. |
RobMeades | 0:5cffef3371f6 | 324 | */ |
RobMeades | 0:5cffef3371f6 | 325 | void lock(void) { _mtx.lock(); } |
RobMeades | 0:5cffef3371f6 | 326 | |
RobMeades | 0:5cffef3371f6 | 327 | /** Helper to make sure that lock unlock pair is always balanced |
RobMeades | 0:5cffef3371f6 | 328 | */ |
RobMeades | 0:5cffef3371f6 | 329 | #define LOCK() { lock() |
RobMeades | 0:5cffef3371f6 | 330 | |
RobMeades | 0:5cffef3371f6 | 331 | /** Unlock the modem when done accessing it. |
RobMeades | 0:5cffef3371f6 | 332 | */ |
RobMeades | 0:5cffef3371f6 | 333 | void unlock(void) { _mtx.unlock(); } |
RobMeades | 0:5cffef3371f6 | 334 | |
RobMeades | 0:5cffef3371f6 | 335 | /** Helper to make sure that lock unlock pair is always balanced |
RobMeades | 0:5cffef3371f6 | 336 | */ |
RobMeades | 0:5cffef3371f6 | 337 | #define UNLOCK() } unlock() |
RobMeades | 0:5cffef3371f6 | 338 | |
RobMeades | 0:5cffef3371f6 | 339 | /** Set the device identity in _dev_info |
RobMeades | 0:5cffef3371f6 | 340 | * based on the ATI string returned by |
RobMeades | 0:5cffef3371f6 | 341 | * the module. |
RobMeades | 0:5cffef3371f6 | 342 | * |
RobMeades | 0:5cffef3371f6 | 343 | * @return true if dev is a known value, |
RobMeades | 0:5cffef3371f6 | 344 | * otherwise false. |
RobMeades | 0:5cffef3371f6 | 345 | */ |
RobMeades | 0:5cffef3371f6 | 346 | bool set_device_identity(DeviceType *dev); |
RobMeades | 0:5cffef3371f6 | 347 | |
RobMeades | 0:5cffef3371f6 | 348 | /** Perform any modem initialisation that is |
RobMeades | 0:5cffef3371f6 | 349 | * specialised by device type. |
RobMeades | 0:5cffef3371f6 | 350 | * |
RobMeades | 0:5cffef3371f6 | 351 | * @return true if successful, otherwise false. |
RobMeades | 0:5cffef3371f6 | 352 | */ |
RobMeades | 0:5cffef3371f6 | 353 | bool device_init(DeviceType dev); |
RobMeades | 0:5cffef3371f6 | 354 | |
RobMeades | 0:5cffef3371f6 | 355 | /** Set up the SIM. |
RobMeades | 0:5cffef3371f6 | 356 | * |
RobMeades | 0:5cffef3371f6 | 357 | * @return true if successful, otherwiss false. |
RobMeades | 0:5cffef3371f6 | 358 | */ |
RobMeades | 0:5cffef3371f6 | 359 | bool initialise_sim_card(); |
RobMeades | 0:5cffef3371f6 | 360 | |
RobMeades | 0:5cffef3371f6 | 361 | private: |
RobMeades | 0:5cffef3371f6 | 362 | |
RobMeades | 0:5cffef3371f6 | 363 | void set_nwk_reg_status_csd(int status); |
RobMeades | 0:5cffef3371f6 | 364 | void set_nwk_reg_status_psd(int status); |
RobMeades | 0:5cffef3371f6 | 365 | void set_nwk_reg_status_eps(int status); |
RobMeades | 0:5cffef3371f6 | 366 | void set_rat(int AcTStatus); |
RobMeades | 0:5cffef3371f6 | 367 | bool get_iccid(); |
RobMeades | 0:5cffef3371f6 | 368 | bool get_imsi(); |
RobMeades | 0:5cffef3371f6 | 369 | bool get_imei(); |
RobMeades | 0:5cffef3371f6 | 370 | bool get_meid(); |
RobMeades | 0:5cffef3371f6 | 371 | bool set_sms(); |
RobMeades | 0:5cffef3371f6 | 372 | void parser_abort_cb(); |
RobMeades | 0:5cffef3371f6 | 373 | void CMX_ERROR_URC(); |
RobMeades | 0:5cffef3371f6 | 374 | void CREG_URC(); |
RobMeades | 0:5cffef3371f6 | 375 | void CGREG_URC(); |
RobMeades | 0:5cffef3371f6 | 376 | void CEREG_URC(); |
RobMeades | 0:5cffef3371f6 | 377 | void UMWI_URC(); |
RobMeades | 0:5cffef3371f6 | 378 | }; |
RobMeades | 0:5cffef3371f6 | 379 | |
rob.meades@u-blox.com | 1:5aaecf2572dc | 380 | #endif // _UBLOX_CELLULAR_BASE_ |
RobMeades | 0:5cffef3371f6 | 381 |