Skip to content

Commit bf573d8

Browse files
committed
Reimplement Dpt15
1 parent 9ef7f12 commit bf573d8

File tree

7 files changed

+151
-91
lines changed

7 files changed

+151
-91
lines changed

src/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ set(SOURCES
6666
./knx/group_object/dpt/dpt13.h
6767
./knx/group_object/dpt/dpt14.cpp
6868
./knx/group_object/dpt/dpt14.h
69+
./knx/group_object/dpt/dpt15.cpp
70+
./knx/group_object/dpt/dpt15.h
6971
./knx/group_object/dpt/dptconvert.cpp
7072
./knx/group_object/dpt/dptconvert.h
7173
./knx/group_object/group_object.cpp

src/knx/group_object/dpt/dpt.h

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "../group_object.h"
44
namespace Knx
55
{
6-
#define DPT_Access_Data Dpt(15, 0)
76
#define DPT_String_ASCII Dpt(16, 0)
87
#define DPT_String_8859_1 Dpt(16, 1)
98
#define DPT_SceneNumber Dpt(17, 1)

src/knx/group_object/dpt/dpt15.cpp

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#include "dpt15.h"
2+
3+
#include "dptconvert.h"
4+
5+
Knx::Go_SizeCode Knx::Dpt15::size() const
6+
{
7+
return Go_4_Octets;
8+
}
9+
10+
void Knx::Dpt15::encode(uint8_t* data) const
11+
{
12+
13+
for (int n = 0, factor = 100000; n < 6; ++n, factor /= 10)
14+
bcdToPayload(data, n, (_accessCode / factor) % 10);
15+
16+
bitToPayload(data, 24, _detectionError);
17+
bitToPayload(data, 25, _permission);
18+
bitToPayload(data, 26, _readDirection == RightToLeft);
19+
bitToPayload(data, 27, _encrypted);
20+
bcdToPayload(data, 7, _index);
21+
}
22+
23+
bool Knx::Dpt15::decode(uint8_t* data)
24+
{
25+
int32_t digits = 0;
26+
27+
for (int n = 0, factor = 100000; n < 6; ++n, factor /= 10)
28+
{
29+
unsigned char digit = bcdFromPayload(data, n);
30+
31+
if (digit > 9)
32+
return false;
33+
34+
digits += digit * factor;
35+
}
36+
37+
_accessCode = digits;
38+
_detectionError = bitFromPayload(data, 24);
39+
_permission = bitFromPayload(data, 25);
40+
_readDirection = bitFromPayload(data, 26) ? RightToLeft : LeftToRight;
41+
_encrypted = bitFromPayload(data, 27);
42+
_index = bcdFromPayload(data, 7);
43+
return true;
44+
}
45+
46+
uint32_t Knx::Dpt15::accessCode() const
47+
{
48+
return _accessCode;
49+
}
50+
51+
void Knx::Dpt15::accessCode(const uint32_t value)
52+
{
53+
if (value > 999999)
54+
return;
55+
56+
_accessCode = value;
57+
}
58+
59+
bool Knx::Dpt15::detectionError() const
60+
{
61+
return _detectionError;
62+
}
63+
64+
void Knx::Dpt15::detetionError(const bool value)
65+
{
66+
_detectionError = value;
67+
}
68+
69+
bool Knx::Dpt15::permission() const
70+
{
71+
return _permission;
72+
}
73+
74+
void Knx::Dpt15::permission(const bool value)
75+
{
76+
_permission = value;
77+
}
78+
79+
Knx::Dpt15::ReadDirectionValue Knx::Dpt15::readDirection() const
80+
{
81+
return _readDirection;
82+
}
83+
84+
void Knx::Dpt15::readDirection(const ReadDirectionValue value)
85+
{
86+
_readDirection = value;
87+
}
88+
89+
bool Knx::Dpt15::encrypted() const
90+
{
91+
return _encrypted;
92+
}
93+
94+
void Knx::Dpt15::encrypted(const bool value)
95+
{
96+
_encrypted = value;
97+
}
98+
99+
uint8_t Knx::Dpt15::index() const
100+
{
101+
return _index;
102+
}
103+
104+
void Knx::Dpt15::index(const uint8_t value)
105+
{
106+
if (value > 15)
107+
return;
108+
109+
_index = value;
110+
}

src/knx/group_object/dpt/dpt15.h

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#pragma once
2+
#include "dpt.h"
3+
namespace Knx
4+
{
5+
class Dpt15: public Dpt
6+
{
7+
enum ReadDirectionValue { LeftToRight = 0, RightToLeft = 1};
8+
public:
9+
Dpt15() {};
10+
Go_SizeCode size() const override;
11+
12+
void encode(uint8_t* data) const override;
13+
bool decode(uint8_t* data) override;
14+
15+
uint32_t accessCode() const;
16+
void accessCode(const uint32_t value);
17+
bool detectionError() const;
18+
void detetionError(const bool value);
19+
bool permission() const;
20+
void permission(const bool value);
21+
ReadDirectionValue readDirection() const;
22+
void readDirection(const ReadDirectionValue value);
23+
bool encrypted() const;
24+
void encrypted(const bool value);
25+
uint8_t index() const;
26+
void index(const uint8_t value);
27+
private:
28+
uint32_t _accessCode;
29+
bool _detectionError;
30+
bool _permission;
31+
ReadDirectionValue _readDirection;
32+
bool _encrypted;
33+
uint8_t _index;
34+
};
35+
36+
typedef Dpt15 DPT_Access_Data;
37+
}

src/knx/group_object/dpt/dptconvert.cpp

-87
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ namespace Knx
1818
{
1919
if (payload_length > 0)
2020
{
21-
// DPT 15.* - Access Data
22-
if (datatype.mainGroup == 15 && !datatype.subGroup && datatype.index <= 5)
23-
return busValueToAccess(payload, payload_length, datatype, value);
24-
2521
// DPT 16.* - String
2622
if (datatype.mainGroup == 16 && datatype.subGroup <= 1 && !datatype.index)
2723
return busValueToString(payload, payload_length, datatype, value);
@@ -108,10 +104,6 @@ namespace Knx
108104

109105
int KNX_Encode_Value(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
110106
{
111-
// DPT 15.* - Access Data
112-
if (datatype.mainGroup == 15 && !datatype.subGroup && datatype.index <= 5)
113-
return valueToBusValueAccess(value, payload, payload_length, datatype);
114-
115107
// DPT 16.* - String
116108
if (datatype.mainGroup == 16 && datatype.subGroup <= 1 && !datatype.index)
117109
return valueToBusValueString(value, payload, payload_length, datatype);
@@ -202,45 +194,6 @@ namespace Knx
202194
return true;
203195
}
204196

205-
int busValueToAccess(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
206-
{
207-
ASSERT_PAYLOAD(4);
208-
209-
switch (datatype.index)
210-
{
211-
case 0:
212-
{
213-
int32_t digits = 0;
214-
215-
for (int n = 0, factor = 100000; n < 6; ++n, factor /= 10)
216-
{
217-
unsigned char digit = bcdFromPayload(payload, n);
218-
219-
if (digit > 9)
220-
return false;
221-
222-
digits += digit * factor;
223-
}
224-
225-
value = digits;
226-
return true;
227-
}
228-
229-
case 1:
230-
case 2:
231-
case 3:
232-
case 4:
233-
value = bitFromPayload(payload, 23 + datatype.index);
234-
return true;
235-
236-
case 5:
237-
value = bcdFromPayload(payload, 7);
238-
return true;
239-
}
240-
241-
return false;
242-
}
243-
244197
int busValueToString(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
245198
{
246199
ASSERT_PAYLOAD(14);
@@ -645,46 +598,6 @@ namespace Knx
645598
return true;
646599
}
647600

648-
int valueToBusValueAccess(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
649-
{
650-
switch (datatype.index)
651-
{
652-
case 0:
653-
{
654-
if ((int64_t)value < INT64_C(0) || (int64_t)value > INT64_C(999999))
655-
return false;
656-
657-
ENSURE_PAYLOAD(4);
658-
659-
for (int n = 0, factor = 100000; n < 6; ++n, factor /= 10)
660-
bcdToPayload(payload, n, ((uint64_t)value / factor) % 10);
661-
662-
break;
663-
}
664-
665-
case 1:
666-
case 2:
667-
case 3:
668-
case 4:
669-
bitToPayload(payload, 23 + datatype.index, value);
670-
break;
671-
672-
case 5:
673-
{
674-
if ((uint64_t)value > INT64_C(15))
675-
return false;
676-
677-
bcdToPayload(payload, 7, (uint64_t)value);
678-
break;
679-
}
680-
681-
default:
682-
return false;
683-
}
684-
685-
return true;
686-
}
687-
688601
int valueToBusValueString(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
689602
{
690603
const char* strValue = value;

src/knx/group_object/dpt/dptconvert.h

-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ namespace Knx
4949
//KNX to internal
5050
int busValueToUnsigned32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
5151
int busValueToSigned32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
52-
int busValueToAccess(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
5352
int busValueToString(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
5453
int busValueToScene(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
5554
int busValueToSceneControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
@@ -72,7 +71,6 @@ namespace Knx
7271
//Internal to KNX
7372
int valueToBusValueUnsigned32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
7473
int valueToBusValueSigned32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
75-
int valueToBusValueAccess(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
7674
int valueToBusValueString(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
7775
int valueToBusValueScene(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
7876
int valueToBusValueSceneControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);

src/knx/group_object/dpt/dpts.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
#include "dpt11.h"
1414
#include "dpt12.h"
1515
#include "dpt13.h"
16-
#include "dpt14.h"
16+
#include "dpt14.h"
17+
#include "dpt15.h"

0 commit comments

Comments
 (0)