-answer correctly on missing objects/properties

-correct length of MAX_APDU_LENGTH
-fix apci of propertyDescriptionReadResponse
This commit is contained in:
Thomas Kunze 2018-04-11 22:52:15 +02:00
parent 2a169ee66b
commit 4479bc25dc
16 changed files with 52 additions and 35 deletions

View File

@ -11,7 +11,7 @@ AddressTableObject::AddressTableObject(uint8_t* memoryReference): TableObject(me
} }
void AddressTableObject::readProperty(PropertyID id, uint32_t start, uint32_t count, uint8_t* data) void AddressTableObject::readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data)
{ {
switch (id) switch (id)
{ {

View File

@ -6,7 +6,7 @@ class AddressTableObject: public TableObject
{ {
public: public:
AddressTableObject(uint8_t* memoryReference); AddressTableObject(uint8_t* memoryReference);
void readProperty(PropertyID id, uint32_t start, uint32_t count, uint8_t* data); void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data);
uint16_t entryCount(); uint16_t entryCount();
uint16_t getGa(uint16_t tsap); uint16_t getGa(uint16_t tsap);
uint16_t getTsap(uint16_t ga); uint16_t getTsap(uint16_t ga);

View File

@ -394,7 +394,7 @@ void ApplicationLayer::propertyDescriptionReadResponse(AckType ack, Priority pri
{ {
CemiFrame frame(8); CemiFrame frame(8);
APDU& apdu = frame.apdu(); APDU& apdu = frame.apdu();
apdu.type(PropertyDescriptionRead); apdu.type(PropertyDescriptionResponse);
uint8_t* data = apdu.data(); uint8_t* data = apdu.data();
data[1] = objectIndex; data[1] = objectIndex;
data[2] = propertyId; data[2] = propertyId;

View File

@ -6,7 +6,7 @@ ApplicationProgramObject::ApplicationProgramObject(uint8_t* memoryReference): Ta
} }
void ApplicationProgramObject::readProperty(PropertyID id, uint32_t start, uint32_t count, uint8_t* data) void ApplicationProgramObject::readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data)
{ {
switch (id) switch (id)
{ {

View File

@ -6,7 +6,7 @@ class ApplicationProgramObject: public TableObject
{ {
public: public:
ApplicationProgramObject(uint8_t* memoryReference); ApplicationProgramObject(uint8_t* memoryReference);
void readProperty(PropertyID id, uint32_t start, uint32_t count, uint8_t* data); void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data);
void writeProperty(PropertyID id, uint8_t start, uint8_t* data, uint8_t count); void writeProperty(PropertyID id, uint8_t start, uint8_t* data, uint8_t count);
uint8_t propertySize(PropertyID id); uint8_t propertySize(PropertyID id);
uint8_t* data(uint32_t addr); uint8_t* data(uint32_t addr);

View File

@ -11,7 +11,7 @@ AssociationTableObject::AssociationTableObject(uint8_t* memoryReference): TableO
} }
void AssociationTableObject::readProperty(PropertyID id, uint32_t start, uint32_t count, uint8_t* data) void AssociationTableObject::readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data)
{ {
switch (id) switch (id)
{ {

View File

@ -6,7 +6,7 @@ class AssociationTableObject: public TableObject
{ {
public: public:
AssociationTableObject(uint8_t* memoryReference); AssociationTableObject(uint8_t* memoryReference);
void readProperty(PropertyID id, uint32_t start, uint32_t count, uint8_t* data); void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data);
uint16_t entryCount(); uint16_t entryCount();
uint16_t operator[](uint16_t idx); uint16_t operator[](uint16_t idx);
uint8_t* save(uint8_t* buffer); uint8_t* save(uint8_t* buffer);

View File

@ -7,7 +7,7 @@ using namespace std;
Bau57B0::Bau57B0(Platform& platform): _memoryReference((uint8_t*)&_deviceObj), _memory(platform), _addrTable(_memoryReference), Bau57B0::Bau57B0(Platform& platform): _memoryReference((uint8_t*)&_deviceObj), _memory(platform), _addrTable(_memoryReference),
_assocTable(_memoryReference), _groupObjTable(_memoryReference), _appProgram(_memoryReference), _assocTable(_memoryReference), _groupObjTable(_memoryReference), _appProgram(_memoryReference),
_ipParameters(_deviceObj, _platform), _platform(platform), _appLayer(_assocTable, *this), _ipParameters(_deviceObj, platform), _platform(platform), _appLayer(_assocTable, *this),
_transLayer(_appLayer, _addrTable, _platform), _netLayer(_transLayer), _transLayer(_appLayer, _addrTable, _platform), _netLayer(_transLayer),
_dlLayer(_deviceObj, _addrTable, _ipParameters, _netLayer, _platform) _dlLayer(_deviceObj, _addrTable, _ipParameters, _netLayer, _platform)
{ {
@ -189,20 +189,30 @@ void Bau57B0::propertyDescriptionReadIndication(Priority priority, HopCountType
void Bau57B0::propertyValueWriteIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t objectIndex, void Bau57B0::propertyValueWriteIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t objectIndex,
uint8_t propertyId, uint8_t numberOfElements, uint16_t startIndex, uint8_t* data, uint8_t length) uint8_t propertyId, uint8_t numberOfElements, uint16_t startIndex, uint8_t* data, uint8_t length)
{ {
InterfaceObject& obj = getInterfaceObject(objectIndex); InterfaceObject* obj = getInterfaceObject(objectIndex);
obj.writeProperty((PropertyID)propertyId, startIndex, data, numberOfElements); if(obj)
obj->writeProperty((PropertyID)propertyId, startIndex, data, numberOfElements);
propertyValueReadIndication(priority, hopType, asap, objectIndex, propertyId, numberOfElements, startIndex); propertyValueReadIndication(priority, hopType, asap, objectIndex, propertyId, numberOfElements, startIndex);
} }
void Bau57B0::propertyValueReadIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t objectIndex, void Bau57B0::propertyValueReadIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t objectIndex,
uint8_t propertyId, uint8_t numberOfElements, uint16_t startIndex) uint8_t propertyId, uint8_t numberOfElements, uint16_t startIndex)
{ {
InterfaceObject& obj = getInterfaceObject(objectIndex); uint8_t size = 0;
uint8_t elementSize = obj.propertySize((PropertyID)propertyId); uint32_t elementCount = numberOfElements;
uint8_t size = elementSize * numberOfElements; InterfaceObject* obj = getInterfaceObject(objectIndex);
if (obj)
{
uint8_t elementSize = obj->propertySize((PropertyID)propertyId);
size = elementSize * numberOfElements;
}
else
elementCount = 0;
uint8_t data[size]; uint8_t data[size];
obj.readProperty((PropertyID)propertyId, startIndex, numberOfElements, data); if(obj)
_appLayer.propertyValueReadResponse(AckRequested, priority, hopType, asap, objectIndex, propertyId, numberOfElements, obj->readProperty((PropertyID)propertyId, startIndex, elementCount, data);
_appLayer.propertyValueReadResponse(AckRequested, priority, hopType, asap, objectIndex, propertyId, elementCount,
startIndex, data, size); startIndex, data, size);
} }
@ -264,23 +274,25 @@ void Bau57B0::groupValueWriteIndication(uint16_t asap, Priority priority, HopCou
updateGroupObject(go, data, dataLength); updateGroupObject(go, data, dataLength);
} }
InterfaceObject& Bau57B0::getInterfaceObject(uint8_t idx) InterfaceObject* Bau57B0::getInterfaceObject(uint8_t idx)
{ {
switch (idx) switch (idx)
{ {
case 0: case 0:
return _deviceObj; return &_deviceObj;
case 1: case 1:
return _addrTable; return &_addrTable;
case 2: case 2:
return _assocTable; return &_assocTable;
case 3: case 3:
return _groupObjTable; return &_groupObjTable;
case 4: case 4:
return _appProgram; return &_appProgram;
case 5: case 5: // would be app_program 2
return _ipParameters; return nullptr;
case 6:
return &_ipParameters;
default: default:
return _deviceObj; return nullptr;
} }
} }

View File

@ -55,7 +55,7 @@ protected:
void groupValueWriteIndication(uint16_t asap, Priority priority, HopCountType hopType, void groupValueWriteIndication(uint16_t asap, Priority priority, HopCountType hopType,
uint8_t* data, uint8_t dataLength); uint8_t* data, uint8_t dataLength);
InterfaceObject& getInterfaceObject(uint8_t idx); InterfaceObject* getInterfaceObject(uint8_t idx);
void sendNextGroupTelegram(); void sendNextGroupTelegram();
void updateGroupObject(GroupObject& go, uint8_t* data, uint8_t length); void updateGroupObject(GroupObject& go, uint8_t* data, uint8_t length);
private: private:

View File

@ -2,7 +2,7 @@
#include "device_object.h" #include "device_object.h"
#include "bits.h" #include "bits.h"
void DeviceObject::readProperty(PropertyID propertyId, uint32_t start, uint32_t count, uint8_t* data) void DeviceObject::readProperty(PropertyID propertyId, uint32_t start, uint32_t& count, uint8_t* data)
{ {
switch (propertyId) switch (propertyId)
{ {
@ -35,7 +35,7 @@ void DeviceObject::readProperty(PropertyID propertyId, uint32_t start, uint32_t
*data = _prgMode; *data = _prgMode;
break; break;
case PID_MAX_APDU_LENGTH: case PID_MAX_APDU_LENGTH:
*data = 15; pushWord(15, data);
break; break;
case PID_SUBNET_ADDR: case PID_SUBNET_ADDR:
*data = ((_ownAddress >> 8) & 0xff); *data = ((_ownAddress >> 8) & 0xff);
@ -58,6 +58,8 @@ void DeviceObject::readProperty(PropertyID propertyId, uint32_t start, uint32_t
data[0] = 0x57; data[0] = 0x57;
data[1] = 0xB0; data[1] = 0xB0;
break; break;
default:
count = 0;
} }
} }
@ -85,13 +87,13 @@ uint8_t DeviceObject::propertySize(PropertyID id)
case PID_DEVICE_CONTROL: case PID_DEVICE_CONTROL:
case PID_ROUTING_COUNT: case PID_ROUTING_COUNT:
case PID_PROG_MODE: case PID_PROG_MODE:
case PID_MAX_APDU_LENGTH:
case PID_SUBNET_ADDR: case PID_SUBNET_ADDR:
case PID_DEVICE_ADDR: case PID_DEVICE_ADDR:
return 1; return 1;
case PID_MANUFACTURER_ID: case PID_MANUFACTURER_ID:
case PID_VERSION: case PID_VERSION:
case PID_DEVICE_DESCRIPTOR: case PID_DEVICE_DESCRIPTOR:
case PID_MAX_APDU_LENGTH:
return 2; return 2;
case PID_IO_LIST: case PID_IO_LIST:
return 4; return 4;

View File

@ -5,7 +5,7 @@
class DeviceObject: public InterfaceObject class DeviceObject: public InterfaceObject
{ {
public: public:
void readProperty(PropertyID id, uint32_t start, uint32_t count, uint8_t* data); void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data);
void writeProperty(PropertyID id, uint8_t start, uint8_t* data, uint8_t count); void writeProperty(PropertyID id, uint8_t start, uint8_t* data, uint8_t count);
uint8_t propertySize(PropertyID id); uint8_t propertySize(PropertyID id);
uint8_t* save(uint8_t* buffer); uint8_t* save(uint8_t* buffer);

View File

@ -10,7 +10,7 @@ GroupObjectTableObject::GroupObjectTableObject(uint8_t* memoryReference): TableO
_groupObjectCount = 0; _groupObjectCount = 0;
} }
void GroupObjectTableObject::readProperty(PropertyID id, uint32_t start, uint32_t count, uint8_t* data) void GroupObjectTableObject::readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data)
{ {
switch (id) switch (id)
{ {

View File

@ -9,7 +9,7 @@ class GroupObjectTableObject: public TableObject
public: public:
GroupObjectTableObject(uint8_t* memoryReference); GroupObjectTableObject(uint8_t* memoryReference);
void readProperty(PropertyID id, uint32_t start, uint32_t count, uint8_t* data); void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data);
uint16_t entryCount(); uint16_t entryCount();
GroupObject& get(uint16_t asap); GroupObject& get(uint16_t asap);
GroupObject& nextUpdatedObject(bool& valid); GroupObject& nextUpdatedObject(bool& valid);

View File

@ -54,7 +54,7 @@ class InterfaceObject: public SaveRestore
{ {
public: public:
virtual ~InterfaceObject() {} virtual ~InterfaceObject() {}
virtual void readProperty(PropertyID id, uint32_t start, uint32_t count, uint8_t* data) = 0; virtual void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data) = 0;
virtual void writeProperty(PropertyID id, uint8_t start, uint8_t* data, uint8_t count) = 0; virtual void writeProperty(PropertyID id, uint8_t start, uint8_t* data, uint8_t count) = 0;
virtual uint8_t propertySize(PropertyID id) = 0; virtual uint8_t propertySize(PropertyID id) = 0;
protected: protected:

View File

@ -10,7 +10,7 @@ IpParameterObject::IpParameterObject(DeviceObject& deviceObject, Platform& platf
_platform(platform) _platform(platform)
{} {}
void IpParameterObject::readProperty(PropertyID propertyId, uint32_t start, uint32_t count, uint8_t* data) void IpParameterObject::readProperty(PropertyID propertyId, uint32_t start, uint32_t& count, uint8_t* data)
{ {
switch (propertyId) switch (propertyId)
{ {
@ -52,7 +52,7 @@ void IpParameterObject::readProperty(PropertyID propertyId, uint32_t start, uint
break; break;
case PID_MAC_ADDRESS: case PID_MAC_ADDRESS:
{ {
uint8_t macAddr[6]; uint8_t macAddr[6] = { 0, 0, 0, 0, 0, 0 };
_platform.macAddress(macAddr); _platform.macAddress(macAddr);
pushByteArray(macAddr, 6, data); pushByteArray(macAddr, 6, data);
break; break;
@ -73,6 +73,9 @@ void IpParameterObject::readProperty(PropertyID propertyId, uint32_t start, uint
for (uint8_t i = start; i < start + count; i++) for (uint8_t i = start; i < start + count; i++)
data[i-start] = _friendlyName[i-1]; data[i-start] = _friendlyName[i-1];
break; break;
default:
count = 0;
break;
} }
} }

View File

@ -8,7 +8,7 @@ class IpParameterObject: public InterfaceObject
{ {
public: public:
IpParameterObject(DeviceObject& deviceObject, Platform& platform); IpParameterObject(DeviceObject& deviceObject, Platform& platform);
void readProperty(PropertyID id, uint32_t start, uint32_t count, uint8_t* data); void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data);
void writeProperty(PropertyID id, uint8_t start, uint8_t* data, uint8_t count); void writeProperty(PropertyID id, uint8_t start, uint8_t* data, uint8_t count);
uint8_t propertySize(PropertyID id); uint8_t propertySize(PropertyID id);