Host library for controlling a WiConnect enabled Wi-Fi module.

Dependents:   wiconnect-ota_example wiconnect-web_setup_example wiconnect-test-console wiconnect-tcp_server_example ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers WiconnectSocket.h Source File

WiconnectSocket.h

00001 /**
00002  * ACKme WiConnect Host Library is licensed under the BSD licence: 
00003  * 
00004  * Copyright (c)2014 ACKme Networks.
00005  * All rights reserved. 
00006  * 
00007  * Redistribution and use in source and binary forms, with or without modification, 
00008  * are permitted provided that the following conditions are met: 
00009  * 
00010  * 1. Redistributions of source code must retain the above copyright notice, 
00011  * this list of conditions and the following disclaimer. 
00012  * 2. Redistributions in binary form must reproduce the above copyright notice, 
00013  * this list of conditions and the following disclaimer in the documentation 
00014  * and/or other materials provided with the distribution. 
00015  * 3. The name of the author may not be used to endorse or promote products 
00016  * derived from this software without specific prior written permission. 
00017  * 
00018  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED 
00019  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00020  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
00021  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00022  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
00023  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
00026  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
00027  * OF SUCH DAMAGE.
00028  */
00029 #pragma once
00030 
00031 
00032 #include "api/WiconnectTypes.h"
00033 
00034 namespace wiconnect
00035 {
00036 
00037 /**
00038  * @ingroup api_socket_types
00039  *
00040  * @brief Connection object to remote server.
00041  *
00042  */
00043 class WiconnectSocket
00044 {
00045 public:
00046     WiconnectSocket(int rxBufferLen = 0, void *rxBuffer = NULL, int txBufferLen = 0, void *txBuffer = NULL);
00047     ~WiconnectSocket();
00048 
00049     WiconnectResult close();
00050     WiconnectResult poll(bool *rxDataAvailablePtr, bool autoClose = false);
00051     WiconnectResult write(const void* buffer, int length, bool flush = true);
00052     WiconnectResult write(int length, bool flush = true);
00053     WiconnectResult read(void* buffer, uint16_t maxLength, uint16_t *bytesRead);
00054     WiconnectResult read(uint8_t **bufferPtr = NULL, uint16_t *bytesReadPtr = NULL);
00055     WiconnectResult putc(uint8_t c, bool flush = false);
00056     WiconnectResult puts(const char *s, bool flush = true);
00057     WiconnectResult getc(uint8_t *c);
00058     WiconnectResult printf(const char* format, ...);
00059     virtual WiconnectResult flushTxBuffer();
00060     void clearRxBuffer();
00061 
00062     uint8_t *getTxBuffer();
00063     int getTxBufferSize();
00064     int getTxBufferBytesPending();
00065     uint8_t *getRxBuffer();
00066     int getRxBufferSize();
00067     int getRxBufferBytesPending();
00068 
00069     bool isConnected();
00070     SocketType getType();
00071     const char* getHost();
00072     uint16_t getLocalPort();
00073     uint16_t getRemotePort();
00074     uint8_t getHandle();
00075 
00076 protected:
00077     bool connected;
00078     bool enableAutoClose;
00079     SocketType type;
00080     uint8_t handle;
00081     char host[WICONNECT_MAX_HOST_SIZE];
00082     uint16_t localPort;
00083     uint16_t remotePort;
00084     Wiconnect *wiconnect;
00085     Buffer txBuffer;
00086     Buffer rxBuffer;
00087 
00088     WiconnectResult init(uint8_t handle, SocketType type, const char *host, uint16_t remotePort, uint16_t localPort);
00089 
00090     friend class SocketInterface;
00091     friend class GhmInterface;
00092 };
00093 
00094 
00095 }