mbed-os

Fork of mbed-os by erkin yucel

Committer:
xuaner
Date:
Thu Jul 20 14:26:57 2017 +0000
Revision:
1:3deb71413561
Parent:
0:f269e3021894
mbed_os

Who changed what in which revision?

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