Skip to content

Commit

Permalink
feat(plc4go/cbus): expose bridge addressing in tags
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Mar 27, 2023
1 parent c045c60 commit 65414b2
Show file tree
Hide file tree
Showing 4 changed files with 709 additions and 107 deletions.
4 changes: 2 additions & 2 deletions plc4go/internal/cbus/Subscriber.go
Expand Up @@ -117,7 +117,7 @@ func (m *Subscriber) handleMonitoredMMI(calReply readWriteModel.CALReply) bool {
tagName := subscriptionHandle.tagName

if unitAddress := tag.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
Expand Down Expand Up @@ -275,7 +275,7 @@ func (m *Subscriber) handleMonitoredSal(sal readWriteModel.MonitoredSAL) bool {
salData = sal.GetSalData()
}
if unitAddress := tag.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
Expand Down
118 changes: 59 additions & 59 deletions plc4go/internal/cbus/Tag.go
Expand Up @@ -24,10 +24,10 @@ import (
"encoding/binary"
"fmt"

"github.com/apache/plc4x/plc4go/pkg/api/model"
"github.com/apache/plc4x/plc4go/pkg/api/values"
apiModel "github.com/apache/plc4x/plc4go/pkg/api/model"
apiValues "github.com/apache/plc4x/plc4go/pkg/api/values"
readWriteModel "github.com/apache/plc4x/plc4go/protocols/cbus/readwrite/model"
model2 "github.com/apache/plc4x/plc4go/spi/model"
spiModel "github.com/apache/plc4x/plc4go/spi/model"
"github.com/apache/plc4x/plc4go/spi/utils"
)

Expand All @@ -49,7 +49,7 @@ func (s StatusRequestType) String() string {
}

type Tag interface {
model.PlcTag
apiModel.PlcTag

GetTagType() TagType
}
Expand Down Expand Up @@ -128,7 +128,7 @@ type CALGetStatusTag interface {
func NewCALGetStatusTag(unitAddress readWriteModel.UnitAddress, bridgeAddresses []readWriteModel.BridgeAddress, parameter readWriteModel.Parameter, count uint8, numElements uint16) CALGetStatusTag {
return &calGetStatusTag{
calTag: calTag{bridgeAddresses, unitAddress},
tagType: CAL_RECALL,
tagType: CAL_GETSTATUS,
parameter: parameter,
count: count,
numElements: numElements,
Expand Down Expand Up @@ -158,11 +158,11 @@ func NewSALTag(bridgeAddresses []readWriteModel.BridgeAddress, application readW
type SALMonitorTag interface {
Tag

GetUnitAddress() *readWriteModel.UnitAddress
GetUnitAddress() readWriteModel.UnitAddress
GetApplication() *readWriteModel.ApplicationIdContainer
}

func NewSALMonitorTag(unitAddress *readWriteModel.UnitAddress, application *readWriteModel.ApplicationIdContainer, numElements uint16) SALMonitorTag {
func NewSALMonitorTag(unitAddress readWriteModel.UnitAddress, application *readWriteModel.ApplicationIdContainer, numElements uint16) SALMonitorTag {
return &salMonitorTag{
tagType: SAL_MONITOR,
unitAddress: unitAddress,
Expand All @@ -175,11 +175,11 @@ func NewSALMonitorTag(unitAddress *readWriteModel.UnitAddress, application *read
type MMIMonitorTag interface {
Tag

GetUnitAddress() *readWriteModel.UnitAddress
GetUnitAddress() readWriteModel.UnitAddress
GetApplication() *readWriteModel.ApplicationIdContainer
}

func NewMMIMonitorTag(unitAddress *readWriteModel.UnitAddress, application *readWriteModel.ApplicationIdContainer, numElements uint16) SALMonitorTag {
func NewMMIMonitorTag(unitAddress readWriteModel.UnitAddress, application *readWriteModel.ApplicationIdContainer, numElements uint16) SALMonitorTag {
return &mmiMonitorTag{
tagType: MMI_STATUS_MONITOR,
unitAddress: unitAddress,
Expand Down Expand Up @@ -241,14 +241,14 @@ type salTag struct {

type salMonitorTag struct {
tagType TagType
unitAddress *readWriteModel.UnitAddress
unitAddress readWriteModel.UnitAddress
application *readWriteModel.ApplicationIdContainer
numElements uint16
}

type mmiMonitorTag struct {
tagType TagType
unitAddress *readWriteModel.UnitAddress
unitAddress readWriteModel.UnitAddress
application *readWriteModel.ApplicationIdContainer
numElements uint16
}
Expand All @@ -275,20 +275,20 @@ func (s statusTag) GetAddressString() string {
return fmt.Sprintf("status/%s/%s", statusRequestType, s.application)
}

func (s statusTag) GetValueType() values.PlcValueType {
return values.NULL
func (s statusTag) GetValueType() apiValues.PlcValueType {
return apiValues.NULL
}

func (s statusTag) GetArrayInfo() []model.ArrayInfo {
func (s statusTag) GetArrayInfo() []apiModel.ArrayInfo {
if s.numElements != 1 {
return []model.ArrayInfo{
model2.DefaultArrayInfo{
return []apiModel.ArrayInfo{
spiModel.DefaultArrayInfo{
LowerBound: 0,
UpperBound: uint32(s.numElements),
},
}
}
return []model.ArrayInfo{}
return []apiModel.ArrayInfo{}
}

func (s statusTag) GetTagType() TagType {
Expand Down Expand Up @@ -416,20 +416,20 @@ func (c calRecallTag) GetAddressString() string {
return fmt.Sprintf("cal/%d/recall=%s", c.unitAddress.GetAddress(), c.parameter)
}

func (c calRecallTag) GetValueType() values.PlcValueType {
return values.Struct
func (c calRecallTag) GetValueType() apiValues.PlcValueType {
return apiValues.Struct
}

func (c calRecallTag) GetArrayInfo() []model.ArrayInfo {
func (c calRecallTag) GetArrayInfo() []apiModel.ArrayInfo {
if c.count != 1 {
return []model.ArrayInfo{
model2.DefaultArrayInfo{
return []apiModel.ArrayInfo{
spiModel.DefaultArrayInfo{
LowerBound: 0,
UpperBound: uint32(c.count),
},
}
}
return []model.ArrayInfo{}
return []apiModel.ArrayInfo{}
}

func (c calRecallTag) GetTagType() TagType {
Expand Down Expand Up @@ -483,20 +483,20 @@ func (c calIdentifyTag) GetAddressString() string {
return fmt.Sprintf("cal/%d/identify=%s", c.unitAddress.GetAddress(), c.GetAttribute())
}

func (c calIdentifyTag) GetValueType() values.PlcValueType {
return values.Struct
func (c calIdentifyTag) GetValueType() apiValues.PlcValueType {
return apiValues.Struct
}

func (c calIdentifyTag) GetArrayInfo() []model.ArrayInfo {
func (c calIdentifyTag) GetArrayInfo() []apiModel.ArrayInfo {
if c.numElements != 1 {
return []model.ArrayInfo{
model2.DefaultArrayInfo{
return []apiModel.ArrayInfo{
spiModel.DefaultArrayInfo{
LowerBound: 0,
UpperBound: uint32(c.numElements),
},
}
}
return []model.ArrayInfo{}
return []apiModel.ArrayInfo{}
}

func (c calIdentifyTag) GetTagType() TagType {
Expand Down Expand Up @@ -550,20 +550,20 @@ func (c calGetStatusTag) GetAddressString() string {
return fmt.Sprintf("cal/getstatus=%s, %d", c.parameter, c.GetCount())
}

func (c calGetStatusTag) GetValueType() values.PlcValueType {
return values.Struct
func (c calGetStatusTag) GetValueType() apiValues.PlcValueType {
return apiValues.Struct
}

func (c calGetStatusTag) GetArrayInfo() []model.ArrayInfo {
func (c calGetStatusTag) GetArrayInfo() []apiModel.ArrayInfo {
if c.count != 1 {
return []model.ArrayInfo{
model2.DefaultArrayInfo{
return []apiModel.ArrayInfo{
spiModel.DefaultArrayInfo{
LowerBound: 0,
UpperBound: uint32(c.count),
},
}
}
return []model.ArrayInfo{}
return []apiModel.ArrayInfo{}
}

func (c calGetStatusTag) GetTagType() TagType {
Expand Down Expand Up @@ -625,20 +625,20 @@ func (s salTag) GetAddressString() string {
return fmt.Sprintf("sal/%s/%s", s.application, s.salCommand)
}

func (s salTag) GetValueType() values.PlcValueType {
return values.Struct
func (s salTag) GetValueType() apiValues.PlcValueType {
return apiValues.Struct
}

func (s salTag) GetArrayInfo() []model.ArrayInfo {
func (s salTag) GetArrayInfo() []apiModel.ArrayInfo {
if s.numElements != 1 {
return []model.ArrayInfo{
model2.DefaultArrayInfo{
return []apiModel.ArrayInfo{
spiModel.DefaultArrayInfo{
LowerBound: 0,
UpperBound: uint32(s.numElements),
},
}
}
return []model.ArrayInfo{}
return []apiModel.ArrayInfo{}
}

func (s salTag) GetTagType() TagType {
Expand Down Expand Up @@ -697,7 +697,7 @@ func (s salTag) String() string {
func (s salMonitorTag) GetAddressString() string {
unitAddress := "*"
if s.unitAddress != nil {
unitAddress = fmt.Sprintf("%d", (*s.unitAddress).GetAddress())
unitAddress = fmt.Sprintf("%d", s.unitAddress.GetAddress())
}
application := "*"
if s.application != nil {
Expand All @@ -706,27 +706,27 @@ func (s salMonitorTag) GetAddressString() string {
return fmt.Sprintf("salmonitor/%s/%s", unitAddress, application)
}

func (s salMonitorTag) GetValueType() values.PlcValueType {
return values.Struct
func (s salMonitorTag) GetValueType() apiValues.PlcValueType {
return apiValues.Struct
}

func (s salMonitorTag) GetArrayInfo() []model.ArrayInfo {
func (s salMonitorTag) GetArrayInfo() []apiModel.ArrayInfo {
if s.numElements != 1 {
return []model.ArrayInfo{
model2.DefaultArrayInfo{
return []apiModel.ArrayInfo{
spiModel.DefaultArrayInfo{
LowerBound: 0,
UpperBound: uint32(s.numElements),
},
}
}
return []model.ArrayInfo{}
return []apiModel.ArrayInfo{}
}

func (s salMonitorTag) GetTagType() TagType {
return s.tagType
}

func (s salMonitorTag) GetUnitAddress() *readWriteModel.UnitAddress {
func (s salMonitorTag) GetUnitAddress() readWriteModel.UnitAddress {
return s.unitAddress
}

Expand All @@ -748,7 +748,7 @@ func (s salMonitorTag) SerializeWithWriteBuffer(ctx context.Context, writeBuffer
}

if unitAddress := s.unitAddress; unitAddress != nil {
if err := (*unitAddress).SerializeWithWriteBuffer(ctx, writeBuffer); err != nil {
if err := unitAddress.SerializeWithWriteBuffer(ctx, writeBuffer); err != nil {
return err
}
}
Expand All @@ -775,7 +775,7 @@ func (s salMonitorTag) String() string {
func (m mmiMonitorTag) GetAddressString() string {
unitAddress := "*"
if m.unitAddress != nil {
unitAddress = fmt.Sprintf("%d", (*m.unitAddress).GetAddress())
unitAddress = fmt.Sprintf("%d", m.unitAddress.GetAddress())
}
application := "*"
if m.application != nil {
Expand All @@ -784,27 +784,27 @@ func (m mmiMonitorTag) GetAddressString() string {
return fmt.Sprintf("mmimonitor/%s/%s", unitAddress, application)
}

func (m mmiMonitorTag) GetValueType() values.PlcValueType {
return values.Struct
func (m mmiMonitorTag) GetValueType() apiValues.PlcValueType {
return apiValues.Struct
}

func (m mmiMonitorTag) GetArrayInfo() []model.ArrayInfo {
func (m mmiMonitorTag) GetArrayInfo() []apiModel.ArrayInfo {
if m.numElements != 1 {
return []model.ArrayInfo{
model2.DefaultArrayInfo{
return []apiModel.ArrayInfo{
spiModel.DefaultArrayInfo{
LowerBound: 0,
UpperBound: uint32(m.numElements),
},
}
}
return []model.ArrayInfo{}
return []apiModel.ArrayInfo{}
}

func (m mmiMonitorTag) GetTagType() TagType {
return m.tagType
}

func (m mmiMonitorTag) GetUnitAddress() *readWriteModel.UnitAddress {
func (m mmiMonitorTag) GetUnitAddress() readWriteModel.UnitAddress {
return m.unitAddress
}

Expand All @@ -826,7 +826,7 @@ func (m mmiMonitorTag) SerializeWithWriteBuffer(ctx context.Context, writeBuffer
}

if unitAddress := m.unitAddress; unitAddress != nil {
if err := (*unitAddress).SerializeWithWriteBuffer(ctx, writeBuffer); err != nil {
if err := unitAddress.SerializeWithWriteBuffer(ctx, writeBuffer); err != nil {
return err
}
}
Expand Down

0 comments on commit 65414b2

Please sign in to comment.