add overrides keyword for all interface objects.

refactor properties more
This commit is contained in:
Thomas Kunze 2019-12-11 23:32:57 +01:00
parent 396994c1a5
commit 71448efdad
22 changed files with 164 additions and 96 deletions

View File

@ -87,11 +87,11 @@ static PropertyDescription _propertyDescriptions[] =
{ PID_ERROR_CODE, false, PDT_ENUM8, 1, ReadLv3 | WriteLv0 },
};
static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
static uint8_t _propertyDescriptionCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
uint8_t AddressTableObject::propertyCount()
uint8_t AddressTableObject::propertyDescriptionCount()
{
return _propertyCount;
return _propertyDescriptionCount;
}

View File

@ -52,9 +52,9 @@ class AddressTableObject : public TableObject
bool contains(uint16_t groupAddress);
protected:
virtual void beforeStateChange(LoadState& newState);
uint8_t propertyCount();
PropertyDescription* propertyDescriptions();
virtual void beforeStateChange(LoadState& newState) override;
uint8_t propertyDescriptionCount() override;
PropertyDescription* propertyDescriptions() override;
private:
uint16_t* _groupAddresses = 0;

View File

@ -97,11 +97,11 @@ static PropertyDescription _propertyDescriptions[] =
{ PID_PEI_TYPE, false, PDT_UNSIGNED_CHAR, 1, ReadLv3 | WriteLv0 },
{ PID_PROG_VERSION, true, PDT_GENERIC_05, 1, ReadLv3 | WriteLv3 },
};
static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
static uint8_t _propertyDescriptionCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
uint8_t ApplicationProgramObject::propertyCount()
uint8_t ApplicationProgramObject::propertyDescriptionCount()
{
return _propertyCount;
return _propertyDescriptionCount;
}

View File

@ -6,21 +6,21 @@ class ApplicationProgramObject : public TableObject
{
public:
ApplicationProgramObject(Memory& memory);
void readProperty(PropertyID id, uint16_t start, uint8_t& count, uint8_t* data);
void writeProperty(PropertyID id, uint16_t start, uint8_t* data, uint8_t& count);
uint8_t propertySize(PropertyID id);
ObjectType objectType() { return OT_APPLICATION_PROG; }
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;
ObjectType objectType() override { return OT_APPLICATION_PROG; }
uint8_t* data(uint32_t addr);
uint8_t getByte(uint32_t addr);
uint16_t getWord(uint32_t addr);
uint32_t getInt(uint32_t addr);
uint8_t* save(uint8_t* buffer);
uint8_t* restore(uint8_t* buffer);
uint16_t saveSize();
uint8_t* save(uint8_t* buffer) override;
uint8_t* restore(uint8_t* buffer) override;
uint16_t saveSize() override;
protected:
uint8_t propertyCount();
PropertyDescription* propertyDescriptions();
uint8_t propertyDescriptionCount() override;
PropertyDescription* propertyDescriptions() override;
private:
uint8_t _programVersion[5] = {0, 0, 0, 0, 0};

View File

@ -81,11 +81,11 @@ static PropertyDescription _propertyDescriptions[] =
{ PID_TABLE_REFERENCE, false, PDT_UNSIGNED_LONG, 1, ReadLv3 | WriteLv0 },
{ PID_ERROR_CODE, false, PDT_ENUM8, 1, ReadLv3 | WriteLv0 },
};
static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
static uint8_t _propertyDescriptionCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
uint8_t AssociationTableObject::propertyCount()
uint8_t AssociationTableObject::propertyDescriptionCount()
{
return _propertyCount;
return _propertyDescriptionCount;
}

View File

