Nicholas Herriot / VodafoneK3770Lib
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SMSInterface.h Source File

SMSInterface.h

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