ansible4ozw 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. data/lib/ansible.rb +12 -9
  2. data/lib/ansible/ansible_device.rb +1 -1
  3. data/lib/ansible/ansible_value.rb +1 -1
  4. data/lib/ansible/config.rb +8 -5
  5. data/lib/ansible/devices.rb +1 -0
  6. data/lib/ansible/knx.rb +0 -0
  7. data/lib/ansible/knx/dpt/tests/test_dpt10.rb~ +45 -0
  8. data/lib/ansible/knx/dpt/tests/test_dpt9.rb~ +55 -0
  9. data/lib/ansible/transceiver.rb +0 -3
  10. data/lib/ansible/version.rb +3 -0
  11. data/lib/ansible/zwave.rb +1 -0
  12. data/lib/ansible/{openzwave → zwave/openzwave}/ozw_constants.rb +1 -2
  13. data/lib/ansible/{openzwave → zwave/openzwave}/ozw_headers.rb +2 -6
  14. data/lib/ansible/{openzwave → zwave/openzwave}/ozw_remote_manager.rb +0 -3
  15. data/lib/ansible/{openzwave → zwave/openzwave}/ozw_types.rb +0 -0
  16. data/lib/ansible/zwave/openzwave/src/Driver.h +695 -0
  17. data/lib/ansible/zwave/openzwave/src/Notification.h +165 -0
  18. data/lib/ansible/zwave/openzwave/src/command_classes/Alarm.cpp +142 -0
  19. data/lib/ansible/zwave/openzwave/src/command_classes/Alarm.h +69 -0
  20. data/lib/ansible/zwave/openzwave/src/command_classes/ApplicationStatus.cpp +93 -0
  21. data/lib/ansible/zwave/openzwave/src/command_classes/ApplicationStatus.h +57 -0
  22. data/lib/ansible/zwave/openzwave/src/command_classes/Association.cpp +385 -0
  23. data/lib/ansible/zwave/openzwave/src/command_classes/Association.h +73 -0
  24. data/lib/ansible/zwave/openzwave/src/command_classes/AssociationCommandConfiguration.cpp +277 -0
  25. data/lib/ansible/zwave/openzwave/src/command_classes/AssociationCommandConfiguration.h +70 -0
  26. data/lib/ansible/zwave/openzwave/src/command_classes/Basic.cpp +212 -0
  27. data/lib/ansible/zwave/openzwave/src/command_classes/Basic.h +72 -0
  28. data/lib/ansible/zwave/openzwave/src/command_classes/BasicWindowCovering.cpp +118 -0
  29. data/lib/ansible/zwave/openzwave/src/command_classes/BasicWindowCovering.h +64 -0
  30. data/lib/ansible/zwave/openzwave/src/command_classes/Battery.cpp +141 -0
  31. data/lib/ansible/zwave/openzwave/src/command_classes/Battery.h +65 -0
  32. data/lib/ansible/zwave/openzwave/src/command_classes/ClimateControlSchedule.cpp +415 -0
  33. data/lib/ansible/zwave/openzwave/src/command_classes/ClimateControlSchedule.h +71 -0
  34. data/lib/ansible/zwave/openzwave/src/command_classes/Clock.cpp +227 -0
  35. data/lib/ansible/zwave/openzwave/src/command_classes/Clock.h +67 -0
  36. data/lib/ansible/zwave/openzwave/src/command_classes/CommandClass.cpp +546 -0
  37. data/lib/ansible/zwave/openzwave/src/command_classes/CommandClass.h +145 -0
  38. data/lib/ansible/zwave/openzwave/src/command_classes/CommandClasses.cpp +291 -0
  39. data/lib/ansible/zwave/openzwave/src/command_classes/CommandClasses.h +79 -0
  40. data/lib/ansible/zwave/openzwave/src/command_classes/Configuration.cpp +258 -0
  41. data/lib/ansible/zwave/openzwave/src/command_classes/Configuration.h +67 -0
  42. data/lib/ansible/zwave/openzwave/src/command_classes/ControllerReplication.cpp +142 -0
  43. data/lib/ansible/zwave/openzwave/src/command_classes/ControllerReplication.h +63 -0
  44. data/lib/ansible/zwave/openzwave/src/command_classes/EnergyProduction.cpp +163 -0
  45. data/lib/ansible/zwave/openzwave/src/command_classes/EnergyProduction.h +65 -0
  46. data/lib/ansible/zwave/openzwave/src/command_classes/Hail.cpp +68 -0
  47. data/lib/ansible/zwave/openzwave/src/command_classes/Hail.h +58 -0
  48. data/lib/ansible/zwave/openzwave/src/command_classes/Indicator.cpp +159 -0
  49. data/lib/ansible/zwave/openzwave/src/command_classes/Indicator.h +66 -0
  50. data/lib/ansible/zwave/openzwave/src/command_classes/Language.cpp +159 -0
  51. data/lib/ansible/zwave/openzwave/src/command_classes/Language.h +65 -0
  52. data/lib/ansible/zwave/openzwave/src/command_classes/Lock.cpp +159 -0
  53. data/lib/ansible/zwave/openzwave/src/command_classes/Lock.h +66 -0
  54. data/lib/ansible/zwave/openzwave/src/command_classes/ManufacturerSpecific.cpp +439 -0
  55. data/lib/ansible/zwave/openzwave/src/command_classes/ManufacturerSpecific.h +116 -0
  56. data/lib/ansible/zwave/openzwave/src/command_classes/Meter.cpp +541 -0
  57. data/lib/ansible/zwave/openzwave/src/command_classes/Meter.h +73 -0
  58. data/lib/ansible/zwave/openzwave/src/command_classes/MeterPulse.cpp +137 -0
  59. data/lib/ansible/zwave/openzwave/src/command_classes/MeterPulse.h +65 -0
  60. data/lib/ansible/zwave/openzwave/src/command_classes/MultiCmd.cpp +77 -0
  61. data/lib/ansible/zwave/openzwave/src/command_classes/MultiCmd.h +63 -0
  62. data/lib/ansible/zwave/openzwave/src/command_classes/MultiInstance.cpp +568 -0
  63. data/lib/ansible/zwave/openzwave/src/command_classes/MultiInstance.h +96 -0
  64. data/lib/ansible/zwave/openzwave/src/command_classes/MultiInstanceAssociation.cpp +61 -0
  65. data/lib/ansible/zwave/openzwave/src/command_classes/MultiInstanceAssociation.h +59 -0
  66. data/lib/ansible/zwave/openzwave/src/command_classes/NodeNaming.cpp +525 -0
  67. data/lib/ansible/zwave/openzwave/src/command_classes/NodeNaming.h +66 -0
  68. data/lib/ansible/zwave/openzwave/src/command_classes/Powerlevel.cpp +157 -0
  69. data/lib/ansible/zwave/openzwave/src/command_classes/Powerlevel.h +82 -0
  70. data/lib/ansible/zwave/openzwave/src/command_classes/Proprietary.cpp +62 -0
  71. data/lib/ansible/zwave/openzwave/src/command_classes/Proprietary.h +58 -0
  72. data/lib/ansible/zwave/openzwave/src/command_classes/Protection.cpp +177 -0
  73. data/lib/ansible/zwave/openzwave/src/command_classes/Protection.h +73 -0
  74. data/lib/ansible/zwave/openzwave/src/command_classes/SensorAlarm.cpp +208 -0
  75. data/lib/ansible/zwave/openzwave/src/command_classes/SensorAlarm.h +77 -0
  76. data/lib/ansible/zwave/openzwave/src/command_classes/SensorBinary.cpp +134 -0
  77. data/lib/ansible/zwave/openzwave/src/command_classes/SensorBinary.h +65 -0
  78. data/lib/ansible/zwave/openzwave/src/command_classes/SensorMultilevel.cpp +237 -0
  79. data/lib/ansible/zwave/openzwave/src/command_classes/SensorMultilevel.h +71 -0
  80. data/lib/ansible/zwave/openzwave/src/command_classes/SwitchAll.cpp +219 -0
  81. data/lib/ansible/zwave/openzwave/src/command_classes/SwitchAll.h +69 -0
  82. data/lib/ansible/zwave/openzwave/src/command_classes/SwitchBinary.cpp +157 -0
  83. data/lib/ansible/zwave/openzwave/src/command_classes/SwitchBinary.h +66 -0
  84. data/lib/ansible/zwave/openzwave/src/command_classes/SwitchMultilevel.cpp +559 -0
  85. data/lib/ansible/zwave/openzwave/src/command_classes/SwitchMultilevel.h +83 -0
  86. data/lib/ansible/zwave/openzwave/src/command_classes/SwitchToggleBinary.cpp +151 -0
  87. data/lib/ansible/zwave/openzwave/src/command_classes/SwitchToggleBinary.h +66 -0
  88. data/lib/ansible/zwave/openzwave/src/command_classes/SwitchToggleMultilevel.cpp +195 -0
  89. data/lib/ansible/zwave/openzwave/src/command_classes/SwitchToggleMultilevel.h +75 -0
  90. data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatFanMode.cpp +332 -0
  91. data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatFanMode.h +77 -0
  92. data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatFanState.cpp +149 -0
  93. data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatFanState.h +71 -0
  94. data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatMode.cpp +373 -0
  95. data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatMode.h +76 -0
  96. data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatOperatingState.cpp +147 -0
  97. data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatOperatingState.h +71 -0
  98. data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatSetpoint.cpp +317 -0
  99. data/lib/ansible/zwave/openzwave/src/command_classes/ThermostatSetpoint.h +73 -0
  100. data/lib/ansible/zwave/openzwave/src/command_classes/Version.cpp +255 -0
  101. data/lib/ansible/zwave/openzwave/src/command_classes/Version.h +71 -0
  102. data/lib/ansible/zwave/openzwave/src/command_classes/WakeUp.cpp +391 -0
  103. data/lib/ansible/zwave/openzwave/src/command_classes/WakeUp.h +85 -0
  104. data/lib/ansible/zwave/openzwave/src/platform/Controller.cpp +68 -0
  105. data/lib/ansible/zwave/openzwave/src/platform/Controller.h +106 -0
  106. data/lib/ansible/zwave/openzwave/src/platform/Event.cpp +102 -0
  107. data/lib/ansible/zwave/openzwave/src/platform/Event.h +91 -0
  108. data/lib/ansible/zwave/openzwave/src/platform/HidController.cpp +539 -0
  109. data/lib/ansible/zwave/openzwave/src/platform/HidController.h +147 -0
  110. data/lib/ansible/zwave/openzwave/src/platform/Log.cpp +310 -0
  111. data/lib/ansible/zwave/openzwave/src/platform/Log.h +184 -0
  112. data/lib/ansible/zwave/openzwave/src/platform/Mutex.cpp +96 -0
  113. data/lib/ansible/zwave/openzwave/src/platform/Mutex.h +88 -0
  114. data/lib/ansible/zwave/openzwave/src/platform/Ref.h +91 -0
  115. data/lib/ansible/zwave/openzwave/src/platform/SerialController.cpp +180 -0
  116. data/lib/ansible/zwave/openzwave/src/platform/SerialController.h +138 -0
  117. data/lib/ansible/zwave/openzwave/src/platform/Stream.cpp +229 -0
  118. data/lib/ansible/zwave/openzwave/src/platform/Stream.h +135 -0
  119. data/lib/ansible/zwave/openzwave/src/platform/Thread.cpp +118 -0
  120. data/lib/ansible/zwave/openzwave/src/platform/Thread.h +101 -0
  121. data/lib/ansible/zwave/openzwave/src/platform/TimeStamp.cpp +92 -0
  122. data/lib/ansible/zwave/openzwave/src/platform/TimeStamp.h +85 -0
  123. data/lib/ansible/zwave/openzwave/src/platform/Wait.cpp +176 -0
  124. data/lib/ansible/zwave/openzwave/src/platform/Wait.h +113 -0
  125. data/lib/ansible/zwave/openzwave/src/platform/unix/EventImpl.cpp +262 -0
  126. data/lib/ansible/zwave/openzwave/src/platform/unix/EventImpl.h +62 -0
  127. data/lib/ansible/zwave/openzwave/src/platform/unix/LogImpl.cpp +304 -0
  128. data/lib/ansible/zwave/openzwave/src/platform/unix/LogImpl.h +70 -0
  129. data/lib/ansible/zwave/openzwave/src/platform/unix/MutexImpl.cpp +136 -0
  130. data/lib/ansible/zwave/openzwave/src/platform/unix/MutexImpl.h +56 -0
  131. data/lib/ansible/zwave/openzwave/src/platform/unix/SerialControllerImpl.cpp +368 -0
  132. data/lib/ansible/zwave/openzwave/src/platform/unix/SerialControllerImpl.h +74 -0
  133. data/lib/ansible/zwave/openzwave/src/platform/unix/ThreadImpl.cpp +181 -0
  134. data/lib/ansible/zwave/openzwave/src/platform/unix/ThreadImpl.h +67 -0
  135. data/lib/ansible/zwave/openzwave/src/platform/unix/TimeStampImpl.cpp +121 -0
  136. data/lib/ansible/zwave/openzwave/src/platform/unix/TimeStampImpl.h +84 -0
  137. data/lib/ansible/zwave/openzwave/src/platform/unix/WaitImpl.cpp +160 -0
  138. data/lib/ansible/zwave/openzwave/src/platform/unix/WaitImpl.h +74 -0
  139. data/lib/ansible/zwave/openzwave/src/platform/windows/EventImpl.cpp +102 -0
  140. data/lib/ansible/zwave/openzwave/src/platform/windows/EventImpl.h +60 -0
  141. data/lib/ansible/zwave/openzwave/src/platform/windows/LogImpl.cpp +302 -0
  142. data/lib/ansible/zwave/openzwave/src/platform/windows/LogImpl.h +71 -0
  143. data/lib/ansible/zwave/openzwave/src/platform/windows/MutexImpl.cpp +114 -0
  144. data/lib/ansible/zwave/openzwave/src/platform/windows/MutexImpl.h +58 -0
  145. data/lib/ansible/zwave/openzwave/src/platform/windows/SerialControllerImpl.cpp +410 -0
  146. data/lib/ansible/zwave/openzwave/src/platform/windows/SerialControllerImpl.h +66 -0
  147. data/lib/ansible/zwave/openzwave/src/platform/windows/ThreadImpl.cpp +158 -0
  148. data/lib/ansible/zwave/openzwave/src/platform/windows/ThreadImpl.h +71 -0
  149. data/lib/ansible/zwave/openzwave/src/platform/windows/TimeStampImpl.cpp +95 -0
  150. data/lib/ansible/zwave/openzwave/src/platform/windows/TimeStampImpl.h +83 -0
  151. data/lib/ansible/zwave/openzwave/src/platform/windows/WaitImpl.cpp +134 -0
  152. data/lib/ansible/zwave/openzwave/src/platform/windows/WaitImpl.h +73 -0
  153. data/lib/ansible/zwave/openzwave/src/value_classes/ValueID.h +283 -0
  154. data/lib/ansible/zwave/{types → openzwave/types}/valuetype_bool.rb +0 -0
  155. data/lib/ansible/zwave/{types → openzwave/types}/valuetype_button.rb +0 -0
  156. data/lib/ansible/zwave/{types → openzwave/types}/valuetype_byte.rb +0 -0
  157. data/lib/ansible/zwave/{types → openzwave/types}/valuetype_decimal.rb +0 -0
  158. data/lib/ansible/zwave/{types → openzwave/types}/valuetype_int.rb +0 -0
  159. data/lib/ansible/zwave/{types → openzwave/types}/valuetype_list.rb +0 -0
  160. data/lib/ansible/zwave/{types → openzwave/types}/valuetype_short.rb +0 -0
  161. data/lib/ansible/zwave/{types → openzwave/types}/valuetype_string.rb +0 -0
  162. data/lib/ansible/zwave/zwave_transceiver.rb +2 -8
  163. data/lib/ansible/zwave/zwave_value.rb +6 -10
  164. metadata +159 -17
  165. data/lib/ansible/zwave/zwave_node.rb +0 -5