@ -6,18 +6,18 @@ class AssociationTableObject : public TableObject
{
public:
AssociationTableObject(Memory& memory);
void readProperty(PropertyID id, uint16_t start, uint8_t& count, uint8_t* data);
ObjectType objectType() { return OT_ASSOC_TABLE; }
void readProperty(PropertyID id, uint16_t start, uint8_t& count, uint8_t* data) override;
ObjectType objectType() override { return OT_ASSOC_TABLE; }
uint8_t* restore(uint8_t* buffer);
uint8_t* restore(uint8_t* buffer) override;
int32_t translateAsap(uint16_t asap);
int32_t nextAsap(uint16_t tsap, uint16_t& startIdx);
protected:
void beforeStateChange(LoadState& newState);
uint8_t propertyCount();
PropertyDescription* propertyDescriptions();
void beforeStateChange(LoadState& newState) override;
uint8_t propertyDescriptionCount() override;
PropertyDescription* propertyDescriptions() override;
private:
uint16_t entryCount();

View File

@ -6,6 +6,12 @@ CallbackProperty::CallbackProperty(PropertyID id, bool writeEnable, PropertyData
: Property(id, writeEnable, type, maxElements, access), _readCallback(), _writeCallback()
{}
CallbackProperty::CallbackProperty(PropertyID id, bool writeEnable, PropertyDataType type,
uint16_t maxElements, uint8_t access,
PropertyCallback readCallback)
: Property(id, writeEnable, type, maxElements, access), _readCallback()
{}
uint8_t CallbackProperty::read(uint16_t start, uint8_t count, uint8_t* data)
{
if (count == 0 || _readCallback == nullptr)

View File

@ -9,6 +9,8 @@ class CallbackProperty : public Property
public:
CallbackProperty(PropertyID id, bool writeEnable, PropertyDataType type, uint16_t maxElements,
uint8_t access, PropertyCallback readCallback, PropertyCallback writeCallback);
CallbackProperty(PropertyID id, bool writeEnable, PropertyDataType type, uint16_t maxElements,
uint8_t access, PropertyCallback readCallback);
virtual uint8_t read(uint16_t start, uint8_t count, uint8_t* data) override;
virtual uint8_t write(uint16_t start, uint8_t count, uint8_t* data) override;
private:

View File

@ -100,11 +100,11 @@ static PropertyDescription _propertyDescriptions[] =
{ PID_MEDIUM_AVAILABILITY, false, PDT_BITSET16, 1, ReadLv3 | WriteLv0 },
{ PID_ADD_INFO_TYPES, false, PDT_ENUM8, 1, ReadLv3 | WriteLv0 }
};
static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
static uint8_t _propertyDescriptionCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
uint8_t CemiServerObject::propertyCount()
uint8_t CemiServerObject::propertyDescriptionCount()
{
return _propertyCount;
return _propertyDescriptionCount;
}
PropertyDescription* CemiServerObject::propertyDescriptions()

View File

@ -8,14 +8,13 @@ public:
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* save(uint8_t* buffer);
uint8_t* restore(uint8_t* buffer);
void readPropertyDescription(uint8_t propertyId, uint8_t& propertyIndex, bool& writeEnable, uint8_t& type, uint16_t& numberOfElements, uint8_t& access);
ObjectType objectType() { return OT_CEMI_SERVER; }
uint8_t* save(uint8_t* buffer) override;
uint8_t* restore(uint8_t* buffer) override;
ObjectType objectType() override { return OT_CEMI_SERVER; }
protected:
uint8_t propertyCount();
PropertyDescription* propertyDescriptions();
uint8_t propertyDescriptionCount() override;
PropertyDescription* propertyDescriptions() override;
private:
// cEMI additional info types supported by this cEMI server: only 0x02 (RF Control Octet and Serial Number or DoA)
uint8_t _addInfoTypesTable[1] = { 0x02 };

View File

@ -324,11 +324,11 @@ static PropertyDescription _propertyDescriptions[] =
{ PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 },
{ PID_SERIAL_NUMBER, false, PDT_GENERIC_06, 1, ReadLv3 | WriteLv0 }
};
static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
static uint8_t _propertyDescriptionCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
uint8_t DeviceObject::propertyCount()
uint8_t DeviceObject::propertyDescriptionCount()
{
return _propertyCount;
return _propertyDescriptionCount;
}

View File

@ -7,14 +7,14 @@
class DeviceObject: public InterfaceObject
{
public:
void readProperty(PropertyID id, uint16_t start, uint8_t& count, uint8_t* data);
void writeProperty(PropertyID id, uint16_t start, uint8_t* data, uint8_t& count);
uint8_t propertySize(PropertyID id);
uint8_t* save(uint8_t* buffer);
uint8_t* restore(uint8_t* buffer);
uint16_t saveSize();
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* save(uint8_t* buffer) override;
uint8_t* restore(uint8_t* buffer) override;
uint16_t saveSize() override;
void readPropertyDescription(uint8_t propertyId, uint8_t& propertyIndex, bool& writeEnable, uint8_t& type, uint16_t& numberOfElements, uint8_t& access);
ObjectType objectType() { return OT_DEVICE; }
ObjectType objectType() override { return OT_DEVICE; }
uint16_t induvidualAddress();
void induvidualAddress(uint16_t value);
@ -49,8 +49,8 @@ public:
uint8_t* rfDomainAddress();
void rfDomainAddress(uint8_t* value);
protected:
uint8_t propertyCount();
PropertyDescription* propertyDescriptions();
uint8_t propertyDescriptionCount() override;
PropertyDescription* propertyDescriptions() override;
private:
uint8_t _deviceControl = 0;
uint8_t _routingCount = 0;

View File

@ -133,11 +133,11 @@ static PropertyDescription _propertyDescriptions[] =
{ PID_TABLE_REFERENCE, false, PDT_UNSIGNED_LONG, 1, ReadLv3 | WriteLv0 },
{ PID_ERROR_CODE, false, PDT_ENUM8, 1, ReadLv3 | WriteLv0 },
};
static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
static uint8_t _propertyDescriptionCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
uint8_t GroupObjectTableObject::propertyCount()
uint8_t GroupObjectTableObject::propertyDescriptionCount()
{
return _propertyCount;
return _propertyDescriptionCount;
}

View File

@ -10,19 +10,19 @@ class GroupObjectTableObject : public TableObject
public:
GroupObjectTableObject(Memory& memory);
virtual ~GroupObjectTableObject();
void readProperty(PropertyID id, uint16_t start, uint8_t& count, uint8_t* data);
ObjectType objectType() { return OT_GRP_OBJ_TABLE; }
void readProperty(PropertyID id, uint16_t start, uint8_t& count, uint8_t* data) override;
ObjectType objectType() override { return OT_GRP_OBJ_TABLE; }
uint16_t entryCount();
GroupObject& get(uint16_t asap);
GroupObject& nextUpdatedObject(bool& valid);
void groupObjects(GroupObject* objs, uint16_t size);
uint8_t* restore(uint8_t* buffer);
uint8_t* restore(uint8_t* buffer) override;
protected:
void beforeStateChange(LoadState& newState);
uint8_t propertyCount();
PropertyDescription* propertyDescriptions();
void beforeStateChange(LoadState& newState) override;
uint8_t propertyDescriptionCount() override;
PropertyDescription* propertyDescriptions() override;
private:
void freeGroupObjects();

View File

@ -1,9 +1,17 @@
#include <cstring>
#include "interface_object.h"
InterfaceObject::~InterfaceObject()
{
if (_properties != nullptr)
delete[] _properties;
}
void InterfaceObject::readPropertyDescription(uint8_t& propertyId, uint8_t& propertyIndex, bool& writeEnable, uint8_t& type, uint16_t& numberOfElements, uint8_t& access)
{
PropertyDescription* descriptions = propertyDescriptions();
uint8_t count = propertyCount();
uint8_t count = propertyDescriptionCount();
numberOfElements = 0;
if (descriptions == nullptr || count == 0)
@ -65,7 +73,7 @@ uint8_t InterfaceObject::propertySize(PropertyID id)
return 0;
}
uint8_t InterfaceObject::propertyCount()
uint8_t InterfaceObject::propertyDescriptionCount()
{
return 0;
}
@ -75,3 +83,20 @@ PropertyDescription* InterfaceObject::propertyDescriptions()
return nullptr;
}
void InterfaceObject::initializeProperties(size_t propertiesSize, Property** properties)
{
_propertyCount = propertiesSize / sizeof(Property*);
_properties = new Property*[_propertyCount];
memcpy(_properties, properties, propertiesSize);
}
Property* InterfaceObject::property(PropertyID id)
{
for (int i = 0; i < _propertyCount; i++)
if (_properties[i]->Id() == id)
return _properties[i];
return nullptr;
}

