This library controls the WNC. There is a derived class for usage from the K64F board.
Fork of WncControllerLibrary by
WncController.cpp@18:ca2899c353c2, 2016-09-13 (annotated)
- Committer:
- fkellermavnet
- Date:
- Tue Sep 13 19:10:34 2016 +0000
- Revision:
- 18:ca2899c353c2
- Parent:
- 17:59b1e9341188
- Child:
- 19:83a52353b97e
Enhanced SMS.; Added ICCID.; Added MSISDN.; Increased max sockets at once to 5.;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fkellermavnet | 0:affdbb35faa4 | 1 | /* |
fkellermavnet | 0:affdbb35faa4 | 2 | Copyright (c) 2016 Fred Kellerman |
fkellermavnet | 0:affdbb35faa4 | 3 | |
fkellermavnet | 0:affdbb35faa4 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
fkellermavnet | 0:affdbb35faa4 | 5 | of this software and associated documentation files (the "Software"), to deal |
fkellermavnet | 0:affdbb35faa4 | 6 | in the Software without restriction, including without limitation the rights |
fkellermavnet | 0:affdbb35faa4 | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
fkellermavnet | 0:affdbb35faa4 | 8 | copies of the Software, and to permit persons to whom the Software is |
fkellermavnet | 0:affdbb35faa4 | 9 | furnished to do so, subject to the following conditions: |
fkellermavnet | 0:affdbb35faa4 | 10 | |
fkellermavnet | 0:affdbb35faa4 | 11 | The above copyright notice and this permission notice shall be included in |
fkellermavnet | 0:affdbb35faa4 | 12 | all copies or substantial portions of the Software. |
fkellermavnet | 0:affdbb35faa4 | 13 | |
fkellermavnet | 0:affdbb35faa4 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
fkellermavnet | 0:affdbb35faa4 | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
fkellermavnet | 0:affdbb35faa4 | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
fkellermavnet | 0:affdbb35faa4 | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
fkellermavnet | 0:affdbb35faa4 | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
fkellermavnet | 0:affdbb35faa4 | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
fkellermavnet | 0:affdbb35faa4 | 20 | THE SOFTWARE. |
fkellermavnet | 0:affdbb35faa4 | 21 | |
fkellermavnet | 0:affdbb35faa4 | 22 | @file WncController.cpp |
fkellermavnet | 0:affdbb35faa4 | 23 | @purpose Controls WNC 14A2A Cellular Modem |
fkellermavnet | 0:affdbb35faa4 | 24 | @version 1.0 |
fkellermavnet | 0:affdbb35faa4 | 25 | @date July 2016 |
fkellermavnet | 0:affdbb35faa4 | 26 | @author Fred Kellerman |
fkellermavnet | 0:affdbb35faa4 | 27 | */ |
fkellermavnet | 0:affdbb35faa4 | 28 | |
fkellermavnet | 0:affdbb35faa4 | 29 | |
fkellermavnet | 0:affdbb35faa4 | 30 | #include <cstdlib> |
fkellermavnet | 0:affdbb35faa4 | 31 | #include <cctype> |
fkellermavnet | 0:affdbb35faa4 | 32 | #include "WncController.h" |
fkellermavnet | 0:affdbb35faa4 | 33 | |
fkellermavnet | 0:affdbb35faa4 | 34 | namespace WncController_fk { |
fkellermavnet | 0:affdbb35faa4 | 35 | |
fkellermavnet | 0:affdbb35faa4 | 36 | ///////////////////////////////////////////////////// |
fkellermavnet | 0:affdbb35faa4 | 37 | // Static initializers |
fkellermavnet | 0:affdbb35faa4 | 38 | ///////////////////////////////////////////////////// |
fkellermavnet | 10:2ec59906a24e | 39 | WncController::WncSocketInfo_s WncController::m_sSock[MAX_NUM_WNC_SOCKETS]; |
fkellermavnet | 10:2ec59906a24e | 40 | const WncController::WncSocketInfo_s WncController::defaultSockStruct = { 0, false, "192.168.0.1", 80, 0, 25, true, 30 }; |
fkellermavnet | 10:2ec59906a24e | 41 | |
fkellermavnet | 0:affdbb35faa4 | 42 | WncController::WncState_e WncController::m_sState = WNC_OFF; |
fkellermavnet | 0:affdbb35faa4 | 43 | uint16_t WncController::m_sCmdTimeoutMs = WNC_CMD_TIMEOUT_MS; |
fkellermavnet | 0:affdbb35faa4 | 44 | string WncController::m_sApnStr = "NULL"; |
fkellermavnet | 0:affdbb35faa4 | 45 | string WncController::m_sWncStr; |
fkellermavnet | 0:affdbb35faa4 | 46 | uint8_t WncController::m_sPowerUpTimeoutSecs = MAX_POWERUP_TIMEOUT; |
fkellermavnet | 0:affdbb35faa4 | 47 | bool WncController::m_sDebugEnabled = false; |
fkellermavnet | 0:affdbb35faa4 | 48 | bool WncController::m_sMoreDebugEnabled = false; |
fkellermavnet | 0:affdbb35faa4 | 49 | bool WncController::m_sCheckNetStatus = false; // Turn on internet status check between every command |
fkellermavnet | 0:affdbb35faa4 | 50 | const char * const WncController::INVALID_IP_STR = ""; |
fkellermavnet | 0:affdbb35faa4 | 51 | bool WncController::m_sReadyForSMS = false; |
fkellermavnet | 0:affdbb35faa4 | 52 | |
fkellermavnet | 0:affdbb35faa4 | 53 | |
fkellermavnet | 0:affdbb35faa4 | 54 | /** |
fkellermavnet | 0:affdbb35faa4 | 55 | * C++ version 0.4 char* style "itoa": |
fkellermavnet | 0:affdbb35faa4 | 56 | * Written by Lukás Chmela |
fkellermavnet | 0:affdbb35faa4 | 57 | * Released under GPLv3. |
fkellermavnet | 0:affdbb35faa4 | 58 | */ |
fkellermavnet | 0:affdbb35faa4 | 59 | |
fkellermavnet | 0:affdbb35faa4 | 60 | static char* itoa(int64_t value, char* result, int base) |
fkellermavnet | 0:affdbb35faa4 | 61 | { |
fkellermavnet | 0:affdbb35faa4 | 62 | // check that the base is valid |
fkellermavnet | 0:affdbb35faa4 | 63 | if ( base < 2 || base > 36 ) { |
fkellermavnet | 0:affdbb35faa4 | 64 | *result = '\0'; |
fkellermavnet | 0:affdbb35faa4 | 65 | return result; |
fkellermavnet | 0:affdbb35faa4 | 66 | } |
fkellermavnet | 0:affdbb35faa4 | 67 | |
fkellermavnet | 0:affdbb35faa4 | 68 | char* ptr = result, *ptr1 = result, tmp_char; |
fkellermavnet | 0:affdbb35faa4 | 69 | int64_t tmp_value; |
fkellermavnet | 0:affdbb35faa4 | 70 | |
fkellermavnet | 0:affdbb35faa4 | 71 | do { |
fkellermavnet | 0:affdbb35faa4 | 72 | tmp_value = value; |
fkellermavnet | 0:affdbb35faa4 | 73 | value /= base; |
fkellermavnet | 0:affdbb35faa4 | 74 | *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - value * base)]; |
fkellermavnet | 0:affdbb35faa4 | 75 | } while ( value ); |
fkellermavnet | 0:affdbb35faa4 | 76 | |
fkellermavnet | 0:affdbb35faa4 | 77 | // Apply negative sign |
fkellermavnet | 0:affdbb35faa4 | 78 | if ( tmp_value < 0 ) |
fkellermavnet | 0:affdbb35faa4 | 79 | *ptr++ = '-'; |
fkellermavnet | 0:affdbb35faa4 | 80 | |
fkellermavnet | 0:affdbb35faa4 | 81 | *ptr-- = '\0'; |
fkellermavnet | 0:affdbb35faa4 | 82 | |
fkellermavnet | 0:affdbb35faa4 | 83 | while ( ptr1 < ptr ) { |
fkellermavnet | 0:affdbb35faa4 | 84 | tmp_char = *ptr; |
fkellermavnet | 0:affdbb35faa4 | 85 | *ptr-- = *ptr1; |
fkellermavnet | 0:affdbb35faa4 | 86 | *ptr1++ = tmp_char; |
fkellermavnet | 0:affdbb35faa4 | 87 | } |
fkellermavnet | 0:affdbb35faa4 | 88 | |
fkellermavnet | 0:affdbb35faa4 | 89 | return result; |
fkellermavnet | 0:affdbb35faa4 | 90 | } |
fkellermavnet | 0:affdbb35faa4 | 91 | |
fkellermavnet | 0:affdbb35faa4 | 92 | const char * WncController::_to_string(int64_t value) |
fkellermavnet | 0:affdbb35faa4 | 93 | { |
fkellermavnet | 0:affdbb35faa4 | 94 | static char str[21]; // room for signed 64-bit + null |
fkellermavnet | 0:affdbb35faa4 | 95 | itoa(value, str, 10); |
fkellermavnet | 0:affdbb35faa4 | 96 | return (str); |
fkellermavnet | 0:affdbb35faa4 | 97 | } |
fkellermavnet | 0:affdbb35faa4 | 98 | |
fkellermavnet | 1:ac2de545b981 | 99 | const char * WncController::_to_hex_string(uint8_t value) |
fkellermavnet | 1:ac2de545b981 | 100 | { |
fkellermavnet | 1:ac2de545b981 | 101 | static char str[3]; // room for 8-bit + null |
fkellermavnet | 1:ac2de545b981 | 102 | itoa(value, str, 16); |
fkellermavnet | 1:ac2de545b981 | 103 | return (str); |
fkellermavnet | 1:ac2de545b981 | 104 | } |
fkellermavnet | 0:affdbb35faa4 | 105 | |
fkellermavnet | 0:affdbb35faa4 | 106 | /** |
fkellermavnet | 0:affdbb35faa4 | 107 | * \brief Constructor for UART controlled WNC |
fkellermavnet | 0:affdbb35faa4 | 108 | * |
fkellermavnet | 0:affdbb35faa4 | 109 | * \param [in] wnc_uart - Reference to a SerialBuffered object which will |
fkellermavnet | 0:affdbb35faa4 | 110 | * be used as the bus to control the WNC. |
fkellermavnet | 0:affdbb35faa4 | 111 | * |
fkellermavnet | 0:affdbb35faa4 | 112 | * \return None. |
fkellermavnet | 0:affdbb35faa4 | 113 | * |
fkellermavnet | 0:affdbb35faa4 | 114 | * \details Adding another way to talk to the WNC, like I2C or USB, |
fkellermavnet | 0:affdbb35faa4 | 115 | * a constructor should be added for each type just like the SerialBuffered |
fkellermavnet | 0:affdbb35faa4 | 116 | * constructor below. |
fkellermavnet | 0:affdbb35faa4 | 117 | */ |
fkellermavnet | 1:ac2de545b981 | 118 | WncController::WncController(void) |
fkellermavnet | 0:affdbb35faa4 | 119 | { |
fkellermavnet | 10:2ec59906a24e | 120 | for(unsigned i; i<MAX_NUM_WNC_SOCKETS; i++) |
fkellermavnet | 10:2ec59906a24e | 121 | m_sSock[i] = defaultSockStruct; |
fkellermavnet | 0:affdbb35faa4 | 122 | } |
fkellermavnet | 0:affdbb35faa4 | 123 | |
fkellermavnet | 0:affdbb35faa4 | 124 | void WncController::enableDebug(bool on, bool moreDebugOn) |
fkellermavnet | 0:affdbb35faa4 | 125 | { |
fkellermavnet | 0:affdbb35faa4 | 126 | m_sDebugEnabled = on; |
fkellermavnet | 0:affdbb35faa4 | 127 | m_sMoreDebugEnabled = moreDebugOn; |
fkellermavnet | 0:affdbb35faa4 | 128 | } |
fkellermavnet | 0:affdbb35faa4 | 129 | |
fkellermavnet | 0:affdbb35faa4 | 130 | /** |
fkellermavnet | 0:affdbb35faa4 | 131 | * \brief Used internally but also make public for a user of the Class to interrogate state as well. |
fkellermavnet | 0:affdbb35faa4 | 132 | * |
fkellermavnet | 0:affdbb35faa4 | 133 | * \param [in] None. |
fkellermavnet | 0:affdbb35faa4 | 134 | * |
fkellermavnet | 0:affdbb35faa4 | 135 | * \return The state of the WNC Modem. |
fkellermavnet | 0:affdbb35faa4 | 136 | * |
fkellermavnet | 0:affdbb35faa4 | 137 | * \details None. |
fkellermavnet | 0:affdbb35faa4 | 138 | */ |
fkellermavnet | 0:affdbb35faa4 | 139 | WncController::WncState_e WncController::getWncStatus(void) |
fkellermavnet | 0:affdbb35faa4 | 140 | { |
fkellermavnet | 0:affdbb35faa4 | 141 | return (m_sState); |
fkellermavnet | 0:affdbb35faa4 | 142 | } |
fkellermavnet | 0:affdbb35faa4 | 143 | |
fkellermavnet | 0:affdbb35faa4 | 144 | /** |
fkellermavnet | 0:affdbb35faa4 | 145 | * \brief Return signal quality dBm level |
fkellermavnet | 0:affdbb35faa4 | 146 | * |
fkellermavnet | 0:affdbb35faa4 | 147 | * \param [in] None. |
fkellermavnet | 0:affdbb35faa4 | 148 | * |
fkellermavnet | 0:affdbb35faa4 | 149 | * \return The dBm signal level at the time of the request. |
fkellermavnet | 0:affdbb35faa4 | 150 | * |
fkellermavnet | 0:affdbb35faa4 | 151 | * \details This polls (at the time of the call) the cell signal. |
fkellermavnet | 0:affdbb35faa4 | 152 | */ |
fkellermavnet | 0:affdbb35faa4 | 153 | int16_t WncController::getDbmRssi(void) |
fkellermavnet | 0:affdbb35faa4 | 154 | { |
fkellermavnet | 0:affdbb35faa4 | 155 | int16_t rssi, ber; |
fkellermavnet | 0:affdbb35faa4 | 156 | if (at_getrssiber_wnc(&rssi, &ber) == true) |
fkellermavnet | 0:affdbb35faa4 | 157 | return (rssi); |
fkellermavnet | 0:affdbb35faa4 | 158 | else |
fkellermavnet | 0:affdbb35faa4 | 159 | return (99); |
fkellermavnet | 0:affdbb35faa4 | 160 | } |
fkellermavnet | 0:affdbb35faa4 | 161 | |
fkellermavnet | 0:affdbb35faa4 | 162 | int16_t WncController::get3gBer(void) |
fkellermavnet | 0:affdbb35faa4 | 163 | { |
fkellermavnet | 0:affdbb35faa4 | 164 | int16_t rssi, ber; |
fkellermavnet | 0:affdbb35faa4 | 165 | if (at_getrssiber_wnc(&rssi, &ber) == true) |
fkellermavnet | 0:affdbb35faa4 | 166 | return (ber); |
fkellermavnet | 0:affdbb35faa4 | 167 | else |
fkellermavnet | 0:affdbb35faa4 | 168 | return (99); |
fkellermavnet | 0:affdbb35faa4 | 169 | } |
fkellermavnet | 0:affdbb35faa4 | 170 | |
fkellermavnet | 0:affdbb35faa4 | 171 | |
fkellermavnet | 0:affdbb35faa4 | 172 | /** |
fkellermavnet | 0:affdbb35faa4 | 173 | * \brief Power up and down (down not implemented yet) |
fkellermavnet | 0:affdbb35faa4 | 174 | * |
fkellermavnet | 0:affdbb35faa4 | 175 | * \param [in] on - set true to power on, otherwise false |
fkellermavnet | 0:affdbb35faa4 | 176 | * |
fkellermavnet | 0:affdbb35faa4 | 177 | * \return None. |
fkellermavnet | 0:affdbb35faa4 | 178 | * |
fkellermavnet | 0:affdbb35faa4 | 179 | * \details Power-on works but not power-down. This will manipulate WNC Shield hardware |
fkellermavnet | 0:affdbb35faa4 | 180 | * and bring it to life. It will also initialize the WNC enough to get it to be able to open sockets |
fkellermavnet | 0:affdbb35faa4 | 181 | * (with AT commands) |
fkellermavnet | 0:affdbb35faa4 | 182 | */ |
fkellermavnet | 1:ac2de545b981 | 183 | bool WncController::powerWncOn(const char * const apn, uint8_t powerUpTimeoutSecs) |
fkellermavnet | 0:affdbb35faa4 | 184 | { |
fkellermavnet | 0:affdbb35faa4 | 185 | dbgPuts("Waiting for WNC to Initialize..."); |
fkellermavnet | 0:affdbb35faa4 | 186 | m_sPowerUpTimeoutSecs = powerUpTimeoutSecs; |
fkellermavnet | 0:affdbb35faa4 | 187 | m_sState = WNC_ON_NO_CELL_LINK; // Turn soft on to allow "AT" for init to be sent! |
fkellermavnet | 0:affdbb35faa4 | 188 | if (initWncModem(powerUpTimeoutSecs) == true) { |
fkellermavnet | 0:affdbb35faa4 | 189 | // Set the Apn |
fkellermavnet | 1:ac2de545b981 | 190 | setApnName(apn); |
fkellermavnet | 0:affdbb35faa4 | 191 | if (false == softwareInitMdm()) { |
fkellermavnet | 0:affdbb35faa4 | 192 | dbgPuts("Software init failed!"); |
fkellermavnet | 0:affdbb35faa4 | 193 | m_sState = WNC_OFF; |
fkellermavnet | 0:affdbb35faa4 | 194 | } |
fkellermavnet | 0:affdbb35faa4 | 195 | } |
fkellermavnet | 0:affdbb35faa4 | 196 | else { |
fkellermavnet | 0:affdbb35faa4 | 197 | dbgPuts("Power up failed!"); |
fkellermavnet | 0:affdbb35faa4 | 198 | m_sState = WNC_OFF; |
fkellermavnet | 0:affdbb35faa4 | 199 | } |
fkellermavnet | 0:affdbb35faa4 | 200 | |
fkellermavnet | 1:ac2de545b981 | 201 | return (m_sState != WNC_ON_NO_CELL_LINK); |
fkellermavnet | 0:affdbb35faa4 | 202 | } |
fkellermavnet | 0:affdbb35faa4 | 203 | |
fkellermavnet | 0:affdbb35faa4 | 204 | size_t WncController::sendCustomCmd(const char * cmd, char * resp, size_t sizeRespBuf, int ms_timeout) |
fkellermavnet | 0:affdbb35faa4 | 205 | { |
fkellermavnet | 0:affdbb35faa4 | 206 | string * respStr; |
fkellermavnet | 0:affdbb35faa4 | 207 | |
fkellermavnet | 0:affdbb35faa4 | 208 | if (sizeRespBuf > 0) { |
fkellermavnet | 0:affdbb35faa4 | 209 | AtCmdErr_e r = at_send_wnc_cmd(cmd, &respStr, ms_timeout); |
fkellermavnet | 18:ca2899c353c2 | 210 | strncpy(resp, respStr->c_str(), sizeRespBuf); |
fkellermavnet | 18:ca2899c353c2 | 211 | if (respStr->size() > sizeRespBuf) |
fkellermavnet | 18:ca2899c353c2 | 212 | dbgPuts("sendCustomCmd truncated!"); |
fkellermavnet | 18:ca2899c353c2 | 213 | |
fkellermavnet | 18:ca2899c353c2 | 214 | return (respStr->size()); |
fkellermavnet | 0:affdbb35faa4 | 215 | } |
fkellermavnet | 0:affdbb35faa4 | 216 | |
fkellermavnet | 0:affdbb35faa4 | 217 | dbgPuts("sendCustomCmd: would have overrun!"); |
fkellermavnet | 0:affdbb35faa4 | 218 | |
fkellermavnet | 0:affdbb35faa4 | 219 | return (0); |
fkellermavnet | 0:affdbb35faa4 | 220 | } |
fkellermavnet | 0:affdbb35faa4 | 221 | |
fkellermavnet | 0:affdbb35faa4 | 222 | bool WncController::pingUrl(const char * url) |
fkellermavnet | 0:affdbb35faa4 | 223 | { |
fkellermavnet | 0:affdbb35faa4 | 224 | string ipAddr; |
fkellermavnet | 0:affdbb35faa4 | 225 | |
fkellermavnet | 0:affdbb35faa4 | 226 | if (true == at_dnsresolve_wnc(url, &ipAddr)) |
fkellermavnet | 0:affdbb35faa4 | 227 | return (pingIp(ipAddr.c_str())); |
fkellermavnet | 0:affdbb35faa4 | 228 | else |
fkellermavnet | 0:affdbb35faa4 | 229 | dbgPuts("pingUrl DNS resolve: failed!"); |
fkellermavnet | 0:affdbb35faa4 | 230 | |
fkellermavnet | 0:affdbb35faa4 | 231 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 232 | } |
fkellermavnet | 0:affdbb35faa4 | 233 | |
fkellermavnet | 0:affdbb35faa4 | 234 | bool WncController::pingIp(const char * ip) |
fkellermavnet | 0:affdbb35faa4 | 235 | { |
fkellermavnet | 0:affdbb35faa4 | 236 | if (true == at_ping_wnc(ip)) |
fkellermavnet | 0:affdbb35faa4 | 237 | return (true); |
fkellermavnet | 0:affdbb35faa4 | 238 | else |
fkellermavnet | 0:affdbb35faa4 | 239 | dbgPuts("pingIp: failed!"); |
fkellermavnet | 0:affdbb35faa4 | 240 | |
fkellermavnet | 0:affdbb35faa4 | 241 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 242 | } |
fkellermavnet | 0:affdbb35faa4 | 243 | |
fkellermavnet | 0:affdbb35faa4 | 244 | bool WncController::getWncNetworkingStats(WncIpStats * s) |
fkellermavnet | 0:affdbb35faa4 | 245 | { |
fkellermavnet | 0:affdbb35faa4 | 246 | return (at_get_wnc_net_stats(s)); |
fkellermavnet | 0:affdbb35faa4 | 247 | } |
fkellermavnet | 0:affdbb35faa4 | 248 | |
fkellermavnet | 0:affdbb35faa4 | 249 | bool WncController::getIpAddr(uint16_t numSock, char myIpAddr[MAX_LEN_IP_STR]) |
fkellermavnet | 0:affdbb35faa4 | 250 | { |
fkellermavnet | 0:affdbb35faa4 | 251 | if (numSock < MAX_NUM_WNC_SOCKETS) { |
fkellermavnet | 0:affdbb35faa4 | 252 | strncpy(myIpAddr, m_sSock[numSock].myIpAddressStr.c_str(), MAX_LEN_IP_STR); |
fkellermavnet | 0:affdbb35faa4 | 253 | myIpAddr[MAX_LEN_IP_STR - 1] = '\0'; |
fkellermavnet | 0:affdbb35faa4 | 254 | return (true); |
fkellermavnet | 0:affdbb35faa4 | 255 | } |
fkellermavnet | 0:affdbb35faa4 | 256 | else { |
fkellermavnet | 0:affdbb35faa4 | 257 | myIpAddr[0] = '\0'; |
fkellermavnet | 0:affdbb35faa4 | 258 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 259 | } |
fkellermavnet | 0:affdbb35faa4 | 260 | } |
fkellermavnet | 0:affdbb35faa4 | 261 | |
fkellermavnet | 0:affdbb35faa4 | 262 | bool WncController::setApnName(const char * const apnStr) |
fkellermavnet | 0:affdbb35faa4 | 263 | { |
fkellermavnet | 0:affdbb35faa4 | 264 | if (at_setapn_wnc(apnStr) == true) |
fkellermavnet | 0:affdbb35faa4 | 265 | { |
fkellermavnet | 0:affdbb35faa4 | 266 | m_sApnStr = apnStr; |
fkellermavnet | 0:affdbb35faa4 | 267 | return (true); |
fkellermavnet | 0:affdbb35faa4 | 268 | } |
fkellermavnet | 0:affdbb35faa4 | 269 | else |
fkellermavnet | 0:affdbb35faa4 | 270 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 271 | } |
fkellermavnet | 0:affdbb35faa4 | 272 | |
fkellermavnet | 0:affdbb35faa4 | 273 | |
fkellermavnet | 0:affdbb35faa4 | 274 | /** |
fkellermavnet | 0:affdbb35faa4 | 275 | * \brief Look-up a URL text string and convert into an IP Address string. |
fkellermavnet | 0:affdbb35faa4 | 276 | * |
fkellermavnet | 0:affdbb35faa4 | 277 | * \param [in] url - the URL to lookup. numSock - the socket number to resolve. |
fkellermavnet | 0:affdbb35faa4 | 278 | * |
fkellermavnet | 0:affdbb35faa4 | 279 | * \return true - if the IP address has been resolved. false - if the URL could not be resolved. |
fkellermavnet | 0:affdbb35faa4 | 280 | * |
fkellermavnet | 0:affdbb35faa4 | 281 | * \details None. |
fkellermavnet | 0:affdbb35faa4 | 282 | */ |
fkellermavnet | 0:affdbb35faa4 | 283 | bool WncController::resolveUrl(uint16_t numSock, const char * url) |
fkellermavnet | 0:affdbb35faa4 | 284 | { |
fkellermavnet | 0:affdbb35faa4 | 285 | bool cmdRes; |
fkellermavnet | 0:affdbb35faa4 | 286 | |
fkellermavnet | 0:affdbb35faa4 | 287 | if (numSock < MAX_NUM_WNC_SOCKETS) { |
fkellermavnet | 0:affdbb35faa4 | 288 | if (strlen(url) > 0) { |
fkellermavnet | 0:affdbb35faa4 | 289 | cmdRes = at_dnsresolve_wnc(url, &m_sSock[numSock].myIpAddressStr); |
fkellermavnet | 0:affdbb35faa4 | 290 | if (cmdRes == false) |
fkellermavnet | 0:affdbb35faa4 | 291 | dbgPuts("Cannot resolve URL!"); |
fkellermavnet | 0:affdbb35faa4 | 292 | return (cmdRes); |
fkellermavnet | 0:affdbb35faa4 | 293 | } |
fkellermavnet | 0:affdbb35faa4 | 294 | else |
fkellermavnet | 0:affdbb35faa4 | 295 | dbgPuts("Invalid URL"); |
fkellermavnet | 0:affdbb35faa4 | 296 | } |
fkellermavnet | 0:affdbb35faa4 | 297 | else |
fkellermavnet | 0:affdbb35faa4 | 298 | dbgPuts("Invalid Sock num!"); |
fkellermavnet | 0:affdbb35faa4 | 299 | |
fkellermavnet | 0:affdbb35faa4 | 300 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 301 | } |
fkellermavnet | 0:affdbb35faa4 | 302 | |
fkellermavnet | 0:affdbb35faa4 | 303 | /** |
fkellermavnet | 0:affdbb35faa4 | 304 | * \brief Set IP Address string |
fkellermavnet | 0:affdbb35faa4 | 305 | * |
fkellermavnet | 0:affdbb35faa4 | 306 | * \param [in] numSock - socket reference to set the string for. ipStr - text string of the IP |
fkellermavnet | 0:affdbb35faa4 | 307 | * address you want to talk to. There is no sanity check - beware!!! |
fkellermavnet | 0:affdbb35faa4 | 308 | * |
fkellermavnet | 0:affdbb35faa4 | 309 | * \return true - if the IP address has been set. false - if the IP could not be set. |
fkellermavnet | 0:affdbb35faa4 | 310 | * |
fkellermavnet | 0:affdbb35faa4 | 311 | * \details None. |
fkellermavnet | 0:affdbb35faa4 | 312 | */ |
fkellermavnet | 0:affdbb35faa4 | 313 | bool WncController::setIpAddr(uint16_t numSock, const char * ipStr) |
fkellermavnet | 0:affdbb35faa4 | 314 | { |
fkellermavnet | 0:affdbb35faa4 | 315 | if (numSock < MAX_NUM_WNC_SOCKETS) { |
fkellermavnet | 0:affdbb35faa4 | 316 | m_sSock[numSock].myIpAddressStr = ipStr; |
fkellermavnet | 0:affdbb35faa4 | 317 | return (true); |
fkellermavnet | 0:affdbb35faa4 | 318 | } |
fkellermavnet | 0:affdbb35faa4 | 319 | else { |
fkellermavnet | 0:affdbb35faa4 | 320 | dbgPuts("Bad socket num!"); |
fkellermavnet | 0:affdbb35faa4 | 321 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 322 | } |
fkellermavnet | 0:affdbb35faa4 | 323 | } |
fkellermavnet | 0:affdbb35faa4 | 324 | |
fkellermavnet | 6:a656e820d7ff | 325 | void WncController::setWncCmdTimeout(uint16_t toMs) |
fkellermavnet | 6:a656e820d7ff | 326 | { |
fkellermavnet | 6:a656e820d7ff | 327 | m_sCmdTimeoutMs = toMs; |
fkellermavnet | 6:a656e820d7ff | 328 | } |
fkellermavnet | 6:a656e820d7ff | 329 | |
fkellermavnet | 0:affdbb35faa4 | 330 | /** |
fkellermavnet | 0:affdbb35faa4 | 331 | * \brief Opens a WNC socket. |
fkellermavnet | 0:affdbb35faa4 | 332 | * |
fkellermavnet | 0:affdbb35faa4 | 333 | * \param [in] sockNum - the number of the socket to open. ipAddr - a string containing |
fkellermavnet | 0:affdbb35faa4 | 334 | * the IP address. port - the IP port number to open the socket connection. |
fkellermavnet | 0:affdbb35faa4 | 335 | * |
fkellermavnet | 0:affdbb35faa4 | 336 | * \return true - if the socket is/was opened. false otherwise. |
fkellermavnet | 0:affdbb35faa4 | 337 | * |
fkellermavnet | 0:affdbb35faa4 | 338 | * \details None. |
fkellermavnet | 0:affdbb35faa4 | 339 | */ |
fkellermavnet | 15:2c8211ef69e1 | 340 | |
fkellermavnet | 15:2c8211ef69e1 | 341 | bool WncController::openSocketUrl(uint16_t numSock, const char * url, uint16_t port, bool tcp, uint16_t timeOutSec) |
fkellermavnet | 15:2c8211ef69e1 | 342 | { |
fkellermavnet | 15:2c8211ef69e1 | 343 | if (resolveUrl(numSock, url) == true) |
fkellermavnet | 15:2c8211ef69e1 | 344 | return (openSocket(numSock, port, tcp, timeOutSec)); |
fkellermavnet | 15:2c8211ef69e1 | 345 | |
fkellermavnet | 15:2c8211ef69e1 | 346 | return (false); |
fkellermavnet | 15:2c8211ef69e1 | 347 | } |
fkellermavnet | 15:2c8211ef69e1 | 348 | |
fkellermavnet | 15:2c8211ef69e1 | 349 | bool WncController::openSocketIpAddr(uint16_t numSock, const char * ipAddr, uint16_t port, bool tcp, uint16_t timeOutSec) |
fkellermavnet | 15:2c8211ef69e1 | 350 | { |
fkellermavnet | 15:2c8211ef69e1 | 351 | if (setIpAddr(numSock, ipAddr) == true) |
fkellermavnet | 15:2c8211ef69e1 | 352 | return (openSocket(numSock, port, tcp, timeOutSec)); |
fkellermavnet | 15:2c8211ef69e1 | 353 | |
fkellermavnet | 15:2c8211ef69e1 | 354 | return (false); |
fkellermavnet | 15:2c8211ef69e1 | 355 | } |
fkellermavnet | 15:2c8211ef69e1 | 356 | |
fkellermavnet | 0:affdbb35faa4 | 357 | bool WncController::openSocket(uint16_t numSock, uint16_t port, bool tcp, uint16_t timeOutSec) |
fkellermavnet | 0:affdbb35faa4 | 358 | { |
fkellermavnet | 0:affdbb35faa4 | 359 | if (numSock < MAX_NUM_WNC_SOCKETS) { |
fkellermavnet | 0:affdbb35faa4 | 360 | // IPV4 ip addr sanity check! |
fkellermavnet | 0:affdbb35faa4 | 361 | size_t lenIpStr = m_sSock[numSock].myIpAddressStr.size(); |
fkellermavnet | 0:affdbb35faa4 | 362 | if (lenIpStr < 7 || lenIpStr > 15) { |
fkellermavnet | 0:affdbb35faa4 | 363 | dbgPuts("Invalid IP Address!"); |
fkellermavnet | 0:affdbb35faa4 | 364 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 365 | } |
fkellermavnet | 0:affdbb35faa4 | 366 | |
fkellermavnet | 0:affdbb35faa4 | 367 | // Already open ? Must close if want to re-open with new settings. |
fkellermavnet | 0:affdbb35faa4 | 368 | if (m_sSock[numSock].open == true) { |
fkellermavnet | 0:affdbb35faa4 | 369 | dbgPuts("Socket already open, close then re-open!"); |
fkellermavnet | 10:2ec59906a24e | 370 | at_sockclose_wnc(m_sSock[numSock].numWncSock); |
fkellermavnet | 0:affdbb35faa4 | 371 | m_sSock[numSock].open = false; |
fkellermavnet | 0:affdbb35faa4 | 372 | } |
fkellermavnet | 0:affdbb35faa4 | 373 | |
fkellermavnet | 0:affdbb35faa4 | 374 | m_sSock[numSock].myPort = port; |
fkellermavnet | 0:affdbb35faa4 | 375 | m_sSock[numSock].isTcp = tcp; |
fkellermavnet | 0:affdbb35faa4 | 376 | m_sSock[numSock].timeOutSec = timeOutSec; |
fkellermavnet | 10:2ec59906a24e | 377 | |
fkellermavnet | 10:2ec59906a24e | 378 | int numWncSock = at_sockopen_wnc(m_sSock[numSock].myIpAddressStr.c_str(), port, numSock, tcp, timeOutSec); |
fkellermavnet | 10:2ec59906a24e | 379 | m_sSock[numSock].numWncSock = numWncSock; |
fkellermavnet | 10:2ec59906a24e | 380 | if (numWncSock > 0 && numWncSock <= MAX_NUM_WNC_SOCKETS) |
fkellermavnet | 10:2ec59906a24e | 381 | m_sSock[numSock].open = true; |
fkellermavnet | 10:2ec59906a24e | 382 | else |
fkellermavnet | 10:2ec59906a24e | 383 | m_sSock[numSock].open = false; |
fkellermavnet | 10:2ec59906a24e | 384 | |
fkellermavnet | 0:affdbb35faa4 | 385 | if (m_sSock[numSock].open == false) { |
fkellermavnet | 0:affdbb35faa4 | 386 | dbgPuts("Socket open fail!!!!"); |
fkellermavnet | 0:affdbb35faa4 | 387 | // Work-around. If the sock open fails it needs to be told |
fkellermavnet | 0:affdbb35faa4 | 388 | // to close. If 6 sock opens happen with a fail, it further |
fkellermavnet | 0:affdbb35faa4 | 389 | // crashes the WNC. Not sure why the sock won't open. |
fkellermavnet | 10:2ec59906a24e | 390 | at_sockclose_wnc(m_sSock[numSock].numWncSock); |
fkellermavnet | 0:affdbb35faa4 | 391 | } |
fkellermavnet | 0:affdbb35faa4 | 392 | } |
fkellermavnet | 0:affdbb35faa4 | 393 | else { |
fkellermavnet | 0:affdbb35faa4 | 394 | dbgPuts("Bad socket num or IP!"); |
fkellermavnet | 0:affdbb35faa4 | 395 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 396 | } |
fkellermavnet | 0:affdbb35faa4 | 397 | |
fkellermavnet | 0:affdbb35faa4 | 398 | return (m_sSock[numSock].open); |
fkellermavnet | 0:affdbb35faa4 | 399 | } |
fkellermavnet | 0:affdbb35faa4 | 400 | |
fkellermavnet | 0:affdbb35faa4 | 401 | /** |
fkellermavnet | 0:affdbb35faa4 | 402 | * \brief Write bytes of data to an open socket |
fkellermavnet | 0:affdbb35faa4 | 403 | * |
fkellermavnet | 0:affdbb35faa4 | 404 | * \param [in] sockNum - the number of the socket to write. s - a string containing |
fkellermavnet | 0:affdbb35faa4 | 405 | * the byte data to send must be less than = 1500. |
fkellermavnet | 0:affdbb35faa4 | 406 | * |
fkellermavnet | 0:affdbb35faa4 | 407 | * \return true - if the write was successful. false otherwise. |
fkellermavnet | 0:affdbb35faa4 | 408 | * |
fkellermavnet | 0:affdbb35faa4 | 409 | * \details The results of the write do not have anything to do with the data |
fkellermavnet | 0:affdbb35faa4 | 410 | * arriving at the endpoint. |
fkellermavnet | 0:affdbb35faa4 | 411 | */ |
fkellermavnet | 0:affdbb35faa4 | 412 | |
fkellermavnet | 13:73629a6e9122 | 413 | bool WncController::sockWrite(const char * const s, uint16_t n, uint16_t numSock, bool isTcp) |
fkellermavnet | 0:affdbb35faa4 | 414 | { |
fkellermavnet | 10:2ec59906a24e | 415 | bool result = true; |
fkellermavnet | 0:affdbb35faa4 | 416 | |
fkellermavnet | 10:2ec59906a24e | 417 | AtCmdErr_e cmdRes = at_sockwrite_wnc(s, n, m_sSock[numSock].numWncSock, isTcp); |
fkellermavnet | 0:affdbb35faa4 | 418 | if (cmdRes != WNC_AT_CMD_OK) { |
fkellermavnet | 0:affdbb35faa4 | 419 | if ((cmdRes == WNC_AT_CMD_ERREXT) || (cmdRes == WNC_AT_CMD_TIMEOUT) || (cmdRes == WNC_AT_CMD_ERRCME)) |
fkellermavnet | 0:affdbb35faa4 | 420 | { |
fkellermavnet | 1:ac2de545b981 | 421 | // This may throw away any data that hasn't been written out of the WNC |
fkellermavnet | 0:affdbb35faa4 | 422 | // but at this point with the way the WNC currently works we have |
fkellermavnet | 0:affdbb35faa4 | 423 | // no choice. |
fkellermavnet | 0:affdbb35faa4 | 424 | closeOpenSocket(numSock); |
fkellermavnet | 0:affdbb35faa4 | 425 | } |
fkellermavnet | 0:affdbb35faa4 | 426 | result = false; |
fkellermavnet | 0:affdbb35faa4 | 427 | } |
fkellermavnet | 0:affdbb35faa4 | 428 | |
fkellermavnet | 0:affdbb35faa4 | 429 | return (result); |
fkellermavnet | 0:affdbb35faa4 | 430 | } |
fkellermavnet | 0:affdbb35faa4 | 431 | |
fkellermavnet | 0:affdbb35faa4 | 432 | bool WncController::write(uint16_t numSock, const char * s, uint32_t n) |
fkellermavnet | 0:affdbb35faa4 | 433 | { |
fkellermavnet | 0:affdbb35faa4 | 434 | bool result; |
fkellermavnet | 0:affdbb35faa4 | 435 | |
fkellermavnet | 0:affdbb35faa4 | 436 | if (numSock < MAX_NUM_WNC_SOCKETS) { |
fkellermavnet | 0:affdbb35faa4 | 437 | if (m_sSock[numSock].open == true) { |
fkellermavnet | 0:affdbb35faa4 | 438 | if (n <= MAX_WNC_WRITE_BYTES) { |
fkellermavnet | 0:affdbb35faa4 | 439 | result = sockWrite(s, n, numSock, m_sSock[numSock].isTcp); |
fkellermavnet | 0:affdbb35faa4 | 440 | } |
fkellermavnet | 0:affdbb35faa4 | 441 | else { |
fkellermavnet | 0:affdbb35faa4 | 442 | uint16_t rem = n % MAX_WNC_WRITE_BYTES; |
fkellermavnet | 13:73629a6e9122 | 443 | while (n >= MAX_WNC_WRITE_BYTES) { |
fkellermavnet | 0:affdbb35faa4 | 444 | n -= MAX_WNC_WRITE_BYTES; |
fkellermavnet | 0:affdbb35faa4 | 445 | result = sockWrite(s, MAX_WNC_WRITE_BYTES, numSock, m_sSock[numSock].isTcp); |
fkellermavnet | 0:affdbb35faa4 | 446 | if (result == false) { |
fkellermavnet | 0:affdbb35faa4 | 447 | n = 0; |
fkellermavnet | 0:affdbb35faa4 | 448 | rem = 0; |
fkellermavnet | 0:affdbb35faa4 | 449 | dbgPuts("Sock write fail!"); |
fkellermavnet | 0:affdbb35faa4 | 450 | } |
fkellermavnet | 0:affdbb35faa4 | 451 | else |
fkellermavnet | 0:affdbb35faa4 | 452 | s += MAX_WNC_WRITE_BYTES; |
fkellermavnet | 0:affdbb35faa4 | 453 | } |
fkellermavnet | 0:affdbb35faa4 | 454 | if (rem > 0) |
fkellermavnet | 0:affdbb35faa4 | 455 | result = sockWrite(s, rem, numSock, m_sSock[numSock].isTcp); |
fkellermavnet | 0:affdbb35faa4 | 456 | } |
fkellermavnet | 0:affdbb35faa4 | 457 | } |
fkellermavnet | 0:affdbb35faa4 | 458 | else { |
fkellermavnet | 0:affdbb35faa4 | 459 | dbgPuts("Socket is closed for write!"); |
fkellermavnet | 0:affdbb35faa4 | 460 | result = false; |
fkellermavnet | 0:affdbb35faa4 | 461 | } |
fkellermavnet | 0:affdbb35faa4 | 462 | } |
fkellermavnet | 0:affdbb35faa4 | 463 | else { |
fkellermavnet | 0:affdbb35faa4 | 464 | dbgPuts("Bad socket num!"); |
fkellermavnet | 0:affdbb35faa4 | 465 | result = false; |
fkellermavnet | 0:affdbb35faa4 | 466 | } |
fkellermavnet | 0:affdbb35faa4 | 467 | |
fkellermavnet | 0:affdbb35faa4 | 468 | return (result); |
fkellermavnet | 0:affdbb35faa4 | 469 | } |
fkellermavnet | 0:affdbb35faa4 | 470 | |
fkellermavnet | 0:affdbb35faa4 | 471 | /** |
fkellermavnet | 0:affdbb35faa4 | 472 | * \brief Poll and read back data from the WNC (if it has any) |
fkellermavnet | 0:affdbb35faa4 | 473 | * If auto poll is enabled this read might fail (return with no data). |
fkellermavnet | 0:affdbb35faa4 | 474 | * |
fkellermavnet | 0:affdbb35faa4 | 475 | * \param [in] sockNum - the number of the socket to read. result - a string pointer containing |
fkellermavnet | 0:affdbb35faa4 | 476 | * the byte data readback from the WNC. |
fkellermavnet | 0:affdbb35faa4 | 477 | * |
fkellermavnet | 0:affdbb35faa4 | 478 | * \return The number of bytes/chars that are read from the socket. |
fkellermavnet | 0:affdbb35faa4 | 479 | * |
fkellermavnet | 0:affdbb35faa4 | 480 | * \details DO NOT use the same string as is passed to the auto poll setup method! |
fkellermavnet | 0:affdbb35faa4 | 481 | */ |
fkellermavnet | 4:c5720f4d13ff | 482 | |
fkellermavnet | 4:c5720f4d13ff | 483 | size_t WncController::read(uint16_t numSock, const uint8_t ** readBuf) |
fkellermavnet | 4:c5720f4d13ff | 484 | { |
fkellermavnet | 4:c5720f4d13ff | 485 | static string theBuf; |
fkellermavnet | 4:c5720f4d13ff | 486 | string readStr; |
fkellermavnet | 4:c5720f4d13ff | 487 | |
fkellermavnet | 4:c5720f4d13ff | 488 | theBuf.erase(); // Clean-up from last time |
fkellermavnet | 4:c5720f4d13ff | 489 | |
fkellermavnet | 4:c5720f4d13ff | 490 | if (numSock < MAX_NUM_WNC_SOCKETS) { |
fkellermavnet | 4:c5720f4d13ff | 491 | if (m_sSock[numSock].open == true) { |
fkellermavnet | 4:c5720f4d13ff | 492 | uint8_t i = m_sSock[numSock].readRetries; |
fkellermavnet | 4:c5720f4d13ff | 493 | uint16_t to = m_sSock[numSock].readRetryWaitMs; |
fkellermavnet | 4:c5720f4d13ff | 494 | bool foundData = false; |
fkellermavnet | 4:c5720f4d13ff | 495 | do { |
fkellermavnet | 4:c5720f4d13ff | 496 | AtCmdErr_e cmdRes; |
fkellermavnet | 10:2ec59906a24e | 497 | cmdRes = at_sockread_wnc(&readStr, m_sSock[numSock].numWncSock, m_sSock[numSock].isTcp); |
fkellermavnet | 4:c5720f4d13ff | 498 | if (WNC_AT_CMD_OK == cmdRes) { |
fkellermavnet | 4:c5720f4d13ff | 499 | // This will let this loop read until the socket data is |
fkellermavnet | 4:c5720f4d13ff | 500 | // empty. If no data, then wait the retry amount of time. |
fkellermavnet | 4:c5720f4d13ff | 501 | if (readStr.size() > 0) { |
fkellermavnet | 4:c5720f4d13ff | 502 | theBuf += readStr; |
fkellermavnet | 4:c5720f4d13ff | 503 | foundData = true; |
fkellermavnet | 4:c5720f4d13ff | 504 | i = 1; |
fkellermavnet | 4:c5720f4d13ff | 505 | } |
fkellermavnet | 4:c5720f4d13ff | 506 | else { |
fkellermavnet | 4:c5720f4d13ff | 507 | // Once data is found start returning it asap |
fkellermavnet | 4:c5720f4d13ff | 508 | if (foundData == false) |
fkellermavnet | 4:c5720f4d13ff | 509 | waitMs(to); |
fkellermavnet | 4:c5720f4d13ff | 510 | } |
fkellermavnet | 4:c5720f4d13ff | 511 | } |
fkellermavnet | 4:c5720f4d13ff | 512 | else { |
fkellermavnet | 4:c5720f4d13ff | 513 | theBuf += readStr; // Append what if any we got before it errored. |
fkellermavnet | 4:c5720f4d13ff | 514 | dbgPuts("Sockread failed!"); |
fkellermavnet | 4:c5720f4d13ff | 515 | if (cmdRes == WNC_AT_CMD_ERREXT || cmdRes == WNC_AT_CMD_TIMEOUT) |
fkellermavnet | 4:c5720f4d13ff | 516 | { |
fkellermavnet | 4:c5720f4d13ff | 517 | // This may throw away any data that hasn't been read out of the WNC |
fkellermavnet | 4:c5720f4d13ff | 518 | // but at this point with the way the WNC currently works we have |
fkellermavnet | 4:c5720f4d13ff | 519 | // no choice. |
fkellermavnet | 4:c5720f4d13ff | 520 | closeOpenSocket(numSock); |
fkellermavnet | 4:c5720f4d13ff | 521 | i = 0; |
fkellermavnet | 4:c5720f4d13ff | 522 | } |
fkellermavnet | 4:c5720f4d13ff | 523 | else |
fkellermavnet | 4:c5720f4d13ff | 524 | waitMs(to); |
fkellermavnet | 4:c5720f4d13ff | 525 | } |
fkellermavnet | 4:c5720f4d13ff | 526 | } while (i-- > 0); |
fkellermavnet | 4:c5720f4d13ff | 527 | } |
fkellermavnet | 4:c5720f4d13ff | 528 | else { |
fkellermavnet | 4:c5720f4d13ff | 529 | dbgPuts("Socket is closed for read"); |
fkellermavnet | 4:c5720f4d13ff | 530 | } |
fkellermavnet | 4:c5720f4d13ff | 531 | } |
fkellermavnet | 4:c5720f4d13ff | 532 | else { |
fkellermavnet | 4:c5720f4d13ff | 533 | dbgPuts("Bad socket num!"); |
fkellermavnet | 4:c5720f4d13ff | 534 | } |
fkellermavnet | 4:c5720f4d13ff | 535 | |
fkellermavnet | 4:c5720f4d13ff | 536 | *readBuf = (const uint8_t *)theBuf.c_str(); |
fkellermavnet | 4:c5720f4d13ff | 537 | |
fkellermavnet | 4:c5720f4d13ff | 538 | return (theBuf.size()); |
fkellermavnet | 4:c5720f4d13ff | 539 | } |
fkellermavnet | 4:c5720f4d13ff | 540 | |
fkellermavnet | 0:affdbb35faa4 | 541 | size_t WncController::read(uint16_t numSock, uint8_t * readBuf, uint32_t maxReadBufLen) |
fkellermavnet | 0:affdbb35faa4 | 542 | { |
fkellermavnet | 0:affdbb35faa4 | 543 | uint32_t numCopied = 0; |
fkellermavnet | 0:affdbb35faa4 | 544 | |
fkellermavnet | 0:affdbb35faa4 | 545 | if (numSock < MAX_NUM_WNC_SOCKETS) { |
fkellermavnet | 0:affdbb35faa4 | 546 | if (m_sSock[numSock].open == true) { |
fkellermavnet | 9:76c6dd1434e1 | 547 | uint8_t i = m_sSock[numSock].readRetries; |
fkellermavnet | 0:affdbb35faa4 | 548 | uint16_t to = m_sSock[numSock].readRetryWaitMs; |
fkellermavnet | 0:affdbb35faa4 | 549 | bool foundData = false; |
fkellermavnet | 12:33290e9e6e5f | 550 | uint16_t numRead; |
fkellermavnet | 0:affdbb35faa4 | 551 | do { |
fkellermavnet | 0:affdbb35faa4 | 552 | AtCmdErr_e cmdRes; |
fkellermavnet | 10:2ec59906a24e | 553 | if (maxReadBufLen < MAX_WNC_READ_BYTES) |
fkellermavnet | 10:2ec59906a24e | 554 | cmdRes = at_sockread_wnc(readBuf, &numRead, maxReadBufLen, m_sSock[numSock].numWncSock, m_sSock[numSock].isTcp); |
fkellermavnet | 0:affdbb35faa4 | 555 | else |
fkellermavnet | 10:2ec59906a24e | 556 | cmdRes = at_sockread_wnc(readBuf, &numRead, MAX_WNC_READ_BYTES, m_sSock[numSock].numWncSock, m_sSock[numSock].isTcp); |
fkellermavnet | 0:affdbb35faa4 | 557 | |
fkellermavnet | 0:affdbb35faa4 | 558 | if (WNC_AT_CMD_OK == cmdRes) { |
fkellermavnet | 0:affdbb35faa4 | 559 | // This will let this loop read until the socket data is |
fkellermavnet | 0:affdbb35faa4 | 560 | // empty. If no data, then wait the retry amount of time. |
fkellermavnet | 0:affdbb35faa4 | 561 | if (numRead > 0) { |
fkellermavnet | 0:affdbb35faa4 | 562 | foundData = true; |
fkellermavnet | 0:affdbb35faa4 | 563 | i = 1; |
fkellermavnet | 10:2ec59906a24e | 564 | if (numRead <= maxReadBufLen) { |
fkellermavnet | 0:affdbb35faa4 | 565 | maxReadBufLen -= numRead; |
fkellermavnet | 0:affdbb35faa4 | 566 | numCopied += numRead; |
fkellermavnet | 0:affdbb35faa4 | 567 | readBuf += numRead; |
fkellermavnet | 0:affdbb35faa4 | 568 | } |
fkellermavnet | 0:affdbb35faa4 | 569 | else { |
fkellermavnet | 0:affdbb35faa4 | 570 | i = 0; // No more room for data! |
fkellermavnet | 0:affdbb35faa4 | 571 | dbgPutsNoTime("No more room for read data!"); |
fkellermavnet | 0:affdbb35faa4 | 572 | } |
fkellermavnet | 0:affdbb35faa4 | 573 | } |
fkellermavnet | 0:affdbb35faa4 | 574 | else { |
fkellermavnet | 0:affdbb35faa4 | 575 | // Once data is found start returning it asap |
fkellermavnet | 0:affdbb35faa4 | 576 | if (foundData == false) |
fkellermavnet | 0:affdbb35faa4 | 577 | waitMs(to); |
fkellermavnet | 0:affdbb35faa4 | 578 | } |
fkellermavnet | 0:affdbb35faa4 | 579 | } |
fkellermavnet | 0:affdbb35faa4 | 580 | else { |
fkellermavnet | 0:affdbb35faa4 | 581 | dbgPuts("Sockread failed!"); |
fkellermavnet | 0:affdbb35faa4 | 582 | if (cmdRes == WNC_AT_CMD_ERREXT || cmdRes == WNC_AT_CMD_TIMEOUT) |
fkellermavnet | 0:affdbb35faa4 | 583 | { |
fkellermavnet | 0:affdbb35faa4 | 584 | // This may throw away any data that hasn't been read out of the WNC |
fkellermavnet | 0:affdbb35faa4 | 585 | // but at this point with the way the WNC currently works we have |
fkellermavnet | 0:affdbb35faa4 | 586 | // no choice. |
fkellermavnet | 0:affdbb35faa4 | 587 | closeOpenSocket(numSock); |
fkellermavnet | 0:affdbb35faa4 | 588 | i = 0; |
fkellermavnet | 0:affdbb35faa4 | 589 | } |
fkellermavnet | 0:affdbb35faa4 | 590 | else |
fkellermavnet | 0:affdbb35faa4 | 591 | waitMs(to); |
fkellermavnet | 0:affdbb35faa4 | 592 | } |
fkellermavnet | 10:2ec59906a24e | 593 | } while ((i-- > 0) && (maxReadBufLen > 0)); |
fkellermavnet | 0:affdbb35faa4 | 594 | } |
fkellermavnet | 0:affdbb35faa4 | 595 | else { |
fkellermavnet | 0:affdbb35faa4 | 596 | dbgPuts("Socket is closed for read"); |
fkellermavnet | 0:affdbb35faa4 | 597 | } |
fkellermavnet | 0:affdbb35faa4 | 598 | } |
fkellermavnet | 0:affdbb35faa4 | 599 | else { |
fkellermavnet | 0:affdbb35faa4 | 600 | dbgPuts("Bad socket num!"); |
fkellermavnet | 0:affdbb35faa4 | 601 | } |
fkellermavnet | 0:affdbb35faa4 | 602 | |
fkellermavnet | 0:affdbb35faa4 | 603 | return (numCopied); |
fkellermavnet | 0:affdbb35faa4 | 604 | } |
fkellermavnet | 0:affdbb35faa4 | 605 | |
fkellermavnet | 0:affdbb35faa4 | 606 | /** |
fkellermavnet | 0:affdbb35faa4 | 607 | * \brief Set how many times the above read method will retry if data is not returned. |
fkellermavnet | 0:affdbb35faa4 | 608 | * |
fkellermavnet | 0:affdbb35faa4 | 609 | * \param [in] sockNum - the number of the socket to set. retries - how many times to |
fkellermavnet | 0:affdbb35faa4 | 610 | * poll until data is found. |
fkellermavnet | 0:affdbb35faa4 | 611 | * |
fkellermavnet | 0:affdbb35faa4 | 612 | * \return None. |
fkellermavnet | 0:affdbb35faa4 | 613 | * |
fkellermavnet | 0:affdbb35faa4 | 614 | * \details None. |
fkellermavnet | 0:affdbb35faa4 | 615 | */ |
fkellermavnet | 0:affdbb35faa4 | 616 | void WncController::setReadRetries(uint16_t numSock, uint16_t retries) |
fkellermavnet | 0:affdbb35faa4 | 617 | { |
fkellermavnet | 0:affdbb35faa4 | 618 | if (numSock < MAX_NUM_WNC_SOCKETS) |
fkellermavnet | 0:affdbb35faa4 | 619 | m_sSock[numSock].readRetries = retries; |
fkellermavnet | 0:affdbb35faa4 | 620 | else |
fkellermavnet | 0:affdbb35faa4 | 621 | dbgPuts("Bad socket num!"); |
fkellermavnet | 0:affdbb35faa4 | 622 | } |
fkellermavnet | 0:affdbb35faa4 | 623 | |
fkellermavnet | 0:affdbb35faa4 | 624 | /** |
fkellermavnet | 0:affdbb35faa4 | 625 | * \brief Set how long between retries to wait. |
fkellermavnet | 0:affdbb35faa4 | 626 | * |
fkellermavnet | 0:affdbb35faa4 | 627 | * \param [in] sockNum - the number of the socket to set. readRetryWaitMs - how long to wait |
fkellermavnet | 0:affdbb35faa4 | 628 | * before doing the read poll (calling read(...)). |
fkellermavnet | 0:affdbb35faa4 | 629 | * |
fkellermavnet | 0:affdbb35faa4 | 630 | * \return None. |
fkellermavnet | 0:affdbb35faa4 | 631 | * |
fkellermavnet | 0:affdbb35faa4 | 632 | * \details None. |
fkellermavnet | 0:affdbb35faa4 | 633 | */ |
fkellermavnet | 0:affdbb35faa4 | 634 | void WncController::setReadRetryWait(uint16_t numSock, uint16_t readRetryWaitMs) |
fkellermavnet | 0:affdbb35faa4 | 635 | { |
fkellermavnet | 0:affdbb35faa4 | 636 | if (numSock < MAX_NUM_WNC_SOCKETS) |
fkellermavnet | 0:affdbb35faa4 | 637 | m_sSock[numSock].readRetryWaitMs = readRetryWaitMs; |
fkellermavnet | 0:affdbb35faa4 | 638 | else |
fkellermavnet | 0:affdbb35faa4 | 639 | dbgPuts("Bad socket num!"); |
fkellermavnet | 0:affdbb35faa4 | 640 | } |
fkellermavnet | 0:affdbb35faa4 | 641 | |
fkellermavnet | 0:affdbb35faa4 | 642 | /** |
fkellermavnet | 0:affdbb35faa4 | 643 | * \brief Close the socket. |
fkellermavnet | 0:affdbb35faa4 | 644 | * |
fkellermavnet | 0:affdbb35faa4 | 645 | * \param [in] sockNum - the number of the socket to close. |
fkellermavnet | 0:affdbb35faa4 | 646 | * |
fkellermavnet | 0:affdbb35faa4 | 647 | * \return None. |
fkellermavnet | 0:affdbb35faa4 | 648 | * |
fkellermavnet | 0:affdbb35faa4 | 649 | * \details None. |
fkellermavnet | 0:affdbb35faa4 | 650 | */ |
fkellermavnet | 0:affdbb35faa4 | 651 | bool WncController::closeSocket(uint16_t numSock) |
fkellermavnet | 0:affdbb35faa4 | 652 | { |
fkellermavnet | 0:affdbb35faa4 | 653 | if (numSock < MAX_NUM_WNC_SOCKETS) { |
fkellermavnet | 0:affdbb35faa4 | 654 | |
fkellermavnet | 10:2ec59906a24e | 655 | if (false == at_sockclose_wnc(m_sSock[numSock].numWncSock)) |
fkellermavnet | 0:affdbb35faa4 | 656 | dbgPuts("Sock close may not have closed!"); |
fkellermavnet | 0:affdbb35faa4 | 657 | |
fkellermavnet | 0:affdbb35faa4 | 658 | // Even with an error the socket could have closed, |
fkellermavnet | 0:affdbb35faa4 | 659 | // can't tell for sure so just soft close it for now. |
fkellermavnet | 0:affdbb35faa4 | 660 | m_sSock[numSock].open = false; |
fkellermavnet | 0:affdbb35faa4 | 661 | } |
fkellermavnet | 0:affdbb35faa4 | 662 | else { |
fkellermavnet | 0:affdbb35faa4 | 663 | dbgPuts("Bad socket num!"); |
fkellermavnet | 0:affdbb35faa4 | 664 | } |
fkellermavnet | 0:affdbb35faa4 | 665 | |
fkellermavnet | 0:affdbb35faa4 | 666 | return (m_sSock[numSock].open == false); |
fkellermavnet | 0:affdbb35faa4 | 667 | } |
fkellermavnet | 0:affdbb35faa4 | 668 | |
fkellermavnet | 0:affdbb35faa4 | 669 | // Note: If you want to make it more portable, create a |
fkellermavnet | 0:affdbb35faa4 | 670 | // arecharsavailable() and readchar() |
fkellermavnet | 1:ac2de545b981 | 671 | size_t WncController::mdmGetline(string * buff, int timeout_ms) |
fkellermavnet | 0:affdbb35faa4 | 672 | { |
fkellermavnet | 0:affdbb35faa4 | 673 | char chin = '\0'; |
fkellermavnet | 0:affdbb35faa4 | 674 | char chin_last; |
fkellermavnet | 0:affdbb35faa4 | 675 | size_t len = 0; |
fkellermavnet | 0:affdbb35faa4 | 676 | |
fkellermavnet | 0:affdbb35faa4 | 677 | startTimerB(); |
fkellermavnet | 17:59b1e9341188 | 678 | while ((len <= MAX_LEN_WNC_CMD_RESPONSE) && (getTimerTicksB_mS() < timeout_ms)) { |
fkellermavnet | 1:ac2de545b981 | 679 | if (charReady()) { |
fkellermavnet | 0:affdbb35faa4 | 680 | chin_last = chin; |
fkellermavnet | 1:ac2de545b981 | 681 | chin = getc(); |
fkellermavnet | 0:affdbb35faa4 | 682 | if (isprint(chin)) { |
fkellermavnet | 1:ac2de545b981 | 683 | *buff += chin; |
fkellermavnet | 0:affdbb35faa4 | 684 | len++; // Bound the copy length to something reaonable just in case |
fkellermavnet | 0:affdbb35faa4 | 685 | continue; |
fkellermavnet | 0:affdbb35faa4 | 686 | } |
fkellermavnet | 0:affdbb35faa4 | 687 | else if ((('\r' == chin_last) && ('\n' == chin)) || (('\n' == chin_last) && ('\r' == chin))) { |
fkellermavnet | 0:affdbb35faa4 | 688 | break; |
fkellermavnet | 0:affdbb35faa4 | 689 | } |
fkellermavnet | 0:affdbb35faa4 | 690 | } |
fkellermavnet | 0:affdbb35faa4 | 691 | } |
fkellermavnet | 0:affdbb35faa4 | 692 | stopTimerB(); |
fkellermavnet | 0:affdbb35faa4 | 693 | |
fkellermavnet | 17:59b1e9341188 | 694 | if (len > MAX_LEN_WNC_CMD_RESPONSE) |
fkellermavnet | 0:affdbb35faa4 | 695 | dbgPuts("Max cmd length reply exceeded!"); |
fkellermavnet | 0:affdbb35faa4 | 696 | |
fkellermavnet | 0:affdbb35faa4 | 697 | return (len); |
fkellermavnet | 0:affdbb35faa4 | 698 | } |
fkellermavnet | 0:affdbb35faa4 | 699 | |
fkellermavnet | 0:affdbb35faa4 | 700 | // Eventually this should try to reinstate the sockets open |
fkellermavnet | 0:affdbb35faa4 | 701 | bool WncController::softwareInitMdm(void) |
fkellermavnet | 0:affdbb35faa4 | 702 | { |
fkellermavnet | 0:affdbb35faa4 | 703 | static bool reportStatus = true; |
fkellermavnet | 0:affdbb35faa4 | 704 | unsigned i; |
fkellermavnet | 0:affdbb35faa4 | 705 | |
fkellermavnet | 0:affdbb35faa4 | 706 | if (checkCellLink() == true) { |
fkellermavnet | 0:affdbb35faa4 | 707 | if (reportStatus == false) { |
fkellermavnet | 0:affdbb35faa4 | 708 | dbgPuts("Re-connected to cellular network!"); |
fkellermavnet | 0:affdbb35faa4 | 709 | reportStatus = true; |
fkellermavnet | 0:affdbb35faa4 | 710 | } |
fkellermavnet | 0:affdbb35faa4 | 711 | |
fkellermavnet | 0:affdbb35faa4 | 712 | // WNC has SIM and registered on network so |
fkellermavnet | 0:affdbb35faa4 | 713 | // soft initialize the WNC. |
fkellermavnet | 0:affdbb35faa4 | 714 | for (i = 0; i < WNC_SOFT_INIT_RETRY_COUNT; i++) |
fkellermavnet | 0:affdbb35faa4 | 715 | if (at_init_wnc() == true) |
fkellermavnet | 0:affdbb35faa4 | 716 | break; |
fkellermavnet | 0:affdbb35faa4 | 717 | |
fkellermavnet | 0:affdbb35faa4 | 718 | // If it did not respond try a hardware init |
fkellermavnet | 0:affdbb35faa4 | 719 | if (i == WNC_SOFT_INIT_RETRY_COUNT) |
fkellermavnet | 0:affdbb35faa4 | 720 | { |
fkellermavnet | 0:affdbb35faa4 | 721 | at_reinitialize_mdm(); |
fkellermavnet | 0:affdbb35faa4 | 722 | return (at_init_wnc(true)); // Hard reset occurred so make it go through the software init(); |
fkellermavnet | 0:affdbb35faa4 | 723 | } |
fkellermavnet | 0:affdbb35faa4 | 724 | else |
fkellermavnet | 0:affdbb35faa4 | 725 | return (true); |
fkellermavnet | 0:affdbb35faa4 | 726 | } |
fkellermavnet | 0:affdbb35faa4 | 727 | else |
fkellermavnet | 0:affdbb35faa4 | 728 | { |
fkellermavnet | 0:affdbb35faa4 | 729 | if (reportStatus == true) { |
fkellermavnet | 0:affdbb35faa4 | 730 | dbgPuts("Not connected to cellular network!"); |
fkellermavnet | 0:affdbb35faa4 | 731 | reportStatus = false; |
fkellermavnet | 0:affdbb35faa4 | 732 | } |
fkellermavnet | 0:affdbb35faa4 | 733 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 734 | } |
fkellermavnet | 0:affdbb35faa4 | 735 | } |
fkellermavnet | 0:affdbb35faa4 | 736 | |
fkellermavnet | 0:affdbb35faa4 | 737 | |
fkellermavnet | 0:affdbb35faa4 | 738 | // Sets a global with failure or success, assumes 1 thread all the time |
fkellermavnet | 0:affdbb35faa4 | 739 | WncController::AtCmdErr_e WncController::sendWncCmd(const char * const s, string ** r, int ms_timeout) |
fkellermavnet | 0:affdbb35faa4 | 740 | { |
fkellermavnet | 0:affdbb35faa4 | 741 | if (checkCellLink() == false) { |
fkellermavnet | 0:affdbb35faa4 | 742 | static string noRespStr; |
fkellermavnet | 0:affdbb35faa4 | 743 | |
fkellermavnet | 0:affdbb35faa4 | 744 | // Save some run-time! |
fkellermavnet | 0:affdbb35faa4 | 745 | if (m_sDebugEnabled) |
fkellermavnet | 0:affdbb35faa4 | 746 | { |
fkellermavnet | 0:affdbb35faa4 | 747 | dbgPuts("FAIL send cmd: ", false); |
fkellermavnet | 0:affdbb35faa4 | 748 | if (m_sMoreDebugEnabled && m_sDebugEnabled) { |
fkellermavnet | 0:affdbb35faa4 | 749 | dbgPutsNoTime(s); |
fkellermavnet | 0:affdbb35faa4 | 750 | } |
fkellermavnet | 0:affdbb35faa4 | 751 | else { |
fkellermavnet | 0:affdbb35faa4 | 752 | size_t n = strlen(s); |
fkellermavnet | 0:affdbb35faa4 | 753 | if (n <= WNC_TRUNC_DEBUG_LENGTH) { |
fkellermavnet | 0:affdbb35faa4 | 754 | dbgPutsNoTime(s); |
fkellermavnet | 0:affdbb35faa4 | 755 | } |
fkellermavnet | 0:affdbb35faa4 | 756 | else { |
fkellermavnet | 0:affdbb35faa4 | 757 | string truncStr(s,WNC_TRUNC_DEBUG_LENGTH/2); |
fkellermavnet | 0:affdbb35faa4 | 758 | truncStr += ".."; |
fkellermavnet | 0:affdbb35faa4 | 759 | truncStr += &s[n-(WNC_TRUNC_DEBUG_LENGTH/2)]; |
fkellermavnet | 0:affdbb35faa4 | 760 | dbgPutsNoTime(truncStr.c_str()); |
fkellermavnet | 0:affdbb35faa4 | 761 | } |
fkellermavnet | 0:affdbb35faa4 | 762 | } |
fkellermavnet | 0:affdbb35faa4 | 763 | } |
fkellermavnet | 0:affdbb35faa4 | 764 | |
fkellermavnet | 0:affdbb35faa4 | 765 | noRespStr.erase(); |
fkellermavnet | 0:affdbb35faa4 | 766 | *r = &noRespStr; |
fkellermavnet | 0:affdbb35faa4 | 767 | |
fkellermavnet | 0:affdbb35faa4 | 768 | return (WNC_AT_CMD_NO_CELL_LINK); |
fkellermavnet | 0:affdbb35faa4 | 769 | } |
fkellermavnet | 0:affdbb35faa4 | 770 | |
fkellermavnet | 0:affdbb35faa4 | 771 | if (m_sCheckNetStatus) |
fkellermavnet | 0:affdbb35faa4 | 772 | { |
fkellermavnet | 0:affdbb35faa4 | 773 | if (m_sMoreDebugEnabled) |
fkellermavnet | 0:affdbb35faa4 | 774 | dbgPuts("[---------- Network Status -------------"); |
fkellermavnet | 0:affdbb35faa4 | 775 | string * pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 776 | at_send_wnc_cmd("AT@SOCKDIAL?", &pRespStr, m_sCmdTimeoutMs); |
fkellermavnet | 0:affdbb35faa4 | 777 | if (m_sMoreDebugEnabled) |
fkellermavnet | 0:affdbb35faa4 | 778 | dbgPuts("---------------------------------------]"); |
fkellermavnet | 0:affdbb35faa4 | 779 | } |
fkellermavnet | 0:affdbb35faa4 | 780 | |
fkellermavnet | 0:affdbb35faa4 | 781 | // If WNC ready, send user command |
fkellermavnet | 0:affdbb35faa4 | 782 | return (at_send_wnc_cmd(s, r, ms_timeout)); |
fkellermavnet | 0:affdbb35faa4 | 783 | } |
fkellermavnet | 0:affdbb35faa4 | 784 | |
fkellermavnet | 0:affdbb35faa4 | 785 | WncController::AtCmdErr_e WncController::at_send_wnc_cmd(const char * s, string ** r, int ms_timeout) |
fkellermavnet | 0:affdbb35faa4 | 786 | { |
fkellermavnet | 0:affdbb35faa4 | 787 | // Save some run-time! |
fkellermavnet | 0:affdbb35faa4 | 788 | if (m_sDebugEnabled) |
fkellermavnet | 0:affdbb35faa4 | 789 | { |
fkellermavnet | 0:affdbb35faa4 | 790 | if (m_sMoreDebugEnabled) { |
fkellermavnet | 0:affdbb35faa4 | 791 | dbgPuts("TX: ", false); dbgPutsNoTime(s); |
fkellermavnet | 0:affdbb35faa4 | 792 | } |
fkellermavnet | 0:affdbb35faa4 | 793 | else { |
fkellermavnet | 0:affdbb35faa4 | 794 | if (m_sDebugEnabled) { // Save some run-time! |
fkellermavnet | 0:affdbb35faa4 | 795 | size_t n = strlen(s); |
fkellermavnet | 0:affdbb35faa4 | 796 | if (n <= WNC_TRUNC_DEBUG_LENGTH) { |
fkellermavnet | 0:affdbb35faa4 | 797 | dbgPuts("TX: ", false); dbgPutsNoTime(s); |
fkellermavnet | 0:affdbb35faa4 | 798 | } |
fkellermavnet | 0:affdbb35faa4 | 799 | else { |
fkellermavnet | 0:affdbb35faa4 | 800 | string truncStr(s,WNC_TRUNC_DEBUG_LENGTH/2); |
fkellermavnet | 0:affdbb35faa4 | 801 | truncStr += ".."; |
fkellermavnet | 0:affdbb35faa4 | 802 | truncStr += &s[n - (WNC_TRUNC_DEBUG_LENGTH/2)]; |
fkellermavnet | 0:affdbb35faa4 | 803 | dbgPuts("TX: ", false); dbgPutsNoTime(truncStr.c_str()); |
fkellermavnet | 0:affdbb35faa4 | 804 | } |
fkellermavnet | 0:affdbb35faa4 | 805 | } |
fkellermavnet | 0:affdbb35faa4 | 806 | } |
fkellermavnet | 0:affdbb35faa4 | 807 | } |
fkellermavnet | 0:affdbb35faa4 | 808 | |
fkellermavnet | 0:affdbb35faa4 | 809 | AtCmdErr_e atResult = mdmSendAtCmdRsp(s, ms_timeout, &m_sWncStr); |
fkellermavnet | 0:affdbb35faa4 | 810 | *r = &m_sWncStr; // Return a pointer to the static string |
fkellermavnet | 0:affdbb35faa4 | 811 | |
fkellermavnet | 0:affdbb35faa4 | 812 | if (atResult != WNC_AT_CMD_TIMEOUT) { |
fkellermavnet | 0:affdbb35faa4 | 813 | // Save some run-time! |
fkellermavnet | 0:affdbb35faa4 | 814 | if (m_sDebugEnabled) |
fkellermavnet | 0:affdbb35faa4 | 815 | { |
fkellermavnet | 0:affdbb35faa4 | 816 | dbgPuts("RX: ", false); |
fkellermavnet | 0:affdbb35faa4 | 817 | if (m_sMoreDebugEnabled) { |
fkellermavnet | 0:affdbb35faa4 | 818 | dbgPutsNoTime(m_sWncStr.c_str()); |
fkellermavnet | 0:affdbb35faa4 | 819 | } |
fkellermavnet | 0:affdbb35faa4 | 820 | else { |
fkellermavnet | 0:affdbb35faa4 | 821 | if (m_sWncStr.size() <= WNC_TRUNC_DEBUG_LENGTH) { |
fkellermavnet | 0:affdbb35faa4 | 822 | dbgPutsNoTime(m_sWncStr.c_str()); |
fkellermavnet | 0:affdbb35faa4 | 823 | } |
fkellermavnet | 0:affdbb35faa4 | 824 | else { |
fkellermavnet | 0:affdbb35faa4 | 825 | string truncStr = m_sWncStr.substr(0,WNC_TRUNC_DEBUG_LENGTH/2) + ".."; |
fkellermavnet | 0:affdbb35faa4 | 826 | truncStr += m_sWncStr.substr(m_sWncStr.size() - (WNC_TRUNC_DEBUG_LENGTH/2), WNC_TRUNC_DEBUG_LENGTH/2); |
fkellermavnet | 0:affdbb35faa4 | 827 | dbgPutsNoTime(truncStr.c_str()); |
fkellermavnet | 0:affdbb35faa4 | 828 | } |
fkellermavnet | 0:affdbb35faa4 | 829 | } |
fkellermavnet | 0:affdbb35faa4 | 830 | } |
fkellermavnet | 0:affdbb35faa4 | 831 | } |
fkellermavnet | 0:affdbb35faa4 | 832 | else { |
fkellermavnet | 0:affdbb35faa4 | 833 | dbgPuts("AT Cmd TIMEOUT!"); |
fkellermavnet | 0:affdbb35faa4 | 834 | dbgPuts("RX: ", false); dbgPutsNoTime(m_sWncStr.c_str()); |
fkellermavnet | 0:affdbb35faa4 | 835 | } |
fkellermavnet | 0:affdbb35faa4 | 836 | |
fkellermavnet | 0:affdbb35faa4 | 837 | return (atResult); |
fkellermavnet | 0:affdbb35faa4 | 838 | } |
fkellermavnet | 0:affdbb35faa4 | 839 | |
fkellermavnet | 0:affdbb35faa4 | 840 | void WncController::closeOpenSocket(uint16_t numSock) |
fkellermavnet | 0:affdbb35faa4 | 841 | { |
fkellermavnet | 0:affdbb35faa4 | 842 | // Try to open and close the socket |
fkellermavnet | 0:affdbb35faa4 | 843 | do { |
fkellermavnet | 0:affdbb35faa4 | 844 | dbgPuts("Try to close and re-open socket"); |
fkellermavnet | 10:2ec59906a24e | 845 | at_sockclose_wnc(m_sSock[numSock].numWncSock); |
fkellermavnet | 10:2ec59906a24e | 846 | |
fkellermavnet | 10:2ec59906a24e | 847 | int numWncSock = at_sockopen_wnc(m_sSock[numSock].myIpAddressStr.c_str(), m_sSock[numSock].myPort, numSock, m_sSock[numSock].isTcp, m_sSock[numSock].timeOutSec); |
fkellermavnet | 10:2ec59906a24e | 848 | m_sSock[numSock].numWncSock = numWncSock; |
fkellermavnet | 10:2ec59906a24e | 849 | if (numWncSock > 0 && numWncSock <= MAX_NUM_WNC_SOCKETS) |
fkellermavnet | 10:2ec59906a24e | 850 | m_sSock[numSock].open = true; |
fkellermavnet | 10:2ec59906a24e | 851 | else |
fkellermavnet | 10:2ec59906a24e | 852 | m_sSock[numSock].open = false; |
fkellermavnet | 10:2ec59906a24e | 853 | |
fkellermavnet | 0:affdbb35faa4 | 854 | if (m_sSock[numSock].open == false) |
fkellermavnet | 0:affdbb35faa4 | 855 | dbgPuts("Failed to re-open socket!"); |
fkellermavnet | 0:affdbb35faa4 | 856 | } while (m_sSock[numSock].open == false); |
fkellermavnet | 0:affdbb35faa4 | 857 | } |
fkellermavnet | 0:affdbb35faa4 | 858 | |
fkellermavnet | 18:ca2899c353c2 | 859 | |
fkellermavnet | 18:ca2899c353c2 | 860 | bool WncController::getICCID(string * iccid) |
fkellermavnet | 18:ca2899c353c2 | 861 | { |
fkellermavnet | 18:ca2899c353c2 | 862 | string * respStr; |
fkellermavnet | 18:ca2899c353c2 | 863 | |
fkellermavnet | 18:ca2899c353c2 | 864 | iccid->erase(); |
fkellermavnet | 18:ca2899c353c2 | 865 | |
fkellermavnet | 18:ca2899c353c2 | 866 | AtCmdErr_e r = at_send_wnc_cmd("AT%CCID", &respStr, m_sCmdTimeoutMs); |
fkellermavnet | 18:ca2899c353c2 | 867 | |
fkellermavnet | 18:ca2899c353c2 | 868 | if (r != WNC_AT_CMD_OK || respStr->size() == 0) |
fkellermavnet | 18:ca2899c353c2 | 869 | return (false); |
fkellermavnet | 18:ca2899c353c2 | 870 | |
fkellermavnet | 18:ca2899c353c2 | 871 | size_t pos = respStr->find("AT%CCID"); |
fkellermavnet | 18:ca2899c353c2 | 872 | if (pos == string::npos) |
fkellermavnet | 18:ca2899c353c2 | 873 | return (false); |
fkellermavnet | 18:ca2899c353c2 | 874 | |
fkellermavnet | 18:ca2899c353c2 | 875 | size_t posOK = respStr->rfind("OK"); |
fkellermavnet | 18:ca2899c353c2 | 876 | if (posOK == string::npos) |
fkellermavnet | 18:ca2899c353c2 | 877 | return (false); |
fkellermavnet | 18:ca2899c353c2 | 878 | |
fkellermavnet | 18:ca2899c353c2 | 879 | pos += 7; // Advanced to the number |
fkellermavnet | 18:ca2899c353c2 | 880 | *iccid = respStr->substr(pos, posOK - pos); |
fkellermavnet | 18:ca2899c353c2 | 881 | |
fkellermavnet | 18:ca2899c353c2 | 882 | return (true); |
fkellermavnet | 18:ca2899c353c2 | 883 | } |
fkellermavnet | 18:ca2899c353c2 | 884 | |
fkellermavnet | 18:ca2899c353c2 | 885 | bool WncController::convertICCIDtoMSISDN(const string & iccid, string * msisdn) |
fkellermavnet | 18:ca2899c353c2 | 886 | { |
fkellermavnet | 18:ca2899c353c2 | 887 | msisdn->erase(); |
fkellermavnet | 18:ca2899c353c2 | 888 | |
fkellermavnet | 18:ca2899c353c2 | 889 | if (iccid.size() != 20 && iccid.size() != 19) { |
fkellermavnet | 18:ca2899c353c2 | 890 | dbgPuts("Invalid ICCID length!"); |
fkellermavnet | 18:ca2899c353c2 | 891 | return (false); |
fkellermavnet | 18:ca2899c353c2 | 892 | } |
fkellermavnet | 18:ca2899c353c2 | 893 | |
fkellermavnet | 18:ca2899c353c2 | 894 | *msisdn = "882350"; |
fkellermavnet | 18:ca2899c353c2 | 895 | |
fkellermavnet | 18:ca2899c353c2 | 896 | if (iccid.size() == 20) |
fkellermavnet | 18:ca2899c353c2 | 897 | *msisdn += iccid.substr(10,iccid.size() - 11); |
fkellermavnet | 18:ca2899c353c2 | 898 | else |
fkellermavnet | 18:ca2899c353c2 | 899 | *msisdn += iccid.substr(10,iccid.size() - 10); |
fkellermavnet | 18:ca2899c353c2 | 900 | |
fkellermavnet | 18:ca2899c353c2 | 901 | return (true); |
fkellermavnet | 18:ca2899c353c2 | 902 | } |
fkellermavnet | 18:ca2899c353c2 | 903 | |
fkellermavnet | 18:ca2899c353c2 | 904 | |
fkellermavnet | 0:affdbb35faa4 | 905 | bool WncController::sendSMSText(const char * const phoneNum, const char * const text) |
fkellermavnet | 0:affdbb35faa4 | 906 | { |
fkellermavnet | 0:affdbb35faa4 | 907 | if (at_sendSMStext_wnc(phoneNum, text) == true) |
fkellermavnet | 0:affdbb35faa4 | 908 | return (true); |
fkellermavnet | 0:affdbb35faa4 | 909 | else { |
fkellermavnet | 0:affdbb35faa4 | 910 | dbgPuts("sendSMSText: Failed!"); |
fkellermavnet | 0:affdbb35faa4 | 911 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 912 | } |
fkellermavnet | 0:affdbb35faa4 | 913 | } |
fkellermavnet | 0:affdbb35faa4 | 914 | |
fkellermavnet | 18:ca2899c353c2 | 915 | bool WncController::readSMSLog(struct WncSmsList * log) |
fkellermavnet | 0:affdbb35faa4 | 916 | { |
fkellermavnet | 18:ca2899c353c2 | 917 | string * logStr; |
fkellermavnet | 18:ca2899c353c2 | 918 | uint16_t i; |
fkellermavnet | 18:ca2899c353c2 | 919 | |
fkellermavnet | 18:ca2899c353c2 | 920 | if (at_readSMSlog_wnc(&logStr) == false) { |
fkellermavnet | 18:ca2899c353c2 | 921 | dbgPuts("readSMSLog: Failed!"); |
fkellermavnet | 18:ca2899c353c2 | 922 | return (false); |
fkellermavnet | 18:ca2899c353c2 | 923 | } |
fkellermavnet | 18:ca2899c353c2 | 924 | |
fkellermavnet | 18:ca2899c353c2 | 925 | dbgPuts(logStr->c_str()); |
fkellermavnet | 18:ca2899c353c2 | 926 | |
fkellermavnet | 18:ca2899c353c2 | 927 | // Clean slate |
fkellermavnet | 18:ca2899c353c2 | 928 | log->msgCount = 0; |
fkellermavnet | 18:ca2899c353c2 | 929 | |
fkellermavnet | 18:ca2899c353c2 | 930 | // Pick out the stuff from the string and convert to struct |
fkellermavnet | 18:ca2899c353c2 | 931 | string s; |
fkellermavnet | 18:ca2899c353c2 | 932 | size_t pos2; |
fkellermavnet | 18:ca2899c353c2 | 933 | size_t pos = logStr->find("+CMGL:"); |
fkellermavnet | 0:affdbb35faa4 | 934 | |
fkellermavnet | 18:ca2899c353c2 | 935 | for(i=0; i<MAX_WNC_SMS_MSG_SLOTS; i++) { |
fkellermavnet | 18:ca2899c353c2 | 936 | if (pos == string::npos) |
fkellermavnet | 18:ca2899c353c2 | 937 | return (false); |
fkellermavnet | 18:ca2899c353c2 | 938 | pos = logStr->find(",\""); |
fkellermavnet | 18:ca2899c353c2 | 939 | if (pos == string::npos) |
fkellermavnet | 18:ca2899c353c2 | 940 | return (false); |
fkellermavnet | 18:ca2899c353c2 | 941 | pos += 3; // Advance to the text we want |
fkellermavnet | 18:ca2899c353c2 | 942 | pos2 = logStr->find("\",", pos); |
fkellermavnet | 18:ca2899c353c2 | 943 | if ((pos2 == string::npos) || (pos >= pos2)) |
fkellermavnet | 18:ca2899c353c2 | 944 | return (false); |
fkellermavnet | 18:ca2899c353c2 | 945 | |
fkellermavnet | 18:ca2899c353c2 | 946 | // Setup attributes |
fkellermavnet | 18:ca2899c353c2 | 947 | log->e[i].unread = false; |
fkellermavnet | 18:ca2899c353c2 | 948 | log->e[i].incoming = false; |
fkellermavnet | 18:ca2899c353c2 | 949 | log->e[i].unsent = false; |
fkellermavnet | 18:ca2899c353c2 | 950 | |
fkellermavnet | 18:ca2899c353c2 | 951 | s = logStr->substr(pos, pos2 - pos); |
fkellermavnet | 18:ca2899c353c2 | 952 | if (s.find("READ") != string::npos) |
fkellermavnet | 18:ca2899c353c2 | 953 | log->e[i].incoming = true; |
fkellermavnet | 18:ca2899c353c2 | 954 | if (s.find("REC UNREAD") != string::npos) |
fkellermavnet | 18:ca2899c353c2 | 955 | log->e[i].unread = true; |
fkellermavnet | 18:ca2899c353c2 | 956 | if (s.find("STO UNSENT") != string::npos) |
fkellermavnet | 18:ca2899c353c2 | 957 | log->e[i].unsent = true; |
fkellermavnet | 18:ca2899c353c2 | 958 | |
fkellermavnet | 18:ca2899c353c2 | 959 | // Tele number |
fkellermavnet | 18:ca2899c353c2 | 960 | pos2 += 3; // Advance to next field |
fkellermavnet | 18:ca2899c353c2 | 961 | pos = logStr->find("\",", pos2); |
fkellermavnet | 18:ca2899c353c2 | 962 | if ((pos == string::npos) || (pos2 > pos)) |
fkellermavnet | 18:ca2899c353c2 | 963 | return (false); |
fkellermavnet | 18:ca2899c353c2 | 964 | if (pos == pos2) |
fkellermavnet | 18:ca2899c353c2 | 965 | log->e[i].number.erase(); |
fkellermavnet | 18:ca2899c353c2 | 966 | else |
fkellermavnet | 18:ca2899c353c2 | 967 | log->e[i].number = logStr->substr(pos2, pos - pos2); |
fkellermavnet | 18:ca2899c353c2 | 968 | |
fkellermavnet | 18:ca2899c353c2 | 969 | // Timestamp |
fkellermavnet | 18:ca2899c353c2 | 970 | pos = pos2 + 4; // Beginning of timestamp field |
fkellermavnet | 18:ca2899c353c2 | 971 | pos2 = logStr->find("\",", pos); // End of timestamp field |
fkellermavnet | 18:ca2899c353c2 | 972 | if ((pos2 == string::npos) || (pos > pos2)) |
fkellermavnet | 18:ca2899c353c2 | 973 | return (false); |
fkellermavnet | 18:ca2899c353c2 | 974 | if (pos == pos2) |
fkellermavnet | 18:ca2899c353c2 | 975 | log->e[i].timestamp.erase(); |
fkellermavnet | 18:ca2899c353c2 | 976 | else |
fkellermavnet | 18:ca2899c353c2 | 977 | log->e[i].timestamp = logStr->substr(pos, pos2 - pos); |
fkellermavnet | 0:affdbb35faa4 | 978 | |
fkellermavnet | 18:ca2899c353c2 | 979 | // Message field |
fkellermavnet | 18:ca2899c353c2 | 980 | |
fkellermavnet | 18:ca2899c353c2 | 981 | // We don't know how many messages we have so the next search |
fkellermavnet | 18:ca2899c353c2 | 982 | // could end with +CMGL or OK. |
fkellermavnet | 18:ca2899c353c2 | 983 | pos2 += 2; // Advanced to message text |
fkellermavnet | 18:ca2899c353c2 | 984 | pos = logStr->find("+CMGL", pos2); |
fkellermavnet | 18:ca2899c353c2 | 985 | if (pos == string::npos) { |
fkellermavnet | 18:ca2899c353c2 | 986 | pos = logStr->find("OK", pos2); |
fkellermavnet | 18:ca2899c353c2 | 987 | if (pos == string::npos) { |
fkellermavnet | 18:ca2899c353c2 | 988 | dbgPuts("Strange SMS Log Ending!"); |
fkellermavnet | 18:ca2899c353c2 | 989 | return (false); |
fkellermavnet | 18:ca2899c353c2 | 990 | } |
fkellermavnet | 18:ca2899c353c2 | 991 | i = MAX_WNC_SMS_MSG_SLOTS; // break |
fkellermavnet | 18:ca2899c353c2 | 992 | } |
fkellermavnet | 18:ca2899c353c2 | 993 | if (pos2 > pos) |
fkellermavnet | 18:ca2899c353c2 | 994 | return (false); |
fkellermavnet | 18:ca2899c353c2 | 995 | if (pos2 == pos) |
fkellermavnet | 18:ca2899c353c2 | 996 | log->e[log->msgCount].msg.erase(); |
fkellermavnet | 18:ca2899c353c2 | 997 | else |
fkellermavnet | 18:ca2899c353c2 | 998 | log->e[log->msgCount].msg = logStr->substr(pos2, pos - pos2); |
fkellermavnet | 18:ca2899c353c2 | 999 | |
fkellermavnet | 18:ca2899c353c2 | 1000 | log->msgCount++; // Message complete |
fkellermavnet | 18:ca2899c353c2 | 1001 | } |
fkellermavnet | 18:ca2899c353c2 | 1002 | |
fkellermavnet | 18:ca2899c353c2 | 1003 | return (true); |
fkellermavnet | 18:ca2899c353c2 | 1004 | } |
fkellermavnet | 18:ca2899c353c2 | 1005 | |
fkellermavnet | 18:ca2899c353c2 | 1006 | bool WncController::readUnreadSMSText(struct WncSmsList * w) |
fkellermavnet | 18:ca2899c353c2 | 1007 | { |
fkellermavnet | 18:ca2899c353c2 | 1008 | struct WncController::WncSmsList tmp; |
fkellermavnet | 18:ca2899c353c2 | 1009 | |
fkellermavnet | 18:ca2899c353c2 | 1010 | if (readSMSLog(&tmp) == false) |
fkellermavnet | 18:ca2899c353c2 | 1011 | return (false); |
fkellermavnet | 18:ca2899c353c2 | 1012 | |
fkellermavnet | 18:ca2899c353c2 | 1013 | w->msgCount = 0; |
fkellermavnet | 18:ca2899c353c2 | 1014 | for(uint16_t i = 0; i < tmp.msgCount; i++) { |
fkellermavnet | 18:ca2899c353c2 | 1015 | if (tmp.e[i].unread == true) { |
fkellermavnet | 18:ca2899c353c2 | 1016 | w->e[w->msgCount] = tmp.e[i]; |
fkellermavnet | 18:ca2899c353c2 | 1017 | w->msgCount++; |
fkellermavnet | 18:ca2899c353c2 | 1018 | } |
fkellermavnet | 18:ca2899c353c2 | 1019 | } |
fkellermavnet | 18:ca2899c353c2 | 1020 | |
fkellermavnet | 18:ca2899c353c2 | 1021 | return (true); |
fkellermavnet | 0:affdbb35faa4 | 1022 | } |
fkellermavnet | 0:affdbb35faa4 | 1023 | |
fkellermavnet | 0:affdbb35faa4 | 1024 | size_t WncController::getSignalQuality(const char ** log) |
fkellermavnet | 0:affdbb35faa4 | 1025 | { |
fkellermavnet | 0:affdbb35faa4 | 1026 | size_t n; |
fkellermavnet | 0:affdbb35faa4 | 1027 | |
fkellermavnet | 0:affdbb35faa4 | 1028 | n = at_getSignalQuality_wnc(log); |
fkellermavnet | 0:affdbb35faa4 | 1029 | if (n == 0) |
fkellermavnet | 0:affdbb35faa4 | 1030 | dbgPuts("readSMSText: Failed!"); |
fkellermavnet | 0:affdbb35faa4 | 1031 | |
fkellermavnet | 0:affdbb35faa4 | 1032 | return (n); |
fkellermavnet | 0:affdbb35faa4 | 1033 | } |
fkellermavnet | 0:affdbb35faa4 | 1034 | |
fkellermavnet | 0:affdbb35faa4 | 1035 | size_t WncController::at_getSignalQuality_wnc(const char ** log) |
fkellermavnet | 0:affdbb35faa4 | 1036 | { |
fkellermavnet | 0:affdbb35faa4 | 1037 | string * pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1038 | static string logStr; |
fkellermavnet | 0:affdbb35faa4 | 1039 | |
fkellermavnet | 0:affdbb35faa4 | 1040 | logStr.erase(); |
fkellermavnet | 0:affdbb35faa4 | 1041 | |
fkellermavnet | 0:affdbb35faa4 | 1042 | if (at_send_wnc_cmd("AT%MEAS=\"0\"", &pRespStr, m_sCmdTimeoutMs) == WNC_AT_CMD_OK) { |
fkellermavnet | 0:affdbb35faa4 | 1043 | logStr = *pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1044 | logStr += "\r\n"; |
fkellermavnet | 0:affdbb35faa4 | 1045 | } |
fkellermavnet | 0:affdbb35faa4 | 1046 | else |
fkellermavnet | 0:affdbb35faa4 | 1047 | dbgPuts("AT%MEAS=0: failed!"); |
fkellermavnet | 0:affdbb35faa4 | 1048 | |
fkellermavnet | 0:affdbb35faa4 | 1049 | if (at_send_wnc_cmd("AT%MEAS=\"1\"", &pRespStr, m_sCmdTimeoutMs) == WNC_AT_CMD_OK) { |
fkellermavnet | 0:affdbb35faa4 | 1050 | logStr += *pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1051 | logStr += "\r\n"; |
fkellermavnet | 0:affdbb35faa4 | 1052 | } |
fkellermavnet | 0:affdbb35faa4 | 1053 | else |
fkellermavnet | 0:affdbb35faa4 | 1054 | dbgPuts("AT%MEAS=1: failed!"); |
fkellermavnet | 0:affdbb35faa4 | 1055 | |
fkellermavnet | 0:affdbb35faa4 | 1056 | if (at_send_wnc_cmd("AT%MEAS=\"2\"", &pRespStr, m_sCmdTimeoutMs) == WNC_AT_CMD_OK) { |
fkellermavnet | 0:affdbb35faa4 | 1057 | logStr += *pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1058 | logStr += "\r\n"; |
fkellermavnet | 0:affdbb35faa4 | 1059 | } |
fkellermavnet | 0:affdbb35faa4 | 1060 | else |
fkellermavnet | 0:affdbb35faa4 | 1061 | dbgPuts("AT%MEAS=2: failed!"); |
fkellermavnet | 0:affdbb35faa4 | 1062 | |
fkellermavnet | 0:affdbb35faa4 | 1063 | if (at_send_wnc_cmd("AT%MEAS=\"3\"", &pRespStr, m_sCmdTimeoutMs) == WNC_AT_CMD_OK) { |
fkellermavnet | 0:affdbb35faa4 | 1064 | logStr += *pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1065 | logStr += "\r\n"; |
fkellermavnet | 0:affdbb35faa4 | 1066 | } |
fkellermavnet | 0:affdbb35faa4 | 1067 | else |
fkellermavnet | 0:affdbb35faa4 | 1068 | dbgPuts("AT%MEAS=3: failed!"); |
fkellermavnet | 0:affdbb35faa4 | 1069 | |
fkellermavnet | 0:affdbb35faa4 | 1070 | if (at_send_wnc_cmd("AT%MEAS=\"4\"", &pRespStr, m_sCmdTimeoutMs) == WNC_AT_CMD_OK) { |
fkellermavnet | 0:affdbb35faa4 | 1071 | logStr += *pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1072 | logStr += "\r\n"; |
fkellermavnet | 0:affdbb35faa4 | 1073 | } |
fkellermavnet | 0:affdbb35faa4 | 1074 | else |
fkellermavnet | 0:affdbb35faa4 | 1075 | dbgPuts("AT%MEAS=4: failed!"); |
fkellermavnet | 0:affdbb35faa4 | 1076 | |
fkellermavnet | 0:affdbb35faa4 | 1077 | if (at_send_wnc_cmd("AT%MEAS=\"5\"", &pRespStr, m_sCmdTimeoutMs) == WNC_AT_CMD_OK) { |
fkellermavnet | 0:affdbb35faa4 | 1078 | logStr += *pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1079 | logStr += "\r\n"; |
fkellermavnet | 0:affdbb35faa4 | 1080 | } |
fkellermavnet | 0:affdbb35faa4 | 1081 | else |
fkellermavnet | 0:affdbb35faa4 | 1082 | dbgPuts("AT%MEAS=5: failed!"); |
fkellermavnet | 0:affdbb35faa4 | 1083 | |
fkellermavnet | 0:affdbb35faa4 | 1084 | if (at_send_wnc_cmd("AT%MEAS=\"8\"", &pRespStr, m_sCmdTimeoutMs) == WNC_AT_CMD_OK) { |
fkellermavnet | 0:affdbb35faa4 | 1085 | logStr += *pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1086 | logStr += "\r\n"; |
fkellermavnet | 0:affdbb35faa4 | 1087 | } |
fkellermavnet | 0:affdbb35faa4 | 1088 | else |
fkellermavnet | 0:affdbb35faa4 | 1089 | dbgPuts("AT%MEAS=8: failed!"); |
fkellermavnet | 0:affdbb35faa4 | 1090 | |
fkellermavnet | 0:affdbb35faa4 | 1091 | if (at_send_wnc_cmd("AT%MEAS=\"98\"", &pRespStr, m_sCmdTimeoutMs) == WNC_AT_CMD_OK) { |
fkellermavnet | 0:affdbb35faa4 | 1092 | logStr += *pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1093 | logStr += "\r\n"; |
fkellermavnet | 0:affdbb35faa4 | 1094 | } |
fkellermavnet | 0:affdbb35faa4 | 1095 | else |
fkellermavnet | 0:affdbb35faa4 | 1096 | dbgPuts("AT%MEAS=98: failed!"); |
fkellermavnet | 0:affdbb35faa4 | 1097 | |
fkellermavnet | 0:affdbb35faa4 | 1098 | *log = logStr.c_str(); |
fkellermavnet | 0:affdbb35faa4 | 1099 | |
fkellermavnet | 0:affdbb35faa4 | 1100 | return (logStr.size()); |
fkellermavnet | 0:affdbb35faa4 | 1101 | } |
fkellermavnet | 0:affdbb35faa4 | 1102 | |
fkellermavnet | 0:affdbb35faa4 | 1103 | bool WncController::getTimeDate(struct WncDateTime * tod) |
fkellermavnet | 0:affdbb35faa4 | 1104 | { |
fkellermavnet | 0:affdbb35faa4 | 1105 | if (at_gettimedate_wnc(tod) == true) |
fkellermavnet | 0:affdbb35faa4 | 1106 | return (true); |
fkellermavnet | 0:affdbb35faa4 | 1107 | else { |
fkellermavnet | 0:affdbb35faa4 | 1108 | dbgPuts("Get time date failed!"); |
fkellermavnet | 0:affdbb35faa4 | 1109 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1110 | } |
fkellermavnet | 0:affdbb35faa4 | 1111 | } |
fkellermavnet | 0:affdbb35faa4 | 1112 | |
fkellermavnet | 0:affdbb35faa4 | 1113 | bool WncController::at_ping_wnc(const char * ip) |
fkellermavnet | 0:affdbb35faa4 | 1114 | { |
fkellermavnet | 0:affdbb35faa4 | 1115 | string * pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1116 | string cmdStr = "AT@PINGREQ=\""; |
fkellermavnet | 0:affdbb35faa4 | 1117 | cmdStr += ip; |
fkellermavnet | 0:affdbb35faa4 | 1118 | cmdStr += "\""; |
fkellermavnet | 0:affdbb35faa4 | 1119 | return (at_send_wnc_cmd(cmdStr.c_str(), &pRespStr, WNC_PING_CMD_TIMEOUT_MS) == WNC_AT_CMD_OK); |
fkellermavnet | 0:affdbb35faa4 | 1120 | } |
fkellermavnet | 0:affdbb35faa4 | 1121 | |
fkellermavnet | 0:affdbb35faa4 | 1122 | bool WncController::at_gettimedate_wnc(struct WncDateTime * tod) |
fkellermavnet | 0:affdbb35faa4 | 1123 | { |
fkellermavnet | 0:affdbb35faa4 | 1124 | string * pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1125 | char * pEnd; |
fkellermavnet | 0:affdbb35faa4 | 1126 | |
fkellermavnet | 0:affdbb35faa4 | 1127 | if (at_send_wnc_cmd("AT+CCLK?", &pRespStr, m_sCmdTimeoutMs) == WNC_AT_CMD_OK) { |
fkellermavnet | 0:affdbb35faa4 | 1128 | if (pRespStr->size() > 0) { |
fkellermavnet | 0:affdbb35faa4 | 1129 | size_t pos1 = pRespStr->find("+CCLK:"); |
fkellermavnet | 0:affdbb35faa4 | 1130 | if (pos1 != string::npos) { |
fkellermavnet | 0:affdbb35faa4 | 1131 | pEnd = (char *)pRespStr->c_str() + pos1 + 8; |
fkellermavnet | 0:affdbb35faa4 | 1132 | tod->year = strtol(pEnd, &pEnd, 10); |
fkellermavnet | 0:affdbb35faa4 | 1133 | tod->month = strtol(pEnd+1, &pEnd, 10); |
fkellermavnet | 0:affdbb35faa4 | 1134 | tod->day = strtol(pEnd+1, &pEnd, 10); |
fkellermavnet | 0:affdbb35faa4 | 1135 | tod->hour = strtol(pEnd+1, &pEnd, 10); |
fkellermavnet | 0:affdbb35faa4 | 1136 | tod->min = strtol(pEnd+1, &pEnd, 10); |
fkellermavnet | 0:affdbb35faa4 | 1137 | tod->sec = strtol(pEnd+1, &pEnd, 10); |
fkellermavnet | 0:affdbb35faa4 | 1138 | return (true); |
fkellermavnet | 0:affdbb35faa4 | 1139 | } |
fkellermavnet | 0:affdbb35faa4 | 1140 | } |
fkellermavnet | 0:affdbb35faa4 | 1141 | } |
fkellermavnet | 0:affdbb35faa4 | 1142 | |
fkellermavnet | 0:affdbb35faa4 | 1143 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1144 | } |
fkellermavnet | 0:affdbb35faa4 | 1145 | |
fkellermavnet | 0:affdbb35faa4 | 1146 | bool WncController::at_get_wnc_net_stats(WncIpStats * s) |
fkellermavnet | 0:affdbb35faa4 | 1147 | { |
fkellermavnet | 0:affdbb35faa4 | 1148 | string * pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1149 | AtCmdErr_e cmdRes = at_send_wnc_cmd("AT+CGCONTRDP=1", &pRespStr, m_sCmdTimeoutMs); |
fkellermavnet | 0:affdbb35faa4 | 1150 | |
fkellermavnet | 0:affdbb35faa4 | 1151 | if (WNC_AT_CMD_OK == cmdRes) { |
fkellermavnet | 0:affdbb35faa4 | 1152 | if (pRespStr->size() > 0) { |
fkellermavnet | 0:affdbb35faa4 | 1153 | memset((void*)s, '\0', sizeof(*s)); // Clean-up |
fkellermavnet | 0:affdbb35faa4 | 1154 | string ss; |
fkellermavnet | 0:affdbb35faa4 | 1155 | size_t pe; |
fkellermavnet | 0:affdbb35faa4 | 1156 | size_t ps = pRespStr->rfind("\""); |
fkellermavnet | 0:affdbb35faa4 | 1157 | if (ps != string::npos) { |
fkellermavnet | 0:affdbb35faa4 | 1158 | ps += 2; // Skip the , after the " |
fkellermavnet | 0:affdbb35faa4 | 1159 | pe = ps; |
fkellermavnet | 14:e846217affcd | 1160 | |
fkellermavnet | 14:e846217affcd | 1161 | pe = pRespStr->find(".", pe); |
fkellermavnet | 14:e846217affcd | 1162 | if (pe == string::npos) |
fkellermavnet | 14:e846217affcd | 1163 | return (false); |
fkellermavnet | 14:e846217affcd | 1164 | else |
fkellermavnet | 14:e846217affcd | 1165 | pe += 1; |
fkellermavnet | 14:e846217affcd | 1166 | pe = pRespStr->find(".", pe); |
fkellermavnet | 14:e846217affcd | 1167 | if (pe == string::npos) |
fkellermavnet | 14:e846217affcd | 1168 | return (false); |
fkellermavnet | 14:e846217affcd | 1169 | else |
fkellermavnet | 14:e846217affcd | 1170 | pe += 1; |
fkellermavnet | 14:e846217affcd | 1171 | pe = pRespStr->find(".", pe); |
fkellermavnet | 14:e846217affcd | 1172 | if (pe == string::npos) |
fkellermavnet | 14:e846217affcd | 1173 | return (false); |
fkellermavnet | 14:e846217affcd | 1174 | else |
fkellermavnet | 14:e846217affcd | 1175 | pe += 1; |
fkellermavnet | 14:e846217affcd | 1176 | pe = pRespStr->find(".", pe); |
fkellermavnet | 14:e846217affcd | 1177 | if (pe == string::npos) |
fkellermavnet | 14:e846217affcd | 1178 | return (false); |
fkellermavnet | 14:e846217affcd | 1179 | else |
fkellermavnet | 14:e846217affcd | 1180 | pe += 1; |
fkellermavnet | 14:e846217affcd | 1181 | |
fkellermavnet | 0:affdbb35faa4 | 1182 | ss = pRespStr->substr(ps, pe - 1 - ps); |
fkellermavnet | 0:affdbb35faa4 | 1183 | strncpy(s->ip, ss.c_str(), MAX_LEN_IP_STR); |
fkellermavnet | 0:affdbb35faa4 | 1184 | s->ip[MAX_LEN_IP_STR - 1] = '\0'; |
fkellermavnet | 0:affdbb35faa4 | 1185 | ps = pe; |
fkellermavnet | 14:e846217affcd | 1186 | |
fkellermavnet | 14:e846217affcd | 1187 | pe = pRespStr->find(".", pe); |
fkellermavnet | 14:e846217affcd | 1188 | if (pe == string::npos) |
fkellermavnet | 14:e846217affcd | 1189 | return (false); |
fkellermavnet | 14:e846217affcd | 1190 | else |
fkellermavnet | 14:e846217affcd | 1191 | pe += 1; |
fkellermavnet | 14:e846217affcd | 1192 | pe = pRespStr->find(".", pe); |
fkellermavnet | 14:e846217affcd | 1193 | if (pe == string::npos) |
fkellermavnet | 14:e846217affcd | 1194 | return (false); |
fkellermavnet | 14:e846217affcd | 1195 | else |
fkellermavnet | 14:e846217affcd | 1196 | pe += 1; |
fkellermavnet | 14:e846217affcd | 1197 | pe = pRespStr->find(".", pe); |
fkellermavnet | 14:e846217affcd | 1198 | if (pe == string::npos) |
fkellermavnet | 14:e846217affcd | 1199 | return (false); |
fkellermavnet | 14:e846217affcd | 1200 | else |
fkellermavnet | 14:e846217affcd | 1201 | pe += 1; |
fkellermavnet | 0:affdbb35faa4 | 1202 | pe = pRespStr->find(",", pe); |
fkellermavnet | 14:e846217affcd | 1203 | |
fkellermavnet | 0:affdbb35faa4 | 1204 | ss = pRespStr->substr(ps, pe - ps); |
fkellermavnet | 0:affdbb35faa4 | 1205 | strncpy(s->mask, ss.c_str(), MAX_LEN_IP_STR); |
fkellermavnet | 0:affdbb35faa4 | 1206 | s->mask[MAX_LEN_IP_STR - 1] = '\0'; |
fkellermavnet | 0:affdbb35faa4 | 1207 | ps = pe + 1; |
fkellermavnet | 14:e846217affcd | 1208 | |
fkellermavnet | 14:e846217affcd | 1209 | pe = pRespStr->find(".", pe); |
fkellermavnet | 14:e846217affcd | 1210 | if (pe == string::npos) |
fkellermavnet | 14:e846217affcd | 1211 | return (false); |
fkellermavnet | 14:e846217affcd | 1212 | else |
fkellermavnet | 14:e846217affcd | 1213 | pe += 1; |
fkellermavnet | 14:e846217affcd | 1214 | pe = pRespStr->find(".", pe); |
fkellermavnet | 14:e846217affcd | 1215 | if (pe == string::npos) |
fkellermavnet | 14:e846217affcd | 1216 | return (false); |
fkellermavnet | 14:e846217affcd | 1217 | else |
fkellermavnet | 14:e846217affcd | 1218 | pe += 1; |
fkellermavnet | 14:e846217affcd | 1219 | pe = pRespStr->find(".", pe); |
fkellermavnet | 14:e846217affcd | 1220 | if (pe == string::npos) |
fkellermavnet | 14:e846217affcd | 1221 | return (false); |
fkellermavnet | 14:e846217affcd | 1222 | else |
fkellermavnet | 14:e846217affcd | 1223 | pe += 1; |
fkellermavnet | 0:affdbb35faa4 | 1224 | pe = pRespStr->find(",", pe); |
fkellermavnet | 14:e846217affcd | 1225 | |
fkellermavnet | 0:affdbb35faa4 | 1226 | ss = pRespStr->substr(ps, pe - ps); |
fkellermavnet | 0:affdbb35faa4 | 1227 | strncpy(s->gateway, ss.c_str(), MAX_LEN_IP_STR); |
fkellermavnet | 0:affdbb35faa4 | 1228 | s->gateway[MAX_LEN_IP_STR - 1] = '\0'; |
fkellermavnet | 0:affdbb35faa4 | 1229 | ps = pe + 1; |
fkellermavnet | 14:e846217affcd | 1230 | |
fkellermavnet | 14:e846217affcd | 1231 | pe = pRespStr->find(".", pe); |
fkellermavnet | 14:e846217affcd | 1232 | if (pe == string::npos) |
fkellermavnet | 14:e846217affcd | 1233 | return (false); |
fkellermavnet | 14:e846217affcd | 1234 | else |
fkellermavnet | 14:e846217affcd | 1235 | pe += 1; |
fkellermavnet | 14:e846217affcd | 1236 | pe = pRespStr->find(".", pe); |
fkellermavnet | 14:e846217affcd | 1237 | if (pe == string::npos) |
fkellermavnet | 14:e846217affcd | 1238 | return (false); |
fkellermavnet | 14:e846217affcd | 1239 | else |
fkellermavnet | 14:e846217affcd | 1240 | pe += 1; |
fkellermavnet | 14:e846217affcd | 1241 | pe = pRespStr->find(".", pe); |
fkellermavnet | 14:e846217affcd | 1242 | if (pe == string::npos) |
fkellermavnet | 14:e846217affcd | 1243 | return (false); |
fkellermavnet | 14:e846217affcd | 1244 | else |
fkellermavnet | 14:e846217affcd | 1245 | pe += 1; |
fkellermavnet | 0:affdbb35faa4 | 1246 | pe = pRespStr->find(",", pe); |
fkellermavnet | 14:e846217affcd | 1247 | |
fkellermavnet | 14:e846217affcd | 1248 | |
fkellermavnet | 0:affdbb35faa4 | 1249 | ss = pRespStr->substr(ps, pe - ps); |
fkellermavnet | 0:affdbb35faa4 | 1250 | strncpy(s->dnsPrimary, ss.c_str(), MAX_LEN_IP_STR); |
fkellermavnet | 0:affdbb35faa4 | 1251 | s->dnsPrimary[MAX_LEN_IP_STR - 1] = '\0'; |
fkellermavnet | 0:affdbb35faa4 | 1252 | ps = pe + 1; |
fkellermavnet | 14:e846217affcd | 1253 | |
fkellermavnet | 14:e846217affcd | 1254 | pe = pRespStr->find(".", pe); |
fkellermavnet | 14:e846217affcd | 1255 | if (pe == string::npos) |
fkellermavnet | 14:e846217affcd | 1256 | return (false); |
fkellermavnet | 14:e846217affcd | 1257 | else |
fkellermavnet | 14:e846217affcd | 1258 | pe += 1; |
fkellermavnet | 14:e846217affcd | 1259 | pe = pRespStr->find(".", pe); |
fkellermavnet | 14:e846217affcd | 1260 | if (pe == string::npos) |
fkellermavnet | 14:e846217affcd | 1261 | return (false); |
fkellermavnet | 14:e846217affcd | 1262 | else |
fkellermavnet | 14:e846217affcd | 1263 | pe += 1; |
fkellermavnet | 14:e846217affcd | 1264 | pe = pRespStr->find(".", pe); |
fkellermavnet | 14:e846217affcd | 1265 | if (pe == string::npos) |
fkellermavnet | 14:e846217affcd | 1266 | return (false); |
fkellermavnet | 14:e846217affcd | 1267 | else |
fkellermavnet | 14:e846217affcd | 1268 | pe += 1; |
fkellermavnet | 0:affdbb35faa4 | 1269 | pe = pRespStr->find(",", pe); |
fkellermavnet | 14:e846217affcd | 1270 | |
fkellermavnet | 14:e846217affcd | 1271 | |
fkellermavnet | 0:affdbb35faa4 | 1272 | ss = pRespStr->substr(ps, pe - ps); |
fkellermavnet | 0:affdbb35faa4 | 1273 | strncpy(s->dnsSecondary, ss.c_str(), MAX_LEN_IP_STR); |
fkellermavnet | 0:affdbb35faa4 | 1274 | s->dnsSecondary[MAX_LEN_IP_STR - 1] = '\0'; |
fkellermavnet | 0:affdbb35faa4 | 1275 | |
fkellermavnet | 0:affdbb35faa4 | 1276 | dbgPuts("~~~~~~~~~~ WNC IP Stats ~~~~~~~~~~~~"); |
fkellermavnet | 0:affdbb35faa4 | 1277 | dbgPuts("ip: ", false); dbgPutsNoTime(s->ip); |
fkellermavnet | 0:affdbb35faa4 | 1278 | dbgPuts("mask: ", false); dbgPutsNoTime(s->mask); |
fkellermavnet | 0:affdbb35faa4 | 1279 | dbgPuts("gateway: ", false); dbgPutsNoTime(s->gateway); |
fkellermavnet | 0:affdbb35faa4 | 1280 | dbgPuts("dns pri: ", false); dbgPutsNoTime(s->dnsPrimary); |
fkellermavnet | 0:affdbb35faa4 | 1281 | dbgPuts("dns sec: ", false); dbgPutsNoTime(s->dnsSecondary); |
fkellermavnet | 0:affdbb35faa4 | 1282 | dbgPuts("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); |
fkellermavnet | 0:affdbb35faa4 | 1283 | |
fkellermavnet | 0:affdbb35faa4 | 1284 | return (true); |
fkellermavnet | 0:affdbb35faa4 | 1285 | } |
fkellermavnet | 0:affdbb35faa4 | 1286 | } |
fkellermavnet | 0:affdbb35faa4 | 1287 | } |
fkellermavnet | 0:affdbb35faa4 | 1288 | |
fkellermavnet | 0:affdbb35faa4 | 1289 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1290 | } |
fkellermavnet | 0:affdbb35faa4 | 1291 | |
fkellermavnet | 0:affdbb35faa4 | 1292 | bool WncController::deleteSMSTextFromMem(char msgIdx) |
fkellermavnet | 0:affdbb35faa4 | 1293 | { |
fkellermavnet | 0:affdbb35faa4 | 1294 | const char * err = "deleteSMSTextFromMem: Failed!"; |
fkellermavnet | 0:affdbb35faa4 | 1295 | |
fkellermavnet | 0:affdbb35faa4 | 1296 | switch (msgIdx) |
fkellermavnet | 0:affdbb35faa4 | 1297 | { |
fkellermavnet | 0:affdbb35faa4 | 1298 | case '*': |
fkellermavnet | 0:affdbb35faa4 | 1299 | at_deleteSMSTextFromMem_wnc('1'); |
fkellermavnet | 0:affdbb35faa4 | 1300 | at_deleteSMSTextFromMem_wnc('2'); |
fkellermavnet | 0:affdbb35faa4 | 1301 | at_deleteSMSTextFromMem_wnc('3'); |
fkellermavnet | 0:affdbb35faa4 | 1302 | return (true); // WNC may error if slot empty, just ignore! |
fkellermavnet | 0:affdbb35faa4 | 1303 | |
fkellermavnet | 0:affdbb35faa4 | 1304 | case '1': |
fkellermavnet | 0:affdbb35faa4 | 1305 | case '2': |
fkellermavnet | 0:affdbb35faa4 | 1306 | case '3': |
fkellermavnet | 0:affdbb35faa4 | 1307 | if (true == at_deleteSMSTextFromMem_wnc(msgIdx)) |
fkellermavnet | 0:affdbb35faa4 | 1308 | return (true); |
fkellermavnet | 0:affdbb35faa4 | 1309 | else { |
fkellermavnet | 0:affdbb35faa4 | 1310 | dbgPuts(err); |
fkellermavnet | 0:affdbb35faa4 | 1311 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1312 | } |
fkellermavnet | 0:affdbb35faa4 | 1313 | |
fkellermavnet | 0:affdbb35faa4 | 1314 | default: |
fkellermavnet | 0:affdbb35faa4 | 1315 | dbgPuts(err); |
fkellermavnet | 0:affdbb35faa4 | 1316 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1317 | } |
fkellermavnet | 0:affdbb35faa4 | 1318 | } |
fkellermavnet | 0:affdbb35faa4 | 1319 | |
fkellermavnet | 0:affdbb35faa4 | 1320 | bool WncController::sendSMSTextFromMem(char msgIdx) |
fkellermavnet | 0:affdbb35faa4 | 1321 | { |
fkellermavnet | 0:affdbb35faa4 | 1322 | const char * err = "deleteSMSTextFromMem: Failed!"; |
fkellermavnet | 0:affdbb35faa4 | 1323 | |
fkellermavnet | 0:affdbb35faa4 | 1324 | switch (msgIdx) |
fkellermavnet | 0:affdbb35faa4 | 1325 | { |
fkellermavnet | 0:affdbb35faa4 | 1326 | case '*': |
fkellermavnet | 0:affdbb35faa4 | 1327 | at_sendSMStextMem_wnc('1'); |
fkellermavnet | 0:affdbb35faa4 | 1328 | at_sendSMStextMem_wnc('2'); |
fkellermavnet | 0:affdbb35faa4 | 1329 | at_sendSMStextMem_wnc('3'); |
fkellermavnet | 0:affdbb35faa4 | 1330 | return (true); // WNC may error if slot is empty, just ignore! |
fkellermavnet | 0:affdbb35faa4 | 1331 | |
fkellermavnet | 0:affdbb35faa4 | 1332 | case '1': |
fkellermavnet | 0:affdbb35faa4 | 1333 | case '2': |
fkellermavnet | 0:affdbb35faa4 | 1334 | case '3': |
fkellermavnet | 0:affdbb35faa4 | 1335 | if (at_sendSMStextMem_wnc(msgIdx) == true) |
fkellermavnet | 0:affdbb35faa4 | 1336 | return (true); |
fkellermavnet | 0:affdbb35faa4 | 1337 | else { |
fkellermavnet | 0:affdbb35faa4 | 1338 | dbgPuts(err); |
fkellermavnet | 0:affdbb35faa4 | 1339 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1340 | } |
fkellermavnet | 0:affdbb35faa4 | 1341 | |
fkellermavnet | 0:affdbb35faa4 | 1342 | default: |
fkellermavnet | 0:affdbb35faa4 | 1343 | dbgPuts(err); |
fkellermavnet | 0:affdbb35faa4 | 1344 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1345 | } |
fkellermavnet | 0:affdbb35faa4 | 1346 | } |
fkellermavnet | 0:affdbb35faa4 | 1347 | |
fkellermavnet | 0:affdbb35faa4 | 1348 | bool WncController::at_deleteSMSTextFromMem_wnc(char n) |
fkellermavnet | 0:affdbb35faa4 | 1349 | { |
fkellermavnet | 0:affdbb35faa4 | 1350 | string cmdStr, respStr; |
fkellermavnet | 0:affdbb35faa4 | 1351 | // Message is stored in WNC, now send it! |
fkellermavnet | 0:affdbb35faa4 | 1352 | cmdStr = "AT+CMGD="; |
fkellermavnet | 0:affdbb35faa4 | 1353 | cmdStr += n; |
fkellermavnet | 0:affdbb35faa4 | 1354 | cmdStr += "\r\n"; |
fkellermavnet | 0:affdbb35faa4 | 1355 | dbgPuts("TX: ", false); dbgPutsNoTime(cmdStr.c_str(), false); |
fkellermavnet | 0:affdbb35faa4 | 1356 | AtCmdErr_e r = mdmSendAtCmdRsp(cmdStr.c_str(), m_sCmdTimeoutMs, &respStr); |
fkellermavnet | 0:affdbb35faa4 | 1357 | dbgPuts("RX: ", false); dbgPutsNoTime(respStr.c_str()); |
fkellermavnet | 0:affdbb35faa4 | 1358 | return (r == WNC_AT_CMD_OK); |
fkellermavnet | 0:affdbb35faa4 | 1359 | } |
fkellermavnet | 0:affdbb35faa4 | 1360 | |
fkellermavnet | 0:affdbb35faa4 | 1361 | bool WncController::at_sendSMStextMem_wnc(char n) |
fkellermavnet | 0:affdbb35faa4 | 1362 | { |
fkellermavnet | 0:affdbb35faa4 | 1363 | string cmdStr, respStr; |
fkellermavnet | 0:affdbb35faa4 | 1364 | // Message is stored in WNC, now send it! |
fkellermavnet | 0:affdbb35faa4 | 1365 | cmdStr = "AT+CMSS="; |
fkellermavnet | 0:affdbb35faa4 | 1366 | cmdStr += n; |
fkellermavnet | 0:affdbb35faa4 | 1367 | cmdStr += "\r\n"; |
fkellermavnet | 0:affdbb35faa4 | 1368 | dbgPuts("TX: ", false); dbgPutsNoTime(cmdStr.c_str(), false); |
fkellermavnet | 0:affdbb35faa4 | 1369 | AtCmdErr_e r = mdmSendAtCmdRsp(cmdStr.c_str(), m_sCmdTimeoutMs, &respStr); |
fkellermavnet | 0:affdbb35faa4 | 1370 | dbgPuts("RX: ", false); dbgPutsNoTime(respStr.c_str()); |
fkellermavnet | 0:affdbb35faa4 | 1371 | return (r == WNC_AT_CMD_OK); |
fkellermavnet | 0:affdbb35faa4 | 1372 | } |
fkellermavnet | 0:affdbb35faa4 | 1373 | |
fkellermavnet | 0:affdbb35faa4 | 1374 | bool WncController::at_sendSMStext_wnc(const char * const phoneNum, const char * const text) |
fkellermavnet | 0:affdbb35faa4 | 1375 | { |
fkellermavnet | 0:affdbb35faa4 | 1376 | string respStr; |
fkellermavnet | 0:affdbb35faa4 | 1377 | string * pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1378 | size_t l = strlen(text); |
fkellermavnet | 0:affdbb35faa4 | 1379 | |
fkellermavnet | 18:ca2899c353c2 | 1380 | if (l <= MAX_WNC_SMS_MSG_SLOTS) |
fkellermavnet | 0:affdbb35faa4 | 1381 | { |
fkellermavnet | 0:affdbb35faa4 | 1382 | // Check to see if the SMS service is available |
fkellermavnet | 0:affdbb35faa4 | 1383 | checkCellLink(); |
fkellermavnet | 0:affdbb35faa4 | 1384 | if (m_sReadyForSMS == true) { |
fkellermavnet | 0:affdbb35faa4 | 1385 | at_send_wnc_cmd("AT+CMGF=1", &pRespStr, m_sCmdTimeoutMs); |
fkellermavnet | 0:affdbb35faa4 | 1386 | string cmdStr("AT+CMGS=\""); |
fkellermavnet | 0:affdbb35faa4 | 1387 | cmdStr += phoneNum; |
fkellermavnet | 0:affdbb35faa4 | 1388 | cmdStr += "\""; |
fkellermavnet | 0:affdbb35faa4 | 1389 | dbgPuts("TX: ", false); dbgPutsNoTime(cmdStr.c_str()); |
fkellermavnet | 0:affdbb35faa4 | 1390 | cmdStr += "\x0d"; // x0d = <ENTER> |
fkellermavnet | 0:affdbb35faa4 | 1391 | // Send raw command with short timeout (the timeout will fail cause the WNC is not supposed to reply yet! |
fkellermavnet | 0:affdbb35faa4 | 1392 | // And we want a delay before sending the actual text part of the string! |
fkellermavnet | 0:affdbb35faa4 | 1393 | mdmSendAtCmdRsp(cmdStr.c_str(), 300, &respStr, false); // False turns off auto-addition of CR+LF (the WNC wants nothing here) |
fkellermavnet | 0:affdbb35faa4 | 1394 | dbgPuts("RX: ", false); dbgPutsNoTime(respStr.c_str()); |
fkellermavnet | 0:affdbb35faa4 | 1395 | if ((respStr.size() > 0) && (respStr.find("ERROR") == string::npos)) { |
fkellermavnet | 0:affdbb35faa4 | 1396 | // Part 2 of the text, this is the actual text part: |
fkellermavnet | 0:affdbb35faa4 | 1397 | cmdStr = text; |
fkellermavnet | 11:3ff6c1cb5b03 | 1398 | dbgPuts("TX: ", false); dbgPutsNoTime(cmdStr.c_str()); |
fkellermavnet | 0:affdbb35faa4 | 1399 | cmdStr += "\x1A"; // <CTRL>-Z is what tells the WNC the message is complete to send! |
fkellermavnet | 0:affdbb35faa4 | 1400 | AtCmdErr_e r = mdmSendAtCmdRsp(cmdStr.c_str(), 10000, &respStr); |
fkellermavnet | 11:3ff6c1cb5b03 | 1401 | dbgPuts("RX: ", false); dbgPutsNoTime(respStr.c_str()); |
fkellermavnet | 0:affdbb35faa4 | 1402 | if (respStr.size() == 0) |
fkellermavnet | 0:affdbb35faa4 | 1403 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1404 | else |
fkellermavnet | 0:affdbb35faa4 | 1405 | return (r == WNC_AT_CMD_OK); |
fkellermavnet | 0:affdbb35faa4 | 1406 | } |
fkellermavnet | 0:affdbb35faa4 | 1407 | } |
fkellermavnet | 0:affdbb35faa4 | 1408 | } |
fkellermavnet | 0:affdbb35faa4 | 1409 | |
fkellermavnet | 0:affdbb35faa4 | 1410 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1411 | } |
fkellermavnet | 0:affdbb35faa4 | 1412 | |
fkellermavnet | 0:affdbb35faa4 | 1413 | bool WncController::saveSMSText(const char * const phoneNum, const char * const text, char * msgIdx) |
fkellermavnet | 0:affdbb35faa4 | 1414 | { |
fkellermavnet | 0:affdbb35faa4 | 1415 | if (at_saveSMStext_wnc(phoneNum, text, msgIdx) == true) |
fkellermavnet | 0:affdbb35faa4 | 1416 | return (true); |
fkellermavnet | 0:affdbb35faa4 | 1417 | else { |
fkellermavnet | 0:affdbb35faa4 | 1418 | dbgPuts("saveSMSTextToMem: failed!\r\n"); |
fkellermavnet | 0:affdbb35faa4 | 1419 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1420 | } |
fkellermavnet | 0:affdbb35faa4 | 1421 | } |
fkellermavnet | 0:affdbb35faa4 | 1422 | |
fkellermavnet | 0:affdbb35faa4 | 1423 | bool WncController::at_saveSMStext_wnc(const char * const phoneNum, const char * const text, char * msgIdx) |
fkellermavnet | 0:affdbb35faa4 | 1424 | { |
fkellermavnet | 0:affdbb35faa4 | 1425 | string respStr; |
fkellermavnet | 0:affdbb35faa4 | 1426 | size_t l = strlen(text); |
fkellermavnet | 0:affdbb35faa4 | 1427 | |
fkellermavnet | 0:affdbb35faa4 | 1428 | if (l <= MAX_WNC_SMS_LENGTH) |
fkellermavnet | 0:affdbb35faa4 | 1429 | { |
fkellermavnet | 0:affdbb35faa4 | 1430 | // Check to see if the SMS service is available |
fkellermavnet | 0:affdbb35faa4 | 1431 | checkCellLink(); |
fkellermavnet | 0:affdbb35faa4 | 1432 | if (m_sReadyForSMS == true) { |
fkellermavnet | 0:affdbb35faa4 | 1433 | string cmdStr("AT+CMGW=\""); |
fkellermavnet | 0:affdbb35faa4 | 1434 | cmdStr += phoneNum; |
fkellermavnet | 0:affdbb35faa4 | 1435 | cmdStr += "\""; |
fkellermavnet | 0:affdbb35faa4 | 1436 | dbgPuts("TX: ", false); dbgPutsNoTime(cmdStr.c_str()); |
fkellermavnet | 0:affdbb35faa4 | 1437 | cmdStr += "\x0d"; // x0d = <ENTER> |
fkellermavnet | 0:affdbb35faa4 | 1438 | // Send raw command with short timeout (the timeout will fail cause the WNC is not supposed to reply yet! |
fkellermavnet | 0:affdbb35faa4 | 1439 | // And we want a delay before sending the actual text part of the string! |
fkellermavnet | 0:affdbb35faa4 | 1440 | mdmSendAtCmdRsp(cmdStr.c_str(), 300, &respStr, false); // False turns off auto-addition of CR+LF (the WNC wants nothing here) |
fkellermavnet | 0:affdbb35faa4 | 1441 | dbgPuts("RX: ", false); dbgPutsNoTime(respStr.c_str()); |
fkellermavnet | 0:affdbb35faa4 | 1442 | if ((respStr.size() > 0) && (respStr.find("ERROR") == string::npos)) { |
fkellermavnet | 0:affdbb35faa4 | 1443 | // Part 2 of the text, this is the actual text part: |
fkellermavnet | 0:affdbb35faa4 | 1444 | cmdStr = text; |
fkellermavnet | 0:affdbb35faa4 | 1445 | dbgPuts("TX: ", false); dbgPutsNoTime(cmdStr.c_str()); |
fkellermavnet | 0:affdbb35faa4 | 1446 | cmdStr += "\x1A"; // <CTRL>-Z is what tells the WNC the message is complete to save! |
fkellermavnet | 0:affdbb35faa4 | 1447 | AtCmdErr_e r = mdmSendAtCmdRsp(cmdStr.c_str(), 10000, &respStr); |
fkellermavnet | 0:affdbb35faa4 | 1448 | dbgPuts("RX: ", false); dbgPutsNoTime(respStr.c_str()); |
fkellermavnet | 0:affdbb35faa4 | 1449 | if (respStr.size() > 0) { |
fkellermavnet | 0:affdbb35faa4 | 1450 | // respStr will have the SMS index |
fkellermavnet | 0:affdbb35faa4 | 1451 | size_t pos1 = respStr.find("+CMGW: "); |
fkellermavnet | 0:affdbb35faa4 | 1452 | size_t pos2 = respStr.rfind("OK"); |
fkellermavnet | 0:affdbb35faa4 | 1453 | if (pos1 != string::npos && pos2 != string::npos) { |
fkellermavnet | 0:affdbb35faa4 | 1454 | *msgIdx = *string(respStr.substr(pos1+7, 1)).c_str(); |
fkellermavnet | 0:affdbb35faa4 | 1455 | return (true); |
fkellermavnet | 0:affdbb35faa4 | 1456 | } |
fkellermavnet | 0:affdbb35faa4 | 1457 | else { |
fkellermavnet | 0:affdbb35faa4 | 1458 | *msgIdx = '!'; |
fkellermavnet | 0:affdbb35faa4 | 1459 | } |
fkellermavnet | 0:affdbb35faa4 | 1460 | } |
fkellermavnet | 0:affdbb35faa4 | 1461 | } |
fkellermavnet | 0:affdbb35faa4 | 1462 | } |
fkellermavnet | 0:affdbb35faa4 | 1463 | } |
fkellermavnet | 0:affdbb35faa4 | 1464 | |
fkellermavnet | 0:affdbb35faa4 | 1465 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1466 | } |
fkellermavnet | 0:affdbb35faa4 | 1467 | |
fkellermavnet | 18:ca2899c353c2 | 1468 | bool WncController::at_readSMSlog_wnc(string ** log) |
fkellermavnet | 0:affdbb35faa4 | 1469 | { |
fkellermavnet | 18:ca2899c353c2 | 1470 | return (at_send_wnc_cmd("AT+CMGL", log, m_sCmdTimeoutMs) == WNC_AT_CMD_OK); |
fkellermavnet | 0:affdbb35faa4 | 1471 | } |
fkellermavnet | 0:affdbb35faa4 | 1472 | |
fkellermavnet | 6:a656e820d7ff | 1473 | size_t WncController::at_readSMStext_wnc(const char n, const char ** log) |
fkellermavnet | 0:affdbb35faa4 | 1474 | { |
fkellermavnet | 6:a656e820d7ff | 1475 | static string smsReadTxtStr; |
fkellermavnet | 0:affdbb35faa4 | 1476 | string * pRespStr; |
fkellermavnet | 6:a656e820d7ff | 1477 | string cmdStr; |
fkellermavnet | 6:a656e820d7ff | 1478 | |
fkellermavnet | 6:a656e820d7ff | 1479 | smsReadTxtStr.erase(); |
fkellermavnet | 6:a656e820d7ff | 1480 | cmdStr = "AT+CMGR"; |
fkellermavnet | 6:a656e820d7ff | 1481 | cmdStr += '1'; |
fkellermavnet | 0:affdbb35faa4 | 1482 | if (at_send_wnc_cmd("AT+CMGR", &pRespStr, m_sCmdTimeoutMs) == WNC_AT_CMD_OK) |
fkellermavnet | 0:affdbb35faa4 | 1483 | *log = pRespStr->c_str(); |
fkellermavnet | 0:affdbb35faa4 | 1484 | else |
fkellermavnet | 0:affdbb35faa4 | 1485 | *log = "\0"; |
fkellermavnet | 0:affdbb35faa4 | 1486 | |
fkellermavnet | 0:affdbb35faa4 | 1487 | return (pRespStr->size()); |
fkellermavnet | 0:affdbb35faa4 | 1488 | } |
fkellermavnet | 0:affdbb35faa4 | 1489 | |
fkellermavnet | 0:affdbb35faa4 | 1490 | bool WncController::at_at_wnc(void) |
fkellermavnet | 0:affdbb35faa4 | 1491 | { |
fkellermavnet | 0:affdbb35faa4 | 1492 | string * pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1493 | return (WNC_AT_CMD_OK == at_send_wnc_cmd("AT", &pRespStr, WNC_QUICK_CMD_TIMEOUT_MS)); // Heartbeat? |
fkellermavnet | 0:affdbb35faa4 | 1494 | } |
fkellermavnet | 0:affdbb35faa4 | 1495 | |
fkellermavnet | 0:affdbb35faa4 | 1496 | bool WncController::at_init_wnc(bool hardReset) |
fkellermavnet | 0:affdbb35faa4 | 1497 | { |
fkellermavnet | 0:affdbb35faa4 | 1498 | string * pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1499 | AtCmdErr_e cmdRes; |
fkellermavnet | 0:affdbb35faa4 | 1500 | |
fkellermavnet | 0:affdbb35faa4 | 1501 | if (hardReset == true) |
fkellermavnet | 0:affdbb35faa4 | 1502 | dbgPuts("Hard Soft Reset!"); |
fkellermavnet | 0:affdbb35faa4 | 1503 | |
fkellermavnet | 0:affdbb35faa4 | 1504 | dbgPuts("Start AT init of WNC:"); |
fkellermavnet | 0:affdbb35faa4 | 1505 | |
fkellermavnet | 0:affdbb35faa4 | 1506 | // Kick it twice to perhaps remove cued responses from an incomplete |
fkellermavnet | 0:affdbb35faa4 | 1507 | // power cycle. |
fkellermavnet | 0:affdbb35faa4 | 1508 | at_send_wnc_cmd("AT", &pRespStr, WNC_QUICK_CMD_TIMEOUT_MS); |
fkellermavnet | 0:affdbb35faa4 | 1509 | at_send_wnc_cmd("AT", &pRespStr, WNC_QUICK_CMD_TIMEOUT_MS); |
fkellermavnet | 0:affdbb35faa4 | 1510 | |
fkellermavnet | 0:affdbb35faa4 | 1511 | // Quick commands below do not need to check cellular connectivity |
fkellermavnet | 0:affdbb35faa4 | 1512 | at_send_wnc_cmd("ATE0", &pRespStr, WNC_QUICK_CMD_TIMEOUT_MS); // Echo Off |
fkellermavnet | 0:affdbb35faa4 | 1513 | at_send_wnc_cmd("AT+CMEE=2", &pRespStr, m_sCmdTimeoutMs); // 2 - verbose error, 1 - numeric error, 0 - just ERROR |
fkellermavnet | 6:a656e820d7ff | 1514 | |
fkellermavnet | 6:a656e820d7ff | 1515 | // Setup 3 memory slots in the WNC SIM for SMS usage. |
fkellermavnet | 6:a656e820d7ff | 1516 | at_send_wnc_cmd("AT+CMGF=1", &pRespStr, m_sCmdTimeoutMs); |
fkellermavnet | 6:a656e820d7ff | 1517 | at_send_wnc_cmd("AT+CPMS=\"SM\",\"SM\",\"SM\"", &pRespStr, m_sCmdTimeoutMs); |
fkellermavnet | 6:a656e820d7ff | 1518 | |
fkellermavnet | 0:affdbb35faa4 | 1519 | cmdRes = at_send_wnc_cmd("AT", &pRespStr, WNC_QUICK_CMD_TIMEOUT_MS); // Heartbeat? |
fkellermavnet | 0:affdbb35faa4 | 1520 | |
fkellermavnet | 0:affdbb35faa4 | 1521 | // If the simple commands are not working, no chance of more complex. |
fkellermavnet | 0:affdbb35faa4 | 1522 | // I have seen re-trying commands make it worse. |
fkellermavnet | 0:affdbb35faa4 | 1523 | if (cmdRes != WNC_AT_CMD_OK) |
fkellermavnet | 0:affdbb35faa4 | 1524 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1525 | |
fkellermavnet | 0:affdbb35faa4 | 1526 | cmdRes = at_send_wnc_cmd("AT@INTERNET=1", &pRespStr, m_sCmdTimeoutMs); |
fkellermavnet | 0:affdbb35faa4 | 1527 | if (cmdRes != WNC_AT_CMD_OK) |
fkellermavnet | 0:affdbb35faa4 | 1528 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1529 | |
fkellermavnet | 0:affdbb35faa4 | 1530 | cmdRes = at_send_wnc_cmd("AT@SOCKDIAL=1", &pRespStr, m_sCmdTimeoutMs); |
fkellermavnet | 0:affdbb35faa4 | 1531 | if (cmdRes != WNC_AT_CMD_OK) |
fkellermavnet | 0:affdbb35faa4 | 1532 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1533 | |
fkellermavnet | 0:affdbb35faa4 | 1534 | dbgPuts("SUCCESS: AT init of WNC!"); |
fkellermavnet | 0:affdbb35faa4 | 1535 | |
fkellermavnet | 0:affdbb35faa4 | 1536 | return (true); |
fkellermavnet | 0:affdbb35faa4 | 1537 | } |
fkellermavnet | 0:affdbb35faa4 | 1538 | |
fkellermavnet | 0:affdbb35faa4 | 1539 | |
fkellermavnet | 10:2ec59906a24e | 1540 | int16_t WncController::at_sockopen_wnc(const char * const ip, uint16_t port, uint16_t numSock, bool tcp, uint16_t timeOutSec) |
fkellermavnet | 0:affdbb35faa4 | 1541 | { |
fkellermavnet | 0:affdbb35faa4 | 1542 | string * pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1543 | string cmd_str("AT@SOCKCREAT="); |
fkellermavnet | 0:affdbb35faa4 | 1544 | AtCmdErr_e res; |
fkellermavnet | 0:affdbb35faa4 | 1545 | |
fkellermavnet | 0:affdbb35faa4 | 1546 | if (tcp) cmd_str += "1"; // TCP |
fkellermavnet | 0:affdbb35faa4 | 1547 | else cmd_str += "2"; // else UDP |
fkellermavnet | 0:affdbb35faa4 | 1548 | |
fkellermavnet | 0:affdbb35faa4 | 1549 | cmd_str += ",0"; |
fkellermavnet | 0:affdbb35faa4 | 1550 | res = sendWncCmd(cmd_str.c_str(), &pRespStr, m_sCmdTimeoutMs); |
fkellermavnet | 14:e846217affcd | 1551 | if (res == WNC_AT_CMD_OK && pRespStr->size() > 0) |
fkellermavnet | 0:affdbb35faa4 | 1552 | { |
fkellermavnet | 10:2ec59906a24e | 1553 | size_t pos1 = pRespStr->find("T:"); |
fkellermavnet | 10:2ec59906a24e | 1554 | size_t pos2 = pRespStr->rfind("OK"); |
fkellermavnet | 10:2ec59906a24e | 1555 | if ((pos1 != string::npos) && (pos2 != string::npos)) { |
fkellermavnet | 10:2ec59906a24e | 1556 | size_t numLen = pos2 - (pos1 + 2); |
fkellermavnet | 10:2ec59906a24e | 1557 | string sockStr = pRespStr->substr(pos1 + 2, numLen); |
fkellermavnet | 10:2ec59906a24e | 1558 | cmd_str = "AT@SOCKCONN="; |
fkellermavnet | 10:2ec59906a24e | 1559 | cmd_str += sockStr; |
fkellermavnet | 10:2ec59906a24e | 1560 | cmd_str += ",\""; |
fkellermavnet | 10:2ec59906a24e | 1561 | cmd_str += ip; |
fkellermavnet | 10:2ec59906a24e | 1562 | cmd_str += "\","; |
fkellermavnet | 10:2ec59906a24e | 1563 | cmd_str += _to_string(port); |
fkellermavnet | 10:2ec59906a24e | 1564 | cmd_str += ","; |
fkellermavnet | 10:2ec59906a24e | 1565 | if (timeOutSec < 30) |
fkellermavnet | 10:2ec59906a24e | 1566 | timeOutSec = 30; |
fkellermavnet | 10:2ec59906a24e | 1567 | else if (timeOutSec > 360) |
fkellermavnet | 10:2ec59906a24e | 1568 | timeOutSec = 360; |
fkellermavnet | 10:2ec59906a24e | 1569 | cmd_str += _to_string(timeOutSec); |
fkellermavnet | 10:2ec59906a24e | 1570 | res = sendWncCmd(cmd_str.c_str(), &pRespStr, 1000 * timeOutSec + 1000); |
fkellermavnet | 10:2ec59906a24e | 1571 | if (m_sMoreDebugEnabled) { |
fkellermavnet | 10:2ec59906a24e | 1572 | at_send_wnc_cmd("AT@SOCKCREAT?", &pRespStr, m_sCmdTimeoutMs); |
fkellermavnet | 10:2ec59906a24e | 1573 | at_send_wnc_cmd("AT@SOCKCONN?", &pRespStr, m_sCmdTimeoutMs); |
fkellermavnet | 10:2ec59906a24e | 1574 | } |
fkellermavnet | 10:2ec59906a24e | 1575 | return (strtol(sockStr.c_str(), NULL, 10)); |
fkellermavnet | 0:affdbb35faa4 | 1576 | } |
fkellermavnet | 10:2ec59906a24e | 1577 | else { |
fkellermavnet | 10:2ec59906a24e | 1578 | dbgPuts("Invalid sockcreat response!"); |
fkellermavnet | 10:2ec59906a24e | 1579 | return (0); |
fkellermavnet | 10:2ec59906a24e | 1580 | } |
fkellermavnet | 0:affdbb35faa4 | 1581 | } |
fkellermavnet | 0:affdbb35faa4 | 1582 | else |
fkellermavnet | 10:2ec59906a24e | 1583 | return (0); |
fkellermavnet | 0:affdbb35faa4 | 1584 | } |
fkellermavnet | 0:affdbb35faa4 | 1585 | |
fkellermavnet | 0:affdbb35faa4 | 1586 | bool WncController::at_sockclose_wnc(uint16_t numSock) |
fkellermavnet | 0:affdbb35faa4 | 1587 | { |
fkellermavnet | 0:affdbb35faa4 | 1588 | string * pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1589 | string cmd_str("AT@SOCKCLOSE="); |
fkellermavnet | 0:affdbb35faa4 | 1590 | |
fkellermavnet | 10:2ec59906a24e | 1591 | cmd_str += _to_string(numSock); |
fkellermavnet | 0:affdbb35faa4 | 1592 | // Don't check the cell status to close the socket |
fkellermavnet | 0:affdbb35faa4 | 1593 | return (WNC_AT_CMD_OK == at_send_wnc_cmd(cmd_str.c_str(), &pRespStr, m_sCmdTimeoutMs)); |
fkellermavnet | 0:affdbb35faa4 | 1594 | } |
fkellermavnet | 0:affdbb35faa4 | 1595 | |
fkellermavnet | 0:affdbb35faa4 | 1596 | bool WncController::at_dnsresolve_wnc(const char * s, string * ipStr) |
fkellermavnet | 0:affdbb35faa4 | 1597 | { |
fkellermavnet | 0:affdbb35faa4 | 1598 | string * pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1599 | string str(s); |
fkellermavnet | 14:e846217affcd | 1600 | AtCmdErr_e r; |
fkellermavnet | 0:affdbb35faa4 | 1601 | |
fkellermavnet | 0:affdbb35faa4 | 1602 | ipStr->erase(); // Clear out string until resolved! |
fkellermavnet | 0:affdbb35faa4 | 1603 | str = "AT@DNSRESVDON=\"" + str; |
fkellermavnet | 0:affdbb35faa4 | 1604 | str += "\""; |
fkellermavnet | 14:e846217affcd | 1605 | r = sendWncCmd(str.c_str(), &pRespStr, WNC_DNS_RESOLVE_WAIT_MS); |
fkellermavnet | 14:e846217affcd | 1606 | if (r == WNC_AT_CMD_OK && pRespStr->size() > 0) { |
fkellermavnet | 0:affdbb35faa4 | 1607 | size_t pos_start = pRespStr->find(":\"") + 2; |
fkellermavnet | 0:affdbb35faa4 | 1608 | if (pos_start != string::npos) { |
fkellermavnet | 0:affdbb35faa4 | 1609 | size_t pos_end = pRespStr->find("\"", pos_start) - 1; |
fkellermavnet | 0:affdbb35faa4 | 1610 | if (pos_end != string::npos) { |
fkellermavnet | 0:affdbb35faa4 | 1611 | if (pos_end > pos_start) { |
fkellermavnet | 0:affdbb35faa4 | 1612 | // Make a copy for use later (the source string is re-used) |
fkellermavnet | 0:affdbb35faa4 | 1613 | *ipStr = pRespStr->substr(pos_start, pos_end - pos_start + 1); |
fkellermavnet | 0:affdbb35faa4 | 1614 | return (true); |
fkellermavnet | 0:affdbb35faa4 | 1615 | } |
fkellermavnet | 0:affdbb35faa4 | 1616 | } |
fkellermavnet | 0:affdbb35faa4 | 1617 | } |
fkellermavnet | 0:affdbb35faa4 | 1618 | } |
fkellermavnet | 0:affdbb35faa4 | 1619 | |
fkellermavnet | 0:affdbb35faa4 | 1620 | *ipStr = INVALID_IP_STR; |
fkellermavnet | 0:affdbb35faa4 | 1621 | |
fkellermavnet | 0:affdbb35faa4 | 1622 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1623 | } |
fkellermavnet | 0:affdbb35faa4 | 1624 | |
fkellermavnet | 0:affdbb35faa4 | 1625 | bool WncController::waitForPowerOnModemToRespond(uint8_t timeoutSecs) |
fkellermavnet | 0:affdbb35faa4 | 1626 | { |
fkellermavnet | 0:affdbb35faa4 | 1627 | // Now, give the modem x seconds to start responding by |
fkellermavnet | 0:affdbb35faa4 | 1628 | // sending simple 'AT' commands to modem once per second. |
fkellermavnet | 0:affdbb35faa4 | 1629 | if (timeoutSecs > 0) { |
fkellermavnet | 0:affdbb35faa4 | 1630 | do { |
fkellermavnet | 0:affdbb35faa4 | 1631 | timeoutSecs--; |
fkellermavnet | 1:ac2de545b981 | 1632 | dbgPutsNoTime("\rWaiting ", false); dbgPutsNoTime(_to_string(timeoutSecs), false); |
fkellermavnet | 1:ac2de545b981 | 1633 | dbgPutsNoTime(" ", false); |
fkellermavnet | 0:affdbb35faa4 | 1634 | AtCmdErr_e rc = mdmSendAtCmdRsp("AT", 500, &m_sWncStr); |
fkellermavnet | 0:affdbb35faa4 | 1635 | if (rc == WNC_AT_CMD_OK) { |
fkellermavnet | 0:affdbb35faa4 | 1636 | dbgPutsNoTime(""); // CR LF |
fkellermavnet | 0:affdbb35faa4 | 1637 | return true; //timer.read(); |
fkellermavnet | 0:affdbb35faa4 | 1638 | } |
fkellermavnet | 0:affdbb35faa4 | 1639 | waitMs(500); |
fkellermavnet | 0:affdbb35faa4 | 1640 | } |
fkellermavnet | 0:affdbb35faa4 | 1641 | while (timeoutSecs > 0); |
fkellermavnet | 1:ac2de545b981 | 1642 | dbgPutsNoTime(""); // CR LF |
fkellermavnet | 0:affdbb35faa4 | 1643 | } |
fkellermavnet | 0:affdbb35faa4 | 1644 | |
fkellermavnet | 0:affdbb35faa4 | 1645 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1646 | } |
fkellermavnet | 0:affdbb35faa4 | 1647 | |
fkellermavnet | 13:73629a6e9122 | 1648 | WncController::AtCmdErr_e WncController::at_sockwrite_wnc(const char * s, uint16_t n, uint16_t numSock, bool isTcp) |
fkellermavnet | 0:affdbb35faa4 | 1649 | { |
fkellermavnet | 0:affdbb35faa4 | 1650 | AtCmdErr_e result; |
fkellermavnet | 0:affdbb35faa4 | 1651 | |
fkellermavnet | 0:affdbb35faa4 | 1652 | if ((n > 0) && (n <= MAX_WNC_WRITE_BYTES)) { |
fkellermavnet | 0:affdbb35faa4 | 1653 | string * pRespStr; |
fkellermavnet | 1:ac2de545b981 | 1654 | const char * num2str; |
fkellermavnet | 0:affdbb35faa4 | 1655 | string cmd_str; |
fkellermavnet | 0:affdbb35faa4 | 1656 | |
fkellermavnet | 0:affdbb35faa4 | 1657 | if (isTcp == true) |
fkellermavnet | 0:affdbb35faa4 | 1658 | cmd_str="AT@SOCKWRITE="; |
fkellermavnet | 0:affdbb35faa4 | 1659 | else |
fkellermavnet | 0:affdbb35faa4 | 1660 | cmd_str="AT@SOCKWRITE="; // "AT@SOCKSEND="; |
fkellermavnet | 0:affdbb35faa4 | 1661 | |
fkellermavnet | 10:2ec59906a24e | 1662 | cmd_str += _to_string(numSock); |
fkellermavnet | 0:affdbb35faa4 | 1663 | cmd_str += ","; |
fkellermavnet | 1:ac2de545b981 | 1664 | cmd_str += _to_string(n); |
fkellermavnet | 0:affdbb35faa4 | 1665 | cmd_str += ",\""; |
fkellermavnet | 6:a656e820d7ff | 1666 | while(n > 0) { |
fkellermavnet | 6:a656e820d7ff | 1667 | n--; |
fkellermavnet | 1:ac2de545b981 | 1668 | num2str = _to_hex_string((uint8_t)*s++); |
fkellermavnet | 0:affdbb35faa4 | 1669 | // Always 2-digit ascii hex: |
fkellermavnet | 13:73629a6e9122 | 1670 | if (num2str[1] == '\0') |
fkellermavnet | 1:ac2de545b981 | 1671 | cmd_str += '0'; |
fkellermavnet | 0:affdbb35faa4 | 1672 | cmd_str += num2str; |
fkellermavnet | 0:affdbb35faa4 | 1673 | } |
fkellermavnet | 0:affdbb35faa4 | 1674 | cmd_str += "\""; |
fkellermavnet | 0:affdbb35faa4 | 1675 | result = sendWncCmd(cmd_str.c_str(), &pRespStr, m_sCmdTimeoutMs); |
fkellermavnet | 0:affdbb35faa4 | 1676 | } |
fkellermavnet | 0:affdbb35faa4 | 1677 | else { |
fkellermavnet | 0:affdbb35faa4 | 1678 | dbgPuts("sockwrite Err, string len bad!"); |
fkellermavnet | 0:affdbb35faa4 | 1679 | result = WNC_AT_CMD_ERR; |
fkellermavnet | 0:affdbb35faa4 | 1680 | } |
fkellermavnet | 0:affdbb35faa4 | 1681 | |
fkellermavnet | 0:affdbb35faa4 | 1682 | return (result); |
fkellermavnet | 0:affdbb35faa4 | 1683 | } |
fkellermavnet | 0:affdbb35faa4 | 1684 | |
fkellermavnet | 4:c5720f4d13ff | 1685 | WncController::AtCmdErr_e WncController::at_sockread_wnc(string * pS, uint16_t numSock, bool isTcp) |
fkellermavnet | 4:c5720f4d13ff | 1686 | { |
fkellermavnet | 4:c5720f4d13ff | 1687 | AtCmdErr_e result = WNC_AT_CMD_OK; |
fkellermavnet | 4:c5720f4d13ff | 1688 | |
fkellermavnet | 4:c5720f4d13ff | 1689 | string * pRespStr; |
fkellermavnet | 4:c5720f4d13ff | 1690 | string cmd_str; |
fkellermavnet | 4:c5720f4d13ff | 1691 | size_t pos_start, pos_end; |
fkellermavnet | 4:c5720f4d13ff | 1692 | int i; |
fkellermavnet | 5:20207cc5502e | 1693 | |
fkellermavnet | 5:20207cc5502e | 1694 | pS->erase(); // Start with a fresh string |
fkellermavnet | 4:c5720f4d13ff | 1695 | |
fkellermavnet | 4:c5720f4d13ff | 1696 | if (isTcp == true) |
fkellermavnet | 4:c5720f4d13ff | 1697 | cmd_str="AT@SOCKREAD="; |
fkellermavnet | 4:c5720f4d13ff | 1698 | else |
fkellermavnet | 4:c5720f4d13ff | 1699 | cmd_str="AT@SOCKREAD="; // "AT@SOCKRECV="; |
fkellermavnet | 4:c5720f4d13ff | 1700 | |
fkellermavnet | 10:2ec59906a24e | 1701 | cmd_str += _to_string(numSock); |
fkellermavnet | 4:c5720f4d13ff | 1702 | cmd_str += ","; |
fkellermavnet | 4:c5720f4d13ff | 1703 | cmd_str += _to_string(MAX_WNC_READ_BYTES); |
fkellermavnet | 4:c5720f4d13ff | 1704 | |
fkellermavnet | 4:c5720f4d13ff | 1705 | // Experimental: read should not need to check cell net status |
fkellermavnet | 4:c5720f4d13ff | 1706 | result = at_send_wnc_cmd(cmd_str.c_str(), &pRespStr, m_sCmdTimeoutMs); |
fkellermavnet | 4:c5720f4d13ff | 1707 | if (result == WNC_AT_CMD_OK) { |
fkellermavnet | 14:e846217affcd | 1708 | if (pRespStr->size() > 0) { |
fkellermavnet | 14:e846217affcd | 1709 | pos_start = pRespStr->find("\""); |
fkellermavnet | 14:e846217affcd | 1710 | pos_end = pRespStr->rfind("\""); |
fkellermavnet | 14:e846217affcd | 1711 | // Make sure search finds what it's looking for! |
fkellermavnet | 14:e846217affcd | 1712 | if (pos_start != string::npos && pos_end != string::npos) { |
fkellermavnet | 14:e846217affcd | 1713 | pos_start++; |
fkellermavnet | 14:e846217affcd | 1714 | i = pos_end - pos_start; // Num hex chars, 2 per byte |
fkellermavnet | 14:e846217affcd | 1715 | } |
fkellermavnet | 14:e846217affcd | 1716 | else |
fkellermavnet | 14:e846217affcd | 1717 | i = 0; |
fkellermavnet | 12:33290e9e6e5f | 1718 | } |
fkellermavnet | 4:c5720f4d13ff | 1719 | else |
fkellermavnet | 4:c5720f4d13ff | 1720 | i = 0; |
fkellermavnet | 4:c5720f4d13ff | 1721 | |
fkellermavnet | 12:33290e9e6e5f | 1722 | if ((i < 0) || ((i % 2) == 1)) |
fkellermavnet | 4:c5720f4d13ff | 1723 | dbgPuts("Invalid READ string!"); |
fkellermavnet | 12:33290e9e6e5f | 1724 | |
fkellermavnet | 12:33290e9e6e5f | 1725 | if (i > 2*MAX_WNC_READ_BYTES) { |
fkellermavnet | 4:c5720f4d13ff | 1726 | i = 2*MAX_WNC_READ_BYTES; |
fkellermavnet | 12:33290e9e6e5f | 1727 | dbgPuts("DANGER WNC read data does not match length!"); |
fkellermavnet | 4:c5720f4d13ff | 1728 | } |
fkellermavnet | 4:c5720f4d13ff | 1729 | |
fkellermavnet | 4:c5720f4d13ff | 1730 | // If data, convert the hex string into byte values |
fkellermavnet | 12:33290e9e6e5f | 1731 | while (i > 0) { |
fkellermavnet | 12:33290e9e6e5f | 1732 | i -= 2; |
fkellermavnet | 12:33290e9e6e5f | 1733 | *pS += (uint8_t)strtol(pRespStr->substr(pos_start, 2).c_str(), NULL, 16); |
fkellermavnet | 12:33290e9e6e5f | 1734 | pos_start += 2; |
fkellermavnet | 4:c5720f4d13ff | 1735 | } |
fkellermavnet | 4:c5720f4d13ff | 1736 | } |
fkellermavnet | 4:c5720f4d13ff | 1737 | |
fkellermavnet | 4:c5720f4d13ff | 1738 | return (result); |
fkellermavnet | 4:c5720f4d13ff | 1739 | } |
fkellermavnet | 4:c5720f4d13ff | 1740 | |
fkellermavnet | 12:33290e9e6e5f | 1741 | WncController::AtCmdErr_e WncController::at_sockread_wnc(uint8_t * pS, uint16_t * numRead, uint16_t n, uint16_t numSock, bool isTcp) |
fkellermavnet | 0:affdbb35faa4 | 1742 | { |
fkellermavnet | 0:affdbb35faa4 | 1743 | AtCmdErr_e result = WNC_AT_CMD_OK; |
fkellermavnet | 0:affdbb35faa4 | 1744 | *numRead = 0; |
fkellermavnet | 0:affdbb35faa4 | 1745 | |
fkellermavnet | 0:affdbb35faa4 | 1746 | if ((n > 0) && (n <= MAX_WNC_READ_BYTES)) { |
fkellermavnet | 0:affdbb35faa4 | 1747 | string * pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1748 | string cmd_str; |
fkellermavnet | 0:affdbb35faa4 | 1749 | size_t pos_start, pos_end; |
fkellermavnet | 0:affdbb35faa4 | 1750 | int i; |
fkellermavnet | 0:affdbb35faa4 | 1751 | |
fkellermavnet | 0:affdbb35faa4 | 1752 | if (isTcp == true) |
fkellermavnet | 0:affdbb35faa4 | 1753 | cmd_str="AT@SOCKREAD="; |
fkellermavnet | 0:affdbb35faa4 | 1754 | else |
fkellermavnet | 0:affdbb35faa4 | 1755 | cmd_str="AT@SOCKREAD="; // "AT@SOCKRECV="; |
fkellermavnet | 0:affdbb35faa4 | 1756 | |
fkellermavnet | 10:2ec59906a24e | 1757 | cmd_str += _to_string(numSock); |
fkellermavnet | 0:affdbb35faa4 | 1758 | cmd_str += ","; |
fkellermavnet | 0:affdbb35faa4 | 1759 | cmd_str += _to_string(n); |
fkellermavnet | 0:affdbb35faa4 | 1760 | |
fkellermavnet | 0:affdbb35faa4 | 1761 | // Experimental: read should not need to check cell net status |
fkellermavnet | 0:affdbb35faa4 | 1762 | result = at_send_wnc_cmd(cmd_str.c_str(), &pRespStr, m_sCmdTimeoutMs); |
fkellermavnet | 0:affdbb35faa4 | 1763 | if (result == WNC_AT_CMD_OK) { |
fkellermavnet | 14:e846217affcd | 1764 | if (pRespStr->size() > 0) { |
fkellermavnet | 14:e846217affcd | 1765 | pos_start = pRespStr->find("\""); |
fkellermavnet | 14:e846217affcd | 1766 | pos_end = pRespStr->rfind("\""); |
fkellermavnet | 14:e846217affcd | 1767 | // Make sure search finds what it's looking for! |
fkellermavnet | 14:e846217affcd | 1768 | if (pos_start != string::npos && pos_end != string::npos) { |
fkellermavnet | 14:e846217affcd | 1769 | pos_start++; |
fkellermavnet | 14:e846217affcd | 1770 | i = pos_end - pos_start; // Num hex chars, 2 per byte |
fkellermavnet | 14:e846217affcd | 1771 | } |
fkellermavnet | 14:e846217affcd | 1772 | else |
fkellermavnet | 14:e846217affcd | 1773 | i = 0; |
fkellermavnet | 12:33290e9e6e5f | 1774 | } |
fkellermavnet | 0:affdbb35faa4 | 1775 | else |
fkellermavnet | 0:affdbb35faa4 | 1776 | i = 0; |
fkellermavnet | 10:2ec59906a24e | 1777 | |
fkellermavnet | 12:33290e9e6e5f | 1778 | if ((i < 0) || ((i % 2) == 1)) |
fkellermavnet | 4:c5720f4d13ff | 1779 | dbgPuts("Invalid READ string!"); |
fkellermavnet | 12:33290e9e6e5f | 1780 | |
fkellermavnet | 12:33290e9e6e5f | 1781 | if (i > 2*n) { |
fkellermavnet | 4:c5720f4d13ff | 1782 | // Bound the ill formated WNC read string! |
fkellermavnet | 7:e6f22159ef23 | 1783 | i = 2*n; |
fkellermavnet | 4:c5720f4d13ff | 1784 | dbgPuts("TRUNCATING read data!"); |
fkellermavnet | 4:c5720f4d13ff | 1785 | } |
fkellermavnet | 4:c5720f4d13ff | 1786 | |
fkellermavnet | 1:ac2de545b981 | 1787 | // If data, convert the hex string into byte values |
fkellermavnet | 16:f748245382ac | 1788 | i /= 2; |
fkellermavnet | 16:f748245382ac | 1789 | *numRead = i; |
fkellermavnet | 12:33290e9e6e5f | 1790 | while (i > 0) { |
fkellermavnet | 16:f748245382ac | 1791 | i--; |
fkellermavnet | 12:33290e9e6e5f | 1792 | *pS++ = (uint8_t)strtol(pRespStr->substr(pos_start, 2).c_str(), NULL, 16); |
fkellermavnet | 12:33290e9e6e5f | 1793 | pos_start += 2; |
fkellermavnet | 0:affdbb35faa4 | 1794 | } |
fkellermavnet | 0:affdbb35faa4 | 1795 | } |
fkellermavnet | 0:affdbb35faa4 | 1796 | } |
fkellermavnet | 0:affdbb35faa4 | 1797 | else { |
fkellermavnet | 0:affdbb35faa4 | 1798 | dbgPuts("sockread Err, to many to read!"); |
fkellermavnet | 0:affdbb35faa4 | 1799 | result = WNC_AT_CMD_ERR; |
fkellermavnet | 0:affdbb35faa4 | 1800 | } |
fkellermavnet | 0:affdbb35faa4 | 1801 | |
fkellermavnet | 0:affdbb35faa4 | 1802 | return (result); |
fkellermavnet | 0:affdbb35faa4 | 1803 | } |
fkellermavnet | 0:affdbb35faa4 | 1804 | |
fkellermavnet | 0:affdbb35faa4 | 1805 | bool WncController::at_reinitialize_mdm(void) |
fkellermavnet | 0:affdbb35faa4 | 1806 | { |
fkellermavnet | 0:affdbb35faa4 | 1807 | // Atempt to re-register |
fkellermavnet | 0:affdbb35faa4 | 1808 | // string * pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1809 | // dbgPuts("Force re-register!"); |
fkellermavnet | 0:affdbb35faa4 | 1810 | // at_send_wnc_cmd("AT+CFUN=0,0", &pRespStr, m_sCmdTimeoutMs); |
fkellermavnet | 0:affdbb35faa4 | 1811 | // waitMs(31000); |
fkellermavnet | 0:affdbb35faa4 | 1812 | // at_send_wnc_cmd("AT+CFUN=1,0", &pRespStr, m_sCmdTimeoutMs); |
fkellermavnet | 0:affdbb35faa4 | 1813 | // waitMs(31000); |
fkellermavnet | 0:affdbb35faa4 | 1814 | |
fkellermavnet | 0:affdbb35faa4 | 1815 | // Initialize the modem |
fkellermavnet | 0:affdbb35faa4 | 1816 | dbgPuts("Modem RE-initializing with SOFT Reset..."); |
fkellermavnet | 0:affdbb35faa4 | 1817 | |
fkellermavnet | 0:affdbb35faa4 | 1818 | string * pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1819 | at_send_wnc_cmd("AT@DMREBOOT", &pRespStr, m_sCmdTimeoutMs); |
fkellermavnet | 0:affdbb35faa4 | 1820 | waitMs(5000); |
fkellermavnet | 0:affdbb35faa4 | 1821 | |
fkellermavnet | 0:affdbb35faa4 | 1822 | // Now, give the modem time to start responding by |
fkellermavnet | 0:affdbb35faa4 | 1823 | // sending simple 'AT' commands to the modem once per second. |
fkellermavnet | 0:affdbb35faa4 | 1824 | int timeoutSecs = WNC_REINIT_MAX_TIME_MS; |
fkellermavnet | 0:affdbb35faa4 | 1825 | do { |
fkellermavnet | 0:affdbb35faa4 | 1826 | dbgPuts("\rWaiting ", false); dbgPutsNoTime(_to_string(timeoutSecs), false); |
fkellermavnet | 0:affdbb35faa4 | 1827 | AtCmdErr_e rc = mdmSendAtCmdRsp("AT", 500, &m_sWncStr); |
fkellermavnet | 0:affdbb35faa4 | 1828 | if (rc == WNC_AT_CMD_OK) { |
fkellermavnet | 0:affdbb35faa4 | 1829 | dbgPutsNoTime(""); // CR LF |
fkellermavnet | 0:affdbb35faa4 | 1830 | break; |
fkellermavnet | 0:affdbb35faa4 | 1831 | } |
fkellermavnet | 0:affdbb35faa4 | 1832 | waitMs(500); |
fkellermavnet | 0:affdbb35faa4 | 1833 | timeoutSecs--; |
fkellermavnet | 0:affdbb35faa4 | 1834 | } |
fkellermavnet | 0:affdbb35faa4 | 1835 | while (timeoutSecs > 0); |
fkellermavnet | 0:affdbb35faa4 | 1836 | |
fkellermavnet | 0:affdbb35faa4 | 1837 | if (timeoutSecs <= 0) |
fkellermavnet | 0:affdbb35faa4 | 1838 | dbgPuts("\r\nModem RE-init FAILED!"); |
fkellermavnet | 0:affdbb35faa4 | 1839 | else |
fkellermavnet | 0:affdbb35faa4 | 1840 | dbgPuts("\r\nModem RE-init complete!"); |
fkellermavnet | 0:affdbb35faa4 | 1841 | |
fkellermavnet | 0:affdbb35faa4 | 1842 | return (timeoutSecs > 0); |
fkellermavnet | 0:affdbb35faa4 | 1843 | } |
fkellermavnet | 0:affdbb35faa4 | 1844 | |
fkellermavnet | 0:affdbb35faa4 | 1845 | WncController::AtCmdErr_e WncController::mdmSendAtCmdRsp(const char *cmd, int timeout_ms, string * rsp, bool crLf) |
fkellermavnet | 0:affdbb35faa4 | 1846 | { |
fkellermavnet | 0:affdbb35faa4 | 1847 | rsp->erase(); // Clean up from possible prior cmd response |
fkellermavnet | 0:affdbb35faa4 | 1848 | |
fkellermavnet | 0:affdbb35faa4 | 1849 | // Don't bother the WNC if user hasn't turned it on. |
fkellermavnet | 0:affdbb35faa4 | 1850 | if (m_sState == WNC_OFF) |
fkellermavnet | 0:affdbb35faa4 | 1851 | return (WNC_AT_CMD_WNC_NOT_ON); |
fkellermavnet | 0:affdbb35faa4 | 1852 | |
fkellermavnet | 0:affdbb35faa4 | 1853 | size_t n = strlen(cmd); |
fkellermavnet | 0:affdbb35faa4 | 1854 | |
fkellermavnet | 0:affdbb35faa4 | 1855 | // Wait per WNC advise |
fkellermavnet | 0:affdbb35faa4 | 1856 | waitMs(WNC_WAIT_FOR_AT_CMD_MS); |
fkellermavnet | 0:affdbb35faa4 | 1857 | |
fkellermavnet | 0:affdbb35faa4 | 1858 | if (cmd && n > 0) { |
fkellermavnet | 0:affdbb35faa4 | 1859 | sendCmd(cmd, crLf); |
fkellermavnet | 0:affdbb35faa4 | 1860 | // sendCmdSlow(cmd, n, 500); // 3rd arg is micro seconds between chars sent |
fkellermavnet | 0:affdbb35faa4 | 1861 | } |
fkellermavnet | 0:affdbb35faa4 | 1862 | |
fkellermavnet | 0:affdbb35faa4 | 1863 | startTimerA(); |
fkellermavnet | 1:ac2de545b981 | 1864 | while (getTimerTicksA_mS() < timeout_ms) { |
fkellermavnet | 1:ac2de545b981 | 1865 | n = mdmGetline(rsp, timeout_ms - getTimerTicksA_mS()); |
fkellermavnet | 0:affdbb35faa4 | 1866 | |
fkellermavnet | 0:affdbb35faa4 | 1867 | if (n == 0) |
fkellermavnet | 0:affdbb35faa4 | 1868 | continue; |
fkellermavnet | 14:e846217affcd | 1869 | |
fkellermavnet | 0:affdbb35faa4 | 1870 | if (rsp->rfind("OK") != string::npos) { |
fkellermavnet | 0:affdbb35faa4 | 1871 | stopTimerA(); |
fkellermavnet | 0:affdbb35faa4 | 1872 | return (WNC_AT_CMD_OK); |
fkellermavnet | 0:affdbb35faa4 | 1873 | } |
fkellermavnet | 0:affdbb35faa4 | 1874 | |
fkellermavnet | 0:affdbb35faa4 | 1875 | if (rsp->rfind("+CME ERROR") != string::npos) { |
fkellermavnet | 0:affdbb35faa4 | 1876 | stopTimerA(); |
fkellermavnet | 0:affdbb35faa4 | 1877 | return (WNC_AT_CMD_ERRCME); |
fkellermavnet | 0:affdbb35faa4 | 1878 | } |
fkellermavnet | 0:affdbb35faa4 | 1879 | |
fkellermavnet | 0:affdbb35faa4 | 1880 | if (rsp->rfind("@EXTERR") != string::npos) { |
fkellermavnet | 0:affdbb35faa4 | 1881 | stopTimerA(); |
fkellermavnet | 0:affdbb35faa4 | 1882 | return (WNC_AT_CMD_ERREXT); |
fkellermavnet | 0:affdbb35faa4 | 1883 | } |
fkellermavnet | 0:affdbb35faa4 | 1884 | |
fkellermavnet | 0:affdbb35faa4 | 1885 | if (rsp->rfind("ERROR") != string::npos) { |
fkellermavnet | 0:affdbb35faa4 | 1886 | stopTimerA(); |
fkellermavnet | 0:affdbb35faa4 | 1887 | return (WNC_AT_CMD_ERR); |
fkellermavnet | 0:affdbb35faa4 | 1888 | } |
fkellermavnet | 0:affdbb35faa4 | 1889 | } |
fkellermavnet | 0:affdbb35faa4 | 1890 | stopTimerA(); |
fkellermavnet | 0:affdbb35faa4 | 1891 | |
fkellermavnet | 0:affdbb35faa4 | 1892 | return (WNC_AT_CMD_TIMEOUT); |
fkellermavnet | 0:affdbb35faa4 | 1893 | } |
fkellermavnet | 0:affdbb35faa4 | 1894 | |
fkellermavnet | 0:affdbb35faa4 | 1895 | bool WncController::at_setapn_wnc(const char * const apnStr) |
fkellermavnet | 0:affdbb35faa4 | 1896 | { |
fkellermavnet | 0:affdbb35faa4 | 1897 | string * pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1898 | |
fkellermavnet | 0:affdbb35faa4 | 1899 | string cmd_str("AT%PDNSET=1,"); |
fkellermavnet | 0:affdbb35faa4 | 1900 | cmd_str += apnStr; |
fkellermavnet | 0:affdbb35faa4 | 1901 | cmd_str += ",IP"; |
fkellermavnet | 0:affdbb35faa4 | 1902 | if (WNC_AT_CMD_OK == at_send_wnc_cmd(cmd_str.c_str(), &pRespStr, WNC_APNSET_TIMEOUT_MS)) // Set APN, cmd seems to take a little longer sometimes |
fkellermavnet | 0:affdbb35faa4 | 1903 | return (true); |
fkellermavnet | 0:affdbb35faa4 | 1904 | else |
fkellermavnet | 0:affdbb35faa4 | 1905 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1906 | } |
fkellermavnet | 0:affdbb35faa4 | 1907 | |
fkellermavnet | 0:affdbb35faa4 | 1908 | bool WncController::at_getrssiber_wnc(int16_t * dBm, int16_t * ber) |
fkellermavnet | 0:affdbb35faa4 | 1909 | { |
fkellermavnet | 0:affdbb35faa4 | 1910 | string * pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1911 | AtCmdErr_e cmdRes; |
fkellermavnet | 0:affdbb35faa4 | 1912 | cmdRes = at_send_wnc_cmd("AT+CSQ", &pRespStr, m_sCmdTimeoutMs); // Check RSSI,BER |
fkellermavnet | 0:affdbb35faa4 | 1913 | if (cmdRes != WNC_AT_CMD_OK) |
fkellermavnet | 0:affdbb35faa4 | 1914 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1915 | |
fkellermavnet | 0:affdbb35faa4 | 1916 | if (pRespStr->size() == 0) { |
fkellermavnet | 0:affdbb35faa4 | 1917 | dbgPuts("Strange RSSI result!"); |
fkellermavnet | 0:affdbb35faa4 | 1918 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1919 | } |
fkellermavnet | 0:affdbb35faa4 | 1920 | else { |
fkellermavnet | 0:affdbb35faa4 | 1921 | size_t pos1 = pRespStr->find("SQ:"); |
fkellermavnet | 0:affdbb35faa4 | 1922 | size_t pos2 = pRespStr->rfind(","); |
fkellermavnet | 0:affdbb35faa4 | 1923 | // Sanity check |
fkellermavnet | 0:affdbb35faa4 | 1924 | if ((pos1 != string::npos) && (pos2 != string::npos) && (pos2 > pos1)) { |
fkellermavnet | 0:affdbb35faa4 | 1925 | string subStr = pRespStr->substr(pos1 + 4, pos2 - pos1 ); |
fkellermavnet | 0:affdbb35faa4 | 1926 | int rawRssi = atoi(subStr.c_str()); |
fkellermavnet | 0:affdbb35faa4 | 1927 | |
fkellermavnet | 0:affdbb35faa4 | 1928 | // Convert WNC RSSI into dBm range: |
fkellermavnet | 0:affdbb35faa4 | 1929 | // 0 - -113 dBm |
fkellermavnet | 0:affdbb35faa4 | 1930 | // 1 - -111 dBm |
fkellermavnet | 0:affdbb35faa4 | 1931 | // 2..30 - -109 to -53 dBm |
fkellermavnet | 0:affdbb35faa4 | 1932 | // 31 - -51dBm or > |
fkellermavnet | 0:affdbb35faa4 | 1933 | // 99 - not known or not detectable |
fkellermavnet | 0:affdbb35faa4 | 1934 | if (rawRssi == 99) |
fkellermavnet | 0:affdbb35faa4 | 1935 | *dBm = -199; |
fkellermavnet | 0:affdbb35faa4 | 1936 | else if (rawRssi == 0) |
fkellermavnet | 0:affdbb35faa4 | 1937 | *dBm = -113; |
fkellermavnet | 0:affdbb35faa4 | 1938 | else if (rawRssi == 1) |
fkellermavnet | 0:affdbb35faa4 | 1939 | *dBm = -111; |
fkellermavnet | 0:affdbb35faa4 | 1940 | else if (rawRssi == 31) |
fkellermavnet | 0:affdbb35faa4 | 1941 | *dBm = -51; |
fkellermavnet | 0:affdbb35faa4 | 1942 | else if (rawRssi >= 2 && rawRssi <= 30) |
fkellermavnet | 0:affdbb35faa4 | 1943 | *dBm = -113 + 2 * rawRssi; |
fkellermavnet | 0:affdbb35faa4 | 1944 | else { |
fkellermavnet | 0:affdbb35faa4 | 1945 | dbgPuts("Invalid RSSI!"); |
fkellermavnet | 0:affdbb35faa4 | 1946 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1947 | } |
fkellermavnet | 0:affdbb35faa4 | 1948 | // Parse out BER: 0..7 as RXQUAL values in the table 3GPP TS 45.008 subclause 8.2.4 |
fkellermavnet | 0:affdbb35faa4 | 1949 | // 99 - unknown or undetectable |
fkellermavnet | 0:affdbb35faa4 | 1950 | subStr = pRespStr->substr(pos2 + 1, pRespStr->length() - (pos2 + 1)); |
fkellermavnet | 0:affdbb35faa4 | 1951 | *ber = atoi(subStr.c_str()); |
fkellermavnet | 0:affdbb35faa4 | 1952 | } |
fkellermavnet | 0:affdbb35faa4 | 1953 | else { |
fkellermavnet | 0:affdbb35faa4 | 1954 | dbgPuts("Strange RSSI result2!"); |
fkellermavnet | 0:affdbb35faa4 | 1955 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1956 | } |
fkellermavnet | 0:affdbb35faa4 | 1957 | } |
fkellermavnet | 0:affdbb35faa4 | 1958 | |
fkellermavnet | 0:affdbb35faa4 | 1959 | return (true); |
fkellermavnet | 0:affdbb35faa4 | 1960 | } |
fkellermavnet | 0:affdbb35faa4 | 1961 | |
fkellermavnet | 0:affdbb35faa4 | 1962 | bool WncController::checkCellLink(void) |
fkellermavnet | 0:affdbb35faa4 | 1963 | { |
fkellermavnet | 0:affdbb35faa4 | 1964 | string * pRespStr; |
fkellermavnet | 0:affdbb35faa4 | 1965 | size_t pos; |
fkellermavnet | 0:affdbb35faa4 | 1966 | int regSts; |
fkellermavnet | 0:affdbb35faa4 | 1967 | int cmdRes1, cmdRes2; |
fkellermavnet | 0:affdbb35faa4 | 1968 | |
fkellermavnet | 0:affdbb35faa4 | 1969 | if (m_sState == WNC_OFF) |
fkellermavnet | 0:affdbb35faa4 | 1970 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1971 | |
fkellermavnet | 0:affdbb35faa4 | 1972 | m_sState = WNC_ON_NO_CELL_LINK; |
fkellermavnet | 0:affdbb35faa4 | 1973 | |
fkellermavnet | 0:affdbb35faa4 | 1974 | if (m_sMoreDebugEnabled) |
fkellermavnet | 0:affdbb35faa4 | 1975 | dbgPuts("<-------- Begin Cell Status ------------"); |
fkellermavnet | 0:affdbb35faa4 | 1976 | |
fkellermavnet | 0:affdbb35faa4 | 1977 | cmdRes1 = at_send_wnc_cmd("AT+CSQ", &pRespStr, m_sCmdTimeoutMs); // Check RSSI,BER |
fkellermavnet | 0:affdbb35faa4 | 1978 | cmdRes2 = at_send_wnc_cmd("AT+CPIN?", &pRespStr, m_sCmdTimeoutMs); // Check if SIM locked |
fkellermavnet | 0:affdbb35faa4 | 1979 | |
fkellermavnet | 14:e846217affcd | 1980 | if ((cmdRes1 != WNC_AT_CMD_OK) || (cmdRes2 != WNC_AT_CMD_OK) || (pRespStr->size() == 0)) |
fkellermavnet | 0:affdbb35faa4 | 1981 | { |
fkellermavnet | 0:affdbb35faa4 | 1982 | if (m_sMoreDebugEnabled) |
fkellermavnet | 0:affdbb35faa4 | 1983 | { |
fkellermavnet | 0:affdbb35faa4 | 1984 | if ((cmdRes1 == WNC_AT_CMD_TIMEOUT) || (cmdRes2 == WNC_AT_CMD_TIMEOUT)) |
fkellermavnet | 0:affdbb35faa4 | 1985 | dbgPuts("------------ WNC No Response! --------->"); |
fkellermavnet | 0:affdbb35faa4 | 1986 | else |
fkellermavnet | 0:affdbb35faa4 | 1987 | dbgPuts("------------ WNC Cmd Error! ----------->"); |
fkellermavnet | 0:affdbb35faa4 | 1988 | } |
fkellermavnet | 0:affdbb35faa4 | 1989 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1990 | } |
fkellermavnet | 0:affdbb35faa4 | 1991 | |
fkellermavnet | 0:affdbb35faa4 | 1992 | // If SIM Card not ready don't bother with commands! |
fkellermavnet | 0:affdbb35faa4 | 1993 | if (pRespStr->find("CPIN: READY") == string::npos) |
fkellermavnet | 0:affdbb35faa4 | 1994 | { |
fkellermavnet | 0:affdbb35faa4 | 1995 | if (m_sMoreDebugEnabled) |
fkellermavnet | 0:affdbb35faa4 | 1996 | dbgPuts("------------ WNC SIM Problem! --------->"); |
fkellermavnet | 0:affdbb35faa4 | 1997 | |
fkellermavnet | 0:affdbb35faa4 | 1998 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 1999 | } |
fkellermavnet | 0:affdbb35faa4 | 2000 | |
fkellermavnet | 0:affdbb35faa4 | 2001 | // SIM card OK, now check for signal and cellular network registration |
fkellermavnet | 0:affdbb35faa4 | 2002 | cmdRes1 = at_send_wnc_cmd("AT+CREG?", &pRespStr, m_sCmdTimeoutMs); // Check if registered on network |
fkellermavnet | 14:e846217affcd | 2003 | if (cmdRes1 != WNC_AT_CMD_OK || pRespStr->size() == 0) |
fkellermavnet | 0:affdbb35faa4 | 2004 | { |
fkellermavnet | 0:affdbb35faa4 | 2005 | if (m_sMoreDebugEnabled) |
fkellermavnet | 0:affdbb35faa4 | 2006 | dbgPuts("------------ WNC +CREG? Fail! --------->"); |
fkellermavnet | 0:affdbb35faa4 | 2007 | |
fkellermavnet | 0:affdbb35faa4 | 2008 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 2009 | } |
fkellermavnet | 0:affdbb35faa4 | 2010 | else |
fkellermavnet | 0:affdbb35faa4 | 2011 | { |
fkellermavnet | 0:affdbb35faa4 | 2012 | pos = pRespStr->find("CREG: "); |
fkellermavnet | 0:affdbb35faa4 | 2013 | if (pos != string::npos) |
fkellermavnet | 0:affdbb35faa4 | 2014 | { |
fkellermavnet | 0:affdbb35faa4 | 2015 | // The registration is the 2nd arg in the comma separated list |
fkellermavnet | 0:affdbb35faa4 | 2016 | *pRespStr = pRespStr->substr(pos+8, 1); |
fkellermavnet | 0:affdbb35faa4 | 2017 | regSts = atoi(pRespStr->c_str()); |
fkellermavnet | 0:affdbb35faa4 | 2018 | switch (regSts) { |
fkellermavnet | 0:affdbb35faa4 | 2019 | case 1: |
fkellermavnet | 0:affdbb35faa4 | 2020 | case 5: |
fkellermavnet | 0:affdbb35faa4 | 2021 | case 6: |
fkellermavnet | 0:affdbb35faa4 | 2022 | case 7: |
fkellermavnet | 0:affdbb35faa4 | 2023 | m_sReadyForSMS = true; |
fkellermavnet | 0:affdbb35faa4 | 2024 | break; |
fkellermavnet | 0:affdbb35faa4 | 2025 | default: |
fkellermavnet | 0:affdbb35faa4 | 2026 | m_sReadyForSMS = false; |
fkellermavnet | 0:affdbb35faa4 | 2027 | dbgPuts("SMS Service Down!"); |
fkellermavnet | 0:affdbb35faa4 | 2028 | } |
fkellermavnet | 0:affdbb35faa4 | 2029 | |
fkellermavnet | 0:affdbb35faa4 | 2030 | // 1 - registered home, 5 - registered roaming |
fkellermavnet | 0:affdbb35faa4 | 2031 | if ((regSts != 1) && (regSts != 5)) |
fkellermavnet | 0:affdbb35faa4 | 2032 | { |
fkellermavnet | 0:affdbb35faa4 | 2033 | if (m_sMoreDebugEnabled) |
fkellermavnet | 0:affdbb35faa4 | 2034 | dbgPuts("------ WNC Cell Link Down for Data! --->"); |
fkellermavnet | 0:affdbb35faa4 | 2035 | |
fkellermavnet | 0:affdbb35faa4 | 2036 | return (false); |
fkellermavnet | 0:affdbb35faa4 | 2037 | } |
fkellermavnet | 0:affdbb35faa4 | 2038 | } |
fkellermavnet | 0:affdbb35faa4 | 2039 | |
fkellermavnet | 0:affdbb35faa4 | 2040 | if (m_sMoreDebugEnabled) |
fkellermavnet | 0:affdbb35faa4 | 2041 | dbgPuts("------------ WNC Ready ---------------->"); |
fkellermavnet | 0:affdbb35faa4 | 2042 | } |
fkellermavnet | 0:affdbb35faa4 | 2043 | |
fkellermavnet | 0:affdbb35faa4 | 2044 | m_sState = WNC_ON; |
fkellermavnet | 0:affdbb35faa4 | 2045 | |
fkellermavnet | 0:affdbb35faa4 | 2046 | return (true); |
fkellermavnet | 0:affdbb35faa4 | 2047 | } |
fkellermavnet | 0:affdbb35faa4 | 2048 | |
fkellermavnet | 0:affdbb35faa4 | 2049 | int WncController::dbgPutsNoTime(const char * s, bool crlf) |
fkellermavnet | 0:affdbb35faa4 | 2050 | { |
fkellermavnet | 0:affdbb35faa4 | 2051 | if (m_sDebugEnabled == true) { |
fkellermavnet | 1:ac2de545b981 | 2052 | int r = dbgWriteChars(s); |
fkellermavnet | 0:affdbb35faa4 | 2053 | if (crlf == true) |
fkellermavnet | 1:ac2de545b981 | 2054 | return (dbgWriteChars("\r\n")); |
fkellermavnet | 0:affdbb35faa4 | 2055 | else |
fkellermavnet | 0:affdbb35faa4 | 2056 | return (r); |
fkellermavnet | 0:affdbb35faa4 | 2057 | } |
fkellermavnet | 0:affdbb35faa4 | 2058 | else |
fkellermavnet | 0:affdbb35faa4 | 2059 | return 0; |
fkellermavnet | 0:affdbb35faa4 | 2060 | }; |
fkellermavnet | 0:affdbb35faa4 | 2061 | |
fkellermavnet | 0:affdbb35faa4 | 2062 | int WncController::dbgPuts(const char * s, bool crlf) |
fkellermavnet | 0:affdbb35faa4 | 2063 | { |
fkellermavnet | 0:affdbb35faa4 | 2064 | dbgPutsNoTime("[*] ", false); |
fkellermavnet | 0:affdbb35faa4 | 2065 | dbgPutsNoTime(_to_string(getLogTimerTicks()), false); |
fkellermavnet | 1:ac2de545b981 | 2066 | dbgPutsNoTime(" ", false); |
fkellermavnet | 0:affdbb35faa4 | 2067 | |
fkellermavnet | 0:affdbb35faa4 | 2068 | int r = dbgPutsNoTime(s, false); |
fkellermavnet | 1:ac2de545b981 | 2069 | |
fkellermavnet | 0:affdbb35faa4 | 2070 | if (crlf == true) |
fkellermavnet | 1:ac2de545b981 | 2071 | return (dbgPutsNoTime("", true)); |
fkellermavnet | 0:affdbb35faa4 | 2072 | else |
fkellermavnet | 0:affdbb35faa4 | 2073 | return (r); |
fkellermavnet | 0:affdbb35faa4 | 2074 | }; |
fkellermavnet | 0:affdbb35faa4 | 2075 | |
fkellermavnet | 0:affdbb35faa4 | 2076 | void WncController::sendCmd(const char * cmd, bool crLf) |
fkellermavnet | 0:affdbb35faa4 | 2077 | { |
fkellermavnet | 0:affdbb35faa4 | 2078 | puts(cmd); |
fkellermavnet | 0:affdbb35faa4 | 2079 | if (crLf == true) |
fkellermavnet | 0:affdbb35faa4 | 2080 | puts("\r\n"); |
fkellermavnet | 0:affdbb35faa4 | 2081 | } |
fkellermavnet | 0:affdbb35faa4 | 2082 | |
fkellermavnet | 0:affdbb35faa4 | 2083 | // WNC used to have troubles handling full speed, seems to not need this now. |
fkellermavnet | 0:affdbb35faa4 | 2084 | void WncController::sendCmd(const char * cmd, unsigned n, unsigned wait_uS, bool crLf) |
fkellermavnet | 0:affdbb35faa4 | 2085 | { |
fkellermavnet | 0:affdbb35faa4 | 2086 | while (n--) { |
fkellermavnet | 0:affdbb35faa4 | 2087 | putc(*cmd++); |
fkellermavnet | 0:affdbb35faa4 | 2088 | waitUs(wait_uS); |
fkellermavnet | 0:affdbb35faa4 | 2089 | }; |
fkellermavnet | 0:affdbb35faa4 | 2090 | if (crLf == true) { |
fkellermavnet | 0:affdbb35faa4 | 2091 | putc('\r'); |
fkellermavnet | 0:affdbb35faa4 | 2092 | waitUs(wait_uS); |
fkellermavnet | 0:affdbb35faa4 | 2093 | putc('\n'); |
fkellermavnet | 0:affdbb35faa4 | 2094 | waitUs(wait_uS); |
fkellermavnet | 0:affdbb35faa4 | 2095 | } |
fkellermavnet | 0:affdbb35faa4 | 2096 | } |
fkellermavnet | 0:affdbb35faa4 | 2097 | |
fkellermavnet | 0:affdbb35faa4 | 2098 | |
fkellermavnet | 0:affdbb35faa4 | 2099 | }; // End namespace WncController_fk |