You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by ld...@apache.org on 2020/10/11 22:31:24 UTC

[plc4x] branch feature/beckhoff-discovery created (now a7555f2)

This is an automated email from the ASF dual-hosted git repository.

ldywicki pushed a change to branch feature/beckhoff-discovery
in repository https://gitbox.apache.org/repos/asf/plc4x.git.


      at a7555f2  Brief support for AMS/ADS discovery packets.

This branch includes the following new commits:

     new a7555f2  Brief support for AMS/ADS discovery packets.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[plc4x] 01/01: Brief support for AMS/ADS discovery packets.

Posted by ld...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ldywicki pushed a commit to branch feature/beckhoff-discovery
in repository https://gitbox.apache.org/repos/asf/plc4x.git

commit a7555f29abdaf782a4d1afa24315f9430ae82316
Author: Ɓukasz Dywicki <lu...@code-house.org>
AuthorDate: Mon Oct 12 00:29:15 2020 +0200

    Brief support for AMS/ADS discovery packets.
---
 plc4j/drivers/ads/pom.xml                          | 14 +++-
 .../ads/AdsDiscoverySerializerParserTest.java      | 30 +++++++
 .../plc4x/protocol/ads/ADSDiscoveryProtocol.java   | 49 +++++++++++
 ...e.plc4x.plugins.codegenerator.protocol.Protocol |  3 +-
 .../resources/protocols/ads/ads-discovery.mspec    | 95 +++++++++++++++++-----
 5 files changed, 167 insertions(+), 24 deletions(-)

diff --git a/plc4j/drivers/ads/pom.xml b/plc4j/drivers/ads/pom.xml
index dd7f451..dc3bbbb 100644
--- a/plc4j/drivers/ads/pom.xml
+++ b/plc4j/drivers/ads/pom.xml
@@ -37,7 +37,7 @@
         <artifactId>plc4x-maven-plugin</artifactId>
         <executions>
           <execution>
-            <id>test</id>
+            <id>generate-ams-structs</id>
             <phase>generate-sources</phase>
             <goals>
               <goal>generate-driver</goal>
@@ -48,6 +48,18 @@
               <outputFlavor>read-write</outputFlavor>
             </configuration>
           </execution>
+          <execution>
+            <id>generate-ams-discovery-structs</id>
+            <phase>generate-sources</phase>
+            <goals>
+              <goal>generate-driver</goal>
+            </goals>
+            <configuration>
+              <protocolName>ads.discovery</protocolName>
+              <languageName>java</languageName>
+              <outputFlavor>read-write</outputFlavor>
+            </configuration>
+          </execution>
         </executions>
       </plugin>
       <plugin>
diff --git a/plc4j/drivers/ads/src/test/java/org/apache/plc4x/protocol/ads/AdsDiscoverySerializerParserTest.java b/plc4j/drivers/ads/src/test/java/org/apache/plc4x/protocol/ads/AdsDiscoverySerializerParserTest.java
new file mode 100644
index 0000000..9cba6a2
--- /dev/null
+++ b/plc4j/drivers/ads/src/test/java/org/apache/plc4x/protocol/ads/AdsDiscoverySerializerParserTest.java
@@ -0,0 +1,30 @@
+/*
+  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.protocol.ads;
+
+import org.apache.plc4x.test.parserserializer.ParserSerializerTestsuiteRunner;
+
+public class AdsDiscoverySerializerParserTest extends ParserSerializerTestsuiteRunner {
+
+    public AdsDiscoverySerializerParserTest() {
+        super("/testsuite/AdsDiscoverySerializerTest.xml");
+    }
+
+}
diff --git a/protocols/ads/src/main/java/org/apache/plc4x/protocol/ads/ADSDiscoveryProtocol.java b/protocols/ads/src/main/java/org/apache/plc4x/protocol/ads/ADSDiscoveryProtocol.java
new file mode 100644
index 0000000..105a037
--- /dev/null
+++ b/protocols/ads/src/main/java/org/apache/plc4x/protocol/ads/ADSDiscoveryProtocol.java
@@ -0,0 +1,49 @@
+/*
+ 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.protocol.ads;
+
+import org.apache.plc4x.plugins.codegenerator.language.mspec.parser.MessageFormatParser;
+import org.apache.plc4x.plugins.codegenerator.protocol.Protocol;
+import org.apache.plc4x.plugins.codegenerator.types.definitions.TypeDefinition;
+import org.apache.plc4x.plugins.codegenerator.types.exceptions.GenerationException;
+
+import java.io.InputStream;
+import java.util.Map;
+
+/**
+ * Little helper protocol used to communicate over UDP with Beckhoff hardware.
+ */
+public class ADSDiscoveryProtocol implements Protocol {
+
+    @Override
+    public String getName() {
+        return "ads.discovery";
+    }
+
+    @Override
+    public Map<String, TypeDefinition> getTypeDefinitions() throws GenerationException {
+        InputStream schemaInputStream = ADSDiscoveryProtocol.class.getResourceAsStream("/protocols/ads/ads-discovery.mspec");
+        if(schemaInputStream == null) {
+            throw new GenerationException("Error loading message-format schema for protocol '" + getName() + "'");
+        }
+        return new MessageFormatParser().parse(schemaInputStream);
+    }
+
+}
diff --git a/protocols/ads/src/main/resources/META-INF/services/org.apache.plc4x.plugins.codegenerator.protocol.Protocol b/protocols/ads/src/main/resources/META-INF/services/org.apache.plc4x.plugins.codegenerator.protocol.Protocol
index 71c570e..dac8da8 100644
--- a/protocols/ads/src/main/resources/META-INF/services/org.apache.plc4x.plugins.codegenerator.protocol.Protocol
+++ b/protocols/ads/src/main/resources/META-INF/services/org.apache.plc4x.plugins.codegenerator.protocol.Protocol
@@ -16,4 +16,5 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-org.apache.plc4x.protocol.ads.ADSProtocol
\ No newline at end of file
+org.apache.plc4x.protocol.ads.ADSProtocol
+org.apache.plc4x.protocol.ads.ADSDiscoveryProtocol
\ No newline at end of file
diff --git a/protocols/ads/src/main/resources/protocols/ads/ads-discovery.mspec b/protocols/ads/src/main/resources/protocols/ads/ads-discovery.mspec
index f549d70..3dabd91 100644
--- a/protocols/ads/src/main/resources/protocols/ads/ads-discovery.mspec
+++ b/protocols/ads/src/main/resources/protocols/ads/ads-discovery.mspec
@@ -21,31 +21,82 @@
 // AMS/TCP Packet
 ////////////////////////////////////////////////////////////////
 
