-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFXCOM] Support all data from wind sensors #2329
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
* | ||
* @author Marc SAUVEUR - Initial contribution | ||
* @author Pauli Anttila | ||
* @author Mike Jagdis - Support all available data from sensors | ||
*/ | ||
public class RFXComWindMessage extends RFXComBaseMessage { | ||
|
||
|
@@ -60,14 +61,17 @@ public static SubType fromByte(int input) throws RFXComUnsupportedValueException | |
|
||
private static final List<RFXComValueSelector> SUPPORTED_INPUT_VALUE_SELECTORS = Arrays.asList( | ||
RFXComValueSelector.SIGNAL_LEVEL, RFXComValueSelector.BATTERY_LEVEL, RFXComValueSelector.WIND_DIRECTION, | ||
RFXComValueSelector.WIND_SPEED); | ||
RFXComValueSelector.AVG_WIND_SPEED, RFXComValueSelector.WIND_SPEED); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How could both of us miss this 😉 The temperature fields were not added here. See https://github.com/openhab/openhab2-addons/issues/2495#issuecomment-318463340 If you ( @mjagdis ) would have time to fix this that would be great, I have no opportunity because I m not near anything except for a tablet for at least one more week. |
||
|
||
private static final List<RFXComValueSelector> SUPPORTED_OUTPUT_VALUE_SELECTORS = Collections.emptyList(); | ||
|
||
public SubType subType; | ||
public int sensorId; | ||
public double windDirection; | ||
public double windSpeed; | ||
public double avgWindSpeed; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quite some changes, should you be added as an co-author? |
||
public double temperature; | ||
public double chillTemperature; | ||
public byte signalLevel; | ||
public byte batteryLevel; | ||
|
||
|
@@ -81,17 +85,16 @@ public RFXComWindMessage(byte[] data) throws RFXComException { | |
|
||
@Override | ||
public String toString() { | ||
String str = ""; | ||
|
||
str += super.toString(); | ||
str += ", Sub type = " + subType; | ||
str += ", Device Id = " + getDeviceId(); | ||
str += ", Wind direction = " + windDirection; | ||
str += ", Wind speed = " + windSpeed; | ||
str += ", Signal level = " + signalLevel; | ||
str += ", Battery level = " + batteryLevel; | ||
|
||
return str; | ||
return super.toString() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this style better :-) |
||
+ ", Sub type = " + subType | ||
+ ", Device Id = " + getDeviceId() | ||
+ ", Wind direction = " + windDirection | ||
+ ", Wind gust = " + windSpeed | ||
+ ", Average wind speed = " + avgWindSpeed | ||
+ ", Temperature = " + temperature | ||
+ ", Chill temperature = " + chillTemperature | ||
+ ", Signal level = " + signalLevel | ||
+ ", Battery level = " + batteryLevel; | ||
} | ||
|
||
@Override | ||
|
@@ -103,7 +106,25 @@ public void encodeMessage(byte[] data) throws RFXComException { | |
sensorId = (data[4] & 0xFF) << 8 | (data[5] & 0xFF); | ||
|
||
windDirection = (short) ((data[6] & 0xFF) << 8 | (data[7] & 0xFF)); | ||
|
||
if (subType != SubType.WIND5) { | ||
avgWindSpeed = (short) ((data[8] & 0xFF) << 8 | (data[9] & 0xFF)) * 0.1; | ||
} | ||
|
||
windSpeed = (short) ((data[10] & 0xFF) << 8 | (data[11] & 0xFF)) * 0.1; | ||
|
||
if (subType == SubType.WIND4) { | ||
temperature = (short) ((data[12] & 0x7F) << 8 | (data[13] & 0xFF)) * 0.1; | ||
if ((data[12] & 0x80) != 0) { | ||
temperature = -temperature; | ||
} | ||
|
||
chillTemperature = (short) ((data[14] & 0x7F) << 8 | (data[15] & 0xFF)) * 0.1; | ||
if ((data[14] & 0x80) != 0) { | ||
chillTemperature = -chillTemperature; | ||
} | ||
} | ||
|
||
signalLevel = (byte) ((data[16] & 0xF0) >> 4); | ||
batteryLevel = (byte) (data[16] & 0x0F); | ||
} | ||
|
@@ -123,10 +144,32 @@ public byte[] decodeMessage() { | |
data[6] = (byte) ((absWindDirection >> 8) & 0xFF); | ||
data[7] = (byte) (absWindDirection & 0xFF); | ||
|
||
if (subType != SubType.WIND5) { | ||
int absAvgWindSpeedTimesTen = (short) Math.abs(avgWindSpeed) * 10; | ||
data[8] = (byte) ((absAvgWindSpeedTimesTen >> 8) & 0xFF); | ||
data[9] = (byte) (absAvgWindSpeedTimesTen & 0xFF); | ||
} | ||
|
||
int absWindSpeedTimesTen = (short) Math.abs(windSpeed) * 10; | ||
data[10] = (byte) ((absWindSpeedTimesTen >> 8) & 0xFF); | ||
data[11] = (byte) (absWindSpeedTimesTen & 0xFF); | ||
|
||
if (subType == SubType.WIND4) { | ||
int temp = (short) Math.abs(temperature) * 10; | ||
data[12] = (byte) ((temp >> 8) & 0x7F); | ||
data[13] = (byte) (temp & 0xFF); | ||
if (temperature < 0) { | ||
data[12] |= 0x80; | ||
} | ||
|
||
int chill = (short) Math.abs(chillTemperature) * 10; | ||
data[14] = (byte) ((chill >> 8) & 0x7F); | ||
data[15] = (byte) (chill & 0xFF); | ||
if (chillTemperature < 0) { | ||
data[14] |= 0x80; | ||
} | ||
} | ||
|
||
data[16] = (byte) (((signalLevel & 0x0F) << 4) | (batteryLevel & 0x0F)); | ||
|
||
return data; | ||
|
@@ -155,10 +198,23 @@ public State convertToState(RFXComValueSelector valueSelector) throws RFXComExce | |
} else if (valueSelector == RFXComValueSelector.WIND_DIRECTION) { | ||
|
||
state = new DecimalType(windDirection); | ||
|
||
} else if (valueSelector == RFXComValueSelector.AVG_WIND_SPEED) { | ||
|
||
state = new DecimalType(avgWindSpeed); | ||
|
||
} else if (valueSelector == RFXComValueSelector.WIND_SPEED) { | ||
|
||
state = new DecimalType(windSpeed); | ||
|
||
} else if (valueSelector == RFXComValueSelector.TEMPERATURE) { | ||
|
||
state = new DecimalType(temperature); | ||
|
||
} else if (valueSelector == RFXComValueSelector.CHILL_TEMPERATURE) { | ||
|
||
state = new DecimalType(chillTemperature); | ||
|
||
} else { | ||
throw new RFXComException("Can't convert " + valueSelector + " to NumberItem"); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were these already unused and not defined somewhere else, where they also should be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They were unused. Previously the gust value was what was being returned as windSpeed so to avoid breaking existing "working" setups I elected to keep that and add averageWindSpeed.