fork of VodafoneUSBModem with updated USBHost library
Dependencies: Socket USBHost lwip-sys lwip
Dependents: VodafoneUSBModemSMSTest
link/LinkMonitor.cpp@49:978bffab17a8, 2012-09-27 (annotated)
- Committer:
- nherriot
- Date:
- Thu Sep 27 10:13:44 2012 +0000
- Revision:
- 49:978bffab17a8
- Parent:
- 47:47d6101eebeb
- Child:
- 51:54ca82a7644c
changed AT string for getLinkStatus method so that it does not request cell ID. Also changed the init function so that it tells the modem to report operator in the CC and NC 5 digit BCD number.
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 | { |
nherriot | 49:978bffab17a8 | 41 | // we need to make sure that we setup the operator selection to be in 'numeric' format. |
nherriot | 49:978bffab17a8 | 42 | // i.e. it is made up of a network and country code when returned by the modem e.g. Operator = 23415. This allows easy logic parsing for |
nherriot | 49:978bffab17a8 | 43 | // setting up other network parameters in future. |
nherriot | 49:978bffab17a8 | 44 | |
nherriot | 49:978bffab17a8 | 45 | DBG("LinkMonitor::init() being called. This should only happen once: executinging AT+COPS=0,2"); |
nherriot | 49:978bffab17a8 | 46 | int ret = m_pIf->execute("AT+COPS=0,2", this, NULL, DEFAULT_TIMEOUT); //Configure to set the operator string to Country Code and mobile network code |
nherriot | 49:978bffab17a8 | 47 | if(ret != OK) |
nherriot | 49:978bffab17a8 | 48 | { |
nherriot | 49:978bffab17a8 | 49 | WARN(" NET_PROTOCOL error from sending the AT+COPS command to the modem. "); |
nherriot | 49:978bffab17a8 | 50 | return NET_PROTOCOL; |
nherriot | 49:978bffab17a8 | 51 | } |
donatien | 12:66dc2c8eba2d | 52 | return OK; |
donatien | 12:66dc2c8eba2d | 53 | } |
donatien | 12:66dc2c8eba2d | 54 | |
donatien | 12:66dc2c8eba2d | 55 | /*virtual*/ int LinkMonitor::onNewATResponseLine(ATCommandsInterface* pInst, const char* line) |
donatien | 12:66dc2c8eba2d | 56 | { |
donatien | 12:66dc2c8eba2d | 57 | DBG("Line is %s", line); |
donatien | 12:66dc2c8eba2d | 58 | int v; |
donatien | 12:66dc2c8eba2d | 59 | if( sscanf(line, "+CREG: %*d,%d", &v) >= 1 ) //Reg state is valid |
donatien | 12:66dc2c8eba2d | 60 | { |
donatien | 12:66dc2c8eba2d | 61 | DBG("+CREG %d", v); |
donatien | 12:66dc2c8eba2d | 62 | switch( v ) |
donatien | 12:66dc2c8eba2d | 63 | { |
donatien | 12:66dc2c8eba2d | 64 | case 0: |
donatien | 12:66dc2c8eba2d | 65 | m_registrationState = REGISTRATION_STATE_UNKNOWN; |
donatien | 12:66dc2c8eba2d | 66 | break; |
donatien | 12:66dc2c8eba2d | 67 | case 1: |
donatien | 12:66dc2c8eba2d | 68 | m_registrationState = REGISTRATION_STATE_HOME_NETWORK; |
donatien | 12:66dc2c8eba2d | 69 | break; |
donatien | 12:66dc2c8eba2d | 70 | case 2: |
donatien | 12:66dc2c8eba2d | 71 | m_registrationState = REGISTRATION_STATE_REGISTERING; |
donatien | 12:66dc2c8eba2d | 72 | break; |
donatien | 12:66dc2c8eba2d | 73 | case 3: |
donatien | 12:66dc2c8eba2d | 74 | m_registrationState = REGISTRATION_STATE_DENIED; |
donatien | 12:66dc2c8eba2d | 75 | break; |
donatien | 12:66dc2c8eba2d | 76 | case 4: |
donatien | 12:66dc2c8eba2d | 77 | m_registrationState = REGISTRATION_STATE_NO_SIGNAL; |
donatien | 12:66dc2c8eba2d | 78 | break; |
donatien | 12:66dc2c8eba2d | 79 | case 5: |
donatien | 12:66dc2c8eba2d | 80 | m_registrationState = REGISTRATION_STATE_ROAMING; |
donatien | 12:66dc2c8eba2d | 81 | break; |
donatien | 12:66dc2c8eba2d | 82 | default: |
donatien | 12:66dc2c8eba2d | 83 | m_registrationState = REGISTRATION_STATE_UNKNOWN; |
donatien | 12:66dc2c8eba2d | 84 | break; |
donatien | 12:66dc2c8eba2d | 85 | } |
donatien | 12:66dc2c8eba2d | 86 | } |
donatien | 12:66dc2c8eba2d | 87 | else if( sscanf(line, "+COPS: %*d,%*d,\"%*[^\"]\",%d", &v) >= 1 ) |
donatien | 12:66dc2c8eba2d | 88 | { |
donatien | 12:66dc2c8eba2d | 89 | DBG("+COPS %d", v); |
donatien | 12:66dc2c8eba2d | 90 | switch( v ) |
donatien | 12:66dc2c8eba2d | 91 | { |
donatien | 12:66dc2c8eba2d | 92 | case 0: |
donatien | 12:66dc2c8eba2d | 93 | m_bearer = BEARER_GSM; |
donatien | 12:66dc2c8eba2d | 94 | break; |
donatien | 12:66dc2c8eba2d | 95 | case 2: |
donatien | 12:66dc2c8eba2d | 96 | m_bearer = BEARER_UMTS; |
donatien | 12:66dc2c8eba2d | 97 | break; |
donatien | 12:66dc2c8eba2d | 98 | case 3: |
donatien | 12:66dc2c8eba2d | 99 | m_bearer = BEARER_EDGE; |
donatien | 12:66dc2c8eba2d | 100 | break; |
donatien | 12:66dc2c8eba2d | 101 | case 4: //HSDPA |
donatien | 12:66dc2c8eba2d | 102 | case 5: //HSUPA |
donatien | 12:66dc2c8eba2d | 103 | case 6: //HSDPA + HSUPA |
donatien | 12:66dc2c8eba2d | 104 | m_bearer = BEARER_HSPA; |
donatien | 12:66dc2c8eba2d | 105 | break; |
donatien | 12:66dc2c8eba2d | 106 | case 7: |
donatien | 12:66dc2c8eba2d | 107 | m_bearer = BEARER_LTE; |
donatien | 12:66dc2c8eba2d | 108 | break; |
donatien | 12:66dc2c8eba2d | 109 | case 1: //GSM Compact |
donatien | 12:66dc2c8eba2d | 110 | default: |
donatien | 12:66dc2c8eba2d | 111 | m_bearer = BEARER_UNKNOWN; |
donatien | 12:66dc2c8eba2d | 112 | break; |
donatien | 12:66dc2c8eba2d | 113 | } |
donatien | 12:66dc2c8eba2d | 114 | } |
donatien | 12:66dc2c8eba2d | 115 | else if( sscanf(line, "+CSQ: %d,%*d", &v) >= 1 ) |
donatien | 12:66dc2c8eba2d | 116 | { |
donatien | 12:66dc2c8eba2d | 117 | DBG("+CSQ %d", v); |
donatien | 12:66dc2c8eba2d | 118 | if(v == 99) //Unknown |
donatien | 12:66dc2c8eba2d | 119 | { |
donatien | 12:66dc2c8eba2d | 120 | m_rssi = 0; //Unknown |
donatien | 12:66dc2c8eba2d | 121 | } |
donatien | 12:66dc2c8eba2d | 122 | else |
donatien | 12:66dc2c8eba2d | 123 | { |
donatien | 12:66dc2c8eba2d | 124 | m_rssi = -113 + 2*v; |
donatien | 12:66dc2c8eba2d | 125 | } |
donatien | 12:66dc2c8eba2d | 126 | } |
donatien | 12:66dc2c8eba2d | 127 | return OK; |
donatien | 12:66dc2c8eba2d | 128 | } |
donatien | 12:66dc2c8eba2d | 129 | |
donatien | 12:66dc2c8eba2d | 130 | /*virtual*/ int LinkMonitor::onNewEntryPrompt(ATCommandsInterface* pInst) |
donatien | 12:66dc2c8eba2d | 131 | { |
donatien | 12:66dc2c8eba2d | 132 | return OK; |
donatien | 12:66dc2c8eba2d | 133 | } |
donatien | 12:66dc2c8eba2d | 134 | |
donatien | 12:66dc2c8eba2d | 135 | int LinkMonitor::getState(int* pRssi, REGISTRATION_STATE* pRegistrationState, BEARER* pBearer) |
donatien | 12:66dc2c8eba2d | 136 | { |
donatien | 12:66dc2c8eba2d | 137 | m_rssi = 0; |
donatien | 12:66dc2c8eba2d | 138 | m_registrationState = REGISTRATION_STATE_UNKNOWN; |
donatien | 12:66dc2c8eba2d | 139 | m_bearer = BEARER_UNKNOWN; |
nherriot | 49:978bffab17a8 | 140 | int ret = m_pIf->execute("AT+CREG=0;+CREG?;+COPS?;+CSQ", this, NULL, DEFAULT_TIMEOUT); //Configure to get registration info & get it; get signal quality |
donatien | 12:66dc2c8eba2d | 141 | if(ret != OK) |
donatien | 12:66dc2c8eba2d | 142 | { |
donatien | 12:66dc2c8eba2d | 143 | return NET_PROTOCOL; |
donatien | 12:66dc2c8eba2d | 144 | } |
donatien | 12:66dc2c8eba2d | 145 | *pRssi = m_rssi; |
donatien | 12:66dc2c8eba2d | 146 | *pRegistrationState = m_registrationState; |
donatien | 12:66dc2c8eba2d | 147 | *pBearer = m_bearer; |
donatien | 12:66dc2c8eba2d | 148 | return OK; |
donatien | 12:66dc2c8eba2d | 149 | } |