machine-head 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Rusty Burchfield
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ = machine-head
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Rusty Burchfield. See LICENSE for details.
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "machine-head"
8
+ gem.summary = %Q{Ruby API for HDHomeRun dual ATSC tuner}
9
+ gem.description = %Q{Ruby API for HDHomeRun dual ATSC tuner. Requires hdhomerun_config.}
10
+ gem.email = "GICodeWarrior@gmail.com"
11
+ gem.homepage = "http://github.com/GICodeWarrior/machine-head"
12
+ gem.authors = ["Rusty Burchfield"]
13
+ gem.add_dependency 'gnuplot', '>= 2.3.1'
14
+ gem.add_development_dependency "rspec", ">= 1.2.9"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "machine-head #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'timeout'
4
+ require 'rubygems'
5
+ require 'machine-head'
6
+ require 'gnuplot'
7
+
8
+ def avg(values)
9
+ values.inject(:+) / values.size.to_f
10
+ end
11
+
12
+ def stddev(values)
13
+ count = values.size
14
+ mean = avg(values)
15
+
16
+ Math.sqrt(values.inject(0){|sum, e| sum + (e - mean) ** 2} / count.to_f)
17
+ end
18
+
19
+ device = MachineHead::Device.new('FFFFFFFF')
20
+ tuner = device.tuners.last
21
+ channels = (2..69).to_a
22
+
23
+ signal_strengths = []
24
+ signal_qualities = []
25
+ symbol_qualities = []
26
+
27
+ channels.each do |channel|
28
+ STDOUT.print "#{channel}, "
29
+ STDOUT.flush
30
+
31
+ tuner.channel = "8vsb:#{channel}"
32
+ sleep 2
33
+
34
+ signal_status = []
35
+ begin
36
+ timeout(10.0) do
37
+ loop do
38
+ signal_status << tuner.status
39
+ end
40
+ end
41
+ rescue Timeout::Error
42
+ end
43
+
44
+ if signal_status.detect{|s| s.lock != 'none'}
45
+ strengths = signal_status.map(&:signal_strength).map(&:to_i)
46
+ signal_strengths << [channel, avg(strengths), stddev(strengths)]
47
+
48
+ qualities = signal_status.map(&:signal_quality).map(&:to_i)
49
+ signal_qualities << [channel, avg(qualities), stddev(qualities)]
50
+
51
+ symbols = signal_status.map(&:symbol_quality).map(&:to_i)
52
+ symbol_qualities << [channel, avg(symbols), stddev(symbols)]
53
+ end
54
+ end
55
+
56
+ puts
57
+ puts "Locked: #{signal_strengths.map(&:first).join(', ')}"
58
+
59
+ Gnuplot.open do |gp|
60
+ Gnuplot::Plot.new( gp ) do |plot|
61
+
62
+ plot.title 'Signal breakdown'
63
+ plot.ylabel '%'
64
+ plot.xlabel 'Channel'
65
+ plot.xrange '[0:70]'
66
+ plot.yrange '[0:100]'
67
+ plot.key 'outside bottom'
68
+
69
+ labels = signal_qualities.map do |channel|
70
+ channel = channel.dup
71
+ channel[1] -= channel[2] + 6
72
+ channel[2] = channel[0]
73
+
74
+ channel
75
+ end
76
+
77
+ plot.data = [
78
+ Gnuplot::DataSet.new(signal_strengths.transpose) {|ds|
79
+ ds.with = 'yerrorbars'
80
+ ds.title = 'Signal Strength'
81
+ ds.linewidth = 1
82
+ },
83
+
84
+ Gnuplot::DataSet.new(signal_qualities.transpose) {|ds|
85
+ ds.with = 'yerrorbars'
86
+ ds.title = 'Signal Quality'
87
+ ds.linewidth = 1
88
+ },
89
+
90
+ Gnuplot::DataSet.new(symbol_qualities.transpose) {|ds|
91
+ ds.with = 'yerrorbars'
92
+ ds.title = 'Symbol Quality'
93
+ ds.linewidth = 1
94
+ },
95
+
96
+ Gnuplot::DataSet.new(labels.transpose) {|ds|
97
+ ds.with = 'labels'
98
+ ds.notitle
99
+ }
100
+ ]
101
+ end
102
+ end
@@ -0,0 +1,7 @@
1
+ module MachineHead
2
+ TOOL_PATH = '/usr/bin/hdhomerun_config'
3
+ end
4
+
5
+ require 'machine_head/device'
6
+ require 'machine_head/tuner'
7
+ require 'machine_head/status'
@@ -0,0 +1,36 @@
1
+ module MachineHead
2
+ class Device
3
+ attr_reader :id, :tuners
4
+
5
+ def initialize(id='FFFFFFFF')
6
+ @id = id
7
+
8
+ @tuners = [Tuner.new(self, 0), Tuner.new(self, 1)].freeze
9
+ end
10
+
11
+ def get(command)
12
+ `#{TOOL_PATH} #{id} get #{command}`
13
+ end
14
+
15
+ def set(command, data)
16
+ `#{TOOL_PATH} #{id} set #{command} #{data}`
17
+ end
18
+
19
+ %w(model features version copyright debug).each do |method|
20
+ define_method method do
21
+ get "/sys/#{method}"
22
+ end
23
+ end
24
+
25
+ def self.discover
26
+ devices = []
27
+
28
+ `#{TOOL_PATH} discover`.each_line do |line|
29
+ device = line.match(/^hdhomerun device ([0-9A-F]{8}) found/)
30
+ devices << self.new(device[1]) if device
31
+ end
32
+
33
+ devices
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,12 @@
1
+ module MachineHead
2
+ class Status
3
+ attr_reader :channel, :lock, :signal_strength, :signal_quality,
4
+ :symbol_quality, :raw_bitrate, :net_packetrate
5
+
6
+ def initialize(status_text)
7
+ @channel, @lock, @signal_strength, @signal_quality,
8
+ @symbol_quality, @raw_bitrate,
9
+ @net_packetrate = status_text.split.map{|i| i.split('=').last}
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,36 @@
1
+ module MachineHead
2
+ class Tuner
3
+ attr_reader :id, :device
4
+
5
+ def initialize(device, id)
6
+ @device = device
7
+ @id = id
8
+ end
9
+
10
+ def get(command)
11
+ device.get("/tuner#{id}/#{command}")
12
+ end
13
+
14
+ def set(command, data)
15
+ device.set("/tuner#{id}/#{command}", data)
16
+ end
17
+
18
+ %w(channel channelmap filter program target).each do |method|
19
+ define_method method do
20
+ get method
21
+ end
22
+
23
+ define_method "#{method}=" do |data|
24
+ set method, data
25
+ end
26
+ end
27
+
28
+ def streaminfo
29
+ get 'streaminfo'
30
+ end
31
+
32
+ def status
33
+ Status.new(get('status'))
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{machine-head}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Rusty Burchfield"]
12
+ s.date = %q{2010-07-29}
13
+ s.default_executable = %q{scanner.rb}
14
+ s.description = %q{Ruby API for HDHomeRun dual ATSC tuner. Requires hdhomerun_config.}
15
+ s.email = %q{GICodeWarrior@gmail.com}
16
+ s.executables = ["scanner.rb"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".gitignore",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/scanner.rb",
29
+ "lib/machine-head.rb",
30
+ "lib/machine_head/device.rb",
31
+ "lib/machine_head/status.rb",
32
+ "lib/machine_head/tuner.rb",
33
+ "machine-head.gemspec",
34
+ "spec/machine-head_spec.rb",
35
+ "spec/spec.opts",
36
+ "spec/spec_helper.rb"
37
+ ]
38
+ s.homepage = %q{http://github.com/GICodeWarrior/machine-head}
39
+ s.rdoc_options = ["--charset=UTF-8"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.7}
42
+ s.summary = %q{Ruby API for HDHomeRun dual ATSC tuner}
43
+ s.test_files = [
44
+ "spec/machine-head_spec.rb",
45
+ "spec/spec_helper.rb"
46
+ ]
47
+
48
+ if s.respond_to? :specification_version then
49
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
+ s.add_runtime_dependency(%q<gnuplot>, [">= 2.3.1"])
54
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
55
+ else
56
+ s.add_dependency(%q<gnuplot>, [">= 2.3.1"])
57
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
58
+ end
59
+ else
60
+ s.add_dependency(%q<gnuplot>, [">= 2.3.1"])
61
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
62
+ end
63
+ end
64
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "MachineHead" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'machine-head'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: machine-head
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Rusty Burchfield
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-29 00:00:00 -07:00
19
+ default_executable: scanner.rb
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: gnuplot
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 1
30
+ segments:
31
+ - 2
32
+ - 3
33
+ - 1
34
+ version: 2.3.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 13
46
+ segments:
47
+ - 1
48
+ - 2
49
+ - 9
50
+ version: 1.2.9
51
+ type: :development
52
+ version_requirements: *id002
53
+ description: Ruby API for HDHomeRun dual ATSC tuner. Requires hdhomerun_config.
54
+ email: GICodeWarrior@gmail.com
55
+ executables:
56
+ - scanner.rb
57
+ extensions: []
58
+
59
+ extra_rdoc_files:
60
+ - LICENSE
61
+ - README.rdoc
62
+ files:
63
+ - .document
64
+ - .gitignore
65
+ - LICENSE
66
+ - README.rdoc
67
+ - Rakefile
68
+ - VERSION
69
+ - bin/scanner.rb
70
+ - lib/machine-head.rb
71
+ - lib/machine_head/device.rb
72
+ - lib/machine_head/status.rb
73
+ - lib/machine_head/tuner.rb
74
+ - machine-head.gemspec
75
+ - spec/machine-head_spec.rb
76
+ - spec/spec.opts
77
+ - spec/spec_helper.rb
78
+ has_rdoc: true
79
+ homepage: http://github.com/GICodeWarrior/machine-head
80
+ licenses: []
81
+
82
+ post_install_message:
83
+ rdoc_options:
84
+ - --charset=UTF-8
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
95
+ version: "0"
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ requirements: []
106
+
107
+ rubyforge_project:
108
+ rubygems_version: 1.3.7
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: Ruby API for HDHomeRun dual ATSC tuner
112
+ test_files:
113
+ - spec/machine-head_spec.rb
114
+ - spec/spec_helper.rb