Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: WncControllerK64F
Fork of WNCInterface by
Diff: WNCInterface.h
- Revision:
- 0:55ec71dc0347
- Child:
- 3:1d7e6ed11269
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/WNCInterface.h Wed Sep 21 14:30:06 2016 +0000
@@ -0,0 +1,140 @@
+/* =====================================================================
+ Copyright © 2016, Avnet (R)
+
+ Contributors:
+ * James Flynn, www.em.avnet.com
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ either express or implied. See the License for the specific
+ language governing permissions and limitations under the License.
+
+ @file WNCInterface.h
+ @version 1.0
+ @date Sept 2016
+
+======================================================================== */
+
+
+#include <stddef.h>
+#include "WncControllerK64F/WncControllerK64F.h"
+
+#ifndef _WNCINTERFACE_H_
+#define _WNCINTERFACE_H_
+
+#define WNC_DEBUG 1 //1=enable the WNC debug port
+ //0=disable the WNC debug port
+#define STOP_ON_FE 1 //1=hang forever if a fatal error occurs
+ //0=simply return failed response for all socket calls
+#define DISPLAY_FE 1 //1 to display the fatal error when it occurs
+ //0 to NOT display the fatal error
+#define APN_DEFAULT "m2m.com.attz"
+
+//
+// WNC Error Handling macros & data
+//
+#define FATAL_FLAG WncController_fk::WncController::WNC_NO_RESPONSE
+#define WNC_GOOD WncController_fk::WncController::WNC_ON
+
+#define RETfail return -1
+#define RETvoid return
+#define RETnull return NULL
+#define DORET(x) RET##x
+
+#define TOSTR(x) #x
+#define INTSTR(x) TOSTR(x)
+#define FATAL_STR __FILE__ ":" INTSTR(__LINE__)
+
+#if DISPLAY_FE == 1
+#define PFE printf("WNC FAILED @ %s\r\n", FATAL_STR)
+#else
+#define PFE
+#endif
+
+#if STOP_ON_FE == 1
+#define FATAL_WNC_ERROR(v) {extern char *_fatal_err_loc;_fatal_err_loc=FATAL_STR;PFE;while(1);}
+#else
+#define FATAL_WNC_ERROR(v) {extern char *_fatal_err_loc;_fatal_err_loc=FATAL_STR;PFE;DORET(v);}
+#endif
+
+
+// Because the WncController has intermixed socket & interface functionallity
+// will need to make the Socket class a friend of the Interface class. This
+// will allow the Socket class to get to the WNC functions needed for the
+// socket. Forward reference the class
+
+class Socket;
+class Endpoint;
+class UDPSocket;
+class TCPSocketConnection;
+
+class WNCInterface
+{
+ class WncControllerK64F; //forward reference the Controller Class
+ friend class TCPSocketConnection;
+ friend class UDPSocket;
+ friend class Endpoint;
+ friend class Socket;
+
+public:
+ /** Create WNC Data Module Interface Instance for the device (M14A2A) */
+ WNCInterface();
+
+ /** Initialize the interface (no connection at this point).
+ * \return 0 on success, a negative number on failure
+ */
+ static int init(const char* apn=NULL, int debug=0);
+
+ /** Open an LTE internet data connection
+ @return 0 on success, error code on failure
+ */
+ int connect(void);
+
+ /** Disconnect
+ * Bring the interface down
+ * \return 0 on success, a negative number on failure
+ */
+ static int disconnect();
+
+ /** Because the WNCInterface is cellular based there is no MAC Ethernet address to return, so this function
+ * returns a bogus MAC address created from the ICCD on the SIM that is being used.
+ * \return a pointer to a pesudo-MAC string containing "NN:NN:NN:NN:NN:NN"
+ */
+ static char* getMACAddress();
+
+ /** Get the IP address of your Ethernet interface
+ * \return a pointer to a string containing the IP address
+ */
+ static char* getIPAddress();
+
+ /** Get the Gateway address of your Ethernet interface
+ * \return a pointer to a string containing the Gateway address
+ */
+ static char* getGateway();
+
+ /** Get the Network mask of your Ethernet interface
+ * \return a pointer to a string containing the Network mask
+ */
+ static char* getNetworkMask();
+
+ /** Manipulate the debug output of the WncController, for debug purposes.
+ * \return nothing.
+ */
+ void doDebug(int val); //doing this so I can get to the wnc controller pointer
+
+private:
+ static WncController_fk::WncIpStats myNetStats; //maintaint the network statistics
+ static WncControllerK64F_fk::WncControllerK64F *_pwnc; //pointer to the WncController instance
+ static string mac;
+};
+
+#endif /* _WNCINTERFACE_ */
+
+
