Vodafone K3770/K3772-Z modems driver & networking library
Dependencies: Socket USBHostWANDongle lwip-sys lwip
Dependents: VodafoneUSBModemHTTPClientTest VodafoneUSBModemNTPClientTest VodafoneUSBModemSMSTest VodafoneUSBModemUSSDTest ... more
Fork of VodafoneUSBModem_bleedingedge by
VodafoneUSBModem.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 VODAFONEUSBMODEM_H_ 00021 #define VODAFONEUSBMODEM_H_ 00022 00023 #include "core/fwk.h" 00024 00025 #include "USB3GModule/WANDongle.h" 00026 #include "at/ATCommandsInterface.h" 00027 #include "serial/usb/USBSerialStream.h" 00028 #include "ip/PPPIPInterface.h" 00029 #include "sms/SMSInterface.h" 00030 #include "ussd/USSDInterface.h" 00031 #include "link/LinkMonitor.h" 00032 00033 /** Vodafone USB Modem (K3770/K3772-Z) dongle 00034 */ 00035 class VodafoneUSBModem 00036 { 00037 public: 00038 /** Create Vodafone USB Modem (K3770/K3772-Z) dongle API instance 00039 @param powerGatingPin Optional pin commanding a power gating transistor on the modem's power line 00040 @param powerGatingOnWhenPinHigh true if the pin needs to be high to power the dongle, defaults to true 00041 */ 00042 VodafoneUSBModem(PinName powerGatingPin = NC, bool powerGatingOnWhenPinHigh = true); 00043 00044 //Internet-related functions 00045 00046 /** Open a 3G internet connection 00047 @return 0 on success, error code on failure 00048 */ 00049 int connect(const char* apn = NULL, const char* user = NULL, const char* password = NULL); 00050 00051 /** Close the internet connection 00052 @return 0 on success, error code on failure 00053 */ 00054 int disconnect(); 00055 00056 00057 /** Send a SM 00058 @param number The receiver's phone number 00059 @param message The message to send 00060 @return 0 on success, error code on failure 00061 */ 00062 int sendSM(const char* number, const char* message); 00063 00064 00065 /** Receive a SM 00066 @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) 00067 @param message Pointer to a buffer to store the the incoming message 00068 @param maxLength Maximum message length that can be stored in buffer (including null-terminating character) 00069 @return 0 on success, error code on failure 00070 */ 00071 int getSM(char* number, char* message, size_t maxLength); 00072 00073 /** Get the number of SMs in the incoming box 00074 @param pCount pointer to store the number of unprocessed SMs on 00075 @return 0 on success, error code on failure 00076 */ 00077 int getSMCount(size_t* pCount); 00078 00079 /** Send a USSD command & wait for its result 00080 @param command The command to send 00081 @param result Buffer in which to store the result 00082 @param maxLength Maximum result length that can be stored in buffer (including null-terminating character) 00083 @return 0 on success, error code on failure 00084 */ 00085 int sendUSSD(const char* command, char* result, size_t maxLength); 00086 00087 /** Get link state 00088 @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 00089 @param pRegistrationState pointer to store the current registration state 00090 @param pBearer pointer to store the current bearer 00091 @return 0 on success, error code on failure 00092 */ 00093 int getLinkState(int* pRssi, LinkMonitor::REGISTRATION_STATE* pRegistrationState, LinkMonitor::BEARER* pBearer); 00094 00095 /** Get the ATCommandsInterface instance 00096 @return Pointer to the ATCommandsInterface instance 00097 */ 00098 ATCommandsInterface* getATCommandsInterface(); 00099 00100 /** Switch power on or off 00101 In order to use this function, a pin name must have been entered in the constructor 00102 @param enable true to switch the dongle on, false to switch it off 00103 @return 0 on success, error code on failure 00104 */ 00105 int power(bool enable); 00106 00107 /** Get the IP address of a connected device 00108 @return A pointer to a string containing the IP address. 00109 */ 00110 char* getIPAddress(); 00111 00112 protected: 00113 bool power(); //< Turn power to USB dongle ON. 00114 00115 /** Initialise dongle. 00116 * The following actions are performed: 00117 * 1) Power up 00118 * 2) Establish USB connection to dongle 00119 * 3) Start AT interface thread 00120 * 4) Wait for network registration 00121 */ 00122 int init(); 00123 00124 /** De-initialise dongle. 00125 * The following actions are performed: 00126 * 1) Tear down PPP session 00127 * 2) Set SMS,USSD, and LinkMonitor subsystems to un-initialised 00128 * 3) Close the AT commands interface 00129 * 4) Tear down the USB connection to dongle 00130 */ 00131 int cleanup(); 00132 00133 private: 00134 WANDongle m_dongle; //< Interface to USB connected WAN dongle 00135 00136 USBSerialStream m_atStream; //< Serial interface to AT channel on modem 00137 USBSerialStream m_pppStream; //< Serial interface to PPP channel on modem 00138 00139 ATCommandsInterface m_at; //< Interface to AT commands processing 00140 00141 SMSInterface m_sms; //< Interface to SMS manager (send/receive etc) 00142 USSDInterface m_ussd; //< Interface to USSD manager (send etc) 00143 LinkMonitor m_linkMonitor; //< Interface to link monitor (RSSI) 00144 00145 PPPIPInterface m_ppp; //< Interface to PPP conection manager (IP assignment etc) 00146 00147 bool m_dongleConnected; //< Is the dongle physically connected (does the USB stack respond)? true/false 00148 bool m_ipInit; //< Has PPIPInterface object (m_ppp) been initialised? true/false 00149 bool m_smsInit; //< Has SMSInterface object (m_sms) been initialised? true/false 00150 bool m_ussdInit; //< Has USSDInterface object (m_ussd) been initialised? true/false 00151 bool m_linkMonitorInit; //< Has LinkMonitor object (m_linkMonitor) been initialised? true/false 00152 bool m_atOpen; //< Is the interface to the ATCommandsInterface open? true/false 00153 00154 PinName m_powerGatingPin; //< Pin which toggles power gating 00155 bool m_powerGatingOnWhenPinHigh; //< Semantics of power gating (whether high or low toggles power gating) 00156 }; 00157 00158 00159 #endif /* VODAFONEUSBMODEM_H_ */
Generated on Tue Jul 12 2022 12:11:28 by 1.7.2