gom-sensor-ports 0.1.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b33f183a094f50f689b5e0f928e85f777cc35464
4
+ data.tar.gz: c68ddf9f61a70e16d275033d48b3e57e80736215
5
+ SHA512:
6
+ metadata.gz: 8ce8b07eba98e6ce221a9f0a909b443c0481ca4db7b6b90699d1358938d7adeb638af1238f9f78af4901a37ca2a785eaebe98e9721032a5a5bcec93ae2791d86
7
+ data.tar.gz: 494c09640086cd7fbbf35a02bcee854f75f96be502ecb952f1663a873f37ee618e0991fed2b84aa70449b91890b2bf158393e37198eb38c9f120eff2444424f1
data/.gitignore CHANGED
@@ -1,27 +1,11 @@
1
- ## MAC OS
2
- .DS_Store
1
+ # Ignore bundler config
2
+ /.bundle
3
3
 
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
4
+ # Ignore the default SQLite database.
5
+ /db/*.sqlite3
7
6
 
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
7
+ # Ignore all logfiles and tempfiles.
8
+ /log/*.log
9
+ /tmp
20
10
 
21
11
  ## PROJECT::SPECIFIC
22
- *.sw?
23
- .DS_Store
24
- coverage
25
- rdoc
26
- pkg
27
- *.gemspec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gom-sensor-ports.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,74 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gom-sensor-ports (0.2.2)
5
+ daemons
6
+ gom-core (~> 0.2.2)
7
+ gom-script (~> 0.2.2)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ applix (0.4.10)
13
+ daemons
14
+ columnize (0.3.6)
15
+ daemons (1.0.10)
16
+ debugger (1.6.0)
17
+ columnize (>= 0.3.1)
18
+ debugger-linecache (~> 1.2.0)
19
+ debugger-ruby_core_source (~> 1.2.1)
20
+ debugger-linecache (1.2.0)
21
+ debugger-ruby_core_source (1.2.2)
22
+ diff-lcs (1.1.3)
23
+ fakeweb (1.3.0)
24
+ ffi (1.0.11)
25
+ gem_plugin (0.2.3)
26
+ gom-core (0.2.2)
27
+ gom-script (0.2.2)
28
+ applix
29
+ gom-core (~> 0.2.2)
30
+ json
31
+ mongrel (>= 1.2.0.pre2)
32
+ rack
33
+ growl (1.0.3)
34
+ guard (1.2.3)
35
+ listen (>= 0.4.2)
36
+ thor (>= 0.14.6)
37
+ guard-rspec (1.2.0)
38
+ guard (>= 1.1)
39
+ json (1.7.3)
40
+ listen (0.4.7)
41
+ rb-fchange (~> 0.0.5)
42
+ rb-fsevent (~> 0.9.1)
43
+ rb-inotify (~> 0.8.8)
44
+ mongrel (1.2.0.pre2)
45
+ daemons (~> 1.0.10)
46
+ gem_plugin (~> 0.2.3)
47
+ rack (1.4.1)
48
+ rb-fchange (0.0.5)
49
+ ffi
50
+ rb-fsevent (0.9.1)
51
+ rb-inotify (0.8.8)
52
+ ffi (>= 0.5.0)
53
+ rspec (2.11.0)
54
+ rspec-core (~> 2.11.0)
55
+ rspec-expectations (~> 2.11.0)
56
+ rspec-mocks (~> 2.11.0)
57
+ rspec-core (2.11.0)
58
+ rspec-expectations (2.11.1)
59
+ diff-lcs (~> 1.1.3)
60
+ rspec-mocks (2.11.1)
61
+ thor (0.15.4)
62
+
63
+ PLATFORMS
64
+ ruby
65
+
66
+ DEPENDENCIES
67
+ debugger
68
+ fakeweb
69
+ gom-sensor-ports!
70
+ growl
71
+ guard
72
+ guard-rspec
73
+ rspec
74
+ rspec-mocks
data/Guardfile ADDED
@@ -0,0 +1,11 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2, :cli => '-d' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+
8
+ watch('spec/spec_helper.rb') { "spec" }
9
+ watch('*.gemspec') { "spec" }
10
+ watch('Gemfile') { "spec" }
11
+ end
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 dirk luesebrink
1
+ Copyright (c) 2009/10/11/12 art+com AG/dirk luesebrink
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.mkd CHANGED
@@ -1,17 +1,21 @@
1
1
  # gom-sensor-ports
2
-
3
- Easy access over the wire to a remote GOM node. This gem includes a GNP
2
+ Easy UDP/TCP sensor data sending to a remote GOM node. This gem includes a GNP
4
3
  callback server, support for automatic observer refreshments and command line
5
4
  tools for reading, writing and observing GOM entries.
6
5
 
7
6
  ## Install
8
-
9
- use the jewler tasks:
7
+ use the bundler tasks:
8
+
9
+ $ rake build install
10
10
 
11
- $ rake gemspec build install
11
+ optional:
12
+
13
+ $ rake release
12
14
 
13
15
  ## Dependencies
14
16
 
17
+ see Gemfile
18
+
15
19
  ## Note on Patches/Pull Requests
16
20
 
17
21
  * Fork the project.
data/Rakefile CHANGED
@@ -1,12 +1,14 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ __END__
3
5
 
4
6
  begin
5
7
  require 'jeweler'
6
8
  Jeweler::Tasks.new do |gem|
7
9
  gem.name = "gom-sensor-ports"
8
10
  gem.summary = %Q{
9
- gateway for barebone TCP/UCP reporting sensors to GOM/HTTP protocoll
11
+ gateway for barebone TCP/UDP reporting sensors to GOM/HTTP protocoll
10
12
  }
11
13
  gem.description = %Q{
12
14
  This gems implements a gateway server to allow barebone basic sensor
@@ -24,6 +26,7 @@ begin
24
26
 
25
27
  gem.add_runtime_dependency "applix"
26
28
  gem.add_runtime_dependency "gom-script"
29
+ gem.add_runtime_dependency "gom-core"
27
30
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
28
31
  end
29
32
  Jeweler::GemcutterTasks.new
@@ -31,16 +34,19 @@ rescue LoadError
31
34
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
32
35
  end
33
36
 
34
- require 'spec/rake/spectask'
35
- Spec::Rake::SpecTask.new(:spec) do |spec|
36
- spec.libs << 'lib' << 'spec'
37
- spec.spec_files = FileList['spec/**/*_spec.rb']
38
- end
39
-
40
- Spec::Rake::SpecTask.new(:rcov) do |spec|
41
- spec.libs << 'lib' << 'spec'
42
- spec.pattern = 'spec/**/*_spec.rb'
43
- spec.rcov = true
37
+ #require 'spec/rake/spectask'
38
+ #Spec::Rake::SpecTask.new(:spec) do |spec|
39
+ # spec.libs << 'lib' << 'spec'
40
+ # spec.spec_files = FileList['spec/**/*_spec.rb']
41
+ #end
42
+ #Spec::Rake::SpecTask.new(:rcov) do |spec|
43
+ # spec.libs << 'lib' << 'spec'
44
+ # spec.pattern = 'spec/**/*_spec.rb'
45
+ # spec.rcov = true
46
+ #end
47
+ require 'rspec/core/rake_task'
48
+ RSpec::Core::RakeTask.new(:rcov) do |t|
49
+ t.rcov_opts = %q[--exclude "spec"]
44
50
  end
