move KnxValue and Dpt to extra files

This commit is contained in:
Thomas Kunze 2019-06-03 22:15:32 +02:00
parent 58cb349e6f
commit 6acaf59ddd
8 changed files with 383 additions and 99 deletions

View File

@ -31,7 +31,9 @@ add_executable(knx-linux
main.cpp main.cpp
../src/linux_platform.cpp ../src/linux_platform.cpp
../src/knx_facade.cpp ../src/knx_facade.cpp
../src/knx/dptconvert.cpp) ../src/knx/dptconvert.cpp
../src/knx/knx_value.cpp
../src/knx/dpt.cpp)
target_link_libraries(knx-linux "${LIBRARIES_FROM_REFERENCES}") target_link_libraries(knx-linux "${LIBRARIES_FROM_REFERENCES}")
include_directories(../src) include_directories(../src)
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wno-unknown-pragmas -Wno-switch -g -O0") set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wno-unknown-pragmas -Wno-switch -g -O0")

View File

@ -84,6 +84,7 @@
<ClInclude Include="..\src\knx\cemi_frame.h" /> <ClInclude Include="..\src\knx\cemi_frame.h" />
<ClInclude Include="..\src\knx\data_link_layer.h" /> <ClInclude Include="..\src\knx\data_link_layer.h" />
<ClInclude Include="..\src\knx\device_object.h" /> <ClInclude Include="..\src\knx\device_object.h" />
<ClInclude Include="..\src\knx\dpt.h" />
<ClInclude Include="..\src\knx\dptconvert.h" /> <ClInclude Include="..\src\knx\dptconvert.h" />
<ClInclude Include="..\src\knx\group_object.h" /> <ClInclude Include="..\src\knx\group_object.h" />
<ClInclude Include="..\src\knx\group_object_table_object.h" /> <ClInclude Include="..\src\knx\group_object_table_object.h" />
@ -91,6 +92,7 @@
<ClInclude Include="..\src\knx\ip_data_link_layer.h" /> <ClInclude Include="..\src\knx\ip_data_link_layer.h" />
<ClInclude Include="..\src\knx\ip_parameter_object.h" /> <ClInclude Include="..\src\knx\ip_parameter_object.h" />
<ClInclude Include="..\src\knx\knx_types.h" /> <ClInclude Include="..\src\knx\knx_types.h" />
<ClInclude Include="..\src\knx\knx_value.h" />
<ClInclude Include="..\src\knx\memory.h" /> <ClInclude Include="..\src\knx\memory.h" />
<ClInclude Include="..\src\knx\network_layer.h" /> <ClInclude Include="..\src\knx\network_layer.h" />
<ClInclude Include="..\src\knx\npdu.h" /> <ClInclude Include="..\src\knx\npdu.h" />
@ -127,12 +129,14 @@
<ClCompile Include="..\src\knx\cemi_frame.cpp" /> <ClCompile Include="..\src\knx\cemi_frame.cpp" />
<ClCompile Include="..\src\knx\data_link_layer.cpp" /> <ClCompile Include="..\src\knx\data_link_layer.cpp" />
<ClCompile Include="..\src\knx\device_object.cpp" /> <ClCompile Include="..\src\knx\device_object.cpp" />
<ClCompile Include="..\src\knx\dpt.cpp" />
<ClCompile Include="..\src\knx\dptconvert.cpp" /> <ClCompile Include="..\src\knx\dptconvert.cpp" />
<ClCompile Include="..\src\knx\group_object.cpp" /> <ClCompile Include="..\src\knx\group_object.cpp" />
<ClCompile Include="..\src\knx\group_object_table_object.cpp" /> <ClCompile Include="..\src\knx\group_object_table_object.cpp" />
<ClCompile Include="..\src\knx\interface_object.cpp" /> <ClCompile Include="..\src\knx\interface_object.cpp" />
<ClCompile Include="..\src\knx\ip_data_link_layer.cpp" /> <ClCompile Include="..\src\knx\ip_data_link_layer.cpp" />
<ClCompile Include="..\src\knx\ip_parameter_object.cpp" /> <ClCompile Include="..\src\knx\ip_parameter_object.cpp" />
<ClCompile Include="..\src\knx\knx_value.cpp" />
<ClCompile Include="..\src\knx\memory.cpp" /> <ClCompile Include="..\src\knx\memory.cpp" />
<ClCompile Include="..\src\knx\network_layer.cpp" /> <ClCompile Include="..\src\knx\network_layer.cpp" />
<ClCompile Include="..\src\knx\npdu.cpp" /> <ClCompile Include="..\src\knx\npdu.cpp" />

