Skip to content

Commit e4431d6

Browse files
committed
reimplement dpt 11-13
1 parent 02b0736 commit e4431d6

13 files changed

+198
-89
lines changed

src/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ set(SOURCES
5858
./knx/group_object/dpt/dpt9.h
5959
./knx/group_object/dpt/dpt10.cpp
6060
./knx/group_object/dpt/dpt10.h
61+
./knx/group_object/dpt/dpt11.cpp
62+
./knx/group_object/dpt/dpt11.h
63+
./knx/group_object/dpt/dpt12.cpp
64+
./knx/group_object/dpt/dpt12.h
65+
./knx/group_object/dpt/dpt13.cpp
66+
./knx/group_object/dpt/dpt13.h
6167
./knx/group_object/dpt/dptconvert.cpp
6268
./knx/group_object/dpt/dptconvert.h
6369
./knx/group_object/group_object.cpp

src/knx/group_object/dpt/dpt.h

-11
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,6 @@
33
#include "../group_object.h"
44
namespace Knx
55
{
6-
#define DPT_Date Dpt(11, 1)
7-
#define DPT_Value_4_Ucount Dpt(12, 1)
8-
#define DPT_Value_4_Count Dpt(13, 1)
9-
#define DPT_FlowRate_m3 Dpt(13, 2) / h
10-
#define DPT_ActiveEnergy Dpt(13, 10)
11-
#define DPT_ApparantEnergy Dpt(13, 11)
12-
#define DPT_ReactiveEnergy Dpt(13, 12)
13-
#define DPT_ActiveEnergy_kWh Dpt(13, 13)
14-
#define DPT_ApparantEnergy_kVAh Dpt(13, 14)
15-
#define DPT_ReactiveEnergy_kVARh Dpt(13, 15)
16-
#define DPT_LongDeltaTimeSec Dpt(13, 100)
176
#define DPT_Value_Acceleration Dpt(14, 0)
187
#define DPT_Value_Acceleration_Angular Dpt(14, 1)
198
#define DPT_Value_Activation_Energy Dpt(14, 2)

src/knx/group_object/dpt/dpt11.cpp

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#include "dpt10.h"
2+
3+
#include "dptconvert.h"
4+
#include "dpt11.h"
5+
6+
Knx::Go_SizeCode Knx::DPT_Date::size() const
7+
{
8+
return Go_3_Octets;
9+
}
10+
11+
void Knx::DPT_Date::encode(uint8_t* data) const
12+
{
13+
unsigned8ToPayload(data, 0, _day, 0x1F);
14+
unsigned8ToPayload(data, 1, _month, 0x0F);
15+
unsigned8ToPayload(data, 2, _year % 100, 0x7F);
16+
}
17+
18+
bool Knx::DPT_Date::decode(uint8_t* data)
19+
{
20+
_year = unsigned8FromPayload(data, 2) & 0x7F;
21+
_month = unsigned8FromPayload(data, 1) & 0x0F;
22+
_day = unsigned8FromPayload(data, 0) & 0x1F;
23+
24+
if (_year > 99 || _month < 1 || _month > 12 || _day < 1)
25+
{
26+
_year = 0;
27+
_month = 0;
28+
_day = 0;
29+
return false;
30+
}
31+
32+
_year += _year >= 90 ? 1900 : 2000;
33+
return true;
34+
}
35+
36+
uint8_t Knx::DPT_Date::day() const
37+
{
38+
return _day;
39+
}
40+
41+
void Knx::DPT_Date::day(uint8_t value)
42+
{
43+
if (value < 1 || value > 31)
44+
return;
45+
46+
_day = value;
47+
}
48+
49+
uint8_t Knx::DPT_Date::month() const
50+
{
51+
return _month;
52+
}
53+
54+
void Knx::DPT_Date::month(uint8_t value)
55+
{
56+
if (value < 1 || value > 12)
57+
return;
58+
59+
_month = value;
60+
}
61+
62+
uint16_t Knx::DPT_Date::year() const
63+
{
64+
return _year;
65+
}
66+
67+
void Knx::DPT_Date::year(uint16_t value)
68+
{
69+
if (value < 1990 || value > 2089)
70+
return;
71+
72+
_year = value;
73+
}

src/knx/group_object/dpt/dpt11.h

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
#include "dpt.h"
3+
namespace Knx
4+
{
5+
class DPT_Date: public Dpt
6+
{
7+
public:
8+
Go_SizeCode size() const override;
9+
10+
void encode(uint8_t* data) const override;
11+
bool decode(uint8_t* data) override;
12+
13+
uint8_t day() const;
14+
void day(uint8_t value);
15+
16+
uint8_t month() const;
17+
void month(uint8_t value);
18+
19+
uint16_t year() const;
20+
void year(uint16_t value);
21+
private:
22+
uint8_t _day;
23+
uint8_t _month;
24+
uint16_t _year;
25+
};
26+
27+
28+
}

src/knx/group_object/dpt/dpt12.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "dpt12.h"
2+
3+
#include "dptconvert.h"
4+
5+
Knx::Go_SizeCode Knx::Dpt12::size() const
6+
{
7+
return Go_4_Octets;
8+
}
9+
10+
void Knx::Dpt12::encode(uint8_t* data) const
11+
{
12+
unsigned32ToPayload(data, 0, _value, 0xFFFFFFFF);
13+
}
14+
15+
bool Knx::Dpt12::decode(uint8_t* data)
16+
{
17+
_value = unsigned32FromPayload(data, 0);
18+
return true;
19+
}

src/knx/group_object/dpt/dpt12.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
#include "dpt.h"
3+
namespace Knx
4+
{
5+
class Dpt12: public ValueDpt<uint32_t>
6+
{
7+
public:
8+
Dpt12() {};
9+
Dpt12(uint32_t value) : ValueDpt(value) {}
10+
Go_SizeCode size() const override;
11+
12+
void encode(uint8_t* data) const override;
13+
bool decode(uint8_t* data) override;
14+
};
15+
16+
typedef Dpt12 DPT_Value_4_Ucount;
17+
typedef Dpt12 DPT_LongTimePeriod_Sec;
18+
typedef Dpt12 DPT_LongTimePeriod_Min;
19+
typedef Dpt12 DPT_LongTimePeriod_Hrs;
20+
}

src/knx/group_object/dpt/dpt13.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "dpt13.h"
2+
3+
#include "dptconvert.h"
4+
5+
Knx::Go_SizeCode Knx::Dpt13::size() const
6+
{
7+
return Go_4_Octets;
8+
}
9+
10+
void Knx::Dpt13::encode(uint8_t* data) const
11+
{
12+
signed32ToPayload(data, 0, _value, 0xFFFFFFFF);
13+
}
14+
15+
bool Knx::Dpt13::decode(uint8_t* data)
16+
{
17+
_value = signed32FromPayload(data, 0);
18+
return true;
19+
}

src/knx/group_object/dpt/dpt13.h

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
#include "dpt.h"
3+
namespace Knx
4+
{
5+
class Dpt13: public ValueDpt<int32_t>
6+
{
7+
public:
8+
Dpt13() {};
9+
Dpt13(int32_t value) : ValueDpt(value) {}
10+
Go_SizeCode size() const override;
11+
12+
void encode(uint8_t* data) const override;
13+
bool decode(uint8_t* data) override;
14+
};
15+
16+
typedef Dpt13 DPT_Value_4_Count;
17+
typedef Dpt13 DPT_FlowRate_m3_h;
18+
typedef Dpt13 DPT_ActiveEnergy;
19+
typedef Dpt13 DPT_ApparantEnergy;
20+
typedef Dpt13 DPT_ReactiveEnergy;
21+
typedef Dpt13 DPT_ActiveEnergy_kWh;
22+
typedef Dpt13 DPT_ApparantEnergy_kVAh;
23+
typedef Dpt13 DPT_ReactiveEnergy_kVARh;
24+
typedef Dpt13 DPT_ActiveEnergy_MWh;
25+
typedef Dpt13 DPT_LongDeltaTimeSec;
26+
}

src/knx/group_object/dpt/dpt9.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Knx::Go_SizeCode Knx::Dpt9::size() const
66
{
7-
return Go_1_Bit;
7+
return Go_2_Octets;
88
}
99

1010
void Knx::Dpt9::encode(uint8_t* data) const

src/knx/group_object/dpt/dpt9.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ namespace Knx
6060
typedef Dpt9 DPT_Rain_Amount;
6161
typedef Dpt9 DPT_Value_Wsp_kmh;
6262
typedef Dpt9GeZero DPT_Value_Absolute_Humidity;
63-
typedef Dpt9GeZero DPT_Concentration_µgm3;
63+
typedef Dpt9GeZero DPT_Concentration_ugm3;
6464
}

src/knx/group_object/dpt/dptconvert.cpp

-73
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,6 @@ namespace Knx
1818
{
1919
if (payload_length > 0)
2020
{
21-
// DPT 11.* - Date
22-
if (datatype.mainGroup == 11 && datatype.subGroup == 1 && !datatype.index)
23-
return busValueToDate(payload, payload_length, datatype, value);
24-
25-
// DPT 12.* - Unsigned 32 Bit Integer
26-
if (datatype.mainGroup == 12 && datatype.subGroup == 1 && !datatype.index)
27-
return busValueToUnsigned32(payload, payload_length, datatype, value);
28-
29-
// DPT 13.001/13.002/13.010-13.015 - Signed 32 Bit Integer
30-
if (datatype.mainGroup == 13 && (datatype.subGroup == 1 || datatype.subGroup == 2 || (datatype.subGroup >= 10 && datatype.subGroup <= 15)) && !datatype.index)
31-
return busValueToSigned32(payload, payload_length, datatype, value);
32-
33-
// DPT 13.100 - Long Time Period
34-
if (datatype.mainGroup == 13 && datatype.subGroup == 100 && !datatype.index)
35-
return busValueToLongTimePeriod(payload, payload_length, datatype, value);
36-
3721
// DPT 14.* - 32 Bit Float
3822
if (datatype.mainGroup == 14 && datatype.subGroup <= 79 && !datatype.index)
3923
return busValueToFloat32(payload, payload_length, datatype, value);
@@ -128,22 +112,6 @@ namespace Knx
128112

129113
int KNX_Encode_Value(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
130114
{
131-
// DPT 11.* - Date
132-
if (datatype.mainGroup == 11 && datatype.subGroup == 1 && !datatype.index)
133-
return valueToBusValueDate(value, payload, payload_length, datatype);
134-
135-
// DPT 12.* - Unsigned 32 Bit Integer
136-
if (datatype.mainGroup == 12 && datatype.subGroup == 1 && !datatype.index)
137-
return valueToBusValueUnsigned32(value, payload, payload_length, datatype);
138-
139-
// DPT 13.001/13.002/13.010-13.015 - Signed 32 Bit Integer
140-
if (datatype.mainGroup == 13 && (datatype.subGroup == 1 || datatype.subGroup == 2 || (datatype.subGroup >= 10 && datatype.subGroup <= 15)) && !datatype.index)
141-
return valueToBusValueSigned32(value, payload, payload_length, datatype);
142-
143-
// DPT 13.100 - Long Time Period
144-
if (datatype.mainGroup == 13 && datatype.subGroup == 100 && !datatype.index)
145-
return valueToBusValueLongTimePeriod(value, payload, payload_length, datatype);
146-
147115
// DPT 14.* - 32 Bit Float
148116
if (datatype.mainGroup == 14 && datatype.subGroup <= 79 && !datatype.index)
149117
return valueToBusValueFloat32(value, payload, payload_length, datatype);
@@ -235,25 +203,6 @@ namespace Knx
235203
return false;
236204
}
237205

238-
int busValueToDate(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
239-
{
240-
ASSERT_PAYLOAD(3);
241-
unsigned short year = unsigned8FromPayload(payload, 2) & 0x7F;
242-
unsigned char month = unsigned8FromPayload(payload, 1) & 0x0F;
243-
unsigned char day = unsigned8FromPayload(payload, 0) & 0x1F;
244-
245-
if (year > 99 || month < 1 || month > 12 || day < 1)
246-
return false;
247-
248-
struct tm tmp = {0};
249-
year += year >= 90 ? 1900 : 2000;
250-
tmp.tm_mday = day;
251-
tmp.tm_year = year;
252-
tmp.tm_mon = month;
253-
value = tmp;
254-
return true;
255-
}
256-
257206
int busValueToUnsigned32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
258207
{
259208
ASSERT_PAYLOAD(4);
@@ -716,19 +665,6 @@ namespace Knx
716665

717666
//-------------------------------------------------------------------------------------------------------------------------------------
718667

719-
int valueToBusValueDate(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
720-
{
721-
struct tm tmp = value;
722-
723-
if (tmp.tm_year < 1990 || tmp.tm_year > 2089)
724-
return false;
725-
726-
unsigned8ToPayload(payload, 0, tmp.tm_mday, 0x1F);
727-
unsigned8ToPayload(payload, 1, tmp.tm_mon, 0x0F);
728-
unsigned8ToPayload(payload, 2, tmp.tm_year % 100, 0x7F);
729-
return true;
730-
}
731-
732668
int valueToBusValueUnsigned32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
733669
{
734670
if ((int64_t)value < INT64_C(0) || (int64_t)value > INT64_C(4294967295))
@@ -738,15 +674,6 @@ namespace Knx
738674
return true;
739675
}
740676

741-
int valueToBusValueSigned32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
742-
{
743-
if ((int64_t)value < INT64_C(-2147483648) || (int64_t)value > INT64_C(2147483647))
744-
return false;
745-
746-
signed32ToPayload(payload, 0, (uint64_t)value, 0xFFFFFFFF);
747-
return true;
748-
}
749-
750677
int valueToBusValueLongTimePeriod(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
751678
{
752679
if ((int64_t)value < INT64_C(-2147483648) || (int64_t)value > INT64_C(2147483647))

src/knx/group_object/dpt/dptconvert.h

-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ namespace Knx
4747
int KNX_Encode_Value(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
4848

4949
//KNX to internal
50-
int busValueToDate(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
5150
int busValueToUnsigned32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
5251
int busValueToSigned32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
5352
int busValueToLongTimePeriod(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
@@ -73,7 +72,6 @@ namespace Knx
7372
int busValueToActiveEnergy(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
7473

7574
//Internal to KNX
76-
int valueToBusValueDate(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
7775
int valueToBusValueUnsigned32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
7876
int valueToBusValueSigned32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
7977
int valueToBusValueLongTimePeriod(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);

src/knx/group_object/dpt/dpts.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@
88
#include "dpt6.h"
99
#include "dpt7.h"
1010
#include "dpt8.h"
11-
#include "dpt9.h"
11+
#include "dpt9.h"
12+
#include "dpt10.h"
13+
#include "dpt11.h"
14+
#include "dpt12.h"
15+
#include "dpt13.h"

0 commit comments

Comments
 (0)