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.
Revision 8:4b38bfb1704d, committed 2016-10-07
- Comitter:
- JMF
- Date:
- Fri Oct 07 00:36:47 2016 +0000
- Parent:
- 7:fded23f50479
- Child:
- 9:9f0578ff157a
- Commit message:
- Corrected Mutex implementation. Now it is static global to the WNCInterface class.
Changed in this revision
| WNCInterface.cpp | Show annotated file Show diff for this revision Revisions of this file |
| WNCInterface.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/WNCInterface.cpp Thu Oct 06 21:17:18 2016 +0000
+++ b/WNCInterface.cpp Fri Oct 07 00:36:47 2016 +0000
@@ -42,6 +42,7 @@
char * _fatal_err_loc; //GLOBAL::holds any error location info
MODSERIAL * _dbgout;
+Mutex _WNCLock;
using namespace WncControllerK64F_fk; // namespace for the controller class use
@@ -61,21 +62,18 @@
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();
+ M_LOCK;
_pwnc->enableDebug( (v&1), (v&2) );
- WNCLock->unlock();
+ M_ULOCK;
}
//
@@ -92,7 +90,7 @@
int WNCInterface::init(const char* apn, MODSERIAL * debug) {
int ret = 0;
- WNCLock->lock();
+ M_LOCK;
if( debug ) {
_dbgout = debug;
_pwnc = new WncControllerK64F_fk::WncControllerK64F::WncControllerK64F(&wncPinList, &mdmUart, debug);
@@ -109,7 +107,7 @@
ret = ( _pwnc->powerWncOn(apn,40) )? 2:0;
ret |= ( _pwnc->setApnName(apn) )? 1:0;
ret |= ( _pwnc->getWncNetworkingStats(&myNetStats) )? 4:0;
- WNCLock->unlock();
+ M_ULOCK;
return ret;
}
@@ -135,14 +133,14 @@
// update the networking stats and return the IP Address
//
char * WNCInterface::getIPAddress() {
- WNCLock->lock();
+ M_LOCK;
if ( _pwnc->getWncNetworkingStats(&myNetStats) ) {
if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
FATAL_WNC_ERROR(null);
- WNCLock->unlock();
+ M_ULOCK;
return &myNetStats.ip[0];
}
- WNCLock->unlock();
+ M_ULOCK;
return NULL;
}
@@ -150,14 +148,14 @@
// update the networking stats and return the Gateway Address
//
char * WNCInterface::getGateway() {
- WNCLock->lock();
+ M_LOCK;
if ( _pwnc->getWncNetworkingStats(&myNetStats) ) {
if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
FATAL_WNC_ERROR(null);
- WNCLock->unlock();
+ M_ULOCK;
return &WNCInterface::myNetStats.gateway[0];
}
- WNCLock->unlock();
+ M_ULOCK;
return NULL;
}
@@ -165,14 +163,14 @@
// update the networking stats and return the Network Mask
//
char * WNCInterface::getNetworkMask() {
- WNCLock->lock();
+ M_LOCK;
if ( _pwnc->getWncNetworkingStats(&myNetStats) ) {
if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
FATAL_WNC_ERROR(null);
- WNCLock->unlock();
+ M_ULOCK;
return &WNCInterface::myNetStats.mask[0];
}
- WNCLock->unlock();
+ M_ULOCK;
return NULL;
}
@@ -182,16 +180,16 @@
char* WNCInterface::getMACAddress( void ) {
string str;
- WNCLock->lock();
+ M_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]=':';
- WNCLock->unlock();
+ M_ULOCK;
return (char*)mac.c_str();
}
- WNCLock->unlock();
+ M_ULOCK;
return NULL;
}
--- a/WNCInterface.h Thu Oct 06 21:17:18 2016 +0000
+++ b/WNCInterface.h Fri Oct 07 00:36:47 2016 +0000
@@ -79,8 +79,8 @@
#define FATAL_WNC_ERROR(v) {extern char *_fatal_err_loc;_fatal_err_loc=FATAL_STR;PFE;DORET(v);}
#endif
-#define M_LOCK WNCInterface::WNCLock->lock()
-#define M_ULOCK WNCInterface::WNCLock->unlock()
+#define M_LOCK {extern Mutex _WNCLock; _WNCLock.lock();}
+#define M_ULOCK {extern Mutex _WNCLock; _WNCLock.unlock();}
// Because the WncController has intermixed socket & interface functionallity
// will need to make the Socket class a friend of the Interface class. This
@@ -152,7 +152,6 @@
private:
static WncController_fk::WncIpStats myNetStats; //maintaint the network statistics
static WncControllerK64F_fk::WncControllerK64F *_pwnc; //pointer to the WncController instance
- static Mutex *WNCLock;
static string mac;
};

