Skip to content

Commit d1bdc6e

Browse files
committed
-remove hack for 0 terminating string in groupobjects
-fix logging on linux -add parameters to python bindings
1 parent b687cd2 commit d1bdc6e

File tree

17 files changed

+77
-54
lines changed

17 files changed

+77
-54
lines changed

examples/knx-demo/knx-demo.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ void setup()
9191
goMin.dataPointType(DPT_Value_Temp);
9292
goMax.dataPointType(DPT_Value_Temp);
9393

94-
Serial.print("Timeout: ");
94+
Serial.print("Startverzögerung s: ");
9595
Serial.println(knx.paramByte(0));
96-
Serial.print("Zykl. senden: ");
96+
Serial.print("Aenderung senden (*0.1K): ");
9797
Serial.println(knx.paramByte(1));
98-
Serial.print("Min/Max senden: ");
98+
Serial.print("Zykl. senden min: ");
9999
Serial.println(knx.paramByte(2));
100-
Serial.print("Aenderung senden: ");
100+
Serial.print("Min/Max senden: ");
101101
Serial.println(knx.paramByte(3));
102102
Serial.print("Abgleich: ");
103103
Serial.println(knx.paramByte(4));

examples/knx-linux/main.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ void setup()
9999
srand((unsigned int)time(NULL));
100100

101101
Logger::logLevel("App", Logger::Info);
102-
Logger::logLevel("ApplicationLayer", Logger::Info);
102+
Logger::logLevel("TableObject", Logger::Info);
103+
Logger::logLevel("Memory", Logger::Info);
103104
knx.readMemory();
104105

105106
if (knx.individualAddress() == 0xFFFF)
@@ -115,11 +116,11 @@ void setup()
115116
GO_MAX.dataPointType(Dpt(9, 1));
116117
GO_MAX.valueNoSend(-273.0);
117118
GO_RESET.dataPointType(Dpt(1, 15));
118-
LOGGER.info("Timeout: %d", knx.paramWord(0));
119-
LOGGER.info("Zykl. senden: %d", knx.paramByte(2));
119+
LOGGER.info("Startverzögerung s: %d", knx.paramByte(0));
120+
LOGGER.info("Aenderung senden (*0.1K): %d", knx.paramByte(1));
121+
LOGGER.info("Zykl. senden min: %d", knx.paramByte(2));
120122
LOGGER.info("Min/Max senden: %d", knx.paramByte(3));
121-
LOGGER.info("Aenderung senden: %d", knx.paramByte(4));
122-
LOGGER.info("Abgleich %d", knx.paramByte(5));
123+
LOGGER.info("Abgleich %d", knx.paramInt(4));
123124
}
124125
else
125126
LOGGER.info("not configured");

examples/knxPython/knxmodule.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ namespace py = pybind11;
1414
#include <vector>
1515
#include <algorithm>
1616

17-
#include "knx/bits.h"
18-
#include "knx/platform/linux_platform.h"
19-
#include "knx/ip/bau57B0.h"
20-
#include "knx/interface_object/group_object_table_object.h"
21-
#include "knx/util/logger.h"
17+
#include <knx/bits.h>
18+
#include <knx/platform/linux_platform.h>
19+
#include <knx/ip/bau57B0.h>
20+
#include <knx/interface_object/group_object_table_object.h>
21+
#include <knx/util/logger.h>
2222

2323
#define LOGGER Logger::logger("knxmodule")
2424

@@ -56,6 +56,8 @@ static void init()
5656
Logger::logLevel("ApplicationLayer", Logger::Info);
5757
Logger::logLevel("BauSystemBDevice", Logger::Info);
5858
Logger::logLevel("GroupObject", Logger::Info);
59+
Logger::logLevel("TableObject", Logger::Info);
60+
Logger::logLevel("Memory", Logger::Info);
5961

