The WDCInterface is is a drop-in replacement for an EthernetInterface class that allows the user to connect to the Internet with a Wistron NeWeb Corporation (WNC) M14A2A Series data module using the standard network Socket API's. This interface class is used in the AT&T Cellular IoT Starter Kit which is sold by Avnet (http://cloudconnectkits.org/product/att-cellular-iot-starter-kit).

Dependencies:   WncControllerK64F

Dependents:   WNCProximityMqtt Pubnub_ATT_IoT_SK_WNC_sync BluemixDemo BluemixQS ... more

See the WNCInterface README in the Wiki tab for detailed information on this library.

Committer:
JMF
Date:
Tue Sep 27 19:16:22 2016 +0000
Revision:
3:1d7e6ed11269
Parent:
0:55ec71dc0347
Child:
4:99e7aeaceae7
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?

UserRevisionLine numberNew 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 M 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.cpp
JMF 0:55ec71dc0347 20 @version 1.0
JMF 0:55ec71dc0347 21 @date Sept 2016
JMF 0:55ec71dc0347 22 @author James Flynn
JMF 0:55ec71dc0347 23
JMF 0:55ec71dc0347 24 ======================================================================== */
JMF 0:55ec71dc0347 25
JMF 0:55ec71dc0347 26
JMF 0:55ec71dc0347 27 #ifndef __MODULE__
JMF 0:55ec71dc0347 28 #define __MODULE__ "WNCInterface.cpp"
JMF 0:55ec71dc0347 29 #endif
JMF 0:55ec71dc0347 30
JMF 0:55ec71dc0347 31 #include "WNCInterface.h"
JMF 0:55ec71dc0347 32
JMF 0:55ec71dc0347 33 /////////////////////////////////////////////////////
JMF 0:55ec71dc0347 34 // NXP GPIO Pins that are used to initialize the WNC Shield
JMF 0:55ec71dc0347 35 /////////////////////////////////////////////////////
JMF 0:55ec71dc0347 36 DigitalOut mdm_uart2_rx_boot_mode_sel(PTC17); // on powerup, 0 = boot mode, 1 = normal boot
JMF 0:55ec71dc0347 37 DigitalOut mdm_power_on(PTB9); // 0 = turn modem on, 1 = turn modem off (should be held high for >5 seconds to cycle modem)
JMF 0:55ec71dc0347 38 DigitalOut mdm_wakeup_in(PTC2); // 0 = let modem sleep, 1 = keep modem awake -- Note: pulled high on shield
JMF 0:55ec71dc0347 39 DigitalOut mdm_reset(PTC12); // active high
JMF 0:55ec71dc0347 40 DigitalOut shield_3v3_1v8_sig_trans_ena(PTC4); // 0 = disabled (all signals high impedence, 1 = translation active
JMF 0:55ec71dc0347 41 DigitalOut mdm_uart1_cts(PTD0);
JMF 0:55ec71dc0347 42
JMF 0:55ec71dc0347 43 char * _fatal_err_loc; //GLOBAL::holds any error location info
JMF 0:55ec71dc0347 44
JMF 0:55ec71dc0347 45 using namespace WncControllerK64F_fk; // namespace for the controller class use
JMF 0:55ec71dc0347 46
JMF 0:55ec71dc0347 47 // Define pin associations for the controller class to use be careful to
JMF 0:55ec71dc0347 48 // keep the order of the pins in the initialization list.
JMF 0:55ec71dc0347 49 WncGpioPinListK64F wncPinList = {
JMF 0:55ec71dc0347 50 &mdm_uart2_rx_boot_mode_sel,
JMF 0:55ec71dc0347 51 &mdm_power_on,
JMF 0:55ec71dc0347 52 &mdm_wakeup_in,
JMF 0:55ec71dc0347 53 &mdm_reset,
JMF 0:55ec71dc0347 54 &shield_3v3_1v8_sig_trans_ena,
JMF 0:55ec71dc0347 55 &mdm_uart1_cts
JMF 0:55ec71dc0347 56 };
JMF 0:55ec71dc0347 57
JMF 0:55ec71dc0347 58 static MODSERIAL mdmUart(PTD3,PTD2,256,4096); //UART for WNC Module
JMF 0:55ec71dc0347 59
JMF 3:1d7e6ed11269 60 WncControllerK64F *WNCInterface::_pwnc;
JMF 0:55ec71dc0347 61 WncIpStats WNCInterface::myNetStats;
JMF 0:55ec71dc0347 62 string WNCInterface::mac;
JMF 0:55ec71dc0347 63
JMF 0:55ec71dc0347 64 WNCInterface::WNCInterface() {
JMF 0:55ec71dc0347 65 }
JMF 0:55ec71dc0347 66
JMF 0:55ec71dc0347 67 void WNCInterface::doDebug( int v ) {
JMF 0:55ec71dc0347 68 //basic debug = 0x01
JMF 0:55ec71dc0347 69 //more debug = 0x02
JMF 0:55ec71dc0347 70 //all debug = 0x03
JMF 0:55ec71dc0347 71 _pwnc->enableDebug( (v&1), (v&2) );
JMF 0:55ec71dc0347 72 }
JMF 0:55ec71dc0347 73
JMF 0:55ec71dc0347 74 //
JMF 0:55ec71dc0347 75 // Power-up the WNC module. The caller can optionally configure.
JMF 0:55ec71dc0347 76 // Inputs:
JMF 0:55ec71dc0347 77 // apn - Caller can specify an APN. If none is provided will use "m2m.com.attz"
JMF 0:55ec71dc0347 78 // debug- specify the amount of debug the WNC controller should output:
JMF 0:55ec71dc0347 79 // 1 - Basic Debug output
JMF 0:55ec71dc0347 80 // 2 - Verbose Debug output
JMF 0:55ec71dc0347 81 // 3 - Full Debug output
JMF 0:55ec71dc0347 82 // Returns: 0 if unable to initialize the WNC module
JMF 0:55ec71dc0347 83 // -1 if successfully initialized
JMF 0:55ec71dc0347 84 //
JMF 3:1d7e6ed11269 85 int WNCInterface::init(const char* apn, MODSERIAL * debug) {
JMF 0:55ec71dc0347 86 int ret = 0;
JMF 0:55ec71dc0347 87 _pwnc = &wnc; //set the pointer to the WNC controller class. Used for all WNC accesses
JMF 0:55ec71dc0347 88
JMF 3:1d7e6ed11269 89 if( debug )
JMF 3:1d7e6ed11269 90 _pwnc = new WncControllerK64F_fk::WncControllerK64F::WncControllerK64F(&wncPinList, &mdmUart, debug);
JMF 3:1d7e6ed11269 91 else
JMF 3:1d7e6ed11269 92 _pwnc = new WncControllerK64F_fk::WncControllerK64F::WncControllerK64F(&wncPinList, &mdmUart, NULL);
JMF 3:1d7e6ed11269 93
JMF 0:55ec71dc0347 94 if( apn==NULL )
JMF 0:55ec71dc0347 95 apn = APN_DEFAULT;
JMF 0:55ec71dc0347 96
JMF 0:55ec71dc0347 97 ret = ( _pwnc->powerWncOn(apn,40) )? 2:0;
JMF 0:55ec71dc0347 98 ret |= ( _pwnc->setApnName(apn) )? 1:0;
JMF 0:55ec71dc0347 99 ret |= ( _pwnc->getWncNetworkingStats(&myNetStats) )? 4:0;
JMF 0:55ec71dc0347 100
JMF 0:55ec71dc0347 101 return ret;
JMF 0:55ec71dc0347 102 }
JMF 0:55ec71dc0347 103
JMF 0:55ec71dc0347 104 //
JMF 0:55ec71dc0347 105 // check to see if we are connected to the internet or not. The
JMF 0:55ec71dc0347 106 // connection is supposed to happen during init. If we are
JMF 0:55ec71dc0347 107 // connected to the internet return 0 otherwise return -1
JMF 0:55ec71dc0347 108 //
JMF 0:55ec71dc0347 109 int WNCInterface::connect(void) {
JMF 0:55ec71dc0347 110 return ( _pwnc->getWncStatus() == WNC_GOOD )? 0 : -1;
JMF 0:55ec71dc0347 111 }
JMF 0:55ec71dc0347 112
JMF 0:55ec71dc0347 113 //
JMF 0:55ec71dc0347 114 // ok, the user wants to disconnect. At present, this isn't possible
JMF 0:55ec71dc0347 115 // with the WNC, so just fake it and say we did...
JMF 0:55ec71dc0347 116 //
JMF 0:55ec71dc0347 117 int WNCInterface::disconnect() {
JMF 0:55ec71dc0347 118 return 0;
JMF 0:55ec71dc0347 119 }
JMF 0:55ec71dc0347 120
JMF 0:55ec71dc0347 121 //
JMF 0:55ec71dc0347 122 // update the networking stats and return the IP Address
JMF 0:55ec71dc0347 123 //
JMF 0:55ec71dc0347 124 char * WNCInterface::getIPAddress() {
JMF 0:55ec71dc0347 125 if ( _pwnc->getWncNetworkingStats(&myNetStats) ) {
JMF 0:55ec71dc0347 126 if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
JMF 0:55ec71dc0347 127 FATAL_WNC_ERROR(null);
JMF 0:55ec71dc0347 128 return &myNetStats.ip[0];
JMF 0:55ec71dc0347 129 }
JMF 0:55ec71dc0347 130 return NULL;
JMF 0:55ec71dc0347 131 }
JMF 0:55ec71dc0347 132
JMF 0:55ec71dc0347 133 //
JMF 0:55ec71dc0347 134 // update the networking stats and return the Gateway Address
JMF 0:55ec71dc0347 135 //
JMF 0:55ec71dc0347 136 char * WNCInterface::getGateway() {
JMF 0:55ec71dc0347 137 if ( _pwnc->getWncNetworkingStats(&myNetStats) ) {
JMF 0:55ec71dc0347 138 if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
JMF 0:55ec71dc0347 139 FATAL_WNC_ERROR(null);
JMF 0:55ec71dc0347 140 return &WNCInterface::myNetStats.gateway[0];
JMF 0:55ec71dc0347 141 }
JMF 0:55ec71dc0347 142 return NULL;
JMF 0:55ec71dc0347 143 }
JMF 0:55ec71dc0347 144
JMF 0:55ec71dc0347 145 //
JMF 0:55ec71dc0347 146 // update the networking stats and return the Network Mask
JMF 0:55ec71dc0347 147 //
JMF 0:55ec71dc0347 148 char * WNCInterface::getNetworkMask() {
JMF 0:55ec71dc0347 149 if ( _pwnc->getWncNetworkingStats(&myNetStats) ) {
JMF 0:55ec71dc0347 150 if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
JMF 0:55ec71dc0347 151 FATAL_WNC_ERROR(null);
JMF 0:55ec71dc0347 152 return &WNCInterface::myNetStats.mask[0];
JMF 0:55ec71dc0347 153 }
JMF 0:55ec71dc0347 154 return NULL;
JMF 0:55ec71dc0347 155 }
JMF 0:55ec71dc0347 156
JMF 0:55ec71dc0347 157 //
JMF 0:55ec71dc0347 158 // return a pesudo-MAC address created from the ICCID
JMF 0:55ec71dc0347 159 //
JMF 0:55ec71dc0347 160 char* WNCInterface::getMACAddress( void ) {
JMF 0:55ec71dc0347 161 string str;
JMF 0:55ec71dc0347 162
JMF 0:55ec71dc0347 163 if( _pwnc->getICCID(&str) ) {
JMF 0:55ec71dc0347 164 if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
JMF 0:55ec71dc0347 165 FATAL_WNC_ERROR(null);
JMF 0:55ec71dc0347 166 mac = str.substr(3,20);
JMF 0:55ec71dc0347 167 mac[2]=mac[5]=mac[8]=mac[11]=mac[14]=':';
JMF 0:55ec71dc0347 168 return (char*)mac.c_str();
JMF 0:55ec71dc0347 169 }
JMF 0:55ec71dc0347 170 return NULL;
JMF 0:55ec71dc0347 171 }
JMF 0:55ec71dc0347 172
JMF 3:1d7e6ed11269 173