mbed-os
Fork of mbed-os by
features/unsupported/net/cellular/UbloxUSBModem/UbloxModem.h@0:f269e3021894, 2016-10-23 (annotated)
- Committer:
- elessair
- Date:
- Sun Oct 23 15:10:02 2016 +0000
- Revision:
- 0:f269e3021894
Initial commit
Who changed what in which revision?
User | Revision | Line number | New 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 UBLOXMODEM_H_ |
elessair | 0:f269e3021894 | 21 | #define UBLOXMODEM_H_ |
elessair | 0:f269e3021894 | 22 | |
elessair | 0:f269e3021894 | 23 | #include "core/fwk.h" |
elessair | 0:f269e3021894 | 24 | |
elessair | 0:f269e3021894 | 25 | #include "at/ATCommandsInterface.h" |
elessair | 0:f269e3021894 | 26 | #include "ip/PPPIPInterface.h" |
elessair | 0:f269e3021894 | 27 | #include "sms/GSMSMSInterface.h" |
elessair | 0:f269e3021894 | 28 | #include "sms/CDMASMSInterface.h" |
elessair | 0:f269e3021894 | 29 | #include "ussd/USSDInterface.h" |
elessair | 0:f269e3021894 | 30 | #include "link/LinkMonitor.h" |
elessair | 0:f269e3021894 | 31 | #include "CellularModem.h" |
elessair | 0:f269e3021894 | 32 | |
elessair | 0:f269e3021894 | 33 | class genericAtProcessor : public IATCommandsProcessor |
elessair | 0:f269e3021894 | 34 | { |
elessair | 0:f269e3021894 | 35 | public: |
elessair | 0:f269e3021894 | 36 | genericAtProcessor(); |
elessair | 0:f269e3021894 | 37 | const char* getResponse(void); |
elessair | 0:f269e3021894 | 38 | private: |
elessair | 0:f269e3021894 | 39 | virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line); |
elessair | 0:f269e3021894 | 40 | virtual int onNewEntryPrompt(ATCommandsInterface* pInst); |
elessair | 0:f269e3021894 | 41 | protected: |
elessair | 0:f269e3021894 | 42 | char str[256]; |
elessair | 0:f269e3021894 | 43 | int i; |
elessair | 0:f269e3021894 | 44 | }; |
elessair | 0:f269e3021894 | 45 | |
elessair | 0:f269e3021894 | 46 | /** u-blox WCDMA modem (LISA-U200) |
elessair | 0:f269e3021894 | 47 | */ |
elessair | 0:f269e3021894 | 48 | class UbloxModem: public CellularModem |
elessair | 0:f269e3021894 | 49 | { |
elessair | 0:f269e3021894 | 50 | public: |
elessair | 0:f269e3021894 | 51 | /** Create u-blox API instance |
elessair | 0:f269e3021894 | 52 | @param powerGatingPin Optional pin commanding a power gating transistor on the modem's power line |
elessair | 0:f269e3021894 | 53 | @param powerGatingOnWhenPinHigh true if the pin needs to be high to power the dongle, defaults to true |
elessair | 0:f269e3021894 | 54 | */ |
elessair | 0:f269e3021894 | 55 | UbloxModem(IOStream* atStream, IOStream* pppStream); |
elessair | 0:f269e3021894 | 56 | |
elessair | 0:f269e3021894 | 57 | //Internet-related functions |
elessair | 0:f269e3021894 | 58 | |
elessair | 0:f269e3021894 | 59 | /** Open a 3G internet connection |
elessair | 0:f269e3021894 | 60 | @return 0 on success, error code on failure |
elessair | 0:f269e3021894 | 61 | */ |
elessair | 0:f269e3021894 | 62 | virtual int connect(const char* apn = NULL, const char* user = NULL, const char* password = NULL); |
elessair | 0:f269e3021894 | 63 | |
elessair | 0:f269e3021894 | 64 | /** Close the internet connection |
elessair | 0:f269e3021894 | 65 | @return 0 on success, error code on failure |
elessair | 0:f269e3021894 | 66 | */ |
elessair | 0:f269e3021894 | 67 | virtual int disconnect(); |
elessair | 0:f269e3021894 | 68 | |
elessair | 0:f269e3021894 | 69 | |
elessair | 0:f269e3021894 | 70 | /** Send a SM |
elessair | 0:f269e3021894 | 71 | @param number The receiver's phone number |
elessair | 0:f269e3021894 | 72 | @param message The message to send |
elessair | 0:f269e3021894 | 73 | @return 0 on success, error code on failure |
elessair | 0:f269e3021894 | 74 | */ |
elessair | 0:f269e3021894 | 75 | virtual int sendSM(const char* number, const char* message); |
elessair | 0:f269e3021894 | 76 | |
elessair | 0:f269e3021894 | 77 | |
elessair | 0:f269e3021894 | 78 | /** Receive a SM |
elessair | 0:f269e3021894 | 79 | @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 | 80 | @param message Pointer to a buffer to store the the incoming message |
elessair | 0:f269e3021894 | 81 | @param maxLength Maximum message length that can be stored in buffer (including null-terminating character) |
elessair | 0:f269e3021894 | 82 | @return 0 on success, error code on failure |
elessair | 0:f269e3021894 | 83 | */ |
elessair | 0:f269e3021894 | 84 | virtual int getSM(char* number, char* message, size_t maxLength); |
elessair | 0:f269e3021894 | 85 | |
elessair | 0:f269e3021894 | 86 | /** Get the number of SMs in the incoming box |
elessair | 0:f269e3021894 | 87 | @param pCount pointer to store the number of unprocessed SMs on |
elessair | 0:f269e3021894 | 88 | @return 0 on success, error code on failure |
elessair | 0:f269e3021894 | 89 | */ |
elessair | 0:f269e3021894 | 90 | virtual int getSMCount(size_t* pCount); |
elessair | 0:f269e3021894 | 91 | |
elessair | 0:f269e3021894 | 92 | /** Send a USSD command & wait for its result |
elessair | 0:f269e3021894 | 93 | @param command The command to send |
elessair | 0:f269e3021894 | 94 | @param result Buffer in which to store the result |
elessair | 0:f269e3021894 | 95 | @param maxLength Maximum result length that can be stored in buffer (including null-terminating character) |
elessair | 0:f269e3021894 | 96 | @return 0 on success, error code on failure |
elessair | 0:f269e3021894 | 97 | */ |
elessair | 0:f269e3021894 | 98 | int sendUSSD(const char* command, char* result, size_t maxLength); |
elessair | 0:f269e3021894 | 99 | |
elessair | 0:f269e3021894 | 100 | /** Get link state |
elessair | 0:f269e3021894 | 101 | @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 | 102 | @param pRegistrationState pointer to store the current registration state |
elessair | 0:f269e3021894 | 103 | @param pBearer pointer to store the current bearer |
elessair | 0:f269e3021894 | 104 | @return 0 on success, error code on failure |
elessair | 0:f269e3021894 | 105 | */ |
elessair | 0:f269e3021894 | 106 | int getLinkState(int* pRssi, LinkMonitor::REGISTRATION_STATE* pRegistrationState, LinkMonitor::BEARER* pBearer); |
elessair | 0:f269e3021894 | 107 | |
elessair | 0:f269e3021894 | 108 | int getPhoneNumber(char* phoneNumber); |
elessair | 0:f269e3021894 | 109 | |
elessair | 0:f269e3021894 | 110 | /** Get the ATCommandsInterface instance |
elessair | 0:f269e3021894 | 111 | @return Pointer to the ATCommandsInterface instance |
elessair | 0:f269e3021894 | 112 | */ |
elessair | 0:f269e3021894 | 113 | virtual ATCommandsInterface* getATCommandsInterface(); |
elessair | 0:f269e3021894 | 114 | |
elessair | 0:f269e3021894 | 115 | protected: |
elessair | 0:f269e3021894 | 116 | /** Initialise dongle. |
elessair | 0:f269e3021894 | 117 | * The following actions are performed: |
elessair | 0:f269e3021894 | 118 | * 1) Start AT interface thread |
elessair | 0:f269e3021894 | 119 | * 2) Wait for network registration |
elessair | 0:f269e3021894 | 120 | */ |
elessair | 0:f269e3021894 | 121 | virtual int init(); |
elessair | 0:f269e3021894 | 122 | |
elessair | 0:f269e3021894 | 123 | /** De-initialise dongle. |
elessair | 0:f269e3021894 | 124 | * The following actions are performed: |
elessair | 0:f269e3021894 | 125 | * 1) Tear down PPP session |
elessair | 0:f269e3021894 | 126 | * 2) Set SMS,USSD, and LinkMonitor subsystems to un-initialised |
elessair | 0:f269e3021894 | 127 | * 3) Close the AT commands interface |
elessair | 0:f269e3021894 | 128 | */ |
elessair | 0:f269e3021894 | 129 | virtual int cleanup(); |
elessair | 0:f269e3021894 | 130 | |
elessair | 0:f269e3021894 | 131 | private: |
elessair | 0:f269e3021894 | 132 | ATCommandsInterface m_at; //< Interface to AT commands processing |
elessair | 0:f269e3021894 | 133 | |
elessair | 0:f269e3021894 | 134 | CDMASMSInterface m_CdmaSms; //< Interface to SMS manager (send/receive etc) |
elessair | 0:f269e3021894 | 135 | GSMSMSInterface m_GsmSms; //< Interface to SMS manager (send/receive etc) |
elessair | 0:f269e3021894 | 136 | USSDInterface m_ussd; //< Interface to USSD manager (send etc) |
elessair | 0:f269e3021894 | 137 | LinkMonitor m_linkMonitor; //< Interface to link monitor (RSSI) |
elessair | 0:f269e3021894 | 138 | |
elessair | 0:f269e3021894 | 139 | PPPIPInterface m_ppp; //< Interface to PPP conection manager (IP assignment etc) |
elessair | 0:f269e3021894 | 140 | |
elessair | 0:f269e3021894 | 141 | bool m_ipInit; //< Has PPIPInterface object (m_ppp) been initialised? true/false |
elessair | 0:f269e3021894 | 142 | bool m_smsInit; //< Has SMSInterface object (m_sms) been initialised? true/false |
elessair | 0:f269e3021894 | 143 | bool m_ussdInit; //< Has USSDInterface object (m_ussd) been initialised? true/false |
elessair | 0:f269e3021894 | 144 | bool m_linkMonitorInit; //< Has LinkMonitor object (m_linkMonitor) been initialised? true/false |
elessair | 0:f269e3021894 | 145 | bool m_atOpen; //< Is the interface to the ATCommandsInterface open? true/false |
elessair | 0:f269e3021894 | 146 | protected: |
elessair | 0:f269e3021894 | 147 | bool m_onePort; |
elessair | 0:f269e3021894 | 148 | enum { LISA_C200, LISA_U200, SARA_G350, UNKNOWN } m_type; |
elessair | 0:f269e3021894 | 149 | }; |
elessair | 0:f269e3021894 | 150 | |
elessair | 0:f269e3021894 | 151 | #include "WANDongle.h" |
elessair | 0:f269e3021894 | 152 | #include "serial/usb/USBSerialStream.h" |
elessair | 0:f269e3021894 | 153 | |
elessair | 0:f269e3021894 | 154 | class UbloxUSBModem: public UbloxModem |
elessair | 0:f269e3021894 | 155 | { |
elessair | 0:f269e3021894 | 156 | public: |
elessair | 0:f269e3021894 | 157 | UbloxUSBModem(); |
elessair | 0:f269e3021894 | 158 | virtual int init(); |
elessair | 0:f269e3021894 | 159 | virtual int cleanup(); |
elessair | 0:f269e3021894 | 160 | virtual int power(bool enable) { return 1; } |
elessair | 0:f269e3021894 | 161 | |
elessair | 0:f269e3021894 | 162 | private: |
elessair | 0:f269e3021894 | 163 | WANDongle m_dongle; //< Interface to USB connected WAN dongle |
elessair | 0:f269e3021894 | 164 | |
elessair | 0:f269e3021894 | 165 | USBSerialStream m_atStream; //< Serial interface to AT channel on modem |
elessair | 0:f269e3021894 | 166 | USBSerialStream m_pppStream; //< Serial interface to PPP channel on modem |
elessair | 0:f269e3021894 | 167 | |
elessair | 0:f269e3021894 | 168 | bool m_dongleConnected; //< Is the dongle physically connected (does the USB stack respond)? true/false |
elessair | 0:f269e3021894 | 169 | }; |
elessair | 0:f269e3021894 | 170 | |
elessair | 0:f269e3021894 | 171 | #include "serial/io/IOSerialStream.h" |
elessair | 0:f269e3021894 | 172 | |
elessair | 0:f269e3021894 | 173 | class UbloxSerModem: public UbloxModem |
elessair | 0:f269e3021894 | 174 | { |
elessair | 0:f269e3021894 | 175 | public: |
elessair | 0:f269e3021894 | 176 | UbloxSerModem(); |
elessair | 0:f269e3021894 | 177 | virtual int power(bool enable) { return 1; } |
elessair | 0:f269e3021894 | 178 | private: |
elessair | 0:f269e3021894 | 179 | RawSerial m_Serial; |
elessair | 0:f269e3021894 | 180 | IOSerialStream m_atStream; //< Serial interface to AT channel on modem |
elessair | 0:f269e3021894 | 181 | }; |
elessair | 0:f269e3021894 | 182 | |
elessair | 0:f269e3021894 | 183 | #endif /* UBLOXMODEM_H_ */ |