@@ -0,0 +1,96 @@
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 "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
+ static CommandClass* Create( uint32 const _homeId, uint8 const _nodeId ){ return new MultiInstance( _homeId, _nodeId ); }
58
+ virtual ~MultiInstance(){}
59
+
60
+ static uint8 const StaticGetCommandClassId(){ return 0x60; }
61
+ static string const StaticGetCommandClassName(){ return "COMMAND_CLASS_MULTI_INSTANCE/CHANNEL"; }
62
+
63
+ bool RequestInstances();
64
+
65
+ // From CommandClass
66
+ virtual uint8 const GetCommandClassId()const{ return StaticGetCommandClassId(); }
67
+ virtual string const GetCommandClassName()const{ return StaticGetCommandClassName(); }
68
+ virtual bool HandleMsg( uint8 const* _data, uint32 const _length, uint32 const _instance = 1 );
69
+ virtual uint8 GetMaxVersion(){ return 2; }
70
+
71
+ void SendEncap( uint8 const* _data, uint32 const _length, uint32 const _instance, uint32 const _requestFlags );
72
+
73
+ private:
74
+ MultiInstance( uint32 const _homeId, uint8 const _nodeId );
75
+
76
+ void HandleMultiInstanceReport( uint8 const* _data, uint32 const _length );
77
+ void HandleMultiInstanceEncap( uint8 const* _data, uint32 const _length );
78
+ void HandleMultiChannelEndPointReport( uint8 const* _data, uint32 const _length );
79
+ void HandleMultiChannelCapabilityReport( uint8 const* _data, uint32 const _length );
80
+ void HandleMultiChannelEndPointFindReport( uint8 const* _data, uint32 const _length );
81
+ void HandleMultiChannelEncap( uint8 const* _data, uint32 const _length );
82
+
83
+ bool m_numEndPointsCanChange;
84
+ bool m_endPointsAreSameClass;
85
+ uint8 m_numEndpoints;
86
+
87
+ // Finding endpoints
88
+ uint8 m_endPointFindIndex;
89
+ uint8 m_numEndPointsFound;
90
+ set<uint8> m_endPointCommandClasses;
91
+ };
92
+
93
+ } // namespace OpenZWave
94
+
95
+ #endif
96
+
@@ -0,0 +1,61 @@
1
+ //-----------------------------------------------------------------------------
2
+ //
3
+ // MultiInstanceAssociation.cpp
4
+ //
5
+ // Implementation of the Z-Wave COMMAND_CLASS_MULTI_INSTANCE_ASSOCIATION
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
+ #include "CommandClasses.h"
29
+ #include "MultiInstanceAssociation.h"
30
+ #include "Defs.h"
31
+ #include "Msg.h"
32
+ #include "Driver.h"
33
+ #include "Log.h"
34
+
35
+ using namespace OpenZWave;
36
+
37
+ enum MultiInstanceAssociationCmd
38
+ {
39
+ MultiInstanceAssociationCmd_Set = 0x01,
40
+ MultiInstanceAssociationCmd_Get = 0x02,
41
+ MultiInstanceAssociationCmd_Report = 0x03,
42
+ MultiInstanceAssociationCmd_Remove = 0x04,
43
+ MultiInstanceAssociationCmd_GroupingsGet = 0x05,
44
+ MultiInstanceAssociationCmd_GroupingsReport = 0x06
45
+ };
46
+
47
+
48
+ //-----------------------------------------------------------------------------
49
+ // <MultiInstanceAssociation::HandleMsg>
50
+ // Handle a message from the Z-Wave network
51
+ //-----------------------------------------------------------------------------
52
+ bool MultiInstanceAssociation::HandleMsg
53
+ (
54
+ uint8 const* _data,
55
+ uint32 const _length,
56
+ uint32 const _instance // = 1
57
+ )
58
+ {
59
+ return false;
60
+ }
61
+
@@ -0,0 +1,59 @@
1
+ //-----------------------------------------------------------------------------
2
+ //
3
+ // MultiInstanceAssociation.h
4
+ //
5
+ // Implementation of the Z-Wave COMMAND_CLASS_MULTI_INSTANCE_ASSOCIATION
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 _MultiInstanceAssociation_H
29
+ #define _MultiInstanceAssociation_H
30
+
31
+ #include <vector>
32
+ #include "CommandClass.h"
33
+
34
+ namespace OpenZWave
35
+ {
36
+ /** \brief Implements COMMAND_CLASS_MULTI_INSTANCE_ASSOCIATION (0x8E), a Z-Wave device command class.
37
+ */
38
+ class MultiInstanceAssociation: public CommandClass
39
+ {
40
+ public:
41
+ static CommandClass* Create( uint32 const _homeId, uint8 const _nodeId ){ return new MultiInstanceAssociation( _homeId, _nodeId ); }
42
+ virtual ~MultiInstanceAssociation(){}
43
+
44
+ static uint8 const StaticGetCommandClassId(){ return 0x8e; }
45
+ static string const StaticGetCommandClassName(){ return "COMMAND_CLASS_MULTI_INSTANCE_ASSOCIATION"; }
46
+
47
+ // From CommandClass
48
+ virtual uint8 const GetCommandClassId()const{ return StaticGetCommandClassId(); }
49
+ virtual string const GetCommandClassName()const{ return StaticGetCommandClassName(); }
50
+ virtual bool HandleMsg( uint8 const* _data, uint32 const _length, uint32 const _instance = 1 );
51
+
52
+ private:
53
+ MultiInstanceAssociation( uint32 const _homeId, uint8 const _nodeId ): CommandClass( _homeId, _nodeId ){}
54
+ };
55
+
56
+ } // namespace OpenZWave
57
+
58
+ #endif
59
+
@@ -0,0 +1,525 @@
1
+ //-----------------------------------------------------------------------------
2
+ //
3
+ // NodeNaming.cpp
4
+ //
5
+ // Implementation of the Z-Wave COMMAND_CLASS_NODE_NAMING
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
+ #include "CommandClasses.h"
29
+ #include "NodeNaming.h"
30
+ #include "Association.h"
31
+ #include "Defs.h"
32
+ #include "Msg.h"
33
+ #include "Node.h"
34
+ #include "Driver.h"
35
+ #include "Log.h"
36
+ #include "Notification.h"
37
+
38
+ using namespace OpenZWave;
39
+
40
+ enum NodeNamingCmd
41
+ {
42
+ NodeNamingCmd_Set = 0x01,
43
+ NodeNamingCmd_Get = 0x02,
44
+ NodeNamingCmd_Report = 0x03,
45
+ NodeNamingCmd_LocationSet = 0x04,
46
+ NodeNamingCmd_LocationGet = 0x05,
47
+ NodeNamingCmd_LocationReport = 0x06
48
+ };
49
+
50
+ enum StringEncoding
51
+ {
52
+ StringEncoding_ASCII = 0,
53
+ StringEncoding_ExtendedASCII,
54
+ StringEncoding_UTF16
55
+ };
56
+
57
+ // Mapping of characters 0x80 and above to Unicode.
58
+ uint16 const c_extendedAsciiToUnicode[] =
59
+ {
60
+ 0x20ac, // 0x80 - Euro Sign
61
+ 0x0081, // 0x81 -
62
+ 0x201a, // 0x82 - Single Low-9 Quotation Mark
63
+ 0x0192, // 0x83 - Latin Small Letter F With Hook
64
+ 0x201e, // 0x84 - Double Low-9 Quotation Mark
65
+ 0x2026, // 0x85 - Horizontal Ellipsis
66
+ 0x2020, // 0x86 - Dagger
67
+ 0x2021, // 0x87 - Double Dagger
68
+ 0x02c6, // 0x88 - Modifier Letter Circumflex Accent
69
+ 0x2030, // 0x89 - Per Mille Sign
70
+ 0x0160, // 0x8a - Latin Capital Letter S With Caron
71
+ 0x2039, // 0x8b - Single Left-Pointing Angle Quotation Mark
72
+ 0x0152, // 0x8c - Latin Capital Ligature Oe
73
+ 0x008d, // 0x8d -
74
+ 0x017d, // 0x8e - Latin Capital Letter Z With Caron
75
+ 0x008f, // 0x8f -
76
+
77
+ 0x0090, // 0x90 -
78
+ 0x2018, // 0x91 - Left Single Quotation Mark
79
+ 0x2019, // 0x92 - Right Single Quotation Mark
80
+ 0x201c, // 0x93 - Left Double Quotation Mark
81
+ 0x201d, // 0x94 - Right Double Quotation Mark
82
+ 0x2022, // 0x95 - Bullet
83
+ 0x2013, // 0x96 - En Dash
84
+ 0x2014, // 0x97 - Em Dash
85
+ 0x02dc, // 0x98 - Small Tilde
86
+ 0x2122, // 0x99 - Trade Mark Sign
87
+ 0x0161, // 0x9a - Latin Small Letter S With Caron
88
+ 0x203a, // 0x9b - Single Right-Pointing Angle Quotation Mark
89
+ 0x0153, // 0x9c - Latin Small Ligature Oe
90
+ 0x009d, // 0x9d -
91
+ 0x017e, // 0x9e - Latin Small Letter Z With Caron
92
+ 0x0178, // 0x9f - Latin Capital Letter Y With Diaeresis
93
+
94
+ 0x00a0, // 0xa0 - No-Break Space
95
+ 0x00a1, // 0xa1 - Inverted Exclamation Mark
96
+ 0x00a2, // 0xa2 - Cent Sign
97
+ 0x00a3, // 0xa3 - Pound Sign
98
+ 0x00a4, // 0xa4 - Currency Sign
99
+ 0x00a5, // 0xa5 - Yen Sign
100
+ 0x00a6, // 0xa6 - Broken Bar
101
+ 0x00a7, // 0xa7 - Section Sign
102
+ 0x00a8, // 0xa8 - Diaeresis
103
+ 0x00a9, // 0xa9 - Copyright Sign
104
+ 0x00aa, // 0xaa - Feminine Ordinal Indicator
105
+ 0x00ab, // 0xab - Left-Pointing Double Angle Quotation Mark
106
+ 0x00ac, // 0xac - Not Sign
107
+ 0x00ad, // 0xad - Soft Hyphen
108
+ 0x00ae, // 0xae - Registered Sign
109
+ 0x00af, // 0xaf - Macron
110
+
111
+ 0x00b0, // 0xb0 - Degree Sign
112
+ 0x00b1, // 0xb1 - Plus-Minus Sign
113
+ 0x00b2, // 0xb2 - Superscript Two
114
+ 0x00b3, // 0xb3 - Superscript Three
115
+ 0x00b4, // 0xb4 - Acute Accent
116
+ 0x00b5, // 0xb5 - Micro Sign
117
+ 0x00b6, // 0xb6 - Pilcrow Sign
118
+ 0x00b7, // 0xb7 - Middle Dot
119
+ 0x00b8, // 0xb8 - Cedilla
120
+ 0x00b9, // 0xb9 - Superscript One
121
+ 0x00ba, // 0xba - Masculine Ordinal Indicator
122
+ 0x00bb, // 0xbb - Right-Pointing Double Angle Quotation Mark
123
+ 0x00bc, // 0xbc - Vulgar Fraction One Quarter
124
+ 0x00bd, // 0xbd - Vulgar Fraction One Half
125
+ 0x00be, // 0xbe - Vulgar Fraction Three Quarters
126
+ 0x00bf, // 0xbf - Inverted Question Mark
127
+
128
+ 0x00c0, // 0xc0 - Latin Capital Letter A With Grave
129
+ 0x00c1, // 0xc1 - Latin Capital Letter A With Acute
130
+ 0x00c2, // 0xc2 - Latin Capital Letter A With Circumflex
131
+ 0x00c3, // 0xc3 - Latin Capital Letter A With Tilde
132
+ 0x00c4, // 0xc4 - Latin Capital Letter A With Diaeresis
133
+ 0x00c5, // 0xc5 - Latin Capital Letter A With Ring Above
134
+ 0x00c6, // 0xc6 - Latin Capital Ligature Ae
135
+ 0x00c7, // 0xc7 - Latin Capital Letter C With Cedilla
136
+ 0x00c8, // 0xc8 - Latin Capital Letter E With Grave
137
+ 0x00c9, // 0xc9 - Latin Capital Letter E With Acute
138
+ 0x00ca, // 0xca - Latin Capital Letter E With Circumflex
139
+ 0x00cb, // 0xcb - Latin Capital Letter E With Diaeresis
140
+ 0x00cc, // 0xcc - Latin Capital Letter I With Grave
141
+ 0x00cd, // 0xcd - Latin Capital Letter I With Acute
142
+ 0x00ce, // 0xce - Latin Capital Letter I With Circumflex
143
+ 0x00cf, // 0xcf - Latin Capital Letter I With Diaeresis
144
+
145
+ 0x00d0, // 0xd0 - Latin Capital Letter Eth
146
+ 0x00d1, // 0xd1 - Latin Capital Letter N With Tilde
147
+ 0x00d2, // 0xd2 - Latin Capital Letter O With Grave
148
+ 0x00d3, // 0xd3 - Latin Capital Letter O With Acute
149
+ 0x00d4, // 0xd4 - Latin Capital Letter O With Circumflex
150
+ 0x00d5, // 0xd5 - Latin Capital Letter O With Tilde
151
+ 0x00d6, // 0xd6 - Latin Capital Letter O With Diaeresis
152
+ 0x00d7, // 0xd7 - Multiplication Sign
153
+ 0x00d8, // 0xd8 - Latin Capital Letter O With Stroke
154
+ 0x00d9, // 0xd9 - Latin Capital Letter U With Grave
155
+ 0x00da, // 0xda - Latin Capital Letter U With Acute
156
+ 0x00db, // 0xdb - Latin Capital Letter U With Circumflex
157
+ 0x00dc, // 0xdc - Latin Capital Letter U With Diaeresis
158
+ 0x00dd, // 0xdd - Latin Capital Letter Y With Acute
159
+ 0x00de, // 0xde - Latin Capital Letter Thorn
160
+ 0x00df, // 0xdf - Latin Small Letter Sharp S
161
+
162
+ 0x00e0, // 0xe0 - Latin Small Letter A With Grave
163
+ 0x00e1, // 0xe1 - Latin Small Letter A With Acute
164
+ 0x00e2, // 0xe2 - Latin Small Letter A With Circumflex
165
+ 0x00e3, // 0xe3 - Latin Small Letter A With Tilde
166
+ 0x00e4, // 0xe4 - Latin Small Letter A With Diaeresis
167
+ 0x00e5, // 0xe5 - Latin Small Letter A With Ring Above
168
+ 0x00e6, // 0xe6 - Latin Small Ligature Ae
169
+ 0x00e7, // 0xe7 - Latin Small Letter C With Cedilla
170
+ 0x00e8, // 0xe8 - Latin Small Letter E With Grave
171
+ 0x00e9, // 0xe9 - Latin Small Letter E With Acute
172
+ 0x00ea, // 0xea - Latin Small Letter E With Circumflex
173
+ 0x00eb, // 0xeb - Latin Small Letter E With Diaeresis
174
+ 0x00ec, // 0xec - Latin Small Letter I With Grave
175
+ 0x00ed, // 0xed - Latin Small Letter I With Acute
176
+ 0x00ee, // 0xee - Latin Small Letter I With Circumflex
177
+ 0x00ef, // 0xef - Latin Small Letter I With Diaeresis
178
+
179
+ 0x00f0, // 0xf0 - Latin Small Letter Eth
180
+ 0x00f1, // 0xf1 - Latin Small Letter N With Tilde
181
+ 0x00f2, // 0xf2 - Latin Small Letter O With Grave
182
+ 0x00f3, // 0xf3 - Latin Small Letter O With Acute
183
+ 0x00f4, // 0xf4 - Latin Small Letter O With Circumflex
184
+ 0x00f5, // 0xf5 - Latin Small Letter O With Tilde
185
+ 0x00f6, // 0xf6 - Latin Small Letter O With Diaeresis
186
+ 0x00f7, // 0xf7 - Division Sign
187
+ 0x00f8, // 0xf8 - Latin Small Letter O With Stroke
188
+ 0x00f9, // 0xf9 - Latin Small Letter U With Grave
189
+ 0x00fa, // 0xfa - Latin Small Letter U With Acute
190
+ 0x00fb, // 0xfb - Latin Small Letter U With Circumflex
191
+ 0x00fc, // 0xfc - Latin Small Letter U With Diaeresis
192
+ 0x00fd, // 0xfd - Latin Small Letter Y With Acute
193
+ 0x00fe, // 0xfe - Latin Small Letter Thorn
194
+ 0x00ff // 0xff - Latin Small Letter Y With Diaeresis
195
+ };
196
+
197
+ //-----------------------------------------------------------------------------
198
+ // <NodeNaming::RequestState>
199
+ // Request current state from the device
200
+ //-----------------------------------------------------------------------------
201
+ bool NodeNaming::RequestState
202
+ (
203
+ uint32 const _requestFlags,
204
+ uint8 const _instance,
205
+ Driver::MsgQueue const _queue
206
+ )
207
+ {
208
+ bool res = false;
209
+ if( _requestFlags & RequestFlag_Session )
210
+ {
211
+ if( Node* node = GetNodeUnsafe() )
212
+ {
213
+ if( node->m_nodeName == "" )
214
+ {
215
+ // If we don't already have a user-defined name, fetch it from the device
216
+ res |= RequestValue( _requestFlags, NodeNamingCmd_Get, _instance, _queue );
217
+ }
218
+
219
+ if( node->m_location == "" )
220
+ {
221
+ // If we don't already have a user-defined location, fetch it from the device
222
+ res |= RequestValue( _requestFlags, NodeNamingCmd_LocationGet, _instance, _queue );
223
+ }
224
+ }
225
+ }
226
+
227
+ return res;
228
+ }
229
+
230
+ //-----------------------------------------------------------------------------
231
+ // <NodeNaming::RequestValue>
232
+ // Request current value from the device
233
+ //-----------------------------------------------------------------------------
234
+ bool NodeNaming::RequestValue
235
+ (
236
+ uint32 const _requestFlags,
237
+ uint8 const _getTypeEnum,
238
+ uint8 const _instance,
239
+ Driver::MsgQueue const _queue
240
+ )
241
+ {
242
+ if( _instance != 1 )
243
+ {
244
+ // This command class doesn't work with multiple instances
245
+ return false;
246
+ }
247
+
248
+ Msg* msg;
249
+ if( _getTypeEnum == NodeNamingCmd_Get )
250
+ {
251
+ msg = new Msg( "NodeNamingCmd_Get", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true, true, FUNC_ID_APPLICATION_COMMAND_HANDLER, GetCommandClassId() );
252
+ msg->Append( GetNodeId() );
253
+ msg->Append( 2 );
254
+ msg->Append( GetCommandClassId() );
255
+ msg->Append( NodeNamingCmd_Get );
256
+ msg->Append( TRANSMIT_OPTION_ACK | TRANSMIT_OPTION_AUTO_ROUTE );
257
+ GetDriver()->SendMsg( msg, _queue );
258
+ return true;
259
+ }
260
+
261
+ if( _getTypeEnum == NodeNamingCmd_LocationGet )
262
+ {
263
+ // If we don't already have a user-defined name, fetch it from the device
264
+ msg = new Msg( "NodeNamingCmd_LocationGet", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true, true, FUNC_ID_APPLICATION_COMMAND_HANDLER, GetCommandClassId() );
265
+ msg->Append( GetNodeId() );
266
+ msg->Append( 2 );
267
+ msg->Append( GetCommandClassId() );
268
+ msg->Append( NodeNamingCmd_LocationGet );
269
+ msg->Append( TRANSMIT_OPTION_ACK | TRANSMIT_OPTION_AUTO_ROUTE );
270
+ GetDriver()->SendMsg( msg, _queue );
271
+ return true;
272
+ }
273
+ return false;
274
+ }
275
+
276
+ //-----------------------------------------------------------------------------
277
+ // <NodeNaming::HandleMsg>
278
+ // Handle a message from the Z-Wave network
279
+ //-----------------------------------------------------------------------------
280
+ bool NodeNaming::HandleMsg
281
+ (
282
+ uint8 const* _data,
283
+ uint32 const _length,
284
+ uint32 const _instance // = 1
285
+ )
286
+ {
287
+ bool updated = false;
288
+ if( Node* node = GetNodeUnsafe() )
289
+ {
290
+ if( NodeNamingCmd_Report == (NodeNamingCmd)_data[0] )
291
+ {
292
+ string name = ExtractString( _data, _length );
293
+ if( node->m_nodeName == "" )
294
+ {
295
+ // We only overwrite the name if it is empty
296
+ node->m_nodeName = name;
297
+ Log::Write( LogLevel_Info, GetNodeId(), "Received the name: %s.", name.c_str() );
298
+ updated = true;
299
+ }
300
+ }
301
+ else if( NodeNamingCmd_LocationReport == (NodeNamingCmd)_data[0] )
302
+ {
303
+ string location = ExtractString( _data, _length );
304
+ if( node->m_location == "" )
305
+ {
306
+ // We only overwrite the location if it is empty
307
+ node->m_location = location;
308
+ Log::Write( LogLevel_Info, GetNodeId(), "Received the location: %s.", location.c_str() );
309
+ updated = true;
310
+ }
311
+ }
312
+ }
313
+
314
+ if( updated )
315
+ {
316
+ Notification* notification = new Notification( Notification::Type_NodeNaming );
317
+ notification->SetHomeAndNodeIds( GetHomeId(), GetNodeId() );
318
+ GetDriver()->QueueNotification( notification );
319
+ }
320
+
321
+ return true;
322
+ }
323
+
324
+ //-----------------------------------------------------------------------------
325
+ // <NodeNaming::SetName>
326
+ // Set the name in the device
327
+ //-----------------------------------------------------------------------------
328
+ void NodeNaming::SetName
329
+ (
330
+ string const& _name
331
+ )
332
+ {
333
+ uint32 length = _name.size();
334
+ if( length > 16 )
335
+ {
336
+ length = 16;
337
+ }
338
+
339
+ Log::Write( LogLevel_Info, GetNodeId(), "NodeNaming::Set - Naming to '%s'", _name.c_str() );
340
+ Msg* msg = new Msg( "NodeNaming Set", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true );
341
+ msg->Append( GetNodeId() );
342
+ msg->Append( (uint8)(length + 3) );
343
+ msg->Append( GetCommandClassId() );
344
+ msg->Append( NodeNamingCmd_Set );
345
+ msg->Append( (uint8)StringEncoding_ASCII );
346
+
347
+ for( uint32 i=0; i<length; ++i )
348
+ {
349
+ msg->Append( _name[i] );
350
+ }
351
+
352
+ msg->Append( TRANSMIT_OPTION_ACK | TRANSMIT_OPTION_AUTO_ROUTE );
353
+ GetDriver()->SendMsg( msg, Driver::MsgQueue_Send );
354
+ }
355
+
356
+ //-----------------------------------------------------------------------------
357
+ // <NodeNaming::SetLocation>
358
+ // Set the location in the device
359
+ //-----------------------------------------------------------------------------
360
+ void NodeNaming::SetLocation
361
+ (
362
+ string const& _location
363
+ )
364
+ {
365
+ uint32 length = _location.size();
366
+ if( length > 16 )
367
+ {
368
+ length = 16;
369
+ }
370
+
371
+ Log::Write( LogLevel_Info, GetNodeId(), "NodeNaming::SetLocation - Setting location to '%s'", _location.c_str() );
372
+ Msg* msg = new Msg( "NodeNaming Set", GetNodeId(), REQUEST, FUNC_ID_ZW_SEND_DATA, true );
373
+ msg->Append( GetNodeId() );
374
+ msg->Append( (uint8)(length + 3) );
375
+ msg->Append( GetCommandClassId() );
376
+ msg->Append( NodeNamingCmd_LocationSet );
377
+ msg->Append( (uint8)StringEncoding_ASCII );
378
+
379
+ for( uint32 i=0; i<length; ++i )
380
+ {
381
+ msg->Append( _location[i] );
382
+ }
383
+
384
+ msg->Append( TRANSMIT_OPTION_ACK | TRANSMIT_OPTION_AUTO_ROUTE );
385
+ GetDriver()->SendMsg( msg, Driver::MsgQueue_Send );
386
+ }
387
+
388
+ //-----------------------------------------------------------------------------
389
+ // <NodeNaming::ExtractString>
390
+ // Extract a string from the report data
391
+ //-----------------------------------------------------------------------------
392
+ string NodeNaming::ExtractString
393
+ (
394
+ uint8 const* _data,
395
+ uint32 const _length
396
+ )
397
+ {
398
+ uint8 i;
399
+ char str[32];
400
+ uint32 pos = 0;
401
+
402
+ str[0] = 0;
403
+ StringEncoding encoding = (StringEncoding)( _data[1] & 0x07 );
404
+
405
+ if( _length >= 3 )
406
+ {
407
+ // Get the length of the string (maximum allowed is 16 bytes)
408
+ uint8 numBytes = _length - 3;
409
+ if( numBytes > 16 )
410
+ {
411
+ numBytes = 16;
412
+ }
413
+
414
+ switch( encoding )
415
+ {
416
+ case StringEncoding_ASCII:
417
+ {
418
+ // Copy data as-is
419
+ for( i=0; i<numBytes; ++i )
420
+ {
421
+ str[pos++] = _data[i+2];
422
+ }
423
+ break;
424
+ }
425
+ case StringEncoding_ExtendedASCII:
426
+ {
427
+ // Convert Extended ASCII characters to UTF-8
428
+ for( i=0; i<numBytes; ++i )
429
+ {
430
+ uint8 ch = _data[i+2];
431
+ if( ch >= 0x80 )
432
+ {
433
+ uint16 utf16 = c_extendedAsciiToUnicode[ch-0x80];
434
+ pos = ConvertUFT16ToUTF8( utf16, str, pos );
435
+ }
436
+ else
437
+ {
438
+ str[pos++] = (char)ch;
439
+ }
440
+ }
441
+ break;
442
+ }
443
+ case StringEncoding_UTF16:
444
+ {
445
+ // Convert UTF-16 characters to UTF-8
446
+ for( i=0; i<numBytes; i+=2 )
447
+ {
448
+ uint16 utf16 = (((uint16)_data[i+2])<<8) | (uint16)_data[i+3];
449
+ pos = ConvertUFT16ToUTF8( utf16, str, pos );
450
+ }
451
+ break;
452
+ }
453
+ default:
454
+ {
455
+ }
456
+ }
457
+
458
+ str[pos] = 0;
459
+ }
460
+
461
+ return string( str );
462
+ }
463
+
464
+ //-----------------------------------------------------------------------------
465
+ // <NodeNaming::ConvertUFT16ToUTF8>
466
+ // Convert a UTF-16 string into UTF-8 encoding.
467
+ //-----------------------------------------------------------------------------
468
+ uint32 NodeNaming::ConvertUFT16ToUTF8
469
+ (
470
+ uint16 _utf16,
471
+ char* _buffer,
472
+ uint32 pos
473
+ )
474
+ {
475
+ static uint16 surrogate = 0;
476
+
477
+ if( ( surrogate != 0 ) && ( ( _utf16 & 0xdc00 ) == 0xdc00 ) )
478
+ {
479
+ // UTF-16 surrogate character pair converts to four UTF-8 characters.
480
+ // We have the second member of the pair, so we can do the conversion now.
481
+ _buffer[pos++] = (char)( ((surrogate>>7) & 0x0007) | 0x00f0 );
482
+ _buffer[pos++] = (char)( ((surrogate>>1) & 0x0020) | ((surrogate>>2) & 0x000f) | 0x0090 );
483
+ _buffer[pos++] = (char)( ((_utf16>>6) & 0x000f) | ((surrogate<<4) & 0x0030) | 0x0080 );
484
+ _buffer[pos++] = (char)( (_utf16 & 0x003f) | 0x0080 );
485
+ }
486
+ else
487
+ {
488
+ surrogate = 0;
489
+ if( _utf16 & 0xff80 )
490
+ {
491
+ if( _utf16 & 0xf800 )
492
+ {
493
+ if( ( _utf16 & 0xd800 ) == 0xd800 )
494
+ {
495
+ // UTF-16 surrogate character pair converts to four UTF-8 characters.
496
+ // We have the first member of the pair, so we store it for next time.
497
+ surrogate = _utf16;
498
+ }
499
+ else
500
+ {
501
+ // UTF-16 character can be represented by three UTF-8 characters.
502
+ _buffer[pos++] = (char)( (_utf16>>12) | 0x00e0 );
503
+ _buffer[pos++] = (char)( ((_utf16>>6) & 0x003f) | 0x0080 );
504
+ _buffer[pos++] = (char)( (_utf16 & 0x003f) | 0x0080 );
505
+ }
506
+ }
507
+ else
508
+ {
509
+ // UTF-16 character can be represented by two UTF-8 characters.
510
+ _buffer[pos++] = (char)( (_utf16>>6) | 0x00c0 );
511
+ _buffer[pos++] = (char)( (_utf16 & 0x003f) | 0x0080 );
512
+ }
513
+ }
514
+ else
515
+ {
516
+ // UTF-16 character matches single ascii character.
517
+ _buffer[pos++] = (char)_utf16;
518
+ }
519
+ }
520
+
521
+ return pos;
522
+ }
523
+
524
+
525
+