u-blox USB modems (GSM and CDMA)

Dependencies:   CellularUSBModem

Dependents:   C027_CANInterfaceComm C027_ModemTransparentUSBCDC_revb UbloxModemHTTPClientTest C027_HTTPClientTest ... more

Legacy Networking Libray

This is an mbed 2 networking library. For an mbed OS 5 compatible library, please see:

Import libraryC027Interface

Socket interface for C027Interface. Implements the NetworkSocketAPI

Committer:
bogdanm
Date:
Thu Oct 17 13:06:33 2013 +0300
Revision:
1:71286b99c1cb
Child:
3:4d2c18a3b2a4
Initial release of the UbloxUSBModem library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 1:71286b99c1cb 1 /* VodafoneUSBModem.h */
bogdanm 1:71286b99c1cb 2 /* Copyright (C) 2012 mbed.org, MIT License
bogdanm 1:71286b99c1cb 3 *
bogdanm 1:71286b99c1cb 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
bogdanm 1:71286b99c1cb 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
bogdanm 1:71286b99c1cb 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
bogdanm 1:71286b99c1cb 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
bogdanm 1:71286b99c1cb 8 * furnished to do so, subject to the following conditions:
bogdanm 1:71286b99c1cb 9 *
bogdanm 1:71286b99c1cb 10 * The above copyright notice and this permission notice shall be included in all copies or
bogdanm 1:71286b99c1cb 11 * substantial portions of the Software.
bogdanm 1:71286b99c1cb 12 *
bogdanm 1:71286b99c1cb 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
bogdanm 1:71286b99c1cb 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
bogdanm 1:71286b99c1cb 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
bogdanm 1:71286b99c1cb 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
bogdanm 1:71286b99c1cb 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
bogdanm 1:71286b99c1cb 18 */
bogdanm 1:71286b99c1cb 19
bogdanm 1:71286b99c1cb 20 #ifndef UBLOXUSBGSMMODEM_H_
bogdanm 1:71286b99c1cb 21 #define UBLOXUSBGSMMODEM_H_
bogdanm 1:71286b99c1cb 22
bogdanm 1:71286b99c1cb 23 #include "core/fwk.h"
bogdanm 1:71286b99c1cb 24
bogdanm 1:71286b99c1cb 25 #include "WANDongle.h"
bogdanm 1:71286b99c1cb 26 #include "at/ATCommandsInterface.h"
bogdanm 1:71286b99c1cb 27 #include "serial/usb/USBSerialStream.h"
bogdanm 1:71286b99c1cb 28 #include "ip/PPPIPInterface.h"
bogdanm 1:71286b99c1cb 29 #include "sms/GSMSMSInterface.h"
bogdanm 1:71286b99c1cb 30 #include "ussd/USSDInterface.h"
bogdanm 1:71286b99c1cb 31 #include "link/LinkMonitor.h"
bogdanm 1:71286b99c1cb 32
bogdanm 1:71286b99c1cb 33 /** u-blox WCDMA modem (LISA-U200)
bogdanm 1:71286b99c1cb 34 */
bogdanm 1:71286b99c1cb 35 class UbloxUSBGSMModem
bogdanm 1:71286b99c1cb 36 {
bogdanm 1:71286b99c1cb 37 public:
bogdanm 1:71286b99c1cb 38 /** Create u-blox API instance
bogdanm 1:71286b99c1cb 39 @param powerGatingPin Optional pin commanding a power gating transistor on the modem's power line
bogdanm 1:71286b99c1cb 40 @param powerGatingOnWhenPinHigh true if the pin needs to be high to power the dongle, defaults to true
bogdanm 1:71286b99c1cb 41 */
bogdanm 1:71286b99c1cb 42 UbloxUSBGSMModem(PinName powerGatingPin = NC, bool powerGatingOnWhenPinHigh = true);
bogdanm 1:71286b99c1cb 43
bogdanm 1:71286b99c1cb 44 //Internet-related functions
bogdanm 1:71286b99c1cb 45
bogdanm 1:71286b99c1cb 46 /** Open a 3G internet connection
bogdanm 1:71286b99c1cb 47 @return 0 on success, error code on failure
bogdanm 1:71286b99c1cb 48 */
bogdanm 1:71286b99c1cb 49 int connect(const char* apn = NULL, const char* user = NULL, const char* password = NULL);
bogdanm 1:71286b99c1cb 50
bogdanm 1:71286b99c1cb 51 /** Close the internet connection
bogdanm 1:71286b99c1cb 52 @return 0 on success, error code on failure
bogdanm 1:71286b99c1cb 53 */
bogdanm 1:71286b99c1cb 54 int disconnect();
bogdanm 1:71286b99c1cb 55
bogdanm 1:71286b99c1cb 56
bogdanm 1:71286b99c1cb 57 /** Send a SM
bogdanm 1:71286b99c1cb 58 @param number The receiver's phone number
bogdanm 1:71286b99c1cb 59 @param message The message to send
bogdanm 1:71286b99c1cb 60 @return 0 on success, error code on failure
bogdanm 1:71286b99c1cb 61 */
bogdanm 1:71286b99c1cb 62 int sendSM(const char* number, const char* message);
bogdanm 1:71286b99c1cb 63
bogdanm 1:71286b99c1cb 64
bogdanm 1:71286b99c1cb 65 /** Receive a SM
bogdanm 1:71286b99c1cb 66 @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)
bogdanm 1:71286b99c1cb 67 @param message Pointer to a buffer to store the the incoming message
bogdanm 1:71286b99c1cb 68 @param maxLength Maximum message length that can be stored in buffer (including null-terminating character)
bogdanm 1:71286b99c1cb 69 @return 0 on success, error code on failure
bogdanm 1:71286b99c1cb 70 */
bogdanm 1:71286b99c1cb 71 int getSM(char* number, char* message, size_t maxLength);
bogdanm 1:71286b99c1cb 72
bogdanm 1:71286b99c1cb 73 /** Get the number of SMs in the incoming box
bogdanm 1:71286b99c1cb 74 @param pCount pointer to store the number of unprocessed SMs on
bogdanm 1:71286b99c1cb 75 @return 0 on success, error code on failure
bogdanm 1:71286b99c1cb 76 */
bogdanm 1:71286b99c1cb 77 int getSMCount(size_t* pCount);
bogdanm 1:71286b99c1cb 78
bogdanm 1:71286b99c1cb 79 /** Send a USSD command & wait for its result
bogdanm 1:71286b99c1cb 80 @param command The command to send
bogdanm 1:71286b99c1cb 81 @param result Buffer in which to store the result
bogdanm 1:71286b99c1cb 82 @param maxLength Maximum result length that can be stored in buffer (including null-terminating character)
bogdanm 1:71286b99c1cb 83 @return 0 on success, error code on failure
bogdanm 1:71286b99c1cb 84 */
bogdanm 1:71286b99c1cb 85 int sendUSSD(const char* command, char* result, size_t maxLength);
bogdanm 1:71286b99c1cb 86
bogdanm 1:71286b99c1cb 87 /** Get link state
bogdanm 1:71286b99c1cb 88 @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
bogdanm 1:71286b99c1cb 89 @param pRegistrationState pointer to store the current registration state
bogdanm 1:71286b99c1cb 90 @param pBearer pointer to store the current bearer
bogdanm 1:71286b99c1cb 91 @return 0 on success, error code on failure
bogdanm 1:71286b99c1cb 92 */
bogdanm 1:71286b99c1cb 93 int getLinkState(int* pRssi, LinkMonitor::REGISTRATION_STATE* pRegistrationState, LinkMonitor::BEARER* pBearer);
bogdanm 1:71286b99c1cb 94
bogdanm 1:71286b99c1cb 95 /** Get the ATCommandsInterface instance
bogdanm 1:71286b99c1cb 96 @return Pointer to the ATCommandsInterface instance
bogdanm 1:71286b99c1cb 97 */
bogdanm 1:71286b99c1cb 98 ATCommandsInterface* getATCommandsInterface();
bogdanm 1:71286b99c1cb 99
bogdanm 1:71286b99c1cb 100 /** Switch power on or off
bogdanm 1:71286b99c1cb 101 In order to use this function, a pin name must have been entered in the constructor
bogdanm 1:71286b99c1cb 102 @param enable true to switch the dongle on, false to switch it off
bogdanm 1:71286b99c1cb 103 @return 0 on success, error code on failure
bogdanm 1:71286b99c1cb 104 */
bogdanm 1:71286b99c1cb 105 int power(bool enable);
bogdanm 1:71286b99c1cb 106
bogdanm 1:71286b99c1cb 107 protected:
bogdanm 1:71286b99c1cb 108 bool power(); //< Turn power to USB dongle ON.
bogdanm 1:71286b99c1cb 109
bogdanm 1:71286b99c1cb 110 /** Initialise dongle.
bogdanm 1:71286b99c1cb 111 * The following actions are performed:
bogdanm 1:71286b99c1cb 112 * 1) Power up
bogdanm 1:71286b99c1cb 113 * 2) Establish USB connection to dongle
bogdanm 1:71286b99c1cb 114 * 3) Start AT interface thread
bogdanm 1:71286b99c1cb 115 * 4) Wait for network registration
bogdanm 1:71286b99c1cb 116 */
bogdanm 1:71286b99c1cb 117 int init();
bogdanm 1:71286b99c1cb 118
bogdanm 1:71286b99c1cb 119 /** De-initialise dongle.
bogdanm 1:71286b99c1cb 120 * The following actions are performed:
bogdanm 1:71286b99c1cb 121 * 1) Tear down PPP session
bogdanm 1:71286b99c1cb 122 * 2) Set SMS,USSD, and LinkMonitor subsystems to un-initialised
bogdanm 1:71286b99c1cb 123 * 3) Close the AT commands interface
bogdanm 1:71286b99c1cb 124 * 4) Tear down the USB connection to dongle
bogdanm 1:71286b99c1cb 125 */
bogdanm 1:71286b99c1cb 126 int cleanup();
bogdanm 1:71286b99c1cb 127
bogdanm 1:71286b99c1cb 128 private:
bogdanm 1:71286b99c1cb 129 WANDongle m_dongle; //< Interface to USB connected WAN dongle
bogdanm 1:71286b99c1cb 130
bogdanm 1:71286b99c1cb 131 USBSerialStream m_atStream; //< Serial interface to AT channel on modem
bogdanm 1:71286b99c1cb 132 USBSerialStream m_pppStream; //< Serial interface to PPP channel on modem
bogdanm 1:71286b99c1cb 133
bogdanm 1:71286b99c1cb 134 ATCommandsInterface m_at; //< Interface to AT commands processing
bogdanm 1:71286b99c1cb 135
bogdanm 1:71286b99c1cb 136 GSMSMSInterface m_sms; //< Interface to SMS manager (send/receive etc)
bogdanm 1:71286b99c1cb 137 USSDInterface m_ussd; //< Interface to USSD manager (send etc)
bogdanm 1:71286b99c1cb 138 LinkMonitor m_linkMonitor; //< Interface to link monitor (RSSI)
bogdanm 1:71286b99c1cb 139
bogdanm 1:71286b99c1cb 140 PPPIPInterface m_ppp; //< Interface to PPP conection manager (IP assignment etc)
bogdanm 1:71286b99c1cb 141
bogdanm 1:71286b99c1cb 142 bool m_dongleConnected; //< Is the dongle physically connected (does the USB stack respond)? true/false
bogdanm 1:71286b99c1cb 143 bool m_ipInit; //< Has PPIPInterface object (m_ppp) been initialised? true/false
bogdanm 1:71286b99c1cb 144 bool m_smsInit; //< Has SMSInterface object (m_sms) been initialised? true/false
bogdanm 1:71286b99c1cb 145 bool m_ussdInit; //< Has USSDInterface object (m_ussd) been initialised? true/false
bogdanm 1:71286b99c1cb 146 bool m_linkMonitorInit; //< Has LinkMonitor object (m_linkMonitor) been initialised? true/false
bogdanm 1:71286b99c1cb 147 bool m_atOpen; //< Is the interface to the ATCommandsInterface open? true/false
bogdanm 1:71286b99c1cb 148
bogdanm 1:71286b99c1cb 149 PinName m_powerGatingPin; //< Pin which toggles power gating
bogdanm 1:71286b99c1cb 150 bool m_powerGatingOnWhenPinHigh; //< Semantics of power gating (whether high or low toggles power gating)
bogdanm 1:71286b99c1cb 151 };
bogdanm 1:71286b99c1cb 152
bogdanm 1:71286b99c1cb 153
bogdanm 1:71286b99c1cb 154 #endif /* UBLOXMODEM_H_ */