6062
/*
6163
// copy args so we control the livetime of the char*
@@ -186,6 +188,14 @@ PYBIND11_MODULE(knx, m)
186188
{
187189
GroupObject::classCallback(handler);
188190
});
191+
m.def("Parameters", []()
192+
{
193+
uint8_t* data = bau->parameters().data();
194+
if (data == nullptr)
195+
return py::bytes();
196+
197+
return py::bytes((const char*)data, bau->parameters().dataSize());
198+
});
189199

190200
py::class_<GroupObject>(m, "GroupObject", py::dynamic_attr())
191201
.def(py::init())

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ build-backend = "scikit_build_core.build"
44

55
[project]
66
name = "knxPython"
7-
version = "0.1.5"
7+
version = "1.5.0"

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ set(SOURCES
187187

188188
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wno-unknown-pragmas -g -O0")
189189
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wno-unknown-pragmas -g -O0")
190-
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -g -O0")
190+
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -DKNX_FLASH_SIZE=0x20000")
191191

192192
add_library(knx ${SOURCES})
193193
target_include_directories(knx PUBLIC .)

src/knx/bau/bau_systemB_device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace Knx
2727
void loop() override;
2828
bool configured() override;
2929
GroupObjectTableObject& groupObjectTable();
30+
3031

3132
protected:
3233
ApplicationLayer& applicationLayer() override;

src/knx/group_object/dpt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,5 +372,7 @@ namespace Knx
372372
unsigned short index;
373373
bool operator==(const Dpt& other) const;
374374
bool operator!=(const Dpt& other) const;
375+
376+
375377
};
376378
}

src/knx/group_object/dptconvert.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -629,16 +629,16 @@ namespace Knx
629629
int busValueToString(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
630630
{
631631
ASSERT_PAYLOAD(14);
632-
632+
char strValue[15];
633+
strValue[14] = '\0';
633634
for (int n = 0; n < 14; ++n)
634635
{
635-
auto value = signed8FromPayload(payload, n);
636-
637-
if (!datatype.subGroup && (value & 0x80))
636+
strValue[n] = signed8FromPayload(payload, n);
637+
if (!datatype.subGroup && (strValue[n] & 0x80))
638638
return false;
639639
}
640640

641-
value = (const char*) payload;
641+
value = strValue;
642642
return true;
643643
}
644644

src/knx/group_object/group_object.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -202,20 +202,6 @@ namespace Knx
202202
return asapValueSize(code);
203203
}
204204

205-
size_t GroupObject::sizeInMemory() const
206-
{
207-
uint8_t code = lowByte(ntohs(_table->_tableData[_asap]));
208-
size_t result = asapValueSize(code);
209-
210-
if (code == 0)
211-
return 1;
212-
213-
if (code == 14)
214-
return 14 + 1;
215-
216-
return result;
217-
}
218-
219205
GroupObjectUpdatedHandler GroupObject::classCallback()
220206
{
221207
return _updateHandlerStatic;

src/knx/group_object/group_object.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,6 @@ namespace Knx
128128
* will return 0.
129129
*/
130130
size_t sizeInTelegram();
131-
/**
132-
* returns the size of the group object in the heap memory of the group object. The function returns the same value as goSize(),
133-
* exept fot the 14 byte string type to reserve one byte of a \0 terminator character.
134-
*/
135-
size_t sizeInMemory() const;
136131
/**
137132
* returns the pointer to the value of the group object. This can be used if a datapoint type is not supported or if you want do
138133
* your own conversion.

src/knx/interface_object/application_program_object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ namespace Knx
2222
uint16_t getWord(uint32_t addr);
2323
uint32_t getInt(uint32_t addr);
2424
double getFloat(uint32_t addr, ParameterFloatEncodings encoding);
25+
using TableObject::data;
26+
using TableObject::dataSize;
2527
const char* name() override
2628
{
2729
return "ApplicationProgram";

src/knx/interface_object/group_object_table_object.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace Knx
3535

3636
GroupObject& GroupObjectTableObject::get(uint16_t asap)
3737
{
38-
if(asap == 0 || asap > entryCount())
38+
if (asap == 0 || asap > entryCount())
3939
LOGGER.warning("get: %d is no valid GroupObject. Asap must be > 0 and <= %d", asap, entryCount());
4040

4141
return _groupObjects[asap - 1];
@@ -122,9 +122,8 @@ namespace Knx
122122
go._table = this;
123123

124124
go._dataLength = go.goSize();
125-
size_t sizeInMemory = go.sizeInMemory();
126-
go._data = new uint8_t[sizeInMemory];
127-
memset(go._data, 0, sizeInMemory);
125+
go._data = new uint8_t[go._dataLength];
126+
memset(go._data, 0, go._dataLength);
128127

129128
if (go.valueReadOnInit())
130129
go.requestObjectRead();

src/knx/interface_object/table_object.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,11 @@ namespace Knx
317317
return _data;
318318
}
319319

320+
uint32_t TableObject::dataSize()
321+
{
322+
return _size;
323+
}
324+
320325
void TableObject::errorCode(ErrorCode errorCode)
321326
{
322327
uint8_t data = errorCode;

src/knx/interface_object/table_object.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ namespace Knx
5050
* must not be written at nor freed.
5151
*/
5252
uint8_t* data();
53+
54+
/**
55+
* returns the size in bytes of the internal data of the interface object.
56+
*/
57+
uint32_t dataSize();
58+
5359
/**
5460
* Set the reason for a state change failure.
5561
*/

