Changes to support Vodafone K4606
Dependencies: Socket USBHostWANDongle lwip-sys lwip
Fork of VodafoneUSBModem by
VodafoneK3770.cpp@11:565b2ec40dea, 2012-07-11 (annotated)
- Committer:
- donatien
- Date:
- Wed Jul 11 12:47:53 2012 +0000
- Revision:
- 11:565b2ec40dea
- Parent:
- 10:21a6f09d5631
- Parent:
- 9:3f077dde13c9
- Child:
- 12:66dc2c8eba2d
Merge;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 8:04b6a042595f | 1 | /* VodafoneK3770.cpp */ |
donatien | 8:04b6a042595f | 2 | /* |
donatien | 8:04b6a042595f | 3 | Copyright (C) 2012 ARM Limited. |
donatien | 8:04b6a042595f | 4 | |
donatien | 8:04b6a042595f | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of |
donatien | 8:04b6a042595f | 6 | this software and associated documentation files (the "Software"), to deal in |
donatien | 8:04b6a042595f | 7 | the Software without restriction, including without limitation the rights to |
donatien | 8:04b6a042595f | 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
donatien | 8:04b6a042595f | 9 | of the Software, and to permit persons to whom the Software is furnished to do |
donatien | 8:04b6a042595f | 10 | so, subject to the following conditions: |
donatien | 8:04b6a042595f | 11 | |
donatien | 8:04b6a042595f | 12 | The above copyright notice and this permission notice shall be included in all |
donatien | 8:04b6a042595f | 13 | copies or substantial portions of the Software. |
donatien | 8:04b6a042595f | 14 | |
donatien | 8:04b6a042595f | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
donatien | 8:04b6a042595f | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
donatien | 8:04b6a042595f | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
donatien | 8:04b6a042595f | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
donatien | 8:04b6a042595f | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
donatien | 8:04b6a042595f | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
donatien | 8:04b6a042595f | 21 | SOFTWARE. |
donatien | 8:04b6a042595f | 22 | */ |
donatien | 8:04b6a042595f | 23 | |
donatien | 8:04b6a042595f | 24 | #define __DEBUG__ 4 |
donatien | 8:04b6a042595f | 25 | #ifndef __MODULE__ |
donatien | 8:04b6a042595f | 26 | #define __MODULE__ "VodafoneK3770.cpp" |
donatien | 8:04b6a042595f | 27 | #endif |
donatien | 8:04b6a042595f | 28 | |
donatien | 8:04b6a042595f | 29 | #include "core/fwk.h" |
donatien | 8:04b6a042595f | 30 | |
donatien | 8:04b6a042595f | 31 | #include "VodafoneK3770.h" |
donatien | 8:04b6a042595f | 32 | |
donatien | 8:04b6a042595f | 33 | VodafoneK3770::VodafoneK3770() : m_dongle(), |
donatien | 10:21a6f09d5631 | 34 | m_atStream(m_dongle.getSerial(1)), m_pppStream(m_dongle.getSerial(0)), m_at(&m_atStream), |
donatien | 10:21a6f09d5631 | 35 | m_sms(&m_at), m_ussd(&m_at), m_ppp(&m_pppStream), |
donatien | 8:04b6a042595f | 36 | m_dongleConnected(false), m_ipInit(false), m_smsInit(false), m_atOpen(false) |
donatien | 8:04b6a042595f | 37 | { |
donatien | 8:04b6a042595f | 38 | |
donatien | 8:04b6a042595f | 39 | } |
donatien | 8:04b6a042595f | 40 | |
donatien | 8:04b6a042595f | 41 | class CREGProcessor : public IATCommandsProcessor |
donatien | 8:04b6a042595f | 42 | { |
donatien | 8:04b6a042595f | 43 | public: |
donatien | 8:04b6a042595f | 44 | CREGProcessor() : status(STATUS_REGISTERING) |
donatien | 8:04b6a042595f | 45 | { |
donatien | 8:04b6a042595f | 46 | |
donatien | 8:04b6a042595f | 47 | } |
donatien | 8:04b6a042595f | 48 | enum REGISTERING_STATUS { STATUS_REGISTERING, STATUS_OK, STATUS_FAILED }; |
donatien | 8:04b6a042595f | 49 | REGISTERING_STATUS getStatus() |
donatien | 8:04b6a042595f | 50 | { |
donatien | 8:04b6a042595f | 51 | return status; |
donatien | 8:04b6a042595f | 52 | } |
donatien | 8:04b6a042595f | 53 | private: |
donatien | 8:04b6a042595f | 54 | virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line) |
donatien | 8:04b6a042595f | 55 | { |
donatien | 8:04b6a042595f | 56 | int r; |
donatien | 8:04b6a042595f | 57 | if( sscanf(line, "+CREG: %*d,%d", &r) == 1 ) |
donatien | 8:04b6a042595f | 58 | { |
donatien | 8:04b6a042595f | 59 | switch(r) |
donatien | 8:04b6a042595f | 60 | { |
donatien | 8:04b6a042595f | 61 | case 1: |
donatien | 8:04b6a042595f | 62 | case 5: |
donatien | 8:04b6a042595f | 63 | status = STATUS_OK; |
donatien | 8:04b6a042595f | 64 | break; |
donatien | 8:04b6a042595f | 65 | case 0: |
donatien | 8:04b6a042595f | 66 | case 2: |
donatien | 8:04b6a042595f | 67 | status = STATUS_REGISTERING; |
donatien | 8:04b6a042595f | 68 | break; |
donatien | 8:04b6a042595f | 69 | case 3: |
donatien | 8:04b6a042595f | 70 | default: |
donatien | 8:04b6a042595f | 71 | status = STATUS_FAILED; |
donatien | 8:04b6a042595f | 72 | break; |
donatien | 8:04b6a042595f | 73 | } |
donatien | 8:04b6a042595f | 74 | } |
donatien | 8:04b6a042595f | 75 | return OK; |
donatien | 8:04b6a042595f | 76 | } |
donatien | 8:04b6a042595f | 77 | virtual int onNewEntryPrompt(ATCommandsInterface* pInst) |
donatien | 8:04b6a042595f | 78 | { |
donatien | 8:04b6a042595f | 79 | return OK; |
donatien | 8:04b6a042595f | 80 | } |
donatien | 8:04b6a042595f | 81 | volatile REGISTERING_STATUS status; |
donatien | 8:04b6a042595f | 82 | }; |
donatien | 8:04b6a042595f | 83 | |
donatien | 8:04b6a042595f | 84 | class COPSProcessor : public IATCommandsProcessor |
donatien | 8:04b6a042595f | 85 | { |
donatien | 8:04b6a042595f | 86 | public: |
donatien | 8:04b6a042595f | 87 | COPSProcessor() : valid(false) |
donatien | 8:04b6a042595f | 88 | { |
donatien | 8:04b6a042595f | 89 | network[0] = '\0'; |
donatien | 8:04b6a042595f | 90 | apn[0] = '\0'; |
donatien | 8:04b6a042595f | 91 | bearer[0] = '\0'; |
donatien | 8:04b6a042595f | 92 | } |
donatien | 8:04b6a042595f | 93 | char* getNetwork() |
donatien | 8:04b6a042595f | 94 | { |
donatien | 8:04b6a042595f | 95 | return network; |
donatien | 8:04b6a042595f | 96 | } |
donatien | 8:04b6a042595f | 97 | char* getAPN() |
donatien | 8:04b6a042595f | 98 | { |
donatien | 8:04b6a042595f | 99 | return apn; |
donatien | 8:04b6a042595f | 100 | } |
donatien | 8:04b6a042595f | 101 | char* getBearer() |
donatien | 8:04b6a042595f | 102 | { |
donatien | 8:04b6a042595f | 103 | return bearer; |
donatien | 8:04b6a042595f | 104 | } |
donatien | 8:04b6a042595f | 105 | bool isValid() |
donatien | 8:04b6a042595f | 106 | { |
donatien | 8:04b6a042595f | 107 | return valid; |
donatien | 8:04b6a042595f | 108 | } |
donatien | 8:04b6a042595f | 109 | private: |
donatien | 8:04b6a042595f | 110 | virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line) |
donatien | 8:04b6a042595f | 111 | { |
donatien | 8:04b6a042595f | 112 | int networkId; |
donatien | 8:04b6a042595f | 113 | int bearerId; |
donatien | 8:04b6a042595f | 114 | int s = sscanf(line, "+COPS: %*d,%*d,\"%d\",%d", &networkId, &bearerId); |
donatien | 8:04b6a042595f | 115 | if( s == 2 ) |
donatien | 8:04b6a042595f | 116 | { |
donatien | 8:04b6a042595f | 117 | switch(networkId) |
donatien | 8:04b6a042595f | 118 | { |
donatien | 8:04b6a042595f | 119 | case 23415: |
donatien | 8:04b6a042595f | 120 | strcpy(network, "Vodafone UK"); |
donatien | 8:04b6a042595f | 121 | strcpy(apn, "pp.vodafone.co.uk"); |
donatien | 8:04b6a042595f | 122 | valid = true; |
donatien | 8:04b6a042595f | 123 | break; |
donatien | 8:04b6a042595f | 124 | case 20810: |
donatien | 8:04b6a042595f | 125 | strcpy(network, "SFR FR"); |
donatien | 8:04b6a042595f | 126 | strcpy(apn, "websfr"); |
donatien | 8:04b6a042595f | 127 | valid = true; |
donatien | 8:04b6a042595f | 128 | break; |
donatien | 8:04b6a042595f | 129 | default: |
donatien | 8:04b6a042595f | 130 | break; |
donatien | 8:04b6a042595f | 131 | } |
donatien | 8:04b6a042595f | 132 | } |
donatien | 8:04b6a042595f | 133 | else |
donatien | 8:04b6a042595f | 134 | { |
donatien | 8:04b6a042595f | 135 | return OK; |
donatien | 8:04b6a042595f | 136 | } |
donatien | 8:04b6a042595f | 137 | switch(bearerId) |
donatien | 8:04b6a042595f | 138 | { |
donatien | 8:04b6a042595f | 139 | case 0: strcpy(bearer, "GSM"); break; |
donatien | 8:04b6a042595f | 140 | case 1: strcpy(bearer, "GSM Compact"); break; |
donatien | 8:04b6a042595f | 141 | case 2: strcpy(bearer, "UTRAN"); break; |
donatien | 8:04b6a042595f | 142 | case 3: strcpy(bearer, "GSM w/EGPRS"); break; |
donatien | 8:04b6a042595f | 143 | case 4: strcpy(bearer, "UTRAN w/HSDPA"); break; |
donatien | 8:04b6a042595f | 144 | case 5: strcpy(bearer, "UTRAN w/HSUPA"); break; |
donatien | 8:04b6a042595f | 145 | case 6: strcpy(bearer, "UTRAN w/HSDPA and HSUPA"); break; |
donatien | 8:04b6a042595f | 146 | case 7: strcpy(bearer, "E-UTRAN"); break; |
donatien | 8:04b6a042595f | 147 | |
donatien | 8:04b6a042595f | 148 | default: |
donatien | 8:04b6a042595f | 149 | break; |
donatien | 8:04b6a042595f | 150 | } |
donatien | 8:04b6a042595f | 151 | return OK; |
donatien | 8:04b6a042595f | 152 | } |
donatien | 8:04b6a042595f | 153 | virtual int onNewEntryPrompt(ATCommandsInterface* pInst) |
donatien | 8:04b6a042595f | 154 | { |
donatien | 8:04b6a042595f | 155 | return OK; |
donatien | 8:04b6a042595f | 156 | } |
donatien | 8:04b6a042595f | 157 | char network[24]; |
donatien | 8:04b6a042595f | 158 | char bearer[24]; |
donatien | 8:04b6a042595f | 159 | char apn[24]; |
donatien | 8:04b6a042595f | 160 | volatile bool valid; |
donatien | 8:04b6a042595f | 161 | }; |
donatien | 8:04b6a042595f | 162 | |
donatien | 8:04b6a042595f | 163 | |
donatien | 8:04b6a042595f | 164 | int VodafoneK3770::connect(const char* apn, const char* user, const char* password) |
donatien | 8:04b6a042595f | 165 | { |
donatien | 8:04b6a042595f | 166 | if( !m_ipInit ) |
donatien | 8:04b6a042595f | 167 | { |
donatien | 8:04b6a042595f | 168 | m_ipInit = true; |
donatien | 8:04b6a042595f | 169 | m_ppp.init(); |
donatien | 8:04b6a042595f | 170 | } |
donatien | 8:04b6a042595f | 171 | m_ppp.setup(user, password); |
donatien | 8:04b6a042595f | 172 | |
donatien | 8:04b6a042595f | 173 | int ret = init(); |
donatien | 8:04b6a042595f | 174 | if(ret) |
donatien | 8:04b6a042595f | 175 | { |
donatien | 8:04b6a042595f | 176 | return ret; |
donatien | 8:04b6a042595f | 177 | } |
donatien | 8:04b6a042595f | 178 | |
donatien | 9:3f077dde13c9 | 179 | #if USE_ONE_PORT |
donatien | 8:04b6a042595f | 180 | m_smsInit = false; //SMS status reset |
donatien | 8:04b6a042595f | 181 | m_ussdInit = false; //USSD status reset |
donatien | 9:3f077dde13c9 | 182 | #endif |
donatien | 8:04b6a042595f | 183 | |
donatien | 8:04b6a042595f | 184 | ATCommandsInterface::ATResult result; |
donatien | 8:04b6a042595f | 185 | |
donatien | 9:3f077dde13c9 | 186 | #if 0 |
donatien | 8:04b6a042595f | 187 | //Get network info & select corresponding APN |
donatien | 8:04b6a042595f | 188 | COPSProcessor copsProcessor; |
donatien | 8:04b6a042595f | 189 | DBG("Get network info & select APN from DB"); |
donatien | 8:04b6a042595f | 190 | ret = m_at.execute("AT+COPS=,2;+COPS?", &copsProcessor, &result); //Configure to get operator's info in numeric code & get operator's id |
donatien | 8:04b6a042595f | 191 | DBG("Result of command: Err code=%d", ret); |
donatien | 8:04b6a042595f | 192 | DBG("ATResult: AT return=%d (code %d)", result.result, result.code); |
donatien | 8:04b6a042595f | 193 | |
donatien | 8:04b6a042595f | 194 | if(!copsProcessor.isValid()) |
donatien | 8:04b6a042595f | 195 | { |
donatien | 8:04b6a042595f | 196 | WARN("Connected to an unknown network, try to connect with default parameters"); |
donatien | 8:04b6a042595f | 197 | DBG("Connected with %s", copsProcessor.getBearer()); |
donatien | 8:04b6a042595f | 198 | } |
donatien | 8:04b6a042595f | 199 | else |
donatien | 8:04b6a042595f | 200 | { |
donatien | 8:04b6a042595f | 201 | DBG("Connected to %s with %s", copsProcessor.getNetwork(), copsProcessor.getBearer()); |
donatien | 8:04b6a042595f | 202 | char cmd[48]; |
donatien | 8:04b6a042595f | 203 | sprintf(cmd, "AT+CGDCONT=1,\"IP\",\"%s\"", copsProcessor.getAPN()); |
donatien | 8:04b6a042595f | 204 | ret = m_at.executeSimple(cmd, &result); |
donatien | 8:04b6a042595f | 205 | DBG("Result of command: Err code=%d", ret); |
donatien | 8:04b6a042595f | 206 | DBG("ATResult: AT return=%d (code %d)", result.result, result.code); |
donatien | 8:04b6a042595f | 207 | DBG("APN set to %s", copsProcessor.getAPN()); |
donatien | 8:04b6a042595f | 208 | } |
donatien | 8:04b6a042595f | 209 | #else |
donatien | 8:04b6a042595f | 210 | if(apn != NULL) |
donatien | 8:04b6a042595f | 211 | { |
donatien | 8:04b6a042595f | 212 | char cmd[48]; |
donatien | 8:04b6a042595f | 213 | sprintf(cmd, "AT+CGDCONT=1,\"IP\",\"%s\"", apn); |
donatien | 8:04b6a042595f | 214 | ret = m_at.executeSimple(cmd, &result); |
donatien | 8:04b6a042595f | 215 | DBG("Result of command: Err code=%d", ret); |
donatien | 8:04b6a042595f | 216 | DBG("ATResult: AT return=%d (code %d)", result.result, result.code); |
donatien | 8:04b6a042595f | 217 | DBG("APN set to %s", apn); |
donatien | 8:04b6a042595f | 218 | } |
donatien | 8:04b6a042595f | 219 | #endif |
donatien | 8:04b6a042595f | 220 | |
donatien | 8:04b6a042595f | 221 | |
donatien | 8:04b6a042595f | 222 | //Connect |
donatien | 8:04b6a042595f | 223 | DBG("Connecting"); |
donatien | 9:3f077dde13c9 | 224 | #if 0 |
donatien | 8:04b6a042595f | 225 | ret = m_at.executeSimple("ATDT *99#", &result); |
donatien | 8:04b6a042595f | 226 | DBG("Result of command: Err code=%d", ret); |
donatien | 8:04b6a042595f | 227 | DBG("ATResult: AT return=%d (code %d)", result.result, result.code); |
donatien | 9:3f077dde13c9 | 228 | #endif |
donatien | 9:3f077dde13c9 | 229 | #if USE_ONE_PORT |
donatien | 8:04b6a042595f | 230 | m_at.close(); // Closing AT parser |
donatien | 8:04b6a042595f | 231 | m_atOpen = false; //Will need to be reinitialized afterwards |
donatien | 9:3f077dde13c9 | 232 | #endif |
donatien | 8:04b6a042595f | 233 | |
donatien | 9:3f077dde13c9 | 234 | #if 0 |
donatien | 8:04b6a042595f | 235 | DBG("AT Parser closed"); |
donatien | 8:04b6a042595f | 236 | if( (ret!=NET_MOREINFO) || (result.result != ATCommandsInterface::ATResult::AT_CONNECT)) |
donatien | 8:04b6a042595f | 237 | { |
donatien | 8:04b6a042595f | 238 | ERR("Could not connect"); |
donatien | 8:04b6a042595f | 239 | return ret; //Could not connect |
donatien | 8:04b6a042595f | 240 | } |
donatien | 9:3f077dde13c9 | 241 | #endif |
donatien | 8:04b6a042595f | 242 | DBG("Connecting PPP"); |
donatien | 8:04b6a042595f | 243 | |
donatien | 9:3f077dde13c9 | 244 | ret = m_ppp.connect("*99#"); |
donatien | 8:04b6a042595f | 245 | DBG("Result of connect: Err code=%d", ret); |
donatien | 8:04b6a042595f | 246 | return ret; |
donatien | 8:04b6a042595f | 247 | } |
donatien | 8:04b6a042595f | 248 | |
donatien | 8:04b6a042595f | 249 | |
donatien | 8:04b6a042595f | 250 | int VodafoneK3770::disconnect() |
donatien | 8:04b6a042595f | 251 | { |
donatien | 8:04b6a042595f | 252 | DBG("Disconnecting from PPP"); |
donatien | 8:04b6a042595f | 253 | int ret = m_ppp.disconnect(); |
donatien | 8:04b6a042595f | 254 | if(ret) |
donatien | 8:04b6a042595f | 255 | { |
donatien | 8:04b6a042595f | 256 | ERR("Disconnect returned %d, still trying to disconnect", ret); |
donatien | 8:04b6a042595f | 257 | } |
donatien | 8:04b6a042595f | 258 | |
donatien | 8:04b6a042595f | 259 | //Ugly but leave dongle time to recover |
donatien | 8:04b6a042595f | 260 | Thread::wait(500); |
donatien | 8:04b6a042595f | 261 | |
donatien | 9:3f077dde13c9 | 262 | #if USE_ONE_PORT |
donatien | 8:04b6a042595f | 263 | ATCommandsInterface::ATResult result; |
donatien | 8:04b6a042595f | 264 | DBG("Starting AT thread"); |
donatien | 8:04b6a042595f | 265 | ret = m_at.open(); |
donatien | 8:04b6a042595f | 266 | if(ret) |
donatien | 8:04b6a042595f | 267 | { |
donatien | 8:04b6a042595f | 268 | return ret; |
donatien | 8:04b6a042595f | 269 | } |
donatien | 9:3f077dde13c9 | 270 | #endif |
donatien | 8:04b6a042595f | 271 | |
donatien | 8:04b6a042595f | 272 | DBG("Trying to hangup"); |
donatien | 8:04b6a042595f | 273 | |
donatien | 9:3f077dde13c9 | 274 | #if 0 //Does not appear to work |
donatien | 8:04b6a042595f | 275 | int tries = 10; |
donatien | 8:04b6a042595f | 276 | do |
donatien | 8:04b6a042595f | 277 | { |
donatien | 8:04b6a042595f | 278 | ret = m_at.executeSimple("+++", &result, 1000); |
donatien | 8:04b6a042595f | 279 | DBG("Result of command: Err code=%d\n", ret); |
donatien | 8:04b6a042595f | 280 | DBG("ATResult: AT return=%d (code %d)\n", result.result, result.code); |
donatien | 8:04b6a042595f | 281 | } while(tries-- && ret); |
donatien | 8:04b6a042595f | 282 | if(!ret) |
donatien | 8:04b6a042595f | 283 | { |
donatien | 8:04b6a042595f | 284 | ret = m_at.executeSimple("ATH", &result); |
donatien | 8:04b6a042595f | 285 | DBG("Result of command: Err code=%d\n", ret); |
donatien | 8:04b6a042595f | 286 | DBG("ATResult: AT return=%d (code %d)\n", result.result, result.code); |
donatien | 8:04b6a042595f | 287 | } |
donatien | 9:3f077dde13c9 | 288 | #endif |
donatien | 8:04b6a042595f | 289 | |
donatien | 9:3f077dde13c9 | 290 | #if USE_ONE_PORT |
donatien | 8:04b6a042595f | 291 | //Reinit AT parser |
donatien | 8:04b6a042595f | 292 | ret = m_at.init(); |
donatien | 8:04b6a042595f | 293 | DBG("Result of command: Err code=%d\n", ret); |
donatien | 8:04b6a042595f | 294 | if(ret) |
donatien | 8:04b6a042595f | 295 | { |
donatien | 8:04b6a042595f | 296 | m_at.close(); // Closing AT parser |
donatien | 8:04b6a042595f | 297 | DBG("AT Parser closed, could not complete disconnection"); |
donatien | 8:04b6a042595f | 298 | return NET_TIMEOUT; |
donatien | 8:04b6a042595f | 299 | } |
donatien | 8:04b6a042595f | 300 | |
donatien | 9:3f077dde13c9 | 301 | #if 0 |
donatien | 8:04b6a042595f | 302 | m_at.close(); // Closing AT parser |
donatien | 8:04b6a042595f | 303 | DBG("AT Parser closed"); |
donatien | 9:3f077dde13c9 | 304 | #endif |
donatien | 9:3f077dde13c9 | 305 | #endif |
donatien | 8:04b6a042595f | 306 | return OK; |
donatien | 8:04b6a042595f | 307 | } |
donatien | 8:04b6a042595f | 308 | |
donatien | 8:04b6a042595f | 309 | int VodafoneK3770::sendSM(const char* number, const char* message) |
donatien | 8:04b6a042595f | 310 | { |
donatien | 8:04b6a042595f | 311 | int ret = init(); |
donatien | 8:04b6a042595f | 312 | if(ret) |
donatien | 8:04b6a042595f | 313 | { |
donatien | 8:04b6a042595f | 314 | return ret; |
donatien | 8:04b6a042595f | 315 | } |
donatien | 8:04b6a042595f | 316 | |
donatien | 8:04b6a042595f | 317 | if(!m_smsInit) |
donatien | 8:04b6a042595f | 318 | { |
donatien | 8:04b6a042595f | 319 | ret = m_sms.init(); |
donatien | 8:04b6a042595f | 320 | if(ret) |
donatien | 8:04b6a042595f | 321 | { |
donatien | 8:04b6a042595f | 322 | return ret; |
donatien | 8:04b6a042595f | 323 | } |
donatien | 8:04b6a042595f | 324 | m_smsInit = true; |
donatien | 8:04b6a042595f | 325 | } |
donatien | 8:04b6a042595f | 326 | |
donatien | 8:04b6a042595f | 327 | ret = m_sms.send(number, message); |
donatien | 8:04b6a042595f | 328 | if(ret) |
donatien | 8:04b6a042595f | 329 | { |
donatien | 8:04b6a042595f | 330 | return ret; |
donatien | 8:04b6a042595f | 331 | } |
donatien | 8:04b6a042595f | 332 | |
donatien | 8:04b6a042595f | 333 | return OK; |
donatien | 8:04b6a042595f | 334 | } |
donatien | 8:04b6a042595f | 335 | |
donatien | 8:04b6a042595f | 336 | int VodafoneK3770::getSM(char* number, char* message, size_t maxLength) |
donatien | 8:04b6a042595f | 337 | { |
donatien | 8:04b6a042595f | 338 | int ret = init(); |
donatien | 8:04b6a042595f | 339 | if(ret) |
donatien | 8:04b6a042595f | 340 | { |
donatien | 8:04b6a042595f | 341 | return ret; |
donatien | 8:04b6a042595f | 342 | } |
donatien | 8:04b6a042595f | 343 | |
donatien | 8:04b6a042595f | 344 | if(!m_smsInit) |
donatien | 8:04b6a042595f | 345 | { |
donatien | 8:04b6a042595f | 346 | ret = m_sms.init(); |
donatien | 8:04b6a042595f | 347 | if(ret) |
donatien | 8:04b6a042595f | 348 | { |
donatien | 8:04b6a042595f | 349 | return ret; |
donatien | 8:04b6a042595f | 350 | } |
donatien | 8:04b6a042595f | 351 | m_smsInit = true; |
donatien | 8:04b6a042595f | 352 | } |
donatien | 8:04b6a042595f | 353 | |
donatien | 8:04b6a042595f | 354 | ret = m_sms.get(number, message, maxLength); |
donatien | 8:04b6a042595f | 355 | if(ret) |
donatien | 8:04b6a042595f | 356 | { |
donatien | 8:04b6a042595f | 357 | return ret; |
donatien | 8:04b6a042595f | 358 | } |
donatien | 8:04b6a042595f | 359 | |
donatien | 8:04b6a042595f | 360 | return OK; |
donatien | 8:04b6a042595f | 361 | } |
donatien | 8:04b6a042595f | 362 | |
donatien | 8:04b6a042595f | 363 | int VodafoneK3770::getSMCount(size_t* pCount) |
donatien | 8:04b6a042595f | 364 | { |
donatien | 8:04b6a042595f | 365 | int ret = init(); |
donatien | 8:04b6a042595f | 366 | if(ret) |
donatien | 8:04b6a042595f | 367 | { |
donatien | 8:04b6a042595f | 368 | return ret; |
donatien | 8:04b6a042595f | 369 | } |
donatien | 8:04b6a042595f | 370 | |
donatien | 8:04b6a042595f | 371 | if(!m_smsInit) |
donatien | 8:04b6a042595f | 372 | { |
donatien | 8:04b6a042595f | 373 | ret = m_sms.init(); |
donatien | 8:04b6a042595f | 374 | if(ret) |
donatien | 8:04b6a042595f | 375 | { |
donatien | 8:04b6a042595f | 376 | return ret; |
donatien | 8:04b6a042595f | 377 | } |
donatien | 8:04b6a042595f | 378 | m_smsInit = true; |
donatien | 8:04b6a042595f | 379 | } |
donatien | 8:04b6a042595f | 380 | |
donatien | 8:04b6a042595f | 381 | ret = m_sms.getCount(pCount); |
donatien | 8:04b6a042595f | 382 | if(ret) |
donatien | 8:04b6a042595f | 383 | { |
donatien | 8:04b6a042595f | 384 | return ret; |
donatien | 8:04b6a042595f | 385 | } |
donatien | 8:04b6a042595f | 386 | |
donatien | 8:04b6a042595f | 387 | return OK; |
donatien | 8:04b6a042595f | 388 | } |
donatien | 8:04b6a042595f | 389 | |
donatien | 8:04b6a042595f | 390 | int VodafoneK3770::sendUSSD(const char* command, char* result, size_t maxLength) |
donatien | 8:04b6a042595f | 391 | { |
donatien | 8:04b6a042595f | 392 | int ret = init(); |
donatien | 8:04b6a042595f | 393 | if(ret) |
donatien | 8:04b6a042595f | 394 | { |
donatien | 8:04b6a042595f | 395 | return ret; |
donatien | 8:04b6a042595f | 396 | } |
donatien | 8:04b6a042595f | 397 | |
donatien | 8:04b6a042595f | 398 | if(!m_ussdInit) |
donatien | 8:04b6a042595f | 399 | { |
donatien | 8:04b6a042595f | 400 | ret = m_ussd.init(); |
donatien | 8:04b6a042595f | 401 | if(ret) |
donatien | 8:04b6a042595f | 402 | { |
donatien | 8:04b6a042595f | 403 | return ret; |
donatien | 8:04b6a042595f | 404 | } |
donatien | 8:04b6a042595f | 405 | m_ussdInit = true; |
donatien | 8:04b6a042595f | 406 | } |
donatien | 8:04b6a042595f | 407 | |
donatien | 8:04b6a042595f | 408 | ret = m_ussd.send(command, result, maxLength); |
donatien | 8:04b6a042595f | 409 | if(ret) |
donatien | 8:04b6a042595f | 410 | { |
donatien | 8:04b6a042595f | 411 | return ret; |
donatien | 8:04b6a042595f | 412 | } |
donatien | 8:04b6a042595f | 413 | |
donatien | 8:04b6a042595f | 414 | return OK; |
donatien | 8:04b6a042595f | 415 | } |
donatien | 8:04b6a042595f | 416 | |
donatien | 8:04b6a042595f | 417 | ATCommandsInterface* VodafoneK3770::getATCommandsInterface() |
donatien | 8:04b6a042595f | 418 | { |
donatien | 8:04b6a042595f | 419 | return &m_at; |
donatien | 8:04b6a042595f | 420 | } |
donatien | 8:04b6a042595f | 421 | |
donatien | 8:04b6a042595f | 422 | int VodafoneK3770::init() |
donatien | 8:04b6a042595f | 423 | { |
donatien | 8:04b6a042595f | 424 | if( !m_dongleConnected ) |
donatien | 8:04b6a042595f | 425 | { |
donatien | 8:04b6a042595f | 426 | m_dongleConnected = true; |
donatien | 8:04b6a042595f | 427 | while( !m_dongle.connected() ) |
donatien | 8:04b6a042595f | 428 | { |
donatien | 8:04b6a042595f | 429 | m_dongle.tryConnect(); |
donatien | 8:04b6a042595f | 430 | Thread::wait(10); |
donatien | 8:04b6a042595f | 431 | } |
donatien | 8:04b6a042595f | 432 | } |
donatien | 8:04b6a042595f | 433 | |
donatien | 8:04b6a042595f | 434 | if(m_atOpen) |
donatien | 8:04b6a042595f | 435 | { |
donatien | 8:04b6a042595f | 436 | return OK; |
donatien | 8:04b6a042595f | 437 | } |
donatien | 8:04b6a042595f | 438 | |
donatien | 8:04b6a042595f | 439 | DBG("Starting AT thread if needed"); |
donatien | 8:04b6a042595f | 440 | int ret = m_at.open(); |
donatien | 8:04b6a042595f | 441 | if(ret) |
donatien | 8:04b6a042595f | 442 | { |
donatien | 8:04b6a042595f | 443 | return ret; |
donatien | 8:04b6a042595f | 444 | } |
donatien | 8:04b6a042595f | 445 | |
donatien | 8:04b6a042595f | 446 | DBG("Sending initialisation commands"); |
donatien | 8:04b6a042595f | 447 | ret = m_at.init(); |
donatien | 8:04b6a042595f | 448 | if(ret) |
donatien | 8:04b6a042595f | 449 | { |
donatien | 8:04b6a042595f | 450 | return ret; |
donatien | 8:04b6a042595f | 451 | } |
donatien | 8:04b6a042595f | 452 | |
donatien | 9:3f077dde13c9 | 453 | #if USE_ONE_PORT |
donatien | 8:04b6a042595f | 454 | DBG("Configuring unsolicited result codes support properly"); |
donatien | 8:04b6a042595f | 455 | //Configuring port |
donatien | 8:04b6a042595f | 456 | ret = m_at.executeSimple("AT^CURC=0;^PORTSEL=1", NULL); //Huawei-specific, not 3GPP-compliant |
donatien | 8:04b6a042595f | 457 | if(ret != OK) |
donatien | 8:04b6a042595f | 458 | { |
donatien | 8:04b6a042595f | 459 | return NET_PROTOCOL; |
donatien | 8:04b6a042595f | 460 | } |
donatien | 9:3f077dde13c9 | 461 | #endif |
donatien | 8:04b6a042595f | 462 | |
donatien | 8:04b6a042595f | 463 | ATCommandsInterface::ATResult result; |
donatien | 8:04b6a042595f | 464 | |
donatien | 8:04b6a042595f | 465 | //Wait for network registration |
donatien | 8:04b6a042595f | 466 | CREGProcessor cregProcessor; |
donatien | 8:04b6a042595f | 467 | do |
donatien | 8:04b6a042595f | 468 | { |
donatien | 8:04b6a042595f | 469 | DBG("Waiting for network registration"); |
donatien | 8:04b6a042595f | 470 | ret = m_at.execute("AT+CREG?", &cregProcessor, &result); |
donatien | 8:04b6a042595f | 471 | DBG("Result of command: Err code=%d\n", ret); |
donatien | 8:04b6a042595f | 472 | DBG("ATResult: AT return=%d (code %d)\n", result.result, result.code); |
donatien | 8:04b6a042595f | 473 | if(cregProcessor.getStatus() == CREGProcessor::STATUS_REGISTERING) |
donatien | 8:04b6a042595f | 474 | { |
donatien | 8:04b6a042595f | 475 | Thread::wait(3000); |
donatien | 8:04b6a042595f | 476 | } |
donatien | 8:04b6a042595f | 477 | } while(cregProcessor.getStatus() == CREGProcessor::STATUS_REGISTERING); |
donatien | 8:04b6a042595f | 478 | if(cregProcessor.getStatus() == CREGProcessor::STATUS_FAILED) |
donatien | 8:04b6a042595f | 479 | { |
donatien | 8:04b6a042595f | 480 | ERR("Registration denied"); |
donatien | 8:04b6a042595f | 481 | return NET_AUTH; |
donatien | 8:04b6a042595f | 482 | } |
donatien | 8:04b6a042595f | 483 | |
donatien | 8:04b6a042595f | 484 | m_atOpen = true; |
donatien | 8:04b6a042595f | 485 | |
donatien | 8:04b6a042595f | 486 | return OK; |
donatien | 8:04b6a042595f | 487 | } |
donatien | 8:04b6a042595f | 488 | |
donatien | 8:04b6a042595f | 489 | |
donatien | 8:04b6a042595f | 490 |