这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on May 17, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ swegongw -v -d /dev/ttyUSB0 -a 192.168.1.10

This binding can be configured in the file `services/swegonventilation.cfg`.

| Property | Default | Required | Description |
|----------|---------|:--------:|-------------|
| udpPort | 9998 | No | UDP port on which the binding will listen |
| Property | Default | Required | Description |
|---------------|---------|:--------:|-------------|
| udpPort | 9998 | No | UDP port on which the binding will listen |
| throttleTime | 0 | No | Throttle received messages. 0 = throttle is disabled, otherwise throttle time in milliseconds. |

## Item Configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class SwegonVentilationBinding extends AbstractBinding<SwegonVentilationB
private int udpPort = 9998;
private String serialPort = null;
private boolean simulator = false;
private int throttleTime = 0;

/** Thread to handle messages from heat pump */
private MessageListener messageListener = null;
Expand Down Expand Up @@ -112,6 +113,11 @@ public void updated(Dictionary<String, ?> config) throws ConfigurationException
if (StringUtils.isNotBlank(simulateString)) {
simulator = Boolean.parseBoolean(simulateString);
}

String throttleTimeString = (String) config.get("throttleTime");
if (StringUtils.isNotBlank(throttleTimeString)) {
throttleTime = Integer.parseInt(throttleTimeString);
}
}

if (messageListener != null) {
Expand Down Expand Up @@ -219,7 +225,7 @@ public void run() {
logger.trace("Received data (len={}): {}", data.length, DatatypeConverter.printHexBinary(data));

HashMap<SwegonVentilationCommandType, Integer> regValues = SwegonVentilationDataParser
.parseData(data);
.parseData(data, throttleTime);

if (regValues != null) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import org.openhab.binding.swegonventilation.internal.SwegonVentilationCommandType;
import org.openhab.binding.swegonventilation.internal.SwegonVentilationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Class for parse data packets from Swegon ventilation system.
Expand All @@ -20,8 +22,20 @@
* @since 1.4.0
*/
public class SwegonVentilationDataParser {
private static final Logger LOGGER = LoggerFactory.getLogger(SwegonVentilationDataParser.class);

public static HashMap<SwegonVentilationCommandType, Integer> parseData(byte[] data)
private static HashMap<Byte, Long> updateTimes = new HashMap<Byte, Long>();

private static long getLastUpdateTime(byte msgType) {
Long throttleTime = updateTimes.get(msgType);
return throttleTime != null ? throttleTime : 0;
}

private static void setLastUpdateTime(byte msgType, long time) {
updateTimes.put(msgType, time);
}

public static HashMap<SwegonVentilationCommandType, Integer> parseData(byte[] data, int throttleTime)
throws SwegonVentilationException {

if (data[0] == (byte) 0x64) {
Expand All @@ -41,15 +55,28 @@ public static HashMap<SwegonVentilationCommandType, Integer> parseData(byte[] da
d[i - 8] = data[i];
}

switch (msgType) {
case (byte) 0x21:
return parseMessage21(d);
case (byte) 0x71:
return parseMessage71(d);
case (byte) 0x73:
return parseMessage73(d);
boolean parse = true;

LOGGER.debug("Received message type '{}'", msgType);
if (throttleTime > 0) {
if ((getLastUpdateTime(msgType) + throttleTime) > System.currentTimeMillis()) {
LOGGER.debug("Skipping message parsing");
parse = false;
}
}

if (parse) {
LOGGER.debug("Parsing message");
setLastUpdateTime(msgType, System.currentTimeMillis());
switch (msgType) {
case (byte) 0x21:
return parseMessage21(d);
case (byte) 0x71:
return parseMessage71(d);
case (byte) 0x73:
return parseMessage73(d);
}
}
} else {
throw new SwegonVentilationException("Illegal data received, first byte mismatch!");
}
Expand Down