Skip to content

Commit

Permalink
refactor dpts
Browse files Browse the repository at this point in the history
  • Loading branch information
thelsing committed Sep 13, 2024
1 parent 5ef9c8c commit 00b9c98
Show file tree
Hide file tree
Showing 18 changed files with 614 additions and 371 deletions.
1 change: 0 additions & 1 deletion examples/knx-cc1310/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ set(${PROJECT_NAME}_SOURCES
../../src/knx/interface_object/data_property.h
../../src/knx/interface_object/device_object.cpp
../../src/knx/interface_object/device_object.h
../../src/knx/group_object/dpt/dpt.cpp
../../src/knx/group_object/dpt/dpt.h
../../src/knx/group_object/dpt/dptconvert.cpp
../../src/knx/group_object/dpt/dptconvert.h
Expand Down
7 changes: 5 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ set(SOURCES
./knx/data_secure/security_interface_object.cpp
./knx/data_secure/security_interface_object.h
./knx/group_object/dpt/dpts.h
./knx/group_object/dpt/dpt.cpp
./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/dpt3.h
./knx/group_object/dpt/dpt4.cpp
./knx/group_object/dpt/dpt4.h
./knx/group_object/dpt/dpt5.cpp
./knx/group_object/dpt/dpt5.h
./knx/group_object/dpt/dpt9.cpp
./knx/group_object/dpt/dpt9.h
./knx/group_object/dpt/dptconvert.cpp
Expand Down
19 changes: 0 additions & 19 deletions src/knx/group_object/dpt/dpt.cpp

This file was deleted.

51 changes: 19 additions & 32 deletions src/knx/group_object/dpt/dpt.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@
#include "../group_object.h"
namespace Knx
{
#define DPT_Control_Dimming Dpt(3, 7)
#define DPT_Control_Blinds Dpt(3, 8)
#define DPT_Char_ASCII Dpt(4, 1)
#define DPT_Char_8859_1 Dpt(4, 2)
#define DPT_Scaling Dpt(5, 1)
#define DPT_Angle Dpt(5, 3)
#define DPT_Percent_U8 Dpt(5, 4)
#define DPT_DecimalFactor Dpt(5, 5)
#define DPT_Tariff Dpt(5, 6)
#define DPT_Value_1_Ucount Dpt(5, 10)




#define DPT_Percent_V8 Dpt(6, 1)
#define DPT_Value_1_Count Dpt(6, 10)
#define DPT_Status_Mode3 Dpt(6, 20)
Expand All @@ -36,25 +30,6 @@ namespace Knx
#define DPT_DeltaTimeHrs Dpt(8, 7)
#define DPT_Percent_V16 Dpt(8, 10)
#define DPT_Rotation_Angle Dpt(8, 11)
#define DPT_Value_Temp Dpt(9, 1)
#define DPT_Value_Tempd Dpt(9, 2)
#define DPT_Value_Tempa Dpt(9, 3)
#define DPT_Value_Lux Dpt(9, 4)
#define DPT_Value_Wsp Dpt(9, 5)
#define DPT_Value_Pres Dpt(9, 6)
#define DPT_Value_Humidity Dpt(9, 7)
#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)
#define DPT_Value_Curr Dpt(9, 21)
#define DPT_PowerDensity Dpt(9, 22)
#define DPT_KelvinPerPercent Dpt(9, 23)
#define DPT_Power Dpt(9, 24)
#define DPT_Value_Volume_Flow Dpt(9, 25)
#define DPT_Rain_Amount Dpt(9, 26)
#define DPT_Value_Temp_F Dpt(9, 27)
#define DPT_Value_Wsp_kmh Dpt(9, 28)
#define DPT_TimeOfDay Dpt(10, 1, 1)
#define DPT_Date Dpt(11, 1)
#define DPT_Value_4_Ucount Dpt(12, 1)
Expand Down Expand Up @@ -328,19 +303,31 @@ namespace Knx
#define DPT_StatusSAB Dpt(241, 800)
#define DPT_Colour_RGBW Dpt(251, 600)

/**
* This class represents a value to sent to or receive from the bus. The stored data is always a valid representation of the Dpt.
*/
class Dpt
{
public:
Dpt();
Dpt(short mainGroup, short subGroup, short index = 0);
virtual ~Dpt() {}
unsigned short mainGroup;
unsigned short subGroup;
unsigned short index;

/**
* Size of the Dpt. It can only assigned to or received from group objects with a matching size code.
*/
virtual Go_SizeCode size() const = 0;

/**
* Encode the data to a byte array. The size of the array is implict decided by the size of the Dpt.
*/
virtual void encode(uint8_t* data) const = 0;
virtual void decode(uint8_t* data) = 0;

/**
* Decodes the data from a byte array. @return true if the data can be decoded without error and false otherwise.
* This method will also return false, if the date could fit the datatype but is invalid for this Dpt.
*/
virtual bool decode(uint8_t* data) = 0;
};
}
82 changes: 5 additions & 77 deletions src/knx/group_object/dpt/dpt1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

#include "dptconvert.h"

Knx::Dpt1::Dpt1(unsigned short subgroup /*= 0*/) : Dpt(1, subgroup) {}
Knx::Dpt1::Dpt1() {}

Knx::Dpt1::Dpt1(bool value) : Dpt1()
Knx::Dpt1::Dpt1(bool value)
{
_value = value;
this->value(value);
}

Knx::Go_SizeCode Knx::Dpt1::size() const
Expand All @@ -19,9 +19,10 @@ void Knx::Dpt1::encode(uint8_t* data) const
bitToPayload(data, 7, _value);
}

void Knx::Dpt1::decode(uint8_t* data)
bool Knx::Dpt1::decode(uint8_t* data)
{
_value = bitFromPayload(data, 7);
return true;
}

void Knx::Dpt1::value(bool value)
Expand All @@ -39,81 +40,8 @@ Knx::Dpt1::operator bool() const
return _value;
}


