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.
Diff: WNCInterface.cpp
- Revision:
- 7:fded23f50479
- Parent:
- 5:759dceff95b9
- Child:
- 8:4b38bfb1704d
--- a/WNCInterface.cpp Wed Sep 28 00:17:57 2016 +0000
+++ b/WNCInterface.cpp Thu Oct 06 21:17:18 2016 +0000
@@ -41,6 +41,7 @@
DigitalOut mdm_uart1_cts(PTD0);
char * _fatal_err_loc; //GLOBAL::holds any error location info
+MODSERIAL * _dbgout;
using namespace WncControllerK64F_fk; // namespace for the controller class use
@@ -60,15 +61,21 @@
WncControllerK64F *WNCInterface::_pwnc;
WncIpStats WNCInterface::myNetStats;
string WNCInterface::mac;
-
+Mutex *WNCInterface::WNCLock;
+
WNCInterface::WNCInterface() {
+ _dbgout = NULL;
+ WNCLock = new Mutex();
+ WNCLock->unlock();
}
void WNCInterface::doDebug( int v ) {
//basic debug = 0x01
//more debug = 0x02
//all debug = 0x03
+ WNCLock->lock();
_pwnc->enableDebug( (v&1), (v&2) );
+ WNCLock->unlock();
}
//
@@ -84,8 +91,10 @@
//
int WNCInterface::init(const char* apn, MODSERIAL * debug) {
int ret = 0;
-
+
+ WNCLock->lock();
if( debug ) {
+ _dbgout = debug;
_pwnc = new WncControllerK64F_fk::WncControllerK64F::WncControllerK64F(&wncPinList, &mdmUart, debug);
#if WNC_DEBUG == 1
_pwnc->enableDebug(1,1);
@@ -100,7 +109,8 @@
ret = ( _pwnc->powerWncOn(apn,40) )? 2:0;
ret |= ( _pwnc->setApnName(apn) )? 1:0;
ret |= ( _pwnc->getWncNetworkingStats(&myNetStats) )? 4:0;
-
+ WNCLock->unlock();
+
return ret;
}
@@ -125,11 +135,14 @@
// update the networking stats and return the IP Address
//
char * WNCInterface::getIPAddress() {
+ WNCLock->lock();
if ( _pwnc->getWncNetworkingStats(&myNetStats) ) {
if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
FATAL_WNC_ERROR(null);
+ WNCLock->unlock();
return &myNetStats.ip[0];
}
+ WNCLock->unlock();
return NULL;
}
@@ -137,11 +150,14 @@
// update the networking stats and return the Gateway Address
//
char * WNCInterface::getGateway() {
+ WNCLock->lock();
if ( _pwnc->getWncNetworkingStats(&myNetStats) ) {
if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
FATAL_WNC_ERROR(null);
+ WNCLock->unlock();
return &WNCInterface::myNetStats.gateway[0];
}
+ WNCLock->unlock();
return NULL;
}
@@ -149,11 +165,14 @@
// update the networking stats and return the Network Mask
//
char * WNCInterface::getNetworkMask() {
+ WNCLock->lock();
if ( _pwnc->getWncNetworkingStats(&myNetStats) ) {
if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
FATAL_WNC_ERROR(null);
+ WNCLock->unlock();
return &WNCInterface::myNetStats.mask[0];
}
+ WNCLock->unlock();
return NULL;
}
@@ -162,14 +181,17 @@
//
char* WNCInterface::getMACAddress( void ) {
string str;
-
+
+ WNCLock->lock();
if( _pwnc->getICCID(&str) ) {
if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
FATAL_WNC_ERROR(null);
mac = str.substr(3,20);
mac[2]=mac[5]=mac[8]=mac[11]=mac[14]=':';
- return (char*)mac.c_str();
+ WNCLock->unlock();
+ return (char*)mac.c_str();
}
+ WNCLock->unlock();
return NULL;
}

