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 © 2016, Avnet (R)
ampembeng 15:6f2798e45099 3
ampembeng 15:6f2798e45099 4 Contributors:
ampembeng 15:6f2798e45099 5 * James Flynn, www.em.avnet.com
ampembeng 15:6f2798e45099 6
ampembeng 15:6f2798e45099 7 Licensed under the Apache License, Version 2.0 (the "License");
ampembeng 15:6f2798e45099 8 you may not use this file except in compliance with the License.
ampembeng 15:6f2798e45099 9 You may obtain a copy of the License at
ampembeng 15:6f2798e45099 10
ampembeng 15:6f2798e45099 11 http://www.apache.org/licenses/LICENSE-2.0
ampembeng 15:6f2798e45099 12
ampembeng 15:6f2798e45099 13 Unless required by applicable law or agreed to in writing,
ampembeng 15:6f2798e45099 14 software distributed under the License is distributed on an
ampembeng 15:6f2798e45099 15 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
ampembeng 15:6f2798e45099 16 either express or implied. See the License for the specific
ampembeng 15:6f2798e45099 17 language governing permissions and limitations under the License.
ampembeng 15:6f2798e45099 18
ampembeng 15:6f2798e45099 19 @file WNCInterface.h
ampembeng 15:6f2798e45099 20 @version 1.0
ampembeng 15:6f2798e45099 21 @date Sept 2016
ampembeng 15:6f2798e45099 22
ampembeng 15:6f2798e45099 23 ======================================================================== */
ampembeng 15:6f2798e45099 24
ampembeng 15:6f2798e45099 25
ampembeng 15:6f2798e45099 26 #include <stddef.h>
ampembeng 15:6f2798e45099 27 #include "WncControllerK64F/WncControllerK64F.h"
ampembeng 15:6f2798e45099 28 #include "WncControllerK64F/WncController/WncController.h"
ampembeng 15:6f2798e45099 29 #include <Mutex.h>
ampembeng 15:6f2798e45099 30
ampembeng 15:6f2798e45099 31 #ifndef _WNCINTERFACE_H_
ampembeng 15:6f2798e45099 32 #define _WNCINTERFACE_H_
ampembeng 15:6f2798e45099 33
jilee 28:54d9a550adf1 34 #define WNC_DEBUG 1 //1=enable the WNC startup debug output
ampembeng 15:6f2798e45099 35 //0=disable the WNC startup debug output
ampembeng 15:6f2798e45099 36 #define STOP_ON_FE 1 //1=hang forever if a fatal error occurs
ampembeng 15:6f2798e45099 37 //0=simply return failed response for all socket calls
ampembeng 15:6f2798e45099 38 #define DISPLAY_FE 1 //1 to display the fatal error when it occurs
ampembeng 15:6f2798e45099 39 //0 to NOT display the fatal error
ampembeng 15:6f2798e45099 40 #define RESETON_FE 0 //1 to cause the MCU to reset on fatal error
ampembeng 15:6f2798e45099 41 //0 to NOT reset the MCU
jilee 28:54d9a550adf1 42 //for att_iot_starter kit card
jilee 28:54d9a550adf1 43 //#define APN_DEFAULT "m2m.com.attz"
jilee 28:54d9a550adf1 44 //for g&d card
jilee 28:54d9a550adf1 45 #define APN_DEFAULT "internet.m2m.com"
ampembeng 15:6f2798e45099 46
ampembeng 15:6f2798e45099 47 //
ampembeng 15:6f2798e45099 48 // WNC Error Handling macros & data
ampembeng 15:6f2798e45099 49 //
ampembeng 15:6f2798e45099 50 #define FATAL_FLAG WncController_fk::WncController::WNC_NO_RESPONSE
ampembeng 15:6f2798e45099 51 #define WNC_GOOD WncController_fk::WncController::WNC_ON
ampembeng 15:6f2798e45099 52
ampembeng 15:6f2798e45099 53 #define RETfail return -1
ampembeng 15:6f2798e45099 54 #define RETvoid return
ampembeng 15:6f2798e45099 55 #define RETnull return NULL
ampembeng 15:6f2798e45099 56 #define RETresume
ampembeng 15:6f2798e45099 57
ampembeng 15:6f2798e45099 58 #define DORET(x) RET##x
ampembeng 15:6f2798e45099 59
ampembeng 15:6f2798e45099 60 #define TOSTR(x) #x
ampembeng 15:6f2798e45099 61 #define INTSTR(x) TOSTR(x)
ampembeng 15:6f2798e45099 62 #define FATAL_STR __FILE__ ":" INTSTR(__LINE__)
ampembeng 15:6f2798e45099 63
ampembeng 15:6f2798e45099 64
ampembeng 15:6f2798e45099 65 #if RESETON_FE == 1
ampembeng 15:6f2798e45099 66 #define MCURESET ((*((volatile unsigned long *)0xE000ED0CU))=(unsigned long)((0x5fa<<16) | 0x04L))
ampembeng 15:6f2798e45099 67 #define RSTMSG "RESET MCU! "
ampembeng 15:6f2798e45099 68 #else
ampembeng 15:6f2798e45099 69 #define MCURESET
ampembeng 15:6f2798e45099 70 #define RSTMSG ""
ampembeng 15:6f2798e45099 71 #endif
ampembeng 15:6f2798e45099 72
ampembeng 15:6f2798e45099 73 #if DISPLAY_FE == 1
ampembeng 15:6f2798e45099 74 #define PFE {extern MODSERIAL *_dbgout;if(_dbgout)_dbgout->printf(RSTMSG "\r\n>>WNC FAILED @ %s\r\n", FATAL_STR);}
ampembeng 15:6f2798e45099 75 #else
ampembeng 15:6f2798e45099 76 #define PFE
ampembeng 15:6f2798e45099 77 #endif
ampembeng 15:6f2798e45099 78
ampembeng 15:6f2798e45099 79 #if STOP_ON_FE == 1
ampembeng 15:6f2798e45099 80 #define FATAL_WNC_ERROR(v) {extern char *_fatal_err_loc;_fatal_err_loc=FATAL_STR;PFE;MCURESET;while(1);}
ampembeng 15:6f2798e45099 81 #else
ampembeng 15:6f2798e45099 82 #define FATAL_WNC_ERROR(v) {extern char *_fatal_err_loc;_fatal_err_loc=FATAL_STR;PFE;DORET(v);}
ampembeng 15:6f2798e45099 83 #endif
ampembeng 15:6f2798e45099 84
ampembeng 15:6f2798e45099 85 #define M_LOCK {extern Mutex _WNCLock; _WNCLock.lock();}
ampembeng 15:6f2798e45099 86 #define M_ULOCK {extern Mutex _WNCLock; _WNCLock.unlock();}
ampembeng 15:6f2798e45099 87 #define CHK_WNCFE(x,y) if( x ){M_ULOCK; FATAL_WNC_ERROR(y);}
ampembeng 15:6f2798e45099 88
ampembeng 15:6f2798e45099 89 // Because the WncController has intermixed socket & interface functionallity
ampembeng 15:6f2798e45099 90 // will need to make the Socket class a friend of the Interface class. This
ampembeng 15:6f2798e45099 91 // will allow the Socket class to get to the WNC functions needed for the
ampembeng 15:6f2798e45099 92 // socket. Forward reference the class
ampembeng 15:6f2798e45099 93
ampembeng 15:6f2798e45099 94 class Socket;
ampembeng 15:6f2798e45099 95 class Endpoint;
ampembeng 15:6f2798e45099 96 class UDPSocket;
ampembeng 15:6f2798e45099 97 class TCPSocketConnection;
ampembeng 15:6f2798e45099 98 class WNCSms;
ampembeng 15:6f2798e45099 99
ampembeng 15:6f2798e45099 100 class WNCInterface
ampembeng 15:6f2798e45099 101 {
ampembeng 15:6f2798e45099 102 class WncControllerK64F; //forward reference the Controller Class
ampembeng 15:6f2798e45099 103 friend class TCPSocketConnection;
ampembeng 15:6f2798e45099 104 friend class UDPSocket;
ampembeng 15:6f2798e45099 105 friend class Endpoint;
ampembeng 15:6f2798e45099 106 friend class Socket;
ampembeng 15:6f2798e45099 107 friend class WNCSms;
ampembeng 15:6f2798e45099 108
ampembeng 15:6f2798e45099 109 public:
ampembeng 15:6f2798e45099 110 /** Create WNC Data Module Interface Instance for the device (M14A2A) */
ampembeng 15:6f2798e45099 111 WNCInterface();
ampembeng 15:6f2798e45099 112
ampembeng 15:6f2798e45099 113 /** Initialize the interface (no connection at this point).
ampembeng 15:6f2798e45099 114 * \return 0 on success, a negative number on failure
ampembeng 15:6f2798e45099 115 */
ampembeng 15:6f2798e45099 116 static int init(const char* apn=NULL, MODSERIAL * debug=NULL);
ampembeng 15:6f2798e45099 117
ampembeng 15:6f2798e45099 118 /** Open an LTE internet data connection
ampembeng 15:6f2798e45099 119 @return 0 on success, error code on failure
ampembeng 15:6f2798e45099 120 */
ampembeng 15:6f2798e45099 121 int connect(void);
ampembeng 15:6f2798e45099 122
ampembeng 15:6f2798e45099 123 /** Disconnect
ampembeng 15:6f2798e45099 124 * Bring the interface down
ampembeng 15:6f2798e45099 125 * \return 0 on success, a negative number on failure
ampembeng 15:6f2798e45099 126 */
ampembeng 15:6f2798e45099 127 static int disconnect();
ampembeng 15:6f2798e45099 128
ampembeng 15:6f2798e45099 129 /** Because the WNCInterface is cellular based there is no MAC Ethernet address to return, so this function
ampembeng 15:6f2798e45099 130 * returns a bogus MAC address created from the ICCD on the SIM that is being used.
ampembeng 15:6f2798e45099 131 * \return a pointer to a pesudo-MAC string containing "NN:NN:NN:NN:NN:NN"
ampembeng 15:6f2798e45099 132 */
ampembeng 15:6f2798e45099 133 static char* getMACAddress();
ampembeng 15:6f2798e45099 134
ampembeng 15:6f2798e45099 135 /** Get the IP address of your Ethernet interface
ampembeng 15:6f2798e45099 136 * \return a pointer to a string containing the IP address
ampembeng 15:6f2798e45099 137 */
ampembeng 15:6f2798e45099 138 static char* getIPAddress();
ampembeng 15:6f2798e45099 139
ampembeng 15:6f2798e45099 140 /** Get the Gateway address of your Ethernet interface
ampembeng 15:6f2798e45099 141 * \return a pointer to a string containing the Gateway address
ampembeng 15:6f2798e45099 142 */
ampembeng 15:6f2798e45099 143 static char* getGateway();
ampembeng 15:6f2798e45099 144
ampembeng 15:6f2798e45099 145 /** Get the Network mask of your Ethernet interface
ampembeng 15:6f2798e45099 146 * \return a pointer to a string containing the Network mask
ampembeng 15:6f2798e45099 147 */
ampembeng 15:6f2798e45099 148 static char* getNetworkMask();
ampembeng 15:6f2798e45099 149
ampembeng 15:6f2798e45099 150 /** Manipulate the debug output of the WncController, for debug purposes.
ampembeng 15:6f2798e45099 151 * \return nothing.
ampembeng 15:6f2798e45099 152 */
ampembeng 15:6f2798e45099 153 void doDebug(int val); //doing this so I can get to the wnc controller pointer
ampembeng 15:6f2798e45099 154
ampembeng 23:b9ff83dc965f 155 /** Returns full ICCD on the SIM that is being used.
ampembeng 23:b9ff83dc965f 156 */
ampembeng 23:b9ff83dc965f 157 void WNCInterface::getICCID(string *str);
ampembeng 15:6f2798e45099 158
jilee 28:54d9a550adf1 159 //certificate and key
jilee 29:f71a0be59b99 160 void getObject(string sObjectName, unsigned char *ucObject, int *iObjectLength);
jilee 29:f71a0be59b99 161
jilee 29:f71a0be59b99 162 int16_t getSignalStrength();
jilee 29:f71a0be59b99 163 bool getUpdateStatus(unsigned char *cStatus);
jilee 29:f71a0be59b99 164 bool getAllObjects();
jilee 28:54d9a550adf1 165
ampembeng 15:6f2798e45099 166 //private:
ampembeng 15:6f2798e45099 167 static WncController_fk::WncIpStats myNetStats; //maintaint the network statistics
ampembeng 15:6f2798e45099 168 static WncControllerK64F_fk::WncControllerK64F *_pwnc; //pointer to the WncController instance
ampembeng 15:6f2798e45099 169 static string mac;
ampembeng 15:6f2798e45099 170
ampembeng 15:6f2798e45099 171 };
ampembeng 15:6f2798e45099 172
ampembeng 15:6f2798e45099 173 #endif /* _WNCINTERFACE_ */
ampembeng 15:6f2798e45099 174
ampembeng 15:6f2798e45099 175