The WDCInterface is is a drop-in replacement for an EthernetInterface class that allows the user to connect to the Internet with a Wistron NeWeb Corporation (WNC) M14A2A Series data module using the standard network Socket API's. This interface class is used in the AT&T Cellular IoT Starter Kit which is sold by Avnet (http://cloudconnectkits.org/product/att-cellular-iot-starter-kit).

Dependencies:   WncControllerK64F

Dependents:   WNCProximityMqtt Pubnub_ATT_IoT_SK_WNC_sync BluemixDemo BluemixQS ... more

See the WNCInterface README in the Wiki tab for detailed information on this library.

Committer:
JMF
Date:
Fri Oct 07 00:36:47 2016 +0000
Revision:
8:4b38bfb1704d
Parent:
7:fded23f50479
Child:
9:9f0578ff157a
Corrected Mutex implementation.  Now it is static global to the WNCInterface class.

Who changed what in which revision?

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