tg-can-controls-gateway 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ begin
18
18
  gem.add_runtime_dependency "eventmachine", ">=0.12.10"
19
19
  gem.add_runtime_dependency "applix"
20
20
  gem.add_runtime_dependency "gom-core", ">=0.1.1"
21
- gem.add_runtime_dependency "gom-script"
21
+ gem.add_runtime_dependency "gom-script", ">=0.1.6"
22
22
  gem.add_runtime_dependency "osc", ">=0.1.4"
23
23
  end
24
24
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -23,6 +23,7 @@ def main argv
23
23
  service = nil
24
24
  daemon = Gom::Remote::Daemon.new(service_url, options) do |daemon, path|
25
25
  service = CcgRunner.new(path, options)
26
+ daemon.redirect_log service.logfile
26
27
  daemon.check_in
27
28
  end
28
29
  daemon.background_loop(5) { service.run }
@@ -5,3 +5,14 @@ module CcgLogger
5
5
  #LOGGER = Logger.new(File.join(File.dirname(__FILE__), '..', 'log/ccg.log'))
6
6
  LOGGER = Gom::Logger.new
7
7
  end
8
+
9
+ module Ccg
10
+ def self.logger out = nil
11
+ if out.nil?
12
+ @@logger ||= Gom::Logger.new
13
+ else
14
+ out = STDOUT if(out == '-')
15
+ @@logger = (Gom::Logger.new out)
16
+ end
17
+ end
18
+ end
@@ -26,60 +26,38 @@ module CanControlsGateway
26
26
  if my_station
27
27
 
28
28
  @events.each do |event|
29
- ##
30
- #CcgLogger::LOGGER.info "#{Time.now.iso8601} | Dispatcher: rca dispatching: event_type: #{event.event_type}"
31
- ##
32
-
33
29
  # If it is a RCA mappable event send it as RCA command...
34
30
  if EVENTS[event.event_type]
35
31
  if my_station['rci_uri']
36
32
  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}"
33
+ Ccg.logger.info "Dispatcher: sending command : rci_uri: #{my_station['rci_uri']}, target: #{my_station['target']}, args: #{my_args.inspect}"
38
34
  my_command = CanControlsGateway::RcaCommand.new my_station['rci_uri'],
39
35
  my_station['target'],
40
36
  my_args
41
- CcgLogger::LOGGER.info "#{Time.now.iso8601} #{my_command.send_command}"
37
+ Ccg.logger.info my_command.send_command
42
38
  else
43
- CcgLogger::LOGGER.info "#{Time.now.iso8601} | Device '#{my_station['device']}' not properly initialized in gom? (sender: station #{station})"
39
+ Ccg.logger.info "Device '#{my_station['device']}' not properly initialized in gom? (sender: station #{station})"
44
40
  end
45
41
  else
46
- ##
47
- #CcgLogger::LOGGER.info "#{Time.now.iso8601} | event '#{event.event_type}' not mappable to RCA command..."
48
- ##
42
+ # ????
49
43
  end
50
44
  end
51
45
 
52
46
  else
53
- #CcgLogger::LOGGER.info "#{Time.now.iso8601} | unknown station_id '#{@station_id.inspect}'"
47
+ # ????
54
48
  end
55
49
 
56
50
  rescue => e
57
51
  "ERROR: #{e.backtrace.join "\n\t"}"
58
52
  end
59
53
 
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
54
  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
-
55
+ def get_raw_events
56
+ my_events = []
57
+ my_event_nodes = REXML::XPath.each(@raw_data, "/trackingdata/event") { |event|
58
+ my_events << CanControlsGateway::RawEvent.new(event)
59
+ }
60
+ my_events
61
+ end
83
62
  end
84
-
85
- end
63
+ end
@@ -15,9 +15,6 @@ module CanControlsGateway
15
15
 
16
16
  def broadcast
17
17
  my_message = prepare_message
18
- ##
19
- #CcgLogger::LOGGER.info "#{Time.now.iso8601} | broadcasting osc_package with vector '#{@event.vector}' and event_type '#{@event.event_type}'"
20
- ##
21
18
  my_encoded_message = my_message.encode
22
19
  BasicSocket.do_not_reverse_lookup = true
23
20
  my_socket = UDPSocket.new
@@ -53,4 +50,4 @@ module CanControlsGateway
53
50
 
54
51
  end
55
52
 
56
- end
53
+ end
@@ -17,11 +17,11 @@ module CanControlsGateway
17
17
  def dispatch_rca
18
18
  return true if @event.nil?
19
19
  my_args = { 'action' => @event }
20
- CcgLogger::LOGGER.info "#{Time.now.iso8601} | >> OscToRcaDispatcher: sending command : rci_uri: #{STATION['rci_uri']}, target: #{STATION['target']}, args: #{my_args.inspect}"
20
+ Ccg.logger.info "OscToRcaDispatcher: sending command : rci_uri: #{STATION['rci_uri']}, target: #{STATION['target']}, args: #{my_args.inspect}"
21
21
  my_command = CanControlsGateway::RcaCommand.new STATION['rci_uri'],
22
22
  STATION['target'],
23
23
  my_args
24
- CcgLogger::LOGGER.info "#{Time.now.iso8601} #{my_command.send_command}"
24
+ Ccg.logger.info my_command.send_command
25
25
  end
