You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2022/09/08 17:30:19 UTC
[plc4x] branch develop updated: fix(plc4go/cbus): fixed field addresses
This is an automated email from the ASF dual-hosted git repository.
sruehl 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 f409645fe fix(plc4go/cbus): fixed field addresses
f409645fe is described below
commit f409645fefacd7e25f5f3a71e6e2cff369085c56
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Sep 8 19:30:13 2022 +0200
fix(plc4go/cbus): fixed field addresses
---
plc4go/internal/cbus/Field.go | 75 +++++++++++++++++++++++-------------
plc4go/internal/cbus/FieldHandler.go | 20 +++++++---
plc4go/internal/cbus/Subscriber.go | 4 +-
3 files changed, 64 insertions(+), 35 deletions(-)
diff --git a/plc4go/internal/cbus/Field.go b/plc4go/internal/cbus/Field.go
index 84f32cb55..a2cd08a4b 100644
--- a/plc4go/internal/cbus/Field.go
+++ b/plc4go/internal/cbus/Field.go
@@ -136,11 +136,11 @@ func NewSALField(application readWriteModel.ApplicationIdContainer, salCommand s
// SALMonitorField can be used to monitor sal fields
type SALMonitorField interface {
model.PlcField
- GetUnitAddress() readWriteModel.UnitAddress
+ GetUnitAddress() *readWriteModel.UnitAddress
GetApplication() *readWriteModel.ApplicationIdContainer
}
-func NewSALMonitorField(unitAddress readWriteModel.UnitAddress, application *readWriteModel.ApplicationIdContainer, numElements uint16) SALMonitorField {
+func NewSALMonitorField(unitAddress *readWriteModel.UnitAddress, application *readWriteModel.ApplicationIdContainer, numElements uint16) SALMonitorField {
return &salMonitorField{
fieldType: SAL_MONITOR,
unitAddress: unitAddress,
@@ -152,12 +152,11 @@ func NewSALMonitorField(unitAddress readWriteModel.UnitAddress, application *rea
// MMIMonitorField can be used to monitor mmi fields
type MMIMonitorField interface {
model.PlcField
- CalField
- GetUnitAddress() readWriteModel.UnitAddress
+ GetUnitAddress() *readWriteModel.UnitAddress
GetApplication() *readWriteModel.ApplicationIdContainer
}
-func NewMMIMonitorField(unitAddress readWriteModel.UnitAddress, application *readWriteModel.ApplicationIdContainer, numElements uint16) SALMonitorField {
+func NewMMIMonitorField(unitAddress *readWriteModel.UnitAddress, application *readWriteModel.ApplicationIdContainer, numElements uint16) SALMonitorField {
return &mmiMonitorField{
fieldType: MMI_STATUS_MONITOR,
unitAddress: unitAddress,
@@ -231,14 +230,14 @@ type salField struct {
}
type salMonitorField struct {
fieldType FieldType
- unitAddress readWriteModel.UnitAddress
+ unitAddress *readWriteModel.UnitAddress
application *readWriteModel.ApplicationIdContainer
numElements uint16
}
type mmiMonitorField struct {
fieldType FieldType
- unitAddress readWriteModel.UnitAddress
+ unitAddress *readWriteModel.UnitAddress
application *readWriteModel.ApplicationIdContainer
numElements uint16
}
@@ -257,8 +256,15 @@ type unitInfoField struct {
///////////////////////////////////////
func (m statusField) GetAddressString() string {
- // TODO: this is nonsense... fix that
- return fmt.Sprintf("%d[%d]", m.fieldType, m.numElements)
+ statusRequestType := ""
+ switch m.statusRequestType {
+ case StatusRequestTypeBinaryState:
+ statusRequestType = "binary"
+ case StatusRequestTypeLevel:
+ statusRequestType = "level"
+ statusRequestType += fmt.Sprintf("=0x%x", *m.startingGroupAddressLabel)
+ }
+ return fmt.Sprintf("status/%s/%s", statusRequestType, m.application)
}
func (m statusField) GetStatusRequestType() StatusRequestType {
@@ -329,8 +335,7 @@ func (c calRecallField) GetCount() uint8 {
}
func (c calRecallField) GetAddressString() string {
- // TODO: this is nonsense... fix that
- return fmt.Sprintf("%d[%d]", c.fieldType, c.numElements)
+ return fmt.Sprintf("cal/%d/recall=%s", c.unitAddress.GetAddress(), c.parameter)
}
func (c calRecallField) GetTypeName() string {
@@ -424,8 +429,7 @@ func (c calGetstatusField) GetCount() uint8 {
}
func (c calGetstatusField) GetAddressString() string {
- // TODO: this is nonsense... fix that
- return fmt.Sprintf("%d[%d]", c.fieldType, c.numElements)
+ return fmt.Sprintf("cal/getstatus=%s, %d", c.parameter, c.GetCount())
}
func (c calGetstatusField) GetTypeName() string {
@@ -515,8 +519,15 @@ func (s salField) String() string {
}
func (s salMonitorField) GetAddressString() string {
- // TODO: this is nonsense... fix that
- return fmt.Sprintf("%d/%s%s[%d]", s.fieldType, s.unitAddress, s.application, s.numElements)
+ unitAddress := "*"
+ if s.unitAddress != nil {
+ unitAddress = fmt.Sprintf("%d", (*s.unitAddress).GetAddress())
+ }
+ application := "*"
+ if s.application != nil {
+ application = fmt.Sprintf("%d", *s.application)
+ }
+ return fmt.Sprintf("salmonitor/%s/%s", unitAddress, application)
}
func (s salMonitorField) GetTypeName() string {
@@ -527,7 +538,7 @@ func (s salMonitorField) GetQuantity() uint16 {
return s.numElements
}
-func (s salMonitorField) GetUnitAddress() readWriteModel.UnitAddress {
+func (s salMonitorField) GetUnitAddress() *readWriteModel.UnitAddress {
return s.unitAddress
}
@@ -541,13 +552,14 @@ func (s salMonitorField) Serialize(writeBuffer utils.WriteBuffer) error {
}
if unitAddress := s.unitAddress; unitAddress != nil {
- if err := unitAddress.Serialize(writeBuffer); err != nil {
+ if err := (*unitAddress).Serialize(writeBuffer); err != nil {
return err
}
}
-
- if err := s.application.Serialize(writeBuffer); err != nil {
- return err
+ if application := s.application; application != nil {
+ if err := application.Serialize(writeBuffer); err != nil {
+ return err
+ }
}
if err := writeBuffer.PopContext(s.fieldType.GetName()); err != nil {
@@ -565,8 +577,15 @@ func (s salMonitorField) String() string {
}
func (m mmiMonitorField) GetAddressString() string {
- // TODO: this is nonsense... fix that
- return fmt.Sprintf("%d/%s%s[%d]", m.fieldType, m.unitAddress, m.application, m.numElements)
+ unitAddress := "*"
+ if m.unitAddress != nil {
+ unitAddress = fmt.Sprintf("%d", (*m.unitAddress).GetAddress())
+ }
+ application := "*"
+ if m.application != nil {
+ application = fmt.Sprintf("%d", *m.application)
+ }
+ return fmt.Sprintf("mmimonitor/%s/%s", unitAddress, application)
}
func (m mmiMonitorField) GetTypeName() string {
@@ -577,7 +596,7 @@ func (m mmiMonitorField) GetQuantity() uint16 {
return m.numElements
}
-func (m mmiMonitorField) GetUnitAddress() readWriteModel.UnitAddress {
+func (m mmiMonitorField) GetUnitAddress() *readWriteModel.UnitAddress {
return m.unitAddress
}
@@ -591,12 +610,14 @@ func (m mmiMonitorField) Serialize(writeBuffer utils.WriteBuffer) error {
}
if unitAddress := m.unitAddress; unitAddress != nil {
- if err := unitAddress.Serialize(writeBuffer); err != nil {
+ if err := (*unitAddress).Serialize(writeBuffer); err != nil {
return err
}
}
- if err := m.application.Serialize(writeBuffer); err != nil {
- return err
+ if application := m.application; application != nil {
+ if err := application.Serialize(writeBuffer); err != nil {
+ return err
+ }
}
if err := writeBuffer.PopContext(m.fieldType.GetName()); err != nil {
@@ -624,7 +645,7 @@ func (u unitInfoField) GetAttribute() *readWriteModel.Attribute {
func (u unitInfoField) GetAddressString() string {
unitAddressString := "*"
if u.unitAddress != nil {
- unitAddressString = fmt.Sprintf("%d", *u.unitAddress)
+ unitAddressString = fmt.Sprintf("%d", (*u.unitAddress).GetAddress())
}
attributeString := "*"
if u.attribute != nil {
diff --git a/plc4go/internal/cbus/FieldHandler.go b/plc4go/internal/cbus/FieldHandler.go
index 4ba91ea90..7480d3cfe 100644
--- a/plc4go/internal/cbus/FieldHandler.go
+++ b/plc4go/internal/cbus/FieldHandler.go
@@ -304,7 +304,7 @@ func (m FieldHandler) handleSALPattern(match map[string]string) (model.PlcField,
}
func (m FieldHandler) handleSALMonitorPattern(match map[string]string) (model.PlcField, error) {
- var unitAddress readWriteModel.UnitAddress
+ var unitAddress *readWriteModel.UnitAddress
{
unitAddressArgument := match["unitAddress"]
if unitAddressArgument == "*" {
@@ -317,13 +317,17 @@ func (m FieldHandler) handleSALMonitorPattern(match map[string]string) (model.Pl
if len(decodedHex) != 1 {
return nil, errors.Errorf("Hex must be exatly one byte")
}
- unitAddress = readWriteModel.NewUnitAddress(decodedHex[0])
+ var unitAddressVar readWriteModel.UnitAddress
+ unitAddressVar = readWriteModel.NewUnitAddress(decodedHex[0])
+ unitAddress = &unitAddressVar
} else {
atoi, err := strconv.ParseUint(unitAddressArgument, 10, 8)
if err != nil {
return nil, errors.Errorf("Unknown unit address %s", unitAddressArgument)
}
- unitAddress = readWriteModel.NewUnitAddress(byte(atoi))
+ var unitAddressVar readWriteModel.UnitAddress
+ unitAddressVar = readWriteModel.NewUnitAddress(byte(atoi))
+ unitAddress = &unitAddressVar
}
}
@@ -345,7 +349,7 @@ func (m FieldHandler) handleSALMonitorPattern(match map[string]string) (model.Pl
}
func (m FieldHandler) handleMMIMonitorPattern(match map[string]string) (model.PlcField, error) {
- var unitAddress readWriteModel.UnitAddress
+ var unitAddress *readWriteModel.UnitAddress
{
unitAddressArgument := match["unitAddress"]
if unitAddressArgument == "*" {
@@ -358,13 +362,17 @@ func (m FieldHandler) handleMMIMonitorPattern(match map[string]string) (model.Pl
if len(decodedHex) != 1 {
return nil, errors.Errorf("Hex must be exatly one byte")
}
- unitAddress = readWriteModel.NewUnitAddress(decodedHex[0])
+ var unitAddressVar readWriteModel.UnitAddress
+ unitAddressVar = readWriteModel.NewUnitAddress(decodedHex[0])
+ unitAddress = &unitAddressVar
} else {
atoi, err := strconv.ParseUint(unitAddressArgument, 10, 8)
if err != nil {
return nil, errors.Errorf("Unknown unit address %s", unitAddressArgument)
}
- unitAddress = readWriteModel.NewUnitAddress(byte(atoi))
+ var unitAddressVar readWriteModel.UnitAddress
+ unitAddressVar = readWriteModel.NewUnitAddress(byte(atoi))
+ unitAddress = &unitAddressVar
}
}
diff --git a/plc4go/internal/cbus/Subscriber.go b/plc4go/internal/cbus/Subscriber.go
index e5c1056b7..3f64dcbb4 100644
--- a/plc4go/internal/cbus/Subscriber.go
+++ b/plc4go/internal/cbus/Subscriber.go
@@ -116,7 +116,7 @@ func (m *Subscriber) handleMonitoredMMI(calReply readWriteModel.CALReply) bool {
fieldName := subscriptionHandle.fieldName
if unitAddress := field.GetUnitAddress(); unitAddress != nil {
- unitSuffix := fmt.Sprintf("u%d", unitAddress.GetAddress())
+ unitSuffix := fmt.Sprintf("u%d", (*unitAddress).GetAddress())
if !strings.HasSuffix(unitAddressString, unitSuffix) {
log.Debug().Msgf("Current address string %s has not the suffix %s", unitAddressString, unitSuffix)
continue
@@ -274,7 +274,7 @@ func (m *Subscriber) handleMonitoredSal(sal readWriteModel.MonitoredSAL) bool {
salData = sal.GetSalData()
}
if unitAddress := field.GetUnitAddress(); unitAddress != nil {
- unitSuffix := fmt.Sprintf("u%d", unitAddress.GetAddress())
+ unitSuffix := fmt.Sprintf("u%d", (*unitAddress).GetAddress())
if !strings.HasSuffix(unitAddressString, unitSuffix) {
log.Debug().Msgf("Current address string %s has not the suffix %s", unitAddressString, unitSuffix)
continue