45
51
 
46
52
  task :spec => :check_dependencies
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.1
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "rspec2" }
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'applix'
5
+
6
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
7
+ require 'gom/sensor_port'
8
+
9
+ Defaults = { :verbose => false }
10
+
11
+ def usage
12
+ puts "#{__FILE__} serve <gom sensor node URL>"
13
+ end
14
+
15
+ Applix.main(ARGV, Defaults) do
16
+
17
+ any { usage }
18
+
19
+ # example: gom-sensor-port serve /gom/sensors/udp
20
+ handle(:serve) do |*args, options|
21
+ puts "args: #{args.inspect}"
22
+ puts "opts: #{options}"
23
+ path, _ = *args
24
+ _, node_path = (Gom::Remote::Connection.init path)
25
+ gsp = Gom::SensorPort.new(node_path, options)
26
+ gsp.listen
27
+ end
28
+ end
data/bin/gom-sensor-ports CHANGED
@@ -1,3 +1,4 @@
1
+ __END__
1
2
  #!/usr/bin/env ruby
2
3
 
3
4
  require 'rubygems'
@@ -23,7 +24,14 @@ def main argv
23
24
 
24
25
  Gom::Remote::Daemon.new(sensor_url, options) do |daemon, path|
25
26
  sp = Gom::SensorPorts.new path, options
