refactor cemi server object

This commit is contained in:
Thomas Kunze 2019-12-28 10:56:33 +01:00
parent 1465cb558c
commit 82f463f965
2 changed files with 21 additions and 105 deletions

View File

@ -4,103 +4,30 @@
#include <cstring>
#include "cemi_server_object.h"
#include "bits.h"
#include "data_property.h"
void CemiServerObject::readProperty(PropertyID propertyId, uint16_t start, uint8_t& count, uint8_t* data)
CemiServerObject::CemiServerObject()
{
switch (propertyId)
{
case PID_OBJECT_TYPE:
pushWord(OT_CEMI_SERVER, data);
break;
case PID_MEDIUM_TYPE: // PDT_BITSET16
#if MEDIUM_TYPE==0
pushWord(2, data); // TP1 supported
#elif MEDIUM_TYPE==2
pushWord(16, data); // RF supported
#elif MEDIUM_TYPE==5
pushWord(32, data); // IP supported
uint16_t mediumType = 0;
#if MEDIUM_TYPE == 0
mediumType = 2; // TP1 supported
#elif MEDIUM_TYPE == 2
mediumType = 16; // RF supported
#elif MEDIUM_TYPE == 5
mediumType = 32; // IP supported
#endif
break;
case PID_COMM_MODE: // PDT_ENUM8
// See KNX spec. cEMI 3/6/3 p.110
data[0] = 0x00; // Only Data Link Layer mode supported and we do not allow switching (read-only)
break;
case PID_COMM_MODES_SUPPORTED:
data[0] = 0x00;
data[1] = 0x01;
break;
case PID_MEDIUM_AVAILABILITY: // PDT_BITSET16
#if MEDIUM_TYPE==0
pushWord(2, data); // TP1 active
#elif MEDIUM_TYPE==2
pushWord(16, data); // RF active
#elif MEDIUM_TYPE==5
pushWord(32, data); // IP active
#endif
break;
case PID_ADD_INFO_TYPES: // PDT_ENUM8[]
pushByteArray((uint8_t*)_addInfoTypesTable, sizeof(_addInfoTypesTable), data);
break;
// Not supported yet
break;
default:
count = 0;
}
}
void CemiServerObject::writeProperty(PropertyID id, uint16_t start, uint8_t* data, uint8_t& count)
{
switch (id)
Property* properties[] =
{
case PID_COMM_MODE:
//_commMode = data[0]; // TODO: only Data Link Layer supported for now
// Property is also marked as read-only, normally it is read/write.
break;
default:
count = 0;
break;
}
new DataProperty( PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0, (uint16_t)OT_CEMI_SERVER ),
new DataProperty( PID_MEDIUM_TYPE, false, PDT_BITSET16, 1, ReadLv3 | WriteLv0, mediumType),
new DataProperty( PID_COMM_MODE, false, PDT_ENUM8, 1, ReadLv3 | WriteLv0, (uint16_t)0),
new DataProperty( PID_COMM_MODES_SUPPORTED, false, PDT_BITSET16, 1, ReadLv3 | WriteLv0, (uint16_t)0x100),
new DataProperty( PID_MEDIUM_AVAILABILITY, false, PDT_BITSET16, 1, ReadLv3 | WriteLv0, mediumType),
// cEMI additional info types supported by this cEMI server: only 0x02 (RF Control Octet and Serial Number or DoA)
new DataProperty( PID_ADD_INFO_TYPES, false, PDT_ENUM8, 1, ReadLv3 | WriteLv0, (uint8_t)0x02)
};
initializeProperties(sizeof(properties), properties);
}
uint8_t CemiServerObject::propertySize(PropertyID id)
{
switch (id)
{
case PID_COMM_MODE:
return 1;
case PID_OBJECT_TYPE:
case PID_MEDIUM_TYPE:
case PID_MEDIUM_AVAILABILITY:
case PID_COMM_MODES_SUPPORTED:
return 2;
case PID_ADD_INFO_TYPES:
return sizeof(_addInfoTypesTable);
default:
break;
}
return 0;
}
static PropertyDescription _propertyDescriptions[] =
{
{ PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 },
{ PID_MEDIUM_TYPE, false, PDT_BITSET16, 1, ReadLv3 | WriteLv0 },
{ PID_COMM_MODE, false, PDT_ENUM8, 1, ReadLv3 | WriteLv0 },
{ PID_COMM_MODES_SUPPORTED, false, PDT_BITSET16, 1, ReadLv3 | WriteLv0 },
{ PID_MEDIUM_AVAILABILITY, false, PDT_BITSET16, 1, ReadLv3 | WriteLv0 },
{ PID_ADD_INFO_TYPES, false, PDT_ENUM8, 1, ReadLv3 | WriteLv0 }
};
static uint8_t _propertyDescriptionCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
uint8_t CemiServerObject::propertyDescriptionCount()
{
return _propertyDescriptionCount;
}
PropertyDescription* CemiServerObject::propertyDescriptions()
{
return _propertyDescriptions;
}
#endif

View File

@ -8,17 +8,6 @@
class CemiServerObject: public InterfaceObject
{
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;
protected:
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 };
uint8_t _commMode = 0x00;
CemiServerObject();
};
#endif