2018-04-09 22:30:23 +02:00
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
#include "association_table_object.h"
|
|
|
|
#include "bits.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
AssociationTableObject::AssociationTableObject(uint8_t* memoryReference): TableObject(memoryReference)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-04-11 22:52:15 +02:00
|
|
|
void AssociationTableObject::readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data)
|
2018-04-09 22:30:23 +02:00
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case PID_OBJECT_TYPE:
|
|
|
|
pushWord(OT_ASSOC_TABLE, data);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
TableObject::readProperty(id, start, count, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t AssociationTableObject::entryCount()
|
|
|
|
{
|
|
|
|
return ntohs(_tableData[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t AssociationTableObject::operator[](uint16_t idx)
|
|
|
|
{
|
|
|
|
if (idx < 0 || idx >= entryCount())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return ntohs(_tableData[idx + 1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t* AssociationTableObject::save(uint8_t* buffer)
|
|
|
|
{
|
|
|
|
return TableObject::save(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t* AssociationTableObject::restore(uint8_t* buffer)
|
|
|
|
{
|
|
|
|
buffer = TableObject::restore(buffer);
|
|
|
|
_tableData = (uint16_t*)_data;
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t AssociationTableObject::translateAsap(uint16_t asap)
|
|
|
|
{
|
|
|
|
uint16_t entries = entryCount();
|
|
|
|
for (uint16_t i = 0; i < entries; i++)
|
|
|
|
{
|
|
|
|
uint16_t entry = ntohs(operator[](i));
|
|
|
|
if (lowByte(entry) == asap)
|
|
|
|
return highByte(entry);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AssociationTableObject::beforeStateChange(LoadState& newState)
|
|
|
|
{
|
|
|
|
if (newState != LS_LOADED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_tableData = (uint16_t*)_data;
|
2018-04-13 22:08:10 +02:00
|
|
|
}
|
|
|
|
|
2018-04-25 23:20:00 +02:00
|
|
|
static PropertyDescription _propertyDescriptions[] =
|
|
|
|
{
|
|
|
|
{ PID_OBJECT_TYPE, false, PDT_UNSIGNED_INT, 1, ReadLv3 | WriteLv0 },
|
|
|
|
{ PID_TABLE, false, PDT_GENERIC_02, 254, ReadLv3 | WriteLv0 }
|
2018-04-21 21:38:12 +02:00
|
|
|
};
|
2018-04-13 22:08:10 +02:00
|
|
|
static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription);
|
|
|
|
|
|
|
|
uint8_t AssociationTableObject::propertyCount()
|
|
|
|
{
|
|
|
|
return _propertyCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PropertyDescription* AssociationTableObject::propertyDescriptions()
|
|
|
|
{
|
|
|
|
return _propertyDescriptions;
|
2018-04-09 22:30:23 +02:00
|
|
|
}
|