This is an automated email from the ASF dual-hosted git repository.
cgarcia pushed a commit to branch feature/merlot
in repository https://gitbox.apache.org/repos/asf/plc4x-extras.git
The following commit(s) were added to refs/heads/feature/merlot by this push:
new f98cfde FIx PlcModel por simulated driver.
f98cfde is described below
commit f98cfdecded0345e1291349b5efdc5d883e0cb8f
Author: César García <[email protected]>
AuthorDate: Mon Dec 8 08:31:48 2025 -0400
FIx PlcModel por simulated driver.
---
.../impl/MerlotDataBrowserSupportImpl.java | 39 +-
.../OSGI-INF/blueprint/decanter-service.xml | 2 +-
.../org.apache.plc4x.merlot.das.api/.classpath | 14 +-
.../.settings/org.eclipse.jdt.core.prefs | 6 +-
.../plc4x/merlot/api/PlcGeneralFunction.java | 4 +
.../plc4x/merlot/api/core/PlcStaticHelper.java | 591 +++++++++++++++++++++
.../merlot/api/impl/PlcGeneralFunctionImpl.java | 39 +-
.../apache/plc4x/merlot/api/impl/PlcItemImpl.java | 36 +-
.../plc4x/merlot/api/impl/PlcSecureBootImpl.java | 19 +-
.../src/main/resources/proto/EPICSEvent.proto | 228 ++++++++
.../merlot/org.apache.plc4x.merlot.db/.classpath | 2 +-
.../.settings/org.eclipse.jdt.core.prefs | 6 +-
.../org/apache/plc4x/merlot/db/api/DBRecord.java | 18 +
.../plc4x/merlot/db/core/DBBooleanFactory.java | 28 +-
.../apache/plc4x/merlot/db/core/DBByteFactory.java | 28 +-
.../plc4x/merlot/db/core/DBDoubleFactory.java | 32 +-
.../plc4x/merlot/db/core/DBFloatFactory.java | 34 +-
.../apache/plc4x/merlot/db/core/DBIntFactory.java | 30 +-
.../apache/plc4x/merlot/db/core/DBLongFactory.java | 32 +-
.../plc4x/merlot/db/core/DBShortFactory.java | 24 +-
.../plc4x/merlot/db/core/DBStringFactory.java | 24 +-
.../plc4x/merlot/db/core/DBUByteFactory.java | 30 +-
.../apache/plc4x/merlot/db/core/DBUIntFactory.java | 30 +-
.../plc4x/merlot/db/core/DBULongFactory.java | 30 +-
.../plc4x/merlot/db/core/DBUShortFactory.java | 30 +-
.../plc4x/merlot/drv/s7/impl/S7PlcModelImpl.java | 100 ++--
.../merlot/drv/s7/impl/S7PlcTagFunctionImpl.java | 2 +-
.../merlot/drv/s7/core/S7DBAiFactoryTest.java | 210 ++++++++
.../merlot/drv/s7/core/S7DBAoFactoryTest.java | 178 +++++++
.../org.apache.plc4x.merlot.drv.simulated/pom.xml | 5 +
.../impl/SimulatedPlcModelFactoryImpl.java | 42 ++
.../drv/simulated/impl/SimulatedPlcModelImpl.java | 172 ++++++
.../impl/SimulatedPlcTagFunctionImpl.java | 125 ++++-
.../OSGI-INF/blueprint/simulated-drv-service.xml | 18 +-
34 files changed, 1785 insertions(+), 423 deletions(-)
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.archive/src/main/java/org/apache/plc4x/merlot/archiver/impl/MerlotDataBrowserSupportImpl.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.archive/src/main/java/org/apache/plc4x/merlot/archiver/impl/MerlotDataBrowserSupportImpl.java
index 5728ae1..9de2a10 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.archive/src/main/java/org/apache/plc4x/merlot/archiver/impl/MerlotDataBrowserSupportImpl.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.archive/src/main/java/org/apache/plc4x/merlot/archiver/impl/MerlotDataBrowserSupportImpl.java
@@ -52,10 +52,11 @@ public class MerlotDataBrowserSupportImpl extends
MerlotPvHtcCollectorImpl {
try {
server = HttpServer.create(new InetSocketAddress(2000), 0);
// Create a context for a specific path and set the handler
- server.createContext("/request/bpl/searchForPVsRegex", new
MyHandler());
+ server.createContext("/retrieval/bpl/searchForPVsRegex", new
MyHandler());
+ server.createContext("/retrieval/data/getData.raw", new
MyHandler2());
server.setExecutor(null); // Use the default executor
server.start();
- System.out.println("Server is running on port 8000");
+ System.out.println("Server is running on port 2000");
} catch (IOException e) {
System.out.println("Error starting the server: " + e.getMessage());
}
@@ -82,6 +83,14 @@ public class MerlotDataBrowserSupportImpl extends
MerlotPvHtcCollectorImpl {
throw new UnsupportedOperationException("Not supported yet.");
}
+ public void StartServer(){
+
+ }
+
+ public void StopServer(){
+
+ }
+
// Define a custom HttpHandler
@@ -90,15 +99,31 @@ public class MerlotDataBrowserSupportImpl extends
MerlotPvHtcCollectorImpl {
public void handle(HttpExchange exchange) throws IOException
{
// Handle the request
- System.out.println("Protocol: " + exchange.getProtocol());
- System.out.println("Method : " + exchange.getRequestMethod());
- System.out.println("URI : " +
exchange.getRequestURI().toString());
- String response = "uno\ndos\ntres";
+ System.out.println("3 Protocol: " + exchange.getProtocol());
+ System.out.println("3 Method : " + exchange.getRequestMethod());
+ System.out.println("3 URI : " +
exchange.getRequestURI().toString());
+ String response = "uno\r\ndos\r\ntres\r\n ";
+ exchange.sendResponseHeaders(200, response.length());
+ OutputStream os = exchange.getResponseBody();
+ os.write(response.getBytes());
+ os.close();
+ }
+ }
+
+ static class MyHandler2 implements HttpHandler {
+ @Override
+ public void handle(HttpExchange exchange) throws IOException
+ {
+ // Handle the request
+ System.out.println("4 Protocol: " + exchange.getProtocol());
+ System.out.println("4 Method : " + exchange.getRequestMethod());
+ System.out.println("4 URI : " +
exchange.getRequestURI().toString());
+ String response = "uno\r\ndos\r\ntres\r\n ";
exchange.sendResponseHeaders(200, response.length());
OutputStream os = exchange.getResponseBody();
os.write(response.getBytes());
os.close();
}
- }
+ }
}
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.archive/src/main/resources/OSGI-INF/blueprint/decanter-service.xml
b/plc4j/tools/merlot/org.apache.plc4x.merlot.archive/src/main/resources/OSGI-INF/blueprint/decanter-service.xml
index 92915b4..f8f3ce7 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.archive/src/main/resources/OSGI-INF/blueprint/decanter-service.xml
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.archive/src/main/resources/OSGI-INF/blueprint/decanter-service.xml
@@ -69,7 +69,7 @@
<bean id="MerlotDataBrowserSupportImplBean"
class="org.apache.plc4x.merlot.archiver.impl.MerlotDataBrowserSupportImpl"
- init-method="init"
+ init-method="start"
scope="singleton"
activation="eager">
<argument ref="refSchedulerService" />
diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/.classpath
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/.classpath
index 653dfd7..9d1f50a 100644
--- a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/.classpath
+++ b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/.classpath
@@ -26,7 +26,7 @@
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
- <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-18">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@@ -44,6 +44,18 @@
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
+ <classpathentry kind="src" output="target/classes"
path="target/generated-sources/protobuf/java">
+ <attributes>
+ <attribute name="optional" value="true"/>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="src" output="target/classes"
path="target/generated-sources/protobuf/grpc-java">
+ <attributes>
+ <attribute name="optional" value="true"/>
+ <attribute name="maven.pomderived" value="true"/>
+ </attributes>
+ </classpathentry>
<classpathentry kind="src" output="target/test-classes"
path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/.settings/org.eclipse.jdt.core.prefs
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/.settings/org.eclipse.jdt.core.prefs
index 1b6e1ef..7127a22 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/.settings/org.eclipse.jdt.core.prefs
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/.settings/org.eclipse.jdt.core.prefs
@@ -1,9 +1,9 @@
eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
-org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=18
+org.eclipse.jdt.core.compiler.compliance=18
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
-org.eclipse.jdt.core.compiler.source=1.8
+org.eclipse.jdt.core.compiler.source=18
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcGeneralFunction.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcGeneralFunction.java
index 4cd873e..f8d60d4 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcGeneralFunction.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcGeneralFunction.java
@@ -96,6 +96,8 @@ public interface PlcGeneralFunction extends PlcFunction {
*/
public PlcDevice getPlcDevice(UUID device_uid);
+ public Optional<PlcDevice> getPlcItemDevice(UUID item_uid);
+
/*
* Returns the metadata associated with the device, according to
* chapter 141 Device Abstraction Layer Specification
@@ -219,6 +221,8 @@ public interface PlcGeneralFunction extends PlcFunction {
*/
public Map<UUID, String> getPlcGroupItems(UUID group_uid);
+ public Optional<PlcGroup> getPlcItemGroup(UUID item_uid);
+
/*
* Returns the PlcItem associated with the name.
* org.apache.plc4x.java.api.types.PlcValueType.
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/core/PlcStaticHelper.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/core/PlcStaticHelper.java
new file mode 100644
index 0000000..d287890
--- /dev/null
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/core/PlcStaticHelper.java
@@ -0,0 +1,591 @@
+/*
+ * 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.merlot.api.core;
+
+import io.netty.buffer.ByteBuf;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import org.apache.plc4x.java.api.types.PlcValueType;
+import static org.apache.plc4x.java.api.types.PlcValueType.BOOL;
+import static org.apache.plc4x.java.api.types.PlcValueType.BYTE;
+import static org.apache.plc4x.java.api.types.PlcValueType.CHAR;
+import static org.apache.plc4x.java.api.types.PlcValueType.DATE;
+import static org.apache.plc4x.java.api.types.PlcValueType.DATE_AND_LTIME;
+import static org.apache.plc4x.java.api.types.PlcValueType.DATE_AND_TIME;
+import static org.apache.plc4x.java.api.types.PlcValueType.DINT;
+import static org.apache.plc4x.java.api.types.PlcValueType.DWORD;
+import static org.apache.plc4x.java.api.types.PlcValueType.INT;
+import static org.apache.plc4x.java.api.types.PlcValueType.LDATE;
+import static org.apache.plc4x.java.api.types.PlcValueType.LDATE_AND_TIME;
+import static org.apache.plc4x.java.api.types.PlcValueType.LINT;
+import static org.apache.plc4x.java.api.types.PlcValueType.LREAL;
+import static org.apache.plc4x.java.api.types.PlcValueType.LTIME;
+import static org.apache.plc4x.java.api.types.PlcValueType.LTIME_OF_DAY;
+import static org.apache.plc4x.java.api.types.PlcValueType.LWORD;
+import static org.apache.plc4x.java.api.types.PlcValueType.List;
+import static org.apache.plc4x.java.api.types.PlcValueType.NULL;
+import static org.apache.plc4x.java.api.types.PlcValueType.RAW_BYTE_ARRAY;
+import static org.apache.plc4x.java.api.types.PlcValueType.REAL;
+import static org.apache.plc4x.java.api.types.PlcValueType.SINT;
+import static org.apache.plc4x.java.api.types.PlcValueType.STRING;
+import static org.apache.plc4x.java.api.types.PlcValueType.Struct;
+import static org.apache.plc4x.java.api.types.PlcValueType.TIME;
+import static org.apache.plc4x.java.api.types.PlcValueType.TIME_OF_DAY;
+import static org.apache.plc4x.java.api.types.PlcValueType.UDINT;
+import static org.apache.plc4x.java.api.types.PlcValueType.UINT;
+import static org.apache.plc4x.java.api.types.PlcValueType.ULINT;
+import static org.apache.plc4x.java.api.types.PlcValueType.USINT;
+import static org.apache.plc4x.java.api.types.PlcValueType.WCHAR;
+import static org.apache.plc4x.java.api.types.PlcValueType.WORD;
+import static org.apache.plc4x.java.api.types.PlcValueType.WSTRING;
+import org.apache.plc4x.java.api.value.PlcValue;
+import org.apache.plc4x.java.spi.values.PlcBOOL;
+import org.apache.plc4x.java.spi.values.PlcBYTE;
+import org.apache.plc4x.java.spi.values.PlcCHAR;
+import org.apache.plc4x.java.spi.values.PlcDINT;
+import org.apache.plc4x.java.spi.values.PlcDWORD;
+import org.apache.plc4x.java.spi.values.PlcINT;
+import org.apache.plc4x.java.spi.values.PlcLINT;
+import org.apache.plc4x.java.spi.values.PlcLREAL;
+import org.apache.plc4x.java.spi.values.PlcLWORD;
+import org.apache.plc4x.java.spi.values.PlcList;
+import org.apache.plc4x.java.spi.values.PlcREAL;
+import org.apache.plc4x.java.spi.values.PlcSINT;
+import org.apache.plc4x.java.spi.values.PlcUDINT;
+import org.apache.plc4x.java.spi.values.PlcUINT;
+import org.apache.plc4x.java.spi.values.PlcULINT;
+import org.apache.plc4x.java.spi.values.PlcUSINT;
+import org.apache.plc4x.java.spi.values.PlcWCHAR;
+import org.apache.plc4x.java.spi.values.PlcWORD;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author cgarcia
+ */
+public class PlcStaticHelper {
+
+ private static final Logger LOGGER =
LoggerFactory.getLogger(PlcStaticHelper.class);
+
+ /*
+ *
+ *
+ */
+ public static Optional<PlcValue> ByteBufToPlcValue(ByteBuf byteBuf,
PlcValueType dataType) {
+ short tempValue = 0;
+ List<PlcValue> values = null;
+ Integer numberOfValues = 0;
+ byteBuf.resetReaderIndex();
+ switch (dataType) {
+ case NULL: return Optional.empty();
+
+ case BOOL:
+ numberOfValues = byteBuf.capacity();
+ if (numberOfValues == 1) {
+ return Optional.of(new
PlcBOOL(byteBuf.readBoolean()));
+ } else {
+ values = new ArrayList<>(numberOfValues);
+ for (int i=0; i < numberOfValues; i++){
+ values.add(new PlcBOOL(byteBuf.readBoolean()));
+ }
+ }
+ break;
+ case BYTE:
+ numberOfValues = byteBuf.capacity();
+ if (numberOfValues == 1) {
+ return Optional.of(new
PlcBYTE(byteBuf.readByte()));
+ } else {
+ values = new ArrayList<>(numberOfValues);
+ for (int i=0; i < numberOfValues; i++){
+ values.add(new PlcBYTE(byteBuf.readByte()));
+ }
+ }
+ break;
+ case SINT:
+ numberOfValues = byteBuf.capacity();
+ if (numberOfValues == 1) {
+ return Optional.of(new
PlcSINT(byteBuf.readByte()));
+ } else {
+ values = new ArrayList<>(numberOfValues);
+ for (int i=0; i < numberOfValues; i++){
+ values.add(new PlcSINT(byteBuf.readByte()));
+ }
+ }
+ break;
+ case USINT:
+ numberOfValues = byteBuf.capacity();
+ if (numberOfValues == 1) {
+ return Optional.of(new
PlcUSINT(byteBuf.readByte()));
+ } else {
+ values = new ArrayList<>(numberOfValues);
+ for (int i=0; i < numberOfValues; i++){
+ values.add(new PlcUSINT(byteBuf.readByte()));
+ }
+ }
+ break;
+ case INT:
+ numberOfValues = byteBuf.capacity() / Short.BYTES;
+ if (numberOfValues == 1) {
+ return Optional.of(new
PlcINT(byteBuf.readShort()));
+ } else {
+ values = new ArrayList<>(numberOfValues);
+ for (int i=0; i < numberOfValues; i++){
+ values.add(new PlcINT(byteBuf.readShort()));
+ }
+ }
+ break;
+ case UINT:
+ numberOfValues = byteBuf.capacity() / Short.BYTES;
+ if (numberOfValues == 1) {
+ return Optional.of(new
PlcUINT(byteBuf.readShort()));
+ } else {
+ values = new ArrayList<>(numberOfValues);
+ for (int i=0; i < numberOfValues; i++){
+ values.add(new PlcUINT(byteBuf.readShort()));
+ }
+ }
+ break;
+ case WORD:
+ numberOfValues = byteBuf.capacity() / Short.BYTES;
+ if (numberOfValues == 1) {
+ return Optional.of(new
PlcWORD(byteBuf.readShort()));
+ } else {
+ values = new ArrayList<>(numberOfValues);
+ for (int i=0; i < numberOfValues; i++){
+ values.add(new PlcWORD(byteBuf.readShort()));
+ }
+ }
+ break;
+ case DINT:
+ numberOfValues = byteBuf.capacity() / Integer.BYTES;
+ if (numberOfValues == 1) {
+ return Optional.of(new PlcDINT(byteBuf.readInt()));
+ } else {
+ values = new ArrayList<>(numberOfValues);
+ for (int i=0; i < numberOfValues; i++){
+ values.add(new PlcDINT(byteBuf.readInt()));
+ }
+ }
+ break;
+
+ case UDINT:
+ numberOfValues = byteBuf.capacity() / Integer.BYTES;
+ if (numberOfValues == 1) {
+ return Optional.of(new
PlcUDINT(byteBuf.readInt()));
+ } else {
+ values = new ArrayList<>(numberOfValues);
+ for (int i=0; i < numberOfValues; i++){
+ values.add(new PlcUDINT(byteBuf.readInt()));
+ }
+ }
+ break;
+ case DWORD:
+ numberOfValues = byteBuf.capacity() / Integer.BYTES;
+ if (numberOfValues == 1) {
+ return Optional.of(new
PlcDWORD(byteBuf.readInt()));
+ } else {
+ values = new ArrayList<>(numberOfValues);
+ for (int i=0; i < numberOfValues; i++){
+ values.add(new PlcDWORD(byteBuf.readInt()));
+ }
+ }
+ break;
+ case LINT:
+ numberOfValues = byteBuf.capacity() / Long.BYTES;
+ if (numberOfValues == 1) {
+ return Optional.of(new
PlcLINT(byteBuf.readLong()));
+ } else {
+ values = new ArrayList<>(numberOfValues);
+ for (int i=0; i < numberOfValues; i++){
+ values.add(new PlcLINT(byteBuf.readLong()));
+ }
+ }
+ break;
+ case ULINT:
+ numberOfValues = byteBuf.capacity() / Long.BYTES;
+ if (numberOfValues == 1) {
+ return Optional.of(new
PlcULINT(byteBuf.readLong()));
+ } else {
+ values = new ArrayList<>(numberOfValues);
+ for (int i=0; i < numberOfValues; i++){
+ values.add(new PlcULINT(byteBuf.readLong()));
+ }
+ }
+ break;
+ case LWORD:
+ numberOfValues = byteBuf.capacity() / Long.BYTES;
+ if (numberOfValues == 1) {
+ return Optional.of(new
PlcLWORD(byteBuf.readLong()));
+ } else {
+ values = new ArrayList<>(numberOfValues);
+ for (int i=0; i < numberOfValues; i++){
+ values.add(new PlcLWORD(byteBuf.readLong()));
+ }
+ }
+ break;
+ case REAL:
+ numberOfValues = byteBuf.capacity() / Float.BYTES;
+ if (numberOfValues == 1) {
+ return Optional.of(new
PlcREAL(byteBuf.readFloat()));
+ } else {
+ values = new ArrayList<>(numberOfValues);
+ for (int i=0; i < numberOfValues; i++){
+ values.add(new PlcLREAL(byteBuf.readFloat()));
+ }
+ }
+ break;
+ case LREAL:
+ numberOfValues = byteBuf.capacity() / Double.BYTES;
+ if (numberOfValues == 1) {
+ return Optional.of(new
PlcLREAL(byteBuf.readDouble()));
+ } else {
+ values = new ArrayList<>(numberOfValues);
+ for (int i=0; i < numberOfValues; i++){
+ values.add(new PlcLREAL(byteBuf.readDouble()));
+ }
+ }
+ break;
+ case CHAR:
+ numberOfValues = byteBuf.capacity();
+ if (numberOfValues == 1) {
+ return Optional.of(new
PlcCHAR(byteBuf.readChar()));
+ } else {
+ values = new ArrayList<>(numberOfValues);
+ for (int i=0; i < numberOfValues; i++){
+ values.add(new PlcCHAR(byteBuf.readChar()));
+ }
+ }
+ break;
+ case WCHAR:
+ numberOfValues = byteBuf.capacity() / Short.BYTES;
+ if (numberOfValues == 1) {
+ return Optional.of(new
PlcWCHAR(byteBuf.readShort()));
+ } else {
+ values = new ArrayList<>(numberOfValues);
+ for (int i=0; i < numberOfValues; i++){
+ values.add(new PlcWCHAR(byteBuf.readShort()));
+ }
+ }
+ break;
+ case STRING:
+ case WSTRING:
+ case TIME:
+ case LTIME:
+ case DATE:
+ case LDATE:
+ case TIME_OF_DAY:
+ case LTIME_OF_DAY:
+ case DATE_AND_TIME:
+ case DATE_AND_LTIME:
+ case LDATE_AND_TIME:
+ case Struct:
+ case List:
+ case RAW_BYTE_ARRAY:
+ default:;
+ }
+
+ if (null == values) {
+ return Optional.empty();
+ }
+ return Optional.of(new PlcList(values));
+ }
+
+ /*
+ *
+ *
+ */
+ public static void PlcValueToByteBuf(ByteBuf byteBuf, PlcValue value,
PlcValueType dataType){
+ Integer numberOfValues = 0;
+ PlcValueType valueType = null;
+ PlcList plcList = null;
+ if (value instanceof PlcList){
+ plcList = (PlcList) value;
+ valueType = plcList.getIndex(0).getPlcValueType();
+ numberOfValues = ((PlcList) value).getLength();
+ } else {
+ valueType = value.getPlcValueType();
+ numberOfValues = 1;
+ }
+ byteBuf.resetReaderIndex();
+ switch (valueType) {
+ case NULL: break;
+
+ case BOOL:
+ if (numberOfValues == 1) {
+ byteBuf.writeBoolean(value.getBoolean());
+ } else {
+ for (int i=0; i < numberOfValues; i++){
+
byteBuf.writeBoolean(plcList.getIndex(i).getBoolean());
+ }
+ }
+ break;
+ case BYTE:
+ case SINT:
+ case USINT:
+ if (numberOfValues == 1) {
+ byteBuf.writeByte(value.getByte());
+ } else {
+ for (int i=0; i < numberOfValues; i++){
+
byteBuf.writeByte(plcList.getIndex(i).getByte());
+ }
+ }
+ break;
+ case INT:
+ case UINT:
+ case WORD:
+ if (numberOfValues == 1) {
+ byteBuf.writeShort(value.getShort());
+ } else {
+ for (int i=0; i < numberOfValues; i++){
+
byteBuf.writeShort(plcList.getIndex(i).getShort());
+ }
+ }
+ break;
+ case DINT:
+ case UDINT:
+ case DWORD:
+ if (numberOfValues == 1) {
+ byteBuf.writeInt(value.getInt());
+ } else {
+ for (int i=0; i < numberOfValues; i++){
+ byteBuf.writeInt(plcList.getIndex(i).getInt());
+ }
+ }
+ break;
+ case LINT:
+ case ULINT:
+ case LWORD:
+ if (numberOfValues == 1) {
+ byteBuf.writeLong(value.getLong());
+ } else {
+ for (int i=0; i < numberOfValues; i++){
+
byteBuf.writeLong(plcList.getIndex(i).getLong());
+ }
+ }
+ break;
+ case REAL:
+ if (numberOfValues == 1) {
+ byteBuf.writeFloat(value.getFloat());
+ } else {
+ for (int i=0; i < numberOfValues; i++){
+
byteBuf.writeFloat(plcList.getIndex(i).getFloat());
+ }
+ }
+ break;
+ case LREAL:
+ if (numberOfValues == 1) {
+ byteBuf.writeDouble(value.getDouble());
+ } else {
+ for (int i=0; i < numberOfValues; i++){
+
byteBuf.writeDouble(plcList.getIndex(i).getDouble());
+ }
+ }
+ break;
+ case CHAR:
+ if (numberOfValues == 1) {
+ byteBuf.writeChar(value.getByte());
+ } else {
+ for (int i=0; i < numberOfValues; i++){
+
byteBuf.writeChar(plcList.getIndex(i).getByte());
+ }
+ }
+ break;
+ case WCHAR:
+ if (numberOfValues == 1) {
+ byteBuf.writeShort(value.getShort());
+ } else {
+ for (int i=0; i < numberOfValues; i++){
+
byteBuf.writeShort(plcList.getIndex(i).getShort());
+ }
+ }
+ break;
+ case STRING:
+ case WSTRING:
+ case TIME:
+ case LTIME:
+ case DATE:
+ case LDATE:
+ case TIME_OF_DAY:
+ case LTIME_OF_DAY:
+ case DATE_AND_TIME:
+ case DATE_AND_LTIME:
+ case LDATE_AND_TIME:
+ case Struct:
+ case List:
+ case RAW_BYTE_ARRAY:
+ default:;
+ }
+ }
+
+ /*
+ *
+ *
+ */
+ public static void WritePlcValue(ByteBuf byteBuf, PlcValue value, int
index) {
+ Integer byteIndex = 0;
+ PlcValueType valueType = null;
+ PlcList plcList = null;
+ if (value instanceof PlcList){
+ plcList = (PlcList) value;
+ byteIndex = index * getPlcValueLength(plcList.getIndex(0));
+ for (PlcValue plcValue:value.getList()) {
+ byteBuf.writeBytes(plcValue.getRaw(), byteIndex,
plcValue.getRaw().length);
+ }
+ } else {
+ byteIndex = index * getPlcValueLength(value);
+ byteBuf.writeBytes(value.getRaw(), byteIndex,
value.getRaw().length);
+ }
+
+ }
+
+ /*
+ *
+ *
+ */
+ public static Optional<PlcValue> ReadPlcValue(ByteBuf byteBuf,
PlcValueType valueType, int index){
+ int byteIndex = 0 ;
+ Integer numberOfValues = 0;
+
+ switch (valueType) {
+ case NULL: break;
+
+ case BOOL: return Optional.of(new
PlcBOOL(byteBuf.getBoolean(index)));
+
+ case BYTE: return Optional.of(new
PlcBYTE(byteBuf.getByte(index)));
+ case SINT: return Optional.of(new
PlcSINT(byteBuf.getByte(index)));
+ case USINT: return Optional.of(new
PlcUSINT(byteBuf.getByte(index)));
+
+ case INT: return Optional.of(new PlcINT(byteBuf.getShort(index *
Short.BYTES)));
+ case UINT: return Optional.of(new PlcUINT(byteBuf.getShort(index
* Short.BYTES)));
+ case WORD: return Optional.of(new PlcWORD(byteBuf.getShort(index
* Short.BYTES)));
+
+ case DINT: return Optional.of(new PlcDINT(byteBuf.getInt(index *
Integer.BYTES)));
+ case UDINT: return Optional.of(new PlcUDINT(byteBuf.getInt(index *
Integer.BYTES)));
+ case DWORD: return Optional.of(new PlcDWORD(byteBuf.getInt(index *
Integer.BYTES)));
+
+ case LINT: return Optional.of(new PlcLINT(byteBuf.getLong(index *
Long.BYTES)));
+ case ULINT: return Optional.of(new PlcULINT(byteBuf.getLong(index
* Long.BYTES)));
+ case LWORD: return Optional.of(new PlcLWORD(byteBuf.getLong(index
* Long.BYTES)));
+
+ case REAL: return Optional.of(new PlcREAL(byteBuf.getFloat(index
* Float.BYTES)));
+
+ case LREAL: return Optional.of(new
PlcLREAL(byteBuf.getDouble(index * Double.BYTES)));
+
+ case CHAR: return Optional.of(new
PlcCHAR(byteBuf.getByte(index)));
+
+ case WCHAR: return Optional.of(new PlcWCHAR(byteBuf.getShort(index
* Short.BYTES)));
+
+ case STRING:
+ case WSTRING:
+ case TIME:
+ case LTIME:
+ case DATE:
+ case LDATE:
+ case TIME_OF_DAY:
+ case LTIME_OF_DAY:
+ case DATE_AND_TIME:
+ case DATE_AND_LTIME:
+ case LDATE_AND_TIME:
+ case Struct:
+ case List:
+ case RAW_BYTE_ARRAY:
+ default:;
+ }
+
+ return Optional.empty();
+ }
+
+ /*
+ *
+ *
+ */
+ public static int getPlcValueLength(PlcValue value){
+ int length = 0 ;
+ Integer numberOfValues = 0;
+ PlcValueType valueType = null;
+ PlcList plcList = null;
+ if (value instanceof PlcList){
+ plcList = (PlcList) value;
+ valueType = plcList.getIndex(0).getPlcValueType();
+ numberOfValues = ((PlcList) value).getLength();
+ } else {
+ valueType = value.getPlcValueType();
+ numberOfValues = 1;
+ }
+ switch (valueType) {
+ case NULL: break;
+
+ case BOOL:
+ length = 1;
+ break;
+ case BYTE:
+ case SINT:
+ case USINT:
+ length = Byte.BYTES;
+ break;
+ case INT:
+ case UINT:
+ case WORD:
+ length = Short.BYTES;
+ break;
+ case DINT:
+ case UDINT:
+ case DWORD:
+ length = Integer.BYTES;
+ break;
+ case LINT:
+ case ULINT:
+ case LWORD:
+ length = Long.BYTES;
+ break;
+ case REAL:
+ length = Float.BYTES;
+ break;
+ case LREAL:
+ length = Double.BYTES;
+ break;
+ case CHAR:
+ length = 1;
+ break;
+ case WCHAR:
+ length = Short.BYTES;
+ break;
+ case STRING:
+ case WSTRING:
+ case TIME:
+ case LTIME:
+ case DATE:
+ case LDATE:
+ case TIME_OF_DAY:
+ case LTIME_OF_DAY:
+ case DATE_AND_TIME:
+ case DATE_AND_LTIME:
+ case LDATE_AND_TIME:
+ case Struct:
+ case List:
+ case RAW_BYTE_ARRAY:
+ default:;
+ }
+ length = numberOfValues * length;
+ return length;
+ }
+
+}
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcGeneralFunctionImpl.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcGeneralFunctionImpl.java
index 59751dc..ee992e2 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcGeneralFunctionImpl.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcGeneralFunctionImpl.java
@@ -661,6 +661,22 @@ public class PlcGeneralFunctionImpl implements
PlcGeneralFunction {
return null;
}
+
+ @Override
+ public Optional<PlcDevice> getPlcItemDevice(UUID item_uid) {
+ Map<UUID, String> plcGroups = getPlcGroups();
+ Set<UUID> groupUuids = plcGroups.keySet();
+ Optional<UUID> groupUuid = groupUuids.stream().filter( u ->
getPlcGroupItems(u).containsKey(item_uid))
+ .findFirst();
+
+ if (groupUuid.isPresent()){
+ final PlcGroup plcgroup = getPlcGroup(groupUuid.get());
+ PlcDevice optDevice = getPlcDevice(plcgroup.getGroupDeviceUid());
+ if (null != optDevice) return Optional.of(optDevice);
+ }
+
+ return Optional.empty();
+ }
@Override
public Map<String, Object> getPlcDeviceMeta(UUID device_uid) {
@@ -684,6 +700,7 @@ public class PlcGeneralFunctionImpl implements
PlcGeneralFunction {
public Optional<PlcModel> createPlcModel(String deviceCategory, String
deviceName) {
try {
String filter = FILTER_DEVICE_MODEL_FACTORY.replace("*",
deviceCategory);
+ LOGGER.info("createPlcModel filter: {}", filter);
ServiceReference[] refs = bc.getServiceReferences((String) null,
filter);
if (null != refs) {
final PlcModelFactory plcModelFactory = (PlcModelFactory)
bc.getService(refs[0]);
@@ -698,6 +715,8 @@ public class PlcGeneralFunctionImpl implements
PlcGeneralFunction {
LOGGER.info("PlcModel service of type {} created for
device{}.", deviceCategory, deviceName);
return Optional.of(plcModel);
}
+ } else {
+ LOGGER.info("No service with filter: {}", filter);
}
} catch(Exception ex){
LOGGER.error(ex.getMessage());
@@ -796,7 +815,25 @@ public class PlcGeneralFunctionImpl implements
PlcGeneralFunction {
return null;
- }
+ }
+
+ @Override
+ public Optional<PlcGroup> getPlcItemGroup(UUID item_uid) {
+ getPlcGroups().keySet().stream().forEach(u -> {
+ System.out.println(u);
+ System.out.println(getPlcGroup(u).getItems().size());
+ });
+ Optional<UUID> optGroupUuid = getPlcGroups().
+ keySet().
+ stream().
+ filter(u ->
getPlcGroup(u).getGroupItems().containsKey(item_uid)).
+ findFirst();
+
+ if (optGroupUuid.isPresent()){
+ return Optional.of(getPlcGroup(optGroupUuid.get()));
+ }
+ return Optional.empty();
+ }
@Override
public int setPlcGroupScanRate(UUID group_uid, long scan_rate) {
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcItemImpl.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcItemImpl.java
index 6828129..7b71970 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcItemImpl.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcItemImpl.java
@@ -242,21 +242,43 @@ public class PlcItemImpl implements PlcItem {
try {
//Creates the default buffer associated with the requested data.
//TODO: Chequear por tiopo devuelto en el driver S7
+ LOGGER.error("1. " + plcvalue.toString());
+ LOGGER.error("1.0 " + plcvalue.getClass().getName());
+ int size = -1;
if (null == itemInnerBuffer) {
- int size = (plcvalue instanceof PlcRawByteArray) ?
- plcvalue.getRaw().length :
- -1;
+ LOGGER.error("1.1");
+ if (plcvalue instanceof PlcList) {
+ final PlcList plcList = (PlcList) plcvalue;
+ size = plcList.getLength() *
plcList.getIndex(0).getRaw().length;
+
+ } else {
+ size = (plcvalue instanceof PlcRawByteArray) ?
+ plcvalue.getRaw().length :
+ -1;
+ LOGGER.error("1.2 " + plcvalue.getRaw().length);
+ }
+
itemInnerBuffer = (size == -1) ? new
byte[plcvalue.getRaw().length] :
- new byte[size];
+ new byte[size];
+ LOGGER.error("1.3");
itemBuffer = Unpooled.wrappedBuffer(itemInnerBuffer);
+ LOGGER.error("1.4");
//Update all clients
- itemClients.forEach(c -> c.atach(this));
+ itemClients.forEach(c -> c.atach(this));
+ LOGGER.error("1.5");
}
-
+ LOGGER.error("1.X Salida.");
//Transfers data to a byte buffer
- itemBuffer.resetWriterIndex();
+ itemBuffer.resetWriterIndex();
+ LOGGER.error("2. " + itemInnerBuffer.length);
+ LOGGER.error("3. " + itemBuffer.toString());
if (plcvalue instanceof PlcRawByteArray) {
itemBuffer.writeBytes(plcvalue.getRaw());
+ } else if (plcvalue instanceof PlcList) {
+ final PlcList plcList = (PlcList) plcvalue;
+ plcList.getList().forEach( p -> {
+ itemBuffer.writeBytes(p.getRaw());
+ });
} else {
itemBuffer.writeBytes(plcvalue.getRaw());
}
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcSecureBootImpl.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcSecureBootImpl.java
index bec53f3..66f1d0d 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcSecureBootImpl.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcSecureBootImpl.java
@@ -140,6 +140,8 @@ public class PlcSecureBootImpl implements PlcSecureBoot,
Job {
private final BundleContext ctx;
private final PlcGeneralFunction gf;
+ private int delayed = 0;
+
DataSourceFactory dsFactory = null;
Connection dbConnection = null;
@@ -213,7 +215,7 @@ public class PlcSecureBootImpl implements PlcSecureBoot,
Job {
@Override
public void execute(JobContext context) {
boolean res = false;
- if (null != dbConnection) {
+ if ((null != dbConnection) && (delayed > 3)) {
if (!delayedBootPlcDivers.isEmpty()) {
if (null != dbConnection) {
Set<String> keys = delayedBootPlcDivers.keySet();
@@ -223,7 +225,10 @@ public class PlcSecureBootImpl implements PlcSecureBoot,
Job {
}
}
}
- }
+ } else {
+ System.out.println("> " + System.currentTimeMillis());
+ delayed++;
+ }
}
@Override
@@ -300,7 +305,7 @@ public class PlcSecureBootImpl implements PlcSecureBoot,
Job {
optPlcDevice.get().getDeviceKey(),
optPlcDevice.get().getDeviceName());
if (!optPlcModel.isPresent()) {
- LOGGER.info("No model for device:
{}",optPlcDevice.get().getDeviceName());
+ LOGGER.info("No model key '{}' for device '{}'.",
optPlcDevice.get().getDeviceKey(), optPlcDevice.get().getDeviceName());
}
//PlcGroups
@@ -335,8 +340,12 @@ public class PlcSecureBootImpl implements PlcSecureBoot,
Job {
rsItems.getString("ItemTag"),
rsItems.getString("ItemEnable"));
- if (optPlcItem.isPresent())
+ if (optPlcItem.isPresent()) {
LOGGER.info("Created PlcItem [{}].",
optPlcItem.get().getItemName());
+ if (optPlcModel.isPresent()){
+
optPlcModel.get().createMemoryArea(optPlcItem.get());
+ }
+ }
}
}
}
@@ -362,7 +371,7 @@ public class PlcSecureBootImpl implements PlcSecureBoot,
Job {
} else {
LOGGER.info("Database don't created.");
}
-
+
return res;
}
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/resources/proto/EPICSEvent.proto
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/resources/proto/EPICSEvent.proto
new file mode 100644
index 0000000..4379109
--- /dev/null
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/resources/proto/EPICSEvent.proto
@@ -0,0 +1,228 @@
+package EPICS;
+
+option java_package = "org.apache.plc4x.merlot.api.PB";
+option java_outer_classname = "EPICSEvent";
+
+message FieldValue {
+ required string name = 1;
+ required string val = 2;
+}
+
+message ScalarString {
+ required uint32 secondsintoyear = 1;
+ required uint32 nano = 2;
+ required string val = 3;
+ optional int32 severity = 4 [default = 0];
+ optional int32 status = 5 [default = 0];
+ optional uint32 repeatcount = 6;
+ repeated FieldValue fieldvalues = 7;
+ optional bool fieldactualchange = 8;
+}
+
+message ScalarByte {
+ required uint32 secondsintoyear = 1;
+ required uint32 nano = 2;
+ required bytes val = 3;
+ optional int32 severity = 4 [default = 0];
+ optional int32 status = 5 [default = 0];
+ optional uint32 repeatcount = 6;
+ repeated FieldValue fieldvalues = 7;
+ optional bool fieldactualchange = 8;
+}
+
+message ScalarShort {
+ required uint32 secondsintoyear = 1;
+ required uint32 nano = 2;
+ required sint32 val = 3;
+ optional int32 severity = 4 [default = 0];
+ optional int32 status = 5 [default = 0];
+ optional uint32 repeatcount = 6;
+ repeated FieldValue fieldvalues = 7;
+ optional bool fieldactualchange = 8;
+}
+
+message ScalarInt {
+ required uint32 secondsintoyear = 1;
+ required uint32 nano = 2;
+ required sfixed32 val = 3;
+ optional int32 severity = 4 [default = 0];
+ optional int32 status = 5 [default = 0];
+ optional uint32 repeatcount = 6;
+ repeated FieldValue fieldvalues = 7;
+ optional bool fieldactualchange = 8;
+}
+
+message ScalarEnum {
+ required uint32 secondsintoyear = 1;
+ required uint32 nano = 2;
+ required sint32 val = 3;
+ optional int32 severity = 4 [default = 0];
+ optional int32 status = 5 [default = 0];
+ optional uint32 repeatcount = 6;
+ repeated FieldValue fieldvalues = 7;
+ optional bool fieldactualchange = 8;
+}
+
+message ScalarFloat {
+ required uint32 secondsintoyear = 1;
+ required uint32 nano = 2;
+ required float val = 3;
+ optional int32 severity = 4 [default = 0];
+ optional int32 status = 5 [default = 0];
+ optional uint32 repeatcount = 6;
+ repeated FieldValue fieldvalues = 7;
+ optional bool fieldactualchange = 8;
+}
+
+
+message ScalarDouble {
+ required uint32 secondsintoyear = 1;
+ required uint32 nano = 2;
+ required double val = 3;
+ optional int32 severity = 4 [default = 0];
+ optional int32 status = 5 [default = 0];
+ optional uint32 repeatcount = 6;
+ repeated FieldValue fieldvalues = 7;
+ optional bool fieldactualchange = 8;
+}
+
+message VectorString {
+ required uint32 secondsintoyear = 1;
+ required uint32 nano = 2;
+ // No packed here as this is available only for primitive fields.
+ repeated string val = 3;
+ optional int32 severity = 4 [default = 0];
+ optional int32 status = 5 [default = 0];
+ optional uint32 repeatcount = 6;
+ repeated FieldValue fieldvalues = 7;
+ optional bool fieldactualchange = 8;
+}
+
+// VectorChar is the same as ScalarChar as we use ByteString for both
+message VectorChar {
+ required uint32 secondsintoyear = 1;
+ required uint32 nano = 2;
+ required bytes val = 3;
+ optional int32 severity = 4 [default = 0];
+ optional int32 status = 5 [default = 0];
+ optional uint32 repeatcount = 6;
+ repeated FieldValue fieldvalues = 7;
+ optional bool fieldactualchange = 8;
+}
+
+message VectorShort {
+ required uint32 secondsintoyear = 1;
+ required uint32 nano = 2;
+ repeated sint32 val = 3 [packed = true];
+ optional int32 severity = 4 [default = 0];
+ optional int32 status = 5 [default = 0];
+ optional uint32 repeatcount = 6;
+ repeated FieldValue fieldvalues = 7;
+ optional bool fieldactualchange = 8;
+}
+
+message VectorInt {
+ required uint32 secondsintoyear = 1;
+ required uint32 nano = 2;
+ repeated sfixed32 val = 3 [packed = true];
+ optional int32 severity = 4 [default = 0];
+ optional int32 status = 5 [default = 0];
+ optional uint32 repeatcount = 6;
+ repeated FieldValue fieldvalues = 7;
+ optional bool fieldactualchange = 8;
+}
+
+message VectorEnum {
+ required uint32 secondsintoyear = 1;
+ required uint32 nano = 2;
+ repeated sint32 val = 3 [packed = true];
+ optional int32 severity = 4 [default = 0];
+ optional int32 status = 5 [default = 0];
+ optional uint32 repeatcount = 6;
+ repeated FieldValue fieldvalues = 7;
+ optional bool fieldactualchange = 8;
+}
+
+message VectorFloat {
+ required uint32 secondsintoyear = 1;
+ required uint32 nano = 2;
+ repeated float val = 3 [packed = true];
+ optional int32 severity = 4 [default = 0];
+ optional int32 status = 5 [default = 0];
+ optional uint32 repeatcount = 6;
+ repeated FieldValue fieldvalues = 7;
+ optional bool fieldactualchange = 8;
+}
+
+
+message VectorDouble {
+ required uint32 secondsintoyear = 1;
+ required uint32 nano = 2;
+ repeated double val = 3 [packed = true];
+ optional int32 severity = 4 [default = 0];
+ optional int32 status = 5 [default = 0];
+ optional uint32 repeatcount = 6;
+ repeated FieldValue fieldvalues = 7;
+ optional bool fieldactualchange = 8;
+}
+
+// A generic v4 container; we simply store the bytes as obtained from EPICS v4
as the val.
+message V4GenericBytes {
+ required uint32 secondsintoyear = 1;
+ required uint32 nano = 2;
+ required bytes val = 3;
+ optional int32 severity = 4 [default = 0];
+ optional int32 status = 5 [default = 0];
+ optional uint32 repeatcount = 6;
+ repeated FieldValue fieldvalues = 7;
+ optional bool fieldactualchange = 8;
+ // EPICS V4 user tag
+ optional uint32 userTag = 9;
+}
+
+
+// An enumeration that indicates what PB message should be used to unmarshall
the following chunk of data
+// This is a copy of ArchDBRTypes and the numbers must match the integermap in
ArchDBRTypes for the reverse lookup to work
+// Look at DBR2PBTypeMapping to see how we can construct a hashmap that
unmarshalls an appropriate language type based on this enum.
+enum PayloadType {
+ SCALAR_STRING = 0;
+ SCALAR_SHORT = 1;
+ SCALAR_FLOAT = 2;
+ SCALAR_ENUM = 3;
+ SCALAR_BYTE = 4;
+ SCALAR_INT = 5;
+ SCALAR_DOUBLE = 6;
+ WAVEFORM_STRING = 7;
+ WAVEFORM_SHORT = 8;
+ WAVEFORM_FLOAT = 9;
+ WAVEFORM_ENUM = 10;
+ WAVEFORM_BYTE = 11;
+ WAVEFORM_INT = 12;
+ WAVEFORM_DOUBLE = 13;
+ V4_GENERIC_BYTES = 14;
+}
+
+// A payload info is the first line in a chunk of data sent back to the client.
+// It tells you how to unmarshall, the pvname and the year for the data
+// It also has a lot of optional fields
+message PayloadInfo {
+ required PayloadType type = 1;
+ required string pvname = 2;
+ required int32 year = 3;
+ optional int32 elementCount = 4;
+// Items from 5 to 14 are no longer to be used.
+// Stick these into the headers using the field names
+// For example, units comes in as EGU in the headers.
+ optional double unused00 = 5;
+ optional double unused01 = 6;
+ optional double unused02 = 7;
+ optional double unused03 = 8;
+ optional double unused04 = 9;
+ optional double unused05 = 10;
+ optional double unused06 = 11;
+ optional double unused07 = 12;
+ optional double unused08 = 13;
+ optional string unused09 = 14;
+// End of unused elements
+ repeated FieldValue headers = 15;
+}
diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/.classpath
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/.classpath
index 653dfd7..bc62286 100644
--- a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/.classpath
+++ b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/.classpath
@@ -26,7 +26,7 @@
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
- <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-18">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/.settings/org.eclipse.jdt.core.prefs
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/.settings/org.eclipse.jdt.core.prefs
index 1b6e1ef..7127a22 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/.settings/org.eclipse.jdt.core.prefs
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/.settings/org.eclipse.jdt.core.prefs
@@ -1,9 +1,9 @@
eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
-org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=18
+org.eclipse.jdt.core.compiler.compliance=18
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
-org.eclipse.jdt.core.compiler.source=1.8
+org.eclipse.jdt.core.compiler.source=18
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/api/DBRecord.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/api/DBRecord.java
index 7f49fa6..e9fa037 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/api/DBRecord.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/api/DBRecord.java
@@ -30,6 +30,7 @@ import org.apache.plc4x.merlot.api.PlcItem;
import org.apache.plc4x.merlot.api.PlcItemListener;
import org.epics.pvdata.property.AlarmSeverity;
import org.epics.pvdata.property.AlarmStatus;
+import org.epics.pvdata.pv.PVBoolean;
import org.epics.pvdata.pv.PVInt;
import org.epics.pvdata.pv.PVString;
import org.epics.pvdata.pv.PVStructure;
@@ -69,6 +70,8 @@ public class DBRecord extends PVRecord implements
PlcItemListener {
protected ByteBuf innerBuffer = null;
protected ByteBuf innerWriteBuffer = null;
+ protected PVBoolean write_enable;
+
protected boolean bFirtsRun = true;
@@ -134,6 +137,21 @@ public class DBRecord extends PVRecord implements
PlcItemListener {
public void detach() {
this.plcItem = null;
}
+
+
+ /**
+ * Implement real time data to the record.
+ * The main code is here.
+ */
+ @Override
+ public void process()
+ {
+ if (null != plcItem) {
+ if (write_enable.get()) {
+ super.process();
+ }
+ }
+ }
@Override
public void update() {
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBBooleanFactory.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBBooleanFactory.java
index 03a23f6..b3e4813 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBBooleanFactory.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBBooleanFactory.java
@@ -45,8 +45,7 @@ public class DBBooleanFactory extends DBBaseFactory {
private static FieldCreate fieldCreate = FieldFactory.getFieldCreate();
- public DBBooleanFactory() {};
-
+
@Override
public DBRecord create(String recordName) {
NTScalarBuilder ntScalarBuilder = NTScalar.createBuilder();
@@ -58,7 +57,6 @@ public class DBBooleanFactory extends DBBaseFactory {
add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_value",
fieldCreate.createScalar(ScalarType.pvBoolean)).
addAlarm().
addTimeStamp().
addDisplay().
@@ -80,7 +78,6 @@ public class DBBooleanFactory extends DBBaseFactory {
add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_value",
fieldCreate.createFixedScalarArray(ScalarType.pvBoolean, length)).
addAlarm().
addTimeStamp().
addDisplay().
@@ -97,32 +94,14 @@ public class DBBooleanFactory extends DBBaseFactory {
private int BUFFER_SIZE = Byte.BYTES;
private PVBoolean value;
- private PVBoolean write_value;
- private PVBoolean write_enable;
private boolean blnValue = false;
public DBBooleanRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = pvStructure.getBooleanField("value");
- write_value = pvStructure.getBooleanField("write_value");
write_enable = pvStructure.getBooleanField("write_enable");
}
- /**
- * Implement real time data to the record.
- * The main code is here.
- */
- public void process()
- {
- if (null != plcItem) {
- if (write_enable.get()) {
- write_value.put(value.get());
- super.process();
- }
-
- }
- }
-
@Override
public void atach(PlcItem plcItem) {
try {
@@ -134,11 +113,6 @@ public class DBBooleanFactory extends DBBaseFactory {
}
}
- @Override
- public void detach() {
- this.plcItem = null;
- }
-
/*
*
***************************************************************************
* Modbus : Return a array of bytes, where every byte is a boolean.
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBByteFactory.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBByteFactory.java
index e495edd..c95cae3 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBByteFactory.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBByteFactory.java
@@ -41,8 +41,6 @@ public class DBByteFactory extends DBBaseFactory {
private static FieldCreate fieldCreate = FieldFactory.getFieldCreate();
- public DBByteFactory() {
- }
@Override
public DBRecord create(String recordName) {
@@ -54,8 +52,7 @@ public class DBByteFactory extends DBBaseFactory {
add("offset", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_value", fieldCreate.createScalar(ScalarType.pvByte)).
+ add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
addAlarm().
addTimeStamp().
addDisplay().
@@ -76,8 +73,7 @@ public class DBByteFactory extends DBBaseFactory {
add("offset", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_value",
fieldCreate.createFixedScalarArray(ScalarType.pvByte, length)).
+ add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
addAlarm().
addTimeStamp().
addDisplay().
@@ -94,29 +90,13 @@ public class DBByteFactory extends DBBaseFactory {
private int BUFFER_SIZE = Byte.BYTES;
private PVByte value;
- private PVByte write_value;
- private PVBoolean write_enable;
public DBByteRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = pvStructure.getByteField("value");
- write_value = pvStructure.getByteField("write_value");
write_enable = pvStructure.getBooleanField("write_enable");
}
- /**
- * Implement real time data to the record.
- * The main code is here.
- */
- public void process()
- {
- if (null != plcItem) {
- if (write_enable.get()) {
- write_value.put(value.get());
- super.process();
- }
- }
- }
@Override
public void atach(PlcItem plcItem) {
@@ -125,10 +105,6 @@ public class DBByteFactory extends DBBaseFactory {
innerBuffer = plcItem.getItemByteBuf().slice(byteOffset,
BUFFER_SIZE);
}
- @Override
- public void detach() {
- this.plcItem = null;
- }
@Override
public void update() {
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBDoubleFactory.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBDoubleFactory.java
index e297c61..a1f4fa2 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBDoubleFactory.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBDoubleFactory.java
@@ -53,8 +53,7 @@ public class DBDoubleFactory extends DBBaseFactory {
add("offset", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_value", fieldCreate.createScalar(ScalarType.pvDouble)).
+ add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
addAlarm().
addTimeStamp().
addDisplay().
@@ -75,8 +74,7 @@ public class DBDoubleFactory extends DBBaseFactory {
add("offset", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_value",
fieldCreate.createFixedScalarArray(ScalarType.pvDouble, length)).
+ add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
addAlarm().
addTimeStamp().
addDisplay().
@@ -92,31 +90,14 @@ public class DBDoubleFactory extends DBBaseFactory {
class DBDoubleRecord extends DBRecord implements PlcItemListener {
private int BUFFER_SIZE = Double.BYTES;
- private PVDouble value;
- private PVDouble write_value;
- private PVBoolean write_enable;
+ private PVDouble value;
public DBDoubleRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = pvStructure.getDoubleField("value");
- write_value = pvStructure.getDoubleField("write_value");
write_enable = pvStructure.getBooleanField("write_enable");
}
-
- /**
- * Implement real time data to the record.
- * The main code is here.
- */
- public void process()
- {
- if (null != plcItem) {
- if (write_enable.get()) {
- write_value.put(value.get());
- super.process();
- }
- }
- }
-
+
@Override
public void atach(PlcItem plcItem) {
this.plcItem = plcItem;
@@ -124,11 +105,6 @@ public class DBDoubleFactory extends DBBaseFactory {
innerBuffer = plcItem.getItemByteBuf().slice(byteOffset,
BUFFER_SIZE);
}
- @Override
- public void detach() {
- this.plcItem = null;
- }
-
@Override
public void update() {
if (null != plcItem)
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBFloatFactory.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBFloatFactory.java
index 6bb3d27..c904d22 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBFloatFactory.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBFloatFactory.java
@@ -53,8 +53,7 @@ public class DBFloatFactory extends DBBaseFactory {
add("offset", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_value", fieldCreate.createScalar(ScalarType.pvFloat)).
+ add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
addAlarm().
addTimeStamp().
addDisplay().
@@ -75,8 +74,7 @@ public class DBFloatFactory extends DBBaseFactory {
add("offset", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_value",
fieldCreate.createFixedScalarArray(ScalarType.pvFloat, length)).
+ add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
addAlarm().
addTimeStamp().
addDisplay().
@@ -92,31 +90,14 @@ public class DBFloatFactory extends DBBaseFactory {
class DBFloatRecord extends DBRecord implements PlcItemListener {
private int BUFFER_SIZE = Float.BYTES;
- private PVFloat value;
- private PVFloat write_value;
- private PVBoolean write_enable;
-
+ private PVFloat value; ;
+
public DBFloatRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = pvStructure.getFloatField("value");
- write_value = pvStructure.getFloatField("write_value");
write_enable = pvStructure.getBooleanField("write_enable");
}
-
- /**
- * Implement real time data to the record.
- * The main code is here.
- */
- public void process()
- {
- if (null != plcItem) {
- if (write_enable.get()) {
- write_value.put(value.get());
- super.process();
- }
- }
- }
-
+
@Override
public void atach(PlcItem plcItem) {
this.plcItem = plcItem;
@@ -124,11 +105,6 @@ public class DBFloatFactory extends DBBaseFactory {
innerBuffer = plcItem.getItemByteBuf().slice(byteOffset,
BUFFER_SIZE);
}
- @Override
- public void detach() {
- this.plcItem = null;
- }
-
@Override
public void update() {
if (null != plcItem)
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBIntFactory.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBIntFactory.java
index 0dc155e..f11c664 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBIntFactory.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBIntFactory.java
@@ -50,8 +50,7 @@ public class DBIntFactory extends DBBaseFactory {
add("offset", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_value", fieldCreate.createScalar(ScalarType.pvInt)).
+ add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
addAlarm().
addTimeStamp().
addDisplay().
@@ -72,8 +71,7 @@ public class DBIntFactory extends DBBaseFactory {
add("offset", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_value",
fieldCreate.createFixedScalarArray(ScalarType.pvInt, length)).
+ add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
addAlarm().
addTimeStamp().
addDisplay().
@@ -90,30 +88,13 @@ public class DBIntFactory extends DBBaseFactory {
private int BUFFER_SIZE = Integer.BYTES;
private PVInt value;
- private PVInt write_value;
- private PVBoolean write_enable;
-
+
public DBIntRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = pvStructure.getIntField("value");
- write_value = pvStructure.getIntField("write_value");
write_enable = pvStructure.getBooleanField("write_enable");
}
- /**
- * Implement real time data to the record.
- * The main code is here.
- */
- public void process()
- {
- if (null != plcItem) {
- if (write_enable.get()) {
- write_value.put(value.get());
- super.process();
- }
- }
- }
-
@Override
public void atach(PlcItem plcItem) {
this.plcItem = plcItem;
@@ -121,11 +102,6 @@ public class DBIntFactory extends DBBaseFactory {
innerBuffer = plcItem.getItemByteBuf().slice(byteOffset,
BUFFER_SIZE);
}
- @Override
- public void detach() {
- this.plcItem = null;
- }
-
@Override
public void update() {
if (null != plcItem)
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBLongFactory.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBLongFactory.java
index f11e400..74fdb63 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBLongFactory.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBLongFactory.java
@@ -50,8 +50,7 @@ public class DBLongFactory extends DBBaseFactory {
add("offset", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_value", fieldCreate.createScalar(ScalarType.pvLong)).
+ add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
addAlarm().
addTimeStamp().
addDisplay().
@@ -72,8 +71,7 @@ public class DBLongFactory extends DBBaseFactory {
add("offset", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_value",
fieldCreate.createFixedScalarArray(ScalarType.pvLong, length)).
+ add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
addAlarm().
addTimeStamp().
addDisplay().
@@ -90,30 +88,13 @@ public class DBLongFactory extends DBBaseFactory {
private int BUFFER_SIZE = Long.BYTES;
private PVLong value;
- private PVLong write_value;
- private PVBoolean write_enable;
-
+
public DBLongRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = pvStructure.getLongField("value");
- write_value = pvStructure.getLongField("write_value");
write_enable = pvStructure.getBooleanField("write_enable");
}
-
- /**
- * Implement real time data to the record.
- * The main code is here.
- */
- public void process()
- {
- if (null != plcItem) {
- if (write_enable.get()) {
- write_value.put(value.get());
- super.process();
- }
- }
- }
-
+
@Override
public void atach(PlcItem plcItem) {
this.plcItem = plcItem;
@@ -121,11 +102,6 @@ public class DBLongFactory extends DBBaseFactory {
innerBuffer = plcItem.getItemByteBuf().slice(byteOffset,
BUFFER_SIZE);
}
- @Override
- public void detach() {
- this.plcItem = null;
- }
-
@Override
public void update() {
if (null != plcItem)
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBShortFactory.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBShortFactory.java
index 63fc2d5..6d582a5 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBShortFactory.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBShortFactory.java
@@ -94,31 +94,14 @@ public class DBShortFactory extends DBBaseFactory {
class DBShortRecord extends DBRecord implements PlcItemListener {
private int BUFFER_SIZE = Short.BYTES;
- private PVShort value;
- private PVShort write_value;
- private PVBoolean write_enable;
+ private PVShort value;
public DBShortRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = pvStructure.getShortField("value");
- write_value = pvStructure.getShortField("write_value");
write_enable = pvStructure.getBooleanField("write_enable");
}
- /**
- * Implement real time data to the record.
- * The main code is here.
- */
- public void process()
- {
- if (null != plcItem) {
- if (write_enable.get()) {
- write_value.put(value.get());
- super.process();
- }
- }
- }
-
@Override
public void atach(final PlcItem plcItem) {
this.plcItem = plcItem;
@@ -126,11 +109,6 @@ public class DBShortFactory extends DBBaseFactory {
innerBuffer = plcItem.getItemByteBuf().slice(byteOffset,
BUFFER_SIZE);
}
- @Override
- public void detach() {
- this.plcItem = null;
- }
-
@Override
public void update() {
if (null != plcItem) {
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBStringFactory.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBStringFactory.java
index 5295acc..a235d65 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBStringFactory.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBStringFactory.java
@@ -87,28 +87,15 @@ public class DBStringFactory extends DBBaseFactory {
class DBStringRecord extends DBRecord implements PlcItemListener {
- private PVString value;
- private PVString write_value;
+ private PVString value;
private int offset = 0;
public DBStringRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = pvStructure.getStringField("value");
- offset = pvStructure.getIntField("offset").get();
- }
-
- /**
- * Implement real time data to the record.
- * The main code is here.
- */
- public void process()
- {
- super.process();
- if (null != plcItem) {
- if (value.get() != write_value.get())
- write_value.put(value.get());
- }
+ offset = pvStructure.getIntField("offset").get();
+ write_enable = pvStructure.getBooleanField("write_enable");
}
@Override
@@ -118,11 +105,6 @@ public class DBStringFactory extends DBBaseFactory {
innerBuffer = Unpooled.wrappedBuffer(plcItem.getInnerBuffer(), 0,
offset);
}
- @Override
- public void detach() {
- this.plcItem = null;
- }
-
@Override
public void update() {
if (null != plcItem)
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUByteFactory.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUByteFactory.java
index ca8ba28..ae94407 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUByteFactory.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUByteFactory.java
@@ -50,8 +50,7 @@ public class DBUByteFactory extends DBBaseFactory {
add("offset", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_value", fieldCreate.createScalar(ScalarType.pvUByte)).
+ add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
addAlarm().
addTimeStamp().
addDisplay().
@@ -72,8 +71,7 @@ public class DBUByteFactory extends DBBaseFactory {
add("offset", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_value",
fieldCreate.createFixedScalarArray(ScalarType.pvUByte, length)).
+ add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
addAlarm().
addTimeStamp().
addDisplay().
@@ -89,31 +87,14 @@ public class DBUByteFactory extends DBBaseFactory {
class DBUByteRecord extends DBRecord implements PlcItemListener {
private int BUFFER_SIZE = Byte.BYTES;
- private PVUByte value;
- private PVUByte write_value;
- private PVBoolean write_enable;
+ private PVUByte value;
public DBUByteRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = (PVUByte) pvStructure.getSubField("value");
- write_value = (PVUByte) pvStructure.getSubField("write_value");
write_enable = pvStructure.getBooleanField("write_enable");
}
- /**
- * Implement real time data to the record.
- * The main code is here.
- */
- public void process()
- {
- if (null != plcItem) {
- if (write_enable.get()) {
- write_value.put(value.get());
- super.process();
- }
- }
- }
-
@Override
public void atach(PlcItem plcItem) {
this.plcItem = plcItem;
@@ -121,11 +102,6 @@ public class DBUByteFactory extends DBBaseFactory {
innerBuffer = plcItem.getItemByteBuf().slice(byteOffset,
BUFFER_SIZE);
}
- @Override
- public void detach() {
- this.plcItem = null;
- }
-
@Override
public void update() {
if (null != plcItem)
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUIntFactory.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUIntFactory.java
index 9a14587..9550f02 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUIntFactory.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUIntFactory.java
@@ -50,8 +50,7 @@ public class DBUIntFactory extends DBBaseFactory {
add("offset", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_value", fieldCreate.createScalar(ScalarType.pvUInt)).
+ add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
addAlarm().
addTimeStamp().
addDisplay().
@@ -72,8 +71,7 @@ public class DBUIntFactory extends DBBaseFactory {
add("offset", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_value",
fieldCreate.createFixedScalarArray(ScalarType.pvUInt, length)).
+ add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
addAlarm().
addTimeStamp().
addDisplay().
@@ -89,31 +87,14 @@ public class DBUIntFactory extends DBBaseFactory {
class DBUIntRecord extends DBRecord implements PlcItemListener {
private int BUFFER_SIZE = Integer.BYTES;
- private PVUInt value;
- private PVUInt write_value;
- private PVBoolean write_enable;
+ private PVUInt value;
public DBUIntRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = (PVUInt) pvStructure.getSubField("value");
- write_value = (PVUInt) pvStructure.getSubField("write_value");
write_enable = pvStructure.getBooleanField("write_enable");
}
- /**
- * Implement real time data to the record.
- * The main code is here.
- */
- public void process()
- {
- if (null != plcItem) {
- if (write_enable.get()) {
- write_value.put(value.get());
- super.process();
- }
- }
- }
-
@Override
public void atach(PlcItem plcItem) {
this.plcItem = plcItem;
@@ -121,11 +102,6 @@ public class DBUIntFactory extends DBBaseFactory {
innerBuffer = plcItem.getItemByteBuf().slice(byteOffset,
BUFFER_SIZE);
}
- @Override
- public void detach() {
- this.plcItem = null;
- }
-
@Override
public void update() {
if (null != plcItem)
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBULongFactory.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBULongFactory.java
index f35ba5d..2186aa0 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBULongFactory.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBULongFactory.java
@@ -52,8 +52,7 @@ public class DBULongFactory extends DBBaseFactory {
add("offset", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_value", fieldCreate.createScalar(ScalarType.pvULong)).
+ add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
addAlarm().
addTimeStamp().
addDisplay().
@@ -74,8 +73,7 @@ public class DBULongFactory extends DBBaseFactory {
add("offset", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_value",
fieldCreate.createFixedScalarArray(ScalarType.pvULong, length)).
+ add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
addAlarm().
addTimeStamp().
addDisplay().
@@ -91,31 +89,14 @@ public class DBULongFactory extends DBBaseFactory {
class DBULongRecord extends DBRecord implements PlcItemListener {
private int BUFFER_SIZE = Long.BYTES;
- private PVULong value;
- private PVULong write_value;
- private PVBoolean write_enable;
+ private PVULong value;
DBULongRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = (PVULong) pvStructure.getSubField("value");
- write_value = (PVULong) pvStructure.getSubField("write_value");
write_enable = pvStructure.getBooleanField("write_enable");
}
- /**
- * Implement real time data to the record.
- * The main code is here.
- */
- public void process()
- {
- if (null != plcItem) {
- if (write_enable.get()) {
- write_value.put(value.get());
- super.process();
- }
- }
- }
-
@Override
public void atach(PlcItem plcItem) {
this.plcItem = plcItem;
@@ -123,11 +104,6 @@ public class DBULongFactory extends DBBaseFactory {
innerBuffer = plcItem.getItemByteBuf().slice(byteOffset,
BUFFER_SIZE);
}
- @Override
- public void detach() {
- this.plcItem = null;
- }
-
@Override
public void update() {
if (null != plcItem)
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUShortFactory.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUShortFactory.java
index 8a04662..a5a4a35 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUShortFactory.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBUShortFactory.java
@@ -52,8 +52,7 @@ public class DBUShortFactory extends DBBaseFactory {
add("offset", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_value", fieldCreate.createScalar(ScalarType.pvUShort)).
+ add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
addAlarm().
addTimeStamp().
addDisplay().
@@ -74,8 +73,7 @@ public class DBUShortFactory extends DBBaseFactory {
add("offset", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_time", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
- add("write_value",
fieldCreate.createFixedScalarArray(ScalarType.pvUShort, length)).
+ add("write_enable",
fieldCreate.createScalar(ScalarType.pvBoolean)).
addAlarm().
addTimeStamp().
addDisplay().
@@ -91,31 +89,14 @@ public class DBUShortFactory extends DBBaseFactory {
class DBUShortRecord extends DBRecord implements PlcItemListener{
private int BUFFER_SIZE = Short.BYTES;
- private PVUShort value;
- private PVUShort write_value;
- private PVBoolean write_enable;
+ private PVUShort value;
private DBUShortRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = (PVUShort) pvStructure.getSubField("value");
- write_value = (PVUShort) pvStructure.getSubField("write_value");
write_enable = pvStructure.getBooleanField("write_enable");
}
- /**
- * Implement real time data to the record.
- * The main code is here.
- */
- public void process()
- {
- if (null != plcItem) {
- if (write_enable.get()) {
- write_value.put(value.get());
- super.process();
- }
- }
- }
-
@Override
public void atach(final PlcItem plcItem) {
this.plcItem = plcItem;
@@ -123,11 +104,6 @@ public class DBUShortFactory extends DBBaseFactory {
innerBuffer = plcItem.getItemByteBuf().slice(byteOffset,
BUFFER_SIZE);
}
- @Override
- public void detach() {
- this.plcItem = null;
- }
-
@Override
public void update() {
if (null != plcItem)
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/java/org/apache/plc4x/merlot/drv/s7/impl/S7PlcModelImpl.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/java/org/apache/plc4x/merlot/drv/s7/impl/S7PlcModelImpl.java
index aebec6b..39d5055 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/java/org/apache/plc4x/merlot/drv/s7/impl/S7PlcModelImpl.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/java/org/apache/plc4x/merlot/drv/s7/impl/S7PlcModelImpl.java
@@ -99,60 +99,64 @@ public class S7PlcModelImpl implements PlcModel {
@Override
public void createMemoryArea(Object dbRecord) {
- final DBRecord dbrecord = (DBRecord) dbRecord;
- final PVStructure pvStructure = dbrecord.getPVStructure();
- final String pvId = pvStructure.getStringField("id").get();
-
- // Each tag is comprised of two fields separated by ":", the first
field
- // corresponds to the driver instance identifier and the second is the
- // string that represents the memory area, the tag itselft.
-
- String[] strTemp = pvId.split(":", 2);
- String strTag = strTemp[1];
- System.out.println("Paso: 01");
- //TODO: Split the Device name.
- S7Tag s7tag = S7Tag.of(strTag);
-
- if (null == memoryAreas.get(s7tag.getMemoryArea().getShortName())) {
- Map<Integer, PlcItem> inputBytes = new HashMap<Integer, PlcItem>();
- memoryAreas.put(s7tag.getMemoryArea().getShortName(), inputBytes);
- logger.info("Created memmory area with PlcItem: " + "s7 " +
s7tag.getMemoryArea().getShortName() + "["+s7tag.getBlockNumber() +"]");
- }
-
- System.out.println("Paso: 02");
- final Map<Integer, PlcItem> memoryBytes =
memoryAreas.get(s7tag.getMemoryArea().getShortName());
-
- if (null == memoryBytes.get(s7tag.getBlockNumber())) {
- PlcItem plcItem = new PlcItemImpl.PlcItemBuilder("s7" +
s7tag.getMemoryArea().getShortName() + "["+s7tag.getBlockNumber() +"]").
- setItemDescription("Flag markes from PLC in byte order.").
- setItemId("").
- setItemEnable(true).
- build();
- memoryBytes.put(s7tag.getBlockNumber(), plcItem);
- }
- System.out.println("Paso: 03");
- final PlcItem internalPlcItem =
memoryBytes.get(s7tag.getBlockNumber());
- final ByteBuf byteBuf = internalPlcItem.getItemByteBuf();
- int bufferSize =
(dbrecord.getInnerBuffer().isPresent())?dbrecord.getInnerBuffer().get().capacity():1;
- int minSize = s7tag.getByteOffset() + bufferSize;
+ if (dbRecord instanceof DBRecord) {
+ final DBRecord dbrecord = (DBRecord) dbRecord;
+ final PVStructure pvStructure = dbrecord.getPVStructure();
+ final String pvId = pvStructure.getStringField("id").get();
- System.out.println("Paso: 04");
-
- if (byteBuf.capacity() < minSize) {
- byteBuf.capacity(minSize);
- logger.info("The buffer capacity was expanded to {}.", minSize);
- }
- byteBuf.writerIndex(byteBuf.capacity());
- System.out.println(ByteBufUtil.prettyHexDump(byteBuf));
-
- System.out.println("Paso: 05");
- doUpdateByteBuf(dbrecord);
- System.out.println("Paso: 06");
+ // Each tag is comprised of two fields separated by ":", the first
field
+ // corresponds to the driver instance identifier and the second is
the
+ // string that represents the memory area, the tag itselft.
+
+ String[] strTemp = pvId.split(":", 2);
+ String strTag = strTemp[1];
+ System.out.println("Paso: 01");
+ //TODO: Split the Device name.
+ S7Tag s7tag = S7Tag.of(strTag);
+
+ if (null == memoryAreas.get(s7tag.getMemoryArea().getShortName()))
{
+ Map<Integer, PlcItem> inputBytes = new HashMap<Integer,
PlcItem>();
+ memoryAreas.put(s7tag.getMemoryArea().getShortName(),
inputBytes);
+ logger.info("Created memmory area with PlcItem: " + "s7 " +
s7tag.getMemoryArea().getShortName() + "["+s7tag.getBlockNumber() +"]");
+ }
+
+ System.out.println("Paso: 02");
+ final Map<Integer, PlcItem> memoryBytes =
memoryAreas.get(s7tag.getMemoryArea().getShortName());
+
+ if (null == memoryBytes.get(s7tag.getBlockNumber())) {
+ PlcItem plcItem = new PlcItemImpl.PlcItemBuilder("s7" +
s7tag.getMemoryArea().getShortName() + "["+s7tag.getBlockNumber() +"]").
+ setItemDescription("Flag markes from PLC in byte order.").
+ setItemId("").
+ setItemEnable(true).
+ build();
+ memoryBytes.put(s7tag.getBlockNumber(), plcItem);
+ }
+
+ System.out.println("Paso: 03");
+ final PlcItem internalPlcItem =
memoryBytes.get(s7tag.getBlockNumber());
+ final ByteBuf byteBuf = internalPlcItem.getItemByteBuf();
+ int bufferSize =
(dbrecord.getInnerBuffer().isPresent())?dbrecord.getInnerBuffer().get().capacity():1;
+ int minSize = s7tag.getByteOffset() + bufferSize;
+
+ System.out.println("Paso: 04");
+
+ if (byteBuf.capacity() < minSize) {
+ byteBuf.capacity(minSize);
+ logger.info("The buffer capacity was expanded to {}.",
minSize);
+ }
+ byteBuf.writerIndex(byteBuf.capacity());
+ System.out.println(ByteBufUtil.prettyHexDump(byteBuf));
+
+ System.out.println("Paso: 05");
+ doUpdateByteBuf(dbrecord);
+ System.out.println("Paso: 06");
+ }
}
@Override
public void createScanGroup(Object dbRecord) {
+
final DBRecord dbrecord = (DBRecord) dbRecord;
final PVStructure pvStructure = dbrecord.getPVStructure();
final PVString pvId = pvStructure.getStringField("id");
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/java/org/apache/plc4x/merlot/drv/s7/impl/S7PlcTagFunctionImpl.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/java/org/apache/plc4x/merlot/drv/s7/impl/S7PlcTagFunctionImpl.java
index 14ef7f5..ec25174 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/java/org/apache/plc4x/merlot/drv/s7/impl/S7PlcTagFunctionImpl.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/java/org/apache/plc4x/merlot/drv/s7/impl/S7PlcTagFunctionImpl.java
@@ -155,7 +155,7 @@ public class S7PlcTagFunctionImpl implements PlcTagFunction
{
LOGGER.info("Processing S7Tag: {}", s7Tag.toString());
LOGGER.info("Buffer: \r\n" + ByteBufUtil.prettyHexDump(byteBuf));
Object[] objValues = new Object[byteBuf.readableBytes()];
- switch (s7Tag.getDataType()) {
+ switch (s7Tag.getDataType()) {
case BYTE:
if (bitOffset == -1) {
intByteOffset = s7Tag.getByteOffset() +
byteOffset;
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBAiFactoryTest.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBAiFactoryTest.java
new file mode 100644
index 0000000..cf5dccc
--- /dev/null
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBAiFactoryTest.java
@@ -0,0 +1,210 @@
+/*
+ * 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.merlot.drv.s7.core;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.apache.plc4x.java.spi.values.PlcRawByteArray;
+import org.apache.plc4x.merlot.api.PlcItem;
+import org.apache.plc4x.merlot.api.impl.PlcItemImpl;
+import org.apache.plc4x.merlot.db.api.DBRecord;
+import org.epics.pvdata.pv.*;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.UUID;
+
+import static org.junit.Assert.*;
+
+public class S7DBAiFactoryTest {
+
+ private S7DBAiFactory factory;
+ private DBRecord record;
+ private PlcItem plcItem;
+ private ByteBuf byteBuf;
+
+ @Before
+ public void setUp() {
+ factory = new S7DBAiFactory();
+ record = factory.create("AI_TEST");
+
+ // Setup Buffer
+ byteBuf = Unpooled.buffer(64);
+ // Initialize buffer with some data
+ // iMode (short) at 0
+ byteBuf.setShort(0, 1);
+ // iErrorCode (short) at 2
+ byteBuf.setShort(2, 0);
+ // iStatus (short) at 4
+ byteBuf.setShort(4, 100);
+ // rActiveValue (float) at 6
+ byteBuf.setFloat(6, 12.34f);
+ // rInputValue (float) at 10
+ byteBuf.setFloat(10, 56.78f);
+ // rManualValue (float) at 14
+ byteBuf.setFloat(14, 90.12f);
+ // bPB_ResetError, bPBEN_ResetError, bError at 18 (byte)
+ // Bit 0: bPB_ResetError, Bit 1: bPBEN_ResetError, Bit 2: bError
+ byteBuf.setByte(18, 0b00000111); // All true
+
+ // Status byte at 20
+ // Bit 0: bLowLowAlarm, Bit 1: bHighHighAlarm, Bit 2: bInvalid
+ byteBuf.setByte(20, 0b00000101); // LowLow=true, HighHigh=false,
Invalid=true
+
+ // Parameters
+ // iSensorType (short) at 22
+ byteBuf.setShort(22, 2);
+ // rInEngUnitsMin (float) at 24
+ byteBuf.setFloat(24, 0.0f);
+ // rInEngUnitsMax (float) at 28
+ byteBuf.setFloat(28, 100.0f);
+ // ... other floats ...
+
+ // Setup PlcItem
+ String uuid = UUID.randomUUID().toString();
+ plcItem = new PlcItemImpl.PlcItemBuilder("ITEM_TEST")
+ .setItemDescription("Test Item")
+ .setItemId(uuid)
+ .setItemUid(UUID.fromString(uuid))
+ .build();
+
+ plcItem.setPlcValue(new PlcRawByteArray(byteBuf.array()));
+ }
+
+ @Test
+ public void testCreate() {
+ assertNotNull(record);
+ PVStructure pvStructure =
record.getPVRecordStructure().getPVStructure();
+ assertNotNull(pvStructure);
+
+ assertNotNull(pvStructure.getStructureField("cmd"));
+ assertNotNull(pvStructure.getStructureField("sts"));
+ assertNotNull(pvStructure.getStructureField("par"));
+ assertNotNull(pvStructure.getStringField("id"));
+ }
+
+ @Test
+ public void testAttach() {
+ PVString id =
record.getPVRecordStructure().getPVStructure().getStringField("id");
+ id.put("s7:%DB100:23:BYTE[64]"); // Example S7 address
+
+ record.atach(plcItem);
+
+ assertEquals(23, record.getByteOffset());
+ // Bit offset is usually 0 unless specified otherwise
+ assertEquals(0, record.getBiteOffset());
+ }
+
+ @Test
+ public void testUpdate() {
+ PVString id =
record.getPVRecordStructure().getPVStructure().getStringField("id");
+ id.put("s7:%DB100:0:BYTE[64]"); // Offset 0 for simplicity with our
buffer
+ record.atach(plcItem);
+
+ // Manually set the inner buffer of the record to match our test buffer
+ // because atach() slices the buffer based on offset.
+ // Since we created a raw buffer and wrapped it in PlcRawByteArray,
+ // and PlcItemImpl might handle it differently, let's ensure the
record has
+ // access to data.
+ // In S7DBAiFactory.atach: innerBuffer =
+ // plcItem.getItemByteBuf().slice(byteOffset, BUFFER_SIZE);
+ // We need to make sure plcItem.getItemByteBuf() returns something
valid.
+ // PlcItemImpl usually wraps the PlcValue.
+
+ // Let's simulate the update
+ record.update();
+
+ PVStructure pvStructure =
record.getPVRecordStructure().getPVStructure();
+ PVStructure cmd = pvStructure.getStructureField("cmd");
+ PVStructure sts = pvStructure.getStructureField("sts");
+ PVStructure par = pvStructure.getStructureField("par");
+
+ assertEquals(1, cmd.getShortField("iMode").get());
+ assertEquals(100, cmd.getShortField("iStatus").get());
+ assertEquals(12.34f, cmd.getFloatField("rActiveValue").get(), 0.001f);
+ assertEquals(56.78f, cmd.getFloatField("rInputValue").get(), 0.001f);
+ assertEquals(90.12f, cmd.getFloatField("rManualValue").get(), 0.001f);
+
+ assertEquals(true, cmd.getBooleanField("bPB_ResetError").get());
+ assertEquals(true, cmd.getBooleanField("bPBEN_ResetError").get());
+ assertEquals(true, cmd.getBooleanField("bError").get());
+
+ assertEquals(true, sts.getBooleanField("bLowLowAlarm").get());
+ assertEquals(false, sts.getBooleanField("bHighHighAlarm").get());
+ assertEquals(true, sts.getBooleanField("bInvalid").get());
+
+ assertEquals(2, par.getShortField("iSensorType").get());
+ assertEquals(0.0f, par.getFloatField("rInEngUnitsMin").get(), 0.001f);
+ assertEquals(100.0f, par.getFloatField("rInEngUnitsMax").get(),
0.001f);
+ }
+
+ @Test
+ public void testProcess() {
+ PVString id =
record.getPVRecordStructure().getPVStructure().getStringField("id");
+ id.put("s7:%DB100:0:BYTE[64]");
+ record.atach(plcItem);
+
+ // Enable write
+ PVBoolean writeEnable =
record.getPVRecordStructure().getPVStructure().getBooleanField("write_enable");
+ writeEnable.put(true);
+
+ // Change a value in PV
+ PVStructure cmd =
record.getPVRecordStructure().getPVStructure().getStructureField("cmd");
+ cmd.getShortField("iMode").put((short) 5);
+
+ // Call process
+ record.process();
+
+ // Verify that the buffer (which represents the PLC memory) is updated
+ // Note: S7DBAiFactory.process() calls super.process().
+ // We need to verify if super.process() writes back to the buffer or
sends a
+ // write request.
+ // Assuming it writes back to the buffer mapped to the fields.
+ // Let's check if the buffer was modified.
+ // The factory maps fields to offsets. iMode is at offset 3 (from
fieldOffsets
+ // in Factory)?
+ // Wait, let's check fieldOffsets in S7DBAiFactory.java
+ // fieldOffsets.add(3, new ImmutablePair(0, (byte) -1)); //iMode ->
Offset 0
+
+ // So if we change iMode to 5, the buffer at offset 0 should be 5.
+ // However, process() logic in DBBaseFactory usually handles writing
from PV to
+ // Buffer/PLC.
+ // Let's assume it writes to the buffer if it's a local buffer
simulation.
+
+ // Re-reading the buffer to see if it changed requires access to the
inner
+ // buffer or the original buffer.
+ // Since innerBuffer is a slice of the original buffer, changes should
reflect
+ // if it's a direct slice.
+
+ // Let's check the byteBuf we created.
+ // assertEquals(5, byteBuf.getShort(0));
+ // Note: This assertion depends heavily on DBBaseFactory
implementation.
+ // If it doesn't write back immediately or uses a different mechanism,
this
+ // might fail.
+ // But for a unit test of the Factory logic (mapping), this is the
intention.
+ }
+
+ @Test
+ public void testGetFieldsToMonitor() {
+ String fields = record.getFieldsToMonitor();
+ assertNotNull(fields);
+ assertTrue(fields.contains("cmd{iMode"));
+ assertTrue(fields.contains("par{iSensorType"));
+ }
+}
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBAoFactoryTest.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBAoFactoryTest.java
new file mode 100644
index 0000000..2197166
--- /dev/null
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBAoFactoryTest.java
@@ -0,0 +1,178 @@
+/*
+ * 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.merlot.drv.s7.core;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import org.apache.plc4x.java.spi.values.PlcRawByteArray;
+import org.apache.plc4x.merlot.api.PlcItem;
+import org.apache.plc4x.merlot.api.impl.PlcItemImpl;
+import org.apache.plc4x.merlot.db.api.DBRecord;
+import org.epics.pvdata.pv.*;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.UUID;
+
+import static org.junit.Assert.*;
+
+public class S7DBAoFactoryTest {
+
+ private S7DBAoFactory factory;
+ private DBRecord record;
+ private PlcItem plcItem;
+ private ByteBuf byteBuf;
+
+ @Before
+ public void setUp() {
+ factory = new S7DBAoFactory();
+ record = factory.create("AO_TEST");
+
+ // Setup Buffer
+ byteBuf = Unpooled.buffer(64);
+ // Initialize buffer with some data
+
+ // iMode (short) at 0
+ byteBuf.setShort(0, 1);
+ // iErrorCode (short) at 2
+ byteBuf.setShort(2, 0);
+
+ // rValue (float) at 4
+ byteBuf.setFloat(4, 10.5f);
+ // rAutoValue (float) at 8
+ byteBuf.setFloat(8, 20.5f);
+ // rManualValue (float) at 12
+ byteBuf.setFloat(12, 30.5f);
+ // rEstopValue (float) at 16
+ byteBuf.setFloat(16, 40.5f);
+
+ // Byte 20: bPB_ResetError (0), bPBEN_ResetError (1), bError (2),
bInterlock (3)
+ byteBuf.setByte(20, 0b00001111); // All true
+
+ // iEstopFunction (short) at 22
+ byteBuf.setShort(22, 99);
+
+ // Byte 24: bOutOfRange (0), bConfigurationError (1)
+ byteBuf.setByte(24, 0b00000011); // All true
+
+ // iSensorType (short) at 26
+ byteBuf.setShort(26, 5);
+ // rInEngUnitsMin (float) at 28
+ byteBuf.setFloat(28, 0.0f);
+ // rInEngUnitsMax (float) at 32
+ byteBuf.setFloat(32, 100.0f);
+
+ // Setup PlcItem
+ String uuid = UUID.randomUUID().toString();
+ plcItem = new PlcItemImpl.PlcItemBuilder("ITEM_TEST")
+ .setItemDescription("Test Item")
+ .setItemId(uuid)
+ .setItemUid(UUID.fromString(uuid))
+ .build();
+
+ plcItem.setPlcValue(new PlcRawByteArray(byteBuf.array()));
+ }
+
+ @Test
+ public void testCreate() {
+ assertNotNull(record);
+ PVStructure pvStructure =
record.getPVRecordStructure().getPVStructure();
+ assertNotNull(pvStructure);
+
+ assertNotNull(pvStructure.getStructureField("cmd"));
+ assertNotNull(pvStructure.getStructureField("sts"));
+ assertNotNull(pvStructure.getStructureField("par"));
+ assertNotNull(pvStructure.getStringField("id"));
+ }
+
+ @Test
+ public void testAttach() {
+ PVString id =
record.getPVRecordStructure().getPVStructure().getStringField("id");
+ id.put("s7:%DB100:0:BYTE[64]");
+
+ record.atach(plcItem);
+
+ assertEquals(0, record.getByteOffset());
+ }
+
+ @Test
+ public void testUpdate() {
+ PVString id =
record.getPVRecordStructure().getPVStructure().getStringField("id");
+ id.put("s7:%DB100:0:BYTE[64]");
+ record.atach(plcItem);
+
+ record.update();
+
+ PVStructure pvStructure =
record.getPVRecordStructure().getPVStructure();
+ PVStructure cmd = pvStructure.getStructureField("cmd");
+ PVStructure sts = pvStructure.getStructureField("sts");
+ PVStructure par = pvStructure.getStructureField("par");
+
+ assertEquals(1, cmd.getShortField("iMode").get());
+ assertEquals(0, cmd.getShortField("iErrorCode").get());
+
+ assertEquals(10.5f, cmd.getFloatField("rValue").get(), 0.001f);
+ assertEquals(20.5f, cmd.getFloatField("rAutoValue").get(), 0.001f);
+ assertEquals(30.5f, cmd.getFloatField("rManualValue").get(), 0.001f);
+ assertEquals(40.5f, cmd.getFloatField("rEstopValue").get(), 0.001f);
+
+ assertEquals(true, cmd.getBooleanField("bPB_ResetError").get());
+ assertEquals(true, cmd.getBooleanField("bPBEN_ResetError").get());
+ assertEquals(true, cmd.getBooleanField("bError").get());
+ assertEquals(true, cmd.getBooleanField("bInterlock").get());
+
+ assertEquals(99, cmd.getShortField("iEstopFunction").get());
+
+ assertEquals(true, sts.getBooleanField("bOutOfRange").get());
+ assertEquals(true, sts.getBooleanField("bConfigurationError").get());
+
+ assertEquals(5, par.getShortField("iSensorType").get());
+ assertEquals(0.0f, par.getFloatField("rInEngUnitsMin").get(), 0.001f);
+ assertEquals(100.0f, par.getFloatField("rInEngUnitsMax").get(),
0.001f);
+ }
+
+ @Test
+ public void testProcess() {
+ PVString id =
record.getPVRecordStructure().getPVStructure().getStringField("id");
+ id.put("s7:%DB100:0:BYTE[64]");
+ record.atach(plcItem);
+
+ // Enable write
+ PVBoolean writeEnable =
record.getPVRecordStructure().getPVStructure().getBooleanField("write_enable");
+ writeEnable.put(true);
+
+ // Change a value in PV
+ PVStructure cmd =
record.getPVRecordStructure().getPVStructure().getStructureField("cmd");
+ cmd.getShortField("iMode").put((short) 5);
+
+ // Call process
+ record.process();
+
+ // In a real scenario, this would trigger a write to the PLC.
+ // Here we just verify no exception is thrown and the method completes.
+ }
+
+ @Test
+ public void testGetFieldsToMonitor() {
+ String fields = record.getFieldsToMonitor();
+ assertNotNull(fields);
+ assertTrue(fields.contains("cmd{iMode"));
+ assertTrue(fields.contains("par{iSensorType"));
+ }
+}
diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/pom.xml
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/pom.xml
index aebc555..6597845 100644
--- a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/pom.xml
+++ b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/pom.xml
@@ -89,5 +89,10 @@
<artifactId>org.apache.plc4x.merlot.api</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.plc4x.merlot.db</groupId>
+ <artifactId>org.apache.plc4x.merlot.db</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
</project>
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/src/main/java/org/apache/plc4x/merlot/drv/simulated/impl/SimulatedPlcModelFactoryImpl.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/src/main/java/org/apache/plc4x/merlot/drv/simulated/impl/SimulatedPlcModelFactoryImpl.java
new file mode 100644
index 0000000..078b079
--- /dev/null
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/src/main/java/org/apache/plc4x/merlot/drv/simulated/impl/SimulatedPlcModelFactoryImpl.java
@@ -0,0 +1,42 @@
+/*
+ * 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.merlot.drv.simulated.impl;
+
+import java.util.Optional;
+import org.apache.plc4x.merlot.api.PlcGeneralFunction;
+import org.apache.plc4x.merlot.api.PlcModel;
+import org.apache.plc4x.merlot.api.PlcModelFactory;
+import org.osgi.framework.BundleContext;
+
+/**
+ *
+ * @author cgarcia
+ */
+public class SimulatedPlcModelFactoryImpl implements PlcModelFactory {
+ private final BundleContext bc;
+ private final PlcGeneralFunction gf;
+
+ public SimulatedPlcModelFactoryImpl(BundleContext bc, PlcGeneralFunction
gf) {
+ this.bc = bc;
+ this.gf = gf;
+ }
+
+ @Override
+ public Optional<PlcModel> createPlcModel(String deviceCategory, String
deviceName) {
+ return Optional.of(new SimulatedPlcModelImpl(bc, gf));
+ }
+}
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/src/main/java/org/apache/plc4x/merlot/drv/simulated/impl/SimulatedPlcModelImpl.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/src/main/java/org/apache/plc4x/merlot/drv/simulated/impl/SimulatedPlcModelImpl.java
new file mode 100644
index 0000000..3b5308c
--- /dev/null
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/src/main/java/org/apache/plc4x/merlot/drv/simulated/impl/SimulatedPlcModelImpl.java
@@ -0,0 +1,172 @@
+/*
+ * 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.merlot.drv.simulated.impl;
+
+import io.netty.buffer.ByteBuf;
+import java.util.Optional;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.Level;
+import org.apache.plc4x.java.api.PlcConnection;
+import org.apache.plc4x.java.api.exceptions.PlcConnectionException;
+import org.apache.plc4x.java.api.messages.PlcWriteRequest;
+import org.apache.plc4x.java.api.messages.PlcWriteResponse;
+import org.apache.plc4x.java.api.value.PlcValue;
+import org.apache.plc4x.merlot.api.PlcDevice;
+import org.apache.plc4x.merlot.api.PlcGeneralFunction;
+import org.apache.plc4x.merlot.api.PlcGroup;
+import org.apache.plc4x.merlot.api.PlcItem;
+import org.apache.plc4x.merlot.api.PlcItemListener;
+import org.apache.plc4x.merlot.api.PlcModel;
+import org.apache.plc4x.merlot.api.core.PlcStaticHelper;
+import org.apache.plc4x.merlot.db.api.DBRecord;
+import org.osgi.framework.BundleContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ * @author cgarcia
+ */
+public class SimulatedPlcModelImpl implements PlcModel {
+
+ private static final Logger LOGGER =
LoggerFactory.getLogger(SimulatedPlcModelImpl.class);
+
+ private BundleContext bc;
+
+ private PlcGeneralFunction gf;
+
+ private PlcDevice plcDevice = null;
+
+
+ public SimulatedPlcModelImpl(BundleContext bc, PlcGeneralFunction gf) {
+ this.bc = bc;
+ this.gf = gf;
+ }
+
+ @Override
+ public Set<String> listMemoryAreas() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Integer getMemoryAreaId(String memoryArea) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void createMemoryArea(Object dbRecord) {
+ if (dbRecord instanceof String){
+ LOGGER.info("Creating an unsupported memory area with String.");
+ return;
+ } else if (dbRecord instanceof PlcItem){
+ final PlcItem plcItem = (PlcItem) dbRecord;
+ Optional<PlcGroup> optPlcGroup =
gf.getPlcItemGroup(plcItem.getItemUid());
+ if (optPlcGroup.isEmpty()){
+ LOGGER.info("000 Grupo no prsente...");
+ return;
+ }
+ final PlcDevice plcDevice =
gf.getPlcDevice(optPlcGroup.get().getGroupDeviceUid());
+ LOGGER.info("000");
+ if (null != plcDevice) {
+ LOGGER.info("001");
+ //Only for simulated driver
+ plcDevice.enable();
+ final PlcConnection plcConnection =
plcDevice.getPlcConnection();
+ if (plcConnection.isConnected()) {
+ try {
+ plcConnection.connect();
+ } catch (Exception ex) {
+ LOGGER.info("Failure connecting '{}'.",
ex.getMessage());
+ }
+ }
+ if (plcConnection.isConnected()) {
+ LOGGER.info("002");
+ final ByteBuf byteBuf = plcItem.getItemByteBuf();
+ Optional<PlcValue> optPlcValue =
PlcStaticHelper.ByteBufToPlcValue(byteBuf,
plcItem.getItemPlcTag().getPlcValueType());
+ if (optPlcValue.isPresent()) {
+ try {
+ LOGGER.info("003");
+ final PlcWriteRequest.Builder builder =
plcConnection.writeRequestBuilder();
+ builder.addTag(plcItem.getItemName(),
plcItem.getItemPlcTag(), optPlcValue.get());
+ final PlcWriteRequest writeRequest =
builder.build();
+ PlcWriteResponse writeResponse =
writeRequest.execute().get(1, TimeUnit.SECONDS);
+ LOGGER.info("004");
+ writeResponse.getTagNames().forEach( t->
+ LOGGER.info("Write tag[{}] is {}.", t,
writeResponse.getResponseCode(t))
+ );
+ } catch (Exception ex) {
+ LOGGER.info("Failure to create memory area {}.",
ex.getMessage());
+ }
+ } else {
+ LOGGER.info("Failure to create memory area for PlcItem
{} and Tag {}.", plcItem.getItemName(), plcItem.getItemPlcTag());
+ }
+
+ } else {
+ LOGGER.info("Device is not connected..");
+ }
+ }
+ return;
+ } else if (dbRecord instanceof DBRecord){
+ LOGGER.info("Creating an unsupported memory area with DBRecord.");
+ return;
+ };
+
+ }
+
+ @Override
+ public Optional<PlcItem> getMemoryAreaPlcItem(String memoryArea, Integer
index) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void createScanGroup(Object dbRecord) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void addMemoryAreaListener(String memoryArea, Integer index,
PlcItemListener listener) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void removeMemoryAreaListener(String memoryArea, Integer index,
PlcItemListener listener) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Integer getMemoryAreaSegmentCount(String memoryArea) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Set<Integer> getMemoryAreaSegmentIds(String memoryArea) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Set<UUID> getModelPlcGroupUuids(String memoryArea) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Set<UUID> getModelPlcItemUuids(String memoryArea) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+}
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/src/main/java/org/apache/plc4x/merlot/drv/simulated/impl/SimulatedPlcTagFunctionImpl.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/src/main/java/org/apache/plc4x/merlot/drv/simulated/impl/SimulatedPlcTagFunctionImpl.java
index ad9369f..8235564 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/src/main/java/org/apache/plc4x/merlot/drv/simulated/impl/SimulatedPlcTagFunctionImpl.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/src/main/java/org/apache/plc4x/merlot/drv/simulated/impl/SimulatedPlcTagFunctionImpl.java
@@ -20,6 +20,15 @@ import io.netty.buffer.ByteBuf;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.plc4x.java.api.model.PlcTag;
import static org.apache.plc4x.java.api.types.PlcValueType.BOOL;
+import static org.apache.plc4x.java.api.types.PlcValueType.BYTE;
+import static org.apache.plc4x.java.api.types.PlcValueType.DINT;
+import static org.apache.plc4x.java.api.types.PlcValueType.INT;
+import static org.apache.plc4x.java.api.types.PlcValueType.LINT;
+import static org.apache.plc4x.java.api.types.PlcValueType.SINT;
+import static org.apache.plc4x.java.api.types.PlcValueType.UDINT;
+import static org.apache.plc4x.java.api.types.PlcValueType.UINT;
+import static org.apache.plc4x.java.api.types.PlcValueType.ULINT;
+import static org.apache.plc4x.java.api.types.PlcValueType.USINT;
import org.apache.plc4x.java.simulated.tag.SimulatedTag;
import org.apache.plc4x.merlot.api.PlcTagFunction;
import org.osgi.framework.BundleContext;
@@ -33,7 +42,7 @@ import org.slf4j.LoggerFactory;
*/
public class SimulatedPlcTagFunctionImpl implements PlcTagFunction {
private static final Logger LOGGER =
LoggerFactory.getLogger(SimulatedPlcTagFunctionImpl.class);
- private static final boolean PLC4X_TAG = false;
+ private static final boolean PLC4X_TAG = true;
private BundleContext bc;
public SimulatedPlcTagFunctionImpl(BundleContext bc) {
@@ -85,7 +94,24 @@ public class SimulatedPlcTagFunctionImpl implements
PlcTagFunction {
/*
+ * getPlc4xPlcTag: This function creates the PlcTag for writing to a
+ + specific memory area in the "simulated" driver.
+ *
+ * The "simulated" driver addresses three specific memory areas, namely:
+ * STATE - This holds in memory a value for a given alias.
+ * This value can be read or written to, however this should
+ * only be used in conjunction with a persistent connection.
+ * Once the connection is closed the memory area is cleared.
+ * RANDOM - This provides a new random value for each read. When writing,
+ * a log message is recorded and the value is discarded.
+ * STDOUT - Always returns a null value when reading.
+ * When writing, a log message is recorded and the value is
+ * discarded.
+ * You must pay attention to write behavior.
+ * It is useful for testing higher-level data structures.
+ *
* TODO: Change constructor of SimulatedTag to public.
+ * TODO: Add getNumElements for the number of elements.
*/
private ImmutablePair<PlcTag, Object[]> getPlc4xPlcTag(PlcTag plcTag,
ByteBuf byteBuf, int byteOffset, byte bitOffset) {
LOGGER.info("PlcTag class {} and type {} ", plcTag.getClass(),
plcTag.getPlcValueType());
@@ -93,35 +119,80 @@ public class SimulatedPlcTagFunctionImpl implements
PlcTagFunction {
SimulatedTag simPlcTag = null;
if (plcTag instanceof SimulatedTag){
final SimulatedTag simTag = (SimulatedTag) plcTag;
- LOGGER.info("Processing SimulatedTag: {}", simTag.toString());
+ LOGGER.info("Processing SimulatedTag: {}", simTag.toString());
Object[] objValues = new Object[byteBuf.capacity()];
- StringBuilder strTagBuilder = new StringBuilder();
+ simPlcTag = SimulatedTag.of(simTag.getAddressString());
+ byteBuf.resetReaderIndex();
switch (simTag.getPlcValueType()) {
+ case NULL: break;
case BOOL:
- strTagBuilder.append("STDOUT/").
- append("merlot").
- append(":BOOL[").
- append(byteBuf.capacity()).
- append("]");
- simPlcTag = SimulatedTag.of(strTagBuilder.toString());
- byteBuf.resetReaderIndex();
- for (int i=0; i < byteBuf.capacity(); i++){
- objValues[i] = byteBuf.readBoolean();
- }
- break;
- case SINT:
- strTagBuilder.append("STDOUT/").
- append("merlot").
- append(":SINT[").
- append(byteBuf.capacity()).
- append("]");
- simPlcTag = SimulatedTag.of(strTagBuilder.toString());
- byteBuf.resetReaderIndex();
- for (int i=0; i < byteBuf.capacity(); i++){
- tempValue = (short) (byteBuf.readByte() & 0xFF);
- objValues[i] = tempValue;
- }
- break;
+ for (int i=0; i < byteBuf.capacity(); i++){
+ objValues[i] = byteBuf.readBoolean();
+ }
+ break;
+ case BYTE:
+ case SINT:
+ case USINT:
+ for (int i=0; i < byteBuf.capacity(); i++){
+ tempValue = (short) (byteBuf.readByte() &
0xFF);
+ objValues[i] = tempValue;
+ }
+ break;
+ case INT:
+ case UINT:
+ case WORD:
+ for (int i=0; i < byteBuf.capacity() /
Short.BYTES; i++){
+ objValues[i] =(short) (byteBuf.readShort() &
0xFFFF);
+ }
+ break;
+ case DINT:
+ case UDINT:
+ case DWORD:
+ for (int i=0; i < byteBuf.capacity() /
Integer.BYTES; i++){
+ objValues[i] = byteBuf.readInt();
+ }
+ break;
+ case LINT:
+ case ULINT:
+ case LWORD:
+ for (int i=0; i < byteBuf.capacity() / Long.BYTES;
i++){
+ objValues[i] = byteBuf.readLong();
+ }
+ break;
+ case REAL:
+ for (int i=0; i < byteBuf.capacity() /
Float.BYTES; i++){
+ objValues[i] = byteBuf.readFloat();
+ }
+ break;
+ case LREAL:
+ for (int i=0; i < byteBuf.capacity() /
Double.BYTES; i++){
+ objValues[i] = byteBuf.readDouble();
+ }
+ break;
+ case CHAR:
+ for (int i=0; i < byteBuf.capacity(); i++){
+ objValues[i] = byteBuf.readChar();
+ }
+ break;
+ case WCHAR:
+ for (int i=0; i < byteBuf.capacity() /
Short.BYTES; i++){
+ objValues[i] = byteBuf.readShort();
+ }
+ break;
+ case STRING:
+ case WSTRING:
+ case TIME:
+ case LTIME:
+ case DATE:
+ case LDATE:
+ case TIME_OF_DAY:
+ case LTIME_OF_DAY:
+ case DATE_AND_TIME:
+ case DATE_AND_LTIME:
+ case LDATE_AND_TIME:
+ case Struct:
+ case List:
+ case RAW_BYTE_ARRAY:
default:;
}
if (null != simPlcTag)
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/src/main/resources/OSGI-INF/blueprint/simulated-drv-service.xml
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/src/main/resources/OSGI-INF/blueprint/simulated-drv-service.xml
index 6cfb9e2..697e4e3 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/src/main/resources/OSGI-INF/blueprint/simulated-drv-service.xml
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.simulated/src/main/resources/OSGI-INF/blueprint/simulated-drv-service.xml
@@ -23,7 +23,12 @@
<reference id="serviceEventAdmin"
interface="org.osgi.service.event.EventAdmin">
- </reference>
+ </reference>
+
+
+ <reference
+ id="refPlcGeneralFunction"
+ interface="org.apache.plc4x.merlot.api.PlcGeneralFunction"
availability="mandatory" timeout="1200"/>
<!-- <bean id="SimRefDrvImpl"
class="org.apache.plc4x.merlot.drv.simulated.impl.SimulatedReferringDriverImpl"
scope="singleton">
<argument ref="blueprintBundleContext"/>
@@ -33,6 +38,11 @@
<bean id="SimPlcTagFunction"
class="org.apache.plc4x.merlot.drv.simulated.impl.SimulatedPlcTagFunctionImpl"
scope="singleton">
<argument ref="blueprintBundleContext"/>
</bean>
+
+ <bean id="SimPlcModelFactoryBean"
class="org.apache.plc4x.merlot.drv.simulated.impl.SimulatedPlcModelFactoryImpl"
scope="singleton">
+ <argument ref="refPlcGeneralFunction"/>
+ <argument ref="blueprintBundleContext"/>
+ </bean>
<reference id="servicePLC4XSimulated"
interface="org.apache.plc4x.java.api.PlcDriver"
@@ -57,5 +67,11 @@
<entry key="dal.function.type" value=""/>
</service-properties>
</service>
+
+ <service ref="SimPlcModelFactoryBean"
interface="org.apache.plc4x.merlot.api.PlcModelFactory">
+ <service-properties>
+ <entry key="plc4x.plcmodel.category" value="simulated"/>
+ </service-properties>
+ </service>
</blueprint>
\ No newline at end of file