1 //-----------------------------------------------------------------------------
2 //
3 //	ManufacturerSpecific.h
4 //
5 //	Implementation of the Z-Wave COMMAND_CLASS_MANUFACTURER_SPECIFIC
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 _ManufacturerSpecific_H
29 #define _ManufacturerSpecific_H
30 
31 #include <map>
32 #include "command_classes/CommandClass.h"
33 
34 namespace OpenZWave
35 {
36 	/** \brief Implements COMMAND_CLASS_MANUFACTURER_SPECIFIC (0x72), a Z-Wave device command class.
37 	 */
38 	class ManufacturerSpecific: public CommandClass
39 	{
40 	public:
Create(uint32 const _homeId,uint8 const _nodeId)41 		static CommandClass* Create( uint32 const _homeId, uint8 const _nodeId ){ return new ManufacturerSpecific( _homeId, _nodeId ); }
~ManufacturerSpecific()42 		virtual ~ManufacturerSpecific(){ UnloadProductXML(); }
43 
StaticGetCommandClassId()44 		static uint8 const StaticGetCommandClassId(){ return 0x72; }
StaticGetCommandClassName()45 		static string const StaticGetCommandClassName(){ return "COMMAND_CLASS_MANUFACTURER_SPECIFIC"; }
46 
47 		// From CommandClass
48 		virtual bool RequestState( uint32 const _requestFlags, uint8 const _instance, Driver::MsgQueue const _queue );
49 		virtual bool RequestValue( uint32 const _requestFlags, uint8 const _index, uint8 const _instance, Driver::MsgQueue const _queue );
GetCommandClassId()50 		virtual uint8 const GetCommandClassId()const{ return StaticGetCommandClassId(); }
GetCommandClassName()51 		virtual string const GetCommandClassName()const{ return StaticGetCommandClassName(); }
52 		virtual bool HandleMsg( uint8 const* _data, uint32 const _length, uint32 const _instance = 1 );
53 
54 		static string SetProductDetails( Node *_node, uint16 _manufacturerId, uint16 _productType, uint16 _productId );
55 		static bool LoadConfigXML( Node* _node, string const& _configXML );
56 
57 		void ReLoadConfigXML();
58 
59 	private:
ManufacturerSpecific(uint32 const _homeId,uint8 const _nodeId)60 		ManufacturerSpecific( uint32 const _homeId, uint8 const _nodeId ): CommandClass( _homeId, _nodeId ){ SetStaticRequest( StaticRequest_Values ); }
61 		static bool LoadProductXML();
62 		static void UnloadProductXML();
63 
64 		class Product
65 		{
66 		public:
Product(uint16 _manufacturerId,uint16 _productType,uint16 _productId,string const & _productName,string const & _configPath)67 			Product
68 			(
69 				uint16 _manufacturerId,
70 				uint16 _productType,
71 				uint16 _productId,
72 				string const& _productName,
73 				string const& _configPath
74 			):
75 				m_manufacturerId( _manufacturerId ),
76 				m_productType( _productType ),
77 				m_productId( _productId ),
78 				m_productName( _productName ),
79 				m_configPath( _configPath )
80 			{
81 			}
82 
GetKey()83 			int64 GetKey()const
84 			{
85 				return( GetKey( m_manufacturerId, m_productType, m_productId ) );
86 			}
87 
GetKey(uint16 _manufacturerId,uint16 _productType,uint16 _productId)88 			static int64 GetKey( uint16 _manufacturerId, uint16 _productType, uint16 _productId )
89 			{
90 				int64 key = (((int64)_manufacturerId)<<32) | (((int64)_productType)<<16) | (int64)_productId;
91 				return key;
92 			}
93 
GetManufacturerId()94 			uint16 GetManufacturerId()const{ return m_manufacturerId; }
GetProductType()95 			uint16 GetProductType()const{ return m_productType; }
GetProductId()96 			uint16 GetProductId()const{ return m_productId; }
GetProductName()97 			string GetProductName()const{ return m_productName; }
GetConfigPath()98 			string GetConfigPath()const{ return m_configPath; }
99 
100 		private:
101 			uint16	m_manufacturerId;
102 			uint16	m_productType;
103 			uint16	m_productId;
104 			string	m_productName;
105 			string	m_configPath;
106 		};
107 
108 		static map<uint16,string>	s_manufacturerMap;
109 		static map<int64,Product*>	s_productMap;
110 		static bool					s_bXmlLoaded;
111 	};
112 
113 } // namespace OpenZWave
114 
115 #endif
116 
117