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 2022/08/17 19:37:45 UTC
[plc4x] 01/02: Merge remote-tracking branch 'origin/develop' into feature/ads-symbol-discovery
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch feature/ads-symbol-discovery
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit f2387df8d4f519b2d054b41346677c65c12a1f3e
Merge: bd1162193 6bd288c47
Author: Christofer Dutz <ch...@rivian.com>
AuthorDate: Wed Aug 17 20:24:11 2022 +0200
Merge remote-tracking branch 'origin/develop' into feature/ads-symbol-discovery
# Conflicts:
# plc4go/internal/bacnetip/Discoverer.go
# plc4go/internal/bacnetip/Driver.go
# plc4go/internal/knxnetip/Discoverer.go
# plc4go/internal/knxnetip/Driver.go
# plc4go/internal/simulated/Driver.go
# plc4go/internal/simulated/Driver_test.go
# plc4go/pkg/api/driver.go
# plc4go/pkg/api/driverManager.go
# plc4go/spi/PlcDiscoverer.go
.github/workflows/ensure-platforms.yml | 11 +-
plc4c/pom.xml | 2 +-
plc4go/internal/ads/Reader.go | 83 +-
plc4go/internal/ads/Writer.go | 59 +-
plc4go/internal/bacnetip/Discoverer.go | 5 +-
plc4go/internal/bacnetip/Driver.go | 7 +-
plc4go/internal/bacnetip/Reader.go | 99 +-
plc4go/internal/bacnetip/Subscriber.go | 7 +-
plc4go/internal/cbus/Browser.go | 183 ++-
plc4go/internal/cbus/Connection.go | 367 +++---
plc4go/internal/cbus/Discoverer.go | 209 ++--
plc4go/internal/cbus/Driver.go | 7 +-
plc4go/internal/cbus/Field.go | 86 +-
plc4go/internal/cbus/FieldHandler.go | 55 +
plc4go/internal/cbus/MessageCodec.go | 104 +-
plc4go/internal/cbus/Reader.go | 383 ++++---
plc4go/internal/cbus/Subscriber.go | 130 ++-
plc4go/internal/cbus/Writer.go | 4 +-
plc4go/internal/cbus/fieldtype_string.go | 11 +-
plc4go/internal/eip/Connection.go | 93 +-
plc4go/internal/eip/Reader.go | 184 ++-
plc4go/internal/eip/Writer.go | 184 ++-
plc4go/internal/knxnetip/Browser.go | 76 +-
plc4go/internal/knxnetip/Connection.go | 19 +-
.../knxnetip/ConnectionDriverSpecificOperations.go | 41 +-
plc4go/internal/knxnetip/ConnectionHelper.go | 7 +-
.../knxnetip/ConnectionInternalOperations.go | 1189 +++++++++-----------
plc4go/internal/knxnetip/Discoverer.go | 128 ++-
plc4go/internal/knxnetip/Driver.go | 15 +-
plc4go/internal/knxnetip/Reader.go | 14 +-
plc4go/internal/knxnetip/Subscriber.go | 7 +-
plc4go/internal/knxnetip/Writer.go | 4 +-
plc4go/internal/modbus/Connection.go | 46 +-
plc4go/internal/modbus/Reader.go | 63 +-
plc4go/internal/modbus/Writer.go | 61 +-
plc4go/internal/s7/Connection.go | 191 ++--
plc4go/internal/s7/Reader.go | 85 +-
plc4go/internal/s7/Writer.go | 87 +-
plc4go/internal/simulated/Driver.go | 34 +-
plc4go/internal/simulated/Driver_test.go | 120 +-
plc4go/internal/simulated/Reader.go | 4 +-
plc4go/internal/simulated/Reader_test.go | 3 +-
plc4go/internal/simulated/Writer.go | 4 +-
plc4go/internal/simulated/Writer_test.go | 3 +-
plc4go/pkg/api/cache/plc_connection_cache.go | 9 +
plc4go/pkg/api/driver.go | 2 +
plc4go/pkg/api/driverManager.go | 9 +-
plc4go/pkg/api/model/plc_browse.go | 9 +-
plc4go/pkg/api/model/plc_read.go | 6 +-
plc4go/pkg/api/model/plc_subscription.go | 2 +
plc4go/pkg/api/model/plc_unsubscription.go | 3 +
plc4go/pkg/api/model/plc_write.go | 6 +-
.../cbus/readwrite/model/IdentifyReplyCommand.go | 4 +-
.../IdentifyReplyCommandNetworkTerminalLevels.go | 36 +-
...reSummary.go => IdentifyReplyCommandSummary.go} | 114 +-
plc4go/spi/MessageCodec.go | 12 +-
plc4go/spi/PlcBrowser.go | 9 +-
plc4go/spi/PlcDiscoverer.go | 2 +
plc4go/spi/PlcReader.go | 7 +-
plc4go/spi/PlcSubscriber.go | 9 +-
plc4go/spi/PlcWriter.go | 7 +-
plc4go/spi/RequestTransactionManager.go | 2 +-
plc4go/spi/default/DefaultBrowser.go | 84 ++
plc4go/spi/default/DefaultCodec.go | 39 +-
plc4go/spi/default/DefaultConnection.go | 3 +
plc4go/spi/default/DefaultDriver.go | 5 +
plc4go/spi/interceptors/RequestInterceptor.go | 9 +-
.../interceptors/SingleItemRequestInterceptor.go | 13 +-
plc4go/spi/model/DefaultPlcBrowseRequest.go | 13 +-
plc4go/spi/model/DefaultPlcReadRequest.go | 25 +-
plc4go/spi/model/DefaultPlcSubscriptionRequest.go | 7 +-
plc4go/spi/model/DefaultPlcWriteRequest.go | 24 +-
plc4go/spi/testutils/DriverTestRunner.go | 9 +-
plc4go/spi/transports/TransportInstance.go | 67 +-
plc4go/spi/transports/pcap/Transport.go | 11 +-
plc4go/spi/transports/serial/Transport.go | 11 +-
plc4go/spi/transports/tcp/Transport.go | 19 +-
plc4go/spi/transports/test/Transport.go | 5 +
plc4go/spi/transports/udp/Transport.go | 8 +-
plc4go/spi/utils/net.go | 25 +-
.../tests/drivers/tests/manual_cbus_driver_test.go | 52 +
.../apache/plc4x/java/cbus/RandomPackagesTest.java | 1 +
plc4j/integrations/apache-camel/pom.xml | 2 +-
pom.xml | 14 +-
.../src/main/resources/protocols/cbus/c-bus.mspec | 10 +-
protocols/knxnetip/pom.xml | 2 +-
protocols/opcua/pom.xml | 2 +-
.../server/cbus/protocol/CBusServerAdapter.java | 2 +-
88 files changed, 2852 insertions(+), 2332 deletions(-)
diff --cc plc4go/internal/bacnetip/Discoverer.go
index e61f6ed6b,36f1d77b9..e303c847b
--- a/plc4go/internal/bacnetip/Discoverer.go
+++ b/plc4go/internal/bacnetip/Discoverer.go
@@@ -48,7 -48,8 +48,8 @@@ func NewDiscoverer() *Discoverer
return &Discoverer{}
}
- func (d *Discoverer) Discover(callback func(event apiModel.PlcDiscoveryItem), discoveryOptions ...options.WithDiscoveryOption) error {
-func (d *Discoverer) Discover(ctx context.Context, callback func(event apiModel.PlcDiscoveryEvent), discoveryOptions ...options.WithDiscoveryOption) error {
++func (d *Discoverer) Discover(ctx context.Context, callback func(event apiModel.PlcDiscoveryItem), discoveryOptions ...options.WithDiscoveryOption) error {
+ // TODO: handle ctx
interfaces, err := extractInterfaces(discoveryOptions)
if err != nil {
return errors.Wrap(err, "error extracting interfaces")
diff --cc plc4go/internal/bacnetip/Driver.go
index 26552395a,24512c95f..f9d40dd7e
--- a/plc4go/internal/bacnetip/Driver.go
+++ b/plc4go/internal/bacnetip/Driver.go
@@@ -133,6 -134,10 +134,10 @@@ func (m *Driver) SupportsDiscovery() bo
return true
}
-func (m *Driver) Discover(callback func(event apiModel.PlcDiscoveryEvent), discoveryOptions ...options.WithDiscoveryOption) error {
+func (m *Driver) Discover(callback func(event apiModel.PlcDiscoveryItem), discoveryOptions ...options.WithDiscoveryOption) error {
- return NewDiscoverer().Discover(callback, discoveryOptions...)
+ return m.DiscoverWithContext(context.TODO(), callback, discoveryOptions...)
+ }
+
+ func (m *Driver) DiscoverWithContext(ctx context.Context, callback func(event apiModel.PlcDiscoveryEvent), discoveryOptions ...options.WithDiscoveryOption) error {
+ return NewDiscoverer().Discover(ctx, callback, discoveryOptions...)
}
diff --cc plc4go/internal/knxnetip/Discoverer.go
index 12f780068,7c435bca2..965fa1220
--- a/plc4go/internal/knxnetip/Discoverer.go
+++ b/plc4go/internal/knxnetip/Discoverer.go
@@@ -44,7 -45,8 +45,8 @@@ func NewDiscoverer() *Discoverer
return &Discoverer{}
}
- func (d *Discoverer) Discover(callback func(event apiModel.PlcDiscoveryItem), discoveryOptions ...options.WithDiscoveryOption) error {
-func (d *Discoverer) Discover(ctx context.Context, callback func(event apiModel.PlcDiscoveryEvent), discoveryOptions ...options.WithDiscoveryOption) error {
++func (d *Discoverer) Discover(ctx context.Context, callback func(event apiModel.PlcDiscoveryItem), discoveryOptions ...options.WithDiscoveryOption) error {
+ // TODO: handle ctx
udpTransport := udp.NewTransport()
// Create a connection string for the KNX broadcast discovery address.
diff --cc plc4go/internal/knxnetip/Driver.go
index 9c456e440,721c65861..60deb4fb9
--- a/plc4go/internal/knxnetip/Driver.go
+++ b/plc4go/internal/knxnetip/Driver.go
@@@ -77,6 -78,10 +78,10 @@@ func (m *Driver) SupportsDiscovery() bo
return true
}
- func (m Driver) Discover(callback func(event apiModel.PlcDiscoveryItem), discoveryOptions ...options.WithDiscoveryOption) error {
- return NewDiscoverer().Discover(callback, discoveryOptions...)
-func (m *Driver) Discover(callback func(event apiModel.PlcDiscoveryEvent), discoveryOptions ...options.WithDiscoveryOption) error {
++func (m *Driver) Discover(callback func(event apiModel.PlcDiscoveryItem), discoveryOptions ...options.WithDiscoveryOption) error {
+ return m.DiscoverWithContext(context.TODO(), callback, discoveryOptions...)
+ }
+
+ func (m *Driver) DiscoverWithContext(ctx context.Context, callback func(event apiModel.PlcDiscoveryEvent), discoveryOptions ...options.WithDiscoveryOption) error {
+ return NewDiscoverer().Discover(ctx, callback, discoveryOptions...)
}
diff --cc plc4go/internal/simulated/Driver.go
index ec1d97a13,0b0fdd19c..2026bbc35
--- a/plc4go/internal/simulated/Driver.go
+++ b/plc4go/internal/simulated/Driver.go
@@@ -40,40 -38,8 +38,18 @@@ func NewDriver() plc4go.PlcDriver
}
}
- // GetProtocolCode Get the short code used to identify this driver (As used in the connection string)
- func (d *Driver) GetProtocolCode() string {
- return "simulated"
- }
-
- // GetProtocolName Get a human-readable name for this driver
- func (d *Driver) GetProtocolName() string {
- return "Simulated PLC4X Datasource"
- }
-
- // GetDefaultTransport If the driver has a default form of transport, provide this and make
- // providing the transport code optional in the connection string
- func (d *Driver) GetDefaultTransport() string {
- return "none"
- }
-
- // CheckQuery Have the driver parse the query string and provide feedback if it's not a valid one
- func (d *Driver) CheckQuery(query string) error {
- _, err := d.fieldHandler.ParseQuery(query)
- return err
- }
-
// GetConnection Establishes a connection to a given PLC using the information in the connectionString
func (d *Driver) GetConnection(_ url.URL, _ map[string]transports.Transport, options map[string][]string) <-chan plc4go.PlcConnectionConnectResult {
- connection := NewConnection(NewDevice("test"), d.fieldHandler, d.valueHandler, options)
+ connection := NewConnection(NewDevice("test"), d.GetPlcFieldHandler(), d.valueHandler, options)
return connection.Connect()
}
+
+// SupportsDiscovery returns true if this driver supports discovery
+// TODO: Actually the connection could support discovery to list up all fields in the Device
+func (d *Driver) SupportsDiscovery() bool {
+ return false
+}
+
+func (d *Driver) Discover(_ func(event model.PlcDiscoveryItem), _ ...options.WithDiscoveryOption) error {
+ return errors.New("unsupported operation")
+}
diff --cc plc4go/internal/simulated/Driver_test.go
index aca7bf1f1,ad34db3ec..16631d0c6
--- a/plc4go/internal/simulated/Driver_test.go
+++ b/plc4go/internal/simulated/Driver_test.go
@@@ -67,53 -53,7 +53,49 @@@ func TestDriver_CheckQuery(t *testing.T
}
}
+func TestDriver_Discover(t *testing.T) {
+ type fields struct {
+ fieldHandler FieldHandler
+ valueHandler ValueHandler
+ }
+ type args struct {
+ callback func(event model.PlcDiscoveryItem)
+ discoveryOptions []options.WithDiscoveryOption
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ wantErr bool
+ }{
+ {
+ name: "discovery fails",
+ fields: fields{
+ fieldHandler: NewFieldHandler(),
+ valueHandler: NewValueHandler(),
+ },
+ args: args{
+ // Can all be nil, as the call is expected to fail
+ callback: nil,
+ discoveryOptions: nil,
+ },
+ wantErr: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &Driver{
+ fieldHandler: tt.fields.fieldHandler,
+ valueHandler: tt.fields.valueHandler,
+ }
+ if err := d.Discover(tt.args.callback, tt.args.discoveryOptions...); (err != nil) != tt.wantErr {
+ t.Errorf("Discover() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ })
+ }
+}
+
func TestDriver_GetConnection(t *testing.T) {
- type fields struct {
- fieldHandler FieldHandler
- valueHandler ValueHandler
- }
type args struct {
in0 url.URL
in1 map[string]transports.Transport
diff --cc plc4go/pkg/api/driver.go
index f07ba0a21,ffdf79adf..67760f4d3
--- a/plc4go/pkg/api/driver.go
+++ b/plc4go/pkg/api/driver.go
@@@ -48,5 -49,6 +49,6 @@@ type PlcDriver interface
// Discover TODO: document me
// FIXME: this leaks spi in the signature move to spi driver or create interfaces. Can also be done by moving spi in a proper module
- Discover(callback func(event model.PlcDiscoveryEvent), discoveryOptions ...options.WithDiscoveryOption) error
+ Discover(callback func(event model.PlcDiscoveryItem), discoveryOptions ...options.WithDiscoveryOption) error
+ DiscoverWithContext(ctx context.Context, callback func(event model.PlcDiscoveryEvent), discoveryOptions ...options.WithDiscoveryOption) error
}
diff --cc plc4go/pkg/api/driverManager.go
index d093ed6e0,8f0be21c9..4e8e5ecc4
--- a/plc4go/pkg/api/driverManager.go
+++ b/plc4go/pkg/api/driverManager.go
@@@ -41,7 -42,9 +42,9 @@@ type PlcDriverManager interface
GetConnection(connectionString string) <-chan PlcConnectionConnectResult
// Discover Execute all available discovery methods on all available drivers using all transports
- Discover(callback func(event model.PlcDiscoveryEvent), discoveryOptions ...WithDiscoveryOption) error
+ Discover(callback func(event model.PlcDiscoveryItem), discoveryOptions ...WithDiscoveryOption) error
+ // DiscoverWithContext Execute all available discovery methods on all available drivers using all transports
+ DiscoverWithContext(ctx context.Context, callback func(event model.PlcDiscoveryEvent), discoveryOptions ...WithDiscoveryOption) error
}
func NewPlcDriverManager() PlcDriverManager {
@@@ -282,7 -285,11 +285,11 @@@ func (m *plcDriverManger) GetConnection
return driver.GetConnection(transportUrl, m.transports, configOptions)
}
-func (m *plcDriverManger) Discover(callback func(event model.PlcDiscoveryEvent), discoveryOptions ...WithDiscoveryOption) error {
+func (m *plcDriverManger) Discover(callback func(event model.PlcDiscoveryItem), discoveryOptions ...WithDiscoveryOption) error {
+ return m.DiscoverWithContext(context.TODO(), callback, discoveryOptions...)
+ }
+
+ func (m *plcDriverManger) DiscoverWithContext(ctx context.Context, callback func(event model.PlcDiscoveryEvent), discoveryOptions ...WithDiscoveryOption) error {
// Check if we've got at least one option to restrict to certain protocols only.
// If there is at least one, we only check that protocol, if there are none, all
// available protocols are checked.
diff --cc plc4go/spi/PlcDiscoverer.go
index 812a25fab,33c8af325..d0241389a
--- a/plc4go/spi/PlcDiscoverer.go
+++ b/plc4go/spi/PlcDiscoverer.go
@@@ -25,5 -26,6 +26,6 @@@ import
)
type PlcDiscoverer interface {
- Discover(callback func(event model.PlcDiscoveryEvent), discoveryOptions ...options.WithDiscoveryOption) error
+ Discover(callback func(event model.PlcDiscoveryItem), discoveryOptions ...options.WithDiscoveryOption) error
+ DiscoverWithContext(ctx context.Context, callback func(event model.PlcDiscoveryEvent), discoveryOptions ...options.WithDiscoveryOption) error
}