2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.plclogo.internal.config;
15 import static org.openhab.binding.plclogo.internal.PLCLogoBindingConstants.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
20 * The {@link PLCMemoryConfiguration} is a class for configuration
21 * of Siemens LOGO! PLC memory input/outputs blocks.
23 * @author Alexander Falkenstern - Initial contribution
26 public class PLCMemoryConfiguration extends PLCCommonConfiguration {
28 private String block = "";
29 private Integer threshold = 0;
32 * Get configured Siemens LOGO! memory block name.
34 * @return Configured Siemens LOGO! memory block name
36 public String getBlockName() {
41 * Set Siemens LOGO! memory block name.
43 * @param name Siemens LOGO! memory block name
45 public void setBlockName(final String name) {
46 this.block = name.trim();
50 * Get Siemens LOGO! blocks update threshold.
52 * @return Configured Siemens LOGO! update threshold
54 public Integer getThreshold() {
59 * Set Siemens LOGO! blocks update threshold.
63 public void setThreshold(final Integer threshold) {
64 this.threshold = threshold;
68 public String getChannelType() {
69 final String kind = getBlockKind();
70 return kind.equalsIgnoreCase(MEMORY_BYTE) && block.contains(".") ? DIGITAL_OUTPUT_ITEM : ANALOG_ITEM;
74 public String getBlockKind() {
75 return getBlockKind(block);
78 protected static String getBlockKind(final String name) {
79 String kind = "Unknown";
80 if (Character.isDigit(name.charAt(1))) {
81 kind = name.substring(0, 1);
82 } else if (Character.isDigit(name.charAt(2))) {
83 kind = name.substring(0, 2);
84 } else if (Character.isDigit(name.charAt(3))) {
85 kind = name.substring(0, 3);