[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:
parent
f7815f8eb2
commit
2b9a37efa9
|
@ -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_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.
|
||||
*/
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
*/
|
||||
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.OutputStream;
|
||||
import java.util.TooManyListenersException;
|
||||
|
@ -63,7 +65,7 @@ public class RFXComSerialConnector extends RFXComBaseConnector implements Serial
|
|||
|
||||
serialPort = commPort;
|
||||
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.
|
||||
|
||||
in = serialPort.getInputStream();
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
*/
|
||||
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.util.Arrays;
|
||||
|
||||
|
@ -30,7 +32,6 @@ import org.slf4j.LoggerFactory;
|
|||
public class RFXComStreamReader extends Thread {
|
||||
private final Logger logger = LoggerFactory.getLogger(RFXComStreamReader.class);
|
||||
private static final int MAX_READ_TIMEOUTS = 4;
|
||||
private static final int MAX_RFXCOM_MESSAGE_LEN = 256;
|
||||
|
||||
private RFXComBaseConnector connector;
|
||||
|
||||
|
|
Loading…
Reference in New Issue