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
common.h
00001 /** 00002 * ACKme WiConnect Host Library is licensed under the BSD licence: 00003 * 00004 * Copyright (c)2014 ACKme Networks. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without modification, 00008 * are permitted provided that the following conditions are met: 00009 * 00010 * 1. Redistributions of source code must retain the above copyright notice, 00011 * this list of conditions and the following disclaimer. 00012 * 2. Redistributions in binary form must reproduce the above copyright notice, 00013 * this list of conditions and the following disclaimer in the documentation 00014 * and/or other materials provided with the distribution. 00015 * 3. The name of the author may not be used to endorse or promote products 00016 * derived from this software without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED 00019 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00020 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00021 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00022 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00023 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00026 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00027 * OF SUCH DAMAGE. 00028 */ 00029 #ifndef _COMMON_H_ 00030 #define _COMMON_H_ 00031 00032 00033 #include "WiconnectCommands.h" 00034 00035 00036 00037 /* Note we need the 2 concats below because arguments to ## 00038 * are not expanded, so we need to expand __LINE__ with one indirection 00039 * before doing the actual concatenation. */ 00040 #define ASSERT_CONCAT_(a, b) a ## b 00041 #define ASSERT_CONCAT(a, b) ASSERT_CONCAT_(a, b) 00042 #define ct_assert(e) enum { ASSERT_CONCAT(assert_line_, __LINE__) = 1/(!!(e)) } 00043 00044 #define wiconnect_assert(_wiconnect, msg, expr) if(!(expr)){if(_wiconnect != NULL) _wiconnect->assertLogger.call(msg); for(;;); } 00045 00046 00047 00048 #ifndef WICONNECT_ASYNC_TIMER_ENABLED 00049 #define CHECK_CALLBACK_AVAILABLE(cb) if(cb.isValid()) return WICONNECT_UNSUPPORTED 00050 #else 00051 #define CHECK_CALLBACK_AVAILABLE(cb) 00052 #endif 00053 00054 #define UNUSED(expr) do { (void)(expr); } while (0) 00055 00056 #define CHECK_CLEANUP_COMMAND() \ 00057 if(result != WICONNECT_PROCESSING) \ 00058 { \ 00059 wiconnect->internalProcessingState = 0; \ 00060 wiconnect->currentCommandId = NULL; \ 00061 } 00062 00063 #define CHECK_OTHER_COMMAND_EXECUTING() \ 00064 { \ 00065 static const volatile uint8_t __funcId = 0; \ 00066 if(wiconnect->currentCommandId == NULL) \ 00067 { \ 00068 wiconnect->currentCommandId = (void*)&__funcId; \ 00069 } \ 00070 else if(wiconnect->currentCommandId != (void*)&__funcId) \ 00071 { \ 00072 return WICONNECT_ANOTHER_CMD_EXECUTING; \ 00073 } \ 00074 } 00075 00076 #define _CHECK_CLEANUP_COMMAND() \ 00077 if(result != WICONNECT_PROCESSING) \ 00078 { \ 00079 internalProcessingState = 0; \ 00080 currentCommandId = NULL; \ 00081 } 00082 00083 #define _CHECK_OTHER_COMMAND_EXECUTING() \ 00084 { \ 00085 static const volatile uint8_t __funcId = 0; \ 00086 if(currentCommandId == NULL) \ 00087 { \ 00088 currentCommandId = (void*)&__funcId; \ 00089 } \ 00090 else if(currentCommandId != (void*)&__funcId) \ 00091 { \ 00092 return WICONNECT_ANOTHER_CMD_EXECUTING; \ 00093 } \ 00094 } 00095 00096 #define WICONNECT_IS_IDLE() (wiconnect->currentCommandId == NULL) 00097 #define _WICONNECT_IS_IDLE() (currentCommandId == NULL) 00098 00099 00100 00101 #ifdef WICONNECT_USE_DEFAULT_STRING_BUFFERS 00102 #define SET_STR_BUFFER(_buffer, size) \ 00103 char *ptr; \ 00104 static char defaultBuffer[size]; \ 00105 ptr = (_buffer == NULL) ? defaultBuffer : _buffer; 00106 #else 00107 #define SET_STR_BUFFER(_buffer, size) \ 00108 char *ptr; \ 00109 if(_buffer == NULL) \ 00110 { \ 00111 return "<null>"; \ 00112 } \ 00113 ptr = _buffer; 00114 #endif 00115 00116 00117 #endif
Generated on Tue Jul 12 2022 17:35:58 by 1.7.2