mirror of
https://github.com/thelsing/knx.git
synced 2024-12-18 19:08:18 +01:00
reimplement dpt16
This commit is contained in:
parent
bf573d8253
commit
e67369caf1
@ -68,6 +68,8 @@ set(SOURCES
|
||||
./knx/group_object/dpt/dpt14.h
|
||||
./knx/group_object/dpt/dpt15.cpp
|
||||
./knx/group_object/dpt/dpt15.h
|
||||
./knx/group_object/dpt/dpt16.cpp
|
||||
./knx/group_object/dpt/dpt16.h
|
||||
./knx/group_object/dpt/dptconvert.cpp
|
||||
./knx/group_object/dpt/dptconvert.h
|
||||
./knx/group_object/group_object.cpp
|
||||
|
@ -3,8 +3,6 @@
|
||||
#include "../group_object.h"
|
||||
namespace Knx
|
||||
{
|
||||
#define DPT_String_ASCII Dpt(16, 0)
|
||||
#define DPT_String_8859_1 Dpt(16, 1)
|
||||
#define DPT_SceneNumber Dpt(17, 1)
|
||||
#define DPT_SceneControl Dpt(18, 1)
|
||||
#define DPT_DateTime Dpt(19, 1)
|
||||
|
78
src/knx/group_object/dpt/dpt16.cpp
Normal file
78
src/knx/group_object/dpt/dpt16.cpp
Normal file
@ -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;
|
||||
}
|
32
src/knx/group_object/dpt/dpt16.h
Normal file
32
src/knx/group_object/dpt/dpt16.h
Normal file
@ -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;
|
||||
};
|
||||
}
|
@ -18,10 +18,6 @@ namespace Knx
|
||||
{
|
||||
if (payload_length > 0)
|
||||
{
|
||||
// DPT 16.* - String
|
||||
if (datatype.mainGroup == 16 && datatype.subGroup <= 1 && !datatype.index)
|
||||
return busValueToString(payload, payload_length, datatype, value);
|
||||
|
||||
// DPT 17.* - Scene Number
|
||||
if (datatype.mainGroup == 17 && datatype.subGroup == 1 && !datatype.index)
|
||||
return busValueToScene(payload, payload_length, datatype, value);
|
||||
@ -104,10 +100,6 @@ namespace Knx
|
||||
|
||||
int KNX_Encode_Value(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||
{
|
||||
// DPT 16.* - String
|
||||
if (datatype.mainGroup == 16 && datatype.subGroup <= 1 && !datatype.index)
|
||||
return valueToBusValueString(value, payload, payload_length, datatype);
|
||||
|
||||
// DPT 17.* - Scene Number
|
||||
if (datatype.mainGroup == 17 && datatype.subGroup == 1 && !datatype.index)
|
||||
return valueToBusValueScene(value, payload, payload_length, datatype);
|
||||
@ -598,22 +590,6 @@ namespace Knx
|
||||
return true;
|
||||
}
|
||||
|
||||
int valueToBusValueString(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||
{
|
||||
const char* strValue = value;
|
||||
uint8_t val = strValue[0];
|
||||
|
||||
for (int n = 0; n < 14; n++)
|
||||
{
|
||||
if (val)
|
||||
val = strValue[n]; //string terminator 0x00 will stop further assignments and init the remainig payload with zero
|
||||
|
||||
unsigned8ToPayload(payload, n, val, 0xff);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int valueToBusValueScene(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
|
||||
{
|
||||
if ((int64_t)value < INT64_C(0) || (int64_t)value > INT64_C(63))
|
||||
|
@ -49,7 +49,6 @@ namespace Knx
|
||||
//KNX to internal
|
||||
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);
|
||||
int busValueToString(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||
int busValueToScene(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||
int busValueToSceneControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||
int busValueToSceneInfo(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
|
||||
@ -71,7 +70,6 @@ namespace Knx
|
||||
//Internal to KNX
|
||||
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);
|
||||
int valueToBusValueString(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||
int valueToBusValueScene(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||
int valueToBusValueSceneControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||
int valueToBusValueSceneInfo(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
|
||||
|
@ -15,3 +15,4 @@
|
||||
#include "dpt13.h"
|
||||
#include "dpt14.h"
|
||||
#include "dpt15.h"
|
||||
#include "dpt16.h"
|
Loading…
Reference in New Issue
Block a user