diff --git a/src/knx/application_layer.cpp b/src/knx/application_layer.cpp index 4ea0452..ec8f447 100644 --- a/src/knx/application_layer.cpp +++ b/src/knx/application_layer.cpp @@ -22,8 +22,6 @@ void ApplicationLayer::transportLayer(TransportLayer& layer) void ApplicationLayer::dataGroupIndication(HopCountType hopType, Priority priority, uint16_t tsap, APDU& apdu) { - uint16_t entries = _assocTable.entryCount(); - uint8_t len = apdu.length(); uint8_t dataArray[len]; uint8_t* data = dataArray; @@ -39,14 +37,12 @@ void ApplicationLayer::dataGroupIndication(HopCountType hopType, Priority priori len -= 1; } - for (uint16_t i = 0; i < entries; i++) + uint16_t startIdx = 0; + uint32_t asap = _assocTable.nextAsap(tsap, startIdx); + for (; asap != -1; asap = _assocTable.nextAsap(tsap, startIdx)) { - uint16_t entry = _assocTable[i]; - if (highByte(entry) == tsap) + switch (apdu.type()) { - uint16_t asap = lowByte(entry); - switch (apdu.type()) - { case GroupValueRead: _bau.groupValueReadIndication(asap, priority, hopType); break; @@ -55,7 +51,6 @@ void ApplicationLayer::dataGroupIndication(HopCountType hopType, Priority priori break; case GroupValueWrite: _bau.groupValueWriteIndication(asap, priority, hopType, data, len); - } } } } diff --git a/src/knx/association_table_object.cpp b/src/knx/association_table_object.cpp index 3c76674..edf8451 100644 --- a/src/knx/association_table_object.cpp +++ b/src/knx/association_table_object.cpp @@ -49,6 +49,7 @@ uint8_t* AssociationTableObject::restore(uint8_t* buffer) return buffer; } +// return type is int32 so that we can return uint16 and -1 int32_t AssociationTableObject::translateAsap(uint16_t asap) { uint16_t entries = entryCount(); @@ -61,6 +62,8 @@ int32_t AssociationTableObject::translateAsap(uint16_t asap) return -1; } + + void AssociationTableObject::beforeStateChange(LoadState& newState) { if (newState != LS_LOADED) @@ -88,4 +91,18 @@ uint8_t AssociationTableObject::propertyCount() PropertyDescription* AssociationTableObject::propertyDescriptions() { return _propertyDescriptions; -} \ No newline at end of file +} + +int32_t AssociationTableObject::nextAsap(uint16_t tsap, uint16_t startIdx) +{ + uint16_t entries = entryCount(); + for (uint16_t i = startIdx; i < entries; i++) + { + uint16_t entry = operator[](i); + if (highByte(entry) == tsap) + { + return lowByte(entry); + } + } + return -1; +} diff --git a/src/knx/association_table_object.h b/src/knx/association_table_object.h index 0021046..beab8a8 100644 --- a/src/knx/association_table_object.h +++ b/src/knx/association_table_object.h @@ -7,12 +7,12 @@ class AssociationTableObject : public TableObject public: AssociationTableObject(Platform& platform); void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data); - uint16_t entryCount(); - uint16_t operator[](uint16_t idx); + uint8_t* save(uint8_t* buffer); uint8_t* restore(uint8_t* buffer); int32_t translateAsap(uint16_t asap); + int32_t nextAsap(uint16_t tsap, uint16_t startIdx); protected: void beforeStateChange(LoadState& newState); @@ -20,5 +20,7 @@ class AssociationTableObject : public TableObject PropertyDescription* propertyDescriptions(); private: + uint16_t entryCount(); + uint16_t operator[](uint16_t idx); uint16_t* _tableData = 0; }; \ No newline at end of file