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
Diff: sms/SMSInterface.cpp
- Revision:
- 50:8ad4cb12749d
- Parent:
- 46:c2282539c858
- Child:
- 58:f1965f3f4504
diff -r 978bffab17a8 -r 8ad4cb12749d sms/SMSInterface.cpp --- a/sms/SMSInterface.cpp Thu Sep 27 10:13:44 2012 +0000 +++ b/sms/SMSInterface.cpp Thu Sep 27 13:11:44 2012 +0000 @@ -157,29 +157,29 @@ if (m_state != SMS_CMD_PROCESSED) { - WARN(" State variable is not 'SMS_CMD_PROCESSED' - returning 'NET_EMPTY'"); - m_state = SMS_IDLE; - m_inboxMtx.unlock(); - return NET_EMPTY; + WARN("State variable is not 'SMS_CMD_PROCESSED' - returning 'NET_EMPTY'"); } - m_state = SMS_IDLE; - DBG("Deleting message from index number: %d", m_msgRefList[0] ); //Delete message from outbox std::sprintf(cmd, "AT+CMGD=%d", m_msgRefList[0]); ret = m_pIf->executeSimple(cmd, NULL, DEFAULT_TIMEOUT); if(ret != OK) { - m_inboxMtx.unlock(); - WARN("Could not delete message"); + ERR("Could not delete message"); } - else - { //Remove message from list std::memmove(m_msgRefList, m_msgRefList+1, m_msgRefListCount-1); m_msgRefListCount--; - } + + if (m_state != SMS_CMD_PROCESSED) + { + m_state = SMS_IDLE; + m_inboxMtx.unlock(); + return NET_EMPTY; + } + + m_state = SMS_IDLE; m_inboxMtx.unlock(); return OK; @@ -342,18 +342,25 @@ if( std::sscanf(evt, "\"SM\",%d", &msgRef) == 1 ) { DBG("Adding message to list (ref %d)", msgRef); - m_inboxMtx.lock(); - //Add message to list - if(m_msgRefListCount < MAX_SM) + if(m_inboxMtx.trylock()) { - m_msgRefList[m_msgRefListCount] = msgRef; + //Add message to list + if(m_msgRefListCount < MAX_SM) + { + m_msgRefList[m_msgRefListCount] = msgRef; + } + else + { + m_needsUpdate = true; + } + m_msgRefListCount++; //Always count message + m_inboxMtx.unlock(); } else { + WARN("Could not get lock"); m_needsUpdate = true; } - m_msgRefListCount++; //Always count message - m_inboxMtx.unlock(); } } @@ -363,6 +370,7 @@ DBG("Updating inbox"); m_msgRefListCount = 0; //Reset list + m_needsUpdate = false; //Assume we won't need update after this routine (can be set to true by an incoming SM event) //First list the "REC READ" messages that were not processed in the previous session m_state = SMS_GET_COUNT_CMD_SENT; @@ -376,7 +384,7 @@ return NET_PROTOCOL; } - //Now list the "REC UNREAD" messages that were received modem since + //Now list the "REC UNREAD" messages that were received by the modem since m_state = SMS_GET_COUNT_CMD_SENT; ret = m_pIf->execute("AT+CMGL=\"REC UNREAD\"", this, NULL, DEFAULT_TIMEOUT); if( ret != OK ) @@ -394,10 +402,6 @@ { m_needsUpdate = true; } - else - { - m_needsUpdate = false; - } m_state = SMS_IDLE;