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
ScanResultList.cpp
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 #include "Wiconnect.h" 00030 #include "api/types/ScanResult.h" 00031 #include "internal/common.h" 00032 00033 00034 /*************************************************************************************************/ 00035 ScanResultList::ScanResultList(int bufferLen_, void *buffer_) 00036 { 00037 Wiconnect *wiconnect = Wiconnect::getInstance(); 00038 wiconnect_assert(wiconnect, "ScanResultList(), bad buffer", (bufferLen_ == 0 && buffer_ == NULL) || (bufferLen_ != 0 && buffer_ != NULL)); 00039 buffer = (uint8_t*)buffer_; 00040 bufferLen = bufferLen_; 00041 reset(); 00042 } 00043 00044 /*************************************************************************************************/ 00045 ScanResultList::~ScanResultList() 00046 { 00047 reset(); 00048 } 00049 00050 /*************************************************************************************************/ 00051 void ScanResultList::reset(void) 00052 { 00053 #ifdef WICONNECT_ENABLE_MALLOC 00054 if(buffer == NULL) 00055 { 00056 ScanResult* result = listHead; 00057 while(result != NULL) 00058 { 00059 ScanResult* tmp = result; 00060 result = result->next; 00061 delete tmp; 00062 } 00063 } 00064 #endif 00065 listHead = listTail = NULL; 00066 bufferPtr = buffer; 00067 bufferRemaining = bufferLen; 00068 count = 0; 00069 } 00070 00071 00072 /*************************************************************************************************/ 00073 WiconnectResult ScanResultList::add(const char *channelStr, const char *rssiStr, const char* macStr, const char *rateStr, const char *secStr, const char *ssidStr) 00074 { 00075 WiconnectResult result; 00076 ScanResult *res; 00077 00078 if(buffer == NULL) 00079 { 00080 #ifdef WICONNECT_ENABLE_MALLOC 00081 res = new ScanResult(); 00082 if(res == NULL) 00083 #endif 00084 { 00085 return WICONNECT_NULL_BUFFER; 00086 } 00087 } 00088 else 00089 { 00090 if(bufferRemaining < sizeof(ScanResult)) 00091 { 00092 return WICONNECT_OVERFLOW; 00093 } 00094 res = (ScanResult*)bufferPtr; 00095 memset(res, 0, sizeof(ScanResult)); 00096 bufferRemaining -= sizeof(ScanResult); 00097 bufferPtr += sizeof(ScanResult); 00098 } 00099 00100 if(WICONNECT_FAILED(result, res->init(channelStr, rssiStr, macStr, rateStr, secStr, ssidStr))) 00101 { 00102 if(buffer == NULL) 00103 { 00104 delete res; 00105 } 00106 } 00107 else 00108 { 00109 if(listHead == NULL) 00110 { 00111 listHead = listTail = res; 00112 } 00113 else 00114 { 00115 res->previous = listTail; 00116 listTail->next = res; 00117 listTail = res; 00118 } 00119 ++count; 00120 } 00121 00122 return result; 00123 } 00124 00125 /*************************************************************************************************/ 00126 const ScanResult* ScanResultList::getListHead() const 00127 { 00128 return listHead; 00129 } 00130 00131 /*************************************************************************************************/ 00132 int ScanResultList::getCount() const 00133 { 00134 return count; 00135 } 00136 00137 /*************************************************************************************************/ 00138 const ScanResult* ScanResultList::getResult(int i) const 00139 { 00140 if(i >= count) 00141 return NULL; 00142 00143 ScanResult* result = listHead; 00144 while(i-- != 0) 00145 result = result->next; 00146 00147 return result; 00148 } 00149 00150 /*************************************************************************************************/ 00151 const ScanResult* ScanResultList::operator [](int i) const 00152 { 00153 return getResult(i); 00154 } 00155 00156 00157 00158 00159
Generated on Tue Jul 12 2022 17:35:58 by 1.7.2