From 5f7e9e2f984e5fe7f58d21384b9ceefe9ac4f501 Mon Sep 17 00:00:00 2001 From: Waldemar Porscha Date: Wed, 2 Mar 2022 09:27:12 +0100 Subject: [PATCH] changes for PR - (old) version is again part of version check - naming conventions --- src/knx/bau_systemB.cpp | 8 ++++---- src/knx/bau_systemB.h | 4 ++-- src/knx/memory.cpp | 28 +++++++++++++++++++--------- src/knx/memory.h | 10 +++++----- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/knx/bau_systemB.cpp b/src/knx/bau_systemB.cpp index 26a3af7..df7df8c 100644 --- a/src/knx/bau_systemB.cpp +++ b/src/knx/bau_systemB.cpp @@ -612,12 +612,12 @@ Memory& BauSystemB::memory() return _memory; } -void BauSystemB::addVersionCheckCallback(versionCheckCallback func) +void BauSystemB::versionCheckCallback(VersionCheckCallback func) { - _memory.addVersionCheckCallback(func); + _memory.versionCheckCallback(func); } -versionCheckCallback BauSystemB::getVersionCheckCallback() +VersionCheckCallback BauSystemB::versionCheckCallback() { - return _memory.getVersionCheckCallback(); + return _memory.versionCheckCallback(); } \ No newline at end of file diff --git a/src/knx/bau_systemB.h b/src/knx/bau_systemB.h index 7b5be26..bab492f 100644 --- a/src/knx/bau_systemB.h +++ b/src/knx/bau_systemB.h @@ -38,8 +38,8 @@ class BauSystemB : protected BusAccessUnit void propertyValueWrite(ObjectType objectType, uint8_t objectInstance, uint8_t propertyId, uint8_t& numberOfElements, uint16_t startIndex, uint8_t* data, uint32_t length) override; - void addVersionCheckCallback(versionCheckCallback func); - versionCheckCallback getVersionCheckCallback(); + void versionCheckCallback(VersionCheckCallback func); + VersionCheckCallback versionCheckCallback(); protected: virtual ApplicationLayer& applicationLayer() = 0; diff --git a/src/knx/memory.cpp b/src/knx/memory.cpp index 04a2219..f550c39 100644 --- a/src/knx/memory.cpp +++ b/src/knx/memory.cpp @@ -29,19 +29,22 @@ void Memory::readMemory() _freeList = new MemoryBlock(flashStart + metadataBlockSize, flashSize - metadataBlockSize); + uint16_t version = 0; + const uint8_t* buffer = popWord(version, buffer); + uint16_t manufacturerId = 0; - const uint8_t* buffer = popWord(manufacturerId, flashStart); + buffer = popWord(manufacturerId, flashStart); uint8_t hardwareType[LEN_HARDWARE_TYPE] = {0}; buffer = popByteArray(hardwareType, LEN_HARDWARE_TYPE, buffer); - uint16_t version = 0; - buffer = popWord(version, buffer); + uint16_t apiVersion = 0; + buffer = popWord(apiVersion, buffer); VersionCheckResult versionCheck = FlashAllInvalid; // first check correct format of deviceObject-API - if (_deviceObject.apiVersion == version) + if (_deviceObject.apiVersion == apiVersion) { if (_versionCheckCallback != 0) { versionCheck = _versionCheckCallback(manufacturerId, hardwareType); @@ -50,7 +53,13 @@ void Memory::readMemory() else if (_deviceObject.manufacturerId() == manufacturerId && memcmp(_deviceObject.hardwareType(), hardwareType, LEN_HARDWARE_TYPE) == 0) { - versionCheck = FlashValid; + if (_deviceObject.version() == version) { + versionCheck = FlashValid; + } + else + { + versionCheck = FlashTablesInvalid; + } } else { @@ -72,7 +81,7 @@ void Memory::readMemory() print("expexted DataObject api version: "); print(_deviceObject.apiVersion, HEX); print(", stored api version: "); - println(version, HEX); + println(apiVersion, HEX); } if (versionCheck == FlashAllInvalid) @@ -129,9 +138,10 @@ void Memory::writeMemory() uint32_t flashPos = 0; uint8_t* bufferPos = buffer; + bufferPos = pushWord(_deviceObject.apiVersion, bufferPos); bufferPos = pushWord(_deviceObject.manufacturerId(), bufferPos); bufferPos = pushByteArray(_deviceObject.hardwareType(), LEN_HARDWARE_TYPE, bufferPos); - bufferPos = pushWord(_deviceObject.apiVersion, bufferPos); + bufferPos = pushWord(_deviceObject.version(), bufferPos); flashPos = _platform.writeNonVolatileMemory(flashPos, buffer, bufferPos - buffer); @@ -478,12 +488,12 @@ void Memory::addNewUsedBlock(uint8_t* address, size_t size) addToUsedList(newUsedBlock); } -void Memory::addVersionCheckCallback(versionCheckCallback func) +void Memory::versionCheckCallback(VersionCheckCallback func) { _versionCheckCallback = func; } -versionCheckCallback Memory::getVersionCheckCallback() +VersionCheckCallback Memory::versionCheckCallback() { return _versionCheckCallback; } diff --git a/src/knx/memory.h b/src/knx/memory.h index 4006e47..58a10ef 100644 --- a/src/knx/memory.h +++ b/src/knx/memory.h @@ -31,7 +31,7 @@ enum VersionCheckResult FlashValid = 2 //!< Flash content is valid and will be used }; -typedef VersionCheckResult (*versionCheckCallback)(uint16_t manufacturerId, uint8_t* hardwareType); +typedef VersionCheckResult (*VersionCheckCallback)(uint16_t manufacturerId, uint8_t* hardwareType, uint16_t version); class Memory { @@ -50,8 +50,8 @@ public: uint8_t* toAbsolute(uint32_t relativeAddress); uint32_t toRelative(uint8_t* absoluteAddress); - void addVersionCheckCallback(versionCheckCallback func); - versionCheckCallback getVersionCheckCallback(); + void versionCheckCallback(VersionCheckCallback func); + VersionCheckCallback versionCheckCallback(); private: void removeFromFreeList(MemoryBlock* block); @@ -68,7 +68,7 @@ public: uint8_t* eraseBlockEnd(uint32_t blockNum); void saveBufferdEraseBlock(); - versionCheckCallback _versionCheckCallback = 0; + VersionCheckCallback _versionCheckCallback = 0; Platform& _platform; DeviceObject& _deviceObject; SaveRestore* _saveRestores[MAXSAVE] = {0}; @@ -77,5 +77,5 @@ public: uint8_t _tableObjCount = 0; MemoryBlock* _freeList = nullptr; MemoryBlock* _usedList = nullptr; - uint16_t _metadataSize = 4 + LEN_HARDWARE_TYPE; // accounting for 2x pushWord and pushByteArray of length LEN_HARDWARE_TYPE + uint16_t _metadataSize = 6 + LEN_HARDWARE_TYPE; // accounting for 3x pushWord and pushByteArray of length LEN_HARDWARE_TYPE };