-[type 'AmsTCPDiscoveryPacket'
-    [const uint 32 'header' '0x03661471']
-    [reserved   uint 32  '0x00000000']
-    [simple     uint 16  'something']
-    [reserved   uint 16  '0x0000']
-    [simple     AmsNetId 'amsNetId']
-    [reserved   uint 16  '0x1027']
-    [simple     uint 16  'something2']
-    [reserved   uint 32  '0x0000']
-    [simple     uint 16  'something3']
-    [implicit   uint 16  'hostnameLength' 'COUNT(hostname)']
-    [array      int 8    'hostname' COUNT 'hostnameLength']
-    [reserved   uint 16  '0x4000']
-    [simple     uint 16  'something4']
-    [simple     uint 16  'something5']
-    [reserved   uint 32  '0x0000']
-    [simple     uint 16  'something6']
-    [reserved   uint 32  '0x0000']
-    [reserved   uint 32  '0x00000000']
-    [reserved   uint 32  '0x00000000']
+[enum uint 8 'Operation'
+    ['0x01' DISCOVERY]
+    ['0x06' ROUTE    ]
+]
+
+[enum uint 8 'Direction'
+    ['0x00' REQUEST ]
+    ['0x80' RESPONSE]
+]
+
+[discriminatedType 'AdsDiscovery'
+    [const uint 32 'header' '0x03661471L']
+    [reserved   uint 32  '0x00000000L']
+    [enum Operation 'operation']
     [reserved   uint 16  '0x0000']
-    [implicit   uint 16  'ipLength' 'COUNT(ip)']
-    [array      int 8    'ip' COUNT 'ipLength']
+    [enum Direction 'direction']
+    [typeSwitch 'operation', 'direction'
+        ['Operation.DISCOVERY', 'Direction.REQUEST' DiscoveryRequest
+            [simple AmsNetId 'amsNetId']
+            [reserved uint 16 '0x1027']
+            [reserved uint 32 '0x00000000L']
+        ]
+        ['Operation.DISCOVERY', 'Direction.RESPONSE' DiscoveryResponse
+            [simple AmsNetId 'amsNetId']
+            [reserved uint 16 '0x1027']
+            [reserved uint 16 '0x0400']
+            [reserved uint 32 '0x00000500L']
+        ]
+        ['Operation.ROUTE', 'Direction.REQUEST' RouteRequest
+            [simple     AmsNetId 'sender']
+            [reserved   uint 16  '0x1027']
+            [reserved   uint 16  '0x0500']
+            [reserved   uint 24  '0x0C00']
+            [simple AmsMagicString 'ip' ]
+            [reserved   uint 16 '0x0007']
+            [implicit   uint 8 'amsSize' 'target.lengthInBytes']
+            [simple AmsNetId 'target']
+            [const uint 16 'usernamePrefix' '0x000D']
+            [simple AmsMagicString 'username']
+            [const uint 16 'passwordPrefix' '0x0002']
+            [simple AmsMagicString 'password']
+            [const uint 16 'routePrefix' '0x0005']
+            [simple AmsMagicString 'routeName']
+
+        ]
+        ['Operation.ROUTE', 'Direction.RESPONSE' RouteResponse
+            [simple AmsNetId 'amsNetId']
+            [reserved uint 16 '0x1027']
+            [reserved uint 16 '0x0100']
+            [reserved uint 32 '0x00000100']
+            [enum RouteStatus 'status']
+            [reserved uint 24 '0x000000']
+        ]
+    ]
+]
+
+[enum uint 24 'RouteStatus'
+    ['0x040000' SUCCESS]
+    ['0x000407' FAILURE]
 ]
 
+[type 'AmsMagicString'
+    [implicit uint 8 'len' 'COUNT(text)']
+    [reserved uint 8 '0x00']
+    [array int 8 'text' COUNT 'len']
+    [reserved uint 8 '0x00']
+]
+
+[type 'IPv4Address'
+    [simple     uint        8   'octet1'            ]
+    [simple     uint        8   'octet2'            ]
+    [simple     uint        8   'octet3'            ]
+    [simple     uint        8   'octet4'            ]
+]
+
+
 [type 'AmsNetId'
     [simple     uint        8   'octet1'            ]
     [simple     uint        8   'octet2'            ]