ublox-cellular-base_R4_PR
UbloxCellularBase.cpp@30:38230504a646, 2019-08-27 (annotated)
- Committer:
- fahimalavi
- Date:
- Tue Aug 27 18:38:29 2019 +0500
- Revision:
- 30:38230504a646
- Parent:
- 29:8a38f91009ad
- Child:
- 31:b0a6a610d114
Support for Band select bitmask feature added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fahimalavi | 26:e4e444cc7b14 | 1 | /* Copyright (c) 2019 ublox 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 | |
RobMeades | 0:5cffef3371f6 | 16 | #include "UARTSerial.h" |
RobMeades | 0:5cffef3371f6 | 17 | #include "APN_db.h" |
RobMeades | 0:5cffef3371f6 | 18 | #include "UbloxCellularBase.h" |
RobMeades | 0:5cffef3371f6 | 19 | #include "onboard_modem_api.h" |
RobMeades | 0:5cffef3371f6 | 20 | #ifdef FEATURE_COMMON_PAL |
RobMeades | 0:5cffef3371f6 | 21 | #include "mbed_trace.h" |
RobMeades | 0:5cffef3371f6 | 22 | #define TRACE_GROUP "UCB" |
RobMeades | 0:5cffef3371f6 | 23 | #else |
rob.meades@u-blox.com | 2:73fcc33c9400 | 24 | #define tr_debug(format, ...) debug_if(_debug_trace_on, format "\n", ## __VA_ARGS__) |
rob.meades@u-blox.com | 2:73fcc33c9400 | 25 | #define tr_info(format, ...) debug_if(_debug_trace_on, format "\n", ## __VA_ARGS__) |
rob.meades@u-blox.com | 2:73fcc33c9400 | 26 | #define tr_warn(format, ...) debug_if(_debug_trace_on, format "\n", ## __VA_ARGS__) |
rob.meades@u-blox.com | 2:73fcc33c9400 | 27 | #define tr_error(format, ...) debug_if(_debug_trace_on, format "\n", ## __VA_ARGS__) |
RobMeades | 0:5cffef3371f6 | 28 | #endif |
RobMeades | 0:5cffef3371f6 | 29 | |
RobMeades | 14:e420232ee4e7 | 30 | /* Array to convert the 3G qual number into a median EC_NO_LEV number. |
RobMeades | 14:e420232ee4e7 | 31 | */ |
RobMeades | 14:e420232ee4e7 | 32 | /* 0 1 2 3 4 5 6 7 */ |
fahim.alavi@u-blox.com | 15:93b157a47b8d | 33 | /* 44, 41, 35, 29, 23, 17, 11, 7*/ |
fahim.alavi@u-blox.com | 15:93b157a47b8d | 34 | const int qualConvert3G[] = {-2, -4, -7, -10, -13, -16, -19, -21}; |
RobMeades | 14:e420232ee4e7 | 35 | |
RobMeades | 14:e420232ee4e7 | 36 | /* Array to convert the 3G "rssi" number into a dBm RSCP value rounded up to the |
RobMeades | 14:e420232ee4e7 | 37 | * nearest whole number. |
RobMeades | 14:e420232ee4e7 | 38 | */ |
RobMeades | 14:e420232ee4e7 | 39 | const int rscpConvert3G[] = {-108, -105, -103, -100, -98, -96, -94, -93, /* 0 - 7 */ |
RobMeades | 14:e420232ee4e7 | 40 | -91, -89, -88, -85, -83, -80, -78, -76, /* 8 - 15 */ |
RobMeades | 14:e420232ee4e7 | 41 | -74, -73, -70, -68, -66, -64, -63, -60, /* 16 - 23 */ |
RobMeades | 14:e420232ee4e7 | 42 | -58, -56, -54, -53, -51, -49, -48, -46}; /* 24 - 31 */ |
RobMeades | 14:e420232ee4e7 | 43 | |
RobMeades | 14:e420232ee4e7 | 44 | /* Array to convert the LTE rssi number into a dBm value rounded up to the |
RobMeades | 14:e420232ee4e7 | 45 | * nearest whole number. |
RobMeades | 14:e420232ee4e7 | 46 | */ |
RobMeades | 14:e420232ee4e7 | 47 | const int rssiConvertLte[] = {-118, -115, -113, -110, -108, -105, -103, -100, /* 0 - 7 */ |
RobMeades | 14:e420232ee4e7 | 48 | -98, -95, -93, -90, -88, -85, -83, -80, /* 8 - 15 */ |
RobMeades | 14:e420232ee4e7 | 49 | -78, -76, -74, -73, -71, -69, -68, -65, /* 16 - 23 */ |
RobMeades | 14:e420232ee4e7 | 50 | -63, -61, -60, -59, -58, -55, -53, -48}; /* 24 - 31 */ |
RobMeades | 14:e420232ee4e7 | 51 | |
RobMeades | 0:5cffef3371f6 | 52 | /********************************************************************** |
RobMeades | 0:5cffef3371f6 | 53 | * PRIVATE METHODS |
RobMeades | 0:5cffef3371f6 | 54 | **********************************************************************/ |
RobMeades | 0:5cffef3371f6 | 55 | |
RobMeades | 0:5cffef3371f6 | 56 | void UbloxCellularBase::set_nwk_reg_status_csd(int status) |
RobMeades | 0:5cffef3371f6 | 57 | { |
RobMeades | 0:5cffef3371f6 | 58 | switch (status) { |
RobMeades | 0:5cffef3371f6 | 59 | case CSD_NOT_REGISTERED_NOT_SEARCHING: |
RobMeades | 0:5cffef3371f6 | 60 | case CSD_NOT_REGISTERED_SEARCHING: |
RobMeades | 0:5cffef3371f6 | 61 | tr_info("Not (yet) registered for circuit switched service"); |
RobMeades | 0:5cffef3371f6 | 62 | break; |
RobMeades | 0:5cffef3371f6 | 63 | case CSD_REGISTERED: |
RobMeades | 0:5cffef3371f6 | 64 | case CSD_REGISTERED_ROAMING: |
RobMeades | 0:5cffef3371f6 | 65 | tr_info("Registered for circuit switched service"); |
RobMeades | 0:5cffef3371f6 | 66 | break; |
RobMeades | 0:5cffef3371f6 | 67 | case CSD_REGISTRATION_DENIED: |
RobMeades | 0:5cffef3371f6 | 68 | tr_info("Circuit switched service denied"); |
RobMeades | 0:5cffef3371f6 | 69 | break; |
RobMeades | 0:5cffef3371f6 | 70 | case CSD_UNKNOWN_COVERAGE: |
RobMeades | 0:5cffef3371f6 | 71 | tr_info("Out of circuit switched service coverage"); |
RobMeades | 0:5cffef3371f6 | 72 | break; |
RobMeades | 0:5cffef3371f6 | 73 | case CSD_SMS_ONLY: |
RobMeades | 0:5cffef3371f6 | 74 | tr_info("SMS service only"); |
RobMeades | 0:5cffef3371f6 | 75 | break; |
RobMeades | 0:5cffef3371f6 | 76 | case CSD_SMS_ONLY_ROAMING: |
RobMeades | 0:5cffef3371f6 | 77 | tr_info("SMS service only"); |
RobMeades | 0:5cffef3371f6 | 78 | break; |
RobMeades | 0:5cffef3371f6 | 79 | case CSD_CSFB_NOT_PREFERRED: |
RobMeades | 0:5cffef3371f6 | 80 | tr_info("Registered for circuit switched service with CSFB not preferred"); |
RobMeades | 0:5cffef3371f6 | 81 | break; |
RobMeades | 0:5cffef3371f6 | 82 | default: |
RobMeades | 0:5cffef3371f6 | 83 | tr_info("Unknown circuit switched service registration status. %d", status); |
RobMeades | 0:5cffef3371f6 | 84 | break; |
RobMeades | 0:5cffef3371f6 | 85 | } |
RobMeades | 0:5cffef3371f6 | 86 | |
RobMeades | 0:5cffef3371f6 | 87 | _dev_info.reg_status_csd = static_cast<NetworkRegistrationStatusCsd>(status); |
RobMeades | 0:5cffef3371f6 | 88 | } |
RobMeades | 0:5cffef3371f6 | 89 | |
RobMeades | 0:5cffef3371f6 | 90 | void UbloxCellularBase::set_nwk_reg_status_psd(int status) |
RobMeades | 0:5cffef3371f6 | 91 | { |
RobMeades | 0:5cffef3371f6 | 92 | switch (status) { |
RobMeades | 0:5cffef3371f6 | 93 | case PSD_NOT_REGISTERED_NOT_SEARCHING: |
RobMeades | 0:5cffef3371f6 | 94 | case PSD_NOT_REGISTERED_SEARCHING: |
RobMeades | 0:5cffef3371f6 | 95 | tr_info("Not (yet) registered for packet switched service"); |
RobMeades | 0:5cffef3371f6 | 96 | break; |
RobMeades | 0:5cffef3371f6 | 97 | case PSD_REGISTERED: |
RobMeades | 0:5cffef3371f6 | 98 | case PSD_REGISTERED_ROAMING: |
RobMeades | 0:5cffef3371f6 | 99 | tr_info("Registered for packet switched service"); |
RobMeades | 0:5cffef3371f6 | 100 | break; |
RobMeades | 0:5cffef3371f6 | 101 | case PSD_REGISTRATION_DENIED: |
RobMeades | 0:5cffef3371f6 | 102 | tr_info("Packet switched service denied"); |
RobMeades | 0:5cffef3371f6 | 103 | break; |
RobMeades | 0:5cffef3371f6 | 104 | case PSD_UNKNOWN_COVERAGE: |
RobMeades | 0:5cffef3371f6 | 105 | tr_info("Out of packet switched service coverage"); |
RobMeades | 0:5cffef3371f6 | 106 | break; |
RobMeades | 0:5cffef3371f6 | 107 | case PSD_EMERGENCY_SERVICES_ONLY: |
RobMeades | 0:5cffef3371f6 | 108 | tr_info("Limited access for packet switched service. Emergency use only."); |
RobMeades | 0:5cffef3371f6 | 109 | break; |
RobMeades | 0:5cffef3371f6 | 110 | default: |
RobMeades | 0:5cffef3371f6 | 111 | tr_info("Unknown packet switched service registration status. %d", status); |
RobMeades | 0:5cffef3371f6 | 112 | break; |
RobMeades | 0:5cffef3371f6 | 113 | } |
RobMeades | 0:5cffef3371f6 | 114 | |
RobMeades | 0:5cffef3371f6 | 115 | _dev_info.reg_status_psd = static_cast<NetworkRegistrationStatusPsd>(status); |
RobMeades | 0:5cffef3371f6 | 116 | } |
RobMeades | 0:5cffef3371f6 | 117 | |
RobMeades | 0:5cffef3371f6 | 118 | void UbloxCellularBase::set_nwk_reg_status_eps(int status) |
RobMeades | 0:5cffef3371f6 | 119 | { |
RobMeades | 0:5cffef3371f6 | 120 | switch (status) { |
RobMeades | 0:5cffef3371f6 | 121 | case EPS_NOT_REGISTERED_NOT_SEARCHING: |
RobMeades | 0:5cffef3371f6 | 122 | case EPS_NOT_REGISTERED_SEARCHING: |
RobMeades | 0:5cffef3371f6 | 123 | tr_info("Not (yet) registered for EPS service"); |
RobMeades | 0:5cffef3371f6 | 124 | break; |
RobMeades | 0:5cffef3371f6 | 125 | case EPS_REGISTERED: |
RobMeades | 0:5cffef3371f6 | 126 | case EPS_REGISTERED_ROAMING: |
RobMeades | 0:5cffef3371f6 | 127 | tr_info("Registered for EPS service"); |
RobMeades | 0:5cffef3371f6 | 128 | break; |
RobMeades | 0:5cffef3371f6 | 129 | case EPS_REGISTRATION_DENIED: |
RobMeades | 0:5cffef3371f6 | 130 | tr_info("EPS service denied"); |
RobMeades | 0:5cffef3371f6 | 131 | break; |
RobMeades | 0:5cffef3371f6 | 132 | case EPS_UNKNOWN_COVERAGE: |
RobMeades | 0:5cffef3371f6 | 133 | tr_info("Out of EPS service coverage"); |
RobMeades | 0:5cffef3371f6 | 134 | break; |
RobMeades | 0:5cffef3371f6 | 135 | case EPS_EMERGENCY_SERVICES_ONLY: |
RobMeades | 0:5cffef3371f6 | 136 | tr_info("Limited access for EPS service. Emergency use only."); |
RobMeades | 0:5cffef3371f6 | 137 | break; |
RobMeades | 0:5cffef3371f6 | 138 | default: |
RobMeades | 0:5cffef3371f6 | 139 | tr_info("Unknown EPS service registration status. %d", status); |
RobMeades | 0:5cffef3371f6 | 140 | break; |
RobMeades | 0:5cffef3371f6 | 141 | } |
RobMeades | 0:5cffef3371f6 | 142 | |
RobMeades | 0:5cffef3371f6 | 143 | _dev_info.reg_status_eps = static_cast<NetworkRegistrationStatusEps>(status); |
RobMeades | 0:5cffef3371f6 | 144 | } |
RobMeades | 0:5cffef3371f6 | 145 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 146 | #ifdef TARGET_UBLOX_C030_R412M |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 147 | void UbloxCellularBase::set_modem_psm_state(int status) |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 148 | { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 149 | switch (status) { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 150 | case ASLEEP: |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 151 | tr_info("Modem is going in PSM sleep"); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 152 | break; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 153 | case AWAKE: |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 154 | tr_info("Modem is awake from PSM sleep"); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 155 | break; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 156 | default: |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 157 | tr_info("Unknown PSM state. %d", status); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 158 | break; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 159 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 160 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 161 | _dev_info.modem_psm_state = static_cast<ModemPSMState>(status); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 162 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 163 | #endif |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 164 | |
RobMeades | 14:e420232ee4e7 | 165 | void UbloxCellularBase::set_rat(int acTStatus) |
RobMeades | 0:5cffef3371f6 | 166 | { |
RobMeades | 14:e420232ee4e7 | 167 | switch (acTStatus) { |
RobMeades | 0:5cffef3371f6 | 168 | case GSM: |
RobMeades | 0:5cffef3371f6 | 169 | case COMPACT_GSM: |
RobMeades | 0:5cffef3371f6 | 170 | tr_info("Connected in GSM"); |
RobMeades | 0:5cffef3371f6 | 171 | break; |
RobMeades | 0:5cffef3371f6 | 172 | case UTRAN: |
RobMeades | 0:5cffef3371f6 | 173 | tr_info("Connected to UTRAN"); |
RobMeades | 0:5cffef3371f6 | 174 | break; |
RobMeades | 0:5cffef3371f6 | 175 | case EDGE: |
RobMeades | 0:5cffef3371f6 | 176 | tr_info("Connected to EDGE"); |
RobMeades | 0:5cffef3371f6 | 177 | break; |
RobMeades | 0:5cffef3371f6 | 178 | case HSDPA: |
RobMeades | 0:5cffef3371f6 | 179 | tr_info("Connected to HSDPA"); |
RobMeades | 0:5cffef3371f6 | 180 | break; |
RobMeades | 0:5cffef3371f6 | 181 | case HSUPA: |
RobMeades | 0:5cffef3371f6 | 182 | tr_info("Connected to HSPA"); |
RobMeades | 0:5cffef3371f6 | 183 | break; |
RobMeades | 0:5cffef3371f6 | 184 | case HSDPA_HSUPA: |
RobMeades | 0:5cffef3371f6 | 185 | tr_info("Connected to HDPA/HSPA"); |
RobMeades | 0:5cffef3371f6 | 186 | break; |
RobMeades | 0:5cffef3371f6 | 187 | case LTE: |
RobMeades | 0:5cffef3371f6 | 188 | tr_info("Connected to LTE"); |
RobMeades | 0:5cffef3371f6 | 189 | break; |
fahimalavi | 10:c4281fa79b8f | 190 | case EC_GSM_IoT: |
fahimalavi | 10:c4281fa79b8f | 191 | tr_info("Connected to EC_GSM_IoT"); |
fahimalavi | 10:c4281fa79b8f | 192 | break; |
fahimalavi | 10:c4281fa79b8f | 193 | case E_UTRAN_NB_S1: |
fahimalavi | 10:c4281fa79b8f | 194 | tr_info("Connected to E_UTRAN NB1"); |
fahimalavi | 10:c4281fa79b8f | 195 | break; |
RobMeades | 0:5cffef3371f6 | 196 | default: |
RobMeades | 14:e420232ee4e7 | 197 | tr_info("Unknown RAT %d", acTStatus); |
RobMeades | 0:5cffef3371f6 | 198 | break; |
RobMeades | 0:5cffef3371f6 | 199 | } |
RobMeades | 0:5cffef3371f6 | 200 | |
RobMeades | 14:e420232ee4e7 | 201 | _dev_info.rat = static_cast<RadioAccessNetworkType>(acTStatus); |
RobMeades | 0:5cffef3371f6 | 202 | } |
RobMeades | 0:5cffef3371f6 | 203 | |
RobMeades | 0:5cffef3371f6 | 204 | bool UbloxCellularBase::get_iccid() |
RobMeades | 0:5cffef3371f6 | 205 | { |
RobMeades | 0:5cffef3371f6 | 206 | bool success; |
RobMeades | 0:5cffef3371f6 | 207 | LOCK(); |
RobMeades | 0:5cffef3371f6 | 208 | |
RobMeades | 0:5cffef3371f6 | 209 | MBED_ASSERT(_at != NULL); |
RobMeades | 0:5cffef3371f6 | 210 | |
RobMeades | 0:5cffef3371f6 | 211 | // Returns the ICCID (Integrated Circuit Card ID) of the SIM-card. |
RobMeades | 0:5cffef3371f6 | 212 | // ICCID is a serial number identifying the SIM. |
RobMeades | 0:5cffef3371f6 | 213 | // AT Command Manual UBX-13002752, section 4.12 |
RobMeades | 0:5cffef3371f6 | 214 | success = _at->send("AT+CCID") && _at->recv("+CCID: %20[^\n]\nOK\n", _dev_info.iccid); |
RobMeades | 0:5cffef3371f6 | 215 | tr_info("DevInfo: ICCID=%s", _dev_info.iccid); |
RobMeades | 0:5cffef3371f6 | 216 | |
RobMeades | 0:5cffef3371f6 | 217 | UNLOCK(); |
RobMeades | 0:5cffef3371f6 | 218 | return success; |
RobMeades | 0:5cffef3371f6 | 219 | } |
RobMeades | 0:5cffef3371f6 | 220 | |
RobMeades | 0:5cffef3371f6 | 221 | bool UbloxCellularBase::get_imsi() |
RobMeades | 0:5cffef3371f6 | 222 | { |
RobMeades | 0:5cffef3371f6 | 223 | bool success; |
RobMeades | 0:5cffef3371f6 | 224 | LOCK(); |
RobMeades | 0:5cffef3371f6 | 225 | |
RobMeades | 0:5cffef3371f6 | 226 | MBED_ASSERT(_at != NULL); |
RobMeades | 0:5cffef3371f6 | 227 | |
RobMeades | 0:5cffef3371f6 | 228 | // International mobile subscriber identification |
RobMeades | 0:5cffef3371f6 | 229 | // AT Command Manual UBX-13002752, section 4.11 |
RobMeades | 0:5cffef3371f6 | 230 | success = _at->send("AT+CIMI") && _at->recv("%15[^\n]\nOK\n", _dev_info.imsi); |
RobMeades | 0:5cffef3371f6 | 231 | tr_info("DevInfo: IMSI=%s", _dev_info.imsi); |
RobMeades | 0:5cffef3371f6 | 232 | |
RobMeades | 0:5cffef3371f6 | 233 | UNLOCK(); |
RobMeades | 0:5cffef3371f6 | 234 | return success; |
RobMeades | 0:5cffef3371f6 | 235 | } |
RobMeades | 0:5cffef3371f6 | 236 | |
RobMeades | 0:5cffef3371f6 | 237 | bool UbloxCellularBase::get_imei() |
RobMeades | 0:5cffef3371f6 | 238 | { |
RobMeades | 0:5cffef3371f6 | 239 | bool success; |
RobMeades | 0:5cffef3371f6 | 240 | LOCK(); |
RobMeades | 0:5cffef3371f6 | 241 | |
RobMeades | 0:5cffef3371f6 | 242 | MBED_ASSERT(_at != NULL); |
RobMeades | 0:5cffef3371f6 | 243 | |
RobMeades | 0:5cffef3371f6 | 244 | // International mobile equipment identifier |
RobMeades | 0:5cffef3371f6 | 245 | // AT Command Manual UBX-13002752, section 4.7 |
RobMeades | 0:5cffef3371f6 | 246 | success = _at->send("AT+CGSN") && _at->recv("%15[^\n]\nOK\n", _dev_info.imei); |
RobMeades | 0:5cffef3371f6 | 247 | tr_info("DevInfo: IMEI=%s", _dev_info.imei); |
RobMeades | 0:5cffef3371f6 | 248 | |
RobMeades | 0:5cffef3371f6 | 249 | UNLOCK(); |
RobMeades | 0:5cffef3371f6 | 250 | return success; |
RobMeades | 0:5cffef3371f6 | 251 | } |
RobMeades | 0:5cffef3371f6 | 252 | |
RobMeades | 0:5cffef3371f6 | 253 | bool UbloxCellularBase::get_meid() |
RobMeades | 0:5cffef3371f6 | 254 | { |
RobMeades | 0:5cffef3371f6 | 255 | bool success; |
RobMeades | 0:5cffef3371f6 | 256 | LOCK(); |
RobMeades | 0:5cffef3371f6 | 257 | |
RobMeades | 0:5cffef3371f6 | 258 | MBED_ASSERT(_at != NULL); |
RobMeades | 0:5cffef3371f6 | 259 | |
RobMeades | 0:5cffef3371f6 | 260 | // Mobile equipment identifier |
RobMeades | 0:5cffef3371f6 | 261 | // AT Command Manual UBX-13002752, section 4.8 |
RobMeades | 0:5cffef3371f6 | 262 | success = _at->send("AT+GSN") && _at->recv("%18[^\n]\nOK\n", _dev_info.meid); |
RobMeades | 0:5cffef3371f6 | 263 | tr_info("DevInfo: MEID=%s", _dev_info.meid); |
RobMeades | 0:5cffef3371f6 | 264 | |
RobMeades | 0:5cffef3371f6 | 265 | UNLOCK(); |
RobMeades | 0:5cffef3371f6 | 266 | return success; |
RobMeades | 0:5cffef3371f6 | 267 | } |
RobMeades | 0:5cffef3371f6 | 268 | |
RobMeades | 0:5cffef3371f6 | 269 | bool UbloxCellularBase::set_sms() |
RobMeades | 0:5cffef3371f6 | 270 | { |
RobMeades | 0:5cffef3371f6 | 271 | bool success = false; |
RobMeades | 0:5cffef3371f6 | 272 | char buf[32]; |
RobMeades | 0:5cffef3371f6 | 273 | LOCK(); |
RobMeades | 0:5cffef3371f6 | 274 | |
RobMeades | 0:5cffef3371f6 | 275 | MBED_ASSERT(_at != NULL); |
RobMeades | 0:5cffef3371f6 | 276 | |
RobMeades | 0:5cffef3371f6 | 277 | // Set up SMS format and enable URC |
RobMeades | 0:5cffef3371f6 | 278 | // AT Command Manual UBX-13002752, section 11 |
RobMeades | 0:5cffef3371f6 | 279 | if (_at->send("AT+CMGF=1") && _at->recv("OK")) { |
RobMeades | 0:5cffef3371f6 | 280 | tr_debug("SMS in text mode"); |
RobMeades | 0:5cffef3371f6 | 281 | if (_at->send("AT+CNMI=2,1") && _at->recv("OK")) { |
RobMeades | 0:5cffef3371f6 | 282 | tr_debug("SMS URC enabled"); |
RobMeades | 0:5cffef3371f6 | 283 | // Set to CS preferred since PS preferred doesn't work |
RobMeades | 0:5cffef3371f6 | 284 | // on some networks |
RobMeades | 0:5cffef3371f6 | 285 | if (_at->send("AT+CGSMS=1") && _at->recv("OK")) { |
RobMeades | 0:5cffef3371f6 | 286 | tr_debug("SMS set to CS preferred"); |
RobMeades | 0:5cffef3371f6 | 287 | success = true; |
RobMeades | 0:5cffef3371f6 | 288 | memset (buf, 0, sizeof (buf)); |
RobMeades | 0:5cffef3371f6 | 289 | if (_at->send("AT+CSCA?") && |
RobMeades | 0:5cffef3371f6 | 290 | _at->recv("+CSCA: \"%31[^\"]\"", buf) && |
RobMeades | 0:5cffef3371f6 | 291 | _at->recv("OK")) { |
RobMeades | 0:5cffef3371f6 | 292 | tr_info("SMS Service Centre address is \"%s\"", buf); |
RobMeades | 0:5cffef3371f6 | 293 | } |
RobMeades | 0:5cffef3371f6 | 294 | } |
RobMeades | 0:5cffef3371f6 | 295 | } |
RobMeades | 0:5cffef3371f6 | 296 | } |
RobMeades | 0:5cffef3371f6 | 297 | |
RobMeades | 0:5cffef3371f6 | 298 | UNLOCK(); |
RobMeades | 0:5cffef3371f6 | 299 | return success; |
RobMeades | 0:5cffef3371f6 | 300 | } |
RobMeades | 0:5cffef3371f6 | 301 | |
RobMeades | 0:5cffef3371f6 | 302 | void UbloxCellularBase::parser_abort_cb() |
RobMeades | 0:5cffef3371f6 | 303 | { |
RobMeades | 0:5cffef3371f6 | 304 | _at->abort(); |
RobMeades | 0:5cffef3371f6 | 305 | } |
RobMeades | 0:5cffef3371f6 | 306 | |
RobMeades | 0:5cffef3371f6 | 307 | // Callback for CME ERROR and CMS ERROR. |
RobMeades | 0:5cffef3371f6 | 308 | void UbloxCellularBase::CMX_ERROR_URC() |
RobMeades | 0:5cffef3371f6 | 309 | { |
RobMeades | 0:5cffef3371f6 | 310 | char buf[48]; |
RobMeades | 0:5cffef3371f6 | 311 | |
RobMeades | 0:5cffef3371f6 | 312 | if (read_at_to_char(buf, sizeof (buf), '\n') > 0) { |
RobMeades | 0:5cffef3371f6 | 313 | tr_debug("AT error %s", buf); |
RobMeades | 0:5cffef3371f6 | 314 | } |
RobMeades | 0:5cffef3371f6 | 315 | parser_abort_cb(); |
RobMeades | 0:5cffef3371f6 | 316 | } |
RobMeades | 0:5cffef3371f6 | 317 | |
RobMeades | 0:5cffef3371f6 | 318 | // Callback for circuit switched registration URC. |
RobMeades | 0:5cffef3371f6 | 319 | void UbloxCellularBase::CREG_URC() |
RobMeades | 0:5cffef3371f6 | 320 | { |
RobMeades | 0:5cffef3371f6 | 321 | char buf[10]; |
RobMeades | 0:5cffef3371f6 | 322 | int status; |
RobMeades | 14:e420232ee4e7 | 323 | int acTStatus; |
RobMeades | 0:5cffef3371f6 | 324 | |
RobMeades | 0:5cffef3371f6 | 325 | // If this is the URC it will be a single |
RobMeades | 0:5cffef3371f6 | 326 | // digit followed by \n. If it is the |
RobMeades | 0:5cffef3371f6 | 327 | // answer to a CREG query, it will be |
RobMeades | 0:5cffef3371f6 | 328 | // a ": %d,%d\n" where the second digit |
RobMeades | 0:5cffef3371f6 | 329 | // indicates the status |
RobMeades | 0:5cffef3371f6 | 330 | // Note: not calling _at->recv() from here as we're |
RobMeades | 0:5cffef3371f6 | 331 | // already in an _at->recv() |
RobMeades | 0:5cffef3371f6 | 332 | if (read_at_to_char(buf, sizeof (buf), '\n') > 0) { |
RobMeades | 14:e420232ee4e7 | 333 | if (sscanf(buf, ": %*d,%d,%*d,%*d,%d,", &status, &acTStatus) == 2) { |
RobMeades | 14:e420232ee4e7 | 334 | set_nwk_reg_status_csd(status); |
RobMeades | 14:e420232ee4e7 | 335 | set_rat(acTStatus); |
RobMeades | 14:e420232ee4e7 | 336 | } else if (sscanf(buf, ": %*d,%d", &status) == 1) { |
RobMeades | 0:5cffef3371f6 | 337 | set_nwk_reg_status_csd(status); |
RobMeades | 0:5cffef3371f6 | 338 | } else if (sscanf(buf, ": %d", &status) == 1) { |
RobMeades | 0:5cffef3371f6 | 339 | set_nwk_reg_status_csd(status); |
RobMeades | 0:5cffef3371f6 | 340 | } |
RobMeades | 0:5cffef3371f6 | 341 | } |
RobMeades | 0:5cffef3371f6 | 342 | } |
RobMeades | 0:5cffef3371f6 | 343 | |
RobMeades | 0:5cffef3371f6 | 344 | // Callback for packet switched registration URC. |
RobMeades | 0:5cffef3371f6 | 345 | void UbloxCellularBase::CGREG_URC() |
RobMeades | 0:5cffef3371f6 | 346 | { |
RobMeades | 0:5cffef3371f6 | 347 | char buf[10]; |
RobMeades | 0:5cffef3371f6 | 348 | int status; |
RobMeades | 14:e420232ee4e7 | 349 | int acTStatus; |
RobMeades | 0:5cffef3371f6 | 350 | |
RobMeades | 0:5cffef3371f6 | 351 | // If this is the URC it will be a single |
RobMeades | 0:5cffef3371f6 | 352 | // digit followed by \n. If it is the |
RobMeades | 0:5cffef3371f6 | 353 | // answer to a CGREG query, it will be |
RobMeades | 0:5cffef3371f6 | 354 | // a ": %d,%d\n" where the second digit |
RobMeades | 0:5cffef3371f6 | 355 | // indicates the status |
RobMeades | 0:5cffef3371f6 | 356 | // Note: not calling _at->recv() from here as we're |
RobMeades | 0:5cffef3371f6 | 357 | // already in an _at->recv() |
RobMeades | 0:5cffef3371f6 | 358 | if (read_at_to_char(buf, sizeof (buf), '\n') > 0) { |
RobMeades | 14:e420232ee4e7 | 359 | if (sscanf(buf, ": %*d,%d,%*d,%*d,%d,", &status, &acTStatus) == 2) { |
RobMeades | 14:e420232ee4e7 | 360 | set_nwk_reg_status_csd(status); |
RobMeades | 14:e420232ee4e7 | 361 | set_rat(acTStatus); |
RobMeades | 14:e420232ee4e7 | 362 | } else if (sscanf(buf, ": %*d,%d", &status) == 1) { |
RobMeades | 0:5cffef3371f6 | 363 | set_nwk_reg_status_psd(status); |
RobMeades | 0:5cffef3371f6 | 364 | } else if (sscanf(buf, ": %d", &status) == 1) { |
RobMeades | 0:5cffef3371f6 | 365 | set_nwk_reg_status_psd(status); |
RobMeades | 0:5cffef3371f6 | 366 | } |
RobMeades | 0:5cffef3371f6 | 367 | } |
RobMeades | 0:5cffef3371f6 | 368 | } |
RobMeades | 0:5cffef3371f6 | 369 | |
RobMeades | 0:5cffef3371f6 | 370 | // Callback for EPS registration URC. |
RobMeades | 0:5cffef3371f6 | 371 | void UbloxCellularBase::CEREG_URC() |
RobMeades | 0:5cffef3371f6 | 372 | { |
RobMeades | 0:5cffef3371f6 | 373 | char buf[10]; |
RobMeades | 0:5cffef3371f6 | 374 | int status; |
RobMeades | 14:e420232ee4e7 | 375 | int acTStatus; |
RobMeades | 0:5cffef3371f6 | 376 | |
RobMeades | 0:5cffef3371f6 | 377 | // If this is the URC it will be a single |
RobMeades | 0:5cffef3371f6 | 378 | // digit followed by \n. If it is the |
RobMeades | 0:5cffef3371f6 | 379 | // answer to a CEREG query, it will be |
RobMeades | 0:5cffef3371f6 | 380 | // a ": %d,%d\n" where the second digit |
RobMeades | 0:5cffef3371f6 | 381 | // indicates the status |
RobMeades | 0:5cffef3371f6 | 382 | // Note: not calling _at->recv() from here as we're |
RobMeades | 0:5cffef3371f6 | 383 | // already in an _at->recv() |
RobMeades | 0:5cffef3371f6 | 384 | if (read_at_to_char(buf, sizeof (buf), '\n') > 0) { |
RobMeades | 14:e420232ee4e7 | 385 | if (sscanf(buf, ": %*d,%d,%*d,%*d,%d,", &status, &acTStatus) == 2) { |
RobMeades | 14:e420232ee4e7 | 386 | set_nwk_reg_status_csd(status); |
RobMeades | 14:e420232ee4e7 | 387 | set_rat(acTStatus); |
RobMeades | 14:e420232ee4e7 | 388 | } else if (sscanf(buf, ": %*d,%d", &status) == 1) { |
RobMeades | 0:5cffef3371f6 | 389 | set_nwk_reg_status_eps(status); |
RobMeades | 0:5cffef3371f6 | 390 | } else if (sscanf(buf, ": %d", &status) == 1) { |
RobMeades | 0:5cffef3371f6 | 391 | set_nwk_reg_status_eps(status); |
RobMeades | 0:5cffef3371f6 | 392 | } |
RobMeades | 0:5cffef3371f6 | 393 | } |
RobMeades | 0:5cffef3371f6 | 394 | } |
RobMeades | 0:5cffef3371f6 | 395 | |
RobMeades | 0:5cffef3371f6 | 396 | // Callback UMWI, just filtering it out. |
RobMeades | 0:5cffef3371f6 | 397 | void UbloxCellularBase::UMWI_URC() |
RobMeades | 0:5cffef3371f6 | 398 | { |
RobMeades | 0:5cffef3371f6 | 399 | char buf[10]; |
RobMeades | 0:5cffef3371f6 | 400 | |
RobMeades | 0:5cffef3371f6 | 401 | // Note: not calling _at->recv() from here as we're |
RobMeades | 0:5cffef3371f6 | 402 | // already in an _at->recv() |
RobMeades | 0:5cffef3371f6 | 403 | read_at_to_char(buf, sizeof (buf), '\n'); |
RobMeades | 0:5cffef3371f6 | 404 | } |
RobMeades | 0:5cffef3371f6 | 405 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 406 | #ifdef TARGET_UBLOX_C030_R412M |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 407 | // Callback UUPSMR, set/clear flag for modem psm state. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 408 | void UbloxCellularBase::UUPSMR_URC() |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 409 | { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 410 | int status; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 411 | char buf[10]; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 412 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 413 | if (read_at_to_char(buf, sizeof (buf), '\n') > 0) { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 414 | if (sscanf(buf, ": %d", &status) == 1) { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 415 | set_modem_psm_state(status); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 416 | //call application registered callbacks |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 417 | if (status == AWAKE) { //modem coming out of sleep |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 418 | if (_func_psm_coming_out) { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 419 | _func_psm_coming_out(_cb_param_psm_coming_out); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 420 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 421 | } else if(status == ASLEEP) { //modem going into sleep |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 422 | if (_func_psm_going_in) { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 423 | _func_psm_going_in(_cb_param_psm_going_in); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 424 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 425 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 426 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 427 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 428 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 429 | #endif |
RobMeades | 0:5cffef3371f6 | 430 | /********************************************************************** |
RobMeades | 0:5cffef3371f6 | 431 | * PROTECTED METHODS |
RobMeades | 0:5cffef3371f6 | 432 | **********************************************************************/ |
RobMeades | 0:5cffef3371f6 | 433 | |
RobMeades | 0:5cffef3371f6 | 434 | #if MODEM_ON_BOARD |
RobMeades | 0:5cffef3371f6 | 435 | void UbloxCellularBase::modem_init() |
RobMeades | 0:5cffef3371f6 | 436 | { |
RobMeades | 0:5cffef3371f6 | 437 | ::onboard_modem_init(); |
RobMeades | 0:5cffef3371f6 | 438 | } |
RobMeades | 0:5cffef3371f6 | 439 | |
RobMeades | 0:5cffef3371f6 | 440 | void UbloxCellularBase::modem_deinit() |
RobMeades | 0:5cffef3371f6 | 441 | { |
RobMeades | 0:5cffef3371f6 | 442 | ::onboard_modem_deinit(); |
RobMeades | 0:5cffef3371f6 | 443 | } |
RobMeades | 0:5cffef3371f6 | 444 | |
RobMeades | 0:5cffef3371f6 | 445 | void UbloxCellularBase::modem_power_up() |
RobMeades | 0:5cffef3371f6 | 446 | { |
RobMeades | 0:5cffef3371f6 | 447 | ::onboard_modem_power_up(); |
RobMeades | 0:5cffef3371f6 | 448 | } |
RobMeades | 0:5cffef3371f6 | 449 | |
RobMeades | 0:5cffef3371f6 | 450 | void UbloxCellularBase::modem_power_down() |
RobMeades | 0:5cffef3371f6 | 451 | { |
RobMeades | 0:5cffef3371f6 | 452 | ::onboard_modem_power_down(); |
RobMeades | 0:5cffef3371f6 | 453 | } |
RobMeades | 0:5cffef3371f6 | 454 | #else |
RobMeades | 0:5cffef3371f6 | 455 | void UbloxCellularBase::modem_init() |
RobMeades | 0:5cffef3371f6 | 456 | { |
RobMeades | 0:5cffef3371f6 | 457 | // Meant to be overridden |
RobMeades | 0:5cffef3371f6 | 458 | } |
RobMeades | 0:5cffef3371f6 | 459 | |
RobMeades | 0:5cffef3371f6 | 460 | void UbloxCellularBase::modem_deinit() |
RobMeades | 0:5cffef3371f6 | 461 | { |
RobMeades | 0:5cffef3371f6 | 462 | // Meant to be overridden |
RobMeades | 0:5cffef3371f6 | 463 | } |
RobMeades | 0:5cffef3371f6 | 464 | |
RobMeades | 0:5cffef3371f6 | 465 | void UbloxCellularBase::modem_power_up() |
RobMeades | 0:5cffef3371f6 | 466 | { |
RobMeades | 0:5cffef3371f6 | 467 | // Meant to be overridden |
RobMeades | 0:5cffef3371f6 | 468 | } |
RobMeades | 0:5cffef3371f6 | 469 | |
RobMeades | 0:5cffef3371f6 | 470 | void UbloxCellularBase::modem_power_down() |
RobMeades | 0:5cffef3371f6 | 471 | { |
RobMeades | 0:5cffef3371f6 | 472 | // Mmeant to be overridden |
RobMeades | 0:5cffef3371f6 | 473 | } |
RobMeades | 0:5cffef3371f6 | 474 | #endif |
RobMeades | 0:5cffef3371f6 | 475 | |
RobMeades | 0:5cffef3371f6 | 476 | // Constructor. |
RobMeades | 0:5cffef3371f6 | 477 | // Note: to allow this base class to be inherited as a virtual base class |
RobMeades | 0:5cffef3371f6 | 478 | // by everyone, it takes no parameters. See also comment above classInit() |
RobMeades | 0:5cffef3371f6 | 479 | // in the header file. |
RobMeades | 0:5cffef3371f6 | 480 | UbloxCellularBase::UbloxCellularBase() |
RobMeades | 0:5cffef3371f6 | 481 | { |
RobMeades | 0:5cffef3371f6 | 482 | _pin = NULL; |
RobMeades | 0:5cffef3371f6 | 483 | _at = NULL; |
RobMeades | 0:5cffef3371f6 | 484 | _at_timeout = AT_PARSER_TIMEOUT; |
RobMeades | 0:5cffef3371f6 | 485 | _fh = NULL; |
RobMeades | 0:5cffef3371f6 | 486 | _modem_initialised = false; |
RobMeades | 0:5cffef3371f6 | 487 | _sim_pin_check_enabled = false; |
RobMeades | 0:5cffef3371f6 | 488 | _debug_trace_on = false; |
RobMeades | 0:5cffef3371f6 | 489 | |
RobMeades | 0:5cffef3371f6 | 490 | _dev_info.dev = DEV_TYPE_NONE; |
RobMeades | 0:5cffef3371f6 | 491 | _dev_info.reg_status_csd = CSD_NOT_REGISTERED_NOT_SEARCHING; |
RobMeades | 0:5cffef3371f6 | 492 | _dev_info.reg_status_psd = PSD_NOT_REGISTERED_NOT_SEARCHING; |
RobMeades | 0:5cffef3371f6 | 493 | _dev_info.reg_status_eps = EPS_NOT_REGISTERED_NOT_SEARCHING; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 494 | #ifdef TARGET_UBLOX_C030_R412M |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 495 | _dev_info.modem_psm_state = AWAKE; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 496 | _psm_status = false; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 497 | _cb_param_psm_going_in = NULL; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 498 | _func_psm_going_in = NULL; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 499 | _cb_param_psm_coming_out = NULL; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 500 | _func_psm_coming_out = NULL; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 501 | #endif |
fahimalavi | 26:e4e444cc7b14 | 502 | #ifdef TARGET_UBLOX_C030_R41XM |
fahimalavi | 26:e4e444cc7b14 | 503 | _edrx_configured = false; |
fahimalavi | 26:e4e444cc7b14 | 504 | #endif |
RobMeades | 0:5cffef3371f6 | 505 | } |
RobMeades | 0:5cffef3371f6 | 506 | |
RobMeades | 0:5cffef3371f6 | 507 | // Destructor. |
RobMeades | 0:5cffef3371f6 | 508 | UbloxCellularBase::~UbloxCellularBase() |
RobMeades | 0:5cffef3371f6 | 509 | { |
RobMeades | 0:5cffef3371f6 | 510 | deinit(); |
RobMeades | 0:5cffef3371f6 | 511 | delete _at; |
RobMeades | 0:5cffef3371f6 | 512 | delete _fh; |
RobMeades | 0:5cffef3371f6 | 513 | } |
RobMeades | 0:5cffef3371f6 | 514 | |
RobMeades | 0:5cffef3371f6 | 515 | // Initialise the portions of this class that are parameterised. |
RobMeades | 0:5cffef3371f6 | 516 | void UbloxCellularBase::baseClassInit(PinName tx, PinName rx, |
RobMeades | 0:5cffef3371f6 | 517 | int baud, bool debug_on) |
RobMeades | 0:5cffef3371f6 | 518 | { |
RobMeades | 0:5cffef3371f6 | 519 | // Only initialise ourselves if it's not already been done |
RobMeades | 0:5cffef3371f6 | 520 | if (_at == NULL) { |
RobMeades | 0:5cffef3371f6 | 521 | if (_debug_trace_on == false) { |
RobMeades | 0:5cffef3371f6 | 522 | _debug_trace_on = debug_on; |
RobMeades | 0:5cffef3371f6 | 523 | } |
rob.meades@u-blox.com | 4:2e640a101db1 | 524 | _baud = baud; |
RobMeades | 0:5cffef3371f6 | 525 | |
RobMeades | 0:5cffef3371f6 | 526 | // Set up File Handle for buffered serial comms with cellular module |
RobMeades | 0:5cffef3371f6 | 527 | // (which will be used by the AT parser) |
rob.meades@u-blox.com | 4:2e640a101db1 | 528 | // Note: the UART is initialised to run no faster than 115200 because |
rob.meades@u-blox.com | 4:2e640a101db1 | 529 | // the modems cannot reliably auto-baud at faster rates. The faster |
rob.meades@u-blox.com | 4:2e640a101db1 | 530 | // rate is adopted later with a specific AT command and the |
rob.meades@u-blox.com | 4:2e640a101db1 | 531 | // UARTSerial rate is adjusted at that time |
rob.meades@u-blox.com | 4:2e640a101db1 | 532 | if (baud > 115200) { |
rob.meades@u-blox.com | 4:2e640a101db1 | 533 | baud = 115200; |
rob.meades@u-blox.com | 4:2e640a101db1 | 534 | } |
RobMeades | 0:5cffef3371f6 | 535 | _fh = new UARTSerial(tx, rx, baud); |
RobMeades | 0:5cffef3371f6 | 536 | |
RobMeades | 0:5cffef3371f6 | 537 | // Set up the AT parser |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 538 | #ifdef TARGET_UBLOX_C030_R41XM |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 539 | _at = new UbloxATCmdParser(_fh, OUTPUT_ENTER_KEY, AT_PARSER_BUFFER_SIZE, |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 540 | _at_timeout, _debug_trace_on); |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 541 | #else |
RobMeades | 0:5cffef3371f6 | 542 | _at = new ATCmdParser(_fh, OUTPUT_ENTER_KEY, AT_PARSER_BUFFER_SIZE, |
rob.meades@u-blox.com | 3:f9b2cd6f72b1 | 543 | _at_timeout, _debug_trace_on); |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 544 | #endif |
RobMeades | 0:5cffef3371f6 | 545 | |
RobMeades | 0:5cffef3371f6 | 546 | // Error cases, out of band handling |
RobMeades | 0:5cffef3371f6 | 547 | _at->oob("ERROR", callback(this, &UbloxCellularBase::parser_abort_cb)); |
RobMeades | 0:5cffef3371f6 | 548 | _at->oob("+CME ERROR", callback(this, &UbloxCellularBase::CMX_ERROR_URC)); |
RobMeades | 0:5cffef3371f6 | 549 | _at->oob("+CMS ERROR", callback(this, &UbloxCellularBase::CMX_ERROR_URC)); |
RobMeades | 0:5cffef3371f6 | 550 | |
RobMeades | 0:5cffef3371f6 | 551 | // Registration status, out of band handling |
RobMeades | 0:5cffef3371f6 | 552 | _at->oob("+CREG", callback(this, &UbloxCellularBase::CREG_URC)); |
RobMeades | 0:5cffef3371f6 | 553 | _at->oob("+CGREG", callback(this, &UbloxCellularBase::CGREG_URC)); |
RobMeades | 0:5cffef3371f6 | 554 | _at->oob("+CEREG", callback(this, &UbloxCellularBase::CEREG_URC)); |
RobMeades | 0:5cffef3371f6 | 555 | |
RobMeades | 0:5cffef3371f6 | 556 | // Capture the UMWI, just to stop it getting in the way |
RobMeades | 0:5cffef3371f6 | 557 | _at->oob("+UMWI", callback(this, &UbloxCellularBase::UMWI_URC)); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 558 | #ifdef TARGET_UBLOX_C030_R412M |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 559 | // Handle PSM URC for going in and coming out of PSM |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 560 | _at->oob("+UUPSMR", callback(this, &UbloxCellularBase::UUPSMR_URC)); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 561 | #endif |
RobMeades | 0:5cffef3371f6 | 562 | } |
RobMeades | 0:5cffef3371f6 | 563 | } |
RobMeades | 0:5cffef3371f6 | 564 | |
RobMeades | 0:5cffef3371f6 | 565 | // Set the AT parser timeout. |
RobMeades | 0:5cffef3371f6 | 566 | // Note: the AT interface should be locked before this is called. |
RobMeades | 0:5cffef3371f6 | 567 | void UbloxCellularBase::at_set_timeout(int timeout) { |
RobMeades | 0:5cffef3371f6 | 568 | |
RobMeades | 0:5cffef3371f6 | 569 | MBED_ASSERT(_at != NULL); |
RobMeades | 0:5cffef3371f6 | 570 | |
RobMeades | 0:5cffef3371f6 | 571 | _at_timeout = timeout; |
RobMeades | 0:5cffef3371f6 | 572 | _at->set_timeout(timeout); |
RobMeades | 0:5cffef3371f6 | 573 | } |
RobMeades | 0:5cffef3371f6 | 574 | |
RobMeades | 0:5cffef3371f6 | 575 | // Read up to size bytes from the AT interface up to a "end". |
RobMeades | 0:5cffef3371f6 | 576 | // Note: the AT interface should be locked before this is called. |
RobMeades | 0:5cffef3371f6 | 577 | int UbloxCellularBase::read_at_to_char(char * buf, int size, char end) |
RobMeades | 0:5cffef3371f6 | 578 | { |
RobMeades | 0:5cffef3371f6 | 579 | int count = 0; |
RobMeades | 0:5cffef3371f6 | 580 | int x = 0; |
RobMeades | 0:5cffef3371f6 | 581 | |
RobMeades | 0:5cffef3371f6 | 582 | if (size > 0) { |
RobMeades | 0:5cffef3371f6 | 583 | for (count = 0; (count < size) && (x >= 0) && (x != end); count++) { |
RobMeades | 0:5cffef3371f6 | 584 | x = _at->getc(); |
RobMeades | 0:5cffef3371f6 | 585 | *(buf + count) = (char) x; |
RobMeades | 0:5cffef3371f6 | 586 | } |
RobMeades | 0:5cffef3371f6 | 587 | |
RobMeades | 0:5cffef3371f6 | 588 | count--; |
RobMeades | 0:5cffef3371f6 | 589 | *(buf + count) = 0; |
RobMeades | 0:5cffef3371f6 | 590 | |
RobMeades | 0:5cffef3371f6 | 591 | // Convert line endings: |
RobMeades | 0:5cffef3371f6 | 592 | // If end was '\n' (0x0a) and the preceding character was 0x0d, then |
RobMeades | 0:5cffef3371f6 | 593 | // overwrite that with null as well. |
RobMeades | 0:5cffef3371f6 | 594 | if ((count > 0) && (end == '\n') && (*(buf + count - 1) == '\x0d')) { |
RobMeades | 0:5cffef3371f6 | 595 | count--; |
RobMeades | 0:5cffef3371f6 | 596 | *(buf + count) = 0; |
RobMeades | 0:5cffef3371f6 | 597 | } |
RobMeades | 0:5cffef3371f6 | 598 | } |
RobMeades | 0:5cffef3371f6 | 599 | |
RobMeades | 0:5cffef3371f6 | 600 | return count; |
RobMeades | 0:5cffef3371f6 | 601 | } |
RobMeades | 0:5cffef3371f6 | 602 | |
RobMeades | 0:5cffef3371f6 | 603 | // Power up the modem. |
RobMeades | 0:5cffef3371f6 | 604 | // Enables the GPIO lines to the modem and then wriggles the power line in short pulses. |
RobMeades | 0:5cffef3371f6 | 605 | bool UbloxCellularBase::power_up() |
RobMeades | 0:5cffef3371f6 | 606 | { |
RobMeades | 0:5cffef3371f6 | 607 | bool success = false; |
RobMeades | 0:5cffef3371f6 | 608 | int at_timeout; |
RobMeades | 0:5cffef3371f6 | 609 | LOCK(); |
RobMeades | 0:5cffef3371f6 | 610 | |
RobMeades | 0:5cffef3371f6 | 611 | at_timeout = _at_timeout; // Has to be inside LOCK()s |
RobMeades | 0:5cffef3371f6 | 612 | |
RobMeades | 0:5cffef3371f6 | 613 | MBED_ASSERT(_at != NULL); |
RobMeades | 0:5cffef3371f6 | 614 | |
RobMeades | 0:5cffef3371f6 | 615 | /* Initialize GPIO lines */ |
RobMeades | 0:5cffef3371f6 | 616 | tr_info("Powering up modem..."); |
pilotak | 7:c2cf27a981b3 | 617 | modem_init(); |
RobMeades | 0:5cffef3371f6 | 618 | /* Give modem a little time to settle down */ |
RobMeades | 0:5cffef3371f6 | 619 | wait_ms(250); |
RobMeades | 0:5cffef3371f6 | 620 | |
RobMeades | 0:5cffef3371f6 | 621 | for (int retry_count = 0; !success && (retry_count < 20); retry_count++) { |
wajahat.abbas@u-blox.com | 16:afb3ca2d9915 | 622 | //In case of SARA-R4, modem takes a while to turn on, constantly toggling the power pin every ~2 secs causes the modem to never power up. |
wajahat.abbas@u-blox.com | 16:afb3ca2d9915 | 623 | if ( (retry_count % 5) == 0) { |
wajahat.abbas@u-blox.com | 16:afb3ca2d9915 | 624 | modem_power_up(); |
wajahat.abbas@u-blox.com | 16:afb3ca2d9915 | 625 | } |
RobMeades | 0:5cffef3371f6 | 626 | wait_ms(500); |
RobMeades | 0:5cffef3371f6 | 627 | // Modem tends to spit out noise during power up - don't confuse the parser |
RobMeades | 0:5cffef3371f6 | 628 | _at->flush(); |
RobMeades | 0:5cffef3371f6 | 629 | at_set_timeout(1000); |
RobMeades | 0:5cffef3371f6 | 630 | if (_at->send("AT")) { |
RobMeades | 0:5cffef3371f6 | 631 | // C027 needs a delay here |
RobMeades | 0:5cffef3371f6 | 632 | wait_ms(100); |
RobMeades | 0:5cffef3371f6 | 633 | if (_at->recv("OK")) { |
RobMeades | 0:5cffef3371f6 | 634 | success = true; |
RobMeades | 0:5cffef3371f6 | 635 | } |
RobMeades | 0:5cffef3371f6 | 636 | } |
RobMeades | 0:5cffef3371f6 | 637 | at_set_timeout(at_timeout); |
RobMeades | 0:5cffef3371f6 | 638 | } |
RobMeades | 0:5cffef3371f6 | 639 | |
rob.meades@u-blox.com | 4:2e640a101db1 | 640 | if (success) { |
rob.meades@u-blox.com | 4:2e640a101db1 | 641 | // Set the final baud rate |
rob.meades@u-blox.com | 4:2e640a101db1 | 642 | if (_at->send("AT+IPR=%d", _baud) && _at->recv("OK")) { |
rob.meades@u-blox.com | 4:2e640a101db1 | 643 | // Need to wait for things to be sorted out on the modem side |
rob.meades@u-blox.com | 4:2e640a101db1 | 644 | wait_ms(100); |
rob.meades@u-blox.com | 4:2e640a101db1 | 645 | ((UARTSerial *)_fh)->set_baud(_baud); |
rob.meades@u-blox.com | 4:2e640a101db1 | 646 | } |
rob.meades@u-blox.com | 4:2e640a101db1 | 647 | |
rob.meades@u-blox.com | 4:2e640a101db1 | 648 | // Turn off modem echoing and turn on verbose responses |
rob.meades@u-blox.com | 4:2e640a101db1 | 649 | success = _at->send("ATE0;+CMEE=2") && _at->recv("OK") && |
rob.meades@u-blox.com | 4:2e640a101db1 | 650 | // The following commands are best sent separately |
rob.meades@u-blox.com | 4:2e640a101db1 | 651 | _at->send("AT&K0") && _at->recv("OK") && // Turn off RTC/CTS handshaking |
rob.meades@u-blox.com | 4:2e640a101db1 | 652 | _at->send("AT&C1") && _at->recv("OK") && // Set DCD circuit(109), changes in accordance with the carrier detect status |
rob.meades@u-blox.com | 4:2e640a101db1 | 653 | _at->send("AT&D0") && _at->recv("OK"); // Set DTR circuit, we ignore the state change of DTR |
rob.meades@u-blox.com | 4:2e640a101db1 | 654 | } |
RobMeades | 0:5cffef3371f6 | 655 | |
RobMeades | 0:5cffef3371f6 | 656 | if (!success) { |
RobMeades | 0:5cffef3371f6 | 657 | tr_error("Preliminary modem setup failed."); |
RobMeades | 0:5cffef3371f6 | 658 | } |
RobMeades | 0:5cffef3371f6 | 659 | |
RobMeades | 0:5cffef3371f6 | 660 | UNLOCK(); |
RobMeades | 0:5cffef3371f6 | 661 | return success; |
RobMeades | 0:5cffef3371f6 | 662 | } |
RobMeades | 0:5cffef3371f6 | 663 | |
RobMeades | 0:5cffef3371f6 | 664 | // Power down modem via AT interface. |
RobMeades | 0:5cffef3371f6 | 665 | void UbloxCellularBase::power_down() |
RobMeades | 0:5cffef3371f6 | 666 | { |
RobMeades | 0:5cffef3371f6 | 667 | LOCK(); |
RobMeades | 0:5cffef3371f6 | 668 | |
RobMeades | 0:5cffef3371f6 | 669 | MBED_ASSERT(_at != NULL); |
RobMeades | 0:5cffef3371f6 | 670 | |
Mudassar Hussain |
17:c6a4d5072589 | 671 | // power-off modem |
pilotak | 7:c2cf27a981b3 | 672 | modem_power_down(); |
pilotak | 7:c2cf27a981b3 | 673 | modem_deinit(); |
RobMeades | 0:5cffef3371f6 | 674 | |
Mudassar Hussain |
17:c6a4d5072589 | 675 | if (_modem_initialised && (_at != NULL)) { |
Mudassar Hussain |
17:c6a4d5072589 | 676 | int at_timeout = _at_timeout; // Save previous timeout |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 677 | _at->set_timeout(1000); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 678 | // Check modem is powered off |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 679 | if(_at->send("AT") && _at->recv("OK")) { |
Mudassar Hussain |
17:c6a4d5072589 | 680 | _at->send("AT+CPWROFF") && _at->recv("OK"); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 681 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 682 | _at->set_timeout(at_timeout); |
Mudassar Hussain |
17:c6a4d5072589 | 683 | } |
Mudassar Hussain |
17:c6a4d5072589 | 684 | |
RobMeades | 0:5cffef3371f6 | 685 | _dev_info.reg_status_csd = CSD_NOT_REGISTERED_NOT_SEARCHING; |
RobMeades | 0:5cffef3371f6 | 686 | _dev_info.reg_status_psd = PSD_NOT_REGISTERED_NOT_SEARCHING; |
RobMeades | 0:5cffef3371f6 | 687 | _dev_info.reg_status_eps = EPS_NOT_REGISTERED_NOT_SEARCHING; |
RobMeades | 0:5cffef3371f6 | 688 | |
RobMeades | 0:5cffef3371f6 | 689 | UNLOCK(); |
RobMeades | 0:5cffef3371f6 | 690 | } |
RobMeades | 0:5cffef3371f6 | 691 | |
RobMeades | 0:5cffef3371f6 | 692 | // Get the device ID. |
RobMeades | 0:5cffef3371f6 | 693 | bool UbloxCellularBase::set_device_identity(DeviceType *dev) |
RobMeades | 0:5cffef3371f6 | 694 | { |
RobMeades | 0:5cffef3371f6 | 695 | char buf[20]; |
RobMeades | 0:5cffef3371f6 | 696 | bool success; |
RobMeades | 0:5cffef3371f6 | 697 | LOCK(); |
RobMeades | 0:5cffef3371f6 | 698 | |
RobMeades | 0:5cffef3371f6 | 699 | MBED_ASSERT(_at != NULL); |
RobMeades | 0:5cffef3371f6 | 700 | |
RobMeades | 0:5cffef3371f6 | 701 | success = _at->send("ATI") && _at->recv("%19[^\n]\nOK\n", buf); |
RobMeades | 0:5cffef3371f6 | 702 | |
RobMeades | 0:5cffef3371f6 | 703 | if (success) { |
RobMeades | 0:5cffef3371f6 | 704 | if (strstr(buf, "SARA-G35")) |
RobMeades | 0:5cffef3371f6 | 705 | *dev = DEV_SARA_G35; |
RobMeades | 0:5cffef3371f6 | 706 | else if (strstr(buf, "LISA-U200-03S")) |
RobMeades | 0:5cffef3371f6 | 707 | *dev = DEV_LISA_U2_03S; |
RobMeades | 0:5cffef3371f6 | 708 | else if (strstr(buf, "LISA-U2")) |
RobMeades | 0:5cffef3371f6 | 709 | *dev = DEV_LISA_U2; |
RobMeades | 0:5cffef3371f6 | 710 | else if (strstr(buf, "SARA-U2")) |
RobMeades | 0:5cffef3371f6 | 711 | *dev = DEV_SARA_U2; |
fahimalavi | 10:c4281fa79b8f | 712 | else if (strstr(buf, "SARA-R4")) |
fahimalavi | 10:c4281fa79b8f | 713 | *dev = DEV_SARA_R4; |
RobMeades | 0:5cffef3371f6 | 714 | else if (strstr(buf, "LEON-G2")) |
RobMeades | 0:5cffef3371f6 | 715 | *dev = DEV_LEON_G2; |
RobMeades | 0:5cffef3371f6 | 716 | else if (strstr(buf, "TOBY-L2")) |
RobMeades | 0:5cffef3371f6 | 717 | *dev = DEV_TOBY_L2; |
RobMeades | 0:5cffef3371f6 | 718 | else if (strstr(buf, "MPCI-L2")) |
RobMeades | 0:5cffef3371f6 | 719 | *dev = DEV_MPCI_L2; |
RobMeades | 0:5cffef3371f6 | 720 | } |
RobMeades | 0:5cffef3371f6 | 721 | |
RobMeades | 0:5cffef3371f6 | 722 | UNLOCK(); |
RobMeades | 0:5cffef3371f6 | 723 | return success; |
RobMeades | 0:5cffef3371f6 | 724 | } |
RobMeades | 0:5cffef3371f6 | 725 | |
RobMeades | 0:5cffef3371f6 | 726 | // Send initialisation AT commands that are specific to the device. |
RobMeades | 0:5cffef3371f6 | 727 | bool UbloxCellularBase::device_init(DeviceType dev) |
RobMeades | 0:5cffef3371f6 | 728 | { |
RobMeades | 0:5cffef3371f6 | 729 | bool success = false; |
RobMeades | 0:5cffef3371f6 | 730 | LOCK(); |
RobMeades | 0:5cffef3371f6 | 731 | |
RobMeades | 0:5cffef3371f6 | 732 | MBED_ASSERT(_at != NULL); |
RobMeades | 0:5cffef3371f6 | 733 | |
RobMeades | 0:5cffef3371f6 | 734 | if ((dev == DEV_LISA_U2) || (dev == DEV_LEON_G2) || (dev == DEV_TOBY_L2)) { |
RobMeades | 0:5cffef3371f6 | 735 | success = _at->send("AT+UGPIOC=20,2") && _at->recv("OK"); |
RobMeades | 0:5cffef3371f6 | 736 | } else if ((dev == DEV_SARA_U2) || (dev == DEV_SARA_G35)) { |
RobMeades | 0:5cffef3371f6 | 737 | success = _at->send("AT+UGPIOC=16,2") && _at->recv("OK"); |
RobMeades | 0:5cffef3371f6 | 738 | } else { |
RobMeades | 0:5cffef3371f6 | 739 | success = true; |
RobMeades | 0:5cffef3371f6 | 740 | } |
RobMeades | 0:5cffef3371f6 | 741 | |
RobMeades | 0:5cffef3371f6 | 742 | UNLOCK(); |
RobMeades | 0:5cffef3371f6 | 743 | return success; |
RobMeades | 0:5cffef3371f6 | 744 | } |
RobMeades | 0:5cffef3371f6 | 745 | |
RobMeades | 0:5cffef3371f6 | 746 | // Get the SIM card going. |
RobMeades | 0:5cffef3371f6 | 747 | bool UbloxCellularBase::initialise_sim_card() |
RobMeades | 0:5cffef3371f6 | 748 | { |
RobMeades | 0:5cffef3371f6 | 749 | bool success = false; |
RobMeades | 0:5cffef3371f6 | 750 | int retry_count = 0; |
RobMeades | 0:5cffef3371f6 | 751 | bool done = false; |
RobMeades | 0:5cffef3371f6 | 752 | LOCK(); |
RobMeades | 0:5cffef3371f6 | 753 | |
RobMeades | 0:5cffef3371f6 | 754 | MBED_ASSERT(_at != NULL); |
RobMeades | 0:5cffef3371f6 | 755 | |
RobMeades | 0:5cffef3371f6 | 756 | /* SIM initialisation may take a significant amount, so an error is |
RobMeades | 0:5cffef3371f6 | 757 | * kind of expected. We should retry 10 times until we succeed or timeout. */ |
RobMeades | 0:5cffef3371f6 | 758 | for (retry_count = 0; !done && (retry_count < 10); retry_count++) { |
RobMeades | 0:5cffef3371f6 | 759 | char pinstr[16]; |
RobMeades | 0:5cffef3371f6 | 760 | |
RobMeades | 0:5cffef3371f6 | 761 | if (_at->send("AT+CPIN?") && _at->recv("+CPIN: %15[^\n]\n", pinstr) && |
RobMeades | 0:5cffef3371f6 | 762 | _at->recv("OK")) { |
RobMeades | 0:5cffef3371f6 | 763 | done = true; |
RobMeades | 0:5cffef3371f6 | 764 | if (strcmp(pinstr, "SIM PIN") == 0) { |
RobMeades | 0:5cffef3371f6 | 765 | _sim_pin_check_enabled = true; |
RobMeades | 0:5cffef3371f6 | 766 | if (_at->send("AT+CPIN=\"%s\"", _pin)) { |
RobMeades | 0:5cffef3371f6 | 767 | if (_at->recv("OK")) { |
RobMeades | 0:5cffef3371f6 | 768 | tr_info("PIN correct"); |
RobMeades | 0:5cffef3371f6 | 769 | success = true; |
RobMeades | 0:5cffef3371f6 | 770 | } else { |
RobMeades | 0:5cffef3371f6 | 771 | tr_error("Incorrect PIN"); |
RobMeades | 0:5cffef3371f6 | 772 | } |
RobMeades | 0:5cffef3371f6 | 773 | } |
RobMeades | 0:5cffef3371f6 | 774 | } else if (strcmp(pinstr, "READY") == 0) { |
RobMeades | 0:5cffef3371f6 | 775 | _sim_pin_check_enabled = false; |
RobMeades | 0:5cffef3371f6 | 776 | tr_info("No PIN required"); |
RobMeades | 0:5cffef3371f6 | 777 | success = true; |
RobMeades | 0:5cffef3371f6 | 778 | } else { |
RobMeades | 0:5cffef3371f6 | 779 | tr_debug("Unexpected response from SIM: \"%s\"", pinstr); |
RobMeades | 0:5cffef3371f6 | 780 | } |
RobMeades | 0:5cffef3371f6 | 781 | } |
RobMeades | 0:5cffef3371f6 | 782 | |
RobMeades | 0:5cffef3371f6 | 783 | /* wait for a second before retry */ |
RobMeades | 0:5cffef3371f6 | 784 | wait_ms(1000); |
RobMeades | 0:5cffef3371f6 | 785 | } |
RobMeades | 0:5cffef3371f6 | 786 | |
RobMeades | 0:5cffef3371f6 | 787 | if (done) { |
RobMeades | 0:5cffef3371f6 | 788 | tr_info("SIM Ready."); |
RobMeades | 0:5cffef3371f6 | 789 | } else { |
RobMeades | 0:5cffef3371f6 | 790 | tr_error("SIM not ready."); |
RobMeades | 0:5cffef3371f6 | 791 | } |
RobMeades | 0:5cffef3371f6 | 792 | |
RobMeades | 0:5cffef3371f6 | 793 | UNLOCK(); |
RobMeades | 0:5cffef3371f6 | 794 | return success; |
RobMeades | 0:5cffef3371f6 | 795 | } |
RobMeades | 0:5cffef3371f6 | 796 | |
RobMeades | 0:5cffef3371f6 | 797 | /********************************************************************** |
RobMeades | 0:5cffef3371f6 | 798 | * PUBLIC METHODS |
RobMeades | 0:5cffef3371f6 | 799 | **********************************************************************/ |
RobMeades | 0:5cffef3371f6 | 800 | |
RobMeades | 0:5cffef3371f6 | 801 | // Initialise the modem. |
RobMeades | 0:5cffef3371f6 | 802 | bool UbloxCellularBase::init(const char *pin) |
RobMeades | 0:5cffef3371f6 | 803 | { |
RobMeades | 8:a15349fcab25 | 804 | int x; |
RobMeades | 0:5cffef3371f6 | 805 | MBED_ASSERT(_at != NULL); |
RobMeades | 0:5cffef3371f6 | 806 | |
RobMeades | 0:5cffef3371f6 | 807 | if (!_modem_initialised) { |
RobMeades | 0:5cffef3371f6 | 808 | if (power_up()) { |
RobMeades | 0:5cffef3371f6 | 809 | tr_info("Modem Ready."); |
RobMeades | 0:5cffef3371f6 | 810 | if (pin != NULL) { |
RobMeades | 0:5cffef3371f6 | 811 | _pin = pin; |
RobMeades | 0:5cffef3371f6 | 812 | } |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 813 | #ifdef TARGET_UBLOX_C027 |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 814 | if (set_functionality_mode(FUNC_MIN)) { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 815 | #else |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 816 | if (set_functionality_mode(FUNC_AIRPLANE)) { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 817 | #endif |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 818 | if (initialise_sim_card()) { |
fahimalavi | 26:e4e444cc7b14 | 819 | int mno_profile; |
fahimalavi | 26:e4e444cc7b14 | 820 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 821 | #ifdef TARGET_UBLOX_C030_R412M |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 822 | if (_psm_status == false) { //psm is not enabled by application yet so disable it at start-up |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 823 | set_power_saving_mode(0, 0); |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 824 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 825 | #endif |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 826 | #ifdef TARGET_UBLOX_C030_R41XM |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 827 | if (_at->is_idle_mode_enabled() == false) { |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 828 | set_idle_mode(false); //disable idle mode at start up |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 829 | } |
fahimalavi | 26:e4e444cc7b14 | 830 | if(_edrx_configured == false) { |
fahimalavi | 26:e4e444cc7b14 | 831 | // A special form of the command can be given as +CEDRXS=3. |
fahimalavi | 26:e4e444cc7b14 | 832 | // In this form, eDRX will be disabled and data for all parameters in the command +CEDRXS will be removed or, |
fahimalavi | 26:e4e444cc7b14 | 833 | // if available, set to the manufacturer specific default values. |
fahimalavi | 26:e4e444cc7b14 | 834 | set_receive_period(3,UbloxCellularBase::EDRXGSM_A_Gb_mode); |
fahimalavi | 26:e4e444cc7b14 | 835 | set_receive_period(3,UbloxCellularBase::EDRXEUTRAN_WB_S1_mode); |
fahimalavi | 26:e4e444cc7b14 | 836 | set_receive_period(3,UbloxCellularBase::EDRXEUTRAN_NB_S1_mode); |
fahimalavi | 26:e4e444cc7b14 | 837 | } |
fahimalavi | 26:e4e444cc7b14 | 838 | get_receive_period(); |
fahimalavi | 26:e4e444cc7b14 | 839 | |
fahimalavi | 26:e4e444cc7b14 | 840 | if (get_mno_profile(&mno_profile)) |
fahimalavi | 26:e4e444cc7b14 | 841 | tr_info("Current MNO profile is: %d", mno_profile); |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 842 | #endif |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 843 | if (set_device_identity(&_dev_info.dev) && // Set up device identity |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 844 | device_init(_dev_info.dev)) {// Initialise this device |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 845 | // Get the integrated circuit ID of the SIM |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 846 | if (get_iccid()) { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 847 | // Try a few times to get the IMSI (since on some modems this can |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 848 | // take a while to be retrieved, especially if a SIM PIN |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 849 | // was set) |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 850 | for (x = 0; (x < 3) && !get_imsi(); x++) { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 851 | wait_ms(1000); |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 852 | } |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 853 | |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 854 | if (x < 3) { // If we got the IMSI, can get the others |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 855 | if (get_imei() && // Get international mobile equipment identifier |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 856 | get_meid() && // Probably the same as the IMEI |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 857 | set_sms()) { // And set up SMS |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 858 | // The modem is initialised. |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 859 | _modem_initialised = true; |
fahimalavi | 26:e4e444cc7b14 | 860 | tr_info("Modem initialized"); |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 861 | } |
rob.meades@u-blox.com | 6:8fadf1e49487 | 862 | } |
rob.meades@u-blox.com | 6:8fadf1e49487 | 863 | } |
rob.meades@u-blox.com | 6:8fadf1e49487 | 864 | } |
RobMeades | 0:5cffef3371f6 | 865 | } |
RobMeades | 0:5cffef3371f6 | 866 | } |
RobMeades | 0:5cffef3371f6 | 867 | } |
RobMeades | 0:5cffef3371f6 | 868 | } |
RobMeades | 0:5cffef3371f6 | 869 | |
RobMeades | 0:5cffef3371f6 | 870 | return _modem_initialised; |
RobMeades | 0:5cffef3371f6 | 871 | } |
RobMeades | 0:5cffef3371f6 | 872 | |
RobMeades | 0:5cffef3371f6 | 873 | // Perform registration. |
RobMeades | 0:5cffef3371f6 | 874 | bool UbloxCellularBase::nwk_registration() |
RobMeades | 0:5cffef3371f6 | 875 | { |
RobMeades | 0:5cffef3371f6 | 876 | bool atSuccess = false; |
RobMeades | 0:5cffef3371f6 | 877 | bool registered = false; |
RobMeades | 0:5cffef3371f6 | 878 | int status; |
RobMeades | 0:5cffef3371f6 | 879 | int at_timeout; |
RobMeades | 0:5cffef3371f6 | 880 | LOCK(); |
RobMeades | 0:5cffef3371f6 | 881 | |
RobMeades | 0:5cffef3371f6 | 882 | at_timeout = _at_timeout; // Has to be inside LOCK()s |
RobMeades | 0:5cffef3371f6 | 883 | |
RobMeades | 0:5cffef3371f6 | 884 | MBED_ASSERT(_at != NULL); |
RobMeades | 0:5cffef3371f6 | 885 | |
RobMeades | 0:5cffef3371f6 | 886 | if (!is_registered_psd() && !is_registered_csd() && !is_registered_eps()) { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 887 | if (set_functionality_mode(FUNC_FULL)) { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 888 | tr_info("Searching Network..."); |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 889 | // Enable the packet switched and network registration unsolicited result codes |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 890 | if (_at->send("AT+CREG=1") && _at->recv("OK") && |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 891 | _at->send("AT+CGREG=1") && _at->recv("OK")) { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 892 | atSuccess = true; |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 893 | if (_at->send("AT+CEREG=1")) { |
RobMeades | 0:5cffef3371f6 | 894 | _at->recv("OK"); |
RobMeades | 0:5cffef3371f6 | 895 | // Don't check return value as this works for LTE only |
RobMeades | 0:5cffef3371f6 | 896 | } |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 897 | |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 898 | if (atSuccess) { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 899 | // See if we are already in automatic mode |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 900 | if (_at->send("AT+COPS?") && _at->recv("+COPS: %d", &status) && |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 901 | _at->recv("OK")) { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 902 | // If not, set it |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 903 | if (status != 0) { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 904 | // Don't check return code here as there's not much |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 905 | // we can do if this fails. |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 906 | _at->send("AT+COPS=0") && _at->recv("OK"); |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 907 | } |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 908 | } |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 909 | |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 910 | // Query the registration status directly as well, |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 911 | // just in case |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 912 | if (_at->send("AT+CREG?") && _at->recv("OK")) { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 913 | // Answer will be processed by URC |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 914 | } |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 915 | if (_at->send("AT+CGREG?") && _at->recv("OK")) { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 916 | // Answer will be processed by URC |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 917 | } |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 918 | if (_at->send("AT+CEREG?")) { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 919 | _at->recv("OK"); |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 920 | // Don't check return value as this works for LTE only |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 921 | } |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 922 | } |
RobMeades | 0:5cffef3371f6 | 923 | } |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 924 | // Wait for registration to succeed |
RobMeades | 0:5cffef3371f6 | 925 | at_set_timeout(1000); |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 926 | for (int waitSeconds = 0; !registered && (waitSeconds < 180); waitSeconds++) { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 927 | registered = is_registered_psd() || is_registered_csd() || is_registered_eps(); |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 928 | _at->recv(UNNATURAL_STRING); |
RobMeades | 0:5cffef3371f6 | 929 | } |
RobMeades | 0:5cffef3371f6 | 930 | at_set_timeout(at_timeout); |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 931 | |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 932 | if (registered) { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 933 | // This should return quickly but sometimes the status field is not returned |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 934 | // so make the timeout short |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 935 | at_set_timeout(1000); |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 936 | if (_at->send("AT+COPS?") && _at->recv("+COPS: %*d,%*d,\"%*[^\"]\",%d\n", &status)) { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 937 | set_rat(status); |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 938 | } |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 939 | at_set_timeout(at_timeout); |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 940 | } |
RobMeades | 0:5cffef3371f6 | 941 | } |
RobMeades | 0:5cffef3371f6 | 942 | } else { |
RobMeades | 0:5cffef3371f6 | 943 | registered = true; |
RobMeades | 0:5cffef3371f6 | 944 | } |
RobMeades | 0:5cffef3371f6 | 945 | |
RobMeades | 0:5cffef3371f6 | 946 | UNLOCK(); |
RobMeades | 0:5cffef3371f6 | 947 | return registered; |
RobMeades | 0:5cffef3371f6 | 948 | } |
RobMeades | 0:5cffef3371f6 | 949 | |
RobMeades | 0:5cffef3371f6 | 950 | bool UbloxCellularBase::is_registered_csd() |
RobMeades | 0:5cffef3371f6 | 951 | { |
RobMeades | 0:5cffef3371f6 | 952 | return (_dev_info.reg_status_csd == CSD_REGISTERED) || |
RobMeades | 0:5cffef3371f6 | 953 | (_dev_info.reg_status_csd == CSD_REGISTERED_ROAMING) || |
RobMeades | 0:5cffef3371f6 | 954 | (_dev_info.reg_status_csd == CSD_CSFB_NOT_PREFERRED); |
RobMeades | 0:5cffef3371f6 | 955 | } |
RobMeades | 0:5cffef3371f6 | 956 | |
RobMeades | 0:5cffef3371f6 | 957 | bool UbloxCellularBase::is_registered_psd() |
RobMeades | 0:5cffef3371f6 | 958 | { |
RobMeades | 0:5cffef3371f6 | 959 | return (_dev_info.reg_status_psd == PSD_REGISTERED) || |
RobMeades | 0:5cffef3371f6 | 960 | (_dev_info.reg_status_psd == PSD_REGISTERED_ROAMING); |
RobMeades | 0:5cffef3371f6 | 961 | } |
RobMeades | 0:5cffef3371f6 | 962 | |
RobMeades | 0:5cffef3371f6 | 963 | bool UbloxCellularBase::is_registered_eps() |
RobMeades | 0:5cffef3371f6 | 964 | { |
RobMeades | 0:5cffef3371f6 | 965 | return (_dev_info.reg_status_eps == EPS_REGISTERED) || |
RobMeades | 0:5cffef3371f6 | 966 | (_dev_info.reg_status_eps == EPS_REGISTERED_ROAMING); |
RobMeades | 0:5cffef3371f6 | 967 | } |
RobMeades | 0:5cffef3371f6 | 968 | |
RobMeades | 0:5cffef3371f6 | 969 | // Perform deregistration. |
RobMeades | 0:5cffef3371f6 | 970 | bool UbloxCellularBase::nwk_deregistration() |
RobMeades | 0:5cffef3371f6 | 971 | { |
RobMeades | 0:5cffef3371f6 | 972 | bool success = false; |
RobMeades | 0:5cffef3371f6 | 973 | LOCK(); |
RobMeades | 0:5cffef3371f6 | 974 | |
RobMeades | 0:5cffef3371f6 | 975 | MBED_ASSERT(_at != NULL); |
RobMeades | 0:5cffef3371f6 | 976 | |
mudassar0121 |
27:250eaef6232d | 977 | int at_timeout = _at_timeout; // Has to be inside LOCK()s |
fahimalavi | 26:e4e444cc7b14 | 978 | at_set_timeout(3*60*1000); //command has 3 minutes timeout |
fahimalavi | 26:e4e444cc7b14 | 979 | |
RobMeades | 0:5cffef3371f6 | 980 | if (_at->send("AT+COPS=2") && _at->recv("OK")) { |
RobMeades | 0:5cffef3371f6 | 981 | _dev_info.reg_status_csd = CSD_NOT_REGISTERED_NOT_SEARCHING; |
RobMeades | 0:5cffef3371f6 | 982 | _dev_info.reg_status_psd = PSD_NOT_REGISTERED_NOT_SEARCHING; |
RobMeades | 0:5cffef3371f6 | 983 | _dev_info.reg_status_eps = EPS_NOT_REGISTERED_NOT_SEARCHING; |
RobMeades | 0:5cffef3371f6 | 984 | success = true; |
RobMeades | 0:5cffef3371f6 | 985 | } |
RobMeades | 0:5cffef3371f6 | 986 | |
mudassar0121 |
27:250eaef6232d | 987 | at_set_timeout(at_timeout); |
RobMeades | 0:5cffef3371f6 | 988 | UNLOCK(); |
RobMeades | 0:5cffef3371f6 | 989 | return success; |
RobMeades | 0:5cffef3371f6 | 990 | } |
RobMeades | 0:5cffef3371f6 | 991 | |
RobMeades | 0:5cffef3371f6 | 992 | // Put the modem into its lowest power state. |
RobMeades | 0:5cffef3371f6 | 993 | void UbloxCellularBase::deinit() |
RobMeades | 0:5cffef3371f6 | 994 | { |
RobMeades | 0:5cffef3371f6 | 995 | power_down(); |
RobMeades | 0:5cffef3371f6 | 996 | _modem_initialised = false; |
RobMeades | 0:5cffef3371f6 | 997 | } |
RobMeades | 0:5cffef3371f6 | 998 | |
RobMeades | 0:5cffef3371f6 | 999 | // Set the PIN. |
RobMeades | 0:5cffef3371f6 | 1000 | void UbloxCellularBase::set_pin(const char *pin) { |
RobMeades | 0:5cffef3371f6 | 1001 | _pin = pin; |
RobMeades | 0:5cffef3371f6 | 1002 | } |
RobMeades | 0:5cffef3371f6 | 1003 | |
RobMeades | 0:5cffef3371f6 | 1004 | // Enable or disable SIM pin checking. |
rob.meades@u-blox.com | 4:2e640a101db1 | 1005 | bool UbloxCellularBase::sim_pin_check_enable(bool enableNotDisable) |
RobMeades | 0:5cffef3371f6 | 1006 | { |
RobMeades | 0:5cffef3371f6 | 1007 | bool success = false;; |
RobMeades | 0:5cffef3371f6 | 1008 | LOCK(); |
RobMeades | 0:5cffef3371f6 | 1009 | |
RobMeades | 0:5cffef3371f6 | 1010 | MBED_ASSERT(_at != NULL); |
RobMeades | 0:5cffef3371f6 | 1011 | |
RobMeades | 0:5cffef3371f6 | 1012 | if (_pin != NULL) { |
RobMeades | 0:5cffef3371f6 | 1013 | if (_sim_pin_check_enabled && !enableNotDisable) { |
RobMeades | 0:5cffef3371f6 | 1014 | // Disable the SIM lock |
RobMeades | 0:5cffef3371f6 | 1015 | if (_at->send("AT+CLCK=\"SC\",0,\"%s\"", _pin) && _at->recv("OK")) { |
RobMeades | 0:5cffef3371f6 | 1016 | _sim_pin_check_enabled = false; |
RobMeades | 0:5cffef3371f6 | 1017 | success = true; |
RobMeades | 0:5cffef3371f6 | 1018 | } |
RobMeades | 0:5cffef3371f6 | 1019 | } else if (!_sim_pin_check_enabled && enableNotDisable) { |
RobMeades | 0:5cffef3371f6 | 1020 | // Enable the SIM lock |
RobMeades | 0:5cffef3371f6 | 1021 | if (_at->send("AT+CLCK=\"SC\",1,\"%s\"", _pin) && _at->recv("OK")) { |
RobMeades | 0:5cffef3371f6 | 1022 | _sim_pin_check_enabled = true; |
RobMeades | 0:5cffef3371f6 | 1023 | success = true; |
RobMeades | 0:5cffef3371f6 | 1024 | } |
RobMeades | 0:5cffef3371f6 | 1025 | } else { |
RobMeades | 0:5cffef3371f6 | 1026 | success = true; |
RobMeades | 0:5cffef3371f6 | 1027 | } |
RobMeades | 0:5cffef3371f6 | 1028 | } |
RobMeades | 0:5cffef3371f6 | 1029 | |
RobMeades | 0:5cffef3371f6 | 1030 | UNLOCK(); |
RobMeades | 0:5cffef3371f6 | 1031 | return success; |
RobMeades | 0:5cffef3371f6 | 1032 | } |
RobMeades | 0:5cffef3371f6 | 1033 | |
RobMeades | 0:5cffef3371f6 | 1034 | // Change the pin code for the SIM card. |
RobMeades | 0:5cffef3371f6 | 1035 | bool UbloxCellularBase::change_sim_pin(const char *pin) |
RobMeades | 0:5cffef3371f6 | 1036 | { |
RobMeades | 0:5cffef3371f6 | 1037 | bool success = false;; |
RobMeades | 0:5cffef3371f6 | 1038 | LOCK(); |
RobMeades | 0:5cffef3371f6 | 1039 | |
RobMeades | 0:5cffef3371f6 | 1040 | MBED_ASSERT(_at != NULL); |
RobMeades | 0:5cffef3371f6 | 1041 | |
RobMeades | 0:5cffef3371f6 | 1042 | // Change the SIM pin |
RobMeades | 0:5cffef3371f6 | 1043 | if ((pin != NULL) && (_pin != NULL)) { |
RobMeades | 0:5cffef3371f6 | 1044 | if (_at->send("AT+CPWD=\"SC\",\"%s\",\"%s\"", _pin, pin) && _at->recv("OK")) { |
RobMeades | 0:5cffef3371f6 | 1045 | _pin = pin; |
RobMeades | 0:5cffef3371f6 | 1046 | success = true; |
RobMeades | 0:5cffef3371f6 | 1047 | } |
RobMeades | 0:5cffef3371f6 | 1048 | } |
RobMeades | 0:5cffef3371f6 | 1049 | |
RobMeades | 0:5cffef3371f6 | 1050 | UNLOCK(); |
RobMeades | 0:5cffef3371f6 | 1051 | return success; |
RobMeades | 0:5cffef3371f6 | 1052 | } |
RobMeades | 0:5cffef3371f6 | 1053 | |
RobMeades | 14:e420232ee4e7 | 1054 | // Get the IMEI. |
fahim alavi |
13:158a035b1b50 | 1055 | bool UbloxCellularBase::get_imei(char *imei_to_send, int size) |
fahim alavi |
13:158a035b1b50 | 1056 | { |
fahim alavi |
13:158a035b1b50 | 1057 | bool success; |
fahim alavi |
13:158a035b1b50 | 1058 | LOCK(); |
fahim alavi |
13:158a035b1b50 | 1059 | |
fahim alavi |
13:158a035b1b50 | 1060 | MBED_ASSERT(_at != NULL); |
fahim alavi |
13:158a035b1b50 | 1061 | |
fahim alavi |
13:158a035b1b50 | 1062 | // International mobile equipment identifier |
fahim alavi |
13:158a035b1b50 | 1063 | // AT Command Manual UBX-13002752, section 4.7 |
fahim alavi |
13:158a035b1b50 | 1064 | success = _at->send("AT+CGSN") && _at->recv("%15[^\n]\nOK\n", _dev_info.imei); |
fahim alavi |
13:158a035b1b50 | 1065 | tr_info("DevInfo: IMEI=%s", _dev_info.imei); |
fahim alavi |
13:158a035b1b50 | 1066 | |
fahim alavi |
13:158a035b1b50 | 1067 | if (success) { |
fahim alavi |
13:158a035b1b50 | 1068 | memcpy(imei_to_send,_dev_info.imei,size); |
fahim alavi |
13:158a035b1b50 | 1069 | imei_to_send[size-1] = '\0'; |
fahim alavi |
13:158a035b1b50 | 1070 | } |
fahim alavi |
13:158a035b1b50 | 1071 | |
fahim alavi |
13:158a035b1b50 | 1072 | UNLOCK(); |
fahim alavi |
13:158a035b1b50 | 1073 | return success; |
fahim alavi |
13:158a035b1b50 | 1074 | } |
fahim alavi |
13:158a035b1b50 | 1075 | |
RobMeades | 14:e420232ee4e7 | 1076 | // Get the IMEI of the module. |
RobMeades | 14:e420232ee4e7 | 1077 | const char *UbloxCellularBase::imei() |
RobMeades | 14:e420232ee4e7 | 1078 | { |
RobMeades | 14:e420232ee4e7 | 1079 | return _dev_info.imei; |
RobMeades | 14:e420232ee4e7 | 1080 | } |
RobMeades | 14:e420232ee4e7 | 1081 | |
RobMeades | 14:e420232ee4e7 | 1082 | // Get the Mobile Equipment ID (which may be the same as the IMEI). |
RobMeades | 14:e420232ee4e7 | 1083 | const char *UbloxCellularBase::meid() |
RobMeades | 14:e420232ee4e7 | 1084 | { |
RobMeades | 14:e420232ee4e7 | 1085 | return _dev_info.meid; |
RobMeades | 14:e420232ee4e7 | 1086 | } |
RobMeades | 14:e420232ee4e7 | 1087 | |
RobMeades | 14:e420232ee4e7 | 1088 | // Get the IMSI of the SIM. |
RobMeades | 14:e420232ee4e7 | 1089 | const char *UbloxCellularBase::imsi() |
RobMeades | 14:e420232ee4e7 | 1090 | { |
RobMeades | 14:e420232ee4e7 | 1091 | // (try) to update the IMSI, just in case the SIM has changed |
RobMeades | 14:e420232ee4e7 | 1092 | get_imsi(); |
RobMeades | 14:e420232ee4e7 | 1093 | |
RobMeades | 14:e420232ee4e7 | 1094 | return _dev_info.imsi; |
RobMeades | 14:e420232ee4e7 | 1095 | } |
RobMeades | 14:e420232ee4e7 | 1096 | |
RobMeades | 14:e420232ee4e7 | 1097 | // Get the ICCID of the SIM. |
RobMeades | 14:e420232ee4e7 | 1098 | const char *UbloxCellularBase::iccid() |
RobMeades | 14:e420232ee4e7 | 1099 | { |
RobMeades | 14:e420232ee4e7 | 1100 | // (try) to update the ICCID, just in case the SIM has changed |
RobMeades | 14:e420232ee4e7 | 1101 | get_iccid(); |
RobMeades | 14:e420232ee4e7 | 1102 | |
RobMeades | 14:e420232ee4e7 | 1103 | return _dev_info.iccid; |
RobMeades | 14:e420232ee4e7 | 1104 | } |
RobMeades | 14:e420232ee4e7 | 1105 | |
RobMeades | 14:e420232ee4e7 | 1106 | // Get the RSSI in dBm. |
RobMeades | 14:e420232ee4e7 | 1107 | int UbloxCellularBase::rssi() |
RobMeades | 14:e420232ee4e7 | 1108 | { |
RobMeades | 14:e420232ee4e7 | 1109 | char buf[7] = {0}; |
RobMeades | 14:e420232ee4e7 | 1110 | int rssi = 0; |
RobMeades | 14:e420232ee4e7 | 1111 | int qual = 0; |
RobMeades | 14:e420232ee4e7 | 1112 | int rssiRet = 0; |
RobMeades | 14:e420232ee4e7 | 1113 | bool success; |
RobMeades | 14:e420232ee4e7 | 1114 | LOCK(); |
RobMeades | 14:e420232ee4e7 | 1115 | |
RobMeades | 14:e420232ee4e7 | 1116 | MBED_ASSERT(_at != NULL); |
RobMeades | 14:e420232ee4e7 | 1117 | |
RobMeades | 14:e420232ee4e7 | 1118 | success = _at->send("AT+CSQ") && _at->recv("+CSQ: %6[^\n]\nOK\n", buf); |
RobMeades | 14:e420232ee4e7 | 1119 | |
RobMeades | 14:e420232ee4e7 | 1120 | if (success) { |
RobMeades | 14:e420232ee4e7 | 1121 | if (sscanf(buf, "%d,%d", &rssi, &qual) == 2) { |
RobMeades | 14:e420232ee4e7 | 1122 | // AT+CSQ returns a coded RSSI value and an RxQual value |
RobMeades | 14:e420232ee4e7 | 1123 | // For 2G an RSSI of 0 corresponds to -113 dBm or less, |
RobMeades | 14:e420232ee4e7 | 1124 | // an RSSI of 31 corresponds to -51 dBm or less and hence |
RobMeades | 14:e420232ee4e7 | 1125 | // each value is a 2 dB step. |
RobMeades | 14:e420232ee4e7 | 1126 | // For LTE the mapping is defined in the array rssiConvertLte[]. |
RobMeades | 14:e420232ee4e7 | 1127 | // For 3G the mapping to RSCP is defined in the array rscpConvert3G[] |
RobMeades | 14:e420232ee4e7 | 1128 | // and the RSSI value is then RSCP - the EC_NO_LEV number derived |
RobMeades | 14:e420232ee4e7 | 1129 | // by putting the qual number through qualConvert3G[]. |
RobMeades | 14:e420232ee4e7 | 1130 | if ((rssi >= 0) && (rssi <= 31)) { |
RobMeades | 14:e420232ee4e7 | 1131 | switch (_dev_info.rat) { |
RobMeades | 14:e420232ee4e7 | 1132 | case UTRAN: |
RobMeades | 14:e420232ee4e7 | 1133 | case HSDPA: |
RobMeades | 14:e420232ee4e7 | 1134 | case HSUPA: |
RobMeades | 14:e420232ee4e7 | 1135 | case HSDPA_HSUPA: |
RobMeades | 14:e420232ee4e7 | 1136 | // 3G |
RobMeades | 14:e420232ee4e7 | 1137 | if ((qual >= 0) && (qual <= 7)) { |
RobMeades | 14:e420232ee4e7 | 1138 | qual = qualConvert3G[qual]; |
fahim.alavi@u-blox.com | 15:93b157a47b8d | 1139 | rssiRet = rscpConvert3G[rssi]; |
fahim.alavi@u-blox.com | 15:93b157a47b8d | 1140 | rssiRet -= qual; |
RobMeades | 14:e420232ee4e7 | 1141 | } |
fahim.alavi@u-blox.com | 15:93b157a47b8d | 1142 | |
RobMeades | 14:e420232ee4e7 | 1143 | break; |
RobMeades | 14:e420232ee4e7 | 1144 | case LTE: |
RobMeades | 14:e420232ee4e7 | 1145 | // LTE |
RobMeades | 14:e420232ee4e7 | 1146 | rssiRet = rssiConvertLte[rssi]; |
RobMeades | 14:e420232ee4e7 | 1147 | break; |
RobMeades | 14:e420232ee4e7 | 1148 | case GSM: |
RobMeades | 14:e420232ee4e7 | 1149 | case COMPACT_GSM: |
RobMeades | 14:e420232ee4e7 | 1150 | case EDGE: |
RobMeades | 14:e420232ee4e7 | 1151 | default: |
RobMeades | 14:e420232ee4e7 | 1152 | // GSM or assumed GSM if the RAT is not known |
RobMeades | 14:e420232ee4e7 | 1153 | rssiRet = -(113 - (rssi << 2)); |
RobMeades | 14:e420232ee4e7 | 1154 | break; |
RobMeades | 14:e420232ee4e7 | 1155 | } |
RobMeades | 14:e420232ee4e7 | 1156 | } |
RobMeades | 14:e420232ee4e7 | 1157 | } |
RobMeades | 14:e420232ee4e7 | 1158 | } |
RobMeades | 14:e420232ee4e7 | 1159 | |
RobMeades | 14:e420232ee4e7 | 1160 | UNLOCK(); |
RobMeades | 14:e420232ee4e7 | 1161 | return rssiRet; |
RobMeades | 14:e420232ee4e7 | 1162 | } |
RobMeades | 14:e420232ee4e7 | 1163 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1164 | //RAT should be set in a detached state (AT+COPS=2) |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1165 | bool UbloxCellularBase::set_modem_rat(RAT selected_rat, RAT preferred_rat, RAT second_preferred_rat) |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1166 | { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1167 | bool success = false; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1168 | char command[16] = {0x00}; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1169 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1170 | //check if modem is registered with network |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1171 | if (is_registered_csd() || is_registered_psd() || is_registered_eps()) { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1172 | tr_error("RAT should only be set in detached state"); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1173 | return false; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1174 | } |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1175 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1176 | if (preferred_rat != NOT_USED && second_preferred_rat != NOT_USED) { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1177 | sprintf(command, "AT+URAT=%d,%d,%d", selected_rat, preferred_rat, second_preferred_rat); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1178 | } else if (preferred_rat != NOT_USED) { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1179 | sprintf(command, "AT+URAT=%d,%d", selected_rat, preferred_rat); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1180 | } else if (second_preferred_rat != NOT_USED) { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1181 | sprintf(command, "AT+URAT=%d,%d", selected_rat, second_preferred_rat); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1182 | } else { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1183 | sprintf(command, "AT+URAT=%d", selected_rat); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1184 | } |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1185 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1186 | LOCK(); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1187 | if (_at->send(command) && _at->recv("OK")) { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1188 | success = true; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1189 | } else { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1190 | tr_error("unable to set the specified RAT"); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1191 | success = false; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1192 | } |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1193 | UNLOCK(); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1194 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1195 | return success; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1196 | } |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1197 | |
wajahat.abbas@u-blox.com | 22:779971811c46 | 1198 | bool UbloxCellularBase::get_modem_rat(int *selected_rat, int *preferred_rat, int *second_preferred_rat) |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1199 | { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1200 | bool success = false; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1201 | char buf[24] = {0x00}; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1202 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1203 | if (selected_rat == NULL || preferred_rat == NULL || second_preferred_rat == NULL) { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1204 | tr_info("invalid pointers"); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1205 | return false; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1206 | } |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1207 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1208 | MBED_ASSERT(_at != NULL); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1209 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1210 | *selected_rat = NOT_USED; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1211 | *preferred_rat = NOT_USED; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1212 | *second_preferred_rat = NOT_USED; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1213 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1214 | LOCK(); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1215 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1216 | if (_at->send("AT+URAT?") && _at->recv("%23[^\n]\nOK\n", buf)) { |
wajahat.abbas@u-blox.com | 22:779971811c46 | 1217 | if (sscanf(buf, "+URAT: %d,%d,%d", selected_rat, preferred_rat, second_preferred_rat) == 3) { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1218 | success = true; |
wajahat.abbas@u-blox.com | 22:779971811c46 | 1219 | } else if (sscanf(buf, "+URAT: %d,%d", selected_rat, preferred_rat) == 2) { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1220 | success = true; |
wajahat.abbas@u-blox.com | 22:779971811c46 | 1221 | } else if (sscanf(buf, "+URAT: %d", selected_rat) == 1) { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1222 | success = true; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1223 | } |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1224 | } |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1225 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1226 | UNLOCK(); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1227 | return success; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1228 | } |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1229 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1230 | //application should call init() or connect() in order to initialize the modem |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1231 | bool UbloxCellularBase::reboot_modem() |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1232 | { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1233 | return (set_functionality_mode(FUNC_RESET)); |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1234 | } |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1235 | |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1236 | bool UbloxCellularBase::set_functionality_mode(FunctionalityMode mode) |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1237 | { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1238 | bool return_val = false; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1239 | int at_timeout; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1240 | LOCK(); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1241 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1242 | MBED_ASSERT(_at != NULL); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1243 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1244 | at_timeout = _at_timeout; // Has to be inside LOCK()s |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1245 | at_set_timeout(3*60*1000); //command has 3 minutes timeout |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1246 | |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1247 | if (_at->send("AT+CFUN=%d", mode) && _at->recv("OK")) { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1248 | return_val = true; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1249 | } |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1250 | |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1251 | if (mode == FUNC_RESET || mode == FUNC_RESET_WITH_SIM) { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1252 | _modem_initialised = false; |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1253 | } |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1254 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1255 | at_set_timeout(at_timeout); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1256 | UNLOCK(); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1257 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1258 | return return_val; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1259 | } |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1260 | |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1261 | bool UbloxCellularBase::get_functionality_mode(int *mode) |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1262 | { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1263 | bool return_val = false; |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1264 | |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1265 | if (mode == NULL) { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1266 | return false; |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1267 | } |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1268 | |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1269 | LOCK(); |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1270 | MBED_ASSERT(_at != NULL); |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1271 | |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1272 | if ( (_at->send("AT+CFUN?") && _at->recv("+CFUN: %d", mode) && _at->recv("OK")) ) { |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1273 | return_val = true; |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1274 | } |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1275 | |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1276 | UNLOCK(); |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1277 | return return_val; |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1278 | } |
wajahat.abbas@u-blox.com | 24:e26a6ab0dd75 | 1279 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1280 | #ifdef TARGET_UBLOX_C030_R41XM |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1281 | bool UbloxCellularBase::set_mno_profile(MNOProfile profile) |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1282 | { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1283 | bool return_val = false; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1284 | int current_profile; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1285 | MNOProfile arr[MAX_NUM_PROFILES] = { SW_DEFAULT, SIM_ICCID, ATT, TMO, VODAFONE, DT, STANDARD_EU |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1286 | #ifdef TARGET_UBLOX_C030_R410M |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1287 | , VERIZON, TELSTRA, CT, SPRINT, TELUS |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1288 | #endif |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1289 | }; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1290 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1291 | if (is_registered_csd() || is_registered_psd() || is_registered_eps()) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1292 | tr_error("MNO profile should only be set in detached state"); |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1293 | return false; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1294 | } |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1295 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1296 | if (get_mno_profile(¤t_profile)) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1297 | if (current_profile == profile) { //Ref to UBX-18019856 7.1.7, parameters will be updated only if we switch to another profile first |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1298 | for (uint8_t index = 0; index < MAX_NUM_PROFILES; index++) { //get the index of current profile and use the next one |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1299 | if (arr[index] == current_profile) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1300 | index = ((index + 1) % MAX_NUM_PROFILES); |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1301 | current_profile = arr[index]; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1302 | break; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1303 | } |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1304 | } |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1305 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1306 | LOCK(); |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1307 | if (_at->send("AT+UMNOPROF=%d", current_profile) && _at->recv("OK")) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1308 | tr_error("temporary MNO profile set: %d", current_profile); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1309 | } |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1310 | UNLOCK(); |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1311 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1312 | LOCK(); |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1313 | if (_at->send("AT+UMNOPROF=%d", profile) && _at->recv("OK")) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1314 | return_val = true; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1315 | } else { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1316 | tr_error("unable to set user specified profile"); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1317 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1318 | UNLOCK(); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1319 | } else { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1320 | tr_error("could not read MNO profile"); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1321 | } |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1322 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1323 | return return_val; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1324 | } |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1325 | |
wajahat.abbas@u-blox.com | 22:779971811c46 | 1326 | bool UbloxCellularBase::get_mno_profile(int *profile) |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1327 | { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1328 | bool return_val = false; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1329 | char buf[4] = {0x00}; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1330 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1331 | if (profile == NULL) { |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1332 | return false; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1333 | } |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1334 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1335 | LOCK(); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1336 | MBED_ASSERT(_at != NULL); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1337 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1338 | if (_at->send("AT+UMNOPROF?") && _at->recv("+UMNOPROF: %3[^\n]\nOK\n", buf)) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1339 | *profile = atoi(buf); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1340 | return_val = true; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1341 | } |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1342 | |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1343 | UNLOCK(); |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1344 | return return_val; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1345 | } |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1346 | // Enable or Disable the UPSV power saving mode |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1347 | bool UbloxCellularBase::set_idle_mode(bool enable) |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1348 | { |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1349 | #ifdef TARGET_UBLOX_C030_R412M |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1350 | if (_psm_status == true && enable == true) { |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1351 | return false; |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1352 | } |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1353 | #endif |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1354 | |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1355 | bool success = false; |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1356 | LOCK(); |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1357 | |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1358 | MBED_ASSERT(_at != NULL); |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1359 | |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1360 | if (_at->send("AT+UPSV=%d", enable ? 4 : 0) && _at->recv("OK")) { |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1361 | if (enable == true) { |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1362 | _at->idle_mode_enabled(); |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1363 | } |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1364 | else { |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1365 | _at->idle_mode_disabled(); |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1366 | } |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1367 | success = true; |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1368 | } |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1369 | |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1370 | UNLOCK(); |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1371 | return success; |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1372 | } |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1373 | |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1374 | bool UbloxCellularBase::get_idle_mode(int *status) |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1375 | { |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1376 | bool return_val = false; |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1377 | |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1378 | if (status == NULL) { |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1379 | return false; |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1380 | } |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1381 | |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1382 | LOCK(); |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1383 | MBED_ASSERT(_at != NULL); |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1384 | |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1385 | if ( (_at->send("AT+UPSV?") && _at->recv("+UPSV: %d", status) && _at->recv("OK")) ) { |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1386 | if (*status == 4) { |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1387 | *status = 1; |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1388 | } |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1389 | return_val = true; |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1390 | } |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1391 | |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1392 | UNLOCK(); |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1393 | return return_val; |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1394 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1395 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1396 | int UbloxCellularBase::set_receive_period(int mode, tEDRXAccessTechnology act_type, uint8_t edrx_value) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1397 | char edrx[5]; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1398 | uint_to_binary_str(edrx_value, edrx, 5, 4); |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1399 | edrx[4] = '\0'; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1400 | int status = 1; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1401 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1402 | LOCK(); |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1403 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1404 | if (_at->send("AT+CEDRXS=%d,%d,\"%s\"", mode, act_type, edrx) && _at->recv("OK")) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1405 | _edrx_configured = true; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1406 | status = 0; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1407 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1408 | else { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1409 | status = 1; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1410 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1411 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1412 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1413 | UNLOCK(); |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1414 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1415 | return status; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1416 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1417 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1418 | int UbloxCellularBase::set_receive_period(int mode, tEDRXAccessTechnology act_type) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1419 | int status = 1; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1420 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1421 | LOCK(); |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1422 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1423 | if (_at->send("AT+CEDRXS=%d,%d", mode, act_type) && _at->recv("OK")) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1424 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1425 | status = 0; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1426 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1427 | else { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1428 | status = 1; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1429 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1430 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1431 | UNLOCK(); |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1432 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1433 | return status; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1434 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1435 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1436 | int UbloxCellularBase::set_receive_period(int mode) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1437 | int status = 1; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1438 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1439 | LOCK(); |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1440 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1441 | if (_at->send("AT+CEDRXS=%d", mode) && _at->recv("OK")) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1442 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1443 | status = 0; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1444 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1445 | else { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1446 | status = 1; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1447 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1448 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1449 | UNLOCK(); |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1450 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1451 | return status; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1452 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1453 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1454 | uint32_t UbloxCellularBase::get_receive_period() { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1455 | uint32_t edrx_value = 2; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1456 | char buf[24] = {0x00}; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1457 | char edrx_val[5]; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1458 | tEDRXAccessTechnology act_type; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1459 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1460 | LOCK(); |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1461 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1462 | if (_at->send("AT+CEDRXS?") && _at->recv("%23[^\n]\nOK\n", buf)) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1463 | if (sscanf(buf, "+CEDRXS: %d,\"%s\"", (int *)&act_type, edrx_val) == 2) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1464 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1465 | edrx_value = binary_str_to_uint(edrx_val,4); |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1466 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1467 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1468 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1469 | if (_at->send("AT+CEDRXRDP") && _at->recv("OK")) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1470 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1471 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1472 | tr_info("edrx_value. %d", edrx_value); |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1473 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1474 | UNLOCK(); |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1475 | return edrx_value; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1476 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1477 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1478 | void UbloxCellularBase::uint_to_binary_str(uint32_t num, char* str, int str_size, int bit_cnt) |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1479 | { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1480 | if (!str || str_size < bit_cnt) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1481 | return; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1482 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1483 | int tmp, pos = 0; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1484 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1485 | for (int i = 31; i >= 0; i--) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1486 | tmp = num >> i; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1487 | if (i < bit_cnt) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1488 | if (tmp&1) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1489 | str[pos] = 1 + '0'; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1490 | } else { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1491 | str[pos] = 0 + '0'; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1492 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1493 | pos++; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1494 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1495 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1496 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1497 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1498 | uint32_t UbloxCellularBase::binary_str_to_uint(const char *binary_string, int binary_string_length) |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1499 | { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1500 | if (!binary_string || !binary_string_length) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1501 | return 0; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1502 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1503 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1504 | int integer_output = 0, base_exp = 1; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1505 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1506 | for (int i = binary_string_length - 1; i >= 0; i--) { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1507 | if (binary_string[i] == '1') { |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1508 | integer_output += (base_exp << (binary_string_length - (i+1))); |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1509 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1510 | } |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1511 | |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1512 | return integer_output; |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1513 | } |
fahimalavi | 30:38230504a646 | 1514 | |
fahimalavi | 30:38230504a646 | 1515 | bool UbloxCellularBase::set_band_bitmask(RAT rat, uint64_t bitmask) { |
fahimalavi | 30:38230504a646 | 1516 | |
fahimalavi | 30:38230504a646 | 1517 | bool status = false; |
fahimalavi | 30:38230504a646 | 1518 | UBandmaskRAT eBandMastRat; |
fahimalavi | 30:38230504a646 | 1519 | |
fahimalavi | 30:38230504a646 | 1520 | if(rat == LTE_CATM1) { |
fahimalavi | 30:38230504a646 | 1521 | eBandMastRat = UBANDMASK_RAT_LTE_CATM1; |
fahimalavi | 30:38230504a646 | 1522 | } |
fahimalavi | 30:38230504a646 | 1523 | else if(rat == LTE_CATNB1) { |
fahimalavi | 30:38230504a646 | 1524 | eBandMastRat = UBANDMASK_RAT_LTE_CATNB1; |
fahimalavi | 30:38230504a646 | 1525 | } |
fahimalavi | 30:38230504a646 | 1526 | else { |
fahimalavi | 30:38230504a646 | 1527 | tr_error("Invalid RAT for Band mask selection: %d", rat); |
fahimalavi | 30:38230504a646 | 1528 | |
fahimalavi | 30:38230504a646 | 1529 | return false; |
fahimalavi | 30:38230504a646 | 1530 | } |
fahimalavi | 30:38230504a646 | 1531 | |
fahimalavi | 30:38230504a646 | 1532 | tr_info("UBANDMASK RAT %d, bitmask : %llu", eBandMastRat, bitmask); |
fahimalavi | 30:38230504a646 | 1533 | |
fahimalavi | 30:38230504a646 | 1534 | LOCK(); |
fahimalavi | 30:38230504a646 | 1535 | |
fahimalavi | 30:38230504a646 | 1536 | if (_at->send("AT+UBANDMASK=%d,%llu", eBandMastRat, bitmask) && _at->recv("OK")) { |
fahimalavi | 30:38230504a646 | 1537 | |
fahimalavi | 30:38230504a646 | 1538 | status = true; |
fahimalavi | 30:38230504a646 | 1539 | } |
fahimalavi | 30:38230504a646 | 1540 | UNLOCK(); |
fahimalavi | 30:38230504a646 | 1541 | |
fahimalavi | 30:38230504a646 | 1542 | return status; |
fahimalavi | 30:38230504a646 | 1543 | } |
fahimalavi | 30:38230504a646 | 1544 | #endif //TARGET_UBLOX_C030_R41XM |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1545 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1546 | #ifdef TARGET_UBLOX_C030_R412M |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1547 | bool UbloxCellularBase::get_power_saving_mode(int *status, int *periodic_time, int *active_time) |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1548 | { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1549 | char pt_encoded[8+1];// timer value encoded as 3GPP IE |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1550 | char at_encoded[8+1];// timer value encoded as 3GPP IE |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1551 | int value, multiplier; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1552 | bool return_val; |
wajahat.abbas@u-blox.com | 20:31d5e048fbfa | 1553 | |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1554 | if (status == NULL || periodic_time == NULL || active_time == NULL) { |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1555 | return false; |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1556 | } |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1557 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1558 | LOCK(); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1559 | //+UCPSMS:1,,,"01000011","01000011" |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1560 | if (_at->send("AT+UCPSMS?") && _at->recv("+UCPSMS:%d,,,\"%8c\",\"%8c\"\n", status, pt_encoded, at_encoded)) { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1561 | if (*status == true) { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1562 | //PSM is enabled, decode the timer values, periodic TAU first |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1563 | value = (pt_encoded[7]- '0'); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1564 | value += (pt_encoded[6]- '0') << 1; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1565 | value += (pt_encoded[5]- '0') << 2; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1566 | value += (pt_encoded[4]- '0') << 3; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1567 | value += (pt_encoded[3]- '0') << 4; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1568 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1569 | multiplier = (pt_encoded[2]- '0'); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1570 | multiplier += (pt_encoded[1]- '0') << 1; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1571 | multiplier += (pt_encoded[0]- '0') << 2; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1572 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1573 | switch(multiplier) { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1574 | //10 minutes |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1575 | case 0: |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1576 | value = value*10*60; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1577 | break; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1578 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1579 | //1 hour |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1580 | case 1: |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1581 | value = value*60*60; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1582 | break; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1583 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1584 | //10 hours |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1585 | case 2: |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1586 | value = value*10*60*60; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1587 | break; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1588 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1589 | //2 seconds |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1590 | case 3: |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1591 | value = value*2; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1592 | break; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1593 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1594 | //30 seconds |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1595 | case 4: |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1596 | value = value*30; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1597 | break; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1598 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1599 | //1 minute |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1600 | case 5: |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1601 | value = value*60; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1602 | break; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1603 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1604 | //320 hours |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1605 | case 6: |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1606 | value = value*320*60*60; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1607 | break; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1608 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1609 | default: |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1610 | value = 0; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1611 | break; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1612 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1613 | *periodic_time = value; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1614 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1615 | //decode the active time |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1616 | value = (at_encoded[7]- '0'); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1617 | value += (at_encoded[6]- '0') << 1; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1618 | value += (at_encoded[5]- '0') << 2; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1619 | value += (at_encoded[4]- '0') << 3; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1620 | value += (at_encoded[3]- '0') << 4; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1621 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1622 | multiplier = (at_encoded[2]- '0'); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1623 | multiplier += (at_encoded[1]- '0') << 1; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1624 | multiplier += (at_encoded[0]- '0') << 2; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1625 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1626 | switch(multiplier) { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1627 | //2 seconds |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1628 | case 0: |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1629 | value = value*2; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1630 | break; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1631 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1632 | //1 minute |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1633 | case 1: |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1634 | value = value*60; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1635 | break; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1636 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1637 | //decihours (6minutes) |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1638 | case 2: |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1639 | value = value*6*60; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1640 | break; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1641 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1642 | default: |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1643 | value = 0; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1644 | break; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1645 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1646 | *active_time = value; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1647 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1648 | return_val = true; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1649 | } else { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1650 | return_val = false; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1651 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1652 | UNLOCK(); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1653 | return return_val; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1654 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1655 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1656 | bool UbloxCellularBase::set_power_saving_mode(int periodic_time, int active_time) |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1657 | { |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1658 | if (_at->is_idle_mode_enabled() == true && periodic_time != 0 && active_time != 0 ) { |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1659 | return false; |
wajahat.abbas@u-blox.com | 25:e67d3d9d2e7e | 1660 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1661 | bool return_val = false; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1662 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1663 | LOCK(); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1664 | int at_timeout = _at_timeout; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1665 | at_set_timeout(10000); //AT+CPSMS has response time of < 10s |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1666 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1667 | //check if modem supports PSM URCs |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1668 | if (_at->send("AT+UPSMR?") && _at->recv("OK")) { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1669 | if (periodic_time == 0 && active_time == 0) { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1670 | // disable PSM |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1671 | if (_at->send("AT+CPSMS=0") && _at->recv("OK")) { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1672 | if (_at->send("AT+UPSMR=0") && _at->recv("OK")) {//disable the URC |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1673 | //de-register the callback |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1674 | detach_cb_psm_going_in(); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1675 | detach_cb_psm_coming_out(); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1676 | _psm_status = false; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1677 | return_val = true; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1678 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1679 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1680 | } else { //PSM string encoding code borrowed from AT_CellularPower.cpp |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1681 | /** |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1682 | Table 10.5.163a/3GPP TS 24.008: GPRS Timer 3 information element |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1683 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1684 | Bits 5 to 1 represent the binary coded timer value. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1685 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1686 | Bits 6 to 8 defines the timer value unit for the GPRS timer as follows: |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1687 | 8 7 6 |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1688 | 0 0 0 value is incremented in multiples of 10 minutes |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1689 | 0 0 1 value is incremented in multiples of 1 hour |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1690 | 0 1 0 value is incremented in multiples of 10 hours |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1691 | 0 1 1 value is incremented in multiples of 2 seconds |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1692 | 1 0 0 value is incremented in multiples of 30 seconds |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1693 | 1 0 1 value is incremented in multiples of 1 minute |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1694 | 1 1 0 value is incremented in multiples of 320 hours (NOTE 1) |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1695 | 1 1 1 value indicates that the timer is deactivated (NOTE 2). |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1696 | */ |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1697 | char pt[8+1];// timer value encoded as 3GPP IE |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1698 | const int ie_value_max = 0x1f; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1699 | uint32_t periodic_timer = 0; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1700 | if (periodic_time <= 2*ie_value_max) { // multiples of 2 seconds |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1701 | periodic_timer = periodic_time/2; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1702 | strcpy(pt, "01100000"); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1703 | } else { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1704 | if (periodic_time <= 30*ie_value_max) { // multiples of 30 seconds |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1705 | periodic_timer = periodic_time/30; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1706 | strcpy(pt, "10000000"); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1707 | } else { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1708 | if (periodic_time <= 60*ie_value_max) { // multiples of 1 minute |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1709 | periodic_timer = periodic_time/60; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1710 | strcpy(pt, "10100000"); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1711 | } else { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1712 | if (periodic_time <= 10*60*ie_value_max) { // multiples of 10 minutes |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1713 | periodic_timer = periodic_time/(10*60); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1714 | strcpy(pt, "00000000"); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1715 | } else { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1716 | if (periodic_time <= 60*60*ie_value_max) { // multiples of 1 hour |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1717 | periodic_timer = periodic_time/(60*60); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1718 | strcpy(pt, "00100000"); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1719 | } else { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1720 | if (periodic_time <= 10*60*60*ie_value_max) { // multiples of 10 hours |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1721 | periodic_timer = periodic_time/(10*60*60); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1722 | strcpy(pt, "01000000"); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1723 | } else { // multiples of 320 hours |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1724 | int t = periodic_time / (320*60*60); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1725 | if (t > ie_value_max) { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1726 | t = ie_value_max; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1727 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1728 | periodic_timer = t; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1729 | strcpy(pt, "11000000"); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1730 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1731 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1732 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1733 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1734 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1735 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1736 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1737 | uint_to_binary_str(periodic_timer, &pt[3], sizeof(pt)-3, 5); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1738 | pt[8] = '\0'; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1739 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1740 | /** |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1741 | Table 10.5.172/3GPP TS 24.008: GPRS Timer information element |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1742 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1743 | Bits 5 to 1 represent the binary coded timer value. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1744 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1745 | Bits 6 to 8 defines the timer value unit for the GPRS timer as follows: |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1746 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1747 | 8 7 6 |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1748 | 0 0 0 value is incremented in multiples of 2 seconds |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1749 | 0 0 1 value is incremented in multiples of 1 minute |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1750 | 0 1 0 value is incremented in multiples of decihours |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1751 | 1 1 1 value indicates that the timer is deactivated. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1752 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1753 | Other values shall be interpreted as multiples of 1 minute in this version of the protocol. |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1754 | */ |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1755 | char at[8+1]; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1756 | uint32_t active_timer; // timer value encoded as 3GPP IE |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1757 | if (active_time <= 2*ie_value_max) { // multiples of 2 seconds |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1758 | active_timer = active_time/2; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1759 | strcpy(at, "00000000"); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1760 | } else { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1761 | if (active_time <= 60*ie_value_max) { // multiples of 1 minute |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1762 | active_timer = (1<<5) | (active_time/60); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1763 | strcpy(at, "00100000"); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1764 | } else { // multiples of decihours |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1765 | int t = active_time / (6*60); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1766 | if (t > ie_value_max) { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1767 | t = ie_value_max; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1768 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1769 | active_timer = t; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1770 | strcpy(at, "01000000"); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1771 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1772 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1773 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1774 | uint_to_binary_str(active_timer, &at[3], sizeof(at)-3, 5); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1775 | at[8] = '\0'; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1776 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1777 | if (_at->send("AT+CPSMS=1,,,\"%s\",\"%s\"", pt, at) && _at->recv("OK")) { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1778 | if (_at->send("AT+UPSMR=1") && _at->recv("OK")) {//enable the PSM URC |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1779 | tr_info("PSM enabled successfully!"); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1780 | _psm_status = true; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1781 | return_val = true; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1782 | } else { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1783 | tr_error("PSM URCs not supported"); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1784 | return_val = false; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1785 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1786 | } else { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1787 | tr_error("+CPSMS command failed"); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1788 | return_val = false; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1789 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1790 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1791 | } else { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1792 | tr_error("PSM URCs not supported by this version of modem"); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1793 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1794 | at_set_timeout(at_timeout); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1795 | UNLOCK(); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1796 | return return_val; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1797 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1798 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1799 | bool UbloxCellularBase::is_modem_awake() |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1800 | { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1801 | return (_dev_info.modem_psm_state == AWAKE); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1802 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1803 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1804 | //application should call init() or connect() in order to initialize the modem |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1805 | void UbloxCellularBase::wakeup_modem() |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1806 | { |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1807 | LOCK(); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1808 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1809 | MBED_ASSERT(_at != NULL); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1810 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1811 | tr_info("Waking up modem..."); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1812 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1813 | modem_power_up(); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1814 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1815 | _dev_info.reg_status_csd = CSD_NOT_REGISTERED_NOT_SEARCHING; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1816 | _dev_info.reg_status_psd = PSD_NOT_REGISTERED_NOT_SEARCHING; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1817 | _dev_info.reg_status_eps = EPS_NOT_REGISTERED_NOT_SEARCHING; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1818 | _modem_initialised = false; |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1819 | |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1820 | UNLOCK(); |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1821 | } |
wajahat.abbas@u-blox.com | 23:eaab8e812a5d | 1822 | #endif |
wajahat.abbas@u-blox.com | 29:8a38f91009ad | 1823 | |
RobMeades | 0:5cffef3371f6 | 1824 | // End of File |
RobMeades | 0:5cffef3371f6 | 1825 |