Skip to content

Commit

Permalink
feat(plc4go): added GetSource to PlcSubscriptionEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Sep 6, 2022
1 parent 1d0bfbd commit 0e01d37
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
7 changes: 3 additions & 4 deletions plc4go/internal/cbus/SubscriptionEvent.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ type SubscriptionEvent struct {
func NewSubscriptionEvent(fields map[string]apiModel.PlcField, types map[string]internalMode.SubscriptionType,
intervals map[string]time.Duration, responseCodes map[string]apiModel.PlcResponseCode,
address map[string]string, values map[string]values.PlcValue) SubscriptionEvent {
return SubscriptionEvent{
address: address,
DefaultPlcSubscriptionEvent: internalMode.NewDefaultPlcSubscriptionEvent(fields, types, intervals, responseCodes, values),
}
subscriptionEvent := SubscriptionEvent{address: address}
subscriptionEvent.DefaultPlcSubscriptionEvent = internalMode.NewDefaultPlcSubscriptionEvent(subscriptionEvent, fields, types, intervals, responseCodes, values)
return subscriptionEvent
}

func (m SubscriptionEvent) GetAddress(name string) string {
Expand Down
7 changes: 3 additions & 4 deletions plc4go/internal/knxnetip/SubscriptionEvent.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ type SubscriptionEvent struct {
func NewSubscriptionEvent(fields map[string]apiModel.PlcField, types map[string]internalMode.SubscriptionType,
intervals map[string]time.Duration, responseCodes map[string]apiModel.PlcResponseCode,
addresses map[string][]byte, values map[string]values.PlcValue) SubscriptionEvent {
return SubscriptionEvent{
addresses: addresses,
DefaultPlcSubscriptionEvent: internalMode.NewDefaultPlcSubscriptionEvent(fields, types, intervals, responseCodes, values),
}
subscriptionEvent := SubscriptionEvent{addresses: addresses}
subscriptionEvent.DefaultPlcSubscriptionEvent = internalMode.NewDefaultPlcSubscriptionEvent(subscriptionEvent, fields, types, intervals, responseCodes, values)
return subscriptionEvent
}

// GetAddress Decode the binary data in the address according to the field requested
Expand Down
9 changes: 9 additions & 0 deletions plc4go/pkg/api/model/plc_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,18 @@ import (

type PlcSubscriptionEvent interface {
PlcResponse
// GetFieldNames returns all field name which can be found in this event
GetFieldNames() []string
// GetResponseCode returns the PlcResponseCode for a field
GetResponseCode(name string) PlcResponseCode
// GetAddress returns the address for an event. This is meant to for reading or writing one item.
// Sometimes there are fields which can't be directly addressed (e.g. only through a broadcast).
// In that case (if applicable) the GetSource contains the source information about the sending device.
GetAddress(name string) string
// GetSource returns usually the same as GetAddress in case when the address contains information about the source.
// If we have a field which is not directly addressable (see doc for GetAddress) the source is useful to identify the device.
GetSource(name string) string
// GetValue returns the field value for a named field.
GetValue(name string) values.PlcValue
}

Expand Down
24 changes: 17 additions & 7 deletions plc4go/spi/model/DefaultPlcSubscriptionEvent.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,27 @@ import (

type DefaultPlcSubscriptionEvent struct {
DefaultResponse
DefaultPlcSubscriptionEventRequirements
fields map[string]model.PlcField
types map[string]SubscriptionType
intervals map[string]time.Duration
values map[string]values.PlcValue
}

func NewDefaultPlcSubscriptionEvent(fields map[string]model.PlcField, types map[string]SubscriptionType,
type DefaultPlcSubscriptionEventRequirements interface {
GetAddress(name string) string
}

func NewDefaultPlcSubscriptionEvent(defaultPlcSubscriptionEventRequirements DefaultPlcSubscriptionEventRequirements, fields map[string]model.PlcField, types map[string]SubscriptionType,
intervals map[string]time.Duration, responseCodes map[string]model.PlcResponseCode,
values map[string]values.PlcValue) DefaultPlcSubscriptionEvent {
return DefaultPlcSubscriptionEvent{
DefaultResponse: NewDefaultResponse(responseCodes),
fields: fields,
types: types,
intervals: intervals,
values: values,
DefaultResponse: NewDefaultResponse(responseCodes),
DefaultPlcSubscriptionEventRequirements: defaultPlcSubscriptionEventRequirements,
fields: fields,
types: types,
intervals: intervals,
values: values,
}
}

Expand All @@ -67,7 +73,11 @@ func (m DefaultPlcSubscriptionEvent) GetInterval(name string) time.Duration {
}

func (m DefaultPlcSubscriptionEvent) GetAddress(name string) string {
panic("GetAddress not implemented")
return m.DefaultPlcSubscriptionEventRequirements.GetAddress(name)
}

func (m DefaultPlcSubscriptionEvent) GetSource(name string) string {
return m.GetAddress(name)
}

func (m DefaultPlcSubscriptionEvent) GetValue(name string) values.PlcValue {
Expand Down

0 comments on commit 0e01d37

Please sign in to comment.