Skip to content

Commit

Permalink
reimplement dpt1 and dpt9
Browse files Browse the repository at this point in the history
  • Loading branch information
thelsing committed Sep 12, 2024
1 parent d1bdc6e commit 60b414b
Show file tree
Hide file tree
Showing 21 changed files with 658 additions and 534 deletions.
11 changes: 7 additions & 4 deletions examples/knx-cc1310/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,13 @@ set(${PROJECT_NAME}_SOURCES
../../src/knx/interface_object/data_property.h
../../src/knx/interface_object/device_object.cpp
../../src/knx/interface_object/device_object.h
../../src/knx/group_object/dpt.cpp
../../src/knx/group_object/dpt.h
../../src/knx/group_object/dptconvert.cpp
../../src/knx/group_object/dptconvert.h
../../src/knx/group_object/dpt/dpt.cpp
../../src/knx/group_object/dpt/dpt.h
../../src/knx/group_object/dpt/dptconvert.cpp
../../src/knx/group_object/dpt/dptconvert.h
../../src/knx/group_object/dpt/dpt1.cpp
../../src/knx/group_object/dpt/dpt1.h
../../src/knx/group_object/dpt/dpts.h
../../src/knx/interface_object/function_property.h
../../src/knx/group_object/group_object.cpp
../../src/knx/group_object/group_object.h
Expand Down
13 changes: 4 additions & 9 deletions examples/knx-demo/knx-demo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,25 @@ void measureTemp()
currentValue *= 100 * 100;

// write new value to groupobject
goCurrent.value(currentValue);
goCurrent.value<Dpt9>(currentValue);

if (currentValue > maxValue)
{
maxValue = currentValue;
goMax.value(maxValue);
goMax.value<Dpt9>(maxValue);
}

if (currentValue < minValue)
{
minValue = currentValue;
goMin.value(minValue);
goMin.value<Dpt9>(minValue);
}
}

