MCPcopy Create free account
hub / github.com/OpenZWave/open-zwave / HandleSupportedReport

Method HandleSupportedReport

cpp/src/command_classes/Meter.cpp:244–354  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Create the values for this command class based on the reported parameters -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

242// Create the values for this command class based on the reported parameters
243//-----------------------------------------------------------------------------
244bool Meter::HandleSupportedReport
245(
246 uint8 const* _data,
247 uint32 const _length,
248 uint32 const _instance
249)
250{
251 bool canReset = ((_data[1] & 0x80) != 0);
252 int8 meterType = (MeterType)(_data[1] & 0x1f);
253 if (meterType > 4) /* size of c_meterTypes */
254 {
255 Log::Write (LogLevel_Warning, GetNodeId(), "meterType Value was greater than range. Dropping Message");
256 return false;
257 }
258
259
260 ClearStaticRequest( StaticRequest_Version );
261 if( Node* node = GetNodeUnsafe() )
262 {
263 string msg;
264 msg = c_meterTypes[meterType];
265 msg += ": ";
266 // Create the list of supported scales
267 uint8 scaleSupported = _data[2];
268 if( GetVersion() == 2 )
269 {
270 // Only four scales are allowed in version 2
271 scaleSupported &= 0x0f;
272 }
273
274 for( uint8 i=0; i<8; ++i )
275 {
276 if( scaleSupported & (1<<i) )
277 {
278 uint8 baseIndex = i<<2; // We leave space between the value indices to insert previous and time delta values if we need to later on.
279 switch( meterType )
280 {
281 case MeterType_Electric:
282 {
283 if( ValueDecimal* value = static_cast<ValueDecimal*>( GetValue( _instance, baseIndex ) ) )
284 {
285 value->SetLabel( c_electricityLabels[i] );
286 value->SetUnits( c_electricityUnits[i] );
287 value->Release();
288 }
289 else
290 {
291 node->CreateValueDecimal( ValueID::ValueGenre_User, GetCommandClassId(), _instance, baseIndex, c_electricityLabels[i], c_electricityUnits[i], true, false, "0.0", 0 );
292 }
293 if( i != 0 )
294 msg += ", ";
295 msg += c_electricityUnits[i];
296 break;
297 }
298 case MeterType_Gas:
299 {
300 if( ValueDecimal* value = static_cast<ValueDecimal*>( GetValue( _instance, baseIndex ) ) )
301 {

Callers

nothing calls this directly

Calls 11

WriteFunction · 0.85
GetVersionFunction · 0.85
GetCommandClassIdFunction · 0.85
SetUnitsMethod · 0.80
CreateValueDecimalMethod · 0.80
CreateValueBoolMethod · 0.80
CreateValueButtonMethod · 0.80
GetNodeIdFunction · 0.70
SetLabelMethod · 0.45
ReleaseMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected