You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cg...@apache.org on 2024/08/27 13:05:44 UTC
(plc4x-extras) branch feature/merlot updated: Correcting code.
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 1f526fc Correcting code.
1f526fc is described below
commit 1f526fc25239fc855bf3459c992c0496d9e8768f
Author: César García <ce...@ceos.com.ve>
AuthorDate: Tue Aug 27 09:04:54 2024 -0400
Correcting code.
---
.../plc4x/merlot/api/PlcGeneralFunction.java | 19 +++--
.../plc4x/merlot/api/command/DemoCommand002.java | 10 +--
.../plc4x/merlot/api/command/DemoCommand003.java | 87 ----------------------
.../api/command/PlcDeviceControlCommand.java | 20 ++---
...roupNewCommand.java => PlcGroupNewCommand.java} | 9 +--
.../merlot/api/command/PlcItemControlCommand.java | 25 +++++--
...{DemoCommand004.java => PlcItemNewCommand.java} | 6 +-
.../merlot/api/core/PlcDeviceManagedService.java | 8 +-
.../plc4x/merlot/api/impl/PlcDeviceImpl.java | 22 +++---
.../merlot/api/impl/PlcGeneralFunctionImpl.java | 84 ++++++++++++++-------
.../apache/plc4x/merlot/api/impl/PlcGroupImpl.java | 25 +++----
.../apache/plc4x/merlot/api/impl/PlcItemImpl.java | 45 ++++++-----
.../cfg/org.apache.plc4x.merlot.db.records.cfg | 1 +
.../plc4x/merlot/db/command/DBAddCommand.java | 69 ++++++++---------
.../apache/plc4x/merlot/db/core/DBBaseFactory.java | 50 +++++++------
.../apache/plc4x/merlot/db/core/DBByteFactory.java | 31 +++++++-
.../plc4x/merlot/db/core/DBDoubleFactory.java | 30 +++++++-
.../plc4x/merlot/db/core/DBFloatFactory.java | 12 ++-
.../apache/plc4x/merlot/db/core/DBIntFactory.java | 34 ++++++++-
.../apache/plc4x/merlot/db/core/DBLongFactory.java | 32 +++++++-
.../merlot/db/core/DBRecordsManagedService.java | 4 -
.../plc4x/merlot/db/core/DBShortFactory.java | 13 ++--
.../plc4x/merlot/db/core/DBStringFactory.java | 33 +++++++-
.../plc4x/merlot/db/core/DBUByteFactory.java | 30 +++++++-
.../apache/plc4x/merlot/db/core/DBUIntFactory.java | 32 +++++++-
.../plc4x/merlot/db/core/DBULongFactory.java | 32 +++++++-
.../plc4x/merlot/db/core/DBUShortFactory.java | 10 ++-
27 files changed, 488 insertions(+), 285 deletions(-)
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 768c7c2..84cca92 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
@@ -20,7 +20,9 @@ package org.apache.plc4x.merlot.api;
import io.netty.buffer.ByteBuf;
import java.util.Map;
+import java.util.Optional;
import java.util.UUID;
+import org.apache.plc4x.java.api.types.PlcValueType;
import org.apache.plc4x.java.api.value.PlcValue;
@@ -109,6 +111,11 @@ public interface PlcGeneralFunction extends PlcFunction {
*/
public void setPlcDeviceDesc(UUID device_uid, String device_desc);
+ /*
+ *
+ */
+ public Map<UUID, String> getPlcGroups();
+
/*
* Returns a map of groups associated with the device defined by device_uid,
* where key corresponds to the uid of the group, and the value to its name.
@@ -139,7 +146,7 @@ public interface PlcGeneralFunction extends PlcFunction {
* and value corresponding to this property of the device.
*/
public int setPlcGroupScanRate(UUID group_uid, long scan_rate);
-
+
/*
* Returns the number of items associated with the
* indicated group of group_id.
@@ -167,7 +174,7 @@ public interface PlcGeneralFunction extends PlcFunction {
* @param item_uid String representation of the item's UUID.
* @return Return a short value, representing the value type.
*/
- public PlcItem getPlcItem(UUID item_uid);
+ public Optional<PlcItem> getPlcItem(UUID item_uid);
/*
* Returns the data type associated with the item as defined in
@@ -176,7 +183,7 @@ public interface PlcGeneralFunction extends PlcFunction {
* @param item_uid String representation of the item's UUID.
* @return Return a short value, representing the value type.
*/
- public short getPlcItemType(UUID item_uid);
+ public Optional<PlcValueType> getPlcItemType(UUID item_uid);
/*
* Returns the value associated with the Item.
@@ -185,7 +192,7 @@ public interface PlcGeneralFunction extends PlcFunction {
* @return Return a short value, representing the value type.
* It can be null.
*/
- public PlcValue getPlcItemValue(UUID item_uid);
+ public Optional<PlcValue> getPlcItemValue(UUID item_uid);
/*
* Returns the value associated with the Item as a ByteBuf.
@@ -193,7 +200,7 @@ public interface PlcGeneralFunction extends PlcFunction {
* @param item_uid String representation of the item's UUID.
* @return Return a short value, representing the value type.
*/
- public ByteBuf getPlcItemByteBuf(UUID item_uid);
+ public Optional<ByteBuf> getPlcItemByteBuf(UUID item_uid);
/*
* Returns the value associated with the Item as a byte array.
@@ -201,7 +208,7 @@ public interface PlcGeneralFunction extends PlcFunction {
* @return Return a short value, representing the value type.
*/
- public byte[] getPlcItemBytes(UUID item_uid);
+ public Optional<byte[]> getPlcItemBytes(UUID item_uid);
/*
* Enables the element corresponding to the UUID.
diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/DemoCommand002.java b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/DemoCommand002.java
index f58508c..df9151f 100644
--- a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/DemoCommand002.java
+++ b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/DemoCommand002.java
@@ -55,25 +55,23 @@ public class DemoCommand002 implements Action {
@Override
public Object execute() throws Exception {
-
-
-
+
devices.stream().
filter(p -> p.getUid().toString().equalsIgnoreCase(gid)).
forEach(d -> {
PlcItem item;
PlcGroup grupo1 = new PlcGroupImpl.PlcGroupBuilder(bc, group_name, UUID.randomUUID()).
setGroupPeriod(5000L).
- setItemService(items_service).
+ //setItemService(items_service).
setGroupDeviceUid(d.getUid()).
build();
d.putGroup(grupo1);
- for (int i=0; i<1; i++) {
+ for (int i=0; i<2; i++) {
item = new PlcItemImpl.PlcItemBuilder("ITEM_00" + i).
setItemDescription("THE ITEM 00" + i).
- setItemId("RANDOM/foo_" +i + ":INT").
+ setItemId("RANDOM/foo_" +i + ":INT[10]").
setItemEnable(true).
build();
diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/DemoCommand003.java b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/DemoCommand003.java
deleted file mode 100644
index 5e16425..0000000
--- a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/DemoCommand003.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * 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.api.command;
-
-import java.util.List;
-import org.apache.karaf.shell.api.action.Action;
-import org.apache.karaf.shell.api.action.Argument;
-import org.apache.karaf.shell.api.action.Command;
-import org.apache.karaf.shell.api.action.Option;
-import org.apache.karaf.shell.api.action.lifecycle.Reference;
-import org.apache.karaf.shell.api.action.lifecycle.Service;
-import org.apache.plc4x.java.api.value.PlcValue;
-import org.osgi.framework.BundleContext;
-import org.apache.plc4x.merlot.api.PlcGroup;
-import org.apache.plc4x.merlot.api.PlcItem;
-import org.apache.plc4x.merlot.api.PlcItemClient;
-import org.apache.plc4x.merlot.api.core.PlcItemClientService;
-import org.apache.plc4x.merlot.api.impl.PlcItemImpl;
-
-
-@Command(scope = "plc4x", name = "demo_003", description = "Command for test.")
-@Service
-public class DemoCommand003 implements Action, PlcItemClient {
-
- @Reference
- BundleContext bc;
-
- @Reference
- PlcItemClientService clients;
-
- @Reference
- volatile List<PlcGroup> groups;
-
- @Option(name = "-g", aliases = "--gid", description = "Group uid.", required = true, multiValued = false)
- String gid;
-
- @Argument(index = 0, name = "name", description = "Item name", required = true, multiValued = false)
- String item_name;
-
- @Argument(index = 1, name = "desc", description = "Item description", required = true, multiValued = false)
- String item_desc;
-
- @Argument(index = 2, name = "id", description = "Item id", required = true, multiValued = false)
- String item_id;
-
- @Argument(index = 3, name = "enbale", description = "Enable the item", required = true, multiValued = false)
- Boolean item_enable = false;
-
- @Override
- public Object execute() throws Exception {
-
- groups.stream().
- filter(g -> g.getGroupUid().toString().equalsIgnoreCase(gid)).
- forEach(g -> {
- PlcItem item = new PlcItemImpl.PlcItemBuilder(item_name).
- setItemDescription(item_desc).
- setItemId(item_id).
- setItemEnable(item_enable).
- build();
- g.putItem(item);
-
- clients.subcription(this, item.getItemUid());
- });
-
- return null;
- }
-
- @Override
- public void execute(PlcValue plcvalue) {
- System.out.println("Value: " + plcvalue.getString());
- }
-
-}
diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/PlcDeviceControlCommand.java b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/PlcDeviceControlCommand.java
index 0d6593b..ed96f80 100644
--- a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/PlcDeviceControlCommand.java
+++ b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/PlcDeviceControlCommand.java
@@ -18,11 +18,13 @@
*/
package org.apache.plc4x.merlot.api.command;
+import java.util.UUID;
import org.apache.karaf.shell.api.action.Action;
import org.apache.karaf.shell.api.action.Command;
import org.apache.karaf.shell.api.action.Option;
import org.apache.karaf.shell.api.action.lifecycle.Reference;
import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.apache.plc4x.merlot.api.PlcDevice;
import org.apache.plc4x.merlot.api.PlcGeneralFunction;
@Command(scope = "plc4x", name = "device-ctrl", description = "List all channels")
@@ -44,15 +46,15 @@ public class PlcDeviceControlCommand implements Action {
@Override
public Object execute() throws Exception {
-// final PlcDevice dev = plcservice.getPlcDevice(UUID.fromString(did));
-//
-// if (null != dev) {
-// if (enable) {
-// dev.enable();
-// } else if (disable) {
-// dev.disable();
-// }
-// }
+ final PlcDevice dev = plcservice.getPlcDevice(UUID.fromString(did));
+
+ if (null != dev) {
+ if (enable) {
+ dev.enable();
+ } else if (disable) {
+ dev.disable();
+ }
+ }
return null;
}
diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/PlcDeviceGroupNewCommand.java b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/PlcGroupNewCommand.java
similarity index 92%
rename from plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/PlcDeviceGroupNewCommand.java
rename to plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/PlcGroupNewCommand.java
index 6b5962d..0fc5c6d 100644
--- a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/PlcDeviceGroupNewCommand.java
+++ b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/PlcGroupNewCommand.java
@@ -33,9 +33,9 @@ import org.osgi.framework.BundleContext;
import org.apache.plc4x.merlot.api.PlcGroup;
import org.apache.plc4x.merlot.api.impl.PlcGroupImpl;
-@Command(scope = "plc4x", name = "group-new", description = "Create group for a device.")
+@Command(scope = "plc4x", name = "group-new", description = "Create new group for a device.")
@Service
-public class PlcDeviceGroupNewCommand implements Action {
+public class PlcGroupNewCommand implements Action {
@Reference
BundleContext bc;
@@ -81,10 +81,7 @@ public class PlcDeviceGroupNewCommand implements Action {
PlcGroup group = new PlcGroupImpl.PlcGroupBuilder(bc, name).
setGroupPeriod(scantime).build();
- plcDevice.get().putGroup(group);
-
- bc.registerService(new String[]{Job.class.getName(), PlcGroup.class.getName()},
- group, group.getProperties());
+ plcDevice.get().putGroup(group);
} else {
System.out.println("A group with that name already exists.");
diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/PlcItemControlCommand.java b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/PlcItemControlCommand.java
index 8b716de..00ca414 100644
--- a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/PlcItemControlCommand.java
+++ b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/PlcItemControlCommand.java
@@ -18,6 +18,7 @@
*/
package org.apache.plc4x.merlot.api.command;
+import java.util.Optional;
import java.util.UUID;
import org.apache.karaf.shell.api.action.Action;
import org.apache.karaf.shell.api.action.Command;
@@ -38,23 +39,31 @@ public class PlcItemControlCommand implements Action {
@Option(name = "-i", aliases = "--iid", description = "Item uid.", required = true, multiValued = false)
String iid;
- @Option(name = "-e", aliases = "--enable", description = "Enable the device.", required = false, multiValued = false)
+ @Option(name = "-e", aliases = "--enable", description = "Enable the item.", required = false, multiValued = false)
Boolean enable = false;
- @Option(name = "-x", aliases = "--disable", description = "Disable the device.", required = false, multiValued = false)
- Boolean disable = false;
+ @Option(name = "-x", aliases = "--disable", description = "Disable the item.", required = false, multiValued = false)
+ Boolean disable = false;
+
+ @Option(name = "-p", aliases = "--print", description = "Print item information.", required = false, multiValued = false)
+ Boolean print = false;
@Override
public Object execute() throws Exception {
UUID item_uid = UUID.fromString(iid);
- final PlcItem item = plcservice.getPlcItem(item_uid);
+ Optional<PlcItem> item = plcservice.getPlcItem(item_uid);
- if (null != item){
+ if (item.isPresent()){
if (enable) {
- item.enable();
+ item.get().enable();
} else if (disable) {
- item.disable();
- }
+ item.get().disable();
+ }
+
+ if (print) System.out.println(item.get().toString());
+
+ } else {
+ System.out.println("Item not found.");
}
return null;
diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/DemoCommand004.java b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/PlcItemNewCommand.java
similarity index 94%
rename from plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/DemoCommand004.java
rename to plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/PlcItemNewCommand.java
index 6e7d913..f4acbb4 100644
--- a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/DemoCommand004.java
+++ b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/command/PlcItemNewCommand.java
@@ -32,9 +32,9 @@ import org.apache.plc4x.merlot.api.core.PlcItemClientService;
import org.apache.plc4x.merlot.api.impl.PlcItemImpl;
-@Command(scope = "plc4x", name = "demo_004", description = "Prueba Registro glo.")
+@Command(scope = "plc4x", name = "item-new", description = "Prueba Registro glo.")
@Service
-public class DemoCommand004 implements Action, PlcItemClient {
+public class PlcItemNewCommand implements Action, PlcItemClient {
@Reference
BundleContext bc;
@@ -73,7 +73,7 @@ public class DemoCommand004 implements Action, PlcItemClient {
build();
g.putItem(item);
- clients.subcription(this, item.getItemUid());
+ //clients.subcription(this, item.getItemUid());
});
return null;
diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/core/PlcDeviceManagedService.java b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/core/PlcDeviceManagedService.java
index 17a623c..8951193 100644
--- a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/core/PlcDeviceManagedService.java
+++ b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/core/PlcDeviceManagedService.java
@@ -24,6 +24,7 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
+import java.util.logging.Level;
import org.apache.plc4x.java.api.PlcDriver;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@@ -108,6 +109,7 @@ public class PlcDeviceManagedService implements ManagedService, ConfigurationLis
PlcDevice device = bdf.create(key.toString(), drv_data[0], drv_data[1], drv_data[2]);
if (device != null) {
+ device.init();
bc.registerService(org.apache.plc4x.merlot.api.PlcDevice.class.getName(), device, device.getProperties());
} else {
@@ -132,7 +134,9 @@ public class PlcDeviceManagedService implements ManagedService, ConfigurationLis
PlcDeviceFactory bdf = (PlcDeviceFactory) bc.getService(reference);
drv_data = driver_information.split(",",3);
PlcDevice device = bdf.create(key.toString() , drv_data[0], drv_data[1], drv_data[2]);
-
+
+
+ device.init();
bc.registerService(org.apache.plc4x.merlot.api.PlcDevice.class.getName(), device, device.getProperties());
} else {
@@ -142,6 +146,8 @@ public class PlcDeviceManagedService implements ManagedService, ConfigurationLis
}
} catch (InvalidSyntaxException ex) {
LOGGER.info("Exception: " + ex);
+ } catch (Exception ex) {
+ LOGGER.info("Exception: " + ex);
}
} else {
LOGGER.info("Key not valid: " + key.toString() + " : " + drv_data[0]);
diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcDeviceImpl.java b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcDeviceImpl.java
index 1f5b304..9ba4f08 100644
--- a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcDeviceImpl.java
+++ b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcDeviceImpl.java
@@ -27,8 +27,6 @@ import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.UUID;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import static java.util.stream.Collectors.toList;
import org.apache.commons.lang3.time.StopWatch;
@@ -40,7 +38,6 @@ import org.apache.plc4x.java.api.messages.PlcReadResponse;
import org.apache.plc4x.java.api.messages.PlcWriteRequest;
import org.apache.plc4x.java.api.messages.PlcWriteResponse;
import org.apache.plc4x.java.api.model.PlcTag;
-import org.apache.plc4x.java.api.types.PlcValueType;
import org.apache.plc4x.java.api.value.PlcValue;
import org.apache.plc4x.java.simulated.tag.SimulatedTag;
import org.apache.plc4x.merlot.api.PlcDevice;
@@ -144,26 +141,27 @@ public class PlcDeviceImpl implements PlcDevice {
final PlcReadRequest.Builder builder = refPlcConnection.get().readRequestBuilder();
event.getPlcGroup().getGroupItems().forEach((u,i) ->{
if (i.isEnable()) {
- builder.addTagAddress(u.toString(), i.getItemId());
+ builder.addTagAddress(i.getItemName(), i.getItemId());
}
});
final PlcReadRequest readRequest = builder.build();
try {
final PlcReadResponse syncResponse = readRequest.execute().get();
event.getPlcGroup().getGroupItems().forEach((u,i) -> {
- final PlcValue plcValue = syncResponse.getPlcValue(u.toString());
+ final PlcValue plcValue = syncResponse.getPlcValue(i.getItemName());
if (null == plcValue) {
- LOGGER.info(u.toString() + " Null value");
- } else
- LOGGER.info("Write " + i.getItemName());
- i.setPlcValue(plcValue);
+ LOGGER.info("Item[{}] = {} ", i.getItemName(),"Null value");
+ } else {
+ LOGGER.info("Item[{}] Read ", i.getItemName());
+ i.setPlcValue(plcValue);
+ }
});
} catch (Exception ex) {
LOGGER.info(ex.getMessage());
}
watch.stop();
- LOGGER.debug("Elapse time: " + watch.getTime());
+ LOGGER.debug("Elapse time Group[{}] time: {}",event.getPlcGroup().getGroupName(), watch.getTime());
watch.reset();
} else {
LOGGER.info("The driver is disconnected.");
@@ -257,12 +255,13 @@ public class PlcDeviceImpl implements PlcDevice {
//Try to connect
final String url = (String) deviceProperties.get(Device.SERVICE_DRIVER);
try {
+ System.out.println("URL : " + url);
plcConnection = plcDriver.getConnection(url);
plcConnection.connect();
refPlcConnection.set(plcConnection);
if (plcConnection.isConnected()) {
enable = true;
- LOGGER.info("Device [{}] was enbale.", deviceProperties.get(Device.SERVICE_NAME));
+ LOGGER.info("Device [{}] was enable.", deviceProperties.get(Device.SERVICE_NAME));
} else {
LOGGER.info("The connection could not be established, check the url.");
}
@@ -353,6 +352,7 @@ public class PlcDeviceImpl implements PlcDevice {
if ((!enable) && (!deviceGroups.containsKey(group.getGroupUid()))) {
group.setGroupDeviceUid(UUID.fromString((String) deviceProperties.get(PlcDevice.SERVICE_UID)));
group.setPlcConnection(refPlcConnection);
+ group.setReadRingBuffer(readRingBuffer);
deviceGroups.put(group.getGroupUid(), group);
bc.registerService(new String[]{Job.class.getName(),
PlcGroup.class.getName()},
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 61030e5..c6135d8 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
@@ -21,8 +21,11 @@ import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
import java.util.UUID;
import org.apache.plc4x.java.api.PlcDriver;
+import org.apache.plc4x.java.api.types.PlcValueType;
import org.apache.plc4x.java.api.value.PlcValue;
import org.apache.plc4x.merlot.api.PlcDevice;
import org.apache.plc4x.merlot.api.PlcDeviceFactory;
@@ -59,6 +62,8 @@ public class PlcGeneralFunctionImpl implements PlcGeneralFunction {
PlcDevice.class.getName() + ")" +
"(" + PlcDevice.SERVICE_UID + "=*))";
+ private static String FILTER_GROUPS = "(" + Constants.OBJECTCLASS + "=" + PlcGroup.class.getName() + ")";
+
private static String FILTER_DEVICE_GROUP = "(&(" + Constants.OBJECTCLASS + "=" + PlcGroup.class.getName() + ")" +
"(" + org.apache.plc4x.merlot.api.PlcGroup.GROUP_DEVICE_UID + "=*))";
@@ -483,6 +488,27 @@ public class PlcGeneralFunctionImpl implements PlcGeneralFunction {
}
}
+ //Groups
+
+ @Override
+ public Map<UUID, String> getPlcGroups(){
+ Map<UUID, String> plcgroups = new HashMap<>();
+
+ try {
+ ServiceReference[] refs = bc.getServiceReferences((String) null, FILTER_GROUPS);
+ if (null != refs) {
+ for (ServiceReference ref:refs){
+ final PlcGroup group = (PlcGroup) bc.getService(ref);
+ plcgroups.put(group.getGroupUid(),group.getGroupName());
+ }
+ }
+ } catch (InvalidSyntaxException ex) {
+ LOGGER.info(ex.getMessage());
+ } finally {
+ return plcgroups;
+ }
+ }
+
@Override
public Map<UUID, String> getPlcDeviceGroups(UUID device_uid) {
Map<UUID, String> plcgroups = new HashMap<>();
@@ -552,49 +578,57 @@ public class PlcGeneralFunctionImpl implements PlcGeneralFunction {
@Override
public Map<UUID, String> getPlcGroupItems(UUID group_uid) {
- Map<UUID, String> plcitems = new HashMap<>();
+ Map<UUID, String> plcItems = new HashMap<>();
final PlcGroup plcgroup = getPlcGroup(group_uid);
List<PlcItem> items = plcgroup.getItems();
- items.forEach(i -> {plcitems.put(i.getItemUid(), i.getItemName());});
- return plcitems;
+ items.forEach(i -> {plcItems.put(i.getItemUid(), i.getItemName());});
+ return plcItems;
}
//Items
-
- @Override
- public PlcItem getPlcItem(UUID item_uid) {
- String filter = FILTER_ITEM_UID.replace("*", item_uid.toString());
- ServiceReference ref = bc.getServiceReference(filter);
- if (null != ref) {
- final PlcItem plcitem = (PlcItem) bc.getService(ref);
- return plcitem;
- };
- return null;
+ @Override
+ public Optional<PlcItem> getPlcItem(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());
+ Optional<PlcItem> item = plcgroup.getItems().stream().
+ filter(i -> i.getItemUid().equals(item_uid)).findFirst();
+ if (item.isPresent()) return item;
+ }
+ return Optional.empty();
}
+ //TODO: El item no debe almacenar PlcValue
@Override
- public short getPlcItemType(UUID item_uid) {
- final PlcItem item = getPlcItem(item_uid);
- return item.getItemPlcValue().getPlcValueType().getValue();
+ public Optional<PlcValueType> getPlcItemType(UUID item_uid) {
+ Optional<PlcItem> item = getPlcItem(item_uid);
+ if (item.isPresent()) return Optional.of(item.get().getItemPlcValue().getPlcValueType());
+ return Optional.empty();
}
@Override
- public PlcValue getPlcItemValue(UUID item_uid) {
- final PlcItem item = getPlcItem(item_uid);
- return item.getItemPlcValue();
+ public Optional<PlcValue> getPlcItemValue(UUID item_uid) {
+ Optional<PlcItem> item = getPlcItem(item_uid);
+ if (item.isPresent()) return Optional.of(item.get().getItemPlcValue());
+ return Optional.empty();
}
@Override
- public ByteBuf getPlcItemByteBuf(UUID item_uid) {
- final PlcItem item = getPlcItem(item_uid);
- return item.getItemByteBuf();
+ public Optional<ByteBuf> getPlcItemByteBuf(UUID item_uid) {
+ Optional<PlcItem> item = getPlcItem(item_uid);
+ if (item.isPresent()) return Optional.of(item.get().getItemByteBuf());
+ return Optional.empty();
}
@Override
- public byte[] getPlcItemBytes(UUID item_uid) {
- final PlcItem item = getPlcItem(item_uid);
- return item.getInnerBuffer();
+ public Optional<byte[]> getPlcItemBytes(UUID item_uid) {
+ Optional<PlcItem> item = getPlcItem(item_uid);
+ if (item.isPresent()) return Optional.of(item.get().getItemByteBuf().array());
+ return Optional.empty();
}
@Override
diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcGroupImpl.java b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcGroupImpl.java
index 129e681..a65d004 100644
--- a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcGroupImpl.java
+++ b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/impl/PlcGroupImpl.java
@@ -67,7 +67,7 @@ public class PlcGroupImpl implements PlcGroup, Job {
private PlcItemClientService groupItemsService = null;
- private AtomicReference<PlcConnection> plcConnection = null;
+ private AtomicReference<PlcConnection> refPlcConnection = null;
private PlcReadRequest.Builder builder = null;
private StopWatch watch = new StopWatch();
@@ -95,8 +95,8 @@ public class PlcGroupImpl implements PlcGroup, Job {
public void start(int bc){
//
- if (null != plcConnection) {
- if (plcConnection.get().isConnected()) {
+ if (null != refPlcConnection) {
+ if (refPlcConnection.get().isConnected()) {
enable = true;
} else {
enable = false;
@@ -193,10 +193,11 @@ public class PlcGroupImpl implements PlcGroup, Job {
return aux[0];
}
+ //TODO: Check the interface
@Override
- public void setPlcConnection(AtomicReference<PlcConnection> plcConnection) {
+ public void setPlcConnection(AtomicReference<PlcConnection> refPlcConnection) {
LOGGER.info("Grupo [{}] Volatile: Se asigno la conexión.", groupProperties.get(PlcGroup.GROUP_NAME));
- this.plcConnection = plcConnection;
+ this.refPlcConnection = refPlcConnection;
}
@Override
@@ -218,7 +219,7 @@ public class PlcGroupImpl implements PlcGroup, Job {
public void putItem(PlcItem item) {
if (!groupItems.containsKey(item.getItemUid())) {
groupItems.put(item.getItemUid(), item);
- bc.registerService(PlcItem.class.getName(), item, item.getProperties());
+ //bc.registerService(PlcItem.class.getName(), item, item.getProperties());
}
}
@@ -245,22 +246,20 @@ public class PlcGroupImpl implements PlcGroup, Job {
@Override
public void execute(JobContext context) {
if (enable) {
- if (null != plcConnection) {
- if (plcConnection.get().isConnected()) {
- watch.start();
+ if ((null != refPlcConnection) && (null != refPlcConnection.get())) {
+ if (refPlcConnection.get().isConnected()) {
//executeReadAllItems();
long sequenceId = readRingBuffer.next();
final PlcDeviceReadEvent readEvent = readRingBuffer.get(sequenceId);
readEvent.setPlcGroup(this);
readRingBuffer.publish(sequenceId);
- watch.stop();
LOGGER.info("Elapse time: " + watch.getTime());
- watch.reset();
+ watch.reset();
} else {
LOGGER.info("The driver is disconnected.");
}
} else {
- LOGGER.info("Unassigned connection.");
+ LOGGER.info("Unassigned or null PlcConnection connection.");
}
} else {
LOGGER.info("The group {}:{} is disable.",
@@ -287,7 +286,7 @@ public class PlcGroupImpl implements PlcGroup, Job {
*/
public void executeReadAllItems() {
//1. The item was
- builder = plcConnection.get().readRequestBuilder();
+ builder = refPlcConnection.get().readRequestBuilder();
groupItems.forEach((u,i) ->{
if (i.isEnable()) {
builder.addTagAddress(u.toString(), i.getItemId());
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 bf8a543..9231461 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
@@ -22,6 +22,7 @@ import com.lmax.disruptor.RingBuffer;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
+import java.time.Instant;
import java.util.Date;
import java.util.Hashtable;
import java.util.LinkedList;
@@ -221,25 +222,35 @@ public class PlcItemImpl implements PlcItem {
@Override
public void setPlcValue(PlcValue plcvalue) {
-
- if (null == itemInnerBuffer) {
- int size = (plcvalue instanceof PlcList) ?
- ((PlcList) plcvalue).getLength() *
- ((PlcList) plcvalue).getList().get(0).getRaw().length :
- -1;
- itemInnerBuffer = (size == -1) ? new byte[plcvalue.getRaw().length] :
- new byte[size];
- itemBuffer = Unpooled.wrappedBuffer(itemInnerBuffer);
- }
-
- itemBuffer.resetWriterIndex();
- if (plcvalue instanceof PlcList) {
- ((PlcList) plcvalue).getList().forEach(v -> itemBuffer.writeBytes(v.getRaw()));
- } else {
- itemBuffer.writeBytes(plcvalue.getRaw());
+ try {
+ if (null == itemInnerBuffer) {
+ int size = (plcvalue instanceof PlcList) ?
+ ((PlcList) plcvalue).getLength() *
+ ((PlcList) plcvalue).getList().get(0).getRaw().length :
+ -1;
+ itemInnerBuffer = (size == -1) ? new byte[plcvalue.getRaw().length] :
+ new byte[size];
+ itemBuffer = Unpooled.wrappedBuffer(itemInnerBuffer);
+ }
+
+ itemBuffer.resetWriterIndex();
+ if (plcvalue instanceof PlcList) {
+ ((PlcList) plcvalue).getList().forEach(v -> itemBuffer.writeBytes(v.getRaw()));
+ } else {
+ itemBuffer.writeBytes(plcvalue.getRaw());
+ }
+ } catch (Exception ex){
+ itemErrors++;
+ lastErrorDate = Date.from(Instant.now());
}
+
+ //Update stat data
+ itemReceives++;
+ lastReadDate = Date.from(Instant.now());
+ //Update all clients
itemClients.forEach(c -> c.update());
+
//
// lock.lock();
// try {
@@ -345,8 +356,8 @@ public class PlcItemImpl implements PlcItem {
@Override
public void removeItemListener(PlcItemListener client) {
if (!itemClients.contains(client)) {
+ client.detach();
itemClients.remove(client);
- client.detach();
}
}
diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/cfg/org.apache.plc4x.merlot.db.records.cfg b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/cfg/org.apache.plc4x.merlot.db.records.cfg
index 222f6d7..1e91afd 100644
--- a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/cfg/org.apache.plc4x.merlot.db.records.cfg
+++ b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/cfg/org.apache.plc4x.merlot.db.records.cfg
@@ -31,6 +31,7 @@
# . record_name:
# . type:
# . id:
+# . offset:
# . description:
# . scan_time:
# . scan_enable:
diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/command/DBAddCommand.java b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/command/DBAddCommand.java
index d0964e8..64852b4 100644
--- a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/command/DBAddCommand.java
+++ b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/command/DBAddCommand.java
@@ -27,6 +27,7 @@ import org.apache.karaf.shell.api.action.Option;
import org.apache.karaf.shell.api.action.lifecycle.Reference;
import org.apache.karaf.shell.api.action.lifecycle.Service;
import org.epics.pvdata.pv.PVBoolean;
+import org.epics.pvdata.pv.PVInt;
import org.epics.pvdata.pv.PVString;
import org.epics.pvdata.pv.PVStructure;
import org.epics.pvdatabase.PVDatabase;
@@ -49,28 +50,37 @@ public class DBAddCommand implements Action {
// @Reference
DBControl dbControl;
- @Option(name = "-n", aliases = "--new", description = "New DBRecord.", required = false, multiValued = false)
- boolean driver;
-
- @Option(name = "-s", aliases = "--start", description = "Stop and delete the S7 device.", required = false, multiValued = false)
- boolean device;
-
- @Option(name = "-a", aliases = "--array", description = "New DBRecord of the define type.", required = false, multiValued = false)
- boolean array = false;
+// @Option(name = "-n", aliases = "--new", description = "New DBRecord.", required = false, multiValued = false)
+// boolean driver;
+//
+// @Option(name = "-s", aliases = "--start", description = "Stop and delete the S7 device.", required = false, multiValued = false)
+// boolean device;
+//
+// @Option(name = "-a", aliases = "--array", description = "New DBRecord of the define type.", required = false, multiValued = false)
+// boolean array = false;
@Argument(index = 0, name = "type", description = "PVType of the record.", required = true, multiValued = false)
- String type = null;
+ String recordType = null;
@Argument(index = 1, name = "name", description = "Short name of the record.", required = true, multiValued = false)
- String name = null;
+ String recordName = null;
- @Argument(index = 2, name = "id", description = "PLC address of the record.", required = true, multiValued = false)
- String id = null;
+ @Argument(index = 2, name = "item", description = "PlcItem name of the record.", required = true, multiValued = false)
+ String itemName = null;
+
+ @Argument(index = 3, name = "offset", description = "PlcItem data offset.", required = true, multiValued = false)
+ int itemOffset = 0;
+
+ @Argument(index = 4, name = "scan", description = "Scan rate for the record.", required = true, multiValued = false)
+ String scan = null;
+
+ @Argument(index = 5, name = "enable", description = "PvRecord is enbale to scan PlcItem.", required = true, multiValued = false)
+ boolean scanEnable = true;
- @Argument(index = 3, name = "scan", description = "Scan rate for the record.", required = true, multiValued = false)
- String scan = null;
+ @Argument(index = 6, name = "write", description = "PvRecord is enbale to scan PlcItem.", required = true, multiValued = false)
+ boolean writeEnable = false;
- @Argument(index = 4, name = "des", description = "Full description of the record.", required = false, multiValued = false)
+ @Argument(index = 7, name = "des", description = "Full description of the PvRecord.", required = false, multiValued = false)
String descriptor = null;
@@ -81,44 +91,31 @@ public class DBAddCommand implements Action {
PVRecord record;
String filter = "(&(" + Constants.OBJECTCLASS + "=" + DBRecordFactory.class.getName() + ")"+
- "(db.record.type=" + type + "))";
+ "(db.record.type=" + recordType + "))";
ServiceReference[] references = bundleContext.getServiceReferences((String) null, filter);
if (references != null){
ServiceReference reference = references[0];
- if (type.equalsIgnoreCase((String)reference.getProperty("db.record.type"))){
+ if (recordType.equalsIgnoreCase((String)reference.getProperty("db.record.type"))){
DBRecordFactory recordFactory = (DBRecordFactory) bundleContext.getService(reference);
- int start = id.indexOf('[')+1;
- int end = id.indexOf(']');
- if ((start>0) && (end!=-1)){
- String strLength = id.substring(id.indexOf('[')+1, id.indexOf(']'));
- lengthArray = Integer.parseInt(strLength);
- isArray = true;
- }
-
- if (!isArray){
- record = recordFactory.create(name);
- } else {
- record = recordFactory.createArray(name,lengthArray);
- }
+ record = recordFactory.create(recordName);
PVStructure structure = record.getPVStructure();
PVString pvDes = structure.getStringField("descriptor");
pvDes.put(descriptor);
PVString pvId = structure.getStringField("id");
- pvId.put(id);
+ pvId.put(itemName);
+ PVInt pvOffset = structure.getIntField("offset");
+ pvOffset .put(itemOffset);
PVString pvScan = structure.getStringField("scan_rate");
pvScan.put(scan);
PVBoolean pvScanEnable = structure.getBooleanField("scan_enable");
- pvScanEnable.put(true);
+ pvScanEnable.put(scanEnable);
PVBoolean pvWriteEnable = structure.getBooleanField("write_enable");
- pvWriteEnable.put(true);
+ pvWriteEnable.put(writeEnable);
- //TODO: Devolver "true" si se pudo agregar el record.
- //dbControl.attach(record);
- //TODO: Agregar solamente si se pudo agregar al driver
master.addRecord(record);
System.out.println("Record: \r\n" + record.toString());
diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBBaseFactory.java b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBBaseFactory.java
index afed420..4b67846 100644
--- a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBBaseFactory.java
+++ b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBBaseFactory.java
@@ -21,6 +21,7 @@ package org.apache.plc4x.merlot.db.core;
import org.apache.plc4x.merlot.db.api.DBRecordFactory;
import org.epics.pvdata.pv.PVBoolean;
import org.epics.pvdata.pv.PVDouble;
+import org.epics.pvdata.pv.PVInt;
import org.epics.pvdata.pv.PVString;
import org.epics.pvdata.pv.PVStructure;
import org.epics.pvdatabase.PVRecord;
@@ -79,49 +80,51 @@ public class DBBaseFactory implements DBRecordFactory {
pvString.put(fields[2]);
} else return null;
+ //TODO: Agregar el offset e incrementar indice en +1
+
if (!fields[3].isEmpty()) {
+ PVInt pvInt = structure.getIntField("offset");
+ pvInt.put(Integer.getInteger(fields[3]).intValue());
+ } else return null;
+
+ if (!fields[4].isEmpty()) {
pvString = structure.getStringField("scan_rate");
- pvString.put(fields[3]);
+ pvString.put(fields[4]);
} else return null;
- if (!fields[4].isEmpty()) {
+ if (!fields[5].isEmpty()) {
pvBoolean = structure.getBooleanField("scan_enable");
- pvBoolean.put(Boolean.parseBoolean(fields[4]));
+ pvBoolean.put(Boolean.parseBoolean(fields[5]));
} else return null;
- if (!fields[5].isEmpty()) {
+ if (!fields[6].isEmpty()) {
pvBoolean = structure.getBooleanField("write_enable");
- pvBoolean.put(Boolean.parseBoolean(fields[5]));
+ pvBoolean.put(Boolean.parseBoolean(fields[6]));
} else return null;
- if (!fields[6].isEmpty()) {
- pvDouble = structure.getDoubleField("display.limitLow");
- pvDouble.put(Double.parseDouble(fields[6]));
- }
-
if (!fields[7].isEmpty()) {
- pvDouble = structure.getDoubleField("display.limitHigh");
+ pvDouble = structure.getDoubleField("display.limitLow");
pvDouble.put(Double.parseDouble(fields[7]));
- }
+ }
if (!fields[8].isEmpty()) {
- pvString = structure.getStringField("display.description");
- pvString.put(fields[8]);
+ pvDouble = structure.getDoubleField("display.limitHigh");
+ pvDouble.put(Double.parseDouble(fields[8]));
}
if (!fields[9].isEmpty()) {
- pvString = structure.getStringField("display.format");
+ pvString = structure.getStringField("display.description");
pvString.put(fields[9]);
- }
+ }
if (!fields[10].isEmpty()) {
- pvString = structure.getStringField("display.units");
+ pvString = structure.getStringField("display.format");
pvString.put(fields[10]);
- }
+ }
if (!fields[11].isEmpty()) {
- pvDouble = structure.getDoubleField("control.limitHigh");
- pvDouble.put(Double.parseDouble(fields[11]));
+ pvString = structure.getStringField("display.units");
+ pvString.put(fields[11]);
}
if (!fields[12].isEmpty()) {
@@ -130,8 +133,13 @@ public class DBBaseFactory implements DBRecordFactory {
}
if (!fields[13].isEmpty()) {
- pvDouble = structure.getDoubleField("control.minStep");
+ pvDouble = structure.getDoubleField("control.limitHigh");
pvDouble.put(Double.parseDouble(fields[13]));
+ }
+
+ if (!fields[14].isEmpty()) {
+ pvDouble = structure.getDoubleField("control.minStep");
+ pvDouble.put(Double.parseDouble(fields[14]));
}
return pvRecord;
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 00a98ef..f262028 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
@@ -18,6 +18,10 @@
*/
package org.apache.plc4x.merlot.db.core;
+import io.grpc.netty.shaded.io.netty.buffer.ByteBuf;
+import io.grpc.netty.shaded.io.netty.buffer.Unpooled;
+import org.apache.plc4x.merlot.api.PlcItem;
+import org.apache.plc4x.merlot.api.PlcItemListener;
import org.epics.nt.NTScalar;
import org.epics.nt.NTScalarArray;
import org.epics.nt.NTScalarArrayBuilder;
@@ -45,6 +49,7 @@ public class DBByteFactory extends DBBaseFactory {
value(ScalarType.pvByte).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -65,6 +70,7 @@ public class DBByteFactory extends DBBaseFactory {
value(ScalarType.pvByte).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -80,13 +86,17 @@ public class DBByteFactory extends DBBaseFactory {
return pvRecord;
}
- class DBByteRecord extends PVRecord {
+ class DBByteRecord extends PVRecord implements PlcItemListener {
private PVByte value;
+ private PlcItem plcItem = null;
+ private ByteBuf innerBuffer = null;
+ private int offset = 0;
public DBByteRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = pvStructure.getByteField("value");
+ offset = pvStructure.getIntField("offset").get() * Byte.BYTES;
}
/**
@@ -97,6 +107,25 @@ public class DBByteFactory extends DBBaseFactory {
{
super.process();
}
+
+ @Override
+ public void atach(PlcItem plcItem) {
+ this.plcItem = plcItem;
+ innerBuffer = Unpooled.wrappedBuffer(plcItem.getInnerBuffer(), offset, Byte.BYTES);
+ }
+
+ @Override
+ public void detach() {
+ this.plcItem = null;
+ }
+
+ @Override
+ public void update() {
+ if (null != plcItem) {
+ if (value.get() != innerBuffer.getByte(0))
+ value.put(innerBuffer.getByte(0));
+ }
+ }
}
}
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 462d8de..83c84a3 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
@@ -18,6 +18,10 @@
*/
package org.apache.plc4x.merlot.db.core;
+import io.grpc.netty.shaded.io.netty.buffer.ByteBuf;
+import io.grpc.netty.shaded.io.netty.buffer.Unpooled;
+import org.apache.plc4x.merlot.api.PlcItem;
+import org.apache.plc4x.merlot.api.PlcItemListener;
import org.epics.nt.NTScalar;
import org.epics.nt.NTScalarArray;
import org.epics.nt.NTScalarArrayBuilder;
@@ -42,6 +46,7 @@ public class DBDoubleFactory extends DBBaseFactory {
value(ScalarType.pvDouble).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -62,6 +67,7 @@ public class DBDoubleFactory extends DBBaseFactory {
value(ScalarType.pvDouble).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -77,13 +83,17 @@ public class DBDoubleFactory extends DBBaseFactory {
return pvRecord;
}
- class DBDoubleRecord extends PVRecord {
+ class DBDoubleRecord extends PVRecord implements PlcItemListener {
private PVDouble value;
+ private PlcItem plcItem = null;
+ private ByteBuf innerBuffer = null;
+ private int offset = 0;
public DBDoubleRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = pvStructure.getDoubleField("value");
+ offset = pvStructure.getIntField("offset").get() * Double.BYTES;
}
/**
@@ -94,6 +104,24 @@ public class DBDoubleFactory extends DBBaseFactory {
{
super.process();
}
+
+ @Override
+ public void atach(PlcItem plcItem) {
+ this.plcItem = plcItem;
+ innerBuffer = Unpooled.wrappedBuffer(plcItem.getInnerBuffer(), offset, Double.BYTES);
+ }
+
+ @Override
+ public void detach() {
+ this.plcItem = null;
+ }
+
+ @Override
+ public void update() {
+ if (null != plcItem)
+ if (value.get() != innerBuffer.getDouble(0))
+ value.put(innerBuffer.getDouble(0));
+ }
}
}
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 41555d8..ea6c2c0 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
@@ -47,6 +47,7 @@ public class DBFloatFactory extends DBBaseFactory {
value(ScalarType.pvFloat).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -67,6 +68,7 @@ public class DBFloatFactory extends DBBaseFactory {
value(ScalarType.pvFloat).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -92,12 +94,7 @@ public class DBFloatFactory extends DBBaseFactory {
public DBFloatRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = pvStructure.getFloatField("value");
- PVString id = pvStructure.getStringField("id");
- String strId = id.get();
- String[] strParts = strId.split("\\/");
- if (strParts.length == 2) {
- offset = Integer.getInteger(strParts[1]) * Float.BYTES;
- }
+ offset = pvStructure.getIntField("offset").get() * Float.BYTES;
}
/**
@@ -124,7 +121,8 @@ public class DBFloatFactory extends DBBaseFactory {
@Override
public void update() {
- if (null != plcItem)
+ if (null != plcItem)
+ if (value.get() != innerBuffer.getFloat(0))
value.put(innerBuffer.getFloat(0));
}
}
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 30fc2c8..6df0d39 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
@@ -18,6 +18,10 @@
*/
package org.apache.plc4x.merlot.db.core;
+import io.grpc.netty.shaded.io.netty.buffer.ByteBuf;
+import io.grpc.netty.shaded.io.netty.buffer.Unpooled;
+import org.apache.plc4x.merlot.api.PlcItem;
+import org.apache.plc4x.merlot.api.PlcItemListener;
import org.epics.nt.NTScalar;
import org.epics.nt.NTScalarArray;
import org.epics.nt.NTScalarArrayBuilder;
@@ -42,6 +46,7 @@ public class DBIntFactory extends DBBaseFactory {
value(ScalarType.pvInt).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -62,6 +67,7 @@ public class DBIntFactory extends DBBaseFactory {
value(ScalarType.pvInt).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -77,13 +83,17 @@ public class DBIntFactory extends DBBaseFactory {
return pvRecord;
}
- class DBIntRecord extends PVRecord {
+ class DBIntRecord extends PVRecord implements PlcItemListener {
- private PVInt value;
+ private PVInt value;
+ private PlcItem plcItem = null;
+ private ByteBuf innerBuffer = null;
+ private int offset = 0;
public DBIntRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = pvStructure.getIntField("value");
+ offset = pvStructure.getIntField("offset").get() * Integer.BYTES;
}
/**
@@ -95,6 +105,24 @@ public class DBIntFactory extends DBBaseFactory {
super.process();
}
+
+ @Override
+ public void atach(PlcItem plcItem) {
+ this.plcItem = plcItem;
+ innerBuffer = Unpooled.wrappedBuffer(plcItem.getInnerBuffer(), offset, Integer.BYTES);
+ }
+
+ @Override
+ public void detach() {
+ this.plcItem = null;
+ }
+
+ @Override
+ public void update() {
+ if (null != plcItem)
+ if (value.get() != innerBuffer.getInt(0))
+ value.put(innerBuffer.getInt(0));
+ }
}
-
}
+
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 cc71be4..4960cc3 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
@@ -18,6 +18,10 @@
*/
package org.apache.plc4x.merlot.db.core;
+import io.grpc.netty.shaded.io.netty.buffer.ByteBuf;
+import io.grpc.netty.shaded.io.netty.buffer.Unpooled;
+import org.apache.plc4x.merlot.api.PlcItem;
+import org.apache.plc4x.merlot.api.PlcItemListener;
import org.epics.nt.NTScalar;
import org.epics.nt.NTScalarArray;
import org.epics.nt.NTScalarArrayBuilder;
@@ -42,6 +46,7 @@ public class DBLongFactory extends DBBaseFactory {
value(ScalarType.pvLong).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -62,6 +67,7 @@ public class DBLongFactory extends DBBaseFactory {
value(ScalarType.pvLong).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -77,13 +83,17 @@ public class DBLongFactory extends DBBaseFactory {
return pvRecord;
}
- class DBLongRecord extends PVRecord {
+ class DBLongRecord extends PVRecord implements PlcItemListener {
- private PVLong value;
+ private PVLong value;
+ private PlcItem plcItem = null;
+ private ByteBuf innerBuffer = null;
+ private int offset = 0;
public DBLongRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = pvStructure.getLongField("value");
+ offset = pvStructure.getIntField("offset").get() * Long.BYTES;
}
/**
@@ -95,5 +105,23 @@ public class DBLongFactory extends DBBaseFactory {
super.process();
}
+
+ @Override
+ public void atach(PlcItem plcItem) {
+ this.plcItem = plcItem;
+ innerBuffer = Unpooled.wrappedBuffer(plcItem.getInnerBuffer(), offset, Long.BYTES);
+ }
+
+ @Override
+ public void detach() {
+ this.plcItem = null;
+ }
+
+ @Override
+ public void update() {
+ if (null != plcItem)
+ if (value.get() != innerBuffer.getLong(0))
+ value.put(innerBuffer.getLong(0));
+ }
}
}
diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBRecordsManagedService.java b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBRecordsManagedService.java
index 0e8c2ec..8192b32 100644
--- a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBRecordsManagedService.java
+++ b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/core/DBRecordsManagedService.java
@@ -18,7 +18,6 @@
*/
package org.apache.plc4x.merlot.db.core;
-import org.apache.plc4x.merlot.das.base.api.BaseDriver;
import org.apache.plc4x.merlot.db.api.DBControl;
import org.apache.plc4x.merlot.db.api.DBRecordFactory;
import org.apache.plc4x.merlot.scheduler.api.Job;
@@ -32,9 +31,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.stream.Stream;
import org.apache.plc4x.java.api.PlcConnection;
-import org.apache.plc4x.java.api.PlcDriver;
import org.apache.plc4x.merlot.api.PlcDevice;
import org.apache.plc4x.merlot.api.PlcGeneralFunction;
import org.apache.plc4x.merlot.api.PlcItem;
@@ -48,7 +45,6 @@ import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.ConfigurationException;
import org.osgi.service.cm.ManagedServiceFactory;
-import org.osgi.service.device.Driver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 38e0779..a67a860 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
@@ -50,6 +50,7 @@ public class DBShortFactory extends DBBaseFactory {
value(ScalarType.pvShort).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -71,6 +72,7 @@ public class DBShortFactory extends DBBaseFactory {
value(ScalarType.pvShort).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -96,12 +98,7 @@ public class DBShortFactory extends DBBaseFactory {
public DBShortRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = pvStructure.getShortField("value");
- PVString id = pvStructure.getStringField("id");
- String strId = id.get();
- String[] strParts = strId.split("\\/");
- if (strParts.length == 2) {
- offset = Integer.getInteger(strParts[1]) * Short.BYTES;
- }
+ offset = pvStructure.getIntField("offset").get() * Short.BYTES;
}
/**
@@ -128,8 +125,10 @@ public class DBShortFactory extends DBBaseFactory {
@Override
public void update() {
- if (null != plcItem)
+ if (null != plcItem) {
+ if (value.get() != innerBuffer.getShort(0))
value.put(innerBuffer.getShort(0));
+ }
}
}
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 5adfc6c..eef316c 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
@@ -18,6 +18,11 @@
*/
package org.apache.plc4x.merlot.db.core;
+import io.grpc.netty.shaded.io.netty.buffer.ByteBuf;
+import io.grpc.netty.shaded.io.netty.buffer.Unpooled;
+import io.netty.util.CharsetUtil;
+import org.apache.plc4x.merlot.api.PlcItem;
+import org.apache.plc4x.merlot.api.PlcItemListener;
import org.epics.nt.NTScalar;
import org.epics.nt.NTScalarArray;
import org.epics.nt.NTScalarArrayBuilder;
@@ -42,6 +47,7 @@ public class DBStringFactory extends DBBaseFactory {
value(ScalarType.pvString).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -62,6 +68,7 @@ public class DBStringFactory extends DBBaseFactory {
value(ScalarType.pvString).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -77,13 +84,17 @@ public class DBStringFactory extends DBBaseFactory {
return pvRecord;
}
- class DBStringRecord extends PVRecord {
+ class DBStringRecord extends PVRecord implements PlcItemListener {
- private PVString value;
+ private PVString value;
+ private PlcItem plcItem = null;
+ private ByteBuf innerBuffer = null;
+ private int offset = 0;
public DBStringRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = pvStructure.getStringField("value");
+ offset = pvStructure.getIntField("offset").get();
}
/**
@@ -95,6 +106,24 @@ public class DBStringFactory extends DBBaseFactory {
super.process();
}
+
+ @Override
+ public void atach(PlcItem plcItem) {
+ this.plcItem = plcItem;
+ innerBuffer = Unpooled.wrappedBuffer(plcItem.getInnerBuffer(), 0, offset);
+ }
+
+ @Override
+ public void detach() {
+ this.plcItem = null;
+ }
+
+ @Override
+ public void update() {
+ if (null != plcItem)
+ if (!value.get().matches(innerBuffer.toString(CharsetUtil.UTF_8)))
+ value.put( innerBuffer.toString(CharsetUtil.UTF_8) );
+ }
}
}
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 2f4cc19..3d0e7be 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
@@ -18,6 +18,10 @@
*/
package org.apache.plc4x.merlot.db.core;
+import io.grpc.netty.shaded.io.netty.buffer.ByteBuf;
+import io.grpc.netty.shaded.io.netty.buffer.Unpooled;
+import org.apache.plc4x.merlot.api.PlcItem;
+import org.apache.plc4x.merlot.api.PlcItemListener;
import org.epics.nt.NTScalar;
import org.epics.nt.NTScalarArray;
import org.epics.nt.NTScalarArrayBuilder;
@@ -42,6 +46,7 @@ public class DBUByteFactory extends DBBaseFactory {
value(ScalarType.pvByte).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -62,6 +67,7 @@ public class DBUByteFactory extends DBBaseFactory {
value(ScalarType.pvUByte).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -77,13 +83,17 @@ public class DBUByteFactory extends DBBaseFactory {
return pvRecord;
}
- class DBUByteRecord extends PVRecord {
+ class DBUByteRecord extends PVRecord implements PlcItemListener {
private PVUByte value;
+ private PlcItem plcItem = null;
+ private ByteBuf innerBuffer = null;
+ private int offset = 0;
public DBUByteRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = (PVUByte) pvStructure.getByteField("value");
+ offset = pvStructure.getIntField("offset").get() * Byte.BYTES;
}
/**
@@ -95,6 +105,24 @@ public class DBUByteFactory extends DBBaseFactory {
super.process();
}
+
+ @Override
+ public void atach(PlcItem plcItem) {
+ this.plcItem = plcItem;
+ innerBuffer = Unpooled.wrappedBuffer(plcItem.getInnerBuffer(), offset, Byte.BYTES);
+ }
+
+ @Override
+ public void detach() {
+ this.plcItem = null;
+ }
+
+ @Override
+ public void update() {
+ if (null != plcItem)
+ if (value.get() != innerBuffer.getUnsignedByte(0))
+ value.put((byte) innerBuffer.getUnsignedByte(offset));
+ }
}
}
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 0193149..1574f42 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
@@ -18,6 +18,10 @@
*/
package org.apache.plc4x.merlot.db.core;
+import io.grpc.netty.shaded.io.netty.buffer.ByteBuf;
+import io.grpc.netty.shaded.io.netty.buffer.Unpooled;
+import org.apache.plc4x.merlot.api.PlcItem;
+import org.apache.plc4x.merlot.api.PlcItemListener;
import org.epics.nt.NTScalar;
import org.epics.nt.NTScalarArray;
import org.epics.nt.NTScalarArrayBuilder;
@@ -42,6 +46,7 @@ public class DBUIntFactory extends DBBaseFactory {
value(ScalarType.pvUInt).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -62,6 +67,7 @@ public class DBUIntFactory extends DBBaseFactory {
value(ScalarType.pvUInt).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -77,13 +83,17 @@ public class DBUIntFactory extends DBBaseFactory {
return pvRecord;
}
- class DBUIntRecord extends PVRecord {
+ class DBUIntRecord extends PVRecord implements PlcItemListener {
- private PVUInt value;
+ private PVUInt value;
+ private PlcItem plcItem = null;
+ private ByteBuf innerBuffer = null;
+ private int offset = 0;
public DBUIntRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = (PVUInt) pvStructure.getIntField("value");
+ offset = pvStructure.getIntField("offset").get() * Integer.BYTES;
}
/**
@@ -95,6 +105,24 @@ public class DBUIntFactory extends DBBaseFactory {
super.process();
}
+
+ @Override
+ public void atach(PlcItem plcItem) {
+ this.plcItem = plcItem;
+ innerBuffer = Unpooled.wrappedBuffer(plcItem.getInnerBuffer(), offset, Integer.BYTES);
+ }
+
+ @Override
+ public void detach() {
+ this.plcItem = null;
+ }
+
+ @Override
+ public void update() {
+ if (null != plcItem)
+ if (value.get() != innerBuffer.getUnsignedInt(offset))
+ value.put((byte) innerBuffer.getUnsignedInt(offset));
+ }
}
}
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 b520a82..886e5e2 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
@@ -18,6 +18,10 @@
*/
package org.apache.plc4x.merlot.db.core;
+import io.grpc.netty.shaded.io.netty.buffer.ByteBuf;
+import io.grpc.netty.shaded.io.netty.buffer.Unpooled;
+import org.apache.plc4x.merlot.api.PlcItem;
+import org.apache.plc4x.merlot.api.PlcItemListener;
import org.epics.nt.NTScalar;
import org.epics.nt.NTScalarArray;
import org.epics.nt.NTScalarArrayBuilder;
@@ -44,6 +48,7 @@ public class DBULongFactory extends DBBaseFactory {
value(ScalarType.pvULong).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -64,6 +69,7 @@ public class DBULongFactory extends DBBaseFactory {
value(ScalarType.pvULong).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -79,13 +85,17 @@ public class DBULongFactory extends DBBaseFactory {
return pvRecord;
}
- class DBULongRecord extends PVRecord {
+ class DBULongRecord extends PVRecord implements PlcItemListener {
- private PVULong value;
+ private PVULong value;
+ private PlcItem plcItem = null;
+ private ByteBuf innerBuffer = null;
+ private int offset = 0;
DBULongRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = (PVULong) pvStructure.getLongField("value");
+ offset = pvStructure.getIntField("offset").get() * Long.BYTES;
}
/**
@@ -97,6 +107,24 @@ public class DBULongFactory extends DBBaseFactory {
super.process();
}
+
+ @Override
+ public void atach(PlcItem plcItem) {
+ this.plcItem = plcItem;
+ innerBuffer = Unpooled.wrappedBuffer(plcItem.getInnerBuffer(), offset, Long.BYTES);
+ }
+
+ @Override
+ public void detach() {
+ this.plcItem = null;
+ }
+
+ @Override
+ public void update() {
+ if (null != plcItem)
+ if (value.get() != innerBuffer.getUnsignedMedium(offset))
+ value.put(innerBuffer.getUnsignedMedium(offset));
+ }
}
}
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 6653b7a..957b01a 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
@@ -20,9 +20,7 @@ package org.apache.plc4x.merlot.db.core;
import io.grpc.netty.shaded.io.netty.buffer.ByteBuf;
import io.grpc.netty.shaded.io.netty.buffer.Unpooled;
-import org.apache.plc4x.java.api.value.PlcValue;
import org.apache.plc4x.merlot.api.PlcItem;
-import org.apache.plc4x.merlot.api.PlcItemClient;
import org.apache.plc4x.merlot.api.PlcItemListener;
import org.epics.nt.NTScalar;
import org.epics.nt.NTScalarArray;
@@ -50,6 +48,7 @@ public class DBUShortFactory extends DBBaseFactory {
value(ScalarType.pvUShort).
addDescriptor().
add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -69,7 +68,8 @@ public class DBUShortFactory extends DBBaseFactory {
PVStructure pvStructure = ntScalarArrayBuilder.
value(ScalarType.pvUShort).
addDescriptor().
- add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("id", fieldCreate.createScalar(ScalarType.pvString)).
+ add("offset", fieldCreate.createScalar(ScalarType.pvInt)).
add("scan_rate", fieldCreate.createScalar(ScalarType.pvString)).
add("scan_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
add("write_enable", fieldCreate.createScalar(ScalarType.pvBoolean)).
@@ -95,6 +95,7 @@ public class DBUShortFactory extends DBBaseFactory {
private DBUShortRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
value = (PVUShort) pvStructure.getShortField("value");
+ offset = pvStructure.getIntField("offset").get() * Short.BYTES;
}
/**
@@ -122,7 +123,8 @@ public class DBUShortFactory extends DBBaseFactory {
@Override
public void update() {
if (null != plcItem)
- value.put(innerBuffer.getShort(0));
+ if (value.get() != innerBuffer.getUnsignedShort(offset))
+ value.put( (short) innerBuffer.getUnsignedShort(offset));
}