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