u-blox USB modems (GSM and CDMA)

Dependencies:   CellularUSBModem

Dependents:   C027_CANInterfaceComm C027_ModemTransparentUSBCDC_revb UbloxModemHTTPClientTest C027_HTTPClientTest ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers UbloxUSBGSMModem.h Source File

UbloxUSBGSMModem.h

00001 /* VodafoneUSBModem.h */
00002 /* Copyright (C) 2012 mbed.org, MIT License
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00005  * and associated documentation files (the "Software"), to deal in the Software without restriction,
00006  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00007  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00008  * furnished to do so, subject to the following conditions:
00009  *
00010  * The above copyright notice and this permission notice shall be included in all copies or
00011  * substantial portions of the Software.
00012  *
00013  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00014  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00015  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00016  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00017  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00018  */
00019 
00020 #ifndef UBLOXUSBGSMMODEM_H_
00021 #define UBLOXUSBGSMMODEM_H_
00022 
00023 #include "core/fwk.h"
00024 
00025 #include "WANDongle.h"
00026 #include "at/ATCommandsInterface.h"
00027 #include "serial/usb/USBSerialStream.h"
00028 #include "ip/PPPIPInterface.h"
00029 #include "sms/GSMSMSInterface.h"
00030 #include "ussd/USSDInterface.h"
00031 #include "link/LinkMonitor.h"
00032 #include "CellularModem.h"
00033 
00034 /** u-blox WCDMA modem (LISA-U200)
00035  */
00036 class UbloxUSBGSMModem: public CellularModem
00037 {
00038 public:
00039   /** Create u-blox API instance
00040       @param powerGatingPin Optional pin commanding a power gating transistor on the modem's power line 
00041       @param powerGatingOnWhenPinHigh true if the pin needs to be high to power the dongle, defaults to true
00042    */
00043   UbloxUSBGSMModem(PinName powerGatingPin = NC, bool powerGatingOnWhenPinHigh = true);
00044 
00045   //Internet-related functions
00046 
00047   /** Open a 3G internet connection
00048       @return 0 on success, error code on failure
00049   */
00050   virtual int connect(const char* apn = NULL, const char* user = NULL, const char* password = NULL);
00051 
00052   /** Close the internet connection
00053      @return 0 on success, error code on failure
00054   */
00055   virtual int disconnect();
00056 
00057 
00058   /** Send a SM
00059      @param number The receiver's phone number
00060      @param message The message to send
00061      @return 0 on success, error code on failure
00062    */
00063   virtual int sendSM(const char* number, const char* message);
00064 
00065 
00066   /** Receive a SM
00067      @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)
00068      @param message Pointer to a buffer to store the the incoming message
00069      @param maxLength Maximum message length that can be stored in buffer (including null-terminating character)
00070      @return 0 on success, error code on failure
00071    */
00072   virtual int getSM(char* number, char* message, size_t maxLength);
00073 
00074   /** Get the number of SMs in the incoming box
00075      @param pCount pointer to store the number of unprocessed SMs on
00076      @return 0 on success, error code on failure
00077    */
00078   virtual int getSMCount(size_t* pCount);
00079 
00080   /** Send a USSD command & wait for its result
00081     @param command The command to send
00082     @param result Buffer in which to store the result
00083     @param maxLength Maximum result length that can be stored in buffer (including null-terminating character)
00084     @return 0 on success, error code on failure
00085   */
00086   int sendUSSD(const char* command, char* result, size_t maxLength);
00087   
00088   /** Get link state
00089     @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
00090     @param pRegistrationState pointer to store the current registration state
00091     @param pBearer pointer to store the current bearer
00092     @return 0 on success, error code on failure
00093   */
00094   int getLinkState(int* pRssi, LinkMonitor::REGISTRATION_STATE* pRegistrationState, LinkMonitor::BEARER* pBearer);  
00095 
00096   /** Get the ATCommandsInterface instance
00097     @return Pointer to the ATCommandsInterface instance
00098    */
00099   virtual ATCommandsInterface* getATCommandsInterface();
00100   
00101   /** Switch power on or off
00102     In order to use this function, a pin name must have been entered in the constructor
00103     @param enable true to switch the dongle on, false to switch it off
00104     @return 0 on success, error code on failure
00105   */
00106   virtual int power(bool enable);
00107 
00108 protected:
00109   bool power(); //< Turn power to USB dongle ON.
00110 
00111   /** Initialise dongle.
00112    * The following actions are performed:
00113    * 1) Power up
00114    * 2) Establish USB connection to dongle
00115    * 3) Start AT interface thread
00116    * 4) Wait for network registration
00117    */
00118   int init();
00119   
00120   /** De-initialise dongle.
00121    * The following actions are performed:
00122    * 1) Tear down PPP session
00123    * 2) Set SMS,USSD, and LinkMonitor subsystems to un-initialised
00124    * 3) Close the AT commands interface
00125    * 4) Tear down the USB connection to dongle
00126    */
00127   int cleanup();
00128 
00129 private:
00130   WANDongle m_dongle;          //< Interface to USB connected WAN dongle
00131   
00132   USBSerialStream m_atStream;  //< Serial interface to AT channel on modem
00133   USBSerialStream m_pppStream; //< Serial interface to PPP channel on modem
00134   
00135   ATCommandsInterface m_at;    //< Interface to AT commands processing
00136   
00137   GSMSMSInterface m_sms;       //< Interface to SMS manager (send/receive etc)
00138   USSDInterface m_ussd;        //< Interface to USSD manager (send etc)
00139   LinkMonitor m_linkMonitor;   //< Interface to link monitor (RSSI)
00140   
00141   PPPIPInterface m_ppp;        //< Interface to PPP conection manager (IP assignment etc)
00142 
00143   bool m_dongleConnected; //< Is the dongle physically connected (does the USB stack respond)? true/false
00144   bool m_ipInit;          //< Has PPIPInterface object (m_ppp) been initialised? true/false
00145   bool m_smsInit;         //< Has SMSInterface object (m_sms) been initialised? true/false
00146   bool m_ussdInit;        //< Has USSDInterface object (m_ussd) been initialised? true/false
00147   bool m_linkMonitorInit; //< Has LinkMonitor object (m_linkMonitor) been initialised? true/false
00148   bool m_atOpen;          //< Is the interface to the ATCommandsInterface open? true/false
00149   
00150   PinName m_powerGatingPin;        //< Pin which toggles power gating
00151   bool m_powerGatingOnWhenPinHigh; //< Semantics of power gating (whether high or low toggles power gating)
00152 };
00153 
00154 
00155 #endif /* UBLOXMODEM_H_ */