Skip to content

Commit

Permalink
[knx] Add option to use CEMI frame format for serial devices. (openha…
Browse files Browse the repository at this point in the history
…b#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 openhab#10407. Relates to openhab#4026.

Signed-off-by: Holger Friedrich <[email protected]>
  • Loading branch information
holgerfriedrich authored Apr 9, 2022
1 parent b3ade70 commit f65ee6c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions bundles/org.openhab.binding.knx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@
public class SerialBridgeConfiguration extends BridgeConfiguration {

private String serialPort = "";
private boolean useCemi = false;

public String getSerialPort() {
return serialPort;
}

public boolean useCemi() {
return useCemi;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public SerialBridgeThingHandler(Bridge bridge) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
<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
Expand Down

0 comments on commit f65ee6c

Please sign in to comment.