publish final code
Dependencies: WncControllerK64F
Fork of WNCInterface by
WNCInterface.h@3:1d7e6ed11269, 2016-09-27 (annotated)
- Committer:
- JMF
- Date:
- Tue Sep 27 19:16:22 2016 +0000
- Revision:
- 3:1d7e6ed11269
- Parent:
- 0:55ec71dc0347
- Child:
- 5:759dceff95b9
Changed creation of WncControllerK64F class from static to dynamic so that it can be created either with or without the debug port. The caller must provide a pointer to a MODSERIAL object if they want debug output.
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:55ec71dc0347 | 28 | |
JMF | 0:55ec71dc0347 | 29 | #ifndef _WNCINTERFACE_H_ |
JMF | 0:55ec71dc0347 | 30 | #define _WNCINTERFACE_H_ |
JMF | 0:55ec71dc0347 | 31 | |
JMF | 0:55ec71dc0347 | 32 | #define WNC_DEBUG 1 //1=enable the WNC debug port |
JMF | 0:55ec71dc0347 | 33 | //0=disable the WNC debug port |
JMF | 0:55ec71dc0347 | 34 | #define STOP_ON_FE 1 //1=hang forever if a fatal error occurs |
JMF | 0:55ec71dc0347 | 35 | //0=simply return failed response for all socket calls |
JMF | 0:55ec71dc0347 | 36 | #define DISPLAY_FE 1 //1 to display the fatal error when it occurs |
JMF | 0:55ec71dc0347 | 37 | //0 to NOT display the fatal error |
JMF | 3:1d7e6ed11269 | 38 | #define RESETON_FE 1 //1 to cause the MCU to reset on fatal error |
JMF | 3:1d7e6ed11269 | 39 | //0 to NOT reset the MCU |
JMF | 0:55ec71dc0347 | 40 | #define APN_DEFAULT "m2m.com.attz" |
JMF | 0:55ec71dc0347 | 41 | |
JMF | 0:55ec71dc0347 | 42 | // |
JMF | 0:55ec71dc0347 | 43 | // WNC Error Handling macros & data |
JMF | 0:55ec71dc0347 | 44 | // |
JMF | 0:55ec71dc0347 | 45 | #define FATAL_FLAG WncController_fk::WncController::WNC_NO_RESPONSE |
JMF | 0:55ec71dc0347 | 46 | #define WNC_GOOD WncController_fk::WncController::WNC_ON |
JMF | 0:55ec71dc0347 | 47 | |
JMF | 0:55ec71dc0347 | 48 | #define RETfail return -1 |
JMF | 0:55ec71dc0347 | 49 | #define RETvoid return |
JMF | 0:55ec71dc0347 | 50 | #define RETnull return NULL |
JMF | 3:1d7e6ed11269 | 51 | #define RETresume |
JMF | 3:1d7e6ed11269 | 52 | |
JMF | 0:55ec71dc0347 | 53 | #define DORET(x) RET##x |
JMF | 0:55ec71dc0347 | 54 | |
JMF | 0:55ec71dc0347 | 55 | #define TOSTR(x) #x |
JMF | 0:55ec71dc0347 | 56 | #define INTSTR(x) TOSTR(x) |
JMF | 0:55ec71dc0347 | 57 | #define FATAL_STR __FILE__ ":" INTSTR(__LINE__) |
JMF | 0:55ec71dc0347 | 58 | |
JMF | 3:1d7e6ed11269 | 59 | #if RESETON_FE == 1 |
JMF | 3:1d7e6ed11269 | 60 | #define MCURESET ((*((volatile unsigned long *)0xE000ED0CU))=(unsigned long)((0x5fa<<16) | 0x04L)) |
JMF | 3:1d7e6ed11269 | 61 | #define RSTMSG "RESET MCU! " |
JMF | 3:1d7e6ed11269 | 62 | #else |
JMF | 3:1d7e6ed11269 | 63 | #define MCURESET |
JMF | 3:1d7e6ed11269 | 64 | #define RSTMSG "" |
JMF | 3:1d7e6ed11269 | 65 | #endif |
JMF | 3:1d7e6ed11269 | 66 | |
JMF | 0:55ec71dc0347 | 67 | #if DISPLAY_FE == 1 |
JMF | 3:1d7e6ed11269 | 68 | #define PFE printf(RSTMSG "WNC FAILED @ %s\r\n", FATAL_STR) |
JMF | 0:55ec71dc0347 | 69 | #else |
JMF | 0:55ec71dc0347 | 70 | #define PFE |
JMF | 0:55ec71dc0347 | 71 | #endif |
JMF | 0:55ec71dc0347 | 72 | |
JMF | 0:55ec71dc0347 | 73 | #if STOP_ON_FE == 1 |
JMF | 3:1d7e6ed11269 | 74 | #define FATAL_WNC_ERROR(v) {extern char *_fatal_err_loc;_fatal_err_loc=FATAL_STR;PFE;MCURESET;while(1);} |
JMF | 0:55ec71dc0347 | 75 | #else |
JMF | 0:55ec71dc0347 | 76 | #define FATAL_WNC_ERROR(v) {extern char *_fatal_err_loc;_fatal_err_loc=FATAL_STR;PFE;DORET(v);} |
JMF | 0:55ec71dc0347 | 77 | #endif |
JMF | 0:55ec71dc0347 | 78 | |
JMF | 0:55ec71dc0347 | 79 | // Because the WncController has intermixed socket & interface functionallity |
JMF | 0:55ec71dc0347 | 80 | // will need to make the Socket class a friend of the Interface class. This |
JMF | 0:55ec71dc0347 | 81 | // will allow the Socket class to get to the WNC functions needed for the |
JMF | 0:55ec71dc0347 | 82 | // socket. Forward reference the class |
JMF | 0:55ec71dc0347 | 83 | |
JMF | 0:55ec71dc0347 | 84 | class Socket; |
JMF | 0:55ec71dc0347 | 85 | class Endpoint; |
JMF | 0:55ec71dc0347 | 86 | class UDPSocket; |
JMF | 0:55ec71dc0347 | 87 | class TCPSocketConnection; |
JMF | 0:55ec71dc0347 | 88 | |
JMF | 0:55ec71dc0347 | 89 | class WNCInterface |
JMF | 0:55ec71dc0347 | 90 | { |
JMF | 0:55ec71dc0347 | 91 | class WncControllerK64F; //forward reference the Controller Class |
JMF | 0:55ec71dc0347 | 92 | friend class TCPSocketConnection; |
JMF | 0:55ec71dc0347 | 93 | friend class UDPSocket; |
JMF | 0:55ec71dc0347 | 94 | friend class Endpoint; |
JMF | 0:55ec71dc0347 | 95 | friend class Socket; |
JMF | 0:55ec71dc0347 | 96 | |
JMF | 0:55ec71dc0347 | 97 | public: |
JMF | 0:55ec71dc0347 | 98 | /** Create WNC Data Module Interface Instance for the device (M14A2A) */ |
JMF | 0:55ec71dc0347 | 99 | WNCInterface(); |
JMF | 0:55ec71dc0347 | 100 | |
JMF | 0:55ec71dc0347 | 101 | /** Initialize the interface (no connection at this point). |
JMF | 0:55ec71dc0347 | 102 | * \return 0 on success, a negative number on failure |
JMF | 0:55ec71dc0347 | 103 | */ |
JMF | 3:1d7e6ed11269 | 104 | static int init(const char* apn=NULL, MODSERIAL * debug=NULL); |
JMF | 0:55ec71dc0347 | 105 | |
JMF | 0:55ec71dc0347 | 106 | /** Open an LTE internet data connection |
JMF | 0:55ec71dc0347 | 107 | @return 0 on success, error code on failure |
JMF | 0:55ec71dc0347 | 108 | */ |
JMF | 0:55ec71dc0347 | 109 | int connect(void); |
JMF | 0:55ec71dc0347 | 110 | |
JMF | 0:55ec71dc0347 | 111 | /** Disconnect |
JMF | 0:55ec71dc0347 | 112 | * Bring the interface down |
JMF | 0:55ec71dc0347 | 113 | * \return 0 on success, a negative number on failure |
JMF | 0:55ec71dc0347 | 114 | */ |
JMF | 0:55ec71dc0347 | 115 | static int disconnect(); |
JMF | 0:55ec71dc0347 | 116 | |
JMF | 0:55ec71dc0347 | 117 | /** Because the WNCInterface is cellular based there is no MAC Ethernet address to return, so this function |
JMF | 0:55ec71dc0347 | 118 | * returns a bogus MAC address created from the ICCD on the SIM that is being used. |
JMF | 0:55ec71dc0347 | 119 | * \return a pointer to a pesudo-MAC string containing "NN:NN:NN:NN:NN:NN" |
JMF | 0:55ec71dc0347 | 120 | */ |
JMF | 0:55ec71dc0347 | 121 | static char* getMACAddress(); |
JMF | 0:55ec71dc0347 | 122 | |
JMF | 0:55ec71dc0347 | 123 | /** Get the IP address of your Ethernet interface |
JMF | 0:55ec71dc0347 | 124 | * \return a pointer to a string containing the IP address |
JMF | 0:55ec71dc0347 | 125 | */ |
JMF | 0:55ec71dc0347 | 126 | static char* getIPAddress(); |
JMF | 0:55ec71dc0347 | 127 | |
JMF | 0:55ec71dc0347 | 128 | /** Get the Gateway address of your Ethernet interface |
JMF | 0:55ec71dc0347 | 129 | * \return a pointer to a string containing the Gateway address |
JMF | 0:55ec71dc0347 | 130 | */ |
JMF | 0:55ec71dc0347 | 131 | static char* getGateway(); |
JMF | 0:55ec71dc0347 | 132 | |
JMF | 0:55ec71dc0347 | 133 | /** Get the Network mask of your Ethernet interface |
JMF | 0:55ec71dc0347 | 134 | * \return a pointer to a string containing the Network mask |
JMF | 0:55ec71dc0347 | 135 | */ |
JMF | 0:55ec71dc0347 | 136 | static char* getNetworkMask(); |
JMF | 0:55ec71dc0347 | 137 | |
JMF | 0:55ec71dc0347 | 138 | /** Manipulate the debug output of the WncController, for debug purposes. |
JMF | 0:55ec71dc0347 | 139 | * \return nothing. |
JMF | 0:55ec71dc0347 | 140 | */ |
JMF | 0:55ec71dc0347 | 141 | void doDebug(int val); //doing this so I can get to the wnc controller pointer |
JMF | 0:55ec71dc0347 | 142 | |
JMF | 0:55ec71dc0347 | 143 | private: |
JMF | 0:55ec71dc0347 | 144 | static WncController_fk::WncIpStats myNetStats; //maintaint the network statistics |
JMF | 0:55ec71dc0347 | 145 | static WncControllerK64F_fk::WncControllerK64F *_pwnc; //pointer to the WncController instance |
JMF | 0:55ec71dc0347 | 146 | static string mac; |
JMF | 0:55ec71dc0347 | 147 | }; |
JMF | 0:55ec71dc0347 | 148 | |
JMF | 0:55ec71dc0347 | 149 | #endif /* _WNCINTERFACE_ */ |
JMF | 0:55ec71dc0347 | 150 | |
JMF | 0:55ec71dc0347 | 151 |