Skip to content
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

Ignore most significant bit kWh readings #2598

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 12 additions & 7 deletions config/device_configuration.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@
<xs:attribute name='index' type='xs:string' use='required'/>
</xs:complexType>
</xs:element>
<xs:element name="RandomMsbBug" minOccurs='0'>
<xs:complexType mixed="true">
<xs:attribute name='index' type='xs:boolean' use='required'/>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
Expand Down Expand Up @@ -178,8 +183,8 @@
<xs:attribute name='Instance' type='xs:string' use='required'/>
<xs:attribute name='Index' type='xs:string' use='required'/>
</xs:complexType>
</xs:element>
</xs:element>

<xs:element name='TriggerRefreshValue'>
<xs:complexType>
<xs:sequence>
Expand All @@ -198,10 +203,10 @@
<xs:attribute name='Instance' type='xs:string' use='required'/>
<xs:attribute name='Index' type='xs:string' use='required'/>
</xs:complexType>
</xs:element>
</xs:element>




<xs:element name='Value'>
<xs:complexType>
<xs:choice maxOccurs="unbounded" >
Expand Down Expand Up @@ -298,7 +303,7 @@
<xs:attribute name='id' type='xs:string' use='required'/>
</xs:complexType>
</xs:element>


<xs:element name='Item'>
<xs:complexType>
Expand Down Expand Up @@ -347,7 +352,7 @@
</xs:element>

<xs:element name='MetaDataItem'>
<xs:complexType mixed='true'>
<xs:complexType mixed='true'>
<xs:attribute name='name' use='required'>
<xs:simpleType>
<xs:restriction base='xs:string'>
Expand Down Expand Up @@ -382,7 +387,7 @@
</xs:element>

<xs:element name='Entry'>
<xs:complexType mixed='true'>
<xs:complexType mixed='true'>
<xs:attribute name='author' type='xs:string' use='required'/>
<xs:attribute name='date' type='xs:string' use='required'/>
<xs:attribute name='revision' type='xs:integer' use='required'/>
Expand Down
16 changes: 15 additions & 1 deletion config/shenzen_neo/nas-wr01ze.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Product xmlns='https://github.com/OpenZWave/open-zwave' Revision="2">
<Product xmlns='https://github.com/OpenZWave/open-zwave' Revision="3">
<!--
Shenzhen NEO Electronics (Neo-CoolCam) Smart Power Plug EU
-->
Expand Down Expand Up @@ -37,6 +37,7 @@ Reset procedure will delete all information on the Z‐Wave network and Z‐Wave
<MetaDataItem id="1027" name="FrequencyName" type="0100">U.S. / Canada / Mexico</MetaDataItem>
<ChangeLog>
<Entry author="David Burrows - [email protected]" date="19 Aug 2020" revision="2">Added metadata, and added US version (type 0100) that is branded "Power Plug" with no model number displayed. There is no matching Z-Wave Alliance database entry.</Entry>
<Entry author="Mark Ruys - [email protected]" date="25 Mar 2021" revision="3">Enabled RandomMsbBug to ignore random MSB in kWh readings.</Entry>
</ChangeLog>
</MetaData>
<!-- Configuration Parameters -->
Expand Down Expand Up @@ -114,6 +115,19 @@ Reset procedure will delete all information on the Z‐Wave network and Z‐Wave
</Help>
</Value>
</CommandClass>
<!-- Ignore random MSB for kWh readings -->
<CommandClass id="50">
<Compatibility>
<RandomMsbBug index="0">true</RandomMsbBug>
</Compatibility>
<Instance index="1" />
<Value type="decimal" genre="user" instance="1" index="0" label="Electric - kWh" units="kWh" read_only="true" write_only="false" verify_changes="false" min="0" max="0" value="-21474826.32" />
<Value type="decimal" genre="user" instance="1" index="2" label="Electric - W" units="W" read_only="true" write_only="false" verify_changes="false" min="0" max="0" value="0.00" />
<Value type="decimal" genre="user" instance="1" index="4" label="Electric - V" units="V" read_only="true" write_only="false" verify_changes="false" min="0" max="0" value="0.00" />
<Value type="decimal" genre="user" instance="1" index="5" label="Electric - A" units="A" read_only="true" write_only="false" verify_changes="false" min="0" max="0" value="0.00" />
<Value type="bool" genre="user" instance="1" index="256" label="Exporting" units="" read_only="true" write_only="false" verify_changes="false" min="0" max="0" value="False" />
<Value type="button" genre="system" instance="1" index="257" label="Reset" units="" read_only="false" write_only="true" verify_changes="false" min="0" max="0" />
</CommandClass>
<!-- Association Groups -->
<CommandClass id="133">
<Associations num_groups="3">
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/CompatOptionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ namespace OpenZWave
{ "VerifyChanged", COMPAT_FLAG_VERIFYCHANGED, COMPAT_FLAG_TYPE_BOOL_ARRAY },
{ "EnableNotificationClear", COMPAT_FLAG_NOT_ENABLECLEAR, COMPAT_FLAG_TYPE_BOOL },
{ "EnableV1AlarmTypes", COMPAT_FLAG_NOT_V1ALARMTYPES_ENABLED, COMPAT_FLAG_TYPE_BOOL },
{ "NoRefreshAfterSet", COMPAT_FLAG_NO_REFRESH_AFTER_SET, COMPAT_FLAG_TYPE_BOOL_ARRAY }
{ "NoRefreshAfterSet", COMPAT_FLAG_NO_REFRESH_AFTER_SET, COMPAT_FLAG_TYPE_BOOL_ARRAY },
{ "RandomMsbBug", COMPAT_FLAG_RANDOM_MSB_BUG, COMPAT_FLAG_TYPE_BOOL_ARRAY }
};

