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,180 @@
1
+ //-----------------------------------------------------------------------------
2
+ //
3
+ // SerialController.h
4
+ //
5
+ // Cross-platform serial port handler
6
+ //
7
+ // Copyright (c) 2010 Jason Frazier <frazierjason@gmail.com>
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 "Event.h"
29
+ #include "Thread.h"
30
+ #include "Msg.h"
31
+ #include "SerialController.h"
32
+ #include "SerialControllerImpl.h" // Platform-specific implementation of a serial port
33
+ #include "Log.h"
34
+
35
+ using namespace OpenZWave;
36
+
37
+
38
+ //-----------------------------------------------------------------------------
39
+ // <SerialController::SerialController>
40
+ // Constructor
41
+ //-----------------------------------------------------------------------------
42
+ SerialController::SerialController
43
+ (
44
+ ):
45
+ m_baud ( 115200 ),
46
+ m_parity ( SerialController::Parity_None ),
47
+ m_stopBits ( SerialController::StopBits_One ),
48
+ m_bOpen( false )
49
+ {
50
+ m_pImpl = new SerialControllerImpl( this );
51
+ }
52
+
53
+ //-----------------------------------------------------------------------------
54
+ // <SerialController::~SerialController>
55
+ // Destructor
56
+ //-----------------------------------------------------------------------------
57
+ SerialController::~SerialController
58
+ (
59
+ )
60
+ {
61
+ delete m_pImpl;
62
+ }
63
+
64
+ //-----------------------------------------------------------------------------
65
+ // <SerialController::SetBaud>
66
+ // Set the serial port baud rate.
67
+ // The serial port must be closed for the setting to be accepted.
68
+ //-----------------------------------------------------------------------------
69
+ bool SerialController::SetBaud
70
+ (
71
+ uint32 const _baud
72
+ )
73
+ {
74
+ if( m_bOpen )
75
+ {
76
+ return false;
77
+ }
78
+
79
+ m_baud = _baud;
80
+ return true;
81
+ }
82
+
83
+ //-----------------------------------------------------------------------------
84
+ // <SerialController::SetParity>
85
+ // Set the serial port parity.
86
+ // The serial port must be closed for the setting to be accepted.
87
+ //-----------------------------------------------------------------------------
88
+ bool SerialController::SetParity
89
+ (
90
+ Parity const _parity
91
+ )
92
+ {
93
+ if( m_bOpen )
94
+ {
95
+ return false;
96
+ }
97
+
98
+ m_parity = _parity;
99
+ return true;
100
+ }
101
+
102
+ //-----------------------------------------------------------------------------
103
+ // <SerialController::SetStopBits>
104
+ // Set the serial port stop bits.
105
+ // The serial port must be closed for the setting to be accepted.
106
+ //-----------------------------------------------------------------------------
107
+ bool SerialController::SetStopBits
108
+ (
109
+ StopBits const _stopBits
110
+ )
111
+ {
112
+ if( m_bOpen )
113
+ {
114
+ return false;
115
+ }
116
+
117
+ m_stopBits = _stopBits;
118
+ return true;
119
+ }
120
+
121
+ //-----------------------------------------------------------------------------
122
+ // <SerialController::Open>
123
+ // Open and configure a serial port
124
+ //-----------------------------------------------------------------------------
125
+ bool SerialController::Open
126
+ (
127
+ string const& _serialControllerName
128
+ )
129
+ {
130
+ if( m_bOpen )
131
+ {
132
+ return false;
133
+ }
134
+
135
+ m_serialControllerName = _serialControllerName;
136
+ m_bOpen = m_pImpl->Open();
137
+ return m_bOpen;
138
+ }
139
+
140
+ //-----------------------------------------------------------------------------
141
+ // <SerialController::Close>
142
+ // Close a serial port
143
+ //-----------------------------------------------------------------------------
144
+ bool SerialController::Close
145
+ (
146
+ )
147
+ {
148
+ if( !m_bOpen )
149
+ {
150
+ return false;
151
+ }
152
+
153
+ m_pImpl->Close();
154
+ m_bOpen = false;
155
+ return true;
156
+ }
157
+
158
+ //-----------------------------------------------------------------------------
159
+ // <SerialController::Write>
160
+ // Write data to an open serial port
161
+ //-----------------------------------------------------------------------------
162
+ uint32 SerialController::Write
163
+ (
164
+ uint8* _buffer,
165
+ uint32 _length
166
+ )
167
+ {
168
+ if( !m_bOpen )
169
+ {
170
+ return 0;
171
+ }
172
+
173
+ Log::Write( LogLevel_Debug, " SerialController::Write (sent to controller)" );
174
+ LogData(_buffer, _length, " Write: ");
175
+
176
+ return( m_pImpl->Write( _buffer, _length ) );
177
+ }
178
+
179
+
180
+
@@ -0,0 +1,138 @@
1
+ //-----------------------------------------------------------------------------
2
+ //
3
+ // SerialController.h
4
+ //
5
+ // Cross-platform serial port handler
6
+ //
7
+ // Copyright (c) 2010 Jason Frazier <frazierjason@gmail.com>
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 _SerialController_H
29
+ #define _SerialController_H
30
+
31
+ #include <string>
32
+ #include "Defs.h"
33
+ #include "Controller.h"
34
+
35
+ namespace OpenZWave
36
+ {
37
+ class Driver;
38
+ class Msg;
39
+ class SerialControllerImpl;
40
+
41
+ class SerialController: public Controller
42
+ {
43
+ friend class SerialControllerImpl;
44
+
45
+ public:
46
+ enum Parity
47
+ {
48
+ Parity_None = 0,
49
+ Parity_Odd,
50
+ Parity_Even,
51
+ Parity_Mark,
52
+ Parity_Space
53
+ };
54
+
55
+ enum StopBits
56
+ {
57
+ StopBits_One = 0,
58
+ StopBits_OneAndAHalf = 1,
59
+ StopBits_Two = 2
60
+ };
61
+
62
+ /**
63
+ * Constructor.
64
+ * Creates an object that represents a serial port.
65
+ */
66
+ SerialController();
67
+
68
+ /**
69
+ * Destructor.
70
+ * Destroys the serial port object.
71
+ */
72
+ virtual ~SerialController();
73
+
74
+ /**
75
+ * Set the serial port baud rate. The serial port must be closed for the setting to be accepted.
76
+ * @param _baud Integer containing the expected baud-rate of the serial connection. Most Z-Wave interfaces run at 115200 baud.
77
+ * @return True if the baud value was accepted.
78
+ * @see Open, Close
79
+ */
80
+ bool SetBaud( uint32 const _baud );
81
+
82
+ /**
83
+ * Set the serial port parity. The serial port must be closed for the setting to be accepted.
84
+ * @param _parity Parity enum value indicating the serial data's expected type of parity bits, if any.
85
+ * @return True if the parity value was accepted.
86
+ * @see Open, Close
87
+ */
88
+ bool SetParity( Parity const _parity );
89
+
90
+ /**
91
+ * Set the serial port stop bits. The serial port must be closed for the setting to be accepted.
92
+ * @param _stopBits StopBits enum value indicating the serial data's expected number of stop-bits.
93
+ * @return True if the stop bits value was accepted.
94
+ * @see Open, Close
95
+ */
96
+ bool SetStopBits( StopBits const _stopBits );
97
+
98
+ /**
99
+ * Open a serial port.
100
+ * Attempts to open a serial port and initialize it with the specified paramters.
101
+ * @param _SerialControllerName The name of the port to open. For example, ttyS1 on Linux, or \\.\COM2 in Windows.
102
+ * @return True if the port was opened and configured successfully.
103
+ * @see Close, Read, Write
104
+ */
105
+ bool Open( string const& _SerialControllerName );
106
+
107
+ /**
108
+ * Close a serial port.
109
+ * Closes the serial port.
110
+ * @return True if the port was closed successfully, or false if the port was already closed, or an error occurred.
111
+ * @see Open
112
+ */
113
+ bool Close();
114
+
115
+ /**
116
+ * Write to a serial port.
117
+ * Attempts to write data to an open serial port.
118
+ * @param _buffer Pointer to a block of memory containing the data to be written.
119
+ * @param _length Length in bytes of the data.
120
+ * @return The number of bytes written.
121
+ * @see Read, Open, Close
122
+ */
123
+ uint32 Write( uint8* _buffer, uint32 _length );
124
+
125
+ private:
126
+ uint32 m_baud;
127
+ SerialController::Parity m_parity;
128
+ SerialController::StopBits m_stopBits;
129
+ string m_serialControllerName;
130
+
131
+ SerialControllerImpl* m_pImpl; // Pointer to an object that encapsulates the platform-specific implementation of the serial port.
132
+ bool m_bOpen;
133
+ };
134
+
135
+ } // namespace OpenZWave
136
+
137
+ #endif //_SerialController_H
138
+
@@ -0,0 +1,229 @@
1
+ //-----------------------------------------------------------------------------
2
+ //
3
+ // Stream.h
4
+ //
5
+ // Cross-platform circular buffer with signalling
6
+ //
7
+ // Copyright (c) 2010 Mal Lansell <mal@lansell.org>
8
+ // All rights reserved.
9
+ //
10
+ // SOFTWARE NOTICE AND LICENSE
11
+ //
12
+ // This file is part of OpenZWave.
13
+ //
14
+ // OpenZWave is free software: you can redistribute it and/or modify
15
+ // it under the terms of the GNU Lesser General Public License as published
16
+ // by the Free Software Foundation, either version 3 of the License,
17
+ // or (at your option) any later version.
18
+ //
19
+ // OpenZWave is distributed in the hope that it will be useful,
20
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ // GNU Lesser General Public License for more details.
23
+ //
24
+ // You should have received a copy of the GNU Lesser General Public License
25
+ // along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
26
+ //
27
+ //-----------------------------------------------------------------------------
28
+ #include "Stream.h"
29
+ #include "Mutex.h"
30
+ #include "Log.h"
31
+
32
+ #include <string.h>
33
+
34
+ #include <cstdio>
35
+
36
+ using namespace OpenZWave;
37
+
38
+ //-----------------------------------------------------------------------------
39
+ // <Stream::Stream>
40
+ // Constructor
41
+ //-----------------------------------------------------------------------------
42
+ Stream::Stream
43
+ (
44
+ uint32 _bufferSize
45
+ ):
46
+ m_bufferSize( _bufferSize ),
47
+ m_signalSize(1),
48
+ m_dataSize(0),
49
+ m_head(0),
50
+ m_tail(0),
51
+ m_mutex( new Mutex() )
52
+ {
53
+ m_buffer = new uint8[m_bufferSize];
54
+ }
55
+
56
+ //-----------------------------------------------------------------------------
57
+ // <Stream::~Stream>
58
+ // Destructor
59
+ //-----------------------------------------------------------------------------
60
+ Stream::~Stream
61
+ (
62
+ )
63
+ {
64
+ m_mutex->Release();
65
+ delete [] m_buffer;
66
+ }
67
+
68
+ //-----------------------------------------------------------------------------
69
+ // <Stream::SetSignalThreshold>
70
+ // Set the amount of data that must be in the buffer for to to be signalled
71
+ //-----------------------------------------------------------------------------
72
+ void Stream::SetSignalThreshold
73
+ (
74
+ uint32 _size
75
+ )
76
+ {
77
+ m_signalSize = _size;
78
+ if( IsSignalled() )
79
+ {
80
+ // We have more data than we are waiting for, so notify the watchers
81
+ Notify();
82
+ }
83
+ }
84
+
85
+ //-----------------------------------------------------------------------------
86
+ // <Stream::Get>
87
+ // Remove data from the buffer
88
+ //-----------------------------------------------------------------------------
89
+ bool Stream::Get
90
+ (
91
+ uint8* _buffer,
92
+ uint32 _size
93
+ )
94
+ {
95
+ if( m_dataSize < _size )
96
+ {
97
+ // There is not enough data in the buffer to fulfill the request
98
+ Log::Write( LogLevel_Error, "ERROR: Not enough data in stream buffer");
99
+ return false;
100
+ }
101
+
102
+ m_mutex->Lock();
103
+ if( (m_tail + _size) > m_bufferSize )
104
+ {
105
+ // We will have to wrap around
106
+ uint32 block1 = m_bufferSize - m_tail;
107
+ uint32 block2 = _size - block1;
108
+
109
+ memcpy( _buffer, &m_buffer[m_tail], block1 );
110
+ memcpy( &_buffer[block1], m_buffer, block2 );
111
+ m_tail = block2;
112
+ }
113
+ else
114
+ {
115
+ // Requested data is in a contiguous block
116
+ memcpy( _buffer, &m_buffer[m_tail], _size );
117
+ m_tail += _size;
118
+ }
119
+
120
+ Log::Write( LogLevel_Debug, " Stream::Get (provided to application)" );
121
+ LogData( _buffer, _size, " Get: ");
122
+
123
+ m_dataSize -= _size;
124
+ m_mutex->Unlock();
125
+ return true;
126
+ }
127
+
128
+ //-----------------------------------------------------------------------------
129
+ // <Stream::Put>
130
+ // Add data to the buffer
131
+ //-----------------------------------------------------------------------------
132
+ bool Stream::Put
133
+ (
134
+ uint8* _buffer,
135
+ uint32 _size
136
+ )
137
+ {
138
+ if( (m_bufferSize-m_dataSize) < _size )
139
+ {
140
+ // There is not enough space left in the buffer for the data
141
+ Log::Write( LogLevel_Error, "ERROR: Not enough space in stream buffer");
142
+ return false;
143
+ }
144
+
145
+ m_mutex->Lock();
146
+ Log::Write( LogLevel_Debug, " Stream::Put (received from controller)" );
147
+ if( (m_head + _size) > m_bufferSize )
148
+ {
149
+ // We will have to wrap around
150
+ uint32 block1 = m_bufferSize - m_head;
151
+ uint32 block2 = _size - block1;
152
+
153
+ memcpy( &m_buffer[m_head], _buffer, block1 );
154
+ memcpy( m_buffer, &_buffer[block1], block2 );
155
+ m_head = block2;
156
+ LogData( m_buffer + m_head - block1, block1, " Put: ");
157
+ LogData( m_buffer, block2, " Put: ");
158
+ }
159
+ else
160
+ {
161
+ // There is enough space before we reach the end of the buffer
162
+ memcpy( &m_buffer[m_head], _buffer, _size );
163
+ m_head += _size;
164
+ LogData(m_buffer+m_head-_size, _size, " Put: ");
165
+ }
166
+
167
+ m_dataSize += _size;
168
+
169
+ if( IsSignalled() )
170
+ {
171
+ // We now have more data than we are waiting for, so notify the watchers
172
+ Notify();
173
+ }
174
+
175
+ m_mutex->Unlock();
176
+ return true;
177
+ }
178
+
179
+ //-----------------------------------------------------------------------------
180
+ // <Stream::Purge>
181
+ // Empty the data buffer
182
+ //-----------------------------------------------------------------------------
183
+ void Stream::Purge
184
+ (
185
+ )
186
+ {
187
+ m_tail = 0;
188
+ m_head = 0;
189
+ m_dataSize = 0;
190
+ }
191
+
192
+ //-----------------------------------------------------------------------------
193
+ // <Stream::IsSignalled>
194
+ // Test whether there is enough data to be signalled
195
+ //-----------------------------------------------------------------------------
196
+ bool Stream::IsSignalled
197
+ (
198
+ )
199
+ {
200
+ return( m_dataSize >= m_signalSize );
201
+ }
202
+
203
+ //-----------------------------------------------------------------------------
204
+ // <Stream::LogData>
205
+ // Format the stream buffer data for log output
206
+ //-----------------------------------------------------------------------------
207
+ void Stream::LogData
208
+ (
209
+ uint8* _buffer,
210
+ uint32 _length,
211
+ string _function
212
+ )
213
+ {
214
+ if( !_length ) return;
215
+
216
+ string str = "";
217
+ for( uint32 i=0; i<_length; ++i )
218
+ {
219
+ if( i )
220
+ {
221
+ str += ", ";
222
+ }
223
+
224
+ char byteStr[8];
225
+ snprintf( byteStr, sizeof(byteStr), "0x%.2x", _buffer[i] );
226
+ str += byteStr;
227
+ }
228
+ Log::Write( LogLevel_Debug, "%s%s", _function.c_str(), str.c_str() );
229
+ }