View File

@ -135,6 +135,12 @@
<ClInclude Include="..\src\knx\dptconvert.h"> <ClInclude Include="..\src\knx\dptconvert.h">
<Filter>Header files\knx</Filter> <Filter>Header files\knx</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\src\knx\dpt.h">
<Filter>Header files\knx</Filter>
</ClInclude>
<ClInclude Include="..\src\knx\knx_value.h">
<Filter>Header files\knx</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\src\knx\address_table_object.cpp"> <ClCompile Include="..\src\knx\address_table_object.cpp">
@ -227,5 +233,11 @@
<ClCompile Include="..\src\knx\dptconvert.cpp"> <ClCompile Include="..\src\knx\dptconvert.cpp">
<Filter>Source files\knx</Filter> <Filter>Source files\knx</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\src\knx\dpt.cpp">
<Filter>Source files\knx</Filter>
</ClCompile>
<ClCompile Include="..\src\knx\knx_value.cpp">
<Filter>Source files\knx</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>

18
src/knx/dpt.cpp Normal file
View File

@ -0,0 +1,18 @@
#include "dpt.h"
Dpt::Dpt()
{}
Dpt::Dpt(short mainGroup, short subGroup, short index /* = 0 */)
: mainGroup(mainGroup), subGroup(subGroup), index(index)
{}
bool Dpt::operator==(const Dpt& other) const
{
return other.mainGroup == mainGroup && other.subGroup == subGroup && other.index == index;
}
bool Dpt::operator!=(const Dpt& other) const
{
return !(other == *this);
}

13
src/knx/dpt.h Normal file
View File

@ -0,0 +1,13 @@
#pragma once
class Dpt
{
public:
Dpt();
Dpt(short mainGroup, short subGroup, short index = 0);
unsigned short mainGroup;
unsigned short subGroup;
unsigned short index;
bool operator==(const Dpt& other) const;
bool operator!=(const Dpt& other) const;
};

View File

