-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
131 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters