CDMASMSInterface.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 CDMASMSINTERFACE_H_
  20. #define CDMASMSINTERFACE_H_
  21. #include "SMSInterface.h"
  22. #define MAX_SM 8
  23. /** Component to use the Short Messages Service (SMS)
  24. *
  25. */
  26. class CDMASMSInterface : public ISMSInterface, protected IATCommandsProcessor
  27. {
  28. public:
  29. /** Create SMSInterface instance
  30. @param pIf Pointer to the ATCommandsInterface instance to use
  31. */
  32. CDMASMSInterface(ATCommandsInterface* pIf);
  33. /** Initialize interface
  34. Configure SMS commands & register for SMS-related unsolicited result codes
  35. */
  36. virtual int init();
  37. /** Send a SM
  38. @param number The receiver's phone number
  39. @param message The message to send
  40. @return 0 on success, error code on failure
  41. */
  42. virtual int send(const char* number, const char* message);
  43. /** Receive a SM
  44. @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)
  45. @param message Pointer to a buffer to store the the incoming message
  46. @param maxLength Maximum message length that can be stored in buffer (including null-terminating character)
  47. @return 0 on success, error code on failure
  48. */
  49. virtual int get(char* number, char* message, size_t maxLength);
  50. /** Get the number of SMs in the incoming box
  51. @param pCount pointer to store the number of unprocessed SMs on
  52. @return 0 on success, error code on failure
  53. */
  54. virtual int getCount(size_t* pCount);
  55. protected:
  56. //IATCommandsProcessor
  57. virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line);
  58. virtual int onNewEntryPrompt(ATCommandsInterface* pInst);
  59. int updateInbox(); //Update messages count in the different inboxes
  60. private:
  61. ATCommandsInterface* m_pIf;
  62. //Current message
  63. char* m_msg;
  64. size_t m_maxMsgLength;
  65. char* m_msisdn;
  66. //Messages list
  67. size_t m_msgInListsCount[4]; //4 lists
  68. size_t m_headersToRead;
  69. enum { SMS_NONE, SMS_SENT, SMS_PENDING, SMS_FAILED } m_txState;
  70. enum { SMS_IDLE, SMS_SEND_CMD_SENT, SMS_GET_TX_STATUS_CMD_SENT, SMS_GET_CMD_SENT, SMS_GET_HDR_RECEIVED, SMS_GET_COUNT_CMD_SENT, SMS_CMD_PROCESSED } m_state;
  71. };
  72. #endif /* CDMASMSINTERFACE_H_ */