-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathozw-monitor.rb
114 lines (100 loc) · 4.33 KB
/
ozw-monitor.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
=begin
Thrift4OZW - An Apache Thrift wrapper for OpenZWave
----------------------------------------------------
Copyright (c) 2011 Elias Karakoulakis <[email protected]>
SOFTWARE NOTICE AND LICENSE
Thrift4OZW is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
Thrift4OZW is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Thrift4OZW. If not, see <http://www.gnu.org/licenses/>.
for more information on the LGPL, see:
http://en.wikipedia.org/wiki/GNU_Lesser_General_Public_License
=end
# --------------------------
#
# monitor.rb: a rudimentary OpenZWave notification monitor
# spits out all OpenZWave activity posted by Main.cpp to STOMP server
#
# ---------------------------
require 'rubygems'
require 'onstomp'
require 'bit-struct'
require 'ozw-headers'
require 'zwave-command-classes'
#~ // ID Packing:
#~ // Bits
#~ // 24-31: 8 bits. Node ID of device
#~ // 22-23: 2 bits. genre of value (see ValueGenre enum).
#~ // 14-21: 8 bits. ID of command class that created and manages this value.
#~ // 12-13: 2 bits. Unused.
#~ // 04-11: 8 bits. Index of value within all the value created by the command class
#~ // instance (in configuration parameters, this is also the parameter ID).
#~ // 00-03: 4 bits. Type of value (bool, byte, string etc).
class OZW_EventID_id < BitStruct
unsigned :node_id, 8, "Node ID of device"
unsigned :value_genre, 2, "Value Genre"
unsigned :cmd_class, 8, "command class"
unsigned :unused1, 2, "(unused)"
unsigned :value_idx, 8, "value index"
unsigned :value_type, 4, "value type( bool, byte, string etc)"
end
#~ // ID1 Packing:
#~ // Bits
#~ // 24-31 8 bits. Instance Index of the command class.
class OZW_EventID_id1 < BitStruct
unsigned :cmd_class_idx, 8, "cmd class index"
unsigned :unused2 , 24, "(unused)"
end
threads = []
currdir = Dir.getwd.split(File::SEPARATOR)
cpp_src = File.join(currdir[0..-2], "open-zwave-read-only", "cpp", "src")
unless Dir.exists?(cpp_src)
raise "OpenZWave source directory not found!"
end
notificationtypes, valuegenres, valuetypes = parse_ozw_headers(cpp_src) # in ozw-headers.rb
#~ threads << Thread.new() {
begin
server = OnStomp.connect "stomp://localhost"
server.subscribe '/queue/zwave/monitor' do |msg|
# Invoked every time the broker delivers a MESSAGE frame for the
# SUBSCRIBE frame generated by this method call.
puts "\n------ ZWAVE MESSAGE (#{Time.now}) ------"
msg.headers.each { |hdr, val|
#puts "header: #{hdr} == #{val}"
i = 0
case hdr
when "ValueID" then
id = [val.delete(' ')[-8..-1].to_i(16)].pack("N")
id1 = [val.delete(' ')[0..-9].to_i(16)].pack("N")
#
b = OZW_EventID_id.new(id)
puts b.inspect
puts " node ID of device: #{b.node_id}"
puts " value genre: #{valuegenres[b.value_genre.to_i].join(': ')}"
puts " value type: #{valuetypes[b.value_type.to_i].join(': ')}"
puts " value idx: #{b.value_idx}"
puts " command class: #{b.cmd_class} (#{CommandClassesByID[b.cmd_class]})"
b = OZW_EventID_id1.new(id1)
puts " subcommand idx: #{b.cmd_class_idx}"
when "NotificationType" then
puts " notification type: #{notificationtypes[val.to_i(16)].join(': ')}"
else
puts " #{hdr} : #{val}"
end
}
puts " --- message body: ---\n#{msg.body}" unless msg.body.empty?
end
rescue Exception => e
puts e.inspect
puts e.backtrace.join("\n ")
#~ ensure
#~ server.disconnect
end
#~ }
#~ threads.each { |aThread| aThread.join }