Skip to content

Commit

Permalink
reimplement Dpt17
Browse files Browse the repository at this point in the history
  • Loading branch information
thelsing committed Sep 22, 2024
1 parent e67369c commit 7280cd0
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 46 deletions.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/knx/group_object/dpt/dpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions src/knx/group_object/dpt/dpt17.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
18 changes: 18 additions & 0 deletions src/knx/group_object/dpt/dpt17.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#include "dpt.h"
namespace Knx
{
class DPT_SceneNumber: public ValueDpt<uint8_t>
{
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;
};
}
42 changes: 0 additions & 42 deletions src/knx/group_object/dpt/dptconvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions src/knx/group_object/dpt/dptconvert.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/knx/group_object/dpt/dpts.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
#include "dpt13.h"
#include "dpt14.h"
#include "dpt15.h"
#include "dpt16.h"
#include "dpt16.h"
#include "dpt17.h"

0 comments on commit 7280cd0

Please sign in to comment.