View File

@ -62,7 +62,7 @@ class InterfaceObject : public SaveRestore
/**
* Destructor
*/
virtual ~InterfaceObject() {}
virtual ~InterfaceObject();
/**
* Read a property of the interface object. See section 4.8.4.2 of @cite knx:3/4/1.
*
@ -126,14 +126,27 @@ class InterfaceObject : public SaveRestore
*/
virtual ObjectType objectType() = 0;
/**
* Gets property with PropertyID id if it exists and nullptr otherwise.
*/
Property* property(PropertyID id);
protected:
/**
* Returns the number of properties the interface object has.
*/
virtual uint8_t propertyCount();
virtual uint8_t propertyDescriptionCount();
/**
* Returns a pointer to the first PropertyDescription of the interface object.
* This is used by readPropertyDescription() together with propertyCount().
*/
virtual PropertyDescription* propertyDescriptions();
/**
* Intializes the Property-array the the supplied values.
*/
void initializeProperties(size_t propertiesSize, Property** properties);
Property** _properties = nullptr;
uint8_t _propertyCount = 0;
};

View File

@ -8,7 +8,13 @@
IpParameterObject::IpParameterObject(DeviceObject& deviceObject, Platform& platform): _deviceObject(deviceObject),
_platform(platform)
{}
{
Property* properties[] =
{
new DataProperty(PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0)
};
initializeProperties(sizeof(properties), properties);
}
void IpParameterObject::readProperty(PropertyID propertyId, uint16_t start, uint8_t& count, uint8_t* data)
{
@ -312,11 +318,11 @@ static PropertyDescription _propertyDescriptions[] =
{ PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 },
{ PID_PROJECT_INSTALLATION_ID, true, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv3 },
};
static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
static uint8_t _propertyDescriptionCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
uint8_t IpParameterObject::propertyCount()
uint8_t IpParameterObject::propertyDescriptionCount()
{
return _propertyCount;
return _propertyDescriptionCount;
}