uint16_t availableCompatFlagsCount = sizeof(availableCompatFlags) / sizeof(availableCompatFlags[0]);
Expand Down
1 change: 1 addition & 0 deletions cpp/src/CompatOptionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ namespace OpenZWave
COMPAT_FLAG_NOT_ENABLECLEAR,
COMPAT_FLAG_NOT_V1ALARMTYPES_ENABLED,
COMPAT_FLAG_NO_REFRESH_AFTER_SET,
COMPAT_FLAG_RANDOM_MSB_BUG,
STATE_FLAG_CCVERSION,
STATE_FLAG_STATIC_REQUESTS,
STATE_FLAG_AFTERMARK,
Expand Down
17 changes: 13 additions & 4 deletions cpp/src/command_classes/CommandClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ namespace OpenZWave
m_com.EnableFlag(COMPAT_FLAG_REFRESHONWAKEUP, false);
m_com.EnableFlag(COMPAT_FLAG_VERIFYCHANGED, false);
m_com.EnableFlag(COMPAT_FLAG_NO_REFRESH_AFTER_SET, false);
m_com.EnableFlag(COMPAT_FLAG_RANDOM_MSB_BUG, false);
m_dom.EnableFlag(STATE_FLAG_CCVERSION, 0);
m_dom.EnableFlag(STATE_FLAG_STATIC_REQUESTS, 0);
m_dom.EnableFlag(STATE_FLAG_AFTERMARK, false);
Expand Down Expand Up @@ -470,8 +471,8 @@ namespace OpenZWave
// <CommandClass::ExtractValue>
// Read a value from a variable length sequence of bytes
//-----------------------------------------------------------------------------
std::string CommandClass::ExtractValue(uint8 const* _data, uint8* _scale, uint8* _precision, uint8 _valueOffset // = 1
) const
std::string CommandClass::ExtractValue(uint16 const _index, uint8 const* _data, uint8* _scale, uint8* _precision, uint8 _valueOffset // == 1
) const
{
uint8 const size = _data[0] & c_sizeMask;
uint8 const precision = (_data[0] & c_precisionMask) >> c_precisionShift;
Expand All @@ -486,17 +487,25 @@ namespace OpenZWave
*_precision = precision;
}

bool mask_msb = m_com.GetFlagBool(COMPAT_FLAG_RANDOM_MSB_BUG, _index);

