From 1e804d459e11e7c7e98079b5d56c098e2e9f3798 Mon Sep 17 00:00:00 2001 From: Thomas Kunze Date: Wed, 24 Jul 2019 22:28:11 +0200 Subject: [PATCH 1/3] add float to knxValue --- examples/knx-bme680/knx-bme680.ino | 4 +++- src/knx/knx_value.cpp | 16 ++++++++++++++++ src/knx/knx_value.h | 6 +++++- visualstudio/knx-bme680.vgdbproj | 3 ++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/examples/knx-bme680/knx-bme680.ino b/examples/knx-bme680/knx-bme680.ino index 3342d26..465f4cd 100644 --- a/examples/knx-bme680/knx-bme680.ino +++ b/examples/knx-bme680/knx-bme680.ino @@ -58,8 +58,10 @@ void setup(void) if(knx.configured()) goTriggerSample.callback(triggerCallback); - // depends on sensor board. Try BME680_I2C_ADDR_PRIMARY if it doen't work. + // Configure Wire pins before this call if needed. + Wire.begin(); + // depends on sensor board. Try BME680_I2C_ADDR_PRIMARY if it doen't work. iaqSensor.begin(BME680_I2C_ADDR_SECONDARY, Wire); checkIaqSensorStatus(); diff --git a/src/knx/knx_value.cpp b/src/knx/knx_value.cpp index f9b8954..4985085 100644 --- a/src/knx/knx_value.cpp +++ b/src/knx/knx_value.cpp @@ -528,4 +528,20 @@ struct tm KNXValue::timeValue() const } struct tm tmp; return tmp; +} + +KNXValue::KNXValue(float value) +{ +} + +KNXValue& KNXValue::operator=(const float value) +{ + _value.doubleValue = value; + _type = DoubleType; + return *this; +} + +KNXValue::operator float() const +{ + return doubleValue(); } \ No newline at end of file diff --git a/src/knx/knx_value.h b/src/knx/knx_value.h index d03f804..e0e5792 100644 --- a/src/knx/knx_value.h +++ b/src/knx/knx_value.h @@ -18,6 +18,7 @@ class KNXValue KNXValue(double value); KNXValue(const char* value); KNXValue(struct tm value); + KNXValue(float value); operator bool() const; operator uint8_t() const; @@ -31,6 +32,7 @@ class KNXValue operator double() const; operator const char*() const; operator struct tm() const; + operator float() const; KNXValue& operator=(const bool value); KNXValue& operator=(const uint8_t value); @@ -44,6 +46,8 @@ class KNXValue KNXValue& operator=(const double value); KNXValue& operator=(const char* value); KNXValue& operator=(const struct tm value); + KNXValue& operator=(const float value); + private: bool boolValue() const; @@ -88,7 +92,7 @@ class KNXValue LongType, DoubleType, StringType, - TimeType + TimeType, }; ValueType _type; diff --git a/visualstudio/knx-bme680.vgdbproj b/visualstudio/knx-bme680.vgdbproj index 5e13a48..2998acb 100644 --- a/visualstudio/knx-bme680.vgdbproj +++ b/visualstudio/knx-bme680.vgdbproj @@ -224,6 +224,7 @@ esp8266:esp8266:nodemcuv2 + COM4 @@ -240,7 +241,7 @@ ssl - all + basic eesz From 8e9aef17ab40768b56fe0d1916720e6a582b0a0e Mon Sep 17 00:00:00 2001 From: Thomas Kunze Date: Fri, 26 Jul 2019 22:07:20 +0200 Subject: [PATCH 2/3] improve encapsulation of accociation table --- src/knx/application_layer.cpp | 13 ++++--------- src/knx/association_table_object.cpp | 19 ++++++++++++++++++- src/knx/association_table_object.h | 6 ++++-- 3 files changed, 26 insertions(+), 12 deletions(-) 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 From de8f4631b6f271fba9dbe928bb2f52701af02776 Mon Sep 17 00:00:00 2001 From: Thomas Kunze Date: Fri, 26 Jul 2019 23:00:08 +0200 Subject: [PATCH 3/3] 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);