diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a6f30ab..5ab9bba 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,6 +43,8 @@ set(SOURCES ./knx/group_object/dpt/dpt.h ./knx/group_object/dpt/dpt1.cpp ./knx/group_object/dpt/dpt1.h +./knx/group_object/dpt/dpt2.cpp +./knx/group_object/dpt/dpt2.h ./knx/group_object/dpt/dpt9.cpp ./knx/group_object/dpt/dpt9.h ./knx/group_object/dpt/dptconvert.cpp diff --git a/src/knx/group_object/dpt/dpt.cpp b/src/knx/group_object/dpt/dpt.cpp index fd0db37..b7b5711 100644 --- a/src/knx/group_object/dpt/dpt.cpp +++ b/src/knx/group_object/dpt/dpt.cpp @@ -14,6 +14,6 @@ namespace Knx : mainGroup(mainGroup), subGroup(subGroup), index(index) { if (subGroup == 0) - println("WARNING: You used and invalid Dpt *.0"); + LOGGER.warning("You used and invalid Dpt *.0"); } } \ No newline at end of file diff --git a/src/knx/group_object/dpt/dpt.h b/src/knx/group_object/dpt/dpt.h index 30e2c3b..ba1c9e6 100644 --- a/src/knx/group_object/dpt/dpt.h +++ b/src/knx/group_object/dpt/dpt.h @@ -3,38 +3,6 @@ #include "../group_object.h" namespace Knx { -#define DPT_Ramp Dpt(1, 4) -#define DPT_Alarm Dpt(1, 5) -#define DPT_BinaryValue Dpt(1, 6) -#define DPT_Step Dpt(1, 7) -#define DPT_UpDown Dpt(1, 8) -#define DPT_OpenClose Dpt(1, 9) -#define DPT_Start Dpt(1, 10) -#define DPT_State Dpt(1, 11) -#define DPT_Invert Dpt(1, 12) -#define DPT_DimSendStyle Dpt(1, 13) -#define DPT_InputSource Dpt(1, 14) -#define DPT_Reset Dpt(1, 15) -#define DPT_Ack Dpt(1, 16) -#define DPT_Trigger Dpt(1, 17) -#define DPT_Occupancy Dpt(1, 18) -#define DPT_Window_Door Dpt(1, 19) -#define DPT_LogicalFunction Dpt(1, 21) -#define DPT_Scene_AB Dpt(1, 22) -#define DPT_ShutterBlinds_Mode Dpt(1, 23) -#define DPT_Heat_Cool Dpt(1, 100) -#define DPT_Switch_Control Dpt(2, 1) -#define DPT_Bool_Control Dpt(2, 2) -#define DPT_Enable_Control Dpt(2, 3) -#define DPT_Ramp_Control Dpt(2, 4) -#define DPT_Alarm_Control Dpt(2, 5) -#define DPT_BinaryValue_Control Dpt(2, 6) -#define DPT_Step_Control Dpt(2, 7) -#define DPT_Direction1_Control Dpt(2, 8) -#define DPT_Direction2_Control Dpt(2, 9) -#define DPT_Start_Control Dpt(2, 10) -#define DPT_State_Control Dpt(2, 11) -#define DPT_Invert_Control Dpt(2, 12) #define DPT_Control_Dimming Dpt(3, 7) #define DPT_Control_Blinds Dpt(3, 8) #define DPT_Char_ASCII Dpt(4, 1) diff --git a/src/knx/group_object/dpt/dpt1.h b/src/knx/group_object/dpt/dpt1.h index 4d37ffb..f53e852 100644 --- a/src/knx/group_object/dpt/dpt1.h +++ b/src/knx/group_object/dpt/dpt1.h @@ -58,4 +58,26 @@ namespace Knx operator EnableValue() const; DPT_Enable& operator=(const EnableValue value); }; + +// TODO: +#define DPT_Ramp Dpt1(4) +#define DPT_Alarm Dpt1(5) +#define DPT_BinaryValue Dpt1(6) +#define DPT_Step Dpt1(7) +#define DPT_UpDown Dpt1(8) +#define DPT_OpenClose Dpt1(9) +#define DPT_Start Dpt1(10) +#define DPT_State Dpt1(11) +#define DPT_Invert Dpt1(12) +#define DPT_DimSendStyle Dpt1(13) +#define DPT_InputSource Dpt1(14) +#define DPT_Reset Dpt1(15) +#define DPT_Ack Dpt1(16) +#define DPT_Trigger Dpt1(17) +#define DPT_Occupancy Dpt1(18) +#define DPT_Window_Door Dpt1(19) +#define DPT_LogicalFunction Dpt1(21) +#define DPT_Scene_AB Dpt1(22) +#define DPT_ShutterBlinds_Mode Dpt1(23) +#define DPT_DayNight Dpt1(24) } \ No newline at end of file diff --git a/src/knx/group_object/dpt/dpt2.cpp b/src/knx/group_object/dpt/dpt2.cpp new file mode 100644 index 0000000..28554e7 --- /dev/null +++ b/src/knx/group_object/dpt/dpt2.cpp @@ -0,0 +1,64 @@ +#include "dpt2.h" + +#include "dptconvert.h" + +Knx::Dpt2::Dpt2(unsigned short subgroup /* = 0*/) : Dpt(2, subgroup) {} + +Knx::Dpt2::Dpt2(Dpt2Value value) : Dpt2() +{ + _value = value; +} + +Knx::Go_SizeCode Knx::Dpt2::size() const +{ + return Go_2_Bit; +} + +void Knx::Dpt2::encode(uint8_t* data) const +{ + if (_value == NoControl) + { + bitToPayload(data, 6, false); + return; + } + + bitToPayload(data, 6, true); + bitToPayload(data, 7, _value == Control_Function1); +} + +void Knx::Dpt2::decode(uint8_t* data) +{ + bool c = bitFromPayload(data, 6); + + if (!c) + { + _value = NoControl; + return; + } + + bool v = bitFromPayload(data, 7); + + _value = v ? Control_Function1 : Control_Function0; +} + +void Knx::Dpt2::value(Dpt2Value value) +{ + _value = value; +} + +Knx::Dpt2::Dpt2Value Knx::Dpt2::value() const +{ + return _value; +} + +Knx::Dpt2::operator Dpt2Value() const +{ + return _value; +} + + +Knx::Dpt2& Knx::Dpt2::operator=(const Dpt2Value value) +{ + _value = value; + return *this; +} diff --git a/src/knx/group_object/dpt/dpt2.h b/src/knx/group_object/dpt/dpt2.h new file mode 100644 index 0000000..85976b7 --- /dev/null +++ b/src/knx/group_object/dpt/dpt2.h @@ -0,0 +1,40 @@ +#pragma once +#include "dpt.h" +namespace Knx +{ + class Dpt2: public Dpt + { + public: + enum Dpt2Value + { + NoControl, Control_Function0, Control_Function1 + }; + + Dpt2(unsigned short subgroup = 0); + Dpt2(Dpt2Value value); + Go_SizeCode size() const override; + + virtual void encode(uint8_t* data) const override; + virtual void decode(uint8_t* data) override; + + void value(Dpt2Value value); + Dpt2Value value() const; + operator Dpt2Value() const; + Dpt2& operator=(const Dpt2Value value); + private: + Dpt2Value _value; + }; + +#define DPT_Switch_Control Dpt2(1) +#define DPT_Bool_Control Dpt2(2) +#define DPT_Enable_Control Dpt2(3) +#define DPT_Ramp_Control Dpt2(4) +#define DPT_Alarm_Control Dpt2(5) +#define DPT_BinaryValue_Control Dpt2(6) +#define DPT_Step_Control Dpt2(7) +#define DPT_Direction1_Control Dpt2(8) +#define DPT_Direction2_Control Dpt2(9) +#define DPT_Start_Control Dpt2(10) +#define DPT_State_Control Dpt2(11) +#define DPT_Invert_Control Dpt2(12) +} \ No newline at end of file diff --git a/src/knx/group_object/dpt/dpt9.cpp b/src/knx/group_object/dpt/dpt9.cpp index cea3652..6060292 100644 --- a/src/knx/group_object/dpt/dpt9.cpp +++ b/src/knx/group_object/dpt/dpt9.cpp @@ -2,9 +2,12 @@ #include "dptconvert.h" -Knx::Dpt9::Dpt9() { mainGroup = 9; } +Knx::Dpt9::Dpt9(unsigned short subgroup /* = 0*/): Dpt(9, subgroup) {} -Knx::Dpt9::Dpt9(float value) : _value(value) { mainGroup = 9; } +Knx::Dpt9::Dpt9(float value) : Dpt9() +{ + _value = value; +} Knx::Go_SizeCode Knx::Dpt9::size() const { diff --git a/src/knx/group_object/dpt/dpt9.h b/src/knx/group_object/dpt/dpt9.h index 6c804a2..b4d4f45 100644 --- a/src/knx/group_object/dpt/dpt9.h +++ b/src/knx/group_object/dpt/dpt9.h @@ -5,7 +5,7 @@ namespace Knx class Dpt9: public Dpt { public: - Dpt9(); + Dpt9(unsigned short subgroup = 0); Dpt9(float value); Go_SizeCode size() const override; diff --git a/src/knx/group_object/dpt/dptconvert.cpp b/src/knx/group_object/dpt/dptconvert.cpp index 1570248..e2804b7 100644 --- a/src/knx/group_object/dpt/dptconvert.cpp +++ b/src/knx/group_object/dpt/dptconvert.cpp @@ -18,11 +18,6 @@ namespace Knx { if (payload_length > 0) { - // DPT 2.* - Binary Control - - if (datatype.mainGroup == 2 && datatype.subGroup >= 1 && datatype.subGroup <= 12 && datatype.index <= 1) - return busValueToBinaryControl(payload, payload_length, datatype, value); - // DPT 3.* - Step Control if (datatype.mainGroup == 3 && datatype.subGroup >= 7 && datatype.subGroup <= 8 && datatype.index <= 1) return busValueToStepControl(payload, payload_length, datatype, value); @@ -173,11 +168,6 @@ namespace Knx int KNX_Encode_Value(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype) { - - // DPT 2.* - Binary Control - if (datatype.mainGroup == 2 && datatype.subGroup >= 1 && datatype.subGroup <= 12 && datatype.index <= 1) - return valueToBusValueBinaryControl(value, payload, payload_length, datatype); - // DPT 3.* - Step Control if (datatype.mainGroup == 3 && datatype.subGroup >= 7 && datatype.subGroup <= 8 && datatype.index <= 1) return valueToBusValueStepControl(value, payload, payload_length, datatype); @@ -325,23 +315,6 @@ namespace Knx return false; } - int busValueToBinaryControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value) - { - ASSERT_PAYLOAD(1); - - switch (datatype.index) - { - case 0: - value = bitFromPayload(payload, 6); - return true; - - case 1: - value = bitFromPayload(payload, 7); - return true; - } - - return false; - } int busValueToStepControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value) { @@ -988,24 +961,6 @@ namespace Knx //------------------------------------------------------------------------------------------------------------------------------------- - int valueToBusValueBinaryControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype) - { - switch (datatype.index) - { - case 0: - bitToPayload(payload, 6, value); - break; - - case 1: - bitToPayload(payload, 7, value); - break; - - default: - return false; - } - - return true; - } int valueToBusValueStepControl(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 012e513..68e2868 100644 --- a/src/knx/group_object/dpt/dpts.h +++ b/src/knx/group_object/dpt/dpts.h @@ -1,4 +1,5 @@ #pragma once #include "dpt1.h" +#include "dpt2.h" #include "dpt9.h" \ No newline at end of file