mirror of
https://github.com/thelsing/knx.git
synced 2025-01-21 00:05:43 +01:00
refactore TableObject classes to use Property class
This commit is contained in:
parent
b9571112d6
commit
6cd570e162
@ -2,25 +2,19 @@
|
|||||||
|
|
||||||
#include "address_table_object.h"
|
#include "address_table_object.h"
|
||||||
#include "bits.h"
|
#include "bits.h"
|
||||||
|
#include "data_property.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
AddressTableObject::AddressTableObject(Memory& memory)
|
AddressTableObject::AddressTableObject(Memory& memory)
|
||||||
: TableObject(memory)
|
: TableObject(memory)
|
||||||
{
|
{
|
||||||
|
Property* properties[] =
|
||||||
}
|
|
||||||
|
|
||||||
void AddressTableObject::readProperty(PropertyID id, uint16_t start, uint8_t& count, uint8_t* data)
|
|
||||||
{
|
|
||||||
switch (id)
|
|
||||||
{
|
{
|
||||||
case PID_OBJECT_TYPE:
|
new DataProperty(PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0, (uint16_t)OT_ADDR_TABLE)
|
||||||
pushWord(OT_ADDR_TABLE, data);
|
};
|
||||||
break;
|
|
||||||
default:
|
TableObject::initializeProperties(sizeof(properties), properties);
|
||||||
TableObject::readProperty(id, start, count, data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t AddressTableObject::entryCount()
|
uint16_t AddressTableObject::entryCount()
|
||||||
@ -78,24 +72,3 @@ void AddressTableObject::beforeStateChange(LoadState& newState)
|
|||||||
|
|
||||||
_groupAddresses = (uint16_t*)data();
|
_groupAddresses = (uint16_t*)data();
|
||||||
}
|
}
|
||||||
|
|
||||||
static PropertyDescription _propertyDescriptions[] =
|
|
||||||
{
|
|
||||||
{ PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 },
|
|
||||||
{ PID_LOAD_STATE_CONTROL, true, PDT_CONTROL, 1, ReadLv3 | WriteLv3 },
|
|
||||||
{ PID_TABLE_REFERENCE, false, PDT_UNSIGNED_LONG, 1, ReadLv3 | WriteLv0 },
|
|
||||||
{ PID_ERROR_CODE, false, PDT_ENUM8, 1, ReadLv3 | WriteLv0 },
|
|
||||||
};
|
|
||||||
|
|
||||||
static uint8_t _propertyDescriptionCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
|
|
||||||
|
|
||||||
uint8_t AddressTableObject::propertyDescriptionCount()
|
|
||||||
{
|
|
||||||
return _propertyDescriptionCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PropertyDescription* AddressTableObject::propertyDescriptions()
|
|
||||||
{
|
|
||||||
return _propertyDescriptions;
|
|
||||||
}
|
|
@ -18,7 +18,6 @@ class AddressTableObject : public TableObject
|
|||||||
* @param memory This parameter is only passed to the custructor of TableObject an not used by this class.
|
* @param memory This parameter is only passed to the custructor of TableObject an not used by this class.
|
||||||
*/
|
*/
|
||||||
AddressTableObject(Memory& memory);
|
AddressTableObject(Memory& memory);
|
||||||
void readProperty(PropertyID id, uint16_t start, uint8_t& count, uint8_t* data) override;
|
|
||||||
uint8_t* restore(uint8_t* buffer) override;
|
uint8_t* restore(uint8_t* buffer) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,8 +51,6 @@ class AddressTableObject : public TableObject
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void beforeStateChange(LoadState& newState) override;
|
virtual void beforeStateChange(LoadState& newState) override;
|
||||||
uint8_t propertyDescriptionCount() override;
|
|
||||||
PropertyDescription* propertyDescriptions() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t* _groupAddresses = 0;
|
uint16_t* _groupAddresses = 0;
|
||||||
|
@ -1,57 +1,27 @@
|
|||||||
#include "application_program_object.h"
|
#include "application_program_object.h"
|
||||||
#include "bits.h"
|
#include "bits.h"
|
||||||
|
#include "data_property.h"
|
||||||
|
#include "callback_property.h"
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
ApplicationProgramObject::ApplicationProgramObject(Memory& memory)
|
ApplicationProgramObject::ApplicationProgramObject(Memory& memory)
|
||||||
: TableObject(memory)
|
: TableObject(memory)
|
||||||
{
|
{
|
||||||
|
Property* properties[] =
|
||||||
}
|
|
||||||
|
|
||||||
void ApplicationProgramObject::readProperty(PropertyID id, uint16_t start, uint8_t& count, uint8_t* data)
|
|
||||||
{
|
|
||||||
switch (id)
|
|
||||||
{
|
{
|
||||||
case PID_OBJECT_TYPE:
|
new DataProperty(PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0, (uint16_t)OT_APPLICATION_PROG),
|
||||||
pushWord(OT_APPLICATION_PROG, data);
|
new DataProperty(PID_PROG_VERSION, true, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv3),
|
||||||
break;
|
new CallbackProperty<ApplicationProgramObject>(this, PID_PEI_TYPE, false, PDT_UNSIGNED_CHAR, 1, ReadLv3 | WriteLv0,
|
||||||
case PID_PROG_VERSION:
|
[](ApplicationProgramObject* io, uint16_t start, uint8_t count, uint8_t* data) -> uint8_t {
|
||||||
pushByteArray(_programVersion, 5, data);
|
if (start == 0)
|
||||||
break;
|
return 1;
|
||||||
case PID_PEI_TYPE:
|
|
||||||
pushByte(0x0, data);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
TableObject::readProperty(id, start, count, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ApplicationProgramObject::writeProperty(PropertyID id, uint16_t start, uint8_t* data, uint8_t& count)
|
data[0] = 0;
|
||||||
{
|
return 1;
|
||||||
switch (id)
|
})
|
||||||
{
|
};
|
||||||
case PID_PROG_VERSION:
|
|
||||||
for (uint32_t i = 0; i < 5; i++)
|
|
||||||
{
|
|
||||||
_programVersion[i] = data[i];
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
TableObject::writeProperty(id, start, data, count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t ApplicationProgramObject::propertySize(PropertyID id)
|
TableObject::initializeProperties(sizeof(properties), properties);
|
||||||
{
|
|
||||||
switch (id)
|
|
||||||
{
|
|
||||||
case PID_PEI_TYPE:
|
|
||||||
return 1;
|
|
||||||
case PID_OBJECT_TYPE:
|
|
||||||
return 2;
|
|
||||||
case PID_PROG_VERSION:
|
|
||||||
return 5;
|
|
||||||
}
|
|
||||||
return TableObject::propertySize(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t * ApplicationProgramObject::data(uint32_t addr)
|
uint8_t * ApplicationProgramObject::data(uint32_t addr)
|
||||||
@ -73,44 +43,3 @@ uint32_t ApplicationProgramObject::getInt(uint32_t addr)
|
|||||||
{
|
{
|
||||||
return ::getInt(TableObject::data() + addr);
|
return ::getInt(TableObject::data() + addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t* ApplicationProgramObject::save(uint8_t* buffer)
|
|
||||||
{
|
|
||||||
buffer = pushByteArray(_programVersion, 5, buffer);
|
|
||||||
|
|
||||||
return TableObject::save(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t* ApplicationProgramObject::restore(uint8_t* buffer)
|
|
||||||
{
|
|
||||||
buffer = popByteArray(_programVersion, 5, buffer);
|
|
||||||
|
|
||||||
return TableObject::restore(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PropertyDescription _propertyDescriptions[] =
|
|
||||||
{
|
|
||||||
{ PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 },
|
|
||||||
{ PID_LOAD_STATE_CONTROL, true, PDT_CONTROL, 1, ReadLv3 | WriteLv3 },
|
|
||||||
{ PID_TABLE_REFERENCE, false, PDT_UNSIGNED_LONG, 1, ReadLv3 | WriteLv0 },
|
|
||||||
{ PID_ERROR_CODE, false, PDT_ENUM8, 1, ReadLv3 | WriteLv0 },
|
|
||||||
{ PID_PEI_TYPE, false, PDT_UNSIGNED_CHAR, 1, ReadLv3 | WriteLv0 },
|
|
||||||
{ PID_PROG_VERSION, true, PDT_GENERIC_05, 1, ReadLv3 | WriteLv3 },
|
|
||||||
};
|
|
||||||
static uint8_t _propertyDescriptionCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
|
|
||||||
|
|
||||||
uint8_t ApplicationProgramObject::propertyDescriptionCount()
|
|
||||||
{
|
|
||||||
return _propertyDescriptionCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PropertyDescription* ApplicationProgramObject::propertyDescriptions()
|
|
||||||
{
|
|
||||||
return _propertyDescriptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t ApplicationProgramObject::saveSize()
|
|
||||||
{
|
|
||||||
return TableObject::saveSize() + 5;
|
|
||||||
}
|
|
@ -6,21 +6,8 @@ class ApplicationProgramObject : public TableObject
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ApplicationProgramObject(Memory& memory);
|
ApplicationProgramObject(Memory& memory);
|
||||||
void readProperty(PropertyID id, uint16_t start, uint8_t& count, uint8_t* data) override;
|
|
||||||
void writeProperty(PropertyID id, uint16_t start, uint8_t* data, uint8_t& count) override;
|
|
||||||
uint8_t propertySize(PropertyID id) override;
|
|
||||||
uint8_t* data(uint32_t addr);
|
uint8_t* data(uint32_t addr);
|
||||||
uint8_t getByte(uint32_t addr);
|
uint8_t getByte(uint32_t addr);
|
||||||
uint16_t getWord(uint32_t addr);
|
uint16_t getWord(uint32_t addr);
|
||||||
uint32_t getInt(uint32_t addr);
|
uint32_t getInt(uint32_t addr);
|
||||||
uint8_t* save(uint8_t* buffer) override;
|
|
||||||
uint8_t* restore(uint8_t* buffer) override;
|
|
||||||
uint16_t saveSize() override;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
uint8_t propertyDescriptionCount() override;
|
|
||||||
PropertyDescription* propertyDescriptions() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
uint8_t _programVersion[5] = {0, 0, 0, 0, 0};
|
|
||||||
};
|
};
|
@ -2,25 +2,19 @@
|
|||||||
|
|
||||||
#include "association_table_object.h"
|
#include "association_table_object.h"
|
||||||
#include "bits.h"
|
#include "bits.h"
|
||||||
|
#include "data_property.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
AssociationTableObject::AssociationTableObject(Memory& memory)
|
AssociationTableObject::AssociationTableObject(Memory& memory)
|
||||||
: TableObject(memory)
|
: TableObject(memory)
|
||||||
{
|
{
|
||||||
|
Property* properties[] =
|
||||||
}
|
|
||||||
|
|
||||||
void AssociationTableObject::readProperty(PropertyID id, uint16_t start, uint8_t& count, uint8_t* data)
|
|
||||||
{
|
|
||||||
switch (id)
|
|
||||||
{
|
{
|
||||||
case PID_OBJECT_TYPE:
|
new DataProperty(PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0, (uint16_t)OT_ASSOC_TABLE)
|
||||||
pushWord(OT_ASSOC_TABLE, data);
|
};
|
||||||
break;
|
|
||||||
default:
|
TableObject::initializeProperties(sizeof(properties), properties);
|
||||||
TableObject::readProperty(id, start, count, data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t AssociationTableObject::entryCount()
|
uint16_t AssociationTableObject::entryCount()
|
||||||
@ -63,8 +57,6 @@ int32_t AssociationTableObject::translateAsap(uint16_t asap)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void AssociationTableObject::beforeStateChange(LoadState& newState)
|
void AssociationTableObject::beforeStateChange(LoadState& newState)
|
||||||
{
|
{
|
||||||
if (newState != LS_LOADED)
|
if (newState != LS_LOADED)
|
||||||
@ -73,27 +65,6 @@ void AssociationTableObject::beforeStateChange(LoadState& newState)
|
|||||||
_tableData = (uint16_t*)data();
|
_tableData = (uint16_t*)data();
|
||||||
}
|
}
|
||||||
|
|
||||||
static PropertyDescription _propertyDescriptions[] =
|
|
||||||
{
|
|
||||||
{ PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 },
|
|
||||||
{ PID_TABLE, false, PDT_GENERIC_04, 65535, ReadLv3 | WriteLv0 },
|
|
||||||
{ PID_LOAD_STATE_CONTROL, true, PDT_CONTROL, 1, ReadLv3 | WriteLv3 },
|
|
||||||
{ PID_TABLE_REFERENCE, false, PDT_UNSIGNED_LONG, 1, ReadLv3 | WriteLv0 },
|
|
||||||
{ PID_ERROR_CODE, false, PDT_ENUM8, 1, ReadLv3 | WriteLv0 },
|
|
||||||
};
|
|
||||||
static uint8_t _propertyDescriptionCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
|
|
||||||
|
|
||||||
uint8_t AssociationTableObject::propertyDescriptionCount()
|
|
||||||
{
|
|
||||||
return _propertyDescriptionCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PropertyDescription* AssociationTableObject::propertyDescriptions()
|
|
||||||
{
|
|
||||||
return _propertyDescriptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t AssociationTableObject::nextAsap(uint16_t tsap, uint16_t& startIdx)
|
int32_t AssociationTableObject::nextAsap(uint16_t tsap, uint16_t& startIdx)
|
||||||
{
|
{
|
||||||
uint16_t entries = entryCount();
|
uint16_t entries = entryCount();
|
||||||
|
@ -6,7 +6,6 @@ class AssociationTableObject : public TableObject
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AssociationTableObject(Memory& memory);
|
AssociationTableObject(Memory& memory);
|
||||||
void readProperty(PropertyID id, uint16_t start, uint8_t& count, uint8_t* data) override;
|
|
||||||
|
|
||||||
uint8_t* restore(uint8_t* buffer) override;
|
uint8_t* restore(uint8_t* buffer) override;
|
||||||
|
|
||||||
@ -15,8 +14,6 @@ class AssociationTableObject : public TableObject
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void beforeStateChange(LoadState& newState) override;
|
void beforeStateChange(LoadState& newState) override;
|
||||||
uint8_t propertyDescriptionCount() override;
|
|
||||||
PropertyDescription* propertyDescriptions() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t entryCount();
|
uint16_t entryCount();
|
||||||
|
@ -3,10 +3,16 @@
|
|||||||
#include "group_object_table_object.h"
|
#include "group_object_table_object.h"
|
||||||
#include "group_object.h"
|
#include "group_object.h"
|
||||||
#include "bits.h"
|
#include "bits.h"
|
||||||
|
#include "data_property.h"
|
||||||
|
|
||||||
GroupObjectTableObject::GroupObjectTableObject(Memory& memory)
|
GroupObjectTableObject::GroupObjectTableObject(Memory& memory)
|
||||||
: TableObject(memory)
|
: TableObject(memory)
|
||||||
{
|
{
|
||||||
|
Property* properties[]
|
||||||
|
{
|
||||||
|
new DataProperty(PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0, (uint16_t)OT_GRP_OBJ_TABLE)
|
||||||
|
};
|
||||||
|
TableObject::initializeProperties(sizeof(properties), properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
GroupObjectTableObject::~GroupObjectTableObject()
|
GroupObjectTableObject::~GroupObjectTableObject()
|
||||||
@ -14,18 +20,6 @@ GroupObjectTableObject::~GroupObjectTableObject()
|
|||||||
freeGroupObjects();
|
freeGroupObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GroupObjectTableObject::readProperty(PropertyID id, uint16_t start, uint8_t& count, uint8_t* data)
|
|
||||||
{
|
|
||||||
switch (id)
|
|
||||||
{
|
|
||||||
case PID_OBJECT_TYPE:
|
|
||||||
pushWord(OT_GRP_OBJ_TABLE, data);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
TableObject::readProperty(id, start, count, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t GroupObjectTableObject::entryCount()
|
uint16_t GroupObjectTableObject::entryCount()
|
||||||
{
|
{
|
||||||
if (loadState() != LS_LOADED)
|
if (loadState() != LS_LOADED)
|
||||||
@ -34,8 +28,6 @@ uint16_t GroupObjectTableObject::entryCount()
|
|||||||
return ntohs(_tableData[0]);
|
return ntohs(_tableData[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GroupObject& GroupObjectTableObject::get(uint16_t asap)
|
GroupObject& GroupObjectTableObject::get(uint16_t asap)
|
||||||
{
|
{
|
||||||
return _groupObjects[asap - 1];
|
return _groupObjects[asap - 1];
|
||||||
@ -126,26 +118,6 @@ bool GroupObjectTableObject::initGroupObjects()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PropertyDescription _propertyDescriptions[] =
|
|
||||||
{
|
|
||||||
{ PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 },
|
|
||||||
{ PID_LOAD_STATE_CONTROL, true, PDT_CONTROL, 1, ReadLv3 | WriteLv3 },
|
|
||||||
{ PID_TABLE_REFERENCE, false, PDT_UNSIGNED_LONG, 1, ReadLv3 | WriteLv0 },
|
|
||||||
{ PID_ERROR_CODE, false, PDT_ENUM8, 1, ReadLv3 | WriteLv0 },
|
|
||||||
};
|
|
||||||
static uint8_t _propertyDescriptionCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
|
|
||||||
|
|
||||||
uint8_t GroupObjectTableObject::propertyDescriptionCount()
|
|
||||||
{
|
|
||||||
return _propertyDescriptionCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PropertyDescription* GroupObjectTableObject::propertyDescriptions()
|
|
||||||
{
|
|
||||||
return _propertyDescriptions;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GroupObjectTableObject::freeGroupObjects()
|
void GroupObjectTableObject::freeGroupObjects()
|
||||||
{
|
{
|
||||||
if (_groupObjects)
|
if (_groupObjects)
|
||||||
|
@ -10,7 +10,6 @@ class GroupObjectTableObject : public TableObject
|
|||||||
public:
|
public:
|
||||||
GroupObjectTableObject(Memory& memory);
|
GroupObjectTableObject(Memory& memory);
|
||||||
virtual ~GroupObjectTableObject();
|
virtual ~GroupObjectTableObject();
|
||||||
void readProperty(PropertyID id, uint16_t start, uint8_t& count, uint8_t* data) override;
|
|
||||||
uint16_t entryCount();
|
uint16_t entryCount();
|
||||||
GroupObject& get(uint16_t asap);
|
GroupObject& get(uint16_t asap);
|
||||||
GroupObject& nextUpdatedObject(bool& valid);
|
GroupObject& nextUpdatedObject(bool& valid);
|
||||||
@ -20,8 +19,6 @@ class GroupObjectTableObject : public TableObject
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void beforeStateChange(LoadState& newState) override;
|
void beforeStateChange(LoadState& newState) override;
|
||||||
uint8_t propertyDescriptionCount() override;
|
|
||||||
PropertyDescription* propertyDescriptions() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void freeGroupObjects();
|
void freeGroupObjects();
|
||||||
|
@ -148,7 +148,7 @@ class InterfaceObject : public SaveRestore
|
|||||||
/**
|
/**
|
||||||
* Intializes the Property-array the the supplied values.
|
* Intializes the Property-array the the supplied values.
|
||||||
*/
|
*/
|
||||||
void initializeProperties(size_t propertiesSize, Property** properties);
|
virtual void initializeProperties(size_t propertiesSize, Property** properties);
|
||||||
|
|
||||||
Property** _properties = nullptr;
|
Property** _properties = nullptr;
|
||||||
uint8_t _propertyCount = 0;
|
uint8_t _propertyCount = 0;
|
||||||
|
@ -3,71 +3,15 @@
|
|||||||
#include "table_object.h"
|
#include "table_object.h"
|
||||||
#include "bits.h"
|
#include "bits.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
#include "callback_property.h"
|
||||||
|
#include "data_property.h"
|
||||||
|
|
||||||
TableObject::TableObject(Memory& memory): _memory(memory)
|
TableObject::TableObject(Memory& memory)
|
||||||
{
|
: _memory(memory)
|
||||||
|
{}
|
||||||
}
|
|
||||||
|
|
||||||
void TableObject::readProperty(PropertyID id, uint16_t start, uint8_t& count, uint8_t* data)
|
|
||||||
{
|
|
||||||
switch (id)
|
|
||||||
{
|
|
||||||
case PID_LOAD_STATE_CONTROL:
|
|
||||||
data[0] = _state;
|
|
||||||
break;
|
|
||||||
case PID_TABLE_REFERENCE:
|
|
||||||
if (_state == LS_UNLOADED)
|
|
||||||
pushInt(0, data);
|
|
||||||
else
|
|
||||||
pushInt(tableReference(), data);
|
|
||||||
break;
|
|
||||||
case PID_ERROR_CODE:
|
|
||||||
data[0] = _errorCode;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
InterfaceObject::readProperty(id, start, count, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TableObject::writeProperty(PropertyID id, uint16_t start, uint8_t* data, uint8_t& count)
|
|
||||||
{
|
|
||||||
switch (id)
|
|
||||||
{
|
|
||||||
case PID_LOAD_STATE_CONTROL:
|
|
||||||
loadEvent(data);
|
|
||||||
break;
|
|
||||||
|
|
||||||
//case PID_MCB_TABLE:
|
|
||||||
// TODO
|
|
||||||
// break;
|
|
||||||
default:
|
|
||||||
InterfaceObject::writeProperty(id, start, data, count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t TableObject::propertySize(PropertyID id)
|
|
||||||
{
|
|
||||||
switch (id)
|
|
||||||
{
|
|
||||||
case PID_LOAD_STATE_CONTROL:
|
|
||||||
return 1;
|
|
||||||
case PID_TABLE_REFERENCE:
|
|
||||||
return 4;
|
|
||||||
case PID_ERROR_CODE:
|
|
||||||
return 1;
|
|
||||||
case PID_OBJECT_TYPE:
|
|
||||||
return 2;
|
|
||||||
default:
|
|
||||||
return InterfaceObject::propertySize(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TableObject::~TableObject()
|
TableObject::~TableObject()
|
||||||
{
|
{}
|
||||||
// if (_data != 0)
|
|
||||||
// _memory.freeMemory(_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadState TableObject::loadState()
|
LoadState TableObject::loadState()
|
||||||
{
|
{
|
||||||
@ -86,7 +30,6 @@ void TableObject::loadState(LoadState newState)
|
|||||||
uint8_t* TableObject::save(uint8_t* buffer)
|
uint8_t* TableObject::save(uint8_t* buffer)
|
||||||
{
|
{
|
||||||
buffer = pushByte(_state, buffer);
|
buffer = pushByte(_state, buffer);
|
||||||
buffer = pushByte(_errorCode, buffer);
|
|
||||||
|
|
||||||
if (_data)
|
if (_data)
|
||||||
buffer = pushInt(_memory.toRelative(_data), buffer);
|
buffer = pushInt(_memory.toRelative(_data), buffer);
|
||||||
@ -100,11 +43,8 @@ uint8_t* TableObject::save(uint8_t* buffer)
|
|||||||
uint8_t* TableObject::restore(uint8_t* buffer)
|
uint8_t* TableObject::restore(uint8_t* buffer)
|
||||||
{
|
{
|
||||||
uint8_t state = 0;
|
uint8_t state = 0;
|
||||||
uint8_t errorCode = 0;
|
|
||||||
buffer = popByte(state, buffer);
|
buffer = popByte(state, buffer);
|
||||||
buffer = popByte(errorCode, buffer);
|
|
||||||
_state = (LoadState)state;
|
_state = (LoadState)state;
|
||||||
_errorCode = (ErrorCode)errorCode;
|
|
||||||
|
|
||||||
uint32_t relativeAddress = 0;
|
uint32_t relativeAddress = 0;
|
||||||
buffer = popInt(relativeAddress, buffer);
|
buffer = popInt(relativeAddress, buffer);
|
||||||
@ -180,7 +120,7 @@ void TableObject::loadEventUnloaded(uint8_t* data)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
loadState(LS_ERROR);
|
loadState(LS_ERROR);
|
||||||
_errorCode = E_GOT_UNDEF_LOAD_CMD;
|
errorCode(E_GOT_UNDEF_LOAD_CMD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,7 +143,7 @@ void TableObject::loadEventLoading(uint8_t* data)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
loadState(LS_ERROR);
|
loadState(LS_ERROR);
|
||||||
_errorCode = E_GOT_UNDEF_LOAD_CMD;
|
errorCode(E_GOT_UNDEF_LOAD_CMD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,11 +169,11 @@ void TableObject::loadEventLoaded(uint8_t* data)
|
|||||||
break;
|
break;
|
||||||
case LE_ADDITIONAL_LOAD_CONTROLS:
|
case LE_ADDITIONAL_LOAD_CONTROLS:
|
||||||
loadState(LS_ERROR);
|
loadState(LS_ERROR);
|
||||||
_errorCode = E_INVALID_OPCODE;
|
errorCode(E_INVALID_OPCODE);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
loadState(LS_ERROR);
|
loadState(LS_ERROR);
|
||||||
_errorCode = E_GOT_UNDEF_LOAD_CMD;
|
errorCode(E_GOT_UNDEF_LOAD_CMD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,7 +192,7 @@ void TableObject::loadEventError(uint8_t* data)
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
loadState(LS_ERROR);
|
loadState(LS_ERROR);
|
||||||
_errorCode = E_GOT_UNDEF_LOAD_CMD;
|
errorCode(E_GOT_UNDEF_LOAD_CMD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,7 +201,7 @@ void TableObject::additionalLoadControls(uint8_t* data)
|
|||||||
if (data[1] != 0x0B) // Data Relative Allocation
|
if (data[1] != 0x0B) // Data Relative Allocation
|
||||||
{
|
{
|
||||||
loadState(LS_ERROR);
|
loadState(LS_ERROR);
|
||||||
_errorCode = E_INVALID_OPCODE;
|
errorCode(E_INVALID_OPCODE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,7 +211,7 @@ void TableObject::additionalLoadControls(uint8_t* data)
|
|||||||
if (!allocTable(size, doFill, fillByte))
|
if (!allocTable(size, doFill, fillByte))
|
||||||
{
|
{
|
||||||
loadState(LS_ERROR);
|
loadState(LS_ERROR);
|
||||||
_errorCode = E_MAX_TABLE_LENGTH_EXEEDED;
|
errorCode(E_MAX_TABLE_LENGTH_EXEEDED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,10 +222,58 @@ uint8_t* TableObject::data()
|
|||||||
|
|
||||||
void TableObject::errorCode(ErrorCode errorCode)
|
void TableObject::errorCode(ErrorCode errorCode)
|
||||||
{
|
{
|
||||||
_errorCode = errorCode;
|
uint8_t data = errorCode;
|
||||||
|
Property* prop = property(PID_ERROR_CODE);
|
||||||
|
prop->write(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t TableObject::saveSize()
|
uint16_t TableObject::saveSize()
|
||||||
{
|
{
|
||||||
return 6;
|
return 5 + InterfaceObject::saveSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TableObject::initializeProperties(size_t propertiesSize, Property** properties)
|
||||||
|
{
|
||||||
|
Property* ownProperties[] =
|
||||||
|
{
|
||||||
|
new CallbackProperty<TableObject>(this, PID_LOAD_STATE_CONTROL, true, PDT_CONTROL, 1, ReadLv3 | WriteLv3,
|
||||||
|
[](TableObject* obj, uint16_t start, uint8_t count, uint8_t* data) -> uint8_t {
|
||||||
|
if (start == 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
data[0] = obj->_state;
|
||||||
|
return 1;
|
||||||
|
},
|
||||||
|
[](TableObject* obj, uint16_t start, uint8_t count, uint8_t* data) -> uint8_t {
|
||||||
|
obj->loadEvent(data);
|
||||||
|
return 1;
|
||||||
|
}),
|
||||||
|
new CallbackProperty<TableObject>(this, PID_TABLE_REFERENCE, false, PDT_UNSIGNED_LONG, 1, ReadLv3 | WriteLv0,
|
||||||
|
[](TableObject* obj, uint16_t start, uint8_t count, uint8_t* data) -> uint8_t {
|
||||||
|
if (start == 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (obj->_state == LS_UNLOADED)
|
||||||
|
pushInt(0, data);
|
||||||
|
else
|
||||||
|
pushInt(obj->tableReference(), data);
|
||||||
|
return 1;
|
||||||
|
}),
|
||||||
|
new DataProperty(PID_ERROR_CODE, false, PDT_ENUM8, 1, ReadLv3 | WriteLv0, (uint8_t)E_NO_FAULT)
|
||||||
|
};
|
||||||
|
//TODO: missing
|
||||||
|
|
||||||
|
// 23 PID_TABLE 3 / (3)
|
||||||
|
// 27 PID_MCB_TABLE 3 / 3
|
||||||
|
|
||||||
|
uint8_t ownPropertiesCount = sizeof(ownProperties) / sizeof(Property*);
|
||||||
|
|
||||||
|
uint8_t propertyCount = propertiesSize / sizeof(Property*);
|
||||||
|
uint8_t allPropertiesCount = propertyCount + ownPropertiesCount;
|
||||||
|
|
||||||
|
Property* allProperties[allPropertiesCount];
|
||||||
|
memcpy(allProperties, properties, propertiesSize);
|
||||||
|
memcpy(allProperties + propertyCount, ownProperties, sizeof(ownProperties));
|
||||||
|
|
||||||
|
InterfaceObject::initializeProperties(sizeof(allProperties), allProperties);
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,7 @@ class TableObject: public InterfaceObject
|
|||||||
* @param memory The instance of the memory management class to use.
|
* @param memory The instance of the memory management class to use.
|
||||||
*/
|
*/
|
||||||
TableObject(Memory& memory);
|
TableObject(Memory& memory);
|
||||||
virtual void readProperty(PropertyID id, uint16_t start, uint8_t& count, uint8_t* data) override;
|
|
||||||
virtual void writeProperty(PropertyID id, uint16_t start, uint8_t* data, uint8_t& count) override;
|
|
||||||
virtual uint8_t propertySize(PropertyID id) override;
|
|
||||||
/**
|
/**
|
||||||
* The destructor.
|
* The destructor.
|
||||||
*/
|
*/
|
||||||
@ -48,6 +46,8 @@ protected:
|
|||||||
*/
|
*/
|
||||||
void errorCode(ErrorCode errorCode);
|
void errorCode(ErrorCode errorCode);
|
||||||
|
|
||||||
|
void initializeProperties(size_t propertiesSize, Property** properties) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t tableReference();
|
uint32_t tableReference();
|
||||||
bool allocTable(uint32_t size, bool doFill, uint8_t fillByte);
|
bool allocTable(uint32_t size, bool doFill, uint8_t fillByte);
|
||||||
@ -68,5 +68,4 @@ protected:
|
|||||||
LoadState _state = LS_UNLOADED;
|
LoadState _state = LS_UNLOADED;
|
||||||
Memory& _memory;
|
Memory& _memory;
|
||||||
uint8_t *_data = 0;
|
uint8_t *_data = 0;
|
||||||
ErrorCode _errorCode = E_NO_FAULT;
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user