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