From 39edb63cafa6d7889873e59e58d971e1d735921f Mon Sep 17 00:00:00 2001 From: Thomas Kunze Date: Fri, 13 Apr 2018 22:08:10 +0200 Subject: [PATCH] add support for propertyDescriptionRead (descriptions are still missing) --- address_table_object.cpp | 14 +++++++++++++ address_table_object.h | 5 +++++ application_program_object.cpp | 15 ++++++++++++++ application_program_object.h | 6 ++++++ association_table_object.cpp | 14 +++++++++++++ association_table_object.h | 5 +++++ bau57B0.cpp | 11 ++++++++-- device_object.cpp | 14 +++++++++++++ device_object.h | 5 +++++ group_object_table_object.cpp | 14 +++++++++++++ group_object_table_object.h | 5 +++++ interface_object.cpp | 38 ++++++++++++++++++++++++++++++++++ interface_object.h | 4 +++- ip_parameter_object.cpp | 14 +++++++++++++ ip_parameter_object.h | 3 +++ property_types.h | 24 +++++++++++++++++++++ 16 files changed, 188 insertions(+), 3 deletions(-) create mode 100644 interface_object.cpp diff --git a/address_table_object.cpp b/address_table_object.cpp index 20ab8cf..5630faa 100644 --- a/address_table_object.cpp +++ b/address_table_object.cpp @@ -83,3 +83,17 @@ void AddressTableObject::beforeStateChange(LoadState& newState) _groupAddresses = (uint16_t*)_data; } + +static PropertyDescription _propertyDescriptions[] = { }; +static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription); + +uint8_t AddressTableObject::propertyCount() +{ + return _propertyCount; +} + + +PropertyDescription* AddressTableObject::propertyDescriptions() +{ + return _propertyDescriptions; +} \ No newline at end of file diff --git a/address_table_object.h b/address_table_object.h index dd83c89..970e438 100644 --- a/address_table_object.h +++ b/address_table_object.h @@ -6,7 +6,10 @@ class AddressTableObject: public TableObject { public: AddressTableObject(uint8_t* memoryReference); + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Woverloaded-virtual" void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data); + #pragma GCC diagnostic pop uint16_t entryCount(); uint16_t getGa(uint16_t tsap); uint16_t getTsap(uint16_t ga); @@ -15,6 +18,8 @@ public: bool contains(uint16_t addr); protected: virtual void beforeStateChange(LoadState& newState); + uint8_t propertyCount(); + PropertyDescription* propertyDescriptions(); private: uint16_t* _groupAddresses; }; \ No newline at end of file diff --git a/application_program_object.cpp b/application_program_object.cpp index d2e3787..d77b18c 100644 --- a/application_program_object.cpp +++ b/application_program_object.cpp @@ -85,3 +85,18 @@ uint8_t* ApplicationProgramObject::restore(uint8_t* buffer) return TableObject::restore(buffer); } + +static PropertyDescription _propertyDescriptions[] = {}; +static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription); + +uint8_t ApplicationProgramObject::propertyCount() +{ + return _propertyCount; +} + + +PropertyDescription* ApplicationProgramObject::propertyDescriptions() +{ + return _propertyDescriptions; +} + diff --git a/application_program_object.h b/application_program_object.h index 853f7b5..e90b13e 100644 --- a/application_program_object.h +++ b/application_program_object.h @@ -6,7 +6,10 @@ class ApplicationProgramObject: public TableObject { public: ApplicationProgramObject(uint8_t* memoryReference); + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Woverloaded-virtual" void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data); + #pragma GCC diagnostic pop void writeProperty(PropertyID id, uint8_t start, uint8_t* data, uint8_t count); uint8_t propertySize(PropertyID id); uint8_t* data(uint32_t addr); @@ -15,6 +18,9 @@ public: uint32_t getInt(uint32_t addr); uint8_t* save(uint8_t* buffer); uint8_t* restore(uint8_t* buffer); +protected: + uint8_t propertyCount(); + PropertyDescription* propertyDescriptions(); private: uint8_t _programVersion[5]; }; \ No newline at end of file diff --git a/association_table_object.cpp b/association_table_object.cpp index 27db23f..3008cab 100644 --- a/association_table_object.cpp +++ b/association_table_object.cpp @@ -66,4 +66,18 @@ void AssociationTableObject::beforeStateChange(LoadState& newState) return; _tableData = (uint16_t*)_data; +} + +static PropertyDescription _propertyDescriptions[] = { }; +static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription); + +uint8_t AssociationTableObject::propertyCount() +{ + return _propertyCount; +} + + +PropertyDescription* AssociationTableObject::propertyDescriptions() +{ + return _propertyDescriptions; } \ No newline at end of file diff --git a/association_table_object.h b/association_table_object.h index 574ba9a..23a8048 100644 --- a/association_table_object.h +++ b/association_table_object.h @@ -6,7 +6,10 @@ class AssociationTableObject: public TableObject { public: AssociationTableObject(uint8_t* memoryReference); + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Woverloaded-virtual" void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data); + #pragma GCC diagnostic pop uint16_t entryCount(); uint16_t operator[](uint16_t idx); uint8_t* save(uint8_t* buffer); @@ -15,6 +18,8 @@ public: int32_t translateAsap(uint16_t asap); protected: void beforeStateChange(LoadState& newState); + uint8_t propertyCount(); + PropertyDescription* propertyDescriptions(); private: uint16_t* _tableData; }; \ No newline at end of file diff --git a/bau57B0.cpp b/bau57B0.cpp index c436e7b..cc34d9c 100644 --- a/bau57B0.cpp +++ b/bau57B0.cpp @@ -181,9 +181,16 @@ void Bau57B0::userMemoryWriteIndication(Priority priority, HopCountType hopType, void Bau57B0::propertyDescriptionReadIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t objectIndex, uint8_t propertyId, uint8_t propertyIndex) { - // TODO: reply correctly + bool writeEnable = false; + uint8_t type = 0; + uint16_t numberOfElements = 0; + uint8_t access = 0; + InterfaceObject* obj = getInterfaceObject(objectIndex); + if (obj) + obj->readPropertyDescription(propertyId, propertyIndex, writeEnable, type, numberOfElements, access); + _appLayer.propertyDescriptionReadResponse(AckRequested, priority, hopType, asap, objectIndex, propertyId, propertyIndex, - false, 0, 0, 0); + writeEnable, type, numberOfElements, access); } void Bau57B0::propertyValueWriteIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t objectIndex, diff --git a/device_object.cpp b/device_object.cpp index 617ccce..34ea7ff 100644 --- a/device_object.cpp +++ b/device_object.cpp @@ -253,3 +253,17 @@ void DeviceObject::version(uint16_t value) { _version = value; } + +static PropertyDescription _propertyDescriptions[] = {}; +static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription); + +uint8_t DeviceObject::propertyCount() +{ + return _propertyCount; +} + + +PropertyDescription* DeviceObject::propertyDescriptions() +{ + return _propertyDescriptions; +} diff --git a/device_object.h b/device_object.h index 4daa0be..c727e54 100644 --- a/device_object.h +++ b/device_object.h @@ -10,6 +10,8 @@ public: uint8_t propertySize(PropertyID id); 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); + uint16_t induvidualAddress(); void induvidualAddress(uint16_t value); @@ -33,6 +35,9 @@ public: void hardwareType(const uint8_t* value); uint16_t version(); void version(uint16_t value); +protected: + uint8_t propertyCount(); + PropertyDescription* propertyDescriptions(); private: uint8_t _deviceControl; uint8_t _routingCount; diff --git a/group_object_table_object.cpp b/group_object_table_object.cpp index f8a7872..d41d30a 100644 --- a/group_object_table_object.cpp +++ b/group_object_table_object.cpp @@ -119,3 +119,17 @@ bool GroupObjectTableObject::initGroupObjects() return true; } + +static PropertyDescription _propertyDescriptions[] = { }; +static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription); + +uint8_t GroupObjectTableObject::propertyCount() +{ + return _propertyCount; +} + + +PropertyDescription* GroupObjectTableObject::propertyDescriptions() +{ + return _propertyDescriptions; +} \ No newline at end of file diff --git a/group_object_table_object.h b/group_object_table_object.h index 708d877..8cd3bdf 100644 --- a/group_object_table_object.h +++ b/group_object_table_object.h @@ -9,7 +9,10 @@ class GroupObjectTableObject: public TableObject public: GroupObjectTableObject(uint8_t* memoryReference); + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Woverloaded-virtual" void readProperty(PropertyID id, uint32_t start, uint32_t& count, uint8_t* data); + #pragma GCC diagnostic pop uint16_t entryCount(); GroupObject& get(uint16_t asap); GroupObject& nextUpdatedObject(bool& valid); @@ -19,6 +22,8 @@ public: virtual uint8_t* restore(uint8_t* buffer); protected: virtual void beforeStateChange(LoadState& newState); + uint8_t propertyCount(); + PropertyDescription* propertyDescriptions(); private: bool initGroupObjects(); uint16_t* _tableData = 0; diff --git a/interface_object.cpp b/interface_object.cpp new file mode 100644 index 0000000..e3db33a --- /dev/null +++ b/interface_object.cpp @@ -0,0 +1,38 @@ +#include "interface_object.h" + +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(); + + PropertyDescription* desc = nullptr; + if (propertyId != 0) + { + + for (uint8_t i = 0; i < count; i++) + { + PropertyDescription d = descriptions[propertyIndex]; + if (d.Id != propertyId) + continue; + + desc = &d; + propertyIndex = i; + break; + } + } + else + { + if (propertyIndex > 0 && propertyIndex < count) + { + desc = &descriptions[propertyIndex]; + } + } + + if (desc != nullptr) + { + writeEnable = desc->WriteEnable; + type = desc->Type; + numberOfElements = desc->MaxElements; + access = desc->Access; + } +} \ No newline at end of file diff --git a/interface_object.h b/interface_object.h index 5102641..826953f 100644 --- a/interface_object.h +++ b/interface_object.h @@ -57,6 +57,8 @@ public: 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 uint8_t propertySize(PropertyID id) = 0; + void readPropertyDescription(uint8_t propertyId, uint8_t& propertyIndex, bool& writeEnable, uint8_t& type, uint16_t& numberOfElements, uint8_t& access); protected: - + virtual uint8_t propertyCount() = 0; + virtual PropertyDescription* propertyDescriptions() = 0; }; \ No newline at end of file diff --git a/ip_parameter_object.cpp b/ip_parameter_object.cpp index fda81ce..547904d 100644 --- a/ip_parameter_object.cpp +++ b/ip_parameter_object.cpp @@ -302,4 +302,18 @@ void IpParameterObject::additionalLoadControls(uint8_t* data) loadState(LS_ERROR); _errorCode = E_INVALID_OPCODE; return; +} + +static PropertyDescription _propertyDescriptions[] = { }; +static uint8_t _propertyCount = sizeof(_propertyDescriptions) / sizeof(PropertyDescription); + +uint8_t IpParameterObject::propertyCount() +{ + return _propertyCount; +} + + +PropertyDescription* IpParameterObject::propertyDescriptions() +{ + return _propertyDescriptions; } \ No newline at end of file diff --git a/ip_parameter_object.h b/ip_parameter_object.h index 4a82429..efd272b 100644 --- a/ip_parameter_object.h +++ b/ip_parameter_object.h @@ -17,6 +17,9 @@ public: uint32_t multicastAddress() const; uint8_t ttl() const { return _ttl; } +protected: + uint8_t propertyCount(); + PropertyDescription* propertyDescriptions(); private: uint16_t _projectInstallationId = 0; uint8_t _ipAssignmentMethod = 0; diff --git a/property_types.h b/property_types.h index 6fab16a..3945828 100644 --- a/property_types.h +++ b/property_types.h @@ -9,6 +9,8 @@ */ #pragma once +#include + enum PropertyDataType { PDT_CONTROL = 0x00, //!< length: 1 read, 10 write @@ -163,4 +165,26 @@ enum ErrorCode E_INVALID_CONNECTION_NUMBER = 16, E_INVALID_GO_NUMBER = 17, E_GO_TYPE_TOO_BIG = 18 +}; + +enum AccessLevel +{ + ReadLv0 = 0x00, + ReadLv1 = 0x10, + ReadLv2 = 0x20, + ReadLv3 = 0x30, + WriteLv0 = 0x00, + WriteLv1 = 0x01, + WriteLv2 = 0x02, + WriteLv3 = 0x03, +}; + +class PropertyDescription +{ +public: + PropertyID Id; + bool WriteEnable; + PropertyDataType Type; + uint16_t MaxElements; + uint8_t Access; }; \ No newline at end of file