26
26
 
27
27
  private
@@ -15,7 +15,7 @@ class CcgRunner < Gom::Remote::Entry
15
15
  }
16
16
 
17
17
  include OAttr
18
- oattr :incoming_osc_port, :device, :valve
18
+ oattr :incoming_osc_port, :device, :valve, :logfile
19
19
 
20
20
  def self.instance
21
21
  @@instance
@@ -26,6 +26,7 @@ class CcgRunner < Gom::Remote::Entry
26
26
  @path = path
27
27
  @options = Defaults.merge(gnode @path).merge(options)
28
28
  puts "options: #{@options.inspect}"
29
+ (Ccg::logger logfile)
29
30
 
30
31
  # FIXIT: legacy! pushing config values from GOM to global variable!!!
31
32
  STATION['port'] = Integer(incoming_osc_port)
@@ -48,10 +49,10 @@ class CcgRunner < Gom::Remote::Entry
48
49
  raise "NOT Starting servers since port cannot be determined"
49
50
  end
50
51
 
51
- puts "#{Time.now.iso8601} | ++ Starting servers"
52
+ Ccg.logger.info "Starting servers"
52
53
  EventMachine::threadpool_size = 20
53
54
  EventMachine::run do
54
- puts "#{Time.now.iso8601} | ++ * UdpServer (port: #{port}) ..."
55
+ Ccg.logger.info "UdpServer (port: #{port}) ..."
55
56
  EventMachine::open_datagram_socket('0.0.0.0', port, UdpServer)
56
57
  # TODO place http server component for GNP callbacks here...
57
58
  end
@@ -71,26 +72,3 @@ class CcgRunner < Gom::Remote::Entry
71
72
  puts " -- can-controls-valve now: #{valve}"
72
73
  end
73
74
  end
74
-
75
- __END__
76
-
77
- def _fill_settings
78
- CcgLogger::LOGGER.info "#{Time.now.iso8601} | ++ Initializing settings ..."
79
- my_gom = RestFs::Client.new GOM_ROOT
80
-
81
- my_res = my_gom.retrieve("#{STATION['device']}:rci_uri")
82
- if my_res
83
- STATION['rci_uri'] = my_res['attribute']['value']
84
- CcgLogger::LOGGER.info "#{Time.now.iso8601} | ++ setting rci_uri for station #{STATION['device']} => #{STATION['rci_uri'].inspect}"
85
-
86
- my_port_res = my_gom.retrieve("#{STATION['device']}/hid:port")
87
- if my_port_res
88
- STATION['port'] = my_port_res['attribute']['value']
89
- else
90
- CcgLogger::LOGGER.info "#{Time.now.iso8601} | ++ device's hid:port #{STATION['device']}/hid:port not found in gom"
91
- end
92
- else
93
- CcgLogger::LOGGER.info "#{Time.now.iso8601} | ++ device's rci_uri #{STATION['device']}:rci_uri not found in gom"
94
- end
95
- end
96
-
@@ -7,41 +7,28 @@ require 'osc_to_rca_dispatcher'
7
7
  module UdpServer
8
8
 
9
9
  def post_init
10
- CcgLogger::LOGGER.info "#{Time.now.iso8601} | ++ ... server started"
10
+ Ccg.logger.info "... server started"
11
11
  end
12
12
 
13
13
  def receive_data(data)
14
14
  return unless(CcgRunner.instance.valve == :open)
15
15
 
16
- ##
17
- #CcgLogger::LOGGER.info "#{Time.now.iso8601} | >> raw incoming data: ----------------------"
18
- #CcgLogger::LOGGER.info data.inspect
19
- #CcgLogger::LOGGER.info " --------------------------------------------"
20
- ##
21
-
22
- #port, ip = Socket.unpack_sockaddr_in(get_peername)
23
- #CcgLogger::LOGGER.info "#{Time.now.iso8601} | >> UdpServer: sender: #{ip}, #{port}"
24
-
25
16
  # RCA
26
17
  rca_dispatching = proc {
27
18
  begin
28
19
  my_dispatcher = CanControlsGateway::OscToRcaDispatcher.new data
29
- #CcgLogger::LOGGER.info my_dispatcher.event.inspect
30
20
  my_dispatcher.dispatch_rca
31
21
  rescue Exception => e
32
22
  puts " ## #{e}\n -> #{e.backtrace.join "\n "}"
33
23
  end
34
24
  }
35
25
  rca_callback = proc { |result|
36
- #if result
37
- # CcgLogger::LOGGER.info "#{Time.now.iso8601} | >> UdpServer: result is: #{result.inspect}"
38
- #end
39
26
  }
40
27
  EventMachine::defer rca_dispatching, rca_callback
41
28
  end
42
29
 
43
30
  def unbind
44
- CcgLogger::LOGGER.info "#{Time.now.iso8601} | -- UdpServer stopped"
31
+ Ccg.logger.info "UdpServer stopped"
45
32
  end
46
33
 
47
34
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tg-can-controls-gateway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - art+com/andreas marr
@@ -60,7 +60,7 @@ dependencies:
60
60
  requirements:
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: "0"
63
+ version: 0.1.6
64
64
  version:
65
65
  - !ruby/object:Gem::Dependency
66
66
  name: osc