dmm_util 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,75 @@
1
+ require 'test_helper'
2
+
3
+
4
+ class RecordingTest < Test::Unit::TestCase
5
+ include DMMTestHelper
6
+
7
+ # def setup
8
+ # @driver_mock = mock()
9
+ # @meter = DmmUtil::Meter.new(@driver_mock)
10
+ # end
11
+
12
+ def test_name
13
+ recording = DmmUtil::Recording.new(nil, {:name => "xyxz", :start_ts => :starttime, :end_ts => :endtime})
14
+ assert_equal "xyxz", recording.name
15
+ assert_equal :starttime, recording.start_ts
16
+ assert_equal :endtime, recording.end_ts
17
+ end
18
+
19
+ def test_measurements_count
20
+ driver_mock = mock()
21
+ recording = DmmUtil::Recording.new(driver_mock, {:num_samples => 66})
22
+ assert_equal 66, recording.measurements.count
23
+ end
24
+
25
+ def test_measurements_index
26
+ driver_mock = mock()
27
+ driver_mock.expects(:qsrr).with(99, 10).returns(
28
+ {
29
+ :start_ts=>Time.parse("Fri May 07 22:48:35.3125 2010"),
30
+ :end_ts=>Time.parse("Fri May 07 22:48:47.18262 2010"),
31
+ :readings=> {
32
+ "MAXIMUM"=> {
33
+ :unit=>"VAC", :state=>"NORMAL", :unit_multiplier=>0, :un1=>5,
34
+ :ts=>Time.parse("Fri May 07 22:48:36.0166 2010"),
35
+ :value=>0.0362, :attribute=>"NONE", :decimals=>4
36
+ }
37
+ },
38
+ :readings2=> {
39
+ "PRIMARY"=> {
40
+ :unit=>"VAC", :state=>"NORMAL", :unit_multiplier=>0, :un1=>5,
41
+ :ts=>Time.parse("Fri May 07 22:48:35.3125 2010"),
42
+ :value=>0.0354, :attribute=>"NONE", :decimals=>4
43
+ }
44
+ },
45
+ }
46
+ )
47
+
48
+ recording = DmmUtil::Recording.new(driver_mock, {:reading_index => 99})
49
+
50
+ measurement = recording.measurements[10]
51
+ assert_equal Time.parse("Fri May 07 22:48:35.3125 2010"), measurement.start_ts
52
+ assert_equal 0.0362, measurement.maximum.value
53
+ assert_equal 0.0354, measurement.primary.value
54
+ end
55
+
56
+ def test_measurements__each
57
+ driver_mock = mock()
58
+ test_time = Time.parse("Fri May 07 22:48:35.3125 2010")
59
+ driver_mock.expects(:qsrr).with(99, 0).returns({:start_ts=> (test_time+1)})
60
+ driver_mock.expects(:qsrr).with(99, 1).returns({:start_ts=> (test_time+2)})
61
+ driver_mock.expects(:qsrr).with(99, 2).returns({:start_ts=> (test_time+3)})
62
+ driver_mock.expects(:qsrr).with(99, 3).returns({:start_ts=> (test_time+4)})
63
+
64
+ recording = DmmUtil::Recording.new(driver_mock, {:num_samples => 4, :reading_index => 99})
65
+
66
+ res = []
67
+ recording.measurements.each do |m|
68
+ res << m.start_ts
69
+ end
70
+
71
+ assert_equal [(test_time+1), (test_time+2), (test_time+3), (test_time+4)], res
72
+ end
73
+
74
+
75
+ end
@@ -0,0 +1,176 @@
1
+ require 'test/unit'
2
+ require 'dmm_util'
3
+ require 'mocha'
4
+ require 'time'
5
+
6
+ module DMMTestHelper
7
+
8
+ def assert_hashes_equal(expected, real, path = [])
9
+ flunk "Values are not hash (#{expected.class.name}, #{expected.class.name})" unless expected.is_a?(Hash) && real.is_a?(Hash)
10
+
11
+ expected_keys = expected.keys
12
+ real_keys = real.keys
13
+ flunk "Following keys expected but not found: #{(expected_keys - real_keys).join(", ")} (#{path.join(":")})" unless (expected_keys - real_keys).empty?
14
+ flunk "Following keys found but not expected: #{(real_keys - expected_keys).join(", ")} (#{path.join(":")})" unless (real_keys - expected_keys).empty?
15
+
16
+ expected_keys.each do |key|
17
+ key_path = path.dup << key
18
+ expected_val = expected[key]
19
+ real_val = real[key]
20
+ expected_val = expected_val.to_f if expected_val.is_a?(Fixnum) && real_val.is_a?(Float)
21
+ flunk "Types for key #{key_path.join(":")} differ: expected #{expected_val.class.name} but was #{real_val.class.name}" if expected_val.class != real_val.class
22
+
23
+ if expected_val.is_a?(Hash)
24
+ assert_hashes_equal expected_val, real_val, key_path
25
+ elsif expected_val.is_a?(Float)
26
+ assert (expected_val - real_val).abs < 0.0000000001, "Values for key #{key_path.join(":")} not equal: Expected #{expected_val} but got #{real_val}"
27
+ elsif expected_val.is_a?(Time)
28
+ assert (expected_val.to_f - real_val.to_f).abs < 0.00001, "Values for key #{key_path.join(":")} not equal: Expected #{expected_val} but got #{real_val}"
29
+ else
30
+ assert_equal expected_val, real_val, "Values for key #{key_path.join(":")} not equal"
31
+ end
32
+ end
33
+ end
34
+
35
+ def assert_sets_equal(expected, real)
36
+ not_found = expected - real
37
+ not_expected = real - expected
38
+ msg = []
39
+ msg << "Expected but not found: #{not_found.join(", ")}." unless not_found.empty?
40
+ msg << "Found but not expected: #{not_expected.join(", ")}." unless not_expected.empty?
41
+ flunk msg.join("\n") unless msg.empty?
42
+ end
43
+
44
+ def hex(bytes)
45
+ bs = DmmUtil::ByteStr.new(bytes)
46
+ hex_chunks = []
47
+ text_chunks = []
48
+ bs.each_slice(8) do |slice|
49
+ hex_chunks << slice.map{|b| "%02X" % b}.join(" ")
50
+ text_chunks << slice.map{|b| (b > 32 && b < 126) ? b.chr : "."}.join
51
+ end
52
+
53
+ lines = []
54
+ (0..hex_chunks.size-1).each_slice(2) do |left, right|
55
+ if right.nil?
56
+ lines << "#{hex_chunks[left]}#{' '*(23-hex_chunks[left].size)} #{' '*23} #{text_chunks[left]}"
57
+ else
58
+ lines << "#{hex_chunks[left]} #{hex_chunks[right]}#{' '*(23-hex_chunks[right].size)} #{text_chunks[left]}#{text_chunks[right]}"
59
+ end
60
+ end
61
+
62
+ lines.join("\n")
63
+ end
64
+
65
+ def bin_parse(hexstr)
66
+ hexstr.split.select{|s| s.size == 2}.map{|s| s.to_i(16).chr}.join
67
+ end
68
+
69
+
70
+ QEMAP = { :secfunction => {
71
+ 5=>"DBV",
72
+ 0=>"NONE",
73
+ 6=>"DBM_HERTZ",
74
+ 1=>"HERTZ",
75
+ 7=>"DBV_HERTZ",
76
+ 2=>"DUTY_CYCLE",
77
+ 8=>"CREST_FACTOR",
78
+ 3=>"PULSE_WIDTH",
79
+ 9=>"PEAK_MIN_MAX",
80
+ 4=>"DBM"},
81
+
82
+ :autorange => {0=>"MANUAL", 1=>"AUTO"},
83
+
84
+ :unit => {
85
+ 16=>"PCT",
86
+ 5=>"ADC",
87
+ 11=>"Hz",
88
+ 0=>"NONE",
89
+ 17=>"dB",
90
+ 6=>"AAC",
91
+ 12=>"S",
92
+ 1=>"VDC",
93
+ 18=>"dBV",
94
+ 7=>"AAC_PLUS_DC",
95
+ 13=>"F",
96
+ 2=>"VAC",
97
+ 19=>"dBm",
98
+ 8=>"A",
99
+ 14=>"CEL",
100
+ 3=>"VAC_PLUS_DC",
101
+ 20=>"CREST_FACTOR",
102
+ 9=>"OHM",
103
+ 15=>"FAR",
104
+ 4=>"V",
105
+ 10=>"SIE"},
106
+
107
+ :mode => {
108
+ 16=>"MIN_MAX_AVG",
109
+ 0=>"NONE",
110
+ 1=>"AUTO_HOLD",
111
+ 128=>"REL_PERCENT",
112
+ 2=>"AUTO_SAVE",
113
+ 8=>"LOW_PASS_FILTER",
114
+ 256=>"CALIBRATION",
115
+ 64=>"REL",
116
+ 4=>"HOLD",
117
+ 32=>"RECORD"},
118
+
119
+ :primfunction => {
120
+ 38=>"CAL_FILT_AMP", 27=>"OHMS", 16=>"UA_DC", 5=>"V_AC_OVER_DC", 44=>"CAL_ACDC_AC_COMP",
121
+ 33=>"OHMS_LOW", 22=>"MA_AC_PLUS_DC", 11=>"A_AC", 0=>"LIMBO", 39=>"CAL_DC_AMP_X5",
122
+ 28=>"CONDUCTANCE", 17=>"A_AC_OVER_DC", 6=>"V_DC_OVER_AC", 45=>"CAL_V_AC_LOZ",
123
+ 34=>"CAL_V_DC_LOZ", 23=>"UA_AC_OVER_DC", 12=>"MA_AC", 1=>"V_AC", 40=>"CAL_DC_AMP_X10",
124
+ 29=>"CONTINUITY", 18=>"A_DC_OVER_AC", 7=>"V_AC_PLUS_DC", 46=>"CAL_V_AC_PEAK", 35=>"CAL_AD_GAIN_X2",
125
+ 24=>"UA_DC_OVER_AC", 13=>"UA_AC", 2=>"MV_AC", 41=>"CAL_NINV_AC_AMP", 30=>"CAPACITANCE",
126
+ 19=>"A_AC_PLUS_DC", 8=>"MV_AC_OVER_DC", 47=>"CAL_MV_AC_PEAK", 36=>"CAL_AD_GAIN_X1",
127
+ 25=>"UA_AC_PLUS_DC", 14=>"A_DC", 3=>"V_DC", 42=>"CAL_ISRC_500NA", 31=>"DIODE_TEST",
128
+ 20=>"MA_AC_OVER_DC", 9=>"MV_DC_OVER_AC", 48=>"CAL_TEMPERATURE", 37=>"CAL_RMS",
129
+ 26=>"TEMPERATURE", 15=>"MA_DC", 4=>"MV_DC", 43=>"CAL_COMP_TRIM_MV_DC", 32=>"V_AC_LOZ",
130
+ 21=>"MA_DC_OVER_AC", 10=>"MV_AC_PLUS_DC"},
131
+
132
+ :bolt => {0=>"OFF", 1=>"ON"},
133
+
134
+ :readingid => {
135
+ 5=>"BARGRAPH",
136
+ 11=>"REL_REFERENCE",
137
+ 12=>"DB_REF",
138
+ 1=>"LIVE",
139
+ 7=>"MINIMUM",
140
+ 13=>"TEMP_OFFSET",
141
+ 2=>"PRIMARY",
142
+ 8=>"MAXIMUM",
143
+ 3=>"SECONDARY",
144
+ 9=>"AVERAGE",
145
+ 4=>"REL_LIVE"},
146
+
147
+ :state => {
148
+ 5=>"OL",
149
+ 0=>"INACTIVE",
150
+ 6=>"OL_MINUS",
151
+ 1=>"INVALID",
152
+ 7=>"OPEN_TC",
153
+ 2=>"NORMAL",
154
+ 3=>"BLANK",
155
+ 4=>"DISCHARGE"},
156
+
157
+ :attribute => {
158
+ 5=>"LO_OHMS",
159
+ 0=>"NONE",
160
+ 6=>"NEGATIVE_EDGE",
161
+ 1=>"OPEN_CIRCUIT",
162
+ 7=>"POSITIVE_EDGE",
163
+ 2=>"SHORT_CIRCUIT",
164
+ 8=>"HIGH_CURRENT",
165
+ 3=>"GLITCH_CIRCUIT",
166
+ 4=>"GOOD_DIODE"},
167
+
168
+ :recordtype => {0=>"INPUT", 1=>"INTERVAL"},
169
+
170
+ :isstableflag => {0=>"UNSTABLE", 1=>"STABLE"},
171
+
172
+ :transientstate => {0=>"NON_T", 1=>"RANGE_UP", 2=>"RANGE_DOWN", 3=>"OVERLOAD", 4=>"OPEN_TC"},
173
+ }
174
+
175
+
176
+ end
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dmm_util
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Fredrik Valeur
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-03 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ name: serialport
31
+ prerelease: false
32
+ type: :runtime
33
+ requirement: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ hash: 3
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ name: shoulda
45
+ prerelease: false
46
+ type: :development
47
+ requirement: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ version_requirements: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ hash: 23
55
+ segments:
56
+ - 1
57
+ - 0
58
+ - 0
59
+ version: 1.0.0
60
+ name: bundler
61
+ prerelease: false
62
+ type: :development
63
+ requirement: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ version_requirements: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ hash: 7
71
+ segments:
72
+ - 1
73
+ - 6
74
+ - 4
75
+ version: 1.6.4
76
+ name: jeweler
77
+ prerelease: false
78
+ type: :development
79
+ requirement: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ version_requirements: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ name: rcov
91
+ prerelease: false
92
+ type: :development
93
+ requirement: *id005
94
+ - !ruby/object:Gem::Dependency
95
+ version_requirements: &id006 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ name: mocha
105
+ prerelease: false
106
+ type: :development
107
+ requirement: *id006
108
+ description: Library and command line utility to download data from Fluke 28x series DMMs
109
+ email: fredrik.valeur@appfolio.com
110
+ executables:
111
+ - dmm_util
112
+ extensions: []
113
+
114
+ extra_rdoc_files:
115
+ - LICENSE.txt
116
+ - README.rdoc
117
+ files:
118
+ - .document
119
+ - Gemfile
120
+ - Gemfile.lock
121
+ - LICENSE.txt
122
+ - README.rdoc
123
+ - Rakefile
124
+ - VERSION
125
+ - bin/dmm_util
126
+ - dmm_util.gemspec
127
+ - lib/dmm_util.rb
128
+ - lib/dmm_util/cursor.rb
129
+ - lib/dmm_util/fluke28x_driver.rb
130
+ - lib/dmm_util/format_convertors.rb
131
+ - lib/dmm_util/measurement.rb
132
+ - lib/dmm_util/meter.rb
133
+ - lib/dmm_util/reading.rb
134
+ - lib/dmm_util/recording.rb
135
+ - lib/dmm_util/recording_measurement.rb
136
+ - lib/dmm_util/recording_measurement_cursor.rb
137
+ - test/communication_test.rb
138
+ - test/dmm_command_test.rb
139
+ - test/format_convertors_test.rb
140
+ - test/integration_itest.rb
141
+ - test/measurement_test.rb
142
+ - test/meter_test.rb
143
+ - test/reading_test.rb
144
+ - test/recording_measurement_test.rb
145
+ - test/recording_test.rb
146
+ - test/test_helper.rb
147
+ homepage: http://github.com/fvaleur/dmm_util
148
+ licenses:
149
+ - MIT
150
+ post_install_message:
151
+ rdoc_options: []
152
+
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ hash: 3
161
+ segments:
162
+ - 0
163
+ version: "0"
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ hash: 3
170
+ segments:
171
+ - 0
172
+ version: "0"
173
+ requirements: []
174
+
175
+ rubyforge_project:
176
+ rubygems_version: 1.8.10
177
+ signing_key:
178
+ specification_version: 3
179
+ summary: Library and command line utility to download data from Fluke 28x series DMMs
180
+ test_files: []
181
+