V.06 11/3
Dependencies: FT6206 SDFileSystem SPI_TFT_ILI9341 TFT_fonts
Fork of ATT_AWS_IoT_demo by
WNCInterface.h
00001 /* ===================================================================== 00002 Copyright © 2016, Avnet (R) 00003 00004 Contributors: 00005 * James Flynn, www.em.avnet.com 00006 00007 Licensed under the Apache License, Version 2.0 (the "License"); 00008 you may not use this file except in compliance with the License. 00009 You may obtain a copy of the License at 00010 00011 http://www.apache.org/licenses/LICENSE-2.0 00012 00013 Unless required by applicable law or agreed to in writing, 00014 software distributed under the License is distributed on an 00015 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 00016 either express or implied. See the License for the specific 00017 language governing permissions and limitations under the License. 00018 00019 @file WNCInterface.h 00020 @version 1.0 00021 @date Sept 2016 00022 00023 ======================================================================== */ 00024 00025 00026 #include <stddef.h> 00027 #include "WncControllerK64F/WncControllerK64F.h" 00028 #include "WncControllerK64F/WncController/WncController.h" 00029 #include <Mutex.h> 00030 00031 #ifndef _WNCINTERFACE_H_ 00032 #define _WNCINTERFACE_H_ 00033 00034 #define WNC_DEBUG 1 //1=enable the WNC startup debug output 00035 //0=disable the WNC startup debug output 00036 #define STOP_ON_FE 1 //1=hang forever if a fatal error occurs 00037 //0=simply return failed response for all socket calls 00038 #define DISPLAY_FE 1 //1 to display the fatal error when it occurs 00039 //0 to NOT display the fatal error 00040 #define RESETON_FE 0 //1 to cause the MCU to reset on fatal error 00041 //0 to NOT reset the MCU 00042 //for att_iot_starter kit card 00043 //#define APN_DEFAULT "m2m.com.attz" 00044 //for g&d card 00045 #define APN_DEFAULT "internet.m2m.com" 00046 00047 // 00048 // WNC Error Handling macros & data 00049 // 00050 #define FATAL_FLAG WncController_fk::WncController::WNC_NO_RESPONSE 00051 #define WNC_GOOD WncController_fk::WncController::WNC_ON 00052 00053 #define RETfail return -1 00054 #define RETvoid return 00055 #define RETnull return NULL 00056 #define RETresume 00057 00058 #define DORET(x) RET##x 00059 00060 #define TOSTR(x) #x 00061 #define INTSTR(x) TOSTR(x) 00062 #define FATAL_STR __FILE__ ":" INTSTR(__LINE__) 00063 00064 00065 #if RESETON_FE == 1 00066 #define MCURESET ((*((volatile unsigned long *)0xE000ED0CU))=(unsigned long)((0x5fa<<16) | 0x04L)) 00067 #define RSTMSG "RESET MCU! " 00068 #else 00069 #define MCURESET 00070 #define RSTMSG "" 00071 #endif 00072 00073 #if DISPLAY_FE == 1 00074 #define PFE {extern MODSERIAL *_dbgout;if(_dbgout)_dbgout->printf(RSTMSG "\r\n>>WNC FAILED @ %s\r\n", FATAL_STR);} 00075 #else 00076 #define PFE 00077 #endif 00078 00079 #if STOP_ON_FE == 1 00080 #define FATAL_WNC_ERROR(v) {extern char *_fatal_err_loc;_fatal_err_loc=FATAL_STR;PFE;MCURESET;while(1);} 00081 #else 00082 #define FATAL_WNC_ERROR(v) {extern char *_fatal_err_loc;_fatal_err_loc=FATAL_STR;PFE;DORET(v);} 00083 #endif 00084 00085 #define M_LOCK {extern Mutex _WNCLock; _WNCLock.lock();} 00086 #define M_ULOCK {extern Mutex _WNCLock; _WNCLock.unlock();} 00087 #define CHK_WNCFE(x,y) if( x ){M_ULOCK; FATAL_WNC_ERROR(y);} 00088 00089 // Because the WncController has intermixed socket & interface functionallity 00090 // will need to make the Socket class a friend of the Interface class. This 00091 // will allow the Socket class to get to the WNC functions needed for the 00092 // socket. Forward reference the class 00093 00094 class Socket; 00095 class Endpoint; 00096 class UDPSocket; 00097 class TCPSocketConnection; 00098 class WNCSms; 00099 00100 class WNCInterface 00101 { 00102 class WncControllerK64F; //forward reference the Controller Class 00103 friend class TCPSocketConnection; 00104 friend class UDPSocket; 00105 friend class Endpoint; 00106 friend class Socket; 00107 friend class WNCSms; 00108 00109 public: 00110 /** Create WNC Data Module Interface Instance for the device (M14A2A) */ 00111 WNCInterface(); 00112 00113 /** Initialize the interface (no connection at this point). 00114 * \return 0 on success, a negative number on failure 00115 */ 00116 static int init(const char* apn=NULL, MODSERIAL * debug=NULL); 00117 00118 /** Open an LTE internet data connection 00119 @return 0 on success, error code on failure 00120 */ 00121 int connect(void); 00122 00123 /** Disconnect 00124 * Bring the interface down 00125 * \return 0 on success, a negative number on failure 00126 */ 00127 static int disconnect(); 00128 00129 /** Because the WNCInterface is cellular based there is no MAC Ethernet address to return, so this function 00130 * returns a bogus MAC address created from the ICCD on the SIM that is being used. 00131 * \return a pointer to a pesudo-MAC string containing "NN:NN:NN:NN:NN:NN" 00132 */ 00133 static char* getMACAddress(); 00134 00135 /** Get the IP address of your Ethernet interface 00136 * \return a pointer to a string containing the IP address 00137 */ 00138 static char* getIPAddress(); 00139 00140 /** Get the Gateway address of your Ethernet interface 00141 * \return a pointer to a string containing the Gateway address 00142 */ 00143 static char* getGateway(); 00144 00145 /** Get the Network mask of your Ethernet interface 00146 * \return a pointer to a string containing the Network mask 00147 */ 00148 static char* getNetworkMask(); 00149 00150 /** Manipulate the debug output of the WncController, for debug purposes. 00151 * \return nothing. 00152 */ 00153 void doDebug(int val); //doing this so I can get to the wnc controller pointer 00154 00155 /** Returns full ICCD on the SIM that is being used. 00156 */ 00157 void WNCInterface::getICCID(string *str); 00158 00159 //certificate and key 00160 void getObject(string sObjectName, unsigned char *ucObject, int *iObjectLength); 00161 00162 int16_t getSignalStrength(); 00163 bool getUpdateStatus(unsigned char *cStatus); 00164 bool getAllObjects(); 00165 00166 //private: 00167 static WncController_fk::WncIpStats myNetStats; //maintaint the network statistics 00168 static WncControllerK64F_fk::WncControllerK64F *_pwnc; //pointer to the WncController instance 00169 static string mac; 00170 00171 }; 00172 00173 #endif /* _WNCINTERFACE_ */ 00174 00175
Generated on Tue Jul 12 2022 14:16:20 by 1.7.2