diff --git a/examples/knx-demo/knx-demo.ino b/examples/knx-demo/knx-demo.ino index 14c02730..d1dd822a 100644 --- a/examples/knx-demo/knx-demo.ino +++ b/examples/knx-demo/knx-demo.ino @@ -91,13 +91,13 @@ void setup() goMin.dataPointType(DPT_Value_Temp); goMax.dataPointType(DPT_Value_Temp); - Serial.print("Timeout: "); + Serial.print("Startverzögerung s: "); Serial.println(knx.paramByte(0)); - Serial.print("Zykl. senden: "); + Serial.print("Aenderung senden (*0.1K): "); Serial.println(knx.paramByte(1)); - Serial.print("Min/Max senden: "); + Serial.print("Zykl. senden min: "); Serial.println(knx.paramByte(2)); - Serial.print("Aenderung senden: "); + Serial.print("Min/Max senden: "); Serial.println(knx.paramByte(3)); Serial.print("Abgleich: "); Serial.println(knx.paramByte(4)); diff --git a/examples/knx-linux/main.cpp b/examples/knx-linux/main.cpp index 094e5b46..26adf540 100644 --- a/examples/knx-linux/main.cpp +++ b/examples/knx-linux/main.cpp @@ -99,7 +99,8 @@ void setup() srand((unsigned int)time(NULL)); Logger::logLevel("App", Logger::Info); - Logger::logLevel("ApplicationLayer", Logger::Info); + Logger::logLevel("TableObject", Logger::Info); + Logger::logLevel("Memory", Logger::Info); knx.readMemory(); if (knx.individualAddress() == 0xFFFF) @@ -115,11 +116,11 @@ void setup() GO_MAX.dataPointType(Dpt(9, 1)); GO_MAX.valueNoSend(-273.0); GO_RESET.dataPointType(Dpt(1, 15)); - LOGGER.info("Timeout: %d", knx.paramWord(0)); - LOGGER.info("Zykl. senden: %d", knx.paramByte(2)); + 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)); LOGGER.info("Min/Max senden: %d", knx.paramByte(3)); - LOGGER.info("Aenderung senden: %d", knx.paramByte(4)); - LOGGER.info("Abgleich %d", knx.paramByte(5)); + LOGGER.info("Abgleich %d", knx.paramInt(4)); } else LOGGER.info("not configured"); diff --git a/examples/knxPython/knxmodule.cpp b/examples/knxPython/knxmodule.cpp index 773e5f36..95bef2d1 100644 --- a/examples/knxPython/knxmodule.cpp +++ b/examples/knxPython/knxmodule.cpp @@ -14,11 +14,11 @@ namespace py = pybind11; #include #include -#include "knx/bits.h" -#include "knx/platform/linux_platform.h" -#include "knx/ip/bau57B0.h" -#include "knx/interface_object/group_object_table_object.h" -#include "knx/util/logger.h" +#include +#include +#include +#include +#include #define LOGGER Logger::logger("knxmodule") @@ -56,6 +56,8 @@ static void init() Logger::logLevel("ApplicationLayer", Logger::Info); Logger::logLevel("BauSystemBDevice", Logger::Info); Logger::logLevel("GroupObject", Logger::Info); + Logger::logLevel("TableObject", Logger::Info); + Logger::logLevel("Memory", Logger::Info); /* // copy args so we control the livetime of the char* @@ -186,6 +188,14 @@ PYBIND11_MODULE(knx, m) { GroupObject::classCallback(handler); }); + m.def("Parameters", []() + { + uint8_t* data = bau->parameters().data(); + if (data == nullptr) + return py::bytes(); + + return py::bytes((const char*)data, bau->parameters().dataSize()); + }); py::class_(m, "GroupObject", py::dynamic_attr()) .def(py::init()) diff --git a/pyproject.toml b/pyproject.toml index 7c0bb39c..42c4700a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,4 +4,4 @@ build-backend = "scikit_build_core.build" [project] name = "knxPython" -version = "0.1.5" \ No newline at end of file +version = "1.5.0" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 605e593a..300ff092 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -187,7 +187,7 @@ set(SOURCES set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wno-unknown-pragmas -g -O0") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wno-unknown-pragmas -g -O0") -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -g -O0") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -DKNX_FLASH_SIZE=0x20000") add_library(knx ${SOURCES}) target_include_directories(knx PUBLIC .) diff --git a/src/knx/bau/bau_systemB_device.h b/src/knx/bau/bau_systemB_device.h index 6f43d784..a71a053b 100644 --- a/src/knx/bau/bau_systemB_device.h +++ b/src/knx/bau/bau_systemB_device.h @@ -27,6 +27,7 @@ namespace Knx void loop() override; bool configured() override; GroupObjectTableObject& groupObjectTable(); + protected: ApplicationLayer& applicationLayer() override; diff --git a/src/knx/group_object/dpt.h b/src/knx/group_object/dpt.h index 23308133..ed2eadaf 100644 --- a/src/knx/group_object/dpt.h +++ b/src/knx/group_object/dpt.h @@ -372,5 +372,7 @@ namespace Knx unsigned short index; bool operator==(const Dpt& other) const; bool operator!=(const Dpt& other) const; + + }; } \ No newline at end of file diff --git a/src/knx/group_object/dptconvert.cpp b/src/knx/group_object/dptconvert.cpp index 7fb85cad..2c8d5c08 100644 --- a/src/knx/group_object/dptconvert.cpp +++ b/src/knx/group_object/dptconvert.cpp @@ -629,16 +629,16 @@ namespace Knx int busValueToString(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value) { ASSERT_PAYLOAD(14); - + char strValue[15]; + strValue[14] = '\0'; for (int n = 0; n < 14; ++n) { - auto value = signed8FromPayload(payload, n); - - if (!datatype.subGroup && (value & 0x80)) + strValue[n] = signed8FromPayload(payload, n); + if (!datatype.subGroup && (strValue[n] & 0x80)) return false; } - value = (const char*) payload; + value = strValue; return true; } diff --git a/src/knx/group_object/group_object.cpp b/src/knx/group_object/group_object.cpp index 855e7968..1cd733dd 100644 --- a/src/knx/group_object/group_object.cpp +++ b/src/knx/group_object/group_object.cpp @@ -202,20 +202,6 @@ namespace Knx return asapValueSize(code); } - size_t GroupObject::sizeInMemory() const - { - uint8_t code = lowByte(ntohs(_table->_tableData[_asap])); - size_t result = asapValueSize(code); - - if (code == 0) - return 1; - - if (code == 14) - return 14 + 1; - - return result; - } - GroupObjectUpdatedHandler GroupObject::classCallback() { return _updateHandlerStatic; diff --git a/src/knx/group_object/group_object.h b/src/knx/group_object/group_object.h index e0001480..22d82bb9 100644 --- a/src/knx/group_object/group_object.h +++ b/src/knx/group_object/group_object.h @@ -128,11 +128,6 @@ namespace Knx * will return 0. */ size_t sizeInTelegram(); - /** - * returns the size of the group object in the heap memory of the group object. The function returns the same value as goSize(), - * exept fot the 14 byte string type to reserve one byte of a \0 terminator character. - */ - size_t sizeInMemory() const; /** * 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 * your own conversion. diff --git a/src/knx/interface_object/application_program_object.h b/src/knx/interface_object/application_program_object.h index 5fe8e140..9c9f4ab6 100644 --- a/src/knx/interface_object/application_program_object.h +++ b/src/knx/interface_object/application_program_object.h @@ -22,6 +22,8 @@ namespace Knx uint16_t getWord(uint32_t addr); uint32_t getInt(uint32_t addr); double getFloat(uint32_t addr, ParameterFloatEncodings encoding); + using TableObject::data; + using TableObject::dataSize; const char* name() override { return "ApplicationProgram"; diff --git a/src/knx/interface_object/group_object_table_object.cpp b/src/knx/interface_object/group_object_table_object.cpp index 50766c11..175b9c2e 100644 --- a/src/knx/interface_object/group_object_table_object.cpp +++ b/src/knx/interface_object/group_object_table_object.cpp @@ -35,7 +35,7 @@ namespace Knx GroupObject& GroupObjectTableObject::get(uint16_t asap) { - if(asap == 0 || asap > entryCount()) + if (asap == 0 || asap > entryCount()) LOGGER.warning("get: %d is no valid GroupObject. Asap must be > 0 and <= %d", asap, entryCount()); return _groupObjects[asap - 1]; @@ -122,9 +122,8 @@ namespace Knx go._table = this; go._dataLength = go.goSize(); - size_t sizeInMemory = go.sizeInMemory(); - go._data = new uint8_t[sizeInMemory]; - memset(go._data, 0, sizeInMemory); + go._data = new uint8_t[go._dataLength]; + memset(go._data, 0, go._dataLength); if (go.valueReadOnInit()) go.requestObjectRead(); diff --git a/src/knx/interface_object/table_object.cpp b/src/knx/interface_object/table_object.cpp index 5b265012..55fa94cd 100644 --- a/src/knx/interface_object/table_object.cpp +++ b/src/knx/interface_object/table_object.cpp @@ -317,6 +317,11 @@ namespace Knx return _data; } + uint32_t TableObject::dataSize() + { + return _size; + } + void TableObject::errorCode(ErrorCode errorCode) { uint8_t data = errorCode; diff --git a/src/knx/interface_object/table_object.h b/src/knx/interface_object/table_object.h index e7547e56..63aaf9c3 100644 --- a/src/knx/interface_object/table_object.h +++ b/src/knx/interface_object/table_object.h @@ -50,6 +50,12 @@ namespace Knx * must not be written at nor freed. */ uint8_t* data(); + + /** + * returns the size in bytes of the internal data of the interface object. + */ + uint32_t dataSize(); + /** * Set the reason for a state change failure. */ diff --git a/src/knx/platform/linux_platform.cpp b/src/knx/platform/linux_platform.cpp index f6715094..9e7717ea 100644 --- a/src/knx/platform/linux_platform.cpp +++ b/src/knx/platform/linux_platform.cpp @@ -293,7 +293,7 @@ namespace Knx fsync(_fd); } -#define FLASHSIZE 0x10000 +#define FLASHSIZE 0x20000 void LinuxPlatform::doMemoryMapping() { fs::path filePath = _flashFilePath; diff --git a/src/knx/util/logger.cpp b/src/knx/util/logger.cpp index a66bf321..fcc72e18 100644 --- a/src/knx/util/logger.cpp +++ b/src/knx/util/logger.cpp @@ -4,16 +4,16 @@ namespace Knx { - Map Logger::_loggers; + Map Logger::_loggers; Logger Logger::_logger; - Logger& Logger::logger(const char* name) + Logger& Logger::logger(loggername_t name) { _logger.name(name); return _logger; } - void Logger::logLevel(const char* name, LogType level) + void Logger::logLevel(loggername_t name, LogType level) { _loggers.insertOrAssign(name, level); } @@ -67,6 +67,12 @@ namespace Knx va_end(objects); #endif } +#ifdef __linux__ + void print(std::string msg) + { + print(msg.c_str()); + } +#endif bool Logger::log(LogType type) { @@ -86,7 +92,7 @@ namespace Knx if (*level > type) return false; - + print(millis()); print(" "); print(_name); diff --git a/src/knx/util/logger.h b/src/knx/util/logger.h index d9cbea78..338471d1 100644 --- a/src/knx/util/logger.h +++ b/src/knx/util/logger.h @@ -3,8 +3,18 @@ #include #include "simple_map.h" +#ifdef __linux + #include + #define loggername_t std::string +#else + #define loggername_t const char* +#endif + + namespace Knx { + + class IPrintable { public: @@ -23,8 +33,8 @@ namespace Knx { public: enum LogType { Info, Warning, Error, Critical, Exception, Disabled}; - static Logger& logger(const char* name); - static void logLevel(const char* name, LogType level); + static Logger& logger(const loggername_t name); + static void logLevel(const loggername_t name, LogType level); void info(const char* message, IPrintable& object) { if (!log(LogType::Info)) @@ -79,14 +89,14 @@ namespace Knx Logger() {} bool log(LogType type); void log(LogType type, const char* format, va_list args); - void name(const char* value) + void name(loggername_t value) { _name = value; } private: const char* enum_name(LogType type); - const char* _name = ""; - static Map _loggers; + loggername_t _name = ""; + static Map _loggers; static Logger _logger; }; } \ No newline at end of file