This is an automated email from the ASF dual-hosted git repository.
hutcheb pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new 261cb2e531 fix(plc4j/profinet): Allow space chars in device, device
access and submodule names
261cb2e531 is described below
commit 261cb2e531f06025b08e07b79268027f8661d134
Author: Ben Hutcheson <[email protected]>
AuthorDate: Sun Mar 19 05:57:45 2023 +0100
fix(plc4j/profinet): Allow space chars in device, device access and
submodule names
---
.../profinet/config/ProfinetConfiguration.java | 10 +--
.../profinet/gsdml/ProfinetConfigurationTests.java | 45 +++++++++++++
.../drivers/profinet/src/test/resources/gsdml.xml | 73 ++++++++++++++++++++++
3 files changed, 124 insertions(+), 4 deletions(-)
diff --git
a/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/config/ProfinetConfiguration.java
b/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/config/ProfinetConfiguration.java
index 8cab2f01e0..8657c8c16a 100644
---
a/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/config/ProfinetConfiguration.java
+++
b/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/config/ProfinetConfiguration.java
@@ -92,8 +92,10 @@ public class ProfinetConfiguration implements Configuration,
RawSocketTransportC
public static class ProfinetDeviceConvertor implements
ConfigurationParameterConverter<ProfinetDevices> {
- public static final Pattern DEVICE_NAME_ARRAY_PATTERN =
Pattern.compile("^\\[(?:(\\[(?:[\\w-]*){1},(?:[\\w]*){1},\\((?:[\\w]*[,
]?)*\\){1}\\])[, ]?)+\\]");
- public static final Pattern DEVICE_PARAMETERS =
Pattern.compile("^(?<devicename>[\\w-]*){1}[, ]+(?<deviceaccess>[\\w]*){1}[,
]+\\((?<submodules>[\\w, ]*)\\)");
+ public static final String DEVICE_STRING = "((?<devicename>[\\w-
]*){1}[, ]+(?<deviceaccess>[\\w ]*){1}[, ]+\\((?<submodules>[\\w, ]*)\\))";
+ public static final String DEVICE_ARRAY_STRING = "^\\[(?:(\\[" +
DEVICE_STRING + "{1}\\])[, ]?)+\\]";
+ public static final Pattern DEVICE_NAME_ARRAY_PATTERN =
Pattern.compile(DEVICE_ARRAY_STRING);
+ public static final Pattern DEVICE_PARAMETERS =
Pattern.compile(DEVICE_STRING);
@Override
public Class<ProfinetDevices> getType() {
@@ -104,7 +106,7 @@ public class ProfinetConfiguration implements
Configuration, RawSocketTransportC
public ProfinetDevices convert(String value) {
// Split up the connection string into its individual segments.
- value = value.replaceAll(" ", "").toUpperCase();
+ value = value.toUpperCase();
Matcher matcher = DEVICE_NAME_ARRAY_PATTERN.matcher(value);
if (!matcher.matches()) {
@@ -112,7 +114,7 @@ public class ProfinetConfiguration implements
Configuration, RawSocketTransportC
}
Map<String, ProfinetDevice> devices = new HashMap<>();
- String[] deviceParameters = value.substring(1, value.length() -
1).replaceAll(" ", "").split("[\\[\\]]");
+ String[] deviceParameters = value.substring(1, value.length() -
1).split("[\\[\\]]");
for (String deviceParameter : deviceParameters) {
if (deviceParameter.length() > 7) {
matcher = DEVICE_PARAMETERS.matcher(deviceParameter);
diff --git
a/plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/gsdml/ProfinetConfigurationTests.java
b/plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/gsdml/ProfinetConfigurationTests.java
index e88d060450..43cf000755 100644
---
a/plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/gsdml/ProfinetConfigurationTests.java
+++
b/plc4j/drivers/profinet/src/test/java/org/apache/plc4x/java/profinet/gsdml/ProfinetConfigurationTests.java
@@ -144,4 +144,49 @@ public class ProfinetConfigurationTests {
XmlMapper xmlMapper = new XmlMapper();
assertDoesNotThrow(() ->
devices.get("DEVICE_NAME_1").getDeviceContext().setGsdFile(xmlMapper.readValue(new
File("src/test/resources/gsdml.xml"), ProfinetISO15745Profile.class)));
}
+
+ @Test
+ public void parseJoinedDeviceConfigurationSpacesInDeviceAccessName() {
+ String[] deviceNames = new String[] {"DEVICE_NAME_1"};
+
+ ProfinetConfiguration configuration = new
ConfigurationFactory().createConfiguration(
+ ProfinetConfiguration.class, "devices=[[device_name_1, PLC4X 1,
(PLC4X_DUMMY_MODULE, PLC4X_DUMMY_MODULE)]]&gsddirectory=src/test/resources");
+
+ Map<String, ProfinetDevice> devices =
configuration.getDevices().getConfiguredDevices();
+
+ for (String deviceName : deviceNames) {
+ assert(devices.containsKey(deviceName));
+
assertEquals(devices.get(deviceName).getDeviceContext().getDeviceAccess(),
"PLC4X 1");
+ }
+ }
+
+ @Test
+ public void parseJoinedDeviceConfigurationSpacesInDeviceName() {
+ String[] deviceNames = new String[] {"DEVICE NAME 1"};
+
+ ProfinetConfiguration configuration = new
ConfigurationFactory().createConfiguration(
+ ProfinetConfiguration.class, "devices=[[device name 1, PLC4X 1,
(PLC4X_DUMMY_MODULE, PLC4X_DUMMY_MODULE)]]&gsddirectory=src/test/resources");
+
+ Map<String, ProfinetDevice> devices =
configuration.getDevices().getConfiguredDevices();
+
+ for (String deviceName : deviceNames) {
+ assert(devices.containsKey(deviceName));
+ }
+ }
+
+ @Test
+ public void parseJoinedDeviceConfigurationSpacesInDeviceModuleName() {
+ String[] deviceNames = new String[] {"DEVICE NAME 1"};
+
+ ProfinetConfiguration configuration = new
ConfigurationFactory().createConfiguration(
+ ProfinetConfiguration.class, "devices=[[device name 1, PLC4X 1,
(PLC4X DUMMY MODULE, PLC4X DUMMY MODULE)]]&gsddirectory=src/test/resources");
+
+ Map<String, ProfinetDevice> devices =
configuration.getDevices().getConfiguredDevices();
+
+ for (String deviceName : deviceNames) {
+ assert(devices.containsKey(deviceName));
+
assertEquals(devices.get(deviceName).getDeviceContext().getSubModules().length,
2);
+
assertEquals(devices.get(deviceName).getDeviceContext().getSubModules()[0],
"PLC4X DUMMY MODULE");
+ }
+ }
}
diff --git a/plc4j/drivers/profinet/src/test/resources/gsdml.xml
b/plc4j/drivers/profinet/src/test/resources/gsdml.xml
index d67fcf5da9..9354695ad2 100644
--- a/plc4j/drivers/profinet/src/test/resources/gsdml.xml
+++ b/plc4j/drivers/profinet/src/test/resources/gsdml.xml
@@ -82,6 +82,48 @@
<GraphicItemRef Type="DeviceSymbol"
GraphicItemTarget="PLC4X-Icon"/>
</Graphics>
</DeviceAccessPointItem>
+ <DeviceAccessPointItem ID="PLC4X 1" PNIO_Version="V2.4"
PhysicalSlots="0..32" ModuleIdentNumber="0x00000001" MinDeviceInterval="32"
DNS_CompatibleName="plc4x" FixedInSlots="0" ObjectUUID_LocalIndex="1"
DeviceAccessSupported="false" MultipleWriteSupported="true"
CheckDeviceID_Allowed="true" NameOfStationNotTransferable="false"
LLDP_NoD_Supported="true" ResetToFactoryModes="1..2">
+ <ModuleInfo>
+ <Name TextId="PLC4X_Module"/>
+ <InfoText TextId="PLC4X_Info"/>
+ <VendorName Value="PLC4X"/>
+ <OrderNumber Value="000000"/>
+ <HardwareRelease Value="0.11"/>
+ <SoftwareRelease Value="0.11"/>
+ </ModuleInfo>
+ <CertificationInfo ConformanceClass="B" ApplicationClass=""
NetloadClass="I"/>
+ <IOConfigData MaxInputLength="40" MaxOutputLength="40"/>
+ <UseableModules>
+ <ModuleItemRef ModuleItemTarget="PLC4X_DUMMY_MODULE"
AllowedInSlots="1..4"/>
+ <ModuleItemRef ModuleItemTarget="PLC4X DUMMY MODULE"
AllowedInSlots="1..4"/>
+ </UseableModules>
+ <VirtualSubmoduleList>
+ <VirtualSubmoduleItem ID="PLC4X_1_V0"
SubmoduleIdentNumber="0x00000001" Writeable_IM_Records="1 2 3"
MayIssueProcessAlarm="false">
+ <IOData/>
+ <ModuleInfo>
+ <Name TextId="Virtual_PLC4X_Module"/>
+ <InfoText TextId="Virtual_PLC4X_Info"/>
+ </ModuleInfo>
+ </VirtualSubmoduleItem>
+ </VirtualSubmoduleList>
+ <SystemDefinedSubmoduleList>
+ <InterfaceSubmoduleItem ID="PLC4X_1_S0"
SubmoduleIdentNumber="0x00000001" SubslotNumber="32768"
TextId="PLC4X_Module_System_0" SupportedRT_Classes="RT_CLASS_1"
SupportedProtocols="SNMP;LLDP" NetworkComponentDiagnosisSupported="false"
PTP_BoundarySupported="true" DCP_BoundarySupported="true">
+ <ApplicationRelations StartupMode="Advanced">
+ <TimingProperties SendClock="32" ReductionRatio="1 2 4 8 16
32 64 128 256 512"/>
+ </ApplicationRelations>
+ </InterfaceSubmoduleItem>
+ <PortSubmoduleItem ID="PLC4X_1_S1"
SubmoduleIdentNumber="0x00000002" SubslotNumber="32769"
TextId="PLC4X_Module_System_1" MaxPortRxDelay="100" MaxPortTxDelay="30">
+ <MAUTypeList>
+ <MAUTypeItem Value="1"/>
+ <MAUTypeItem Value="2"/>
+ <MAUTypeItem Value="3"/>
+ </MAUTypeList>
+ </PortSubmoduleItem>
+ </SystemDefinedSubmoduleList>
+ <Graphics>
+ <GraphicItemRef Type="DeviceSymbol"
GraphicItemTarget="PLC4X-Icon"/>
+ </Graphics>
+ </DeviceAccessPointItem>
</DeviceAccessPointList>
<ModuleList>
<ModuleItem ID="PLC4X_DUMMY_MODULE" ModuleIdentNumber="0x00000003">
@@ -115,6 +157,37 @@
</VirtualSubmoduleItem>
</VirtualSubmoduleList>
</ModuleItem>
+ <ModuleItem ID="PLC4X DUMMY MODULE" ModuleIdentNumber="0x00000004">
+ <ModuleInfo>
+ <Name TextId="PLC4X_INPUT_MODULE_NAME"/>
+ <InfoText TextId="PLC4X_INPUT_MODULE_INFO"/>
+ <HardwareRelease Value="0.11"/>
+ <SoftwareRelease Value="0.11"/>
+ </ModuleInfo>
+ <VirtualSubmoduleList>
+ <VirtualSubmoduleItem ID="PLC4X_DUMMY_MODULE_V0"
SubmoduleIdentNumber="0x0002" MayIssueProcessAlarm="true">
+ <IOData>
+ <Input Consistency="None">
+ <DataItem DataType="Unsigned8"
TextId="PLC4X_INPUT_MODULE_INFO_32" UseAsBits="true">
+ <BitDataItem BitOffset="0"
TextId="PLC4X_INPUT_MODULE_INFO_32"/>
+ <BitDataItem BitOffset="1"
TextId="PLC4X_INPUT_MODULE_INFO_32"/>
+ <BitDataItem BitOffset="2"
TextId="PLC4X_INPUT_MODULE_INFO_32"/>
+ <BitDataItem BitOffset="3"
TextId="PLC4X_INPUT_MODULE_INFO_32"/>
+ <BitDataItem BitOffset="4"
TextId="PLC4X_INPUT_MODULE_INFO_32"/>
+ <BitDataItem BitOffset="5"
TextId="PLC4X_INPUT_MODULE_INFO_32"/>
+ <BitDataItem BitOffset="6"
TextId="PLC4X_INPUT_MODULE_INFO_32"/>
+ <BitDataItem BitOffset="7"
TextId="PLC4X_INPUT_MODULE_INFO_32"/>
+ </DataItem>
+ <DataItem DataType="Float32"
TextId="PLC4X_INPUT_MODULE_INFO_FLOAT"/>
+ </Input>
+ </IOData>
+ <ModuleInfo>
+ <Name TextId="PLC4X_VIRTUAL_INPUT_MODULE_NAME"/>
+ <InfoText TextId="PLC4X_VIRTUAL_INPUT_MODULE_INFO"/>
+ </ModuleInfo>
+ </VirtualSubmoduleItem>
+ </VirtualSubmoduleList>
+ </ModuleItem>
</ModuleList>
<LogBookEntryList>
<LogBookEntryItem Status="1">