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:
Fri Mar 24 22:26:23 2017 +0000
Revision:
29:b278b745fb4f
Parent:
28:dceb8da78e6d
updated Class name of TCPSocketConnection to WncTCPSocketConnection;

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 #ifndef TCPSOCKET_H
JMF 1:e511ea8d39d5 26 #define TCPSOCKET_H
JMF 1:e511ea8d39d5 27
JMF 26:81e520908460 28 #include "WncSocket.h"
JMF 26:81e520908460 29 #include "WncEndpoint.h"
JMF 1:e511ea8d39d5 30
JMF 1:e511ea8d39d5 31 /**
JMF 1:e511ea8d39d5 32 TCP socket connection
JMF 1:e511ea8d39d5 33 */
JMF 29:b278b745fb4f 34 class WncTCPSocketConnection : public WncSocket, public WncEndpoint {
JMF 1:e511ea8d39d5 35
JMF 1:e511ea8d39d5 36 public:
JMF 29:b278b745fb4f 37 WncTCPSocketConnection(void) : _is_blocking(0),
JMF 29:b278b745fb4f 38 _btimeout(0);
JMF 1:e511ea8d39d5 39
JMF 1:e511ea8d39d5 40 /** Connects this TCP socket to the server
JMF 1:e511ea8d39d5 41 \param host The host to connect to. It can either be an IP Address or a hostname that will be resolved with DNS.
JMF 1:e511ea8d39d5 42 \param port The host's port to connect to.
JMF 1:e511ea8d39d5 43 \return 0 on success, -1 on failure.
JMF 1:e511ea8d39d5 44 */
JMF 1:e511ea8d39d5 45 int connect(const char* host, const int port);
JMF 1:e511ea8d39d5 46
JMF 1:e511ea8d39d5 47 /** Check if the socket is connected
JMF 1:e511ea8d39d5 48 \return true if connected, false otherwise.
JMF 1:e511ea8d39d5 49 */
JMF 1:e511ea8d39d5 50 bool is_connected(void);
JMF 1:e511ea8d39d5 51
JMF 1:e511ea8d39d5 52 /** Send data to the remote host.
JMF 1:e511ea8d39d5 53 \param data The buffer to send to the host.
JMF 1:e511ea8d39d5 54 \param length The length of the buffer to send.
JMF 1:e511ea8d39d5 55 \return the number of written bytes on success (>=0) or -1 on failure
JMF 1:e511ea8d39d5 56 */
JMF 1:e511ea8d39d5 57 int send(char* data, int length);
JMF 1:e511ea8d39d5 58
JMF 1:e511ea8d39d5 59 /** Send all the data to the remote host.
JMF 1:e511ea8d39d5 60 \param data The buffer to send to the host.
JMF 1:e511ea8d39d5 61 \param length The length of the buffer to send.
JMF 1:e511ea8d39d5 62 \return the number of written bytes on success (>=0) or -1 on failure
JMF 1:e511ea8d39d5 63 */
JMF 1:e511ea8d39d5 64 int send_all(char* data, int length);
JMF 1:e511ea8d39d5 65
JMF 1:e511ea8d39d5 66 /** Receive data from the remote host.
JMF 1:e511ea8d39d5 67 \param data The buffer in which to store the data received from the host.
JMF 1:e511ea8d39d5 68 \param length The maximum length of the buffer.
JMF 1:e511ea8d39d5 69 \return the number of received bytes on success (>=0) or -1 on failure
JMF 1:e511ea8d39d5 70 */
JMF 1:e511ea8d39d5 71 int receive(char* data, int length);
JMF 1:e511ea8d39d5 72
JMF 1:e511ea8d39d5 73 /** Receive all the data from the remote host.
JMF 1:e511ea8d39d5 74 \param data The buffer in which to store the data received from the host.
JMF 1:e511ea8d39d5 75 \param length The maximum length of the buffer.
JMF 1:e511ea8d39d5 76 \return the number of received bytes on success (>=0) or -1 on failure
JMF 1:e511ea8d39d5 77 */
JMF 1:e511ea8d39d5 78 int receive_all(char* data, int length);
JMF 1:e511ea8d39d5 79
JMF 1:e511ea8d39d5 80 /** Set blocking or non-blocking mode of the socket and a timeout
JMF 1:e511ea8d39d5 81 \param blocking true for blocking mode, false for non-blocking mode.
JMF 1:e511ea8d39d5 82 \return none
JMF 1:e511ea8d39d5 83 */
JMF 1:e511ea8d39d5 84 void set_blocking (bool blocking, unsigned int timeout=1500);
JMF 1:e511ea8d39d5 85
JMF 1:e511ea8d39d5 86 /** Close the socket
JMF 1:e511ea8d39d5 87 \param none
JMF 1:e511ea8d39d5 88 \return 0 if closed successfully, -1 on failure
JMF 1:e511ea8d39d5 89 */
JMF 1:e511ea8d39d5 90 int close(void);
JMF 1:e511ea8d39d5 91
JMF 1:e511ea8d39d5 92 private:
JMF 1:e511ea8d39d5 93 bool _is_blocking;
JMF 1:e511ea8d39d5 94 unsigned int _btimeout;
JMF 1:e511ea8d39d5 95
JMF 1:e511ea8d39d5 96 };
JMF 1:e511ea8d39d5 97
JMF 1:e511ea8d39d5 98 #endif