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 USSDINTERFACE_H_
21 #define USSDINTERFACE_H_
27 #include "at/ATCommandsInterface.h"
29 /** Component to send/receive Unstructured Supplementary Service Data (USSD)
32 class USSDInterface
: protected IATCommandsProcessor
, IATEventsHandler
35 /** Create USSDInterface instance
36 @param pIf Pointer to the ATCommandsInterface instance to use
38 USSDInterface(ATCommandsInterface
* pIf
);
40 /** Initialize interface
41 Configure USSD commands & register for USSD-related unsolicited result codes
45 /** Send a USSD command & wait for its result
46 @param command The command to send
47 @param result Buffer in which to store the result
48 @param maxLength Maximum result length that can be stored in buffer (including null-terminating character)
49 @return 0 on success, error code on failure
51 int send(const char* command
, char* result
, size_t maxLength
);
54 //IATCommandsProcessor, needed for implementations of 3GGP standard < r06
55 virtual int onNewATResponseLine(ATCommandsInterface
* pInst
, const char* line
);
56 virtual int onNewEntryPrompt(ATCommandsInterface
* pInst
);
58 //IATEventsHandler, needed for implementations of 3GGP standard >= r06
59 virtual bool isATCodeHandled(const char* atCode
); //Is this AT code handled
60 virtual void onDispatchStart();
61 virtual void onDispatchStop();
62 virtual char* getEventsEnableCommand();
63 virtual char* getEventsDisableCommand();
64 virtual void onEvent(const char* atCode
, const char* evt
);
67 void processResult(const char* data
);
69 ATCommandsInterface
* m_pIf
;
70 Mutex m_responseMtx
; //To protect concurrent accesses btw the user's thread and the AT thread
71 Semaphore m_responseSphre
;
74 volatile char* m_result
;
75 volatile size_t m_maxResultLength
;
80 #endif /* USSDINTERFACE_H_ */