]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/net/cellular/UbloxUSBModem/UbloxModem.h
Chibios: Revert common.mk change (fix AVR linking problem).
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / net / cellular / UbloxUSBModem / UbloxModem.h
1 /* VodafoneUSBModem.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 UBLOXMODEM_H_
21 #define UBLOXMODEM_H_
22
23 #include "core/fwk.h"
24
25 #include "at/ATCommandsInterface.h"
26 #include "ip/PPPIPInterface.h"
27 #include "sms/GSMSMSInterface.h"
28 #include "sms/CDMASMSInterface.h"
29 #include "ussd/USSDInterface.h"
30 #include "link/LinkMonitor.h"
31 #include "CellularModem.h"
32
33 class genericAtProcessor : public IATCommandsProcessor
34 {
35 public:
36 genericAtProcessor();
37 const char* getResponse(void);
38 private:
39 virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line);
40 virtual int onNewEntryPrompt(ATCommandsInterface* pInst);
41 protected:
42 char str[256];
43 int i;
44 };
45
46 /** u-blox WCDMA modem (LISA-U200)
47 */
48 class UbloxModem: public CellularModem
49 {
50 public:
51 /** Create u-blox API instance
52 @param powerGatingPin Optional pin commanding a power gating transistor on the modem's power line
53 @param powerGatingOnWhenPinHigh true if the pin needs to be high to power the dongle, defaults to true
54 */
55 UbloxModem(IOStream* atStream, IOStream* pppStream);
56
57 //Internet-related functions
58
59 /** Open a 3G internet connection
60 @return 0 on success, error code on failure
61 */
62 virtual int connect(const char* apn = NULL, const char* user = NULL, const char* password = NULL);
63
64 /** Close the internet connection
65 @return 0 on success, error code on failure
66 */
67 virtual int disconnect();
68
69
70 /** Send a SM
71 @param number The receiver's phone number
72 @param message The message to send
73 @return 0 on success, error code on failure
74 */
75 virtual int sendSM(const char* number, const char* message);
76
77
78 /** Receive a SM
79 @param number Pointer to a buffer to store the sender's phone number (must be at least 17 characters-long, including the sapce for the null-terminating char)
80 @param message Pointer to a buffer to store the the incoming message
81 @param maxLength Maximum message length that can be stored in buffer (including null-terminating character)
82 @return 0 on success, error code on failure
83 */
84 virtual int getSM(char* number, char* message, size_t maxLength);
85
86 /** Get the number of SMs in the incoming box
87 @param pCount pointer to store the number of unprocessed SMs on
88 @return 0 on success, error code on failure
89 */
90 virtual int getSMCount(size_t* pCount);
91
92 /** Send a USSD command & wait for its result
93 @param command The command to send
94 @param result Buffer in which to store the result
95 @param maxLength Maximum result length that can be stored in buffer (including null-terminating character)
96 @return 0 on success, error code on failure
97 */
98 int sendUSSD(const char* command, char* result, size_t maxLength);
99
100 /** Get link state
101 @param pRssi pointer to store the current RSSI in dBm, between -51 dBm and -113 dBm if known; -51 dBm means -51 dBm or more; -113 dBm means -113 dBm or less; 0 if unknown
102 @param pRegistrationState pointer to store the current registration state
103 @param pBearer pointer to store the current bearer
104 @return 0 on success, error code on failure
105 */
106 int getLinkState(int* pRssi, LinkMonitor::REGISTRATION_STATE* pRegistrationState, LinkMonitor::BEARER* pBearer);
107
108 int getPhoneNumber(char* phoneNumber);
109
110 /** Get the ATCommandsInterface instance
111 @return Pointer to the ATCommandsInterface instance
112 */
113 virtual ATCommandsInterface* getATCommandsInterface();
114
115 protected:
116 /** Initialise dongle.
117 * The following actions are performed:
118 * 1) Start AT interface thread
119 * 2) Wait for network registration
120 */
121 virtual int init();
122
123 /** De-initialise dongle.
124 * The following actions are performed:
125 * 1) Tear down PPP session
126 * 2) Set SMS,USSD, and LinkMonitor subsystems to un-initialised
127 * 3) Close the AT commands interface
128 */
129 virtual int cleanup();
130
131 private:
132 ATCommandsInterface m_at; //< Interface to AT commands processing
133
134 CDMASMSInterface m_CdmaSms; //< Interface to SMS manager (send/receive etc)
135 GSMSMSInterface m_GsmSms; //< Interface to SMS manager (send/receive etc)
136 USSDInterface m_ussd; //< Interface to USSD manager (send etc)
137 LinkMonitor m_linkMonitor; //< Interface to link monitor (RSSI)
138
139 PPPIPInterface m_ppp; //< Interface to PPP conection manager (IP assignment etc)
140
141 bool m_ipInit; //< Has PPIPInterface object (m_ppp) been initialised? true/false
142 bool m_smsInit; //< Has SMSInterface object (m_sms) been initialised? true/false
143 bool m_ussdInit; //< Has USSDInterface object (m_ussd) been initialised? true/false
144 bool m_linkMonitorInit; //< Has LinkMonitor object (m_linkMonitor) been initialised? true/false
145 bool m_atOpen; //< Is the interface to the ATCommandsInterface open? true/false
146 protected:
147 bool m_onePort;
148 enum { LISA_C200, LISA_U200, SARA_G350, UNKNOWN } m_type;
149 };
150
151 #include "WANDongle.h"
152 #include "serial/usb/USBSerialStream.h"
153
154 class UbloxUSBModem: public UbloxModem
155 {
156 public:
157 UbloxUSBModem();
158 virtual int init();
159 virtual int cleanup();
160 virtual int power(bool enable) { return 1; }
161
162 private:
163 WANDongle m_dongle; //< Interface to USB connected WAN dongle
164
165 USBSerialStream m_atStream; //< Serial interface to AT channel on modem
166 USBSerialStream m_pppStream; //< Serial interface to PPP channel on modem
167
168 bool m_dongleConnected; //< Is the dongle physically connected (does the USB stack respond)? true/false
169 };
170
171 #include "serial/io/IOSerialStream.h"
172
173 class UbloxSerModem: public UbloxModem
174 {
175 public:
176 UbloxSerModem();
177 virtual int power(bool enable) { return 1; }
178 private:
179 RawSerial m_Serial;
180 IOSerialStream m_atStream; //< Serial interface to AT channel on modem
181 };
182
183 #endif /* UBLOXMODEM_H_ */
Imprint / Impressum