V.06 11/3

Dependencies:   FT6206 SDFileSystem SPI_TFT_ILI9341 TFT_fonts

Fork of ATT_AWS_IoT_demo by attiot

Committer:
jilee
Date:
Fri Nov 03 20:28:02 2017 +0000
Revision:
29:f71a0be59b99
Parent:
28:54d9a550adf1
v.06 11/03/2016

Who changed what in which revision?

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