----------------------------------------------------------------------------- Handle a message from the Z-Wave network -----------------------------------------------------------------------------
| 290 | // Handle a message from the Z-Wave network |
| 291 | //----------------------------------------------------------------------------- |
| 292 | bool ThermostatMode::HandleMsg |
| 293 | ( |
| 294 | uint8 const* _data, |
| 295 | uint32 const _length, |
| 296 | uint32 const _instance // = 1 |
| 297 | ) |
| 298 | { |
| 299 | if( ThermostatModeCmd_Report == (ThermostatModeCmd)_data[0] ) |
| 300 | { |
| 301 | uint8 mode = _data[1]&0x1f; |
| 302 | bool validMode = false; |
| 303 | for (vector<ValueList::Item>::iterator it = m_supportedModes.begin(); it != m_supportedModes.end(); ++it ) |
| 304 | { |
| 305 | ValueList::Item const& item = *it; |
| 306 | if (item.m_value == mode) { |
| 307 | validMode = true; |
| 308 | break; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | if( validMode ) |
| 313 | { |
| 314 | // We have received the thermostat mode from the Z-Wave device |
| 315 | if( ValueList* valueList = static_cast<ValueList*>( GetValue( _instance, 0 ) ) ) |
| 316 | { |
| 317 | valueList->OnValueRefreshed( mode ); |
| 318 | if (valueList->GetItem()) |
| 319 | Log::Write( LogLevel_Info, GetNodeId(), "Received thermostat mode: %s", valueList->GetItem()->m_label.c_str() ); |
| 320 | else |
| 321 | Log::Write( LogLevel_Info, GetNodeId(), "Received thermostat mode: %d", mode); |
| 322 | valueList->Release(); |
| 323 | } |
| 324 | else |
| 325 | { |
| 326 | Log::Write( LogLevel_Info, GetNodeId(), "Received thermostat mode: index %d", mode ); |
| 327 | } |
| 328 | } |
| 329 | else |
| 330 | { |
| 331 | Log::Write( LogLevel_Info, GetNodeId(), "Received unknown thermostat mode: index %d", mode ); |
| 332 | } |
| 333 | return true; |
| 334 | } |
| 335 | |
| 336 | if( ThermostatModeCmd_SupportedReport == (ThermostatModeCmd)_data[0] ) |
| 337 | { |
| 338 | // We have received the supported thermostat modes from the Z-Wave device |
| 339 | // these values are used to populate m_supportedModes which, in turn, is used to "seed" the values |
| 340 | // for each m_modes instance |
| 341 | Log::Write( LogLevel_Info, GetNodeId(), "Received supported thermostat modes" ); |
| 342 | |
| 343 | m_supportedModes.clear(); |
| 344 | for( uint32 i=1; i<_length-1; ++i ) |
| 345 | { |
| 346 | for( int32 bit=0; bit<8; ++bit ) |
| 347 | { |
| 348 | if( ( _data[i] & (1<<bit) ) != 0 ) |
| 349 | { |