local fork
Dependencies: Socket USBHostWANDongle_bleedingedge lwip-sys lwip
Fork of VodafoneUSBModem_bleedingedge by
link/LinkMonitor.cpp@47:47d6101eebeb, 2012-09-26 (annotated)
- Committer:
- nherriot
- Date:
- Wed Sep 26 17:01:50 2012 +0000
- Revision:
- 47:47d6101eebeb
- Parent:
- 25:6f3b97dc4295
- Child:
- 49:978bffab17a8
debug switched on for testing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
donatien | 12:66dc2c8eba2d | 1 | /* LinkMonitor.cpp */ |
donatien | 22:06fb2a93a1f6 | 2 | /* Copyright (C) 2012 mbed.org, MIT License |
donatien | 22:06fb2a93a1f6 | 3 | * |
donatien | 22:06fb2a93a1f6 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
donatien | 22:06fb2a93a1f6 | 5 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
donatien | 22:06fb2a93a1f6 | 6 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
donatien | 22:06fb2a93a1f6 | 7 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
donatien | 22:06fb2a93a1f6 | 8 | * furnished to do so, subject to the following conditions: |
donatien | 22:06fb2a93a1f6 | 9 | * |
donatien | 22:06fb2a93a1f6 | 10 | * The above copyright notice and this permission notice shall be included in all copies or |
donatien | 22:06fb2a93a1f6 | 11 | * substantial portions of the Software. |
donatien | 22:06fb2a93a1f6 | 12 | * |
donatien | 22:06fb2a93a1f6 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
donatien | 22:06fb2a93a1f6 | 14 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
donatien | 22:06fb2a93a1f6 | 15 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
donatien | 22:06fb2a93a1f6 | 16 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
donatien | 22:06fb2a93a1f6 | 17 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
donatien | 22:06fb2a93a1f6 | 18 | */ |
donatien | 12:66dc2c8eba2d | 19 | |
nherriot | 47:47d6101eebeb | 20 | #define __DEBUG__ 4 |
donatien | 12:66dc2c8eba2d | 21 | #ifndef __MODULE__ |
donatien | 12:66dc2c8eba2d | 22 | #define __MODULE__ "LinkMonitor.cpp" |
donatien | 12:66dc2c8eba2d | 23 | #endif |
donatien | 12:66dc2c8eba2d | 24 | |
donatien | 12:66dc2c8eba2d | 25 | #include "core/fwk.h" |
donatien | 12:66dc2c8eba2d | 26 | |
donatien | 12:66dc2c8eba2d | 27 | #include "LinkMonitor.h" |
donatien | 12:66dc2c8eba2d | 28 | |
donatien | 12:66dc2c8eba2d | 29 | #include <cstdio> |
donatien | 25:6f3b97dc4295 | 30 | using std::sscanf; |
donatien | 12:66dc2c8eba2d | 31 | |
donatien | 12:66dc2c8eba2d | 32 | #define DEFAULT_TIMEOUT 10000 |
donatien | 12:66dc2c8eba2d | 33 | |
donatien | 12:66dc2c8eba2d | 34 | LinkMonitor::LinkMonitor(ATCommandsInterface* pIf) : m_pIf(pIf), m_rssi(0), m_registrationState(REGISTRATION_STATE_UNKNOWN), m_bearer(BEARER_UNKNOWN) |
donatien | 12:66dc2c8eba2d | 35 | { |
donatien | 12:66dc2c8eba2d | 36 | |
donatien | 12:66dc2c8eba2d | 37 | } |
donatien | 12:66dc2c8eba2d | 38 | |
donatien | 12:66dc2c8eba2d | 39 | int LinkMonitor::init() |
donatien | 12:66dc2c8eba2d | 40 | { |
donatien | 12:66dc2c8eba2d | 41 | return OK; |
donatien | 12:66dc2c8eba2d | 42 | } |
donatien | 12:66dc2c8eba2d | 43 | |
donatien | 12:66dc2c8eba2d | 44 | /*virtual*/ int LinkMonitor::onNewATResponseLine(ATCommandsInterface* pInst, const char* line) |
donatien | 12:66dc2c8eba2d | 45 | { |
donatien | 12:66dc2c8eba2d | 46 | DBG("Line is %s", line); |
donatien | 12:66dc2c8eba2d | 47 | int v; |
donatien | 12:66dc2c8eba2d | 48 | if( sscanf(line, "+CREG: %*d,%d", &v) >= 1 ) //Reg state is valid |
donatien | 12:66dc2c8eba2d | 49 | { |
donatien | 12:66dc2c8eba2d | 50 | DBG("+CREG %d", v); |
donatien | 12:66dc2c8eba2d | 51 | switch( v ) |
donatien | 12:66dc2c8eba2d | 52 | { |
donatien | 12:66dc2c8eba2d | 53 | case 0: |
donatien | 12:66dc2c8eba2d | 54 | m_registrationState = REGISTRATION_STATE_UNKNOWN; |
donatien | 12:66dc2c8eba2d | 55 | break; |
donatien | 12:66dc2c8eba2d | 56 | case 1: |
donatien | 12:66dc2c8eba2d | 57 | m_registrationState = REGISTRATION_STATE_HOME_NETWORK; |
donatien | 12:66dc2c8eba2d | 58 | break; |
donatien | 12:66dc2c8eba2d | 59 | case 2: |
donatien | 12:66dc2c8eba2d | 60 | m_registrationState = REGISTRATION_STATE_REGISTERING; |
donatien | 12:66dc2c8eba2d | 61 | break; |
donatien | 12:66dc2c8eba2d | 62 | case 3: |
donatien | 12:66dc2c8eba2d | 63 | m_registrationState = REGISTRATION_STATE_DENIED; |
donatien | 12:66dc2c8eba2d | 64 | break; |
donatien | 12:66dc2c8eba2d | 65 | case 4: |
donatien | 12:66dc2c8eba2d | 66 | m_registrationState = REGISTRATION_STATE_NO_SIGNAL; |
donatien | 12:66dc2c8eba2d | 67 | break; |
donatien | 12:66dc2c8eba2d | 68 | case 5: |
donatien | 12:66dc2c8eba2d | 69 | m_registrationState = REGISTRATION_STATE_ROAMING; |
donatien | 12:66dc2c8eba2d | 70 | break; |
donatien | 12:66dc2c8eba2d | 71 | default: |
donatien | 12:66dc2c8eba2d | 72 | m_registrationState = REGISTRATION_STATE_UNKNOWN; |
donatien | 12:66dc2c8eba2d | 73 | break; |
donatien | 12:66dc2c8eba2d | 74 | } |
donatien | 12:66dc2c8eba2d | 75 | } |
donatien | 12:66dc2c8eba2d | 76 | else if( sscanf(line, "+COPS: %*d,%*d,\"%*[^\"]\",%d", &v) >= 1 ) |
donatien | 12:66dc2c8eba2d | 77 | { |
donatien | 12:66dc2c8eba2d | 78 | DBG("+COPS %d", v); |
donatien | 12:66dc2c8eba2d | 79 | switch( v ) |
donatien | 12:66dc2c8eba2d | 80 | { |
donatien | 12:66dc2c8eba2d | 81 | case 0: |
donatien | 12:66dc2c8eba2d | 82 | m_bearer = BEARER_GSM; |
donatien | 12:66dc2c8eba2d | 83 | break; |
donatien | 12:66dc2c8eba2d | 84 | case 2: |
donatien | 12:66dc2c8eba2d | 85 | m_bearer = BEARER_UMTS; |
donatien | 12:66dc2c8eba2d | 86 | break; |
donatien | 12:66dc2c8eba2d | 87 | case 3: |
donatien | 12:66dc2c8eba2d | 88 | m_bearer = BEARER_EDGE; |
donatien | 12:66dc2c8eba2d | 89 | break; |
donatien | 12:66dc2c8eba2d | 90 | case 4: //HSDPA |
donatien | 12:66dc2c8eba2d | 91 | case 5: //HSUPA |
donatien | 12:66dc2c8eba2d | 92 | case 6: //HSDPA + HSUPA |
donatien | 12:66dc2c8eba2d | 93 | m_bearer = BEARER_HSPA; |
donatien | 12:66dc2c8eba2d | 94 | break; |
donatien | 12:66dc2c8eba2d | 95 | case 7: |
donatien | 12:66dc2c8eba2d | 96 | m_bearer = BEARER_LTE; |
donatien | 12:66dc2c8eba2d | 97 | break; |
donatien | 12:66dc2c8eba2d | 98 | case 1: //GSM Compact |
donatien | 12:66dc2c8eba2d | 99 | default: |
donatien | 12:66dc2c8eba2d | 100 | m_bearer = BEARER_UNKNOWN; |
donatien | 12:66dc2c8eba2d | 101 | break; |
donatien | 12:66dc2c8eba2d | 102 | } |
donatien | 12:66dc2c8eba2d | 103 | } |
donatien | 12:66dc2c8eba2d | 104 | else if( sscanf(line, "+CSQ: %d,%*d", &v) >= 1 ) |
donatien | 12:66dc2c8eba2d | 105 | { |
donatien | 12:66dc2c8eba2d | 106 | DBG("+CSQ %d", v); |
donatien | 12:66dc2c8eba2d | 107 | if(v == 99) //Unknown |
donatien | 12:66dc2c8eba2d | 108 | { |
donatien | 12:66dc2c8eba2d | 109 | m_rssi = 0; //Unknown |
donatien | 12:66dc2c8eba2d | 110 | } |
donatien | 12:66dc2c8eba2d | 111 | else |
donatien | 12:66dc2c8eba2d | 112 | { |
donatien | 12:66dc2c8eba2d | 113 | m_rssi = -113 + 2*v; |
donatien | 12:66dc2c8eba2d | 114 | } |
donatien | 12:66dc2c8eba2d | 115 | } |
donatien | 12:66dc2c8eba2d | 116 | return OK; |
donatien | 12:66dc2c8eba2d | 117 | } |
donatien | 12:66dc2c8eba2d | 118 | |
donatien | 12:66dc2c8eba2d | 119 | /*virtual*/ int LinkMonitor::onNewEntryPrompt(ATCommandsInterface* pInst) |
donatien | 12:66dc2c8eba2d | 120 | { |
donatien | 12:66dc2c8eba2d | 121 | return OK; |
donatien | 12:66dc2c8eba2d | 122 | } |
donatien | 12:66dc2c8eba2d | 123 | |
donatien | 12:66dc2c8eba2d | 124 | int LinkMonitor::getState(int* pRssi, REGISTRATION_STATE* pRegistrationState, BEARER* pBearer) |
donatien | 12:66dc2c8eba2d | 125 | { |
donatien | 12:66dc2c8eba2d | 126 | m_rssi = 0; |
donatien | 12:66dc2c8eba2d | 127 | m_registrationState = REGISTRATION_STATE_UNKNOWN; |
donatien | 12:66dc2c8eba2d | 128 | m_bearer = BEARER_UNKNOWN; |
donatien | 12:66dc2c8eba2d | 129 | int ret = m_pIf->execute("AT+CREG=2;+CREG?;+CREG=0;+COPS?;+CSQ", this, NULL, DEFAULT_TIMEOUT); //Configure to get registration info & get it; get signal quality |
donatien | 12:66dc2c8eba2d | 130 | if(ret != OK) |
donatien | 12:66dc2c8eba2d | 131 | { |
donatien | 12:66dc2c8eba2d | 132 | return NET_PROTOCOL; |
donatien | 12:66dc2c8eba2d | 133 | } |
donatien | 12:66dc2c8eba2d | 134 | *pRssi = m_rssi; |
donatien | 12:66dc2c8eba2d | 135 | *pRegistrationState = m_registrationState; |
donatien | 12:66dc2c8eba2d | 136 | *pBearer = m_bearer; |
donatien | 12:66dc2c8eba2d | 137 | return OK; |
donatien | 12:66dc2c8eba2d | 138 | } |