tg-can-controls-gateway 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/.gitignore +7 -0
  2. data/Capfile +8 -0
  3. data/README +243 -0
  4. data/Rakefile +54 -0
  5. data/VERSION +1 -0
  6. data/app/controllers/application_controller.rb +10 -0
  7. data/app/helpers/application_helper.rb +3 -0
  8. data/bin/can_controls_gateway +36 -0
  9. data/doc/090630_Gestentracking_RFID.pdf +0 -0
  10. data/doc/README_FOR_APP +3 -0
  11. data/doc/home.png +0 -0
  12. data/doc/life.png +0 -0
  13. data/doc/preshow.png +0 -0
  14. data/doc/recognition-message-example.xml +69 -0
  15. data/etc/init-script_debian +56 -0
  16. data/lib/can-controls-gateway.rb +4 -0
  17. data/lib/ccg_logger.rb +6 -0
  18. data/lib/cursor_vector.rb +60 -0
  19. data/lib/dispatcher.rb +85 -0
  20. data/lib/osc_broadcast_receiver.rb +41 -0
  21. data/lib/osc_broadcast_sender.rb +44 -0
  22. data/lib/osc_package.rb +56 -0
  23. data/lib/osc_to_rca_dispatcher.rb +42 -0
  24. data/lib/ping.rb +84 -0
  25. data/lib/raw_event.rb +33 -0
  26. data/lib/rca_command.rb +42 -0
  27. data/lib/runner.rb +97 -0
  28. data/lib/server.rb +45 -0
  29. data/lib/settings.rb +17 -0
  30. data/log/development.log +0 -0
  31. data/log/production.log +0 -0
  32. data/log/server.log +0 -0
  33. data/log/test.log +0 -0
  34. data/public/404.html +30 -0
  35. data/public/422.html +30 -0
  36. data/public/500.html +30 -0
  37. data/public/favicon.ico +0 -0
  38. data/public/images/gesten/1.png +0 -0
  39. data/public/images/gesten/10.png +0 -0
  40. data/public/images/gesten/11.png +0 -0
  41. data/public/images/gesten/2.png +0 -0
  42. data/public/images/gesten/3.png +0 -0
  43. data/public/images/gesten/4.png +0 -0
  44. data/public/images/gesten/5.png +0 -0
  45. data/public/images/gesten/6.png +0 -0
  46. data/public/images/gesten/7.png +0 -0
  47. data/public/images/gesten/8.png +0 -0
  48. data/public/images/gesten/9.png +0 -0
  49. data/public/images/rails.png +0 -0
  50. data/public/index.html +275 -0
  51. data/public/javascripts/application.js +2 -0
  52. data/public/javascripts/controls.js +963 -0
  53. data/public/javascripts/dragdrop.js +973 -0
  54. data/public/javascripts/effects.js +1128 -0
  55. data/public/javascripts/prototype.js +4320 -0
  56. data/public/robots.txt +5 -0
  57. data/script/about +4 -0
  58. data/script/console +3 -0
  59. data/script/dbconsole +3 -0
  60. data/script/destroy +3 -0
  61. data/script/generate +3 -0
  62. data/script/performance/benchmarker +3 -0
  63. data/script/performance/profiler +3 -0
  64. data/script/plugin +3 -0
  65. data/script/runner +3 -0
  66. data/script/server +3 -0
  67. data/spec/can-controls-gateway/rca_command_spec.rb +31 -0
  68. data/spec/spec.opts +1 -0
  69. data/spec/spec_helper.rb +10 -0
  70. data/test/performance/browsing_test.rb +9 -0
  71. data/test/test_helper.rb +38 -0
  72. metadata +167 -0
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ *.gemspec
7
+ log/*
data/Capfile ADDED
@@ -0,0 +1,8 @@
1
+ load 'deploy' if respond_to?(:namespace) # cap2 differentiator
2
+ Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
3
+
4
+ # Standard cap deploy recipe
5
+ load 'config/deploy'
6
+
7
+ # Add your own recipes in files placed in lib/recipes ending in .rb,
8
+ Dir['lib/recipes/**/*.rb'].each { |recipe| load recipe }
data/README ADDED
@@ -0,0 +1,243 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application framework that includes everything needed to create
4
+ database-backed web applications according to the Model-View-Control pattern.
5
+
6
+ This pattern splits the view (also called the presentation) into "dumb" templates
7
+ that are primarily responsible for inserting pre-built data in between HTML tags.
8
+ The model contains the "smart" domain objects (such as Account, Product, Person,
9
+ Post) that holds all the business logic and knows how to persist themselves to
10
+ a database. The controller handles the incoming requests (such as Save New Account,
11
+ Update Product, Show Post) by manipulating the model and directing data to the view.
12
+
13
+ In Rails, the model is handled by what's called an object-relational mapping
14
+ layer entitled Active Record. This layer allows you to present the data from
15
+ database rows as objects and embellish these data objects with business logic
16
+ methods. You can read more about Active Record in
17
+ link:files/vendor/rails/activerecord/README.html.
18
+
19
+ The controller and view are handled by the Action Pack, which handles both
20
+ layers by its two parts: Action View and Action Controller. These two layers
21
+ are bundled in a single package due to their heavy interdependence. This is
22
+ unlike the relationship between the Active Record and Action Pack that is much
23
+ more separate. Each of these packages can be used independently outside of
24
+ Rails. You can read more about Action Pack in
25
+ link:files/vendor/rails/actionpack/README.html.
26
+
27
+
28
+ == Getting Started
29
+
30
+ 1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
31
+ and your application name. Ex: rails myapp
32
+ 2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
33
+ 3. Go to http://localhost:3000/ and get "Welcome aboard: You're riding the Rails!"
34
+ 4. Follow the guidelines to start developing your application
35
+
36
+
37
+ == Web Servers
38
+
39
+ By default, Rails will try to use Mongrel if it's are installed when started with script/server, otherwise Rails will use WEBrick, the webserver that ships with Ruby. But you can also use Rails
40
+ with a variety of other web servers.
41
+
42
+ Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
43
+ suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
44
+ getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
45
+ More info at: http://mongrel.rubyforge.org
46
+
47
+ Say other Ruby web servers like Thin and Ebb or regular web servers like Apache or LiteSpeed or
48
+ Lighttpd or IIS. The Ruby web servers are run through Rack and the latter can either be setup to use
49
+ FCGI or proxy to a pack of Mongrels/Thin/Ebb servers.
50
+
51
+ == Apache .htaccess example for FCGI/CGI
52
+
53
+ # General Apache options
54
+ AddHandler fastcgi-script .fcgi
55
+ AddHandler cgi-script .cgi
56
+ Options +FollowSymLinks +ExecCGI
57
+
58
+ # If you don't want Rails to look in certain directories,
59
+ # use the following rewrite rules so that Apache won't rewrite certain requests
60
+ #
61
+ # Example:
62
+ # RewriteCond %{REQUEST_URI} ^/notrails.*
63
+ # RewriteRule .* - [L]
64
+
65
+ # Redirect all requests not available on the filesystem to Rails
66
+ # By default the cgi dispatcher is used which is very slow
67
+ #
68
+ # For better performance replace the dispatcher with the fastcgi one
69
+ #
70
+ # Example:
71
+ # RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
72
+ RewriteEngine On
73
+
74
+ # If your Rails application is accessed via an Alias directive,
75
+ # then you MUST also set the RewriteBase in this htaccess file.
76
+ #
77
+ # Example:
78
+ # Alias /myrailsapp /path/to/myrailsapp/public
79
+ # RewriteBase /myrailsapp
80
+
81
+ RewriteRule ^$ index.html [QSA]
82
+ RewriteRule ^([^.]+)$ $1.html [QSA]
83
+ RewriteCond %{REQUEST_FILENAME} !-f
84
+ RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
85
+
86
+ # In case Rails experiences terminal errors
87
+ # Instead of displaying this message you can supply a file here which will be rendered instead
88
+ #
89
+ # Example:
90
+ # ErrorDocument 500 /500.html
91
+
92
+ ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
93
+
94
+
95
+ == Debugging Rails
96
+
97
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
98
+ will help you debug it and get it back on the rails.
99
+
100
+ First area to check is the application log files. Have "tail -f" commands running
101
+ on the server.log and development.log. Rails will automatically display debugging
102
+ and runtime information to these files. Debugging info will also be shown in the
103
+ browser on requests from 127.0.0.1.
104
+
105
+ You can also log your own messages directly into the log file from your code using
106
+ the Ruby logger class from inside your controllers. Example:
107
+
108
+ class WeblogController < ActionController::Base
109
+ def destroy
110
+ @weblog = Weblog.find(params[:id])
111
+ @weblog.destroy
112
+ logger.info("#{Time.now.iso8601} Destroyed Weblog ID ##{@weblog.id}!")
113
+ end
114
+ end
115
+
116
+ The result will be a message in your log file along the lines of:
117
+
118
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
119
+
120
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
121
+
122
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
123
+
124
+ * The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
125
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
126
+
127
+ These two online (and free) books will bring you up to speed on the Ruby language
128
+ and also on programming in general.
129
+
130
+
131
+ == Debugger
132
+
133
+ Debugger support is available through the debugger command when you start your Mongrel or
134
+ Webrick server with --debugger. This means that you can break out of execution at any point
135
+ in the code, investigate and change the model, AND then resume execution!
136
+ You need to install ruby-debug to run the server in debugging mode. With gems, use 'gem install ruby-debug'
137
+ Example:
138
+
139
+ class WeblogController < ActionController::Base
140
+ def index
141
+ @posts = Post.find(:all)
142
+ debugger
143
+ end
144
+ end
145
+
146
+ So the controller will accept the action, run the first line, then present you
147
+ with a IRB prompt in the server window. Here you can do things like:
148
+
149
+ >> @posts.inspect
150
+ => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
151
+ #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
152
+ >> @posts.first.title = "hello from a debugger"
153
+ => "hello from a debugger"
154
+
155
+ ...and even better is that you can examine how your runtime objects actually work:
156
+
157
+ >> f = @posts.first
158
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
159
+ >> f.
160
+ Display all 152 possibilities? (y or n)
161
+
162
+ Finally, when you're ready to resume execution, you enter "cont"
163
+
164
+
165
+ == Console
166
+
167
+ You can interact with the domain model by starting the console through <tt>script/console</tt>.
168
+ Here you'll have all parts of the application configured, just like it is when the
169
+ application is running. You can inspect domain models, change values, and save to the
170
+ database. Starting the script without arguments will launch it in the development environment.
171
+ Passing an argument will specify a different environment, like <tt>script/console production</tt>.
172
+
173
+ To reload your controllers and models after launching the console run <tt>reload!</tt>
174
+
175
+ == dbconsole
176
+
177
+ You can go to the command line of your database directly through <tt>script/dbconsole</tt>.
178
+ You would be connected to the database with the credentials defined in database.yml.
179
+ Starting the script without arguments will connect you to the development database. Passing an
180
+ argument will connect you to a different database, like <tt>script/dbconsole production</tt>.
181
+ Currently works for mysql, postgresql and sqlite.
182
+
183
+ == Description of Contents
184
+
185
+ app
186
+ Holds all the code that's specific to this particular application.
187
+
188
+ app/controllers
189
+ Holds controllers that should be named like weblogs_controller.rb for
190
+ automated URL mapping. All controllers should descend from ApplicationController
191
+ which itself descends from ActionController::Base.
192
+
193
+ app/models
194
+ Holds models that should be named like post.rb.
195
+ Most models will descend from ActiveRecord::Base.
196
+
197
+ app/views
198
+ Holds the template files for the view that should be named like
199
+ weblogs/index.html.erb for the WeblogsController#index action. All views use eRuby
200
+ syntax.
201
+
202
+ app/views/layouts
203
+ Holds the template files for layouts to be used with views. This models the common
204
+ header/footer method of wrapping views. In your views, define a layout using the
205
+ <tt>layout :default</tt> and create a file named default.html.erb. Inside default.html.erb,
206
+ call <% yield %> to render the view using this layout.
207
+
208
+ app/helpers
209
+ Holds view helpers that should be named like weblogs_helper.rb. These are generated
210
+ for you automatically when using script/generate for controllers. Helpers can be used to
211
+ wrap functionality for your views into methods.
212
+
213
+ config
214
+ Configuration files for the Rails environment, the routing map, the database, and other dependencies.
215
+
216
+ db
217
+ Contains the database schema in schema.rb. db/migrate contains all
218
+ the sequence of Migrations for your schema.
219
+
220
+ doc
221
+ This directory is where your application documentation will be stored when generated
222
+ using <tt>rake doc:app</tt>
223
+
224
+ lib
225
+ Application specific libraries. Basically, any kind of custom code that doesn't
226
+ belong under controllers, models, or helpers. This directory is in the load path.
227
+
228
+ public
229
+ The directory available for the web server. Contains subdirectories for images, stylesheets,
230
+ and javascripts. Also contains the dispatchers and the default HTML files. This should be
231
+ set as the DOCUMENT_ROOT of your web server.
232
+
233
+ script
234
+ Helper scripts for automation and generation.
235
+
236
+ test
237
+ Unit and functional tests along with fixtures. When using the script/generate scripts, template
238
+ test files will be generated for you and placed in this directory.
239
+
240
+ vendor
241
+ External libraries that the application depends on. Also includes the plugins subdirectory.
242
+ If the app has frozen rails, those gems also go here, under vendor/rails/.
243
+ This directory is in the load path.
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "tg-can-controls-gateway"
8
+ gem.summary = %Q{mapping CC gesture events to RCA}
9
+ gem.description = <<-TXT.strip.gsub(/\s+/, ' ')
10
+ to be written
11
+ TXT
12
+ gem.email = "entwicklung.t-gallery@artcom.de"
13
+ gem.homepage = "http://artcom.de/"
14
+ gem.authors = ["art+com/andreas marr"]
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+
17
+ gem.add_development_dependency "rspec"
18
+ gem.add_runtime_dependency "applix"
19
+ gem.add_runtime_dependency "gom-script"
20
+ gem.add_runtime_dependency "eventmachine", ">=0.12.10"
21
+ end
22
+ rescue LoadError
23
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
24
+ end
25
+
26
+ require 'spec/rake/spectask'
27
+ Spec::Rake::SpecTask.new(:spec) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.spec_files = FileList['spec/**/*_spec.rb']
30
+ end
31
+
32
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
33
+ spec.libs << 'lib' << 'spec'
34
+ spec.pattern = 'spec/**/*_spec.rb'
35
+ spec.rcov = true
36
+ end
37
+
38
+ task :spec => :check_dependencies
39
+
40
+ task :default => :spec
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION')
45
+ version = File.read('VERSION')
46
+ else
47
+ version = ""
48
+ end
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "tg-can-controls-gateway #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,10 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ helper :all # include all helpers, all the time
6
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
7
+
8
+ # Scrub sensitive parameters from your log
9
+ # filter_parameter_logging :password
10
+ end
@@ -0,0 +1,3 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ end
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'applix'
5
+
6
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
7
+ require 'can-controls-gateway'
8
+
9
+ $stderr.sync = true
10
+ $stdout.sync = true
11
+
12
+ Defaults = {
13
+ }
14
+
15
+ def main argv
16
+ options = Defaults.merge(Hash.from_argv argv)
17
+
18
+ puts " -- starting #{File.basename __FILE__} at #{Time.now}"
19
+ args = (options.delete :args)
20
+ #debugger if (defined? debugger)
21
+ service_url = (args.shift || 'http://gom/services/ccg/home')
22
+ puts " .. #{service_url}"
23
+ service = nil
24
+ daemon = Gom::Remote::Daemon.new(service_url, options) do |daemon, path|
25
+ service = CcgRunner.new(path, options)
26
+ daemon.check_in
27
+ end
28
+ daemon.background_loop(5) { service.run }
29
+ daemon.actor_loop { |daemon| puts " -- gom refresh: #{Time.now}" }
30
+
31
+ rescue => e
32
+ puts " ## #{e}\n -> #{e.backtrace.join "\n "}"
33
+ end
34
+
35
+ main ARGV
36
+ # vim: syntax=ruby
Binary file
@@ -0,0 +1,3 @@
1
+ Use this README file to introduce your application and point to useful places
2
+ in the API for learning more. Run "rake doc:app" to generate API documentation
3
+ for your models, controllers, helpers, and libraries.
data/doc/home.png ADDED
Binary file
data/doc/life.png ADDED
Binary file
data/doc/preshow.png ADDED
Binary file
@@ -0,0 +1,69 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- we propose adding a timestamp -->
3
+ <!-- seems redundant since we already agreed upon TCP as a transport layer protocol -->
4
+ <!-- transport layer protocol changed to UDP. added station ID in order for the receiver
5
+ to be able to identify the originating station in a broadcast situation -->
6
+ <!-- As of 2009/09/04 a sequence attribute has been added. The sequence attribute holds
7
+ an ever increasing counter value while the timestamp attribute now holds the system time
8
+ of the sending machine in ms since system start -->
9
+ <trackingdata ts="" sequence="" station_id="">
10
+
11
+ <!-- for every continuously tracked person a unique id is attached to the
12
+ <person> element. -->
13
+ <person id="1">
14
+
15
+ <!-- every person has arms which a identified as 'right' or 'left' -->
16
+ <arm side="right">
17
+
18
+ <!-- a recognized hand is always part of an arm and has a destinct shape.
19
+ The list of knows shapes is:
20
+ - thumbLeft
21
+ - TODO: list of known shapes
22
+ -->
23
+ <hand shape="thumbLeft">
24
+
25
+ <!-- positions elements have to be of type 'vec3f' and have to contain
26
+ a comma separated list of 3 floating point values. whitespace is
27
+ optional, e.g. "1.0,2,3.0" and "1 , 2, 3" are equally valid.
28
+
29
+ coordinate_system for this element must be 'world'.
30
+ -->
31
+ <position type="vec3f" coordinate_system="world">
32
+ 1.0, 2.0, 3.0
33
+ </position>
34
+
35
+ <!-- <finger> elements are part of the hand and have name which is one
36
+ of: 'index', 'small', 'thumb', 'ring', 'middle'. TODO: confirm
37
+ proper english vocabulary here! -->
38
+ <finger name="index">
39
+
40
+ <!-- every <finger> position is given as a 'vev3f' value and defines
41
+ the 3D position vector of the tip of the finger. (TODO: is that
42
+ correct?)
43
+
44
+ usually the fingers position corrdinate system is same as the one
45
+ of the hand and therefor can be ommitted here -->
46
+ <position type="vec3f" coordinate_system="world">
47
+ 3.0, 2.0, 1.0
48
+ </position>
49
+ </finger>
50
+ </hand>
51
+ </arm>
52
+ </person>
53
+
54
+ <!-- <event> elements are totally optional as when there is no event, they
55
+ are not send at all.
56
+
57
+ when <event> elements are send they must contain an 'type' attributes.
58
+ known events are: 'mouseDown', 'mouseUp'. TODO: discuss list of supported
59
+ events.
60
+ -->
61
+ <event type="mouseDown">
62
+
63
+ <!-- 'mouseDown' and 'mouseUp' event are defined by their <position>
64
+ element. The <position> element is defined as above. -->
65
+ <position type="vec3f" coordinate_system="plane">
66
+ 3.0, 2.0, 1.0
67
+ </position>
68
+ </event>
69
+ </trackingdata>
@@ -0,0 +1,56 @@
1
+ #!/bin/sh
2
+ # init script for the CanControlsGateway. Goes into /etc/init.d/
3
+
4
+ name="can_controls_gateway"
5
+ executable="/home/webs/CanControlsGateway/current/bin/can_controls_gateway"
6
+ rubypath="/usr/bin/env ruby"
7
+ pidfile="/var/run/$name.pid"
8
+ user=webs
9
+
10
+ stop_can_controls_gateway() {
11
+ echo "stopping $name ..."
12
+ start-stop-daemon --stop --pidfile $pidfile -v
13
+ rm -f $pidfile
14
+ }
15
+
16
+ start_can_controls_gateway() {
17
+ echo "starting $name ..."
18
+ start-stop-daemon -c $user --start --background --make-pidfile -v --pidfile $pidfile --exec $executable
19
+ }
20
+
21
+ running() {
22
+ if [ -f $pidfile ]
23
+ then
24
+ return 0
25
+ else
26
+ return 1
27
+ fi
28
+ }
29
+
30
+ if [ ! -x $executable ]
31
+ then
32
+ echo "Cannot find $name executable. Aborting."
33
+ exit 0
34
+ fi
35
+
36
+ case "$1" in
37
+ start)
38
+ if running
39
+ then
40
+ echo "$name already running or stale pidfile. Aborting."
41
+ exit 0
42
+ fi
43
+ start_can_controls_gateway
44
+ ;;
45
+ stop)
46
+ stop_can_controls_gateway
47
+ ;;
48
+ restart)
49
+ stop_can_controls_gateway
50
+ start_can_controls_gateway
51
+ ;;
52
+ *)
53
+ echo "Usage: $0 {start|stop|restart}" >&2
54
+ exit 3
55
+ ;;
56
+ esac
@@ -0,0 +1,4 @@
1
+ require 'gom/remote'
2
+ require 'ccg_logger'
3
+ require 'runner'
4
+ require 'rca_command'
data/lib/ccg_logger.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'logger'
2
+ require 'time'
3
+
4
+ module CcgLogger
5
+ LOGGER = Logger.new(File.join(File.dirname(__FILE__), '..', 'log/ccg.log'))
6
+ end
@@ -0,0 +1,60 @@
1
+ require 'rexml/document'
2
+ require 'rexml/xpath'
3
+
4
+ module CanControlsGateway
5
+
6
+ class CursorVector
7
+
8
+ attr_reader :x, :y
9
+
10
+ def initialize xml_node
11
+ @xml_node = REXML::Document.new(xml_node.to_s)
12
+ @x = nil
13
+ @y = nil
14
+
15
+ parse_xml
16
+ end
17
+
18
+ def is_valid?
19
+ if (@y && @x)
20
+ true
21
+ else
22
+ false
23
+ end
24
+ end
25
+
26
+ def dimensions
27
+ if is_valid?
28
+ 2
29
+ else
30
+ 0
31
+ end
32
+ end
33
+
34
+ def to_s
35
+ if is_valid?
36
+ "#{x},#{y}"
37
+ else
38
+ ""
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def parse_xml
45
+ my_vector_data = REXML::XPath.first(@xml_node, "/position").text
46
+ my_vector_data.to_s.strip!
47
+ my_vector_data = my_vector_data.split(",")
48
+ if my_vector_data.size > 1
49
+ @x = Float(my_vector_data[0].to_s.strip)
50
+ @y = Float(my_vector_data[1].to_s.strip.to_f)
51
+ else
52
+ @x, @y = nil
53
+ end
54
+ rescue
55
+ @x, @y = nil
56
+ end
57
+
58
+ end
59
+
60
+ end
data/lib/dispatcher.rb ADDED
@@ -0,0 +1,85 @@
1
+ require 'rexml/document'
2
+ require 'rexml/xpath'
3
+
4
+ ## require 'osc_package'
5
+ require 'rca_command'
6
+ require 'raw_event'
7
+
8
+ module CanControlsGateway
9
+
10
+ class Dispatcher
11
+
12
+ attr_reader :raw_data, :events, :station_id
13
+
14
+ def initialize data
15
+ # TODO remove REXML usage - REXML is horribly slow
16
+ @raw_data = REXML::Document.new("#{data}")
17
+ @events = get_raw_events
18
+ @station_id = REXML::XPath.first(@raw_data, "/trackingdata/attribute::station_id")
19
+ @station_id = @station_id.value if @station_id
20
+ end
21
+
22
+ def dispatch_rca
23
+ my_station = STATIONS[@station_id]
24
+
25
+ # Do we know this station?
26
+ if my_station
27
+
28
+ @events.each do |event|
29
+ ##
30
+ #CcgLogger::LOGGER.info "#{Time.now.iso8601} | Dispatcher: rca dispatching: event_type: #{event.event_type}"
31
+ ##
32
+
33
+ # If it is a RCA mappable event send it as RCA command...
34
+ if EVENTS[event.event_type]
35
+ if my_station['rci_uri']
36
+ my_args = { 'action' => EVENTS[event.event_type] }
37
+ CcgLogger::LOGGER.info "#{Time.now.iso8601} | >> Dispatcher: sending command : rci_uri: #{my_station['rci_uri']}, target: #{my_station['target']}, args: #{my_args.inspect}"
38
+ my_command = CanControlsGateway::RcaCommand.new my_station['rci_uri'],
39
+ my_station['target'],
40
+ my_args
41
+ CcgLogger::LOGGER.info "#{Time.now.iso8601} #{my_command.send_command}"
42
+ else
43
+ CcgLogger::LOGGER.info "#{Time.now.iso8601} | Device '#{my_station['device']}' not properly initialized in gom? (sender: station #{station})"
44
+ end
45
+ else
46
+ ##
47
+ #CcgLogger::LOGGER.info "#{Time.now.iso8601} | event '#{event.event_type}' not mappable to RCA command..."
48
+ ##
49
+ end
50
+ end
51
+
52
+ else
53
+ #CcgLogger::LOGGER.info "#{Time.now.iso8601} | unknown station_id '#{@station_id.inspect}'"
54
+ end
55
+
56
+ rescue => e
57
+ "ERROR: #{e.backtrace.join "\n\t"}"
58
+ end
59
+
60
+ #def dispatch_osc
61
+ # @events.each do |event|
62
+ # if event.event_type && @station_id
63
+ # ##
64
+ # #CcgLogger::LOGGER.info "#{Time.now.iso8601} | Dispatcher: osc dispatching: event_type: #{event.event_type} - vector: #{event.vector}"
65
+ # ##
66
+ # my_osc_package = CanControlsGateway::OscPackage.new event, @station_id
67
+ # my_ret = my_osc_package.broadcast
68
+ # nil
69
+ # end
70
+ # end
71
+ #end
72
+
73
+ private
74
+
75
+ def get_raw_events
76
+ my_events = []
77
+ my_event_nodes = REXML::XPath.each(@raw_data, "/trackingdata/event") { |event|
78
+ my_events << CanControlsGateway::RawEvent.new(event)
79
+ }
80
+ my_events
81
+ end
82
+
83
+ end
84
+
85
+ end