View File

@ -1,6 +1,7 @@
#pragma once
#include "interface_object.h"
#include "data_property.h"
#include "device_object.h"
#include "platform.h"
@ -8,21 +9,24 @@ class IpParameterObject : public InterfaceObject
{
public:
IpParameterObject(DeviceObject& deviceObject, Platform& platform);
void readProperty(PropertyID id, uint16_t start, uint8_t& count, uint8_t* data);
void writeProperty(PropertyID id, uint16_t start, uint8_t* data, uint8_t& count);
uint8_t propertySize(PropertyID id);
ObjectType objectType() { return OT_IP_PARAMETER; }
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;
ObjectType objectType() override
{
return OT_IP_PARAMETER;
}
uint8_t* save(uint8_t* buffer);
uint8_t* restore(uint8_t* buffer);
uint16_t saveSize();
uint8_t* save(uint8_t* buffer) override;
uint8_t* restore(uint8_t* buffer) override;
uint16_t saveSize() override;
uint32_t multicastAddress() const;
uint8_t ttl() const { return _ttl; }
protected:
uint8_t propertyCount();
PropertyDescription* propertyDescriptions();
uint8_t propertyDescriptionCount() override;
PropertyDescription* propertyDescriptions() override;
private:
uint16_t _projectInstallationId = 0;
@ -46,4 +50,7 @@ class IpParameterObject : public InterfaceObject
void loadState(LoadState newState);
LoadState _state = LS_UNLOADED;
ErrorCode _errorCode = E_NO_FAULT;
Property** _properties = nullptr;
uint8_t _propertyCount = 0;
};