uint32 value = 0;
uint8 i;
for (i = 0; i < size; ++i)
{
uint8 byte = _data[i + (uint32) _valueOffset];
if (mask_msb && i == 0 && (byte & 0x80)) {
Log::Write(LogLevel_Warning, GetNodeId(), "CommandClass::ExtractValue: repair MSB");
byte &= 0x7f;
}

value <<= 8;
value |= (uint32) _data[i + (uint32) _valueOffset];
value |= (uint32) byte;
}

// Deal with sign extension. All values are signed
std::string res;
if (_data[_valueOffset] & 0x80)
if ((_data[_valueOffset] & 0x80) && ! mask_msb)
{
res = "-";

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/command_classes/CommandClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ namespace OpenZWave
}

// Helper methods
string ExtractValue(uint8 const* _data, uint8* _scale, uint8* _precision, uint8 _valueOffset = 1) const;
string ExtractValue(uint16 const _index, uint8 const* _data, uint8* _scale, uint8* _precision, uint8 _valueOffset = 1) const;
uint32 decodeDuration(uint8 data) const;
uint8 encodeDuration(uint32 seconds) const;
/**
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/command_classes/EnergyProduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ namespace OpenZWave
{
uint8 scale;
uint8 precision = 0;
string value = ExtractValue(&_data[2], &scale, &precision);
uint16 index = 0;
string value = ExtractValue(index, &_data[2], &scale, &precision);
uint8 paramType = _data[1];
if (paramType > 4) /* size of c_energyParameterNames minus Invalid Entry*/
{
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/command_classes/Meter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ namespace OpenZWave
// Get the value and scale
uint8 scale;
uint8 precision = 0;
string valueStr = ExtractValue(&_data[2], &scale, &precision);
scale = GetScale(_data, _length);
int8 meterType = (MeterType) (_data[1] & 0x1f);

Expand All @@ -370,6 +369,8 @@ namespace OpenZWave
return false;
}

string valueStr = ExtractValue(index, &_data[2], &scale, &precision);

Log::Write(LogLevel_Info, GetNodeId(), "Received Meter Report for %s (%d) with Units %s (%d) on Index %d: %s",MeterTypes.at(index).Label.c_str(), meterType, MeterTypes.at(index).Unit.c_str(), scale, index, valueStr.c_str());

Internal::VC::ValueDecimal* value = static_cast<Internal::VC::ValueDecimal*>(GetValue(_instance, index));
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/command_classes/SensorMultilevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ namespace OpenZWave
uint8 scale;
uint8 precision = 0;
uint8 sensorType = _data[1];
string valueStr = ExtractValue(&_data[2], &scale, &precision);
uint16 index = 0;
string valueStr = ExtractValue(index, &_data[2], &scale, &precision);

Node* node = GetNodeUnsafe();
if (node != NULL)
Expand Down
9 changes: 5 additions & 4 deletions cpp/src/command_classes/ThermostatSetpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ namespace OpenZWave
{
uint8 scale;
uint8 precision = 0;
string temperature = ExtractValue(&_data[2], &scale, &precision);
uint16 index = 0;
string temperature = ExtractValue(index, &_data[2], &scale, &precision);

value->SetUnits(scale ? "F" : "C");
value->OnValueRefreshed(temperature);
Expand Down Expand Up @@ -238,12 +239,12 @@ namespace OpenZWave
uint8 scale;
uint8 precision = 0;
uint8 size = _data[2] & 0x07;
string minValue = ExtractValue(&_data[2], &scale, &precision);
string maxValue = ExtractValue(&_data[2 + size + 1], &scale, &precision);
uint8 index = _data[1];
string minValue = ExtractValue(index, &_data[2], &scale, &precision);
string maxValue = ExtractValue(index, &_data[2 + size + 1], &scale, &precision);

Log::Write(LogLevel_Info, GetNodeId(), "Received capabilities of thermostat setpoint type %d, min %s max %s", (int) _data[1], minValue.c_str(), maxValue.c_str());

uint8 index = _data[1];
// Add supported setpoint
if (index < ThermostatSetpoint_Count)
{
Expand Down