@ -29,105 +29,9 @@
#pragma once #pragma once
#include <cstdint> #include <cstdint>
#include <ctime>
class Dpt #include "dpt.h"
{ #include "knx_value.h"
public:
Dpt() {}
Dpt(short mainGroup, short subGroup, short index = 0)
{
this->mainGroup = mainGroup;
this->subGroup = subGroup;
this->index = index;
}
unsigned short mainGroup;
unsigned short subGroup;
unsigned short index;
bool operator==(const Dpt& other) const
{
return other.mainGroup == mainGroup && other.subGroup == subGroup && other.index == index;
}
bool operator!=(const Dpt& other) const
{
return !(other == *this);
}
};
class KNXValue
{
public:
KNXValue() {}
KNXValue(bool value) { _value.boolValue = value; }
KNXValue(uint8_t value) { _value.ucharValue = value; }
KNXValue(uint16_t value) { _value.ushortValue = value; }
KNXValue(uint32_t value) { _value.uintValue = value; }
KNXValue(uint64_t value) { _value.ulongValue = value; }
KNXValue(int8_t value) { _value.charValue = value; }
KNXValue(int16_t value) { _value.shortValue = value; }
KNXValue(int32_t value) { _value.intValue = value; }
KNXValue(int64_t value) { _value.longValue = value; }
KNXValue(double value) { _value.doubleValue = value; }
KNXValue(char* value) { _value.stringValue = value; }
KNXValue(struct tm value) { _value.timeValue = value; }
operator bool() const { return _value.boolValue; }
operator uint8_t() const { return _value.ucharValue; }
operator uint16_t() const { return _value.ushortValue; }
operator uint32_t() const { return _value.uintValue; }
operator uint64_t() const { return _value.ulongValue; }
operator int8_t() const { return _value.charValue; }
operator int16_t() const { return _value.shortValue; }
operator int32_t() const { return _value.intValue; }
operator int64_t() const { return _value.longValue; }
operator double() const { return _value.doubleValue; }
operator char*() const { return _value.stringValue; }
operator struct tm() const { return _value.timeValue; }
bool boolValue() const { return _value.boolValue; }
uint8_t ucharValue() const { return _value.ucharValue; }
uint16_t ushortValue() const { return _value.ushortValue; }
uint32_t uintValue() const { return _value.uintValue; }
uint64_t ulongValue() const { return _value.ulongValue; }
int8_t charValue() const { return _value.charValue; }
int16_t shortValue() const { return _value.shortValue; }
int32_t intValue() const { return _value.intValue; }
int64_t longValue() const { return _value.longValue; }
double doubleValue() const { return _value.doubleValue; }
char* stringValue() const { return _value.stringValue; }
struct tm timeValue() const { return _value.timeValue; }
void boolValue(bool value) { _value.boolValue = value; }
void ucharValue(uint8_t value) { _value.ucharValue = value; }
void ushortValue(uint16_t value) { _value.ushortValue = value; }
void uintValue(uint32_t value) { _value.uintValue = value; }
void ulongValue(uint64_t value) { _value.ulongValue = value; }
void charValue(int8_t value) { _value.charValue = value; }
void shortValue(int16_t value) { _value.shortValue = value; }
void intValue(int32_t value) { _value.intValue = value; }
void longValue(int64_t value) { _value.longValue = value; }
void doubleValue(double value) { _value.doubleValue = value; }
void stringValue(char* value) { _value.stringValue = value; }
void timeValue(struct tm value) { _value.timeValue = value; }
private:
union Value
{
bool boolValue;
uint8_t ucharValue;
uint16_t ushortValue;
uint32_t uintValue;
uint64_t ulongValue;
int8_t charValue;
int16_t shortValue;
int32_t intValue;
int64_t longValue;
double doubleValue;
char* stringValue;
struct tm timeValue;
};
Value _value;
};
/** /**
* Converts the KNX Payload given by the specific DPT and puts the value in the KNXValue struc * Converts the KNX Payload given by the specific DPT and puts the value in the KNXValue struc

250
src/knx/knx_value.cpp Normal file
View File

@ -0,0 +1,250 @@
#include "knx_value.h"
KNXValue::KNXValue()
{}
KNXValue::KNXValue(bool value)
{
_value.boolValue = value;
}
KNXValue::KNXValue(uint8_t value)
{
_value.ucharValue = value;
}
KNXValue::KNXValue(uint16_t value)
{
_value.ushortValue = value;
}
KNXValue::KNXValue(uint32_t value)
{
_value.uintValue = value;
}
KNXValue::KNXValue(uint64_t value)
{
_value.ulongValue = value;
}
KNXValue::KNXValue(int8_t value)
{
_value.charValue = value;
}
KNXValue::KNXValue(int16_t value)
{
_value.shortValue = value;
}
KNXValue::KNXValue(int32_t value)
{
_value.intValue = value;
}
KNXValue::KNXValue(int64_t value)
{
_value.longValue = value;
}
KNXValue::KNXValue(double value)
{
_value.doubleValue = value;
}
KNXValue::KNXValue(char* value)
{
_value.stringValue = value;
}
KNXValue::KNXValue(struct tm value)
{
_value.timeValue = value;
}
KNXValue::operator bool() const
{
return _value.boolValue;
}
KNXValue::operator uint8_t() const
{
return _value.ucharValue;
}
KNXValue::operator uint16_t() const
{
return _value.ushortValue;
}
KNXValue::operator uint32_t() const
{
return _value.uintValue;
}
KNXValue::operator uint64_t() const
{
return _value.ulongValue;
}
KNXValue::operator int8_t() const
{
return _value.charValue;
}
KNXValue::operator int16_t() const
{
return _value.shortValue;
}
KNXValue::operator int32_t() const
{
return _value.intValue;
}
KNXValue::operator int64_t() const
{
return _value.longValue;
}
KNXValue::operator double() const
{
return _value.doubleValue;
}
KNXValue::operator char*() const
{
return _value.stringValue;
}
KNXValue::operator struct tm() const
{
return _value.timeValue;
}
KNXValue& KNXValue::operator=(const bool value)
{
_value.boolValue = value;
return *this;
}
bool KNXValue::boolValue() const
{
return _value.boolValue;
}
uint8_t KNXValue::ucharValue() const
{
return _value.ucharValue;
}
uint16_t KNXValue::ushortValue() const
{
return _value.ushortValue;
}
uint32_t KNXValue::uintValue() const
{
return _value.uintValue;
}
uint64_t KNXValue::ulongValue() const
{
return _value.ulongValue;
}
int8_t KNXValue::charValue() const
{
return _value.charValue;
}
int16_t KNXValue::shortValue() const
{
return _value.shortValue;
}
int32_t KNXValue::intValue() const
{
return _value.intValue;
}
int64_t KNXValue::longValue() const
{
return _value.longValue;
}
double KNXValue::doubleValue() const
{
return _value.doubleValue;
}
char* KNXValue::stringValue() const
{
return _value.stringValue;
}
struct tm KNXValue::timeValue() const
{
return _value.timeValue;
}
void KNXValue::boolValue(bool value)
{
_value.boolValue = value;
}
void KNXValue::ucharValue(uint8_t value)
{
_value.ucharValue = value;
}
void KNXValue::ushortValue(uint16_t value)
{
_value.ushortValue = value;
}
void KNXValue::uintValue(uint32_t value)
{
_value.uintValue = value;
}
void KNXValue::ulongValue(uint64_t value)
{
_value.ulongValue = value;
}
void KNXValue::charValue(int8_t value)
{
_value.charValue = value;
}
void KNXValue::shortValue(int16_t value)
{
_value.shortValue = value;
}
void KNXValue::intValue(int32_t value)
{
_value.intValue = value;
}
void KNXValue::longValue(int64_t value)
{
_value.longValue = value;
}
void KNXValue::doubleValue(double value)
{
_value.doubleValue = value;
}
void KNXValue::stringValue(char* value)
{
_value.stringValue = value;
}
void KNXValue::timeValue(struct tm value)
{
_value.timeValue = value;
}

81
src/knx/knx_value.h Normal file
View File

@ -0,0 +1,81 @@
#pragma once
#include <cstdint>
#include <ctime>
class KNXValue
{
public:
KNXValue();
KNXValue(bool value);
KNXValue(uint8_t value);
KNXValue(uint16_t value);
KNXValue(uint32_t value);
KNXValue(uint64_t value);
KNXValue(int8_t value);
KNXValue(int16_t value);
KNXValue(int32_t value);
KNXValue(int64_t value);
KNXValue(double value);
KNXValue(char* value);
KNXValue(struct tm value);
operator bool() const;
operator uint8_t() const;
operator uint16_t() const;
operator uint32_t() const;
operator uint64_t() const;
operator int8_t() const;
operator int16_t() const;
operator int32_t() const;
operator int64_t() const;
operator double() const;
operator char*() const;
operator struct tm() const;
KNXValue& operator=(const bool value);
bool boolValue() const;
uint8_t ucharValue() const;
uint16_t ushortValue() const;
uint32_t uintValue() const;
uint64_t ulongValue() const;
int8_t charValue() const;
int16_t shortValue() const;
int32_t intValue() const;
int64_t longValue() const;
double doubleValue() const;
char* stringValue() const;
struct tm timeValue() const;
void boolValue(bool value);
void ucharValue(uint8_t value);
void ushortValue(uint16_t value);
void uintValue(uint32_t value);
void ulongValue(uint64_t value);
void charValue(int8_t value);
void shortValue(int16_t value);
void intValue(int32_t value);
void longValue(int64_t value);
void doubleValue(double value);
void stringValue(char* value);
void timeValue(struct tm value);
private:
union Value
{
bool boolValue;
uint8_t ucharValue;
uint16_t ushortValue;
uint32_t uintValue;
uint64_t ulongValue;
int8_t charValue;
int16_t shortValue;
int32_t intValue;
int64_t longValue;
double doubleValue;
char* stringValue;
struct tm timeValue;
};
Value _value;
};