more dpt refactoring

This commit is contained in:
Thomas Kunze 2024-09-14 20:46:30 +02:00
parent f093f0a304
commit 27473ffae4
12 changed files with 183 additions and 76 deletions

View File

@ -52,6 +52,8 @@ set(SOURCES
./knx/group_object/dpt/dpt6.h ./knx/group_object/dpt/dpt6.h
./knx/group_object/dpt/dpt7.cpp ./knx/group_object/dpt/dpt7.cpp
./knx/group_object/dpt/dpt7.h ./knx/group_object/dpt/dpt7.h
./knx/group_object/dpt/dpt8.cpp
./knx/group_object/dpt/dpt8.h
./knx/group_object/dpt/dpt9.cpp ./knx/group_object/dpt/dpt9.cpp
./knx/group_object/dpt/dpt9.h ./knx/group_object/dpt/dpt9.h
./knx/group_object/dpt/dptconvert.cpp ./knx/group_object/dpt/dptconvert.cpp

View File

@ -3,15 +3,6 @@
#include "../group_object.h" #include "../group_object.h"
namespace Knx namespace Knx
{ {
#define DPT_Value_2_Count Dpt(8, 1)
#define DPT_DeltaTimeMsec Dpt(8, 2)
#define DPT_DeltaTime10MSec Dpt(8, 3)
#define DPT_DeltaTime100MSec Dpt(8, 4)
#define DPT_DeltaTimeSec Dpt(8, 5)
#define DPT_DeltaTimeMin Dpt(8, 6)
#define DPT_DeltaTimeHrs Dpt(8, 7)
#define DPT_Percent_V16 Dpt(8, 10)
#define DPT_Rotation_Angle Dpt(8, 11)
#define DPT_TimeOfDay Dpt(10, 1, 1) #define DPT_TimeOfDay Dpt(10, 1, 1)
#define DPT_Date Dpt(11, 1) #define DPT_Date Dpt(11, 1)
#define DPT_Value_4_Ucount Dpt(12, 1) #define DPT_Value_4_Ucount Dpt(12, 1)
@ -313,11 +304,11 @@ namespace Knx
virtual bool decode(uint8_t* data) = 0; virtual bool decode(uint8_t* data) = 0;
}; };
template<typename T> class DPT: public Dpt template<typename T> class ValueDpt: public Dpt
{ {
public: public:
DPT() {}; ValueDpt() {};
DPT(T value) ValueDpt(T value)
{ {
_value = value; _value = value;
} }
@ -337,7 +328,7 @@ namespace Knx
return _value; return _value;
} }
DPT& operator=(const T value) ValueDpt& operator=(const T value)
{ {
_value = value; _value = value;
return *this; return *this;

View File

@ -2,9 +2,11 @@
#include "dpt.h" #include "dpt.h"
namespace Knx namespace Knx
{ {
class Dpt1: public DPT<bool> class Dpt1: public ValueDpt<bool>
{ {
public: public:
Dpt1() {}
Dpt1(bool value) : ValueDpt(value) {}
Go_SizeCode size() const override; Go_SizeCode size() const override;
void encode(uint8_t* data) const override; void encode(uint8_t* data) const override;
bool decode(uint8_t* data) override; bool decode(uint8_t* data) override;

View File

@ -9,9 +9,11 @@ namespace Knx
{ {
NoControl, Control NoControl, Control
}; };
template<typename T> class DPT2: public DPT<T> template<typename T> class DPT2: public ValueDpt<T>
{ {
public: public:
DPT2() {};
DPT2(bool value) : ValueDpt<T>(value) {}
Go_SizeCode size() const override Go_SizeCode size() const override
{ {
return Go_2_Bit; return Go_2_Bit;
@ -26,7 +28,7 @@ namespace Knx
} }
bitToPayload(data, 6, true); bitToPayload(data, 6, true);
bitToPayload(data, 7, ((int)DPT<T>::value()) == 1); bitToPayload(data, 7, ((int)ValueDpt<T>::value()) == 1);
} }
bool decode(uint8_t* data) override bool decode(uint8_t* data) override

View File

@ -2,9 +2,11 @@
#include "dpt.h" #include "dpt.h"
namespace Knx namespace Knx
{ {
class Dpt4: public DPT<char> class Dpt4: public ValueDpt<char>
{ {
public: public:
Dpt4() {};
Dpt4(char value) : ValueDpt(value) {}
Go_SizeCode size() const override; Go_SizeCode size() const override;
void encode(uint8_t* data) const override; void encode(uint8_t* data) const override;
@ -13,6 +15,9 @@ namespace Knx
class DPT_Char_ASCII: public Dpt4 class DPT_Char_ASCII: public Dpt4
{ {
public:
DPT_Char_ASCII() {};
DPT_Char_ASCII(char value) : Dpt4(value) {}
bool decode(uint8_t* data) override; bool decode(uint8_t* data) override;
void value(char value) override; void value(char value) override;
}; };

View File

@ -2,9 +2,11 @@
#include "dpt.h" #include "dpt.h"
namespace Knx namespace Knx
{ {
class Dpt6: public DPT<int8_t> class Dpt6: public ValueDpt<int8_t>
{ {
public: public:
Dpt6() {};
Dpt6(int8_t value) : ValueDpt(value) {}
Go_SizeCode size() const override; Go_SizeCode size() const override;
void encode(uint8_t* data) const override; void encode(uint8_t* data) const override;

View File

@ -2,9 +2,11 @@
#include "dpt.h" #include "dpt.h"
namespace Knx namespace Knx
{ {
class Dpt7: public DPT<uint16_t> class Dpt7: public ValueDpt<uint16_t>
{ {
public: public:
Dpt7() {};
Dpt7(uint16_t value) : ValueDpt(value) {}
Go_SizeCode size() const override; Go_SizeCode size() const override;
void encode(uint8_t* data) const override; void encode(uint8_t* data) const override;

View File

@ -0,0 +1,19 @@
#include "dpt8.h"
#include "dptconvert.h"
Knx::Go_SizeCode Knx::Dpt8::size() const
{
return Go_2_Octets;
}
void Knx::Dpt8::encode(uint8_t* data) const
{
signed16ToPayload(data, 0, _value, 0xFFFF);
}
bool Knx::Dpt8::decode(uint8_t* data)
{
_value = signed16FromPayload(data, 0);
return true;
}

View File

@ -0,0 +1,25 @@
#pragma once
#include "dpt.h"
namespace Knx
{
class Dpt8: public ValueDpt<int16_t>
{
public:
Dpt8() {};
Dpt8(int16_t value) : ValueDpt(value) {}
Go_SizeCode size() const override;
void encode(uint8_t* data) const override;
bool decode(uint8_t* data) override;
};
typedef Dpt8 DPT_Value_2_Count;
typedef Dpt8 DPT_DeltaTimeMsec;
typedef Dpt8 DPT_DeltaTime10MSec;
typedef Dpt8 DPT_DeltaTime100MSec;
typedef Dpt8 DPT_DeltaTimeSec;
typedef Dpt8 DPT_DeltaTimeMin;
typedef Dpt8 DPT_DeltaTimeHrs;
typedef Dpt8 DPT_Percent_V16;
typedef Dpt8 DPT_Rotation_Angle;
}

View File

@ -2,13 +2,6 @@
#include "dptconvert.h" #include "dptconvert.h"
Knx::Dpt9::Dpt9() {}
Knx::Dpt9::Dpt9(float value)
{
_value = value;
}
Knx::Go_SizeCode Knx::Dpt9::size() const Knx::Go_SizeCode Knx::Dpt9::size() const
{ {
return Go_1_Bit; return Go_1_Bit;
@ -28,24 +21,65 @@ bool Knx::Dpt9::decode(uint8_t* data)
return true; return true;
} }
void Knx::Dpt9::value(float value) bool Knx::DPT_Value_Temp::decode(uint8_t* data)
{ {
_value = value; Dpt9::decode(data);
if (_value < -273.0f)
{
_value = 0;
return false;
} }
float Knx::Dpt9::value() const return true;
{
return _value;
} }
Knx::Dpt9::operator float() const void Knx::DPT_Value_Temp::value(float value)
{ {
return _value; if (value < -273.0f)
return;
Dpt9::value(value);
} }
bool Knx::DPT_Value_Temp_F::decode(uint8_t* data)
Knx::Dpt9& Knx::Dpt9::operator=(const float value)
{ {
_value = value; Dpt9::decode(data);
return *this;
if (_value < -459.6f)
{
_value = 0;
return false;
}
return true;
}
void Knx::DPT_Value_Temp_F::value(float value)
{
if (value < -459.6f)
return;
Dpt9::value(value);
}
bool Knx::Dpt9GeZero::decode(uint8_t* data)
{
Dpt9::decode(data);
if (_value < 0)
{
_value = 0;
return false;
}
return true;
}
void Knx::Dpt9GeZero::value(float value)
{
if (value < 0)
return;
Dpt9::value(value);
} }

View File

@ -2,41 +2,63 @@
#include "dpt.h" #include "dpt.h"
namespace Knx namespace Knx
{ {
class Dpt9: public Dpt class Dpt9: public ValueDpt<float>
{ {
public: public:
Dpt9(); Dpt9() {};
Dpt9(float value); Dpt9(float value) : ValueDpt(value) {}
Go_SizeCode size() const override; Go_SizeCode size() const override;
void encode(uint8_t* data) const override; void encode(uint8_t* data) const override;
bool decode(uint8_t* data) override; bool decode(uint8_t* data) override;
void value(float value);
float value() const;
operator float() const;
Dpt9& operator=(const float value);
private:
float _value;
}; };
#define DPT_Value_Temp Dpt(9, 1) class DPT_Value_Temp : public Dpt9
#define DPT_Value_Tempd Dpt(9, 2) {
#define DPT_Value_Tempa Dpt(9, 3) public:
#define DPT_Value_Lux Dpt(9, 4) DPT_Value_Temp() {};
#define DPT_Value_Wsp Dpt(9, 5) DPT_Value_Temp(float value) : Dpt9(value) {}
#define DPT_Value_Pres Dpt(9, 6) bool decode(uint8_t* data) override;
#define DPT_Value_Humidity Dpt(9, 7) void value(float value) override;
#define DPT_Value_AirQuality Dpt(9, 8)
#define DPT_Value_Time1 Dpt(9, 10) };
#define DPT_Value_Time2 Dpt(9, 11)
#define DPT_Value_Volt Dpt(9, 20) class DPT_Value_Temp_F : public Dpt9
#define DPT_Value_Curr Dpt(9, 21) {
#define DPT_PowerDensity Dpt(9, 22) public:
#define DPT_KelvinPerPercent Dpt(9, 23) DPT_Value_Temp_F() {};
#define DPT_Power Dpt(9, 24) DPT_Value_Temp_F(float value) : Dpt9(value) {}
#define DPT_Value_Volume_Flow Dpt(9, 25) bool decode(uint8_t* data) override;
#define DPT_Rain_Amount Dpt(9, 26) void value(float value) override;
#define DPT_Value_Temp_F Dpt(9, 27)
#define DPT_Value_Wsp_kmh Dpt(9, 28) };
class Dpt9GeZero : public Dpt9
{
public:
Dpt9GeZero() {};
Dpt9GeZero(float value) : Dpt9(value) {}
bool decode(uint8_t* data) override;
void value(float value) override;
};
typedef Dpt9 DPT_Value_Tempd;
typedef Dpt9 DPT_Value_Tempa;
typedef Dpt9GeZero DPT_Value_Lux;
typedef Dpt9GeZero DPT_Value_Wsp;
typedef Dpt9GeZero DPT_Value_Pres;
typedef Dpt9GeZero DPT_Value_Humidity;
typedef Dpt9GeZero DPT_Value_AirQuality;
typedef Dpt9 DPT_Value_Time1;
typedef Dpt9 DPT_Value_Time2;
typedef Dpt9 DPT_Value_Volt;
typedef Dpt9 DPT_Value_Curr;
typedef Dpt9 DPT_PowerDensity;
typedef Dpt9 DPT_KelvinPerPercent;
typedef Dpt9 DPT_Power;
typedef Dpt9 DPT_Value_Volume_Flow;
typedef Dpt9 DPT_Rain_Amount;
typedef Dpt9 DPT_Value_Wsp_kmh;
typedef Dpt9GeZero DPT_Value_Absolute_Humidity;
typedef Dpt9GeZero DPT_Concentration_µgm3;
} }

View File

@ -7,4 +7,5 @@
#include "dpt5.h" #include "dpt5.h"
#include "dpt6.h" #include "dpt6.h"
#include "dpt7.h" #include "dpt7.h"
#include "dpt8.h"
#include "dpt9.h" #include "dpt9.h"