Vodafone K3770/K3772-Z modems driver & networking library
This library is deprecated. Please use the newest production branch of the library from https://mbed.org/users/mbed_official/code/VodafoneUSBModem/
sms/SMSInterface.h@0:bd5343539e38, 2012-08-17 (annotated)
- Committer:
- donatien
- Date:
- Fri Aug 17 15:21:55 2012 +0000
- Revision:
- 0:bd5343539e38
Initial public commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 0:bd5343539e38 | 1 | /* SMSInterface.h */ |
donatien | 0:bd5343539e38 | 2 | /* Copyright (C) 2012 mbed.org, MIT License |
donatien | 0:bd5343539e38 | 3 | * |
donatien | 0:bd5343539e38 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
donatien | 0:bd5343539e38 | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
donatien | 0:bd5343539e38 | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
donatien | 0:bd5343539e38 | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
donatien | 0:bd5343539e38 | 8 | * furnished to do so, subject to the following conditions: |
donatien | 0:bd5343539e38 | 9 | * |
donatien | 0:bd5343539e38 | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
donatien | 0:bd5343539e38 | 11 | * substantial portions of the Software. |
donatien | 0:bd5343539e38 | 12 | * |
donatien | 0:bd5343539e38 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
donatien | 0:bd5343539e38 | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
donatien | 0:bd5343539e38 | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
donatien | 0:bd5343539e38 | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
donatien | 0:bd5343539e38 | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
donatien | 0:bd5343539e38 | 18 | */ |
donatien | 0:bd5343539e38 | 19 | |
donatien | 0:bd5343539e38 | 20 | #ifndef SMSINTERFACE_H_ |
donatien | 0:bd5343539e38 | 21 | #define SMSINTERFACE_H_ |
donatien | 0:bd5343539e38 | 22 | |
donatien | 0:bd5343539e38 | 23 | #include "core/fwk.h" |
donatien | 0:bd5343539e38 | 24 | |
donatien | 0:bd5343539e38 | 25 | #include "rtos.h" |
donatien | 0:bd5343539e38 | 26 | |
donatien | 0:bd5343539e38 | 27 | #include "at/ATCommandsInterface.h" |
donatien | 0:bd5343539e38 | 28 | |
donatien | 0:bd5343539e38 | 29 | #define MAX_SM 8 |
donatien | 0:bd5343539e38 | 30 | |
donatien | 0:bd5343539e38 | 31 | /** Component to use the Short Messages Service (SMS) |
donatien | 0:bd5343539e38 | 32 | * |
donatien | 0:bd5343539e38 | 33 | */ |
donatien | 0:bd5343539e38 | 34 | class SMSInterface : protected IATCommandsProcessor, IATEventsHandler |
donatien | 0:bd5343539e38 | 35 | { |
donatien | 0:bd5343539e38 | 36 | public: |
donatien | 0:bd5343539e38 | 37 | /** Create SMSInterface instance |
donatien | 0:bd5343539e38 | 38 | @param pIf Pointer to the ATCommandsInterface instance to use |
donatien | 0:bd5343539e38 | 39 | */ |
donatien | 0:bd5343539e38 | 40 | SMSInterface(ATCommandsInterface* pIf); |
donatien | 0:bd5343539e38 | 41 | |
donatien | 0:bd5343539e38 | 42 | /** Initialize interface |
donatien | 0:bd5343539e38 | 43 | Configure SMS commands & register for SMS-related unsolicited result codes |
donatien | 0:bd5343539e38 | 44 | */ |
donatien | 0:bd5343539e38 | 45 | int init(); |
donatien | 0:bd5343539e38 | 46 | |
donatien | 0:bd5343539e38 | 47 | /** Send a SM |
donatien | 0:bd5343539e38 | 48 | @param number The receiver's phone number |
donatien | 0:bd5343539e38 | 49 | @param message The message to send |
donatien | 0:bd5343539e38 | 50 | @return 0 on success, error code on failure |
donatien | 0:bd5343539e38 | 51 | */ |
donatien | 0:bd5343539e38 | 52 | int send(const char* number, const char* message); |
donatien | 0:bd5343539e38 | 53 | |
donatien | 0:bd5343539e38 | 54 | |
donatien | 0:bd5343539e38 | 55 | /** Receive a SM |
donatien | 0:bd5343539e38 | 56 | @param number Pointer to a buffer to store the sender's phone number (must be at least 17 characters-long, including the space for the null-terminating char) |
donatien | 0:bd5343539e38 | 57 | @param message Pointer to a buffer to store the the incoming message |
donatien | 0:bd5343539e38 | 58 | @param maxLength Maximum message length that can be stored in buffer (including null-terminating character) |
donatien | 0:bd5343539e38 | 59 | @return 0 on success, error code on failure |
donatien | 0:bd5343539e38 | 60 | */ |
donatien | 0:bd5343539e38 | 61 | int get(char* number, char* message, size_t maxLength); |
donatien | 0:bd5343539e38 | 62 | |
donatien | 0:bd5343539e38 | 63 | |
donatien | 0:bd5343539e38 | 64 | /** Get the number of SMs in the incoming box |
donatien | 0:bd5343539e38 | 65 | @param pCount pointer to store the number of unprocessed SMs on |
donatien | 0:bd5343539e38 | 66 | @return 0 on success, error code on failure |
donatien | 0:bd5343539e38 | 67 | */ |
donatien | 0:bd5343539e38 | 68 | int getCount(size_t* pCount); |
donatien | 0:bd5343539e38 | 69 | |
donatien | 0:bd5343539e38 | 70 | protected: |
donatien | 0:bd5343539e38 | 71 | //IATCommandsProcessor |
donatien | 0:bd5343539e38 | 72 | virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line); |
donatien | 0:bd5343539e38 | 73 | virtual int onNewEntryPrompt(ATCommandsInterface* pInst); |
donatien | 0:bd5343539e38 | 74 | |
donatien | 0:bd5343539e38 | 75 | //IATEventsHandler |
donatien | 0:bd5343539e38 | 76 | virtual bool isATCodeHandled(const char* atCode); //Is this AT code handled |
donatien | 0:bd5343539e38 | 77 | virtual void onDispatchStart(); |
donatien | 0:bd5343539e38 | 78 | virtual void onDispatchStop(); |
donatien | 0:bd5343539e38 | 79 | virtual void onEvent(const char* atCode, const char* evt); |
donatien | 0:bd5343539e38 | 80 | |
donatien | 0:bd5343539e38 | 81 | //Updates messages count/references |
donatien | 0:bd5343539e38 | 82 | int updateInbox(); |
donatien | 0:bd5343539e38 | 83 | |
donatien | 0:bd5343539e38 | 84 | private: |
donatien | 0:bd5343539e38 | 85 | ATCommandsInterface* m_pIf; |
donatien | 0:bd5343539e38 | 86 | |
donatien | 0:bd5343539e38 | 87 | //Current message |
donatien | 0:bd5343539e38 | 88 | char* m_msg; |
donatien | 0:bd5343539e38 | 89 | size_t m_maxMsgLength; |
donatien | 0:bd5343539e38 | 90 | char* m_msisdn; |
donatien | 0:bd5343539e38 | 91 | |
donatien | 0:bd5343539e38 | 92 | //Messages list |
donatien | 0:bd5343539e38 | 93 | int m_msgRefList[MAX_SM]; |
donatien | 0:bd5343539e38 | 94 | size_t m_msgRefListCount; |
donatien | 0:bd5343539e38 | 95 | bool m_needsUpdate; |
donatien | 0:bd5343539e38 | 96 | Mutex m_inboxMtx; //To protect concurrent accesses btw the user's thread and the AT thread |
donatien | 0:bd5343539e38 | 97 | |
donatien | 0:bd5343539e38 | 98 | enum { SMS_IDLE, SMS_SEND_CMD_SENT, SMS_GET_CMD_SENT, SMS_GET_HDR_RECEIVED, SMS_GET_COUNT_CMD_SENT, SMS_GET_COUNT_HDR_RECEIVED, SMS_CMD_PROCESSED } m_state; |
donatien | 0:bd5343539e38 | 99 | }; |
donatien | 0:bd5343539e38 | 100 | |
donatien | 0:bd5343539e38 | 101 | #endif /* SMSINTERFACE_H_ */ |