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 d610b0a6ff098ee02b8220db6a6d1dcdf0ae36f1 Author: Christofer Dutz <[email protected]> AuthorDate: Wed Aug 24 08:52:59 2022 +0200 chore(protocols/plc4x-api): Added a new "protocol" for keeping track of the API types (PlcValueType, PlcResponseCode, PlcSubscriptionType) --- protocols/plc4x-api/pom.xml | 43 +++++++++++ .../plc4x/protocol/plc4xapi/v0/Plc4xApi.java | 57 ++++++++++++++ ...e.plc4x.plugins.codegenerator.protocol.Protocol | 19 +++++ .../protocols/plc4xapi/v0/plc4x-api.mspec | 87 ++++++++++++++++++++++ .../protocol/plc4xapi/v0/Plc4xProtocolTest.java | 38 ++++++++++ .../plc4x-api/src/test/resources/logback-test.xml | 36 +++++++++ protocols/pom.xml | 1 + 7 files changed, 281 insertions(+) diff --git a/protocols/plc4x-api/pom.xml b/protocols/plc4x-api/pom.xml new file mode 100644 index 000000000..9918c2804 --- /dev/null +++ b/protocols/plc4x-api/pom.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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 + + https://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. + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.plc4x</groupId> + <artifactId>plc4x-protocols</artifactId> + <version>0.10.0-SNAPSHOT</version> + </parent> + + <artifactId>plc4x-protocols-plc4x-api</artifactId> + + <name>Protocols: PLC4X (API)</name> + <description>General purpose API types</description> + + <dependencies> + <dependency> + <groupId>org.apache.plc4x</groupId> + <artifactId>plc4x-code-generation-protocol-base-mspec</artifactId> + <version>0.10.0-SNAPSHOT</version> + </dependency> + </dependencies> + +</project> \ No newline at end of file diff --git a/protocols/plc4x-api/src/main/java/org/apache/plc4x/protocol/plc4xapi/v0/Plc4xApi.java b/protocols/plc4x-api/src/main/java/org/apache/plc4x/protocol/plc4xapi/v0/Plc4xApi.java new file mode 100644 index 000000000..6e33d85cd --- /dev/null +++ b/protocols/plc4x-api/src/main/java/org/apache/plc4x/protocol/plc4xapi/v0/Plc4xApi.java @@ -0,0 +1,57 @@ +/* + * 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 + * + * https://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.plc4xapi.v0; + +import org.apache.plc4x.plugins.codegenerator.language.mspec.parser.MessageFormatParser; +import org.apache.plc4x.plugins.codegenerator.language.mspec.protocol.ProtocolHelpers; +import org.apache.plc4x.plugins.codegenerator.language.mspec.protocol.ValidatableTypeContext; +import org.apache.plc4x.plugins.codegenerator.protocol.Protocol; +import org.apache.plc4x.plugins.codegenerator.protocol.TypeContext; +import org.apache.plc4x.plugins.codegenerator.types.exceptions.GenerationException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Optional; + +public class Plc4xApi implements Protocol, ProtocolHelpers { + + private static final Logger LOGGER = LoggerFactory.getLogger(Plc4xApi.class); + + @Override + public String getName() { + return "plc4x-api"; + } + + @Override + public Optional<String> getVersion() { + return Optional.of("0"); + } + + @Override + public TypeContext getTypeContext() throws GenerationException { + ValidatableTypeContext typeContext; + + LOGGER.info("Parsing: plc4x-api.mspec"); + typeContext = new MessageFormatParser().parse(getMspecStream()); + + typeContext.validate(); + return typeContext; + } + +} diff --git a/protocols/plc4x-api/src/main/resources/META-INF/services/org.apache.plc4x.plugins.codegenerator.protocol.Protocol b/protocols/plc4x-api/src/main/resources/META-INF/services/org.apache.plc4x.plugins.codegenerator.protocol.Protocol new file mode 100644 index 000000000..fb606ee83 --- /dev/null +++ b/protocols/plc4x-api/src/main/resources/META-INF/services/org.apache.plc4x.plugins.codegenerator.protocol.Protocol @@ -0,0 +1,19 @@ +# +# 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 +# +# https://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. +# +org.apache.plc4x.protocol.plc4xapi.v0.Plc4xApi diff --git a/protocols/plc4x-api/src/main/resources/protocols/plc4xapi/v0/plc4x-api.mspec b/protocols/plc4x-api/src/main/resources/protocols/plc4xapi/v0/plc4x-api.mspec new file mode 100644 index 000000000..6d5a53f66 --- /dev/null +++ b/protocols/plc4x-api/src/main/resources/protocols/plc4xapi/v0/plc4x-api.mspec @@ -0,0 +1,87 @@ +/* + * 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 + * + * https://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. + */ + +[enum uint 8 PlcResponseCode + ['0x01' OK ] + ['0x02' NOT_FOUND ] + ['0x03' ACCESS_DENIED ] + ['0x04' INVALID_ADDRESS ] + ['0x06' INVALID_DATATYPE] + ['0x07' INVALID_DATA ] + ['0x08' INTERNAL_ERROR ] + ['0x09' REMOTE_BUSY ] + ['0x0A' REMOTE_ERROR ] + ['0x0B' UNSUPPORTED ] + ['0x0C' RESPONSE_PENDING] +] + +[enum uint 8 PlcValueType + ['0x00' NULL ] + + // Bit Strings + ['0x01' BOOL ] + ['0x02' BYTE ] + ['0x03' WORD ] + ['0x04' DWORD ] + ['0x05' LWORD ] + + // Unsigned Integers + ['0x11' USINT ] + ['0x12' UINT ] + ['0x13' UDINT ] + ['0x14' ULINT ] + + // Signed Integers + ['0x21' SINT ] + ['0x22' INT ] + ['0x23' DINT ] + ['0x24' LINT ] + + // Floating Point Values + ['0x31' REAL ] + ['0x32' LREAL ] + + // Chars and Strings + ['0x41' CHAR ] + ['0x42' WCHAR ] + ['0x43' STRING ] + ['0x44' WSTRING ] + + // Times and Dates + ['0x51' TIME ] + ['0x52' LTIME ] + ['0x53' DATE ] + ['0x54' LDATE ] + ['0x55' TIME_OF_DAY ] + ['0x56' LTIME_OF_DAY ] + ['0x57' DATE_AND_TIME ] + ['0x58' LDATE_AND_TIME] + + // Complex types + ['0x61' Struct ] + ['0x62' List ] + + ['0x71' RAW_BYTE_ARRAY] +] + +[enum uint 8 PlcSubscriptionType + ['0x01' CYCLIC ] + ['0x02' CHANGE_OF_STATE] + ['0x03' EVENT ] +] \ No newline at end of file diff --git a/protocols/plc4x-api/src/test/java/org/apache/plc4x/protocol/plc4xapi/v0/Plc4xProtocolTest.java b/protocols/plc4x-api/src/test/java/org/apache/plc4x/protocol/plc4xapi/v0/Plc4xProtocolTest.java new file mode 100644 index 000000000..19e305321 --- /dev/null +++ b/protocols/plc4x-api/src/test/java/org/apache/plc4x/protocol/plc4xapi/v0/Plc4xProtocolTest.java @@ -0,0 +1,38 @@ +/* + * 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 + * + * https://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.plc4xapi.v0; + +import org.apache.plc4x.plugins.codegenerator.protocol.TypeContext; +import org.apache.plc4x.protocol.plc4xapi.v0.Plc4xApi; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; + +class Plc4xProtocolTest { + + @Test + void getTypeContext() throws Exception { + TypeContext typeContext = new Plc4xApi().getTypeContext(); + assertNotNull(typeContext); + assertNotNull(typeContext.getUnresolvedTypeReferences()); + assertSame(0, typeContext.getUnresolvedTypeReferences().size()); + } + +} diff --git a/protocols/plc4x-api/src/test/resources/logback-test.xml b/protocols/plc4x-api/src/test/resources/logback-test.xml new file mode 100644 index 000000000..cc4250b21 --- /dev/null +++ b/protocols/plc4x-api/src/test/resources/logback-test.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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 + + https://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. + --> +<configuration xmlns="http://ch.qos.logback/xml/ns/logback" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://ch.qos.logback/xml/ns/logback + https://raw.githubusercontent.com/enricopulatzo/logback-XSD/master/src/main/xsd/logback.xsd"> + + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> + </encoder> + </appender> + + <root level="info"> + <appender-ref ref="STDOUT" /> + </root> + +</configuration> \ No newline at end of file diff --git a/protocols/pom.xml b/protocols/pom.xml index 34d650b49..d2e882a0d 100644 --- a/protocols/pom.xml +++ b/protocols/pom.xml @@ -48,6 +48,7 @@ <module>mqtt</module> <module>opcua</module> <module>plc4x</module> + <module>plc4x-api</module> <module>profinet</module> <module>s7</module> <module>simulated</module>
