mirror of
				https://github.com/thelsing/knx.git
				synced 2025-10-26 10:26:25 +01:00 
			
		
		
		
	get rid of dynamic cast, because we have no rtti on arduino
This commit is contained in:
		
							parent
							
								
									d3cb967216
								
							
						
					
					
						commit
						75958ec52a
					
				@ -1,7 +1,6 @@
 | 
				
			|||||||
#include "memory.h"
 | 
					#include "memory.h"
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
#include "bits.h"
 | 
					#include "bits.h"
 | 
				
			||||||
#include "table_object.h"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
Memory::Memory(Platform& platform, DeviceObject& deviceObject)
 | 
					Memory::Memory(Platform& platform, DeviceObject& deviceObject)
 | 
				
			||||||
    : _platform(platform), _deviceObject(deviceObject)
 | 
					    : _platform(platform), _deviceObject(deviceObject)
 | 
				
			||||||
@ -37,19 +36,19 @@ void Memory::readMemory()
 | 
				
			|||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int size = _saveCount;
 | 
					    for (int i = 0; i < _saveCount; i++)
 | 
				
			||||||
    for (int i = 0; i < size; i++)
 | 
					 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        buffer = _saveRestores[i]->restore(buffer);
 | 
					        buffer = _saveRestores[i]->restore(buffer);
 | 
				
			||||||
        TableObject* tableObject = dynamic_cast<TableObject*>(_saveRestores[i]);
 | 
					    }
 | 
				
			||||||
        if (tableObject)
 | 
					
 | 
				
			||||||
 | 
					    for (int i = 0; i < _tableObjCount; i++)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        buffer = _tableObjects[i]->restore(buffer);
 | 
				
			||||||
        uint16_t memorySize = 0;
 | 
					        uint16_t memorySize = 0;
 | 
				
			||||||
        buffer = popWord(memorySize, buffer);
 | 
					        buffer = popWord(memorySize, buffer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // this works because TableObject saves a relative addr and restores it itself
 | 
					        // this works because TableObject saves a relative addr and restores it itself
 | 
				
			||||||
            addNewUsedBlock(tableObject->_data, memorySize);
 | 
					        addNewUsedBlock(_tableObjects[i]->_data, memorySize);
 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -60,16 +59,18 @@ void Memory::writeMemory()
 | 
				
			|||||||
    buffer = pushByteArray(_deviceObject.hardwareType(), LEN_HARDWARE_TYPE, buffer);
 | 
					    buffer = pushByteArray(_deviceObject.hardwareType(), LEN_HARDWARE_TYPE, buffer);
 | 
				
			||||||
    buffer = pushWord(_deviceObject.version(), buffer);
 | 
					    buffer = pushWord(_deviceObject.version(), buffer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int size = _saveCount;
 | 
					    for (int i = 0; i < _saveCount; i++)
 | 
				
			||||||
    for (int i = 0; i < size; i++)
 | 
					 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        buffer = _saveRestores[i]->save(buffer);
 | 
					        buffer = _saveRestores[i]->save(buffer);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for (int i = 0; i < _tableObjCount; i++)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        buffer = _tableObjects[i]->save(buffer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //save to size of the memoryblock for tableobject too, so that we can rebuild the usedList and freeList
 | 
					        //save to size of the memoryblock for tableobject too, so that we can rebuild the usedList and freeList
 | 
				
			||||||
        TableObject* tableObject = dynamic_cast<TableObject*>(_saveRestores[i]);
 | 
					
 | 
				
			||||||
        if (tableObject)
 | 
					        MemoryBlock* block = findBlockInList(_usedList, _tableObjects[i]->_data);
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            MemoryBlock* block = findBlockInList(_usedList, tableObject->_data);
 | 
					 | 
				
			||||||
        if (block == nullptr)
 | 
					        if (block == nullptr)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            println("_data of TableObject not in errorlist");
 | 
					            println("_data of TableObject not in errorlist");
 | 
				
			||||||
@ -77,7 +78,7 @@ void Memory::writeMemory()
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        buffer = pushWord(block->size, buffer);
 | 
					        buffer = pushWord(block->size, buffer);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    }
 | 
					    
 | 
				
			||||||
    _platform.commitToEeprom();
 | 
					    _platform.commitToEeprom();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -89,14 +90,18 @@ void Memory::addSaveRestore(SaveRestore* obj)
 | 
				
			|||||||
    _saveRestores[_saveCount] = obj;
 | 
					    _saveRestores[_saveCount] = obj;
 | 
				
			||||||
    _saveCount += 1;
 | 
					    _saveCount += 1;
 | 
				
			||||||
    _metadataSize += obj->saveSize();
 | 
					    _metadataSize += obj->saveSize();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    TableObject* tableObject = dynamic_cast<TableObject*>(obj);
 | 
					void Memory::addSaveRestore(TableObject* obj)
 | 
				
			||||||
    if (tableObject)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
        _metadataSize += 2; //
 | 
					    if (_tableObjCount >= MAXTABLEOBJ - 1)
 | 
				
			||||||
    }
 | 
					        return;
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    _tableObjects[_tableObjCount] = obj;
 | 
				
			||||||
 | 
					    _tableObjCount += 1;
 | 
				
			||||||
 | 
					    _metadataSize += obj->saveSize();
 | 
				
			||||||
 | 
					    _metadataSize += 2; // for size
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
uint8_t* Memory::allocMemory(size_t size)
 | 
					uint8_t* Memory::allocMemory(size_t size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
				
			|||||||
@ -4,8 +4,10 @@
 | 
				
			|||||||
#include "save_restore.h"
 | 
					#include "save_restore.h"
 | 
				
			||||||
#include "platform.h"
 | 
					#include "platform.h"
 | 
				
			||||||
#include "device_object.h"
 | 
					#include "device_object.h"
 | 
				
			||||||
 | 
					#include "table_object.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define MAXSAVE 10
 | 
					#define MAXSAVE 5
 | 
				
			||||||
 | 
					#define MAXTABLEOBJ 4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class MemoryBlock
 | 
					class MemoryBlock
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -25,6 +27,7 @@ public:
 | 
				
			|||||||
    void readMemory();
 | 
					    void readMemory();
 | 
				
			||||||
    void writeMemory();
 | 
					    void writeMemory();
 | 
				
			||||||
    void addSaveRestore(SaveRestore* obj);
 | 
					    void addSaveRestore(SaveRestore* obj);
 | 
				
			||||||
 | 
					    void addSaveRestore(TableObject* obj);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    uint8_t* allocMemory(size_t size);
 | 
					    uint8_t* allocMemory(size_t size);
 | 
				
			||||||
    void freeMemory(uint8_t* ptr);
 | 
					    void freeMemory(uint8_t* ptr);
 | 
				
			||||||
@ -45,7 +48,9 @@ public:
 | 
				
			|||||||
    Platform& _platform;
 | 
					    Platform& _platform;
 | 
				
			||||||
    DeviceObject& _deviceObject;
 | 
					    DeviceObject& _deviceObject;
 | 
				
			||||||
    SaveRestore* _saveRestores[MAXSAVE] = {0};
 | 
					    SaveRestore* _saveRestores[MAXSAVE] = {0};
 | 
				
			||||||
    int _saveCount = 0;
 | 
					    TableObject* _tableObjects[MAXTABLEOBJ] = {0};
 | 
				
			||||||
 | 
					    uint8_t _saveCount = 0;
 | 
				
			||||||
 | 
					    uint8_t _tableObjCount = 0;
 | 
				
			||||||
    uint8_t* _data = nullptr;
 | 
					    uint8_t* _data = nullptr;
 | 
				
			||||||
    MemoryBlock* _freeList = nullptr;
 | 
					    MemoryBlock* _freeList = nullptr;
 | 
				
			||||||
    MemoryBlock* _usedList = nullptr;
 | 
					    MemoryBlock* _usedList = nullptr;
 | 
				
			||||||
 | 
				
			|||||||
@ -2,6 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "table_object.h"
 | 
					#include "table_object.h"
 | 
				
			||||||
#include "bits.h"
 | 
					#include "bits.h"
 | 
				
			||||||
 | 
					#include "memory.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TableObject::TableObject(Memory& memory): _memory(memory)
 | 
					TableObject::TableObject(Memory& memory): _memory(memory)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
				
			|||||||
@ -1,8 +1,8 @@
 | 
				
			|||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "interface_object.h"
 | 
					#include "interface_object.h"
 | 
				
			||||||
#include "memory.h"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Memory;
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * This class provides common functionality for interface objects that are configured by ETS with MemorWrite.
 | 
					 * This class provides common functionality for interface objects that are configured by ETS with MemorWrite.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user