publish final code
Dependencies: WncControllerK64F
Fork of WNCInterface by
WNCInterface.h@0:55ec71dc0347, 2016-09-21 (annotated)
- Committer:
- JMF
- Date:
- Wed Sep 21 14:30:06 2016 +0000
- Revision:
- 0:55ec71dc0347
- Child:
- 3:1d7e6ed11269
Initial Commit
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 | 0:55ec71dc0347 | 38 | #define APN_DEFAULT "m2m.com.attz" |
JMF | 0:55ec71dc0347 | 39 | |
JMF | 0:55ec71dc0347 | 40 | // |
JMF | 0:55ec71dc0347 | 41 | // WNC Error Handling macros & data |
JMF | 0:55ec71dc0347 | 42 | // |
JMF | 0:55ec71dc0347 | 43 | #define FATAL_FLAG WncController_fk::WncController::WNC_NO_RESPONSE |
JMF | 0:55ec71dc0347 | 44 | #define WNC_GOOD WncController_fk::WncController::WNC_ON |
JMF | 0:55ec71dc0347 | 45 | |
JMF | 0:55ec71dc0347 | 46 | #define RETfail return -1 |
JMF | 0:55ec71dc0347 | 47 | #define RETvoid return |
JMF | 0:55ec71dc0347 | 48 | #define RETnull return NULL |
JMF | 0:55ec71dc0347 | 49 | #define DORET(x) RET##x |
JMF | 0:55ec71dc0347 | 50 | |
JMF | 0:55ec71dc0347 | 51 | #define TOSTR(x) #x |
JMF | 0:55ec71dc0347 | 52 | #define INTSTR(x) TOSTR(x) |
JMF | 0:55ec71dc0347 | 53 | #define FATAL_STR __FILE__ ":" INTSTR(__LINE__) |
JMF | 0:55ec71dc0347 | 54 | |
JMF | 0:55ec71dc0347 | 55 | #if DISPLAY_FE == 1 |
JMF | 0:55ec71dc0347 | 56 | #define PFE printf("WNC FAILED @ %s\r\n", FATAL_STR) |
JMF | 0:55ec71dc0347 | 57 | #else |
JMF | 0:55ec71dc0347 | 58 | #define PFE |
JMF | 0:55ec71dc0347 | 59 | #endif |
JMF | 0:55ec71dc0347 | 60 | |
JMF | 0:55ec71dc0347 | 61 | #if STOP_ON_FE == 1 |
JMF | 0:55ec71dc0347 | 62 | #define FATAL_WNC_ERROR(v) {extern char *_fatal_err_loc;_fatal_err_loc=FATAL_STR;PFE;while(1);} |
JMF | 0:55ec71dc0347 | 63 | #else |
JMF | 0:55ec71dc0347 | 64 | #define FATAL_WNC_ERROR(v) {extern char *_fatal_err_loc;_fatal_err_loc=FATAL_STR;PFE;DORET(v);} |
JMF | 0:55ec71dc0347 | 65 | #endif |
JMF | 0:55ec71dc0347 | 66 | |
JMF | 0:55ec71dc0347 | 67 | |
JMF | 0:55ec71dc0347 | 68 | // Because the WncController has intermixed socket & interface functionallity |
JMF | 0:55ec71dc0347 | 69 | // will need to make the Socket class a friend of the Interface class. This |
JMF | 0:55ec71dc0347 | 70 | // will allow the Socket class to get to the WNC functions needed for the |
JMF | 0:55ec71dc0347 | 71 | // socket. Forward reference the class |
JMF | 0:55ec71dc0347 | 72 | |
JMF | 0:55ec71dc0347 | 73 | class Socket; |
JMF | 0:55ec71dc0347 | 74 | class Endpoint; |
JMF | 0:55ec71dc0347 | 75 | class UDPSocket; |
JMF | 0:55ec71dc0347 | 76 | class TCPSocketConnection; |
JMF | 0:55ec71dc0347 | 77 | |
JMF | 0:55ec71dc0347 | 78 | class WNCInterface |
JMF | 0:55ec71dc0347 | 79 | { |
JMF | 0:55ec71dc0347 | 80 | class WncControllerK64F; //forward reference the Controller Class |
JMF | 0:55ec71dc0347 | 81 | friend class TCPSocketConnection; |
JMF | 0:55ec71dc0347 | 82 | friend class UDPSocket; |
JMF | 0:55ec71dc0347 | 83 | friend class Endpoint; |
JMF | 0:55ec71dc0347 | 84 | friend class Socket; |
JMF | 0:55ec71dc0347 | 85 | |
JMF | 0:55ec71dc0347 | 86 | public: |
JMF | 0:55ec71dc0347 | 87 | /** Create WNC Data Module Interface Instance for the device (M14A2A) */ |
JMF | 0:55ec71dc0347 | 88 | WNCInterface(); |
JMF | 0:55ec71dc0347 | 89 | |
JMF | 0:55ec71dc0347 | 90 | /** Initialize the interface (no connection at this point). |
JMF | 0:55ec71dc0347 | 91 | * \return 0 on success, a negative number on failure |
JMF | 0:55ec71dc0347 | 92 | */ |
JMF | 0:55ec71dc0347 | 93 | static int init(const char* apn=NULL, int debug=0); |
JMF | 0:55ec71dc0347 | 94 | |
JMF | 0:55ec71dc0347 | 95 | /** Open an LTE internet data connection |
JMF | 0:55ec71dc0347 | 96 | @return 0 on success, error code on failure |
JMF | 0:55ec71dc0347 | 97 | */ |
JMF | 0:55ec71dc0347 | 98 | int connect(void); |
JMF | 0:55ec71dc0347 | 99 | |
JMF | 0:55ec71dc0347 | 100 | /** Disconnect |
JMF | 0:55ec71dc0347 | 101 | * Bring the interface down |
JMF | 0:55ec71dc0347 | 102 | * \return 0 on success, a negative number on failure |
JMF | 0:55ec71dc0347 | 103 | */ |
JMF | 0:55ec71dc0347 | 104 | static int disconnect(); |
JMF | 0:55ec71dc0347 | 105 | |
JMF | 0:55ec71dc0347 | 106 | /** Because the WNCInterface is cellular based there is no MAC Ethernet address to return, so this function |
JMF | 0:55ec71dc0347 | 107 | * returns a bogus MAC address created from the ICCD on the SIM that is being used. |
JMF | 0:55ec71dc0347 | 108 | * \return a pointer to a pesudo-MAC string containing "NN:NN:NN:NN:NN:NN" |
JMF | 0:55ec71dc0347 | 109 | */ |
JMF | 0:55ec71dc0347 | 110 | static char* getMACAddress(); |
JMF | 0:55ec71dc0347 | 111 | |
JMF | 0:55ec71dc0347 | 112 | /** Get the IP address of your Ethernet interface |
JMF | 0:55ec71dc0347 | 113 | * \return a pointer to a string containing the IP address |
JMF | 0:55ec71dc0347 | 114 | */ |
JMF | 0:55ec71dc0347 | 115 | static char* getIPAddress(); |
JMF | 0:55ec71dc0347 | 116 | |
JMF | 0:55ec71dc0347 | 117 | /** Get the Gateway address of your Ethernet interface |
JMF | 0:55ec71dc0347 | 118 | * \return a pointer to a string containing the Gateway address |
JMF | 0:55ec71dc0347 | 119 | */ |
JMF | 0:55ec71dc0347 | 120 | static char* getGateway(); |
JMF | 0:55ec71dc0347 | 121 | |
JMF | 0:55ec71dc0347 | 122 | /** Get the Network mask of your Ethernet interface |
JMF | 0:55ec71dc0347 | 123 | * \return a pointer to a string containing the Network mask |
JMF | 0:55ec71dc0347 | 124 | */ |
JMF | 0:55ec71dc0347 | 125 | static char* getNetworkMask(); |
JMF | 0:55ec71dc0347 | 126 | |
JMF | 0:55ec71dc0347 | 127 | /** Manipulate the debug output of the WncController, for debug purposes. |
JMF | 0:55ec71dc0347 | 128 | * \return nothing. |
JMF | 0:55ec71dc0347 | 129 | */ |
JMF | 0:55ec71dc0347 | 130 | void doDebug(int val); //doing this so I can get to the wnc controller pointer |
JMF | 0:55ec71dc0347 | 131 | |
JMF | 0:55ec71dc0347 | 132 | private: |
JMF | 0:55ec71dc0347 | 133 | static WncController_fk::WncIpStats myNetStats; //maintaint the network statistics |
JMF | 0:55ec71dc0347 | 134 | static WncControllerK64F_fk::WncControllerK64F *_pwnc; //pointer to the WncController instance |
JMF | 0:55ec71dc0347 | 135 | static string mac; |
JMF | 0:55ec71dc0347 | 136 | }; |
JMF | 0:55ec71dc0347 | 137 | |
JMF | 0:55ec71dc0347 | 138 | #endif /* _WNCINTERFACE_ */ |
JMF | 0:55ec71dc0347 | 139 | |
JMF | 0:55ec71dc0347 | 140 |