Knx::Dpt1& Knx::Dpt1::operator=(const bool value)
{
_value = value;
return *this;
}

Knx::DPT_Switch::DPT_Switch() : Dpt1()
{
subGroup = 1;
}

Knx::DPT_Switch::DPT_Switch(SwitchValue value) : Dpt1(value == On)
{
subGroup = 1;
}

void Knx::DPT_Switch::value(SwitchValue value)
{
Dpt1::value(value == On);
}

Knx::DPT_Switch::SwitchValue Knx::DPT_Switch::value() const
{
return Dpt1::value() ? On : Off;
}

Knx::DPT_Switch::operator Knx::DPT_Switch::SwitchValue() const
{
return value();
}

Knx::DPT_Switch& Knx::DPT_Switch::operator=(const Knx::DPT_Switch::SwitchValue value)
{
Dpt1::value(value == On);
return *this;
}

Knx::DPT_Bool::DPT_Bool() : Dpt1()
{
subGroup = 2;
}

Knx::DPT_Bool::DPT_Bool(bool value) : DPT_Bool()
{
Dpt1::value(value);
}

Knx::DPT_Enable::DPT_Enable() : Dpt1()
{
subGroup = 3;
}

Knx::DPT_Enable::DPT_Enable(EnableValue value) : Dpt1(value == Enable)
{
subGroup = 3;
}

void Knx::DPT_Enable::value(EnableValue value)
{
Dpt1::value(value == Enable);
}

Knx::DPT_Enable::EnableValue Knx::DPT_Enable::value() const
{
return Dpt1::value() ? Enable : Disable;
}

Knx::DPT_Enable::operator Knx::DPT_Enable::EnableValue() const
{
return value();
}

Knx::DPT_Enable& Knx::DPT_Enable::operator=(const Knx::DPT_Enable::EnableValue value)
{
Dpt1::value(value == Enable);
return *this;
}
Loading

0 comments on commit 00b9c98

Please sign in to comment.