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
Revision 18:4962b4e95e32, committed 2014-08-23
- Comitter:
- dan_ackme
- Date:
- Sat Aug 23 05:48:49 2014 -0700
- Parent:
- 17:7268f365676b
- Child:
- 19:449a58827ddf
- Commit message:
- removed old files
Changed in this revision
--- a/internal/types/File.cpp Sat Aug 23 05:39:17 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,302 +0,0 @@ -/** - * ACKme WiConnect Host Library is licensed under the BSD licence: - * - * Copyright (c)2014 ACKme Networks. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - */ - -#include "Wiconnect.h" -#include "internal/common.h" - -#define CHECK_OPENED_FOR_READING() if(!readEnabled) return WICONNECT_NOT_OPENED_FOR_READING - - - - -/*************************************************************************************************/ -File::File(int rxBufferLen, void *rxBuffer_) -{ - wiconnect = Wiconnect::getInstance(); - - memset(&rxBuffer, 0, sizeof(Buffer)); - - rxBuffer.size = !wiconnect->nonBlocking ? rxBufferLen : 0; - rxBuffer.buffer = (uint8_t*)rxBuffer_; - - if(rxBuffer.size > 0) - { - if(rxBuffer_ == NULL) - { -#ifdef WICONNECT_ENABLE_MALLOC - wiconnect_assert(wiconnect, "File(), malloc not defined", wiconnect->_malloc != NULL); - rxBuffer.buffer = (uint8_t*)wiconnect->_malloc(rxBufferLen); - wiconnect_assert(wiconnect, "File(), failed to malloc buffer", rxBuffer.buffer != NULL); - rxBuffer.allocated = true; -#else - wiconnect_assert(0); -#endif - } - } - - previous = next = NULL; - handle = 0xff; - readEnabled = false; - *name = 0; - size = 0; - type = FILE_TYPE_UNKNOWN; - version = 0; - flags = FILE_FLAG_NONE; -} - -/*************************************************************************************************/ -File::~File() -{ - while(close() == WICONNECT_PROCESSING) - { - } - -#ifdef WICONNECT_ENABLE_MALLOC - if(rxBuffer.allocated && rxBuffer.size > 0) - { - wiconnect_assert(wiconnect, "~File(), free not defined", wiconnect->_free != NULL); - wiconnect->_free(rxBuffer.buffer); - } -#endif -} - -/*************************************************************************************************/ -WiconnectResult File::openForRead(uint8_t handle_, const char *filename) -{ - handle = handle_; - readEnabled = true; - strcpy(name, filename); - - return WICONNECT_SUCCESS; -} - -/*************************************************************************************************/ -WiconnectResult File::initWithListing(const char *typeStr, const char *flagsStr, const char* sizeStr, const char *versionStr, const char *nameStr) -{ - uint32_t tmp; - - if(!StringUtil::strHexToUint32(&typeStr[2], &tmp)) - { - return WICONNECT_RESPONSE_PARSE_ERROR; - } - type = (FileType)tmp; - - if(!StringUtil::strHexToUint32(flagsStr, &tmp)) - { - return WICONNECT_RESPONSE_PARSE_ERROR; - } - flags = (FileFlags)tmp; - - if(!StringUtil::strToUint32(sizeStr, &tmp)) - { - return WICONNECT_RESPONSE_PARSE_ERROR; - } - size = (uint32_t)tmp; - - if(!FileInterface::fileVersionStrToInt(versionStr, &version)) - { - return WICONNECT_RESPONSE_PARSE_ERROR; - } - - strcpy(name, nameStr); - - return WICONNECT_SUCCESS; -} - -/*************************************************************************************************/ -void* File::operator new(size_t size) -{ - Wiconnect *wiconnect = Wiconnect::getInstance(); - wiconnect_assert(wiconnect, "File:new, malloc not defined", wiconnect->_malloc != NULL); - return Wiconnect::getInstance()->_malloc(size); -} - -/*************************************************************************************************/ -void File::operator delete(void* ptr) -{ - Wiconnect *wiconnect = Wiconnect::getInstance(); - wiconnect_assert(wiconnect, "File:delete, free not defined", wiconnect->_free != NULL); - Wiconnect::getInstance()->_free(ptr); -} - - -/*************************************************************************************************/ -WiconnectResult File::close() -{ - WiconnectResult result; - CHECK_OPENED_FOR_READING(); - CHECK_OTHER_COMMAND_EXECUTING(); - - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("close %d", handle))) - { - readEnabled = false; - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -const char* File::getName() const -{ - return name; -} - -/*************************************************************************************************/ -uint32_t File::getSize() const -{ - return size; -} - -/*************************************************************************************************/ -FileType File::getType() const -{ - return type; -} - -/*************************************************************************************************/ -FileFlags File::getFlags() const -{ - return flags; -} - -/*************************************************************************************************/ -uint32_t File::getVersion() const -{ - return version; -} - -/*************************************************************************************************/ -const char* File::getVersionStr(char *buffer) const -{ - return FileInterface::fileVersionIntToStr(version, true, buffer); -} - -/*************************************************************************************************/ -const File* File::getNext() const -{ - return next; -} - -/*************************************************************************************************/ -const File* File::getPrevious() const -{ - return previous; -} - - -/*************************************************************************************************/ -WiconnectResult File::read(void* buffer, uint16_t maxLength, uint16_t *bytesRead) -{ - WiconnectResult result; - - CHECK_OPENED_FOR_READING(); - CHECK_OTHER_COMMAND_EXECUTING(); - - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand((char*)buffer, maxLength, "read %d %d", handle, maxLength-2))) - { - *bytesRead = wiconnect->getLastCommandResponseLength(); - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult File::read(uint8_t **bufferPtr, uint16_t *bytesReadPtr) -{ - WiconnectResult result = WICONNECT_SUCCESS; - - CHECK_OPENED_FOR_READING(); - - if(rxBuffer.size == 0) - { - return WICONNECT_UNSUPPORTED; - } - else if(bufferPtr != NULL && bytesReadPtr == NULL) - { - return WICONNECT_BAD_ARG; - } - else if(rxBuffer.bytesPending < rxBuffer.size - 2) - { - const int bytesToRead = rxBuffer.size - rxBuffer.bytesPending - 2; - char* ptr = (char*)&rxBuffer.buffer[rxBuffer.bytesPending]; - if(!WICONNECT_FAILED(result, wiconnect->sendCommand(ptr, bytesToRead+2, "read %d %d", handle, bytesToRead))) - { - rxBuffer.bytesPending += wiconnect->getLastCommandResponseLength(); - } - } - - if(bufferPtr != NULL) - { - *bufferPtr = rxBuffer.buffer; - *bytesReadPtr = rxBuffer.bytesPending; - clearRxBuffer(); - } - - return result; -} - -/*************************************************************************************************/ -WiconnectResult File::getc(uint8_t *c) -{ - WiconnectResult result; - - if(rxBuffer.size == 0) - { - return WICONNECT_UNSUPPORTED; - } - - read_data: - if(rxBuffer.bytesPending == 0 && - WICONNECT_FAILED(result, read())) - { - return result; - } - else if(rxBuffer.ptr < &rxBuffer.buffer[rxBuffer.bytesPending]) - { - *c = *rxBuffer.ptr; - ++rxBuffer.ptr; - return WICONNECT_SUCCESS; - } - else - { - clearRxBuffer(); - goto read_data; - } -} - -/*************************************************************************************************/ -void File::clearRxBuffer() -{ - rxBuffer.bytesPending = 0; - rxBuffer.ptr = rxBuffer.buffer; -}
--- a/internal/types/Socket.cpp Sat Aug 23 05:39:17 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,506 +0,0 @@ -/** - * ACKme WiConnect Host Library is licensed under the BSD licence: - * - * Copyright (c)2014 ACKme Networks. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - */ -#include <stdarg.h> -#include "Wiconnect.h" -#include "internal/common.h" -#include "StringUtil.h" - - -#define CHECK_CONNECTED() if(!isConnected()) return WICONNECT_NOT_CONNECTED - - -/*************************************************************************************************/ -Socket::Socket(int rxBufferLen_, void *rxBuffer_, int txBufferLen_, void *txBuffer_) -{ - wiconnect = Wiconnect::getInstance(); - - memset(&txBuffer, 0, sizeof(Buffer)); - memset(&rxBuffer, 0, sizeof(Buffer)); - - txBuffer.size = !wiconnect->nonBlocking ? txBufferLen_ : 0; - txBuffer.buffer = (uint8_t*)txBuffer_; - - rxBuffer.size = !wiconnect->nonBlocking ? rxBufferLen_ : 0; - rxBuffer.buffer = (uint8_t*)rxBuffer_; - - if(txBuffer.size > 0) - { - if(txBuffer_ == NULL) - { -#ifdef WICONNECT_ENABLE_MALLOC - wiconnect_assert(wiconnect, "Socket(), malloc not defined", wiconnect->_malloc != NULL); - txBuffer.buffer = (uint8_t*)wiconnect->_malloc(txBufferLen_); - wiconnect_assert(wiconnect, "Socket(), txBuffer malloc failed", txBuffer.buffer != NULL); - txBuffer.allocated = true; -#else - wiconnect_assert(0); -#endif - } - } - - if(rxBuffer.size > 0) - { - if(rxBuffer_ == NULL) - { -#ifdef WICONNECT_ENABLE_MALLOC - wiconnect_assert(wiconnect, "Socket(), malloc not defined", wiconnect->_malloc != NULL); - rxBuffer.buffer = (uint8_t*)wiconnect->_malloc(rxBufferLen_); - wiconnect_assert(wiconnect, "Socket(), rxBuffer malloc failed", rxBuffer.buffer != NULL); - rxBuffer.allocated = true; -#else - wiconnect_assert(0); -#endif - } - } - - init(SOCKET_INVALID_HANDLE, SOCKET_TYPE_UNKNOWN, NULL, 0, 0); -} - - -/*************************************************************************************************/ -WiconnectResult Socket::init(uint8_t handle_, SocketType type_, const char *host_, uint16_t remotePort_, uint16_t localPort_) -{ - handle = handle_; - type = type_; - remotePort = remotePort_; - localPort = localPort_; - connected = true; - - txBuffer.ptr = txBuffer.buffer; - rxBuffer.ptr = rxBuffer.buffer; - - strncpy(host, host_, sizeof(host)-1); - - return WICONNECT_SUCCESS; -} - -/*************************************************************************************************/ -Socket::~Socket() -{ - while((handle != SOCKET_INVALID_HANDLE) && (close() == WICONNECT_PROCESSING)) - { - } - -#ifdef WICONNECT_ENABLE_MALLOC - if(txBuffer.allocated && txBuffer.size > 0) - { - wiconnect_assert(wiconnect, "~Socket(), free not defined", wiconnect->_free != NULL); - wiconnect->_free(txBuffer.buffer); - } - if(rxBuffer.allocated && rxBuffer.size > 0) - { - wiconnect_assert(wiconnect, "~Socket(), free not defined", wiconnect->_free != NULL); - wiconnect->_free(rxBuffer.buffer); - } -#endif -} - -/*************************************************************************************************/ -bool Socket::isConnected() -{ - return connected; -} - -/*************************************************************************************************/ -SocketType Socket::getType() -{ - return type; -} - -/*************************************************************************************************/ -const char* Socket::getHost() -{ - return host; -} - -/*************************************************************************************************/ -uint16_t Socket::getLocalPort() -{ - return localPort; -} - -/*************************************************************************************************/ -uint16_t Socket::getRemotePort() -{ - return remotePort; -} - -/*************************************************************************************************/ -uint8_t Socket::getHandle() -{ - return handle; -} - - -/*************************************************************************************************/ -WiconnectResult Socket::close() -{ - WiconnectResult result; - CHECK_CONNECTED(); - CHECK_OTHER_COMMAND_EXECUTING(); - - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("close %d", handle))) - { - connected = false; - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult Socket::poll(bool *rxDataAvailablePtr) -{ - WiconnectResult result; - int32_t status; - - CHECK_CONNECTED(); - CHECK_OTHER_COMMAND_EXECUTING(); - - *rxDataAvailablePtr = false; - - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("poll %d", handle))) - { - if(!WICONNECT_FAILED(result, wiconnect->responseToInt32(&status))) - { - if(status == 2) - { - connected = false; - } - else if(status == 1) - { - *rxDataAvailablePtr = true; - } - } - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult Socket::write(int length, bool flush) -{ - CHECK_CONNECTED(); - - if( txBuffer.size == 0) - { - return WICONNECT_UNSUPPORTED; - } - else if(length > txBuffer.size) - { - return WICONNECT_OVERFLOW; - } - txBuffer.bytesPending = length; - - return flush ? flushTxBuffer() : WICONNECT_SUCCESS; -} - -/*************************************************************************************************/ -WiconnectResult Socket::write(const void* buffer, int length, bool flush) -{ - WiconnectResult result = WICONNECT_SUCCESS; - CHECK_CONNECTED(); - - if(txBuffer.size > 0) - { - // NOTE: txBuffer only available in blocking mode (so no need to check if a cmd is executing) - - const uint8_t *src = (const uint8_t *)buffer; - - while(length > 0) - { - int bytesToWrite = MIN(length, txBuffer.size - txBuffer.bytesPending); - uint8_t *dst = (uint8_t*)&txBuffer.buffer[txBuffer.bytesPending]; - memcpy(dst, src, bytesToWrite); - txBuffer.bytesPending += bytesToWrite; - length -= bytesToWrite; - src += bytesToWrite; - - if((txBuffer.bytesPending >= txBuffer.size) && - WICONNECT_FAILED(result, flushTxBuffer())) - { - break; - } - } - - if(flush && txBuffer.bytesPending > 0) - { - result = flushTxBuffer(); - } - } - else - { - if(WICONNECT_IS_IDLE()) - { - txBuffer.ptr = (uint8_t*)buffer; - txBuffer.bytesPending = length; - } - - result = flushTxBuffer(); - } - - return result; -} - -/*************************************************************************************************/ -WiconnectResult Socket::read(void* buffer, uint16_t maxLength, uint16_t *bytesRead) -{ - WiconnectResult result; - - CHECK_CONNECTED(); - CHECK_OTHER_COMMAND_EXECUTING(); - - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand((char*)buffer, maxLength, "read %d %d", handle, maxLength-2))) - { - *bytesRead = wiconnect->getLastCommandResponseLength(); - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult Socket::read(uint8_t **bufferPtr, uint16_t *bytesReadPtr) -{ - WiconnectResult result = WICONNECT_SUCCESS; - - CHECK_CONNECTED(); - - if(rxBuffer.size == 0) - { - return WICONNECT_UNSUPPORTED; - } - else if(bufferPtr != NULL && bytesReadPtr == NULL) - { - return WICONNECT_BAD_ARG; - } - else if(rxBuffer.bytesPending < rxBuffer.size - 2) - { - const int bytesToRead = rxBuffer.size - rxBuffer.bytesPending - 2; - char* ptr = (char*)&rxBuffer.buffer[rxBuffer.bytesPending]; - if(!WICONNECT_FAILED(result, wiconnect->sendCommand(ptr, bytesToRead+2, "read %d %d", handle, bytesToRead))) - { - rxBuffer.bytesPending += wiconnect->getLastCommandResponseLength(); - } - } - - if(bufferPtr != NULL) - { - *bufferPtr = rxBuffer.buffer; - *bytesReadPtr = rxBuffer.bytesPending; - clearRxBuffer(); - } - - return result; -} - -/*************************************************************************************************/ -WiconnectResult Socket::getc(uint8_t *c) -{ - WiconnectResult result; - - if(rxBuffer.size == 0) - { - return WICONNECT_UNSUPPORTED; - } - - read_data: - if(rxBuffer.bytesPending == 0 && - WICONNECT_FAILED(result, read())) - { - return result; - } - else if(rxBuffer.ptr < &rxBuffer.buffer[rxBuffer.bytesPending]) - { - *c = *rxBuffer.ptr; - ++rxBuffer.ptr; - return WICONNECT_SUCCESS; - } - else - { - clearRxBuffer(); - goto read_data; - } -} - -/*************************************************************************************************/ -WiconnectResult Socket::putc(uint8_t c, bool flush) -{ - WiconnectResult result = WICONNECT_SUCCESS; - CHECK_CONNECTED(); - - if(txBuffer.size == 0) - { - return WICONNECT_UNSUPPORTED; - } - else if(txBuffer.bytesPending < txBuffer.size) - { - uint8_t *ptr = (uint8_t*)&txBuffer.buffer[txBuffer.bytesPending]; - *ptr = c; - ++txBuffer.bytesPending; - - if(flush || txBuffer.bytesPending >= txBuffer.size) - { - result = flushTxBuffer(); - } - } - else - { - result = WICONNECT_OVERFLOW; - } - - return result; -} - -/*************************************************************************************************/ -WiconnectResult Socket::puts(const char *s, bool flush) -{ - const int len = strlen(s); - return write(s, len, flush); -} - -/*************************************************************************************************/ -WiconnectResult Socket::printf(const char* format, ...) -{ - WiconnectResult result = WICONNECT_SUCCESS; - - CHECK_CONNECTED(); - if(txBuffer.size == 0) - { - return WICONNECT_UNSUPPORTED; - } - - const int available = txBuffer.size - txBuffer.bytesPending; - char *ptr = (char*)&txBuffer.buffer[txBuffer.bytesPending]; - va_list args; - va_start(args, format); - const int len = vsnprintf(ptr, available, format, args); - if(len > available) - { - return WICONNECT_OVERFLOW; - } - else - { - txBuffer.bytesPending += len; - } - - if(txBuffer.bytesPending >= txBuffer.size) - { - result = flushTxBuffer(); - } - - return result; -} - -/*************************************************************************************************/ -WiconnectResult Socket::flushTxBuffer() -{ - WiconnectResult result = WICONNECT_SUCCESS; - - CHECK_CONNECTED(); - CHECK_OTHER_COMMAND_EXECUTING(); - - if(txBuffer.bytesPending > 0) - { - result = wiconnect->sendCommand(ReaderFunc(this, &Socket::writeDataCallback), NULL, "write %d %d", handle, txBuffer.bytesPending); - } - - CHECK_CLEANUP_COMMAND(); - - if(result != WICONNECT_PROCESSING) - { - txBuffer.ptr = txBuffer.buffer; - txBuffer.bytesPending = 0; - } - - return result; -} - -/*************************************************************************************************/ -void Socket::clearRxBuffer() -{ - rxBuffer.bytesPending = 0; - rxBuffer.ptr = rxBuffer.buffer; -} - -/*************************************************************************************************/ -uint8_t* Socket::getTxBuffer() -{ - return txBuffer.buffer; -} -/*************************************************************************************************/ -int Socket::getTxBufferSize() -{ - return txBuffer.size; -} -/*************************************************************************************************/ -int Socket::getTxBufferBytesPending() -{ - return txBuffer.bytesPending; -} -/*************************************************************************************************/ -uint8_t* Socket::getRxBuffer() -{ - return rxBuffer.buffer; -} -/*************************************************************************************************/ -int Socket::getRxBufferSize() -{ - return rxBuffer.size; -} -/*************************************************************************************************/ -int Socket::getRxBufferBytesPending() -{ - return rxBuffer.bytesPending; -} - - -/*************************************************************************************************/ -WiconnectResult Socket::writeDataCallback(void *user, void *data, int maxReadSize, int *bytesRead) -{ - if(txBuffer.bytesPending == 0) - { - *bytesRead = EOF; - } - else - { - int bytesToWrite = MIN(maxReadSize, txBuffer.bytesPending); - memcpy(data, txBuffer.ptr, bytesToWrite); - txBuffer.ptr += bytesToWrite; - txBuffer.bytesPending -= bytesToWrite; - *bytesRead = bytesToWrite; - } - - return WICONNECT_SUCCESS; -} -
--- a/types/File.h Sat Aug 23 05:39:17 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -/** - * ACKme WiConnect Host Library is licensed under the BSD licence: - * - * Copyright (c)2014 ACKme Networks. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - */ -#pragma once - - -#include "Wiconnect.h" - -namespace wiconnect -{ - - -/** - * @ingroup api_file_types - * - * @brief WiConnect WiFi module file object. - * - */ -class File -{ -public: - File(int rxBufferLen = 0, void *rxBuffer = NULL); - ~File(); - - const char* getName() const; - uint32_t getSize() const; - FileType getType() const; - FileFlags getFlags() const; - uint32_t getVersion() const; - const char* getVersionStr(char *buffer = NULL) const; - - WiconnectResult close(); - WiconnectResult read(void* buffer, uint16_t maxLength, uint16_t *bytesRead); - WiconnectResult read(uint8_t **bufferPtr = NULL, uint16_t *bytesReadPtr = NULL); - WiconnectResult getc(uint8_t *c); - void clearRxBuffer(); - - const File* getNext() const; - const File* getPrevious() const; - -protected: - WiconnectResult openForRead(uint8_t handle, const char *filename); - WiconnectResult initWithListing(const char *typeStr, const char *flagsStr, const char* sizeStr, const char *versionStr, const char *nameStr); - - uint8_t handle; - bool readEnabled; - char name[WICONNECT_MAX_FILENAME_SIZE]; - uint32_t size; - FileType type; - FileFlags flags; - uint32_t version; - Wiconnect *wiconnect; - File *next; - File *previous; - - Buffer rxBuffer; - - void* operator new(size_t size); - void operator delete(void*); - - friend class FileInterface; - friend class FileList; -}; - -}
--- a/types/Socket.h Sat Aug 23 05:39:17 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -/** - * ACKme WiConnect Host Library is licensed under the BSD licence: - * - * Copyright (c)2014 ACKme Networks. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - */ -#pragma once - - -#include "WiconnectTypes.h" - -namespace wiconnect -{ - -/** - * @ingroup api_socket_types - * - * @brief Connection object to remote server. - * - */ -class Socket -{ -public: - Socket(int rxBufferLen = 0, void *rxBuffer = NULL, int txBufferLen = 0, void *txBuffer = NULL); - ~Socket(); - - WiconnectResult close(); - WiconnectResult poll(bool *rxDataAvailablePtr); - WiconnectResult write(const void* buffer, int length, bool flush = false); - WiconnectResult write(int length, bool flush = true); - WiconnectResult read(void* buffer, uint16_t maxLength, uint16_t *bytesRead); - WiconnectResult read(uint8_t **bufferPtr = NULL, uint16_t *bytesReadPtr = NULL); - WiconnectResult putc(uint8_t c, bool flush = false); - WiconnectResult puts(const char *s, bool flush = false); - WiconnectResult getc(uint8_t *c); - WiconnectResult printf(const char* format, ...); - WiconnectResult flushTxBuffer(); - void clearRxBuffer(); - - uint8_t *getTxBuffer(); - int getTxBufferSize(); - int getTxBufferBytesPending(); - uint8_t *getRxBuffer(); - int getRxBufferSize(); - int getRxBufferBytesPending(); - - bool isConnected(); - SocketType getType(); - const char* getHost(); - uint16_t getLocalPort(); - uint16_t getRemotePort(); - uint8_t getHandle(); - -protected: - bool connected; - SocketType type; - uint8_t handle; - char host[WICONNECT_MAX_HOST_SIZE]; - uint16_t localPort; - uint16_t remotePort; - Wiconnect *wiconnect; - Buffer txBuffer; - Buffer rxBuffer; - - WiconnectResult init(uint8_t handle, SocketType type, const char *host, uint16_t remotePort, uint16_t localPort); - - WiconnectResult writeDataCallback(void *user, void *data, int maxReadSize, int *bytesRead); - - friend class SocketInterface; -}; - - -}