ublox-cellular-base_mno_pr

Committer:
wajahat.abbas@u-blox.com
Date:
Mon Sep 23 17:07:23 2019 +0500
Revision:
33:32fc7c6e2f06
Parent:
32:1fc4850f1253
Child:
34:73f2c02f14f3
Application should not use MNO profile 0

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 33:32fc7c6e2f06 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 33:32fc7c6e2f06 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 33:32fc7c6e2f06 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 33:32fc7c6e2f06 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 33:32fc7c6e2f06 817 #ifdef TARGET_UBLOX_C030_R41XM
fahimalavi 26:e4e444cc7b14 818 int mno_profile;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 819 if (get_mno_profile(&mno_profile)) {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 820 if (mno_profile == SW_DEFAULT) {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 821 tr_critical("!!CANNOT USE PROFILE 0(SW_DEFAULT). PLEASE SET AN APPROPRIATE MNO PROFILE!!");
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 822 _default_profile_is_set = true;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 823 return false;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 824 }
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 825 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 826 #ifdef TARGET_UBLOX_C030_R412M
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 827 int status = 0, periodic_time = 0, active_time = 0;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 828 if (_psm_status == UNKNOWN) {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 829 if (get_power_saving_mode(&status, &periodic_time, &active_time)) {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 830 if (status) { //PSM is already enabled either by a previous run or MNO profile
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 831 tr_info("PSM is already enabled, periodic_time %d, active_time %d", periodic_time, active_time);
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 832 _psm_status = ENABLED;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 833 if ( !(set_psm_urcs(true)) ) { //enable PSM URCs
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 834 tr_error("Modem does not support PSM URCs, disabling PSM");
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 835 set_power_saving_mode(0, 0);
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 836 } else if (!_func_psm_going_in){
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 837 tr_critical("!!PSM IS ENABLED, CALLBACK NOT ATTACHED. PLEASE REGISTER ONE!!");
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 838 }
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 839 }
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 840 }
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 841 } else if (_psm_status == ENABLED && !_func_psm_going_in){
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 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 33:32fc7c6e2f06 844 #elif TARGET_UBLOX_C030_R410M
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 845 disable_psm(); //PSM is currently not supported by driver for R410M due to lack of URCs
wajahat.abbas@u-blox.com 23:eaab8e812a5d 846 #endif
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 847 if (_at->is_idle_mode_enabled() == false) {
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 848 set_idle_mode(false); //disable idle mode at start up
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 849 }
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 850 #endif
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 851 if (set_device_identity(&_dev_info.dev) && // Set up device identity
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 852 device_init(_dev_info.dev)) {// Initialise this device
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 853 // Get the integrated circuit ID of the SIM
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 854 if (get_iccid()) {
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 855 // Try a few times to get the IMSI (since on some modems this can
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 856 // take a while to be retrieved, especially if a SIM PIN
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 857 // was set)
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 858 for (x = 0; (x < 3) && !get_imsi(); x++) {
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 859 wait_ms(1000);
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 860 }
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 861
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 862 if (x < 3) { // If we got the IMSI, can get the others
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 863 if (get_imei() && // Get international mobile equipment identifier
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 864 get_meid() && // Probably the same as the IMEI
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 865 set_sms()) { // And set up SMS
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 866 // The modem is initialised.
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 867 _modem_initialised = true;
fahimalavi 26:e4e444cc7b14 868 tr_info("Modem initialized");
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 869 }
rob.meades@u-blox.com 6:8fadf1e49487 870 }
rob.meades@u-blox.com 6:8fadf1e49487 871 }
rob.meades@u-blox.com 6:8fadf1e49487 872 }
RobMeades 0:5cffef3371f6 873 }
RobMeades 0:5cffef3371f6 874 }
RobMeades 0:5cffef3371f6 875 }
RobMeades 0:5cffef3371f6 876 }
RobMeades 0:5cffef3371f6 877
RobMeades 0:5cffef3371f6 878 return _modem_initialised;
RobMeades 0:5cffef3371f6 879 }
RobMeades 0:5cffef3371f6 880
RobMeades 0:5cffef3371f6 881 // Perform registration.
RobMeades 0:5cffef3371f6 882 bool UbloxCellularBase::nwk_registration()
RobMeades 0:5cffef3371f6 883 {
RobMeades 0:5cffef3371f6 884 bool atSuccess = false;
RobMeades 0:5cffef3371f6 885 bool registered = false;
RobMeades 0:5cffef3371f6 886 int status;
RobMeades 0:5cffef3371f6 887 int at_timeout;
RobMeades 0:5cffef3371f6 888 LOCK();
RobMeades 0:5cffef3371f6 889
RobMeades 0:5cffef3371f6 890 at_timeout = _at_timeout; // Has to be inside LOCK()s
RobMeades 0:5cffef3371f6 891
RobMeades 0:5cffef3371f6 892 MBED_ASSERT(_at != NULL);
RobMeades 0:5cffef3371f6 893
RobMeades 0:5cffef3371f6 894 if (!is_registered_psd() && !is_registered_csd() && !is_registered_eps()) {
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 895 if (set_functionality_mode(FUNC_FULL)) {
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 896 tr_info("Searching Network...");
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 897 // Enable the packet switched and network registration unsolicited result codes
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 898 if (_at->send("AT+CREG=1") && _at->recv("OK") &&
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 899 _at->send("AT+CGREG=1") && _at->recv("OK")) {
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 900 atSuccess = true;
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 901 if (_at->send("AT+CEREG=1")) {
RobMeades 0:5cffef3371f6 902 _at->recv("OK");
RobMeades 0:5cffef3371f6 903 // Don't check return value as this works for LTE only
RobMeades 0:5cffef3371f6 904 }
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 905
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 906 if (atSuccess) {
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 907 // See if we are already in automatic mode
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 908 if (_at->send("AT+COPS?") && _at->recv("+COPS: %d", &status) &&
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 909 _at->recv("OK")) {
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 910 // If not, set it
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 911 if (status != 0) {
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 912 // Don't check return code here as there's not much
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 913 // we can do if this fails.
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 914 _at->send("AT+COPS=0") && _at->recv("OK");
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 915 }
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 916 }
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 917
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 918 // Query the registration status directly as well,
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 919 // just in case
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 920 if (_at->send("AT+CREG?") && _at->recv("OK")) {
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 921 // Answer will be processed by URC
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 922 }
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 923 if (_at->send("AT+CGREG?") && _at->recv("OK")) {
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 924 // Answer will be processed by URC
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 925 }
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 926 if (_at->send("AT+CEREG?")) {
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 927 _at->recv("OK");
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 928 // Don't check return value as this works for LTE only
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 929 }
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 930 }
RobMeades 0:5cffef3371f6 931 }
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 932 // Wait for registration to succeed
RobMeades 0:5cffef3371f6 933 at_set_timeout(1000);
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 934 for (int waitSeconds = 0; !registered && (waitSeconds < 180); waitSeconds++) {
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 935 registered = is_registered_psd() || is_registered_csd() || is_registered_eps();
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 936 _at->recv(UNNATURAL_STRING);
RobMeades 0:5cffef3371f6 937 }
RobMeades 0:5cffef3371f6 938 at_set_timeout(at_timeout);
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 939
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 940 if (registered) {
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 941 // This should return quickly but sometimes the status field is not returned
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 942 // so make the timeout short
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 943 at_set_timeout(1000);
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 944 if (_at->send("AT+COPS?") && _at->recv("+COPS: %*d,%*d,\"%*[^\"]\",%d\nOK\n", &status)) {
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 945 set_rat(status);
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 946 }
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 947 at_set_timeout(at_timeout);
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 948 }
RobMeades 0:5cffef3371f6 949 }
RobMeades 0:5cffef3371f6 950 } else {
RobMeades 0:5cffef3371f6 951 registered = true;
RobMeades 0:5cffef3371f6 952 }
RobMeades 0:5cffef3371f6 953
RobMeades 0:5cffef3371f6 954 UNLOCK();
RobMeades 0:5cffef3371f6 955 return registered;
RobMeades 0:5cffef3371f6 956 }
RobMeades 0:5cffef3371f6 957
RobMeades 0:5cffef3371f6 958 bool UbloxCellularBase::is_registered_csd()
RobMeades 0:5cffef3371f6 959 {
RobMeades 0:5cffef3371f6 960 return (_dev_info.reg_status_csd == CSD_REGISTERED) ||
RobMeades 0:5cffef3371f6 961 (_dev_info.reg_status_csd == CSD_REGISTERED_ROAMING) ||
RobMeades 0:5cffef3371f6 962 (_dev_info.reg_status_csd == CSD_CSFB_NOT_PREFERRED);
RobMeades 0:5cffef3371f6 963 }
RobMeades 0:5cffef3371f6 964
RobMeades 0:5cffef3371f6 965 bool UbloxCellularBase::is_registered_psd()
RobMeades 0:5cffef3371f6 966 {
RobMeades 0:5cffef3371f6 967 return (_dev_info.reg_status_psd == PSD_REGISTERED) ||
RobMeades 0:5cffef3371f6 968 (_dev_info.reg_status_psd == PSD_REGISTERED_ROAMING);
RobMeades 0:5cffef3371f6 969 }
RobMeades 0:5cffef3371f6 970
RobMeades 0:5cffef3371f6 971 bool UbloxCellularBase::is_registered_eps()
RobMeades 0:5cffef3371f6 972 {
RobMeades 0:5cffef3371f6 973 return (_dev_info.reg_status_eps == EPS_REGISTERED) ||
RobMeades 0:5cffef3371f6 974 (_dev_info.reg_status_eps == EPS_REGISTERED_ROAMING);
RobMeades 0:5cffef3371f6 975 }
RobMeades 0:5cffef3371f6 976
RobMeades 0:5cffef3371f6 977 // Perform deregistration.
RobMeades 0:5cffef3371f6 978 bool UbloxCellularBase::nwk_deregistration()
RobMeades 0:5cffef3371f6 979 {
RobMeades 0:5cffef3371f6 980 bool success = false;
RobMeades 0:5cffef3371f6 981 LOCK();
RobMeades 0:5cffef3371f6 982
RobMeades 0:5cffef3371f6 983 MBED_ASSERT(_at != NULL);
RobMeades 0:5cffef3371f6 984
mudassar0121 27:250eaef6232d 985 int at_timeout = _at_timeout; // Has to be inside LOCK()s
fahimalavi 26:e4e444cc7b14 986 at_set_timeout(3*60*1000); //command has 3 minutes timeout
fahimalavi 26:e4e444cc7b14 987
RobMeades 0:5cffef3371f6 988 if (_at->send("AT+COPS=2") && _at->recv("OK")) {
RobMeades 0:5cffef3371f6 989 _dev_info.reg_status_csd = CSD_NOT_REGISTERED_NOT_SEARCHING;
RobMeades 0:5cffef3371f6 990 _dev_info.reg_status_psd = PSD_NOT_REGISTERED_NOT_SEARCHING;
RobMeades 0:5cffef3371f6 991 _dev_info.reg_status_eps = EPS_NOT_REGISTERED_NOT_SEARCHING;
RobMeades 0:5cffef3371f6 992 success = true;
RobMeades 0:5cffef3371f6 993 }
RobMeades 0:5cffef3371f6 994
mudassar0121 27:250eaef6232d 995 at_set_timeout(at_timeout);
RobMeades 0:5cffef3371f6 996 UNLOCK();
RobMeades 0:5cffef3371f6 997 return success;
RobMeades 0:5cffef3371f6 998 }
RobMeades 0:5cffef3371f6 999
RobMeades 0:5cffef3371f6 1000 // Put the modem into its lowest power state.
RobMeades 0:5cffef3371f6 1001 void UbloxCellularBase::deinit()
RobMeades 0:5cffef3371f6 1002 {
RobMeades 0:5cffef3371f6 1003 power_down();
RobMeades 0:5cffef3371f6 1004 _modem_initialised = false;
RobMeades 0:5cffef3371f6 1005 }
RobMeades 0:5cffef3371f6 1006
RobMeades 0:5cffef3371f6 1007 // Set the PIN.
RobMeades 0:5cffef3371f6 1008 void UbloxCellularBase::set_pin(const char *pin) {
RobMeades 0:5cffef3371f6 1009 _pin = pin;
RobMeades 0:5cffef3371f6 1010 }
RobMeades 0:5cffef3371f6 1011
RobMeades 0:5cffef3371f6 1012 // Enable or disable SIM pin checking.
rob.meades@u-blox.com 4:2e640a101db1 1013 bool UbloxCellularBase::sim_pin_check_enable(bool enableNotDisable)
RobMeades 0:5cffef3371f6 1014 {
RobMeades 0:5cffef3371f6 1015 bool success = false;;
RobMeades 0:5cffef3371f6 1016 LOCK();
RobMeades 0:5cffef3371f6 1017
RobMeades 0:5cffef3371f6 1018 MBED_ASSERT(_at != NULL);
RobMeades 0:5cffef3371f6 1019
RobMeades 0:5cffef3371f6 1020 if (_pin != NULL) {
RobMeades 0:5cffef3371f6 1021 if (_sim_pin_check_enabled && !enableNotDisable) {
RobMeades 0:5cffef3371f6 1022 // Disable the SIM lock
RobMeades 0:5cffef3371f6 1023 if (_at->send("AT+CLCK=\"SC\",0,\"%s\"", _pin) && _at->recv("OK")) {
RobMeades 0:5cffef3371f6 1024 _sim_pin_check_enabled = false;
RobMeades 0:5cffef3371f6 1025 success = true;
RobMeades 0:5cffef3371f6 1026 }
RobMeades 0:5cffef3371f6 1027 } else if (!_sim_pin_check_enabled && enableNotDisable) {
RobMeades 0:5cffef3371f6 1028 // Enable the SIM lock
RobMeades 0:5cffef3371f6 1029 if (_at->send("AT+CLCK=\"SC\",1,\"%s\"", _pin) && _at->recv("OK")) {
RobMeades 0:5cffef3371f6 1030 _sim_pin_check_enabled = true;
RobMeades 0:5cffef3371f6 1031 success = true;
RobMeades 0:5cffef3371f6 1032 }
RobMeades 0:5cffef3371f6 1033 } else {
RobMeades 0:5cffef3371f6 1034 success = true;
RobMeades 0:5cffef3371f6 1035 }
RobMeades 0:5cffef3371f6 1036 }
RobMeades 0:5cffef3371f6 1037
RobMeades 0:5cffef3371f6 1038 UNLOCK();
RobMeades 0:5cffef3371f6 1039 return success;
RobMeades 0:5cffef3371f6 1040 }
RobMeades 0:5cffef3371f6 1041
RobMeades 0:5cffef3371f6 1042 // Change the pin code for the SIM card.
RobMeades 0:5cffef3371f6 1043 bool UbloxCellularBase::change_sim_pin(const char *pin)
RobMeades 0:5cffef3371f6 1044 {
RobMeades 0:5cffef3371f6 1045 bool success = false;;
RobMeades 0:5cffef3371f6 1046 LOCK();
RobMeades 0:5cffef3371f6 1047
RobMeades 0:5cffef3371f6 1048 MBED_ASSERT(_at != NULL);
RobMeades 0:5cffef3371f6 1049
RobMeades 0:5cffef3371f6 1050 // Change the SIM pin
RobMeades 0:5cffef3371f6 1051 if ((pin != NULL) && (_pin != NULL)) {
RobMeades 0:5cffef3371f6 1052 if (_at->send("AT+CPWD=\"SC\",\"%s\",\"%s\"", _pin, pin) && _at->recv("OK")) {
RobMeades 0:5cffef3371f6 1053 _pin = pin;
RobMeades 0:5cffef3371f6 1054 success = true;
RobMeades 0:5cffef3371f6 1055 }
RobMeades 0:5cffef3371f6 1056 }
RobMeades 0:5cffef3371f6 1057
RobMeades 0:5cffef3371f6 1058 UNLOCK();
RobMeades 0:5cffef3371f6 1059 return success;
RobMeades 0:5cffef3371f6 1060 }
RobMeades 0:5cffef3371f6 1061
RobMeades 14:e420232ee4e7 1062 // Get the IMEI.
fahim alavi 13:158a035b1b50 1063 bool UbloxCellularBase::get_imei(char *imei_to_send, int size)
fahim alavi 13:158a035b1b50 1064 {
fahim alavi 13:158a035b1b50 1065 bool success;
fahim alavi 13:158a035b1b50 1066 LOCK();
fahim alavi 13:158a035b1b50 1067
fahim alavi 13:158a035b1b50 1068 MBED_ASSERT(_at != NULL);
fahim alavi 13:158a035b1b50 1069
fahim alavi 13:158a035b1b50 1070 // International mobile equipment identifier
fahim alavi 13:158a035b1b50 1071 // AT Command Manual UBX-13002752, section 4.7
fahim alavi 13:158a035b1b50 1072 success = _at->send("AT+CGSN") && _at->recv("%15[^\n]\nOK\n", _dev_info.imei);
fahim alavi 13:158a035b1b50 1073 tr_info("DevInfo: IMEI=%s", _dev_info.imei);
fahim alavi 13:158a035b1b50 1074
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1075 if (success) {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1076 memcpy(imei_to_send,_dev_info.imei,size);
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1077 imei_to_send[size-1] = '\0';
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1078 }
fahim alavi 13:158a035b1b50 1079
fahim alavi 13:158a035b1b50 1080 UNLOCK();
fahim alavi 13:158a035b1b50 1081 return success;
fahim alavi 13:158a035b1b50 1082 }
fahim alavi 13:158a035b1b50 1083
RobMeades 14:e420232ee4e7 1084 // Get the IMEI of the module.
RobMeades 14:e420232ee4e7 1085 const char *UbloxCellularBase::imei()
RobMeades 14:e420232ee4e7 1086 {
RobMeades 14:e420232ee4e7 1087 return _dev_info.imei;
RobMeades 14:e420232ee4e7 1088 }
RobMeades 14:e420232ee4e7 1089
RobMeades 14:e420232ee4e7 1090 // Get the Mobile Equipment ID (which may be the same as the IMEI).
RobMeades 14:e420232ee4e7 1091 const char *UbloxCellularBase::meid()
RobMeades 14:e420232ee4e7 1092 {
RobMeades 14:e420232ee4e7 1093 return _dev_info.meid;
RobMeades 14:e420232ee4e7 1094 }
RobMeades 14:e420232ee4e7 1095
RobMeades 14:e420232ee4e7 1096 // Get the IMSI of the SIM.
RobMeades 14:e420232ee4e7 1097 const char *UbloxCellularBase::imsi()
RobMeades 14:e420232ee4e7 1098 {
RobMeades 14:e420232ee4e7 1099 // (try) to update the IMSI, just in case the SIM has changed
RobMeades 14:e420232ee4e7 1100 get_imsi();
RobMeades 14:e420232ee4e7 1101
RobMeades 14:e420232ee4e7 1102 return _dev_info.imsi;
RobMeades 14:e420232ee4e7 1103 }
RobMeades 14:e420232ee4e7 1104
RobMeades 14:e420232ee4e7 1105 // Get the ICCID of the SIM.
RobMeades 14:e420232ee4e7 1106 const char *UbloxCellularBase::iccid()
RobMeades 14:e420232ee4e7 1107 {
RobMeades 14:e420232ee4e7 1108 // (try) to update the ICCID, just in case the SIM has changed
RobMeades 14:e420232ee4e7 1109 get_iccid();
RobMeades 14:e420232ee4e7 1110
RobMeades 14:e420232ee4e7 1111 return _dev_info.iccid;
RobMeades 14:e420232ee4e7 1112 }
RobMeades 14:e420232ee4e7 1113
RobMeades 14:e420232ee4e7 1114 // Get the RSSI in dBm.
RobMeades 14:e420232ee4e7 1115 int UbloxCellularBase::rssi()
RobMeades 14:e420232ee4e7 1116 {
RobMeades 14:e420232ee4e7 1117 char buf[7] = {0};
RobMeades 14:e420232ee4e7 1118 int rssi = 0;
RobMeades 14:e420232ee4e7 1119 int qual = 0;
RobMeades 14:e420232ee4e7 1120 int rssiRet = 0;
RobMeades 14:e420232ee4e7 1121 bool success;
RobMeades 14:e420232ee4e7 1122 LOCK();
RobMeades 14:e420232ee4e7 1123
RobMeades 14:e420232ee4e7 1124 MBED_ASSERT(_at != NULL);
RobMeades 14:e420232ee4e7 1125
RobMeades 14:e420232ee4e7 1126 success = _at->send("AT+CSQ") && _at->recv("+CSQ: %6[^\n]\nOK\n", buf);
RobMeades 14:e420232ee4e7 1127
RobMeades 14:e420232ee4e7 1128 if (success) {
RobMeades 14:e420232ee4e7 1129 if (sscanf(buf, "%d,%d", &rssi, &qual) == 2) {
RobMeades 14:e420232ee4e7 1130 // AT+CSQ returns a coded RSSI value and an RxQual value
RobMeades 14:e420232ee4e7 1131 // For 2G an RSSI of 0 corresponds to -113 dBm or less,
RobMeades 14:e420232ee4e7 1132 // an RSSI of 31 corresponds to -51 dBm or less and hence
RobMeades 14:e420232ee4e7 1133 // each value is a 2 dB step.
RobMeades 14:e420232ee4e7 1134 // For LTE the mapping is defined in the array rssiConvertLte[].
RobMeades 14:e420232ee4e7 1135 // For 3G the mapping to RSCP is defined in the array rscpConvert3G[]
RobMeades 14:e420232ee4e7 1136 // and the RSSI value is then RSCP - the EC_NO_LEV number derived
RobMeades 14:e420232ee4e7 1137 // by putting the qual number through qualConvert3G[].
RobMeades 14:e420232ee4e7 1138 if ((rssi >= 0) && (rssi <= 31)) {
RobMeades 14:e420232ee4e7 1139 switch (_dev_info.rat) {
RobMeades 14:e420232ee4e7 1140 case UTRAN:
RobMeades 14:e420232ee4e7 1141 case HSDPA:
RobMeades 14:e420232ee4e7 1142 case HSUPA:
RobMeades 14:e420232ee4e7 1143 case HSDPA_HSUPA:
RobMeades 14:e420232ee4e7 1144 // 3G
RobMeades 14:e420232ee4e7 1145 if ((qual >= 0) && (qual <= 7)) {
RobMeades 14:e420232ee4e7 1146 qual = qualConvert3G[qual];
fahim.alavi@u-blox.com 15:93b157a47b8d 1147 rssiRet = rscpConvert3G[rssi];
fahim.alavi@u-blox.com 15:93b157a47b8d 1148 rssiRet -= qual;
RobMeades 14:e420232ee4e7 1149 }
fahim.alavi@u-blox.com 15:93b157a47b8d 1150
RobMeades 14:e420232ee4e7 1151 break;
RobMeades 14:e420232ee4e7 1152 case LTE:
RobMeades 14:e420232ee4e7 1153 // LTE
RobMeades 14:e420232ee4e7 1154 rssiRet = rssiConvertLte[rssi];
RobMeades 14:e420232ee4e7 1155 break;
RobMeades 14:e420232ee4e7 1156 case GSM:
RobMeades 14:e420232ee4e7 1157 case COMPACT_GSM:
RobMeades 14:e420232ee4e7 1158 case EDGE:
RobMeades 14:e420232ee4e7 1159 default:
RobMeades 14:e420232ee4e7 1160 // GSM or assumed GSM if the RAT is not known
RobMeades 14:e420232ee4e7 1161 rssiRet = -(113 - (rssi << 2));
RobMeades 14:e420232ee4e7 1162 break;
RobMeades 14:e420232ee4e7 1163 }
RobMeades 14:e420232ee4e7 1164 }
RobMeades 14:e420232ee4e7 1165 }
RobMeades 14:e420232ee4e7 1166 }
RobMeades 14:e420232ee4e7 1167
RobMeades 14:e420232ee4e7 1168 UNLOCK();
RobMeades 14:e420232ee4e7 1169 return rssiRet;
RobMeades 14:e420232ee4e7 1170 }
RobMeades 14:e420232ee4e7 1171
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1172 //RAT should be set in a detached state (AT+COPS=2)
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1173 bool UbloxCellularBase::set_modem_rat(RAT selected_rat, RAT preferred_rat, RAT second_preferred_rat)
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1174 {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1175 #ifdef TARGET_UBLOX_C030_R41XM
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1176 if (_default_profile_is_set == true) {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1177 tr_critical("!!CANNOT USE PROFILE 0(SW_DEFAULT). PLEASE SET AN APPROPRIATE MNO PROFILE!!");
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1178 return false;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1179 }
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1180 #endif
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1181
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1182 bool success = false;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1183 char command[16] = {0x00};
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1184
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1185 //check if modem is registered with network
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1186 if (is_registered_csd() || is_registered_psd() || is_registered_eps()) {
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1187 tr_error("RAT should only be set in detached state");
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1188 return false;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1189 }
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1190
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1191 if (preferred_rat != NOT_USED && second_preferred_rat != NOT_USED) {
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1192 sprintf(command, "AT+URAT=%d,%d,%d", selected_rat, preferred_rat, second_preferred_rat);
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1193 } else if (preferred_rat != NOT_USED) {
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1194 sprintf(command, "AT+URAT=%d,%d", selected_rat, preferred_rat);
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1195 } else if (second_preferred_rat != NOT_USED) {
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1196 sprintf(command, "AT+URAT=%d,%d", selected_rat, second_preferred_rat);
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1197 } else {
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1198 sprintf(command, "AT+URAT=%d", selected_rat);
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1199 }
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1200
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1201 LOCK();
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1202 if (_at->send(command) && _at->recv("OK")) {
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1203 success = true;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1204 } else {
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1205 tr_error("unable to set the specified RAT");
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1206 success = false;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1207 }
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1208 UNLOCK();
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1209
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1210 return success;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1211 }
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1212
wajahat.abbas@u-blox.com 22:779971811c46 1213 bool UbloxCellularBase::get_modem_rat(int *selected_rat, int *preferred_rat, int *second_preferred_rat)
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1214 {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1215 #ifdef TARGET_UBLOX_C030_R41XM
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1216 if (_default_profile_is_set == true) {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1217 tr_critical("!!CANNOT USE PROFILE 0(SW_DEFAULT). PLEASE SET AN APPROPRIATE MNO PROFILE!!");
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1218 return false;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1219 }
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1220 #endif
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1221
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1222 bool success = false;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1223 char buf[24] = {0x00};
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1224
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1225 if (selected_rat == NULL || preferred_rat == NULL || second_preferred_rat == NULL) {
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1226 tr_info("invalid pointers");
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1227 return false;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1228 }
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1229
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1230 MBED_ASSERT(_at != NULL);
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1231
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1232 *selected_rat = NOT_USED;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1233 *preferred_rat = NOT_USED;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1234 *second_preferred_rat = NOT_USED;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1235
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1236 LOCK();
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1237
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1238 if (_at->send("AT+URAT?") && _at->recv("%23[^\n]\nOK\n", buf)) {
wajahat.abbas@u-blox.com 22:779971811c46 1239 if (sscanf(buf, "+URAT: %d,%d,%d", selected_rat, preferred_rat, second_preferred_rat) == 3) {
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1240 success = true;
wajahat.abbas@u-blox.com 22:779971811c46 1241 } else if (sscanf(buf, "+URAT: %d,%d", selected_rat, preferred_rat) == 2) {
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1242 success = true;
wajahat.abbas@u-blox.com 22:779971811c46 1243 } else if (sscanf(buf, "+URAT: %d", selected_rat) == 1) {
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1244 success = true;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1245 }
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1246 }
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1247
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1248 UNLOCK();
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1249 return success;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1250 }
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1251
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1252 //application should call init() or connect() in order to initialize the modem
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1253 bool UbloxCellularBase::reboot_modem()
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1254 {
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1255 return (set_functionality_mode(FUNC_RESET));
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1256 }
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1257
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1258 bool UbloxCellularBase::set_functionality_mode(FunctionalityMode mode)
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1259 {
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1260 bool return_val = false;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1261 int at_timeout;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1262 LOCK();
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1263
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1264 MBED_ASSERT(_at != NULL);
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1265
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1266 at_timeout = _at_timeout; // Has to be inside LOCK()s
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1267 at_set_timeout(3*60*1000); //command has 3 minutes timeout
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1268
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1269 if (_at->send("AT+CFUN=%d", mode) && _at->recv("OK")) {
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1270 return_val = true;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1271 }
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1272
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1273 if (mode == FUNC_RESET || mode == FUNC_RESET_WITH_SIM) {
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1274 _modem_initialised = false;
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1275 }
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1276
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1277 at_set_timeout(at_timeout);
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1278 UNLOCK();
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1279
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1280 return return_val;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1281 }
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1282
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1283 bool UbloxCellularBase::get_functionality_mode(int *mode)
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1284 {
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1285 bool return_val = false;
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1286
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1287 if (mode == NULL) {
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1288 return false;
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1289 }
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1290
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1291 LOCK();
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1292 MBED_ASSERT(_at != NULL);
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1293
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1294 if ( (_at->send("AT+CFUN?") && _at->recv("+CFUN: %d", mode) && _at->recv("OK")) ) {
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1295 return_val = true;
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1296 }
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1297
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1298 UNLOCK();
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1299 return return_val;
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1300 }
wajahat.abbas@u-blox.com 24:e26a6ab0dd75 1301
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1302 #ifdef TARGET_UBLOX_C030_R41XM
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1303 bool UbloxCellularBase::set_mno_profile(MNOProfile profile)
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1304 {
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1305 bool return_val = false;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1306 int current_profile;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1307 MNOProfile arr[MAX_NUM_PROFILES] = { SW_DEFAULT, SIM_ICCID, ATT, TMO, VODAFONE, DT, STANDARD_EU
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1308 #ifdef TARGET_UBLOX_C030_R410M
wajahat.abbas@u-blox.com 29:8a38f91009ad 1309 , VERIZON, TELSTRA, CT, SPRINT, TELUS
wajahat.abbas@u-blox.com 29:8a38f91009ad 1310 #endif
wajahat.abbas@u-blox.com 29:8a38f91009ad 1311 };
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1312
wajahat.abbas@u-blox.com 29:8a38f91009ad 1313 if (is_registered_csd() || is_registered_psd() || is_registered_eps()) {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1314 tr_error("MNO profile should only be set in detached state");
wajahat.abbas@u-blox.com 29:8a38f91009ad 1315 return false;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1316 }
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1317
wajahat.abbas@u-blox.com 29:8a38f91009ad 1318 if (get_mno_profile(&current_profile)) {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1319 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 1320 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 1321 if (arr[index] == current_profile) {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1322 index = ((index + 1) % MAX_NUM_PROFILES);
wajahat.abbas@u-blox.com 29:8a38f91009ad 1323 current_profile = arr[index];
wajahat.abbas@u-blox.com 29:8a38f91009ad 1324 break;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1325 }
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1326 }
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1327
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1328 LOCK();
wajahat.abbas@u-blox.com 29:8a38f91009ad 1329 if (_at->send("AT+UMNOPROF=%d", current_profile) && _at->recv("OK")) {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1330 tr_info("temporary MNO profile set: %d", current_profile);
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1331 }
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1332 UNLOCK();
wajahat.abbas@u-blox.com 29:8a38f91009ad 1333 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1334 LOCK();
wajahat.abbas@u-blox.com 29:8a38f91009ad 1335 if (_at->send("AT+UMNOPROF=%d", profile) && _at->recv("OK")) {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1336 if (profile == SW_DEFAULT) {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1337 tr_critical("!!CANNOT USE PROFILE 0(SW_DEFAULT). PLEASE SET AN APPROPRIATE MNO PROFILE!!");
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1338 _default_profile_is_set = true;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1339 } else {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1340 _default_profile_is_set = false;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1341 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1342 return_val = true;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1343 } else {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1344 tr_error("unable to set user specified profile");
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1345 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1346 UNLOCK();
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1347 } else {
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1348 tr_error("could not read MNO profile");
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1349 }
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1350
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1351 return return_val;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1352 }
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1353
wajahat.abbas@u-blox.com 22:779971811c46 1354 bool UbloxCellularBase::get_mno_profile(int *profile)
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1355 {
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1356 bool return_val = false;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1357 char buf[4] = {0x00};
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1358
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1359 if (profile == NULL) {
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1360 return false;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1361 }
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1362
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1363 LOCK();
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1364 MBED_ASSERT(_at != NULL);
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1365
wajahat.abbas@u-blox.com 29:8a38f91009ad 1366 if (_at->send("AT+UMNOPROF?") && _at->recv("+UMNOPROF: %3[^\n]\nOK\n", buf)) {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1367 *profile = atoi(buf);
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1368 return_val = true;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1369 }
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1370
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1371 UNLOCK();
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1372 return return_val;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1373 }
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1374 // Enable or Disable the UPSV power saving mode
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1375 bool UbloxCellularBase::set_idle_mode(bool enable)
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1376 {
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1377 #ifdef TARGET_UBLOX_C030_R412M
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1378 if (_psm_status == ENABLED && enable == true) {
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1379 return false;
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1380 }
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1381 #endif
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1382
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1383 bool success = false;
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1384 LOCK();
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1385
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1386 MBED_ASSERT(_at != NULL);
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1387
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1388 if (_at->send("AT+UPSV=%d", enable ? 4 : 0) && _at->recv("OK")) {
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1389 if (enable == true) {
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1390 _at->idle_mode_enabled();
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1391 }
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1392 else {
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1393 _at->idle_mode_disabled();
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1394 }
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1395 success = true;
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1396 }
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1397
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1398 UNLOCK();
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1399 return success;
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1400 }
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1401
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1402 bool UbloxCellularBase::get_idle_mode(int *status)
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1403 {
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1404 bool return_val = false;
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1405
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1406 if (status == NULL) {
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1407 return false;
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1408 }
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1409
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1410 LOCK();
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1411 MBED_ASSERT(_at != NULL);
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1412
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1413 if ( (_at->send("AT+UPSV?") && _at->recv("+UPSV: %d", status) && _at->recv("OK")) ) {
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1414 if (*status == 4) {
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1415 *status = 1;
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1416 }
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1417 return_val = true;
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1418 }
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1419
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1420 UNLOCK();
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1421 return return_val;
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1422 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1423
wajahat.abbas@u-blox.com 29:8a38f91009ad 1424 int UbloxCellularBase::set_receive_period(int mode, tEDRXAccessTechnology act_type, uint8_t edrx_value) {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1425 char edrx[5];
wajahat.abbas@u-blox.com 29:8a38f91009ad 1426 uint_to_binary_str(edrx_value, edrx, 5, 4);
wajahat.abbas@u-blox.com 29:8a38f91009ad 1427 edrx[4] = '\0';
wajahat.abbas@u-blox.com 29:8a38f91009ad 1428 int status = 1;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1429
wajahat.abbas@u-blox.com 29:8a38f91009ad 1430 LOCK();
wajahat.abbas@u-blox.com 29:8a38f91009ad 1431
wajahat.abbas@u-blox.com 29:8a38f91009ad 1432 if (_at->send("AT+CEDRXS=%d,%d,\"%s\"", mode, act_type, edrx) && _at->recv("OK")) {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1433 status = 0;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1434 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1435 else {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1436 status = 1;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1437 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1438
wajahat.abbas@u-blox.com 29:8a38f91009ad 1439
wajahat.abbas@u-blox.com 29:8a38f91009ad 1440 UNLOCK();
wajahat.abbas@u-blox.com 29:8a38f91009ad 1441
wajahat.abbas@u-blox.com 29:8a38f91009ad 1442 return status;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1443 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1444
wajahat.abbas@u-blox.com 29:8a38f91009ad 1445 int UbloxCellularBase::set_receive_period(int mode, tEDRXAccessTechnology act_type) {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1446 int status = 1;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1447
wajahat.abbas@u-blox.com 29:8a38f91009ad 1448 LOCK();
wajahat.abbas@u-blox.com 29:8a38f91009ad 1449
wajahat.abbas@u-blox.com 29:8a38f91009ad 1450 if (_at->send("AT+CEDRXS=%d,%d", mode, act_type) && _at->recv("OK")) {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1451
wajahat.abbas@u-blox.com 29:8a38f91009ad 1452 status = 0;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1453 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1454 else {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1455 status = 1;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1456 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1457
wajahat.abbas@u-blox.com 29:8a38f91009ad 1458 UNLOCK();
wajahat.abbas@u-blox.com 29:8a38f91009ad 1459
wajahat.abbas@u-blox.com 29:8a38f91009ad 1460 return status;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1461 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1462
wajahat.abbas@u-blox.com 29:8a38f91009ad 1463 int UbloxCellularBase::set_receive_period(int mode) {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1464 int status = 1;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1465
wajahat.abbas@u-blox.com 29:8a38f91009ad 1466 LOCK();
wajahat.abbas@u-blox.com 29:8a38f91009ad 1467
wajahat.abbas@u-blox.com 29:8a38f91009ad 1468 if (_at->send("AT+CEDRXS=%d", mode) && _at->recv("OK")) {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1469
wajahat.abbas@u-blox.com 29:8a38f91009ad 1470 status = 0;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1471 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1472 else {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1473 status = 1;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1474 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1475
wajahat.abbas@u-blox.com 29:8a38f91009ad 1476 UNLOCK();
wajahat.abbas@u-blox.com 29:8a38f91009ad 1477
wajahat.abbas@u-blox.com 29:8a38f91009ad 1478 return status;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1479 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1480
wajahat.abbas@u-blox.com 29:8a38f91009ad 1481 uint32_t UbloxCellularBase::get_receive_period() {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1482 uint32_t edrx_value = 2;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1483 char buf[24] = {0x00};
wajahat.abbas@u-blox.com 29:8a38f91009ad 1484 char edrx_val[5];
wajahat.abbas@u-blox.com 29:8a38f91009ad 1485 tEDRXAccessTechnology act_type;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1486
wajahat.abbas@u-blox.com 29:8a38f91009ad 1487 LOCK();
wajahat.abbas@u-blox.com 29:8a38f91009ad 1488
wajahat.abbas@u-blox.com 29:8a38f91009ad 1489 if (_at->send("AT+CEDRXS?") && _at->recv("%23[^\n]\nOK\n", buf)) {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1490 if (sscanf(buf, "+CEDRXS: %d,\"%s\"", (int *)&act_type, edrx_val) == 2) {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1491
wajahat.abbas@u-blox.com 29:8a38f91009ad 1492 edrx_value = binary_str_to_uint(edrx_val,4);
wajahat.abbas@u-blox.com 29:8a38f91009ad 1493 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1494 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1495
wajahat.abbas@u-blox.com 29:8a38f91009ad 1496 if (_at->send("AT+CEDRXRDP") && _at->recv("OK")) {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1497 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1498
wajahat.abbas@u-blox.com 29:8a38f91009ad 1499 tr_info("edrx_value. %d", edrx_value);
wajahat.abbas@u-blox.com 29:8a38f91009ad 1500
wajahat.abbas@u-blox.com 29:8a38f91009ad 1501 UNLOCK();
wajahat.abbas@u-blox.com 29:8a38f91009ad 1502 return edrx_value;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1503 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1504
wajahat.abbas@u-blox.com 29:8a38f91009ad 1505 void UbloxCellularBase::uint_to_binary_str(uint32_t num, char* str, int str_size, int bit_cnt)
wajahat.abbas@u-blox.com 29:8a38f91009ad 1506 {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1507 if (!str || str_size < bit_cnt) {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1508 return;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1509 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1510 int tmp, pos = 0;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1511
wajahat.abbas@u-blox.com 29:8a38f91009ad 1512 for (int i = 31; i >= 0; i--) {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1513 tmp = num >> i;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1514 if (i < bit_cnt) {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1515 if (tmp&1) {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1516 str[pos] = 1 + '0';
wajahat.abbas@u-blox.com 29:8a38f91009ad 1517 } else {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1518 str[pos] = 0 + '0';
wajahat.abbas@u-blox.com 29:8a38f91009ad 1519 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1520 pos++;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1521 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1522 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1523 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1524
wajahat.abbas@u-blox.com 29:8a38f91009ad 1525 uint32_t UbloxCellularBase::binary_str_to_uint(const char *binary_string, int binary_string_length)
wajahat.abbas@u-blox.com 29:8a38f91009ad 1526 {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1527 if (!binary_string || !binary_string_length) {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1528 return 0;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1529 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1530
wajahat.abbas@u-blox.com 29:8a38f91009ad 1531 int integer_output = 0, base_exp = 1;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1532
wajahat.abbas@u-blox.com 29:8a38f91009ad 1533 for (int i = binary_string_length - 1; i >= 0; i--) {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1534 if (binary_string[i] == '1') {
wajahat.abbas@u-blox.com 29:8a38f91009ad 1535 integer_output += (base_exp << (binary_string_length - (i+1)));
wajahat.abbas@u-blox.com 29:8a38f91009ad 1536 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1537 }
wajahat.abbas@u-blox.com 29:8a38f91009ad 1538
wajahat.abbas@u-blox.com 29:8a38f91009ad 1539 return integer_output;
wajahat.abbas@u-blox.com 29:8a38f91009ad 1540 }
fahimalavi 30:38230504a646 1541
fahimalavi 30:38230504a646 1542 bool UbloxCellularBase::set_band_bitmask(RAT rat, uint64_t bitmask) {
fahimalavi 30:38230504a646 1543
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1544 if (_default_profile_is_set == true) {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1545 tr_critical("!!CANNOT USE PROFILE 0(SW_DEFAULT). PLEASE SET AN APPROPRIATE MNO PROFILE!!");
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1546 return false;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1547 }
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1548
fahimalavi 30:38230504a646 1549 bool status = false;
fahimalavi 30:38230504a646 1550 UBandmaskRAT eBandMastRat;
fahimalavi 30:38230504a646 1551
fahimalavi 30:38230504a646 1552 if(rat == LTE_CATM1) {
fahimalavi 30:38230504a646 1553 eBandMastRat = UBANDMASK_RAT_LTE_CATM1;
fahimalavi 30:38230504a646 1554 }
fahimalavi 30:38230504a646 1555 else if(rat == LTE_CATNB1) {
fahimalavi 30:38230504a646 1556 eBandMastRat = UBANDMASK_RAT_LTE_CATNB1;
fahimalavi 30:38230504a646 1557 }
fahimalavi 30:38230504a646 1558 else {
fahimalavi 30:38230504a646 1559 tr_error("Invalid RAT for Band mask selection: %d", rat);
fahimalavi 30:38230504a646 1560
fahimalavi 30:38230504a646 1561 return false;
fahimalavi 30:38230504a646 1562 }
fahimalavi 30:38230504a646 1563
fahimalavi 30:38230504a646 1564 tr_info("UBANDMASK RAT %d, bitmask : %llu", eBandMastRat, bitmask);
fahimalavi 30:38230504a646 1565
fahimalavi 30:38230504a646 1566 LOCK();
fahimalavi 30:38230504a646 1567
fahimalavi 30:38230504a646 1568 if (_at->send("AT+UBANDMASK=%d,%llu", eBandMastRat, bitmask) && _at->recv("OK")) {
fahimalavi 30:38230504a646 1569
fahimalavi 30:38230504a646 1570 status = true;
fahimalavi 30:38230504a646 1571 }
fahimalavi 30:38230504a646 1572 UNLOCK();
fahimalavi 30:38230504a646 1573
fahimalavi 30:38230504a646 1574 return status;
fahimalavi 30:38230504a646 1575 }
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1576 bool UbloxCellularBase::get_band_bitmask(uint64_t *m1_bitmask, uint64_t *nb1_bitmask)
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1577 {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1578 if (_default_profile_is_set == true) {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1579 tr_critical("!!CANNOT USE PROFILE 0(SW_DEFAULT). PLEASE SET AN APPROPRIATE MNO PROFILE!!");
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1580 return false;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1581 }
fahimalavi 31:b0a6a610d114 1582
fahimalavi 31:b0a6a610d114 1583 bool status = false;
fahimalavi 31:b0a6a610d114 1584 int eBandMastRat0, eBandMastRat1;
fahimalavi 31:b0a6a610d114 1585
fahimalavi 31:b0a6a610d114 1586 LOCK();
fahimalavi 31:b0a6a610d114 1587
qasim-ublox 32:1fc4850f1253 1588 if(_at->send("AT+UBANDMASK?") && _at->recv("+UBANDMASK: %d,%llu,%d,%llu\nOK\n", &eBandMastRat0, m1_bitmask, &eBandMastRat1, nb1_bitmask)) {
fahimalavi 31:b0a6a610d114 1589
fahimalavi 31:b0a6a610d114 1590 status = true;
fahimalavi 31:b0a6a610d114 1591 }
fahimalavi 31:b0a6a610d114 1592 UNLOCK();
fahimalavi 31:b0a6a610d114 1593
fahimalavi 31:b0a6a610d114 1594 return status;
fahimalavi 31:b0a6a610d114 1595 }
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1596
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1597 bool UbloxCellularBase::disable_psm()
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1598 {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1599 bool return_value = false;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1600
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1601 LOCK();
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1602 if (_at->send("AT+CPSMS=0") && _at->recv("OK")) {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1603 return_value = true;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1604 }
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1605 UNLOCK();
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1606
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1607 return return_value;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1608 }
fahimalavi 30:38230504a646 1609 #endif //TARGET_UBLOX_C030_R41XM
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1610
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1611
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1612 #ifdef TARGET_UBLOX_C030_R412M
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1613 bool UbloxCellularBase::get_power_saving_mode(int *status, int *periodic_time, int *active_time)
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1614 {
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1615 char pt_encoded[8+1];// timer value encoded as 3GPP IE
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1616 char at_encoded[8+1];// timer value encoded as 3GPP IE
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1617 int value, multiplier;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1618 bool return_val;
wajahat.abbas@u-blox.com 20:31d5e048fbfa 1619
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1620 if (status == NULL || periodic_time == NULL || active_time == NULL) {
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1621 return false;
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1622 }
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1623
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1624 LOCK();
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1625 //+UCPSMS:1,,,"01000011","01000011"
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1626 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 1627 if (*status == true) {
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1628 //PSM is enabled, decode the timer values, periodic TAU first
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1629 value = (pt_encoded[7]- '0');
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1630 value += (pt_encoded[6]- '0') << 1;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1631 value += (pt_encoded[5]- '0') << 2;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1632 value += (pt_encoded[4]- '0') << 3;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1633 value += (pt_encoded[3]- '0') << 4;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1634
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1635 multiplier = (pt_encoded[2]- '0');
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1636 multiplier += (pt_encoded[1]- '0') << 1;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1637 multiplier += (pt_encoded[0]- '0') << 2;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1638
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1639 switch(multiplier) {
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1640 //10 minutes
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1641 case 0:
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1642 value = value*10*60;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1643 break;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1644
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1645 //1 hour
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1646 case 1:
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1647 value = value*60*60;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1648 break;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1649
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1650 //10 hours
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1651 case 2:
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1652 value = value*10*60*60;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1653 break;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1654
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1655 //2 seconds
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1656 case 3:
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1657 value = value*2;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1658 break;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1659
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1660 //30 seconds
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1661 case 4:
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1662 value = value*30;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1663 break;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1664
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1665 //1 minute
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1666 case 5:
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1667 value = value*60;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1668 break;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1669
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1670 //320 hours
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1671 case 6:
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1672 value = value*320*60*60;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1673 break;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1674
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1675 default:
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1676 value = 0;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1677 break;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1678 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1679 *periodic_time = value;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1680
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1681 //decode the active time
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1682 value = (at_encoded[7]- '0');
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1683 value += (at_encoded[6]- '0') << 1;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1684 value += (at_encoded[5]- '0') << 2;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1685 value += (at_encoded[4]- '0') << 3;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1686 value += (at_encoded[3]- '0') << 4;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1687
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1688 multiplier = (at_encoded[2]- '0');
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1689 multiplier += (at_encoded[1]- '0') << 1;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1690 multiplier += (at_encoded[0]- '0') << 2;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1691
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1692 switch(multiplier) {
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1693 //2 seconds
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1694 case 0:
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1695 value = value*2;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1696 break;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1697
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1698 //1 minute
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1699 case 1:
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1700 value = value*60;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1701 break;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1702
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1703 //decihours (6minutes)
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1704 case 2:
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1705 value = value*6*60;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1706 break;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1707
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1708 default:
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1709 value = 0;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1710 break;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1711 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1712 *active_time = value;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1713 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1714 return_val = true;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1715 } else {
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1716 return_val = false;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1717 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1718 UNLOCK();
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1719 return return_val;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1720 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1721
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1722 bool UbloxCellularBase::set_power_saving_mode(int periodic_time, int active_time)
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1723 {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1724
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1725 if (_at->is_idle_mode_enabled() == true && periodic_time != 0 && active_time != 0 ) {
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1726 return false;
wajahat.abbas@u-blox.com 25:e67d3d9d2e7e 1727 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1728 bool return_val = false;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1729
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1730 LOCK();
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1731 int at_timeout = _at_timeout;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1732 at_set_timeout(10000); //AT+CPSMS has response time of < 10s
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1733
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1734 if (periodic_time == 0 && active_time == 0) {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1735 // disable PSM
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1736 if (_at->send("AT+CPSMS=0") && _at->recv("OK")) {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1737 set_psm_urcs(false); //disable the URC
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1738 _psm_status = DISABLED;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1739 return_val = true;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1740 }
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1741 } else if (_at->send("AT+UPSMR?") && _at->recv("OK")) { //PSM string encoding code borrowed from AT_CellularPower.cpp
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1742 /**
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1743 Table 10.5.163a/3GPP TS 24.008: GPRS Timer 3 information element
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1744
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1745 Bits 5 to 1 represent the binary coded timer value.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1746
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1747 Bits 6 to 8 defines the timer value unit for the GPRS timer as follows:
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1748 8 7 6
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1749 0 0 0 value is incremented in multiples of 10 minutes
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1750 0 0 1 value is incremented in multiples of 1 hour
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1751 0 1 0 value is incremented in multiples of 10 hours
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1752 0 1 1 value is incremented in multiples of 2 seconds
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1753 1 0 0 value is incremented in multiples of 30 seconds
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1754 1 0 1 value is incremented in multiples of 1 minute
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1755 1 1 0 value is incremented in multiples of 320 hours (NOTE 1)
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1756 1 1 1 value indicates that the timer is deactivated (NOTE 2).
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1757 */
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1758 char pt[8+1];// timer value encoded as 3GPP IE
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1759 const int ie_value_max = 0x1f;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1760 uint32_t periodic_timer = 0;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1761 if (periodic_time <= 2*ie_value_max) { // multiples of 2 seconds
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1762 periodic_timer = periodic_time/2;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1763 strcpy(pt, "01100000");
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1764 } else {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1765 if (periodic_time <= 30*ie_value_max) { // multiples of 30 seconds
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1766 periodic_timer = periodic_time/30;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1767 strcpy(pt, "10000000");
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1768 } else {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1769 if (periodic_time <= 60*ie_value_max) { // multiples of 1 minute
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1770 periodic_timer = periodic_time/60;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1771 strcpy(pt, "10100000");
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1772 } else {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1773 if (periodic_time <= 10*60*ie_value_max) { // multiples of 10 minutes
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1774 periodic_timer = periodic_time/(10*60);
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1775 strcpy(pt, "00000000");
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1776 } else {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1777 if (periodic_time <= 60*60*ie_value_max) { // multiples of 1 hour
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1778 periodic_timer = periodic_time/(60*60);
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1779 strcpy(pt, "00100000");
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1780 } else {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1781 if (periodic_time <= 10*60*60*ie_value_max) { // multiples of 10 hours
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1782 periodic_timer = periodic_time/(10*60*60);
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1783 strcpy(pt, "01000000");
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1784 } else { // multiples of 320 hours
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1785 int t = periodic_time / (320*60*60);
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1786 if (t > ie_value_max) {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1787 t = ie_value_max;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1788 }
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1789 periodic_timer = t;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1790 strcpy(pt, "11000000");
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1791 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1792 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1793 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1794 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1795 }
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1796 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1797
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1798 uint_to_binary_str(periodic_timer, &pt[3], sizeof(pt)-3, 5);
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1799 pt[8] = '\0';
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1800
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1801 /**
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1802 Table 10.5.172/3GPP TS 24.008: GPRS Timer information element
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1803
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1804 Bits 5 to 1 represent the binary coded timer value.
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1805
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1806 Bits 6 to 8 defines the timer value unit for the GPRS timer as follows:
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1807
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1808 8 7 6
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1809 0 0 0 value is incremented in multiples of 2 seconds
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1810 0 0 1 value is incremented in multiples of 1 minute
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1811 0 1 0 value is incremented in multiples of decihours
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1812 1 1 1 value indicates that the timer is deactivated.
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1813
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1814 Other values shall be interpreted as multiples of 1 minute in this version of the protocol.
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1815 */
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1816 char at[8+1];
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1817 uint32_t active_timer; // timer value encoded as 3GPP IE
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1818 if (active_time <= 2*ie_value_max) { // multiples of 2 seconds
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1819 active_timer = active_time/2;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1820 strcpy(at, "00000000");
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1821 } else {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1822 if (active_time <= 60*ie_value_max) { // multiples of 1 minute
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1823 active_timer = (1<<5) | (active_time/60);
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1824 strcpy(at, "00100000");
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1825 } else { // multiples of decihours
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1826 int t = active_time / (6*60);
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1827 if (t > ie_value_max) {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1828 t = ie_value_max;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1829 }
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1830 active_timer = t;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1831 strcpy(at, "01000000");
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1832 }
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1833 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1834
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1835 uint_to_binary_str(active_timer, &at[3], sizeof(at)-3, 5);
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1836 at[8] = '\0';
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1837
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1838 if (_at->send("AT+CPSMS=1,,,\"%s\",\"%s\"", pt, at) && _at->recv("OK")) {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1839 if (set_psm_urcs(true)) {//enable the PSM URC
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1840 tr_info("PSM enabled successfully!");
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1841 _psm_status = ENABLED;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1842 return_val = true;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1843 } else {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1844 tr_error("Error enabling PSM URCs, PSM not enabled");
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1845 _at->send("AT+CPSMS=0");
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1846 _at->recv("OK");
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1847 return_val = false;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1848 }
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1849 } else {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1850 tr_error("+CPSMS command failed");
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1851 return_val = false;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1852 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1853 } else {
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1854 tr_error("PSM URCs not supported by this version of modem");
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1855 }
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1856
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1857 at_set_timeout(at_timeout);
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1858 UNLOCK();
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1859 return return_val;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1860 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1861
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1862 bool UbloxCellularBase::is_modem_awake()
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1863 {
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1864 return (_dev_info.modem_psm_state == AWAKE);
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1865 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1866
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1867 //application should call init() or connect() in order to initialize the modem
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1868 void UbloxCellularBase::wakeup_modem()
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1869 {
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1870 LOCK();
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1871
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1872 MBED_ASSERT(_at != NULL);
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1873
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1874 tr_info("Waking up modem...");
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1875
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1876 modem_power_up();
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1877
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1878 _dev_info.reg_status_csd = CSD_NOT_REGISTERED_NOT_SEARCHING;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1879 _dev_info.reg_status_psd = PSD_NOT_REGISTERED_NOT_SEARCHING;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1880 _dev_info.reg_status_eps = EPS_NOT_REGISTERED_NOT_SEARCHING;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1881 _modem_initialised = false;
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1882
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1883 UNLOCK();
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1884 }
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1885
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1886 bool UbloxCellularBase::set_psm_urcs(bool enable)
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1887 {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1888
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1889 bool success = false;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1890 LOCK();
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1891
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1892 MBED_ASSERT(_at != NULL);
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1893
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1894 if (_at->send("AT+UPSMR=%d", enable ? 1 : 0) && _at->recv("OK")) {
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1895 success = true;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1896 }
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1897
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1898 UNLOCK();
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1899 return success;
wajahat.abbas@u-blox.com 33:32fc7c6e2f06 1900 }
wajahat.abbas@u-blox.com 23:eaab8e812a5d 1901 #endif
wajahat.abbas@u-blox.com 29:8a38f91009ad 1902
RobMeades 0:5cffef3371f6 1903 // End of File
RobMeades 0:5cffef3371f6 1904