26
- daemon.sensor_loop { sp.listen }
27
+ daemon.sensor_loop do
28
+ begin
29
+ sp.listen
30
+ rescue SignalException => e
31
+ Gom::Log.ex e, "shutting down on <#{e.class}>"
32
+ :stop
33
+ end
34
+ end
27
35
  end
28
36
 
29
37
  rescue Usage => e
@@ -34,7 +42,8 @@ usage: #{__FILE__} <sensor port URL>
34
42
  ## #{e}
35
43
  TXT
36
44
  rescue => e
37
- puts " ## #{e}\n -> #{e.backtrace.join "\n "}"
45
+ Gom::Log.ex e
46
+ #puts " ## #{e}\n -> #{e.backtrace.join "\n "}"
38
47
  end
39
48
 
40
49
  main ARGV
@@ -0,0 +1,46 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'gom/sensor_ports/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'gom-sensor-ports'
7
+ s.version = Gom::SensorPorts::VERSION
8
+ s.authors = ['art+com/dirk luesebrink']
9
+ s.email = ['dirk.luesebrink@artcom.de']
10
+ s.homepage = 'http://github.com/crux/gom-sensor-ports'
11
+ s.summary = %q{
12
+ gateway for barebone TCP/UCP reporting sensors to GOM/HTTP protocoll
13
+ }
14
+ s.description = %q{
15
+ This gems implements a gateway server to allow barebone basic sensor
16
+ components to report state change updates as simple protocol free udates
17
+ over TCP/UDP ports without the 'overhead' of the HTTP protocoll. For
18
+ example, a power sensor might just broadcast a four byte floating point
19
+ binary number once every second to an UCP port
20
+ }
21
+
22
+ s.add_dependency 'daemons'
23
+ s.add_dependency 'gom-core', '~>0.2.2'
24
+ s.add_dependency 'gom-script', '~>0.2.2'
25
+
26
+ # development section
27
+ #
28
+ s.add_development_dependency 'rspec'
29
+ s.add_development_dependency 'rspec-mocks'
30
+ s.add_development_dependency 'fakeweb'
31
+ s.add_development_dependency 'guard'
32
+ s.add_development_dependency 'guard-rspec'
33
+ s.add_development_dependency 'growl'
34
+ if RUBY_PLATFORM.match /java/i
35
+ s.add_development_dependency 'ruby-debug'
36
+ else
37
+ s.add_development_dependency 'debugger'
38
+ end
39
+
40
+ s.files = `git ls-files`.split("\n")
41
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
42
+ s.executables = `git ls-files -- bin/*`.split("\n").map do |f|
43
+ File.basename(f)
44
+ end
45
+ s.require_paths = ["lib"]
46
+ end
@@ -0,0 +1,78 @@
1
+ require 'socket'
2
+ require 'applix/oattr'
3
+ require 'gom/remote'
4
+
5
+ module Gom
6
+ class SensorPort
7
+
8
+ # GOM default Logger instance
9
+ Log = Gom::Logger.new
10
+
11
+ Defaults = {
12
+ :interface => '0.0.0.0',
13
+ :port => 44470,
14
+ :mode => :udp,
15
+ :verbose => false,
16
+ }
17
+
18
+ include OAttr
19
+ oattr :interface, :port, :mode
20
+
21
+ def initialize path, options = {}
22
+ @path = path
23
+ @options = Defaults.merge(find_gom_node @path).merge(options)
24
+ #puts " -- new sensor port: #{self.inspect}"
25
+
26
+ verbose? and (Log.level = ::Logger::DEBUG)
27
+ Log.info "new sensor port: #{self.inspect}"
28
+ end
29
+
30
+ def verbose?
31
+ @options[:verbose] || @options[:v]
32
+ end
33
+
34
+ def listen
35
+ #puts " -- listen: #{self.inspect}"
36
+ Log.info "listen: #{self.inspect}"
37
+ self.send "listen_#{mode}"
38
+ end
39
+
40
+ def listen_udp
41
+ socket = UDPSocket.new
42
+ socket.bind(interface, port)
43
+ loop do
44
+ line, source = socket.recvfrom(1024)
45
+ dispatch_sensor_message line, source
46
+ end
47
+ ensure
48
+ socket.close rescue nil
49
+ end
50
+
51
+ def listen_tcp
52
+ raise "not yet implemented"
53
+ end
54
+
55
+ def dispatch_sensor_message line, source = nil
56
+ line.strip!
57
+ Log.debug "-->#{line}<-- #{source.inspect}"
58
+ key, value = (line.split /\s*[:=]\s*/)
59
+ value.nil? or value.strip!
60
+ # TODO: val might need type conversion
61
+ Gom::Remote.connection.write "#{@path}:raw", line
62
+ Gom::Remote.connection.write "#{@path}/values:#{key}", value
63
+ end
64
+
65
+ # TODO: temporarily here from gom-script
66
+ def find_gom_node path
67
+ json = (Gom::Remote.connection.read "#{path}.json")
68
+ (JSON.parse json)["node"]["entries"].select do |entry|
69
+ # 1. select attribute entries
70
+ entry.has_key? "attribute"
71
+ end.inject({}) do |h, a|
72
+ # 2. make it a key, value list
73
+ h[a["attribute"]["name"].to_sym] = a["attribute"]["value"]
74
+ h
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,5 @@
1
+ module Gom
2
+ class SensorPorts
3
+ VERSION = '0.2.3'
4
+ end
5
+ end
@@ -0,0 +1,110 @@
1
+ __END__
2
+ require 'applix/oattr'
3
+ require 'gom/remote'
4
+ require 'gom/log'
5
+ require 'gom/sensor_port'
6
+ require 'gom/sensor_ports/version'
7
+
8
+ module Gom
9
+ class SensorPorts #< Gom::Remote::Entry
10
+
11
+ Defaults = {
12
+ :logfile => '-',
13
+ :interface => '0.0.0.0',
14
+ :sensor_port => 76001,
15
+ :mode => :udp,
16
+ }
17
+
18
+ include OAttr
19
+ oattr :logfile, :interface, :sensor_port, :mode
20
+
21
+ # TODO: temporarily here from gom-script
22
+ def find_gom_node path
23
+ json = (Gom::Remote.connection.read "#{path}.json")
24
+ (JSON.parse json)["node"]["entries"].select do |entry|
25
+ # 1. select attribute entries
26
+ entry.has_key? "attribute"
27
+ end.inject({}) do |h, a|
28
+ # 2. make it a key, value list
29
+ h[a["attribute"]["name"].to_sym] = a["attribute"]["value"]
30
+ h
31
+ end
32
+ end
33
+
34
+ def initialize path, options = {}
35
+ @path = path
36
+ @options = Defaults.merge(find_gom_node @path).merge(options)
37
+ #puts " -- new sensor port: #{self.inspect}"
38
+ Log.info "new sensor port: #{self.inspect}"
39
+
40
+ #redirect_to logfile
41
+ end
42
+
43
+ def serve *args#path, opts = {}
44
+ Log.info "listen: #{self.inspect}"
45
+ self.send "listen_#{mode}"
46
+ end
47
+
48
+ def listen
49
+ #puts " -- listen: #{self.inspect}"
50
+ Log.info "listen: #{self.inspect}"
51
+ self.send "listen_#{mode}"
52
+ end
53
+
54
+ def listen_udp
55
+ socket = UDPSocket.new
56
+ socket.bind(interface, sensor_port)
57
+ loop do
58
+ line, source = socket.recvfrom(1024)
59
+ dispatch_sensor_message line, source
60
+ end
61
+ ensure
62
+ socket.close rescue nil
63
+ end
64
+
65
+ def listen_tcp
66
+ raise "not yet implemented"
67
+ end
68
+
69
+ def dispatch_sensor_message line, source = nil
70
+ line.strip!
71
+ Log.debug "-->#{line}<-- #{source.inspect}"
72
+ key, value = (line.split /\s*[:=]\s*/)
73
+ value.nil? or value.strip!
74
+ # TODO: val might need type conversion
75
+ Gom::Remote.connection.write "#{@path}:last_sensor_message", line
76
+ Gom::Remote.connection.write "#{@path}/keys:#{key}", value
77
+ end
78
+
79
+ def status
80
+ Log.debug @options.inspect
81
+ "not implemented"
82
+ end
83
+
84
+ # TODO: must go into gom-script gem
85
+ def redirect_to logfile
86
+ #(@logfile_fd && @logfile_fd.close) rescue nil
87
+ Log.debug "redirecting stdout/stderr to: #{logfile}"
88
+ if logfile == '-'
89
+ # redirect output back to original stdout/err stream can only be done
90
+ # after a previous call has stored them in @stdout/@stderr member
91
+ # variables
92
+ if (@stdout && @stderr)
93
+ #$stdout, $stderr = @stdout, @stderr
94
+ STDOUT.reopen @stdout
95
+ STDERR.reopen @stderr
96
+ end
97
+ else
98
+ #@stdout, @stderr = STDOUT, STDERR #$stdout, $stderr
99
+ #@logfile_fd = File.open(logfile, File::WRONLY|File::APPEND|File::CREAT)
100
+ #@logfile_fd.sync = true
101
+ ##$stderr = $stdout = @logfile_fd
102
+ @stdout, @stderr = STDOUT.clone, STDERR.clone
103
+ STDOUT.reopen logfile, 'a+'
104
+ STDERR.reopen logfile, 'a+'
105
+ end
106
+ # first line after redirect
107
+ Log.info "daemon logile redirect at #{Time.now}"
108
+ end
109
+ end
110
+ end
@@ -1,3 +1 @@
1
- require 'gom/remote'
2
- require 'applix/oattr'
3
- require 'gom-sensor-ports/sensor-ports'
1
+ require 'gom/sensor_ports'
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Gom::SensorPort" do
4
+ context "given no options" do
5
+
6
+ let(:path) { '/gom-sensor-port' }
7
+ let(:station) { Gom::SensorPort.new "#{path}" }
8
+ let(:json) { <<-JSON
9
+ {
10
+ "node": {
11
+ "uri": "#{path}",
12
+ "entries": [
13
+ { "attribute": {
14
+ "name": "status",
15
+ "node": "#{path}",
16
+ "value": "<void>", "type": "string"
17
+ } }
18
+ ]
19
+ }
20
+ }
21
+ JSON
22
+ }
23
+
24
+ before :each do
25
+ ($gom.stub! :read).with("#{path}.json").and_return(json)
26
+ end
27
+
28
+ describe "#dispatch_sensor_message" do
29
+ it "writes sensor value to gom" do
30
+ $gom.should_receive(:write).
31
+ with("#{path}:raw", "foo:123")
32
+ $gom.should_receive(:write).
33
+ with("#{path}/values:foo", "123")
34
+ station.dispatch_sensor_message "foo:123"
35
+ end
36
+ end
37
+
38
+ describe ".initialize" do
39
+ it "has a default interface" do
40
+ station.interface.should == '0.0.0.0'
41
+ end
42
+
43
+ it "defaults to udp mode" do
44
+ station.mode.should == :udp
45
+ end
46
+
47
+ it "configures sensor port on 76001" do
48
+ station.port.should == 44470
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,65 @@
1
+ __END__
2
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
+
4
+ describe "Gom::SensorPorts" do
5
+ context "given no options" do
6
+
7
+ NODE = '/gom-sensor-ports'
8
+
9
+ before :each do
10
+ ($gom.stub! :read).with("#{NODE}.json").and_return(<<-JSON)
11
+ {
12
+ "node": {
13
+ "uri": "#{NODE}",
14
+ "entries": [
15
+ { "attribute": {
16
+ "name": "status",
17
+ "node": "#{NODE}",
18
+ "value": "<void>", "type": "string"
19
+ } }
20
+ ]
21
+ }
22
+ }
23
+ JSON
24
+ @station = Gom::SensorPorts.new "#{NODE}"
25
+ end
26
+
27
+ #describe "#listen_tcp" do
28
+ # expect { @station.listen_tcp }.to raise_error#(ActiveRecord::RecordNotFound)
29
+ #end
30
+
31
+ describe "#dispatch_sensor_message" do
32
+ it "writes sensor value to gom" do
33
+ $gom.should_receive(:write).
34
+ with("#{NODE}:last_sensor_message", "foo:123")
35
+ $gom.should_receive(:write).
36
+ with("#{NODE}/keys:foo", "123")
37
+ @station.dispatch_sensor_message "foo:123"
38
+ end
39
+ end
40
+
41
+ describe ".initialize" do
42
+ it "has a default interface" do
43
+ @station.interface.should == '0.0.0.0'
44
+ end
45
+
46
+ it "logs to stdout" do
47
+ @station.logfile.should == '-'
48
+ end
49
+
50
+ it "defaults to udp mode" do
51
+ @station.mode.should == :udp
52
+ end
53
+
54
+ it "configures sensor port on 76001" do
55
+ @station.sensor_port.should == 76001
56
+ end
57
+ end
58
+
59
+ describe "#status" do
60
+ it "dumps status to stdout" do
61
+ @station.status.should be
62
+ end
63
+ end
64
+ end
65
+ end
data/spec/spec.opts CHANGED
@@ -1 +1 @@
1
- --color --backtrace --debugger
1
+ --debugger
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  #$:.unshift(File.dirname(__FILE__))
2
2
  $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'rubygems'