src/knx/platform/linux_platform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ namespace Knx
293293
fsync(_fd);
294294
}
295295

296-
#define FLASHSIZE 0x10000
296+
#define FLASHSIZE 0x20000
297297
void LinuxPlatform::doMemoryMapping()
298298
{
299299
fs::path filePath = _flashFilePath;

src/knx/util/logger.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
namespace Knx
66
{
7-
Map<const char*, Logger::LogType, 64> Logger::_loggers;
7+
Map<loggername_t, Logger::LogType, 64> Logger::_loggers;
88
Logger Logger::_logger;
99

10-
Logger& Logger::logger(const char* name)
10+
Logger& Logger::logger(loggername_t name)
1111
{
1212
_logger.name(name);
1313
return _logger;
1414
}
1515

16-
void Logger::logLevel(const char* name, LogType level)
16+
void Logger::logLevel(loggername_t name, LogType level)
1717
{
1818
_loggers.insertOrAssign(name, level);
1919
}
@@ -67,6 +67,12 @@ namespace Knx
6767
va_end(objects);
6868
#endif
6969
}
70+
#ifdef __linux__
71+
void print(std::string msg)
72+
{
73+
print(msg.c_str());
74+
}
75+
#endif
7076

7177
bool Logger::log(LogType type)
7278
{
@@ -86,7 +92,7 @@ namespace Knx
8692

8793
if (*level > type)
8894
return false;
89-
95+
9096
print(millis());
9197
print(" ");
9298
print(_name);

src/knx/util/logger.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,18 @@
33
#include <stdarg.h>
44
#include "simple_map.h"
55

6+
#ifdef __linux
7+
#include <string>
8+
#define loggername_t std::string
9+
#else
10+
#define loggername_t const char*
11+
#endif
12+
13+
614
namespace Knx
715
{
16+
17+
818
class IPrintable
919
{
1020
public:
@@ -23,8 +33,8 @@ namespace Knx
2333
{
2434
public:
2535
enum LogType { Info, Warning, Error, Critical, Exception, Disabled};
26-
static Logger& logger(const char* name);
27-
static void logLevel(const char* name, LogType level);
36+
static Logger& logger(const loggername_t name);
37+
static void logLevel(const loggername_t name, LogType level);
2838
void info(const char* message, IPrintable& object)
2939
{
3040
if (!log(LogType::Info))
@@ -79,14 +89,14 @@ namespace Knx
7989
Logger() {}
8090
bool log(LogType type);
8191
void log(LogType type, const char* format, va_list args);
82-
void name(const char* value)
92+
void name(loggername_t value)
8393
{
8494
_name = value;
8595
}
8696
private:
8797
const char* enum_name(LogType type);
88-
const char* _name = "";
89-
static Map<const char*, LogType, 64> _loggers;
98+
loggername_t _name = "";
99+
static Map<loggername_t, LogType, 64> _loggers;
90100
static Logger _logger;
91101
};
92102
}

0 commit comments

Comments
 (0)