Demo application for using the AT&T IoT Starter Kit Powered by AWS.
Dependencies: SDFileSystem
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 0 //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 #define APN_DEFAULT "m2m.com.attz" 00043 00044 // 00045 // WNC Error Handling macros & data 00046 // 00047 #define FATAL_FLAG WncController_fk::WncController::WNC_NO_RESPONSE 00048 #define WNC_GOOD WncController_fk::WncController::WNC_ON 00049 00050 #define RETfail return -1 00051 #define RETvoid return 00052 #define RETnull return NULL 00053 #define RETresume 00054 00055 #define DORET(x) RET##x 00056 00057 #define TOSTR(x) #x 00058 #define INTSTR(x) TOSTR(x) 00059 #define FATAL_STR __FILE__ ":" INTSTR(__LINE__) 00060 00061 00062 #if RESETON_FE == 1 00063 #define MCURESET ((*((volatile unsigned long *)0xE000ED0CU))=(unsigned long)((0x5fa<<16) | 0x04L)) 00064 #define RSTMSG "RESET MCU! " 00065 #else 00066 #define MCURESET 00067 #define RSTMSG "" 00068 #endif 00069 00070 #if DISPLAY_FE == 1 00071 #define PFE {extern MODSERIAL *_dbgout;if(_dbgout)_dbgout->printf(RSTMSG "\r\n>>WNC FAILED @ %s\r\n", FATAL_STR);} 00072 #else 00073 #define PFE 00074 #endif 00075 00076 #if STOP_ON_FE == 1 00077 #define FATAL_WNC_ERROR(v) {extern char *_fatal_err_loc;_fatal_err_loc=FATAL_STR;PFE;MCURESET;while(1);} 00078 #else 00079 #define FATAL_WNC_ERROR(v) {extern char *_fatal_err_loc;_fatal_err_loc=FATAL_STR;PFE;DORET(v);} 00080 #endif 00081 00082 #define M_LOCK {extern Mutex _WNCLock; _WNCLock.lock();} 00083 #define M_ULOCK {extern Mutex _WNCLock; _WNCLock.unlock();} 00084 #define CHK_WNCFE(x,y) if( x ){M_ULOCK; FATAL_WNC_ERROR(y);} 00085 00086 // Because the WncController has intermixed socket & interface functionallity 00087 // will need to make the Socket class a friend of the Interface class. This 00088 // will allow the Socket class to get to the WNC functions needed for the 00089 // socket. Forward reference the class 00090 00091 class Socket; 00092 class Endpoint; 00093 class UDPSocket; 00094 class TCPSocketConnection; 00095 class WNCSms; 00096 00097 class WNCInterface 00098 { 00099 class WncControllerK64F; //forward reference the Controller Class 00100 friend class TCPSocketConnection; 00101 friend class UDPSocket; 00102 friend class Endpoint; 00103 friend class Socket; 00104 friend class WNCSms; 00105 00106 public: 00107 /** Create WNC Data Module Interface Instance for the device (M14A2A) */ 00108 WNCInterface(); 00109 00110 /** Initialize the interface (no connection at this point). 00111 * \return 0 on success, a negative number on failure 00112 */ 00113 static int init(const char* apn=NULL, MODSERIAL * debug=NULL); 00114 00115 /** Open an LTE internet data connection 00116 @return 0 on success, error code on failure 00117 */ 00118 int connect(void); 00119 00120 /** Disconnect 00121 * Bring the interface down 00122 * \return 0 on success, a negative number on failure 00123 */ 00124 static int disconnect(); 00125 00126 /** Because the WNCInterface is cellular based there is no MAC Ethernet address to return, so this function 00127 * returns a bogus MAC address created from the ICCD on the SIM that is being used. 00128 * \return a pointer to a pesudo-MAC string containing "NN:NN:NN:NN:NN:NN" 00129 */ 00130 static char* getMACAddress(); 00131 00132 /** Get the IP address of your Ethernet interface 00133 * \return a pointer to a string containing the IP address 00134 */ 00135 static char* getIPAddress(); 00136 00137 /** Get the Gateway address of your Ethernet interface 00138 * \return a pointer to a string containing the Gateway address 00139 */ 00140 static char* getGateway(); 00141 00142 /** Get the Network mask of your Ethernet interface 00143 * \return a pointer to a string containing the Network mask 00144 */ 00145 static char* getNetworkMask(); 00146 00147 /** Manipulate the debug output of the WncController, for debug purposes. 00148 * \return nothing. 00149 */ 00150 void doDebug(int val); //doing this so I can get to the wnc controller pointer 00151 00152 /** Returns full ICCD on the SIM that is being used. 00153 */ 00154 void WNCInterface::getICCID(string *str); 00155 00156 //private: 00157 static WncController_fk::WncIpStats myNetStats; //maintaint the network statistics 00158 static WncControllerK64F_fk::WncControllerK64F *_pwnc; //pointer to the WncController instance 00159 static string mac; 00160 00161 }; 00162 00163 #endif /* _WNCINTERFACE_ */ 00164 00165
Generated on Tue Jul 12 2022 22:13:21 by 1.7.2