4
- require 'gom-sensor-ports'
5
- require 'spec'
6
- require 'spec/autorun'
7
3
  require 'fakeweb'
4
+ require 'gom/sensor_port'
8
5
 
9
- Spec::Runner.configure do |config|
6
+ RSpec.configure do |config|
10
7
  config.before :each do
11
8
  FakeWeb.allow_net_connect = false
9
+
10
+ $gom = Gom::Remote.connection = Object.new
11
+ (Gom::Remote::Connection.stub! :new).and_return $gom
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,140 +1,215 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: gom-sensor-ports
3
- version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 2
10
- version: 0.1.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.3
11
5
  platform: ruby
12
- authors:
13
- - art+com AG/dirk luesebrink
6
+ authors:
7
+ - art+com/dirk luesebrink
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2010-10-15 00:00:00 +02:00
19
- default_executable: gom-sensor-ports
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
11
+ date: 2013-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: daemons
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: gom-core
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: gom-script
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.2
55
+ - !ruby/object:Gem::Dependency
22
56
  name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
23
63
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 13
30
- segments:
31
- - 1
32
- - 2
33
- - 9
34
- version: 1.2.9
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-mocks
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
35
76
  type: :development
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
38
84
  name: fakeweb
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
39
91
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
49
104
  type: :development
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: applix
53
105
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- version: "0"
63
- type: :runtime
64
- version_requirements: *id003
65
- - !ruby/object:Gem::Dependency
66
- name: gom-script
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
67
119
  prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
