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 2024/09/01 21:44:32 UTC
(plc4x) 03/03: feat: Enabled the EIP auto-discovery in Java
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
commit 9c2af3e399372bc20cd3b61727e741cbaf21524c
Author: Christofer Dutz <cd...@apache.org>
AuthorDate: Sun Sep 1 23:37:54 2024 +0200
feat: Enabled the EIP auto-discovery in Java
---
.../org/apache/plc4x/java/eip/base/EIPDriver.java | 13 +++++++++
.../plc4x/java/eip/base/ManualEipDiscovery.java | 31 ++++++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/EIPDriver.java b/plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/EIPDriver.java
index 2f85009e8f..a6d731526b 100644
--- a/plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/EIPDriver.java
+++ b/plc4j/drivers/eip/src/main/java/org/apache/plc4x/java/eip/base/EIPDriver.java
@@ -20,6 +20,8 @@ package org.apache.plc4x.java.eip.base;
import io.netty.buffer.ByteBuf;
import org.apache.plc4x.java.api.PlcConnection;
+import org.apache.plc4x.java.api.messages.PlcDiscoveryRequest;
+import org.apache.plc4x.java.eip.base.discovery.EipPlcDiscoverer;
import org.apache.plc4x.java.spi.configuration.PlcConnectionConfiguration;
import org.apache.plc4x.java.spi.configuration.PlcTransportConfiguration;
import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
@@ -33,6 +35,7 @@ import org.apache.plc4x.java.spi.configuration.ConfigurationFactory;
import org.apache.plc4x.java.spi.configuration.HasConfiguration;
import org.apache.plc4x.java.spi.connection.*;
import org.apache.plc4x.java.spi.generation.ByteOrder;
+import org.apache.plc4x.java.spi.messages.DefaultPlcDiscoveryRequest;
import org.apache.plc4x.java.spi.transport.Transport;
import org.apache.plc4x.java.api.value.PlcValueHandler;
@@ -99,6 +102,11 @@ public class EIPDriver extends GeneratedDriverBase<EipPacket> {
return new org.apache.plc4x.java.spi.values.PlcValueHandler();
}
+ @Override
+ public PlcDiscoveryRequest.Builder discoveryRequestBuilder() {
+ return new DefaultPlcDiscoveryRequest.Builder(new EipPlcDiscoverer());
+ }
+
/**
* This protocol doesn't have a disconnect procedure, so there is no need to wait for a login to finish.
* @return false
@@ -118,6 +126,11 @@ public class EIPDriver extends GeneratedDriverBase<EipPacket> {
return true;
}
+ @Override
+ protected boolean canDiscover() {
+ return true;
+ }
+
@Override
protected ProtocolStackConfigurer<EipPacket> getStackConfigurer() {
return SingleProtocolStackConfigurer.builder(EipPacket.class, io -> EipPacket.staticParse(io, true))
diff --git a/plc4j/drivers/eip/src/test/java/org/apache/plc4x/java/eip/base/ManualEipDiscovery.java b/plc4j/drivers/eip/src/test/java/org/apache/plc4x/java/eip/base/ManualEipDiscovery.java
new file mode 100644
index 0000000000..c3d6164b3b
--- /dev/null
+++ b/plc4j/drivers/eip/src/test/java/org/apache/plc4x/java/eip/base/ManualEipDiscovery.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.plc4x.java.eip.base;
+
+import org.apache.plc4x.java.api.messages.PlcDiscoveryResponse;
+
+public class ManualEipDiscovery {
+
+ public static void main(String[] args) throws Exception {
+ PlcDiscoveryResponse discoveryResponse = new EIPDriver().discoveryRequestBuilder().addQuery("all", "*").build().execute().get();
+ System.out.println(discoveryResponse);
+ }
+
+}