Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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