69
- none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
75
- - 0
76
- version: "0"
77
- type: :runtime
78
- version_requirements: *id004
79
- description: "\n This gems implements a gateway server to allow barebone basic sensor\n components to report state change updates as simple protocol free udates\n over TCP/UDP ports without the 'overhead' of the HTTP protocoll. For\n example, a power sensor might just broadcast a four byte floating point\n binary number once every second to an UCP port\n "
80
- email: dirk.luesebrink@gmail.com
81
- executables:
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: growl
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: debugger
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: " \n This gems implements a gateway server to allow barebone basic
154
+ sensor\n components to report state change updates as simple protocol free udates\n
155
+ \ over TCP/UDP ports without the 'overhead' of the HTTP protocoll. For\n example,
156
+ a power sensor might just broadcast a four byte floating point\n binary number
157
+ once every second to an UCP port\n "
158
+ email:
159
+ - dirk.luesebrink@artcom.de
160
+ executables:
161
+ - gom-sensor-port
82
162
  - gom-sensor-ports
83
163
  extensions: []
84
-
85
- extra_rdoc_files:
86
- - LICENSE
87
- - README.mkd
88
- files:
164
+ extra_rdoc_files: []
165
+ files:
89
166
  - .document
90
167
  - .gitignore
168
+ - Gemfile
169
+ - Gemfile.lock
170
+ - Guardfile
91
171
  - LICENSE
