wifi test
Dependencies: X_NUCLEO_IKS01A2 mbed-http
easy-connect/wnc14a2a-driver/WNC14A2AInterface/WncControllerK64F/WncController/WncController.h@0:24d3eb812fd4, 2018-09-05 (annotated)
- Committer:
- JMF
- Date:
- Wed Sep 05 14:28:24 2018 +0000
- Revision:
- 0:24d3eb812fd4
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JMF | 0:24d3eb812fd4 | 1 | /** |
JMF | 0:24d3eb812fd4 | 2 | Copyright (c) 2016 Fred Kellerman |
JMF | 0:24d3eb812fd4 | 3 | |
JMF | 0:24d3eb812fd4 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
JMF | 0:24d3eb812fd4 | 5 | of this software and associated documentation files (the "Software"), to deal |
JMF | 0:24d3eb812fd4 | 6 | in the Software without restriction, including without limitation the rights |
JMF | 0:24d3eb812fd4 | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
JMF | 0:24d3eb812fd4 | 8 | copies of the Software, and to permit persons to whom the Software is |
JMF | 0:24d3eb812fd4 | 9 | furnished to do so, subject to the following conditions: |
JMF | 0:24d3eb812fd4 | 10 | |
JMF | 0:24d3eb812fd4 | 11 | The above copyright notice and this permission notice shall be included in |
JMF | 0:24d3eb812fd4 | 12 | all copies or substantial portions of the Software. |
JMF | 0:24d3eb812fd4 | 13 | |
JMF | 0:24d3eb812fd4 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
JMF | 0:24d3eb812fd4 | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
JMF | 0:24d3eb812fd4 | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
JMF | 0:24d3eb812fd4 | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
JMF | 0:24d3eb812fd4 | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
JMF | 0:24d3eb812fd4 | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
JMF | 0:24d3eb812fd4 | 20 | THE SOFTWARE. |
JMF | 0:24d3eb812fd4 | 21 | |
JMF | 0:24d3eb812fd4 | 22 | @file WncController.h |
JMF | 0:24d3eb812fd4 | 23 | @purpose Controls WNC Cellular Modem |
JMF | 0:24d3eb812fd4 | 24 | @version 1.0 |
JMF | 0:24d3eb812fd4 | 25 | @date July 2016 |
JMF | 0:24d3eb812fd4 | 26 | @author Fred Kellerman |
JMF | 0:24d3eb812fd4 | 27 | |
JMF | 0:24d3eb812fd4 | 28 | Notes: This code originates from the following mbed repository: |
JMF | 0:24d3eb812fd4 | 29 | |
JMF | 0:24d3eb812fd4 | 30 | https://developer.mbed.org/teams/Avnet/code/WncControllerLibrary/ |
JMF | 0:24d3eb812fd4 | 31 | */ |
JMF | 0:24d3eb812fd4 | 32 | |
JMF | 0:24d3eb812fd4 | 33 | |
JMF | 0:24d3eb812fd4 | 34 | #ifndef __WNCCONTROLLER_H_ |
JMF | 0:24d3eb812fd4 | 35 | #define __WNCCONTROLLER_H_ |
JMF | 0:24d3eb812fd4 | 36 | |
JMF | 0:24d3eb812fd4 | 37 | #include <string> |
JMF | 0:24d3eb812fd4 | 38 | #include <stdint.h> |
JMF | 0:24d3eb812fd4 | 39 | |
JMF | 0:24d3eb812fd4 | 40 | namespace WncController_fk { |
JMF | 0:24d3eb812fd4 | 41 | |
JMF | 0:24d3eb812fd4 | 42 | using namespace std; |
JMF | 0:24d3eb812fd4 | 43 | |
JMF | 0:24d3eb812fd4 | 44 | /** @defgroup API The WncControllerLibrary API */ |
JMF | 0:24d3eb812fd4 | 45 | /** @defgroup MISC Misc WncControllerLibrary functions */ |
JMF | 0:24d3eb812fd4 | 46 | /** @defgroup INTERNALS WncControllerLibrary Internals */ |
JMF | 0:24d3eb812fd4 | 47 | |
JMF | 0:24d3eb812fd4 | 48 | static const uint8_t MAX_LEN_IP_STR = 16; // Length includes room for the extra NULL |
JMF | 0:24d3eb812fd4 | 49 | |
JMF | 0:24d3eb812fd4 | 50 | /** \brief Contains info fields for the WNC Internet Attributes */ |
JMF | 0:24d3eb812fd4 | 51 | struct WncIpStats |
JMF | 0:24d3eb812fd4 | 52 | { |
JMF | 0:24d3eb812fd4 | 53 | string wncMAC; |
JMF | 0:24d3eb812fd4 | 54 | char ip[MAX_LEN_IP_STR]; |
JMF | 0:24d3eb812fd4 | 55 | char mask[MAX_LEN_IP_STR]; |
JMF | 0:24d3eb812fd4 | 56 | char gateway[MAX_LEN_IP_STR]; |
JMF | 0:24d3eb812fd4 | 57 | char dnsPrimary[MAX_LEN_IP_STR]; |
JMF | 0:24d3eb812fd4 | 58 | char dnsSecondary[MAX_LEN_IP_STR]; |
JMF | 0:24d3eb812fd4 | 59 | }; |
JMF | 0:24d3eb812fd4 | 60 | |
JMF | 0:24d3eb812fd4 | 61 | |
JMF | 0:24d3eb812fd4 | 62 | /** |
JMF | 0:24d3eb812fd4 | 63 | * @author Fred Kellerman |
JMF | 0:24d3eb812fd4 | 64 | * @see API |
JMF | 0:24d3eb812fd4 | 65 | * |
JMF | 0:24d3eb812fd4 | 66 | * <b>WncController</b> This mbed C++ class is for controlling the WNC |
JMF | 0:24d3eb812fd4 | 67 | * Cellular modem via the serial AT command interface. This was |
JMF | 0:24d3eb812fd4 | 68 | * developed with respect to version 1.3 of the WNC authored |
JMF | 0:24d3eb812fd4 | 69 | * unpublished spec. This class is only designed to have 1 instantiation, |
JMF | 0:24d3eb812fd4 | 70 | * it is also not multi-thread safe. There are no OS specific |
JMF | 0:24d3eb812fd4 | 71 | * entities being used, there are pure virtual methods that an |
JMF | 0:24d3eb812fd4 | 72 | * inheriting class must fulfill. That inheriting class will have |
JMF | 0:24d3eb812fd4 | 73 | * OS and platform specific entities. See WncControllerK64F for an |
JMF | 0:24d3eb812fd4 | 74 | * example for the NXP K64F Freedom board. |
JMF | 0:24d3eb812fd4 | 75 | */ |
JMF | 0:24d3eb812fd4 | 76 | class WncController |
JMF | 0:24d3eb812fd4 | 77 | { |
JMF | 0:24d3eb812fd4 | 78 | public: |
JMF | 0:24d3eb812fd4 | 79 | |
JMF | 0:24d3eb812fd4 | 80 | static const unsigned MAX_NUM_WNC_SOCKETS = 5; // Max number of simultaneous sockets that the WNC supports |
JMF | 0:24d3eb812fd4 | 81 | static const unsigned MAX_POWERUP_TIMEOUT = 60; // How long the powerUp method will try to turn on the WNC Shield |
JMF | 0:24d3eb812fd4 | 82 | // (this is the default if the user does not over-ride on power-up |
JMF | 0:24d3eb812fd4 | 83 | |
JMF | 0:24d3eb812fd4 | 84 | /** Tracks mode of the WNC Shield hardware */ |
JMF | 0:24d3eb812fd4 | 85 | enum WncState_e { |
JMF | 0:24d3eb812fd4 | 86 | WNC_OFF = 0, |
JMF | 0:24d3eb812fd4 | 87 | WNC_ON, // This is intended to mean all systems go, including cell link up but socket may not be open |
JMF | 0:24d3eb812fd4 | 88 | WNC_ON_NO_CELL_LINK, |
JMF | 0:24d3eb812fd4 | 89 | WNC_NO_RESPONSE |
JMF | 0:24d3eb812fd4 | 90 | }; |
JMF | 0:24d3eb812fd4 | 91 | |
JMF | 0:24d3eb812fd4 | 92 | /** |
JMF | 0:24d3eb812fd4 | 93 | * |
JMF | 0:24d3eb812fd4 | 94 | * Constructor for WncController class, sets up internals. |
JMF | 0:24d3eb812fd4 | 95 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 96 | * @return none. |
JMF | 0:24d3eb812fd4 | 97 | */ |
JMF | 0:24d3eb812fd4 | 98 | WncController(void); |
JMF | 0:24d3eb812fd4 | 99 | virtual ~WncController()=0; |
JMF | 0:24d3eb812fd4 | 100 | |
JMF | 0:24d3eb812fd4 | 101 | /** |
JMF | 0:24d3eb812fd4 | 102 | * |
JMF | 0:24d3eb812fd4 | 103 | * Used internally but also make public for a user of the Class to |
JMF | 0:24d3eb812fd4 | 104 | * interrogate state as well. |
JMF | 0:24d3eb812fd4 | 105 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 106 | * @return the current state of the Wnc hardware. |
JMF | 0:24d3eb812fd4 | 107 | */ |
JMF | 0:24d3eb812fd4 | 108 | WncState_e getWncStatus(void); |
JMF | 0:24d3eb812fd4 | 109 | |
JMF | 0:24d3eb812fd4 | 110 | /** |
JMF | 0:24d3eb812fd4 | 111 | * |
JMF | 0:24d3eb812fd4 | 112 | * Allows a user to set the WNC modem to use the given Cellular APN |
JMF | 0:24d3eb812fd4 | 113 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 114 | * @param apnStr - a null terminated c-string |
JMF | 0:24d3eb812fd4 | 115 | * @return true if the APN set was succesful, else false |
JMF | 0:24d3eb812fd4 | 116 | */ |
JMF | 0:24d3eb812fd4 | 117 | bool setApnName(const char * const apnStr); |
JMF | 0:24d3eb812fd4 | 118 | |
JMF | 0:24d3eb812fd4 | 119 | /** |
JMF | 0:24d3eb812fd4 | 120 | * |
JMF | 0:24d3eb812fd4 | 121 | * Queries the WNC modem for the current RX RSSI in units of coded dBm |
JMF | 0:24d3eb812fd4 | 122 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 123 | * @return 0 – -113 dBm or less |
JMF | 0:24d3eb812fd4 | 124 | * 1 – -111 dBm |
JMF | 0:24d3eb812fd4 | 125 | * 2...30 – -109 dBm to –53 dBm |
JMF | 0:24d3eb812fd4 | 126 | * 31 – -51 dBm or greater |
JMF | 0:24d3eb812fd4 | 127 | * 99 – not known or not detectable |
JMF | 0:24d3eb812fd4 | 128 | */ |
JMF | 0:24d3eb812fd4 | 129 | int16_t getDbmRssi(void); |
JMF | 0:24d3eb812fd4 | 130 | |
JMF | 0:24d3eb812fd4 | 131 | /** |
JMF | 0:24d3eb812fd4 | 132 | * |
JMF | 0:24d3eb812fd4 | 133 | * Queries the WNC modem for the current Bit Error Rate |
JMF | 0:24d3eb812fd4 | 134 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 135 | * @return 0...7 – as RXQUAL values in the table in 3GPP TS 45.008 |
JMF | 0:24d3eb812fd4 | 136 | * subclause 8.2.4 |
JMF | 0:24d3eb812fd4 | 137 | * 99 – not known or not detectable |
JMF | 0:24d3eb812fd4 | 138 | */ |
JMF | 0:24d3eb812fd4 | 139 | int16_t get3gBer(void); |
JMF | 0:24d3eb812fd4 | 140 | |
JMF | 0:24d3eb812fd4 | 141 | /** |
JMF | 0:24d3eb812fd4 | 142 | * |
JMF | 0:24d3eb812fd4 | 143 | * Powers up the WNC modem |
JMF | 0:24d3eb812fd4 | 144 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 145 | * @param apn - the apn c-string to set the WNC modem to use |
JMF | 0:24d3eb812fd4 | 146 | * @param powerUpTimeoutSecs - the amount of time to wait for the WNC modem to turn on |
JMF | 0:24d3eb812fd4 | 147 | * @return true if powerup was a success, else false. |
JMF | 0:24d3eb812fd4 | 148 | */ |
JMF | 0:24d3eb812fd4 | 149 | bool powerWncOn(const char * const apn, uint8_t powerUpTimeoutSecs = MAX_POWERUP_TIMEOUT); |
JMF | 0:24d3eb812fd4 | 150 | |
JMF | 0:24d3eb812fd4 | 151 | /** |
JMF | 0:24d3eb812fd4 | 152 | * |
JMF | 0:24d3eb812fd4 | 153 | * Returns the NAT Self, gateway, masks and dns IP |
JMF | 0:24d3eb812fd4 | 154 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 155 | * @param s - a pointer to a struct that will contain the IP info. |
JMF | 0:24d3eb812fd4 | 156 | * @return true if success, else false. |
JMF | 0:24d3eb812fd4 | 157 | */ |
JMF | 0:24d3eb812fd4 | 158 | bool getWncNetworkingStats(WncIpStats * s); |
JMF | 0:24d3eb812fd4 | 159 | |
JMF | 0:24d3eb812fd4 | 160 | /** |
JMF | 0:24d3eb812fd4 | 161 | * |
JMF | 0:24d3eb812fd4 | 162 | * Takes a text URL and converts it internally to an IP address for the |
JMF | 0:24d3eb812fd4 | 163 | * socket number given. |
JMF | 0:24d3eb812fd4 | 164 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 165 | * @param numSock - The number of the socket to lookup the IP address for. |
JMF | 0:24d3eb812fd4 | 166 | * @param url - a c-string text URL |
JMF | 0:24d3eb812fd4 | 167 | * @return true if success, else false. |
JMF | 0:24d3eb812fd4 | 168 | */ |
JMF | 0:24d3eb812fd4 | 169 | bool resolveUrl(uint16_t numSock, const char * url); |
JMF | 0:24d3eb812fd4 | 170 | |
JMF | 0:24d3eb812fd4 | 171 | /** |
JMF | 0:24d3eb812fd4 | 172 | * |
JMF | 0:24d3eb812fd4 | 173 | * If you know the IP address you can set the socket up to use it rather |
JMF | 0:24d3eb812fd4 | 174 | * than using a text URL. |
JMF | 0:24d3eb812fd4 | 175 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 176 | * @param numSock - The number of the socket to use the IP address for. |
JMF | 0:24d3eb812fd4 | 177 | * @param ipStr - a c-string text IP addrese like: 192.168.0.1 |
JMF | 0:24d3eb812fd4 | 178 | * @return true if success, else false. |
JMF | 0:24d3eb812fd4 | 179 | */ |
JMF | 0:24d3eb812fd4 | 180 | bool setIpAddr(uint16_t numSock, const char * ipStr); |
JMF | 0:24d3eb812fd4 | 181 | |
JMF | 0:24d3eb812fd4 | 182 | /** |
JMF | 0:24d3eb812fd4 | 183 | * |
JMF | 0:24d3eb812fd4 | 184 | * Opens a socket for the given number, port and IP protocol. Before |
JMF | 0:24d3eb812fd4 | 185 | * using open, you must use either resolveUrl() or setIpAddr(). |
JMF | 0:24d3eb812fd4 | 186 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 187 | * @param numSock - The number of the socket to open. |
JMF | 0:24d3eb812fd4 | 188 | * @param port - the IP port to open |
JMF | 0:24d3eb812fd4 | 189 | * @param tcp - set true for TCP, false for UDP |
JMF | 0:24d3eb812fd4 | 190 | * @param timeoutSec - the amount of time in seconds to wait for the open to complete |
JMF | 0:24d3eb812fd4 | 191 | * @return true if success, else false. |
JMF | 0:24d3eb812fd4 | 192 | */ |
JMF | 0:24d3eb812fd4 | 193 | bool openSocket(uint16_t numSock, uint16_t port, bool tcp, uint16_t timeOutSec = 30); |
JMF | 0:24d3eb812fd4 | 194 | |
JMF | 0:24d3eb812fd4 | 195 | /** |
JMF | 0:24d3eb812fd4 | 196 | * |
JMF | 0:24d3eb812fd4 | 197 | * Opens a socket for the given text URL, number, port and IP protocol. |
JMF | 0:24d3eb812fd4 | 198 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 199 | * @param numSock - The number of the socket to open. |
JMF | 0:24d3eb812fd4 | 200 | * @param url - a c-string text URL, the one to open a socket for. |
JMF | 0:24d3eb812fd4 | 201 | * @param port - the IP port to open. |
JMF | 0:24d3eb812fd4 | 202 | * @param tcp - set true for TCP, false for UDP. |
JMF | 0:24d3eb812fd4 | 203 | * @param timeoutSec - the amount of time in seconds to wait for the open to complete. |
JMF | 0:24d3eb812fd4 | 204 | * @return true if success, else false. |
JMF | 0:24d3eb812fd4 | 205 | */ |
JMF | 0:24d3eb812fd4 | 206 | bool openSocketUrl(uint16_t numSock, const char * url, uint16_t port, bool tcp, uint16_t timeOutSec = 30); |
JMF | 0:24d3eb812fd4 | 207 | |
JMF | 0:24d3eb812fd4 | 208 | /** |
JMF | 0:24d3eb812fd4 | 209 | * |
JMF | 0:24d3eb812fd4 | 210 | * Opens a socket for the given text IP address, number, port and IP protocol. |
JMF | 0:24d3eb812fd4 | 211 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 212 | * @param numSock - The number of the socket to open. |
JMF | 0:24d3eb812fd4 | 213 | * @param ipAddr - a c-string text IP address like: "192.168.0.1". |
JMF | 0:24d3eb812fd4 | 214 | * @param port - the IP port to open. |
JMF | 0:24d3eb812fd4 | 215 | * @param tcp - set true for TCP, false for UDP. |
JMF | 0:24d3eb812fd4 | 216 | * @param timeoutSec - the amount of time in seconds to wait for the open to complete. |
JMF | 0:24d3eb812fd4 | 217 | * @return true if success, else false. |
JMF | 0:24d3eb812fd4 | 218 | */ |
JMF | 0:24d3eb812fd4 | 219 | bool openSocketIpAddr(uint16_t numSock, const char * ipAddr, uint16_t port, bool tcp, uint16_t timeOutSec = 30); |
JMF | 0:24d3eb812fd4 | 220 | |
JMF | 0:24d3eb812fd4 | 221 | |
JMF | 0:24d3eb812fd4 | 222 | /** |
JMF | 0:24d3eb812fd4 | 223 | * |
JMF | 0:24d3eb812fd4 | 224 | * Write data bytes to a Socket, the Socket must already be open. |
JMF | 0:24d3eb812fd4 | 225 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 226 | * @param numSock - The number of the socket to open. |
JMF | 0:24d3eb812fd4 | 227 | * @parma s - an array of bytes to write to the socket. |
JMF | 0:24d3eb812fd4 | 228 | * @param n - the number of bytes to write. |
JMF | 0:24d3eb812fd4 | 229 | * @return true if success, else false. |
JMF | 0:24d3eb812fd4 | 230 | */ |
JMF | 0:24d3eb812fd4 | 231 | bool write(uint16_t numSock, const uint8_t * s, uint32_t n); |
JMF | 0:24d3eb812fd4 | 232 | |
JMF | 0:24d3eb812fd4 | 233 | /** |
JMF | 0:24d3eb812fd4 | 234 | * |
JMF | 0:24d3eb812fd4 | 235 | * Poll to read available data bytes from an already open Socket. This method |
JMF | 0:24d3eb812fd4 | 236 | * will retry reads to what setReadRetries() sets it to and the delay in between |
JMF | 0:24d3eb812fd4 | 237 | * retries that is set with setReadRetryWait() |
JMF | 0:24d3eb812fd4 | 238 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 239 | * @param numSock - The number of the socket to open. |
JMF | 0:24d3eb812fd4 | 240 | * @parma readBuf - a pointer to where read will put the data. |
JMF | 0:24d3eb812fd4 | 241 | * @param maxReadBufLen - The number of bytes readBuf has room for. |
JMF | 0:24d3eb812fd4 | 242 | * @return the number of bytes actually read into readBuf. 0 is a valid value if no data is available. |
JMF | 0:24d3eb812fd4 | 243 | */ |
JMF | 0:24d3eb812fd4 | 244 | size_t read(uint16_t numSock, uint8_t * readBuf, uint32_t maxReadBufLen); |
JMF | 0:24d3eb812fd4 | 245 | |
JMF | 0:24d3eb812fd4 | 246 | /** |
JMF | 0:24d3eb812fd4 | 247 | * |
JMF | 0:24d3eb812fd4 | 248 | * Poll to read available data bytes from an already open Socket. This method |
JMF | 0:24d3eb812fd4 | 249 | * will retry reads to what setReadRetries() sets it to and the delay in between |
JMF | 0:24d3eb812fd4 | 250 | * retries that is set with setReadRetryWait() |
JMF | 0:24d3eb812fd4 | 251 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 252 | * @param numSock - The number of the socket to open. |
JMF | 0:24d3eb812fd4 | 253 | * @parma readBuf - a pointer to pointer that will be set to point to an internal byte buffer that contains any read data. |
JMF | 0:24d3eb812fd4 | 254 | * @return the number of bytes actually read into the pointer that readBuf points to. 0 is a valid value if no data is available. |
JMF | 0:24d3eb812fd4 | 255 | */ |
JMF | 0:24d3eb812fd4 | 256 | size_t read(uint16_t numSock, const uint8_t ** readBuf); |
JMF | 0:24d3eb812fd4 | 257 | |
JMF | 0:24d3eb812fd4 | 258 | /** |
JMF | 0:24d3eb812fd4 | 259 | * |
JMF | 0:24d3eb812fd4 | 260 | * Set the number of retries that the read methods will use. If a read returns 0 data this setting will have the read |
JMF | 0:24d3eb812fd4 | 261 | * re-read to see if new data is available. |
JMF | 0:24d3eb812fd4 | 262 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 263 | * @param numSock - The number of the socket to open. |
JMF | 0:24d3eb812fd4 | 264 | * @parma retries - the number of retries to perform. |
JMF | 0:24d3eb812fd4 | 265 | * @return none. |
JMF | 0:24d3eb812fd4 | 266 | */ |
JMF | 0:24d3eb812fd4 | 267 | void setReadRetries(uint16_t numSock, uint16_t retries); |
JMF | 0:24d3eb812fd4 | 268 | |
JMF | 0:24d3eb812fd4 | 269 | /** |
JMF | 0:24d3eb812fd4 | 270 | * |
JMF | 0:24d3eb812fd4 | 271 | * Set the time between retires that the read methods will use. If a read returns 0 data this setting will have the read |
JMF | 0:24d3eb812fd4 | 272 | * re-read and use this amount of delay in between the re-reads. |
JMF | 0:24d3eb812fd4 | 273 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 274 | * @param numSock - The number of the socket to open. |
JMF | 0:24d3eb812fd4 | 275 | * @parma waitMs - the amount of time in mS to wait between retries. |
JMF | 0:24d3eb812fd4 | 276 | * @return none. |
JMF | 0:24d3eb812fd4 | 277 | */ |
JMF | 0:24d3eb812fd4 | 278 | void setReadRetryWait(uint16_t numSock, uint16_t waitMs); |
JMF | 0:24d3eb812fd4 | 279 | |
JMF | 0:24d3eb812fd4 | 280 | /** |
JMF | 0:24d3eb812fd4 | 281 | * |
JMF | 0:24d3eb812fd4 | 282 | * Closes an already open Socket. |
JMF | 0:24d3eb812fd4 | 283 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 284 | * @param numSock - The number of the socket to open. |
JMF | 0:24d3eb812fd4 | 285 | * @return true if success else false. |
JMF | 0:24d3eb812fd4 | 286 | */ |
JMF | 0:24d3eb812fd4 | 287 | bool closeSocket(uint16_t numSock); |
JMF | 0:24d3eb812fd4 | 288 | |
JMF | 0:24d3eb812fd4 | 289 | /** |
JMF | 0:24d3eb812fd4 | 290 | * |
JMF | 0:24d3eb812fd4 | 291 | * Sets the amount of time to wait between the raw AT commands that are sent to the WNC modem. |
JMF | 0:24d3eb812fd4 | 292 | * Generally you don't want to use this but it is here just in case. |
JMF | 0:24d3eb812fd4 | 293 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 294 | * @param toMs - num mS to wait between the AT cmds. |
JMF | 0:24d3eb812fd4 | 295 | * @return none. |
JMF | 0:24d3eb812fd4 | 296 | */ |
JMF | 0:24d3eb812fd4 | 297 | void setWncCmdTimeout(uint16_t toMs); |
JMF | 0:24d3eb812fd4 | 298 | |
JMF | 0:24d3eb812fd4 | 299 | /** |
JMF | 0:24d3eb812fd4 | 300 | * |
JMF | 0:24d3eb812fd4 | 301 | * Gets the IP address of the given socket number. |
JMF | 0:24d3eb812fd4 | 302 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 303 | * @param numSock - The number of the socket to open. |
JMF | 0:24d3eb812fd4 | 304 | * @param myIpAddr - a c-string that contains the socket's IP address. |
JMF | 0:24d3eb812fd4 | 305 | * @return true if success else false. |
JMF | 0:24d3eb812fd4 | 306 | */ |
JMF | 0:24d3eb812fd4 | 307 | bool getIpAddr(uint16_t numSock, char myIpAddr[MAX_LEN_IP_STR]); |
JMF | 0:24d3eb812fd4 | 308 | |
JMF | 0:24d3eb812fd4 | 309 | /** |
JMF | 0:24d3eb812fd4 | 310 | * |
JMF | 0:24d3eb812fd4 | 311 | * Enables debug output from this class. |
JMF | 0:24d3eb812fd4 | 312 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 313 | * @param on - true enables debug output, false disables |
JMF | 0:24d3eb812fd4 | 314 | * @param moreDebugOn - true enables verbose debug, false truncates debug output. |
JMF | 0:24d3eb812fd4 | 315 | * @return none. |
JMF | 0:24d3eb812fd4 | 316 | */ |
JMF | 0:24d3eb812fd4 | 317 | void enableDebug(bool on, bool moreDebugOn); |
JMF | 0:24d3eb812fd4 | 318 | |
JMF | 0:24d3eb812fd4 | 319 | /** |
JMF | 0:24d3eb812fd4 | 320 | * |
JMF | 0:24d3eb812fd4 | 321 | * Reports the WNC Firmware Revision info. |
JMF | 0:24d3eb812fd4 | 322 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 323 | * @param none. |
JMF | 0:24d3eb812fd4 | 324 | * @return char * |
JMF | 0:24d3eb812fd4 | 325 | */ |
JMF | 0:24d3eb812fd4 | 326 | const char* getFirmRev(void); |
JMF | 0:24d3eb812fd4 | 327 | |
JMF | 0:24d3eb812fd4 | 328 | /////////////////////////////////////////// |
JMF | 0:24d3eb812fd4 | 329 | // SMS messaging |
JMF | 0:24d3eb812fd4 | 330 | /////////////////////////////////////////// |
JMF | 0:24d3eb812fd4 | 331 | |
JMF | 0:24d3eb812fd4 | 332 | static const uint16_t MAX_WNC_SMS_MSG_SLOTS = 3; // How many SMS messages the WNC can store and receive at a time. |
JMF | 0:24d3eb812fd4 | 333 | static const uint16_t MAX_WNC_SMS_LENGTH = 160; // The maximum length of a 7-bit SMS message the WNC can send and receive. |
JMF | 0:24d3eb812fd4 | 334 | |
JMF | 0:24d3eb812fd4 | 335 | /** Struct for SMS messages */ |
JMF | 0:24d3eb812fd4 | 336 | struct WncSmsInfo |
JMF | 0:24d3eb812fd4 | 337 | { |
JMF | 0:24d3eb812fd4 | 338 | // Content |
JMF | 0:24d3eb812fd4 | 339 | char idx; |
JMF | 0:24d3eb812fd4 | 340 | string number; |
JMF | 0:24d3eb812fd4 | 341 | string date; |
JMF | 0:24d3eb812fd4 | 342 | string time; |
JMF | 0:24d3eb812fd4 | 343 | string msg; |
JMF | 0:24d3eb812fd4 | 344 | |
JMF | 0:24d3eb812fd4 | 345 | // Attributes |
JMF | 0:24d3eb812fd4 | 346 | bool incoming; |
JMF | 0:24d3eb812fd4 | 347 | bool unsent; |
JMF | 0:24d3eb812fd4 | 348 | bool unread; |
JMF | 0:24d3eb812fd4 | 349 | bool pduMode; |
JMF | 0:24d3eb812fd4 | 350 | bool msgReceipt; |
JMF | 0:24d3eb812fd4 | 351 | }; |
JMF | 0:24d3eb812fd4 | 352 | |
JMF | 0:24d3eb812fd4 | 353 | /** Struct to contain a list of SMS message structs */ |
JMF | 0:24d3eb812fd4 | 354 | struct WncSmsList |
JMF | 0:24d3eb812fd4 | 355 | { |
JMF | 0:24d3eb812fd4 | 356 | uint8_t msgCount; |
JMF | 0:24d3eb812fd4 | 357 | WncSmsInfo e[MAX_WNC_SMS_MSG_SLOTS]; |
JMF | 0:24d3eb812fd4 | 358 | }; |
JMF | 0:24d3eb812fd4 | 359 | |
JMF | 0:24d3eb812fd4 | 360 | /** |
JMF | 0:24d3eb812fd4 | 361 | * |
JMF | 0:24d3eb812fd4 | 362 | * Sends an SMS text message to someone. |
JMF | 0:24d3eb812fd4 | 363 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 364 | * @param phoneNum - c-string 15 digit MSISDN number or ATT Jasper number (standard phone number not supported because ATT IoT SMS does not support it). |
JMF | 0:24d3eb812fd4 | 365 | * @param text - the c-string text to send to someone. |
JMF | 0:24d3eb812fd4 | 366 | * @return true if success else false. |
JMF | 0:24d3eb812fd4 | 367 | */ |
JMF | 0:24d3eb812fd4 | 368 | bool sendSMSText(const char * const phoneNum, const char * const text); |
JMF | 0:24d3eb812fd4 | 369 | |
JMF | 0:24d3eb812fd4 | 370 | /** |
JMF | 0:24d3eb812fd4 | 371 | * |
JMF | 0:24d3eb812fd4 | 372 | * Incoming messages are stored in a log in the WNC modem, this will read that |
JMF | 0:24d3eb812fd4 | 373 | * log. |
JMF | 0:24d3eb812fd4 | 374 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 375 | * @param log - the log contents if reading it was successful. |
JMF | 0:24d3eb812fd4 | 376 | * @return true if success else false. |
JMF | 0:24d3eb812fd4 | 377 | */ |
JMF | 0:24d3eb812fd4 | 378 | bool readSMSLog(struct WncSmsList * log); |
JMF | 0:24d3eb812fd4 | 379 | |
JMF | 0:24d3eb812fd4 | 380 | /** |
JMF | 0:24d3eb812fd4 | 381 | * |
JMF | 0:24d3eb812fd4 | 382 | * Incoming messages are stored in a log in the WNC modem, this will read out |
JMF | 0:24d3eb812fd4 | 383 | * messages that are unread and also then mark them read. |
JMF | 0:24d3eb812fd4 | 384 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 385 | * @param w - a list of SMS messages that unread messages will be put into. |
JMF | 0:24d3eb812fd4 | 386 | * @param deleteRead - if a message is read and this is set true the message will be deleted from the WNC modem log. |
JMF | 0:24d3eb812fd4 | 387 | * If it is false the message will remain in the internal log but be marked as read. |
JMF | 0:24d3eb812fd4 | 388 | * @return true if success else false. |
JMF | 0:24d3eb812fd4 | 389 | */ |
JMF | 0:24d3eb812fd4 | 390 | bool readUnreadSMSText(struct WncSmsList * w, bool deleteRead = true); |
JMF | 0:24d3eb812fd4 | 391 | |
JMF | 0:24d3eb812fd4 | 392 | /** |
JMF | 0:24d3eb812fd4 | 393 | * |
JMF | 0:24d3eb812fd4 | 394 | * Saves a text message into internal SIM card memory of the WNC modem. |
JMF | 0:24d3eb812fd4 | 395 | * There are only 3 slots available this is for unread, read and saved. |
JMF | 0:24d3eb812fd4 | 396 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 397 | * @param phoneNum - c-string 15 digit MSISDN number or ATT Jasper number (standard phone number not supported because ATT IoT SMS does not support it). |
JMF | 0:24d3eb812fd4 | 398 | * @param text - the c-string text to send to someone. |
JMF | 0:24d3eb812fd4 | 399 | * @param msgIdx - the slot position to save the message: '1', '2', '3' |
JMF | 0:24d3eb812fd4 | 400 | * @return true if success else false. |
JMF | 0:24d3eb812fd4 | 401 | */ |
JMF | 0:24d3eb812fd4 | 402 | bool saveSMSText(const char * const phoneNum, const char * const text, char * msgIdx); |
JMF | 0:24d3eb812fd4 | 403 | |
JMF | 0:24d3eb812fd4 | 404 | /** |
JMF | 0:24d3eb812fd4 | 405 | * |
JMF | 0:24d3eb812fd4 | 406 | * Sends a prior stored a text message from internal SIM card memory of the WNC modem. |
JMF | 0:24d3eb812fd4 | 407 | * If no messages are stored the behaviour of this method is undefined. |
JMF | 0:24d3eb812fd4 | 408 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 409 | * @param msgIdx - the slot position to save the message: '1', '2', '3' |
JMF | 0:24d3eb812fd4 | 410 | * @return true if success else false. |
JMF | 0:24d3eb812fd4 | 411 | */ |
JMF | 0:24d3eb812fd4 | 412 | bool sendSMSTextFromMem(char msgIdx); |
JMF | 0:24d3eb812fd4 | 413 | |
JMF | 0:24d3eb812fd4 | 414 | /** |
JMF | 0:24d3eb812fd4 | 415 | * |
JMF | 0:24d3eb812fd4 | 416 | * Deletes a prior stored a text message from internal SIM card memory of the WNC modem. |
JMF | 0:24d3eb812fd4 | 417 | * If no messages are stored the behaviour of this method is undefined. |
JMF | 0:24d3eb812fd4 | 418 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 419 | * @param msgIdx - the slot position to save the message: '1', '2', '3' or '*' deletes them all. |
JMF | 0:24d3eb812fd4 | 420 | * @return true if success else false. |
JMF | 0:24d3eb812fd4 | 421 | */ |
JMF | 0:24d3eb812fd4 | 422 | bool deleteSMSTextFromMem(char msgIdx); |
JMF | 0:24d3eb812fd4 | 423 | |
JMF | 0:24d3eb812fd4 | 424 | /** |
JMF | 0:24d3eb812fd4 | 425 | * |
JMF | 0:24d3eb812fd4 | 426 | * Retreives the SIM card ICCID number. |
JMF | 0:24d3eb812fd4 | 427 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 428 | * @param iccid - a pointer to C++ string that contains the retrieved number. |
JMF | 0:24d3eb812fd4 | 429 | * @return true if success else false. |
JMF | 0:24d3eb812fd4 | 430 | */ |
JMF | 0:24d3eb812fd4 | 431 | bool getICCID(string * iccid); |
JMF | 0:24d3eb812fd4 | 432 | |
JMF | 0:24d3eb812fd4 | 433 | /** |
JMF | 0:24d3eb812fd4 | 434 | * |
JMF | 0:24d3eb812fd4 | 435 | * Converts an ICCID number into a MSISDN number. The ATT SMS system for IoT only allows use of the 15-digit MSISDN number. |
JMF | 0:24d3eb812fd4 | 436 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 437 | * @param iccid - the number to convert. |
JMF | 0:24d3eb812fd4 | 438 | * @param msisdn - points to a C++ string that has the converted number. |
JMF | 0:24d3eb812fd4 | 439 | * @return true if success else false. |
JMF | 0:24d3eb812fd4 | 440 | */ |
JMF | 0:24d3eb812fd4 | 441 | bool convertICCIDtoMSISDN(const string & iccid, string * msisdn); |
JMF | 0:24d3eb812fd4 | 442 | |
JMF | 0:24d3eb812fd4 | 443 | /////////////////////////////////////////// |
JMF | 0:24d3eb812fd4 | 444 | // Neighborhood Cell Info |
JMF | 0:24d3eb812fd4 | 445 | /////////////////////////////////////////// |
JMF | 0:24d3eb812fd4 | 446 | |
JMF | 0:24d3eb812fd4 | 447 | /** |
JMF | 0:24d3eb812fd4 | 448 | * |
JMF | 0:24d3eb812fd4 | 449 | * Fetches the signal quality log from the WNC modem. |
JMF | 0:24d3eb812fd4 | 450 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 451 | * @param log - a pointer to an internal buffer who's contents contain the signal quality metrics. |
JMF | 0:24d3eb812fd4 | 452 | * @return The number of chars in the log. |
JMF | 0:24d3eb812fd4 | 453 | */ |
JMF | 0:24d3eb812fd4 | 454 | size_t getSignalQuality(const char ** log); |
JMF | 0:24d3eb812fd4 | 455 | |
JMF | 0:24d3eb812fd4 | 456 | /** A struct for the WNC modem Date and Time */ |
JMF | 0:24d3eb812fd4 | 457 | struct WncDateTime |
JMF | 0:24d3eb812fd4 | 458 | { |
JMF | 0:24d3eb812fd4 | 459 | uint8_t year; |
JMF | 0:24d3eb812fd4 | 460 | uint8_t month; |
JMF | 0:24d3eb812fd4 | 461 | uint8_t day; |
JMF | 0:24d3eb812fd4 | 462 | uint8_t hour; |
JMF | 0:24d3eb812fd4 | 463 | uint8_t min; |
JMF | 0:24d3eb812fd4 | 464 | uint8_t sec; |
JMF | 0:24d3eb812fd4 | 465 | }; |
JMF | 0:24d3eb812fd4 | 466 | |
JMF | 0:24d3eb812fd4 | 467 | /** |
JMF | 0:24d3eb812fd4 | 468 | * |
JMF | 0:24d3eb812fd4 | 469 | * Fetches the cell tower's time and date. The time is accurate when read |
JMF | 0:24d3eb812fd4 | 470 | * but significant delays exist between the time it is read and returned. |
JMF | 0:24d3eb812fd4 | 471 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 472 | * @param tod - User supplies a pointer to a tod struct and this method fills it in. |
JMF | 0:24d3eb812fd4 | 473 | * @return true if success else false. |
JMF | 0:24d3eb812fd4 | 474 | */ |
JMF | 0:24d3eb812fd4 | 475 | bool getTimeDate(struct WncDateTime * tod); |
JMF | 0:24d3eb812fd4 | 476 | |
JMF | 0:24d3eb812fd4 | 477 | /** |
JMF | 0:24d3eb812fd4 | 478 | * |
JMF | 0:24d3eb812fd4 | 479 | * ICMP Pings a URL, the results are only output to the debug log for now! |
JMF | 0:24d3eb812fd4 | 480 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 481 | * @param url - a c-string whose URL is to be pinged. |
JMF | 0:24d3eb812fd4 | 482 | * @return true if success else false. |
JMF | 0:24d3eb812fd4 | 483 | */ |
JMF | 0:24d3eb812fd4 | 484 | bool pingUrl(const char * url); |
JMF | 0:24d3eb812fd4 | 485 | |
JMF | 0:24d3eb812fd4 | 486 | /** |
JMF | 0:24d3eb812fd4 | 487 | * |
JMF | 0:24d3eb812fd4 | 488 | * ICMP Pings an IP, the results are only output to the debug log for now! |
JMF | 0:24d3eb812fd4 | 489 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 490 | * @param ip - a c-string whose IP is to be pinged. |
JMF | 0:24d3eb812fd4 | 491 | * @return true if success else false. |
JMF | 0:24d3eb812fd4 | 492 | */ |
JMF | 0:24d3eb812fd4 | 493 | bool pingIp(const char * ip); |
JMF | 0:24d3eb812fd4 | 494 | |
JMF | 0:24d3eb812fd4 | 495 | /** |
JMF | 0:24d3eb812fd4 | 496 | * |
JMF | 0:24d3eb812fd4 | 497 | * Allows a user to send a raw AT command to the WNC modem. |
JMF | 0:24d3eb812fd4 | 498 | * @ingroup API |
JMF | 0:24d3eb812fd4 | 499 | * @param cmd - the c-string cmd to send like: "AT" |
JMF | 0:24d3eb812fd4 | 500 | * @param resp - a pointer to the c-string cmd's response. |
JMF | 0:24d3eb812fd4 | 501 | * @param sizeRespBuf - how large the command response buffer is, sets the max response length. |
JMF | 0:24d3eb812fd4 | 502 | * @param ms_timeout - how long to wait for the WNC to respond to your command. |
JMF | 0:24d3eb812fd4 | 503 | * @return the number of characters in the response from the WNC modem. |
JMF | 0:24d3eb812fd4 | 504 | */ |
JMF | 0:24d3eb812fd4 | 505 | size_t sendCustomCmd(const char * cmd, char * resp, size_t sizeRespBuf, int ms_timeout); |
JMF | 0:24d3eb812fd4 | 506 | |
JMF | 0:24d3eb812fd4 | 507 | protected: |
JMF | 0:24d3eb812fd4 | 508 | |
JMF | 0:24d3eb812fd4 | 509 | // Debug output methods |
JMF | 0:24d3eb812fd4 | 510 | int dbgPutsNoTime(const char * s, bool crlf = true); |
JMF | 0:24d3eb812fd4 | 511 | int dbgPuts(const char * s, bool crlf = true); |
JMF | 0:24d3eb812fd4 | 512 | const char * _to_string(int64_t value); |
JMF | 0:24d3eb812fd4 | 513 | const char * _to_hex_string(uint8_t value); |
JMF | 0:24d3eb812fd4 | 514 | |
JMF | 0:24d3eb812fd4 | 515 | // Sends commands to WNC via |
JMF | 0:24d3eb812fd4 | 516 | enum AtCmdErr_e { |
JMF | 0:24d3eb812fd4 | 517 | WNC_AT_CMD_OK, |
JMF | 0:24d3eb812fd4 | 518 | WNC_AT_CMD_ERR, |
JMF | 0:24d3eb812fd4 | 519 | WNC_AT_CMD_ERREXT, |
JMF | 0:24d3eb812fd4 | 520 | WNC_AT_CMD_ERRCME, |
JMF | 0:24d3eb812fd4 | 521 | WNC_AT_CMD_INVALID_RESPONSE, |
JMF | 0:24d3eb812fd4 | 522 | WNC_AT_CMD_TIMEOUT, |
JMF | 0:24d3eb812fd4 | 523 | WNC_AT_CMD_NO_CELL_LINK, |
JMF | 0:24d3eb812fd4 | 524 | WNC_AT_CMD_WNC_NOT_ON |
JMF | 0:24d3eb812fd4 | 525 | }; |
JMF | 0:24d3eb812fd4 | 526 | |
JMF | 0:24d3eb812fd4 | 527 | bool waitForPowerOnModemToRespond(uint8_t powerUpTimeoutSecs); |
JMF | 0:24d3eb812fd4 | 528 | AtCmdErr_e sendWncCmd(const char * const s, string ** r, int ms_timeout); |
JMF | 0:24d3eb812fd4 | 529 | |
JMF | 0:24d3eb812fd4 | 530 | // Users must define these functionalities in the inheriting class: |
JMF | 0:24d3eb812fd4 | 531 | // General I/O and timing: |
JMF | 0:24d3eb812fd4 | 532 | virtual int putc(char c) = 0; |
JMF | 0:24d3eb812fd4 | 533 | virtual int puts(const char * s) = 0; |
JMF | 0:24d3eb812fd4 | 534 | virtual char getc(void) = 0; |
JMF | 0:24d3eb812fd4 | 535 | virtual int charReady(void) = 0; |
JMF | 0:24d3eb812fd4 | 536 | virtual int dbgWriteChar(char b) = 0; |
JMF | 0:24d3eb812fd4 | 537 | virtual int dbgWriteChars(const char *b) = 0; |
JMF | 0:24d3eb812fd4 | 538 | virtual void waitMs(int t) = 0; |
JMF | 0:24d3eb812fd4 | 539 | virtual void waitUs(int t) = 0; |
JMF | 0:24d3eb812fd4 | 540 | virtual bool initWncModem(uint8_t powerUpTimeoutSecs) = 0; |
JMF | 0:24d3eb812fd4 | 541 | |
JMF | 0:24d3eb812fd4 | 542 | // Isolate OS timers |
JMF | 0:24d3eb812fd4 | 543 | virtual int getLogTimerTicks(void) = 0; |
JMF | 0:24d3eb812fd4 | 544 | virtual void startTimerA(void) = 0; |
JMF | 0:24d3eb812fd4 | 545 | virtual void stopTimerA(void) = 0; |
JMF | 0:24d3eb812fd4 | 546 | virtual int getTimerTicksA_mS(void) = 0; |
JMF | 0:24d3eb812fd4 | 547 | virtual void startTimerB(void) = 0; |
JMF | 0:24d3eb812fd4 | 548 | virtual void stopTimerB(void) = 0; |
JMF | 0:24d3eb812fd4 | 549 | virtual int getTimerTicksB_mS(void) = 0; |
JMF | 0:24d3eb812fd4 | 550 | |
JMF | 0:24d3eb812fd4 | 551 | private: |
JMF | 0:24d3eb812fd4 | 552 | |
JMF | 0:24d3eb812fd4 | 553 | bool softwareInitMdm(void); |
JMF | 0:24d3eb812fd4 | 554 | bool checkCellLink(void); |
JMF | 0:24d3eb812fd4 | 555 | AtCmdErr_e mdmSendAtCmdRsp(const char * cmd, int timeout_ms, string * rsp, bool crLf = true); |
JMF | 0:24d3eb812fd4 | 556 | size_t mdmGetline(string * buff, int timeout_ms); |
JMF | 0:24d3eb812fd4 | 557 | bool at_at_wnc(void); |
JMF | 0:24d3eb812fd4 | 558 | bool at_init_wnc(bool hardReset = false); |
JMF | 0:24d3eb812fd4 | 559 | int16_t at_sockopen_wnc(const char * const ip, uint16_t port, uint16_t numSock, bool tcp, uint16_t timeOutSec); |
JMF | 0:24d3eb812fd4 | 560 | bool at_sockclose_wnc(uint16_t numSock); |
JMF | 0:24d3eb812fd4 | 561 | bool at_dnsresolve_wnc(const char * s, string * ipStr); |
JMF | 0:24d3eb812fd4 | 562 | AtCmdErr_e at_sockwrite_wnc(const uint8_t * s, uint16_t n, uint16_t numSock, bool isTcp); |
JMF | 0:24d3eb812fd4 | 563 | AtCmdErr_e at_sockread_wnc(uint8_t * pS, uint16_t * numRead, uint16_t n, uint16_t numSock, bool isTcp); |
JMF | 0:24d3eb812fd4 | 564 | AtCmdErr_e at_sockread_wnc(string * pS, uint16_t numSock, bool isTcp); |
JMF | 0:24d3eb812fd4 | 565 | bool at_reinitialize_mdm(void); |
JMF | 0:24d3eb812fd4 | 566 | AtCmdErr_e at_send_wnc_cmd(const char * s, string ** r, int ms_timeout); |
JMF | 0:24d3eb812fd4 | 567 | bool at_setapn_wnc(const char * const apnStr); |
JMF | 0:24d3eb812fd4 | 568 | bool at_sendSMStext_wnc(const char * const phoneNum, const char * const text); |
JMF | 0:24d3eb812fd4 | 569 | bool at_get_wnc_net_stats(WncIpStats * s); |
JMF | 0:24d3eb812fd4 | 570 | bool at_readSMSlog_wnc(string ** log); |
JMF | 0:24d3eb812fd4 | 571 | size_t at_readSMStext_wnc(const char ** log); |
JMF | 0:24d3eb812fd4 | 572 | size_t at_readSMStext_wnc(const char n, const char ** log); |
JMF | 0:24d3eb812fd4 | 573 | bool at_getrssiber_wnc(int16_t * dBm, int16_t * ber3g); |
JMF | 0:24d3eb812fd4 | 574 | void closeOpenSocket(uint16_t numSock); |
JMF | 0:24d3eb812fd4 | 575 | bool sockWrite(const uint8_t * const s, uint16_t n, uint16_t numSock, bool isTcp); |
JMF | 0:24d3eb812fd4 | 576 | bool at_sendSMStextMem_wnc(char n); |
JMF | 0:24d3eb812fd4 | 577 | bool at_deleteSMSTextFromMem_wnc(char n); |
JMF | 0:24d3eb812fd4 | 578 | bool at_saveSMStext_wnc(const char * const phoneNum, const char * const text, char * msgIdx); |
JMF | 0:24d3eb812fd4 | 579 | size_t at_getSignalQuality_wnc(const char ** log); |
JMF | 0:24d3eb812fd4 | 580 | bool at_gettimedate_wnc(struct WncDateTime * tod); |
JMF | 0:24d3eb812fd4 | 581 | bool at_ping_wnc(const char * ip); |
JMF | 0:24d3eb812fd4 | 582 | bool at_geticcid_wnc(string * iccid); |
JMF | 0:24d3eb812fd4 | 583 | |
JMF | 0:24d3eb812fd4 | 584 | // Utility methods |
JMF | 0:24d3eb812fd4 | 585 | void sendCmd(const char * cmd, bool crLf); |
JMF | 0:24d3eb812fd4 | 586 | void sendCmd(const char * cmd, unsigned n, unsigned wait_uS, bool crLf); |
JMF | 0:24d3eb812fd4 | 587 | inline void rx_char_wait(void) { |
JMF | 0:24d3eb812fd4 | 588 | // waitUs(1000); |
JMF | 0:24d3eb812fd4 | 589 | } |
JMF | 0:24d3eb812fd4 | 590 | |
JMF | 0:24d3eb812fd4 | 591 | // Important constants |
JMF | 0:24d3eb812fd4 | 592 | 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 |
JMF | 0:24d3eb812fd4 | 593 | 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. |
JMF | 0:24d3eb812fd4 | 594 | 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. |
JMF | 0:24d3eb812fd4 | 595 | static const uint16_t WNC_AUTO_POLL_MS = 250; // Sets default (may be overriden with method) poll interval (currently not used, future possible feature. |
JMF | 0:24d3eb812fd4 | 596 | 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. |
JMF | 0:24d3eb812fd4 | 597 | 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. |
JMF | 0:24d3eb812fd4 | 598 | static const uint16_t WNC_WAIT_FOR_AT_CMD_MS = 0; // Wait this much between multiple in a row AT commands to the WNC. |
JMF | 0:24d3eb812fd4 | 599 | static const uint16_t WNC_SOFT_INIT_RETRY_COUNT = 10; // How many times the WNC will be tried to revive if it stops responding. |
JMF | 0:24d3eb812fd4 | 600 | 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. |
JMF | 0:24d3eb812fd4 | 601 | 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. |
JMF | 0:24d3eb812fd4 | 602 | static const uint16_t WNC_APNSET_TIMEOUT_MS = 60000; // How long to wait for the WNC to respond to setting the APN string. |
JMF | 0:24d3eb812fd4 | 603 | 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) |
JMF | 0:24d3eb812fd4 | 604 | 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. |
JMF | 0:24d3eb812fd4 | 605 | 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. |
JMF | 0:24d3eb812fd4 | 606 | static const char * const INVALID_IP_STR; // Just a string set to an IP address when DNS resolve fails. |
JMF | 0:24d3eb812fd4 | 607 | |
JMF | 0:24d3eb812fd4 | 608 | struct WncSocketInfo_s { |
JMF | 0:24d3eb812fd4 | 609 | int16_t numWncSock; |
JMF | 0:24d3eb812fd4 | 610 | bool open; |
JMF | 0:24d3eb812fd4 | 611 | string myIpAddressStr; |
JMF | 0:24d3eb812fd4 | 612 | uint16_t myPort; |
JMF | 0:24d3eb812fd4 | 613 | uint8_t readRetries; |
JMF | 0:24d3eb812fd4 | 614 | uint16_t readRetryWaitMs; |
JMF | 0:24d3eb812fd4 | 615 | bool isTcp; |
JMF | 0:24d3eb812fd4 | 616 | uint16_t timeOutSec; |
JMF | 0:24d3eb812fd4 | 617 | }; |
JMF | 0:24d3eb812fd4 | 618 | |
JMF | 0:24d3eb812fd4 | 619 | WncSocketInfo_s m_sSock[MAX_NUM_WNC_SOCKETS]; |
JMF | 0:24d3eb812fd4 | 620 | WncState_e m_sState; |
JMF | 0:24d3eb812fd4 | 621 | uint16_t m_sCmdTimeoutMs; |
JMF | 0:24d3eb812fd4 | 622 | string m_sApnStr; |
JMF | 0:24d3eb812fd4 | 623 | string m_sWncStr; |
JMF | 0:24d3eb812fd4 | 624 | string m_FirmwareRevision; |
JMF | 0:24d3eb812fd4 | 625 | uint8_t m_sPowerUpTimeoutSecs; |
JMF | 0:24d3eb812fd4 | 626 | bool m_sDebugEnabled; |
JMF | 0:24d3eb812fd4 | 627 | bool m_sMoreDebugEnabled; |
JMF | 0:24d3eb812fd4 | 628 | bool m_sCheckNetStatus; |
JMF | 0:24d3eb812fd4 | 629 | bool m_sReadyForSMS; |
JMF | 0:24d3eb812fd4 | 630 | }; |
JMF | 0:24d3eb812fd4 | 631 | |
JMF | 0:24d3eb812fd4 | 632 | }; // End namespace WncController_fk |
JMF | 0:24d3eb812fd4 | 633 | |
JMF | 0:24d3eb812fd4 | 634 | #endif |
JMF | 0:24d3eb812fd4 | 635 |