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

Method HandleReport

cpp/src/command_classes/Meter.cpp:360–517  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Read the reported meter value -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

358// Read the reported meter value
359//-----------------------------------------------------------------------------
360bool Meter::HandleReport
361(
362 uint8 const* _data,
363 uint32 const _length,
364 uint32 const _instance
365)
366{
367 // Import or Export (only valid in version > 1)
368 bool exporting = false;
369 if( GetVersion() > 1 )
370 {
371 exporting = ((_data[1] & 0x60) == 0x40 );
372 if( ValueBool* value = static_cast<ValueBool*>( GetValue( _instance, MeterIndex_Exporting ) ) )
373 {
374 value->OnValueRefreshed( exporting );
375 value->Release();
376 }
377 }
378
379 // Get the value and scale
380 uint8 scale;
381 uint8 precision = 0;
382 string valueStr = ExtractValue( &_data[2], &scale, &precision );
383
384 if (scale > 7) /* size of c_electricityLabels, c_electricityUnits, c_gasUnits, c_waterUnits */
385 {
386 Log::Write (LogLevel_Warning, GetNodeId(), "Scale was greater than range. Setting to Invalid");
387 scale = 7;
388 }
389
390
391 if( GetVersion() == 1 )
392 {
393 // In version 1, we don't know the scale until we get the first value report
394 string label;
395 string units;
396 int8 meterType = (MeterType)(_data[1] & 0x1f);
397 if (meterType > 4) /* size of c_meterTypes */
398 {
399 Log::Write (LogLevel_Warning, GetNodeId(), "meterType Value was greater than range. Dropping Message");
400 return false;
401 }
402
403 switch( (MeterType)(_data[1] & 0x1f) )
404 {
405 case MeterType_Electric:
406 {
407 // Electricity Meter
408 label = c_electricityLabels[scale];
409 units = c_electricityUnits[scale];
410 break;
411 }
412 case MeterType_Gas:
413 {
414 // Gas Meter
415 label = c_meterTypes[MeterType_Gas];
416 units = c_gasUnits[scale];
417 break;

Callers

nothing calls this directly

Calls 14

GetVersionFunction · 0.85
WriteFunction · 0.85
GetCommandClassIdFunction · 0.85
SetUnitsMethod · 0.80
GetPrecisionMethod · 0.80
SetPrecisionMethod · 0.80
CreateValueDecimalMethod · 0.80
CreateValueIntMethod · 0.80
GetNodeIdFunction · 0.70
OnValueRefreshedMethod · 0.45
ReleaseMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected