[rfxcom] Read multiple bytes at a time over serial connection (#10832)

There's no reason not to read multiple bytes at a time (that I could find) so
for best practice, set the read limit to be the maximum size of an rfxcom
message. Tested fine on my system.

Signed-off-by: James Hewitt <james.hewitt@uk.ibm.com>
This commit is contained in:
James Hewitt 2021-06-12 12:22:00 +01:00 committed by GitHub
parent f7815f8eb2
commit 2b9a37efa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 2 deletions

View File

@ -47,6 +47,8 @@ public class RFXComBindingConstants {
public static final ThingTypeUID BRIDGE_RFXTRX315 = new ThingTypeUID(BINDING_ID, BRIDGE_TYPE_RFXTRX315); public static final ThingTypeUID BRIDGE_RFXTRX315 = new ThingTypeUID(BINDING_ID, BRIDGE_TYPE_RFXTRX315);
public static final ThingTypeUID BRIDGE_RFXREC443 = new ThingTypeUID(BINDING_ID, BRIDGE_TYPE_RFXREC433); public static final ThingTypeUID BRIDGE_RFXREC443 = new ThingTypeUID(BINDING_ID, BRIDGE_TYPE_RFXREC433);
public static final int MAX_RFXCOM_MESSAGE_LEN = 256;
/** /**
* Presents all supported Bridge types by RFXCOM binding. * Presents all supported Bridge types by RFXCOM binding.
*/ */

View File

@ -12,6 +12,8 @@
*/ */
package org.openhab.binding.rfxcom.internal.connector; package org.openhab.binding.rfxcom.internal.connector;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.MAX_RFXCOM_MESSAGE_LEN;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.TooManyListenersException; import java.util.TooManyListenersException;
@ -63,7 +65,7 @@ public class RFXComSerialConnector extends RFXComBaseConnector implements Serial
serialPort = commPort; serialPort = commPort;
serialPort.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); serialPort.setSerialPortParams(38400, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
serialPort.enableReceiveThreshold(1); serialPort.enableReceiveThreshold(MAX_RFXCOM_MESSAGE_LEN);
serialPort.enableReceiveTimeout(100); // In ms. Small values mean faster shutdown but more cpu usage. serialPort.enableReceiveTimeout(100); // In ms. Small values mean faster shutdown but more cpu usage.
in = serialPort.getInputStream(); in = serialPort.getInputStream();

View File

@ -12,6 +12,8 @@
*/ */
package org.openhab.binding.rfxcom.internal.connector; package org.openhab.binding.rfxcom.internal.connector;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.MAX_RFXCOM_MESSAGE_LEN;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
@ -30,7 +32,6 @@ import org.slf4j.LoggerFactory;
public class RFXComStreamReader extends Thread { public class RFXComStreamReader extends Thread {
private final Logger logger = LoggerFactory.getLogger(RFXComStreamReader.class); private final Logger logger = LoggerFactory.getLogger(RFXComStreamReader.class);
private static final int MAX_READ_TIMEOUTS = 4; private static final int MAX_READ_TIMEOUTS = 4;
private static final int MAX_RFXCOM_MESSAGE_LEN = 256;
private RFXComBaseConnector connector; private RFXComBaseConnector connector;