AWS IoT demonstration using the Avnet Shield (AT&T LTE) and the FRDM-K64F target board.
Dependencies: K64F_FATFileSystem
Fork of mbed-os-example-tls-tls-client by
WNCInterface/WncControllerK64F/WncController/WncController.h@25:91d771247ac8, 2016-12-19 (annotated)
- Committer:
- ampembeng
- Date:
- Mon Dec 19 20:52:28 2016 +0000
- Revision:
- 25:91d771247ac8
- Parent:
- 15:6f2798e45099
Updated the look/feel of the Python GUI to match the AT&T locker demo S3 page. Added "assets" folder to support this. Updated the README.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ampembeng | 15:6f2798e45099 | 1 | /* |
ampembeng | 15:6f2798e45099 | 2 | Copyright (c) 2016 Fred Kellerman |
ampembeng | 15:6f2798e45099 | 3 | |
ampembeng | 15:6f2798e45099 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
ampembeng | 15:6f2798e45099 | 5 | of this software and associated documentation files (the "Software"), to deal |
ampembeng | 15:6f2798e45099 | 6 | in the Software without restriction, including without limitation the rights |
ampembeng | 15:6f2798e45099 | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
ampembeng | 15:6f2798e45099 | 8 | copies of the Software, and to permit persons to whom the Software is |
ampembeng | 15:6f2798e45099 | 9 | furnished to do so, subject to the following conditions: |
ampembeng | 15:6f2798e45099 | 10 | |
ampembeng | 15:6f2798e45099 | 11 | The above copyright notice and this permission notice shall be included in |
ampembeng | 15:6f2798e45099 | 12 | all copies or substantial portions of the Software. |
ampembeng | 15:6f2798e45099 | 13 | |
ampembeng | 15:6f2798e45099 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
ampembeng | 15:6f2798e45099 | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
ampembeng | 15:6f2798e45099 | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
ampembeng | 15:6f2798e45099 | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
ampembeng | 15:6f2798e45099 | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ampembeng | 15:6f2798e45099 | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
ampembeng | 15:6f2798e45099 | 20 | THE SOFTWARE. |
ampembeng | 15:6f2798e45099 | 21 | |
ampembeng | 15:6f2798e45099 | 22 | @file WncController.h |
ampembeng | 15:6f2798e45099 | 23 | @purpose Controls WNC Cellular Modem |
ampembeng | 15:6f2798e45099 | 24 | @version 1.0 |
ampembeng | 15:6f2798e45099 | 25 | @date July 2016 |
ampembeng | 15:6f2798e45099 | 26 | @author Fred Kellerman |
ampembeng | 15:6f2798e45099 | 27 | |
ampembeng | 15:6f2798e45099 | 28 | Notes: This code originates from the following mbed repository: |
ampembeng | 15:6f2798e45099 | 29 | |
ampembeng | 15:6f2798e45099 | 30 | https://developer.mbed.org/teams/Avnet/code/WncControllerLibrary/ |
ampembeng | 15:6f2798e45099 | 31 | */ |
ampembeng | 15:6f2798e45099 | 32 | |
ampembeng | 15:6f2798e45099 | 33 | |
ampembeng | 15:6f2798e45099 | 34 | #ifndef __WNCCONTROLLER_H_ |
ampembeng | 15:6f2798e45099 | 35 | #define __WNCCONTROLLER_H_ |
ampembeng | 15:6f2798e45099 | 36 | |
ampembeng | 15:6f2798e45099 | 37 | #include <string> |
ampembeng | 15:6f2798e45099 | 38 | #include <stdint.h> |
ampembeng | 15:6f2798e45099 | 39 | |
ampembeng | 15:6f2798e45099 | 40 | namespace WncController_fk { |
ampembeng | 15:6f2798e45099 | 41 | |
ampembeng | 15:6f2798e45099 | 42 | using namespace std; |
ampembeng | 15:6f2798e45099 | 43 | |
ampembeng | 15:6f2798e45099 | 44 | /** |
ampembeng | 15:6f2798e45099 | 45 | * \file WncController.h |
ampembeng | 15:6f2798e45099 | 46 | * \brief This mbed C++ class is for controlling the WNC |
ampembeng | 15:6f2798e45099 | 47 | * Cellular modem via the AT command interface. This was |
ampembeng | 15:6f2798e45099 | 48 | * developed with respect to version 1.3 of the WNC authored |
ampembeng | 15:6f2798e45099 | 49 | * spec. This class is only designed to have 1 instantiation |
ampembeng | 15:6f2798e45099 | 50 | * it is also not multi-thread safe. |
ampembeng | 15:6f2798e45099 | 51 | */ |
ampembeng | 15:6f2798e45099 | 52 | |
ampembeng | 15:6f2798e45099 | 53 | |
ampembeng | 15:6f2798e45099 | 54 | static const uint8_t MAX_LEN_IP_STR = 16; // Length includes room for the extra NULL |
ampembeng | 15:6f2798e45099 | 55 | |
ampembeng | 15:6f2798e45099 | 56 | /** |
ampembeng | 15:6f2798e45099 | 57 | * \brief Contains info fields for the WNC Internet Attributes |
ampembeng | 15:6f2798e45099 | 58 | */ |
ampembeng | 15:6f2798e45099 | 59 | struct WncIpStats |
ampembeng | 15:6f2798e45099 | 60 | { |
ampembeng | 15:6f2798e45099 | 61 | string wncMAC; |
ampembeng | 15:6f2798e45099 | 62 | char ip[MAX_LEN_IP_STR]; |
ampembeng | 15:6f2798e45099 | 63 | char mask[MAX_LEN_IP_STR]; |
ampembeng | 15:6f2798e45099 | 64 | char gateway[MAX_LEN_IP_STR]; |
ampembeng | 15:6f2798e45099 | 65 | char dnsPrimary[MAX_LEN_IP_STR]; |
ampembeng | 15:6f2798e45099 | 66 | char dnsSecondary[MAX_LEN_IP_STR]; |
ampembeng | 15:6f2798e45099 | 67 | }; |
ampembeng | 15:6f2798e45099 | 68 | |
ampembeng | 15:6f2798e45099 | 69 | class WncController |
ampembeng | 15:6f2798e45099 | 70 | { |
ampembeng | 15:6f2798e45099 | 71 | public: |
ampembeng | 15:6f2798e45099 | 72 | static const unsigned MAX_NUM_WNC_SOCKETS = 5; // Max number of simultaneous sockets that the WNC supports |
ampembeng | 15:6f2798e45099 | 73 | static const unsigned MAX_POWERUP_TIMEOUT = 60; // How long the powerUp method will try to turn on the WNC Shield |
ampembeng | 15:6f2798e45099 | 74 | // (this is the default if the user does not over-ride on power-up |
ampembeng | 15:6f2798e45099 | 75 | |
ampembeng | 15:6f2798e45099 | 76 | // Tracks mode of the WNC Shield hardware |
ampembeng | 15:6f2798e45099 | 77 | enum WncState_e { |
ampembeng | 15:6f2798e45099 | 78 | WNC_OFF = 0, |
ampembeng | 15:6f2798e45099 | 79 | WNC_ON, // This is intended to mean all systems go, including cell link up but socket may not be open |
ampembeng | 15:6f2798e45099 | 80 | WNC_ON_NO_CELL_LINK, |
ampembeng | 15:6f2798e45099 | 81 | WNC_NO_RESPONSE |
ampembeng | 15:6f2798e45099 | 82 | }; |
ampembeng | 15:6f2798e45099 | 83 | |
ampembeng | 15:6f2798e45099 | 84 | /** |
ampembeng | 15:6f2798e45099 | 85 | * \brief Constructor for UART controlled WNC |
ampembeng | 15:6f2798e45099 | 86 | * |
ampembeng | 15:6f2798e45099 | 87 | * \param [in] wnc_uart - Reference to a SerialBuffered object which will |
ampembeng | 15:6f2798e45099 | 88 | * be used as the bus to control the WNC. apnStr = a text string for |
ampembeng | 15:6f2798e45099 | 89 | * the cellular APN name. |
ampembeng | 15:6f2798e45099 | 90 | * |
ampembeng | 15:6f2798e45099 | 91 | * \return None. |
ampembeng | 15:6f2798e45099 | 92 | * |
ampembeng | 15:6f2798e45099 | 93 | * \details Adding another way to talk to the WNC, like I2C or USB, |
ampembeng | 15:6f2798e45099 | 94 | * a constructor should be added for each type just like the SerialBuffered |
ampembeng | 15:6f2798e45099 | 95 | * constructor below. Assumes UART is enabled, setup and ready to go. This |
ampembeng | 15:6f2798e45099 | 96 | * class will read and write to this UART. |
ampembeng | 15:6f2798e45099 | 97 | */ |
ampembeng | 15:6f2798e45099 | 98 | WncController(void); |
ampembeng | 15:6f2798e45099 | 99 | |
ampembeng | 15:6f2798e45099 | 100 | // WncController( const char * const apnStr, MODSERIAL * wnc_uart, MODSERIAL * debug_uart = NULL); |
ampembeng | 15:6f2798e45099 | 101 | |
ampembeng | 15:6f2798e45099 | 102 | /** |
ampembeng | 15:6f2798e45099 | 103 | * \brief Used internally but also make public for a user of the Class to interrogate state as well. |
ampembeng | 15:6f2798e45099 | 104 | * |
ampembeng | 15:6f2798e45099 | 105 | * \param [in] None. |
ampembeng | 15:6f2798e45099 | 106 | * |
ampembeng | 15:6f2798e45099 | 107 | * \return The state of the WNC Modem. |
ampembeng | 15:6f2798e45099 | 108 | * |
ampembeng | 15:6f2798e45099 | 109 | * \details None. |
ampembeng | 15:6f2798e45099 | 110 | */ |
ampembeng | 15:6f2798e45099 | 111 | WncState_e getWncStatus(void); |
ampembeng | 15:6f2798e45099 | 112 | |
ampembeng | 15:6f2798e45099 | 113 | bool setApnName(const char * const apnStr); |
ampembeng | 15:6f2798e45099 | 114 | |
ampembeng | 15:6f2798e45099 | 115 | /** |
ampembeng | 15:6f2798e45099 | 116 | * \brief Return signal quality dBm level |
ampembeng | 15:6f2798e45099 | 117 | * |
ampembeng | 15:6f2798e45099 | 118 | * \param [in] None. |
ampembeng | 15:6f2798e45099 | 119 | * |
ampembeng | 15:6f2798e45099 | 120 | * \return The dBm signal level at the time of the request. |
ampembeng | 15:6f2798e45099 | 121 | * |
ampembeng | 15:6f2798e45099 | 122 | * \details This polls (at the time of the call) the cell signal. |
ampembeng | 15:6f2798e45099 | 123 | */ |
ampembeng | 15:6f2798e45099 | 124 | int16_t getDbmRssi(void); |
ampembeng | 15:6f2798e45099 | 125 | int16_t get3gBer(void); |
ampembeng | 15:6f2798e45099 | 126 | |
ampembeng | 15:6f2798e45099 | 127 | /** |
ampembeng | 15:6f2798e45099 | 128 | * \brief Power up and down (down not implemented yet) |
ampembeng | 15:6f2798e45099 | 129 | * |
ampembeng | 15:6f2798e45099 | 130 | * \param [in] NXP Pins that are critical for the initialization of the WNC Shield. |
ampembeng | 15:6f2798e45099 | 131 | * |
ampembeng | 15:6f2798e45099 | 132 | * \return true if request successful else false. |
ampembeng | 15:6f2798e45099 | 133 | * |
ampembeng | 15:6f2798e45099 | 134 | * \details Power-on works but not power-down. This will manipulate WNC Shield hardware |
ampembeng | 15:6f2798e45099 | 135 | * and bring it to life. It will also initialize the WNC enough to get it to be able to open sockets |
ampembeng | 15:6f2798e45099 | 136 | * (with AT commands) |
ampembeng | 15:6f2798e45099 | 137 | */ |
ampembeng | 15:6f2798e45099 | 138 | bool powerWncOn(const char * const apn, uint8_t powerUpTimeoutSecs = MAX_POWERUP_TIMEOUT); |
ampembeng | 15:6f2798e45099 | 139 | |
ampembeng | 15:6f2798e45099 | 140 | /** |
ampembeng | 15:6f2798e45099 | 141 | * \brief Query the WNC modem for its Internet attributes |
ampembeng | 15:6f2798e45099 | 142 | * |
ampembeng | 15:6f2798e45099 | 143 | * \param [in] Pointer to a struct where to put the info. |
ampembeng | 15:6f2798e45099 | 144 | * |
ampembeng | 15:6f2798e45099 | 145 | * \return true if request successful else false. |
ampembeng | 15:6f2798e45099 | 146 | * |
ampembeng | 15:6f2798e45099 | 147 | * \details This method will do a few sanity checks and then gather the |
ampembeng | 15:6f2798e45099 | 148 | * fields of the struct. |
ampembeng | 15:6f2798e45099 | 149 | */ |
ampembeng | 15:6f2798e45099 | 150 | bool getWncNetworkingStats(WncIpStats * s); |
ampembeng | 15:6f2798e45099 | 151 | |
ampembeng | 15:6f2798e45099 | 152 | /** |
ampembeng | 15:6f2798e45099 | 153 | * \brief Look-up a URL text string and convert into an IP Address string. |
ampembeng | 15:6f2798e45099 | 154 | * |
ampembeng | 15:6f2798e45099 | 155 | * \param [in] url - the URL to lookup. numSock - the socket reference. |
ampembeng | 15:6f2798e45099 | 156 | * |
ampembeng | 15:6f2798e45099 | 157 | * \return true - if the IP address has been resolved. false - if the URL could not be resolved. |
ampembeng | 15:6f2798e45099 | 158 | * |
ampembeng | 15:6f2798e45099 | 159 | * \details None. |
ampembeng | 15:6f2798e45099 | 160 | */ |
ampembeng | 15:6f2798e45099 | 161 | bool resolveUrl(uint16_t numSock, const char * url); |
ampembeng | 15:6f2798e45099 | 162 | |
ampembeng | 15:6f2798e45099 | 163 | /** |
ampembeng | 15:6f2798e45099 | 164 | * \brief Set IP Address string |
ampembeng | 15:6f2798e45099 | 165 | * |
ampembeng | 15:6f2798e45099 | 166 | * \param [in] numSock - socket reference to set the string for. ipStr - text string of the IP |
ampembeng | 15:6f2798e45099 | 167 | * address you want to talk to. There is no sanity check - beware!!! |
ampembeng | 15:6f2798e45099 | 168 | * |
ampembeng | 15:6f2798e45099 | 169 | * \return true - if the IP address has been set. false - if the IP could not be set. |
ampembeng | 15:6f2798e45099 | 170 | * |
ampembeng | 15:6f2798e45099 | 171 | * \details None. |
ampembeng | 15:6f2798e45099 | 172 | */ |
ampembeng | 15:6f2798e45099 | 173 | bool setIpAddr(uint16_t numSock, const char * ipStr); |
ampembeng | 15:6f2798e45099 | 174 | |
ampembeng | 15:6f2798e45099 | 175 | /** |
ampembeng | 15:6f2798e45099 | 176 | * \brief Opens a WNC socket. |
ampembeng | 15:6f2798e45099 | 177 | * |
ampembeng | 15:6f2798e45099 | 178 | * \param [in] sockNum - the number of the socket to open. ipAddr - a string containing |
ampembeng | 15:6f2798e45099 | 179 | * the IP address. port - the IP port number to open the socket connection. |
ampembeng | 15:6f2798e45099 | 180 | * |
ampembeng | 15:6f2798e45099 | 181 | * \return true - if the socket is/was opened. false otherwise. |
ampembeng | 15:6f2798e45099 | 182 | * |
ampembeng | 15:6f2798e45099 | 183 | * \details None. |
ampembeng | 15:6f2798e45099 | 184 | */ |
ampembeng | 15:6f2798e45099 | 185 | bool openSocket(uint16_t numSock, uint16_t port, bool tcp, uint16_t timeOutSec = 30); |
ampembeng | 15:6f2798e45099 | 186 | |
ampembeng | 15:6f2798e45099 | 187 | bool openSocketUrl(uint16_t numSock, const char * url, uint16_t port, bool tcp, uint16_t timeOutSec = 30); |
ampembeng | 15:6f2798e45099 | 188 | |
ampembeng | 15:6f2798e45099 | 189 | bool openSocketIpAddr(uint16_t numSock, const char * ipAddr, uint16_t port, bool tcp, uint16_t timeOutSec = 30); |
ampembeng | 15:6f2798e45099 | 190 | |
ampembeng | 15:6f2798e45099 | 191 | |
ampembeng | 15:6f2798e45099 | 192 | /** |
ampembeng | 15:6f2798e45099 | 193 | * \brief Write bytes of data to an open socket |
ampembeng | 15:6f2798e45099 | 194 | * |
ampembeng | 15:6f2798e45099 | 195 | * \param [in] sockNum - the number of the socket to write. s - a string containing |
ampembeng | 15:6f2798e45099 | 196 | * the byte data to send. |
ampembeng | 15:6f2798e45099 | 197 | * |
ampembeng | 15:6f2798e45099 | 198 | * \return true - if the write was successful. false otherwise. |
ampembeng | 15:6f2798e45099 | 199 | * |
ampembeng | 15:6f2798e45099 | 200 | * \details The results of the write do not have anything to do with the data |
ampembeng | 15:6f2798e45099 | 201 | * arriving at the endpoint. |
ampembeng | 15:6f2798e45099 | 202 | */ |
ampembeng | 15:6f2798e45099 | 203 | bool write(uint16_t numSock, const char * s, uint32_t n); |
ampembeng | 15:6f2798e45099 | 204 | |
ampembeng | 15:6f2798e45099 | 205 | /** |
ampembeng | 15:6f2798e45099 | 206 | * \brief Poll and read back data from the WNC (if it has any) |
ampembeng | 15:6f2798e45099 | 207 | * If auto poll is enabled this read might fail (return with no data). |
ampembeng | 15:6f2798e45099 | 208 | * |
ampembeng | 15:6f2798e45099 | 209 | * \param [in] sockNum - the number of the socket to read. result - a string pointer containing |
ampembeng | 15:6f2798e45099 | 210 | * the byte data readback from the WNC. |
ampembeng | 15:6f2798e45099 | 211 | * |
ampembeng | 15:6f2798e45099 | 212 | * \return The number of bytes/chars that are read from the socket. |
ampembeng | 15:6f2798e45099 | 213 | * |
ampembeng | 15:6f2798e45099 | 214 | * \details DO NOT use the same string as is passed to the auto poll setup method! |
ampembeng | 15:6f2798e45099 | 215 | */ |
ampembeng | 15:6f2798e45099 | 216 | size_t read(uint16_t numSock, uint8_t * readBuf, uint32_t maxReadBufLen); |
ampembeng | 15:6f2798e45099 | 217 | |
ampembeng | 15:6f2798e45099 | 218 | size_t read(uint16_t numSock, const uint8_t ** readBuf); |
ampembeng | 15:6f2798e45099 | 219 | |
ampembeng | 15:6f2798e45099 | 220 | /** |
ampembeng | 15:6f2798e45099 | 221 | * \brief Set how many times the above read method will retry if data is not returned. |
ampembeng | 15:6f2798e45099 | 222 | * |
ampembeng | 15:6f2798e45099 | 223 | * \param [in] sockNum - the number of the socket to set. retries - how many times to |
ampembeng | 15:6f2798e45099 | 224 | * poll until data is found. |
ampembeng | 15:6f2798e45099 | 225 | * |
ampembeng | 15:6f2798e45099 | 226 | * \return None. |
ampembeng | 15:6f2798e45099 | 227 | * |
ampembeng | 15:6f2798e45099 | 228 | * \details None. |
ampembeng | 15:6f2798e45099 | 229 | */ |
ampembeng | 15:6f2798e45099 | 230 | void setReadRetries(uint16_t numSock, uint16_t retries); |
ampembeng | 15:6f2798e45099 | 231 | |
ampembeng | 15:6f2798e45099 | 232 | /** |
ampembeng | 15:6f2798e45099 | 233 | * \brief Set how long between retries to wait. |
ampembeng | 15:6f2798e45099 | 234 | * |
ampembeng | 15:6f2798e45099 | 235 | * \param [in] sockNum - the number of the socket to set. waitMs - how long to wait |
ampembeng | 15:6f2798e45099 | 236 | * before doing the read poll (calling read(...)). |
ampembeng | 15:6f2798e45099 | 237 | * |
ampembeng | 15:6f2798e45099 | 238 | * \return None. |
ampembeng | 15:6f2798e45099 | 239 | * |
ampembeng | 15:6f2798e45099 | 240 | * \details None. |
ampembeng | 15:6f2798e45099 | 241 | */ |
ampembeng | 15:6f2798e45099 | 242 | void setReadRetryWait(uint16_t numSock, uint16_t waitMs); |
ampembeng | 15:6f2798e45099 | 243 | |
ampembeng | 15:6f2798e45099 | 244 | /** |
ampembeng | 15:6f2798e45099 | 245 | * \brief Close the socket. |
ampembeng | 15:6f2798e45099 | 246 | * |
ampembeng | 15:6f2798e45099 | 247 | * \param [in] sockNum - the number of the socket to close. |
ampembeng | 15:6f2798e45099 | 248 | * |
ampembeng | 15:6f2798e45099 | 249 | * \return None. |
ampembeng | 15:6f2798e45099 | 250 | * |
ampembeng | 15:6f2798e45099 | 251 | * \details None. |
ampembeng | 15:6f2798e45099 | 252 | */ |
ampembeng | 15:6f2798e45099 | 253 | bool closeSocket(uint16_t numSock); |
ampembeng | 15:6f2798e45099 | 254 | |
ampembeng | 15:6f2798e45099 | 255 | void setWncCmdTimeout(uint16_t toMs); |
ampembeng | 15:6f2798e45099 | 256 | |
ampembeng | 15:6f2798e45099 | 257 | bool getIpAddr(uint16_t numSock, char myIpAddr[MAX_LEN_IP_STR]); |
ampembeng | 15:6f2798e45099 | 258 | |
ampembeng | 15:6f2798e45099 | 259 | void enableDebug(bool on, bool moreDebugOn); |
ampembeng | 15:6f2798e45099 | 260 | |
ampembeng | 15:6f2798e45099 | 261 | /////////////////////////////////////////// |
ampembeng | 15:6f2798e45099 | 262 | // SMS messaging |
ampembeng | 15:6f2798e45099 | 263 | /////////////////////////////////////////// |
ampembeng | 15:6f2798e45099 | 264 | |
ampembeng | 15:6f2798e45099 | 265 | static const uint16_t MAX_WNC_SMS_MSG_SLOTS = 3; // How many SMS messages the WNC can store and receive at a time. |
ampembeng | 15:6f2798e45099 | 266 | static const uint16_t MAX_WNC_SMS_LENGTH = 160; // The maximum length of a 7-bit SMS message the WNC can send and receive. |
ampembeng | 15:6f2798e45099 | 267 | |
ampembeng | 15:6f2798e45099 | 268 | struct WncSmsInfo |
ampembeng | 15:6f2798e45099 | 269 | { |
ampembeng | 15:6f2798e45099 | 270 | // Content |
ampembeng | 15:6f2798e45099 | 271 | char idx; |
ampembeng | 15:6f2798e45099 | 272 | string number; |
ampembeng | 15:6f2798e45099 | 273 | string date; |
ampembeng | 15:6f2798e45099 | 274 | string time; |
ampembeng | 15:6f2798e45099 | 275 | string msg; |
ampembeng | 15:6f2798e45099 | 276 | |
ampembeng | 15:6f2798e45099 | 277 | // Attributes |
ampembeng | 15:6f2798e45099 | 278 | bool incoming; |
ampembeng | 15:6f2798e45099 | 279 | bool unsent; |
ampembeng | 15:6f2798e45099 | 280 | bool unread; |
ampembeng | 15:6f2798e45099 | 281 | bool pduMode; |
ampembeng | 15:6f2798e45099 | 282 | bool msgReceipt; |
ampembeng | 15:6f2798e45099 | 283 | }; |
ampembeng | 15:6f2798e45099 | 284 | |
ampembeng | 15:6f2798e45099 | 285 | struct WncSmsList |
ampembeng | 15:6f2798e45099 | 286 | { |
ampembeng | 15:6f2798e45099 | 287 | uint8_t msgCount; |
ampembeng | 15:6f2798e45099 | 288 | WncSmsInfo e[MAX_WNC_SMS_MSG_SLOTS]; |
ampembeng | 15:6f2798e45099 | 289 | }; |
ampembeng | 15:6f2798e45099 | 290 | |
ampembeng | 15:6f2798e45099 | 291 | bool sendSMSText(const char * const phoneNum, const char * const text); |
ampembeng | 15:6f2798e45099 | 292 | |
ampembeng | 15:6f2798e45099 | 293 | bool readSMSLog(struct WncSmsList * log); |
ampembeng | 15:6f2798e45099 | 294 | |
ampembeng | 15:6f2798e45099 | 295 | bool readUnreadSMSText(struct WncSmsList * w, bool deleteRead = true); |
ampembeng | 15:6f2798e45099 | 296 | |
ampembeng | 15:6f2798e45099 | 297 | bool saveSMSText(const char * const phoneNum, const char * const text, char * msgIdx); |
ampembeng | 15:6f2798e45099 | 298 | |
ampembeng | 15:6f2798e45099 | 299 | bool sendSMSTextFromMem(char msgIdx); |
ampembeng | 15:6f2798e45099 | 300 | |
ampembeng | 15:6f2798e45099 | 301 | bool deleteSMSTextFromMem(char msgIdx); |
ampembeng | 15:6f2798e45099 | 302 | |
ampembeng | 15:6f2798e45099 | 303 | bool getICCID(string * iccid); |
ampembeng | 15:6f2798e45099 | 304 | |
ampembeng | 15:6f2798e45099 | 305 | bool convertICCIDtoMSISDN(const string & iccid, string * msisdn); |
ampembeng | 15:6f2798e45099 | 306 | |
ampembeng | 15:6f2798e45099 | 307 | /////////////////////////////////////////// |
ampembeng | 15:6f2798e45099 | 308 | // Neighborhood Cell Info |
ampembeng | 15:6f2798e45099 | 309 | /////////////////////////////////////////// |
ampembeng | 15:6f2798e45099 | 310 | size_t getSignalQuality(const char ** log); |
ampembeng | 15:6f2798e45099 | 311 | |
ampembeng | 15:6f2798e45099 | 312 | // Date Time |
ampembeng | 15:6f2798e45099 | 313 | struct WncDateTime |
ampembeng | 15:6f2798e45099 | 314 | { |
ampembeng | 15:6f2798e45099 | 315 | uint8_t year; |
ampembeng | 15:6f2798e45099 | 316 | uint8_t month; |
ampembeng | 15:6f2798e45099 | 317 | uint8_t day; |
ampembeng | 15:6f2798e45099 | 318 | uint8_t hour; |
ampembeng | 15:6f2798e45099 | 319 | uint8_t min; |
ampembeng | 15:6f2798e45099 | 320 | uint8_t sec; |
ampembeng | 15:6f2798e45099 | 321 | }; |
ampembeng | 15:6f2798e45099 | 322 | |
ampembeng | 15:6f2798e45099 | 323 | bool getTimeDate(struct WncDateTime * tod); |
ampembeng | 15:6f2798e45099 | 324 | |
ampembeng | 15:6f2798e45099 | 325 | // Ping |
ampembeng | 15:6f2798e45099 | 326 | bool pingUrl(const char * url); |
ampembeng | 15:6f2798e45099 | 327 | bool pingIp(const char * ip); |
ampembeng | 15:6f2798e45099 | 328 | |
ampembeng | 15:6f2798e45099 | 329 | // User command: |
ampembeng | 15:6f2798e45099 | 330 | size_t sendCustomCmd(const char * cmd, char * resp, size_t sizeRespBuf, int ms_timeout); |
ampembeng | 15:6f2798e45099 | 331 | |
ampembeng | 15:6f2798e45099 | 332 | protected: |
ampembeng | 15:6f2798e45099 | 333 | |
ampembeng | 15:6f2798e45099 | 334 | // Debug output methods |
ampembeng | 15:6f2798e45099 | 335 | int dbgPutsNoTime(const char * s, bool crlf = true); |
ampembeng | 15:6f2798e45099 | 336 | int dbgPuts(const char * s, bool crlf = true); |
ampembeng | 15:6f2798e45099 | 337 | const char * _to_string(int64_t value); |
ampembeng | 15:6f2798e45099 | 338 | const char * _to_hex_string(uint8_t value); |
ampembeng | 15:6f2798e45099 | 339 | |
ampembeng | 15:6f2798e45099 | 340 | // Sends commands to WNC via |
ampembeng | 15:6f2798e45099 | 341 | enum AtCmdErr_e { |
ampembeng | 15:6f2798e45099 | 342 | WNC_AT_CMD_OK, |
ampembeng | 15:6f2798e45099 | 343 | WNC_AT_CMD_ERR, |
ampembeng | 15:6f2798e45099 | 344 | WNC_AT_CMD_ERREXT, |
ampembeng | 15:6f2798e45099 | 345 | WNC_AT_CMD_ERRCME, |
ampembeng | 15:6f2798e45099 | 346 | WNC_AT_CMD_INVALID_RESPONSE, |
ampembeng | 15:6f2798e45099 | 347 | WNC_AT_CMD_TIMEOUT, |
ampembeng | 15:6f2798e45099 | 348 | WNC_AT_CMD_NO_CELL_LINK, |
ampembeng | 15:6f2798e45099 | 349 | WNC_AT_CMD_WNC_NOT_ON |
ampembeng | 15:6f2798e45099 | 350 | }; |
ampembeng | 15:6f2798e45099 | 351 | |
ampembeng | 15:6f2798e45099 | 352 | // Users must define these functionalities: |
ampembeng | 15:6f2798e45099 | 353 | virtual int putc(char c) = 0; |
ampembeng | 15:6f2798e45099 | 354 | virtual int puts(const char * s) = 0; |
ampembeng | 15:6f2798e45099 | 355 | virtual char getc(void) = 0; |
ampembeng | 15:6f2798e45099 | 356 | virtual int charReady(void) = 0; |
ampembeng | 15:6f2798e45099 | 357 | virtual int dbgWriteChar(char b) = 0; |
ampembeng | 15:6f2798e45099 | 358 | virtual int dbgWriteChars(const char *b) = 0; |
ampembeng | 15:6f2798e45099 | 359 | virtual void waitMs(int t) = 0; |
ampembeng | 15:6f2798e45099 | 360 | virtual void waitUs(int t) = 0; |
ampembeng | 15:6f2798e45099 | 361 | virtual bool initWncModem(uint8_t powerUpTimeoutSecs) = 0; |
ampembeng | 15:6f2798e45099 | 362 | |
ampembeng | 15:6f2798e45099 | 363 | // Isolate OS timers |
ampembeng | 15:6f2798e45099 | 364 | virtual int getLogTimerTicks(void) = 0; |
ampembeng | 15:6f2798e45099 | 365 | virtual void startTimerA(void) = 0; |
ampembeng | 15:6f2798e45099 | 366 | virtual void stopTimerA(void) = 0; |
ampembeng | 15:6f2798e45099 | 367 | virtual int getTimerTicksA_mS(void) = 0; |
ampembeng | 15:6f2798e45099 | 368 | virtual void startTimerB(void) = 0; |
ampembeng | 15:6f2798e45099 | 369 | virtual void stopTimerB(void) = 0; |
ampembeng | 15:6f2798e45099 | 370 | virtual int getTimerTicksB_mS(void) = 0; |
ampembeng | 15:6f2798e45099 | 371 | |
ampembeng | 15:6f2798e45099 | 372 | bool waitForPowerOnModemToRespond(uint8_t powerUpTimeoutSecs); |
ampembeng | 15:6f2798e45099 | 373 | AtCmdErr_e sendWncCmd(const char * const s, string ** r, int ms_timeout); |
ampembeng | 15:6f2798e45099 | 374 | |
ampembeng | 15:6f2798e45099 | 375 | private: |
ampembeng | 15:6f2798e45099 | 376 | |
ampembeng | 15:6f2798e45099 | 377 | bool softwareInitMdm(void); |
ampembeng | 15:6f2798e45099 | 378 | bool checkCellLink(void); |
ampembeng | 15:6f2798e45099 | 379 | AtCmdErr_e mdmSendAtCmdRsp(const char * cmd, int timeout_ms, string * rsp, bool crLf = true); |
ampembeng | 15:6f2798e45099 | 380 | size_t mdmGetline(string * buff, int timeout_ms); |
ampembeng | 15:6f2798e45099 | 381 | bool at_at_wnc(void); |
ampembeng | 15:6f2798e45099 | 382 | bool at_init_wnc(bool hardReset = false); |
ampembeng | 15:6f2798e45099 | 383 | int16_t at_sockopen_wnc(const char * const ip, uint16_t port, uint16_t numSock, bool tcp, uint16_t timeOutSec); |
ampembeng | 15:6f2798e45099 | 384 | bool at_sockclose_wnc(uint16_t numSock); |
ampembeng | 15:6f2798e45099 | 385 | bool at_dnsresolve_wnc(const char * s, string * ipStr); |
ampembeng | 15:6f2798e45099 | 386 | AtCmdErr_e at_sockwrite_wnc(const char * s, uint16_t n, uint16_t numSock, bool isTcp); |
ampembeng | 15:6f2798e45099 | 387 | AtCmdErr_e at_sockread_wnc(uint8_t * pS, uint16_t * numRead, uint16_t n, uint16_t numSock, bool isTcp); |
ampembeng | 15:6f2798e45099 | 388 | AtCmdErr_e at_sockread_wnc(string * pS, uint16_t numSock, bool isTcp); |
ampembeng | 15:6f2798e45099 | 389 | bool at_reinitialize_mdm(void); |
ampembeng | 15:6f2798e45099 | 390 | AtCmdErr_e at_send_wnc_cmd(const char * s, string ** r, int ms_timeout); |
ampembeng | 15:6f2798e45099 | 391 | bool at_setapn_wnc(const char * const apnStr); |
ampembeng | 15:6f2798e45099 | 392 | bool at_sendSMStext_wnc(const char * const phoneNum, const char * const text); |
ampembeng | 15:6f2798e45099 | 393 | bool at_get_wnc_net_stats(WncIpStats * s); |
ampembeng | 15:6f2798e45099 | 394 | bool at_readSMSlog_wnc(string ** log); |
ampembeng | 15:6f2798e45099 | 395 | size_t at_readSMStext_wnc(const char ** log); |
ampembeng | 15:6f2798e45099 | 396 | size_t at_readSMStext_wnc(const char n, const char ** log); |
ampembeng | 15:6f2798e45099 | 397 | bool at_getrssiber_wnc(int16_t * dBm, int16_t * ber3g); |
ampembeng | 15:6f2798e45099 | 398 | void closeOpenSocket(uint16_t numSock); |
ampembeng | 15:6f2798e45099 | 399 | bool sockWrite(const char * const s, uint16_t n, uint16_t numSock, bool isTcp); |
ampembeng | 15:6f2798e45099 | 400 | bool at_sendSMStextMem_wnc(char n); |
ampembeng | 15:6f2798e45099 | 401 | bool at_deleteSMSTextFromMem_wnc(char n); |
ampembeng | 15:6f2798e45099 | 402 | bool at_saveSMStext_wnc(const char * const phoneNum, const char * const text, char * msgIdx); |
ampembeng | 15:6f2798e45099 | 403 | size_t at_getSignalQuality_wnc(const char ** log); |
ampembeng | 15:6f2798e45099 | 404 | bool at_gettimedate_wnc(struct WncDateTime * tod); |
ampembeng | 15:6f2798e45099 | 405 | bool at_ping_wnc(const char * ip); |
ampembeng | 15:6f2798e45099 | 406 | bool at_geticcid_wnc(string * iccid); |
ampembeng | 15:6f2798e45099 | 407 | |
ampembeng | 15:6f2798e45099 | 408 | // Utility methods |
ampembeng | 15:6f2798e45099 | 409 | void sendCmd(const char * cmd, bool crLf); |
ampembeng | 15:6f2798e45099 | 410 | void sendCmd(const char * cmd, unsigned n, unsigned wait_uS, bool crLf); |
ampembeng | 15:6f2798e45099 | 411 | inline void rx_char_wait(void) { |
ampembeng | 15:6f2798e45099 | 412 | // waitUs(1000); |
ampembeng | 15:6f2798e45099 | 413 | } |
ampembeng | 15:6f2798e45099 | 414 | |
ampembeng | 15:6f2798e45099 | 415 | // Important constants |
ampembeng | 15:6f2798e45099 | 416 | static const uint16_t MAX_WNC_READ_BYTES = 1500; // This bounds the largest amount of data that the WNC read from a socket will return |
ampembeng | 15:6f2798e45099 | 417 | static const uint16_t MAX_WNC_WRITE_BYTES = MAX_WNC_READ_BYTES; // This is the largest amount of data that the WNC can write per sockwrite. |
ampembeng | 15:6f2798e45099 | 418 | static const uint16_t MAX_LEN_WNC_CMD_RESPONSE = (MAX_WNC_READ_BYTES * 2 + 100); // Max number of text characters in a WNC AT response *2 because bytes are converted into 2 hex-digits +100 for other AT@ chars. |
ampembeng | 15:6f2798e45099 | 419 | static const uint16_t WNC_AUTO_POLL_MS = 250; // Sets default (may be overriden with method) poll interval (currently not used, future possible feature. |
ampembeng | 15:6f2798e45099 | 420 | static const uint16_t WNC_CMD_TIMEOUT_MS = 40000; // Sets default (may be overriden) time that the software waits for an AT response from the WNC. |
ampembeng | 15:6f2798e45099 | 421 | static const uint16_t WNC_QUICK_CMD_TIMEOUT_MS = 2000; // Used for simple commands that should immediately respond such as "AT", cmds that are quicker than WNC_CMD_TIMEOUT_MS. |
ampembeng | 15:6f2798e45099 | 422 | static const uint16_t WNC_WAIT_FOR_AT_CMD_MS = 0; // Wait this much between multiple in a row AT commands to the WNC. |
ampembeng | 15:6f2798e45099 | 423 | static const uint16_t WNC_SOFT_INIT_RETRY_COUNT = 10; // How many times the WNC will be tried to revive if it stops responding. |
ampembeng | 15:6f2798e45099 | 424 | static const uint16_t WNC_DNS_RESOLVE_WAIT_MS = 60000; // How much time to wait for the WNC to respond to a DNS resolve/lookup. |
ampembeng | 15:6f2798e45099 | 425 | static const uint16_t WNC_TRUNC_DEBUG_LENGTH = 80; // Always make this an even number, how many chars for the debug output before shortening the debug ouput, this is used when moreDebug = false. |
ampembeng | 15:6f2798e45099 | 426 | static const uint16_t WNC_APNSET_TIMEOUT_MS = 60000; // How long to wait for the WNC to respond to setting the APN string. |
ampembeng | 15:6f2798e45099 | 427 | static const uint16_t WNC_PING_CMD_TIMEOUT_MS = 60000; // Amount of time to wait for the WNC to respond to AT@PINGREQ (with cmd default params for timeout, does not change WNC cmd's timeout) |
ampembeng | 15:6f2798e45099 | 428 | static const int WNC_REINIT_MAX_TIME_MS = 60000; // How long to wait for the WNC to reset after it was already up and running after power-up. |
ampembeng | 15:6f2798e45099 | 429 | static const uint16_t WNC_SOCK_CLOSE_RETRY_CNT = 3; // How many times to try to close the socket if the WNC gives an error. |
ampembeng | 15:6f2798e45099 | 430 | static const char * const INVALID_IP_STR; // Just a string set to an IP address when DNS resolve fails. |
ampembeng | 15:6f2798e45099 | 431 | |
ampembeng | 15:6f2798e45099 | 432 | struct WncSocketInfo_s { |
ampembeng | 15:6f2798e45099 | 433 | int16_t numWncSock; |
ampembeng | 15:6f2798e45099 | 434 | bool open; |
ampembeng | 15:6f2798e45099 | 435 | string myIpAddressStr; |
ampembeng | 15:6f2798e45099 | 436 | uint16_t myPort; |
ampembeng | 15:6f2798e45099 | 437 | uint8_t readRetries; |
ampembeng | 15:6f2798e45099 | 438 | uint16_t readRetryWaitMs; |
ampembeng | 15:6f2798e45099 | 439 | bool isTcp; |
ampembeng | 15:6f2798e45099 | 440 | uint16_t timeOutSec; |
ampembeng | 15:6f2798e45099 | 441 | }; |
ampembeng | 15:6f2798e45099 | 442 | |
ampembeng | 15:6f2798e45099 | 443 | static WncSocketInfo_s m_sSock[MAX_NUM_WNC_SOCKETS]; |
ampembeng | 15:6f2798e45099 | 444 | static const WncSocketInfo_s defaultSockStruct; |
ampembeng | 15:6f2798e45099 | 445 | static WncState_e m_sState; |
ampembeng | 15:6f2798e45099 | 446 | static uint16_t m_sCmdTimeoutMs; |
ampembeng | 15:6f2798e45099 | 447 | static string m_sApnStr; |
ampembeng | 15:6f2798e45099 | 448 | static string m_sWncStr; |
ampembeng | 15:6f2798e45099 | 449 | static uint8_t m_sPowerUpTimeoutSecs; |
ampembeng | 15:6f2798e45099 | 450 | static bool m_sDebugEnabled; |
ampembeng | 15:6f2798e45099 | 451 | static bool m_sMoreDebugEnabled; |
ampembeng | 15:6f2798e45099 | 452 | static bool m_sCheckNetStatus; |
ampembeng | 15:6f2798e45099 | 453 | static bool m_sReadyForSMS; |
ampembeng | 15:6f2798e45099 | 454 | }; |
ampembeng | 15:6f2798e45099 | 455 | |
ampembeng | 15:6f2798e45099 | 456 | }; // End namespace WncController_fk |
ampembeng | 15:6f2798e45099 | 457 | |
ampembeng | 15:6f2798e45099 | 458 | #endif |