You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2021/03/04 08:46:31 UTC

[plc4x] branch develop updated: - Made the driver replace the "field" in case of a subscription event to replace the original field, which can contain patterns, with a concrete version with no patterns. So we can know where an event came from.

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new b47a1b9  - Made the driver replace the "field" in case of a subscription event to replace the original field, which can contain patterns, with a concrete version with no patterns. So we can know where an event came from.
b47a1b9 is described below

commit b47a1b9fff1840ec73287b702917e6a7e95a4cf0
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Thu Mar 4 09:46:21 2021 +0100

    - Made the driver replace the "field" in case of a subscription event to replace the original field, which can contain patterns, with a concrete version with no patterns. So we can know where an event came from.
---
 .../internal/plc4go/knxnetip/KnxNetIpSubscriber.go | 31 +++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/plc4go/internal/plc4go/knxnetip/KnxNetIpSubscriber.go b/plc4go/internal/plc4go/knxnetip/KnxNetIpSubscriber.go
index 2b39375..5c9831e 100644
--- a/plc4go/internal/plc4go/knxnetip/KnxNetIpSubscriber.go
+++ b/plc4go/internal/plc4go/knxnetip/KnxNetIpSubscriber.go
@@ -26,6 +26,7 @@ import (
 	values2 "github.com/apache/plc4x/plc4go/internal/plc4go/spi/values"
 	apiModel "github.com/apache/plc4x/plc4go/pkg/plc4go/model"
 	"github.com/apache/plc4x/plc4go/pkg/plc4go/values"
+	"strconv"
 	"time"
 )
 
@@ -128,7 +129,8 @@ func (m *KnxNetIpSubscriber) handleValueChange(destinationAddress []int8, payloa
 							numElements = uint16(rb.GetTotalBytes()) - rb.GetPos()
 						}
 
-						fields[fieldName] = field
+						// Replace the potentially patten-field with a concrete version.
+						fields[fieldName] = m.getFieldFromGroupAddress(groupAddress, groupAddressField.GetFieldType())
 						types[fieldName] = subscriptionRequest.GetType(fieldName)
 						intervals[fieldName] = subscriptionRequest.GetInterval(fieldName)
 						addresses[fieldName] = destinationAddress
@@ -170,3 +172,30 @@ func (m *KnxNetIpSubscriber) handleValueChange(destinationAddress []int8, payloa
 		}
 	}
 }
+
+func (m *KnxNetIpSubscriber) getFieldFromGroupAddress(groupAddress *driverModel.KnxGroupAddress, fieldType *driverModel.KnxDatapointType) apiModel.PlcField {
+	if groupAddress == nil {
+		return nil
+	}
+	switch groupAddress.Child.(type) {
+	case *driverModel.KnxGroupAddress3Level:
+		groupAddress3Level := groupAddress.Child.(*driverModel.KnxGroupAddress3Level)
+		return NewKnxNetIpGroupAddress3LevelPlcField(
+			strconv.Itoa(int(groupAddress3Level.MainGroup)),
+			strconv.Itoa(int(groupAddress3Level.MiddleGroup)),
+			strconv.Itoa(int(groupAddress3Level.SubGroup)),
+			fieldType)
+	case *driverModel.KnxGroupAddress2Level:
+		groupAddress2Level := groupAddress.Child.(*driverModel.KnxGroupAddress2Level)
+		return NewKnxNetIpGroupAddress2LevelPlcField(
+			strconv.Itoa(int(groupAddress2Level.MainGroup)),
+			strconv.Itoa(int(groupAddress2Level.SubGroup)),
+			fieldType)
+	case *driverModel.KnxGroupAddressFreeLevel:
+		groupAddress1Level := groupAddress.Child.(*driverModel.KnxGroupAddressFreeLevel)
+		return NewKnxNetIpGroupAddress1LevelPlcField(
+			strconv.Itoa(int(groupAddress1Level.SubGroup)),
+			fieldType)
+	}
+	return nil
+}