PHS module SMA-01 library. see: https://developer.mbed.org/users/phsfan/notebook/abitusbmodem/

Dependencies:   Socket lwip-sys lwip

Dependents:   AbitUSBModem_HTTPTest AbitUSBModem_MQTTTest AbitUSBModem_WebsocketTest AbitUSBModem_SMSTest

Fork of VodafoneUSBModem by mbed official

/media/uploads/phsfan/sma01_003.png

Committer:
donatien
Date:
Wed Jul 11 21:25:03 2012 +0000
Revision:
12:66dc2c8eba2d
Parent:
8:04b6a042595f
Child:
22:06fb2a93a1f6
Link Monitoring / Dual serial port support

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:3b2f052c333b 1 /* SMSInterface.cpp */
donatien 0:3b2f052c333b 2 /*
donatien 0:3b2f052c333b 3 Copyright (C) 2012 ARM Limited.
donatien 0:3b2f052c333b 4
donatien 0:3b2f052c333b 5 Permission is hereby granted, free of charge, to any person obtaining a copy of
donatien 0:3b2f052c333b 6 this software and associated documentation files (the "Software"), to deal in
donatien 0:3b2f052c333b 7 the Software without restriction, including without limitation the rights to
donatien 0:3b2f052c333b 8 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
donatien 0:3b2f052c333b 9 of the Software, and to permit persons to whom the Software is furnished to do
donatien 0:3b2f052c333b 10 so, subject to the following conditions:
donatien 0:3b2f052c333b 11
donatien 0:3b2f052c333b 12 The above copyright notice and this permission notice shall be included in all
donatien 0:3b2f052c333b 13 copies or substantial portions of the Software.
donatien 0:3b2f052c333b 14
donatien 0:3b2f052c333b 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
donatien 0:3b2f052c333b 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
donatien 0:3b2f052c333b 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
donatien 0:3b2f052c333b 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
donatien 0:3b2f052c333b 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
donatien 0:3b2f052c333b 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
donatien 0:3b2f052c333b 21 SOFTWARE.
donatien 0:3b2f052c333b 22 */
donatien 0:3b2f052c333b 23
donatien 12:66dc2c8eba2d 24 #define __DEBUG__ 0
donatien 0:3b2f052c333b 25 #ifndef __MODULE__
donatien 0:3b2f052c333b 26 #define __MODULE__ "SMSInterface.cpp"
donatien 0:3b2f052c333b 27 #endif
donatien 0:3b2f052c333b 28
donatien 0:3b2f052c333b 29 #include "core/fwk.h"
donatien 0:3b2f052c333b 30
donatien 0:3b2f052c333b 31 #include "SMSInterface.h"
donatien 0:3b2f052c333b 32
donatien 0:3b2f052c333b 33 #include <cstdio>
donatien 0:3b2f052c333b 34
donatien 0:3b2f052c333b 35 #define DEFAULT_TIMEOUT 10000
donatien 0:3b2f052c333b 36
donatien 0:3b2f052c333b 37 SMSInterface::SMSInterface(ATCommandsInterface* pIf) : m_pIf(pIf), m_msg(NULL), m_maxMsgLength(0), m_msisdn(NULL), /*m_msgCount(0),*/
donatien 0:3b2f052c333b 38 m_msgRefListCount(0), m_needsUpdate(true), m_state(SMS_IDLE)
donatien 0:3b2f052c333b 39 {
donatien 0:3b2f052c333b 40 m_pIf->registerEventsHandler(this); //Add us to the unsolicited result codes handlers
donatien 0:3b2f052c333b 41 }
donatien 0:3b2f052c333b 42
donatien 0:3b2f052c333b 43 int SMSInterface::init()
donatien 0:3b2f052c333b 44 {
donatien 0:3b2f052c333b 45 DBG("Set format");
donatien 0:3b2f052c333b 46 //Set Text mode format
donatien 0:3b2f052c333b 47 int ret = m_pIf->executeSimple("AT+CMGF=1", NULL, DEFAULT_TIMEOUT);
donatien 0:3b2f052c333b 48 if(ret != OK)
donatien 0:3b2f052c333b 49 {
donatien 0:3b2f052c333b 50 return NET_PROTOCOL;
donatien 0:3b2f052c333b 51 }
donatien 0:3b2f052c333b 52
donatien 0:3b2f052c333b 53 DBG("Setup new messages indication");
donatien 0:3b2f052c333b 54 //Setup new messages indication
donatien 0:3b2f052c333b 55 ret = m_pIf->executeSimple("AT+CNMI=2,1,0,0,0", NULL, DEFAULT_TIMEOUT);
donatien 0:3b2f052c333b 56 if(ret != OK)
donatien 0:3b2f052c333b 57 {
donatien 0:3b2f052c333b 58 return NET_PROTOCOL;
donatien 0:3b2f052c333b 59 }
donatien 0:3b2f052c333b 60
donatien 0:3b2f052c333b 61 DBG("Try to fetch inbox");
donatien 0:3b2f052c333b 62 m_inboxMtx.lock();
donatien 0:3b2f052c333b 63 if( m_needsUpdate )
donatien 0:3b2f052c333b 64 {
donatien 0:3b2f052c333b 65 ret = updateInbox(); //Fetch existing messages references
donatien 0:3b2f052c333b 66 if(ret)
donatien 0:3b2f052c333b 67 {
donatien 0:3b2f052c333b 68 m_inboxMtx.unlock();
donatien 0:3b2f052c333b 69 return NET_PROTOCOL;
donatien 0:3b2f052c333b 70 }
donatien 0:3b2f052c333b 71 }
donatien 0:3b2f052c333b 72 m_inboxMtx.unlock();
donatien 0:3b2f052c333b 73
donatien 0:3b2f052c333b 74 DBG("Initialization done");
donatien 0:3b2f052c333b 75 return OK;
donatien 0:3b2f052c333b 76 }
donatien 0:3b2f052c333b 77
donatien 0:3b2f052c333b 78 int SMSInterface::send(const char* number, const char* message)
donatien 0:3b2f052c333b 79 {
donatien 0:3b2f052c333b 80 if( strlen(number) > 16 )
donatien 0:3b2f052c333b 81 {
donatien 0:3b2f052c333b 82 return NET_INVALID; //Number too long to match 3GPP spec
donatien 0:3b2f052c333b 83 }
donatien 0:3b2f052c333b 84
donatien 0:3b2f052c333b 85 int ret;
donatien 0:3b2f052c333b 86
donatien 0:3b2f052c333b 87 //Prepare infos
donatien 0:3b2f052c333b 88 m_state = SMS_SEND_CMD_SENT;
donatien 0:3b2f052c333b 89 m_msg = (char*) message;
donatien 0:3b2f052c333b 90
donatien 0:3b2f052c333b 91 DBG("Send SM");
donatien 0:3b2f052c333b 92 //Send command
donatien 0:3b2f052c333b 93 char cmd[32];
donatien 0:3b2f052c333b 94 std::sprintf(cmd, "AT+CMGS=\"%s\"", number);
donatien 0:3b2f052c333b 95 ret = m_pIf->execute(cmd, this, NULL, DEFAULT_TIMEOUT);
donatien 0:3b2f052c333b 96
donatien 0:3b2f052c333b 97 if( (ret != OK) || (m_state != SMS_CMD_PROCESSED) )
donatien 0:3b2f052c333b 98 {
donatien 0:3b2f052c333b 99 WARN("ret %d, state %d", ret, m_state);
donatien 0:3b2f052c333b 100 m_state = SMS_IDLE;
donatien 0:3b2f052c333b 101 return NET_PROTOCOL;
donatien 0:3b2f052c333b 102 }
donatien 0:3b2f052c333b 103
donatien 0:3b2f052c333b 104 DBG("SM sent");
donatien 0:3b2f052c333b 105 m_state = SMS_IDLE;
donatien 0:3b2f052c333b 106 return OK;
donatien 0:3b2f052c333b 107 }
donatien 0:3b2f052c333b 108
donatien 0:3b2f052c333b 109
donatien 0:3b2f052c333b 110 int SMSInterface::get(char* number, char* message, size_t maxLength)
donatien 0:3b2f052c333b 111 {
donatien 0:3b2f052c333b 112 if( maxLength < 1 )
donatien 0:3b2f052c333b 113 {
donatien 0:3b2f052c333b 114 return NET_INVALID; //Buffer too short
donatien 0:3b2f052c333b 115 }
donatien 0:3b2f052c333b 116
donatien 0:3b2f052c333b 117 int ret;
donatien 0:3b2f052c333b 118
donatien 0:3b2f052c333b 119 DBG("Get next message");
donatien 0:3b2f052c333b 120 m_inboxMtx.lock();
donatien 0:3b2f052c333b 121 if(m_msgRefListCount == 0 && m_needsUpdate)
donatien 0:3b2f052c333b 122 {
donatien 0:3b2f052c333b 123 ret = updateInbox();
donatien 0:3b2f052c333b 124 if (ret)
donatien 0:3b2f052c333b 125 {
donatien 0:3b2f052c333b 126 m_inboxMtx.unlock();
donatien 0:3b2f052c333b 127 return ret;
donatien 0:3b2f052c333b 128 }
donatien 0:3b2f052c333b 129 }
donatien 0:3b2f052c333b 130
donatien 0:3b2f052c333b 131 if(m_msgRefListCount == 0)
donatien 0:3b2f052c333b 132 {
donatien 0:3b2f052c333b 133 m_inboxMtx.unlock();
donatien 0:3b2f052c333b 134 return NET_EMPTY; //No message to read
donatien 0:3b2f052c333b 135 }
donatien 0:3b2f052c333b 136
donatien 0:3b2f052c333b 137 //Prepare infos
donatien 0:3b2f052c333b 138 m_state = SMS_GET_CMD_SENT;
donatien 0:3b2f052c333b 139 m_msisdn = (char*) number;
donatien 0:3b2f052c333b 140 m_msg = (char*) message;
donatien 0:3b2f052c333b 141 m_maxMsgLength = maxLength;
donatien 0:3b2f052c333b 142
donatien 0:3b2f052c333b 143 DBG("Get SMS");
donatien 0:3b2f052c333b 144 //List command
donatien 0:3b2f052c333b 145 char cmd[32];
donatien 0:3b2f052c333b 146 std::sprintf(cmd, "AT+CMGR=%d", m_msgRefList[0]);
donatien 0:3b2f052c333b 147 ret = m_pIf->execute(cmd, this, NULL, DEFAULT_TIMEOUT);
donatien 0:3b2f052c333b 148 if( ret != OK )
donatien 0:3b2f052c333b 149 {
donatien 0:3b2f052c333b 150 WARN("AT+CMGR returned %d", ret);
donatien 0:3b2f052c333b 151 m_state = SMS_IDLE;
donatien 0:3b2f052c333b 152 m_inboxMtx.unlock();
donatien 0:3b2f052c333b 153 return NET_PROTOCOL;
donatien 0:3b2f052c333b 154 }
donatien 0:3b2f052c333b 155
donatien 0:3b2f052c333b 156 if (m_state != SMS_CMD_PROCESSED)
donatien 0:3b2f052c333b 157 {
donatien 0:3b2f052c333b 158 m_state = SMS_IDLE;
donatien 0:3b2f052c333b 159 m_inboxMtx.unlock();
donatien 0:3b2f052c333b 160 return NET_EMPTY;
donatien 0:3b2f052c333b 161 }
donatien 0:3b2f052c333b 162
donatien 0:3b2f052c333b 163 m_state = SMS_IDLE;
donatien 0:3b2f052c333b 164
donatien 0:3b2f052c333b 165 DBG("Deleting message");
donatien 0:3b2f052c333b 166 //Delete message from outbox
donatien 0:3b2f052c333b 167 std::sprintf(cmd, "AT+CMGD=%d", m_msgRefList[0]);
donatien 0:3b2f052c333b 168 ret = m_pIf->executeSimple(cmd, NULL, DEFAULT_TIMEOUT);
donatien 0:3b2f052c333b 169 if(ret != OK)
donatien 0:3b2f052c333b 170 {
donatien 0:3b2f052c333b 171 m_inboxMtx.unlock();
donatien 0:3b2f052c333b 172 WARN("Could not delete message");
donatien 0:3b2f052c333b 173 }
donatien 0:3b2f052c333b 174
donatien 0:3b2f052c333b 175 //Remove message from list
donatien 0:3b2f052c333b 176 std::memmove(m_msgRefList, m_msgRefList+1, m_msgRefListCount-1);
donatien 0:3b2f052c333b 177 m_msgRefListCount--;
donatien 0:3b2f052c333b 178
donatien 0:3b2f052c333b 179 m_inboxMtx.unlock();
donatien 0:3b2f052c333b 180
donatien 0:3b2f052c333b 181 return OK;
donatien 0:3b2f052c333b 182 }
donatien 0:3b2f052c333b 183
donatien 0:3b2f052c333b 184
donatien 0:3b2f052c333b 185 int SMSInterface::getCount(size_t* pCount)
donatien 0:3b2f052c333b 186 {
donatien 0:3b2f052c333b 187 int ret;
donatien 0:3b2f052c333b 188
donatien 0:3b2f052c333b 189 m_inboxMtx.lock();
donatien 0:3b2f052c333b 190 if( m_needsUpdate )
donatien 0:3b2f052c333b 191 {
donatien 0:3b2f052c333b 192 ret = updateInbox();
donatien 0:3b2f052c333b 193 if(ret)
donatien 0:3b2f052c333b 194 {
donatien 0:3b2f052c333b 195 m_inboxMtx.unlock();
donatien 0:3b2f052c333b 196 return NET_PROTOCOL;
donatien 0:3b2f052c333b 197 }
donatien 0:3b2f052c333b 198 }
donatien 0:3b2f052c333b 199
donatien 0:3b2f052c333b 200 *pCount = m_msgRefListCount;
donatien 0:3b2f052c333b 201 m_inboxMtx.unlock();
donatien 0:3b2f052c333b 202
donatien 0:3b2f052c333b 203 return OK;
donatien 0:3b2f052c333b 204 }
donatien 0:3b2f052c333b 205
donatien 0:3b2f052c333b 206
donatien 0:3b2f052c333b 207 /*virtual*/ int SMSInterface::onNewATResponseLine(ATCommandsInterface* pInst, const char* line)
donatien 0:3b2f052c333b 208 {
donatien 0:3b2f052c333b 209 if(m_state == SMS_SEND_CMD_SENT)
donatien 0:3b2f052c333b 210 {
donatien 0:3b2f052c333b 211 if( std::sscanf(line, "+CMGS: %*d") == 0 )
donatien 0:3b2f052c333b 212 {
donatien 0:3b2f052c333b 213 DBG("SM sent");
donatien 0:3b2f052c333b 214 m_state = SMS_CMD_PROCESSED;
donatien 0:3b2f052c333b 215 }
donatien 0:3b2f052c333b 216 }
donatien 0:3b2f052c333b 217 else if(m_state == SMS_GET_CMD_SENT)
donatien 0:3b2f052c333b 218 {
donatien 0:3b2f052c333b 219 DBG("Header: %s", line);
donatien 0:3b2f052c333b 220 if( std::sscanf(line, "+CMGR: %*[^,],\"%16[^\"]\"", m_msisdn) == 1 ) //Get message ref
donatien 0:3b2f052c333b 221 {
donatien 0:3b2f052c333b 222 m_state = SMS_GET_HDR_RECEIVED;
donatien 0:3b2f052c333b 223 }
donatien 0:3b2f052c333b 224 }
donatien 0:3b2f052c333b 225 else if(m_state == SMS_GET_HDR_RECEIVED)
donatien 0:3b2f052c333b 226 {
donatien 0:3b2f052c333b 227 DBG("Message: %s", line);
donatien 0:3b2f052c333b 228 size_t cpyLen = MIN( std::strlen(line), m_maxMsgLength - 1 );
donatien 0:3b2f052c333b 229 std::memcpy( m_msg, line, cpyLen );
donatien 0:3b2f052c333b 230 m_msg[cpyLen] = '\0';
donatien 0:3b2f052c333b 231 m_state = SMS_CMD_PROCESSED;
donatien 0:3b2f052c333b 232 }
donatien 0:3b2f052c333b 233 else if(m_state == SMS_GET_COUNT_CMD_SENT)
donatien 0:3b2f052c333b 234 {
donatien 0:3b2f052c333b 235 DBG("Header: %s", line);
donatien 0:3b2f052c333b 236 int msgRef;
donatien 0:3b2f052c333b 237 if( std::sscanf(line, "+CMGL: %d", &msgRef) == 1 )
donatien 0:3b2f052c333b 238 {
donatien 0:3b2f052c333b 239 m_state = SMS_GET_COUNT_HDR_RECEIVED;
donatien 0:3b2f052c333b 240 //Add message to list
donatien 0:3b2f052c333b 241 if(m_msgRefListCount < MAX_SM)
donatien 0:3b2f052c333b 242 {
donatien 0:3b2f052c333b 243 m_msgRefList[m_msgRefListCount] = msgRef;
donatien 0:3b2f052c333b 244 }
donatien 0:3b2f052c333b 245 m_msgRefListCount++; //Always count message
donatien 0:3b2f052c333b 246 DBG("m_msgRefListCount=%d",m_msgRefListCount);
donatien 0:3b2f052c333b 247 }
donatien 0:3b2f052c333b 248 }
donatien 0:3b2f052c333b 249 else if(m_state == SMS_GET_COUNT_HDR_RECEIVED)
donatien 0:3b2f052c333b 250 {
donatien 0:3b2f052c333b 251 DBG("Message (debug only): %s", line); //For debug only
donatien 0:3b2f052c333b 252 m_state = SMS_GET_COUNT_CMD_SENT;
donatien 0:3b2f052c333b 253 }
donatien 0:3b2f052c333b 254 return OK;
donatien 0:3b2f052c333b 255 }
donatien 0:3b2f052c333b 256
donatien 0:3b2f052c333b 257 /*virtual*/ int SMSInterface::onNewEntryPrompt(ATCommandsInterface* pInst)
donatien 0:3b2f052c333b 258 {
donatien 0:3b2f052c333b 259 if(m_state == SMS_SEND_CMD_SENT)
donatien 0:3b2f052c333b 260 {
donatien 0:3b2f052c333b 261 char* crPtr = strchr(m_msg, CR);
donatien 0:3b2f052c333b 262 if(crPtr != NULL)
donatien 0:3b2f052c333b 263 {
donatien 0:3b2f052c333b 264 int crPos = crPtr - m_msg;
donatien 0:3b2f052c333b 265 //Replace m_inputBuf[crPos] with null-terminating char
donatien 0:3b2f052c333b 266 m_msg[crPos] = '\x0';
donatien 0:3b2f052c333b 267
donatien 0:3b2f052c333b 268 //If there is a CR char, split message there
donatien 0:3b2f052c333b 269
donatien 0:3b2f052c333b 270 //Do print the message
donatien 0:3b2f052c333b 271 int ret = pInst->sendData(m_msg);
donatien 0:3b2f052c333b 272 if(ret)
donatien 0:3b2f052c333b 273 {
donatien 0:3b2f052c333b 274 return ret;
donatien 0:3b2f052c333b 275 }
donatien 0:3b2f052c333b 276
donatien 0:3b2f052c333b 277 char cr[2] = {CR, '\0'};
donatien 0:3b2f052c333b 278 ret = pInst->sendData(cr);
donatien 0:3b2f052c333b 279 if(ret)
donatien 0:3b2f052c333b 280 {
donatien 0:3b2f052c333b 281 return ret;
donatien 0:3b2f052c333b 282 }
donatien 0:3b2f052c333b 283
donatien 0:3b2f052c333b 284 m_msg += crPos;
donatien 0:3b2f052c333b 285
donatien 0:3b2f052c333b 286 if(m_msg[0] == LF)
donatien 0:3b2f052c333b 287 {
donatien 0:3b2f052c333b 288 m_msg++; //Discard LF char as well
donatien 0:3b2f052c333b 289 }
donatien 0:3b2f052c333b 290
donatien 0:3b2f052c333b 291 return NET_MOREINFO;
donatien 0:3b2f052c333b 292 }
donatien 0:3b2f052c333b 293 else
donatien 0:3b2f052c333b 294 {
donatien 0:3b2f052c333b 295 //Do print the message
donatien 0:3b2f052c333b 296 pInst->sendData(m_msg);
donatien 0:3b2f052c333b 297 return OK;
donatien 0:3b2f052c333b 298 }
donatien 0:3b2f052c333b 299 }
donatien 0:3b2f052c333b 300
donatien 0:3b2f052c333b 301 return OK;
donatien 0:3b2f052c333b 302 }
donatien 0:3b2f052c333b 303
donatien 0:3b2f052c333b 304 /*virtual*/ bool SMSInterface::isATCodeHandled(const char* atCode) //Is this AT code handled
donatien 0:3b2f052c333b 305 {
donatien 0:3b2f052c333b 306 DBG("AT code is %s", atCode);
donatien 0:3b2f052c333b 307 if( strcmp("+CMTI", atCode) == 0 )
donatien 0:3b2f052c333b 308 {
donatien 0:3b2f052c333b 309 return true;
donatien 0:3b2f052c333b 310 }
donatien 0:3b2f052c333b 311
donatien 0:3b2f052c333b 312 DBG("Not handled");
donatien 0:3b2f052c333b 313 return false;
donatien 0:3b2f052c333b 314 }
donatien 0:3b2f052c333b 315
donatien 0:3b2f052c333b 316 /*virtual*/ void SMSInterface::onDispatchStart()
donatien 0:3b2f052c333b 317 {
donatien 0:3b2f052c333b 318
donatien 0:3b2f052c333b 319
donatien 0:3b2f052c333b 320 }
donatien 0:3b2f052c333b 321
donatien 0:3b2f052c333b 322 /*virtual*/ void SMSInterface::onDispatchStop()
donatien 0:3b2f052c333b 323 {
donatien 0:3b2f052c333b 324
donatien 0:3b2f052c333b 325 }
donatien 0:3b2f052c333b 326
donatien 0:3b2f052c333b 327 /*virtual*/ void SMSInterface::onEvent(const char* atCode, const char* evt)
donatien 0:3b2f052c333b 328 {
donatien 0:3b2f052c333b 329 if( strcmp("+CMTI", atCode) != 0 )
donatien 0:3b2f052c333b 330 {
donatien 0:3b2f052c333b 331 return; //Not supported
donatien 0:3b2f052c333b 332 }
donatien 0:3b2f052c333b 333
donatien 0:3b2f052c333b 334 DBG("Unsollicited result code: %s - %s", atCode, evt);
donatien 0:3b2f052c333b 335
donatien 0:3b2f052c333b 336 //Get index
donatien 0:3b2f052c333b 337 int msgRef;
donatien 0:3b2f052c333b 338 if( std::sscanf(evt, "\"SM\",%d", &msgRef) == 1 )
donatien 0:3b2f052c333b 339 {
donatien 0:3b2f052c333b 340 DBG("Adding message to list (ref %d)", msgRef);
donatien 0:3b2f052c333b 341 m_inboxMtx.lock();
donatien 0:3b2f052c333b 342 //Add message to list
donatien 0:3b2f052c333b 343 if(m_msgRefListCount < MAX_SM)
donatien 0:3b2f052c333b 344 {
donatien 0:3b2f052c333b 345 m_msgRefList[m_msgRefListCount] = msgRef;
donatien 0:3b2f052c333b 346 }
donatien 0:3b2f052c333b 347 else
donatien 0:3b2f052c333b 348 {
donatien 0:3b2f052c333b 349 m_needsUpdate = true;
donatien 0:3b2f052c333b 350 }
donatien 0:3b2f052c333b 351 m_msgRefListCount++; //Always count message
donatien 0:3b2f052c333b 352 m_inboxMtx.unlock();
donatien 0:3b2f052c333b 353 }
donatien 0:3b2f052c333b 354 }
donatien 0:3b2f052c333b 355
donatien 0:3b2f052c333b 356 int SMSInterface::updateInbox()
donatien 0:3b2f052c333b 357 {
donatien 0:3b2f052c333b 358 //Get memory indexes of unread messages
donatien 0:3b2f052c333b 359 m_state = SMS_GET_COUNT_CMD_SENT;
donatien 0:3b2f052c333b 360
donatien 0:3b2f052c333b 361 DBG("Updating inbox");
donatien 0:3b2f052c333b 362 m_msgRefListCount = 0; //Reset list
donatien 0:3b2f052c333b 363
donatien 0:3b2f052c333b 364 int ret = m_pIf->execute("AT+CMGL=\"REC UNREAD\"", this, NULL, DEFAULT_TIMEOUT);
donatien 0:3b2f052c333b 365 if( ret != OK )
donatien 0:3b2f052c333b 366 {
donatien 0:3b2f052c333b 367 WARN("AT+CMGL returned %d", ret);
donatien 0:3b2f052c333b 368 m_state = SMS_IDLE;
donatien 0:3b2f052c333b 369 m_msgRefListCount = 0; //List could be invalid
donatien 0:3b2f052c333b 370 m_needsUpdate = true;
donatien 0:3b2f052c333b 371 return NET_PROTOCOL;
donatien 0:3b2f052c333b 372 }
donatien 0:3b2f052c333b 373
donatien 0:3b2f052c333b 374 DBG("%d incoming messages in inbox", m_msgRefListCount);
donatien 0:3b2f052c333b 375
donatien 0:3b2f052c333b 376 if( m_msgRefListCount > MAX_SM )
donatien 0:3b2f052c333b 377 {
donatien 0:3b2f052c333b 378 m_needsUpdate = true;
donatien 0:3b2f052c333b 379 }
donatien 0:3b2f052c333b 380 else
donatien 0:3b2f052c333b 381 {
donatien 0:3b2f052c333b 382 m_needsUpdate = false;
donatien 0:3b2f052c333b 383 }
donatien 0:3b2f052c333b 384
donatien 0:3b2f052c333b 385 m_state = SMS_IDLE;
donatien 0:3b2f052c333b 386
donatien 0:3b2f052c333b 387 return OK;
donatien 0:3b2f052c333b 388 }
donatien 0:3b2f052c333b 389
donatien 0:3b2f052c333b 390