// callback from reset-GO
void handler(GroupObject& go)
{
if (go == goReset && go.value())
if (go == goReset && go.value<Dpt1>())
{
maxValue = 0;
minValue = 10000;
Expand Down Expand Up @@ -86,11 +86,6 @@ void setup()
// print values of parameters if device is already configured
if (knx.configured())
{
goReset.dataPointType(DPT_Trigger);
goCurrent.dataPointType(DPT_Value_Temp);
goMin.dataPointType(DPT_Value_Temp);
goMax.dataPointType(DPT_Value_Temp);

Serial.print("Startverzögerung s: ");
Serial.println(knx.paramByte(0));
Serial.print("Aenderung senden (*0.1K): ");
Expand Down
28 changes: 13 additions & 15 deletions examples/knx-linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include "knx/interface_object/group_object_table_object.h"
#include "knx/bits.h"
#include "knx/group_object/dpt/dpts.h"

#include <time.h>
#include <stdlib.h>
#include <stdio.h>
Expand Down Expand Up @@ -61,28 +63,28 @@ void measureTemp()

lastsend = now;
int r = rand();
double currentValue = (r * 1.0) / (RAND_MAX * 1.0);
float currentValue = (r * 1.0f) / (RAND_MAX * 1.0f);
currentValue *= 100;
currentValue -= 50;
// currentValue *= (670433.28 + 273);
// currentValue -= 273;
LOGGER.info("current value: %f",currentValue);
GO_CURR.value(currentValue);
GO_CURR.value<Dpt9>(currentValue);

double max = GO_MAX.value();
float max = GO_MAX.value<Dpt9>();
if (currentValue > max)
GO_MAX.value(currentValue);
GO_MAX.value<Dpt9>(currentValue);

if (currentValue < (double)GO_MIN.value())
GO_MIN.value(currentValue);
if (currentValue < GO_MIN.value<Dpt9>())
GO_MIN.value<Dpt9>(currentValue);
}

void handler(GroupObject& go)
{
if (go == GO_RESET && go.value())
if (go == GO_RESET && go.value<Dpt1>())
{
GO_MAX.valueNoSend(-273.0);
GO_MIN.valueNoSend(670433.28);
GO_MAX.valueNoSend<Dpt9>(-273.0f);
GO_MIN.valueNoSend<Dpt9>(670433.28f);
}
}

Expand Down Expand Up @@ -110,12 +112,8 @@ void setup()

if (knx.configured())
{
GO_CURR.dataPointType(Dpt(9, 1));
GO_MIN.dataPointType(Dpt(9, 1));
GO_MIN.value(670433.28);
GO_MAX.dataPointType(Dpt(9, 1));
GO_MAX.valueNoSend(-273.0);
GO_RESET.dataPointType(Dpt(1, 15));
GO_MIN.value<Dpt9>(670433.28f);
GO_MAX.valueNoSend<Dpt9>(-273.0f);
LOGGER.info("Startverzögerung s: %d", knx.paramByte(0));
LOGGER.info("Aenderung senden (*0.1K): %d", knx.paramByte(1));
LOGGER.info("Zykl. senden min: %d", knx.paramByte(2));
Expand Down
6 changes: 2 additions & 4 deletions examples/knx-usb/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ void setup(void)
cyclSend = knx.paramInt(0);
Serial1.print("Zykl. send:");
Serial1.println(cyclSend);
goTemperature.dataPointType(Dpt(9, 1));
goHumidity.dataPointType(Dpt(9, 1));
}

// start the framework.
Expand Down Expand Up @@ -123,8 +121,8 @@ void loop(void)
{
sendCounter = 0;

goTemperature.value(temp);
goHumidity.value(humi);
goTemperature.value<Dpt9>(temp);
goHumidity.value<Dpt9>(humi);
}

}
15 changes: 9 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ set(SOURCES
./knx/data_secure/secure_application_layer.h
./knx/data_secure/security_interface_object.cpp
./knx/data_secure/security_interface_object.h
./knx/group_object/datapoint_types.cpp
./knx/group_object/datapoint_types.h
./knx/group_object/dpt.cpp
./knx/group_object/dpt.h
./knx/group_object/dptconvert.cpp
./knx/group_object/dptconvert.h
./knx/group_object/dpt/dpts.h
./knx/group_object/dpt/dpt.cpp
./knx/group_object/dpt/dpt.h
./knx/group_object/dpt/dpt1.cpp
./knx/group_object/dpt/dpt1.h
./knx/group_object/dpt/dpt9.cpp
./knx/group_object/dpt/dpt9.h
./knx/group_object/dpt/dptconvert.cpp
./knx/group_object/dpt/dptconvert.h
./knx/group_object/group_object.cpp
./knx/group_object/group_object.h
./knx/group_object/knx_value.cpp
Expand Down
1 change: 1 addition & 0 deletions src/knx.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,5 @@ knx-->Platform
*/
#include "knx/knx_facade.h"
#include "knx/group_object/dpt/dpts.h"
using namespace Knx;
68 changes: 0 additions & 68 deletions src/knx/group_object/datapoint_types.cpp

This file was deleted.

41 changes: 0 additions & 41 deletions src/knx/group_object/datapoint_types.h

This file was deleted.

14 changes: 2 additions & 12 deletions src/knx/group_object/dpt.cpp → src/knx/group_object/dpt/dpt.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "dpt.h"

#include "../util/logger.h"
#include "../bits.h"
#include "../../util/logger.h"
#include "../../bits.h"

#define LOGGER Logger::logger("Dpt")

Expand All @@ -16,14 +16,4 @@ namespace Knx
if (subGroup == 0)
println("WARNING: You used and invalid Dpt *.0");
}

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);
}
}
9 changes: 6 additions & 3 deletions src/knx/group_object/dpt.h → src/knx/group_object/dpt/dpt.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "../group_object.h"
namespace Knx
{
#define DPT_Switch Dpt(1, 1)
Expand Down Expand Up @@ -367,12 +368,14 @@ namespace Knx
public:
Dpt();
Dpt(short mainGroup, short subGroup, short index = 0);
virtual ~Dpt() {}
unsigned short mainGroup;
unsigned short subGroup;
unsigned short index;
bool operator==(const Dpt& other) const;
bool operator!=(const Dpt& other) const;


virtual Go_SizeCode size() const = 0;

virtual void encode(uint8_t* data) const = 0;
virtual void decode(uint8_t* data) = 0;
};
}
44 changes: 44 additions & 0 deletions src/knx/group_object/dpt/dpt1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "dpt1.h"

#include "dptconvert.h"

Knx::Dpt1::Dpt1() {}

Knx::Dpt1::Dpt1(bool value) : _value(value) {}

Knx::Go_SizeCode Knx::Dpt1::size() const
{
return Go_1_Bit;
}

void Knx::Dpt1::encode(uint8_t* data) const
{
bitToPayload(data, 7, _value);
}

void Knx::Dpt1::decode(uint8_t* data)
{
_value = bitFromPayload(data, 7);
}

void Knx::Dpt1::value(bool value)
{
_value = value;
}

bool Knx::Dpt1::value()
{
return _value;
}

Knx::Dpt1::operator bool() const
{
return _value;
}


Knx::Dpt1& Knx::Dpt1::operator=(const bool value)
{
_value = value;
return *this;
}
Loading

0 comments on commit 60b414b

Please sign in to comment.