Base library for cellular modem implementations

Dependencies:   Socket lwip-sys lwip

Dependents:   CellularUSBModem CellularUSBModem

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers GSMSMSInterface.h Source File

GSMSMSInterface.h

00001 /* SMSInterface.h */
00002 /* Copyright (C) 2012 mbed.org, MIT License
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00005  * and associated documentation files (the "Software"), to deal in the Software without restriction,
00006  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00007  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00008  * furnished to do so, subject to the following conditions:
00009  *
00010  * The above copyright notice and this permission notice shall be included in all copies or
00011  * substantial portions of the Software.
00012  *
00013  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00014  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00015  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00016  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00017  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00018  */
00019 
00020 #ifndef GSMSMSINTERFACE_H_
00021 #define GSMSMSINTERFACE_H_
00022 
00023 #include "SMSInterface.h"
00024 
00025 /** Component to use the Short Messages Service (SMS)
00026  *
00027  */
00028 class GSMSMSInterface : public ISMSInterface, protected IATCommandsProcessor, IATEventsHandler
00029 {
00030 public:
00031   /** Create SMSInterface instance
00032      @param pIf Pointer to the ATCommandsInterface instance to use
00033    */
00034   GSMSMSInterface(ATCommandsInterface* pIf);
00035 
00036   /** Initialize interface
00037     Configure SMS commands & register for SMS-related unsolicited result codes
00038    */
00039   virtual int init();
00040 
00041   /** Send a SM
00042      @param number The receiver's phone number
00043      @param message The message to send
00044      @return 0 on success, error code on failure
00045    */
00046   virtual int send(const char* number, const char* message);
00047 
00048 
00049   /** Receive a SM
00050      @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)
00051      @param message Pointer to a buffer to store the the incoming message
00052      @param maxLength Maximum message length that can be stored in buffer (including null-terminating character)
00053      @return 0 on success, error code on failure
00054    */
00055   virtual int get(char* number, char* message, size_t maxLength);
00056 
00057 
00058   /** Get the number of SMs in the incoming box
00059      @param pCount pointer to store the number of unprocessed SMs on
00060      @return 0 on success, error code on failure
00061    */
00062   virtual int getCount(size_t* pCount);
00063 
00064 protected:
00065   //IATCommandsProcessor
00066   virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line);
00067   virtual int onNewEntryPrompt(ATCommandsInterface* pInst);
00068 
00069   //IATEventsHandler
00070   virtual bool isATCodeHandled(const char* atCode); //Is this AT code handled
00071   virtual void onDispatchStart();
00072   virtual void onDispatchStop();
00073   virtual char* getEventsEnableCommand();
00074   virtual char* getEventsDisableCommand();
00075   virtual void onEvent(const char* atCode, const char* evt);
00076 
00077   //Updates messages count/references
00078   int updateInbox();
00079 
00080 private:
00081   ATCommandsInterface* m_pIf;
00082 
00083   //Current message
00084   char* m_msg;
00085   size_t m_maxMsgLength;
00086   char* m_msisdn;
00087 
00088   //Messages list
00089   int m_msgRefList[MAX_SM];
00090   size_t m_msgRefListCount;
00091   bool m_needsUpdate;
00092   Mutex m_inboxMtx; //To protect concurrent accesses btw the user's thread and the AT thread
00093 
00094   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;
00095 };
00096 
00097 #endif /* GSMSMSINTERFACE_H_ */