dmm_util 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem 'serialport'
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "shoulda", ">= 0"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.6.4"
13
+ gem "rcov", ">= 0"
14
+ gem "mocha"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ mocha (0.9.12)
10
+ rake (0.9.2)
11
+ rcov (0.9.10)
12
+ serialport (1.0.4)
13
+ shoulda (2.11.3)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ bundler (~> 1.0.0)
20
+ jeweler (~> 1.6.4)
21
+ mocha
22
+ rcov
23
+ serialport
24
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Fredrik Valeur
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.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = dmm_util
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to dmm_util
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Fredrik Valeur. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "dmm_util"
18
+ gem.homepage = "http://github.com/fvaleur/dmm_util"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Library and command line utility to download data from Fluke 28x series DMMs}
21
+ gem.description = %Q{Library and command line utility to download data from Fluke 28x series DMMs}
22
+ gem.email = "fredrik.valeur@appfolio.com"
23
+ gem.authors = ["Fredrik Valeur"]
24
+ # dependencies defined in Gemfile
25
+ gem.files.include 'lib/dmm_util/*.rb'
26
+ gem.executables = ['dmm_util']
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rake/testtask'
31
+ Rake::TestTask.new(:test) do |test|
32
+ test.libs << 'lib' << 'test'
33
+ test.pattern = 'test/**/*_test.rb'
34
+ test.verbose = true
35
+ end
36
+
37
+ require 'rcov/rcovtask'
38
+ Rcov::RcovTask.new do |test|
39
+ test.libs << 'test'
40
+ test.pattern = 'test/**/test_*.rb'
41
+ test.verbose = true
42
+ test.rcov_opts << '--exclude "gems/*"'
43
+ end
44
+
45
+ task :default => :test
46
+
47
+ require 'rake/rdoctask'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "dmm_util #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/dmm_util ADDED
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path('../../lib/dmm_util', __FILE__)
4
+
5
+ def usage
6
+ $stderr.write "Usage: dmm_util info : Display info about the meter\n"
7
+ $stderr.write " dmm_util recordings [index|name] ... : Display one or all recordings\n"
8
+ $stderr.write " dmm_util saved_measurements [index|name] : Display one or all saved measurements\n"
9
+ $stderr.write " dmm_util saved_min_max [index|name] : Display one or all saved min max measurements\n"
10
+ $stderr.write " dmm_util saved_peak [index|name] : Display one or all saved peak measurements\n"
11
+ $stderr.write " dmm_util measure_now : Display the current meter value\n"
12
+ $stderr.write " dmm_util set <company|contact|operator|site> <value> : Set meter contact info\n"
13
+ $stderr.write " dmm_util sync_time : Sync the clock on the DMM to the computer clock\n"
14
+ $stderr.write "\n"
15
+ exit(1)
16
+ end
17
+
18
+ def parse_int_if(val)
19
+ return Integer(val)
20
+ rescue ArgumentError
21
+ return val
22
+ end
23
+
24
+ def do_info
25
+ meter = DmmUtil.open
26
+ info = meter.driver.id
27
+ puts "Model: #{info[:model_number]}"
28
+ puts "Software Version: #{info[:software_version]}"
29
+ puts "Serial Number: #{info[:serial_number]}"
30
+ puts "Current meter time: #{meter.driver.clock}"
31
+ [:company, :contact, :operator, :site].each do |prop|
32
+ val = meter.driver.send(prop)
33
+ puts "#{prop.to_s.capitalize}: #{val}" unless val == ""
34
+ end
35
+ end
36
+
37
+ def do_set(property, value)
38
+ meter = DmmUtil.open
39
+ meter.driver.send(:"#{property}=", value)
40
+ puts "Sucsessfully set #{property} value"
41
+ end
42
+
43
+ def do_sync_time
44
+ meter = DmmUtil.open
45
+ meter.driver.clock = Time.now
46
+ puts "Sucsessfully synced the clock of the DMM"
47
+ end
48
+
49
+ def do_saved_measurements(type = :saved_measurements)
50
+ meter = DmmUtil.open
51
+ measurements = meter.send(type)
52
+ if ARGV.size == 1
53
+ measurements.each do |measurement|
54
+ puts "#{measurement.name} [#{measurement.ts}] : #{measurement.to_s}"
55
+ end
56
+ else
57
+ ARGV[1..-1].each do |idx|
58
+ idx = parse_int_if(idx)
59
+ if idx.is_a?(String)
60
+ measurement = measurements.find{|r| r.name == idx}
61
+ else
62
+ measurement = measurements[idx]
63
+ end
64
+ raise "Measurement '#{idx}' not found" unless measurement
65
+ puts "#{measurement.name} [#{measurement.ts}] : #{measurement.to_s}"
66
+ end
67
+ end
68
+ end
69
+
70
+ def do_recordings
71
+ meter = DmmUtil.open
72
+ if ARGV.size == 1
73
+ # List all recordings
74
+ meter.recordings.each do |recording|
75
+ puts "#{recording.name} [#{recording.start_ts} - #{recording.end_ts}] : #{recording.num_samples} measurements"
76
+ end
77
+ else
78
+ ARGV[1..-1].each do |idx|
79
+ idx = parse_int_if(idx)
80
+ if idx.is_a?(String)
81
+ recording = meter.recordings.find{|r| r.name == idx}
82
+ else
83
+ recording = meter.recordings[idx]
84
+ end
85
+ raise "Recording '#{idx}' not found" unless recording
86
+
87
+ puts "#{recording.name} (detail) [#{recording.start_ts} - #{recording.end_ts}] : #{recording.num_samples} measurements"
88
+ recording.measurements.each do |measurement|
89
+ puts "#{measurement.start_ts} : #{measurement.to_s}"
90
+ end
91
+ end
92
+ end
93
+
94
+ end
95
+
96
+ def do_measure_now
97
+ meter = DmmUtil.open
98
+ measurement = meter.measure_now
99
+ puts "NOW: #{measurement.to_s}"
100
+ end
101
+
102
+
103
+ ########### MAIN #############
104
+ usage if ARGV.empty?
105
+
106
+ case ARGV[0]
107
+ when "info"
108
+ do_info
109
+ when "saved_measurements"
110
+ do_saved_measurements(:saved_measurements)
111
+ when 'saved_min_max'
112
+ do_saved_measurements(:saved_min_max)
113
+ when 'saved_peak'
114
+ do_saved_measurements(:saved_peak)
115
+ when "recordings"
116
+ do_recordings
117
+ when "measure_now"
118
+ do_measure_now
119
+ when "set"
120
+ usage unless ARGV.size == 3
121
+ usage unless ["company", "site", "operator", "contact"].include?(ARGV[1])
122
+ do_set(ARGV[1], ARGV[2])
123
+ when "sync_time"
124
+ do_sync_time
125
+ else usage
126
+ end
127
+
data/dmm_util.gemspec ADDED
@@ -0,0 +1,84 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "dmm_util"
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 = ["Fredrik Valeur"]
12
+ s.date = "2011-09-03"
13
+ s.description = "Library and command line utility to download data from Fluke 28x series DMMs"
14
+ s.email = "fredrik.valeur@appfolio.com"
15
+ s.executables = ["dmm_util"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/dmm_util",
29
+ "dmm_util.gemspec",
30
+ "lib/dmm_util.rb",
31
+ "lib/dmm_util/cursor.rb",
32
+ "lib/dmm_util/fluke28x_driver.rb",
33
+ "lib/dmm_util/format_convertors.rb",
34
+ "lib/dmm_util/measurement.rb",
35
+ "lib/dmm_util/meter.rb",
36
+ "lib/dmm_util/reading.rb",
37
+ "lib/dmm_util/recording.rb",
38
+ "lib/dmm_util/recording_measurement.rb",
39
+ "lib/dmm_util/recording_measurement_cursor.rb",
40
+ "test/communication_test.rb",
41
+ "test/dmm_command_test.rb",
42
+ "test/format_convertors_test.rb",
43
+ "test/integration_itest.rb",
44
+ "test/measurement_test.rb",
45
+ "test/meter_test.rb",
46
+ "test/reading_test.rb",
47
+ "test/recording_measurement_test.rb",
48
+ "test/recording_test.rb",
49
+ "test/test_helper.rb"
50
+ ]
51
+ s.homepage = "http://github.com/fvaleur/dmm_util"
52
+ s.licenses = ["MIT"]
53
+ s.require_paths = ["lib"]
54
+ s.rubygems_version = "1.8.10"
55
+ s.summary = "Library and command line utility to download data from Fluke 28x series DMMs"
56
+
57
+ if s.respond_to? :specification_version then
58
+ s.specification_version = 3
59
+
60
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
61
+ s.add_runtime_dependency(%q<serialport>, [">= 0"])
62
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
63
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
65
+ s.add_development_dependency(%q<rcov>, [">= 0"])
66
+ s.add_development_dependency(%q<mocha>, [">= 0"])
67
+ else
68
+ s.add_dependency(%q<serialport>, [">= 0"])
69
+ s.add_dependency(%q<shoulda>, [">= 0"])
70
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
71
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
72
+ s.add_dependency(%q<rcov>, [">= 0"])
73
+ s.add_dependency(%q<mocha>, [">= 0"])
74
+ end
75
+ else
76
+ s.add_dependency(%q<serialport>, [">= 0"])
77
+ s.add_dependency(%q<shoulda>, [">= 0"])
78
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
79
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
80
+ s.add_dependency(%q<rcov>, [">= 0"])
81
+ s.add_dependency(%q<mocha>, [">= 0"])
82
+ end
83
+ end
84
+
@@ -0,0 +1,31 @@
1
+ module DmmUtil
2
+ class Cursor
3
+ include Enumerable
4
+
5
+ def initialize(driver, count_name, query_func, klass)
6
+ @driver = driver
7
+ @count_name = count_name
8
+ @query_func = query_func
9
+ @klass = klass
10
+ end
11
+
12
+ def count
13
+ @count = @count || @driver.qsls[@count_name]
14
+ end
15
+
16
+ def each
17
+ (0..(count-1)).each do |idx|
18
+ yield(self[idx])
19
+ end
20
+ end
21
+
22
+ def [](idx)
23
+ if @klass.instance_method(:initialize).arity == 2
24
+ @klass.new(@driver, @driver.send(@query_func, idx))
25
+ else
26
+ @klass.new(@driver.send(@query_func, idx))
27
+ end
28
+ end
29
+
30
+ end
31
+ end