ublox-cellular-base_R4_PR

Committer:
wajahat.abbas@u-blox.com
Date:
Thu Sep 05 15:46:11 2019 +0500
Revision:
32:d961d0c06cdf
Parent:
31:b0a6a610d114
Child:
33:64b96bdac04e
SARA-R4: MNO profile 0 is not supposed to be used

Who changed what in which revision?

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