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 c377b36 Working in PlcModel for s7 driver.
c377b36 is described below
commit c377b36ad62159a2b3a3d27c06cb09ebc53ddfc8
Author: César José García León <[email protected]>
AuthorDate: Fri Jun 20 19:06:25 2025 -0400
Working in PlcModel for s7 driver.
---
.../plc4x/merlot/api/PlcGeneralFunction.java | 14 +-
.../java/org/apache/plc4x/merlot/api/PlcModel.java | 176 ++++---
.../apache/plc4x/merlot/api/PlcModelFactory.java | 11 +
.../merlot/api/impl/PlcGeneralFunctionImpl.java | 77 ++-
.../plc4x/merlot/api/impl/PlcSecureBootImpl.java | 13 +-
.../org/apache/plc4x/merlot/db/api/DBRecord.java | 6 +-
.../apache/plc4x/merlot/db/impl/DBPersistImpl.java | 81 +--
.../merlot/org.apache.plc4x.merlot.drv.s7/pom.xml | 47 +-
.../src/docs/asciidoc/S7PlcModel.puml | 54 ++
.../src/docs/asciidoc/s7notes.adoc | 19 +
.../plc4x/merlot/drv/s7/core/S7DBAiFactory.java | 20 +-
.../merlot/drv/s7/impl/S7PlcModelFactoryImpl.java} | 32 +-
.../plc4x/merlot/drv/s7/impl/S7PlcModelImpl.java | 371 +++++++++-----
.../OSGI-INF/blueprint/s7-drv-service.xml | 27 +-
.../plc4x/merlot/drv/s7/core/MerlotS7Test.java | 95 ----
.../drv/s7/core/RegressionConfiguration.java | 90 ----
.../plc4x/merlot/drv/s7/core/S7DBAiTest.java | 44 +-
.../plc4x/merlot/drv/s7/core/S7DBAoTest.java | 4 +-
.../plc4x/merlot/drv/s7/core/S7DBCounterTest.java | 4 +-
.../merlot/drv/s7/core/S7DBDateAndTimeTest.java | 4 +-
.../plc4x/merlot/drv/s7/core/S7DBDateTest.java | 4 +-
.../plc4x/merlot/drv/s7/core/S7DBMotorTest.java | 4 +-
.../merlot/drv/s7/core/S7DBValveAnalogTest.java | 4 +-
.../merlot/drv/s7/core/S7DBValveSolenoidTest.java | 2 +-
.../plc4x/merlot/drv/s7/core/S7EmptyJUnitTest.java | 90 ++++
.../plc4x/merlot/drv/s7/core/S7PlcModelTest.java | 549 +++++++++++++++++++++
.../plc4x/merlot/drv/s7/core/S7PlcModelTests.java | 167 -------
.../plc4x/merlot/drv/s7/core/S7TestSuite.java | 58 +++
.../apache/plc4x/merlot/drv/s7/core/TestBase.java | 251 ----------
.../impl/SimulatedPlcTagFunctionImpl.java | 1 -
.../src/main/feature/feature.xml | 2 +-
plc4j/tools/merlot/pom.xml | 6 +-
32 files changed, 1413 insertions(+), 914 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 d0f095e..4cd873e 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
@@ -85,7 +85,7 @@ public interface PlcGeneralFunction extends PlcFunction {
* @return Returns a map with key corresponding to the "uid" of the device
* and value corresponding to the "name" of the device.
*/
- public PlcDevice getPlcDevice(String deviceName);
+ public Optional<PlcDevice> getPlcDevice(String deviceName);
/*
* Returns a list of the PlcDevice registered in the context.
@@ -136,6 +136,18 @@ public interface PlcGeneralFunction extends PlcFunction {
*/
public Map<String, Object> getPlcDeviceMeta(UUID group_uid);
+
+ /*
+ *
+ */
+ public Optional<PlcModel> createPlcModel(String deviceCategory, String
deviceName);
+
+
+ /*
+ *
+ */
+ public Optional<PlcModel> getPlcModel(String deviceCategory, String
deviceName);
+
/*
* @param group_uid String representation of the group's UUID.
* @return Returns a map with key corresponding to the property of the
device
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcModel.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcModel.java
index 8f613bb..0405859 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcModel.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcModel.java
@@ -1,88 +1,124 @@
-/*
- * 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;
import java.util.List;
+import java.util.Optional;
import java.util.Set;
import java.util.UUID;
-import org.apache.plc4x.merlot.db.api.DBRecord;
-/*
-* PlcModel represents the internal data structure associated with a PLC,
-* RTU, etc. Exception or time-based subscriptions go against this model.
-*/
+/**
+ * Represents the internal data structure associated with a Programmable Logic
Controller (PLC)
+ * or Remote Terminal Unit (RTU). This model serves as the foundation for
exception-based and
+ * time-based subscriptions.
+ *
+ */
public interface PlcModel {
- /*
- * Lists the different memory areas of this model.
- * They are usually defined in the driver.
- */
- Set<String> ListMemoryAreas();
+ public static final String PLCMODEL_CATEGORY = "plc4x.plcmodel.category";
+
+ public static final String PLCMODEL_DEVICE = "plc4x.plcmodel.device";
+
+
+ /**
+ * Lists all available memory areas defined in this model.
+ * These areas are typically defined by the specific driver implementation.
+ *
+ * @return A set of strings representing the available memory areas
+ */
+ Set<String> listMemoryAreas();
- /*
- * Retrieves the ID assigned to a memory area.
- */
- Integer MemoryAreaId(String strMemoryArea);
+ /**
+ * Retrieves the unique identifier assigned to a specific memory area.
+ *
+ * @param memoryArea The name of the memory area
+ * @return The ID of the memory area, or null if not found
+ * @throws IllegalArgumentException if memoryArea is null or empty
+ */
+ Integer getMemoryAreaId(String memoryArea);
- /*
- * This procedure is responsible for creating the memory areas
- * associated with a particular PLC or Device model.
- */
- void CreateMemoryArea(DBRecord dbRecord);
+ /**
+ * Creates memory areas associated with a specific PLC or device model.
+ *
+ * @param configuration The configuration object containing memory area
specifications
+ * @throws IllegalArgumentException if configuration is null or invalid
+ * @throws PlcConfigurationException if creation fails
+ */
+ void createMemoryArea(Object dbRecord);
- /*
- * This procedure is responsible for creating a scan group
- * associated with a particular PLC or Device model.
- */
- void CreateScanGroup(DBRecord dbRecord);
+ /**
+ * Takes the PlcItem representing the memory area.
+ *
+ * @param memoryArea The name of the memory area
+ * @param indexThe specific index within the memory area
+ * @throws IllegalArgumentException if configuration is null or invalid
+ * @throws PlcConfigurationException if creation fails
+ */
+ Optional<PlcItem> getMemoryAreaPlcItem(String memoryArea, Integer index);
- /*
- * Add a listener to a specific memory area within the model.
- */
- void AddMemoryAreaListener(String strMemmoryArea, Integer index,
PlcItemListener listener);
+ /**
+ * Creates a scan group for monitoring specific memory areas in the
PLC/device model.
+ *
+ * @param configuration The scan group configuration
+ * @throws IllegalArgumentException if configuration is null or invalid
+ * @throws PlcConfigurationException if creation fails
+ */
+ void createScanGroup(Object dbRecord);
- /*
- * Remove a listener.
- */
- void RemoveMemoryAreaListener(String strMemmoryArea, Integer index,
PlcItemListener listener);
+ /**
+ * Registers a listener for a specific memory area to receive updates.
+ *
+ * @param memoryArea The name of the memory area to monitor
+ * @param index The specific index within the memory area
+ * @param listener The listener to receive updates
+ * @throws IllegalArgumentException if any parameter is null or invalid
+ */
+ void addMemoryAreaListener(String memoryArea, Integer index,
PlcItemListener listener);
- /*
- * Returns the number of segments comprising this memory area.
- * For example, for MODBUS, it will always return 1 for
- * any type of memory area. For the S7 driver, specifically for DBs,
- * it will return the number of DB instances required.
- */
- Integer MemoryAreaSegment(String strMemoryArea);
+ /**
+ * Removes a previously registered listener from a memory area.
+ *
+ * @param memoryArea The name of the memory area
+ * @param index The specific index within the memory area
+ * @param listener The listener to remove
+ */
+ void removeMemoryAreaListener(String memoryArea, Integer index,
PlcItemListener listener);
- /*
- * Returns the indices associated with each memory area.
- */
- List<Integer> MemoryAreaSegmentId(String strMemoryArea);
-
+ /**
+ * Returns the number of segments in a memory area.
+ * For example:
+ * - MODBUS: Always returns 1 for any memory area type
+ * - S7 driver: Returns the number of DB instances required for DBs
+ *
+ * @param memoryArea The name of the memory area
+ * @return The number of segments in the memory area
+ * @throws IllegalArgumentException if memoryArea is null or invalid
+ */
+ Integer getMemoryAreaSegmentCount(String memoryArea);
- /*
- * Each "model" must create its own scan PlcGroups.
- */
- List<UUID> ModelPlcGroupsUuid(String strMemoryArea);
+ /**
+ * Retrieves the list of indices associated with a memory area.
+ *
+ * @param memoryArea The name of the memory area
+ * @return List of indices for the memory area
+ * @throws IllegalArgumentException if memoryArea is null or invalid
+ */
+ Set<Integer> getMemoryAreaSegmentIds(String memoryArea);
- /*
- * Returns the PlcItems created for the model update.
- */
- List<UUID> ModelPlcItemsUuid(String strMemoryArea);
+ /**
+ * Retrieves the UUIDs of scan groups created for this model.
+ * Each model is responsible for creating and managing its own scan groups.
+ *
+ * @param memoryArea The name of the memory area
+ * @return List of UUIDs representing the scan groups
+ * @throws IllegalArgumentException if memoryArea is null or invalid
+ */
+ Set<UUID> getModelPlcGroupUuids(String memoryArea);
-
-}
+ /**
+ * Retrieves the UUIDs of PLC items created for model updates.
+ *
+ * @param memoryArea The name of the memory area
+ * @return List of UUIDs representing the PLC items
+ * @throws IllegalArgumentException if memoryArea is null or invalid
+ */
+ Set<UUID> getModelPlcItemUuids(String memoryArea);
+}
\ No newline at end of file
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcModelFactory.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcModelFactory.java
index f6221c7..e359f10 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcModelFactory.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcModelFactory.java
@@ -16,6 +16,8 @@
*/
package org.apache.plc4x.merlot.api;
+import java.util.Optional;
+
/*
* Objects that implement this interface are responsible for building
* specific PlcModels. Each equipment model will have a specific structure.
@@ -23,4 +25,13 @@ package org.apache.plc4x.merlot.api;
*/
public interface PlcModelFactory {
+ /*
+ * @param deviceCategory category of the driver to be instantiated,
+ * for example s7, s7-light or modbus
+ * @param deviceName Technological name of the device,
+ * generally according to IEC.
+ * @return PlcModel according to the specified services.
+ */
+ public Optional<PlcModel> createPlcModel(String deviceCategory, String
deviceName);
+
}
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 70a08bb..ef24de7 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
@@ -18,6 +18,7 @@ package org.apache.plc4x.merlot.api.impl;
import io.netty.buffer.ByteBuf;
import java.util.Collection;
+import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
@@ -45,6 +46,8 @@ import org.osgi.service.dal.OperationMetadata;
import org.osgi.service.dal.PropertyMetadata;
import org.slf4j.LoggerFactory;
import org.apache.plc4x.merlot.api.PlcGeneralFunction;
+import org.apache.plc4x.merlot.api.PlcModel;
+import org.apache.plc4x.merlot.api.PlcModelFactory;
import org.osgi.service.device.Device;
/*DriverName
@@ -60,9 +63,16 @@ public class PlcGeneralFunctionImpl implements
PlcGeneralFunction {
private static String FILTER_DEVICE_CATEGORY = "(&(" +
Constants.OBJECTCLASS + "=" + PlcDevice.class.getName() + ")" +
"(" +
org.osgi.service.device.Constants.DEVICE_CATEGORY + "=*))";
- private static String FILTER_DEVICE = "(&(" + Constants.OBJECTCLASS + "="
+ Device.class.getName() + ")" +
+ private static String FILTER_DEVICE = "(&(" + Constants.OBJECTCLASS + "="
+ PlcDevice.class.getName() + ")" +
"(" +
org.apache.plc4x.merlot.api.PlcDevice.SERVICE_KEY + "=*))";
+ private static String FILTER_DEVICE_MODEL = "(&(" + Constants.OBJECTCLASS
+ "=" + PlcModel.class.getName() + ")" +
+ "(&(" +
org.apache.plc4x.merlot.api.PlcModel.PLCMODEL_CATEGORY + "=*)" +
+ "(" +
org.apache.plc4x.merlot.api.PlcModel.PLCMODEL_DEVICE + "=?)))";
+
+ private static String FILTER_DEVICE_MODEL_FACTORY = "(&(" +
Constants.OBJECTCLASS + "=" + PlcModelFactory.class.getName() + ")" +
+ "(" +
org.apache.plc4x.merlot.api.PlcModel.PLCMODEL_CATEGORY + "=*))";
+
private static String FILTER_FACTORY = "(&(" + Constants.OBJECTCLASS +
"=" + PlcDeviceFactory.class.getName() + ")" +
"(org.apache.plc4x.device.factory=*))";
@@ -620,20 +630,19 @@ public class PlcGeneralFunctionImpl implements
PlcGeneralFunction {
}
@Override
- public PlcDevice getPlcDevice(String deviceName) {
+ public Optional<PlcDevice> getPlcDevice(String deviceName) {
try {
- Collection<ServiceReference<PlcDevice>> refs =
bc.getServiceReferences(PlcDevice.class, null);
- if (null != refs) {
- for (ServiceReference ref:refs){
- final PlcDevice plcDevice = (PlcDevice) bc.getService(ref);
- if (deviceName.equalsIgnoreCase(plcDevice.getDeviceName()))
- return plcDevice;
- }
- }
- } catch (InvalidSyntaxException ex) {
- LOGGER.info(ex.getMessage());
+ String filter = FILTER_DEVICE.replace("*", deviceName);
+ ServiceReference[] refs1 = bc.getServiceReferences((String) null,
filter);
+ for (ServiceReference ref:refs1){
+ final PlcDevice plcDevice = (PlcDevice) bc.getService(ref);
+ if (plcDevice.getDeviceKey().equalsIgnoreCase(deviceName))
+ return Optional.of(plcDevice);
+ }
+ } catch (Exception ex){
+ LOGGER.error(ex.getMessage());
}
- return null;
+ return Optional.empty();
}
@Override
@@ -672,6 +681,48 @@ public class PlcGeneralFunctionImpl implements
PlcGeneralFunction {
}
}
+ @Override
+ public Optional<PlcModel> createPlcModel(String deviceCategory, String
deviceName) {
+ try {
+ String filter = FILTER_DEVICE_MODEL_FACTORY.replace("*",
deviceCategory);
+ ServiceReference[] refs = bc.getServiceReferences((String) null,
filter);
+ if (null != refs) {
+ final PlcModelFactory plcModelFactory = (PlcModelFactory)
bc.getService(refs[0]);
+ Optional<PlcModel> optPlcModel =
plcModelFactory.createPlcModel(deviceCategory, deviceName);
+ if (optPlcModel.isPresent()) {
+ final PlcModel plcModel = optPlcModel.get();
+ Hashtable<String, Object> serviceProperties = new
Hashtable<String,Object>();
+ serviceProperties.put(PlcModel.PLCMODEL_CATEGORY,
deviceCategory);
+ serviceProperties.put(PlcModel.PLCMODEL_DEVICE,
deviceName);
+ bc.registerService(new
String[]{org.apache.plc4x.merlot.api.PlcModel.class.getName()},
+ plcModel, serviceProperties);
+ LOGGER.info("PlcModel service of type {} created for
device{}.", deviceCategory, deviceName);
+ return Optional.of(plcModel);
+ }
+ }
+ } catch(Exception ex){
+ LOGGER.error(ex.getMessage());
+ }
+ return Optional.empty();
+ }
+
+ @Override
+ public Optional<PlcModel> getPlcModel(String deviceCategory, String
deviceName) {
+ try {
+ String filter = FILTER_DEVICE_MODEL.
+ replace("*", deviceCategory).
+ replace("?", deviceName);
+ ServiceReference[] refs = bc.getServiceReferences((String) null,
filter);
+ if (null != refs) {
+ final PlcModel plcModel = (PlcModel) bc.getService(refs[0]);
+ return Optional.of(plcModel);
+ }
+ } catch (Exception ex){
+ LOGGER.error(ex.getMessage());
+ }
+ return Optional.empty();
+ }
+
@Override
public void setPlcDeviceName(UUID deviceUuid, String deviceName) {
final PlcDevice plcdevice = getPlcDevice(deviceUuid);
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 c21c1ff..bec53f3 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
@@ -34,6 +34,7 @@ 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.PlcModel;
import org.apache.plc4x.merlot.api.PlcSecureBoot;
import org.apache.plc4x.merlot.scheduler.api.Job;
import org.apache.plc4x.merlot.scheduler.api.JobContext;
@@ -292,10 +293,16 @@ public class PlcSecureBootImpl implements PlcSecureBoot,
Job {
rsDevices.getString("DeviceName"),
rsDevices.getString("DeviceDescription"),
rsDevices.getString("DeviceEnable"));
-
- if (optPlcDevice.isPresent()) {
+
+ if (optPlcDevice.isPresent()) {
LOGGER.info("Created PlcDevice [{}].",
optPlcDevice.get().getDeviceKey());
-
+ Optional<PlcModel> optPlcModel = gf.createPlcModel(
+ optPlcDevice.get().getDeviceKey(),
+ optPlcDevice.get().getDeviceName());
+ if (!optPlcModel.isPresent()) {
+ LOGGER.info("No model for device:
{}",optPlcDevice.get().getDeviceName());
+ }
+
//PlcGroups
String queryGroups = SQL_SELECT_GROUPS.replace("?",
optPlcDevice.get().getUid().toString());
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 9f89ec1..7f49fa6 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
@@ -22,13 +22,10 @@ package org.apache.plc4x.merlot.db.api;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
-import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.tuple.ImmutablePair;
-import org.apache.commons.lang3.tuple.MutablePair;
-import org.apache.commons.lang3.tuple.Pair;
import org.apache.plc4x.merlot.api.PlcItem;
import org.apache.plc4x.merlot.api.PlcItemListener;
import org.epics.pvdata.property.AlarmSeverity;
@@ -39,7 +36,7 @@ import org.epics.pvdata.pv.PVStructure;
import org.epics.pvdatabase.PVRecord;
@SuppressWarnings("nls")
-public class DBRecord extends PVRecord implements PlcItemListener {
+public class DBRecord extends PVRecord implements PlcItemListener {
protected static final String MONITOR_FIELDS = "field(write_value,"+
"id,"+
"offset,"+
@@ -119,6 +116,7 @@ public class DBRecord extends PVRecord implements
PlcItemListener {
Matcher matcher;
if ((matcher = BYTE_OFFSET_PATTERN.matcher(strOffset)).matches()){
byteOffset = Integer.parseInt(matcher.group(BYTE_OFFSET ));
+ bitOffset = -1;
fieldOffsets.set(2, new ImmutablePair(byteOffset,(byte) -1));
} else if ((matcher =
BIT_OFFSET_PATTERN.matcher(strOffset)).matches()){
byteOffset = Integer.parseInt(matcher.group(BYTE_OFFSET ));
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/impl/DBPersistImpl.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/impl/DBPersistImpl.java
index 5251e54..addd086 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/impl/DBPersistImpl.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.db/src/main/java/org/apache/plc4x/merlot/db/impl/DBPersistImpl.java
@@ -27,9 +27,11 @@ import java.util.Optional;
import java.util.Properties;
import java.util.UUID;
import javax.sql.DataSource;
+import org.apache.plc4x.merlot.api.PlcDevice;
import org.apache.plc4x.merlot.api.PlcGeneralFunction;
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.PlcSecureBoot;
import org.apache.plc4x.merlot.db.api.DBRecord;
import org.apache.plc4x.merlot.db.api.DBRecordFactory;
@@ -45,12 +47,13 @@ import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
+import org.osgi.service.dal.Device;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventHandler;
import org.osgi.service.jdbc.DataSourceFactory;
import org.slf4j.LoggerFactory;
-public class DBPersistImpl implements EventHandler{
+public class DBPersistImpl implements EventHandler {
private static final org.slf4j.Logger LOGGER =
LoggerFactory.getLogger(DBPersistImpl.class);
private static final String DB_URL = "jdbc:sqlite:data/boot.db";
@@ -114,7 +117,7 @@ public class DBPersistImpl implements EventHandler{
private ServiceReference[] references = null;
private final PVDatabase master;
- private final PlcGeneralFunction plcGeneralFunction;
+ private final PlcGeneralFunction gf;
private final DBWriterHandler writerHandler;
DataSourceFactory dsFactory = null;
Connection dbConnection = null;
@@ -122,11 +125,11 @@ public class DBPersistImpl implements EventHandler{
public DBPersistImpl(BundleContext bc,
PVDatabase master,
- PlcGeneralFunction plcGeneralFunction,
+ PlcGeneralFunction gf,
DBWriterHandler writerHandler) {
this.bc = bc;
this.master = master;
- this.plcGeneralFunction = plcGeneralFunction;
+ this.gf = gf;
this.writerHandler = writerHandler;
}
@@ -172,6 +175,7 @@ public class DBPersistImpl implements EventHandler{
@Override
public void handleEvent(Event event) {
+ System.out.println("EWvento: " + event.toString());
if (event.getTopic().equals(PlcSecureBoot.EVENT_STORE)) {
try {
store();
@@ -201,7 +205,7 @@ public class DBPersistImpl implements EventHandler{
}
}
- public void restore() throws SQLException, InvalidSyntaxException {
+ public void restore() throws SQLException, InvalidSyntaxException,
InterruptedException {
String filter = null;
if (null != dbConnection) {
@@ -233,36 +237,55 @@ public class DBPersistImpl implements EventHandler{
pvRecord.getPVStructure().getDoubleField("control.limitHigh").put(Double.parseDouble(rs.getString("PvControlLimitHigh")));
pvRecord.getPVStructure().getDoubleField("control.minStep").put(Double.parseDouble(rs.getString("PvControlMinStep")));
+ //TODO:
//1. Se determina el dispositivo en funcion del pvId -> Se
obtiene el Device Name
//2. Se verifica si existe un factory para el PlcModel en
función del tipo de dispositivo.
//3. Se crean los espacios de memoria en funcion del pvId
y el pvScanTime
//4.
- String[] deviceNames =
pvRecord.getPVStructure().getStringField("id").get().split(":", 2);
-
-
- Optional<PlcItem> plcItem =
plcGeneralFunction.getPlcItem(rs.getString("PvId"));
-
- if (plcItem.isPresent()) {
- if (null ==
master.findRecord(pvRecord.getRecordName())) {
- plcItem.get().addItemListener((PlcItemListener)
pvRecord);
-
- //final UUID deviceUuid =
getDeviceUuid(plcItem.get().getItemUid());
-
- //final String strDriverName = (String)
plcGeneralFunction.getPlcDevice(deviceUuid).getProperties().get("DEVICE_CATEGORY");
-
- master.addRecord(pvRecord);
- final String strDriverName = (String)
refs[0].getProperty("db.record.driver");
-
getWriterHandler(strDriverName).putDBRecord((DBRecord) pvRecord);
-
-
+ String[] strFields =
pvRecord.getPVStructure().getStringField("id").get().split(":", 2);
+
+ Optional<PlcDevice> optPlcDevice =
gf.getPlcDevice(strFields[0]);
+ if (optPlcDevice.isPresent()){
+ final PlcDevice plcDevice = optPlcDevice.get();
+ final String category = (String)
plcDevice.getProperties().get(org.osgi.service.device.Constants.DEVICE_CATEGORY);
+ Optional<PlcModel> optPlcModel =
gf.getPlcModel(category, strFields[0]);
+
+ if (!optPlcModel.isPresent()) {
+ optPlcModel = gf.createPlcModel(category,
strFields[0]);
+ };
+
+ if (optPlcModel.isPresent()) {
+ optPlcModel.get().createScanGroup(pvRecord);
+ optPlcModel.get().createMemoryArea(pvRecord);
} else {
- LOGGER.info("DBRecord [?] already exist.",
rs.getString("PvId"));
- }
-
- } else {
- LOGGER.error("PlcItem [?] don't exist.",
rs.getString("PvId"));
- }
+ LOGGER.info("PlcModel {} is not present.",
strFields[0]);
+ }
+ };
+
+
+// Optional<PlcItem> plcItem = gf.getPlcItem(strFields[1]);
+//
+// if (plcItem.isPresent()) {
+// if (null ==
master.findRecord(pvRecord.getRecordName())) {
+// plcItem.get().addItemListener((PlcItemListener)
pvRecord);
+//
+// //final UUID deviceUuid =
getDeviceUuid(plcItem.get().getItemUid());
+//
+// //final String strDriverName = (String)
gf.getPlcDevice(deviceUuid).getProperties().get("DEVICE_CATEGORY");
+//
+// master.addRecord(pvRecord);
+// final String strDriverName = (String)
refs[0].getProperty("db.record.driver");
+//
getWriterHandler(strDriverName).putDBRecord((DBRecord) pvRecord);
+//
+//
+// } else {
+// LOGGER.info("DBRecord [?] already exist.",
rs.getString("PvId"));
+// }
+//
+// } else {
+// LOGGER.error("PlcItem [?] don't exist.",
rs.getString("PvId"));
+// }
}
}
}
diff --git a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/pom.xml
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/pom.xml
index 5e203b9..414ed30 100644
--- a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/pom.xml
+++ b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/pom.xml
@@ -87,8 +87,17 @@
<my.system.property>foo</my.system.property>
</systemPropertyVariables>
</configuration>
- </plugin>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <version>${maven-failsafe-plugin.version}</version>
+ <configuration>
+
<forkedProcessExitTimeoutInSeconds>0</forkedProcessExitTimeoutInSeconds>
+ </configuration>
+ </plugin>
</plugins>
+
</build>
<dependencies>
@@ -153,6 +162,13 @@
</exclusions>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>compile</scope>
+ <version>4.13.2</version>
+ </dependency>
+
<!-- Required to use shell commands in the tests -->
<dependency>
<groupId>org.apache.karaf.shell</groupId>
@@ -182,18 +198,6 @@
<artifactId>geronimo-atinject_1.0_spec</artifactId>
<version>1.2</version>
<scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.awaitility</groupId>
- <artifactId>awaitility</artifactId>
- <version>4.3.0</version>
- </dependency>
- <dependency>
- <groupId>org.hamcrest</groupId>
- <artifactId>hamcrest</artifactId>
- <version>2.2</version>
- <scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.servicemix.bundles</groupId>
@@ -201,6 +205,21 @@
<version>1.3_1</version>
<scope>runtime</scope>
</dependency>
-
+ <dependency>
+ <groupId>org.apache.plc4x</groupId>
+ <artifactId>plc4j-driver-simulated</artifactId>
+ <version>0.13.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <version>2.0.13</version>
+ </dependency>
+ <dependency>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <version>3.1.6</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/docs/asciidoc/S7PlcModel.puml
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/docs/asciidoc/S7PlcModel.puml
new file mode 100644
index 0000000..22b857b
--- /dev/null
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/docs/asciidoc/S7PlcModel.puml
@@ -0,0 +1,54 @@
+@startgantt
+[InternalPlcItem] requires 60 days and is colored in Lavender/LightBlue
+note bottom
+ Representación de área de memoría
+end note
+-- Scan Items --
+[scanItem01] starts D+0 and requires 8 days and is colored in Coral/Green
+[scanItem02] starts D+10 and requires 8 days and is colored in Coral/Green
+[scanItem03] starts D+20 and requires 8 days and is colored in Coral/Green
+[scanItem04] starts D+30 and requires 8 days and is colored in Coral/Green
+[scanItem05] starts D+40 and requires 8 days and is colored in Coral/Green
+[scanItem06] starts D+50 and requires 8 days and is colored in Coral/Green
+-- DBRecords --
+[dbRecord01] starts D+3 and requires 2 days
+Separator just at [dbRecord01]'s start
+Separator just at [dbRecord01]'s end
+note bottom
+ (x1 >= x) && (x1+l1 <= x+l)
+end note
+
+[dbRecord02] starts D+24 and requires 5 days
+Separator just at [dbRecord02]'s start
+Separator just at [dbRecord02]'s end
+note bottom
+ (min|distance|) && (x1+l1 > x+l)
+ el dbRecord ya esta cubierto por un PlcItem
+end note
+
+[dbRecord03] starts D+31 and requires 8 days
+Separator just at [dbRecord03]'s start
+Separator just at [dbRecord03]'s end
+note bottom
+ (min|distance|) && (x1+l1 > x+l)
+ El dbRecord se encuentra en el area de un PlcItem
+ pero debe no en todo su tamaño.
+end note
+
+[dbRecord04] starts D+39 and requires 8 days
+Separator just at [dbRecord04]'s start
+Separator just at [dbRecord04]'s end
+note bottom
+ (min|distance|) && (l1 > l)
+end note
+
+[dbRecord05] starts D+49 and requires 10 days
+Separator just at [dbRecord05]'s start
+Separator just at [dbRecord05]'s end
+note bottom
+ (min|distance|) && (l1 > l)
+ el dbRecord esta parcialmente cubierto por
+ un PlcItem
+end note
+
+@endgantt
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/docs/asciidoc/s7notes.adoc
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/docs/asciidoc/s7notes.adoc
new file mode 100644
index 0000000..d3af535
--- /dev/null
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/docs/asciidoc/s7notes.adoc
@@ -0,0 +1,19 @@
+= Main title
+Your name
+v1.0
+:toc: left
+:custom-property: custom property value!
+
+== Fisrt section
+
+// Read best practice
+Link to https://asciidoctor.org/docs/asciidoc-recommended-practices/[Asciidoc
recommended practices] +
+Link to https://docs.asciidoctor.org/[Asciidoctor Documentation Site]
+
+custom-property: {custom-property}
+
+.DRAFT
+----
+This document is only a rough draft.
+These recommendations are not doctrine and are subject to change.
+----
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/java/org/apache/plc4x/merlot/drv/s7/core/S7DBAiFactory.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/java/org/apache/plc4x/merlot/drv/s7/core/S7DBAiFactory.java
index eae4f5a..2d4e4d4 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/java/org/apache/plc4x/merlot/drv/s7/core/S7DBAiFactory.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/java/org/apache/plc4x/merlot/drv/s7/core/S7DBAiFactory.java
@@ -1,4 +1,4 @@
- /*
+/*
* 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
@@ -20,6 +20,7 @@ package org.apache.plc4x.merlot.drv.s7.core;
import io.netty.buffer.Unpooled;
import org.apache.commons.lang3.tuple.ImmutablePair;
+import org.apache.plc4x.java.s7.readwrite.tag.S7Tag;
import org.apache.plc4x.merlot.api.PlcItem;
import org.apache.plc4x.merlot.api.PlcItemListener;
import org.apache.plc4x.merlot.db.api.DBRecord;
@@ -33,6 +34,7 @@ import org.epics.pvdata.pv.FieldCreate;
import org.epics.pvdata.pv.PVBoolean;
import org.epics.pvdata.pv.PVFloat;
import org.epics.pvdata.pv.PVShort;
+import org.epics.pvdata.pv.PVString;
import org.epics.pvdata.pv.PVStructure;
import org.epics.pvdata.pv.ScalarType;
import org.epics.pvdata.pv.Structure;
@@ -109,6 +111,7 @@ public class S7DBAiFactory extends DBBaseFactory {
+ "rInLow, rInHigh, rInHighHigh, rInLowLowDeadband,
rInLowDeadband,"
+ "rInHighDeadband, rInHighHighDeadband})";
+ private PVString id;
private PVShort value;
private PVBoolean write_enable;
@@ -147,7 +150,9 @@ public class S7DBAiFactory extends DBBaseFactory {
public DBS7AiRecord(String recordName,PVStructure pvStructure) {
super(recordName, pvStructure);
-
+ innerBuffer = Unpooled.buffer(BUFFER_SIZE);
+
+ id = pvStructure.getStringField("id");
value = pvStructure.getShortField("value");
write_enable = pvStructure.getBooleanField("write_enable");
write_enable.put(false);
@@ -224,11 +229,18 @@ public class S7DBAiFactory extends DBBaseFactory {
public void atach(final PlcItem plcItem) {
this.plcItem = plcItem;
try {
- ParseOffset(
this.getPVStructure().getStringField("offset").get());
+ //ParseOffset(
this.getPVStructure().getStringField("offset").get());
+ String strId = id.get();
+ String[] fields = strId.split(":", 2);
+ S7Tag s7tag = S7Tag.of(fields[1]);
+
+ this.byteOffset = s7tag.getByteOffset();
+ this.bitOffset = s7tag.getBitOffset();
+
innerBuffer = plcItem.getItemByteBuf().slice(byteOffset,
BUFFER_SIZE);
} catch (Exception ex) {
//TODO: Logger
- //System.out.println("Exception: " + ex.getMessage());
+ System.out.println("Exception: " + ex.getMessage());
}
}
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcModelFactory.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/java/org/apache/plc4x/merlot/drv/s7/impl/S7PlcModelFactoryImpl.java
similarity index 52%
copy from
plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcModelFactory.java
copy to
plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/java/org/apache/plc4x/merlot/drv/s7/impl/S7PlcModelFactoryImpl.java
index f6221c7..c5c5a91 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.das.api/src/main/java/org/apache/plc4x/merlot/api/PlcModelFactory.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/java/org/apache/plc4x/merlot/drv/s7/impl/S7PlcModelFactoryImpl.java
@@ -14,13 +14,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.plc4x.merlot.api;
+package org.apache.plc4x.merlot.drv.s7.impl;
-/*
-* Objects that implement this interface are responsible for building
-* specific PlcModels. Each equipment model will have a specific structure.
-* For example, Modbus vs S7 vs Rockwell.
-*/
-public interface PlcModelFactory {
+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;
+
+/**
+ *
+ *
+ */
+public class S7PlcModelFactoryImpl implements PlcModelFactory {
+
+ private final BundleContext bc;
+ private final PlcGeneralFunction gf;
+
+ public S7PlcModelFactoryImpl(BundleContext bc, PlcGeneralFunction gf) {
+ this.bc = bc;
+ this.gf = gf;
+ }
+
+ @Override
+ public Optional<PlcModel> createPlcModel(String deviceCategory, String
deviceName) {
+ return Optional.of(new S7PlcModelImpl(bc, gf));
+ }
}
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 4972947..1ee5566 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
@@ -25,8 +25,11 @@ import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
-import org.apache.plc4x.java.api.model.PlcTag;
+import org.apache.commons.lang3.tuple.MutablePair;
+import org.apache.commons.lang3.tuple.Pair;
import org.apache.plc4x.java.s7.readwrite.MemoryArea;
+import org.apache.plc4x.java.s7.readwrite.TransportSize;
+import static org.apache.plc4x.java.s7.readwrite.TransportSize.BYTE;
import org.apache.plc4x.java.s7.readwrite.tag.S7Tag;
import org.apache.plc4x.merlot.api.PlcDevice;
import org.apache.plc4x.merlot.api.PlcGeneralFunction;
@@ -36,36 +39,40 @@ import org.apache.plc4x.merlot.api.PlcItemListener;
import org.apache.plc4x.merlot.api.PlcModel;
import org.apache.plc4x.merlot.api.impl.PlcItemImpl;
import org.apache.plc4x.merlot.db.api.DBRecord;
-import org.epics.pvdata.property.AlarmSeverity;
-import org.epics.pvdata.property.AlarmStatus;
import org.epics.pvdata.pv.PVString;
import org.epics.pvdata.pv.PVStructure;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-/**
- *
- * @author cgarcia
- */
-public class S7PlcModelImpl implements PlcModel{
+/*
+* S7PlcModelImpl is a representation of the memory areas associated
+* with a Siemens S7 PLC.
+*
+*/
+public class S7PlcModelImpl implements PlcModel {
private static final Logger logger =
LoggerFactory.getLogger(S7PlcModelImpl.class);
-
+
private BundleContext bc;
private PlcGeneralFunction gf;
- private PlcDevice plcDevice;
+ private PlcDevice plcDevice = null;
+ //Memory areas of the physical device
private Map<String, Map<Integer,PlcItem>> memoryAreas;
- private Map<UUID, PlcGroup> scanGroups = new HashMap();
-
+ //Scan group for the device.
+ private Map<UUID, PlcGroup> scanGroups = new HashMap<UUID, PlcGroup>();
+
+ //Individual Items for a memory area.
+ private Map<PlcItem, List<Pair<PlcGroup,PlcItem>>> scanItems = new
HashMap<PlcItem, List<Pair<PlcGroup,PlcItem>>>();
+
public S7PlcModelImpl(BundleContext bc, PlcGeneralFunction gf) {
this.bc = bc;
this.gf = gf;
- memoryAreas = new HashMap();
+ memoryAreas = new HashMap<String, Map<Integer,PlcItem>> ();
memoryAreas.put(MemoryArea.COUNTERS.getShortName(), null);
memoryAreas.put(MemoryArea.TIMERS.getShortName(), null);
memoryAreas.put(MemoryArea.DIRECT_PERIPHERAL_ACCESS.getShortName(),
null);
@@ -74,182 +81,274 @@ public class S7PlcModelImpl implements PlcModel{
memoryAreas.put(MemoryArea.FLAGS_MARKERS.getShortName(), null);
memoryAreas.put(MemoryArea.DATA_BLOCKS.getShortName(), null);
memoryAreas.put(MemoryArea.INSTANCE_DATA_BLOCKS.getShortName(), null);
- memoryAreas.put(MemoryArea.LOCAL_DATA.getShortName(), null);
-
+ memoryAreas.put(MemoryArea.LOCAL_DATA.getShortName(), null);
}
-
+
@Override
- public Set<String> ListMemoryAreas() {
+ public Set<String> listMemoryAreas() {
return memoryAreas.keySet();
}
+
+
@Override
- public Integer MemoryAreaId(String strMemoryArea) {
+ public Integer getMemoryAreaId(String strMemoryArea) {
return
Integer.valueOf(MemoryArea.firstEnumForFieldShortName((strMemoryArea)).getValue());
}
@Override
- public void CreateMemoryArea(DBRecord dbRecord) {
- final PVStructure pvStructure = dbRecord.getPVStructure();
+ 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];
//TODO: Split the Device name.
S7Tag s7tag = S7Tag.of(strTag);
- checkByteBufInstance(s7tag);
-
-
-// switch(s7tag.getMemoryArea().getValue()) {
-// case 0x1C: {
-// if (null == memoryAreas.get("C"))
createCounterArea(s7tag);
-// final Map<Integer, PlcItem> CBytes =
memoryAreas.get("C");
-// };
-// break;
-// case 0x1D: {
-// if (null == memoryAreas.get("T")) createTimerArea(s7tag);
-// final Map<Integer, PlcItem> TBytes =
memoryAreas.get("T");
-// };
-// break;
-// case 0x80: {
-// if (null == memoryAreas.get("D"))
createDirectPeripheralAccessArea(s7tag);
-// final Map<Integer, PlcItem> DBytes =
memoryAreas.get("D");
-// };
-// break;
-// case 0x81:{
-// if (null == memoryAreas.get("I")) createInputArea(s7tag);
-// final Map<Integer, PlcItem> inputBytes =
memoryAreas.get("I");
-// };
-// break;
-// case 0x82: {
-// if (null == memoryAreas.get("Q"))
createOutputArea(s7tag);
-// final Map<Integer, PlcItem> QBytes =
memoryAreas.get("Q");
-// };
-// break;
-// case 0x83: {
-// if (null == memoryAreas.get("M"))
createFlagMarkerArea(s7tag);
-// final Map<Integer, PlcItem> MBytes =
memoryAreas.get("M");
-// };
-// break;
-// case 0x84: {
-// if (null == memoryAreas.get("DB"))
createDataBlocksArea(s7tag);
-// final Map<Integer, PlcItem> DBBytes =
memoryAreas.get("DB");
-//
-// };
-// break;
-// case 0x85: {
-// if (null == memoryAreas.get("DBI"))
createDataBlocksInstanceArea(s7tag);
-// final Map<Integer, PlcItem> DBIBytes =
memoryAreas.get("DBI");
-// };
-// break;
-// case 0x86: {
-// if (null == memoryAreas.get("LD"))
createFlagMarkerArea(s7tag);
-// final Map<Integer, PlcItem> LDBytes =
memoryAreas.get("LD");
-// };
-// break;
-//
-// }
+
+ 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() +"]");
+ }
+
+ 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);
+ }
+
+ 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 (byteBuf.capacity() < minSize) {
+ byteBuf.capacity(minSize);
+ logger.info("The buffer capacity was expanded to {}.", minSize);
+ }
}
@Override
- public void CreateScanGroup(DBRecord dbRecord) {
- final PVStructure pvStructure = dbRecord.getPVStructure();
+ public void createScanGroup(Object dbRecord) {
+ final DBRecord dbrecord = (DBRecord) dbRecord;
+ final PVStructure pvStructure = dbrecord.getPVStructure();
+ final PVString pvId = pvStructure.getStringField("id");
final String pvScanTime =
pvStructure.getStringField("scan_time").get();
long longScanTime = Long.parseLong(pvScanTime);
long scan_time = ( longScanTime < 100) ? 100 : longScanTime;
- Optional<Entry<UUID, PlcGroup>> optEntry = scanGroups.
- entrySet().
- stream().
- filter(g -> g.getValue().getPeriod() == scan_time).
- findFirst();
- if (optEntry.isEmpty()) {
- UUID uuid = UUID.randomUUID();
- Optional<PlcGroup> optPlcGroup = gf.createGroup(uuid.toString(),
- plcDevice.getUid().toString(),
- "",
- "S7 Model group " + scanGroups.size(),
- pvScanTime,
- "true");
- if (optPlcGroup.isPresent()) {
- scanGroups.put(uuid, optPlcGroup.get());
- } else {
- logger.info("Scan group was not created for device {} and time
{}", plcDevice.getDeviceName(), pvScanTime);
+
+ if (null == plcDevice) {
+ String[] strTemp = pvId.get().split(":", 2);
+ String strDevices = strTemp[0];
+ Optional<PlcDevice> optPlcDevice = gf.getPlcDevice(strDevices);
+ if (optPlcDevice.isPresent())
+ plcDevice = optPlcDevice.get();
+ }
+
+ if (null != plcDevice) {
+ Optional<Entry<UUID, PlcGroup>> optEntry = scanGroups.
+ entrySet().
+ stream().
+ filter(g -> g.getValue().getPeriod() == scan_time).
+ findFirst();
+ if (optEntry.isEmpty()) {
+ UUID uuid = UUID.randomUUID();
+ Optional<PlcGroup> optPlcGroup =
gf.createGroup(uuid.toString(),
+ plcDevice.getUid().toString(),
+ Long.toString(System.currentTimeMillis()),
+ "S7 Model group " + scanGroups.size(),
+ pvScanTime,
+ "true");
+ if (optPlcGroup.isPresent()) {
+ scanGroups.put(uuid, optPlcGroup.get());
+ System.out.println("Grupo creado!!!");
+ } else {
+ logger.info("Scan group was not created for device {} and
time {}", plcDevice.getDeviceName(), pvScanTime);
+ }
}
+ } else {
+ logger.info("Scan group was not created for DBRecord {}.");
+ System.out.println("No encontro dispositvo!!!");
}
}
-
-
-
+
@Override
- public Integer MemoryAreaSegment(String strMemoryArea) {
- throw new UnsupportedOperationException("Not supported yet.");
+ public Integer getMemoryAreaSegmentCount(String strMemoryArea) {
+ return memoryAreas.get(strMemoryArea).keySet().size();
}
@Override
- public List<Integer> MemoryAreaSegmentId(String strMemoryArea) {
- throw new UnsupportedOperationException("Not supported yet.");
+ public Set<Integer> getMemoryAreaSegmentIds(String strMemoryArea) {
+ return memoryAreas.get(strMemoryArea).keySet();
}
@Override
- public void AddMemoryAreaListener(String strMemmoryArea, Integer index,
PlcItemListener listener) {
+ public Optional<PlcItem> getMemoryAreaPlcItem(String memoryArea, Integer
index) {
+ if ((memoryAreas.containsKey(memoryArea)) &&
+ (memoryAreas.get(memoryArea).containsKey(index))){
+ return Optional.of(memoryAreas.get(memoryArea).get(index));
+ }
+ return Optional.empty();
+ }
+
+ @Override
+ public void addMemoryAreaListener(String strMemmoryArea, Integer index,
PlcItemListener listener) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
- public void RemoveMemoryAreaListener(String strMemmoryArea, Integer index,
PlcItemListener listener) {
+ public void removeMemoryAreaListener(String strMemmoryArea, Integer index,
PlcItemListener listener) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
- public List<UUID> ModelPlcGroupsUuid(String strMemoryArea) {
+ public Set<UUID> getModelPlcGroupUuids(String strMemoryArea) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
- public List<UUID> ModelPlcItemsUuid(String strMemoryArea) {
+ public Set<UUID> getModelPlcItemUuids(String strMemoryArea) {
throw new UnsupportedOperationException("Not supported yet.");
}
-
- private void checkByteBufInstance(S7Tag tag) {
- if (null == memoryAreas.get(tag.getMemoryArea().getShortName())) {
- PlcItem internalPlcItem = new PlcItemImpl.PlcItemBuilder("s7" +
tag.getMemoryArea().getShortName() + "["+tag.getBlockNumber() +"]").
- setItemDescription("Flag markes from PLC in byte order.").
- setItemId("").
- setItemEnable(true).
- build();
- Map<Integer, PlcItem> inputBytes = new HashMap();
- inputBytes.put(tag.getBlockNumber(), internalPlcItem);
- memoryAreas.put(tag.getMemoryArea().getShortName(), inputBytes);
- logger.info("Creted memmory area with PlcItem: " + "s7" +
tag.getMemoryArea().getShortName() + "["+tag.getBlockNumber() +"]");
- }
+
+ /*
+ *
+ */
+ private void doUpdateByteBuf(DBRecord dbRecord){
+ PlcItem tempPlcItem = null;
+ final DBRecord dbrecord = (DBRecord) dbRecord;
+ final PVStructure pvStructure = dbrecord.getPVStructure();
+ final String pvId = pvStructure.getStringField("id").get();
+ final String pvScanTime =
pvStructure.getStringField("scan_time").get();
+ long longScanTime = Long.parseLong(pvScanTime);
+ long scan_time = ( longScanTime < 100) ? 100 : longScanTime;
- final Map<Integer, PlcItem> memoryBytes =
memoryAreas.get(tag.getMemoryArea().getShortName());
+ // 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.
- if (null == memoryBytes.get(tag.getBlockNumber())) {
- PlcItem plcItem = new PlcItemImpl.PlcItemBuilder("s7" +
tag.getMemoryArea().getShortName() + "["+tag.getBlockNumber() +"]").
- setItemDescription("Flag markes from PLC in byte order.").
- setItemId("").
- setItemEnable(true).
- build();
- memoryBytes.put(tag.getBlockNumber(), plcItem);
- }
+ String[] strTemp = pvId.split(":", 2);
+ String strTag = strTemp[1];
- final PlcItem internalPlcItem = memoryBytes.get(tag.getBlockNumber());
- final ByteBuf byteBuf = internalPlcItem.getItemByteBuf();
+ //TODO: Split the Device name.
+ S7Tag s7tag = S7Tag.of(strTag);
- int minSize = tag.getByteOffset() +
- tag.getDataType().getSizeInBytes() *
tag.getNumberOfElements();
+ final Map<Integer, PlcItem> memoryItems =
memoryAreas.get(s7tag.getMemoryArea().getShortName()); //(01)
+ final PlcItem internalPlcItem =
memoryItems.get(s7tag.getBlockNumber()); //(02)
+ final ByteBuf byteBuf = internalPlcItem.getItemByteBuf();
- if (byteBuf.capacity() < minSize) {
- if (byteBuf.ensureWritable(minSize, true) != 0) {
- logger.info("The buffer capacity was expanded to {}.",
minSize);
+ dbRecord.atach(internalPlcItem);
+
+ //1. Chequea si el direccionamiento esta dentro de uno de los items
+ // si: 1.1 Verifica si esta dentro de todo el segmento.
+ // 1.2 si sobre sale del segmento, llega a una distancia mínima
+ // del sisguiente Item.
+ // si: 1.2.1 recalcula el Item para que cubra ambas area.
+ // trasiega los clientes al nuevo Item.
+ // no: Incrementa la solicitud del Item a las distancia
necesaria.
+ // no: Crea el item con el tamaño necesario, y realiza la
suscripción.
+
+ //2. El attach se realiza al internalPlcItem
+ //3. El Listener se realiza al nuevo PlcIem
+
+ //Take the list of items associated with a memory area
+ var plcItems = scanItems.get(internalPlcItem);
+
+ //Create the first PlcItem in this memory area
+ if (null == plcItems) { //(03)
+
+ scanItems.put(internalPlcItem, new
ArrayList<Pair<PlcGroup,PlcItem>>());
+ //Create a new PlcItem associated with the memory area
+ PlcItem scanPlcItem = new
PlcItemImpl.PlcItemBuilder(UUID.randomUUID().toString()).
+ setItemDescription("Flag markes from PLC in byte order.").
+ setItemId("").
+ setItemEnable(false).
+ build();
+
+ //Assigns the request tag in Bytes.
+
+ S7Tag s7PlcTag = null;
+ s7PlcTag = new S7Tag(TransportSize.USINT,
+ s7tag.getMemoryArea(),
+ s7tag.getBlockNumber(),
+ s7tag.getByteOffset(),
+ (byte) 0,
+
dbRecord.getInnerBuffer().get().writableBytes());
+
+ scanPlcItem.setItemPlcTag(s7PlcTag);
+
+ scanPlcItem.setItemByteBuf(
+ byteBuf.slice(s7tag.getByteOffset(),
s7tag.getNumberOfElements())
+ );
+
+ Optional<Entry<UUID, PlcGroup>> optGroup = scanGroups.
+ entrySet().
+ stream().
+ filter(g -> g.getValue().getPeriod() == scan_time).
+ findFirst();
+
+ if (optGroup.isPresent()) {
+ scanPlcItem.addItemListener(dbrecord);
+ scanPlcItem.setEnable(true);
+ scanItems.get(internalPlcItem).add(new
MutablePair<>(optGroup.get().getValue(), scanPlcItem));
+ optGroup.get().getValue().putItem(scanPlcItem);
+ } else {
+ logger.info("Scan group no present {}.", scan_time);
}
- }
+ } else {
+
+ Optional<PlcItem> optPlcItem = scanItems.keySet().
+ stream().
+ filter(i -> {
+ final S7Tag itemTag = (S7Tag) i.getItemPlcTag();
+ int x1 = itemTag.getByteOffset();
+ int x2 = itemTag.getByteOffset() +
s7tag.getByteOffset();
+
+ return ((s7tag.getByteOffset() >= x1) &&
(s7tag.getByteOffset() + s7tag.getNumberOfElements() <= x2));
+ }).
+ findFirst();
+
+ if (!optPlcItem.isPresent()){
+ List<PlcItem> rangeItems = scanItems.keySet().
+ stream().
+ filter(i -> {
+ final S7Tag itemTag = (S7Tag) i.getItemPlcTag();
+ int x1 = itemTag.getByteOffset();
+ return (s7tag.getByteOffset() >= x1);
+ }).
+ toList();
+
+ int distance = Integer.MAX_VALUE;
+
+ while(rangeItems.listIterator().hasNext()) {
+ final PlcItem i = rangeItems.listIterator().next();
+ final S7Tag itemTag = (S7Tag) i.getItemPlcTag();
+ if (Math.abs(s7tag.getByteOffset() -
itemTag.getByteOffset()) < distance) {
+ distance = Math.abs(s7tag.getByteOffset() -
itemTag.getByteOffset());
+ tempPlcItem = i;
+ }
+ }
+
+ } else {
+ tempPlcItem = optPlcItem.get();
+ }
+ }
+
+
}
-
-
-
+
}
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/resources/OSGI-INF/blueprint/s7-drv-service.xml
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/resources/OSGI-INF/blueprint/s7-drv-service.xml
index 8a645b6..43e40a5 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/resources/OSGI-INF/blueprint/s7-drv-service.xml
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/main/resources/OSGI-INF/blueprint/s7-drv-service.xml
@@ -17,6 +17,11 @@
-->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
default-activation="eager">
+
+ <reference
+ id="refPlcGeneralFunction"
+ interface="org.apache.plc4x.merlot.api.PlcGeneralFunction"
availability="mandatory" timeout="1200"/>
+
<reference id="S7Plc4xDriverRef"
interface="org.apache.plc4x.java.api.PlcDriver"
filter="(org.apache.plc4x.driver.code=s7)"
@@ -56,10 +61,14 @@
<bean id="S7DBValveAnalogFactoryBean"
class="org.apache.plc4x.merlot.drv.s7.core.S7DBValveAnalogFactory"
scope="singleton" />
<bean id="S7DBMotorFactoryBean"
class="org.apache.plc4x.merlot.drv.s7.core.S7DBMotorFactory" scope="singleton"
/>
-
- <bean id="S7DBWriterHandlerImpl"
class="org.apache.plc4x.merlot.drv.s7.impl.S7DBWriterHandlerImpl"/>
-
+ <bean id="S7DBWriterHandlerImpl"
class="org.apache.plc4x.merlot.drv.s7.impl.S7DBWriterHandlerImpl"/>
+
+ <bean id="S7PlcModelFactoryBean"
class="org.apache.plc4x.merlot.drv.s7.impl.S7PlcModelFactoryImpl"
scope="singleton">
+ <argument ref="refPlcGeneralFunction"/>
+ <argument ref="blueprintBundleContext"/>
+ </bean>
+
<service ranking="0" ref="S7PlcTagFunctionBean" auto-export="interfaces">
<service-properties>
<entry key="dal.function.UID" value="org.apache.plc4x.s7"/>
@@ -229,5 +238,17 @@
<entry key="db.record.writehandler.category" value="s7-light"/>
</service-properties>
</service>
+
+ <service ref="S7PlcModelFactoryBean"
interface="org.apache.plc4x.merlot.api.PlcModelFactory">
+ <service-properties>
+ <entry key="plc4x.plcmodel.category" value="s7"/>
+ </service-properties>
+ </service>
+
+ <service ref="S7PlcModelFactoryBean"
interface="org.apache.plc4x.merlot.api.PlcModelFactory">
+ <service-properties>
+ <entry key="plc4x.plcmodel.category" value="s7-light"/>
+ </service-properties>
+ </service>
</blueprint>
\ No newline at end of file
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/MerlotS7Test.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/MerlotS7Test.java
deleted file mode 100644
index 9a5f024..0000000
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/MerlotS7Test.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
to change this license
- * Click
nbfs://nbhost/SystemFileSystem/Templates/UnitTests/JUnit5TestClass.java to edit
this template
- */
-package org.apache.plc4x.merlot.drv.s7.core;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import org.apache.karaf.itests.KarafTestSupport;
-import org.apache.karaf.shell.api.console.Session;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerClass;
-
-
-/**
- *
- * @author cgarcia
- */
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerClass.class)
-public class MerlotS7Test extends TestBase{
-
-
-
- private ExecutorService executor = Executors.newCachedThreadPool();
-
- private ByteArrayOutputStream byteArrayOutputStream = new
ByteArrayOutputStream();
- private PrintStream printStream = new PrintStream(byteArrayOutputStream);
- private PrintStream errStream = new PrintStream(byteArrayOutputStream);
-
-
- final static String UNPACK_DIR_NAME = "merlot";
-
-
-// //@BeforeAll
-// public static void setUpClass() {
-// }
-//
-// //@AfterAll
-// public static void tearDownClass() {
-// }
-//
-// //@BeforeEach
-// public void setUp() {
-// }
-//
-// //@AfterEach
-// public void tearDown() {
-// }
-
- // TODO add test methods here.
- // The methods must be annotated with annotation @Test. For example:
- //
- @Test
- public void hello() {
- System.out.println("Hola mundo");
- }
-
-
- @Test
- public void listBundleCommand() throws Exception {
-// // assert on an available service
-// assertServiceAvailable(FeaturesService.class);
-//
-// // installing a feature and verifying that it's correctly installed
-// installAndAssertFeature("scr");
-//import static junit.framework.Assert.assertEquals;
-// // testing a command execution
-
- //session = sessionFactory.create(System.in, printStream, errStream);
-
- String bundles = executeCommand("bundle:list -t 0");
- System.out.println(bundles);
-
-// assertContains("junit", bundles);
-//
-// String features = executeCommand("feature:list -i");
-// System.out.print(features);
-// assertContains("scr", features);
-//
-// // using a service and assert state or result
-// FeaturesService featuresService =
getOsgiService(FeaturesService.class);
-// Feature scr = featuresService.getFeature("scr");
-// assertEquals("scr", scr.getName());
- }
-
-
-}
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/RegressionConfiguration.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/RegressionConfiguration.java
deleted file mode 100644
index f9442a4..0000000
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/RegressionConfiguration.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright 2011 Harald Wellmann.
- *
- * Licensed 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.s7.core;
-
-import static org.ops4j.pax.exam.CoreOptions.composite;
-import static org.ops4j.pax.exam.CoreOptions.maven;
-import static org.ops4j.pax.exam.CoreOptions.propagateSystemProperty;
-import static org.ops4j.pax.exam.CoreOptions.systemProperty;
-import static org.ops4j.pax.exam.CoreOptions.when;
-import static
org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
-import static
org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureSecurity;
-import static
org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
-import static
org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
-import static
org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
-
-import java.io.File;
-
-import org.ops4j.pax.exam.Option;
-import org.ops4j.pax.exam.karaf.options.configs.CustomProperties;
-import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
-
-/**
- * Default configuration for native container regression tests, overriding the
default test system
- * configuration.
- * <p>
- * We do not need the Remote Bundle Context for Native Container, and we
prefer unified logging with
- * logback.
- * <p>
- * To override the standard options, you need to set the configuration property
- * {@code pax.exam.system = default}.
- *
- * @author Harald Wellmann
- * @since Dec 2011
- */
-public class RegressionConfiguration {
-
- public static final String HTTP_PORT = "9080";
-
- public static Option regressionDefaults(String unpackDir) {
- return composite(
- karafDistributionConfiguration().frameworkUrl(mvnKarafDist())
- .unpackDirectory(unpackDir == null ? null : new
File(unpackDir)),
-
- keepRuntimeFolder(),
-
- configureConsole().ignoreLocalConsole(),
- configureConsole().ignoreRemoteShell(),
- configureSecurity().disableKarafMBeanServerBuilder(),
-
- when(isEquinox()).useOptions(
- editConfigurationFilePut(CustomProperties.KARAF_FRAMEWORK,
"felix"),
- propagateSystemProperty("pax.exam.framework"),
- systemProperty("osgi.console").value("6666"),
- systemProperty("osgi.console.enable.builtin").value("true")));
- }
-
- public static boolean isEquinox() {
- return "equinox".equals(System.getProperty("pax.exam.framework"));
- }
-
- public static boolean isFelix() {
- return "felix".equals(System.getProperty("pax.exam.framework"));
- }
-
- public static MavenArtifactUrlReference mvnKarafDist() {
- return maven().groupId("org.apache.karaf")
- .artifactId("apache-karaf").type("tar.gz").versionAsInProject();
- }
-
- public static MavenArtifactUrlReference featureRepoStandard() {
- return
maven().groupId("org.apache.karaf.features").artifactId("standard").type("xml")
- .classifier("features").versionAsInProject();
- }
-
-}
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBAiTest.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBAiTest.java
index 435891c..1cdd30f 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBAiTest.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBAiTest.java
@@ -35,6 +35,8 @@ import org.epics.pvdata.pv.PVStructure;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -69,7 +71,7 @@ public class S7DBAiTest {
private PVBoolean bInvalid;
- //@BeforeAll
+ @BeforeClass
public static void setUpClass() {
logger.info("Starting the testing of the analog input class");
logger.info("Test Analog inputs for S7 plc");
@@ -89,16 +91,39 @@ public class S7DBAiTest {
byteBuf.setShort(20, 0b0000_0001_0000_0000);//0. bPB_ResetError
//1. bPBEN_ResetError
- //2. bError
+ //2. bError
+
}
- //@AfterAll
+ @BeforeClass
public static void tearDownClass() {
logger.info("Ending the analog input class test");
}
- //@BeforeEach
+ @Before
public void setUp() {
+ System.out.println("setUp");
+
+ logger.info("Starting the testing of the analog input class");
+ logger.info("Test Analog inputs for S7 plc");
+ logger.info("Creating buffer to plcValue");
+ byteBuf = buffer(100);
+ byteBuf.setShort(0, 0b0000_0001_0000_0000); //0. bLowLowAlarm
+ //1. bHighHighAlarm
+ //2. bInvalid
+
+ byteBuf.setShort(2, 1234); //iMOde
+ byteBuf.setShort(4, 4321); //iErrorCode
+ byteBuf.setShort(6, 1010); //iStatus
+
+ byteBuf.setFloat(8, 3.1416F); //iActiveValue
+ byteBuf.setFloat(12, 3.1416F * 2); //rInputValue
+ byteBuf.setFloat(16, 3.1416F * 4); //rManualValue
+
+ byteBuf.setShort(20, 0b0000_0001_0000_0000);//0. bPB_ResetError
+ //1. bPBEN_ResetError
+ //2. bError
+
//Create PLCList for the items
plcValue = new PlcRawByteArray(byteBuf.array());
//Create the Item
@@ -108,13 +133,14 @@ public class S7DBAiTest {
setItemId(uuid).
setItemUid(UUID.fromString(uuid)).
build();
+
assertNotNull(plcItem);
assertNotNull(plcValue);
DBBaseFactory AIFactory = new S7DBAiFactory();
AI = AIFactory.create("AI");
- PVString pvStrOffset =
AI.getPVRecordStructure().getPVStructure().getStringField("offset");
- pvStrOffset.put("0");
+ PVString pvStrId =
AI.getPVRecordStructure().getPVStructure().getStringField("id");
+ pvStrId.put("s7:%DB100:23:BYTE[6]");
AI.atach(plcItem);
}
@@ -133,7 +159,7 @@ public class S7DBAiTest {
@Test
//@Order(2)
public void FieldOffsetTest() {
-
+ System.out.println("@Order(2)");
ArrayList<ImmutablePair<Integer, Byte>> fieldOffsets =
AI.getFieldOffsets();
assertNull(fieldOffsets.get(0));
@@ -169,10 +195,10 @@ public class S7DBAiTest {
// TODO add test methods here.
// The methods must be annotated with annotation @Test. For example:
//
- @Test
+// @Test
//@Order(1)
public void DBRecordTest() {
-
+ System.out.println("@Order(1)");
PVString pvStrOffset =
AI.getPVRecordStructure().getPVStructure().getStringField("offset");
pvStrOffset.put("0");
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBAoTest.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBAoTest.java
index bb7fe6d..b5868c7 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBAoTest.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBAoTest.java
@@ -142,7 +142,7 @@ public class S7DBAoTest {
plcValue = null;
}
- @Test
+// @Test
//@Order(1)
public void DBRecordTest() {
@@ -186,7 +186,7 @@ public class S7DBAoTest {
assertEquals(2345, iEstopFunction.get());
}
- @Test
+// @Test
//@Order(2)
public void FieldOffsetTest() {
ArrayList<ImmutablePair<Integer, Byte>> fieldOffsets =
AO.getFieldOffsets();
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBCounterTest.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBCounterTest.java
index f7aabe7..a835764 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBCounterTest.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBCounterTest.java
@@ -99,7 +99,7 @@ public class S7DBCounterTest {
plcValue = null;
}
- @Test
+// @Test
//@Order(1)
public void DBRecordTest() {
value =
CNT.getPVRecordStructure().getPVStructure().getShortField("value");
@@ -108,7 +108,7 @@ public class S7DBCounterTest {
assertEquals(123, value.get());
}
- @Test
+// @Test
//@Order(2)
public void FieldOffsetTest() {
ArrayList<ImmutablePair<Integer, Byte>> fieldOffsets =
CNT.getFieldOffsets();
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBDateAndTimeTest.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBDateAndTimeTest.java
index 5f14a7e..181e59a 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBDateAndTimeTest.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBDateAndTimeTest.java
@@ -112,7 +112,7 @@ public class S7DBDateAndTimeTest {
plcValue = null;
}
- @Test
+// @Test
//@Order(1)
public void DBRecordTest() {
@@ -123,7 +123,7 @@ public class S7DBDateAndTimeTest {
assertEquals(2667010605989264129L, value.get());
}
- @Test
+// @Test
//@Order(2)
public void FieldOffsetTest() {
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBDateTest.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBDateTest.java
index c6b7644..847e870 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBDateTest.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBDateTest.java
@@ -108,7 +108,7 @@ public class S7DBDateTest {
plcValue = null;
}
- @Test
+// @Test
//@Order(1)
public void DBRecordTest() {
value =
DATE.getPVRecordStructure().getPVStructure().getShortField("value");
@@ -119,7 +119,7 @@ public class S7DBDateTest {
assertEquals((short) 0xFF62, value.get());
}
- @Test
+// @Test
//@Order(2)
public void FieldOffsetTest() {
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBMotorTest.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBMotorTest.java
index d3030de..77519e2 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBMotorTest.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBMotorTest.java
@@ -141,7 +141,7 @@ public class S7DBMotorTest {
plcValue = null;
}
- @Test
+// @Test
//@Order(1)
public void DBRecordTest() {
@@ -215,7 +215,7 @@ public class S7DBMotorTest {
}
- @Test
+// @Test
//@Order(2)
public void FieldOffsetTest() {
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBValveAnalogTest.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBValveAnalogTest.java
index 258f311..a8fad84 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBValveAnalogTest.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBValveAnalogTest.java
@@ -132,7 +132,7 @@ public class S7DBValveAnalogTest {
plcValue = null;
}
- @Test
+// @Test
//@Order(1)
public void DBRecordTest() {
@@ -176,7 +176,7 @@ public class S7DBValveAnalogTest {
}
- @Test
+// @Test
//@Order(2)
public void FieldOffsetTest() {
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBValveSolenoidTest.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBValveSolenoidTest.java
index f055fb8..042bf54 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBValveSolenoidTest.java
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7DBValveSolenoidTest.java
@@ -139,7 +139,7 @@ public class S7DBValveSolenoidTest {
plcValue = null;
}
- @Test
+// @Test
//@Order(1)
public void dbAoRecord() {
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7EmptyJUnitTest.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7EmptyJUnitTest.java
new file mode 100644
index 0000000..af6e097
--- /dev/null
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7EmptyJUnitTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.s7.core;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.apache.karaf.itests.KarafTestSupport;
+import org.junit.FixMethodOrder;
+import org.junit.runners.MethodSorters;
+import org.ops4j.pax.exam.Configuration;
+import static org.ops4j.pax.exam.CoreOptions.keepCaches;
+import org.ops4j.pax.exam.Option;
+import static org.ops4j.pax.exam.OptionUtils.combine;
+
+/**
+ *
+ * @author cgarcia
+ */
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class S7EmptyJUnitTest extends KarafTestSupport{
+
+ private ExecutorService executor = Executors.newCachedThreadPool();
+
+ private ByteArrayOutputStream byteArrayOutputStream = new
ByteArrayOutputStream();
+ private PrintStream printStream = new PrintStream(byteArrayOutputStream);
+ private PrintStream errStream = new PrintStream(byteArrayOutputStream);
+
+ final static String UNPACK_DIR_NAME = "merlot";
+
+ public S7EmptyJUnitTest() {
+ }
+
+ /*
+ * Ensures that the bundle is maintained between different tests.
+ */
+ @Configuration
+ public Option[] config() {
+ return combine(new Option[] {keepCaches()}, super.config());
+ }
+
+ @BeforeClass
+ public static void setUpClass() {
+
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ @Test
+ public void testBundleList_1() {
+ String bundles = executeCommand("bundle:list");
+ System.out.println(bundles);
+ }
+}
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7PlcModelTest.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7PlcModelTest.java
new file mode 100644
index 0000000..44ccd2f
--- /dev/null
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7PlcModelTest.java
@@ -0,0 +1,549 @@
+/*
+ * 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.s7.core;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.Optional;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import javax.inject.Inject;
+import org.apache.karaf.features.BootFinished;
+import org.apache.karaf.itests.KarafTestSupport;
+import org.apache.plc4x.java.api.PlcDriver;
+import org.apache.plc4x.java.s7.readwrite.MemoryArea;
+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.PlcModel;
+import org.apache.plc4x.merlot.api.impl.PlcItemImpl;
+import org.apache.plc4x.merlot.db.api.DBRecord;
+import org.apache.plc4x.merlot.db.api.DBRecordFactory;
+import org.epics.pvdata.pv.PVBoolean;
+import org.epics.pvdata.pv.PVString;
+import org.epics.pvdata.pv.PVStructure;
+import org.junit.After;
+import org.junit.AfterClass;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.ops4j.pax.exam.Configuration;
+import static org.ops4j.pax.exam.CoreOptions.keepCaches;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import static org.ops4j.pax.exam.OptionUtils.combine;
+import org.ops4j.pax.exam.spi.reactors.PerSuite;
+
+/**
+ *
+ * @author cgarcia
+ */
+@RunWith(PaxExam.class)
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+@ExamReactorStrategy(PerSuite.class)
+public class S7PlcModelTest extends KarafTestSupport {
+
+
+ // Wait for all the boot features to be installed.
+ @Inject
+ protected BootFinished bootFinished;
+
+ private ExecutorService executor = Executors.newCachedThreadPool();
+
+ private ByteArrayOutputStream byteArrayOutputStream = new
ByteArrayOutputStream();
+ private PrintStream printStream = new PrintStream(byteArrayOutputStream);
+ private PrintStream errStream = new PrintStream(byteArrayOutputStream);
+
+
+ final static String UNPACK_DIR_NAME = "merlot";
+
+ /*
+ *
+ */
+ @Configuration
+ public Option[] config() {
+ return combine(new Option[] {
+ keepCaches(),
+ mavenBundle("org.json","json","20250517")},
+ super.config());
+ }
+
+ @BeforeClass
+ public static void setUpClass() {
+
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ }
+
+ @Before
+ public void setUp() {
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ /*
+ * Installs all Merlot features associated with the S7 driver.
+ */
+ @Test
+ public void testS7Services_001() throws Exception {
+
addFeaturesRepository("mvn:org.apache.karaf.decanter/apache-karaf-decanter/2.0.0/xml/features");
+
addFeaturesRepository("mvn:org.apache.plc4x.merlot.features/org.apache.plc4x.merlot.features/0.13.0-SNAPSHOT/xml/features");
+ installAndAssertFeature("org.apache.plc4x.merlot.features");
+ }
+
+ /*
+ * List filtered bundle in Merlot server.
+ */
+ @Test
+ public void testS7Services_002() throws Exception {
+// // assert on an available service
+// assertServiceAvailable(FeaturesService.class);
+//
+// // installing a feature and verifying that it's correctly installed
+// installAndAssertFeature("scr");
+//import static junit.framework.Assert.assertEquals;
+// // testing a command execution
+
+ //session = sessionFactory.create(System.in, printStream, errStream);
+
+// String cliRes = executeCommand("ls");
+// System.out.println(cliRes);
+// cliRes = executeCommand("bundle:diag 146");
+// System.out.println(cliRes);
+
+// assertContains("junit", cliRes);
+//
+// String features = executeCommand("feature:list -i");
+// System.out.print(features);
+// assertContains("scr", features);
+//
+// // using a service and assert state or result
+// FeaturesService featuresService =
getOsgiService(FeaturesService.class);
+// Feature scr = featuresService.getFeature("scr");
+// assertEquals("scr", scr.getName());
+ }
+
+ /*
+ * Check that all services are deployed.
+ */
+ @Test
+ public void testS7Services_003() throws Exception {
+ assertFeatureInstalled("org.apache.plc4x.merlot.features");
+ assertServiceAvailable(PlcDriver.class,
"(org.apache.plc4x.driver.code=s7)", 1000);
+ assertServiceAvailable(DBRecordFactory.class, "(db.record.type=s7ai)",
1000);
+ assertServiceAvailable(PlcModel.class,
"(db.record.plcmodel.category=s7)", 1000);
+ assertServiceAvailable(PlcModel.class,
"(db.record.plcmodel.category=s7-light)", 1000);
+ assertServiceAvailable(PlcGeneralFunction.class);
+ }
+
+ /*
+ * Check drivers for this model
+ */
+ @Test
+ public void testS7Services_004() throws Exception {
+ PlcGeneralFunction gf = null;
+ gf = getOsgiService(PlcGeneralFunction.class);
+ assertNotEquals(gf, null);
+ var drivers = gf.getPlcDrivers();
+ assertTrue(drivers.containsKey("simulated"));
+ assertTrue(drivers.containsKey("s7"));
+ assertTrue(drivers.containsKey("s7-light"));
+ }
+
+ /*
+ * Check Memory Areas names.
+ */
+ @Test
+ public void testS7Services_005() throws Exception {
+ PlcGeneralFunction gf = null;
+ gf = getOsgiService(PlcGeneralFunction.class);
+ assertNotEquals(gf, null);
+ PlcModel plcModel = getOsgiService(PlcModel.class,
"(db.record.plcmodel.category=s7)", 1000);
+
assertTrue(plcModel.listMemoryAreas().contains(MemoryArea.COUNTERS.getShortName()));
+
assertTrue(plcModel.listMemoryAreas().contains(MemoryArea.TIMERS.getShortName()));
+
assertTrue(plcModel.listMemoryAreas().contains(MemoryArea.DIRECT_PERIPHERAL_ACCESS.getShortName()));
+
+
assertTrue(plcModel.listMemoryAreas().contains(MemoryArea.INPUTS.getShortName()));
+
assertTrue(plcModel.listMemoryAreas().contains(MemoryArea.OUTPUTS.getShortName()));
+
assertTrue(plcModel.listMemoryAreas().contains(MemoryArea.FLAGS_MARKERS.getShortName()));
+
assertTrue(plcModel.listMemoryAreas().contains(MemoryArea.DATA_BLOCKS.getShortName()));
+
assertTrue(plcModel.listMemoryAreas().contains(MemoryArea.INSTANCE_DATA_BLOCKS.getShortName()));
+
assertTrue(plcModel.listMemoryAreas().contains(MemoryArea.LOCAL_DATA.getShortName()));
+ }
+
+ /*
+ * Check Memory Areas Ids.
+ */
+ @Test
+ public void testS7Services_006() throws Exception {
+ PlcGeneralFunction gf = null;
+ gf = getOsgiService(PlcGeneralFunction.class);
+ assertNotEquals(gf, null);
+ PlcModel plcModel = getOsgiService(PlcModel.class,
"(db.record.plcmodel.category=s7)", 1000);
+ assertEquals(Long.valueOf(plcModel.getMemoryAreaId("C")),
Long.valueOf(0x1C));
+ assertEquals(Long.valueOf(plcModel.getMemoryAreaId("T")),
Long.valueOf(0x1D));
+ assertEquals(Long.valueOf(plcModel.getMemoryAreaId("D")),
Long.valueOf(0x80));
+ assertEquals(Long.valueOf(plcModel.getMemoryAreaId("I")),
Long.valueOf(0x81));
+ assertEquals(Long.valueOf(plcModel.getMemoryAreaId("Q")),
Long.valueOf(0x82));
+ assertEquals(Long.valueOf(plcModel.getMemoryAreaId("M")),
Long.valueOf(0x83));
+ assertEquals(Long.valueOf(plcModel.getMemoryAreaId("DB")),
Long.valueOf(0x84));
+ assertEquals(Long.valueOf(plcModel.getMemoryAreaId("DBI")),
Long.valueOf(0x85));
+ assertEquals(Long.valueOf(plcModel.getMemoryAreaId("LD")),
Long.valueOf(0x86));
+ }
+
+ /*
+ * Check ByteBuf "slice" function from ByteBuf.
+ */
+ @Test
+ public void testS7Services_007() {
+ ByteBuf modelByteBuf = Unpooled.buffer(100);
+
+ modelByteBuf.writeZero(modelByteBuf.capacity());
+
+ PlcItem item01 = new PlcItemImpl.PlcItemBuilder("item1").
+ setItemDescription("Desc").
+ setItemId("").
+ setItemByteBuf(modelByteBuf.slice(80,10)).
+ build();
+
+ PlcItem item02 = new PlcItemImpl.PlcItemBuilder("item2").
+ setItemDescription("Desc").
+ setItemId("").
+ setItemByteBuf(modelByteBuf.slice(80,10)).
+ build();
+
+ PlcItem item03 = new PlcItemImpl.PlcItemBuilder("item3").
+ setItemDescription("Desc").
+ setItemId("").
+ setItemByteBuf(modelByteBuf.slice(0,20)).
+ build();
+
+ modelByteBuf.setByte(80, 255);
+ modelByteBuf.setByte(19, 123);
+
+ assertEquals(modelByteBuf.getByte(80),
item01.getItemByteBuf().getByte(0));
+ assertEquals(modelByteBuf.getByte(80),
item02.getItemByteBuf().getByte(0));
+ assertEquals(modelByteBuf.getByte(19),
item03.getItemByteBuf().getByte(19));
+
+ item01.getItemByteBuf().setFloat(4, (float) 3.1416);
+ item03.getItemByteBuf().setFloat(4, (float) 3.1416);
+
+ assertEquals(Float.valueOf(modelByteBuf.getFloat(84)),
Float.valueOf(item01.getItemByteBuf().getFloat(4)));
+ assertEquals(Float.valueOf(modelByteBuf.getFloat(84)),
Float.valueOf(item02.getItemByteBuf().getFloat(4)));
+ assertEquals(Float.valueOf(modelByteBuf.getFloat(4)),
Float.valueOf(item01.getItemByteBuf().getFloat(4)));
+ }
+
+ /*
+ * Test all db record factorys
+ * .
+ */
+ @Test
+ public void testS7Services_008() throws Exception {
+ PlcModel plcModel = getOsgiService(PlcModel.class,
"(db.record.plcmodel.category=s7)", 1000);
+ assertNotEquals(plcModel, null);
+ DBRecordFactory s7aiFactory = getOsgiService(DBRecordFactory.class,
"(db.record.type=s7ai)", 1000);
+ assertNotEquals(s7aiFactory, null);
+
+ DBRecord dbRecord = s7aiFactory.create("AI001");
+ assertNotEquals(dbRecord, null);
+ PVStructure structure = dbRecord.getPVStructure();
+ PVString pvId = structure.getStringField("id");
+ PVString pvScan = structure.getStringField("scan_time");
+ PVBoolean pvScanEnable = structure.getBooleanField("scan_enable");
+
+ assertNotEquals(pvId, null);
+ assertNotEquals(pvScan, null);
+ assertNotEquals(pvScanEnable, null);
+
+ //PlcItem test
+
+ pvId.put("AG01:%DB100:100:BYTE");
+ plcModel.createMemoryArea(dbRecord);
+
+ pvId.put("AG01:%DB10:2048:BYTE");
+ plcModel.createMemoryArea(dbRecord);
+
+ assertEquals(2L, (long) plcModel.getMemoryAreaSegmentCount("DB"));
+
+ Optional<PlcItem> optMainPlcItem = plcModel.getMemoryAreaPlcItem("DB",
10);
+ assertTrue(optMainPlcItem.isPresent());
+ PlcItem plcMainPlcItem = optMainPlcItem.get();
+
+ ByteBuf byteBuf = plcMainPlcItem.getItemByteBuf();
+ assertEquals(2112L, byteBuf.capacity());
+
+ pvId.put("AG01:%DB10:2936:BYTE");
+ plcModel.createMemoryArea(dbRecord);
+ assertEquals(3000L, byteBuf.capacity());
+
+ optMainPlcItem = plcModel.getMemoryAreaPlcItem("DB", 100);
+ assertTrue(optMainPlcItem.isPresent());
+ plcMainPlcItem = optMainPlcItem.get();
+ byteBuf = plcMainPlcItem.getItemByteBuf();
+ assertEquals(2048L, byteBuf.capacity());
+
+ pvId.put("AG01:%DB100:200:BYTE");
+ plcModel.createMemoryArea(dbRecord);
+ assertEquals(2048L, byteBuf.capacity());
+
+ pvId.put("AG01:%DB100:3064:BYTE");
+ plcModel.createMemoryArea(dbRecord);
+ assertEquals(3128L, byteBuf.capacity());
+
+ Set<Integer> dbs = plcModel.getMemoryAreaSegmentIds("DB");
+
+ assertTrue(dbs.contains(10));
+ assertTrue(dbs.contains(100));
+ assertFalse(dbs.contains(66));
+
+ //Internal ByteBuf test.
+ optMainPlcItem = plcModel.getMemoryAreaPlcItem("DB", 10);
+ byteBuf = plcMainPlcItem.getItemByteBuf();
+
+ DBRecord AI002 = s7aiFactory.create("AI002");
+ assertNotEquals(AI002, null);
+ structure = AI002.getPVStructure();
+ pvId = structure.getStringField("id");
+ pvId.put("AG01:%DB10:640:BYTE");
+ plcModel.createMemoryArea(AI002);
+ AI002.atach(plcMainPlcItem);
+
+ DBRecord AI003 = s7aiFactory.create("AI003");
+ assertNotEquals(AI003, null);
+ structure = AI003.getPVStructure();
+ pvId = structure.getStringField("id");
+ pvId.put("AG01:%DB10:640:BYTE");
+ AI003.atach(plcMainPlcItem);
+
+ byteBuf = plcMainPlcItem.getItemByteBuf();
+ ByteBuf byteBufAI002 = AI002.getInnerBuffer().get();
+ ByteBuf byteBufAI003 = AI003.getInnerBuffer().get();
+
+ byteBuf.setFloat(640, (float) 3.1416);
+ assertEquals(3.1416, (float) byteBuf.getFloat(640), 0.01);
+
+ assertEquals(3.1416, (float) byteBufAI002.getFloat(0), 0.01);
+ assertEquals(3.1416, (float) byteBufAI003.getFloat(0), 0.01);
+
+ //DB100
+
+ optMainPlcItem = plcModel.getMemoryAreaPlcItem("DB", 100);
+ plcMainPlcItem = optMainPlcItem.get();
+
+ DBRecord AI004 = s7aiFactory.create("AI004");
+ assertNotEquals(AI004, null);
+ structure = AI004.getPVStructure();
+ pvId = structure.getStringField("id");
+ pvId.put("AG01:%DB100:0:BYTE");
+ AI004.atach(plcMainPlcItem);
+
+ byteBuf = plcMainPlcItem.getItemByteBuf();
+ ByteBuf byteBufAI004 = AI004.getInnerBuffer().get();
+
+ byteBuf.setFloat(100, (float) 3.1416);
+ assertEquals(3.1416, (float) byteBuf.getFloat(100), 0.01);
+
+ byteBuf.setByte(1, 0x01);
+ byteBuf.setByte(62, 0x1F);
+ byteBuf.setByte(63, 0x2F);
+ byteBuf.writerIndex(byteBuf.capacity());
+
+ assertEquals(0x01, byteBufAI004.getByte(1), 0);
+ assertEquals(0x1F, byteBufAI004.getByte(62), 0);
+ assertEquals(0x2F, byteBufAI004.getByte(63), 0);
+
+ }
+
+ /*
+ * Test slice areas.
+ * .
+ */
+ @Test
+ public void testS7Services_009() throws Exception {
+ PlcGeneralFunction gf = null;
+ gf = getOsgiService(PlcGeneralFunction.class);
+ PlcModel plcModel = getOsgiService(PlcModel.class,
"(db.record.plcmodel.category=s7)", 1000);
+ assertNotEquals(null, plcModel);
+ DBRecordFactory s7aiFactory = getOsgiService(DBRecordFactory.class,
"(db.record.type=s7ai)", 1000);
+ assertNotEquals(null, s7aiFactory);
+
+ DBRecord dbRecord = s7aiFactory.create("AI002");
+ assertNotEquals(null, dbRecord);
+ PVStructure structure = dbRecord.getPVStructure();
+ PVString pvId = structure.getStringField("id");
+ PVString pvScan = structure.getStringField("scan_time");
+ PVBoolean pvScanEnable = structure.getBooleanField("scan_enable");
+
+ assertNotEquals(null, pvId);
+ assertNotEquals(null, pvScan);
+ assertNotEquals(null, pvScanEnable);
+
+ String devUuid = UUID.randomUUID().toString();
+
+ Optional<PlcDevice> optPlcDevice = gf.createDevice(devUuid,
+ "simulated",
+ "AG01",
+ "simulated://127.0.0.1",
+ "+C1=AS01.",
+ "La descripcion",
+ "true");
+ if (optPlcDevice.isPresent()) {
+ System.out.println("Ejecuta ls . " +
optPlcDevice.get().getDeviceName() + " : " +
optPlcDevice.get().getDeviceKey());
+ String cliRes = executeCommand("ls");
+ System.out.println(cliRes);
+ cliRes = executeCommand("bundle:diag 146");
+ System.out.println(cliRes);
+ PlcDevice plcDevice = getOsgiService(PlcDevice.class, 10000);
+ cliRes = executeCommand("ls PlcDevice");
+ System.out.println("> " + cliRes);
+// pvId.put("AG01:%DB20:10:BYTE");
+// pvScan.put("1000");
+// pvScanEnable.put(false);
+// plcModel.createScanGroup(dbRecord);
+//
+// cliRes = executeCommand("ls PlcGroup");
+// System.out.println(cliRes);
+ } else {
+ System.out.println("XXXXXXXXXXXXXXXXXXXXXXX");
+ }
+
+// assertServiceAvailable(PlcDevice.class,
"(org.apache.plc4x.driver.code=s7)", 1000);
+// pvId.put("AG01:%DB10:640:BYTE");
+// pvScanEnable.put(false);
+// pvScan.put("100");
+//
+// plcModel.createScanGroup(dbRecord);
+//
+// PlcGroup plcGroup = getOsgiService(PlcGroup.class);
+// assertNotEquals(null, plcModel);
+
+ }
+
+ /*
+ * Test scan groups.
+ * .
+ */
+ @Test
+ public void testS7Services_010() throws Exception {
+
+ }
+
+ @Test
+ public void testS7Services_012() throws Exception {
+ assumeTrue(S7TestSuite.LIVE_PLC);
+ PlcGeneralFunction gf = null;
+ gf = getOsgiService(PlcGeneralFunction.class);
+ assertNotEquals(gf, null);
+ var drivers = gf.getPlcDrivers();
+ drivers.forEach((k,v) ->{
+ System.out.println(k + " : " + v);
+ });
+
+ UUID devUuid = UUID.randomUUID();
+
+ Optional<PlcDevice> optPlcDevice = gf.createDevice(devUuid.toString(),
+ "s7",
+ "AS01",
+ "s7://10.10.1.191",
+ "+C1=AS01.",
+ "La descripcion",
+ "true");
+ if (optPlcDevice.isPresent()) {
+ System.out.println("Creado el Dispositivo...");
+// assertTrue(optPlcDevice.isPresent());
+ PlcDevice plcDevice = optPlcDevice.get();
+
+ plcDevice.init();
+ plcDevice.enable();
+
+// assumeTrue(plcDevice.getPlcConnection().isConnected());
+
+ UUID grpUuid = UUID.randomUUID();
+
+ Optional<PlcGroup> optPlcGroup =
gf.createGroup(grpUuid.toString(),
+ optPlcDevice.get().getUid().toString(),
+ "GRUPO001",
+ "Descripcion del grupo",
+ "100",
+ "true");
+
+ if (optPlcGroup.isPresent()) {
+ var plcGroups = gf.getPlcGroups();
+// assertTrue(plcGroups.co<ntainsValue("GRUPO001"));
+
+ for (int i= 1; i < 4; i++) {
+ Optional<PlcItem> optPlcItem = gf.
+ createItem(UUID.randomUUID().toString(),
+ optPlcGroup.get().getGroupUid().toString(),
+ optPlcDevice.get().getUid().toString(),
+ "ITEM_" + i,
+ "Item description _" + i,
+ "%DB4:" + i +":DWORD",
+ "true");
+ if (optPlcItem.isPresent()){
+ optPlcItem.get().enable();
+
System.out.println(optPlcItem.get().getItemUid().toString()+ " : " +
optPlcItem.get().getItemName());
+ }
+ }
+ }
+
+ boolean logic = false;
+
+ String cliRes = executeCommand("plc4x:device-list -d " +
devUuid.toString());
+ System.out.println(cliRes);
+
+ cliRes = executeCommand("plc4x:device-list -g " +
grpUuid.toString());
+ System.out.println(cliRes);
+
+ for (int i=0;i<100000000; i++){
+ System.out.print("");
+
+ }
+ try {
+ plcDevice.destroy();
+ plcDevice.disable();
+
+ } catch(Exception ex) {
+ ex.printStackTrace();
+ }
+
+ logic = !plcDevice.isEnable();
+
+ }
+ };
+
+}
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7PlcModelTests.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7PlcModelTests.java
deleted file mode 100644
index 2afd71f..0000000
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7PlcModelTests.java
+++ /dev/null
@@ -1,167 +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.drv.s7.core;
-
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
-import java.util.Set;
-import org.apache.plc4x.java.s7.readwrite.MemoryArea;
-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.apache.plc4x.merlot.db.core.DBBaseFactory;
-import org.apache.plc4x.merlot.drv.s7.impl.S7PlcModelImpl;
-import org.epics.pvdata.pv.PVString;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
-
-
-/**
- *
- * @author cgarcia
- */
-public class S7PlcModelTests {
-
- private static S7PlcModelImpl model;
- private DBRecord AI;
-
- public S7PlcModelTests() {
- }
-
- //@BeforeAll
- public static void setUpClass() {
- model = new S7PlcModelImpl(null, null);
- }
-
- //@AfterAll
- public static void tearDownClass() {
- }
-
- //@BeforeEach
- public void setUp() {
- }
-
- //@AfterEach
- public void tearDown() {
- }
-
- @Test
- public void testAreaModels() {
- Set<String> areas = model.ListMemoryAreas();
- assertTrue(areas.contains(MemoryArea.COUNTERS.getShortName()));
- assertTrue(areas.contains(MemoryArea.TIMERS.getShortName()));
-
assertTrue(areas.contains(MemoryArea.DIRECT_PERIPHERAL_ACCESS.getShortName()));
- assertTrue(areas.contains(MemoryArea.INPUTS.getShortName()));
- assertTrue(areas.contains(MemoryArea.OUTPUTS.getShortName()));
- assertTrue(areas.contains(MemoryArea.FLAGS_MARKERS.getShortName()));
- assertTrue(areas.contains(MemoryArea.DATA_BLOCKS.getShortName()));
-
assertTrue(areas.contains(MemoryArea.INSTANCE_DATA_BLOCKS.getShortName()));
- assertTrue(areas.contains(MemoryArea.LOCAL_DATA.getShortName()));
-
- }
-
- @Test
- public void testAreaModelsId() {
-// assertEquals(model.MemoryAreaId("C"), 0x1C);
-// assertEquals(model.MemoryAreaId("T"), 0x1D);
-// assertEquals(model.MemoryAreaId("D"), 0x80);
-// assertEquals(model.MemoryAreaId("I"), 0x81);
-// assertEquals(model.MemoryAreaId("Q"), 0x82);
-// assertEquals(model.MemoryAreaId("M"), 0x83);
-// assertEquals(model.MemoryAreaId("DB"), 0x84);
-// assertEquals(model.MemoryAreaId("DBI"), 0x85);
-// assertEquals(model.MemoryAreaId("LD"), 0x86);
- }
-
- @Test
- public void testCreateMemoryAreas() {
- DBBaseFactory AIFactory = new S7DBAiFactory();
- AI = AIFactory.create("AI");
- PVString pvId =
AI.getPVRecordStructure().getPVStructure().getStringField("id");
- PVString pvSCanTime =
AI.getPVRecordStructure().getPVStructure().getStringField("scan_time");
-
- pvId.put("DEVICE:%I2500:BYTE[100]");
- model.CreateMemoryArea(AI);
-
- pvId.put("DEVICE:%Q1900:BYTE[100]");
- model.CreateMemoryArea(AI);
-
- pvId.put("DEVICE:%M3000:BYTE[100]");
- model.CreateMemoryArea(AI);
-
- pvId.put("DEVICE:%DB100:10:BYTE[100]");
- model.CreateMemoryArea(AI);
-
- }
-
- @Test
- public void testPlcItemBufferWrapper() {
- ByteBuf modelByteBuf = Unpooled.buffer(100);
-
- modelByteBuf.writeZero(modelByteBuf.capacity());
-
- PlcItem item01 = new PlcItemImpl.PlcItemBuilder("item1").
- setItemDescription("Desc").
- setItemId("").
- setItemByteBuf(modelByteBuf.slice(80,10)).
- build();
-
- PlcItem item02 = new PlcItemImpl.PlcItemBuilder("item2").
- setItemDescription("Desc").
- setItemId("").
- setItemByteBuf(modelByteBuf.slice(80,10)).
- build();
-
- PlcItem item03 = new PlcItemImpl.PlcItemBuilder("item3").
- setItemDescription("Desc").
- setItemId("").
- setItemByteBuf(modelByteBuf.slice(0,20)).
- build();
-
- modelByteBuf.setByte(80, 255);
- modelByteBuf.setByte(19, 123);
-
- assertEquals(modelByteBuf.getByte(80),
item01.getItemByteBuf().getByte(0));
- assertEquals(modelByteBuf.getByte(80),
item02.getItemByteBuf().getByte(0));
- assertEquals(modelByteBuf.getByte(19),
item03.getItemByteBuf().getByte(19));
-
- item01.getItemByteBuf().setFloat(4, (float) 3.1416);
- item03.getItemByteBuf().setFloat(4, (float) 3.1416);
-
- assertEquals(Float.valueOf(modelByteBuf.getFloat(84)),
Float.valueOf(item01.getItemByteBuf().getFloat(4)));
- assertEquals(Float.valueOf(modelByteBuf.getFloat(84)),
Float.valueOf(item02.getItemByteBuf().getFloat(4)));
- assertEquals(Float.valueOf(modelByteBuf.getFloat(4)),
Float.valueOf(item01.getItemByteBuf().getFloat(4)));
-
-
- }
-
- @Test
- public void testDBRecord() {
-
- DBBaseFactory factory = new S7DBAiFactory();
- DBRecord dbRecord = factory.create("record01");
-
- PVString pvId =
dbRecord.getPVRecordStructure().getPVStructure().getStringField("id");
- PVString pvScanTime =
dbRecord.getPVRecordStructure().getPVStructure().getStringField("scan_time");
-
- pvId.put("XX");
- pvScanTime.put("SCANTime");
- }
-
-
-}
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7TestSuite.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7TestSuite.java
new file mode 100644
index 0000000..ce1884e
--- /dev/null
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/S7TestSuite.java
@@ -0,0 +1,58 @@
+/*
+ * 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.s7.core;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+/**
+ *
+ * @author cgarcia
+ */
+@RunWith(Suite.class)
[email protected]({
+ org.apache.plc4x.merlot.drv.s7.core.S7PlcModelTest.class})
+public class S7TestSuite {
+
+ /*
+ * Set this to "true" if you have a PLC online.
+ * You should verify the IP addresses in the test packets.
+ */
+ public static boolean LIVE_PLC = false;
+
+ @BeforeClass
+ public static void setUpClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+}
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/TestBase.java
b/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/TestBase.java
deleted file mode 100644
index 2bf1761..0000000
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.drv.s7/src/test/java/org/apache/plc4x/merlot/drv/s7/core/TestBase.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * Copyright 2015 Achim Nierbeck
- *
- * Licensed 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.s7.core;
-
-import static org.ops4j.pax.exam.CoreOptions.maven;
-import static org.ops4j.pax.exam.MavenUtils.asInProject;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.FutureTask;
-import java.util.concurrent.TimeUnit;
-
-import javax.inject.Inject;
-
-import org.apache.karaf.features.BootFinished;
-import org.apache.karaf.features.FeaturesService;
-import org.apache.karaf.shell.api.console.Session;
-import org.apache.karaf.shell.api.console.SessionFactory;
-import static org.apache.karaf.util.Version.karafVersion;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.ops4j.pax.exam.Configuration;
-import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
-import org.ops4j.pax.exam.Option;
-import static
org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
-import static
org.ops4j.pax.exam.karaf.options.KarafDistributionOption.features;
-import static
org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration;
-import static
org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder;
-import org.ops4j.pax.exam.options.MavenArtifactUrlReference;
-import org.ops4j.pax.exam.options.MavenUrlReference;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.Filter;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.util.tracker.ServiceTracker;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-public class TestBase {
-
- protected final Logger logger = LoggerFactory.getLogger(getClass());
-
- @Inject
- protected BundleContext bc;
-
- @Inject
- protected FeaturesService featuresService;
-
- /**
- * To make sure the tests run only when the boot features are fully
- * installed
- */
- @Inject
- protected BootFinished bootFinished;
-
- @Inject
- protected SessionFactory sessionFactory;
-
-
- private ExecutorService executor = Executors.newCachedThreadPool();
-
- private ByteArrayOutputStream byteArrayOutputStream = new
ByteArrayOutputStream();
- private PrintStream printStream = new PrintStream(byteArrayOutputStream);
- private PrintStream errStream = new PrintStream(byteArrayOutputStream);
- Session session;
-
- @Configuration
- public Option[] config() {
- MavenArtifactUrlReference karafUrl = maven()
- .groupId("org.apache.karaf")
- .artifactId("apache-karaf")
- .version(karafVersion())
- .type("zip");
- MavenUrlReference karafStandardRepo = maven()
- .groupId("org.apache.karaf.features")
- .artifactId("standard")
- .version(karafVersion())
- .classifier("features")
- .type("xml");
- return new Option[] {
- // KarafDistributionOption.debugConfiguration("5005", true),
- karafDistributionConfiguration()
- .frameworkUrl(karafUrl)
- .unpackDirectory(new File("target", "exam"))
- .useDeployFolder(false),
- keepRuntimeFolder(),
- configureConsole().ignoreLocalConsole(),
- features(karafStandardRepo , "scr"),
-
- };
- }
-
- private MavenArtifactUrlReference mvnKarafDist() {
- return
maven().groupId("org.apache.karaf").artifactId("apache-karaf").type("tar.gz").version(asInProject());
- }
-
- private MavenUrlReference karafStandardFeature() {
- return
maven().groupId("org.apache.karaf.features").artifactId("standard").type("xml").classifier("features")
- .version(asInProject());
- }
-
- @Before
- public void setUpITestBase() throws Exception {
- int count = 0;
- logger.info("Waited for Cassandra service to appear: " +
Integer.toString(count * 500));
- session = sessionFactory.create(System.in, printStream, errStream);
- }
-
- @After
- public void cleanupTest() throws Exception {
-
- session = null;
- }
-
- @AfterClass
- public static void tearDown() throws Exception {
- System.out.println("Removing data directory");
- File dataDir = new File("data");
- dataDir.delete();
- }
-
- protected String executeCommand(final String command) throws IOException {
- byteArrayOutputStream.flush();
- byteArrayOutputStream.reset();
-
- String response;
- FutureTask<String> commandFuture = new FutureTask<String>(new
Callable<String>() {
- public String call() {
- try {
- System.err.println(command);
- session.execute(command);
- } catch (Exception e) {
- e.printStackTrace(System.err);
- }
- printStream.flush();
- errStream.flush();
- return byteArrayOutputStream.toString();
- }
- });
-
- try {
- executor.submit(commandFuture);
- response = commandFuture.get(10000L, TimeUnit.MILLISECONDS);
- } catch (Exception e) {
- e.printStackTrace(System.err);
- response = "SHELL COMMAND TIMED OUT: ";
- }
-
- System.err.println(response);
-
- return response;
- }
-
- @SuppressWarnings({ "rawtypes", "unchecked" })
- protected <T> T getOsgiService(Class<T> type, String filter, long timeout)
{
- ServiceTracker tracker = null;
- try {
- String flt;
- if (filter != null) {
- if (filter.startsWith("(")) {
- flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName()
+ ")" + filter + ")";
- } else {
- flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName()
+ ")(" + filter + "))";
- }
- } else {
- flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")";
- }
- Filter osgiFilter = FrameworkUtil.createFilter(flt);
- tracker = new ServiceTracker(bc, osgiFilter, null);
- tracker.open(true);
- // Note that the tracker is not closed to keep the reference
- // This is buggy, as the service reference may change i think
- Object svc = type.cast(tracker.waitForService(timeout));
- if (svc == null) {
- Dictionary dic = bc.getBundle().getHeaders();
- System.err.println("Test bundle headers: " + explode(dic));
-
- for (ServiceReference ref :
asCollection(bc.getAllServiceReferences(null, null))) {
- System.err.println("ServiceReference: " + ref);
- }
-
- for (ServiceReference ref :
asCollection(bc.getAllServiceReferences(null, flt))) {
- System.err.println("Filtered ServiceReference: " + ref);
- }
-
- logger.error("Gave up waiting for service " + flt);
- return null;
- }
- return type.cast(svc);
- } catch (InvalidSyntaxException e) {
- throw new IllegalArgumentException("Invalid filter", e);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
-
- /*
- * Explode the dictionary into a ,-delimited list of key=value pairs
- */
- @SuppressWarnings("rawtypes")
- private static String explode(Dictionary dictionary) {
- Enumeration keys = dictionary.keys();
- StringBuffer result = new StringBuffer();
- while (keys.hasMoreElements()) {
- Object key = keys.nextElement();
- result.append(String.format("%s=%s", key, dictionary.get(key)));
- if (keys.hasMoreElements()) {
- result.append(", ");
- }
- }
- return result.toString();
- }
-
- /**
- * Provides an iterable collection of references, even if the original
array
- * is null
- */
- @SuppressWarnings("rawtypes")
- private static Collection<ServiceReference>
asCollection(ServiceReference[] references) {
- return references != null ? Arrays.asList(references) :
Collections.<ServiceReference> emptyList();
- }
-
-}
\ No newline at end of file
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 f8d5f4f..ad9369f 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
@@ -16,7 +16,6 @@
*/
package org.apache.plc4x.merlot.drv.simulated.impl;
-import com.fasterxml.jackson.databind.PropertyMetadata;
import io.netty.buffer.ByteBuf;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.plc4x.java.api.model.PlcTag;
diff --git
a/plc4j/tools/merlot/org.apache.plc4x.merlot.features/src/main/feature/feature.xml
b/plc4j/tools/merlot/org.apache.plc4x.merlot.features/src/main/feature/feature.xml
index aa67b6b..480a8cd 100644
---
a/plc4j/tools/merlot/org.apache.plc4x.merlot.features/src/main/feature/feature.xml
+++
b/plc4j/tools/merlot/org.apache.plc4x.merlot.features/src/main/feature/feature.xml
@@ -60,7 +60,7 @@
<bundle
start-level="30">wrap:mvn:com.github.jinahya/bit-io/${bit-io.version}/$Export-Package=*;version="${bit-io.version}",!*</bundle>
<bundle
start-level="30">wrap:mvn:io.vavr/vavr/${vavr.version}/$Export-Package=*;version="${vavr.version}",!*</bundle>
<bundle
start-level="30">wrap:mvn:io.vavr/vavr-match/${vavr.version}/$Export-Package=*;version="${vavr.version}",!*</bundle>
- <bundle
start-level="30">wrap:mvn:org.json/json/20250107/$Export-Package=*;version="20250107",!*</bundle>
+ <bundle
start-level="30">wrap:mvn:org.json/json/20250517/$Export-Package=*;version="20250517",!*</bundle>
<bundle
start-level="30">wrap:mvn:com.fasterxml.jackson.core/jackson-core/${jackson.version}/$Export-Package=*;version="${jackson.version}",!*</bundle>
<bundle
start-level="30">wrap:mvn:com.fasterxml.jackson.core/jackson-databind/${jackson.version}/$Export-Package=*;version="${jackson.version}",!*</bundle>
<bundle
start-level="30">wrap:mvn:com.fasterxml.jackson.core/jackson-annotations/${jackson.version}/$Export-Package=*;version="${jackson.version}",!*</bundle>
diff --git a/plc4j/tools/merlot/pom.xml b/plc4j/tools/merlot/pom.xml
index 23d67c6..5b60938 100644
--- a/plc4j/tools/merlot/pom.xml
+++ b/plc4j/tools/merlot/pom.xml
@@ -98,7 +98,7 @@ under the License.
<spifly.version>1.3.6</spifly.version>
- <jackson.version>2.18.0</jackson.version>
+ <jackson.version>2.19.0</jackson.version>
<jakarta.xml.bind.version>2.3.3</jakarta.xml.bind.version>
@@ -113,7 +113,7 @@ under the License.
<asm.version>9.6</asm.version>
<artemis.version>2.38.0</artemis.version>
-
+ <awaitility.version>3.1.6</awaitility.version>
<decanter.version>2.10.0</decanter.version>
<hawtbuf.version>1.11</hawtbuf.version>
<hawtdispatch.version>1.22</hawtdispatch.version>
@@ -150,7 +150,7 @@ under the License.
<org.osgi.dal.version>1.0.2</org.osgi.dal.version>
<disruptor.version>4.0.0</disruptor.version>
-
+ <maven-failsafe-plugin.version>3.5.3</maven-failsafe-plugin.version>
<!-- EPICS -->