ublox-cellular-base_r4

Committer:
wajahat.abbas@u-blox.com
Date:
Wed Sep 04 15:36:23 2019 +0500
Revision:
32:9497868cf171
Parent:
31:b0a6a610d114
Child:
33:093da9fe13ed
SARA-R4: MNO profile 0 is not supposed to be used

Who changed what in which revision?

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