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