]> git.basschouten.com Git - openhab-addons.git/commitdiff
[knx] Add option to use CEMI frame format for serial devices. (#12593)
authorHolger Friedrich <holgerfriedrich@users.noreply.github.com>
Sat, 9 Apr 2022 16:17:52 +0000 (18:17 +0200)
committerGitHub <noreply@github.com>
Sat, 9 Apr 2022 16:17:52 +0000 (18:17 +0200)
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 <mail@holger-friedrich.de>
bundles/org.openhab.binding.knx/README.md
bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/KNXBindingConstants.java
bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/client/SerialClient.java
bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/config/SerialBridgeConfiguration.java
bundles/org.openhab.binding.knx/src/main/java/org/openhab/binding/knx/internal/handler/SerialBridgeThingHandler.java
bundles/org.openhab.binding.knx/src/main/resources/OH-INF/i18n/knx.properties
bundles/org.openhab.binding.knx/src/main/resources/OH-INF/thing/serial.xml

index 87c5b38e55912c5c86af37e89acaa1f3672224b5..078b7f8c3a5986fe9057ed9d99eb36ceff0353e6 100644 (file)
@@ -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
 
index 1896c04a27cfe0f91ca1102ecee09963bead1d71..00dfb907fe099b136843121846cbf328d6e4f3bf 100644 (file)
@@ -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 <a
     // href="http://www.iana.org/assignments/multicast-addresses/multicast-addresses.xml">iana</a> EIBnet/IP
index 3f6113837c901db078a752f0c01680383c5daa4f..2a49d5d2dbaf38fbe3e0b0abd4423ea8c28887b3 100644 (file)
@@ -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) {
index b267ad3338dd0b47666088c6204ac1d70bcebf93..791c45ffd132d6d4f78712ae66d8f44b9162de7c 100644 (file)
@@ -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;
+    }
 }
index 5e6738646a463da3d93da891d1a055f238cfa3e3..4ed6ab511371edc00c294b54bcd87be73d923e9f 100644 (file)
@@ -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
index 01c6da0176556f3a9ebfef5b8ebaa3b0580ef0df..092aa7b582af3ea0108f87c65ac007eee6decc60 100644 (file)
@@ -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
 
index bb7705928889ddd75234a1f1210f7a0eff9fc988..f01503e413b11adb67538ffec58a4f2e45dd9924 100644 (file)
                                <label>Serial Port</label>
                                <description>The serial port to use for connecting to the KNX bus</description>
                        </parameter>
+                       <parameter name="useCemi" type="boolean">
+                               <label>Use CEMI</label>
+                               <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.</description>
+                               <default>false</default>
+                               <advanced>true</advanced>
+                       </parameter>
                        <parameter name="readingPause" type="integer" required="true">
                                <label>Reading Pause</label>
                                <description>Time in milliseconds of how long should be paused between two read requests to the bus during