diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 73d89ed7..ba3a4bfb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -70,6 +70,8 @@ set(SOURCES ./knx/group_object/dpt/dpt15.h ./knx/group_object/dpt/dpt16.cpp ./knx/group_object/dpt/dpt16.h +./knx/group_object/dpt/dpt17.cpp +./knx/group_object/dpt/dpt17.h ./knx/group_object/dpt/dptconvert.cpp ./knx/group_object/dpt/dptconvert.h ./knx/group_object/group_object.cpp diff --git a/src/knx/group_object/dpt/dpt.h b/src/knx/group_object/dpt/dpt.h index e59e2b21..50eb3d64 100644 --- a/src/knx/group_object/dpt/dpt.h +++ b/src/knx/group_object/dpt/dpt.h @@ -3,7 +3,6 @@ #include "../group_object.h" namespace Knx { -#define DPT_SceneNumber Dpt(17, 1) #define DPT_SceneControl Dpt(18, 1) #define DPT_DateTime Dpt(19, 1) #define DPT_SCLOMode Dpt(20, 1) diff --git a/src/knx/group_object/dpt/dpt17.cpp b/src/knx/group_object/dpt/dpt17.cpp new file mode 100644 index 00000000..fe6be99a --- /dev/null +++ b/src/knx/group_object/dpt/dpt17.cpp @@ -0,0 +1,28 @@ +#include "dpt17.h" + +#include "dptconvert.h" + + +Knx::Go_SizeCode Knx::DPT_SceneNumber::size() const +{ + return Go_1_Octet; +} + +void Knx::DPT_SceneNumber::encode(uint8_t* data) const +{ + unsigned8ToPayload(data, 0, _value, 0xFF); +} + +bool Knx::DPT_SceneNumber::decode(uint8_t* data) +{ + _value = unsigned8FromPayload(data, 0) & 0x3F; + return true; +} + +void Knx::DPT_SceneNumber::value(uint8_t value) +{ + if ( value > 63) + return; + + _value = value; +} diff --git a/src/knx/group_object/dpt/dpt17.h b/src/knx/group_object/dpt/dpt17.h new file mode 100644 index 00000000..cc163675 --- /dev/null +++ b/src/knx/group_object/dpt/dpt17.h @@ -0,0 +1,18 @@ +#pragma once +#include "dpt.h" +namespace Knx +{ + class DPT_SceneNumber: public ValueDpt + { + enum ReadDirectionValue { LeftToRight = 0, RightToLeft = 1}; + public: + DPT_SceneNumber(); + DPT_SceneNumber(const char* value); + Go_SizeCode size() const override; + + void encode(uint8_t* data) const override; + bool decode(uint8_t* data) override; + + void value(uint8_t value) override; + }; +} \ No newline at end of file diff --git a/src/knx/group_object/dpt/dptconvert.cpp b/src/knx/group_object/dpt/dptconvert.cpp index 4d537566..e7ea0773 100644 --- a/src/knx/group_object/dpt/dptconvert.cpp +++ b/src/knx/group_object/dpt/dptconvert.cpp @@ -18,10 +18,6 @@ namespace Knx { if (payload_length > 0) { - // DPT 17.* - Scene Number - if (datatype.mainGroup == 17 && datatype.subGroup == 1 && !datatype.index) - return busValueToScene(payload, payload_length, datatype, value); - // DPT 18.* - Scene Control if (datatype.mainGroup == 18 && datatype.subGroup == 1 && datatype.index <= 1) return busValueToSceneControl(payload, payload_length, datatype, value); @@ -100,10 +96,6 @@ namespace Knx int KNX_Encode_Value(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype) { - // DPT 17.* - Scene Number - if (datatype.mainGroup == 17 && datatype.subGroup == 1 && !datatype.index) - return valueToBusValueScene(value, payload, payload_length, datatype); - // DPT 18.* - Scene Control if (datatype.mainGroup == 18 && datatype.subGroup == 1 && datatype.index <= 1) return valueToBusValueSceneControl(value, payload, payload_length, datatype); @@ -186,31 +178,6 @@ namespace Knx return true; } - int busValueToString(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value) - { - ASSERT_PAYLOAD(14); - char strValue[15]; - strValue[14] = '\0'; - - for (int n = 0; n < 14; ++n) - { - strValue[n] = signed8FromPayload(payload, n); - - if (!datatype.subGroup && (strValue[n] & 0x80)) - return false; - } - - value = strValue; - return true; - } - - int busValueToScene(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value) - { - ASSERT_PAYLOAD(1); - value = (uint8_t)(unsigned8FromPayload(payload, 0) & 0x3F); - return true; - } - int busValueToSceneControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value) { ASSERT_PAYLOAD(1); @@ -590,15 +557,6 @@ namespace Knx return true; } - int valueToBusValueScene(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype) - { - if ((int64_t)value < INT64_C(0) || (int64_t)value > INT64_C(63)) - return false; - - unsigned8ToPayload(payload, 0, (uint64_t)value, 0xFF); - return true; - } - int valueToBusValueSceneControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype) { switch (datatype.index) diff --git a/src/knx/group_object/dpt/dptconvert.h b/src/knx/group_object/dpt/dptconvert.h index 6861ad1c..4b407699 100644 --- a/src/knx/group_object/dpt/dptconvert.h +++ b/src/knx/group_object/dpt/dptconvert.h @@ -49,7 +49,6 @@ namespace Knx //KNX to internal int busValueToUnsigned32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value); int busValueToSigned32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value); - int busValueToScene(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value); int busValueToSceneControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value); int busValueToSceneInfo(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value); int busValueToSceneConfig(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value); @@ -70,7 +69,6 @@ namespace Knx //Internal to KNX int valueToBusValueUnsigned32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype); int valueToBusValueSigned32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype); - int valueToBusValueScene(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype); int valueToBusValueSceneControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype); int valueToBusValueSceneInfo(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype); int valueToBusValueSceneConfig(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype); diff --git a/src/knx/group_object/dpt/dpts.h b/src/knx/group_object/dpt/dpts.h index 3b69f8af..98fd2c9a 100644 --- a/src/knx/group_object/dpt/dpts.h +++ b/src/knx/group_object/dpt/dpts.h @@ -15,4 +15,5 @@ #include "dpt13.h" #include "dpt14.h" #include "dpt15.h" -#include "dpt16.h" \ No newline at end of file +#include "dpt16.h" +#include "dpt17.h" \ No newline at end of file