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:
Thu Oct 06 21:17:18 2016 +0000
Revision:
7:fded23f50479
Parent:
1:e511ea8d39d5
Child:
9:9f0578ff157a
This version adds the SMS class and adds support for multi-threading to eliminate  re-entrant with the WncController class

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JMF 1:e511ea8d39d5 1 /* =====================================================================
JMF 1:e511ea8d39d5 2 Copyright © 2016, Avnet (R)
JMF 1:e511ea8d39d5 3
JMF 1:e511ea8d39d5 4 Contributors:
JMF 1:e511ea8d39d5 5 * James M Flynn, www.em.avnet.com
JMF 1:e511ea8d39d5 6
JMF 1:e511ea8d39d5 7 Licensed under the Apache License, Version 2.0 (the "License");
JMF 1:e511ea8d39d5 8 you may not use this file except in compliance with the License.
JMF 1:e511ea8d39d5 9 You may obtain a copy of the License at
JMF 1:e511ea8d39d5 10
JMF 1:e511ea8d39d5 11 http://www.apache.org/licenses/LICENSE-2.0
JMF 1:e511ea8d39d5 12
JMF 1:e511ea8d39d5 13 Unless required by applicable law or agreed to in writing,
JMF 1:e511ea8d39d5 14 software distributed under the License is distributed on an
JMF 1:e511ea8d39d5 15 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
JMF 1:e511ea8d39d5 16 either express or implied. See the License for the specific
JMF 1:e511ea8d39d5 17 language governing permissions and limitations under the License.
JMF 1:e511ea8d39d5 18
JMF 1:e511ea8d39d5 19 @file WNCInterface.cpp
JMF 1:e511ea8d39d5 20 @version 1.0
JMF 1:e511ea8d39d5 21 @date Sept 2016
JMF 1:e511ea8d39d5 22
JMF 1:e511ea8d39d5 23 ======================================================================== */
JMF 1:e511ea8d39d5 24
JMF 1:e511ea8d39d5 25 #include "../WNCInterface.h"
JMF 1:e511ea8d39d5 26 #include "Socket.h"
JMF 1:e511ea8d39d5 27 #include "Endpoint.h"
JMF 1:e511ea8d39d5 28
JMF 1:e511ea8d39d5 29 Endpoint::Endpoint() {
JMF 1:e511ea8d39d5 30 reset_address();
JMF 1:e511ea8d39d5 31 }
JMF 1:e511ea8d39d5 32
JMF 1:e511ea8d39d5 33 Endpoint::~Endpoint() {}
JMF 1:e511ea8d39d5 34
JMF 1:e511ea8d39d5 35 void Endpoint::reset_address(void) {
JMF 1:e511ea8d39d5 36 std::memset(&_epAddr, 0, sizeof(struct EndPointAddr));
JMF 1:e511ea8d39d5 37 }
JMF 1:e511ea8d39d5 38
JMF 1:e511ea8d39d5 39 //
JMF 1:e511ea8d39d5 40 // It is possible to call set_address with either a URL or
JMF 1:e511ea8d39d5 41 // an IP address. So try each in-turn and set the end point
JMF 1:e511ea8d39d5 42 // address.
JMF 1:e511ea8d39d5 43 //
JMF 1:e511ea8d39d5 44
JMF 1:e511ea8d39d5 45 int Endpoint::set_address(const char* host, const int port) {
JMF 1:e511ea8d39d5 46 // IP Address
JMF 1:e511ea8d39d5 47 char address[5];
JMF 1:e511ea8d39d5 48 int rslt;
JMF 1:e511ea8d39d5 49
JMF 1:e511ea8d39d5 50 if( WNCInterface::_pwnc->getWncStatus() == FATAL_FLAG )
JMF 1:e511ea8d39d5 51 FATAL_WNC_ERROR(fail);
JMF 1:e511ea8d39d5 52
JMF 1:e511ea8d39d5 53 reset_address();
JMF 1:e511ea8d39d5 54 _epAddr.port = port; //go ahead and save the port
JMF 1:e511ea8d39d5 55
JMF 1:e511ea8d39d5 56 // Dot-decimal notation?
JMF 1:e511ea8d39d5 57 rslt = std::sscanf(host, "%3u.%3u.%3u.%3u",
JMF 1:e511ea8d39d5 58 (unsigned int*)&address[0], (unsigned int*)&address[1],
JMF 1:e511ea8d39d5 59 (unsigned int*)&address[2], (unsigned int*)&address[3]);
JMF 1:e511ea8d39d5 60
JMF 7:fded23f50479 61 M_LOCK;
JMF 1:e511ea8d39d5 62 if (rslt != 4) // No, need to resolve address with DNS
JMF 1:e511ea8d39d5 63 WNCInterface::_pwnc->resolveUrl(0,host);
JMF 1:e511ea8d39d5 64 else
JMF 1:e511ea8d39d5 65 WNCInterface::_pwnc->setIpAddr(0,host);
JMF 1:e511ea8d39d5 66
JMF 1:e511ea8d39d5 67 rslt = WNCInterface::_pwnc->getIpAddr(0,_epAddr.IP);
JMF 7:fded23f50479 68 M_ULOCK;
JMF 7:fded23f50479 69 return rslt;
JMF 1:e511ea8d39d5 70 }
JMF 1:e511ea8d39d5 71
JMF 1:e511ea8d39d5 72 char* Endpoint::get_address() {
JMF 1:e511ea8d39d5 73 return _epAddr.IP;
JMF 1:e511ea8d39d5 74 }
JMF 1:e511ea8d39d5 75
JMF 1:e511ea8d39d5 76 int Endpoint::get_port() {
JMF 1:e511ea8d39d5 77 return _epAddr.port;
JMF 1:e511ea8d39d5 78 }
JMF 1:e511ea8d39d5 79