----------------------------------------------------------------------------- Read the reported meter value -----------------------------------------------------------------------------
| 358 | // Read the reported meter value |
| 359 | //----------------------------------------------------------------------------- |
| 360 | bool 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; |
nothing calls this directly
no test coverage detected