jphastings-PLW-Parse 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/plw.rb +23 -10
- metadata +2 -2
data/plw.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# A hacked up class for parsing the PLW data format from PicoTech (for their Oscilloscope data). Its not meant for speed but (constructive :P) criticism and ideas are welcome!
|
2
2
|
class PLW
|
3
3
|
attr_reader :signature,:version,:params,:PLS
|
4
|
-
attr_reader :sample_num,:no_samples,:max_samples,:interval,:trigger_sample,:triggered,:first_sample,:sample_length,:setting_byte,:start_date,:start_time,:min_time,:max_time,:notes,:current_time
|
4
|
+
attr_reader :sample_num,:no_samples,:max_samples,:interval,:trigger_sample,:triggered,:first_sample,:sample_length,:setting_byte,:start_date,:start_time,:min_time,:max_time,:notes,:current_time,:no_params
|
5
5
|
attr_accessor :current_sample
|
6
6
|
|
7
7
|
# Will take a filename or a file handle (eg. <tt>"filename.plw"</tt> or <tt>open("filename.plw")</tt>)
|
@@ -62,19 +62,32 @@ class PLW
|
|
62
62
|
# * :time : The time offset of this sample, in seconds
|
63
63
|
# * :data : The data for each channel as a hash
|
64
64
|
def getSamples(n=1)
|
65
|
-
if
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
if n == :all
|
66
|
+
current_sample = 0
|
67
|
+
n = @no_samples - 1
|
68
|
+
else
|
69
|
+
if (@current_sample + n > @no_samples)
|
70
|
+
n = @no_samples - @current_sample
|
71
|
+
if n < 1
|
72
|
+
return false
|
73
|
+
end
|
69
74
|
end
|
70
75
|
end
|
71
76
|
|
72
|
-
|
77
|
+
((@current_sample + 1)..(@current_sample += n)).to_a.collect{ |sample_num|
|
78
|
+
{
|
79
|
+
:time => getuint32*@interval_units,
|
80
|
+
:data => (1..@no_params).to_a.collect { |param_index| getFloat() }
|
81
|
+
}
|
82
|
+
}.flatten
|
73
83
|
end
|
74
|
-
|
84
|
+
|
75
85
|
# A convenience method that just gives the next sample only
|
76
86
|
def getSample
|
77
|
-
getSamples(1)
|
87
|
+
if not (sample = getSamples(1))
|
88
|
+
return false
|
89
|
+
end
|
90
|
+
sample[0]
|
78
91
|
end
|
79
92
|
|
80
93
|
private
|
@@ -82,7 +95,7 @@ class PLW
|
|
82
95
|
def getbytes(numbytes)
|
83
96
|
data = ""
|
84
97
|
numbytes.times do |time|
|
85
|
-
data<<@file.
|
98
|
+
data<<@file.readpartial(1)
|
86
99
|
end
|
87
100
|
data
|
88
101
|
end
|
@@ -110,7 +123,7 @@ class PLW
|
|
110
123
|
end
|
111
124
|
getbytes(2*(250 - @no_params)) # The remaining params aren't used
|
112
125
|
@sample_num = getuint32() # Same as @no_samples unless wraparound occured
|
113
|
-
@no_samples = getuint32()
|
126
|
+
@no_samples = getuint32()
|
114
127
|
@max_samples = getuint32()
|
115
128
|
@interval = getuint32()
|
116
129
|
case getuint16() # next 16 bits are the 'interval unit'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jphastings-PLW-Parse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JP Hastings-Spital
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-05-16 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|