2 /* Copyright (C) 2012 mbed.org, MIT License
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:
10 * The above copyright notice and this permission notice shall be included in all copies or
11 * substantial portions of the Software.
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.
20 #ifndef GSMSMSINTERFACE_H_
21 #define GSMSMSINTERFACE_H_
23 #include "SMSInterface.h"
25 /** Component to use the Short Messages Service (SMS)
28 class GSMSMSInterface
: public ISMSInterface
, protected IATCommandsProcessor
, IATEventsHandler
31 /** Create SMSInterface instance
32 @param pIf Pointer to the ATCommandsInterface instance to use
34 GSMSMSInterface(ATCommandsInterface
* pIf
);
36 /** Initialize interface
37 Configure SMS commands & register for SMS-related unsolicited result codes
42 @param number The receiver's phone number
43 @param message The message to send
44 @return 0 on success, error code on failure
46 virtual int send(const char* number
, const char* message
);
50 @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)
51 @param message Pointer to a buffer to store the the incoming message
52 @param maxLength Maximum message length that can be stored in buffer (including null-terminating character)
53 @return 0 on success, error code on failure
55 virtual int get(char* number
, char* message
, size_t maxLength
);
58 /** Get the number of SMs in the incoming box
59 @param pCount pointer to store the number of unprocessed SMs on
60 @return 0 on success, error code on failure
62 virtual int getCount(size_t* pCount
);
65 //IATCommandsProcessor
66 virtual int onNewATResponseLine(ATCommandsInterface
* pInst
, const char* line
);
67 virtual int onNewEntryPrompt(ATCommandsInterface
* pInst
);
70 virtual bool isATCodeHandled(const char* atCode
); //Is this AT code handled
71 virtual void onDispatchStart();
72 virtual void onDispatchStop();
73 virtual char* getEventsEnableCommand();
74 virtual char* getEventsDisableCommand();
75 virtual void onEvent(const char* atCode
, const char* evt
);
77 //Updates messages count/references
81 ATCommandsInterface
* m_pIf
;
85 size_t m_maxMsgLength
;
89 int m_msgRefList
[MAX_SM
];
90 size_t m_msgRefListCount
;
92 Mutex m_inboxMtx
; //To protect concurrent accesses btw the user's thread and the AT thread
94 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
;
97 #endif /* GSMSMSINTERFACE_H_ */