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 28:3c52f578708a, committed 2014-10-27
- Comitter:
- dan_ackme
- Date:
- Mon Oct 27 13:32:40 2014 -0700
- Parent:
- 27:b63f5a9cdefa
- Child:
- 29:b6af04b77a56
- Commit message:
- refactoring library layout
Changed in this revision
--- a/FileInterface.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,187 +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" -#include "types/FileList.h" - - -/** - * @ingroup api_file_macro - * @brief The maximum filename size of a file on the WiConnect WiFi module filesystem - */ -#define FILE_NAME_MAX_SIZE 96 - -/** - * @ingroup api_file_macro - * @def FILE_MAKE_VERSION(major, minor, patch, rc) - * @brief Combine <\a major>.<\a minor>.<\a patch>.<\a rc> and create version as a uint32_t - */ -#define FILE_MAKE_VERSION(major, minor, patch, rc) ((unsigned int)((major) << 27)|(unsigned int)((minor) << 21)|(unsigned int)((patch) << 8)|(unsigned int)((rc) << 0)) -/** - * @ingroup api_file_macro - * @def FILE_VERSION_ARGS(version) - * @brief Given a uint32_t \a version, return arguments for a variable argument function such as printf(). The format string is: %d.%d.%d.%d - */ -#define FILE_VERSION_ARGS(version) (unsigned int)((version >> 27) & 0x1F),(unsigned int)((version >> 21) & 0x3F),(unsigned int)((version >> 8) & 0x1FFF),(unsigned int)(version & 0xFF) - - -namespace wiconnect { - - -/** - * @ingroup api_file_types - * - * @brief The provides an interface for creating TCP/UDP/TLS/HTTP client sockets. - * A client socket connects to a remote server. - * - * @note This class is an interface to the Wiconnect class. It should never be - * independently instantiated or the parent of another class. - */ -class FileInterface -{ -public: - /** - * @ingroup api_file_methods - * - * @brief Create a file on the Wiconnect WiFi module filesystem. - * - * This creates a file on the module's filesystem. The file's name and size are required. - * Optionally specify the version, type and if it's essential (i.e. if it should never be automatically deleted, careful with - * this optional as it could cause the the module to not be able to update its firmware). - * - * When this method is executed, the file is created on the module then the 'reader' parameter callback is - * called until all the file data is read from the HOST and written to the module file. - * - * @param[in] reader Callback to be executed until all file data has been read from the HOST and written to the module - * @param[in] user This is supplied to the @ref ReaderFunc callback. It is not used by the library. Leave NULL if not needed. - * @param[in] name The name of the file to create - * @param[in] size The size in bytes of the file - * @param[in] version Optional, the version of the file, defaults to 1.0.0.0 - * @param[in] type Optional, the file type, defaults to FILE_TYPE_MISC_FIX_LEN - * @param[in] isEssential Optional, specify if the file should never be automatically deleted during a firmware upgrade - * @param[in] checksum The CRC16 checksum of the file data. The module verifies the written data against this checksum - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult createFile(const ReaderFunc &reader, void *user, const char *name, uint32_t size, uint32_t version = 0, FileType type = FILE_TYPE_ANY, bool isEssential = false, int32_t checksum = -1); - - /** - * @ingroup api_file_methods - * - * @brief Open a file on the Wiconnect WiFi module filesystem for reading. - * - * Once opened, the returned @ref WiconnectFile object may only be read. - * - * @param[out] file The @ref WiconnectFile object to read data from - * @param[in] name The name of the file to open - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult openFile(WiconnectFile &file, const char *name); - - /** - * @ingroup api_file_methods - * - * @brief Delete a file for the Wiconnect WiFi module filesystem. - * - * @param[in] name The name of the file to delete - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult deleteFile(const char *name); - - /** - * @ingroup api_file_methods - * - * @brief Delete a file for the Wiconnect WiFi module filesystem. - * - * @param[in] file The @ref WiconnectFile object of the file to delete - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult deleteFile(const WiconnectFile &file); - - /** - * @ingroup api_file_methods - * - * @brief List the files on the Wiconnect WiFi module filesystem. - * - * This lists all the files on the filesystem. - * Optionally filter by one or more parameters: - * * name - list files only with given name. If the name started with the wildcard character '*', then - * only the characters after it are used for filter. - * Example: - * @code - * wiconnect.listFiles(fileList, "*.txt"); // only list files with '.txt' extension - * @endcode - * * type - only list files with given type - * * version - only list file with given version - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult listFiles(FileList &list, const char *name = NULL, FileType type = FILE_TYPE_ANY, uint32_t version = 0); - - - // ------------------------------------------------------------------------ - - - /** - * @ingroup conversion_util - * - * @brief Convert file version uint32 to string. - */ - static const char* fileVersionIntToStr(uint32_t version, bool verbose = true, char *buffer = NULL); - - /** - * @ingroup conversion_util - * - * @brief Convert string to file version uint32. - */ - static bool fileVersionStrToInt(const char *versionStr, uint32_t *versionIntPtr); - - /** - * @ingroup conversion_util - * - * Convert @ref FileType to string. - */ - static const char* fileTypeToStr(FileType type); - - /** - * @ingroup conversion_util - * - * @brief Convert @ref FileFlags to string. - */ - static const char* fileFlagsToStr(FileFlags flags, char *buffer = NULL); - -protected: - FileInterface(Wiconnect *wiconnect); - - WiconnectResult processFileList(char *responseStr, FileList &list, const char *name, FileType type, uint32_t version); -private: - Wiconnect *wiconnect; -}; - -}
--- a/NetworkInterface.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,402 +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" -#include "types/ScanResultList.h" - - -namespace wiconnect { - - -/** - * @ingroup api_network_types - * - * @brief The provides an interface for joining and/or creating a network. - * It provides other utilities such as scanning for networks, pinging a network, - * resolving a domain name to IP address. - * - * @note This class is an interface to the Wiconnect class. It should never be - * independently instantiated or the parent of another class. - */ -class NetworkInterface -{ -public: - /** - * @ingroup api_network_setup - * - * @brief Start the WiConnect WiFi module 'web setup' feature. - * - * This command has an optional background processing feature. - * Background processing is enabled if the completeHandler parameter - * is specified. If enabled, the library will poll the module every second - * for the web setup status (essentially it'll call isWebSetupRunning() every - * second in the background). When the web setup is no longer running the - * callback will be executed. The background processing is disabled when stopWebSetup() - * is called. - * - * @note only the 'result' parameter of the callback handler is valid. - * - * Refer to @ref setting_async_processing for more info. - * - * @param[in] ssid Optional, optionally set the SSID of module's softAp - * @param[in] password Optional, optionally set the WPA2-PSK password for the module'S softap - * Note: make an OPEN softAp, set this parameter to a null string (i.e. "") - * @param[in] completeHandler Optional, callback to be executed when module web setup completes. - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult startWebSetup(const char *ssid = NULL, const char *password = NULL, const Callback &completeHandler = Callback()); - - /** - * @ingroup api_network_setup - * - * @brief Stop the WiConnect WiFi module 'web setup' feature. - * - * This method should be called AFTER startWebSetup() to prematurely terminate - * web setup. Note that this is not needed if web setup completes by itself - * (i.e. if the user exits web setup from the webpage). - * - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult stopWebSetup(); - - /** - * @ingroup api_network_setup - * - * @brief Return status of WiConnect WiFi module 'web setup' feature. - * - * This may be called at any time (whether web setpu has been stared or not). - * - * @param[out] isRunningPtr Pointer to bool to contain TRUE if web setup is running, FALSE else - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult isWebSetupRunning(bool *isRunningPtr); - - - // ------------------------------------------------------------------------ - - - /** - * @ingroup api_network_wlan - * - * @brief Join a WiFi network. - * - * This command has an optional background processing feature. - * Background processing is enabled if the completeHandler parameter - * is specified. If enabled, the library will poll the module every second - * for the join status (essentially it'll call getNetworkStatus() every - * second in the background). When the module join sequence complete the callback will be executed. - * The background processing is disabled when leave() is called. - * - * * If completeHandler parameter is NOT specified: - * This command will BLOCK/return WICONNECT_PROCESSING until the module has - * either successfully joined the network or failed. - * * If the completeHandler parameter IS specified: - * This command will return and use the background processing feature described above. - * - * @note only the 'result' parameter of the callback handler is valid. - * - * Refer to @ref setting_async_processing for more info. - * - * @param[in] ssid Optional, optionally set the SSID of the network to join - * @param[in] password Optional, optionally set the passkey of the network to join - * Note: to join an OPEN network, set this parameter to a null string (i.e. "") - * @param[in] completeHandler Optional, callback to be executed when the join sequence completes. - * The 'result' callback parameter contains the WiconnectResult of joining. - * The 'arg1' parameter is a @ref NetworkJoinResult of joining. - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult join(const char* ssid = NULL, const char *password = NULL, const Callback &completeHandler = Callback()); - - /** - * @ingroup api_network_wlan - * - * @brief Leave a WiFi network. - * - * This method may be called to either terminate a join sequence or - * leave a previously connected networked. - * - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult leave(); - - /** - * @ingroup api_network_wlan - * - * @brief Get connection status to WiFi network. - * - * Refer to @ref NetworkStatus for more info. - * - * @param[out] statusPtr Point to a @ref NetworkStatus which will hold current network status of module - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult getNetworkStatus(NetworkStatus *statusPtr); - - /** - * @ingroup api_network_wlan - * - * @brief Get the result of joining the network - * - * Refer to @ref NetworkJoinResult for more info. - * - * @param[out] joinResultPtr Point to a @ref NetworkJoinResult which will hold the result of joining the network - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult getNetworkJoinResult(NetworkJoinResult *joinResultPtr); - - // ------------------------------------------------------------------------ - - -// WiconnectResult startSoftAp(const char* ssid = NULL, const char *password = NULL, const Callback &clientConnectedCallback = Callback()); -// WiconnectResult stopSoftAp(); -// WiconnectResult getSoftApClientList(); - - - // ------------------------------------------------------------------------ - - - /** - * @ingroup api_network_util - * - * @brief Scan for available WiFi networks. - * - * The populate the supplied @ref ScanResultList with @ref ScanResult of each found network. - * - * Optionally only scan of specific channels by supplying a null terminated list of channels. - * Example: - * @code - * const uint8_t channelsToScan[] = {1, 6, 11, 0}; - * @endcode - * - * @param[out] resultList List to populate with scan results. - * @param[in] channelList Optional, null terminated list of channels to scan. - * @param[in] ssid Optional, specific network name to scan for. - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult scan(ScanResultList &resultList, const uint8_t *channelList = NULL, const char* ssid = NULL); - - /** - * @ingroup api_network_util - * - * @brief Ping a WiFi network. - * - * Optionally ping a specific server and return the time in milliseconds it took - * for the network to response. If no domain is supplied, the module pings to gateway - * (i.e router it's connected to). - * - * @param[in] domain Optional, the domain name to ping - * @param[out] timeMsPtr Optional, pointer to uint32 to hold time in milliseconds the ping took - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult ping(const char *domain = NULL, uint32_t *timeMsPtr = NULL); - - /** - * @ingroup api_network_util - * - * @brief Resolve domain name into IP address. - * - * @param[in] domain The domain name to resolve - * @param[out] ipAddressPtr pointer to uint32 to hold resolved IP address. Note, the IP address is in network-byte-order. - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult lookup(const char *domain, uint32_t *ipAddressPtr); - - - // ------------------------------------------------------------------------ - - - /** - * @ingroup api_network_settings - * - * @brief Set DHCP enabled. - * - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult setDhcpEnabled(bool enabled); - - /** - * @ingroup api_network_settings - * - * @brief Get if DHCP enabled. - */ - WiconnectResult getDhcpEnabled(bool *enabledPtr); - - /** - * @ingroup api_network_settings - * - * @brief Set static IP settings - */ - WiconnectResult setIpSettings(uint32_t ip, uint32_t netmask, uint32_t gateway); - - /** - * @ingroup api_network_settings - * - * @brief Set static IP settings (with string parameters) - */ - WiconnectResult setIpSettings(const char* ip, const char* netmask, const char* gateway); - - /** - * @ingroup api_network_settings - * - * @brief Get network IP settings - */ - WiconnectResult getIpSettings(uint32_t *ip, uint32_t *netmask, uint32_t *gateway); - - /** - * @ingroup api_network_settings - * - * @brief Get signal strength to WiFi network - */ - WiconnectResult getSignalStrength(NetworkSignalStrength *signalStrengthPtr); - - - /** - * @ingroup api_network_settings - * - * @note This method is only supported in blocking mode. - * - * @brief Return the current IP address of the module if possible, else - * return 0.0.0.0 - * @param[in] buffer Optional, buffer to IP address string. If omitted, - * the IP address string is stored in a local static buffer (this is non-reentrant!) - */ - const char* getIpAddress(char *buffer = NULL); - - - // ------------------------------------------------------------------------ - - - /** - * @ingroup conversion_util - * - * @brief Convert string to IP address - */ - static bool strToIp(const char *str, uint32_t *intPtr); - - /** - * @ingroup conversion_util - * - * @brief Convert IP address to string - */ - static const char* ipToStr(uint32_t ip, char *ipStrBuffer = NULL); - - /** - * @ingroup conversion_util - * - * @brief Convert @ref NetworkStatus to string - */ - static const char* networkStatusToStr(NetworkStatus status); - - /** - * @ingroup conversion_util - * - * @brief Convert @ref NetworkJoinResult to string - */ - static const char* networkJoinResultToStr(NetworkJoinResult joinResult); - - /** - * @ingroup conversion_util - * - * @brief Convert @ref NetworkSignalStrength to string - */ - static const char* signalStrengthToStr(NetworkSignalStrength signalStrenth); - - /** - * @ingroup conversion_util - * - * @brief Convert RSSI (in dBm) to @ref NetworkSignalStrength - */ - static NetworkSignalStrength rssiToSignalStrength(int rssi); - - /** - * @ingroup conversion_util - * - * @brief Convert string to @ref NetworkSecurity - */ - static NetworkSecurity strToNetworkSecurity(const char *str); - - /** - * @ingroup conversion_util - * - * @brief Convert @ref NetworkSecurity to string - */ - static const char* networkSecurityToStr(NetworkSecurity security); - - /** - * @ingroup conversion_util - * - * @brief Convert string @ref Ssid - */ - static bool strToSsid(const char *str, Ssid *ssid); - - /** - * @ingroup conversion_util - * - * @brief Convert @ref Ssid to string - */ - static const char* ssidToStr(const Ssid *ssid, char *ssidStrBuffer = NULL); - - /** - * @ingroup conversion_util - * - * @brief Convert string @ref MacAddress - */ - static bool strToMacAddress(const char *str, MacAddress *macAddress); - - /** - * @ingroup conversion_util - * - * @brief Convert @ref MacAddress to string - */ - static const char* macAddressToStr(const MacAddress *macAddress, char *macStrBuffer = NULL); - -protected: - NetworkInterface(Wiconnect *wiconnect); - - WiconnectResult processScanResults(char *resultStr, ScanResultList &resultList); - -#ifdef WICONNECT_ASYNC_TIMER_ENABLED - Callback completeHandler; - PeriodicTimer monitorTimer; - - void webSetupStatusMonitor(); - void webSetupStatusCheckCallback(WiconnectResult result, void *arg1, void *arg2); - - void joinStatusMonitor(); - void joinStatusCheckCallback(WiconnectResult result, void *arg1, void *arg2); - - //void scanCompleteCallback(WiconnectResult result, void *arg1, void *arg2); -#endif - -private: - Wiconnect *wiconnect; -}; - -}
--- a/README.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,280 +0,0 @@ -/** - * @mainpage Library Overview - * - * @section Overview - * The WiConnect Library runs on a host MCU and controls a - * WiConnect enabled WiFi module. This library is essentially a - * programming API for the WiConnect serial command set. More infomation - * about the serial command set may be found here: - * <a href="http://wiconnect.ack.me" target="_blank">WiConnect Reference Guide</a> - * - * @section notes Important Notes - * - This class is implemented as a 'singleton'. This means it only needs to be - * instantiated once. - * - The WiConnect library does NOT call the global 'new' or 'malloc' functions. - * All memory allocation (if required) comes from a user supplied malloc function pointer or buffer - * - * - * @section features Library Settings - * The WiConnect Library has multiple settings so as to allow - * for the most flexibility within a user's application. - * - * Some of these configurations are as follows: - * - Blocking / Non-blocking - * - Dynamic / Static allocation - * - Asynchronous Processing - * - * - * @subsection setting_blocking_modes Blocking / Non-blocking Modes - * The WiConnect Library may be configured for either 'blocking' or - * 'non-blocking' operation: - * - blocking - API calls do not return until they complete successfully or timeout. - * - non-blocking - API calls return immediately. The caller should check the return code to see - * if the command is still processing, completed, or an error occurred. The caller - * should continue to call the API function (as often as possible) until it returns - * either a success or error code. - * - * @subsubsection setting_blocking_mode Blocking Mode - * In blocking mode, an API function will block until it completes. - * More details to come... - * - * @subsubsection setting_nonblocking_mode Non-Blocking Mode - * In non-blocking mode, an API function returns immediately. - * More details to come... - * - * - * - * @subsection setting_alloc Dynamic / Static Allocation - * There are two cases when memory allocation is required: - * - Buffer allocation - * - Class instantiation - * - * In both cases, either static or dynamic memory allocation may be used. - * - * In cases when memory allocation is needed, the API call requires a buffer pointer - * and length parameters. If both are supplied, the library uses the supplied external buffer. - * This is considered static allocation (however the buffer could have been dynamically allocated). - * The caller is responsible for maintaining the supplied buffer. - * - * If, however, only the buffer length is supplied and the buffer pointer is NULL - * the Wiconnect Library will call the user supplied malloc() function. This is considered - * dynamic allocation. In this case, the library will maintain the buffer and release it - * when necessary using the user supplied free() function. - * - * @note To use dynamic allocation the WiConnect Library must be compiled with - * @ref WICONNECT_ENABLE_MALLOC defined, and the Wiconnect() constructor must be - * supplied with pointers to malloc() and free() functions. - * - * @note The Wiconnect Library does NOT call the global 'new' operator. Classes that are - * internally instantiated overload the 'new' operator and either call the user - * supplied malloc() function or use the supplied static buffer. - * - * - * @subsection setting_async_processing Asynchronous Processing - * When applicable, the WiConnect Library will asynchronously process - * commands in the background. When the background processing completes, the - * supplied callback is called. - * - * User commands may also be executed in the background using the enqueueCommand() - * API function. - * - * @note The WiConnect Library must be compiled with @ref WICONNECT_ASYNC_TIMER_ENABLED - * defined for background processing to be enabled. - * - * - * - * @section send_command_desc Sending Commands To WiFi Module - * More details to come... - * - * - */ - -// ---------------------------------------------------------------------------- - -/** - * @defgroup api_core Core - * @brief This contains all core methods - * - * @{ - */ - -/** - * @defgroup api_core_settings Settings Methods - * @brief API getters/setters for core library settings - */ - -/** - * @defgroup api_core_send_command Send Command Methods - * @brief API methods for sending commands to WiConnect WiFi module - */ - -/** - * @defgroup api_core_misc Miscellaneous Methods - * @brief Other core methods - */ - -/** - * @defgroup api_core_types Types - * @brief Core Types - */ - - -/** - * @defgroup api_core_macro Macros - * @brief Core macros - */ - -/** - * @defgroup api_core_examples Examples - * @brief Core examples - * * @ref ota/example.cpp - */ - -// @} - - -// ---------------------------------------------------------------------------- - -/** - * @defgroup api_network Network - * @brief This contains all network methods - * - * @{ - */ - -/** - * @defgroup api_network_settings Settings Methods - * @brief API getters/setters for module network settings - */ - -/** - * @defgroup api_network_wlan WLAN Methods - * @brief Methods for joining/leaving a WLAN - */ - -/** - * @defgroup api_network_setup Web Setup Methods - * @brief Methods for enabled/disabling module web setup - */ - -/** - * @defgroup api_network_util Utility Methods - * @brief Network utility methods - */ - -/** - * @defgroup api_network_types Types - * @brief Network Types - */ - -/** - * @defgroup api_network_macros Macros - * @brief Network specific macros - */ - -/** - * @defgroup api_network_examples Examples - * @brief Network examples - * * @ref web_setup/example.cpp - * * @ref join/example.cpp - */ - -// @} - - -// ---------------------------------------------------------------------------- - -/** - * @defgroup api_socket Socket - * @brief This contains all socket methods - * - * @{ - */ - -/** - * @defgroup api_socket_tcp TCP Methods - * @brief TCP methods - */ - -/** - * @defgroup api_socket_udp UDP Methods - * @brief UDP methods - */ - -/** - * @defgroup api_socket_tls TLS Methods - * @brief TLS methods - */ - -/** - * @defgroup api_socket_http HTTP Methods - * @brief HTTP methods - */ - -/** - * @defgroup api_socket_misc Miscellaneous Methods - * @brief Miscellaneous socket methods - */ - -/** - * @defgroup api_socket_types Types - * @brief Socket Types - */ - -/** - * @defgroup api_socket_macro Macros - * @brief Socket specific macros - */ - -/** - * @defgroup api_socket_examples Examples - * @brief Socket examples - * * @ref http_get/example.cpp - * * @ref tcp_server/example.cpp - * - */ - -// @} - - -// ---------------------------------------------------------------------------- - -/** - * @defgroup api_file File - * @brief This contains all file methods - * - * @{ - */ - -/** - * @defgroup api_file_methods Methods - * @brief File Types - */ - -/** - * @defgroup api_file_types Types - * @brief File Types - */ - -/** - * @defgroup api_file_macro Macros - * @brief API specific macros - */ - -/** - * @defgroup api_file_examples Examples - * @brief File examples - */ - -// @} - - -// ---------------------------------------------------------------------------- - -/** - * @defgroup conversion_util Conversion Utilities - * @brief This contains all the conversion utility static functions. - * - */ - -
--- a/SocketInterface.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,345 +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" -#include "types/WiconnectSocket.h" -#include "types/SocketIrqHandlerMap.h" - - -/** - * @namespace wiconnect - */ -namespace wiconnect { - - -/** - * @ingroup api_socket_types - * - * @brief The provides an interface for creating TCP/UDP/TLS/HTTP client sockets. - * A client socket connects to a remote server. - * - * @note This class is an interface to the Wiconnect class. It should never be - * independently instantiated or the parent of another class. - */ -class SocketInterface -{ -public: - /** - * @ingroup api_socket_misc - * - * @brief Close all opened sockets. - * - * @note This closes all open sockets on the MODULE side. - * Socket objects on the HOST side will be still open until - * issuing a read/write command to the module using the socket handle. - * - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult closeAllSockets(); - - /** - * @ingroup api_socket_misc - * - * @brief Register a host pin as an external interrupt. When the external interrupt is - * triggered, the supplied callback is executed. - * - * This should be called before calling one of the connect methods below - * with an irqPin parameter. - * - * Basically how this works is: - * 1. The supplied irqPin is configured as an external interrupt pin. - * 2. A connection is opened and configured with the same irqPin. This - * irqPin physically connected to a GPIO on the WiFi module. - * 3. When the WiFi module has data to send to the HOST it asserts the irqPin. - * 4. The irqPin interrupt executes and calls the supplied handler. - * 5. The handler should notify the HOST that the given irqPin has triggered - * and have the associated socket read data from the module. - * - * @note arg1 of the handler contains the irqPin - * - * - * @param[in] irqPin The HOST pin to configure as an external interrupt. - * This pin should be physically connected to a module GPIO. - * @param[in] handler Callback to be executed with the external irqPin interrupt triggers - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult registerSocketIrqHandler(Pin irqPin, const Callback &handler); - - /** - * @ingroup api_socket_misc - * - * @brief Unregister a previously registered IRQ pin. - * - * This disables the given irqPin as an external interrupt. - * Refer to registerSocketIrqHandler() for more information. - * - * @param[in] irqPin The HOST pin to unregister - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult unregisterSocketIrqHandler(Pin irqPin); - - - /** - * @ingroup api_socket_misc - * - * @brief Connect to remote server. - * - * This is the base method used by all the other connect methods. - * - * @param[out] socket @ref WiconnectSocket object of opened connection. - * @param[in] type The @ref SocketType of connection to open - * @param[in] host The host/IP address of the remote server - * @param[in] remortPort The port of the remote server - * @param[in] localPort The port of the module's side of the connection - * @param[in] args Depedent on the connection type - * @param[in] irqPin Data available external interrupt pin. See registerSocketIrqHandler() for more info - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult connect(WiconnectSocket &socket, SocketType type, const char *host, uint16_t remortPort, uint16_t localPort, const void *args, Pin irqPin); - - - // ------------------------------------------------------------------------ - - /** - * @ingroup api_socket_tcp - * - * @brief Connect to remote TCP server. - * - * @param[out] socket TCP @ref WiconnectSocket object of opened connection. - * @param[in] host The host/IP address of the remote TCP server - * @param[in] remortPort The port of the remote server - * @param[in] irqPin Optional, Data available external interrupt pin. See registerSocketIrqHandler() for more info - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult tcpConnect(WiconnectSocket &socket, const char *host, uint16_t remortPort, Pin irqPin = PIN_NC); - - - // ------------------------------------------------------------------------ - - /** - * @ingroup api_socket_tcp - * - * @brief Start internal TCP server and listen on specified port. - * - * @param[in] listeningPort The local port the server should listen on - * @param[in] maxClients Optional, the maximum simultaneous connected clients, 0 is default, 1-8 valid range - * @param[in] irqPin Optional, Data available external interrupt pin. See registerSocketIrqHandler() for more info - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult tcpListen(uint16_t listeningPort, int maxClients = 0, Pin irqPin = PIN_NC); - - - // ------------------------------------------------------------------------ - - /** - * @ingroup api_socket_tcp - * - * @brief Wait for next client to connect to TCP server. - * - * @param[in] socket Socket to connected client - * @param[in] timeoutMs Optional, specifiy maximum amount of time in ms to wait for a client - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult tcpAccept(WiconnectSocket &socket, int timeoutMs = WICONNECT_WAIT_FOREVER); - - - // ------------------------------------------------------------------------ - - /** - * @ingroup api_socket_tcp - * - * @brief Stop TCP server from listening on port. Close all connected clients. - * - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult tcpServerStop(void); - - - // ------------------------------------------------------------------------ - - /** - * @ingroup api_socket_tls - * - * @brief Connect to remote TLS server. - * - * @param[out] socket TLS @ref WiconnectSocket object of opened connection. - * @param[in] host The host/IP address of the remote TLS server - * @param[in] remortPort The port of the remote server - * @param[in] certFilename Optional, filename of certificate on module's file system - * @param[in] irqPin Optional, Data available external interrupt pin. See registerSocketIrqHandler() for more info - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult tlsConnect(WiconnectSocket &socket, const char *host, uint16_t remortPort, const char *certFilename = NULL, Pin irqPin = PIN_NC); - - - // ------------------------------------------------------------------------ - - /** - * @ingroup api_socket_udp - * - * @brief Connect to remote UDP server. - * - * @param[out] socket UDP @ref WiconnectSocket object of opened connection. - * @param[in] host The host/IP address of the remote UDP server - * @param[in] remortPort The port of the remote server - * @param[in] localPort Optional, port of module's side of the connection - * @param[in] irqPin Optional, Data available external interrupt pin. See registerSocketIrqHandler() for more info - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult udpConnect(WiconnectSocket &socket, const char *host, uint16_t remortPort, uint16_t localPort = SOCKET_ANY_PORT, Pin irqPin = PIN_NC); - - - // ------------------------------------------------------------------------ - - /** - * @ingroup api_socket_http - * - * @brief Connect to remote HTTP server. - * - * This is the base method for the other HTTP methods. - * - * @section secure_http_connection Secure HTTP - * Each HTTP method is able to connect to a secure HTTP server. To do this, - * the URL string parameter must start with 'https://' - * To connect to a secure HTTP server a TLS certificate is needed. The certificate - * is specified in the certFilename parameter of the method (or @ref HttpSocketArgs parameter). - * This is the filename of an existing certificate on the module file system. - * - * @note If the URL starts with 'https://' and no certificate filename is specified, - * the module's default certificate is used. - * - * @param[out] socket HTTP @ref WiconnectSocket object of opened connection. - * @param[in] url URL of HTTP request - * @param[in] args Configuration @ref HttpSocketArgs for HTTP connection - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult httpConnect(WiconnectSocket &socket, const char *url, const HttpSocketArgs *args); - - /** - * @ingroup api_socket_http - * - * @brief Issue HTTP GET Request - * - * This method has the open to only 'open' the connection (disabled by default). This means a connection - * to the remote HTTP server is opened, but the HTTP request isn't issued. This - * allow for addition data to be added to the request. For instance, use httpAddHeader() to add - * additional headers to the request. - * Use httpGetStatus() to issue the HTTP request and receive the HTTP response. - * - * @param[out] socket HTTP @ref WiconnectSocket object of opened connection. - * @param[in] url URL of HTTP GET request - * @param[in] openOnly Optional, if TRUE this will only open a connection to the server (it won't issue the request) - * @param[in] certFilename Optional, filename of existing TLS certificate on module's file system. See @ref secure_http_connection - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult httpGet(WiconnectSocket &socket, const char *url, bool openOnly = false, const char *certFilename = NULL); - - /** - * @ingroup api_socket_http - * - * @brief Issue HTTP POST Request - * - * This method has the open to only 'open' the connection which enabled by default. This means a connection - * to the remote HTTP server is opened, but the HTTP request isn't issued. This - * allow for addition data to be added to the request. Use the returned @ref WiconnectSocket object's 'write' methods - * to add POST data to the request. - * When all POST data has been written, use httpGetStatus() to issue the HTTP request and receive the HTTP response. - * - * @param[out] socket HTTP @ref WiconnectSocket object of opened connection. - * @param[in] url URL of HTTP POST request - * @param[in] contextType The value to go into the 'content-type' HTTP header (e.g. 'application/json') - * @param[in] openOnly Optional, if FALSE this will immediately issue the POST request. - * @param[in] certFilename Optional, filename of existing TLS certificate on module's file system. See @ref secure_http_connection - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult httpPost(WiconnectSocket &socket, const char *url, const char *contextType, bool openOnly = true, const char *certFilename = NULL); - - /** - * @ingroup api_socket_http - * - * @brief Issue HTTP HEAD Request - * - * @param[out] socket HTTP @ref WiconnectSocket object of opened connection. - * @param[in] url URL of HTTP HEAD request - * @param[in] certFilename Optional, filename of existing TLS certificate on module's file system. See @ref secure_http_connection - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult httpHead(WiconnectSocket &socket, const char *url, const char *certFilename = NULL); - - /** - * @ingroup api_socket_http - * - * @brief Add HTTP header key/value pair to opened HTTP request. - * - * To use this function, the supplied @ref WiconnectSocket parameter must have been created - * using either httpGet() or httpPost() and the 'openOnly' parameter TRUE. - * - * This will add additional header to the HTTP request. - * - * Use httpGetStatus() to issue the request. - * - * @param[in] socket Opened socket to add additonal HTTP header - * @param[in] key Header key (e.g. 'content-type') - * @param[in] value Header value (e.g. 'application/json') - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult httpAddHeader(WiconnectSocket &socket, const char *key, const char *value); - - /** - * @ingroup api_socket_http - * - * @brief Get the HTTP status code from HTTP request. - * - * This may be used to either issue an HTTP request of an opened HTTP connection - * or return the status code of a request already issued. - * - * @param[in] socket Opened socket to get http response status code - * @param[out] statusCodePtr Pointer to uint32 to hold http status code - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult httpGetStatus(WiconnectSocket &socket, uint32_t *statusCodePtr); - -protected: - SocketInterface(Wiconnect *wiconnect); - ~SocketInterface(); - - SocketIrqHandlerMap irqHandlers; - - bool serverConnectedClientList[WICONNECT_MAX_SOCKETS]; - - WiconnectResult pollForServerClient(uint8_t *handle = NULL, uint16_t *localPort = NULL, uint16_t *remotePort = NULL, uint32_t *ipAddress = NULL); - - void socketClosedCallback(const WiconnectSocket *socket); - -private: - Wiconnect *wiconnect; -}; - -}
--- a/StringUtil.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,413 +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 <string.h> -#include <ctype.h> -#include <stdint.h> -#include <limits.h> - - -#ifdef WICONNECT_USE_STRTOLL -// Necessary to get strtoll in C99 mode. -// http://sourceware.org/ml/newlib/2012/msg00425.html -extern long long strtoll(const char *__n, char **__end_PTR, int __base); -#endif - - -class StringUtil -{ - -public: - /*************************************************************************************************/ - // Helper to find an occurrence of a delimiter string, - // insert '\0' in its place and return string after - // the delimiter e.g. - // if char s[] = "foo://bar"; - // - strchop(s, "://") returns "bar" - // - s becomes "foo" - static char *chop(char *haystack, const char *needle) - { - if (!haystack) - { - return NULL; - } - char *end = strstr(haystack, needle); - if (end) - { - *end = '\0'; - return end + strlen(needle); - } - return NULL; - } - - /*************************************************************************************************/ - // Check if string is non-null and non-empty. - static bool empty(const char *s) - { - return !(s && *s); - } - - /*************************************************************************************************/ - static bool isSpace(const char *s) - { - while(*s != 0) - { - if(!isspace((uint8_t)*s++)) - return false; - } - return true; - } - - /*************************************************************************************************/ - // Convert null-terminated string to lower case. - // ASCII charset only. - static void toLower(char *s) - { - for (; *s; ++s) - { - *s = tolower((int) * s); - } - } - - /*************************************************************************************************/ - // Combination of strip left + right. - static char *strip(char *s, const char *chars) - { - return rightStrip(leftStrip(s, chars), chars); - } - - /*************************************************************************************************/ - // Strip string from the left. - // Returns pointer into the input string. - static char *leftStrip(char *s, const char *chars) - { - return s + strspn(s, chars); - } - - /*************************************************************************************************/ - // Strip string from the right. - // Modified in place. - static char *rightStrip(char *s, const char *chars) - { - char *end = s + strlen(s) - 1; - while (end > s && strstr(chars, end)) - { - *end-- = '\0'; - } - return s; - } - - /*************************************************************************************************/ - // Parse decimal integer and check if it's in bounds [min, max]. - static bool parseInt(const char *s, intmax_t *result, intmax_t min, intmax_t max) - { - return parseBase(s, result, min, max, 10); - } - - // Parse hexadecimal integer and check if it's in bounds [min, max]. - static bool parseHex(const char *s, intmax_t *result, intmax_t min, intmax_t max) - { - return parseBase(s, result, min, max, 16); - } - - /*************************************************************************************************/ - static bool parseBase(const char *s, intmax_t *result, intmax_t min, intmax_t max, int base) - { - if (!s) - { - return false; - } - char *end; -#ifdef WICONNECT_USE_STRTOLL - intmax_t value = strtoll(s, &end, base); -#else - intmax_t value = strtol(s, &end, base); -#endif - if (*end || value < min || value > max) - { - return false; - } - *result = value; - return true; - } - - /*************************************************************************************************/ - // Parse an long long integer. - static bool parseBool(const char *onoff, bool *var) - { - const char* const on_vals[] = - { - "1", - "on", - "true", - "yes", - }; - - for(uint8_t i = 0; i < ARRAY_COUNT(on_vals); ++i) - { - if(strcasecmp(on_vals[i], onoff) == 0) - { - *var = true; - return true; - } - } - - const char* const off_vals[] = - { - "0", - "false", - "no", - "off", - NULL - }; - for(uint8_t i = 0; i < ARRAY_COUNT(off_vals); ++i) - { - if(strcasecmp(off_vals[i], onoff) == 0) - { - *var = false; - return true; - } - } - - return false; - } - - /*************************************************************************************************/ - // convert binary data to hex string - static void binToHex(char *dst, int max_dst, const void *data, int data_len) - { - char *end = dst + max_dst - 1; - for (int i = 0; i < data_len; ++i) - { - if (dst < end) - { - dst += sprintf(dst, "%2.2x", ((uint8_t *)data)[i]); - } - } - } - - - /*************************************************************************************************/ - // Parse binary data into hex string - // the input buffer MUST be len*2 long - // as the parsing is destructive and done in-place - static void binToHex(void *h, int len) - { - char *dst = (char*)h; - char *src= (char*)h+len; - - memmove(src, dst, len); - - while(len--) - { - sprintf(dst, "%2.2X", (unsigned int)(*src & 0xff)); - dst += 2; - ++src; - } - } - - - /*************************************************************************************************/ - // Parses hex representation of binary data destructively. - // Returns number of bytes parsed or -1 on error. - static int hexToBin(char *s) - { - int len, i, j; - len = strlen(s); - if (len % 2) - { - return -1; - } - for (i = j = 0; i < len; i += 2, j++) - { - const int num = hexToInt(&s[i]); - if(num == -1) - return -1; - s[j] = (char)num; - } - return j; - } - - /*************************************************************************************************/ - // hex string to integer, returns -1 on error - static int hexToInt(const char *hex_str) - { - int hi = hexToNibble(*hex_str); - int lo = hexToNibble(*(hex_str+1)); - if (hi == -1 || lo == -1) - { - return -1; - } - return (hi << 4) | lo; - } - - /*************************************************************************************************/ - static int hexToNibble(char c) - { - if (c >= '0' && c <= '9') - { - return c - '0'; - } - if (c >= 'a' && c <= 'f') - { - return 10 + (c - 'a'); - } - if (c >= 'A' && c <= 'F') - { - return 10 + (c - 'A'); - } - return -1; - } - - /*************************************************************************************************/ - static const char* uint32ToStr(char* intStrBuffer, int integer) - { - sprintf(intStrBuffer, "%u", integer); - return intStrBuffer; - } - - /*************************************************************************************************/ - static bool strToUint32(const char *str, uint32_t *uint32Ptr) - { - intmax_t r; - bool result = (str[0] == '0' && str[1] == 'x') ? StringUtil::parseHex(&str[2], &r, 0, UINT_MAX): StringUtil::parseInt(str, &r, 0, UINT_MAX); - *uint32Ptr = (uint32_t)r; - return result; - } - - /*************************************************************************************************/ - static bool strToUint16(const char *str, uint16_t *uint16Ptr) - { - intmax_t r; - bool result = StringUtil::parseInt(str, &r, 0, USHRT_MAX); - *uint16Ptr = (uint16_t)r; - return result; - } - - /*************************************************************************************************/ - static bool strToInt32(const char *str, int32_t *int32Ptr) - { - intmax_t r; - bool result = StringUtil::parseInt(str, &r, INT_MIN, INT_MAX); - *int32Ptr = (int32_t)r; - return result; - } - - /*************************************************************************************************/ - // uint32 hex string to uint32 - static bool strHexToUint32(const char *strHex, uint32_t *uint32Ptr) - { - intmax_t r; - bool result = StringUtil::parseHex(strHex, &r, 0, UINT_MAX); - *uint32Ptr = (uint32_t)r; - return result; - } - - /*************************************************************************************************/ - static char *strtok_r(char *str, const char *delim, char **nextp) - { - char *ret; - - if (str == NULL) - { - str = *nextp; - } - - str += strspn(str, delim); - - if (*str == '\0') - { - return NULL; - } - - ret = str; - - str += strcspn(str, delim); - - if (*str) - { - *str++ = '\0'; - } - - *nextp = str; - - return ret; - } - - /*************************************************************************************************/ - static int strncasecmp(const char *s1, const char *s2, int n) - { - if (n == 0) - return 0; - - while (n-- != 0 && tolower(*s1) == tolower(*s2)) - { - if (n == 0 || *s1 == '\0' || *s2 == '\0') - break; - s1++; - s2++; - } - - return tolower(*(unsigned char *) s1) - tolower(*(unsigned char *) s2); - } - - /*************************************************************************************************/ - static int strcasecmp(const char *s1, const char *s2) - { - register const unsigned char *p1 = (const unsigned char *) s1; - register const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; - - if (p1 == p2) - return 0; - - do - { - c1 = tolower (*p1); - c2 = tolower (*p2); - - if (c1 == '\0') - break; - - ++p1; - ++p2; - } - while (c1 == c2); - - if (UCHAR_MAX <= INT_MAX) - return c1 - c2; - else - /* On machines where 'char' and 'int' are types of the same size, the - difference of two 'unsigned char' values - including the sign bit - - doesn't fit in an 'int'. */ - return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0); - } -};
--- a/Wiconnect.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +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 "WiconnectInterface.h" - - -using namespace wiconnect; -
--- a/WiconnectInterface.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,760 +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" - - -#include "types/LogFunc.h" -#include "types/ReaderFunc.h" -#include "types/Callback.h" -#include "types/QueuedCommand.h" -#include "types/CommandQueue.h" -#include "types/TimeoutTimer.h" -#include "types/PeriodicTimer.h" -#include "types/Gpio.h" -#include "types/WiconnectSerial.h" - -#include "NetworkInterface.h" -#include "SocketInterface.h" -#include "FileInterface.h" - - -#ifdef WICONNECT_ENABLE_MALLOC -/// These are optional arguments for host specific malloc/free -#define WICONNECT_MALLOC_ARGS , void* (*malloc_)(size_t) = WICONNECT_DEFAULT_MALLOC, void (*free_)(void*) = WICONNECT_DEFAULT_FREE -#else -#define WICONNECT_MALLOC_ARGS -#endif - - -/** - * @namespace wiconnect - */ -namespace wiconnect { - - -/** - * @ingroup api_core_types - * - * @brief The root WiConnect library class. This class - * inheriets all WiConnect functionality. - * - * This class is implemented as a 'singleton'. This means it - * only needs to be instantiated once. Subsequent class may either - * use the class instance or the static function: @ref Wiconnect::getInstance() - * - */ -class Wiconnect : public NetworkInterface, - public SocketInterface, - public FileInterface -{ -public: - - /** - * @brief WiConnect class constructor - * - * @note This should only be called once within a program as the WiConnect - * library is implemented as a singleton. - * - * @note If this constructor is used, then all commands must be supplied with an external response buffer. - * This means most the API functions will not work as they use the internal buffer. - * It's recommended to use the other constructor that supplies an internal buffer. See @ref setting_alloc - * - * @param[in] serialConfig The serial (i.e. UART) configuration connected to a WiConnect module. - * @param[in] reset Optional, The pin connected to the WiConnect module reset signal. Default: No connection - * @param[in] wake Optional, The pin connected to the WiConnect module wake signal. Default: No connection - * @param[in] nonBlocking Optional, indicates if the API blocking mode. See @ref setting_blocking_modes - */ - Wiconnect(const SerialConfig &serialConfig, Pin reset = PIN_NC, Pin wake = PIN_NC, bool nonBlocking = WICONNECT_DEFAULT_NONBLOCKING WICONNECT_MALLOC_ARGS); - - /** - * @brief WiConnect class constructor - * - * @note This should only be called once within a program as the WiConnect - * library is implemented as a singleton. - * - * @note This is the recommended construstor as it supplies the WiConnect library with an - * internal buffer. Most API calls require the internal buffer. - * - * @param[in] serialConfig The serial (i.e. UART) configuration connected to a WiConnect module. - * @param[in] internalBufferSize The size of the internal buffer. If internalBuffer is NULL, then this size will be dynamically allocated. See @ref setting_alloc - * @param[in] internalBuffer Optional, a user allocated buffer. See @ref setting_alloc - * @param[in] reset Optional, The pin connected to the WiConnect module reset signal. Default: No connection - * @param[in] wake Optional, The pin connected to the WiConnect module wake signal. Default: No connection - * @param[in] nonBlocking Optional, indicates if the API blocking mode. See @ref setting_blocking_modes - */ - Wiconnect(const SerialConfig &serialConfig, int internalBufferSize, void *internalBuffer = NULL, Pin reset = PIN_NC, Pin wake = PIN_NC, bool nonBlocking = WICONNECT_DEFAULT_NONBLOCKING WICONNECT_MALLOC_ARGS); - ~Wiconnect(); - - - // ------------------------------------------------------------------------ - - - /** - * @ingroup api_core_misc - * - * @brief Get instance of previously instantiated Wiconnect Library - * - * @return Pointer to instance of @ref Wiconnect Library. - */ - static Wiconnect* getInstance(); - - /** - * @ingroup api_core_misc - * - * @brief Initialize library and communication link with WiConnect WiFi module. - * - * @note This function is always blocking regardless of configured mode. - * - * @param[in] bringNetworkUp Flag indicating if the module should try to bring the network up upon initialization. - * @return Result of initialization. See @ref WiconnectResult - */ - WiconnectResult init(bool bringNetworkUp=false); - - /** - * @ingroup api_core_misc - * - * @brief De-initialize library. - */ - void deinit(); - - /** - * @ingroup api_core_misc - * - * @brief Return TRUE if library is able to communicated with WiConnect WiFi module. - * FALSE else. - * - * @return TRUE if library can communicate with WiFi module, FALSE else. - */ - bool isInitialized(); - - /** - * @ingroup api_core_misc - * - * @brief Toggle the WiConnect WiFi module reset signal. - * - * @note This only resets the module if the library was instantiated with the 'reset' pin - * parameter in the Wiconnect::Wiconnect constructor. - * @note This method is always blocking. A small (1s) delay is added to ensure the module - * has returned from reset and ready. - * - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult reset(); - - /** - * @ingroup api_core_misc - * - * @brief Toggle the WiConnect WiFi moduel wakeup signal. - * - * @note This only wakes the module if the library was instantiated with the 'wake' pin - * parameter in the Wiconnect::Wiconnect constructor. - * @note This method is always blocking. - * - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult wakeup(); - - /** - * @ingroup api_core_misc - * - * @brief Flush any received data in serial RX buffer and terminate any commands on WiConnect WiFi module. - * - * The delayMs parameter is used as the delay between terminating commands on the module and flushing - * the serial RX buffer. This is needed because after terminating commands on the module, the module will - * returns a response. These responses are invalid at this point and should be flushed from the serial RX buffer. - * - * @param[in] delayMs Optional, if not specificed this only flushes the serial RX buffer. - */ - void flush(int delayMs = 500); - - /** - * @ingroup api_core_misc - * - * @brief Return current version of WiConnect WiFi module. - * @param[in] versionBuffer Optional, Buffer to hold received version string - * @param[in] versionBufferSize Optional, required if versionBuffer specified. - * @param[in] completeCallback Optional, callback when version is received. arg1 of callback contains version buffer pointer. - * - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult getVersion(char *versionBuffer = NULL, int versionBufferSize = 0, const Callback &completeCallback = Callback()); - - - /** - * @ingroup api_core_misc - * - * @brief Update the wifi module's internal firmware. - * @param[in] forced Optional, If true, force update of all firmware files to latest version, else only update out-dated files. - * @param[in] versionStr Optional, If specified, update to specific firmware version, else update to latest version. - * @param[in] completeCallback Optional, callback when update is complete. 'result' callback argument contains result of update. - * - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult updateFirmware(bool forced = false, const char *versionStr = NULL, const Callback &completeCallback = Callback()); - - - // ------------------------------------------------------------------------ - - - /** - * @ingroup api_core_send_command - * - * @brief Send command to WiConnect WiFi module - * - * @note Refer to @ref send_command_desc for more info - * - * @param[in] completeCallback Callback when command completes. arg1 of callback contains responseBuffer pointer, arg2 contains the response length - * @param[in] responseBuffer Buffer to hold command response - * @param[in] responseBufferLen Length of responseBuffer - * @param[in] timeoutMs Maximum time in milliseconds this command should execute - * @param[in] reader Callback for reading data to be read from host and send to module during command - * @param[in] user User data struct used during read Callback. Library doesn't use this. Set NULL if not used. - * @param[in] cmd WiConnect command to send to module - * @param[in] vaList Varaible list of arguments - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult sendCommand(const Callback &completeCallback, char *responseBuffer, int responseBufferLen, - int timeoutMs, const ReaderFunc &reader, void *user, const char *cmd, va_list vaList); - /** - * @ingroup api_core_send_command - * - * @brief Send command to WiConnect WiFi module - * - * @note Refer to @ref send_command_desc for more info - * - * @param[in] responseBuffer Buffer to hold command response - * @param[in] responseBufferLen Length of responseBuffer - * @param[in] timeoutMs Maximum time in milliseconds this command should execute - * @param[in] reader Callback for reading data to be read from host and send to module during command - * @param[in] user User data struct used during read Callback. Library doesn't use this. Set NULL if not used. - * @param[in] cmd WiConnect command to send to module - * @param[in] vaList Varaible list of arguments - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult sendCommand(char *responseBuffer, int responseBufferLen, int timeoutMs, const ReaderFunc &reader, - void *user, const char *cmd, va_list vaList); - - /** - * @ingroup api_core_send_command - * - * @brief Send command to WiConnect WiFi module - * - * @note Refer to @ref send_command_desc for more info - * @note This method supports variable arguments - * - * @param[in] responseBuffer Buffer to hold command response - * @param[in] responseBufferLen Length of responseBuffer - * @param[in] timeoutMs Maximum time in milliseconds this command should execute - * @param[in] reader Callback for reading data to be read from host and send to module during command - * @param[in] user User data struct used during read Callback. Library doesn't use this. Set NULL if not used. - * @param[in] cmd WiConnect command to send to module - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult sendCommand(char *responseBuffer, int responseBufferLen, int timeoutMs, const ReaderFunc &reader, - void *user, const char *cmd, ...); - - /** - * @ingroup api_core_send_command - * - * @brief Send command to WiConnect WiFi module - * - * This method uses the library internal buffer. - * - * @note Refer to @ref send_command_desc for more info - * @note This method supports variable arguments - * - * @param[in] timeoutMs Maximum time in milliseconds this command should execute - * @param[in] reader Callback for reading data to be read from host and send to module during command - * @param[in] user User data struct used during read Callback. Library doesn't use this. Set NULL if not used. - * @param[in] cmd WiConnect command to send to module - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult sendCommand( int timeoutMs, const ReaderFunc &reader, void *user, const char *cmd, ...); - - /** - * @ingroup api_core_send_command - * - * @brief Send command to WiConnect WiFi module - * - * - This method uses the library internal buffer and - * - default timeout. See setCommandDefaultTimeout() - * - * @note Refer to @ref send_command_desc for more info - * @note This method supports variable arguments - * - * @param[in] reader Callback for reading data to be read from host and send to module during command - * @param[in] user User data struct used during read Callback. Library doesn't use this. Set NULL if not used. - * @param[in] cmd WiConnect command to send to module - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult sendCommand(const ReaderFunc &reader, void *user, const char *cmd, ...); - - /** - * @ingroup api_core_send_command - * - * @brief Send command to WiConnect WiFi module - * - * @note Refer to @ref send_command_desc for more info - * @note This method supports variable arguments - * - * @param[in] responseBuffer Buffer to hold command response - * @param[in] responseBufferLen Length of responseBuffer - * @param[in] timeoutMs Maximum time in milliseconds this command should execute - * @param[in] cmd WiConnect command to send to module - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult sendCommand(char *responseBuffer, int responseBufferLen, int timeoutMs, const char *cmd, ...); - - /** - * @ingroup api_core_send_command - * - * @brief Send command to WiConnect WiFi module - * - * @note Refer to @ref send_command_desc for more info - * @note This method supports variable arguments - * - * @param[in] completeCallback Callback when command completes. arg1 of callback contains responseBuffer pointer, arg2 contains the response length - * @param[in] responseBuffer Buffer to hold command response - * @param[in] responseBufferLen Length of responseBuffer - * @param[in] cmd WiConnect command to send to module - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult sendCommand(const Callback &completeCallback, char *responseBuffer, int responseBufferLen, const char *cmd, ...); - - /** - * @ingroup api_core_send_command - * - * @brief Send command to WiConnect WiFi module - * - * @note Refer to @ref send_command_desc for more info - * @note This method supports variable arguments - * - * @param[in] responseBuffer Buffer to hold command response - * @param[in] responseBufferLen Length of responseBuffer - * @param[in] cmd WiConnect command to send to module - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult sendCommand(char *responseBuffer, int responseBufferLen, const char *cmd, ...); - - /** - * @ingroup api_core_send_command - * - * @brief Send command to WiConnect WiFi module - * - * - This method uses the library internal buffer and - * - default timeout. See setCommandDefaultTimeout() - * - * @note Refer to @ref send_command_desc for more info - * @note This method supports variable arguments - * - * @param[in] completeCallback Callback when command completes. arg1 of callback contains responseBuffer pointer, arg2 contains the response length - * @param[in] cmd WiConnect command to send to module - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult sendCommand(const Callback &completeCallback, const char *cmd, ...); - - /** - * @ingroup api_core_send_command - * - * @brief Send command to WiConnect WiFi module - * - * - This method uses the library internal buffer and - * - default timeout. See setCommandDefaultTimeout() - * - * @note Refer to @ref send_command_desc for more info - * @note This method supports variable arguments - * - * @param[in] cmd WiConnect command to send to module - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult sendCommand(const char *cmd, ...); - - /** - * @ingroup api_core_send_command - * - * This method uses the library internal buffer - * - * @note Refer to @ref send_command_desc for more info - * @note This method supports variable arguments - * - * @param[in] completeCallback Callback when command completes. arg1 of callback contains responseBuffer pointer, arg2 contains the response length - * @param[in] timeoutMs Maximum time in milliseconds this command should execute - * @param[in] cmd WiConnect command to send to module - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult sendCommand(const Callback &completeCallback, int timeoutMs, const char *cmd, ...); - - /** - * @ingroup api_core_send_command - * - * @brief Send command to WiConnect WiFi module - * - * This method uses the library internal buffer - * - * @note Refer to @ref send_command_desc for more info - * @note This method supports variable arguments - * - * @param[in] timeoutMs Maximum time in milliseconds this command should execute - * @param[in] cmd WiConnect command to send to module - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult sendCommand(int timeoutMs, const char *cmd, ...); - - /** - * @ingroup api_core_send_command - * - * - This method uses the library internal buffer and - * - default timeout. See setCommandDefaultTimeout() - * - * @note Refer to @ref send_command_desc for more info - * - * @param[in] cmd WiConnect command to send to module - * @param[in] vaList Varaible list of arguments - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult sendCommand(const char *cmd, va_list vaList); - - /** - * @ingroup api_core_send_command - * - * @brief Check the status of the currently executing command. - * - * Refer to @ref WiconnectResult for more information about the return code. - * - * @note This command is only applicable for non-blocking mode. Refer to @ref setting_blocking_modes. - * - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult checkCurrentCommand(); - - /** - * @ingroup api_core_send_command - * - * @brief Stop the currently executing command. - * - * @note This command is only applicable for non-blocking mode. Refer to @ref setting_blocking_modes. - */ - void stopCurrentCommand(); - - - // ------------------------------------------------------------------------ - - - /** - * @ingroup api_core_misc - * - * @brief When the WiConnect WiFi module returns a response, it contains a - * response code in the header. This function converts the previous response code - * to a readable string. - * - * @return string representation of module response code - */ - const char* getLastCommandResponseCodeStr(); - - /** - * @ingroup api_core_misc - * - * @brief Return the length in bytes of the previous response. - * - * @return length of previous response - */ - uint16_t getLastCommandResponseLength(); - - /** - * @ingroup api_core_misc - * - * @brief Return pointer to internal response buffer. - * - * @return pointer to internal response buffer - */ - char* getResponseBuffer(); - - /** - * @ingroup api_core_misc - * - * @brief Helper method to convert previous response to uint32 - * - * @note This uses the internal response buffer. - * - * @param[out] uint32Ptr Pointer to hold result of conversion. - * @return Result of conversion. See @ref WiconnectResult - */ - WiconnectResult responseToUint32(uint32_t *uint32Ptr); - - /** - * @ingroup api_core_misc - * - * @brief Helper method to convert previous response to int32 - * - * @note This uses the internal response buffer. - * - * @param[out] int32Ptr Pointer to hold result of conversion. - * @return Result of conversion. See @ref WiconnectResult - */ - WiconnectResult responseToInt32(int32_t *int32Ptr); - - - // ------------------------------------------------------------------------ - - /** - * @ingroup api_core_settings - * - * @brief Set a module setting - * - * Refer to: http://wiconnect.ack.me/2.0/variables - * for a list of the available settings and descriptions - * - * @param settingStr String module setting name. - * @param value The integer value to set - * - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult setSetting(const char *settingStr, uint32_t value); - - /** - * @ingroup api_core_settings - * - * @brief Set a module setting - * - * Refer to: http://wiconnect.ack.me/2.0/variables - * for a list of the available settings and descriptions - * - * @param settingStr String module setting name. - * @param value The string value to set - * - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult setSetting(const char *settingStr, const char *value); - - /** - * @ingroup api_core_settings - * - * @brief Get a module setting - * - * Refer to: http://wiconnect.ack.me/2.0/variables - * for a list of the available settings and descriptions - * - * @param settingStr String module setting name. - * @param valuePtr Pointer to buffer to contain integer value - * - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult getSetting(const char *settingStr, uint32_t *valuePtr); - - /** - * @ingroup api_core_settings - * - * @brief Get a module setting - * - * Refer to: http://wiconnect.ack.me/2.0/variables - * for a list of the available settings and descriptions - * - * @param settingStr String module setting name. - * @param valuePtr Pointer to hold pointer to internal API buffer containing retrieved setting result - * - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult getSetting(const char *settingStr, char **valuePtr); - - /** - * @ingroup api_core_settings - * - * @brief Get a module setting - * - * Refer to: http://wiconnect.ack.me/2.0/variables - * for a list of the available settings and descriptions - * - * @param settingStr String module setting name. - * @param valueBuffer Buffer to hold retrieved setting result - * @param valueBufferLen The length of the input buffer - * - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult getSetting(const char *settingStr, char *valueBuffer, uint16_t valueBufferLen); - - - /** - * @ingroup api_core_settings - * - * @brief Sets the default maximum time an API method may execute before - * terminating and return a timeout error code. - * - * @note All API methods (execpt some sendCommand()) use this default value. - * - * @param[in] timeoutMs Default command timeout in milliseconds - */ - void setCommandDefaultTimeout(int timeoutMs); - - /** - * @ingroup api_core_settings - * - * @brief Returns the current default maximum API execution time. - * - * @return Default command timeout in milliseconds - */ - int getCommandDefaultTimeout(); - - /** - * @ingroup api_core_settings - * - * @brief Sets a mapping function used to convert from a host Pin to WiConnect WiFi module GPIO. - * - * @param[in] mapper Pin to GPIO mapper function pointer - */ - void setPinToGpioMapper(PinToGpioMapper mapper); - - /** - * @ingroup api_core_settings - * - * @brief Sets callback function used to debug WiConnect WiFi module RX/TX serial data. - * - * @param[in] logFunc Logging function pointer - */ - void setDebugLogger(LogFunc logFunc); - - /** - * @ingroup api_core_settings - * - * @brief Sets callback used when Wiconnect Library hits and internal assertion. - * - * @note This is mainly for debugging. There's nothing the callback can do to fix the assertion. - * - * @param[in] assertLogFunc Logging function pointer - */ - void setAssertLogger(LogFunc assertLogFunc); - - - // ------------------------------------------------------------------------ - - -#ifdef WICONNECT_ASYNC_TIMER_ENABLED - /** - * @ingroup api_core_send_command - * - * @brief Add user command to be executed asynchronously. - * - * Refer to @ref setting_async_processing for more info. - * - * @param[in] command Pointer to QueuedCommand to be executed asynchronously - * @param[in] commandCompleteHandler Callback to be executed when processing is complete. - * @return Result of method. See @ref WiconnectResult - */ - WiconnectResult enqueueCommand(QueuedCommand *command, const Callback &commandCompleteHandler = Callback()); - - /** - * @ingroup api_core_settings - * - * @brief Set the period at which an asynchronous command should be processed. - * - * Refer to @ref setting_async_processing for more info. - * - * @param[in] periodMs Processing period in milliseconds - */ - void setCommandProcessingPeriod(uint32_t periodMs); -#endif - - - /** - * @ingroup conversion_util - * - * @brief Converts a @ref WiconnectResult to string representation. - * - * @param[in] wiconnectResult Result code - * @return String representaion of result code - */ - static const char* getWiconnectResultStr(WiconnectResult wiconnectResult); - -protected: - -#ifdef WICONNECT_ENABLE_MALLOC - void* (*_malloc)(size_t); - void (*_free)(void *); - friend class QueuedCommand; - friend class WiconnectSerial; - friend class ScanResult; - friend class ScanResultList; - friend class WiconnectSocket; - friend class WiconnectFile; -#endif - - wiconnect::WiconnectSerial serial; - wiconnect::Gpio resetGpio; - wiconnect::Gpio wakeGpio; - - volatile bool commandExecuting; - bool initialized; - bool nonBlocking; - - PinToGpioMapper pinToGpioMapper; - - char *internalBuffer; - int internalBufferSize; - bool internalBufferAlloc; - uint8_t internalProcessingState; - void *currentCommandId; - - wiconnect::TimeoutTimer timeoutTimer; - int defaultTimeoutMs; - - uint8_t commandHeaderBuffer[32]; - char commandFormatBuffer[WICONNECT_MAX_CMD_SIZE]; - uint8_t commandContext[96]; - - void prepare(void *internalBuffer, int internalBufferSize, bool nonBlocking); - WiconnectResult inline receiveResponse(); - WiconnectResult inline receivePacket(); - void issueCommandCallback(WiconnectResult result); - - LogFunc debugLogger; - LogFunc assertLogger; - void debugLog(const char *msg, ...); - -#ifdef WICONNECT_ASYNC_TIMER_ENABLED - wiconnect::PeriodicTimer commandProcessorTimer; - uint32_t commandProcessingPeriod; - CommandQueue commandQueue; - wiconnect::QueuedCommand *currentQueuedCommand; - - void commandProcessingTimerHandler(void); - void processNextQueuedCommand(); - void checkQueuedCommandTimeout(); -#endif - - friend class NetworkInterface; - friend class SocketInterface; - friend class FileInterface; -}; - -} - - -#include "sdkTypes.h" -
--- a/WiconnectTypes.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,433 +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 <stdint.h> -#include <stdarg.h> -#include <cstddef> - -#include "sdk.h" - -/** - * @namespace wiconnect - * - * @brief The entire Wiconnect Library is contained within the 'wiconnect' namespace - */ -namespace wiconnect { - - -#ifndef MIN -/** - * @ingroup api_core_macro - * @def MIN(x,y) - * @brief Computes the minimum of \a x and \a y. - */ -#define MIN(x,y) ((x) < (y) ? (x) : (y)) -#endif -#ifndef MAX -/** - * @ingroup api_core_macro - * @def MAX(x,y) - * @brief Computes the maximum of \a x and \a y. - */ -#define MAX(x,y) ((x) > (y) ? (x) : (y)) -#endif -/** - * @ingroup api_core_macro - * @def ALIGN_n(x, n) - * @brief Align \a x to \a n bytes (\a n must be power of 2) - */ -#define ALIGN_n(x, n) ((((uint32_t)x) + ((n)-1)) & ~((n)-1)) -/** - * @ingroup api_core_macro - * @def ALIGN_8(x) - * @brief Align \a x to 8 bytes - */ -#define ALIGN_8(x) ALIGN_n(x, 8) -/** - * @ingroup api_core_macro - * @def ALIGN_4(x) - * @brief Align \a x to 4 bytes - */ -#define ALIGN_4(x) ALIGN_n(x, 4) -/** - * @ingroup api_core_macro - * @def ARRAY_COUNT(x) - * @brief Return number of elements in static array \a x - */ -#define ARRAY_COUNT(x) (sizeof (x) / sizeof *(x)) - - -/** - * @ingroup api_core_macro - * @def WICONNECT_FAILED(result, func) - * @brief Populates \a result with return value from \a func, returns TRUE if return value contains error. - */ -#define WICONNECT_FAILED(result, func) ((int)(result = (func)) < (int)wiconnect::WICONNECT_SUCCESS) - -/** - * @ingroup api_core_macro - * @def WICONNECT_SUCCEEDED(result, func) - * @brief Populates \a result with return value from \a func, returns TRUE if return value is WICONNECT_SUCCESS. - */ -#define WICONNECT_SUCCEEDED(result, func) ((result = (func)) == wiconnect::WICONNECT_SUCCESS) - - -/** - * @ingroup api_core_macro - * @brief The maximum command size that may be sent to the WiConnect WiFi module - */ -#define WICONNECT_MAX_CMD_SIZE 128 -/** - * @ingroup api_core_macro - * @brief The maximum WiConnect WiFi module version string size - */ -#define WICONNECT_MAX_VERSION_SIZE 96 -/** - * @ingroup api_core_macro - * @brief The maximum number of simulanteous opened sockets - */ -#define WICONNECT_MAX_SOCKETS 8 -/** - * @ingroup api_core_macro - * @brief The maximum server string length - */ -#define WICONNECT_MAX_HOST_SIZE 64 -/** - * @ingroup api_core_macro - * @brief The maximum Wiconnect Module flash filesystem filename length - */ -#define WICONNECT_MAX_FILENAME_SIZE 96 -/** - * @ingroup api_core_macro - * @brief Never timeout - */ -#define WICONNECT_WAIT_FOREVER 0xFFFFFFFF -/** - * @ingroup api_core_macro - * @brief Timeout immediately - */ -#define WICONNECT_NO_WAIT 0 -/** - * @ingroup api_core_macro - * @brief Default firmware update timeout in ms - */ -#define WICONNECT_FIRMWARE_UPDATE_TIMEOUT 90000 - -/** - * @ingroup api_socket_macro - * @brief Default which indicates to use the most optimal port - */ -#define SOCKET_ANY_PORT (uint16_t)0 -/** - * @ingroup api_socket_macro - * @brief Default which indicates to use the most optimal port - */ -#define SOCKET_INVALID_HANDLE ((uint8_t)0xFF) - - -/** - * @ingroup api_core_types - * @brief API Result code - */ -typedef enum -{ - // Status Codes - WICONNECT_ABORTED = 3, ///< Command was aborted - WICONNECT_IDLE = 2, ///< Library not processing any commands - WICONNECT_PROCESSING = 1, ///< Library processing current command - WICONNECT_SUCCESS = 0, ///< Command successfully completed - - // Error codes - WICONNECT_ERROR = -1, ///< Generic error - WICONNECT_CMD_RESPONSE_ERROR = -2, ///< Module returned error code - WICONNECT_NULL_BUFFER = -3, ///< Null buffer supplied - WICONNECT_NOT_INITIALIZED = -4, ///< Library not initialed - WICONNECT_OVERFLOW = -5, ///< Buffer overflowed - WICONNECT_TIMEOUT = -6, ///< Command timed out -// WICONNECT_RESPONSE_HANDLER_NULL = -7, ///< - WICONNECT_RESPONSE_PARSE_ERROR = -8, ///< Failed to parse module response - WICONNECT_ANOTHER_CMD_EXECUTING = -9, ///< Currently executing another command - WICONNECT_BAD_ARG = -10, ///< Bad argument supplied - WICONNECT_UNSUPPORTED = -11, ///< Command / parameter not supported - WICONNECT_PINNAME_TO_GPIO_MAPPER_NULL = -12, ///< The pinToGpioMapper hasn't been set - WICONNECT_DUPLICATE = -13, ///< Duplicate value - WICONNECT_NOT_FOUND = -14, ///< Not found - WICONNECT_PINNAME_TO_GPIO_NO_MAPPING = -15, ///< No mapping found for given pin - WICONNECT_NOT_CONNECTED = -16, ///< Not connected - WICONNECT_UNDERFLOW = -17, ///< Data underflow - WICONNECT_MONITOR_NOT_AVAILABLE = -18, ///< Background processing monitor is not available (i.e in use) - WICONNECT_NOT_OPENED_FOR_READING = -19, ///< The file is not open for reading -} WiconnectResult; - - - -/** - * @ingroup types_core - * @brief File type type - */ -typedef enum -{ - SETTING_WLAN_CHANNEL_MASK, ///< Mask of channels that are scan when joining a network -} WiconnectSetting; - - -/** - * @ingroup types_core - * @brief Function pointer for mapping from a host pin to a WiConnect Module GPIO. - * - * @param[in] pin A host pin - * @return The corresponding WiConnect Module GPIO (which the given pin is physically connected). - * Return -1 if no mapping is available. - */ -typedef int8_t (*PinToGpioMapper)(Pin pin); - -/** - * @brief Generic buffer type - * - * @note Internal use only - */ -typedef struct -{ - int size; - uint8_t *buffer; - uint8_t *ptr; - int bytesPending; - bool allocated; -} Buffer; - - -// ---------------------------------------------------------------------------- - - - -/** - * @ingroup api_network_types - * @brief Network connection status - */ -typedef enum -{ - NETWORK_STATUS_DOWN, ///< Not connected to network - NETWORK_STATUS_WIFI_ONLY, ///< Connected to network but don't have IP address - NETWORK_STATUS_UP, ///< Conntected to network and have IP address - NETWORK_STATUS_JOINING ///< Joining a network -} NetworkStatus; - -/** - * @ingroup api_network_types - * @brief Network connection status - */ -typedef enum -{ - NETWORK_JOIN_RESULT_NONE, ///< Haven't attempted to join - NETWORK_JOIN_RESULT_SUCCESS, ///< Successfully joined the network - NETWORK_JOIN_RESULT_JOINING, ///< Currently attempting to join - NETWORK_JOIN_RESULT_NO_SSID, ///< The SSID has not be configured - NETWORK_JOIN_RESULT_NO_PASSWORD, ///< The network requires a password and none has been set - NETWORK_JOIN_RESULT_BAD_SECURITY, ///< The specified security type is not supported by the network - NETWORK_JOIN_RESULT_NOT_FOUND, ///< The network with the configured SSID was not found - NETWORK_JOIN_RESULT_FAILED, ///< Failed to join the network - NETWORK_JOIN_RESULT_ABORTED, ///< Joining was aborted (via command) -} NetworkJoinResult; - -/** - * @ingroup api_network_types - * @brief Network RSSI signal level - */ -typedef enum -{ - NETWORK_RSSI_EXCELLENT = 0, ///< \> -20 dBm - NETWORK_RSSI_VERY_GOOD = 1, ///< \> -35 dBm - NETWORK_RSSI_GOOD = 2, ///< \> -50 dBm - NETWORK_RSSI_POOR = 3, ///< \> -70 dBm - NETWORK_RSSI_VERY_POOR = 4, ///< < -71 dBm - NETWORK_RSSI_UNKNOWN = 5 ///< Not available -} NetworkSignalStrength; - -/** - * @ingroup api_network_types - * @brief Network security type - */ -typedef enum -{ - NETWORK_SECURITY_OPEN, - NETWORK_SECURITY_WEP_PSK, - NETWORK_SECURITY_WPA_AES_PSK, - NETWORK_SECURITY_WPA_TKIP_PSK, - NETWORK_SECURITY_WPA2_AES_PSK, - NETWORK_SECURITY_WPA2_MIXED_PSK, - NETWORK_SECURITY_WPA2_TKIP_PSK, - NETWORK_SECURITY_UNKNOWN -} NetworkSecurity; - -/** - * @ingroup api_network_types - * @brief Network SSID type - */ -typedef struct -{ - uint8_t val[32]; ///< The raw data of the SSID (not necessarily a string) - uint8_t len; ///< The length in bytes of the SSID raw data -} Ssid; - -/** - * @ingroup api_network_types - * @brief Network MAC Address type - */ -typedef struct -{ - uint8_t octet[6]; -} MacAddress; - -/** - * @ingroup api_network_types - * @brief Buffer to hold a MAC address string - */ -typedef char MacAddressStrBuffer[18]; - -/** - * @ingroup api_network_types - * @brief Buffer to hold a SSID string - */ -typedef char SsidStrBuffer[129]; - -/** - * @ingroup api_network_types - * @brief Buffer to hold an IP address string - */ -typedef char IpStrBuffer[18]; - - -// ---------------------------------------------------------------------------- - - -/** - * @ingroup api_socket_types - * @brief Socket type - */ -typedef enum -{ - SOCKET_TYPE_UNKNOWN, ///< Socket type not known - SOCKET_TYPE_TCP, ///< TCP Socket type - SOCKET_TYPE_TLS, ///< TLS Socket type - SOCKET_TYPE_UDP, ///< UDP Socket type - SOCKET_TYPE_HTTP, ///< HTTP Socket type -} SocketType; - -/** - * @ingroup api_socket_types - * @brief HTTP Socket sub-type - */ -typedef enum -{ - SOCKET_HTTP_GET, ///< HTTP GET Request socket type - SOCKET_HTTP_POST, ///< HTTP POST Request socket type - SOCKET_HTTP_HEAD, ///< HTTP HEAD Request socket type -} HttpSocketType; - -/** - * @ingroup api_socket_types - * @brief Struct for hold HTTP socket configuration - */ -typedef struct -{ - const char *contextType; ///< A POST Request 'context-type' value - const char *certName; ///< TLS certificate filename on module flash file system - bool openOnly; ///< Only open the connection, don't issue the request yet - HttpSocketType type; ///< The type of HTTP connection -} HttpSocketArgs; - - -// ---------------------------------------------------------------------------- - - -/** - * @ingroup api_file_types - * @brief File flags type - */ -typedef enum -{ - FILE_FLAG_NONE = 0, ///< No flags - - FILE_FLAG_VALID = (1 << 0), ///< File valid - FILE_FLAG_EXECUTABLE = (1 << 1), ///< File executable - FILE_FLAG_ENCRYPTED = (1 << 2), ///< File encrypted - FILE_FLAG_INTERNAL = (1 << 3), ///< File on internal module flash - FILE_FLAG_BOOTABLE = (1 << 4), ///< File bootable - FILE_FLAG_USER = (1 << 5), ///< File created by user - FILE_FLAG_ESSENTIAL = (1 << 6), ///< File is essential - - FILE_FLAG_INVALID = 0xFFFF ///< File flags invalid -} FileFlags; - -/** - * @ingroup api_file_types - * @brief File type type - */ -typedef enum -{ - FILE_TYPE_UPGRADE_APP = 0x00, ///< Internal upgrade application - FILE_TYPE_WIFI_FW = 0x01, ///< Wifi firmware binary - - FILE_TYPE_REGULAR_APP = 0x81, ///< Regular application - - FILE_TYPE_USER_RANGE_START = 150, ///< User type start index - FILE_TYPE_USER_RANGE_END = 199, ///< User type end index - - FILE_TYPE_TEMPORY = 0xF9, ///< Temporary file - FILE_TYPE_GPIO_CONFIG = 0xFA, ///< GPIO configuration file - FILE_TYPE_COMMAND_HELP = 0xFB, ///< WiConnect command help file - FILE_TYPE_SDC_CAPS = 0xFC, ///< SDC / goHACK.me file - FILE_TYPE_SETUP_SCRIPT = 0xFD, ///< Setup script file - FILE_TYPE_MISC_FIX_LEN = 0xFE, ///< Miscellaneous fixed length file - FILE_TYPE_UNKNOWN = 0xFF, ///< Unknown file type - FILE_TYPE_ANY = FILE_TYPE_UNKNOWN -} FileType; - - -// Forward declarations - -class Wiconnect; -class TimeoutTimer; -class PeriodicTimer; -class QueuedCommand; -class CommandQueue; -class LogFunc; -class ReaderFunc; -class Callback; -class ScanResult; -class ScanResultList; -class WiconnectSocket; -class WiconnectSerial; -class WiconnectFile; -class FileList; -class Gpio; -class SocketIrqHandlerMap; - -}
--- a/internal/WiconnectCommands.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +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 - - - - -#define CMD_SAVE "save" -#define CMD_GET_VERSION "ver" - - -#define CMD_SET_SYSTEM_COMMAND_MODE "set system.cmd.mode %s" -#define CMD_SET_NETWORK_DHCP "set network.dhcp.enabled %d" -#define CMD_SET_STATIC_IP "set static.ip %d.%d.%d.%d" -#define CMD_SET_STATIC_GATEWAY "set static.netmask %d.%d.%d.%d" -#define CMD_SET_STATIC_NETMASK "set static.gatewat %d.%d.%d.%d" - - -#define CMD_GET_NETWORK_STATUS "get network.status" -
--- a/internal/common.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +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. - */ -#ifndef _COMMON_H_ -#define _COMMON_H_ - - -#include "WiconnectCommands.h" - - - -/* Note we need the 2 concats below because arguments to ## - * are not expanded, so we need to expand __LINE__ with one indirection - * before doing the actual concatenation. */ -#define ASSERT_CONCAT_(a, b) a ## b -#define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b) -#define ct_assert(e) enum { ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(e)) } - -#define wiconnect_assert(_wiconnect, msg, expr) if(!(expr)){_wiconnect->assertLogger.call(msg); for(;;); } - - - -#ifndef WICONNECT_ASYNC_TIMER_ENABLED -#define CHECK_CALLBACK_AVAILABLE(cb) if(cb.isValid()) return WICONNECT_UNSUPPORTED -#else -#define CHECK_CALLBACK_AVAILABLE(cb) -#endif - -#define UNUSED(expr) do { (void)(expr); } while (0) - -#define CHECK_CLEANUP_COMMAND() \ - if(result != WICONNECT_PROCESSING) \ - { \ - wiconnect->internalProcessingState = 0; \ - wiconnect->currentCommandId = NULL; \ - } - -#define CHECK_OTHER_COMMAND_EXECUTING() \ -{ \ - static const volatile uint8_t __funcId = 0; \ - if(wiconnect->currentCommandId == NULL) \ - { \ - wiconnect->currentCommandId = (void*)&__funcId; \ - } \ - else if(wiconnect->currentCommandId != (void*)&__funcId) \ - { \ - return WICONNECT_ANOTHER_CMD_EXECUTING; \ - } \ -} - -#define _CHECK_CLEANUP_COMMAND() \ - if(result != WICONNECT_PROCESSING) \ - { \ - internalProcessingState = 0; \ - currentCommandId = NULL; \ - } - -#define _CHECK_OTHER_COMMAND_EXECUTING() \ -{ \ - static const volatile uint8_t __funcId = 0; \ - if(currentCommandId == NULL) \ - { \ - currentCommandId = (void*)&__funcId; \ - } \ - else if(currentCommandId != (void*)&__funcId) \ - { \ - return WICONNECT_ANOTHER_CMD_EXECUTING; \ - } \ -} - -#define WICONNECT_IS_IDLE() (wiconnect->currentCommandId == NULL) -#define _WICONNECT_IS_IDLE() (currentCommandId == NULL) - - - -#ifdef WICONNECT_USE_DEFAULT_STRING_BUFFERS -#define SET_STR_BUFFER(_buffer, size) \ - char *ptr; \ - static char defaultBuffer[size]; \ - ptr = (_buffer == NULL) ? defaultBuffer : _buffer; -#else -#define SET_STR_BUFFER(_buffer, size) \ - char *ptr; \ - if(_buffer == NULL) \ - { \ - return "<null>"; \ - } \ - ptr = _buffer; -#endif - - -#endif
--- a/internal/file/FileInterface.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,226 +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" -#include "StringUtil.h" - - -/*************************************************************************************************/ -FileInterface::FileInterface(Wiconnect *wiconnect_) -{ - wiconnect = wiconnect_; -} - -/*************************************************************************************************/ -WiconnectResult FileInterface::openFile(WiconnectFile &file, const char *name) -{ - WiconnectResult result; - - CHECK_OTHER_COMMAND_EXECUTING(); - - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("fop %s", name))) - { - int32_t handle; - if(!WICONNECT_FAILED(result, wiconnect->responseToInt32(&handle))) - { - file.openForRead(handle, name); - } - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult FileInterface::createFile(const ReaderFunc &reader, void *user, const char *name, uint32_t size, uint32_t version, FileType type, bool isEssential, int32_t checksum) -{ - WiconnectResult result; - char cmdBuffer[WICONNECT_MAX_CMD_SIZE]; - - if(WICONNECT_IS_IDLE()) - { - char *ptr = cmdBuffer; - - ptr += sprintf(cmdBuffer, "fcr %s%s %d", isEssential ? "-e " : "", name, size); - - if(version != 0) - { - *ptr = ' '; - ++ptr; - FileInterface::fileVersionIntToStr(version, true, ptr); - ptr = ptr + strlen(ptr); - } - if(type != FILE_TYPE_ANY) - { - ptr += sprintf(ptr, " %X", type); - } - if(checksum != -1) - { - ptr += sprintf(ptr, " %X", checksum); - } - } - - CHECK_OTHER_COMMAND_EXECUTING(); - - result = wiconnect->sendCommand(reader, user, (const char *)cmdBuffer); - - CHECK_CLEANUP_COMMAND(); - - return result; -} - - -/*************************************************************************************************/ -WiconnectResult FileInterface::deleteFile(const char *name) -{ - WiconnectResult result; - - CHECK_OTHER_COMMAND_EXECUTING(); - - result = wiconnect->sendCommand("fde %s", name); - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult FileInterface::deleteFile(const WiconnectFile &file) -{ - return deleteFile(file.getName()); -} - - -/*************************************************************************************************/ -const char* FileInterface::fileVersionIntToStr(uint32_t version, bool verbose, char *buffer) -{ - SET_STR_BUFFER(buffer, 32); - const char *fmt = verbose ? "%u.%u.%u.%u" : "%u.%u.%u"; - sprintf(ptr, fmt, FILE_VERSION_ARGS(version)); - return ptr; -} - -/*************************************************************************************************/ -bool FileInterface::fileVersionStrToInt(const char *versionStr, uint32_t *versionIntPtr) -{ - const uint8_t offsets[] = {27, 21, 8, 0}; - char buffer[18]; - char *tok, *ptr = buffer; - uint32_t version = 0; - - strcpy(buffer, versionStr); - - for(int i = 0; i < 4 && (tok = strtok(ptr, ".")) != NULL; ++i) - { - char *end; - const uint32_t value = strtol(tok, &end, 10); - if(*end != 0) - { - return false; - } - version |= (value << offsets[i]); - ptr = NULL; - } - - *versionIntPtr = version; - - return true; -} - -/*************************************************************************************************/ -const char* FileInterface::fileTypeToStr(FileType type) -{ - switch(type) - { - case FILE_TYPE_UPGRADE_APP: - return "Upgrade App"; - case FILE_TYPE_WIFI_FW: - return "Wifi Firmware"; - case FILE_TYPE_REGULAR_APP: - return "Regular App"; - case FILE_TYPE_TEMPORY: - return "Temporary"; - case FILE_TYPE_GPIO_CONFIG: - return "GPIO Default Configuration"; - case FILE_TYPE_COMMAND_HELP: - return "Command Help"; - case FILE_TYPE_SDC_CAPS: - return "goHACK.me Capabilities"; - case FILE_TYPE_SETUP_SCRIPT: - return "Setup Script"; - case FILE_TYPE_MISC_FIX_LEN: - return "Miscellaneous"; - default: - if(type >= FILE_TYPE_USER_RANGE_START && type <= FILE_TYPE_USER_RANGE_END) - return "User"; - else - return "Unknown"; - } -} - -/*************************************************************************************************/ -const char* FileInterface::fileFlagsToStr(FileFlags flags, char *buffer) -{ - SET_STR_BUFFER(buffer, 64); - char *buf = ptr; - - static const char* const flag_strings[] = { - "Valid", - "Executable", - "Encrypted", - "Internal", - "Bootable", - "User", - "Essential", - }; - - int i = 0; - *ptr = 0; - - for(uint16_t f = flags; f != 0 && i < 7; f >>= 1, ++i) - { - if(f & 0x0001) - { - ptr += sprintf(ptr, "%s,", flag_strings[i]); - } - } - - if(ptr == buffer) - { - strcpy(buffer, "None"); - } - else - { - *(ptr-1) = 0; - } - - return buf; -}
--- a/internal/file/FileList.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,129 +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" -#include "StringUtil.h" - - -static bool nameMatches(const char *needle, const char* haystack); - - - -/*************************************************************************************************/ -WiconnectResult FileInterface::listFiles(FileList &list, const char *name, FileType type, uint32_t version) -{ - WiconnectResult result; - - CHECK_OTHER_COMMAND_EXECUTING(); - - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("ls -v"))) - { - result = processFileList(wiconnect->internalBuffer, list, name, type, version); - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult FileInterface::processFileList(char *responseStr, FileList &list, const char *name, FileType type, uint32_t version) -{ - WiconnectResult result = WICONNECT_SUCCESS; - char *line, *savedLine; - - for(savedLine = responseStr; (line = StringUtil::strtok_r(savedLine, "\r\n", &savedLine)) != NULL;) - { - uint32_t tmp; - char *toks[7], *savedTok; - - if(*line != '#') - { - continue; - } - savedTok = line + 2; - - for(int i = 0; i < 6 && (toks[i] = StringUtil::strtok_r(savedTok, " ", &savedTok)) != NULL; ++i) - { - if(toks[i] == NULL) - { - result = WICONNECT_RESPONSE_PARSE_ERROR; - goto exit; - } - } - - - if(name != NULL && !nameMatches(name, savedTok+1)) - { - continue; - } - else if((type != FILE_TYPE_ANY) && - StringUtil::strHexToUint32((const char*)&toks[1][2], &tmp) && - (type != (FileType)tmp)) - { - continue; - } - else if((version != 0) && - FileInterface::fileVersionStrToInt(toks[5], &tmp) && - (version != tmp)) - { - continue; - } - else if(WICONNECT_FAILED(result, list.add(toks[1], toks[2], toks[4], toks[5], savedTok+1))) - { - goto exit; - } - } - - exit: - return result; -} - - -/*************************************************************************************************/ -static bool nameMatches(const char *needle, const char* haystack) -{ - const int haystackLen = strlen(haystack); - - if(*needle == '*') - { - const int n = strlen(needle + 1); - - if(n > haystackLen) - { - return false; - } - return strcmp(needle+1, &haystack[haystackLen - n]) == 0; - } - else - { - return strcmp(needle, haystack) == 0; - } -}
--- a/internal/network/NetworkInterface.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,564 +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" -#include "StringUtil.h" - - -#define IPV4_FORMAT "%d.%d.%d.%d" -#define IPV4_ARGS(ip) \ - (int)( (ip) & 0xff), \ - (int)(((ip) >> 8) & 0xff), \ - (int)(((ip) >> 16) & 0xff), \ - (int)(((ip) >> 24) & 0xff) - - - -/*************************************************************************************************/ -NetworkInterface::NetworkInterface(Wiconnect *wiconnect_) -{ - wiconnect = wiconnect_; -} - -/*************************************************************************************************/ -WiconnectResult NetworkInterface::ping(const char *domain, uint32_t *timeMsPtr) -{ - WiconnectResult result; - - CHECK_OTHER_COMMAND_EXECUTING(); - - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand(completeHandler, "ping %s", (domain == NULL) ? "-g" : domain)) && - timeMsPtr != NULL) - { - if(sscanf(wiconnect->internalBuffer, "Ping reply in %ums", timeMsPtr) != 1) - { - result = WICONNECT_RESPONSE_PARSE_ERROR; - } - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult NetworkInterface::lookup(const char *domain, uint32_t *ipAddressPtr) -{ - WiconnectResult result; - - CHECK_OTHER_COMMAND_EXECUTING(); - - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("nlo %s", domain))) - { - if(!NetworkInterface::strToIp(wiconnect->internalBuffer, ipAddressPtr)) - { - result = WICONNECT_RESPONSE_PARSE_ERROR; - } - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult NetworkInterface::setDhcpEnabled(bool enabled) -{ - WiconnectResult result; - - CHECK_OTHER_COMMAND_EXECUTING(); - - result = wiconnect->sendCommand(CMD_SET_NETWORK_DHCP, enabled); - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult NetworkInterface::getDhcpEnabled(bool *enabledPtr) -{ - WiconnectResult result; - - CHECK_OTHER_COMMAND_EXECUTING(); - - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("get network.dhcp.enabled"))) - { - int32_t enabled; - if(WICONNECT_SUCCEEDED(result, wiconnect->responseToInt32(&enabled))) - { - *enabledPtr = (bool)enabled; - } - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult NetworkInterface::setIpSettings(uint32_t ip, uint32_t netmask, uint32_t gateway) -{ - WiconnectResult result = WICONNECT_ERROR; - - enum - { - FS_SET_IP, - FS_SET_NETMASK, - FS_SET_GATEWAY - }; - - CHECK_OTHER_COMMAND_EXECUTING(); - - if(wiconnect->internalProcessingState == FS_SET_IP) - { - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand(CMD_SET_STATIC_IP, IPV4_ARGS(ip)))) - { - wiconnect->internalProcessingState = FS_SET_NETMASK; - } - } - - if(wiconnect->internalProcessingState == FS_SET_NETMASK) - { - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand(CMD_SET_STATIC_NETMASK, IPV4_ARGS(netmask)))) - { - wiconnect->internalProcessingState = FS_SET_GATEWAY; - } - } - - if(wiconnect->internalProcessingState == FS_SET_GATEWAY) - { - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand(CMD_SET_STATIC_GATEWAY, IPV4_ARGS(gateway)))) - { - } - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult NetworkInterface::setIpSettings(const char* ipStr, const char* netmaskStr, const char* gatewayStr) -{ - uint32_t ip, nm, gw; - - if( !NetworkInterface::strToIp(ipStr, &ip) || - !NetworkInterface::strToIp(netmaskStr, &nm) || - !NetworkInterface::strToIp(gatewayStr, &gw)) - { - return WICONNECT_ERROR; - } - return setIpSettings(ip, nm, gw); -} - -/*************************************************************************************************/ -WiconnectResult NetworkInterface::getIpSettings(uint32_t *ip, uint32_t *netmask, uint32_t *gateway) -{ - WiconnectResult result = WICONNECT_ERROR; - - enum - { - FS_GET_IP, - FS_GET_NETMASK, - FS_GET_GATEWAY - }; - - CHECK_OTHER_COMMAND_EXECUTING(); - - if(wiconnect->internalProcessingState == FS_GET_IP) - { - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("get network.ip"))) - { - if(!NetworkInterface::strToIp(wiconnect->internalBuffer, ip)) - { - result = WICONNECT_RESPONSE_PARSE_ERROR; - } - else - { - wiconnect->internalProcessingState = FS_GET_NETMASK; - } - } - } - - if(wiconnect->internalProcessingState == FS_GET_NETMASK) - { - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("get network.netmask"))) - { - if(!NetworkInterface::strToIp(wiconnect->internalBuffer, netmask)) - { - result = WICONNECT_RESPONSE_PARSE_ERROR; - } - else - { - wiconnect->internalProcessingState = FS_GET_GATEWAY; - } - } - } - - if(wiconnect->internalProcessingState == FS_GET_GATEWAY) - { - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("get network.gateway"))) - { - if(!NetworkInterface::strToIp(wiconnect->internalBuffer, gateway)) - { - result = WICONNECT_RESPONSE_PARSE_ERROR; - } - } - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} -/*************************************************************************************************/ -WiconnectResult NetworkInterface::getSignalStrength(NetworkSignalStrength *signalStrengthPtr) -{ - WiconnectResult result; - int32_t rssi_dbm; - - CHECK_OTHER_COMMAND_EXECUTING(); - - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("rssi"))) - { - if(!WICONNECT_FAILED(result, wiconnect->responseToInt32(&rssi_dbm))) - { - *signalStrengthPtr = NetworkInterface::rssiToSignalStrength(rssi_dbm); - } - } - - if(result == WICONNECT_CMD_RESPONSE_ERROR) - { - *signalStrengthPtr = NETWORK_RSSI_UNKNOWN; - result = WICONNECT_SUCCESS; - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -const char* NetworkInterface::getIpAddress(char *ipStrBuffer) -{ - SET_STR_BUFFER(ipStrBuffer, 17); - - if(wiconnect->nonBlocking) - { - return "Err"; - } - - if(wiconnect->sendCommand(ptr, 17, "get network.ip") != WICONNECT_SUCCESS) - { - strcpy(ptr, "0.0.0.0"); - } - - return ptr; -} - - -//----------------------------------------------------------------------------------------------- - - -/*************************************************************************************************/ -bool NetworkInterface::strToIp(const char *str, uint32_t *intPtr) -{ - if (!intPtr) - { - return false; - } - int temp[4]; - - if(sscanf(str, "%d.%d.%d.%d", &temp[0], &temp[1], &temp[2], &temp[3] ) != 4) - { - return false; - } - else if(temp[0] > 255 || temp[1] > 255 || temp[2] > 255 || temp[3] > 255) - { - return false; - } - *intPtr = (uint32_t)temp[3] << 24 | temp[2] << 16 | temp[1] << 8 | temp[0]; - - return true; -} - -/*************************************************************************************************/ -const char* NetworkInterface::ipToStr(uint32_t ip, char *ipStrBuffer) -{ - SET_STR_BUFFER(ipStrBuffer, 17); - sprintf(ptr, IPV4_FORMAT, IPV4_ARGS(ip)); - return ptr; -} - -/*************************************************************************************************/ -const char* NetworkInterface::networkStatusToStr(NetworkStatus status) -{ - switch(status) - { - case NETWORK_STATUS_DOWN: - return "Down"; - case NETWORK_STATUS_WIFI_ONLY: - return "WiFi Only"; - case NETWORK_STATUS_UP: - return "Up"; - default: - return "Unknown"; - } -} - -/*************************************************************************************************/ -const char* NetworkInterface::networkJoinResultToStr(NetworkJoinResult joinResult) -{ - switch(joinResult) - { - case NETWORK_JOIN_RESULT_NONE: - return "None"; - case NETWORK_JOIN_RESULT_SUCCESS: - return "Success"; - case NETWORK_JOIN_RESULT_JOINING: - return "Joining"; - case NETWORK_JOIN_RESULT_NO_SSID: - return "No SSID"; - case NETWORK_JOIN_RESULT_NO_PASSWORD: - return "No Password"; - case NETWORK_JOIN_RESULT_BAD_SECURITY: - return "Bad Security Setting"; - case NETWORK_JOIN_RESULT_NOT_FOUND: - return "Network Not Found"; - case NETWORK_JOIN_RESULT_FAILED: - return "Failed"; - case NETWORK_JOIN_RESULT_ABORTED: - return "Aborted"; - default: - return "Unknown"; - } -} - - -/*************************************************************************************************/ -const char* NetworkInterface::signalStrengthToStr(NetworkSignalStrength signalStrenth) -{ - switch(signalStrenth) - { - case NETWORK_RSSI_EXCELLENT: - return "Excellent"; - case NETWORK_RSSI_VERY_GOOD: - return "Very Good"; - case NETWORK_RSSI_GOOD: - return "Good"; - case NETWORK_RSSI_POOR: - return "Poor"; - case NETWORK_RSSI_VERY_POOR: - return "Very Poor"; - case NETWORK_RSSI_UNKNOWN: - default: - return "Unknown"; - } -} - -/*************************************************************************************************/ -NetworkSignalStrength NetworkInterface::rssiToSignalStrength(int rssi_dbm) -{ - if(rssi_dbm > -20) - { - return NETWORK_RSSI_EXCELLENT; - } - else if(rssi_dbm > -35) - { - return NETWORK_RSSI_VERY_GOOD; - } - else if(rssi_dbm > -50) - { - return NETWORK_RSSI_GOOD; - } - else if(rssi_dbm > -70) - { - return NETWORK_RSSI_POOR; - } - else - { - return NETWORK_RSSI_VERY_POOR; - } -} - - -typedef struct -{ - const char* key; - NetworkSecurity value; -} NetworkSecurityTableEntry; - -static const NetworkSecurityTableEntry networkSecurityTable[] = { - {"Auto", NETWORK_SECURITY_UNKNOWN}, - {"Open", NETWORK_SECURITY_OPEN}, - {"Unknown", NETWORK_SECURITY_UNKNOWN}, - {"WEP", NETWORK_SECURITY_WEP_PSK}, - {"WPA-AES", NETWORK_SECURITY_WPA_AES_PSK}, - {"WPA-TKIP", NETWORK_SECURITY_WPA_TKIP_PSK}, - {"WPA2-AES", NETWORK_SECURITY_WPA2_AES_PSK}, - {"WPA2-Mixed", NETWORK_SECURITY_WPA2_MIXED_PSK}, - {"WPA2-TKIP", NETWORK_SECURITY_WPA2_TKIP_PSK}, -}; - - -/*************************************************************************************************/ -NetworkSecurity NetworkInterface::strToNetworkSecurity(const char *str) -{ - const NetworkSecurityTableEntry *end = &networkSecurityTable[ARRAY_COUNT(networkSecurityTable)]; - - for(const NetworkSecurityTableEntry *e = networkSecurityTable; e < end; ++e) - { - if(StringUtil::strcasecmp(e->key, str) == 0) - { - return e->value; - } - } - return NETWORK_SECURITY_UNKNOWN; -} - -/*************************************************************************************************/ -const char* NetworkInterface::networkSecurityToStr(NetworkSecurity security) -{ - const NetworkSecurityTableEntry *end = &networkSecurityTable[ARRAY_COUNT(networkSecurityTable)]; - - for(const NetworkSecurityTableEntry *e = networkSecurityTable; e < end; ++e) - { - if(e->value == security) - { - return e->key; - } - } - return "Unknown"; -} - -/*************************************************************************************************/ -bool NetworkInterface::strToSsid(const char *str, Ssid *ssid) -{ -#define ESCAPE_CHARACTER_DELIMITER '\\' -#define HEX_ESCAPE_CHARACTER 'x' - int c; - uint8_t *ssidPtr = ssid->val; - int ssidLen = 0; - - while((c = (int)(*str++)) != 0) - { - if(c == ESCAPE_CHARACTER_DELIMITER) - { - if(*str == HEX_ESCAPE_CHARACTER) - { - c = StringUtil::hexToInt(str+1); - if(c == -1) - return false; - str += 3; - } - else - { - return false; - } - } - if(ssidLen >= sizeof(ssid->val)) - return false; - ++ssidLen; - *ssidPtr++ = (uint8_t)c; - } - - ssid->len = ssidLen; - - return true; -} - -/*************************************************************************************************/ -const char* NetworkInterface::ssidToStr(const Ssid *ssid, char *ssidStrBuffer) -{ - SET_STR_BUFFER(ssidStrBuffer, sizeof(SsidStrBuffer)); - const char *src = (const char*)ssid->val; - int len = ssid->len; - char *buf = ptr; - - while(len--) - { - if(*src >= 0x20 && *src <= 0x7E) - { - *ptr++ = *src; - } - else - { - ptr += sprintf(ptr, "\\x%02X", (*src) & 0xff); - } - ++src; - } - *ptr = 0; - return buf; -} - -/*************************************************************************************************/ -bool NetworkInterface::strToMacAddress(const char *str, MacAddress *macAddress) -{ - const char* strPtr = str; - uint8_t *macPtr = (uint8_t*)macAddress->octet; - - for(int count = 0; count < 6; ++count) - { - if(count < 5) - { - const char *idx = strchr(strPtr, ':'); - if(idx == NULL) - { - return false; - } - } - int num = StringUtil::hexToInt(strPtr); - if(num == -1) - { - return false; - } - *macPtr++ = (uint8_t)num; - strPtr += 3; - } - - return true; -} - -/*************************************************************************************************/ -const char* NetworkInterface::macAddressToStr(const MacAddress *macAddress, char *macStrBuffer) -{ - SET_STR_BUFFER(macStrBuffer, sizeof(MacAddressStrBuffer)); - const uint8_t *mac = macAddress->octet; - - sprintf(ptr, "%02X:%02X:%02X:%02X:%02X:%02X", - (unsigned int)mac[0], - (unsigned int)mac[1], - (unsigned int)mac[2], - (unsigned int)mac[3], - (unsigned int)mac[4], - (unsigned int)mac[5]); - - return ptr; -}
--- a/internal/network/NetworkJoin.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,251 +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" - -/*************************************************************************************************/ -WiconnectResult NetworkInterface::join(const char* ssid, const char *password, const Callback &completeHandler_) -{ - WiconnectResult result = WICONNECT_ERROR; - - enum - { - FS_SET_SSID, - FS_SET_PASSWORD, - FS_NETWORK_UP, - FS_GET_STATUS - }; - - CHECK_CALLBACK_AVAILABLE(completeHandler_); - - CHECK_OTHER_COMMAND_EXECUTING(); - - if(wiconnect->internalProcessingState == FS_SET_SSID) - { - if(ssid == NULL || - WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("set wlan.ssid %s", ssid))) - { - wiconnect->internalProcessingState = FS_SET_PASSWORD; - } - } - - if(wiconnect->internalProcessingState == FS_SET_PASSWORD) - { - if(password == NULL || *password == 0 || - WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("set wlan.passkey %s", password))) - { - wiconnect->internalProcessingState = FS_NETWORK_UP; - } - } - - if(wiconnect->internalProcessingState == FS_NETWORK_UP) - { - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("network_up"))) - { - if(!completeHandler_.isValid()) - { - wiconnect->internalProcessingState = FS_GET_STATUS; - } -#ifdef WICONNECT_ASYNC_TIMER_ENABLED - else - { - monitorTimer.stop(); - completeHandler = completeHandler_; - monitorTimer.start(this, &NetworkInterface::joinStatusMonitor, 1000); - } -#endif - } - } - - if(wiconnect->internalProcessingState == FS_GET_STATUS) - { -#define MAX_JOIN_TIME 30000 - TimeoutTimer timeout; - - status_loop: - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("get wlan.join.result"))) - { - int32_t status; - if(!WICONNECT_FAILED(result, wiconnect->responseToInt32(&status))) - { - if((NetworkJoinResult)status == NETWORK_JOIN_RESULT_JOINING) - { - if(timeout.timedOut(MAX_JOIN_TIME)) - { - result = WICONNECT_TIMEOUT; - } - else if(!wiconnect->nonBlocking) - { - goto status_loop; - } - else - { - result = WICONNECT_PROCESSING; - } - } - else - { - result = ((NetworkJoinResult)status == NETWORK_JOIN_RESULT_SUCCESS) ? WICONNECT_SUCCESS : WICONNECT_NOT_CONNECTED; - } - } - } - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - - - -/*************************************************************************************************/ -WiconnectResult NetworkInterface::leave() -{ - WiconnectResult result; - - CHECK_OTHER_COMMAND_EXECUTING(); - -#ifdef WICONNECT_ASYNC_TIMER_ENABLED - monitorTimer.stop(); -#endif - result = wiconnect->sendCommand("network_down"); - - CHECK_CLEANUP_COMMAND(); - - return result; -} - - -/*************************************************************************************************/ -WiconnectResult NetworkInterface::getNetworkStatus(NetworkStatus *statusPtr) -{ - WiconnectResult result; - - CHECK_OTHER_COMMAND_EXECUTING(); - - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("get network.status"))) - { - int32_t status; - if(!WICONNECT_FAILED(result, wiconnect->responseToInt32(&status))) - { - if(status != NETWORK_STATUS_DOWN) - { -#ifdef WICONNECT_ASYNC_TIMER_ENABLED - monitorTimer.stop(); -#endif - } - *statusPtr = (NetworkStatus)status; - } - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult NetworkInterface::getNetworkJoinResult(NetworkJoinResult *joinResultPtr) -{ - WiconnectResult result; - - CHECK_OTHER_COMMAND_EXECUTING(); - - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("get wlan.join.result"))) - { - int32_t status; - if(!WICONNECT_FAILED(result, wiconnect->responseToInt32(&status))) - { - if(status != NETWORK_JOIN_RESULT_JOINING) - { -#ifdef WICONNECT_ASYNC_TIMER_ENABLED - monitorTimer.stop(); -#endif - } - *joinResultPtr = (NetworkJoinResult)status; - } - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -#ifdef WICONNECT_ASYNC_TIMER_ENABLED - - -/*************************************************************************************************/ -// this is called every 1s by the monitorTimer -void NetworkInterface::joinStatusMonitor() -{ - static char responseBuffer[4]; - static uint8_t cmdBuffer[sizeof(QueuedCommand)]; - QueuedCommand *cmd = (QueuedCommand*)cmdBuffer; - - monitorTimer.stop(); - - *cmd = QueuedCommand(sizeof(responseBuffer), responseBuffer, "get wlan.join.result"); - - wiconnect->enqueueCommand(cmd, Callback(this, &NetworkInterface::joinStatusCheckCallback)); -} - -/*************************************************************************************************/ -// this is called on the completion of the 'get'wlan.join.result' command above -void NetworkInterface::joinStatusCheckCallback(WiconnectResult result, void *arg1, void *arg2) -{ - bool isComplete = false; - NetworkJoinResult joinResult = NETWORK_JOIN_RESULT_NONE; - - QueuedCommand *cmd = (QueuedCommand*)arg1; - - if(result == WICONNECT_SUCCESS) - { - int32_t status; - if(!StringUtil::strToInt32(cmd->responseBuffer, &status)) - { - result = WICONNECT_RESPONSE_PARSE_ERROR; - } - else if((NetworkJoinResult)status != NETWORK_JOIN_RESULT_JOINING) - { - isComplete = true; - joinResult = (NetworkJoinResult)status; - result = (joinResult == NETWORK_JOIN_RESULT_SUCCESS) ? WICONNECT_SUCCESS : WICONNECT_NOT_CONNECTED; - } - } - - if(isComplete || result != WICONNECT_SUCCESS) - { - completeHandler.call(result, (void*)joinResult, NULL); - } - else - { - monitorTimer.start(this, &NetworkInterface::joinStatusMonitor, 1000); - } -} - -#endif
--- a/internal/network/NetworkScan.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,160 +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 SCAN_TIMEOUT 15000 - - - - -/*************************************************************************************************/ -WiconnectResult NetworkInterface::scan(ScanResultList &resultList, const uint8_t *channelList, const char* ssid) -{ - WiconnectResult result; - char cmdBuffer[WICONNECT_MAX_CMD_SIZE]; - - CHECK_CALLBACK_AVAILABLE(completeHandler_); - - if(WICONNECT_IS_IDLE()) - { -#define SCAN_CMD "scan -v " - char *cmdBufferPtr = cmdBuffer + sizeof(SCAN_CMD)-1; - - strcpy(cmdBuffer, SCAN_CMD); - - if(channelList != NULL) - { - for(const uint8_t *ch = (const uint8_t *)channelList; *ch != 0; ++ch) - { - cmdBufferPtr += sprintf(cmdBufferPtr, "%d,", *ch); - } - *(cmdBufferPtr-1) = ' '; - } - else - { - strcat(cmdBufferPtr, "all "); - cmdBufferPtr += 4; - } - - if(ssid != NULL) - { - strcpy(cmdBufferPtr, ssid); - } - } - - CHECK_OTHER_COMMAND_EXECUTING(); - - //if(!completeHandler_.isValid()) - { - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand(SCAN_TIMEOUT, cmdBuffer))) - { - result = processScanResults(wiconnect->internalBuffer, resultList); - } - } -//#ifdef WICONNECT_ASYNC_TIMER_ENABLED -// else -// { -// QueuedCommand *cmd = new QueuedCommand(NULL, 4096, SCAN_TIMEOUT, cmdBuffer); -// cmd->userData = (void*)resultList; -// completeHandler = completeHandler_; -// if(WICONNECT_FAILED(result, wiconnect->enqueueCommand(cmd, Callback(this, &NetworkInterface::scanCompleteCallback)))) -// { -// delete cmd; -// } -// else -// { -// result = WICONNECT_PROCESSING; -// } -// } -//#endif - - CHECK_CLEANUP_COMMAND(); - - return result; -} - - - - - -/*************************************************************************************************/ -WiconnectResult NetworkInterface::processScanResults(char *resultStr, ScanResultList &resultList) -{ - WiconnectResult result = WICONNECT_SUCCESS; - char *line, *savedLine; - - for(savedLine = resultStr; (line = StringUtil::strtok_r(savedLine, "\r\n", &savedLine)) != NULL;) - { - char *toks[9], *savedTok; - - if(*line != '#') - { - continue; - } - savedTok = line + 2; - - for(int i = 0; i < 8 && (toks[i] = StringUtil::strtok_r(savedTok, " ", &savedTok)) != NULL; ++i) - { - if(toks[i] == NULL) - { - result = WICONNECT_RESPONSE_PARSE_ERROR; - goto exit; - } - } - - if(WICONNECT_FAILED(result, resultList.add(toks[1], toks[2], toks[3], toks[4], toks[5], savedTok))) - { - goto exit; - } - } - - exit: - return result; -} - -//#ifdef WICONNECT_ASYNC_TIMER_ENABLED -// -/*************************************************************************************************/ -//void NetworkInterface::scanCompleteCallback(WiconnectResult result, void *arg1, void *arg2) -//{ -// QueuedCommand *cmd = (QueuedCommand*)arg1; -// ScanResultList *listPtr = (ScanResultList*)cmd->userData; -// -// if(result == WICONNECT_SUCCESS) -// { -// result = processScanResults(cmd->responseBuffer, listPtr); -// } -// delete cmd; -// -// completeHandler.call(result, listPtr, NULL); -//} -// -//#endif
--- a/internal/network/NetworkSoftAp.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +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" - - - -///*************************************************************************************************/ -//WiconnectResult NetworkInterface::startSoftAp(const char* ssid, const char *password, WiconnectAsyncCallback *clientConnected) -//{ -// return WICONNECT_UNSUPPORTED; -//} -// -///*************************************************************************************************/ -//WiconnectResult NetworkInterface::stopSoftAp() -//{ -// return WICONNECT_UNSUPPORTED; -//} -// -///*************************************************************************************************/ -//WiconnectResult NetworkInterface::getSoftApClientList() -//{ -// return WICONNECT_UNSUPPORTED; -//}
--- a/internal/network/NetworkWebSetup.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,181 +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" - - - -/*************************************************************************************************/ -WiconnectResult NetworkInterface::startWebSetup(const char *ssid, const char *password, const Callback &completeHandler_) -{ - WiconnectResult result = WICONNECT_ERROR;; - - enum - { - FS_SET_SSID, - FS_SET_PASSWORD, - FS_NETWORK_UP - }; - - CHECK_CALLBACK_AVAILABLE(completeHandler_); - CHECK_OTHER_COMMAND_EXECUTING(); - - if(wiconnect->internalProcessingState == FS_SET_SSID) - { - if(ssid == NULL || - WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("set setup.web.ssid %s", ssid))) - { - wiconnect->internalProcessingState = FS_SET_PASSWORD; - } - } - - if(wiconnect->internalProcessingState == FS_SET_PASSWORD) - { - if(password == NULL || - WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("set setup.web.passkey %s", password))) - { - wiconnect->internalProcessingState = FS_NETWORK_UP; - } - } - - if(wiconnect->internalProcessingState == FS_NETWORK_UP) - { - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("setup web"))) - { -#ifdef WICONNECT_ASYNC_TIMER_ENABLED - if(completeHandler_.isValid()) - { -#ifdef WICONNECT_ASYNC_TIMER_ENABLED - monitorTimer.stop(); -#endif - completeHandler = completeHandler_; - monitorTimer.start(this, &NetworkInterface::webSetupStatusMonitor, 1000); - } -#endif - } - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult NetworkInterface::stopWebSetup() -{ - WiconnectResult result; - - CHECK_OTHER_COMMAND_EXECUTING(); - - #ifdef WICONNECT_ASYNC_TIMER_ENABLED - monitorTimer.stop(); - #endif - result = wiconnect->sendCommand("setup stop"); - - CHECK_CLEANUP_COMMAND(); - - return result; -} - - -/*************************************************************************************************/ -WiconnectResult NetworkInterface::isWebSetupRunning(bool *isRunningPtr) -{ - WiconnectResult result; - - CHECK_OTHER_COMMAND_EXECUTING(); - - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("setup status"))) - { - int32_t status; - if(!WICONNECT_FAILED(result, wiconnect->responseToInt32(&status))) - { - if(status) - { -#ifdef WICONNECT_ASYNC_TIMER_ENABLED - monitorTimer.stop(); -#endif - } - *isRunningPtr = (bool)status; - } - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - - -#ifdef WICONNECT_ASYNC_TIMER_ENABLED - -/*************************************************************************************************/ -void NetworkInterface::webSetupStatusMonitor() -{ - static char responseBuffer[4]; - static uint8_t cmdBuffer[sizeof(QueuedCommand)]; - QueuedCommand *cmd = (QueuedCommand*)cmdBuffer; - - monitorTimer.stop(); - - *cmd = QueuedCommand(sizeof(responseBuffer), responseBuffer, "setup status"); - - wiconnect->enqueueCommand(cmd, Callback(this, &NetworkInterface::webSetupStatusCheckCallback)); -} - -/*************************************************************************************************/ -void NetworkInterface::webSetupStatusCheckCallback(WiconnectResult result, void *arg1, void *arg2) -{ - bool isComplete = true; - - QueuedCommand *cmd = (QueuedCommand*)arg1; - - if(result == WICONNECT_SUCCESS) - { - int32_t status; - if(!StringUtil::strToInt32(cmd->responseBuffer, &status)) - { - result = WICONNECT_RESPONSE_PARSE_ERROR; - } - else if(status > 0) - { - isComplete = false; - } - } - - if(isComplete) - { - completeHandler.call(result, NULL, NULL); - } - else - { - monitorTimer.start(this, &NetworkInterface::webSetupStatusMonitor, 1000); - } -} - -#endif
--- a/internal/socket/SocketInterface.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,295 +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 <string.h> -#include "Wiconnect.h" -#include "internal/common.h" -#include "StringUtil.h" - -#include "types/SocketIrqHandlerMap.h" - - - - -/*************************************************************************************************/ -SocketInterface::SocketInterface(Wiconnect *wiconnect_) -{ - wiconnect = wiconnect_; - memset((void*)serverConnectedClientList, 0, sizeof(serverConnectedClientList)); -} - -/*************************************************************************************************/ -SocketInterface::~SocketInterface() -{ -} - -/*************************************************************************************************/ -WiconnectResult SocketInterface::connect(WiconnectSocket &socket, SocketType type, const char *host, uint16_t remortPort, uint16_t localPort, const void *args, Pin irqPin) -{ - WiconnectResult result; - int32_t handle; - char cmdBuffer[WICONNECT_MAX_CMD_SIZE]; - - if(WICONNECT_IS_IDLE()) - { - char gpioOption[8] = ""; - - if(irqPin != PIN_NC) - { - PinToGpioMapper mapper = wiconnect->pinToGpioMapper; - if(mapper == NULL) - { - return WICONNECT_PINNAME_TO_GPIO_MAPPER_NULL; - } - int8_t gpio = mapper(irqPin); - if(gpio == -1) - { - return WICONNECT_PINNAME_TO_GPIO_NO_MAPPING; - } - else if(!irqHandlers.pinIsRegistered(irqPin)) - { - return WICONNECT_NOT_FOUND; - } - - sprintf(gpioOption, "-g %d ", gpio); - } - - - switch(type) - { - case SOCKET_TYPE_TCP: - sprintf(cmdBuffer, "tcpc %s%s %d", gpioOption, host, remortPort); - break; - - case SOCKET_TYPE_UDP: { - char tmp[16]; - sprintf(cmdBuffer, "udpc %s%s %d %s", gpioOption, host, remortPort, - (localPort != SOCKET_ANY_PORT) ? StringUtil::uint32ToStr(tmp, localPort) : ""); - } break; - - case SOCKET_TYPE_TLS: - sprintf(cmdBuffer, "tlsc %s%s %d %s", gpioOption, host, remortPort, - (args != NULL) ? (char*)args : ""); - break; - - case SOCKET_TYPE_HTTP: { - const HttpSocketArgs *httpArgs = (const HttpSocketArgs*)args; - switch(httpArgs->type) - { - case SOCKET_HTTP_GET: - sprintf(cmdBuffer, "http_get %s%s %s", httpArgs->openOnly ? "-o " : "", - host, - (httpArgs->certName != NULL) ? httpArgs->certName : ""); - break; - - case SOCKET_HTTP_HEAD: - sprintf(cmdBuffer, "http_head %s%s %s", httpArgs->openOnly ? "-o " : "", - host, - (httpArgs->certName != NULL) ? httpArgs->certName : ""); - break; - - case SOCKET_HTTP_POST: - sprintf(cmdBuffer, "http_post %s%s %s %s", httpArgs->openOnly ? "-o " : "", - host, - httpArgs->contextType, - (httpArgs->certName != NULL) ? httpArgs->certName : ""); - break; - - default: - return WICONNECT_BAD_ARG; - } - - } break; - default: - return WICONNECT_BAD_ARG; - } - } - - CHECK_OTHER_COMMAND_EXECUTING(); - - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand(cmdBuffer))) - { - if(!WICONNECT_FAILED(result, wiconnect->responseToInt32(&handle))) - { - socket.init(handle, type, host, remortPort, localPort); - } - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult SocketInterface::tcpConnect(WiconnectSocket &socket, const char *host, uint16_t remortPort, Pin irqPin) -{ - return connect(socket, SOCKET_TYPE_TCP, host, remortPort, SOCKET_ANY_PORT, NULL, irqPin); -} - -/*************************************************************************************************/ -WiconnectResult SocketInterface::tlsConnect(WiconnectSocket &socket, const char *host, uint16_t remortPort, const char *certFilename, Pin irqPin) -{ - return connect(socket, SOCKET_TYPE_TLS, host, remortPort, SOCKET_ANY_PORT, certFilename, irqPin); -} - -/*************************************************************************************************/ -WiconnectResult SocketInterface::udpConnect(WiconnectSocket &socket, const char *host, uint16_t remortPort, uint16_t localPort, Pin irqPin) -{ - return connect(socket, SOCKET_TYPE_UDP, host, remortPort, localPort, NULL, irqPin); -} - -/*************************************************************************************************/ -WiconnectResult SocketInterface::httpConnect(WiconnectSocket &socket, const char *url, const HttpSocketArgs *args) -{ - return connect(socket, SOCKET_TYPE_HTTP, url, SOCKET_ANY_PORT, SOCKET_ANY_PORT, args, NC); -} - -/*************************************************************************************************/ -WiconnectResult SocketInterface::httpGet(WiconnectSocket &socket, const char *url, bool openOnly, const char *certFilename) -{ - const HttpSocketArgs args = - { - NULL, - certFilename, - openOnly, - SOCKET_HTTP_GET - }; - return httpConnect(socket, url, &args); -} - -/*************************************************************************************************/ -WiconnectResult SocketInterface::httpPost(WiconnectSocket &socket, const char *url, const char *contextType, bool openOnly, const char *certFilename) -{ - const HttpSocketArgs args = - { - contextType, - certFilename, - openOnly, - SOCKET_HTTP_POST - }; - return httpConnect(socket, url, &args); -} - -/*************************************************************************************************/ -WiconnectResult SocketInterface::httpHead(WiconnectSocket &socket, const char *url, const char *certFilename) -{ - const HttpSocketArgs args = - { - NULL, - certFilename, - false, - SOCKET_HTTP_HEAD - }; - return httpConnect(socket, url, &args); -} - -/*************************************************************************************************/ -WiconnectResult SocketInterface::httpAddHeader(WiconnectSocket &socket, const char *key, const char *value) -{ - WiconnectResult result; - char cmdBuffer[WICONNECT_MAX_CMD_SIZE]; - - if(WICONNECT_IS_IDLE()) - { - sprintf(cmdBuffer, "http_add_header %d %s %s", socket.getHandle(), key, value); - } - - CHECK_OTHER_COMMAND_EXECUTING(); - - result = wiconnect->sendCommand(cmdBuffer); - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult SocketInterface::httpGetStatus(WiconnectSocket &socket, uint32_t *statusCodePtr) -{ - WiconnectResult result; - - CHECK_OTHER_COMMAND_EXECUTING(); - - result = wiconnect->sendCommand("http_read_status %d", socket.getHandle()); - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult SocketInterface::closeAllSockets() -{ - WiconnectResult result; - - CHECK_OTHER_COMMAND_EXECUTING(); - - result = wiconnect->sendCommand("close all"); - - CHECK_CLEANUP_COMMAND(); - - return result; -} - - -/*************************************************************************************************/ -WiconnectResult SocketInterface::registerSocketIrqHandler(Pin irqPin, const Callback &handler) -{ - PinToGpioMapper mapper = wiconnect->pinToGpioMapper; - if(irqHandlers.pinIsRegistered(irqPin)) - { - return WICONNECT_DUPLICATE; - } - else if(mapper == NULL) - { - return WICONNECT_PINNAME_TO_GPIO_MAPPER_NULL; - } - int8_t gpio = mapper(irqPin); - if(gpio == -1) - { - return WICONNECT_PINNAME_TO_GPIO_NO_MAPPING; - } - - return irqHandlers.registerHandler(irqPin, handler); -} - -/*************************************************************************************************/ -WiconnectResult SocketInterface::unregisterSocketIrqHandler(Pin irqPin) -{ - return irqHandlers.unregisterHandler(irqPin); -} - -/*************************************************************************************************/ -void SocketInterface::socketClosedCallback(const WiconnectSocket *socket) -{ - if(serverConnectedClientList[socket->handle]) - { - serverConnectedClientList[socket->handle] = false; - } -}
--- a/internal/socket/TcpServer.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,269 +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" -#include "StringUtil.h" - -#include "types/SocketIrqHandlerMap.h" - -#define TCP_SERVER_MONITOR_PERIOD 250 //ms - - - -static WiconnectResult parseIpPortStr(char *str, uint32_t *ipAddress, uint16_t *port); - - - - -/*************************************************************************************************/ -WiconnectResult SocketInterface::tcpListen(uint16_t listeningPort, int maxClients, Pin irqPin) -{ - WiconnectResult result = WICONNECT_ERROR; - - enum - { - FS_SET_MAX_CLIENTS, - FS_SET_DATA_GPIO, - FS_START_SERVER, - }; - - CHECK_OTHER_COMMAND_EXECUTING(); - - if(wiconnect->internalProcessingState == FS_SET_MAX_CLIENTS) - { - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("set tcp.server.max_clients", maxClients))) - { - wiconnect->internalProcessingState = FS_SET_DATA_GPIO; - } - else if(result == WICONNECT_CMD_RESPONSE_ERROR) - { - // if there was a module error, then the wiconnect version probably doesn't support this option - // just continue to the next state - wiconnect->internalProcessingState = FS_SET_DATA_GPIO; - } - } - - if(wiconnect->internalProcessingState == FS_SET_DATA_GPIO) - { - if(irqPin == PIN_NC) - { - wiconnect->internalProcessingState = FS_START_SERVER; - } - else - { - PinToGpioMapper mapper = wiconnect->pinToGpioMapper; - if(mapper == NULL) - { - return WICONNECT_PINNAME_TO_GPIO_MAPPER_NULL; - } - int8_t gpio = mapper(irqPin); - if(gpio == -1) - { - return WICONNECT_PINNAME_TO_GPIO_NO_MAPPING; - } - else if(!irqHandlers.pinIsRegistered(irqPin)) - { - return WICONNECT_NOT_FOUND; - } - else if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("set tcp.server.data_gpio %d", gpio))) - { - wiconnect->internalProcessingState = FS_START_SERVER; - } - } - } - - if(wiconnect->internalProcessingState == FS_START_SERVER) - { - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("tcps start %d", listeningPort))) - { -//#ifdef WICONNECT_ASYNC_TIMER_ENABLED -// if(clientConnectedCallback.isValid() && !wiconnect->nonBlocking) -// { -// serverClientConnectedCallback = clientConnectedCallback; -// serverMonitorTimer.start(this, &SocketInterface::serverClientMonitor, TCP_SERVER_MONITOR_PERIOD); -// } -//#endif - } - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult SocketInterface::tcpAccept(WiconnectSocket &socket, int timeoutMs) -{ - TimeoutTimer timer; - - do - { - uint8_t handle; - uint16_t local, remote; - uint32_t ipAddress; - WiconnectResult result; - - if(WICONNECT_SUCCEEDED(result, pollForServerClient(&handle, &local, &remote, &ipAddress))) - { - if(WICONNECT_FAILED(result, socket.init(handle, SOCKET_TYPE_TCP, Wiconnect::ipToStr(ipAddress), remote, local))) - { - return result; - } - serverConnectedClientList[handle] = true; - return WICONNECT_SUCCESS; - } - else if(!(result == WICONNECT_PROCESSING || result == WICONNECT_NOT_FOUND)) - { - return result; - } - - } while(timeoutMs == WICONNECT_WAIT_FOREVER || !timer.timedOut(timeoutMs)); - - return WICONNECT_TIMEOUT; -} - -/*************************************************************************************************/ -WiconnectResult SocketInterface::tcpServerStop(void) -{ - WiconnectResult result = WICONNECT_ERROR; - - CHECK_OTHER_COMMAND_EXECUTING(); - - result = wiconnect->sendCommand("tcps stop"); - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult SocketInterface::pollForServerClient(uint8_t *handlePtr, uint16_t *localPort, uint16_t *remotePort, uint32_t *ipAddress) -{ - WiconnectResult result; - - CHECK_OTHER_COMMAND_EXECUTING(); - - if(WICONNECT_SUCCEEDED(result, wiconnect->sendCommand("list"))) - { - bool connectedClients[WICONNECT_MAX_SOCKETS]; - char *line, *savedLine; - result = WICONNECT_NOT_FOUND; - - memset(connectedClients, 0, sizeof(connectedClients)); - - for(savedLine = wiconnect->internalBuffer; (line = StringUtil::strtok_r(savedLine, "\r\n", &savedLine)) != NULL;) - { - char *toks[4], *savedTok; - - if(*line != '#') - { - continue; - } - savedTok = line + 2; - - for(int i = 0; i < 4 && (toks[i] = StringUtil::strtok_r(savedTok, " ", &savedTok)) != NULL; ++i) - { - if(toks[i] == NULL) - { - result = WICONNECT_RESPONSE_PARSE_ERROR; - goto exit; - } - } - - if(strcmp(toks[1], "TCPS") != 0) - { - continue; - } - - uint8_t handle = (uint8_t)(*toks[0] - '0'); - if(handle >= WICONNECT_MAX_SOCKETS) - { - result = WICONNECT_RESPONSE_PARSE_ERROR; - goto exit; - } - - connectedClients[handle] = true; - - if(result == WICONNECT_SUCCESS) - { - continue; - } - else if(serverConnectedClientList[handle]) - { - continue; - } - - result = WICONNECT_SUCCESS; - - if(handlePtr != NULL) - { - *handlePtr = handle; - parseIpPortStr(toks[2], NULL, localPort); - parseIpPortStr(toks[3], ipAddress, remotePort); - } - } - - for(int i = 0; i < WICONNECT_MAX_SOCKETS; ++i) - { - if(connectedClients[i] == false) - { - serverConnectedClientList[i] = false; - } - } - } - - -exit: - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -static WiconnectResult parseIpPortStr(char *str, uint32_t *ipAddress, uint16_t *port) -{ - char *colon = strchr(str, ':'); - if(colon == NULL) - { - return WICONNECT_RESPONSE_PARSE_ERROR; - } - *colon++ = 0; - - if(ipAddress != NULL && !Wiconnect::strToIp(str, ipAddress)) - { - return WICONNECT_RESPONSE_PARSE_ERROR; - } - else if(!StringUtil::strToUint16(colon, port)) - { - return WICONNECT_RESPONSE_PARSE_ERROR; - } - - return WICONNECT_SUCCESS; -}
--- a/internal/types/FileList.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,142 +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 "types/FileList.h" - - - -/*************************************************************************************************/ -FileList::FileList(int bufferLen_, void *buffer_) -{ - count = 0; - listHead = listTail = NULL; - buffer = (uint8_t*)buffer_; - bufferPtr = buffer; - bufferLen = bufferLen_; -} - -/*************************************************************************************************/ -FileList::~FileList() -{ - if(buffer == NULL) - { - WiconnectFile* result = listHead; - while(result != NULL) - { - WiconnectFile* tmp = result; - result = result->next; - delete tmp; - } - } -} - -/*************************************************************************************************/ -WiconnectResult FileList::add(const char *typeStr, const char *flagsStr, const char* sizeStr, const char *versionStr, const char *nameStr) -{ - WiconnectResult result; - WiconnectFile *res; - - if(buffer == NULL) - { - res = new WiconnectFile(); - if(res == NULL) - { - return WICONNECT_NULL_BUFFER; - } - } - else - { - if(bufferLen < sizeof(WiconnectFile)) - { - return WICONNECT_OVERFLOW; - } - res = (WiconnectFile*)bufferPtr; - memset(res, 0, sizeof(WiconnectFile)); - bufferLen -= sizeof(WiconnectFile); - bufferPtr += sizeof(WiconnectFile); - } - - if(WICONNECT_FAILED(result, res->initWithListing(typeStr, flagsStr, sizeStr, versionStr, nameStr))) - { - if(buffer == NULL) - { - delete res; - } - } - else - { - if(listHead == NULL) - { - listHead = listTail = res; - } - else - { - res->previous = listTail; - listTail->next = res; - listTail = res; - } - ++count; - } - - return result; -} - -/*************************************************************************************************/ -const WiconnectFile* FileList::getListHead() const -{ - return listHead; -} - -/*************************************************************************************************/ -int FileList::getCount() const -{ - return count; -} - -/*************************************************************************************************/ -const WiconnectFile* FileList::getResult(int i) const -{ - if(i >= count) - return NULL; - - WiconnectFile* result = listHead; - while(i-- != 0) - result = result->next; - - return result; -} - -/*************************************************************************************************/ -const WiconnectFile* FileList::operator [](int i) const -{ - return getResult(i); -} -
--- a/internal/types/QueuedCommand.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,191 +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" - -/*************************************************************************************************/ -QueuedCommand::QueuedCommand(int responseBufferLen_, char *responseBuffer_, int timeoutMs_, const ReaderFunc &reader_, void *user_, const char *cmd_, va_list vaList) -{ - initialize(responseBufferLen_, responseBuffer_, timeoutMs_, reader_, user_, cmd_, vaList); -} - -/*************************************************************************************************/ -QueuedCommand::QueuedCommand(int responseBufferLen_, char* responseBuffer_, int timeoutMs_, const char *cmd_, ...) -{ - va_list args; - va_start(args, cmd_); - initialize(responseBufferLen_, responseBuffer_, timeoutMs_, ReaderFunc(), NULL, cmd_, args); - va_end(args); -} - -/*************************************************************************************************/ -QueuedCommand::QueuedCommand(int responseBufferLen_, char *responseBuffer_, const char *cmd_, ...) -{ - va_list args; - va_start(args, cmd_); - initialize(responseBufferLen_, responseBuffer_, WICONNECT_DEFAULT_TIMEOUT, ReaderFunc(), NULL, cmd_, args); - va_end(args); -} - -/*************************************************************************************************/ -QueuedCommand::QueuedCommand(int timeoutMs_, const char *cmd_, ...) -{ - va_list args; - va_start(args, cmd_); - initialize(0, NULL, timeoutMs_, ReaderFunc(), NULL, cmd_, args); - va_end(args); -} - -/*************************************************************************************************/ -QueuedCommand::QueuedCommand(const char *cmd_, ...) -{ - va_list args; - va_start(args, cmd_); - initialize(0, NULL, WICONNECT_DEFAULT_TIMEOUT, ReaderFunc(), NULL, cmd_, args); - va_end(args); -} - -/*************************************************************************************************/ -QueuedCommand::~QueuedCommand() -{ -#ifdef WICONNECT_ENABLE_MALLOC - if(allocatedBuffer) - { - Wiconnect::getInstance()->_free(responseBuffer); - } -#endif -} - -/*************************************************************************************************/ -char *QueuedCommand::getResponseBuffer() -{ - return responseBuffer; -} -/*************************************************************************************************/ -int QueuedCommand::getResponseBufferLen() -{ - return responseBufferLen; -} -/*************************************************************************************************/ -int QueuedCommand::getTimeoutMs() -{ - return timeoutMs; -} -/*************************************************************************************************/ -ReaderFunc QueuedCommand::getReader() -{ - return reader; -} -/*************************************************************************************************/ -void * QueuedCommand::getReaderUserData() -{ - return user; -} -/*************************************************************************************************/ -char* QueuedCommand::getCommand() -{ - return command; -} -/*************************************************************************************************/ -Callback QueuedCommand::getCompletedCallback() -{ - return completeCallback; -} -/*************************************************************************************************/ -void QueuedCommand::setCompletedCallback(const Callback &cb) -{ - completeCallback = cb; -} - -/*************************************************************************************************/ -QueuedCommand& QueuedCommand::operator=( const QueuedCommand& other ) -{ - responseBuffer = other.responseBuffer; - responseBufferLen = other.responseBufferLen; - timeoutMs = other.timeoutMs; - reader = other.reader; - user = other.user; - completeCallback = other.completeCallback; - memcpy(command, other.command, sizeof(command)); - return *this; -} - -/*************************************************************************************************/ -void* QueuedCommand::operator new(size_t size) -{ - Wiconnect *wiconnect = Wiconnect::getInstance(); - wiconnect_assert(wiconnect, "QueuedCommand:new malloc not defined", wiconnect->_malloc != NULL); - return Wiconnect::getInstance()->_malloc(size); -} - -/*************************************************************************************************/ -void QueuedCommand::operator delete(void* ptr) -{ - Wiconnect *wiconnect = Wiconnect::getInstance(); - wiconnect_assert(wiconnect, "QueuedCommand:delete free not defined", wiconnect->_free != NULL); - Wiconnect::getInstance()->_free(ptr); -} - -/*************************************************************************************************/ -void QueuedCommand::initialize(int responseBufferLen_, char *responseBuffer_, int timeoutMs_, const ReaderFunc &reader_, void *user_, const char *cmd_, va_list vaList) -{ - if(responseBufferLen_ > 0) - { -#ifdef WICONNECT_ENABLE_MALLOC - Wiconnect *wiconnect = Wiconnect::getInstance(); - allocatedBuffer = false; - if(responseBuffer_ == NULL) - { - wiconnect_assert(wiconnect, "QueuedCommand() malloc not defined", wiconnect->_malloc != NULL); - responseBuffer = (char*)wiconnect->_malloc(responseBufferLen_); - wiconnect_assert(wiconnect, "QueuedCommand() responseBuffer malloc failed", responseBuffer != NULL); - allocatedBuffer = true; - } - else -#endif - { - wiconnect_assert(wiconnect, "QueuedCommand(), null buffer", responseBuffer_ != NULL); - responseBuffer = responseBuffer_; - } - } - responseBufferLen = responseBufferLen_; - timeoutMs = timeoutMs_; - reader = reader_; - user = user_; - userData = NULL; - - if(cmd_ != NULL) - { - int len = vsnprintf(command, sizeof(command)-3, cmd_, vaList); - command[len++] = '\r'; - command[len++] = '\n'; - command[len] = 0; - } -}
--- a/internal/types/ScanResult.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,184 +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 "types/ScanResult.h" -#include "NetworkInterface.h" -#include "internal/common.h" - - -static inline bool floatToFixedPointInt(const char *str, uint32_t *res); - - - -/*************************************************************************************************/ -ScanResult::ScanResult() -{ - next = NULL; - previous = NULL; - channel = 0xff; - rssi = -9999; - rate = 0; - security = NETWORK_SECURITY_UNKNOWN; - memset(&mac, 0, (uint32_t)sizeof(mac)); - memset(&ssid, 0, (uint32_t)sizeof(ssid)); -} - -/*************************************************************************************************/ -WiconnectResult ScanResult::init(const char *channelStr, const char *rssiStr, const char* macStr, const char *rateStr, const char *secStr, const char *ssidStr) -{ - intmax_t r; - if(!StringUtil::parseInt(channelStr, &r, 0, 15)) - { - return WICONNECT_RESPONSE_PARSE_ERROR; - } - channel = (int)r; - if(!StringUtil::parseInt(rssiStr, &r, -200, 100)) - { - return WICONNECT_RESPONSE_PARSE_ERROR; - } - rssi = (int)r; - - if(!Wiconnect::strToMacAddress(macStr, &mac)) - { - return WICONNECT_RESPONSE_PARSE_ERROR; - } - - if(!floatToFixedPointInt(rateStr, &rate)) - { - return WICONNECT_RESPONSE_PARSE_ERROR; - } - security = Wiconnect::strToNetworkSecurity(secStr); - - if(!Wiconnect::strToSsid(ssidStr, &ssid)) - { - return WICONNECT_RESPONSE_PARSE_ERROR; - } - - return WICONNECT_SUCCESS; -} - -/*************************************************************************************************/ -void* ScanResult::operator new(size_t size) -{ - Wiconnect *wiconnect = Wiconnect::getInstance(); - wiconnect_assert(wiconnect, "ScanResult:new, malloc not defined", wiconnect->_malloc != NULL); - return Wiconnect::getInstance()->_malloc(size); -} - -/*************************************************************************************************/ -void ScanResult::operator delete(void* ptr) -{ - Wiconnect *wiconnect = Wiconnect::getInstance(); - wiconnect_assert(wiconnect, "ScanResult:delete, free not defined", wiconnect->_free != NULL); - Wiconnect::getInstance()->_free(ptr); -} - -/*************************************************************************************************/ -uint8_t ScanResult::getChannel() const -{ - return channel; -} -/*************************************************************************************************/ -NetworkSignalStrength ScanResult::getSignalStrength() const -{ - return Wiconnect::rssiToSignalStrength(rssi); -} -/*************************************************************************************************/ -const MacAddress* ScanResult::getMacAddress() const -{ - return &mac; -} -/*************************************************************************************************/ -uint32_t ScanResult::getRate() const -{ - return rate; -} -/*************************************************************************************************/ -const char* ScanResult::getRateStr(char *buffer) const -{ - SET_STR_BUFFER(buffer, 16); - uint32_t i = rate / 10; - uint32_t f = rate % 10; - sprintf(ptr, "%u.%u", i, f); - return ptr; -} -/*************************************************************************************************/ -NetworkSecurity ScanResult::getSecurityType() const -{ - return security; -} -/*************************************************************************************************/ -const Ssid* ScanResult::getSsid() const -{ - return &ssid; -} - -/*************************************************************************************************/ -const ScanResult* ScanResult::getNext() const -{ - return next; -} - -/*************************************************************************************************/ -const ScanResult* ScanResult::getPrevious() const -{ - return previous; -} - - -/*************************************************************************************************/ -static inline bool floatToFixedPointInt(const char *str, uint32_t *res) -{ - intmax_t i; - intmax_t f = 0; - char buffer[32]; - - strcpy(buffer, str); - - char* frac = strchr(buffer, '.'); - if(frac != NULL) - { - *frac = 0; - ++frac; - } - - if(!StringUtil::parseInt(buffer, &i, 0, 1000)) - { - return false; - } - if(frac != NULL && !StringUtil::parseInt(frac, &f, 0, 9)) - { - return false; - } - - *res = (((uint32_t)i) * 10) + (uint32_t)f; - - return true; -} -
--- a/internal/types/ScanResultList.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,146 +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 "types/ScanResult.h" -#include "internal/common.h" - - -/*************************************************************************************************/ -ScanResultList::ScanResultList(int bufferLen_, void *buffer_) -{ - Wiconnect *wiconnect = Wiconnect::getInstance(); - wiconnect_assert(wiconnect, "ScanResultList(), bad buffer", (bufferLen_ == 0 && buffer_ == NULL) || (bufferLen_ != 0 && buffer_ != NULL)); - count = 0; - listHead = listTail = NULL; - buffer = (uint8_t*)buffer_; - bufferPtr = buffer; - bufferLen = bufferLen_; -} - -/*************************************************************************************************/ -ScanResultList::~ScanResultList() -{ - if(buffer == NULL) - { - ScanResult* result = listHead; - while(result != NULL) - { - ScanResult* tmp = result; - result = result->next; - delete tmp; - } - } -} - -/*************************************************************************************************/ -WiconnectResult ScanResultList::add(const char *channelStr, const char *rssiStr, const char* macStr, const char *rateStr, const char *secStr, const char *ssidStr) -{ - WiconnectResult result; - ScanResult *res; - - if(buffer == NULL) - { - res = new ScanResult(); - if(res == NULL) - { - return WICONNECT_NULL_BUFFER; - } - } - else - { - if(bufferLen < sizeof(ScanResult)) - { - return WICONNECT_OVERFLOW; - } - res = (ScanResult*)bufferPtr; - memset(res, 0, sizeof(ScanResult)); - bufferLen -= sizeof(ScanResult); - bufferPtr += sizeof(ScanResult); - } - - if(WICONNECT_FAILED(result, res->init(channelStr, rssiStr, macStr, rateStr, secStr, ssidStr))) - { - if(buffer == NULL) - { - delete res; - } - } - else - { - if(listHead == NULL) - { - listHead = listTail = res; - } - else - { - res->previous = listTail; - listTail->next = res; - listTail = res; - } - ++count; - } - - return result; -} - -/*************************************************************************************************/ -const ScanResult* ScanResultList::getListHead() const -{ - return listHead; -} - -/*************************************************************************************************/ -int ScanResultList::getCount() const -{ - return count; -} - -/*************************************************************************************************/ -const ScanResult* ScanResultList::getResult(int i) const -{ - if(i >= count) - return NULL; - - ScanResult* result = listHead; - while(i-- != 0) - result = result->next; - - return result; -} - -/*************************************************************************************************/ -const ScanResult* ScanResultList::operator [](int i) const -{ - return getResult(i); -} - - - - -
--- a/internal/types/WiconnectFile.cpp Thu Oct 23 15:21:50 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 - - - - -/*************************************************************************************************/ -WiconnectFile::WiconnectFile(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; -} - -/*************************************************************************************************/ -WiconnectFile::~WiconnectFile() -{ - 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 WiconnectFile::openForRead(uint8_t handle_, const char *filename) -{ - handle = handle_; - readEnabled = true; - strcpy(name, filename); - - return WICONNECT_SUCCESS; -} - -/*************************************************************************************************/ -WiconnectResult WiconnectFile::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* WiconnectFile::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 WiconnectFile::operator delete(void* ptr) -{ - Wiconnect *wiconnect = Wiconnect::getInstance(); - wiconnect_assert(wiconnect, "File:delete, free not defined", wiconnect->_free != NULL); - Wiconnect::getInstance()->_free(ptr); -} - - -/*************************************************************************************************/ -WiconnectResult WiconnectFile::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* WiconnectFile::getName() const -{ - return name; -} - -/*************************************************************************************************/ -uint32_t WiconnectFile::getSize() const -{ - return size; -} - -/*************************************************************************************************/ -FileType WiconnectFile::getType() const -{ - return type; -} - -/*************************************************************************************************/ -FileFlags WiconnectFile::getFlags() const -{ - return flags; -} - -/*************************************************************************************************/ -uint32_t WiconnectFile::getVersion() const -{ - return version; -} - -/*************************************************************************************************/ -const char* WiconnectFile::getVersionStr(char *buffer) const -{ - return FileInterface::fileVersionIntToStr(version, true, buffer); -} - -/*************************************************************************************************/ -const WiconnectFile* WiconnectFile::getNext() const -{ - return next; -} - -/*************************************************************************************************/ -const WiconnectFile* WiconnectFile::getPrevious() const -{ - return previous; -} - - -/*************************************************************************************************/ -WiconnectResult WiconnectFile::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))) - { - *bytesRead = wiconnect->getLastCommandResponseLength(); - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult WiconnectFile::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 WiconnectFile::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 WiconnectFile::clearRxBuffer() -{ - rxBuffer.bytesPending = 0; - rxBuffer.ptr = rxBuffer.buffer; -}
--- a/internal/types/WiconnectSocket.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,514 +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 - - -/*************************************************************************************************/ -WiconnectSocket::WiconnectSocket(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 - } - } - - handle = SOCKET_INVALID_HANDLE; - type = SOCKET_TYPE_UNKNOWN; - remotePort = 0; - localPort = 0; - connected = false; - host[0] = 0; -} - - -/*************************************************************************************************/ -WiconnectResult WiconnectSocket::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; -} - -/*************************************************************************************************/ -WiconnectSocket::~WiconnectSocket() -{ - 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 WiconnectSocket::isConnected() -{ - return connected; -} - -/*************************************************************************************************/ -SocketType WiconnectSocket::getType() -{ - return type; -} - -/*************************************************************************************************/ -const char* WiconnectSocket::getHost() -{ - return host; -} - -/*************************************************************************************************/ -uint16_t WiconnectSocket::getLocalPort() -{ - return localPort; -} - -/*************************************************************************************************/ -uint16_t WiconnectSocket::getRemotePort() -{ - return remotePort; -} - -/*************************************************************************************************/ -uint8_t WiconnectSocket::getHandle() -{ - return handle; -} - - -/*************************************************************************************************/ -WiconnectResult WiconnectSocket::close() -{ - WiconnectResult result; - CHECK_CONNECTED(); - CHECK_OTHER_COMMAND_EXECUTING(); - - result = wiconnect->sendCommand("close %d", handle); - - if(result != WICONNECT_PROCESSING) - { - connected = false; - wiconnect->socketClosedCallback(this); - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult WiconnectSocket::poll(bool *rxDataAvailablePtr, bool autoClose) -{ - 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 > 0) - { - *rxDataAvailablePtr = true; - if(status == 2 && autoClose) - { - connected = false; - } - } - } - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult WiconnectSocket::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 WiconnectSocket::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 WiconnectSocket::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))) - { - *bytesRead = wiconnect->getLastCommandResponseLength(); - } - - CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult WiconnectSocket::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) - { - const int bytesToRead = rxBuffer.size - rxBuffer.bytesPending; - char* ptr = (char*)&rxBuffer.buffer[rxBuffer.bytesPending]; - if(!WICONNECT_FAILED(result, wiconnect->sendCommand(ptr, bytesToRead, "read %d %d", handle, bytesToRead))) - { - rxBuffer.bytesPending += wiconnect->getLastCommandResponseLength(); - } - } - - if(bufferPtr != NULL) - { - *bufferPtr = rxBuffer.buffer; - *bytesReadPtr = rxBuffer.bytesPending; - clearRxBuffer(); - } - - return result; -} - -/*************************************************************************************************/ -WiconnectResult WiconnectSocket::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 WiconnectSocket::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 WiconnectSocket::puts(const char *s, bool flush) -{ - const int len = strlen(s); - return write(s, len, flush); -} - -/*************************************************************************************************/ -WiconnectResult WiconnectSocket::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 WiconnectSocket::flushTxBuffer() -{ - WiconnectResult result = WICONNECT_SUCCESS; - - CHECK_CONNECTED(); - CHECK_OTHER_COMMAND_EXECUTING(); - - if(txBuffer.bytesPending > 0) - { - result = wiconnect->sendCommand(ReaderFunc(this, &WiconnectSocket::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 WiconnectSocket::clearRxBuffer() -{ - rxBuffer.bytesPending = 0; - rxBuffer.ptr = rxBuffer.buffer; -} - -/*************************************************************************************************/ -uint8_t* WiconnectSocket::getTxBuffer() -{ - return txBuffer.buffer; -} -/*************************************************************************************************/ -int WiconnectSocket::getTxBufferSize() -{ - return txBuffer.size; -} -/*************************************************************************************************/ -int WiconnectSocket::getTxBufferBytesPending() -{ - return txBuffer.bytesPending; -} -/*************************************************************************************************/ -uint8_t* WiconnectSocket::getRxBuffer() -{ - return rxBuffer.buffer; -} -/*************************************************************************************************/ -int WiconnectSocket::getRxBufferSize() -{ - return rxBuffer.size; -} -/*************************************************************************************************/ -int WiconnectSocket::getRxBufferBytesPending() -{ - return rxBuffer.bytesPending; -} - - -/*************************************************************************************************/ -WiconnectResult WiconnectSocket::writeDataCallback(void *user, void *data, int maxReadSize, int *bytesRead) -{ - if(txBuffer.bytesPending == 0) - { - *bytesRead = EOF; - } - else - { - const int bytesToWrite = MIN(maxReadSize, txBuffer.bytesPending); - memcpy(data, txBuffer.ptr, bytesToWrite); - txBuffer.ptr += bytesToWrite; - txBuffer.bytesPending -= bytesToWrite; - *bytesRead = bytesToWrite; - } - - return WICONNECT_SUCCESS; -} -
--- a/internal/wiconnect/AsyncCommand.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,116 +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 "CommandCommon.h" - -#ifdef WICONNECT_ASYNC_TIMER_ENABLED - - - -/*************************************************************************************************/ -WiconnectResult Wiconnect::enqueueCommand(QueuedCommand *command, const Callback &commandCompleteHandler) -{ - if(commandQueue.isFull()) - { - return WICONNECT_OVERFLOW; - } - command->setCompletedCallback(commandCompleteHandler); - DEBUG_INFO("Queuing command: %s", command->getCommand()); - commandQueue.push(command); - processNextQueuedCommand(); - return WICONNECT_SUCCESS; -} - -/*************************************************************************************************/ -void Wiconnect::processNextQueuedCommand() -{ - if(commandQueue.isEmpty()) - { - return; - } - else if(commandExecuting) - { - return; - } - - CommandContext *context = (CommandContext*)commandContext; - CommandHeader *header = (CommandHeader*)commandHeaderBuffer; - - commandExecuting = true; - currentQueuedCommand = commandQueue.pop(); - - DEBUG_INFO("Processing next cmd in queue"); - - strcpy(commandFormatBuffer, currentQueuedCommand->command); - - RESET_CMD_HEADER(header); - - memset(context, 0, sizeof(CommandContext)); - if(currentQueuedCommand->responseBufferLen > 0) - { - context->responseBuffer = currentQueuedCommand->responseBuffer; - context->responseBufferLen = currentQueuedCommand->responseBufferLen; - } - else - { - context->responseBuffer = internalBuffer; - context->responseBufferLen = internalBufferSize; - } - - context->responseBufferPtr = context->responseBuffer; - context->commandLen = strlen(commandFormatBuffer); - context->commandPtr = commandFormatBuffer; - context->reader = currentQueuedCommand->reader; - context->user = currentQueuedCommand->userData; - context->timeoutMs = currentQueuedCommand->timeoutMs; - context->callback = currentQueuedCommand->completeCallback; - context->nonBlocking = true; - - DEBUG_CMD_SEND(commandFormatBuffer); - - commandExecuting = true; - timeoutTimer.reset(); - - commandProcessorTimer.start(this, &Wiconnect::commandProcessingTimerHandler, commandProcessingPeriod); -} - -/*************************************************************************************************/ -void Wiconnect::setCommandProcessingPeriod(uint32_t periodMs) -{ - commandProcessingPeriod = periodMs; -} - -/*************************************************************************************************/ -void Wiconnect::commandProcessingTimerHandler() -{ - checkCurrentCommand(); -} - -#endif -
--- a/internal/wiconnect/CommandCommon.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +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 <stdio.h> -#include <stdarg.h> -#include "Wiconnect.h" -#include "StringUtil.h" -#include "internal/common.h" - - -#define CHECK_NULL_BUFFER(buf) if(buf == NULL) return WICONNECT_NULL_BUFFER -#define CHECK_INITIALIZED() if(!initialized) return WICONNECT_NOT_INITIALIZED -#define RESET_CMD_HEADER(header) memset(header, 0, sizeof(CommandHeader)); header->bytes_remaining = WICONNECT_HEADER_LENGTH - -#define DEBUG_CMD_SEND(cmd) debugLog(">> CMD: %s", cmd) -#define DEBUG_CMD_LOG(res) debugLog("<< LOG: %s", res) -#define DEBUG_CMD_RESPONSE(res) debugLog("<< RES: %s", res) -#define DEBUG_CMD_ERROR(code) debugLog("<< ERR:(%d) %s", code, getLastCommandResponseCodeStr()) -#define DEBUG_ERROR(msg, ...) debugLog(" ERR: " msg, ## __VA_ARGS__) -#define DEBUG_INFO(msg, ...) debugLog(" DBG: " msg, ## __VA_ARGS__) - - - -typedef enum -{ - WICONNECT_CMD_TYPE_NULL = 0, - WICONNECT_CMD_TYPE_REPLY = 'R', - WICONNECT_CMD_TYPE_LOG = 'L', - WICONNECT_CMD_TYPE_SAFEMODE = 'S' -} ResponseType; - -typedef enum -{ - WICONNECT_CMD_CODE_NULL = 0, - WICONNECT_CMD_SUCCESS = 1, // The command was successful - WICONNECT_CMD_FAILED = 2, // The command failed, most likely in the firmware - WICONNECT_CMD_PARSE_ERROR = 3, // Failed to parse the command - WICONNECT_CMD_UNKNOWN = 4, // Unknown command - WICONNECT_CMD_TOO_FEW_ARGS = 5, // Not enough command arguments - WICONNECT_CMD_TOO_MANY_ARGS = 6, // Too many command arguments - WICONNECT_CMD_UNKNOWN_OPTION = 7, // Unknown option (e.g. known 'set' command option) - WICONNECT_CMD_BAD_ARGS = 8, // Invalid command arguments -} ResponseCode; - -#define WICONNECT_HEADER_LENGTH 9 -typedef struct -{ - ResponseType response_type; - ResponseCode response_code; - uint16_t response_len; - uint8_t len_buffer[WICONNECT_HEADER_LENGTH]; - uint8_t *len_buffer_ptr; - uint8_t bytes_remaining; -} CommandHeader; - -typedef struct -{ - char *responseBuffer; - char *responseBufferPtr; - int responseBufferLen; - ReaderFunc reader; - void *user; - char *commandPtr; - int commandLen; - int bytesToWrite; - int bytesToRead; - int timeoutMs; - Callback callback; - bool nonBlocking; -} CommandContext;
--- a/internal/wiconnect/ProcessCommand.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,351 +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 "CommandCommon.h" - - - -/*************************************************************************************************/ -WiconnectResult Wiconnect::checkCurrentCommand() -{ - WiconnectResult result; - - start: - CHECK_INITIALIZED(); - if(!commandExecuting) - { - return WICONNECT_IDLE; - } - - CommandContext *context = (CommandContext*)commandContext; - - if(context->commandLen > 0) - { - const int timeout = context->nonBlocking ? 0 : timeoutTimer.remainingMs(context->timeoutMs); - const int bytesToWrite = context->commandLen; - const int bytesWritten = serial.write(context->commandPtr, bytesToWrite, timeout); - context->commandPtr += bytesWritten; - context->commandLen -= bytesWritten; - if(bytesToWrite != bytesWritten) - { - if(timeoutTimer.timedOut(context->timeoutMs)) - { - issueCommandCallback(WICONNECT_TIMEOUT); - return WICONNECT_TIMEOUT; - } - else - { - return WICONNECT_PROCESSING; - } - } - } - - while(context->reader.isValid()) - { - if(context->bytesToWrite == 0) - { - context->responseBufferPtr = context->responseBuffer; - if(WICONNECT_FAILED(result, context->reader.call(context->user, context->responseBuffer, context->responseBufferLen, &context->bytesToWrite))) - { - issueCommandCallback(result); - return result; - } - else if(context->bytesToWrite == EOF) - { - context->reader.setInvalid(); - context->bytesToWrite = 0; - context->responseBufferPtr = context->responseBuffer; - break; - } - else - { - timeoutTimer.reset(); - } - } - if(context->bytesToWrite > 0) - { - const int timeout = context->nonBlocking ? 0 : timeoutTimer.remainingMs(context->timeoutMs); - const int bytesToWrite = context->bytesToWrite; - const int bytesWritten = serial.write(context->responseBufferPtr, bytesToWrite, timeout); - context->responseBufferPtr += bytesWritten; - context->bytesToWrite -= bytesWritten; - if(bytesToWrite != bytesWritten) - { - if(timeoutTimer.timedOut(context->timeoutMs)) - { - issueCommandCallback(WICONNECT_TIMEOUT); - return WICONNECT_TIMEOUT; - } - else - { - return WICONNECT_PROCESSING; - } - } - } - } - - result = receiveResponse(); - if(result == WICONNECT_PROCESSING && !context->nonBlocking) - { - goto start; - } - return result; -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::receiveResponse() -{ -loop: - WiconnectResult result = receivePacket(); - - if(result == WICONNECT_PROCESSING) - { - } - else if(result == WICONNECT_SUCCESS) - { - CommandHeader *header = (CommandHeader*)commandHeaderBuffer; - CommandContext *context = (CommandContext*)commandContext; - - // TODO: need to notify safemode - - if(header->response_type == WICONNECT_CMD_TYPE_REPLY || header->response_type == WICONNECT_CMD_TYPE_SAFEMODE) - { - if(header->response_code != WICONNECT_CMD_SUCCESS) - { - DEBUG_CMD_ERROR(header->response_code); - flush(); - issueCommandCallback(WICONNECT_CMD_RESPONSE_ERROR); - return WICONNECT_CMD_RESPONSE_ERROR; - } - else if(header->response_len > 0) - { - DEBUG_CMD_RESPONSE(context->responseBuffer); - if(header->response_len < context->responseBufferLen) - { - context->responseBuffer[header->response_len] = 0; - } - } - else - { - *context->responseBuffer = 0; - } - - issueCommandCallback(WICONNECT_SUCCESS); - - return WICONNECT_SUCCESS; - } - else - { - DEBUG_CMD_LOG(context->responseBuffer); - RESET_CMD_HEADER(header); - context->responseBufferPtr = context->responseBuffer; - goto loop; - } - } - else - { - issueCommandCallback(result); - } - - return result; -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::receivePacket() -{ - CommandHeader *header = (CommandHeader*)commandHeaderBuffer; - CommandContext *context = (CommandContext*)commandContext; - - if(header->bytes_remaining > 0) - { - uint16_t bytesReceived; - uint8_t buffer[WICONNECT_HEADER_LENGTH]; - - while(header->bytes_remaining > 0) - { - const int timeout = context->nonBlocking ? 0 : timeoutTimer.remainingMs(context->timeoutMs); - bytesReceived = serial.read((char*)buffer, header->bytes_remaining, timeout); - if(bytesReceived == 0) - { - return timeoutTimer.timedOut(context->timeoutMs) ? WICONNECT_TIMEOUT : WICONNECT_PROCESSING; - } - - for(uint8_t *ptr = buffer; bytesReceived > 0; ++ptr) - { - if(header->response_type == WICONNECT_CMD_TYPE_NULL) - { - if( *ptr == WICONNECT_CMD_TYPE_REPLY || - *ptr == WICONNECT_CMD_TYPE_LOG || - *ptr == WICONNECT_CMD_TYPE_SAFEMODE) - { - header->response_type = (ResponseType)*ptr; - -- header->bytes_remaining; - } - --bytesReceived; - } - else if(header->response_code == WICONNECT_CMD_CODE_NULL) - { - if(*ptr >= '0' && *ptr <= '7') - { - header->response_code = (ResponseCode)(*ptr - '0' + 1); - --header->bytes_remaining; - header->len_buffer_ptr = header->len_buffer; - } - else - { - RESET_CMD_HEADER(header); - } - --bytesReceived; - } - else if(header->bytes_remaining > 2) - { - uint8_t len_chars = MIN((int)bytesReceived, (int)(header->bytes_remaining-2)); - header->bytes_remaining -= len_chars; - bytesReceived -= len_chars; - while(len_chars-- > 0) - { - *header->len_buffer_ptr++ = *ptr++; - } - --ptr; // need to decrement since the for loop increments - if(header->bytes_remaining == 2) - { - uint32_t packetLen; - *header->len_buffer_ptr = 0; - if(!StringUtil::strToUint32((const char*)header->len_buffer, &packetLen)) - { - RESET_CMD_HEADER(header); - } - else - { - if(packetLen > 0) - { - if(packetLen == 1 || packetLen == 2) - { - return WICONNECT_CMD_RESPONSE_ERROR; - } - packetLen -= 2; - } - if((int)packetLen > context->responseBufferLen) - { - DEBUG_ERROR("Packet larger than response buffer: %d > %d", packetLen, context->responseBufferLen); - return WICONNECT_OVERFLOW; - } - header->response_len = (uint16_t)packetLen; - context->bytesToRead = packetLen; - } - } - } - else if(header->bytes_remaining == 2) - { - --bytesReceived; - if(*ptr == '\r') - { - header->bytes_remaining = 1; - } - else - { - RESET_CMD_HEADER(header); - } - } - else - { - --bytesReceived; - if(*ptr == '\n') - { - header->bytes_remaining = 0; - break; - } - else - { - RESET_CMD_HEADER(header); - } - } - } - } - } - - while(context->bytesToRead > 0) - { - const int timeout = context->nonBlocking ? 0 : timeoutTimer.remainingMs(context->timeoutMs); - const int bytesToRead = context->bytesToRead; - const int bytesReceived = serial.read(context->responseBufferPtr, bytesToRead, timeout); - context->responseBufferPtr += bytesReceived; - context->bytesToRead -= bytesReceived; - - if(bytesReceived != bytesToRead) - { - return timeoutTimer.timedOut(context->timeoutMs) ? WICONNECT_TIMEOUT : WICONNECT_PROCESSING; - } - else if(context->bytesToRead == 0) - { - *context->responseBufferPtr = 0; - - // read the trailing \r\n - char trailingCRLF[2]; - const int bytesReceived = serial.read(trailingCRLF, 2, 100); - // FIXME there's a potenital weakness where the trailing \r\n isn't ready to be recieved - if(bytesReceived != 2) - { - return WICONNECT_TIMEOUT; - } - } - } - - return (header->response_code != WICONNECT_CMD_CODE_NULL && - header->response_type != WICONNECT_CMD_TYPE_NULL && - context->bytesToRead == 0) ? WICONNECT_SUCCESS : WICONNECT_PROCESSING; -} - -/*************************************************************************************************/ -void Wiconnect::issueCommandCallback(WiconnectResult result) -{ - CommandHeader *header = (CommandHeader*)commandHeaderBuffer; - CommandContext *context = (CommandContext*)commandContext; -#ifdef WICONNECT_ASYNC_TIMER_ENABLED - void *returnPtr = (currentQueuedCommand != NULL) ? (void*)currentQueuedCommand : (void*)context->responseBuffer; - currentQueuedCommand = NULL; - commandProcessorTimer.stop(); -#else - void *returnPtr = (void*)context->responseBuffer; -#endif - context->callback.call(result, returnPtr, (void*)(uint32_t)header->response_len); - commandExecuting = false; - -#ifdef WICONNECT_ASYNC_TIMER_ENABLED - processNextQueuedCommand(); -#endif -} - -/*************************************************************************************************/ -void Wiconnect::stopCurrentCommand() -{ - internalProcessingState = 0; - issueCommandCallback(WICONNECT_ABORTED); -} -
--- a/internal/wiconnect/SendCommand.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,209 +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 "CommandCommon.h" - - -/*************************************************************************************************/ -WiconnectResult Wiconnect::sendCommand(const Callback &completeCallback, char *responseBuffer, - int responseBufferLen, int timeoutMs, const ReaderFunc &reader, void *user, - const char *cmd, va_list vaList) -{ - // preprocessor assertion - ct_assert(sizeof(commandContext) >=sizeof(CommandContext)); - CHECK_INITIALIZED(); - CHECK_NULL_BUFFER(responseBuffer); - if(commandExecuting) - { - return checkCurrentCommand(); - } - - CommandContext *context = (CommandContext*)commandContext; - CommandHeader *header = (CommandHeader*)commandHeaderBuffer; - - int len = vsnprintf(commandFormatBuffer, sizeof(commandFormatBuffer)-3, cmd, vaList); - - if(len > (int)(sizeof(commandFormatBuffer)-3)) - { - DEBUG_ERROR("Command overflowed: %d > %d", len, sizeof(commandFormatBuffer)-3); - return WICONNECT_OVERFLOW; - } - - commandFormatBuffer[len++] = '\r'; - commandFormatBuffer[len++] = '\n'; - commandFormatBuffer[len] = 0; - - RESET_CMD_HEADER(header); - - memset(context, 0, sizeof(CommandContext)); - context->responseBuffer = responseBuffer; - context->responseBufferPtr = context->responseBuffer; - context->responseBufferLen = responseBufferLen; - context->commandLen = len; - context->commandPtr = commandFormatBuffer; - context->reader = reader; - context->user = user; - context->timeoutMs = timeoutMs; - context->callback = completeCallback; - context->nonBlocking = nonBlocking; - - DEBUG_CMD_SEND(commandFormatBuffer); - - commandExecuting = true; - flush(0); - timeoutTimer.reset(); - - return checkCurrentCommand(); -} - - -/*************************************************************************************************/ -WiconnectResult Wiconnect::sendCommand(char *responseBuffer, int responseBufferLen, int timeoutMs, - const ReaderFunc &reader, void *user, const char *cmd, va_list vaList) -{ - return sendCommand(Callback(), responseBuffer, responseBufferLen, timeoutMs, reader, user, cmd, vaList); -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::sendCommand(char *responseBuffer, int responseBufferLen, int timeoutMs, - const ReaderFunc &reader, void *user, const char *cmd, ...) -{ - WiconnectResult result; - va_list args; - va_start(args, cmd); - result = sendCommand(Callback(), responseBuffer, responseBufferLen, timeoutMs, reader, user, cmd, args); - va_end(args); - return result; -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::sendCommand( int timeoutMs, const ReaderFunc &reader, void *user, const char *cmd, ...) -{ - WiconnectResult result; - va_list args; - va_start(args, cmd); - result = sendCommand(Callback(), internalBuffer, internalBufferSize, timeoutMs, reader, user, cmd, args); - va_end(args); - return result; -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::sendCommand(const ReaderFunc &reader, void *user, const char *cmd, ...) -{ - WiconnectResult result; - va_list args; - va_start(args, cmd); - result = sendCommand(Callback(), internalBuffer, internalBufferSize, defaultTimeoutMs, reader, user, cmd, args); - va_end(args); - return result; -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::sendCommand(char *responseBuffer, int responseBufferLen, int timeoutMs, const char *cmd, ...) -{ - WiconnectResult result; - va_list args; - va_start(args, cmd); - result = sendCommand(Callback(), responseBuffer, responseBufferLen, timeoutMs, ReaderFunc(), NULL, cmd, args); - va_end(args); - return result; -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::sendCommand(const Callback &completeCallback, char *responseBuffer, int responseBufferLen, const char *cmd, ...) -{ - WiconnectResult result; - va_list args; - va_start(args, cmd); - result = sendCommand(completeCallback, responseBuffer, responseBufferLen, defaultTimeoutMs, ReaderFunc(), NULL, cmd, args); - va_end(args); - return result; -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::sendCommand(char *responseBuffer, int responseBufferLen, const char *cmd, ...) -{ - WiconnectResult result; - va_list args; - va_start(args, cmd); - result = sendCommand(Callback(), responseBuffer, responseBufferLen, defaultTimeoutMs, ReaderFunc(), NULL, cmd, args); - va_end(args); - return result; -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::sendCommand(const Callback &completeCallback, const char *cmd, ...) -{ - WiconnectResult result; - va_list args; - va_start(args, cmd); - result = sendCommand(completeCallback, internalBuffer, internalBufferSize, defaultTimeoutMs, ReaderFunc(), NULL, cmd, args); - va_end(args); - return result; -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::sendCommand(const char *cmd, ...) -{ - WiconnectResult result; - va_list args; - va_start(args, cmd); - result = sendCommand(Callback(), internalBuffer, internalBufferSize, defaultTimeoutMs, ReaderFunc(), NULL, cmd, args); - va_end(args); - return result; -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::sendCommand(const Callback &completeCallback, int timeoutMs, const char *cmd, ...) -{ - WiconnectResult result; - va_list args; - va_start(args, cmd); - result = sendCommand(completeCallback, internalBuffer, internalBufferSize, timeoutMs, ReaderFunc(), NULL, cmd, args); - va_end(args); - return result; -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::sendCommand(int timeoutMs, const char *cmd, ...) -{ - WiconnectResult result; - va_list args; - va_start(args, cmd); - result = sendCommand(Callback(), internalBuffer, internalBufferSize, timeoutMs, ReaderFunc(), NULL, cmd, args); - va_end(args); - return result; -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::sendCommand(const char *cmd, va_list vaList) -{ - return sendCommand(Callback(), internalBuffer, internalBufferSize, defaultTimeoutMs, ReaderFunc(), NULL, cmd, vaList); -} -
--- a/internal/wiconnect/Wiconnect.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,376 +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 <stdio.h> -#include <stdarg.h> -#include <string.h> - -#include "WiconnectInterface.h" -#include "internal/common.h" - - - - - -using namespace wiconnect; - - - - - -#ifdef WICONNECT_ENABLE_MALLOC -#define MALLOC_ARGS , void* (*mallocPtr)(size_t), void (*freePtr)(void*) -#define MALLOC_CONSTRUCTORS _malloc(mallocPtr), _free(freePtr), -#else -#define MALLOC_ARGS -#define MALLOC_CONSTRUCTORS -#endif - - -static Wiconnect* instance = NULL; - - - - -/*************************************************************************************************/ -void Wiconnect::prepare(void *internalBuffer_, int internalBufferSize_, bool nonBlocking_) -{ - instance = this; - internalBufferAlloc = false; -#ifdef WICONNECT_ENABLE_MALLOC - if(internalBufferSize_ > 0 && internalBuffer_ == NULL) - { - wiconnect_assert(this, "Wiconnect(), malloc not defined", _malloc != NULL); - internalBuffer = (char*)_malloc(internalBufferSize_); - internalBufferAlloc = true; - } - else -#endif - { - internalBuffer = (char*)internalBuffer_; - } - - internalProcessingState = 0; - currentCommandId = NULL; - internalBufferSize = internalBufferSize_; - nonBlocking = nonBlocking_; - commandExecuting = false; - initialized = false; - pinToGpioMapper = NULL; - defaultTimeoutMs = WICONNECT_DEFAULT_TIMEOUT; - - memset(commandContext, 0, sizeof(commandContext)); - -#ifdef WICONNECT_ASYNC_TIMER_ENABLED - commandProcessingPeriod = WICONNECT_DEFAULT_COMMAND_PROCESSING_PERIOD; - currentQueuedCommand = NULL; -#endif -} - - -/*************************************************************************************************/ -Wiconnect::Wiconnect(const SerialConfig &serialConfig, int internalBufferSize, void *internalBuffer, Pin reset, Pin wake, bool nonBlocking MALLOC_ARGS) : - NetworkInterface(this), SocketInterface(this), FileInterface(this), MALLOC_CONSTRUCTORS serial(serialConfig, this), resetGpio(reset), wakeGpio(wake) -{ -#ifdef WICONNECT_ENABLE_MALLOC - wiconnect_assert(this, "Wiconnect(), bad malloc/free", (mallocPtr == NULL && freePtr == NULL) || (mallocPtr != NULL && freePtr != NULL)); -#endif - prepare(internalBuffer, internalBufferSize, nonBlocking); -} - -/*************************************************************************************************/ -Wiconnect::Wiconnect(const SerialConfig &serialConfig, Pin reset, Pin wake, bool nonBlocking MALLOC_ARGS) : - NetworkInterface(this), SocketInterface(this), FileInterface(this), MALLOC_CONSTRUCTORS serial(serialConfig, this), resetGpio(reset), wakeGpio(wake) -{ -#ifdef WICONNECT_ENABLE_MALLOC - wiconnect_assert(this, "Wiconnect(), bad malloc/free", (mallocPtr == NULL && freePtr == NULL) || (mallocPtr != NULL && freePtr != NULL)); -#endif - prepare(NULL, 0, nonBlocking); -} - -/*************************************************************************************************/ -Wiconnect::~Wiconnect() -{ -#ifdef WICONNECT_ENABLE_MALLOC - if(internalBufferAlloc) - { - _free(internalBuffer); - } -#endif -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::init(bool bringNetworkUp) -{ - WiconnectResult result; - int retries; - bool savedNonBlocking = nonBlocking; - - if(WICONNECT_FAILED(result, reset())) - { - return result; - } - - delayMs(1000); - - initialized = true; - nonBlocking = false; - - for(retries = 3; retries > 0; --retries) - { - result = sendCommand(CMD_SET_SYSTEM_COMMAND_MODE, "machine"); - if(result != WICONNECT_SUCCESS) - { - delayMs(1000); - } - else - { - break; - } - } - - if(result == WICONNECT_SUCCESS) - { - sendCommand("set stream.auto_close 0"); - } - if(result == WICONNECT_SUCCESS && bringNetworkUp) - { - sendCommand(15000, "ping -g"); - } - - nonBlocking = savedNonBlocking; - if(result != WICONNECT_SUCCESS) - { - initialized = false; - } - - - return result; -} - -/*************************************************************************************************/ -void Wiconnect::deinit(void) -{ - initialized = false; -} - -/*************************************************************************************************/ -Wiconnect* Wiconnect::getInstance() -{ - return instance; -} - -/*************************************************************************************************/ -bool Wiconnect::isInitialized() -{ - return initialized; -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::reset() -{ - resetGpio = 0; - delayMs(10); - resetGpio = 1; - delayMs(1000); - return WICONNECT_SUCCESS; -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::wakeup() -{ - wakeGpio = 1; - delayMs(1); - wakeGpio = 0; - return WICONNECT_SUCCESS; -} - -/*************************************************************************************************/ -void Wiconnect::flush(int delayMs) -{ - if(delayMs != 0) - { - serial.write("\r\n\r\n", 4, 0); - } - delayMs(delayMs); - serial.flush(); -} - -/*************************************************************************************************/ -void Wiconnect::setPinToGpioMapper(PinToGpioMapper mapper) -{ - pinToGpioMapper = mapper; -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::getVersion(char *versionBuffer, int versionBufferSize, const Callback &completeCallback) -{ - WiconnectResult result; - - if(versionBuffer != NULL && versionBufferSize == 0) - { - return WICONNECT_BAD_ARG; - } - - _CHECK_OTHER_COMMAND_EXECUTING(); - - if(versionBuffer == NULL) - { - result = sendCommand(completeCallback, CMD_GET_VERSION); - } - else - { - result = sendCommand(completeCallback, versionBuffer, versionBufferSize, CMD_GET_VERSION); - } - - _CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::updateFirmware(bool forced, const char *versionStr, const Callback &completeCallback) -{ - WiconnectResult result; - char cmdBuffer[WICONNECT_MAX_CMD_SIZE]; - - if(_WICONNECT_IS_IDLE()) - { - strcpy(cmdBuffer, "ota "); - if(versionStr != NULL) - { - strcat(cmdBuffer, "-b wiconnect-"); - strcat(cmdBuffer, versionStr); - } - else if(forced) - { - strcat(cmdBuffer, "-f"); - } - } - - _CHECK_OTHER_COMMAND_EXECUTING(); - - result = sendCommand(completeCallback, WICONNECT_FIRMWARE_UPDATE_TIMEOUT, cmdBuffer); - - _CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -const char* Wiconnect::getWiconnectResultStr(WiconnectResult wiconnectResult) -{ - static const char* const wiconnectSuccessStrTable[] = { - "Success", // WICONNECT_SUCCESS - "Processing command", // WICONNECT_PROCESSING - "Idle", // WICONNECT_IDLE - "Aborted", // WICONNECT_ABORTED - }; - static const char* const wiconnectErrorStrTable[] = { - "", - "General error", // WICONNECT_ERROR - "WiConnect command code error", // WICONNECT_CMD_RESPONSE_ERROR - "Null buffer", // WICONNECT_NULL_BUFFER - "Not initialized", // WICONNECT_NOT_INITIALIZED - "Overflow", // WICONNECT_OVERFLOW - "Timeout", // WICONNECT_TIMEOUT - "Response handler null", // WICONNECT_RESPONSE_HANDLER_NULL - "Response parse error", // WICONNECT_RESPONSE_PARSE_ERROR - "Another command is executing", // WICONNECT_ANOTHER_CMD_EXECUTING - "Bad argument(s)", // WICONNECT_BAD_ARG - "Unsupported", // WICONNECT_UNSUPPORTED - "Pin name to GPIO mapper null", // WICONNECT_PINNAME_TO_GPIO_MAPPER_NULL - "Duplicate", // WICONNECT_DUPLICATE - "Not found", // WICONNECT_NOT_FOUND - "No mapping for pinname to GPIO", // WICONNECT_PINNAME_TO_GPIO_NO_MAPPING - "Not connected", // WICONNECT_NOT_CONNECTED - "Underflow", // WICONNECT_UNDERFLOW - "A monitor is not available", // WICONNECT_MONITOR_NOT_AVAILABLE - "Not opened for reading", // WICONNECT_NOT_OPENED_FOR_READING - }; - - if((int)wiconnectResult >= (int)WICONNECT_SUCCESS) - { - return wiconnectSuccessStrTable[wiconnectResult]; - } - else - { - wiconnectResult = (WiconnectResult)(-((int)wiconnectResult)); - return wiconnectErrorStrTable[wiconnectResult]; - } -} - - -/*************************************************************************************************/ -void Wiconnect::setDebugLogger(LogFunc logFunc) -{ - debugLogger = logFunc; -} - -/*************************************************************************************************/ -void Wiconnect::setAssertLogger(LogFunc assertLogFunc) -{ - assertLogger = assertLogFunc; -} - -/*************************************************************************************************/ -void Wiconnect::debugLog(const char *msg, ...) -{ - if(!debugLogger.isValid()) - { - return; - } - - char buffer[96]; - va_list args; - va_start(args, msg); - int len = vsnprintf(buffer, sizeof(buffer), msg, args); - va_end(args); - - if(len > (int)(sizeof(buffer)-6)) - { - char *p = &buffer[sizeof(buffer)-6]; - *p++ = '.'; - *p++ = '.'; - *p++ = '.'; - *p++ = '\r'; - *p++ = '\n'; - *p = 0; - } - else - { - if(buffer[len-2] != '\r') - { - char *p = &buffer[len]; - *p++ = '\r'; - *p++ = '\n'; - *p = 0; - } - } - debugLogger.call(buffer); -}
--- a/internal/wiconnect/WiconnectCommand.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +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 "CommandCommon.h" -#include "StringUtil.h" - - - -/*************************************************************************************************/ -void Wiconnect::setCommandDefaultTimeout(int timeoutMs) -{ - defaultTimeoutMs = timeoutMs; -} - -/*************************************************************************************************/ -int Wiconnect::getCommandDefaultTimeout() -{ - return defaultTimeoutMs; -} - -/*************************************************************************************************/ -char* Wiconnect::getResponseBuffer() -{ - return internalBuffer; -} - -/*************************************************************************************************/ -uint16_t Wiconnect::getLastCommandResponseLength() -{ - CommandHeader *header = (CommandHeader*)commandHeaderBuffer; - return header->response_len; -} - -/*************************************************************************************************/ -const char* Wiconnect::getLastCommandResponseCodeStr() -{ - if(!initialized) - { - return NULL; - } - static const char* const response_error_strings[] ={ - "Null", - "Success", - "Failed", - "Parse error", - "Unknown command", - "Too few arguments", - "Too many arguments", - "Unknown command option", - "Bad command arguments" - }; - CommandHeader *header = (CommandHeader*)commandHeaderBuffer; - - return response_error_strings[header->response_code]; -} - - -/*************************************************************************************************/ -WiconnectResult Wiconnect::responseToUint32(uint32_t *uint32Ptr) -{ - CHECK_INITIALIZED(); - return StringUtil::strToUint32(internalBuffer, uint32Ptr) ? WICONNECT_SUCCESS : WICONNECT_RESPONSE_PARSE_ERROR; -} - - -/*************************************************************************************************/ -WiconnectResult Wiconnect::responseToInt32(int32_t *int32Ptr) -{ - CHECK_INITIALIZED(); - return StringUtil::strToInt32(internalBuffer, int32Ptr) ? WICONNECT_SUCCESS : WICONNECT_RESPONSE_PARSE_ERROR; -} - -
--- a/internal/wiconnect/WiconnectSettings.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,112 +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" - - - -/*************************************************************************************************/ -WiconnectResult Wiconnect::setSetting(const char *settingStr, uint32_t value) -{ - WiconnectResult result; - - _CHECK_OTHER_COMMAND_EXECUTING(); - - result = sendCommand("set %s %u", settingStr, value); - - _CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::setSetting(const char *settingStr, const char *value) -{ - WiconnectResult result; - - _CHECK_OTHER_COMMAND_EXECUTING(); - - result = sendCommand("set %s %s", settingStr, value); - - _CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::getSetting(const char *settingStr, uint32_t *valuePtr) -{ - WiconnectResult result = WICONNECT_ERROR; - - - _CHECK_OTHER_COMMAND_EXECUTING(); - - if(WICONNECT_SUCCEEDED(result, sendCommand("get %s", settingStr))) - { - result = responseToUint32(valuePtr); - } - - _CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::getSetting(const char *settingStr, char **valuePtr) -{ - WiconnectResult result = WICONNECT_ERROR; - - - _CHECK_OTHER_COMMAND_EXECUTING(); - - if(WICONNECT_SUCCEEDED(result, sendCommand("get %s", settingStr))) - { - *valuePtr = internalBuffer; - } - - _CHECK_CLEANUP_COMMAND(); - - return result; -} - -/*************************************************************************************************/ -WiconnectResult Wiconnect::getSetting(const char *settingStr, char *valueBuffer, uint16_t valueBufferLen) -{ - WiconnectResult result = WICONNECT_ERROR; - - - _CHECK_OTHER_COMMAND_EXECUTING(); - - result = sendCommand(valueBuffer, valueBufferLen, "get %s", settingStr); - - _CHECK_CLEANUP_COMMAND(); - - return result; -}
--- a/sdk/mbed/Gpio.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +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" - -#include "platform.h" -#include "gpio_api.h" - - - -/*************************************************************************************************/ -Gpio::Gpio(Pin pin) : DigitalOut(pin) -{ -} - -/*************************************************************************************************/ -void Gpio::write(bool value) -{ - gpio_write(&gpio, (int)value); -} - -/*************************************************************************************************/ -bool Gpio::read(void) -{ - const int v = gpio_read(&gpio); - return (bool)v; -} - -/*************************************************************************************************/ -Gpio& Gpio::operator= (bool value) -{ - write(value); - return *this; -} - -/*************************************************************************************************/ -Gpio& Gpio::operator= (const Gpio& other) -{ - memcpy((void*)&gpio, (void*)&other.gpio, sizeof(gpio)); - return *this; -}
--- a/sdk/mbed/PeriodicTimer.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +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" - -#include "Ticker.h" - - -/*************************************************************************************************/ -PeriodicTimer::PeriodicTimer() -{ - running = false; -} - -/*************************************************************************************************/ -template<typename T> -void PeriodicTimer::start(T* tptr, void (T::*mptr)(void), int timeoutMs) -{ - attach_us(tptr, mptr, timeoutMs*1000); - running = true; -} -template void PeriodicTimer::start<Wiconnect>(Wiconnect* tptr, void (Wiconnect::*mptr)(void), int timeoutMs); -template void PeriodicTimer::start<NetworkInterface>(NetworkInterface* tptr, void (NetworkInterface::*mptr)(void), int timeoutMs); -template void PeriodicTimer::start<SocketInterface>(SocketInterface* tptr, void (SocketInterface::*mptr)(void), int timeoutMs); -template void PeriodicTimer::start<FileInterface>(FileInterface* tptr, void (FileInterface::*mptr)(void), int timeoutMs); - -/*************************************************************************************************/ -void PeriodicTimer::stop(void) -{ - detach(); - running = false; -} - -/*************************************************************************************************/ -bool PeriodicTimer::isRunning() -{ - return running; -}
--- a/sdk/mbed/PinIrqHandler.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +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 "types/PinIrqHandler.h" - - - -/*************************************************************************************************/ -PinIrqHandler::PinIrqHandler(PinName irqPin_, const Callback &callback_) : InterruptIn(irqPin_) -{ - irqPin = irqPin_; - callback = callback_; - mode(PullDown); - rise(this, &PinIrqHandler::irqHandler); - enable_irq(); -} - -/*************************************************************************************************/ -PinIrqHandler::~PinIrqHandler() -{ - disable_irq(); -} - - -/*************************************************************************************************/ -void PinIrqHandler::irqHandler() -{ - callback.call(WICONNECT_SUCCESS, (void*)irqPin, NULL); -}
--- a/sdk/mbed/TimeoutTimer.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +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 "us_ticker_api.h" - -/*************************************************************************************************/ -TimeoutTimer::TimeoutTimer() -{ - _start = 0; - us_ticker_init(); -} - -/*************************************************************************************************/ -void TimeoutTimer::reset(void) -{ - _start = us_ticker_read(); -} - -/*************************************************************************************************/ -uint32_t TimeoutTimer::remainingMs(uint32_t timeoutMs) -{ - const uint32_t diff = readUs() / 1000; - return (timeoutMs > diff) ? timeoutMs - diff : 0; -} - -/*************************************************************************************************/ -uint32_t TimeoutTimer::readUs() -{ - return us_ticker_read() - _start; -} - -/*************************************************************************************************/ -bool TimeoutTimer::timedOut(uint32_t timeoutMs) -{ - timeoutMs *= 1000; - return (timeoutMs <= readUs()); -}
--- a/sdk/mbed/WiconnectSerial.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,197 +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" - -#ifndef WICONNECT_SERIAL_RX_BUFFER -#error WICONNECT_SERIAL_RX_BUFFER NOT defined NOT currently supported -#endif - - - - -typedef struct -{ - uint16_t size; - volatile uint16_t count; - uint8_t *start, *end; - volatile uint8_t *head; - volatile uint8_t *tail; -} SerialRxBuffer; - - -/*************************************************************************************************/ -WiconnectSerial::WiconnectSerial(const SerialConfig &config, Wiconnect *wiconnect) : RawSerial(config.tx, config.rx) -{ - ct_assert(sizeof(ringBuffer) >= sizeof(SerialRxBuffer)); - - baud(config.baud); - - SerialRxBuffer *rxBuffer = (SerialRxBuffer*)ringBuffer; - memset(rxBuffer, 0, sizeof(SerialRxBuffer)); - bufferAlloc = false; - if(config.serialRxBufferSize > 0) - { - if(config.serialRxBuffer != NULL) - { - rxBuffer->start = (uint8_t*)config.serialRxBuffer; - } -#ifdef WICONNECT_ENABLE_MALLOC - else - { - wiconnect_assert(wiconnect, "WiconnectSerial(), malloc not defined", wiconnect->_malloc != NULL); - rxBuffer->start = (uint8_t*)wiconnect->_malloc(config.serialRxBufferSize); - wiconnect_assert(wiconnect, "WiconnectSerial(), malloc failed", rxBuffer->start != NULL); - bufferAlloc = true; - } -#endif - rxBuffer->head = rxBuffer->tail = (volatile uint8_t*)rxBuffer->start; - rxBuffer->end = (uint8_t*)rxBuffer->head + config.serialRxBufferSize; - rxBuffer->size = config.serialRxBufferSize; - attach(this, &WiconnectSerial::rxIrqHandler, SerialBase::RxIrq); - } -} - -/*************************************************************************************************/ -WiconnectSerial::~WiconnectSerial() -{ -#ifdef WICONNECT_ENABLE_MALLOC - if(bufferAlloc) - { - SerialRxBuffer *rxBuffer = (SerialRxBuffer*)ringBuffer; - Wiconnect::getInstance()->_free(rxBuffer->start); - } -#endif -} - -/*************************************************************************************************/ -void WiconnectSerial::flush(void) -{ - while (readable()) - { - int c = getc(); - } - - SerialRxBuffer *rxBuffer = (SerialRxBuffer*)ringBuffer; - rxBuffer->tail = rxBuffer->head = rxBuffer->start; - rxBuffer->count = 0; -} - -/*************************************************************************************************/ -int WiconnectSerial::write(const void *data, int bytesToWrite, int timeoutMs) -{ - uint8_t *ptr = (uint8_t*)data; - int remaining = bytesToWrite; - - while(remaining > 0) - { - if(!writeable()) - { - timeoutTimer.reset(); - while(!writeable()) - { - if(timeoutMs == 0) - { - if(timeoutTimer.readUs() >= 500) - { - goto exit; - } - } - else - { - if(timeoutTimer.readUs() >= timeoutMs*1000) - { - goto exit; - } - } - } - } - - putc(*ptr); - ++ptr; - --remaining; - } - - exit: - return bytesToWrite - remaining; -} - -/*************************************************************************************************/ -int WiconnectSerial::read(void *data, int bytesToRead, int timeoutMs) -{ - SerialRxBuffer *rxBuffer = (SerialRxBuffer*)ringBuffer; - uint8_t *ptr = (uint8_t*)data; - int remaining = bytesToRead; - - while(remaining > 0) - { - if(rxBuffer->count == 0) - { - if(timeoutMs == 0) - { - break; - } - else - { - timeoutTimer.reset(); - while(rxBuffer->count == 0) - { - if(timeoutTimer.readUs() >= timeoutMs*1000) - { - goto exit; - } - } - } - } - - *ptr++ = *rxBuffer->tail++; - --remaining; - --rxBuffer->count; - if(rxBuffer->tail >= rxBuffer->end) - rxBuffer->tail = rxBuffer->start; - } - -exit: - return bytesToRead - remaining; -} - -/*************************************************************************************************/ -void WiconnectSerial::rxIrqHandler(void) -{ - SerialRxBuffer *rxBuffer = (SerialRxBuffer*)ringBuffer; - - while (readable() && rxBuffer->count < rxBuffer->size) - { - *rxBuffer->head++ = (uint8_t)getc(); - ++rxBuffer->count; - if(rxBuffer->head >= rxBuffer->end) - rxBuffer->head = rxBuffer->start; - } -}
--- a/sdk/mbed/sdk.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,185 +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 - - -#define MBED_SDK - -#include "mbed.h" - - - - -namespace wiconnect -{ - -/** - * @ingroup api_core_macro - * @brief When defined enables asynchronous command processing - */ -#define WICONNECT_ASYNC_TIMER_ENABLED -/** - * @ingroup api_core_macro - * @brief When defined enables user supplied dynamic memory allocation - */ -#define WICONNECT_ENABLE_MALLOC -/** - * @ingroup api_core_macro - * @brief When defined enables Host<->Wiconnect Module serial RX buffering - */ -#define WICONNECT_SERIAL_RX_BUFFER -/** - * @ingroup api_core_macro - * @brief When defined enables certain conversion API functions to use a default buffer to store string - */ -#define WICONNECT_USE_DEFAULT_STRING_BUFFERS - -/** - * @ingroup api_core_macro - * @brief When WICONNECT_ENABLE_MALLOC defined, this is the default malloc function - */ -#define WICONNECT_DEFAULT_MALLOC malloc -/** - * @ingroup api_core_macro - * @brief When WICONNECT_ENABLE_MALLOC defined, this is the default free function - */ -#define WICONNECT_DEFAULT_FREE free - -/** - * @ingroup api_core_macro - * @brief The default Host<->Wiconnect Module serial BAUD rate - */ -#define WICONNECT_DEFAULT_BAUD 115200 -/** - * @ingroup api_core_macro - * @brief The default command timeout (i.e max command executing time) - */ -#define WICONNECT_DEFAULT_TIMEOUT 3000 // ms -/** - * @ingroup api_core_macro - * @brief When WICONNECT_ASYNC_TIMER_ENABLED, this specifies the max number of asynchronous commands that may be queued - */ -#define WICONNECT_MAX_QUEUED_COMMANDS 8 -/** - * @ingroup api_core_macro - * @brief When WICONNECT_ASYNC_TIMER_ENABLED, this specifies the period in milliseconds commands should be processed - */ -#define WICONNECT_DEFAULT_COMMAND_PROCESSING_PERIOD 50 // ms - -/** - * @ingroup api_core_macro - * @brief The default blocking mode of the Library. - */ -#define WICONNECT_DEFAULT_NONBLOCKING false - - - -// ---------------------------------------------------------------------------- - -#define WICONNECT_GPIO_BASE_CLASS : DigitalOut -#define WICONNECT_SERIAL_BASE_CLASS : RawSerial -#define WICONNECT_PERIODIC_TIMER_BASE_CLASS : Ticker -#define WICONNECT_EXTERNAL_INTERRUPT_GPIO_BASE_CLASS : InterruptIn - -#define WICONNECT_MAX_PIN_IRQ_HANDLERS 3 - - -/** - * @ingroup api_core_macro - * @brief Default value for a pin, Not connected - */ -#define PIN_NC NC - -/** - * @ingroup api_core_types - * @brief Pin name on HOST - */ -typedef PinName Pin; - -/** - * @ingroup api_core_types - * @brief Host<->Wiconnect Module serial configuration - */ -class SerialConfig -{ -public: - Pin rx; - Pin tx; - Pin cts; - Pin rts; - int baud; - void *serialRxBuffer; - int serialRxBufferSize; - - SerialConfig(Pin rx, Pin tx, Pin cts, Pin rts, int baud, int serialRxBufferSize, void *serialRxBuffer = NULL) - { - this->rx =rx; - this->tx =tx; - this->cts =cts; - this->rts =rts; - this->baud = baud; - this->serialRxBuffer =serialRxBuffer; - this->serialRxBufferSize =serialRxBufferSize; - } - - SerialConfig(Pin rx, Pin tx, int serialRxBufferSize, void *serialRxBuffer = NULL) - { - this->rx =rx; - this->tx =tx; - this->cts = PIN_NC; - this->rts = PIN_NC; - this->baud = WICONNECT_DEFAULT_BAUD; - this->serialRxBuffer =serialRxBuffer; - this->serialRxBufferSize =serialRxBufferSize; - } - - SerialConfig(Pin rx, Pin tx) - { - this->rx =rx; - this->tx =tx; - this->cts =PIN_NC; - this->rts =PIN_NC; - this->baud = WICONNECT_DEFAULT_BAUD; - this->serialRxBuffer =NULL; - this->serialRxBufferSize =0; - } - -}; - - -/** - * @ingroup api_core_macro - * @brief Function to stop processor for specified number of milliseconds - */ -#define delayMs(ms) wait_ms(ms) - - - - -}
--- a/sdk/mbed/sdkTypes.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +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 "types/Socket/mBedSocketApi.h"
--- a/sdk/mbed/target_config.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +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 - - -// The BAUD rate your PC/MAC/Linux terminal uses with the eval board -#define CONSOLE_BAUD 115200 - - -// Uncomment this to enable WiConnect serial interface hardware flow control -// NOTE: your platform must support the serial flow control api functions -//#define ENABLE_FLOW_CONTROL - - -#define WICONNECT_INTERNAL_BUFFER_SIZE (4*1024) -#define WICONNECT_SERIAL_RX_BUFFER_SIZE (4*1024) - -#define DEFAULT_CMD_GETCHAR_TIMEOUT 250 -#define DEFAULT_COMMAND_LINE_LENGTH_MAX 128 -#define DEFAULT_COMMAND_MAX_HISTORY 16 -#define DEFAULT_CMD_PROMPT_STR "> " -#define DEFAULT_COMMAND_MAX_ARGV 16 - -#define TEST_NONBLOCKING_API false -#define TEST_BUFFER_LENGTH 4*1024 - - -//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// Seabass Target Configuration -#ifdef TARGET_SEABASS - -#define WICONNECT_TX_PIN PA_9 -#define WICONNECT_RX_PIN PA_10 -#define WICONNECT_RESET_PIN PB_0 -#define WICONNECT_WAKE_PIN NC - -#ifdef ENABLE_FLOW_CONTROL -#define WICONNECT_CTS_PIN PA_11 -#define WICONNECT_RTS_PIN PA_12 -#else -#define WICONNECT_CTS_PIN NC -#define WICONNECT_RTS_PIN NC -#endif - -#endif - - -//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// Nucleo F401RE Target Configuration -#ifdef TARGET_NUCLEO_F401RE - -#define WICONNECT_TX_PIN PA_9 -#define WICONNECT_RX_PIN PA_10 -#define WICONNECT_RESET_PIN PC_7 -#define WICONNECT_WAKE_PIN NC - -#ifdef ENABLE_FLOW_CONTROL -#define WICONNECT_CTS_PIN PA_11 -#define WICONNECT_RTS_PIN PA_12 -#else -#define WICONNECT_CTS_PIN NC -#define WICONNECT_RTS_PIN NC -#endif - -#endif -
--- a/types/Callback.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +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" -#include "FunctionPointer.h" - - - -namespace wiconnect -{ - - -typedef void (*_Callback)(WiconnectResult result, void *arg1, void *arg2); - - -/** - * @ingroup api_core_types - * - * @brief Generic callback function. - */ -class Callback : public FunctionPointer -{ -public: - /*************************************************************************************************/ - Callback(_Callback func = 0) - { - _function = (void*)func; - _membercaller = NULL; - _object = NULL; - } - - /*************************************************************************************************/ - template<typename T> - Callback(T *object, void (T::*member)(WiconnectResult result, void *arg1, void *arg2)) - { - _object = static_cast<void*>(object); - memcpy(_member, (char*)&member, sizeof(member)); - _membercaller = (void*)&Callback::membercaller<T>; - _function = 0; - } - - /*************************************************************************************************/ - void call(WiconnectResult result, void *arg1, void *arg2) - { - if (_function) - { - ((_Callback)_function)(result, arg1, arg2); - } - else if (_object) - { - typedef void (*membercallerFunc)(void*, char*, WiconnectResult result, void *arg1, void *arg2); - ((membercallerFunc)_membercaller)(_object, _member, result, arg1, arg2); - } - } - -private: - - /*************************************************************************************************/ - template<typename T> - static void membercaller(void *object, char *member, WiconnectResult result, void *arg1, void *arg2) - { - T* o = static_cast<T*>(object); - void (T::*m)(WiconnectResult result, void *arg1, void *arg2); - memcpy((char*)&m, member, sizeof(m)); - (o->*m)(result, arg1, arg2); - } - -}; - - -}
--- a/types/CommandQueue.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +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 -{ - -/** - * Class for hold queued commands - * - * @note Internal use only - */ -class CommandQueue -{ -public: - /*************************************************************************************************/ - CommandQueue() - { - head = tail = queue; - count = 0; - } - - /*************************************************************************************************/ - bool isFull() - { - return count == WICONNECT_MAX_QUEUED_COMMANDS; - } - - /*************************************************************************************************/ - bool isEmpty() - { - return count == 0; - } - - /*************************************************************************************************/ - bool push(QueuedCommand *cmd) - { - if(isFull()) - { - return false; - } - ++count; - *tail = cmd; - if(++tail >= queue + WICONNECT_MAX_QUEUED_COMMANDS) - { - tail = queue; - } - - return true; - } - - /*************************************************************************************************/ - QueuedCommand* pop() - { - if(isEmpty()) - return NULL; - - QueuedCommand* cmd = *head; - --count; - if(++head >= queue + WICONNECT_MAX_QUEUED_COMMANDS) - { - head = queue; - } - return cmd; - } - -protected: - QueuedCommand* queue[WICONNECT_MAX_QUEUED_COMMANDS]; - QueuedCommand** head; - QueuedCommand** tail; - int count; -}; - - - - -}
--- a/types/FileList.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +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" -#include "types/WiconnectFile.h" - -namespace wiconnect -{ - -/** - * @ingroup api_file_types - * - * @brief WiConnect WiFi module file listing. - * - */ -class FileList -{ -public: - FileList(int bufferLen = 0, void *buffer = NULL); - ~FileList(); - - const WiconnectFile* getListHead() const; - int getCount() const; - const WiconnectFile* getResult(int i) const; - const WiconnectFile* operator [](int i) const; - -protected: - WiconnectFile *listHead, *listTail; - uint8_t *buffer; - uint8_t *bufferPtr; - int bufferLen; - int count; - - WiconnectResult add(const char *typeStr, const char *flagsStr, const char* sizeStr, const char *versionStr, const char *nameStr); - - friend class FileInterface; -}; - - -}
--- a/types/FunctionPointer.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +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 - - -namespace wiconnect -{ - - -/** - * @brief Generic function pointer. - * @note Internal use only - */ -class FunctionPointer -{ -public: - /*************************************************************************************************/ - FunctionPointer& operator=( const FunctionPointer& other ) - { - _object = other._object; - _function = other._function; - _membercaller = other._membercaller; - memcpy(_member, other._member, sizeof(_member)); - return *this; - } - - /*************************************************************************************************/ - bool isValid() const - { - return (_function != NULL) || (_object != NULL); - } - - /*************************************************************************************************/ - void setInvalid() - { - _function = NULL; - _object = NULL; - } - -protected: - void *_object; - void *_function; - char _member[16]; - void *_membercaller; -}; - -}
--- a/types/Gpio.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +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 -{ - -/** - * Host GPIO class. - * - * @note Internal use only - */ -class Gpio WICONNECT_GPIO_BASE_CLASS -{ -public: - Gpio(Pin pin); - - void write(bool value); - - bool read(void); - - Gpio& operator= (bool value); - - Gpio& operator= (const Gpio& other); - -}; - - -}
--- a/types/LogFunc.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,100 +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" -#include "FunctionPointer.h" - -namespace wiconnect -{ - -typedef int (*_LogFunc)(const char *str); - - -/** - * @ingroup api_core_types - * - * @brief Logging callback function. - */ -class LogFunc : public FunctionPointer -{ -public: - /*************************************************************************************************/ - LogFunc(_LogFunc func = 0) - { - _function = (void*)func; - _membercaller = NULL; - _object = NULL; - } - - /*************************************************************************************************/ - template<typename T> - LogFunc(T *object, WiconnectResult (T::*member)(const char *str)) - { - _object = static_cast<void*>(object); - memcpy(_member, (char*)&member, sizeof(member)); - _membercaller = (void*)&LogFunc::membercaller<T>; - _function = 0; - } - - /*************************************************************************************************/ - int call(const char *str) - { - if (_function) - { - return ((_LogFunc)_function)(str); - } - else if (_object) - { - typedef int (*membercallerFunc)(void*, char*, const char *str); - return ((membercallerFunc)_membercaller)(_object, _member, str); - } - else - { - return -1; - } - } - -private: - - /*************************************************************************************************/ - template<typename T> - static int membercaller(void *object, char *member, const char *str) - { - T* o = static_cast<T*>(object); - int (T::*m)(const char *str); - memcpy((char*)&m, member, sizeof(m)); - return (o->*m)(str); - } -}; - - - - -}
--- a/types/PeriodicTimer.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +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 -{ - -/** - * Class for periodically calling a supplied callback. - * - * @note Internal use only - */ -class PeriodicTimer WICONNECT_PERIODIC_TIMER_BASE_CLASS -{ -public: - PeriodicTimer(); - - template<typename T> - void start(T* tptr, void (T::*mptr)(void), int timeoutMs); - void stop(void); - bool isRunning(); -protected: - bool running; -}; - - -}
--- a/types/PinIrqHandler.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +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 -{ - - -class SocketIrqHandlerMap; - -/** - * Class for handlinga Pin IRQ. - * - * @note Internal use only - */ -class PinIrqHandler WICONNECT_EXTERNAL_INTERRUPT_GPIO_BASE_CLASS -{ -public: - PinIrqHandler(Pin irqPin, const Callback &callback); - virtual ~PinIrqHandler(); - - void irqHandler(); - -protected: - PinName irqPin; - Callback callback; - - friend class SocketIrqHandlerMap; -}; - - -typedef uint8_t PinIrqHandlerBuffer[sizeof(PinIrqHandler)]; - -}
--- a/types/QueuedCommand.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +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_core_types - * - * @brief Class which contains command for asynchronous processing. - */ - -class QueuedCommand -{ -public: - void *userData; - - - QueuedCommand(int responseBufferLen, char *responseBuffer, int timeoutMs, const ReaderFunc &reader, void *user, const char *cmd, va_list vaList); - QueuedCommand(int responseBufferLen, char *responseBuffer, int timeoutMs, const char *cmd, ...); - QueuedCommand(int responseBufferLen, char *responseBuffer, const char *cmd, ...); - QueuedCommand(int timeoutMs_, const char *cmd, ...); - QueuedCommand(const char *cmd, ...); - ~QueuedCommand(); - - char *getResponseBuffer(); - int getResponseBufferLen(); - int getTimeoutMs(); - ReaderFunc getReader(); - void * getReaderUserData(); - char* getCommand(); - Callback getCompletedCallback(); - void setCompletedCallback(const Callback &cb); - - QueuedCommand& operator=( const QueuedCommand& other ); - void* operator new(size_t size); - void operator delete(void*); - -protected: - char *responseBuffer; - int responseBufferLen; - int timeoutMs; - ReaderFunc reader; - void *user; - char command[WICONNECT_MAX_CMD_SIZE]; - Callback completeCallback; -#ifdef WICONNECT_ENABLE_MALLOC - bool allocatedBuffer; -#endif - friend class NetworkInterface; - friend class Wiconnect; - - void initialize(int responseBufferLen, char *responseBuffer_, int timeoutMs_, const ReaderFunc &reader_, void *user_, const char *cmd_, va_list vaList); -}; - - - -}
--- a/types/ReaderFunc.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +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" -#include "FunctionPointer.h" - - -namespace wiconnect -{ - -typedef WiconnectResult (*_ReaderFunc)(void *user, void *data, int maxReadSize, int *bytesRead); - -/** - * @ingroup api_core_types - * - * @brief Generic data reading callback function. - */ -class ReaderFunc : public FunctionPointer -{ -public: - - /*************************************************************************************************/ - ReaderFunc(_ReaderFunc func = 0) - { - _function = (void*)func; - _membercaller = NULL; - _object = NULL; - } - - /*************************************************************************************************/ - template<typename T> - ReaderFunc(T *object, WiconnectResult (T::*member)(void *user, void *data, int maxReadSize, int *bytesRead)) - { - _object = static_cast<void*>(object); - memcpy(_member, (char*)&member, sizeof(member)); - _membercaller = (void*)&ReaderFunc::membercaller<T>; - _function = 0; - } - - /*************************************************************************************************/ - WiconnectResult call(void *user, void *data, int maxReadSize, int *bytesRead) - { - if (_function) - { - return ((_ReaderFunc)_function)(user, data, maxReadSize, bytesRead); - } - else if (_object) - { - typedef WiconnectResult (*membercallerFunc)(void*, char*, void *user, void *data, int maxReadSize, int *bytesRead); - return ((membercallerFunc)_membercaller)(_object, _member, user, data, maxReadSize, bytesRead); - } - else - { - return WICONNECT_ERROR; - } - } - -private: - - /*************************************************************************************************/ - template<typename T> - static WiconnectResult membercaller(void *object, char *member, void *user, void *data, int maxReadSize, int *bytesRead) - { - T* o = static_cast<T*>(object); - WiconnectResult (T::*m)(void *user, void *data, int maxReadSize, int *bytesRead); - memcpy((char*)&m, member, sizeof(m)); - return (o->*m)(user, data, maxReadSize, bytesRead); - } -}; - -}
--- a/types/ScanResult.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +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" -#include "StringUtil.h" - - -namespace wiconnect -{ - -/** - * @ingroup api_network_types - * - * @brief Contains single entry from WiFi scan results - * - */ -class ScanResult -{ -public: - uint8_t getChannel() const; - NetworkSignalStrength getSignalStrength() const; - const MacAddress* getMacAddress() const; - NetworkSecurity getSecurityType() const; - uint32_t getRate() const; - const char* getRateStr(char *buffer = NULL) const; - const Ssid* getSsid() const; - - const ScanResult* getNext() const; - const ScanResult* getPrevious() const; - -protected: - ScanResult(); - - WiconnectResult init(const char *channelStr, const char *rssiStr, const char* macStr, const char *rateStr, const char *secStr, const char *ssidStr); - ScanResult *next; - ScanResult *previous; - uint8_t channel; - int16_t rssi; - MacAddress mac; - uint32_t rate; - NetworkSecurity security; - Ssid ssid; - - void* operator new(size_t size); - void operator delete(void*); - - friend class ScanResultList; -}; - - - - - - -}
--- a/types/ScanResultList.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +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" -#include "types/ScanResult.h" - - - -namespace wiconnect -{ - - -/** - * @ingroup api_network_types - * - * @brief List of WiFi network scan results. - * - */ -class ScanResultList -{ -public: - ScanResultList(int bufferLen = 0, void *buffer = NULL); - ~ScanResultList(); - - const ScanResult* getListHead() const; - int getCount() const; - const ScanResult* getResult(int i) const; - const ScanResult* operator [](int i) const; - -protected: - ScanResult *listHead, *listTail; - uint8_t *buffer; - uint8_t *bufferPtr; - int bufferLen; - int count; - - WiconnectResult add(const char *channelStr, const char *rssiStr, const char* macStr, const char *rateStr, const char *secStr, const char *ssidStr); - - - friend class NetworkInterface; -}; - - -}
--- a/types/Socket/Endpoint.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef ENDPOINT_H -#define ENDPOINT_H - - -#include "types/Socket/lwip/sockets.h" - - -class UDPSocket; - -/** -IP Endpoint (address, port) -*/ -class Endpoint { - friend class UDPSocket; - -public: - /** IP Endpoint (address, port) - */ - Endpoint(void); - - ~Endpoint(void); - - /** Reset the address of this endpoint - */ - void reset_address(void); - - /** Set the address of this endpoint - \param host The endpoint address (it can either be an IP Address or a hostname that will be resolved with DNS). - \param port The endpoint port - \return 0 on success, -1 on failure (when an hostname cannot be resolved by DNS). - */ - int set_address(const char* host, const int port); - - /** Get the IP address of this endpoint - \return The IP address of this endpoint. - */ - char* get_address(void); - - /** Get the port of this endpoint - \return The port of this endpoint - */ - int get_port(void); - -protected: - char _ipAddress[17]; - struct sockaddr_in _remoteHost; - -}; - -#endif
--- a/types/Socket/Socket.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,98 +0,0 @@ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef SOCKET_H_ -#define SOCKET_H_ - - -#include "types/Socket/lwip/sockets.h" -#include "types/Socket/lwip/netdb.h" -#include "WiconnectTypes.h" -#include "types/WiconnectSocket.h" - - -using namespace wiconnect; - - -#define SOCKET_API_DEFAULT_RX_BUFFER_SIZE 128 -#define SOCKET_API_DEFAULT_TX_BUFFER_SIZE 128 - - -int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop); -struct hostent *gethostbyname(const char *name); - - - - -/** Socket file descriptor and select wrapper - */ -class Socket { -public: - /** Socket - */ - Socket(); - Socket(int rxBufferLen, void *rxBuffer, int txBufferLen, void *txBuffer); - - /** Set blocking or non-blocking mode of the socket and a timeout on - blocking socket operations - - \note Currently the blocking/timeout functionality is only supported - for 'read' methods - \param blocking true for blocking mode, false for non-blocking mode. - \param timeout timeout in ms [Default: (1500)ms]. - */ - void set_blocking(bool blocking, unsigned int timeout=1500); - - /** Set socket options - * - * \note NOT supported in this version. - * - \param level stack level (see: lwip/sockets.h) - \param optname option ID - \param optval option value - \param socklen_t length of the option value - \return 0 on success, -1 on failure - */ - int set_option(int level, int optname, const void *optval, socklen_t optlen); - - /** Get socket options - * - * \note NOT supported in this version. - * - \param level stack level (see: lwip/sockets.h) - \param optname option ID - \param optval buffer pointer where to write the option value - \param socklen_t length of the option value - \return 0 on success, -1 on failure - */ - int get_option(int level, int optname, void *optval, socklen_t *optlen); - - /** Close the socket - \param shutdown free the left-over data in message queues - */ - int close(bool shutdown=true); - - ~Socket(); - -protected: - bool _blocking; - unsigned int _timeout; - - WiconnectSocket socket; -}; - -#endif /* SOCKET_H_ */
--- a/types/Socket/TCPSocketConnection.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef TCPSOCKET_H -#define TCPSOCKET_H - -#include "types/Socket/Socket.h" -#include "types/Socket/Endpoint.h" - -/** -TCP socket connection -*/ -class TCPSocketConnection : public Socket, public Endpoint { - friend class TCPSocketServer; - -public: - /** TCP socket connection - */ - TCPSocketConnection(int rxBufferLen = SOCKET_API_DEFAULT_RX_BUFFER_SIZE, void *rxBuffer = NULL, int txBufferLen = SOCKET_API_DEFAULT_TX_BUFFER_SIZE, void *txBuffer = NULL); - - /** Connects this TCP socket to the server - \param host The host to connect to. It can either be an IP Address or a hostname that will be resolved with DNS. - \param port The host's port to connect to. - \return 0 on success, -1 on failure. - */ - int connect(const char* host, const int port); - - /** Check if the socket is connected - \return true if connected, false otherwise. - */ - bool is_connected(void); - - /** Send data to the remote host. - \param data The buffer to send to the host. - \param length The length of the buffer to send. - \return the number of written bytes on success (>=0) or -1 on failure - */ - int send(char* data, int length); - - /** Send all the data to the remote host. - \param data The buffer to send to the host. - \param length The length of the buffer to send. - \return the number of written bytes on success (>=0) or -1 on failure - */ - int send_all(char* data, int length); - - /** Receive data from the remote host. - \param data The buffer in which to store the data received from the host. - \param length The maximum length of the buffer. - \return the number of received bytes on success (>=0) or -1 on failure - */ - int receive(char* data, int length); - - /** Receive all the data from the remote host. - \param data The buffer in which to store the data received from the host. - \param length The maximum length of the buffer. - \return the number of received bytes on success (>=0) or -1 on failure - */ - int receive_all(char* data, int length); - - -}; - -#endif
--- a/types/Socket/TCPSocketServer.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef TCPSOCKETSERVER_H -#define TCPSOCKETSERVER_H - -#include "types/Socket/Socket.h" -#include "types/Socket/TCPSocketConnection.h" - -/** TCP Server. - * - * - * - * NOTE: This class is not currently supported - * - * - * - */ -class TCPSocketServer : public Socket { - public: - /** Instantiate a TCP Server. - */ - TCPSocketServer(); - - /** Bind a socket to a specific port. - \param port The port to listen for incoming connections on. - \return 0 on success, -1 on failure. - */ - int bind(int port); - - /** Start listening for incoming connections. - \param backlog number of pending connections that can be queued up at any - one time [Default: 1]. - \return 0 on success, -1 on failure. - */ - int listen(int backlog=1); - - /** Accept a new connection. - \param connection A TCPSocketConnection instance that will handle the incoming connection. - \return 0 on success, -1 on failure. - */ - int accept(TCPSocketConnection& connection); -}; - -#endif
--- a/types/Socket/UDPSocket.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,93 +0,0 @@ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef UDPSOCKET_H -#define UDPSOCKET_H - -#include "types/Socket/Socket.h" -#include "types/Socket/Endpoint.h" - -/** -UDP Socket -*/ -class UDPSocket : public Socket { - -public: - /** Instantiate an UDP Socket. - */ - UDPSocket(int rxBufferLen = SOCKET_API_DEFAULT_RX_BUFFER_SIZE, void *rxBuffer = NULL, int txBufferLen = SOCKET_API_DEFAULT_TX_BUFFER_SIZE, void *txBuffer = NULL); - - /** Init the UDP Client Socket without binding it to any specific port - \return 0 on success, -1 on failure. - */ - int init(void); - - /** Bind a UDP Server Socket to a specific port - \param port The port to listen for incoming connections on - \return 0 on success, -1 on failure. - */ - int bind(int port); - - /** Join the multicast group at the given address - * - * \note This is not currently supported. - * - \param address The address of the multicast group - \return 0 on success, -1 on failure. - */ - int join_multicast_group(const char* address); - - /** Set the socket in broadcasting mode - * - * \note Broadcasting is always enabled, so this - * doesn't do anything useful. - * - \return 0 on success, -1 on failure. - */ - int set_broadcasting(bool broadcast=true); - - /** Send a packet to a remote endpoint - * - * \note Currently only one remote client address is supported - * - \param remote The remote endpoint - \param packet The packet to be sent - \param length The length of the packet to be sent - \return the number of written bytes on success (>=0) or -1 on failure - */ - int sendTo(Endpoint &remote, char *packet, int length); - - /** Receive a packet from a remote endpoint - * - * \note Currently only one remote client address is supported - * - * - \param remote The remote endpoint - \param buffer The buffer for storing the incoming packet data. If a packet - is too long to fit in the supplied buffer, excess bytes are discarded - \param length The length of the buffer - \return the number of received bytes on success (>=0) or -1 on failure - */ - int receiveFrom(Endpoint &remote, char *buffer, int length); - - -private: - int localPort; -}; - -#endif
--- a/types/Socket/internal/Endpoint.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#include "types/Socket/Socket.h" -#include "types/Socket/Endpoint.h" -#include <cstring> -#include <cstdio> - - - -/*************************************************************************************************/ -Endpoint::Endpoint() -{ - reset_address(); -} - -/*************************************************************************************************/ -Endpoint::~Endpoint() {} - -/*************************************************************************************************/ -void Endpoint::reset_address(void) -{ - std::memset(&_remoteHost, 0, sizeof(struct sockaddr_in)); - _ipAddress[0] = '\0'; -} - -/*************************************************************************************************/ -int Endpoint::set_address(const char* host, const int port) -{ - reset_address(); - - // IP Address - char address[5]; - char *p_address = address; - - // Dot-decimal notation - int result = std::sscanf(host, "%3u.%3u.%3u.%3u", - (unsigned int*)&address[0], (unsigned int*)&address[1], - (unsigned int*)&address[2], (unsigned int*)&address[3]); - - if (result != 4) - { - // Resolve address with DNS - struct hostent *host_address = gethostbyname(host); - if (host_address == NULL) - return -1; //Could not resolve address - p_address = (char*)host_address->h_addr_list[0]; - } - std::memcpy((char*)&_remoteHost.sin_addr.s_addr, p_address, 4); - - // Address family - _remoteHost.sin_family = AF_INET; - - // Set port - _remoteHost.sin_port = htons(port); - - return 0; -} - -/*************************************************************************************************/ -char* Endpoint::get_address() -{ - if ((_ipAddress[0] == '\0') && (_remoteHost.sin_addr.s_addr != 0)) - inet_ntoa_r(_remoteHost.sin_addr, _ipAddress, sizeof(_ipAddress)); - return _ipAddress; -} - -/*************************************************************************************************/ -int Endpoint::get_port() -{ - return ntohs(_remoteHost.sin_port); -}
--- a/types/Socket/internal/Socket.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +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 "types/Socket/Socket.h" -#include "common.h" - - - - -/*************************************************************************************************/ -Socket::Socket() : _blocking(true), _timeout(1500) -{ -} - -/*************************************************************************************************/ -Socket::Socket(int rxBufferLen, void *rxBuffer, int txBufferLen, void *txBuffer) : - _blocking(true), _timeout(1500), socket(rxBufferLen, rxBuffer, txBufferLen, txBuffer) -{ - -} - -/*************************************************************************************************/ -Socket::~Socket() -{ - close(true); -} - -/*************************************************************************************************/ -void Socket::set_blocking(bool blocking, unsigned int timeout) -{ - _blocking = blocking; - _timeout = timeout; -} - -/*************************************************************************************************/ -int Socket::set_option(int level, int optname, const void *optval, socklen_t optlen) -{ - return -1; -} - -/*************************************************************************************************/ -int Socket::get_option(int level, int optname, void *optval, socklen_t *optlen) -{ - return -1; -} - -/*************************************************************************************************/ -int Socket::close(bool shutdown) -{ - return (socket.close() == WICONNECT_SUCCESS) ? 0 : -1; -} - -
--- a/types/Socket/internal/TCPSocketConnection.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,141 +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 "types/Socket/TCPSocketConnection.h" -#include "common.h" - - - -/*************************************************************************************************/ -TCPSocketConnection::TCPSocketConnection(int rxBufferLen, void *rxBuffer, int txBufferLen, void *txBuffer) -: Socket(rxBufferLen, rxBuffer, txBufferLen, txBuffer) -{ -} - -/*************************************************************************************************/ -int TCPSocketConnection::connect(const char* host, const int port) -{ - return (Wiconnect::getInstance()->tcpConnect(socket, host, (uint16_t)port) == WICONNECT_SUCCESS) ? 0 : -1; -} - -/*************************************************************************************************/ -bool TCPSocketConnection::is_connected(void) -{ - return socket.isConnected(); -} - -/*************************************************************************************************/ -// currently there's no way to timeout writing data to WiConnect, so we just have to try and send it all. -// NOTE: this WILL be fixed in the next version -int TCPSocketConnection::send(char* data, int length) -{ - return send_all(data, length); -} - -/*************************************************************************************************/ -// -1 if unsuccessful, else number of bytes written -int TCPSocketConnection::send_all(char* data, int length) -{ - return (socket.write(data, length, true) == WICONNECT_SUCCESS) ? length : -1; -} - -/*************************************************************************************************/ -int TCPSocketConnection::receive(char* data, int length) -{ - uint16_t bytesRead; - - if (!_blocking) - { - if(socket.getRxBufferSize() == 0 || socket.getRxBufferBytesPending() == 0) - { - TimeoutTimer timer; - - for(;;) - { - bool hasData; - - if(socket.poll(&hasData) != WICONNECT_SUCCESS) - { - return -1; - } - else if(hasData) - { - break; - } - else if(timer.timedOut(_timeout)) - { - return -1; - } - } - } - } - - if(length == 1 && socket.getRxBufferSize() > 0) - { - return (socket.getc((uint8_t*)data) == WICONNECT_SUCCESS) ? 1 : -1; - } - else - { - for(;;) - { - if(socket.read(data, length, &bytesRead) != WICONNECT_SUCCESS) - { - return -1; - } - else if(bytesRead > 0) - { - return bytesRead; - } - } - } -} - -/*************************************************************************************************/ -// -1 if unsuccessful, else number of bytes received -int TCPSocketConnection::receive_all(char* data, int length) -{ - char *ptr = data; - int totReadSize = length; - - while(length > 0) - { - int bytesRead = receive(ptr, length); - if(bytesRead == -1) - { - return -1; - } - ptr += bytesRead; - length -= bytesRead; - } - - return totReadSize; -} - -
--- a/types/Socket/internal/TCPSocketServer.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +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 "types/Socket/TCPSocketServer.h" -#include "common.h" - - -/*************************************************************************************************/ -TCPSocketServer::TCPSocketServer() -{ -} - - -/*************************************************************************************************/ -int TCPSocketServer::bind(int port) -{ - return -1; -} - -/*************************************************************************************************/ -int TCPSocketServer::listen(int max) -{ - return -1; -} - -/*************************************************************************************************/ -int TCPSocketServer::accept(TCPSocketConnection& connection) -{ - return -1; -}
--- a/types/Socket/internal/UDPSocket.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,140 +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 "types/Socket/UDPSocket.h" -#include "common.h" - - -/*************************************************************************************************/ -UDPSocket::UDPSocket(int rxBufferLen, void *rxBuffer, int txBufferLen, void *txBuffer) -: Socket(rxBufferLen, rxBuffer, txBufferLen, txBuffer), localPort(SOCKET_ANY_PORT) -{ -} - -/*************************************************************************************************/ -int UDPSocket::init(void) -{ - return 0; -} - -/*************************************************************************************************/ -// Server initialization -int UDPSocket::bind(int port) -{ - localPort = port; - return 0; -} - -/*************************************************************************************************/ -int UDPSocket::join_multicast_group(const char* address) -{ - return -1; -} - -/*************************************************************************************************/ -int UDPSocket::set_broadcasting(bool broadcast) -{ - return 0; -} - -/*************************************************************************************************/ -// -1 if unsuccessful, else number of bytes written -int UDPSocket::sendTo(Endpoint &remote, char *packet, int length) -{ - if(!socket.isConnected()) - { - if(Wiconnect::getInstance()->udpConnect(socket, remote.get_address(), remote.get_port(), localPort) != WICONNECT_SUCCESS) - { - return -1; - } - } - return (socket.write(packet, length, true) == WICONNECT_SUCCESS) ? length : -1; -} - -/*************************************************************************************************/ -// -1 if unsuccessful, else number of bytes received -int UDPSocket::receiveFrom(Endpoint &remote, char *buffer, int length) -{ - uint16_t bytesRead; - - if(!socket.isConnected()) - { - if(Wiconnect::getInstance()->udpConnect(socket, remote._ipAddress, remote.get_port(), localPort) != WICONNECT_SUCCESS) - { - return -1; - } - } - - if (!_blocking) - { - if(socket.getRxBufferSize() == 0 || socket.getRxBufferBytesPending() == 0) - { - TimeoutTimer timer; - - for(;;) - { - bool hasData; - - if(socket.poll(&hasData) != WICONNECT_SUCCESS) - { - return -1; - } - else if(hasData) - { - break; - } - else if(timer.timedOut(_timeout)) - { - return -1; - } - } - } - } - - if(length == 1 && socket.getRxBufferSize() > 0) - { - return (socket.getc((uint8_t*)buffer) == WICONNECT_SUCCESS) ? 1 : -1; - } - else - { - for(;;) - { - if(socket.read(buffer, length, &bytesRead) != WICONNECT_SUCCESS) - { - return -1; - } - else if(bytesRead > 0) - { - return bytesRead; - } - } - } - -}
--- a/types/Socket/internal/common.cpp Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/* - * Copyright 2014, ACKme Networks - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of ACKme Networks; - * the contents of this file may not be disclosed to third parties, copied - * or duplicated in any form, in whole or in part, without the prior - * written permission of ACKme Networks. - */ - - - -#include "types/Socket/Socket.h" -#include "common.h" - - -/*************************************************************************************************/ -int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) -{ - return -1; -} - -/*************************************************************************************************/ -struct hostent *gethostbyname(const char *name) -{ - static uint8_t buffer[sizeof(struct hostent) + sizeof(void*)*3 + 1*sizeof(uint32_t)]; - struct hostent *hostPtr = (struct hostent*)buffer; - char **ipPtrList = (char**)&buffer[sizeof(struct hostent)]; - char **aliasPtrList = (char**)&buffer[sizeof(struct hostent) + sizeof(void*)*2]; - uint32_t *ipPtr = (uint32_t*)&buffer[sizeof(struct hostent) + sizeof(void*)*3]; - - - hostPtr->h_addr_list = ipPtrList; - hostPtr->h_aliases = aliasPtrList; - hostPtr->h_addrtype = AF_INET; - hostPtr->h_length = sizeof(uint32_t); - hostPtr->h_name = (char*)name; - - aliasPtrList[0] = NULL; - ipPtrList[0] = (char*)ipPtr; - ipPtrList[1] = NULL; - - Wiconnect *wiconnect = Wiconnect::getInstance(); - if(wiconnect->lookup(name, ipPtr) != WICONNECT_SUCCESS) - { - ipPtrList[0] = NULL; - } - - return hostPtr; -} - -/*************************************************************************************************/ -u32_t ipaddr_addr(const char *cp) -{ - u32_t ip = 0; - - Wiconnect::strToIp(cp, &ip); - - return ip; -} - -/*************************************************************************************************/ -int ipaddr_aton(const char *cp, ip_addr_t *addr) -{ - return Wiconnect::strToIp(cp, &addr->addr) ? 0 : -1; -} - -/*************************************************************************************************/ -// returns ptr to static buffer; not reentrant! -char *ipaddr_ntoa(const ip_addr_t *addr) -{ - return (char*)Wiconnect::ipToStr(addr->addr); -} - -/*************************************************************************************************/ -char *ipaddr_ntoa_r(const ip_addr_t *addr, char *buf, int buflen) -{ - return (char*)Wiconnect::ipToStr(addr->addr, buf); -}
--- a/types/Socket/internal/common.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -#include "Wiconnect.h"
--- a/types/Socket/lwip/inet.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,108 +0,0 @@ - -/* - * Copyright (c) 2001-2004 Swedish Institute of Computer Science. - * 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels <adam@sics.se> - * - */ -#ifndef __LWIP_INET_H__ -#define __LWIP_INET_H__ - -#include "opt.h" -#include "ip_addr.h" - - -#ifdef __cplusplus -extern "C" { -#endif - -/** For compatibility with BSD code */ -struct in_addr { - u32_t s_addr; -}; - -/** 255.255.255.255 */ -#define INADDR_NONE IPADDR_NONE -/** 127.0.0.1 */ -#define INADDR_LOOPBACK IPADDR_LOOPBACK -/** 0.0.0.0 */ -#define INADDR_ANY IPADDR_ANY -/** 255.255.255.255 */ -#define INADDR_BROADCAST IPADDR_BROADCAST - -/* Definitions of the bits in an Internet address integer. - - On subnets, host and network parts are found according to - the subnet mask, not these masks. */ -#define IN_CLASSA(a) IP_CLASSA(a) -#define IN_CLASSA_NET IP_CLASSA_NET -#define IN_CLASSA_NSHIFT IP_CLASSA_NSHIFT -#define IN_CLASSA_HOST IP_CLASSA_HOST -#define IN_CLASSA_MAX IP_CLASSA_MAX - -#define IN_CLASSB(b) IP_CLASSB(b) -#define IN_CLASSB_NET IP_CLASSB_NET -#define IN_CLASSB_NSHIFT IP_CLASSB_NSHIFT -#define IN_CLASSB_HOST IP_CLASSB_HOST -#define IN_CLASSB_MAX IP_CLASSB_MAX - -#define IN_CLASSC(c) IP_CLASSC(c) -#define IN_CLASSC_NET IP_CLASSC_NET -#define IN_CLASSC_NSHIFT IP_CLASSC_NSHIFT -#define IN_CLASSC_HOST IP_CLASSC_HOST -#define IN_CLASSC_MAX IP_CLASSC_MAX - -#define IN_CLASSD(d) IP_CLASSD(d) -#define IN_CLASSD_NET IP_CLASSD_NET /* These ones aren't really */ -#define IN_CLASSD_NSHIFT IP_CLASSD_NSHIFT /* net and host fields, but */ -#define IN_CLASSD_HOST IP_CLASSD_HOST /* routing needn't know. */ -#define IN_CLASSD_MAX IP_CLASSD_MAX - -#define IN_MULTICAST(a) IP_MULTICAST(a) - -#define IN_EXPERIMENTAL(a) IP_EXPERIMENTAL(a) -#define IN_BADCLASS(a) IP_BADCLASS(a) - -#define IN_LOOPBACKNET IP_LOOPBACKNET - -#define inet_addr_from_ipaddr(target_inaddr, source_ipaddr) ((target_inaddr)->s_addr = ip4_addr_get_u32(source_ipaddr)) -#define inet_addr_to_ipaddr(target_ipaddr, source_inaddr) (ip4_addr_set_u32(target_ipaddr, (source_inaddr)->s_addr)) -/* ATTENTION: the next define only works because both s_addr and ip_addr_t are an u32_t effectively! */ -#define inet_addr_to_ipaddr_p(target_ipaddr_p, source_inaddr) ((target_ipaddr_p) = (ip_addr_t*)&((source_inaddr)->s_addr)) - -/* directly map this to the lwip internal functions */ -#define inet_addr(cp) ipaddr_addr(cp) -#define inet_aton(cp, addr) ipaddr_aton(cp, (ip_addr_t*)addr) -#define inet_ntoa(addr) ipaddr_ntoa((ip_addr_t*)&(addr)) -#define inet_ntoa_r(addr, buf, buflen) ipaddr_ntoa_r((ip_addr_t*)&(addr), buf, buflen) - -#ifdef __cplusplus -} -#endif - -#endif /* __LWIP_INET_H__ */
--- a/types/Socket/lwip/ip_addr.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,243 +0,0 @@ -/* - * Copyright (c) 2001-2004 Swedish Institute of Computer Science. - * 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels <adam@sics.se> - * - */ -#ifndef __LWIP_IP_ADDR_H__ -#define __LWIP_IP_ADDR_H__ - -#include "opt.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* This is the aligned version of ip_addr_t, - used as local variable, on the stack, etc. */ -struct ip_addr { - u32_t addr; -}; - -/* This is the packed version of ip_addr_t, - used in network headers that are itself packed */ -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct ip_addr_packed { - PACK_STRUCT_FIELD(u32_t addr); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -/** ip_addr_t uses a struct for convenience only, so that the same defines can - * operate both on ip_addr_t as well as on ip_addr_p_t. */ -typedef struct ip_addr ip_addr_t; -typedef struct ip_addr_packed ip_addr_p_t; - -/* - * struct ipaddr2 is used in the definition of the ARP packet format in - * order to support compilers that don't have structure packing. - */ -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/bpstruct.h" -#endif -PACK_STRUCT_BEGIN -struct ip_addr2 { - PACK_STRUCT_FIELD(u16_t addrw[2]); -} PACK_STRUCT_STRUCT; -PACK_STRUCT_END -#ifdef PACK_STRUCT_USE_INCLUDES -# include "arch/epstruct.h" -#endif - -/* Forward declaration to not include netif.h */ -struct netif; - -extern const ip_addr_t ip_addr_any; -extern const ip_addr_t ip_addr_broadcast; - -/** IP_ADDR_ can be used as a fixed IP address - * for the wildcard and the broadcast address - */ -#define IP_ADDR_ANY ((ip_addr_t *)&ip_addr_any) -#define IP_ADDR_BROADCAST ((ip_addr_t *)&ip_addr_broadcast) - -/** 255.255.255.255 */ -#define IPADDR_NONE ((u32_t)0xffffffffUL) -/** 127.0.0.1 */ -#define IPADDR_LOOPBACK ((u32_t)0x7f000001UL) -/** 0.0.0.0 */ -#define IPADDR_ANY ((u32_t)0x00000000UL) -/** 255.255.255.255 */ -#define IPADDR_BROADCAST ((u32_t)0xffffffffUL) - -/* Definitions of the bits in an Internet address integer. - - On subnets, host and network parts are found according to - the subnet mask, not these masks. */ -#define IP_CLASSA(a) ((((u32_t)(a)) & 0x80000000UL) == 0) -#define IP_CLASSA_NET 0xff000000 -#define IP_CLASSA_NSHIFT 24 -#define IP_CLASSA_HOST (0xffffffff & ~IP_CLASSA_NET) -#define IP_CLASSA_MAX 128 - -#define IP_CLASSB(a) ((((u32_t)(a)) & 0xc0000000UL) == 0x80000000UL) -#define IP_CLASSB_NET 0xffff0000 -#define IP_CLASSB_NSHIFT 16 -#define IP_CLASSB_HOST (0xffffffff & ~IP_CLASSB_NET) -#define IP_CLASSB_MAX 65536 - -#define IP_CLASSC(a) ((((u32_t)(a)) & 0xe0000000UL) == 0xc0000000UL) -#define IP_CLASSC_NET 0xffffff00 -#define IP_CLASSC_NSHIFT 8 -#define IP_CLASSC_HOST (0xffffffff & ~IP_CLASSC_NET) - -#define IP_CLASSD(a) (((u32_t)(a) & 0xf0000000UL) == 0xe0000000UL) -#define IP_CLASSD_NET 0xf0000000 /* These ones aren't really */ -#define IP_CLASSD_NSHIFT 28 /* net and host fields, but */ -#define IP_CLASSD_HOST 0x0fffffff /* routing needn't know. */ -#define IP_MULTICAST(a) IP_CLASSD(a) - -#define IP_EXPERIMENTAL(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL) -#define IP_BADCLASS(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL) - -#define IP_LOOPBACKNET 127 /* official! */ - - -#if BYTE_ORDER == BIG_ENDIAN -/** Set an IP address given by the four byte-parts */ -#define IP4_ADDR(ipaddr, a,b,c,d) \ - (ipaddr)->addr = ((u32_t)((a) & 0xff) << 24) | \ - ((u32_t)((b) & 0xff) << 16) | \ - ((u32_t)((c) & 0xff) << 8) | \ - (u32_t)((d) & 0xff) -#else -/** Set an IP address given by the four byte-parts. - Little-endian version that prevents the use of htonl. */ -#define IP4_ADDR(ipaddr, a,b,c,d) \ - (ipaddr)->addr = ((u32_t)((d) & 0xff) << 24) | \ - ((u32_t)((c) & 0xff) << 16) | \ - ((u32_t)((b) & 0xff) << 8) | \ - (u32_t)((a) & 0xff) -#endif - -/** MEMCPY-like copying of IP addresses where addresses are known to be - * 16-bit-aligned if the port is correctly configured (so a port could define - * this to copying 2 u16_t's) - no NULL-pointer-checking needed. */ -#ifndef IPADDR2_COPY -#define IPADDR2_COPY(dest, src) SMEMCPY(dest, src, sizeof(ip_addr_t)) -#endif - -/** Copy IP address - faster than ip_addr_set: no NULL check */ -#define ip_addr_copy(dest, src) ((dest).addr = (src).addr) -/** Safely copy one IP address to another (src may be NULL) */ -#define ip_addr_set(dest, src) ((dest)->addr = \ - ((src) == NULL ? 0 : \ - (src)->addr)) -/** Set complete address to zero */ -#define ip_addr_set_zero(ipaddr) ((ipaddr)->addr = 0) -/** Set address to IPADDR_ANY (no need for htonl()) */ -#define ip_addr_set_any(ipaddr) ((ipaddr)->addr = IPADDR_ANY) -/** Set address to loopback address */ -#define ip_addr_set_loopback(ipaddr) ((ipaddr)->addr = PP_HTONL(IPADDR_LOOPBACK)) -/** Safely copy one IP address to another and change byte order - * from host- to network-order. */ -#define ip_addr_set_hton(dest, src) ((dest)->addr = \ - ((src) == NULL ? 0:\ - htonl((src)->addr))) -/** IPv4 only: set the IP address given as an u32_t */ -#define ip4_addr_set_u32(dest_ipaddr, src_u32) ((dest_ipaddr)->addr = (src_u32)) -/** IPv4 only: get the IP address as an u32_t */ -#define ip4_addr_get_u32(src_ipaddr) ((src_ipaddr)->addr) - -/** Get the network address by combining host address with netmask */ -#define ip_addr_get_network(target, host, netmask) ((target)->addr = ((host)->addr) & ((netmask)->addr)) - -/** - * Determine if two address are on the same network. - * - * @arg addr1 IP address 1 - * @arg addr2 IP address 2 - * @arg mask network identifier mask - * @return !0 if the network identifiers of both address match - */ -#define ip_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \ - (mask)->addr) == \ - ((addr2)->addr & \ - (mask)->addr)) -#define ip_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr) - -#define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == IPADDR_ANY) - -#define ip_addr_isbroadcast(ipaddr, netif) ip4_addr_isbroadcast((ipaddr)->addr, (netif)) -u8_t ip4_addr_isbroadcast(u32_t addr, const struct netif *netif); - -#define ip_addr_netmask_valid(netmask) ip4_addr_netmask_valid((netmask)->addr) -u8_t ip4_addr_netmask_valid(u32_t netmask); - -#define ip_addr_ismulticast(addr1) (((addr1)->addr & PP_HTONL(0xf0000000UL)) == PP_HTONL(0xe0000000UL)) - -#define ip_addr_islinklocal(addr1) (((addr1)->addr & PP_HTONL(0xffff0000UL)) == PP_HTONL(0xa9fe0000UL)) - -//#define ip_addr_debug_print(debug, ipaddr) \ -// LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F, \ -// ipaddr != NULL ? ip4_addr1_16(ipaddr) : 0, \ -// ipaddr != NULL ? ip4_addr2_16(ipaddr) : 0, \ -// ipaddr != NULL ? ip4_addr3_16(ipaddr) : 0, \ -// ipaddr != NULL ? ip4_addr4_16(ipaddr) : 0)) - -/* Get one byte from the 4-byte address */ -#define ip4_addr1(ipaddr) (((u8_t*)(ipaddr))[0]) -#define ip4_addr2(ipaddr) (((u8_t*)(ipaddr))[1]) -#define ip4_addr3(ipaddr) (((u8_t*)(ipaddr))[2]) -#define ip4_addr4(ipaddr) (((u8_t*)(ipaddr))[3]) -/* These are cast to u16_t, with the intent that they are often arguments - * to printf using the U16_F format from cc.h. */ -#define ip4_addr1_16(ipaddr) ((u16_t)ip4_addr1(ipaddr)) -#define ip4_addr2_16(ipaddr) ((u16_t)ip4_addr2(ipaddr)) -#define ip4_addr3_16(ipaddr) ((u16_t)ip4_addr3(ipaddr)) -#define ip4_addr4_16(ipaddr) ((u16_t)ip4_addr4(ipaddr)) - -/** For backwards compatibility */ -#define ip_ntoa(ipaddr) ipaddr_ntoa(ipaddr) - -u32_t ipaddr_addr(const char *cp); -int ipaddr_aton(const char *cp, ip_addr_t *addr); -/** returns ptr to static buffer; not reentrant! */ -char *ipaddr_ntoa(const ip_addr_t *addr); -char *ipaddr_ntoa_r(const ip_addr_t *addr, char *buf, int buflen); - -#ifdef __cplusplus -} -#endif - -#endif /* __LWIP_IP_ADDR_H__ */
--- a/types/Socket/lwip/netdb.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,111 +0,0 @@ -/* - * 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Simon Goldschmidt - * - */ - -#include "opt.h" - -#if LWIP_DNS && LWIP_SOCKET - -#include "sockets.h" - -/* some rarely used options */ -#ifndef LWIP_DNS_API_DECLARE_H_ERRNO -#define LWIP_DNS_API_DECLARE_H_ERRNO 1 -#endif - -#ifndef LWIP_DNS_API_DEFINE_ERRORS -#define LWIP_DNS_API_DEFINE_ERRORS 1 -#endif - -#ifndef LWIP_DNS_API_DECLARE_STRUCTS -#define LWIP_DNS_API_DECLARE_STRUCTS 1 -#endif - -#if LWIP_DNS_API_DEFINE_ERRORS -/** Errors used by the DNS API functions, h_errno can be one of them */ -#define EAI_NONAME 200 -#define EAI_SERVICE 201 -#define EAI_FAIL 202 -#define EAI_MEMORY 203 - -#define HOST_NOT_FOUND 210 -#define NO_DATA 211 -#define NO_RECOVERY 212 -#define TRY_AGAIN 213 -#endif /* LWIP_DNS_API_DEFINE_ERRORS */ - -#if LWIP_DNS_API_DECLARE_STRUCTS -struct hostent { - char *h_name; /* Official name of the host. */ - char **h_aliases; /* A pointer to an array of pointers to alternative host names, - terminated by a null pointer. */ - int h_addrtype; /* Address type. */ - int h_length; /* The length, in bytes, of the address. */ - char **h_addr_list; /* A pointer to an array of pointers to network addresses (in - network byte order) for the host, terminated by a null pointer. */ -#define h_addr h_addr_list[0] /* for backward compatibility */ -}; - -struct addrinfo { - int ai_flags; /* Input flags. */ - int ai_family; /* Address family of socket. */ - int ai_socktype; /* Socket type. */ - int ai_protocol; /* Protocol of socket. */ - socklen_t ai_addrlen; /* Length of socket address. */ - struct sockaddr *ai_addr; /* Socket address of socket. */ - char *ai_canonname; /* Canonical name of service location. */ - struct addrinfo *ai_next; /* Pointer to next in list. */ -}; -#endif /* LWIP_DNS_API_DECLARE_STRUCTS */ - -#if LWIP_DNS_API_DECLARE_H_ERRNO -/* application accessable error code set by the DNS API functions */ -extern int h_errno; -#endif /* LWIP_DNS_API_DECLARE_H_ERRNO*/ - -#if 0 -struct hostent *lwip_gethostbyname(const char *name); -int lwip_gethostbyname_r(const char *name, struct hostent *ret, char *buf, - size_t buflen, struct hostent **result, int *h_errnop); -void lwip_freeaddrinfo(struct addrinfo *ai); -int lwip_getaddrinfo(const char *nodename, - const char *servname, - const struct addrinfo *hints, - struct addrinfo **res); -#endif - -#if LWIP_COMPAT_SOCKETS -#define gethostbyname(name) lwip_gethostbyname(name) -#define gethostbyname_r(name, ret, buf, buflen, result, h_errnop) \ - lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop) -#define freeaddrinfo(addrinfo) lwip_freeaddrinfo(a) -#define getaddrinfo(nodname, servname, hints, res) \ - lwip_getaddrinfo(nodname, servname, hints, res) -#endif /* LWIP_COMPAT_SOCKETS */ - -#endif /* LWIP_DNS && LWIP_SOCKET */
--- a/types/Socket/lwip/opt.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ - -#include <stdint.h> - - -#define LWIP_SOCKET 1 -#define LWIP_TCP 1 -#define LWIP_UDPLITE 1 -#define LWIP_DNS 1 - -#define LWIP_DNS_API_DECLARE_H_ERRNO 0 -#define LWIP_DNS_API_DEFINE_ERRORS 0 - -#define LWIP_PLATFORM_BYTESWAP 1 - - -typedef uint8_t u8_t; -typedef uint16_t u16_t; -typedef uint32_t u32_t; - -typedef int8_t s8_t; -typedef int16_t s16_t; -typedef int32_t s32_t; - - - - -#define PACK_STRUCT_FIELD(x) x __attribute__((packed)) - #define PACK_STRUCT_STRUCT __attribute__((packed)) - #define PACK_STRUCT_BEGIN - #define PACK_STRUCT_END - - - -#define LWIP_PLATFORM_HTONS(x) ( (((u16_t)(x))>>8) | (((x)&0xFF)<<8) ) -#define LWIP_PLATFORM_HTONL(x) ( (((u32_t)(x))>>24) | (((x)&0xFF0000)>>8) \ - | (((x)&0xFF00)<<8) | (((x)&0xFF)<<24) ) - - -#ifdef LWIP_PLATFORM_BYTESWAP - -#define htons LWIP_PLATFORM_HTONS -#define htonl LWIP_PLATFORM_HTONL -#define ntohs LWIP_PLATFORM_HTONS -#define ntohl LWIP_PLATFORM_HTONL - -#else - -#define htons(x) x -#define htonl(x) x -#define ntohs(x) x -#define ntohl(x) x - -#endif
--- a/types/Socket/lwip/sockets.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,379 +0,0 @@ -/* - * Copyright (c) 2001-2004 Swedish Institute of Computer Science. - * 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels <adam@sics.se> - * - */ - - -#ifndef __LWIP_SOCKETS_H__ -#define __LWIP_SOCKETS_H__ - -#include "opt.h" - -#if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ - -#include <stddef.h> /* for size_t */ - -#include "ip_addr.h" -#include "inet.h" - -#ifdef __cplusplus -extern "C" { -#endif - - -/* members are in network byte order */ -struct sockaddr_in { - u8_t sin_len; - u8_t sin_family; - u16_t sin_port; - struct in_addr sin_addr; - char sin_zero[8]; -}; - -struct sockaddr { - u8_t sa_len; - u8_t sa_family; - u16_t sa_data[14]; -}; - -#ifndef socklen_t -# define socklen_t u32_t -#endif - -/* Socket protocol types (TCP/UDP/RAW) */ -#define SOCK_STREAM 1 -#define SOCK_DGRAM 2 -#define SOCK_RAW 3 - -/* - * Option flags per-socket. These must match the SOF_ flags in ip.h (checked in init.c) - */ -#define SO_DEBUG 0x0001 /* Unimplemented: turn on debugging info recording */ -#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */ -#define SO_REUSEADDR 0x0004 /* Allow local address reuse */ -#define SO_KEEPALIVE 0x0008 /* keep connections alive */ -#define SO_DONTROUTE 0x0010 /* Unimplemented: just use interface addresses */ -#define SO_BROADCAST 0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */ -#define SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */ -#define SO_LINGER 0x0080 /* linger on close if data present */ -#define SO_OOBINLINE 0x0100 /* Unimplemented: leave received OOB data in line */ -#define SO_REUSEPORT 0x0200 /* Unimplemented: allow local address & port reuse */ - -#define SO_DONTLINGER ((int)(~SO_LINGER)) - -/* - * Additional options, not kept in so_options. - */ -#define SO_SNDBUF 0x1001 /* Unimplemented: send buffer size */ -#define SO_RCVBUF 0x1002 /* receive buffer size */ -#define SO_SNDLOWAT 0x1003 /* Unimplemented: send low-water mark */ -#define SO_RCVLOWAT 0x1004 /* Unimplemented: receive low-water mark */ -#define SO_SNDTIMEO 0x1005 /* Unimplemented: send timeout */ -#define SO_RCVTIMEO 0x1006 /* receive timeout */ -#define SO_ERROR 0x1007 /* get error status and clear */ -#define SO_TYPE 0x1008 /* get socket type */ -#define SO_CONTIMEO 0x1009 /* Unimplemented: connect timeout */ -#define SO_NO_CHECK 0x100a /* don't create UDP checksum */ - - -/* - * Structure used for manipulating linger option. - */ -struct linger { - int l_onoff; /* option on/off */ - int l_linger; /* linger time */ -}; - -/* - * Level number for (get/set)sockopt() to apply to socket itself. - */ -#define SOL_SOCKET 0xfff /* options for socket level */ - - -#define AF_UNSPEC 0 -#define AF_INET 2 -#define PF_INET AF_INET -#define PF_UNSPEC AF_UNSPEC - -#define IPPROTO_IP 0 -#define IPPROTO_TCP 6 -#define IPPROTO_UDP 17 -#define IPPROTO_UDPLITE 136 - -/* Flags we can use with send and recv. */ -#define MSG_PEEK 0x01 /* Peeks at an incoming message */ -#define MSG_WAITALL 0x02 /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */ -#define MSG_OOB 0x04 /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */ -#define MSG_DONTWAIT 0x08 /* Nonblocking i/o for this operation only */ -#define MSG_MORE 0x10 /* Sender will send more */ - - -/* - * Options for level IPPROTO_IP - */ -#define IP_TOS 1 -#define IP_TTL 2 - -#if LWIP_TCP -/* - * Options for level IPPROTO_TCP - */ -#define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */ -#define TCP_KEEPALIVE 0x02 /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */ -#define TCP_KEEPIDLE 0x03 /* set pcb->keep_idle - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */ -#define TCP_KEEPINTVL 0x04 /* set pcb->keep_intvl - Use seconds for get/setsockopt */ -#define TCP_KEEPCNT 0x05 /* set pcb->keep_cnt - Use number of probes sent for get/setsockopt */ -#endif /* LWIP_TCP */ - -#if LWIP_UDP && LWIP_UDPLITE -/* - * Options for level IPPROTO_UDPLITE - */ -#define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */ -#define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */ -#endif /* LWIP_UDP && LWIP_UDPLITE*/ - - -#if LWIP_IGMP -/* - * Options and types for UDP multicast traffic handling - */ -#define IP_ADD_MEMBERSHIP 3 -#define IP_DROP_MEMBERSHIP 4 -#define IP_MULTICAST_TTL 5 -#define IP_MULTICAST_IF 6 -#define IP_MULTICAST_LOOP 7 - -typedef struct ip_mreq { - struct in_addr imr_multiaddr; /* IP multicast address of group */ - struct in_addr imr_interface; /* local IP address of interface */ -} ip_mreq; -#endif /* LWIP_IGMP */ - -/* - * The Type of Service provides an indication of the abstract - * parameters of the quality of service desired. These parameters are - * to be used to guide the selection of the actual service parameters - * when transmitting a datagram through a particular network. Several - * networks offer service precedence, which somehow treats high - * precedence traffic as more important than other traffic (generally - * by accepting only traffic above a certain precedence at time of high - * load). The major choice is a three way tradeoff between low-delay, - * high-reliability, and high-throughput. - * The use of the Delay, Throughput, and Reliability indications may - * increase the cost (in some sense) of the service. In many networks - * better performance for one of these parameters is coupled with worse - * performance on another. Except for very unusual cases at most two - * of these three indications should be set. - */ -#define IPTOS_TOS_MASK 0x1E -#define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK) -#define IPTOS_LOWDELAY 0x10 -#define IPTOS_THROUGHPUT 0x08 -#define IPTOS_RELIABILITY 0x04 -#define IPTOS_LOWCOST 0x02 -#define IPTOS_MINCOST IPTOS_LOWCOST - -/* - * The Network Control precedence designation is intended to be used - * within a network only. The actual use and control of that - * designation is up to each network. The Internetwork Control - * designation is intended for use by gateway control originators only. - * If the actual use of these precedence designations is of concern to - * a particular network, it is the responsibility of that network to - * control the access to, and use of, those precedence designations. - */ -#define IPTOS_PREC_MASK 0xe0 -#define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK) -#define IPTOS_PREC_NETCONTROL 0xe0 -#define IPTOS_PREC_INTERNETCONTROL 0xc0 -#define IPTOS_PREC_CRITIC_ECP 0xa0 -#define IPTOS_PREC_FLASHOVERRIDE 0x80 -#define IPTOS_PREC_FLASH 0x60 -#define IPTOS_PREC_IMMEDIATE 0x40 -#define IPTOS_PREC_PRIORITY 0x20 -#define IPTOS_PREC_ROUTINE 0x00 - - -/* - * Commands for ioctlsocket(), taken from the BSD file fcntl.h. - * lwip_ioctl only supports FIONREAD and FIONBIO, for now - * - * Ioctl's have the command encoded in the lower word, - * and the size of any in or out parameters in the upper - * word. The high 2 bits of the upper word are used - * to encode the in/out status of the parameter; for now - * we restrict parameters to at most 128 bytes. - */ -#if !defined(FIONREAD) || !defined(FIONBIO) -#define IOCPARM_MASK 0x7fU /* parameters must be < 128 bytes */ -#define IOC_VOID 0x20000000UL /* no parameters */ -#define IOC_OUT 0x40000000UL /* copy out parameters */ -#define IOC_IN 0x80000000UL /* copy in parameters */ -#define IOC_INOUT (IOC_IN|IOC_OUT) - /* 0x20000000 distinguishes new & - old ioctl's */ -#define _IO(x,y) (IOC_VOID|((x)<<8)|(y)) - -#define _IOR(x,y,t) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y)) - -#define _IOW(x,y,t) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y)) -#endif /* !defined(FIONREAD) || !defined(FIONBIO) */ - -#ifndef FIONREAD -#define FIONREAD _IOR('f', 127, unsigned long) /* get # bytes to read */ -#endif -#ifndef FIONBIO -#define FIONBIO _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */ -#endif - -/* Socket I/O Controls: unimplemented */ -#ifndef SIOCSHIWAT -#define SIOCSHIWAT _IOW('s', 0, unsigned long) /* set high watermark */ -#define SIOCGHIWAT _IOR('s', 1, unsigned long) /* get high watermark */ -#define SIOCSLOWAT _IOW('s', 2, unsigned long) /* set low watermark */ -#define SIOCGLOWAT _IOR('s', 3, unsigned long) /* get low watermark */ -#define SIOCATMARK _IOR('s', 7, unsigned long) /* at oob mark? */ -#endif - -/* commands for fnctl */ -#ifndef F_GETFL -#define F_GETFL 3 -#endif -#ifndef F_SETFL -#define F_SETFL 4 -#endif - -/* File status flags and file access modes for fnctl, - these are bits in an int. */ -#ifndef O_NONBLOCK -#define O_NONBLOCK 1 /* nonblocking I/O */ -#endif -#ifndef O_NDELAY -#define O_NDELAY 1 /* same as O_NONBLOCK, for compatibility */ -#endif - -#ifndef SHUT_RD - #define SHUT_RD 1 - #define SHUT_WR 2 - #define SHUT_RDWR 3 -#endif - -/* FD_SET used for lwip_select */ -//#ifndef FD_SET -// #undef FD_SETSIZE -// /* Make FD_SETSIZE match NUM_SOCKETS in socket.c */ -// #define FD_SETSIZE MEMP_NUM_NETCONN -// #define FD_SET(n, p) ((p)->fd_bits[(n)/8] |= (1 << ((n) & 7))) -// #define FD_CLR(n, p) ((p)->fd_bits[(n)/8] &= ~(1 << ((n) & 7))) -// #define FD_ISSET(n,p) ((p)->fd_bits[(n)/8] & (1 << ((n) & 7))) -// #define FD_ZERO(p) memset((void*)(p),0,sizeof(*(p))) -// -// typedef struct fd_set { -// unsigned char fd_bits [(FD_SETSIZE+7)/8]; -// } fd_set; -// -//#endif /* FD_SET */ - -/** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided - * by your system, set this to 0 and include <sys/time.h> in cc.h */ -#ifndef LWIP_TIMEVAL_PRIVATE -#define LWIP_TIMEVAL_PRIVATE 1 -#endif - -#if LWIP_TIMEVAL_PRIVATE -struct timeval { - long tv_sec; /* seconds */ - long tv_usec; /* and microseconds */ -}; -#endif /* LWIP_TIMEVAL_PRIVATE */ - -#if 0 -void lwip_socket_init(void); - -int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen); -int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen); -int lwip_shutdown(int s, int how); -int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen); -int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen); -int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen); -int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen); -int lwip_close(int s); -int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen); -int lwip_listen(int s, int backlog); -int lwip_recv(int s, void *mem, size_t len, int flags); -int lwip_read(int s, void *mem, size_t len); -int lwip_recvfrom(int s, void *mem, size_t len, int flags, - struct sockaddr *from, socklen_t *fromlen); -int lwip_send(int s, const void *dataptr, size_t size, int flags); -int lwip_sendto(int s, const void *dataptr, size_t size, int flags, - const struct sockaddr *to, socklen_t tolen); -int lwip_socket(int domain, int type, int protocol); -int lwip_write(int s, const void *dataptr, size_t size); -int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, - struct timeval *timeout); -int lwip_ioctl(int s, long cmd, void *argp); -int lwip_fcntl(int s, int cmd, int val); - -#if LWIP_COMPAT_SOCKETS -#define accept(a,b,c) lwip_accept(a,b,c) -#define bind(a,b,c) lwip_bind(a,b,c) -#define shutdown(a,b) lwip_shutdown(a,b) -#define closesocket(s) lwip_close(s) -#define connect(a,b,c) lwip_connect(a,b,c) -#define getsockname(a,b,c) lwip_getsockname(a,b,c) -#define getpeername(a,b,c) lwip_getpeername(a,b,c) -#define setsockopt(a,b,c,d,e) lwip_setsockopt(a,b,c,d,e) -#define getsockopt(a,b,c,d,e) lwip_getsockopt(a,b,c,d,e) -#define listen(a,b) lwip_listen(a,b) -#define recv(a,b,c,d) lwip_recv(a,b,c,d) -#define recvfrom(a,b,c,d,e,f) lwip_recvfrom(a,b,c,d,e,f) -#define send(a,b,c,d) lwip_send(a,b,c,d) -#define sendto(a,b,c,d,e,f) lwip_sendto(a,b,c,d,e,f) -#define socket(a,b,c) lwip_socket(a,b,c) -#define select(a,b,c,d,e) lwip_select(a,b,c,d,e) -#define ioctlsocket(a,b,c) lwip_ioctl(a,b,c) - -#if LWIP_POSIX_SOCKETS_IO_NAMES -#define read(a,b,c) lwip_read(a,b,c) -#define write(a,b,c) lwip_write(a,b,c) -#define close(s) lwip_close(s) -#endif /* LWIP_POSIX_SOCKETS_IO_NAMES */ - -#endif /* LWIP_COMPAT_SOCKETS */ -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* LWIP_SOCKET */ - -#endif /* __LWIP_SOCKETS_H__ */
--- a/types/Socket/mBedSocketApi.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +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 "types/Socket/Socket.h" -#include "types/Socket/TCPSocketServer.h" -#include "types/Socket/TCPSocketConnection.h" -#include "types/Socket/UDPSocket.h"
--- a/types/SocketIrqHandlerMap.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,128 +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" -#include "types/PinIrqHandler.h" - -namespace wiconnect -{ - -/** - * Generic callback function. - * - * @note Internal use only. - */ -class SocketIrqHandlerMap -{ -public: - /*************************************************************************************************/ - SocketIrqHandlerMap() - { - memset(handlers, 0, sizeof(handlers)); - } - - /*************************************************************************************************/ - ~SocketIrqHandlerMap() - { - for(int i = 0; i < WICONNECT_MAX_PIN_IRQ_HANDLERS; ++i) - { - if(handlers[i] != NULL) - { - handlers[i]->~PinIrqHandler(); - } - } - } - - /*************************************************************************************************/ - bool pinIsRegistered(Pin pin) - { - for(int i = 0; i < WICONNECT_MAX_PIN_IRQ_HANDLERS; ++i) - { - if(handlers[i] != NULL && handlers[i]->irqPin == pin) - { - return true; - } - } - return false; - } - - /*************************************************************************************************/ - WiconnectResult registerHandler(Pin pin, const Callback &callback) - { - if(pinIsRegistered(pin)) - { - return WICONNECT_DUPLICATE; - } - - PinIrqHandler *handler = NULL; - - for(int i = 0; i < WICONNECT_MAX_PIN_IRQ_HANDLERS; ++i) - { - if(handlers[i] == NULL) - { - handler = (PinIrqHandler*)&handlerBuffers[i]; - handlers[i] = handler; - } - } - - if(handler == NULL) - { - return WICONNECT_NOT_FOUND; - } - - *handler = PinIrqHandler(pin, callback); - - return WICONNECT_SUCCESS; - } - - /*************************************************************************************************/ - WiconnectResult unregisterHandler(Pin pin) - { - for(int i = 0; i < WICONNECT_MAX_PIN_IRQ_HANDLERS; ++i) - { - if(handlers[i] != NULL && handlers[i]->irqPin == pin) - { - handlers[i]->~PinIrqHandler(); - handlers[i] = NULL; - return WICONNECT_SUCCESS; - } - } - - return WICONNECT_NOT_FOUND; - } - -private: - PinIrqHandler *handlers[WICONNECT_MAX_PIN_IRQ_HANDLERS]; - PinIrqHandlerBuffer handlerBuffers[WICONNECT_MAX_PIN_IRQ_HANDLERS]; -}; - - - -}
--- a/types/TimeoutTimer.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +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 - - -namespace wiconnect -{ - -/** - * Class for maintaining command processing timeouts. - * - * @note Internal use only. - */ -class TimeoutTimer -{ -public: - TimeoutTimer(); - - void reset(void); - - uint32_t remainingMs(uint32_t timeoutMs); - uint32_t readUs(); - - bool timedOut(uint32_t timeoutMs); - -protected: - uint32_t _start; - -}; - - -}
--- a/types/WiconnectFile.h Thu Oct 23 15:21:50 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 WiconnectFile -{ -public: - WiconnectFile(int rxBufferLen = 0, void *rxBuffer = NULL); - ~WiconnectFile(); - - 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 WiconnectFile* getNext() const; - const WiconnectFile* 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; - WiconnectFile *next; - WiconnectFile *previous; - - Buffer rxBuffer; - - void* operator new(size_t size); - void operator delete(void*); - - friend class FileInterface; - friend class FileList; -}; - -}
--- a/types/WiconnectSerial.h Thu Oct 23 15:21:50 2014 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +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 -{ - -/** - * Serial class for interfacing to WiConnect WiFi module. - * - * @note Internal use only. - */ -class WiconnectSerial WICONNECT_SERIAL_BASE_CLASS -{ -public: - WiconnectSerial(const SerialConfig &config, Wiconnect *wiconnect = NULL); - virtual ~WiconnectSerial(); - - void flush(void); - int write(const void *data, int bytesToWrite, int timeoutMs); - int read(void *data, int bytesToRead, int timeoutMs); - -protected: - TimeoutTimer timeoutTimer; -#ifdef WICONNECT_SERIAL_RX_BUFFER - uint8_t ringBuffer[32]; - bool bufferAlloc; - void rxIrqHandler(void); -#endif -}; - - -} - -
--- a/types/WiconnectSocket.h Thu Oct 23 15:21:50 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 WiconnectSocket -{ -public: - WiconnectSocket(int rxBufferLen = 0, void *rxBuffer = NULL, int txBufferLen = 0, void *txBuffer = NULL); - ~WiconnectSocket(); - - WiconnectResult close(); - WiconnectResult poll(bool *rxDataAvailablePtr, bool autoClose = false); - WiconnectResult write(const void* buffer, int length, bool flush = true); - 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 = true); - 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; -}; - - -}