V.06 11/3

Dependencies:   FT6206 SDFileSystem SPI_TFT_ILI9341 TFT_fonts

Fork of ATT_AWS_IoT_demo by attiot

Committer:
jilee
Date:
Fri Nov 03 20:28:02 2017 +0000
Revision:
29:f71a0be59b99
Parent:
28:54d9a550adf1
v.06 11/03/2016

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ampembeng 15:6f2798e45099 1 /* =====================================================================
ampembeng 15:6f2798e45099 2 Copyright © 2016, Avnet (R)
ampembeng 15:6f2798e45099 3
ampembeng 15:6f2798e45099 4 Contributors:
ampembeng 15:6f2798e45099 5 * James M Flynn, www.em.avnet.com
ampembeng 15:6f2798e45099 6
ampembeng 15:6f2798e45099 7 Licensed under the Apache License, Version 2.0 (the "License");
ampembeng 15:6f2798e45099 8 you may not use this file except in compliance with the License.
ampembeng 15:6f2798e45099 9 You may obtain a copy of the License at
ampembeng 15:6f2798e45099 10
ampembeng 15:6f2798e45099 11 http://www.apache.org/licenses/LICENSE-2.0
ampembeng 15:6f2798e45099 12
ampembeng 15:6f2798e45099 13 Unless required by applicable law or agreed to in writing,
ampembeng 15:6f2798e45099 14 software distributed under the License is distributed on an
ampembeng 15:6f2798e45099 15 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
ampembeng 15:6f2798e45099 16 either express or implied. See the License for the specific
ampembeng 15:6f2798e45099 17 language governing permissions and limitations under the License.
ampembeng 15:6f2798e45099 18
ampembeng 15:6f2798e45099 19 @file WNCInterface.cpp
ampembeng 15:6f2798e45099 20 @version 1.0
ampembeng 15:6f2798e45099 21 @date Sept 2016
ampembeng 15:6f2798e45099 22 @author James Flynn
ampembeng 15:6f2798e45099 23
ampembeng 15:6f2798e45099 24 ======================================================================== */
ampembeng 15:6f2798e45099 25
ampembeng 15:6f2798e45099 26
ampembeng 15:6f2798e45099 27 #ifndef __MODULE__
ampembeng 15:6f2798e45099 28 #define __MODULE__ "WNCInterface.cpp"
ampembeng 15:6f2798e45099 29 #endif
ampembeng 15:6f2798e45099 30
ampembeng 15:6f2798e45099 31 #include "WNCInterface.h"
ampembeng 15:6f2798e45099 32
ampembeng 15:6f2798e45099 33 /////////////////////////////////////////////////////
ampembeng 15:6f2798e45099 34 // NXP GPIO Pins that are used to initialize the WNC Shield
ampembeng 15:6f2798e45099 35 /////////////////////////////////////////////////////
ampembeng 15:6f2798e45099 36 DigitalOut mdm_uart2_rx_boot_mode_sel(PTC17); // on powerup, 0 = boot mode, 1 = normal boot
ampembeng 15:6f2798e45099 37 DigitalOut mdm_power_on(PTB9); // 0 = turn modem on, 1 = turn modem off (should be held high for >5 seconds to cycle modem)
ampembeng 15:6f2798e45099 38 DigitalOut mdm_wakeup_in(PTC2); // 0 = let modem sleep, 1 = keep modem awake -- Note: pulled high on shield
ampembeng 15:6f2798e45099 39 DigitalOut mdm_reset(PTC12); // active high
ampembeng 15:6f2798e45099 40 DigitalOut shield_3v3_1v8_sig_trans_ena(PTC4); // 0 = disabled (all signals high impedence, 1 = translation active
ampembeng 15:6f2798e45099 41 DigitalOut mdm_uart1_cts(PTD0);
ampembeng 15:6f2798e45099 42
jilee 28:54d9a550adf1 43 //original value
jilee 28:54d9a550adf1 44 //DigitalOut shield_3v3_1v8_sig_trans_ena(PTC4); // 0 = disabled (all signals high impedence, 1 = translation active
jilee 28:54d9a550adf1 45 //DigitalOut mdm_uart1_cts(PTD0);
jilee 28:54d9a550adf1 46
jilee 28:54d9a550adf1 47
ampembeng 15:6f2798e45099 48 char * _fatal_err_loc; //GLOBAL::holds any error location info
ampembeng 15:6f2798e45099 49 MODSERIAL * _dbgout;
ampembeng 15:6f2798e45099 50 Mutex _WNCLock;
ampembeng 15:6f2798e45099 51
ampembeng 15:6f2798e45099 52 using namespace WncControllerK64F_fk; // namespace for the controller class use
ampembeng 15:6f2798e45099 53
ampembeng 15:6f2798e45099 54 // Define pin associations for the controller class to use be careful to
ampembeng 15:6f2798e45099 55 // keep the order of the pins in the initialization list.
ampembeng 15:6f2798e45099 56 WncGpioPinListK64F wncPinList = {
ampembeng 15:6f2798e45099 57 &mdm_uart2_rx_boot_mode_sel,
ampembeng 15:6f2798e45099 58 &mdm_power_on,
ampembeng 15:6f2798e45099 59 &mdm_wakeup_in,
ampembeng 15:6f2798e45099 60 &mdm_reset,
ampembeng 15:6f2798e45099 61 &shield_3v3_1v8_sig_trans_ena,
ampembeng 15:6f2798e45099 62 &mdm_uart1_cts
ampembeng 15:6f2798e45099 63 };
ampembeng 15:6f2798e45099 64
ampembeng 15:6f2798e45099 65 static MODSERIAL mdmUart(PTD3,PTD2,256,4096); //UART for WNC Module
ampembeng 15:6f2798e45099 66
ampembeng 15:6f2798e45099 67 WncControllerK64F *WNCInterface::_pwnc;
ampembeng 15:6f2798e45099 68 WncIpStats WNCInterface::myNetStats;
ampembeng 15:6f2798e45099 69 string WNCInterface::mac;
ampembeng 15:6f2798e45099 70
ampembeng 15:6f2798e45099 71 WNCInterface::WNCInterface() {
ampembeng 15:6f2798e45099 72 _dbgout = NULL;
ampembeng 15:6f2798e45099 73 }
ampembeng 15:6f2798e45099 74
ampembeng 15:6f2798e45099 75 void WNCInterface::doDebug( int v ) {
ampembeng 15:6f2798e45099 76 //basic debug = 0x01
ampembeng 15:6f2798e45099 77 //more debug = 0x02
ampembeng 15:6f2798e45099 78 //all debug = 0x03
ampembeng 15:6f2798e45099 79 M_LOCK;
ampembeng 15:6f2798e45099 80 _pwnc->enableDebug( (v&1), (v&2) );
ampembeng 15:6f2798e45099 81 M_ULOCK;
ampembeng 15:6f2798e45099 82 }
ampembeng 15:6f2798e45099 83
ampembeng 15:6f2798e45099 84 //
ampembeng 15:6f2798e45099 85 // Power-up the WNC module. The caller can optionally configure.
ampembeng 15:6f2798e45099 86 // Inputs:
ampembeng 15:6f2798e45099 87 // apn - Caller can specify an APN. If none is provided will use "m2m.com.attz"
ampembeng 15:6f2798e45099 88 // debug- specify the amount of debug the WNC controller should output:
ampembeng 15:6f2798e45099 89 // 1 - Basic Debug output
ampembeng 15:6f2798e45099 90 // 2 - Verbose Debug output
ampembeng 15:6f2798e45099 91 // 3 - Full Debug output
ampembeng 15:6f2798e45099 92 // Returns: 0 if unable to initialize the WNC module
ampembeng 15:6f2798e45099 93 // -1 if successfully initialized
ampembeng 15:6f2798e45099 94 //
ampembeng 15:6f2798e45099 95 int WNCInterface::init(const char* apn, MODSERIAL * debug) {
ampembeng 15:6f2798e45099 96 int ret = 0;
ampembeng 15:6f2798e45099 97
ampembeng 15:6f2798e45099 98 M_LOCK;
ampembeng 15:6f2798e45099 99 if( debug ) {
ampembeng 15:6f2798e45099 100 _dbgout = debug;
ampembeng 15:6f2798e45099 101 _pwnc = new WncControllerK64F_fk::WncControllerK64F::WncControllerK64F(&wncPinList, &mdmUart, debug);
ampembeng 15:6f2798e45099 102 #if WNC_DEBUG == 1
ampembeng 15:6f2798e45099 103 _pwnc->enableDebug(1,1);
ampembeng 15:6f2798e45099 104 #endif
ampembeng 15:6f2798e45099 105 }
ampembeng 15:6f2798e45099 106 else
ampembeng 15:6f2798e45099 107 _pwnc = new WncControllerK64F_fk::WncControllerK64F::WncControllerK64F(&wncPinList, &mdmUart, NULL);
ampembeng 15:6f2798e45099 108
ampembeng 15:6f2798e45099 109 if( apn==NULL )
ampembeng 15:6f2798e45099 110 apn = APN_DEFAULT;
ampembeng 15:6f2798e45099 111
ampembeng 15:6f2798e45099 112 ret = ( _pwnc->powerWncOn(apn,40) )? 2:0;
jilee 28:54d9a550adf1 113
ampembeng 15:6f2798e45099 114 ret |= ( _pwnc->setApnName(apn) )? 1:0;
ampembeng 15:6f2798e45099 115 ret |= ( _pwnc->getWncNetworkingStats(&myNetStats) )? 4:0;
ampembeng 15:6f2798e45099 116 M_ULOCK;
ampembeng 15:6f2798e45099 117
ampembeng 15:6f2798e45099 118 return ret;
ampembeng 15:6f2798e45099 119 }
ampembeng 15:6f2798e45099 120
ampembeng 15:6f2798e45099 121 //
ampembeng 15:6f2798e45099 122 // check to see if we are connected to the internet or not. The
ampembeng 15:6f2798e45099 123 // connection is supposed to happen during init. If we are
ampembeng 15:6f2798e45099 124 // connected to the internet return 0 otherwise return -1
ampembeng 15:6f2798e45099 125 //
ampembeng 15:6f2798e45099 126 int WNCInterface::connect(void) {
ampembeng 15:6f2798e45099 127 return ( _pwnc->getWncStatus() == WNC_GOOD )? 0 : -1;
ampembeng 15:6f2798e45099 128 }
ampembeng 15:6f2798e45099 129
ampembeng 15:6f2798e45099 130 //
ampembeng 15:6f2798e45099 131 // ok, the user wants to disconnect. At present, this isn't possible
ampembeng 15:6f2798e45099 132 // with the WNC, so just fake it and say we did...
ampembeng 15:6f2798e45099 133 //
ampembeng 15:6f2798e45099 134 int WNCInterface::disconnect() {
ampembeng 15:6f2798e45099 135 return 0;
ampembeng 15:6f2798e45099 136 }
ampembeng 15:6f2798e45099 137
ampembeng 15:6f2798e45099 138 //
ampembeng 15:6f2798e45099 139 // update the networking stats and return the IP Address
ampembeng 15:6f2798e45099 140 //
ampembeng 15:6f2798e45099 141 char * WNCInterface::getIPAddress() {
ampembeng 15:6f2798e45099 142 M_LOCK;
ampembeng 15:6f2798e45099 143 if ( _pwnc->getWncNetworkingStats(&myNetStats) ) {
ampembeng 15:6f2798e45099 144 CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), null);
ampembeng 15:6f2798e45099 145 M_ULOCK;
ampembeng 15:6f2798e45099 146 return &myNetStats.ip[0];
ampembeng 15:6f2798e45099 147 }
ampembeng 15:6f2798e45099 148 M_ULOCK;
ampembeng 15:6f2798e45099 149 return NULL;
ampembeng 15:6f2798e45099 150 }
ampembeng 15:6f2798e45099 151
ampembeng 15:6f2798e45099 152 //
ampembeng 15:6f2798e45099 153 // update the networking stats and return the Gateway Address
ampembeng 15:6f2798e45099 154 //
ampembeng 15:6f2798e45099 155 char * WNCInterface::getGateway() {
ampembeng 15:6f2798e45099 156 M_LOCK;
ampembeng 15:6f2798e45099 157 if ( _pwnc->getWncNetworkingStats(&myNetStats) ) {
ampembeng 15:6f2798e45099 158 CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), null);
ampembeng 15:6f2798e45099 159 M_ULOCK;
ampembeng 15:6f2798e45099 160 return &WNCInterface::myNetStats.gateway[0];
ampembeng 15:6f2798e45099 161 }
ampembeng 15:6f2798e45099 162 M_ULOCK;
ampembeng 15:6f2798e45099 163 return NULL;
ampembeng 15:6f2798e45099 164 }
ampembeng 15:6f2798e45099 165
ampembeng 15:6f2798e45099 166 //
ampembeng 15:6f2798e45099 167 // update the networking stats and return the Network Mask
ampembeng 15:6f2798e45099 168 //
ampembeng 15:6f2798e45099 169 char * WNCInterface::getNetworkMask() {
ampembeng 15:6f2798e45099 170 M_LOCK;
ampembeng 15:6f2798e45099 171 if ( _pwnc->getWncNetworkingStats(&myNetStats) ) {
ampembeng 15:6f2798e45099 172 CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), null);
ampembeng 15:6f2798e45099 173 M_ULOCK;
ampembeng 15:6f2798e45099 174 return &WNCInterface::myNetStats.mask[0];
ampembeng 15:6f2798e45099 175 }
ampembeng 15:6f2798e45099 176 M_ULOCK;
ampembeng 15:6f2798e45099 177 return NULL;
ampembeng 15:6f2798e45099 178 }
ampembeng 15:6f2798e45099 179
ampembeng 15:6f2798e45099 180 //
ampembeng 15:6f2798e45099 181 // return a pesudo-MAC address created from the ICCID
ampembeng 15:6f2798e45099 182 //
ampembeng 15:6f2798e45099 183 char* WNCInterface::getMACAddress( void ) {
ampembeng 15:6f2798e45099 184 string str;
ampembeng 15:6f2798e45099 185
ampembeng 15:6f2798e45099 186 M_LOCK;
ampembeng 15:6f2798e45099 187 if( _pwnc->getICCID(&str) ) {
ampembeng 15:6f2798e45099 188 CHK_WNCFE(( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG ), null);
ampembeng 15:6f2798e45099 189 mac = str.substr(3,20);
ampembeng 15:6f2798e45099 190 mac[2]=mac[5]=mac[8]=mac[11]=mac[14]=':';
ampembeng 15:6f2798e45099 191 M_ULOCK;
ampembeng 15:6f2798e45099 192 return (char*)mac.c_str();
ampembeng 15:6f2798e45099 193 }
ampembeng 15:6f2798e45099 194 M_ULOCK;
ampembeng 15:6f2798e45099 195 return NULL;
ampembeng 15:6f2798e45099 196 }
ampembeng 15:6f2798e45099 197
ampembeng 23:b9ff83dc965f 198 //
ampembeng 23:b9ff83dc965f 199 // return the ICCID
ampembeng 23:b9ff83dc965f 200 //
jilee 29:f71a0be59b99 201 void WNCInterface::getICCID(string *str)
jilee 29:f71a0be59b99 202 {
ampembeng 23:b9ff83dc965f 203 _pwnc->getICCID(str);
ampembeng 23:b9ff83dc965f 204 }
ampembeng 15:6f2798e45099 205
jilee 29:f71a0be59b99 206 void WNCInterface::getObject(string sObjectName, unsigned char *ucObject, int *iObjectLength)
jilee 29:f71a0be59b99 207 {
jilee 28:54d9a550adf1 208 _pwnc->getObject(sObjectName, ucObject, iObjectLength);
jilee 28:54d9a550adf1 209 }
jilee 29:f71a0be59b99 210
jilee 29:f71a0be59b99 211 int16_t WNCInterface::getSignalStrength()
jilee 29:f71a0be59b99 212 {
jilee 29:f71a0be59b99 213 return ( _pwnc->getDbmRssi());
jilee 29:f71a0be59b99 214 }
jilee 29:f71a0be59b99 215
jilee 29:f71a0be59b99 216 bool WNCInterface::getUpdateStatus(unsigned char *cStatus)
jilee 29:f71a0be59b99 217 {
jilee 29:f71a0be59b99 218 return ( _pwnc->getUpdateStatus(cStatus));
jilee 29:f71a0be59b99 219 }
jilee 29:f71a0be59b99 220
jilee 29:f71a0be59b99 221 bool WNCInterface::getAllObjects()
jilee 29:f71a0be59b99 222 {
jilee 29:f71a0be59b99 223 return ( _pwnc->getAllObjects());
jilee 29:f71a0be59b99 224 }