From 72269b567529cfd9a8b3771e763889322d2d0596 Mon Sep 17 00:00:00 2001 From: Thomas Kunze Date: Mon, 21 Jan 2019 21:29:00 +0100 Subject: [PATCH] make path of flash.bin configurable --- knxPython/knxPython-Debug.vgdbsettings | 8 +++++--- knxPython/knxmodule.cpp | 2 ++ src/linux_platform.cpp | 21 +++++++++++++++++++-- src/linux_platform.h | 7 ++++++- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/knxPython/knxPython-Debug.vgdbsettings b/knxPython/knxPython-Debug.vgdbsettings index dca4fc8..5f641c5 100644 --- a/knxPython/knxPython-Debug.vgdbsettings +++ b/knxPython/knxPython-Debug.vgdbsettings @@ -7,14 +7,14 @@ Win10LXSS - Suzail + Immerlund SSH tkunze false - Suzail + Immerlund SSH tkunze @@ -55,7 +55,7 @@ knxPython DEBUG - Debug + false @@ -74,6 +74,8 @@ BuiltinShortcut $(ToolchainCMake) + . + $(BuildDir) false diff --git a/knxPython/knxmodule.cpp b/knxPython/knxmodule.cpp index bc9281b..a3de115 100644 --- a/knxPython/knxmodule.cpp +++ b/knxPython/knxmodule.cpp @@ -80,6 +80,8 @@ PYBIND11_MODULE(knx, m) m.def("ProgramMode", (bool(*)(bool))&ProgramMode, "Activate / deactivate programing mode."); m.def("Configured", (bool(*)())&Configured, "get configured status."); m.def("RegisterGroupObjects", &RegisterGroupObjects); + m.def("FlashFilePath", []() { return platform.flashFilePath(); }); + m.def("FlashFilePath", [](std::string path) { platform.flashFilePath(path); }); py::class_(m, "GroupObject", py::dynamic_attr()) .def(py::init()) diff --git a/src/linux_platform.cpp b/src/linux_platform.cpp index 65265a6..92d1613 100644 --- a/src/linux_platform.cpp +++ b/src/linux_platform.cpp @@ -31,7 +31,6 @@ LinuxPlatform::LinuxPlatform() { - doMemoryMapping(); Platform::_memoryReference = (uint8_t*)malloc(MAX_MEM); _currentMaxMem = Platform::_memoryReference; } @@ -204,18 +203,24 @@ int LinuxPlatform::readBytes(uint8_t * buffer, uint16_t maxLen) uint8_t * LinuxPlatform::getEepromBuffer(uint16_t size) { + if (_fd < 0) + doMemoryMapping(); + return _mappedFile + 2; } void LinuxPlatform::commitToEeprom() { + if (_fd < 0) + doMemoryMapping(); + fsync(_fd); } #define FLASHSIZE 0x10000 void LinuxPlatform::doMemoryMapping() { - _fd = open("flash.bin", O_RDWR | O_CREAT, S_IRWXU | S_IRGRP | S_IROTH); + _fd = open(_flashFilePath.c_str(), O_RDWR | O_CREAT, S_IRWXU | S_IRGRP | S_IROTH); if (_fd < 0) { puts("Error in file opening"); @@ -315,3 +320,15 @@ void LinuxPlatform::freeMemory(uint8_t* ptr) } #endif + + +void LinuxPlatform::flashFilePath(const std::string path) +{ + _flashFilePath = path; +} + + +std::string LinuxPlatform::flashFilePath() +{ + return _flashFilePath; +} diff --git a/src/linux_platform.h b/src/linux_platform.h index ff3ac6c..af9c98c 100644 --- a/src/linux_platform.h +++ b/src/linux_platform.h @@ -2,6 +2,7 @@ #ifdef __linux__ +#include #include "knx/platform.h" class LinuxPlatform: public Platform @@ -9,6 +10,9 @@ class LinuxPlatform: public Platform using Platform::_memoryReference; public: LinuxPlatform(); + + std::string flashFilePath(); + void flashFilePath(const std::string path); // ip stuff uint32_t currentIpAddress() override; @@ -48,8 +52,9 @@ private: int _socketFd = -1; void doMemoryMapping(); uint8_t* _mappedFile; - int _fd; + int _fd = -1; uint8_t* _currentMaxMem = 0; + std::string _flashFilePath = "flash.bin"; }; #endif \ No newline at end of file