-
Notifications
You must be signed in to change notification settings - Fork 100
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
7 changed files
with
114 additions
and
29 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,78 @@ | ||
#include "dpt16.h" | ||
|
||
#include "dptconvert.h" | ||
#include <cstring> | ||
|
||
Knx::Dpt16::Dpt16() | ||
{ | ||
memset(_value, 0, 15); | ||
} | ||
|
||
Knx::Dpt16::Dpt16(const char* value) : Dpt16() | ||
{ | ||
this->value(value); | ||
} | ||
|
||
Knx::Go_SizeCode Knx::Dpt16::size() const | ||
{ | ||
return Go_14_Octets; | ||
} | ||
|
||
void Knx::Dpt16::encode(uint8_t* data) const | ||
{ | ||
uint8_t val = _value[0]; | ||
|
||
for (int n = 0; n < 14; n++) | ||
{ | ||
if (val) | ||
val = _value[n]; //string terminator 0x00 will stop further assignments and init the remainig payload with zero | ||
|
||
unsigned8ToPayload(data, n, val, 0xff); | ||
} | ||
} | ||
|
||
bool Knx::Dpt16::decode(uint8_t* data) | ||
{ | ||
|
||
_value[14] = '\0'; | ||
|
||
for (int n = 0; n < 14; ++n) | ||
{ | ||
_value[n] = signed8FromPayload(data, n); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
const char* Knx::Dpt16::value() const | ||
{ | ||
return _value; | ||
} | ||
|
||
void Knx::Dpt16::value(const char* value) | ||
{ | ||
strncpy(_value, value, 14); | ||
_value[14] = 0; | ||
} | ||
|
||
Knx::DPT_String_ASCII::DPT_String_ASCII() : Dpt16() {} | ||
|
||
Knx::DPT_String_ASCII::DPT_String_ASCII(const char* value) : Dpt16(value) {} | ||
|
||
bool Knx::DPT_String_ASCII::decode(uint8_t* data) | ||
{ | ||
_value[14] = '\0'; | ||
|
||
for (int n = 0; n < 14; ++n) | ||
{ | ||
_value[n] = signed8FromPayload(data, n); | ||
|
||
if ((_value[n] & 0x80)) | ||
{ | ||
_value[0] = 0; | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} |
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,32 @@ | ||
#pragma once | ||
#include "dpt.h" | ||
namespace Knx | ||
{ | ||
class Dpt16: public Dpt | ||
{ | ||
enum ReadDirectionValue { LeftToRight = 0, RightToLeft = 1}; | ||
public: | ||
Dpt16(); | ||
Dpt16(const char* value); | ||
Go_SizeCode size() const override; | ||
|
||
void encode(uint8_t* data) const override; | ||
bool decode(uint8_t* data) override; | ||
|
||
const char* value() const; | ||
void value(const char* value); | ||
protected: | ||
// one character more than the dpt to store \0 | ||
char _value[15]; | ||
}; | ||
|
||
typedef Dpt16 DPT_String_8859_1; | ||
|
||
class DPT_String_ASCII: public Dpt16 | ||
{ | ||
public: | ||
DPT_String_ASCII(); | ||
DPT_String_ASCII(const char* value); | ||
bool decode(uint8_t* data) override; | ||
}; | ||
} |
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