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/01/04 14:00:14 UTC
[plc4x] branch develop updated: - Added the "CanBrowse" to the
connection metadata
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 5d9f8ac - Added the "CanBrowse" to the connection metadata
5d9f8ac is described below
commit 5d9f8ac3954e027216c4eafff320199390a61e37
Author: cdutz <ch...@c-ware.de>
AuthorDate: Mon Jan 4 15:00:03 2021 +0100
- Added the "CanBrowse" to the connection metadata
---
.../internal/plc4go/knxnetip/KnxNetIpConnection.go | 4 ++
plc4go/internal/plc4go/modbus/ModbusConnection.go | 51 ++++++++++++----------
plc4go/pkg/plc4go/model/plc_connection_metadata.go | 7 +--
3 files changed, 35 insertions(+), 27 deletions(-)
diff --git a/plc4go/internal/plc4go/knxnetip/KnxNetIpConnection.go b/plc4go/internal/plc4go/knxnetip/KnxNetIpConnection.go
index 0075883..f10ec3a 100644
--- a/plc4go/internal/plc4go/knxnetip/KnxNetIpConnection.go
+++ b/plc4go/internal/plc4go/knxnetip/KnxNetIpConnection.go
@@ -84,6 +84,10 @@ func (m ConnectionMetadata) CanSubscribe() bool {
return true
}
+func (m ConnectionMetadata) CanBrowse() bool {
+ return true
+}
+
type KnxNetIpConnection struct {
messageCodec spi.MessageCodec
options map[string][]string
diff --git a/plc4go/internal/plc4go/modbus/ModbusConnection.go b/plc4go/internal/plc4go/modbus/ModbusConnection.go
index fd69205..b26e09e 100644
--- a/plc4go/internal/plc4go/modbus/ModbusConnection.go
+++ b/plc4go/internal/plc4go/modbus/ModbusConnection.go
@@ -24,19 +24,18 @@ import (
"github.com/apache/plc4x/plc4go/internal/plc4go/spi"
"github.com/apache/plc4x/plc4go/internal/plc4go/spi/interceptors"
internalModel "github.com/apache/plc4x/plc4go/internal/plc4go/spi/model"
- "github.com/apache/plc4x/plc4go/internal/plc4go/spi/transports"
+ "github.com/apache/plc4x/plc4go/internal/plc4go/spi/transports"
"github.com/apache/plc4x/plc4go/pkg/plc4go"
apiModel "github.com/apache/plc4x/plc4go/pkg/plc4go/model"
- "time"
+ "time"
)
type ConnectionMetadata struct {
- apiModel.PlcConnectionMetadata
+ apiModel.PlcConnectionMetadata
}
func (m ConnectionMetadata) GetConnectionAttributes() map[string]string {
- return map[string]string {
- }
+ return map[string]string{}
}
func (m ConnectionMetadata) CanRead() bool {
@@ -51,6 +50,10 @@ func (m ConnectionMetadata) CanSubscribe() bool {
return false
}
+func (m ConnectionMetadata) CanBrowse() bool {
+ return false
+}
+
type ModbusConnection struct {
unitIdentifier uint8
messageCodec spi.MessageCodec
@@ -100,25 +103,25 @@ func (m ModbusConnection) Ping() <-chan plc4go.PlcConnectionPingResult {
go func() {
pingRequest := driverModel.NewModbusTcpADU(1, m.unitIdentifier, diagnosticRequestPdu)
err := m.messageCodec.SendRequest(
- pingRequest,
- func(message interface{}) bool {
- responseAdu := driverModel.CastModbusTcpADU(message)
- return responseAdu.TransactionIdentifier == 1 &&
- responseAdu.UnitIdentifier == m.unitIdentifier
- },
- func(message interface{}) error {
- if message != nil {
- // If we got a valid response (even if it will probably contain an error, we know the remote is available)
- result <- plc4go.NewPlcConnectionPingResult(nil)
- } else {
- result <- plc4go.NewPlcConnectionPingResult(errors.New("no response"))
- }
- return nil
- },
- time.Second * 1)
- if err != nil {
- result <- plc4go.NewPlcConnectionPingResult(err)
- }
+ pingRequest,
+ func(message interface{}) bool {
+ responseAdu := driverModel.CastModbusTcpADU(message)
+ return responseAdu.TransactionIdentifier == 1 &&
+ responseAdu.UnitIdentifier == m.unitIdentifier
+ },
+ func(message interface{}) error {
+ if message != nil {
+ // If we got a valid response (even if it will probably contain an error, we know the remote is available)
+ result <- plc4go.NewPlcConnectionPingResult(nil)
+ } else {
+ result <- plc4go.NewPlcConnectionPingResult(errors.New("no response"))
+ }
+ return nil
+ },
+ time.Second*1)
+ if err != nil {
+ result <- plc4go.NewPlcConnectionPingResult(err)
+ }
}()
return result
diff --git a/plc4go/pkg/plc4go/model/plc_connection_metadata.go b/plc4go/pkg/plc4go/model/plc_connection_metadata.go
index 382f47d..2dcfe8a 100644
--- a/plc4go/pkg/plc4go/model/plc_connection_metadata.go
+++ b/plc4go/pkg/plc4go/model/plc_connection_metadata.go
@@ -22,8 +22,8 @@ package model
// This includes connection and driver specific metadata.
type PlcConnectionMetadata interface {
- // Gives access to a map of additional information the driver might be able to provide.
- GetConnectionAttributes() map[string]string
+ // Gives access to a map of additional information the driver might be able to provide.
+ GetConnectionAttributes() map[string]string
// Indicates that the connection supports reading.
CanRead() bool
@@ -31,5 +31,6 @@ type PlcConnectionMetadata interface {
CanWrite() bool
// Indicates that the connection supports subscription.
CanSubscribe() bool
-
+ // Indicates that the connection supports browsing.
+ CanBrowse() bool
}