21 uint16_t AssociationTableObject::entryCount()
23 return ntohs(_tableData[0]);
26 uint16_t AssociationTableObject::getTSAP(uint16_t idx)
28 if (idx >= entryCount())
31 return ntohs(_tableData[2 * idx + 1]);
34 uint16_t AssociationTableObject::getASAP(uint16_t idx)
36 if (idx >= entryCount())
39 return ntohs(_tableData[2 * idx + 2]);
45 void AssociationTableObject::prepareBinarySearch()
49 uint16_t lastASAP = 0;
50 uint16_t currentASAP = 0;
51 uint16_t lookupIdx = 0;
52 uint16_t lookupASAP = 0;
57 if (_tableData !=
nullptr)
59 for (uint16_t idx = 0; idx < entryCount(); idx++)
61 currentASAP = getASAP(idx);
66 while (lookupIdx < sortedEntryCount)
68 lookupASAP = getASAP(lookupIdx);
70 if (currentASAP <= lookupASAP)
76 if (currentASAP < lookupASAP || lookupIdx >= sortedEntryCount)
86 if (currentASAP > lastASAP)
87 lastASAP = currentASAP;
90 sortedEntryCount = idx;
97 if (lookupIdx == 0 && sortedEntryCount == 0)
98 sortedEntryCount = entryCount();
107 _tableData = (uint16_t*)
data();
108 prepareBinarySearch();
118 if (sortedEntryCount)
121 uint16_t high = sortedEntryCount - 1;
125 uint16_t i = (low + high) / 2;
126 uint16_t asap_i = getASAP(i);
140 for (uint16_t i = 0; i < entryCount(); i++)
141 if (getASAP(i) == asap)
155 _tableData = (uint16_t*)
data();
156 prepareBinarySearch();
161 uint16_t entries = entryCount();
163 for (uint16_t i = startIdx; i < entries; i++)
167 if (getTSAP(i) == tsap)
int32_t translateAsap(uint16_t asap)
const uint8_t * restore(const uint8_t *buffer) override
This method is called when the object should restore its state from the buffer.
void beforeStateChange(LoadState &newState) override
This method is called before the interface object enters a new LoadState.
int32_t nextAsap(uint16_t tsap, uint16_t &startIdx)
AssociationTableObject(Memory &memory)
This class provides common functionality for interface objects that are configured by ETS with MemorW...
void initializeProperties(size_t propertiesSize, Property **properties) override
Intializes the Property-array the the supplied values.
uint8_t * data()
returns the internal data of the interface object.
virtual void beforeStateChange(LoadState &newState)
This method is called before the interface object enters a new LoadState.
const uint8_t * restore(const uint8_t *buffer) override
This method is called when the object should restore its state from the buffer.
@ OT_ASSOC_TABLE
Association table object.
@ PID_OBJECT_TYPE
Interface Object Type independent Properties.
@ PDT_GENERIC_04
length: 4
@ PDT_UNSIGNED_INT
length: 2