GSMSMSInterface.h 3.6 KB

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