[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 <mail@holger-friedrich.de>
This commit is contained in:
Holger Friedrich 2022-04-09 18:17:52 +02:00 committed by GitHub
parent b3ade70e29
commit f65ee6c3a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 3 deletions

View 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

View 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

View 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) {

View 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;
}
}

View 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

View 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

View File

@ -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