View File

@ -124,11 +124,11 @@ static PropertyDescription _propertyDescriptions[] =
{ PID_RF_RETRANSMITTER, false, PDT_GENERIC_01, 1, ReadLv3 | WriteLv0 },
{ PID_RF_DOMAIN_ADDRESS, true, PDT_GENERIC_06, 1, ReadLv3 | WriteLv0 }
};
static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
static uint8_t _propertyDescriptionCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
uint8_t RfMediumObject::propertyCount()
uint8_t RfMediumObject::propertyDescriptionCount()
{
return _propertyCount;
return _propertyDescriptionCount;
}
PropertyDescription* RfMediumObject::propertyDescriptions()

View File

@ -5,21 +5,20 @@
class RfMediumObject: public InterfaceObject
{
public:
void readProperty(PropertyID id, uint16_t start, uint8_t& count, uint8_t* data);
void writeProperty(PropertyID id, uint16_t start, uint8_t* data, uint8_t& count);
uint8_t propertySize(PropertyID id);
uint8_t* save(uint8_t* buffer);
uint8_t* restore(uint8_t* buffer);
uint16_t saveSize();
void readPropertyDescription(uint8_t propertyId, uint8_t& propertyIndex, bool& writeEnable, uint8_t& type, uint16_t& numberOfElements, uint8_t& access);
ObjectType objectType() { return OT_RF_MEDIUM; }
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* save(uint8_t* buffer) override;
uint8_t* restore(uint8_t* buffer) override;
uint16_t saveSize() override;
ObjectType objectType() override { return OT_RF_MEDIUM; }
uint8_t* rfDomainAddress();
void rfDomainAddress(uint8_t* value);
protected:
uint8_t propertyCount();
PropertyDescription* propertyDescriptions();
uint8_t propertyDescriptionCount() override;
PropertyDescription* propertyDescriptions() override;
private:
uint8_t _rfDomainAddress[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // see KNX RF S-Mode AN160 p.11
uint8_t _rfDiagSourceAddressFilterTable[24] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,};

View File

@ -15,7 +15,11 @@ class SaveRestore
* @return The buffer plus the size of the object state. The next object will use this value as
* the start of its buffer.
*/
virtual uint8_t* save(uint8_t* buffer) = 0;
virtual uint8_t* save(uint8_t* buffer)
{
return buffer;
}
/**
* This method is called when the object should restore its state from the buffer.
*
@ -24,9 +28,16 @@ class SaveRestore
* @return The buffer plus the size of the object state. The next object will use this value as
* the start of its buffer.
*/
virtual uint8_t* restore(uint8_t* buffer) = 0;
virtual uint8_t* restore(uint8_t* buffer)
{
return buffer;
}
/**
* @return The number of byte the object needs to save its state.
*/
virtual uint16_t saveSize() = 0;
virtual uint16_t saveSize()
{
return 0;
}
};

View File

@ -16,9 +16,9 @@ class TableObject: public InterfaceObject
* @param memory The instance of the memory management class to use.
*/
TableObject(Memory& memory);
virtual void readProperty(PropertyID id, uint16_t start, uint8_t& count, uint8_t* data);
virtual void writeProperty(PropertyID id, uint16_t start, uint8_t* data, uint8_t& count);
virtual uint8_t propertySize(PropertyID id);
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.
*/
@ -27,9 +27,9 @@ class TableObject: public InterfaceObject
* This method returns the ::LoadState of the interface object.
*/
LoadState loadState();
virtual uint8_t* save(uint8_t* buffer);
virtual uint8_t* restore(uint8_t* buffer);
uint16_t saveSize();
virtual uint8_t* save(uint8_t* buffer) override;
virtual uint8_t* restore(uint8_t* buffer) override;
uint16_t saveSize() override;
protected:
/**
* This method is called before the interface object enters a new ::LoadState.