diff --git a/address_table_object.cpp b/address_table_object.cpp index 9420704..20ab8cf 100644 --- a/address_table_object.cpp +++ b/address_table_object.cpp @@ -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) { diff --git a/address_table_object.h b/address_table_object.h index 3786295..dd83c89 100644 --- a/address_table_object.h +++ b/address_table_object.h @@ -6,7 +6,7 @@ class AddressTableObject: public TableObject { public: 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 getGa(uint16_t tsap); uint16_t getTsap(uint16_t ga); diff --git a/application_layer.cpp b/application_layer.cpp index 3cc3c8e..4ea0452 100644 --- a/application_layer.cpp +++ b/application_layer.cpp @@ -394,7 +394,7 @@ void ApplicationLayer::propertyDescriptionReadResponse(AckType ack, Priority pri { CemiFrame frame(8); APDU& apdu = frame.apdu(); - apdu.type(PropertyDescriptionRead); + apdu.type(PropertyDescriptionResponse); uint8_t* data = apdu.data(); data[1] = objectIndex; data[2] = propertyId; diff --git a/application_program_object.cpp b/application_program_object.cpp index 6050e40..d2e3787 100644 --- a/application_program_object.cpp +++ b/application_program_object.cpp @@ -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) { diff --git a/application_program_object.h b/application_program_object.h index 27cb694..853f7b5 100644 --- a/application_program_object.h +++ b/application_program_object.h @@ -6,7 +6,7 @@ class ApplicationProgramObject: public TableObject { public: 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); uint8_t propertySize(PropertyID id); uint8_t* data(uint32_t addr); diff --git a/association_table_object.cpp b/association_table_object.cpp index 92429d4..27db23f 100644 --- a/association_table_object.cpp +++ b/association_table_object.cpp @@ -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) { diff --git a/association_table_object.h b/association_table_object.h index 7377ab1..574ba9a 100644 --- a/association_table_object.h +++ b/association_table_object.h @@ -6,7 +6,7 @@ class AssociationTableObject: public TableObject { public: 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 operator[](uint16_t idx); uint8_t* save(uint8_t* buffer); diff --git a/bau57B0.cpp b/bau57B0.cpp index c2b954f..c436e7b 100644 --- a/bau57B0.cpp +++ b/bau57B0.cpp @@ -7,7 +7,7 @@ using namespace std; Bau57B0::Bau57B0(Platform& platform): _memoryReference((uint8_t*)&_deviceObj), _memory(platform), _addrTable(_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), _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, uint8_t propertyId, uint8_t numberOfElements, uint16_t startIndex, uint8_t* data, uint8_t length) { - InterfaceObject& obj = getInterfaceObject(objectIndex); - obj.writeProperty((PropertyID)propertyId, startIndex, data, numberOfElements); + InterfaceObject* obj = getInterfaceObject(objectIndex); + if(obj) + obj->writeProperty((PropertyID)propertyId, startIndex, data, numberOfElements); propertyValueReadIndication(priority, hopType, asap, objectIndex, propertyId, numberOfElements, startIndex); } void Bau57B0::propertyValueReadIndication(Priority priority, HopCountType hopType, uint16_t asap, uint8_t objectIndex, uint8_t propertyId, uint8_t numberOfElements, uint16_t startIndex) { - InterfaceObject& obj = getInterfaceObject(objectIndex); - uint8_t elementSize = obj.propertySize((PropertyID)propertyId); - uint8_t size = elementSize * numberOfElements; + uint8_t size = 0; + uint32_t elementCount = numberOfElements; + InterfaceObject* obj = getInterfaceObject(objectIndex); + if (obj) + { + uint8_t elementSize = obj->propertySize((PropertyID)propertyId); + size = elementSize * numberOfElements; + } + else + elementCount = 0; + uint8_t data[size]; - obj.readProperty((PropertyID)propertyId, startIndex, numberOfElements, data); - _appLayer.propertyValueReadResponse(AckRequested, priority, hopType, asap, objectIndex, propertyId, numberOfElements, + if(obj) + obj->readProperty((PropertyID)propertyId, startIndex, elementCount, data); + _appLayer.propertyValueReadResponse(AckRequested, priority, hopType, asap, objectIndex, propertyId, elementCount, startIndex, data, size); } @@ -264,23 +274,25 @@ void Bau57B0::groupValueWriteIndication(uint16_t asap, Priority priority, HopCou updateGroupObject(go, data, dataLength); } -InterfaceObject& Bau57B0::getInterfaceObject(uint8_t idx) +InterfaceObject* Bau57B0::getInterfaceObject(uint8_t idx) { switch (idx) { case 0: - return _deviceObj; + return &_deviceObj; case 1: - return _addrTable; + return &_addrTable; case 2: - return _assocTable; + return &_assocTable; case 3: - return _groupObjTable; + return &_groupObjTable; case 4: - return _appProgram; - case 5: - return _ipParameters; + return &_appProgram; + case 5: // would be app_program 2 + return nullptr; + case 6: + return &_ipParameters; default: - return _deviceObj; + return nullptr; } } \ No newline at end of file diff --git a/bau57B0.h b/bau57B0.h index 4462d14..9fd39ad 100644 --- a/bau57B0.h +++ b/bau57B0.h @@ -55,7 +55,7 @@ protected: void groupValueWriteIndication(uint16_t asap, Priority priority, HopCountType hopType, uint8_t* data, uint8_t dataLength); - InterfaceObject& getInterfaceObject(uint8_t idx); + InterfaceObject* getInterfaceObject(uint8_t idx); void sendNextGroupTelegram(); void updateGroupObject(GroupObject& go, uint8_t* data, uint8_t length); private: diff --git a/device_object.cpp b/device_object.cpp index 2a1a97a..617ccce 100644 --- a/device_object.cpp +++ b/device_object.cpp @@ -2,7 +2,7 @@ #include "device_object.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) { @@ -35,7 +35,7 @@ void DeviceObject::readProperty(PropertyID propertyId, uint32_t start, uint32_t *data = _prgMode; break; case PID_MAX_APDU_LENGTH: - *data = 15; + pushWord(15, data); break; case PID_SUBNET_ADDR: *data = ((_ownAddress >> 8) & 0xff); @@ -58,6 +58,8 @@ void DeviceObject::readProperty(PropertyID propertyId, uint32_t start, uint32_t data[0] = 0x57; data[1] = 0xB0; break; + default: + count = 0; } } @@ -85,13 +87,13 @@ uint8_t DeviceObject::propertySize(PropertyID id) case PID_DEVICE_CONTROL: case PID_ROUTING_COUNT: case PID_PROG_MODE: - case PID_MAX_APDU_LENGTH: case PID_SUBNET_ADDR: case PID_DEVICE_ADDR: return 1; case PID_MANUFACTURER_ID: case PID_VERSION: case PID_DEVICE_DESCRIPTOR: + case PID_MAX_APDU_LENGTH: return 2; case PID_IO_LIST: return 4; diff --git a/device_object.h b/device_object.h index c9d5180..4daa0be 100644 --- a/device_object.h +++ b/device_object.h @@ -5,7 +5,7 @@ class DeviceObject: public InterfaceObject { 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); uint8_t propertySize(PropertyID id); uint8_t* save(uint8_t* buffer); diff --git a/group_object_table_object.cpp b/group_object_table_object.cpp index 4dbf366..f8a7872 100644 --- a/group_object_table_object.cpp +++ b/group_object_table_object.cpp @@ -10,7 +10,7 @@ GroupObjectTableObject::GroupObjectTableObject(uint8_t* memoryReference): TableO _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) { diff --git a/group_object_table_object.h b/group_object_table_object.h index 4677ca1..708d877 100644 --- a/group_object_table_object.h +++ b/group_object_table_object.h @@ -9,7 +9,7 @@ class GroupObjectTableObject: public TableObject public: 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(); GroupObject& get(uint16_t asap); GroupObject& nextUpdatedObject(bool& valid); diff --git a/interface_object.h b/interface_object.h index dfa6b6e..5102641 100644 --- a/interface_object.h +++ b/interface_object.h @@ -54,7 +54,7 @@ class InterfaceObject: public SaveRestore { public: 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 uint8_t propertySize(PropertyID id) = 0; protected: diff --git a/ip_parameter_object.cpp b/ip_parameter_object.cpp index e6e0dce..fda81ce 100644 --- a/ip_parameter_object.cpp +++ b/ip_parameter_object.cpp @@ -10,7 +10,7 @@ IpParameterObject::IpParameterObject(DeviceObject& deviceObject, Platform& platf _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) { @@ -52,7 +52,7 @@ void IpParameterObject::readProperty(PropertyID propertyId, uint32_t start, uint break; case PID_MAC_ADDRESS: { - uint8_t macAddr[6]; + uint8_t macAddr[6] = { 0, 0, 0, 0, 0, 0 }; _platform.macAddress(macAddr); pushByteArray(macAddr, 6, data); break; @@ -73,6 +73,9 @@ void IpParameterObject::readProperty(PropertyID propertyId, uint32_t start, uint for (uint8_t i = start; i < start + count; i++) data[i-start] = _friendlyName[i-1]; break; + default: + count = 0; + break; } } diff --git a/ip_parameter_object.h b/ip_parameter_object.h index 29b51bd..4a82429 100644 --- a/ip_parameter_object.h +++ b/ip_parameter_object.h @@ -8,7 +8,7 @@ class IpParameterObject: public InterfaceObject { public: 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); uint8_t propertySize(PropertyID id);