92
172
  - README.mkd
93
173
  - Rakefile
94
174
  - VERSION
175
+ - autotest/discover.rb
176
+ - bin/gom-sensor-port
95
177
  - bin/gom-sensor-ports
96
178
  - etc/gom-sensor-ports-debian-init-script
179
+ - gom-sensor-ports.gemspec
97
180
  - lib/gom-sensor-ports.rb
98
- - lib/gom-sensor-ports/sensor-ports.rb
99
- - spec/gom-sensor-ports/sensor-ports_spec.rb
100
- - spec/gom-sensor-ports_spec.rb
181
+ - lib/gom/sensor_port.rb
182
+ - lib/gom/sensor_ports.rb
183
+ - lib/gom/sensor_ports/version.rb
184
+ - spec/lib/gom/sensor_port_spec.rb
185
+ - spec/lib/gom/sensor_ports_spec.rb
101
186
  - spec/spec.opts
102
187
  - spec/spec_helper.rb
103
- has_rdoc: true
104
188
  homepage: http://github.com/crux/gom-sensor-ports
105
189
  licenses: []
106
-
190
+ metadata: {}
107
191
  post_install_message:
108
- rdoc_options:
109
- - --charset=UTF-8
110
- require_paths:
192
+ rdoc_options: []
193
+ require_paths:
111
194
  - lib
