mirror of
https://github.com/thelsing/knx.git
synced 2025-09-14 17:50:55 +02:00
Corrected BIN_SEARCH
This commit is contained in:
parent
bd840098e9
commit
9b79710cd9
@ -38,11 +38,11 @@ uint16_t AddressTableObject::getTsap(uint16_t addr)
|
|||||||
{
|
{
|
||||||
uint16_t size = entryCount();
|
uint16_t size = entryCount();
|
||||||
#ifdef USE_BINSEARCH
|
#ifdef USE_BINSEARCH
|
||||||
addr = htons(addr);
|
addr = ntohs(addr);
|
||||||
|
|
||||||
uint16_t low,high,i;
|
uint16_t low,high,i;
|
||||||
low = 0;
|
low = 1;
|
||||||
high = size-1;
|
high = size;
|
||||||
|
|
||||||
while(low <= high)
|
while(low <= high)
|
||||||
{
|
{
|
||||||
@ -77,30 +77,8 @@ const uint8_t* AddressTableObject::restore(const uint8_t* buffer)
|
|||||||
|
|
||||||
bool AddressTableObject::contains(uint16_t addr)
|
bool AddressTableObject::contains(uint16_t addr)
|
||||||
{
|
{
|
||||||
uint16_t size = entryCount();
|
uint16_t foundTsap = getTsap(addr);
|
||||||
#ifdef USE_BINSEARCH
|
return (foundTsap > 0);
|
||||||
addr = htons(addr);
|
|
||||||
|
|
||||||
uint16_t low,high,i;
|
|
||||||
low = 0;
|
|
||||||
high = size-1;
|
|
||||||
|
|
||||||
while(low <= high)
|
|
||||||
{
|
|
||||||
i = (low+high)/2;
|
|
||||||
if (_groupAddresses[i] == addr)
|
|
||||||
return true;
|
|
||||||
if(addr < _groupAddresses[i])
|
|
||||||
high = i - 1;
|
|
||||||
else
|
|
||||||
low = i + 1 ;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
for (uint16_t i = 1; i <= size; i++)
|
|
||||||
if (ntohs(_groupAddresses[i]) == addr)
|
|
||||||
return true;
|
|
||||||
#endif
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddressTableObject::beforeStateChange(LoadState& newState)
|
void AddressTableObject::beforeStateChange(LoadState& newState)
|
||||||
|
@ -65,9 +65,9 @@ int32_t AssociationTableObject::translateAsap(uint16_t asap)
|
|||||||
// search downwards to return the first occurence in the table
|
// search downwards to return the first occurence in the table
|
||||||
while(getASAP(--i) == asap)
|
while(getASAP(--i) == asap)
|
||||||
;
|
;
|
||||||
return getASAP(i+1);
|
return getTSAP(i+1);
|
||||||
}
|
}
|
||||||
if(asap_i < asap)
|
if(asap_i > asap)
|
||||||
high = i - 1;
|
high = i - 1;
|
||||||
else
|
else
|
||||||
low = i + 1 ;
|
low = i + 1 ;
|
||||||
|
Loading…
Reference in New Issue
Block a user