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