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
commit 09c5dc7792e0dab81c0fe154ed61ffd113dfc8bb Author: Ben Hutcheson <[email protected]> AuthorDate: Thu Mar 23 05:31:16 2023 +0100 fix(plc4j/profinet): Format of Allowed in slots string can be a single digit. --- .../profinet/context/ProfinetDeviceContext.java | 9 +++--- .../profinet/gsdml/ProfinetConfigurationTests.java | 19 +++++++++++++ .../drivers/profinet/src/test/resources/gsdml.xml | 32 ++++++++++++++++++++++ 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/context/ProfinetDeviceContext.java b/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/context/ProfinetDeviceContext.java index 128f89fa98..345fe04366 100644 --- a/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/context/ProfinetDeviceContext.java +++ b/plc4j/drivers/profinet/src/main/java/org/apache/plc4x/java/profinet/context/ProfinetDeviceContext.java @@ -48,7 +48,7 @@ public class ProfinetDeviceContext implements DriverContext, HasConfiguration<Pr public static final short BLOCK_VERSION_HIGH = 1; public static final short BLOCK_VERSION_LOW = 0; public static final MacAddress DEFAULT_EMPTY_MAC_ADDRESS; - public static final Pattern RANGE_PATTERN = Pattern.compile("(?<from>\\d+)\\.\\.(?<to>\\d+)"); + public static final Pattern RANGE_PATTERN = Pattern.compile("(?<from>\\d+)(\\.\\.(?<to>\\d+))*"); static { try { @@ -369,7 +369,8 @@ public class ProfinetDeviceContext implements DriverContext, HasConfiguration<Pr if (!matcher.group("from").equals("0")) { throw new PlcConnectionException("Physical Slots don't start from 0, instead starts at " + deviceAccessItem.getPhysicalSlots()); } - int numberOfSlots = Integer.parseInt(matcher.group("to")); + int numberOfSlots = matcher.group("to") != null ? Integer.parseInt(matcher.group("to")) : 0; + this.modules = new ProfinetModule[numberOfSlots]; this.modules[deviceAccessItem.getFixedInSlots()] = new ProfinetModuleImpl(deviceAccessItem, 0, 0, deviceAccessItem.getFixedInSlots()); @@ -387,8 +388,8 @@ public class ProfinetDeviceContext implements DriverContext, HasConfiguration<Pr if (!matcher.matches()) { throw new PlcConnectionException("Physical Slots Range is not in the correct format " + useableModule.getAllowedInSlots()); } - int from = Integer.parseInt(matcher.group("from")); - int to = Integer.parseInt(matcher.group("to")); + int from = matcher.group("to") != null ? Integer.parseInt(matcher.group("from")) : 0; + int to = matcher.group("to") != null ? Integer.parseInt(matcher.group("to")) : Integer.parseInt(matcher.group("from")); if (currentSlot < from || currentSlot > to) { throw new PlcConnectionException("Current Submodule Slot " + currentSlot + " is not with the allowable slots" + useableModule.getAllowedInSlots()); } 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 43cf000755..3b7199ae31 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 @@ -189,4 +189,23 @@ public class ProfinetConfigurationTests { assertEquals(devices.get(deviceName).getDeviceContext().getSubModules()[0], "PLC4X DUMMY MODULE"); } } + + @Test + public void parseAllowedModuleSingleSlot() { + 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,,1)]]&gsddirectory=src/test/resources"); + + Map<String, ProfinetDevice> devices = configuration.getDevices().getConfiguredDevices(); + XmlMapper xmlMapper = new XmlMapper(); + + assertDoesNotThrow(() -> devices.get("DEVICE NAME 1").getDeviceContext().setGsdFile(xmlMapper.readValue(new File("src/test/resources/gsdml.xml"), ProfinetISO15745Profile.class))); + + for (String deviceName : deviceNames) { + assert(devices.containsKey(deviceName)); + assertEquals(devices.get(deviceName).getDeviceContext().getSubModules().length, 4); + assertEquals(devices.get(deviceName).getDeviceContext().getSubModules()[3], "1"); + } + } } diff --git a/plc4j/drivers/profinet/src/test/resources/gsdml.xml b/plc4j/drivers/profinet/src/test/resources/gsdml.xml index 9354695ad2..7631f229cf 100644 --- a/plc4j/drivers/profinet/src/test/resources/gsdml.xml +++ b/plc4j/drivers/profinet/src/test/resources/gsdml.xml @@ -96,6 +96,7 @@ <UseableModules> <ModuleItemRef ModuleItemTarget="PLC4X_DUMMY_MODULE" AllowedInSlots="1..4"/> <ModuleItemRef ModuleItemTarget="PLC4X DUMMY MODULE" AllowedInSlots="1..4"/> + <ModuleItemRef ModuleItemTarget="1" AllowedInSlots="4"/> </UseableModules> <VirtualSubmoduleList> <VirtualSubmoduleItem ID="PLC4X_1_V0" SubmoduleIdentNumber="0x00000001" Writeable_IM_Records="1 2 3" MayIssueProcessAlarm="false"> @@ -188,6 +189,37 @@ </VirtualSubmoduleItem> </VirtualSubmoduleList> </ModuleItem> + <ModuleItem ID="1" ModuleIdentNumber="0x00000005"> + <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">
