1 //-----------------------------------------------------------------------------
2 //
3 //	MultiInstance.h
4 //
5 //	Implementation of the Z-Wave COMMAND_CLASS_MULTI_INSTANCE
6 //
7 //	Copyright (c) 2010 Mal Lansell <openzwave@lansell.org>
8 //
9 //	SOFTWARE NOTICE AND LICENSE
10 //
11 //	This file is part of OpenZWave.
12 //
13 //	OpenZWave is free software: you can redistribute it and/or modify
14 //	it under the terms of the GNU Lesser General Public License as published
15 //	by the Free Software Foundation, either version 3 of the License,
16 //	or (at your option) any later version.
17 //
18 //	OpenZWave is distributed in the hope that it will be useful,
19 //	but WITHOUT ANY WARRANTY; without even the implied warranty of
20 //	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 //	GNU Lesser General Public License for more details.
22 //
23 //	You should have received a copy of the GNU Lesser General Public License
24 //	along with OpenZWave.  If not, see <http://www.gnu.org/licenses/>.
25 //
26 //-----------------------------------------------------------------------------
27 
28 #ifndef _MultiInstance_H
29 #define _MultiInstance_H
30 
31 #include <set>
32 #include "command_classes/CommandClass.h"
33 
34 namespace OpenZWave
35 {
36 	/** \brief Implements COMMAND_CLASS_MULTI_INSTANCE (0x60), a Z-Wave device command class.
37 	 */
38 	class MultiInstance: public CommandClass
39 	{
40 	public:
41 		enum MultiInstanceCmd
42 		{
43 			MultiInstanceCmd_Get				= 0x04,
44 			MultiInstanceCmd_Report				= 0x05,
45 			MultiInstanceCmd_Encap				= 0x06,
46 
47 			// Version 2
48 			MultiChannelCmd_EndPointGet			= 0x07,
49 			MultiChannelCmd_EndPointReport			= 0x08,
50 			MultiChannelCmd_CapabilityGet			= 0x09,
51 			MultiChannelCmd_CapabilityReport		= 0x0a,
52 			MultiChannelCmd_EndPointFind			= 0x0b,
53 			MultiChannelCmd_EndPointFindReport		= 0x0c,
54 			MultiChannelCmd_Encap				= 0x0d
55 		};
56 
57 		enum MultiInstanceMapping
58 		{
59 			MultiInstanceMapAll,
60 			MultiInstanceMapEndPoints,
61 			MultiInstanceMapOther
62 		};
63 
Create(uint32 const _homeId,uint8 const _nodeId)64 		static CommandClass* Create( uint32 const _homeId, uint8 const _nodeId ){ return new MultiInstance( _homeId, _nodeId ); }
~MultiInstance()65 		virtual ~MultiInstance(){}
66 
StaticGetCommandClassId()67 		static uint8 const StaticGetCommandClassId(){ return 0x60; }
StaticGetCommandClassName()68 		static string const StaticGetCommandClassName(){ return "COMMAND_CLASS_MULTI_INSTANCE/CHANNEL"; }
69 
70 		bool RequestInstances();
71 
72 		// From CommandClass
73 		virtual void ReadXML( TiXmlElement const* _ccElement );
74 		virtual void WriteXML( TiXmlElement* _ccElement );
GetCommandClassId()75 		virtual uint8 const GetCommandClassId()const{ return StaticGetCommandClassId(); }
GetCommandClassName()76 		virtual string const GetCommandClassName()const{ return StaticGetCommandClassName(); }
77 		virtual bool HandleMsg( uint8 const* _data, uint32 const _length, uint32 const _instance = 1 );
GetMaxVersion()78 		virtual uint8 GetMaxVersion(){ return 2; }
79 
GetEndPointMap()80 		MultiInstanceMapping GetEndPointMap(){ return m_endPointMap; }
81 
82 	private:
83 		MultiInstance( uint32 const _homeId, uint8 const _nodeId );
84 
85 		void HandleMultiInstanceReport( uint8 const* _data, uint32 const _length );
86 		void HandleMultiInstanceEncap( uint8 const* _data, uint32 const _length );
87 		void HandleMultiChannelEndPointReport( uint8 const* _data, uint32 const _length );
88 		void HandleMultiChannelCapabilityReport( uint8 const* _data, uint32 const _length );
89 		void HandleMultiChannelEndPointFindReport( uint8 const* _data, uint32 const _length );
90 		void HandleMultiChannelEncap( uint8 const* _data, uint32 const _length );
91 
92 		bool		m_numEndPointsCanChange;
93 		bool		m_endPointsAreSameClass;
94 		uint8		m_numEndPoints;
95 
96 		// Finding endpoints
97 		uint8		m_endPointFindIndex;
98 		uint8		m_numEndPointsFound;
99 		set<uint8>	m_endPointCommandClasses;
100 
101 		// configuration
102 		uint8		m_numEndPointsHint;		// for nodes that do not report correct number of end points
103 		MultiInstanceMapping m_endPointMap;		// Determine how to map end points to value id instances
104 		bool		m_endPointFindSupported;	// for nodes that (someday may) support endpointfind
105 		bool 		m_ignoreUnsolicitedMultiChannelCapabilityReport;
106 		bool		m_uniqueendpoints;
107 	};
108 
109 } // namespace OpenZWave
110 
111 #endif
112 
113