I added functionality to get the RSSI, BER, and Cell Neighbor for reporting connection issues to M2X
Dependencies: WncControllerK64F
WNCInterface.h@31:5a632bf373fb, 2019-04-18 (annotated)
- Committer:
- ng977t
- Date:
- Thu Apr 18 22:56:31 2019 +0000
- Revision:
- 31:5a632bf373fb
- Parent:
- 30:0b1a174c0d4f
I added functionality to get the RSSI, BER, and Cell Neighbor for reporting connection issues to M2X
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 | 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 | 10:9d8b23b60fd6 | 34 | #define WNC_DEBUG 0 //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 | 10:9d8b23b60fd6 | 71 | #define PFE {extern MODSERIAL *_dbgout;if(_dbgout)_dbgout->printf(RSTMSG "\r\n>>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 | 9:9f0578ff157a | 84 | #define CHK_WNCFE(x,y) if( x ){M_ULOCK; FATAL_WNC_ERROR(y);} |
JMF | 7:fded23f50479 | 85 | |
JMF | 0:55ec71dc0347 | 86 | // Because the WncController has intermixed socket & interface functionallity |
JMF | 0:55ec71dc0347 | 87 | // will need to make the Socket class a friend of the Interface class. This |
JMF | 0:55ec71dc0347 | 88 | // will allow the Socket class to get to the WNC functions needed for the |
JMF | 0:55ec71dc0347 | 89 | // socket. Forward reference the class |
JMF | 0:55ec71dc0347 | 90 | |
JMF | 28:dceb8da78e6d | 91 | class WncSocket; |
JMF | 27:2dc9461c04dc | 92 | class WncEndpoint; |
JMF | 28:dceb8da78e6d | 93 | class WncUDPSocket; |
JMF | 0:55ec71dc0347 | 94 | class TCPSocketConnection; |
JMF | 7:fded23f50479 | 95 | class WNCSms; |
JMF | 0:55ec71dc0347 | 96 | |
JMF | 0:55ec71dc0347 | 97 | class WNCInterface |
JMF | 0:55ec71dc0347 | 98 | { |
JMF | 0:55ec71dc0347 | 99 | class WncControllerK64F; //forward reference the Controller Class |
JMF | 0:55ec71dc0347 | 100 | friend class TCPSocketConnection; |
JMF | 28:dceb8da78e6d | 101 | friend class WncUDPSocket; |
JMF | 27:2dc9461c04dc | 102 | friend class WncEndpoint; |
JMF | 28:dceb8da78e6d | 103 | friend class WncSocket; |
JMF | 7:fded23f50479 | 104 | friend class WNCSms; |
JMF | 0:55ec71dc0347 | 105 | |
JMF | 0:55ec71dc0347 | 106 | public: |
JMF | 0:55ec71dc0347 | 107 | /** Create WNC Data Module Interface Instance for the device (M14A2A) */ |
JMF | 0:55ec71dc0347 | 108 | WNCInterface(); |
JMF | 0:55ec71dc0347 | 109 | |
JMF | 0:55ec71dc0347 | 110 | /** Initialize the interface (no connection at this point). |
JMF | 0:55ec71dc0347 | 111 | * \return 0 on success, a negative number on failure |
JMF | 0:55ec71dc0347 | 112 | */ |
JMF | 3:1d7e6ed11269 | 113 | static int init(const char* apn=NULL, MODSERIAL * debug=NULL); |
JMF | 0:55ec71dc0347 | 114 | |
JMF | 0:55ec71dc0347 | 115 | /** Open an LTE internet data connection |
JMF | 0:55ec71dc0347 | 116 | @return 0 on success, error code on failure |
JMF | 0:55ec71dc0347 | 117 | */ |
JMF | 0:55ec71dc0347 | 118 | int connect(void); |
JMF | 0:55ec71dc0347 | 119 | |
JMF | 0:55ec71dc0347 | 120 | /** Disconnect |
JMF | 0:55ec71dc0347 | 121 | * Bring the interface down |
JMF | 0:55ec71dc0347 | 122 | * \return 0 on success, a negative number on failure |
JMF | 0:55ec71dc0347 | 123 | */ |
JMF | 0:55ec71dc0347 | 124 | static int disconnect(); |
JMF | 0:55ec71dc0347 | 125 | |
JMF | 0:55ec71dc0347 | 126 | /** Because the WNCInterface is cellular based there is no MAC Ethernet address to return, so this function |
JMF | 0:55ec71dc0347 | 127 | * returns a bogus MAC address created from the ICCD on the SIM that is being used. |
JMF | 0:55ec71dc0347 | 128 | * \return a pointer to a pesudo-MAC string containing "NN:NN:NN:NN:NN:NN" |
JMF | 0:55ec71dc0347 | 129 | */ |
JMF | 0:55ec71dc0347 | 130 | static char* getMACAddress(); |
JMF | 0:55ec71dc0347 | 131 | |
JMF | 0:55ec71dc0347 | 132 | /** Get the IP address of your Ethernet interface |
JMF | 0:55ec71dc0347 | 133 | * \return a pointer to a string containing the IP address |
JMF | 0:55ec71dc0347 | 134 | */ |
JMF | 0:55ec71dc0347 | 135 | static char* getIPAddress(); |
JMF | 0:55ec71dc0347 | 136 | |
JMF | 0:55ec71dc0347 | 137 | /** Get the Gateway address of your Ethernet interface |
JMF | 0:55ec71dc0347 | 138 | * \return a pointer to a string containing the Gateway address |
JMF | 0:55ec71dc0347 | 139 | */ |
JMF | 0:55ec71dc0347 | 140 | static char* getGateway(); |
JMF | 0:55ec71dc0347 | 141 | |
JMF | 0:55ec71dc0347 | 142 | /** Get the Network mask of your Ethernet interface |
JMF | 0:55ec71dc0347 | 143 | * \return a pointer to a string containing the Network mask |
JMF | 0:55ec71dc0347 | 144 | */ |
JMF | 0:55ec71dc0347 | 145 | static char* getNetworkMask(); |
JMF | 0:55ec71dc0347 | 146 | |
JMF | 0:55ec71dc0347 | 147 | /** Manipulate the debug output of the WncController, for debug purposes. |
JMF | 0:55ec71dc0347 | 148 | * \return nothing. |
JMF | 0:55ec71dc0347 | 149 | */ |
JMF | 0:55ec71dc0347 | 150 | void doDebug(int val); //doing this so I can get to the wnc controller pointer |
JMF | 7:fded23f50479 | 151 | |
ng977t | 30:0b1a174c0d4f | 152 | static int16_t getRSSI(); // to get the RSSI - Nate |
ng977t | 30:0b1a174c0d4f | 153 | static int16_t get3gBer(); // to get the ber - Nate |
ng977t | 30:0b1a174c0d4f | 154 | static string * readCellNeighbor_wnc();// Reads cell towwr neightbow - Nate |
JMF | 7:fded23f50479 | 155 | |
JMF | 0:55ec71dc0347 | 156 | private: |
JMF | 0:55ec71dc0347 | 157 | static WncController_fk::WncIpStats myNetStats; //maintaint the network statistics |
JMF | 0:55ec71dc0347 | 158 | static WncControllerK64F_fk::WncControllerK64F *_pwnc; //pointer to the WncController instance |
JMF | 0:55ec71dc0347 | 159 | static string mac; |
JMF | 7:fded23f50479 | 160 | |
JMF | 0:55ec71dc0347 | 161 | }; |
JMF | 0:55ec71dc0347 | 162 | |
JMF | 0:55ec71dc0347 | 163 | #endif /* _WNCINTERFACE_ */ |
JMF | 0:55ec71dc0347 | 164 |