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

Method HandleMsg

cpp/src/command_classes/SensorMultilevel.cpp:339–555  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Handle a message from the Z-Wave network -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

337// Handle a message from the Z-Wave network
338//-----------------------------------------------------------------------------
339bool SensorMultilevel::HandleMsg
340(
341 uint8 const* _data,
342 uint32 const _length,
343 uint32 const _instance // = 1
344)
345{
346 if (SensorMultilevelCmd_SupportedReport == (SensorMultilevelCmd)_data[0])
347 {
348 string msg = "";
349
350 if( Node* node = GetNodeUnsafe() )
351 {
352 for( uint8 i = 1; i <= ( _length - 2 ); i++ )
353 {
354 for( uint8 j = 0; j < 8; j++ )
355 {
356 if( _data[i] & ( 1 << j ) )
357 {
358 if( msg != "" )
359 msg += ", ";
360 uint8 index = ( ( i - 1 ) * 8 ) + j + 1;
361 if (index >= SensorType_MaxType) /* max size for c_sensorTypeNames */
362 {
363 Log::Write (LogLevel_Warning, GetNodeId(), "SensorType Value was greater than range. Dropping");
364 continue;
365 }
366 msg += c_sensorTypeNames[index];
367 ValueDecimal* value = static_cast<ValueDecimal*>( GetValue( _instance, index ) );
368 if( value == NULL)
369 {
370 node->CreateValueDecimal( ValueID::ValueGenre_User, GetCommandClassId(), _instance, index, c_sensorTypeNames[index], "", true, false, "0.0", 0 );
371 }
372 }
373 }
374 }
375 }
376 Log::Write( LogLevel_Info, GetNodeId(), "Received SensorMultiLevel supported report from node %d: %s", GetNodeId(), msg.c_str() );
377 }
378 else if (SensorMultilevelCmd_Report == (SensorMultilevelCmd)_data[0])
379 {
380 uint8 scale;
381 uint8 precision = 0;
382 uint8 sensorType = _data[1];
383 string valueStr = ExtractValue( &_data[2], &scale, &precision );
384
385 Node* node = GetNodeUnsafe();
386 if( node != NULL )
387 {
388 char const* units = "";
389 switch( sensorType )
390 {
391 case SensorType_Temperature: units = scale ? "F" : "C"; break;
392 case SensorType_General: units = scale ? "" : "%"; break;
393 case SensorType_Luminance: units = scale ? "lux" : "%"; break;
394 case SensorType_Power: units = scale ? "BTU/h" : "W"; break;
395 case SensorType_RelativeHumidity: units = scale ? "" : "%"; break;
396 case SensorType_Velocity: units = scale ? "mph" : "m/s"; break;

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected