]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/net/cellular/CellularModem/sms/GSMSMSInterface.h
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / net / cellular / CellularModem / sms / GSMSMSInterface.h
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
20 #ifndef GSMSMSINTERFACE_H_
21 #define GSMSMSINTERFACE_H_
22
23 #include "SMSInterface.h"
24
25 /** Component to use the Short Messages Service (SMS)
26 *
27 */
28 class GSMSMSInterface : public ISMSInterface, protected IATCommandsProcessor, IATEventsHandler
29 {
30 public:
31 /** Create SMSInterface instance
32 @param pIf Pointer to the ATCommandsInterface instance to use
33 */
34 GSMSMSInterface(ATCommandsInterface* pIf);
35
36 /** Initialize interface
37 Configure SMS commands & register for SMS-related unsolicited result codes
38 */
39 virtual int init();
40
41 /** Send a SM
42 @param number The receiver's phone number
43 @param message The message to send
44 @return 0 on success, error code on failure
45 */
46 virtual int send(const char* number, const char* message);
47
48
49 /** Receive a SM
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
54 */
55 virtual int get(char* number, char* message, size_t maxLength);
56
57
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
61 */
62 virtual int getCount(size_t* pCount);
63
64 protected:
65 //IATCommandsProcessor
66 virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line);
67 virtual int onNewEntryPrompt(ATCommandsInterface* pInst);
68
69 //IATEventsHandler
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);
76
77 //Updates messages count/references
78 int updateInbox();
79
80 private:
81 ATCommandsInterface* m_pIf;
82
83 //Current message
84 char* m_msg;
85 size_t m_maxMsgLength;
86 char* m_msisdn;
87
88 //Messages list
89 int m_msgRefList[MAX_SM];
90 size_t m_msgRefListCount;
91 bool m_needsUpdate;
92 Mutex m_inboxMtx; //To protect concurrent accesses btw the user's thread and the AT thread
93
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;
95 };
96
97 #endif /* GSMSMSINTERFACE_H_ */
Imprint / Impressum