]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/net/cellular/UbloxUSBModem/UbloxUSBGSMModem.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / net / cellular / UbloxUSBModem / UbloxUSBGSMModem.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 UBLOXUSBGSMMODEM_H_
21 #define UBLOXUSBGSMMODEM_H_
22
23 #include "core/fwk.h"
24
25 #include "WANDongle.h"
26 #include "at/ATCommandsInterface.h"
27 #include "serial/usb/USBSerialStream.h"
28 #include "ip/PPPIPInterface.h"
29 #include "sms/GSMSMSInterface.h"
30 #include "ussd/USSDInterface.h"
31 #include "link/LinkMonitor.h"
32 #include "CellularModem.h"
33
34 /** u-blox WCDMA modem (LISA-U200)
35  */
36 class UbloxUSBGSMModem: public CellularModem
37 {
38 public:
39   /** Create u-blox API instance
40       @param powerGatingPin Optional pin commanding a power gating transistor on the modem's power line 
41       @param powerGatingOnWhenPinHigh true if the pin needs to be high to power the dongle, defaults to true
42    */
43   UbloxUSBGSMModem(PinName powerGatingPin = NC, bool powerGatingOnWhenPinHigh = true);
44
45   //Internet-related functions
46
47   /** Open a 3G internet connection
48       @return 0 on success, error code on failure
49   */
50   virtual int connect(const char* apn = NULL, const char* user = NULL, const char* password = NULL);
51
52   /** Close the internet connection
53      @return 0 on success, error code on failure
54   */
55   virtual int disconnect();
56
57
58   /** Send a SM
59      @param number The receiver's phone number
60      @param message The message to send
61      @return 0 on success, error code on failure
62    */
63   virtual int sendSM(const char* number, const char* message);
64
65
66   /** Receive a SM
67      @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)
68      @param message Pointer to a buffer to store the the incoming message
69      @param maxLength Maximum message length that can be stored in buffer (including null-terminating character)
70      @return 0 on success, error code on failure
71    */
72   virtual int getSM(char* number, char* message, size_t maxLength);
73
74   /** Get the number of SMs in the incoming box
75      @param pCount pointer to store the number of unprocessed SMs on
76      @return 0 on success, error code on failure
77    */
78   virtual int getSMCount(size_t* pCount);
79
80   /** Send a USSD command & wait for its result
81     @param command The command to send
82     @param result Buffer in which to store the result
83     @param maxLength Maximum result length that can be stored in buffer (including null-terminating character)
84     @return 0 on success, error code on failure
85   */
86   int sendUSSD(const char* command, char* result, size_t maxLength);
87   
88   /** Get link state
89     @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
90     @param pRegistrationState pointer to store the current registration state
91     @param pBearer pointer to store the current bearer
92     @return 0 on success, error code on failure
93   */
94   int getLinkState(int* pRssi, LinkMonitor::REGISTRATION_STATE* pRegistrationState, LinkMonitor::BEARER* pBearer);  
95
96   /** Get the ATCommandsInterface instance
97     @return Pointer to the ATCommandsInterface instance
98    */
99   virtual ATCommandsInterface* getATCommandsInterface();
100   
101   /** Switch power on or off
102     In order to use this function, a pin name must have been entered in the constructor
103     @param enable true to switch the dongle on, false to switch it off
104     @return 0 on success, error code on failure
105   */
106   virtual int power(bool enable);
107
108 protected:
109   bool power(); //< Turn power to USB dongle ON.
110
111   /** Initialise dongle.
112    * The following actions are performed:
113    * 1) Power up
114    * 2) Establish USB connection to dongle
115    * 3) Start AT interface thread
116    * 4) Wait for network registration
117    */
118   int init();
119   
120   /** De-initialise dongle.
121    * The following actions are performed:
122    * 1) Tear down PPP session
123    * 2) Set SMS,USSD, and LinkMonitor subsystems to un-initialised
124    * 3) Close the AT commands interface
125    * 4) Tear down the USB connection to dongle
126    */
127   int cleanup();
128
129 private:
130   WANDongle m_dongle;          //< Interface to USB connected WAN dongle
131   
132   USBSerialStream m_atStream;  //< Serial interface to AT channel on modem
133   USBSerialStream m_pppStream; //< Serial interface to PPP channel on modem
134   
135   ATCommandsInterface m_at;    //< Interface to AT commands processing
136   
137   GSMSMSInterface m_sms;       //< Interface to SMS manager (send/receive etc)
138   USSDInterface m_ussd;        //< Interface to USSD manager (send etc)
139   LinkMonitor m_linkMonitor;   //< Interface to link monitor (RSSI)
140   
141   PPPIPInterface m_ppp;        //< Interface to PPP conection manager (IP assignment etc)
142
143   bool m_dongleConnected; //< Is the dongle physically connected (does the USB stack respond)? true/false
144   bool m_ipInit;          //< Has PPIPInterface object (m_ppp) been initialised? true/false
145   bool m_smsInit;         //< Has SMSInterface object (m_sms) been initialised? true/false
146   bool m_ussdInit;        //< Has USSDInterface object (m_ussd) been initialised? true/false
147   bool m_linkMonitorInit; //< Has LinkMonitor object (m_linkMonitor) been initialised? true/false
148   bool m_atOpen;          //< Is the interface to the ATCommandsInterface open? true/false
149   
150   PinName m_powerGatingPin;        //< Pin which toggles power gating
151   bool m_powerGatingOnWhenPinHigh; //< Semantics of power gating (whether high or low toggles power gating)
152 };
153
154
155 #endif /* UBLOXMODEM_H_ */