From de8f4631b6f271fba9dbe928bb2f52701af02776 Mon Sep 17 00:00:00 2001 From: Thomas Kunze Date: Fri, 26 Jul 2019 23:00:08 +0200 Subject: [PATCH] change association table to format 1 (see 3_5_1 p 157) --- src/knx/application_layer.cpp | 2 +- src/knx/association_table_object.cpp | 20 ++++++++++---------- src/knx/association_table_object.h | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/knx/application_layer.cpp b/src/knx/application_layer.cpp index ec8f447..3d96559 100644 --- a/src/knx/application_layer.cpp +++ b/src/knx/application_layer.cpp @@ -38,7 +38,7 @@ void ApplicationLayer::dataGroupIndication(HopCountType hopType, Priority priori } uint16_t startIdx = 0; - uint32_t asap = _assocTable.nextAsap(tsap, startIdx); + int32_t asap = _assocTable.nextAsap(tsap, startIdx); for (; asap != -1; asap = _assocTable.nextAsap(tsap, startIdx)) { switch (apdu.type()) diff --git a/src/knx/association_table_object.cpp b/src/knx/association_table_object.cpp index edf8451..926cd9d 100644 --- a/src/knx/association_table_object.cpp +++ b/src/knx/association_table_object.cpp @@ -34,7 +34,7 @@ uint16_t AssociationTableObject::operator[](uint16_t idx) if (idx < 0 || idx >= entryCount()) return 0; - return ntohs(_tableData[idx + 1]); + return ntohs(_tableData[2 * idx + 1]); } uint8_t* AssociationTableObject::save(uint8_t* buffer) @@ -53,11 +53,10 @@ uint8_t* AssociationTableObject::restore(uint8_t* buffer) int32_t AssociationTableObject::translateAsap(uint16_t asap) { uint16_t entries = entryCount(); - for (uint16_t i = 0; i < entries; i++) + for (uint16_t i = 0; i < entries * 2; i+=2) { - uint16_t entry = operator[](i); - if (lowByte(entry) == asap) - return highByte(entry); + if (operator[](i + 1) == asap) + return operator[](i); } return -1; } @@ -75,7 +74,7 @@ void AssociationTableObject::beforeStateChange(LoadState& newState) static PropertyDescription _propertyDescriptions[] = { { PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 }, - { PID_TABLE, false, PDT_GENERIC_02, 254, ReadLv3 | WriteLv0 }, + { PID_TABLE, false, PDT_GENERIC_04, 65535, ReadLv3 | WriteLv0 }, { PID_LOAD_STATE_CONTROL, true, PDT_CONTROL, 1, ReadLv3 | WriteLv3 }, { PID_TABLE_REFERENCE, false, PDT_UNSIGNED_LONG, 1, ReadLv3 | WriteLv0 }, { PID_ERROR_CODE, false, PDT_ENUM8, 1, ReadLv3 | WriteLv0 }, @@ -93,15 +92,16 @@ PropertyDescription* AssociationTableObject::propertyDescriptions() return _propertyDescriptions; } -int32_t AssociationTableObject::nextAsap(uint16_t tsap, uint16_t startIdx) +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) + startIdx = i; + + if (operator[](i) == tsap) { - return lowByte(entry); + return operator[](i+1); } } return -1; diff --git a/src/knx/association_table_object.h b/src/knx/association_table_object.h index beab8a8..7b943ce 100644 --- a/src/knx/association_table_object.h +++ b/src/knx/association_table_object.h @@ -12,7 +12,7 @@ class AssociationTableObject : public TableObject uint8_t* restore(uint8_t* buffer); int32_t translateAsap(uint16_t asap); - int32_t nextAsap(uint16_t tsap, uint16_t startIdx); + int32_t nextAsap(uint16_t tsap, uint16_t& startIdx); protected: void beforeStateChange(LoadState& newState);