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