mirror of
https://github.com/thelsing/knx.git
synced 2024-12-18 19:08:18 +01:00
reimplement dpt10
This commit is contained in:
parent
27473ffae4
commit
02b07362e6
@ -56,6 +56,8 @@ set(SOURCES
|
||||
./knx/group_object/dpt/dpt8.h
|
||||
./knx/group_object/dpt/dpt9.cpp
|
||||
./knx/group_object/dpt/dpt9.h
|
||||
./knx/group_object/dpt/dpt10.cpp
|
||||
./knx/group_object/dpt/dpt10.h
|
||||
./knx/group_object/dpt/dptconvert.cpp
|
||||
./knx/group_object/dpt/dptconvert.h
|
||||
./knx/group_object/group_object.cpp
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include "../group_object.h"
|
||||
namespace Knx
|
||||
{
|
||||
#define DPT_TimeOfDay Dpt(10, 1, 1)
|
||||
#define DPT_Date Dpt(11, 1)
|
||||
#define DPT_Value_4_Ucount Dpt(12, 1)
|
||||
#define DPT_Value_4_Count Dpt(13, 1)
|
||||
|
84
src/knx/group_object/dpt/dpt10.cpp
Normal file
84
src/knx/group_object/dpt/dpt10.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
#include "dpt10.h"
|
||||
|
||||
#include "dptconvert.h"
|
||||
|
||||
Knx::Go_SizeCode Knx::DPT_TimeOfDay::size() const
|
||||
{
|
||||
return Go_3_Octets;
|
||||
}
|
||||
|
||||
void Knx::DPT_TimeOfDay::encode(uint8_t* data) const
|
||||
{
|
||||
unsigned8ToPayload(data, 0, (uint8_t)_dow << 5, 0xE0);
|
||||
unsigned8ToPayload(data, 0, _hours, 0x1F);
|
||||
unsigned8ToPayload(data, 1, _minutes, 0x3F);
|
||||
unsigned8ToPayload(data, 2, _seconds, 0x3F);
|
||||
}
|
||||
|
||||
bool Knx::DPT_TimeOfDay::decode(uint8_t* data)
|
||||
{
|
||||
_dow = (DayOfWeekValue) ((unsigned8FromPayload(data, 0) & 0xE0) >> 5);
|
||||
_hours = unsigned8FromPayload(data, 0) & 0x1F;
|
||||
_minutes = unsigned8FromPayload(data, 1) & 0x3F;
|
||||
_seconds = unsigned8FromPayload(data, 2) & 0x3F;
|
||||
|
||||
if (_hours > 23 || _minutes > 59 || _seconds > 59)
|
||||
{
|
||||
_hours = 0;
|
||||
_minutes = 0;
|
||||
_seconds = 0;
|
||||
_dow = NoDay;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Knx::DPT_TimeOfDay::DayOfWeekValue Knx::DPT_TimeOfDay::day() const
|
||||
{
|
||||
return _dow;
|
||||
}
|
||||
|
||||
void Knx::DPT_TimeOfDay::day(DayOfWeekValue value)
|
||||
{
|
||||
_dow = value;
|
||||
}
|
||||
|
||||
uint8_t Knx::DPT_TimeOfDay::hours() const
|
||||
{
|
||||
return _hours;
|
||||
}
|
||||
|
||||
void Knx::DPT_TimeOfDay::hours(uint8_t value)
|
||||
{
|
||||
if (value > 23)
|
||||
return;
|
||||
|
||||
_hours = value;
|
||||
}
|
||||
|
||||
uint8_t Knx::DPT_TimeOfDay::minutes() const
|
||||
{
|
||||
return _minutes;
|
||||
}
|
||||
|
||||
void Knx::DPT_TimeOfDay::minutes(uint8_t value)
|
||||
{
|
||||
if (value > 59)
|
||||
return;
|
||||
|
||||
_minutes = value;
|
||||
}
|
||||
|
||||
uint8_t Knx::DPT_TimeOfDay::seconds() const
|
||||
{
|
||||
return _seconds;
|
||||
}
|
||||
|
||||
void Knx::DPT_TimeOfDay::seconds(uint8_t value)
|
||||
{
|
||||
if (value > 59)
|
||||
return;
|
||||
|
||||
_seconds = value;
|
||||
}
|
45
src/knx/group_object/dpt/dpt10.h
Normal file
45
src/knx/group_object/dpt/dpt10.h
Normal file
@ -0,0 +1,45 @@
|
||||
#pragma once
|
||||
#include "dpt.h"
|
||||
namespace Knx
|
||||
{
|
||||
class DPT_TimeOfDay: public Dpt
|
||||
{
|
||||
public:
|
||||
enum DayOfWeekValue
|
||||
{
|
||||
NoDay = 0,
|
||||
Monday = 1,
|
||||
Tuesday = 2,
|
||||
Wednesday = 3,
|
||||
Thursday = 4,
|
||||
Friday = 5,
|
||||
Saturday = 6,
|
||||
Sunday = 7
|
||||
};
|
||||
|
||||
|
||||
Go_SizeCode size() const override;
|
||||
|
||||
void encode(uint8_t* data) const override;
|
||||
bool decode(uint8_t* data) override;
|
||||
|
||||
DayOfWeekValue day() const;
|
||||
void day(DayOfWeekValue value);
|
||||
|
||||
uint8_t hours() const;
|
||||
void hours(uint8_t value);
|
||||
|
||||
uint8_t minutes() const;
|
||||
void minutes(uint8_t value);
|
||||
|
||||
uint8_t seconds() const;
|
||||
void seconds(uint8_t value);
|
||||
private:
|
||||
DayOfWeekValue _dow;
|
||||
uint8_t _hours;
|
||||
uint8_t _minutes;
|
||||
uint8_t _seconds;
|
||||
};
|
||||
|
||||
|
||||
}
|
@ -18,18 +18,6 @@ namespace Knx
|
||||
{
|
||||
if (payload_length > 0)
|
||||
{
|
||||
// DPT 8.001/8.010/8.011 - Signed 16 Bit Integer
|
||||
if (datatype.mainGroup == 8 && (datatype.subGroup == 1 || datatype.subGroup == 10 || datatype.subGroup == 11) && !datatype.index)
|
||||
return busValueToSigned16(payload, payload_length, datatype, value);
|
||||
|
||||
// DPT 8.002-DPT 8.007 - Time Delta
|
||||
if (datatype.mainGroup == 8 && datatype.subGroup >= 2 && datatype.subGroup <= 7 && !datatype.index)
|
||||
return busValueToTimeDelta(payload, payload_length, datatype, value);
|
||||
|
||||
// DPT 10.* - Time and Weekday
|
||||
if (datatype.mainGroup == 10 && datatype.subGroup == 1 && datatype.index <= 1)
|
||||
return busValueToTime(payload, payload_length, datatype, value);
|
||||
|
||||
// DPT 11.* - Date
|
||||
if (datatype.mainGroup == 11 && datatype.subGroup == 1 && !datatype.index)
|
||||
return busValueToDate(payload, payload_length, datatype, value);
|
||||
@ -140,18 +128,6 @@ namespace Knx
|
||||
|
||||
int KNX_Encode_Value(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||
{
|
||||
// DPT 8.001/8.010/8.011 - Signed 16 Bit Integer
|
||||
if (datatype.mainGroup == 8 && (datatype.subGroup == 1 || datatype.subGroup == 10 || datatype.subGroup == 11) && !datatype.index)
|
||||
return valueToBusValueSigned16(value, payload, payload_length, datatype);
|
||||
|
||||
// DPT 8.002-DPT 8.007 - Time Delta
|
||||
if (datatype.mainGroup == 8 && datatype.subGroup >= 2 && datatype.subGroup <= 7 && !datatype.index)
|
||||
return valueToBusValueTimeDelta(value, payload, payload_length, datatype);
|
||||
|
||||
// DPT 10.* - Time and Weekday
|
||||
if (datatype.mainGroup == 10 && datatype.subGroup == 1 && datatype.index <= 1)
|
||||
return valueToBusValueTime(value, payload, payload_length, datatype);
|
||||
|
||||
// DPT 11.* - Date
|
||||
if (datatype.mainGroup == 11 && datatype.subGroup == 1 && !datatype.index)
|
||||
return valueToBusValueDate(value, payload, payload_length, datatype);
|
||||
@ -259,63 +235,6 @@ namespace Knx
|
||||
return false;
|
||||
}
|
||||
|
||||
int busValueToSigned16(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||
{
|
||||
ASSERT_PAYLOAD(2);
|
||||
|
||||
if (datatype.subGroup == 10)
|
||||
{
|
||||
value = signed16FromPayload(payload, 0) / 100.0;
|
||||
return true;
|
||||
}
|
||||
|
||||
value = signed16FromPayload(payload, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
int busValueToTimeDelta(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||
{
|
||||
ASSERT_PAYLOAD(2);
|
||||
|
||||
int64_t duration = signed16FromPayload(payload, 0);
|
||||
value = duration;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int busValueToTime(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||
{
|
||||
ASSERT_PAYLOAD(3);
|
||||
|
||||
switch (datatype.index)
|
||||
{
|
||||
case 0:
|
||||
value = (uint8_t)((unsigned8FromPayload(payload, 0) >> 5) & 0x07);
|
||||
return true;
|
||||
|
||||
case 1:
|
||||
{
|
||||
unsigned char hours = unsigned8FromPayload(payload, 0) & 0x1F;
|
||||
unsigned char weekDay = (unsigned8FromPayload(payload, 0) & 0xE0) >> 5;
|
||||
unsigned char minutes = unsigned8FromPayload(payload, 1) & 0x3F;
|
||||
unsigned char seconds = unsigned8FromPayload(payload, 2) & 0x3F;
|
||||
|
||||
if (hours > 23 || minutes > 59 || seconds > 59)
|
||||
return false;
|
||||
|
||||
struct tm tmp = {0};
|
||||
tmp.tm_hour = hours;
|
||||
tmp.tm_wday = weekDay;
|
||||
tmp.tm_min = minutes;
|
||||
tmp.tm_sec = seconds;
|
||||
value = tmp;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int busValueToDate(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
|
||||
{
|
||||
ASSERT_PAYLOAD(3);
|
||||
@ -797,68 +716,6 @@ namespace Knx
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
int valueToBusValueSigned16(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||
{
|
||||
if ((int64_t)value < INT64_C(-32768) || (int64_t)value > INT64_C(32767))
|
||||
return false;
|
||||
|
||||
if (datatype.subGroup == 10)
|
||||
{
|
||||
if ((double)value < -327.68 || (double)value > 327.67)
|
||||
return false;
|
||||
|
||||
signed16ToPayload(payload, 0, (int16_t)((double)value * 100.0), 0xFFFF);
|
||||
}
|
||||
else
|
||||
signed16ToPayload(payload, 0, (uint64_t)value, 0xffff);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int valueToBusValueTimeDelta(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||
{
|
||||
struct tm tmp = value;
|
||||
time_t timeSinceEpoch = mktime(&tmp);
|
||||
|
||||
if (timeSinceEpoch < INT64_C(-32768) || timeSinceEpoch > INT64_C(32767))
|
||||
return false;
|
||||
|
||||
signed16ToPayload(payload, 0, timeSinceEpoch, 0xFFFF);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int valueToBusValueTime(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||
{
|
||||
switch (datatype.index)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
if ((int64_t)value < INT64_C(0) || (int64_t)value > INT64_C(7))
|
||||
return false;
|
||||
|
||||
ENSURE_PAYLOAD(3);
|
||||
unsigned8ToPayload(payload, 0, (uint64_t)value << 5, 0xE0);
|
||||
break;
|
||||
}
|
||||
|
||||
case 1:
|
||||
{
|
||||
struct tm tmp = value;
|
||||
unsigned8ToPayload(payload, 0, tmp.tm_hour, 0x1F);
|
||||
unsigned8ToPayload(payload, 1, tmp.tm_min, 0x3F);
|
||||
unsigned8ToPayload(payload, 2, tmp.tm_sec, 0x3F);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int valueToBusValueDate(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||
{
|
||||
struct tm tmp = value;
|
||||
|
@ -47,11 +47,6 @@ namespace Knx
|
||||
int KNX_Encode_Value(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||
|
||||
//KNX to internal
|
||||
int busValueToUnsigned16(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||
int busValueToTimePeriod(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||
int busValueToSigned16(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||
int busValueToTimeDelta(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||
int busValueToTime(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||
int busValueToDate(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||
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);
|
||||
@ -78,11 +73,6 @@ namespace Knx
|
||||
int busValueToActiveEnergy(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||
|
||||
//Internal to KNX
|
||||
int valueToBusValueUnsigned16(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||
int valueToBusValueTimePeriod(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||
int valueToBusValueSigned16(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||
int valueToBusValueTimeDelta(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||
int valueToBusValueTime(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||
int valueToBusValueDate(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user