112
- required_ruby_version: !ruby/object:Gem::Requirement
113
- none: false
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- hash: 3
118
- segments:
119
- - 0
120
- version: "0"
121
- required_rubygems_version: !ruby/object:Gem::Requirement
122
- none: false
123
- requirements:
124
- - - ">="
125
- - !ruby/object:Gem::Version
126
- hash: 3
127
- segments:
128
- - 0
129
- version: "0"
195
+ required_ruby_version: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - '>='
198
+ - !ruby/object:Gem::Version
199
+ version: '0'
200
+ required_rubygems_version: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - '>='
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
130
205
  requirements: []
131
-
132
206
  rubyforge_project:
133
- rubygems_version: 1.3.7
207
+ rubygems_version: 2.0.3
134
208
  signing_key:
135
- specification_version: 3
209
+ specification_version: 4
136
210
  summary: gateway for barebone TCP/UCP reporting sensors to GOM/HTTP protocoll
137
- test_files:
138
- - spec/gom-sensor-ports/sensor-ports_spec.rb
139
- - spec/gom-sensor-ports_spec.rb
211
+ test_files:
212
+ - spec/lib/gom/sensor_port_spec.rb
213
+ - spec/lib/gom/sensor_ports_spec.rb
214
+ - spec/spec.opts
140
215
  - spec/spec_helper.rb
