mirror of
https://github.com/thelsing/knx.git
synced 2025-04-19 01:15:27 +02:00
refactor dpts
This commit is contained in:
parent
5ef9c8c040
commit
00b9c98786
@ -71,7 +71,6 @@ set(${PROJECT_NAME}_SOURCES
|
|||||||
../../src/knx/interface_object/data_property.h
|
../../src/knx/interface_object/data_property.h
|
||||||
../../src/knx/interface_object/device_object.cpp
|
../../src/knx/interface_object/device_object.cpp
|
||||||
../../src/knx/interface_object/device_object.h
|
../../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/dpt.h
|
||||||
../../src/knx/group_object/dpt/dptconvert.cpp
|
../../src/knx/group_object/dpt/dptconvert.cpp
|
||||||
../../src/knx/group_object/dpt/dptconvert.h
|
../../src/knx/group_object/dpt/dptconvert.h
|
||||||
|
@ -39,12 +39,15 @@ set(SOURCES
|
|||||||
./knx/data_secure/security_interface_object.cpp
|
./knx/data_secure/security_interface_object.cpp
|
||||||
./knx/data_secure/security_interface_object.h
|
./knx/data_secure/security_interface_object.h
|
||||||
./knx/group_object/dpt/dpts.h
|
./knx/group_object/dpt/dpts.h
|
||||||
./knx/group_object/dpt/dpt.cpp
|
|
||||||
./knx/group_object/dpt/dpt.h
|
./knx/group_object/dpt/dpt.h
|
||||||
./knx/group_object/dpt/dpt1.cpp
|
./knx/group_object/dpt/dpt1.cpp
|
||||||
./knx/group_object/dpt/dpt1.h
|
./knx/group_object/dpt/dpt1.h
|
||||||
./knx/group_object/dpt/dpt2.cpp
|
|
||||||
./knx/group_object/dpt/dpt2.h
|
./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.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
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
#include "dpt.h"
|
|
||||||
|
|
||||||
#include "../../util/logger.h"
|
|
||||||
#include "../../bits.h"
|
|
||||||
|
|
||||||
#define LOGGER Logger::logger("Dpt")
|
|
||||||
|
|
||||||
namespace Knx
|
|
||||||
{
|
|
||||||
Dpt::Dpt()
|
|
||||||
{}
|
|
||||||
|
|
||||||
Dpt::Dpt(short mainGroup, short subGroup, short index /* = 0 */)
|
|
||||||
: mainGroup(mainGroup), subGroup(subGroup), index(index)
|
|
||||||
{
|
|
||||||
if (subGroup == 0)
|
|
||||||
LOGGER.warning("You used and invalid Dpt *.0");
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,16 +3,10 @@
|
|||||||
#include "../group_object.h"
|
#include "../group_object.h"
|
||||||
namespace Knx
|
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_Percent_V8 Dpt(6, 1)
|
||||||
#define DPT_Value_1_Count Dpt(6, 10)
|
#define DPT_Value_1_Count Dpt(6, 10)
|
||||||
#define DPT_Status_Mode3 Dpt(6, 20)
|
#define DPT_Status_Mode3 Dpt(6, 20)
|
||||||
@ -36,25 +30,6 @@ namespace Knx
|
|||||||
#define DPT_DeltaTimeHrs Dpt(8, 7)
|
#define DPT_DeltaTimeHrs Dpt(8, 7)
|
||||||
#define DPT_Percent_V16 Dpt(8, 10)
|
#define DPT_Percent_V16 Dpt(8, 10)
|
||||||
#define DPT_Rotation_Angle Dpt(8, 11)
|
#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_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)
|
||||||
@ -328,19 +303,31 @@ namespace Knx
|
|||||||
#define DPT_StatusSAB Dpt(241, 800)
|
#define DPT_StatusSAB Dpt(241, 800)
|
||||||
#define DPT_Colour_RGBW Dpt(251, 600)
|
#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
|
class Dpt
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Dpt();
|
|
||||||
Dpt(short mainGroup, short subGroup, short index = 0);
|
|
||||||
virtual ~Dpt() {}
|
virtual ~Dpt() {}
|
||||||
unsigned short mainGroup;
|
unsigned short mainGroup;
|
||||||
unsigned short subGroup;
|
unsigned short subGroup;
|
||||||
unsigned short index;
|
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;
|
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 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;
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
#include "dptconvert.h"
|
#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
|
Knx::Go_SizeCode Knx::Dpt1::size() const
|
||||||
@ -19,9 +19,10 @@ void Knx::Dpt1::encode(uint8_t* data) const
|
|||||||
bitToPayload(data, 7, _value);
|
bitToPayload(data, 7, _value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Knx::Dpt1::decode(uint8_t* data)
|
bool Knx::Dpt1::decode(uint8_t* data)
|
||||||
{
|
{
|
||||||
_value = bitFromPayload(data, 7);
|
_value = bitFromPayload(data, 7);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Knx::Dpt1::value(bool value)
|
void Knx::Dpt1::value(bool value)
|
||||||
@ -39,81 +40,8 @@ Knx::Dpt1::operator bool() const
|
|||||||
return _value;
|
return _value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Knx::Dpt1& Knx::Dpt1::operator=(const bool value)
|
Knx::Dpt1& Knx::Dpt1::operator=(const bool value)
|
||||||
{
|
{
|
||||||
_value = value;
|
_value = value;
|
||||||
return *this;
|
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;
|
|
||||||
}
|
|
@ -5,12 +5,12 @@ namespace Knx
|
|||||||
class Dpt1: public Dpt
|
class Dpt1: public Dpt
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Dpt1(unsigned short subgroup = 0);
|
Dpt1();
|
||||||
Dpt1(bool value);
|
Dpt1(bool value);
|
||||||
Go_SizeCode size() const override;
|
Go_SizeCode size() const override;
|
||||||
|
|
||||||
virtual void encode(uint8_t* data) const override;
|
void encode(uint8_t* data) const override;
|
||||||
virtual void decode(uint8_t* data) override;
|
bool decode(uint8_t* data) override;
|
||||||
|
|
||||||
void value(bool value);
|
void value(bool value);
|
||||||
bool value() const;
|
bool value() const;
|
||||||
@ -20,64 +20,164 @@ namespace Knx
|
|||||||
bool _value;
|
bool _value;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DPT_Switch : public Dpt1
|
template<typename T> class DPT1 : public Dpt1
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum SwitchValue
|
DPT1() {};
|
||||||
|
DPT1(T value) : Dpt1(((int)value) == 1) {}
|
||||||
|
void value(T value)
|
||||||
{
|
{
|
||||||
Off, On
|
Dpt1::value(((int)value) == 1);
|
||||||
};
|
}
|
||||||
|
T value() const
|
||||||
DPT_Switch();
|
|
||||||
DPT_Switch(SwitchValue value);
|
|
||||||
void value(SwitchValue value);
|
|
||||||
SwitchValue value() const;
|
|
||||||
operator SwitchValue() const;
|
|
||||||
DPT_Switch& operator=(const SwitchValue value);
|
|
||||||
};
|
|
||||||
|
|
||||||
class DPT_Bool : public Dpt1
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
DPT_Bool();
|
|
||||||
DPT_Bool(bool value);
|
|
||||||
};
|
|
||||||
|
|
||||||
class DPT_Enable : public Dpt1
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
enum EnableValue
|
|
||||||
{
|
{
|
||||||
Disable, Enable
|
return Dpt1::value() ? (T)1 : (T)0;
|
||||||
};
|
}
|
||||||
|
operator T() const
|
||||||
DPT_Enable();
|
{
|
||||||
DPT_Enable(EnableValue value);
|
return value();
|
||||||
void value(EnableValue value);
|
}
|
||||||
EnableValue value() const;
|
DPT1& operator=(const T value)
|
||||||
operator EnableValue() const;
|
{
|
||||||
DPT_Enable& operator=(const EnableValue value);
|
this->value(value);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO:
|
enum SwitchValue
|
||||||
#define DPT_Ramp Dpt1(4)
|
{
|
||||||
#define DPT_Alarm Dpt1(5)
|
Off = 0, On = 1
|
||||||
#define DPT_BinaryValue Dpt1(6)
|
};
|
||||||
#define DPT_Step Dpt1(7)
|
typedef DPT1<SwitchValue> DPT_Switch;
|
||||||
#define DPT_UpDown Dpt1(8)
|
|
||||||
#define DPT_OpenClose Dpt1(9)
|
typedef Dpt1 DPT_Bool;
|
||||||
#define DPT_Start Dpt1(10)
|
|
||||||
#define DPT_State Dpt1(11)
|
enum EnableValue
|
||||||
#define DPT_Invert Dpt1(12)
|
{
|
||||||
#define DPT_DimSendStyle Dpt1(13)
|
Disable = 0, Enable = 1
|
||||||
#define DPT_InputSource Dpt1(14)
|
};
|
||||||
#define DPT_Reset Dpt1(15)
|
typedef DPT1<EnableValue> DPT_Enable;
|
||||||
#define DPT_Ack Dpt1(16)
|
|
||||||
#define DPT_Trigger Dpt1(17)
|
enum RampValue
|
||||||
#define DPT_Occupancy Dpt1(18)
|
{
|
||||||
#define DPT_Window_Door Dpt1(19)
|
NoRamp = 0, Ramp = 1
|
||||||
#define DPT_LogicalFunction Dpt1(21)
|
};
|
||||||
#define DPT_Scene_AB Dpt1(22)
|
typedef DPT1<RampValue> DPT_Ramp;
|
||||||
#define DPT_ShutterBlinds_Mode Dpt1(23)
|
|
||||||
#define DPT_DayNight Dpt1(24)
|
enum AlarmValue
|
||||||
|
{
|
||||||
|
NoAlarm = 0, Alarm = 1
|
||||||
|
};
|
||||||
|
typedef DPT1<AlarmValue> DPT_Alarm;
|
||||||
|
|
||||||
|
enum BinaryValue
|
||||||
|
{
|
||||||
|
Low = 0, High = 1
|
||||||
|
};
|
||||||
|
typedef DPT1<BinaryValue> DPT_BinaryValue;
|
||||||
|
|
||||||
|
enum StepValue
|
||||||
|
{
|
||||||
|
Decrease = 0, Increase = 1
|
||||||
|
};
|
||||||
|
typedef DPT1<StepValue> DPT_Step;
|
||||||
|
|
||||||
|
enum UpDownValue
|
||||||
|
{
|
||||||
|
Up = 0, Down = 1
|
||||||
|
};
|
||||||
|
typedef DPT1<UpDownValue> DPT_UpDown;
|
||||||
|
|
||||||
|
enum OpenCloseValue
|
||||||
|
{
|
||||||
|
OpenNormallyOpen = 0, ClosedNormallyOpen = 1
|
||||||
|
};
|
||||||
|
typedef DPT1<OpenCloseValue> DPT_OpenClose;
|
||||||
|
|
||||||
|
enum StartValue
|
||||||
|
{
|
||||||
|
Stop = 0, Start = 1
|
||||||
|
};
|
||||||
|
typedef DPT1<StartValue> DPT_Start;
|
||||||
|
|
||||||
|
enum StateValue
|
||||||
|
{
|
||||||
|
Inactive = 0, Active = 1
|
||||||
|
};
|
||||||
|
typedef DPT1<StateValue> DPT_State;
|
||||||
|
|
||||||
|
enum InvertValue
|
||||||
|
{
|
||||||
|
NotInverted = 0, Inverted = 1
|
||||||
|
};
|
||||||
|
typedef DPT1<InvertValue> DPT_Invert;
|
||||||
|
|
||||||
|
enum DimSendStyleValue
|
||||||
|
{
|
||||||
|
StartStop = 0, Cyclically = 1
|
||||||
|
};
|
||||||
|
typedef DPT1<DimSendStyleValue> DPT_DimSendStyle;
|
||||||
|
|
||||||
|
enum InputSourceValue
|
||||||
|
{
|
||||||
|
Fixed = 0, Calculated = 1
|
||||||
|
};
|
||||||
|
typedef DPT1<InputSourceValue> DPT_InputSource;
|
||||||
|
|
||||||
|
enum ResetValue
|
||||||
|
{
|
||||||
|
NoActionReset = 0, ResetCommand = 1
|
||||||
|
};
|
||||||
|
typedef DPT1<ResetValue> DPT_Reset;
|
||||||
|
|
||||||
|
enum AckValue
|
||||||
|
{
|
||||||
|
NoActionAck = 0, AcknowledgeCommand = 1
|
||||||
|
};
|
||||||
|
typedef DPT1<AckValue> DPT_Ack;
|
||||||
|
|
||||||
|
typedef Dpt1 DPT_Trigger;
|
||||||
|
|
||||||
|
enum OccupancyValue
|
||||||
|
{
|
||||||
|
NotOccupied = 0, Occupied = 1
|
||||||
|
};
|
||||||
|
typedef DPT1<OccupancyValue> DPT_Occupancy;
|
||||||
|
|
||||||
|
enum WindowDoorValue
|
||||||
|
{
|
||||||
|
ClosedNormallyClosed = 0, OpenNormallyClosed = 1
|
||||||
|
};
|
||||||
|
typedef DPT1<WindowDoorValue> DPT_Window_Door;
|
||||||
|
|
||||||
|
enum LogicalFunctionValue
|
||||||
|
{
|
||||||
|
OR = 0, AND = 1
|
||||||
|
};
|
||||||
|
typedef DPT1<LogicalFunctionValue> DPT_LogicalFunction;
|
||||||
|
|
||||||
|
enum SceneABValue
|
||||||
|
{
|
||||||
|
SceneA = 0, SceneB = 1
|
||||||
|
};
|
||||||
|
typedef DPT1<SceneABValue> DPT_Scene_AB;
|
||||||
|
|
||||||
|
enum ShutterBlindsMode
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Only move up/down
|
||||||
|
*/
|
||||||
|
Shutter = 0,
|
||||||
|
/**
|
||||||
|
* move up/down and step/stop
|
||||||
|
*/
|
||||||
|
Blinds = 1
|
||||||
|
};
|
||||||
|
typedef DPT1<ShutterBlindsMode> DPT_ShutterBlinds_Mode;
|
||||||
|
|
||||||
|
enum DayNightValue
|
||||||
|
{
|
||||||
|
Day = 0, Night = 1
|
||||||
|
};
|
||||||
|
typedef DPT1<DayNightValue> DPT_DayNight;
|
||||||
}
|
}
|
@ -1,64 +0,0 @@
|
|||||||
#include "dpt2.h"
|
|
||||||
|
|
||||||
#include "dptconvert.h"
|
|
||||||
|
|
||||||
Knx::Dpt2::Dpt2(unsigned short subgroup /* = 0*/) : Dpt(2, subgroup) {}
|
|
||||||
|
|
||||||
Knx::Dpt2::Dpt2(Dpt2Value value) : Dpt2()
|
|
||||||
{
|
|
||||||
_value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
Knx::Go_SizeCode Knx::Dpt2::size() const
|
|
||||||
{
|
|
||||||
return Go_2_Bit;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Knx::Dpt2::encode(uint8_t* data) const
|
|
||||||
{
|
|
||||||
if (_value == NoControl)
|
|
||||||
{
|
|
||||||
bitToPayload(data, 6, false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bitToPayload(data, 6, true);
|
|
||||||
bitToPayload(data, 7, _value == Control_Function1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Knx::Dpt2::decode(uint8_t* data)
|
|
||||||
{
|
|
||||||
bool c = bitFromPayload(data, 6);
|
|
||||||
|
|
||||||
if (!c)
|
|
||||||
{
|
|
||||||
_value = NoControl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool v = bitFromPayload(data, 7);
|
|
||||||
|
|
||||||
_value = v ? Control_Function1 : Control_Function0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Knx::Dpt2::value(Dpt2Value value)
|
|
||||||
{
|
|
||||||
_value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
Knx::Dpt2::Dpt2Value Knx::Dpt2::value() const
|
|
||||||
{
|
|
||||||
return _value;
|
|
||||||
}
|
|
||||||
|
|
||||||
Knx::Dpt2::operator Dpt2Value() const
|
|
||||||
{
|
|
||||||
return _value;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Knx::Dpt2& Knx::Dpt2::operator=(const Dpt2Value value)
|
|
||||||
{
|
|
||||||
_value = value;
|
|
||||||
return *this;
|
|
||||||
}
|
|
@ -1,40 +1,85 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "dpt.h"
|
#include "dpt.h"
|
||||||
|
#include "dpt1.h"
|
||||||
|
#include "dptconvert.h"
|
||||||
|
|
||||||
namespace Knx
|
namespace Knx
|
||||||
{
|
{
|
||||||
class Dpt2: public Dpt
|
enum ControlValue
|
||||||
|
{
|
||||||
|
NoControl, Control
|
||||||
|
};
|
||||||
|
template<typename T> class DPT2: public Dpt
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum Dpt2Value
|
Go_SizeCode size() const override
|
||||||
{
|
{
|
||||||
NoControl, Control_Function0, Control_Function1
|
return Go_2_Bit;
|
||||||
};
|
}
|
||||||
|
|
||||||
Dpt2(unsigned short subgroup = 0);
|
void encode(uint8_t* data) const override
|
||||||
Dpt2(Dpt2Value value);
|
{
|
||||||
Go_SizeCode size() const override;
|
if (_control == NoControl)
|
||||||
|
{
|
||||||
|
bitToPayload(data, 6, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void encode(uint8_t* data) const override;
|
bitToPayload(data, 6, true);
|
||||||
virtual void decode(uint8_t* data) override;
|
bitToPayload(data, 7, ((int)_value) == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool decode(uint8_t* data) override
|
||||||
|
{
|
||||||
|
bool c = bitFromPayload(data, 6);
|
||||||
|
|
||||||
|
if (!c)
|
||||||
|
{
|
||||||
|
_control = NoControl;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool v = bitFromPayload(data, 7);
|
||||||
|
|
||||||
|
_value = v ? (T)1 : (T)0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void control(ControlValue control)
|
||||||
|
{
|
||||||
|
_control = control;
|
||||||
|
}
|
||||||
|
|
||||||
|
ControlValue control() const
|
||||||
|
{
|
||||||
|
return _control;
|
||||||
|
}
|
||||||
|
|
||||||
|
void value(T value)
|
||||||
|
{
|
||||||
|
_value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
T value() const
|
||||||
|
{
|
||||||
|
return _value;
|
||||||
|
}
|
||||||
|
|
||||||
void value(Dpt2Value value);
|
|
||||||
Dpt2Value value() const;
|
|
||||||
operator Dpt2Value() const;
|
|
||||||
Dpt2& operator=(const Dpt2Value value);
|
|
||||||
private:
|
private:
|
||||||
Dpt2Value _value;
|
ControlValue _control;
|
||||||
|
T _value;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DPT_Switch_Control Dpt2(1)
|
typedef DPT2<SwitchValue> DPT_Switch_Control;
|
||||||
#define DPT_Bool_Control Dpt2(2)
|
typedef DPT2<bool> DPT_Bool_Control;
|
||||||
#define DPT_Enable_Control Dpt2(3)
|
typedef DPT2<EnableValue> DPT_Enable_Control;
|
||||||
#define DPT_Ramp_Control Dpt2(4)
|
typedef DPT2<RampValue> DPT_Ramp_Control;
|
||||||
#define DPT_Alarm_Control Dpt2(5)
|
typedef DPT2<AlarmValue> DPT_Alarm_Control;
|
||||||
#define DPT_BinaryValue_Control Dpt2(6)
|
typedef DPT2<BinaryValue> DPT_BinaryValue_Control;
|
||||||
#define DPT_Step_Control Dpt2(7)
|
typedef DPT2<StepValue> DPT_Step_Control;
|
||||||
#define DPT_Direction1_Control Dpt2(8)
|
typedef DPT2<UpDownValue> DPT_Direction1_Control;
|
||||||
#define DPT_Direction2_Control Dpt2(9)
|
typedef DPT2<UpDownValue> DPT_Direction2_Control;
|
||||||
#define DPT_Start_Control Dpt2(10)
|
typedef DPT2<StartValue> DPT_Start_Control;
|
||||||
#define DPT_State_Control Dpt2(11)
|
typedef DPT2<StateValue> DPT_State_Control;
|
||||||
#define DPT_Invert_Control Dpt2(12)
|
typedef DPT2<InvertValue> DPT_Invert_Control;
|
||||||
}
|
}
|
68
src/knx/group_object/dpt/dpt3.h
Normal file
68
src/knx/group_object/dpt/dpt3.h
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "dpt.h"
|
||||||
|
#include "dpt1.h"
|
||||||
|
#include "dptconvert.h"
|
||||||
|
namespace Knx
|
||||||
|
{
|
||||||
|
template<typename T> class DPT3: public Dpt
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Go_SizeCode size() const override
|
||||||
|
{
|
||||||
|
return Go_4_Bit;
|
||||||
|
}
|
||||||
|
|
||||||
|
void encode(uint8_t* data) const override
|
||||||
|
{
|
||||||
|
bitToPayload(data, 4, ((int)_direction) == 1);
|
||||||
|
unsigned8ToPayload(data, 0, _stepCode, 0x07);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool decode(uint8_t* data) override
|
||||||
|
{
|
||||||
|
bool c = bitFromPayload(data, 4);
|
||||||
|
_direction = c ? (T)1 : (T)0;
|
||||||
|
_stepCode = unsigned8FromPayload(data, 0) & 0x07;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
T direction() const
|
||||||
|
{
|
||||||
|
return _direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
void direction(T value)
|
||||||
|
{
|
||||||
|
_direction = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
float stepPercent() const
|
||||||
|
{
|
||||||
|
if (_stepCode == 0)
|
||||||
|
return 0.0f;
|
||||||
|
|
||||||
|
return 100.0f / (0x1 << (_stepCode - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t stepCode() const
|
||||||
|
{
|
||||||
|
return _stepCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void stepCode(uint8_t value)
|
||||||
|
{
|
||||||
|
_stepCode = value & 0x7;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool stop() const
|
||||||
|
{
|
||||||
|
return _stepCode == 0;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
T _direction;
|
||||||
|
uint8_t _stepCode;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef DPT3<StepValue> DPT_Control_Dimming;
|
||||||
|
typedef DPT3<UpDownValue> DPT_Control_Blinds;
|
||||||
|
}
|
58
src/knx/group_object/dpt/dpt4.cpp
Normal file
58
src/knx/group_object/dpt/dpt4.cpp
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#include "dpt4.h"
|
||||||
|
|
||||||
|
#include "dptconvert.h"
|
||||||
|
|
||||||
|
Knx::Dpt4::Dpt4() {}
|
||||||
|
|
||||||
|
Knx::Dpt4::Dpt4(char value)
|
||||||
|
{
|
||||||
|
_value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Knx::Go_SizeCode Knx::Dpt4::size() const
|
||||||
|
{
|
||||||
|
return Go_1_Octet;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Knx::Dpt4::encode(uint8_t* data) const
|
||||||
|
{
|
||||||
|
unsigned8ToPayload(data, 0, _value, 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Knx::Dpt4::decode(uint8_t* data)
|
||||||
|
{
|
||||||
|
_value = signed8FromPayload(data, 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Knx::Dpt4::value(char value)
|
||||||
|
{
|
||||||
|
_value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
char Knx::Dpt4::value() const
|
||||||
|
{
|
||||||
|
return _value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Knx::Dpt4::operator char() const
|
||||||
|
{
|
||||||
|
return _value;
|
||||||
|
}
|
||||||
|
|
||||||
|
Knx::Dpt4& Knx::Dpt4::operator=(const char value)
|
||||||
|
{
|
||||||
|
_value = value;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Knx::DPT_Char_ASCII::decode(uint8_t* data)
|
||||||
|
{
|
||||||
|
Dpt4::value(signed8FromPayload(data, 0) & 0x7F);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Knx::DPT_Char_ASCII::value(char value)
|
||||||
|
{
|
||||||
|
Dpt4::value(value & 0x7F);
|
||||||
|
}
|
30
src/knx/group_object/dpt/dpt4.h
Normal file
30
src/knx/group_object/dpt/dpt4.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "dpt.h"
|
||||||
|
namespace Knx
|
||||||
|
{
|
||||||
|
class Dpt4: public Dpt
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Dpt4();
|
||||||
|
Dpt4(char value);
|
||||||
|
Go_SizeCode size() const override;
|
||||||
|
|
||||||
|
void encode(uint8_t* data) const override;
|
||||||
|
bool decode(uint8_t* data) override;
|
||||||
|
|
||||||
|
virtual void value(char value);
|
||||||
|
char value() const;
|
||||||
|
operator char() const;
|
||||||
|
Dpt4& operator=(const char value);
|
||||||
|
private:
|
||||||
|
char _value;
|
||||||
|
};
|
||||||
|
|
||||||
|
class DPT_Char_ASCII: public Dpt4
|
||||||
|
{
|
||||||
|
bool decode(uint8_t* data) override;
|
||||||
|
void value(char value) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef Dpt4 DPT_Char_8859_1;
|
||||||
|
}
|
105
src/knx/group_object/dpt/dpt5.cpp
Normal file
105
src/knx/group_object/dpt/dpt5.cpp
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
#include "dpt5.h"
|
||||||
|
|
||||||
|
#include "dptconvert.h"
|
||||||
|
|
||||||
|
Knx::Dpt5::Dpt5() {}
|
||||||
|
|
||||||
|
Knx::Dpt5::Dpt5(float value)
|
||||||
|
{
|
||||||
|
this->value(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
Knx::Go_SizeCode Knx::Dpt5::size() const
|
||||||
|
{
|
||||||
|
return Go_1_Octet;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Knx::Dpt5::encode(uint8_t* data) const
|
||||||
|
{
|
||||||
|
unsigned8ToPayload(data, 0, _rawValue, 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Knx::Dpt5::decode(uint8_t* data)
|
||||||
|
{
|
||||||
|
_rawValue = signed8FromPayload(data, 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Knx::Dpt5::value(float value)
|
||||||
|
{
|
||||||
|
_rawValue = (uint8_t)(value / scale() * 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
float Knx::Dpt5::value() const
|
||||||
|
{
|
||||||
|
return _rawValue / 0xFF * scale();
|
||||||
|
}
|
||||||
|
|
||||||
|
Knx::Dpt5::operator float() const
|
||||||
|
{
|
||||||
|
return value();
|
||||||
|
}
|
||||||
|
|
||||||
|
Knx::Dpt5& Knx::Dpt5::operator=(const float value)
|
||||||
|
{
|
||||||
|
this->value(value);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Knx::DPT_Value_1_Ucount::DPT_Value_1_Ucount() {}
|
||||||
|
|
||||||
|
Knx::DPT_Value_1_Ucount::DPT_Value_1_Ucount(uint8_t value)
|
||||||
|
{
|
||||||
|
this->value(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Knx::DPT_Value_1_Ucount::value(uint8_t value)
|
||||||
|
{
|
||||||
|
Dpt5::_rawValue = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t Knx::DPT_Value_1_Ucount::value() const
|
||||||
|
{
|
||||||
|
return Dpt5::_rawValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Knx::DPT_Value_1_Ucount::operator uint8_t() const
|
||||||
|
{
|
||||||
|
return value();
|
||||||
|
}
|
||||||
|
|
||||||
|
Knx::DPT_Value_1_Ucount& Knx::DPT_Value_1_Ucount::operator=(const uint8_t value)
|
||||||
|
{
|
||||||
|
this->value(value);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Knx::DPT_Tariff::DPT_Tariff() {}
|
||||||
|
|
||||||
|
Knx::DPT_Tariff::DPT_Tariff(uint8_t value)
|
||||||
|
{
|
||||||
|
this->value(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Knx::DPT_Tariff::tariffAvailable()
|
||||||
|
{
|
||||||
|
return _rawValue == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Knx::DPT_Tariff::value(uint8_t value)
|
||||||
|
{
|
||||||
|
if ( value == 0xFF)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Knx::DPT_Tariff::decode(uint8_t* data)
|
||||||
|
{
|
||||||
|
uint8_t value = signed8FromPayload(data, 0);
|
||||||
|
|
||||||
|
if (value == 0xFF)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
_rawValue = value;
|
||||||
|
return true;
|
||||||
|
}
|
68
src/knx/group_object/dpt/dpt5.h
Normal file
68
src/knx/group_object/dpt/dpt5.h
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "dpt.h"
|
||||||
|
namespace Knx
|
||||||
|
{
|
||||||
|
class Dpt5: public Dpt
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Dpt5();
|
||||||
|
Dpt5(float value);
|
||||||
|
Go_SizeCode size() const override;
|
||||||
|
|
||||||
|
void encode(uint8_t* data) const override;
|
||||||
|
bool decode(uint8_t* data) override;
|
||||||
|
|
||||||
|
void value(float value);
|
||||||
|
float value() const;
|
||||||
|
operator float() const;
|
||||||
|
Dpt5& operator=(const float value);
|
||||||
|
protected:
|
||||||
|
virtual float scale() const
|
||||||
|
{
|
||||||
|
return 1.0;
|
||||||
|
};
|
||||||
|
uint8_t _rawValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
class DPT_Scaling : public Dpt5
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
float scale() const override
|
||||||
|
{
|
||||||
|
return 100.0f;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class DPT_Angle : public Dpt5
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
float scale() const override
|
||||||
|
{
|
||||||
|
return 360.0f;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class DPT_Value_1_Ucount : protected Dpt5
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DPT_Value_1_Ucount();
|
||||||
|
DPT_Value_1_Ucount(uint8_t value);
|
||||||
|
virtual void value(uint8_t value);
|
||||||
|
uint8_t value() const;
|
||||||
|
operator uint8_t() const;
|
||||||
|
DPT_Value_1_Ucount& operator=(const uint8_t value);
|
||||||
|
};
|
||||||
|
|
||||||
|
class DPT_Tariff: public DPT_Value_1_Ucount
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DPT_Tariff();
|
||||||
|
DPT_Tariff(uint8_t value);
|
||||||
|
bool tariffAvailable();
|
||||||
|
void value(uint8_t value) override;
|
||||||
|
bool decode(uint8_t* data) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef Dpt5 DPT_Percent_U8;
|
||||||
|
typedef Dpt5 DPT_DecimalFactor;
|
||||||
|
}
|
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
#include "dptconvert.h"
|
#include "dptconvert.h"
|
||||||
|
|
||||||
Knx::Dpt9::Dpt9(unsigned short subgroup /* = 0*/): Dpt(9, subgroup) {}
|
Knx::Dpt9::Dpt9() {}
|
||||||
|
|
||||||
Knx::Dpt9::Dpt9(float value) : Dpt9()
|
Knx::Dpt9::Dpt9(float value)
|
||||||
{
|
{
|
||||||
_value = value;
|
_value = value;
|
||||||
}
|
}
|
||||||
@ -19,12 +19,13 @@ void Knx::Dpt9::encode(uint8_t* data) const
|
|||||||
float16ToPayload(data, 0, _value, 0xFFFF);
|
float16ToPayload(data, 0, _value, 0xFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Knx::Dpt9::decode(uint8_t* data)
|
bool Knx::Dpt9::decode(uint8_t* data)
|
||||||
{
|
{
|
||||||
if (unsigned16FromPayload(data, 0) == 0x7FFF)
|
if (unsigned16FromPayload(data, 0) == 0x7FFF)
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
_value = float16FromPayload(data, 0);
|
_value = float16FromPayload(data, 0);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Knx::Dpt9::value(float value)
|
void Knx::Dpt9::value(float value)
|
||||||
|
@ -5,12 +5,12 @@ namespace Knx
|
|||||||
class Dpt9: public Dpt
|
class Dpt9: public Dpt
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Dpt9(unsigned short subgroup = 0);
|
Dpt9();
|
||||||
Dpt9(float value);
|
Dpt9(float value);
|
||||||
Go_SizeCode size() const override;
|
Go_SizeCode size() const override;
|
||||||
|
|
||||||
virtual void encode(uint8_t* data) const override;
|
void encode(uint8_t* data) const override;
|
||||||
virtual void decode(uint8_t* data) override;
|
bool decode(uint8_t* data) override;
|
||||||
|
|
||||||
void value(float value);
|
void value(float value);
|
||||||
float value() const;
|
float value() const;
|
||||||
@ -19,4 +19,24 @@ namespace Knx
|
|||||||
private:
|
private:
|
||||||
float _value;
|
float _value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#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)
|
||||||
}
|
}
|
@ -18,14 +18,6 @@ namespace Knx
|
|||||||
{
|
{
|
||||||
if (payload_length > 0)
|
if (payload_length > 0)
|
||||||
{
|
{
|
||||||
// DPT 3.* - Step Control
|
|
||||||
if (datatype.mainGroup == 3 && datatype.subGroup >= 7 && datatype.subGroup <= 8 && datatype.index <= 1)
|
|
||||||
return busValueToStepControl(payload, payload_length, datatype, value);
|
|
||||||
|
|
||||||
// DPT 4.* - Character
|
|
||||||
if (datatype.mainGroup == 4 && datatype.subGroup >= 1 && datatype.subGroup <= 2 && !datatype.index)
|
|
||||||
return busValueToCharacter(payload, payload_length, datatype, value);
|
|
||||||
|
|
||||||
// DPT 5.* - Unsigned 8 Bit Integer
|
// DPT 5.* - Unsigned 8 Bit Integer
|
||||||
if (datatype.mainGroup == 5 && ((datatype.subGroup >= 1 && datatype.subGroup <= 6 && datatype.subGroup != 2) || datatype.subGroup == 10) && !datatype.index)
|
if (datatype.mainGroup == 5 && ((datatype.subGroup >= 1 && datatype.subGroup <= 6 && datatype.subGroup != 2) || datatype.subGroup == 10) && !datatype.index)
|
||||||
return busValueToUnsigned8(payload, payload_length, datatype, value);
|
return busValueToUnsigned8(payload, payload_length, datatype, value);
|
||||||
@ -168,13 +160,6 @@ namespace Knx
|
|||||||
|
|
||||||
int KNX_Encode_Value(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
int KNX_Encode_Value(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
// DPT 3.* - Step Control
|
|
||||||
if (datatype.mainGroup == 3 && datatype.subGroup >= 7 && datatype.subGroup <= 8 && datatype.index <= 1)
|
|
||||||
return valueToBusValueStepControl(value, payload, payload_length, datatype);
|
|
||||||
|
|
||||||
// DPT 4.* - Character
|
|
||||||
if (datatype.mainGroup == 4 && datatype.subGroup >= 1 && datatype.subGroup <= 2 && !datatype.index)
|
|
||||||
return valueToBusValueCharacter(value, payload, payload_length, datatype);
|
|
||||||
|
|
||||||
// DPT 5.* - Unsigned 8 Bit Integer
|
// DPT 5.* - Unsigned 8 Bit Integer
|
||||||
if (datatype.mainGroup == 5 && ((datatype.subGroup >= 1 && datatype.subGroup <= 6 && datatype.subGroup != 2) || datatype.subGroup == 10) && !datatype.index)
|
if (datatype.mainGroup == 5 && ((datatype.subGroup >= 1 && datatype.subGroup <= 6 && datatype.subGroup != 2) || datatype.subGroup == 10) && !datatype.index)
|
||||||
@ -315,45 +300,6 @@ namespace Knx
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int busValueToStepControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
|
||||||
{
|
|
||||||
ASSERT_PAYLOAD(1);
|
|
||||||
|
|
||||||
switch (datatype.index)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
value = bitFromPayload(payload, 4);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
const unsigned char stepCode = unsigned8FromPayload(payload, 0) & 0x07;
|
|
||||||
value = stepCode;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
int busValueToCharacter(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
|
||||||
{
|
|
||||||
ASSERT_PAYLOAD(1);
|
|
||||||
int8_t charValue = signed8FromPayload(payload, 0);
|
|
||||||
|
|
||||||
if (datatype.subGroup == 1 && (charValue & 0x80))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (datatype.subGroup == 2)
|
|
||||||
{
|
|
||||||
value = (uint8_t)charValue;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
value = charValue;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int busValueToUnsigned8(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
int busValueToUnsigned8(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||||
{
|
{
|
||||||
ASSERT_PAYLOAD(1);
|
ASSERT_PAYLOAD(1);
|
||||||
@ -961,40 +907,6 @@ namespace Knx
|
|||||||
|
|
||||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
int valueToBusValueStepControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
|
||||||
{
|
|
||||||
switch (datatype.index)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
bitToPayload(payload, 4, value);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
{
|
|
||||||
if ((int64_t)value < INT64_C(0) || (int64_t)value > INT64_C(7))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
unsigned8ToPayload(payload, 0, (uint64_t)value, 0x07);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int valueToBusValueCharacter(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
|
||||||
{
|
|
||||||
if ((uint64_t)value > INT64_C(255) || (datatype.subGroup == 1 && (uint64_t)value > INT64_C(127)))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
unsigned8ToPayload(payload, 0, (uint64_t)value, 0xFF);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int valueToBusValueUnsigned8(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
int valueToBusValueUnsigned8(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||||
{
|
{
|
||||||
if ((int64_t)value < INT64_C(0))
|
if ((int64_t)value < INT64_C(0))
|
||||||
|
@ -2,4 +2,7 @@
|
|||||||
|
|
||||||
#include "dpt1.h"
|
#include "dpt1.h"
|
||||||
#include "dpt2.h"
|
#include "dpt2.h"
|
||||||
|
#include "dpt3.h"
|
||||||
|
#include "dpt4.h"
|
||||||
|
#include "dpt5.h"
|
||||||
#include "dpt9.h"
|
#include "dpt9.h"
|
@ -504,8 +504,7 @@ namespace Knx
|
|||||||
if (value.size() != sizeCode())
|
if (value.size() != sizeCode())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
value.decode(_data);
|
return value.decode(_data);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class DPT> void GroupObject::valueNoSend(const DPT& value)
|
template<class DPT> void GroupObject::valueNoSend(const DPT& value)
|
||||||
|
Loading…
Reference in New Issue
Block a user