From f65ee6c3a8e7a690960db4c789c5e0a8147da36d Mon Sep 17 00:00:00 2001 From: Holger Friedrich Date: Sat, 9 Apr 2022 18:17:52 +0200 Subject: [PATCH] [knx] Add option to use CEMI frame format for serial devices. (#12593) CEMI frame format is used by newer serial devices like kBerry. Calimero library can be configured to use CEMI instead of default EMI. Followup on #10407. Relates to #4026. Signed-off-by: Holger Friedrich --- bundles/org.openhab.binding.knx/README.md | 1 + .../binding/knx/internal/KNXBindingConstants.java | 1 + .../binding/knx/internal/client/SerialClient.java | 12 ++++++++++-- .../internal/config/SerialBridgeConfiguration.java | 5 +++++ .../internal/handler/SerialBridgeThingHandler.java | 3 ++- .../src/main/resources/OH-INF/i18n/knx.properties | 2 ++ .../src/main/resources/OH-INF/thing/serial.xml | 7 +++++++ 7 files changed, 28 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.knx/README.md b/bundles/org.openhab.binding.knx/README.md index 87c5b38e5..078b7f8c3 100644 --- a/bundles/org.openhab.binding.knx/README.md +++ b/bundles/org.openhab.binding.knx/README.md @@ -52,6 +52,7 @@ The *serial* bridge accepts the following configuration parameters: | responseTimeout | N | Timeout in seconds to wait for a response from the KNX bus | 10 | | readRetriesLimit | N | Limits the read retries while initialization from the KNX bus | 3 | | autoReconnectPeriod | N | Seconds between connect retries when KNX link has been lost, 0 means never retry | 0 | +| useCemi | N | Use newer CEMI message format, useful for newer devices like KNX RF sticks, kBerry, etc. | false | ## Things diff --git a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/KNXBindingConstants.java b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/KNXBindingConstants.java index 1896c04a2..00dfb907f 100644 --- a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/KNXBindingConstants.java +++ b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/KNXBindingConstants.java @@ -53,6 +53,7 @@ public class KNXBindingConstants { public static final String LOCAL_SOURCE_ADDRESS = "localSourceAddr"; public static final String PORT_NUMBER = "portNumber"; public static final String SERIAL_PORT = "serialPort"; + public static final String USE_CEMI = "useCemi"; // The default multicast ip address (see iana EIBnet/IP diff --git a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/client/SerialClient.java b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/client/SerialClient.java index 3f6113837..2a49d5d2d 100644 --- a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/client/SerialClient.java +++ b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/client/SerialClient.java @@ -39,20 +39,28 @@ public class SerialClient extends AbstractKNXClient { private final Logger logger = LoggerFactory.getLogger(SerialClient.class); private final String serialPort; + private final boolean useCemi; public SerialClient(int autoReconnectPeriod, ThingUID thingUID, int responseTimeout, int readingPause, - int readRetriesLimit, ScheduledExecutorService knxScheduler, String serialPort, + int readRetriesLimit, ScheduledExecutorService knxScheduler, String serialPort, boolean useCemi, StatusUpdateCallback statusUpdateCallback) { super(autoReconnectPeriod, thingUID, responseTimeout, readingPause, readRetriesLimit, knxScheduler, statusUpdateCallback); this.serialPort = serialPort; + this.useCemi = useCemi; } @Override protected KNXNetworkLink establishConnection() throws KNXException, InterruptedException { try { RXTXVersion.getVersion(); - logger.debug("Establishing connection to KNX bus through FT1.2 on serial port {}.", serialPort); + logger.debug("Establishing connection to KNX bus through FT1.2 on serial port {}{}.", serialPort, + (useCemi ? " using CEMI" : "")); + // CEMI support by Calimero library, userful for newer serial devices like KNX RF sticks, kBerry, + // etc.; default is still old EMI frame format + if (useCemi) { + return KNXNetworkLinkFT12.newCemiLink(serialPort, new TPSettings()); + } return new KNXNetworkLinkFT12(serialPort, new TPSettings()); } catch (NoClassDefFoundError e) { diff --git a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/config/SerialBridgeConfiguration.java b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/config/SerialBridgeConfiguration.java index b267ad333..791c45ffd 100644 --- a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/config/SerialBridgeConfiguration.java +++ b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/config/SerialBridgeConfiguration.java @@ -24,8 +24,13 @@ import org.eclipse.jdt.annotation.NonNullByDefault; public class SerialBridgeConfiguration extends BridgeConfiguration { private String serialPort = ""; + private boolean useCemi = false; public String getSerialPort() { return serialPort; } + + public boolean useCemi() { + return useCemi; + } } diff --git a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/handler/SerialBridgeThingHandler.java b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/handler/SerialBridgeThingHandler.java index 5e6738646..4ed6ab511 100644 --- a/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/handler/SerialBridgeThingHandler.java +++ b/bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/handler/SerialBridgeThingHandler.java @@ -38,7 +38,8 @@ public class SerialBridgeThingHandler extends KNXBridgeBaseThingHandler { SerialBridgeConfiguration config = getConfigAs(SerialBridgeConfiguration.class); client = new SerialClient(config.getAutoReconnectPeriod(), thing.getUID(), config.getResponseTimeout().intValue(), config.getReadingPause().intValue(), - config.getReadRetriesLimit().intValue(), getScheduler(), config.getSerialPort(), this); + config.getReadRetriesLimit().intValue(), getScheduler(), config.getSerialPort(), config.useCemi(), + this); } @Override diff --git a/bundles/org.openhab.binding.knx/src/main/resources/OH-INF/i18n/knx.properties b/bundles/org.openhab.binding.knx/src/main/resources/OH-INF/i18n/knx.properties index 01c6da017..092aa7b58 100644 --- a/bundles/org.openhab.binding.knx/src/main/resources/OH-INF/i18n/knx.properties +++ b/bundles/org.openhab.binding.knx/src/main/resources/OH-INF/i18n/knx.properties @@ -54,6 +54,8 @@ thing-type.config.knx.serial.responseTimeout.label = Response Timeout thing-type.config.knx.serial.responseTimeout.description = Seconds to wait for a response from the KNX bus thing-type.config.knx.serial.serialPort.label = Serial Port thing-type.config.knx.serial.serialPort.description = The serial port to use for connecting to the KNX bus +thing-type.config.knx.serial.useCemi.label = Use CEMI +thing-type.config.knx.serial.useCemi.description = Use newer CEMI frame format instead of default EMI frame format. May be useful for newer serial devices like KNX RF sticks, kBerry, etc. # channel types diff --git a/bundles/org.openhab.binding.knx/src/main/resources/OH-INF/thing/serial.xml b/bundles/org.openhab.binding.knx/src/main/resources/OH-INF/thing/serial.xml index bb7705928..f01503e41 100644 --- a/bundles/org.openhab.binding.knx/src/main/resources/OH-INF/thing/serial.xml +++ b/bundles/org.openhab.binding.knx/src/main/resources/OH-INF/thing/serial.xml @@ -13,6 +13,13 @@ The serial port to use for connecting to the KNX bus + + + Use newer CEMI frame format instead of default EMI frame format. May be useful for newer serial devices + like KNX RF sticks, kBerry, etc. + false + true + Time in milliseconds of how long should be paused between two read requests to the bus during