@@ -1,67 +0,0 @@
1
- module Gom
2
- class SensorPorts < Gom::Remote::Entry
3
-
4
- Defaults = {
5
- :logfile => '-',
6
- :interface => '0.0.0.0',
7
- :sensor_port => 76001,
8
- :mode => :udp,
9
- }
10
-
11
- include OAttr
12
- oattr :logfile, :interface, :sensor_port, :mode
13
-
14
- def initialize path, options = {}
15
- @path = path
16
- @options = Defaults.merge(gnode @path).merge(options)
17
- puts " -- new sensor port: #{self.inspect}"
18
-
19
- redirect_to logfile
20
- end
21
-
22
- def listen
23
- puts " -- listen: #{self.inspect}"
24
- self.send "listen_#{mode}"
25
- end
26
-
27
- def listen_udp
28
- socket = UDPSocket.new
29
- socket.bind(interface, sensor_port)
30
- loop do
31
- val, sender = socket.recvfrom(1024)
32
- puts "-->#{val}<-- #{sender.inspect}"
33
- connection.write "#{@path}:current_value", val.to_s
34
- end
35
- ensure
36
- socket.close rescue nil
37
- end
38
-
39
- def status
40
- puts @options.inspect
41
- #t = Net::Telnet::new(
42
- # "Host" => device_ip, "Timeout" => 10, "Prompt" => /[$%#>] \z/n
43
- #)
44
- #t.login(user, password) { |c| puts c }
45
- "not implemented"
46
- end
47
-
48
- def redirect_to logfile
49
- (@logfile_fd && @logfile_fd.close) rescue nil
50
- puts " -- redirecting stdout/stderr to: #{logfile}"
51
- if logfile == '-'
52
- if @stdout
53
- $stderr, $stdout = @stdout, @stderr
54
- end
55
- else
56
- @stderr, @stdout = $stdout, $stderr
57
- @logfile_fd = File.open(logfile, File::WRONLY|File::APPEND|File::CREAT)
58
- @logfile_fd.sync = true
59
- $stderr = $stdout = @logfile_fd
60
- end
61
- # first line after redirect
62
- puts " -- daemon logile redirect at #{Time.now}"
63
- end
64
-
65
- end
66
- end
67
-
@@ -1,33 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe "Gom::SensorPorts" do
4
-
5
- before :each do
6
- $gom = Gom::Remote.connection = Object.new
7
- (Gom::Remote::Connection.stub! :new).and_return $gom
8
- ($gom.stub! :read).with('/gom/sensor-ports.json').and_return(<<-JSON)
9
- {
10
- "node": {
11
- "uri": "/services/viko/work",
12
- "mtime": "2010-01-06T15:14:57+01:00",
13
- "ctime": "2010-01-06T15:14:57+01:00",
14
- "entries": [
15
- { "attribute": {
16
- "name": "status",
17
- "node": "/services/viko/work",
18
- "value": "<void>",
19
- "type": "string",
20
- "mtime": "2010-01-07T19:30:36+01:00",
21
- "ctime": "2010-01-07T19:30:36+01:00"
22
- } }
23
- ]
24
- }
25
- }
26
- JSON
27
- end
28
-
29
- it "should dump status" do
30
- station = Gom::SensorPorts.new '/gom/sensor-ports'
31
- station.status.should_not == nil
32
- end
33
- end
@@ -1,7 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
-
3
- describe "GomSensorPorts" do
4
- it "should require service" do
5
- Gom::SensorPorts.should_not == nil
6
- end
7
- end