elia 1.2.0 → 2.3.2

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.
data/Rakefile CHANGED
@@ -44,3 +44,10 @@ Rake::RDocTask.new do |rdoc|
44
44
  rdoc.rdoc_files.include('README*')
45
45
  rdoc.rdoc_files.include('lib/**/*.rb')
46
46
  end
47
+
48
+ task :tag do
49
+ root = File.dirname(__FILE__)
50
+ version = File.read( File.join(root,'VERSION') )
51
+ exec "git tag -f v#{version}"
52
+ end
53
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 2.3.2
@@ -1,4 +1,5 @@
1
1
  require 'world_logger'
2
+ require 'ruby19' # for string ecoding compatibility
2
3
 
3
4
  #
4
5
  # BitFields provides a simple way to extract a values from bit fields,
@@ -70,6 +71,11 @@ module BitFields
70
71
  # Collects the full <tt>String#unpack</tt> directive used to parse the raw value.
71
72
  attr_reader :unpack_recipe
72
73
 
74
+ # Defines accessors for the attributes hash
75
+ def bits_attr_accessor name
76
+ class_eval "def #{name}; self.attributes[#{name.inspect}]; end;", __FILE__, __LINE__
77
+ class_eval "def #{name}=(val); self.attributes[#{name.inspect}]=val; end;", __FILE__, __LINE__
78
+ end
73
79
 
74
80
  ##
75
81
  # Defines a field to be extracted with String#unpack from the raw value
@@ -80,6 +86,8 @@ module BitFields
80
86
  #
81
87
  # Also defines the attribute reader method
82
88
  #
89
+ # TODO: add a skip bits syntax
90
+ #
83
91
  def field name, unpack_recipe = 'C', &bit_fields_definitions_block
84
92
  include InstanceMethods # when used we include instance methods
85
93
 
@@ -92,8 +100,8 @@ module BitFields
92
100
  @unpack_recipe << unpack_recipe
93
101
  @fields << name
94
102
 
95
- # Define the attribute reader
96
- class_eval "def #{name}; self.attributes[#{name.inspect}]; end;", __FILE__, __LINE__
103
+ # Define the attribute accessor
104
+ bits_attr_accessor(name)
97
105
 
98
106
  # There's a bit-structure too?
99
107
  if block_given?
@@ -101,7 +109,7 @@ module BitFields
101
109
 
102
110
  bit_fields_definitions_block.call
103
111
 
104
- @bit_fields[name] = @_current_bit_fields.reverse
112
+ @bit_fields[name] = @_current_bit_fields
105
113
  @_current_bit_fields = nil
106
114
  end
107
115
  end
@@ -112,14 +120,17 @@ module BitFields
112
120
  # +name+ :: the name of the bit field (that will be used to access it)
113
121
  # +width+ :: the number of bits from which this value should be extracted
114
122
  #
123
+ # TODO: add options to enable method aliases
124
+ # TODO: add a skip bits syntax
125
+ #
115
126
  def bit_field name, width
116
127
  raise "'bit_field' can be used only inside a 'field' block." if @_current_bit_fields.nil?
117
128
 
118
129
  # Register the bit field definition
119
130
  @_current_bit_fields << [name, width, bit_mask(width)]
120
131
 
121
- # Define the attribute reader
122
- class_eval "def #{name}; self.attributes[#{name.inspect}]; end\n", __FILE__, __LINE__
132
+ # Define the attribute accessor
133
+ bits_attr_accessor(name)
123
134
 
124
135
  if width == 1 or name.to_s =~ /_flag$/
125
136
  # Define a question mark method if the size is 1 bit
@@ -151,9 +162,17 @@ module BitFields
151
162
  # caches the bin string unpacked values
152
163
  attr_reader :unpacked
153
164
 
165
+ class ValueOverflow < StandardError
166
+ end
167
+
154
168
  # Takes the raw binary string and parses it
155
- def initialize bit_string
156
- parse_bit_fields(bit_string.dup.freeze)
169
+ def initialize bit_string_or_hash
170
+ if bit_string_or_hash.kind_of?(Hash)
171
+ @attributes = bit_string_or_hash
172
+ pack_bit_fields
173
+ else
174
+ parse_bit_fields(bit_string_or_hash) #.dup.freeze REMOVED: seems useless
175
+ end
157
176
  end
158
177
 
159
178
  # Makes defined fields accessible like a +Hash+
@@ -163,19 +182,6 @@ module BitFields
163
182
 
164
183
  private
165
184
 
166
- def eat_right_bits original_value, bits_number, bit_mask
167
- # Filter the original value with the
168
- # proper bitmask to get the rightmost bits
169
- new_value = original_value & bit_mask
170
-
171
- # Eat those rightmost bits
172
- # wich we have just consumed
173
- remaning = original_value >> bits_number
174
-
175
- # Return also the remaning bits
176
- return new_value, remaning
177
- end
178
-
179
185
  # Parses the raw value extracting the defined bit fields
180
186
  def parse_bit_fields raw
181
187
  @raw = raw
@@ -188,21 +194,55 @@ module BitFields
188
194
 
189
195
  @attributes[name] = @unpacked[position]
190
196
 
191
- # We must extract bits from end since
192
- # ruby doesn't have types (and fixed lengths)
193
197
  if bit_fields = self.class.bit_fields[name]
194
-
198
+
195
199
  bit_value = attributes[name]
200
+
201
+ # We must extract bits from end since
202
+ # ruby doesn't have types (and fixed lengths)
203
+ bit_fields.reverse.each do |(bit_name, bits_number, bit_mask)|
204
+ @attributes[bit_name] = bit_value & bit_mask
205
+ bit_value = bit_value >> bits_number
206
+ end
207
+ end
208
+ end
209
+ end
210
+
211
+ public
212
+
213
+
214
+ # Parses the raw value extracting the defined bit fields
215
+ def pack_bit_fields
216
+ @unpacked = []
217
+
218
+ self.class.fields.each_with_index do |name, position|
219
+
220
+ if bit_fields = self.class.bit_fields[name]
221
+
222
+ bit_value = 0
196
223
  bit_fields.each do |(bit_name, bits_number, bit_mask)|
197
- # @attributes[bit_name], bit_value = eat_right_bits(bit_value, bits_number, bit_mask)
198
- # logger.debug "#{bit_name.to_s.rjust(20)}: #{bit_value.to_s(2).rjust(40)} & #{bit_mask.to_s(2).rjust(20)} = #{(bit_value & bit_mask).to_s(2).rjust(20)}"
224
+ masked = @attributes[bit_name] & bit_mask
225
+
226
+ raise ValueOverflow,
227
+ "the value #{@attributes[bit_name]} "+
228
+ "is too big for #{bits_number} bits" if masked != @attributes[bit_name]
199
229
 
200
- @attributes[bit_name] = bit_value & bit_mask
201
- bit_value = bit_value >> bits_number
230
+ bit_value = bit_value << bits_number
231
+ bit_value |= masked
202
232
  end
233
+
234
+ # Value of fields composed by binary fields is always overwritten
235
+ # by the composition of the latter
236
+ attributes[name] = bit_value
203
237
  end
238
+
239
+ @unpacked[position] = @attributes[name] || 0
240
+
204
241
  end
242
+
243
+ @raw = @unpacked.pack( self.class.unpack_recipe )
205
244
  end
245
+ alias pack pack_bit_fields
206
246
 
207
247
  def to_s
208
248
  raw.to_s
@@ -0,0 +1,11 @@
1
+ module ErrnoKnows
2
+ def knows? error
3
+ @constants ||= constants.map{|n| const_get(n)}
4
+ @constants.include? error.class
5
+ end
6
+ end
7
+
8
+ module Errno
9
+ extend ErrnoKnows
10
+ end
11
+
@@ -5,7 +5,7 @@ module FileWithBufferedRead
5
5
 
6
6
  def buffered_read size
7
7
  output = read_buffer.read(size)
8
- until output.size == size or self.eof?
8
+ until output.nil? or output.size == size or self.eof?
9
9
  output << read_buffer.read(size - output.size)
10
10
  end
11
11
  return output
@@ -19,7 +19,7 @@ module FileWithBufferedRead
19
19
  def read_buffer
20
20
  if @read_buffer.nil? or @read_buffer.eof?
21
21
  # logger.debug{ "Buffering #{READ_BUFFER_SIZE} from #{self.inspect} current position: #{self.pos}" }
22
- @read_buffer = StringIO.new(read(READ_BUFFER_SIZE))
22
+ @read_buffer = StringIO.new(read(READ_BUFFER_SIZE) || '')
23
23
  # logger.debug{ "Buffered #{@read_buffer.size}, EOF:#{self.eof?} current position: #{self.pos}" }
24
24
  @buffer_left = @read_buffer.size
25
25
  end
@@ -0,0 +1,31 @@
1
+ module Ini
2
+ def parse_ini(input)
3
+ hash = {}
4
+ current_section = nil
5
+
6
+ input.each_line do |line|
7
+ line = line.sub(/\;.*$/, '').strip.chomp.strip # strip comments
8
+ next if line.strip.empty?
9
+
10
+ if line.strip =~ /\[([^\]]+)\]/
11
+ current_section = $1.downcase
12
+ hash[current_section] ||= {}
13
+ else
14
+ key, value = line.split('=')
15
+
16
+ value.strip!
17
+ value = case value
18
+ when /0x[\da-f]/i : value.hex
19
+ when /^[\+\-]?\d+$/ : value.to_i
20
+ when /^\"(.*)\"$/ : $1
21
+ else value
22
+ end
23
+ hash[current_section][key.downcase] = value
24
+ end
25
+ end
26
+
27
+ hash
28
+ end
29
+
30
+ extend self
31
+ end
@@ -0,0 +1,7 @@
1
+ # A collection of backports from Ruby 1.9 to ruby 1.8
2
+
3
+ class Object
4
+ def ruby18 &block
5
+ block.call if RUBY_VERSION.to_f == 1.8
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ require 'ruby19'
2
+
3
+ ruby18 do
4
+ module Binread
5
+ def binread path_or_file_descriptor
6
+ open(path_or_file_descriptor,'rb'){|io| io.read }
7
+ end
8
+ end
9
+
10
+ IO.extend(Binread)
11
+ File.extend(Binread)
12
+
13
+ class String
14
+ def encode encoding
15
+ if %w[BINARY ASCII-8BIT].include? encoding
16
+ return self
17
+ else
18
+ super
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ require 'ruby19'
2
+
3
+ ruby18 do
4
+
5
+ # from http://github.com/tmm1/fiber18
6
+ require 'ruby19/tmm1-fiber18-a37a4c3/lib/fiber18'
7
+
8
+ end
@@ -0,0 +1,21 @@
1
+ Poor Man's Fiber (API compatible Thread based Fiber implementation for Ruby 1.8)
2
+ (c) 2008 Aman Gupta (tmm1)
3
+
4
+ == Usage
5
+
6
+ f = Fiber.new{ |sym|
7
+ p(sym)
8
+ puts 'hi'
9
+ p(Fiber.yield 1)
10
+ puts 'bye'
11
+ :end
12
+ }
13
+ p(f.resume :begin)
14
+ p(f.resume 2)
15
+
16
+ :begin
17
+ hi
18
+ 1
19
+ 2
20
+ bye
21
+ :end
@@ -0,0 +1,8 @@
1
+ task :test do
2
+ # sh 'ruby -Ilib -rfiber18 test/test_fiber.rb'
3
+ $:.unshift 'lib'
4
+ require 'fiber18'
5
+ require 'test/test_fiber'
6
+ end
7
+
8
+ task :default => :test
@@ -0,0 +1,96 @@
1
+ # Poor Man's Fiber (API compatible Thread based Fiber implementation for Ruby 1.8)
2
+ # (c) 2008 Aman Gupta (tmm1)
3
+
4
+ unless defined? Fiber
5
+ $:.unshift File.expand_path(File.dirname(__FILE__)) + '/compat'
6
+ require 'thread'
7
+
8
+ class FiberError < StandardError; end
9
+
10
+ class Fiber
11
+ def initialize
12
+ raise ArgumentError, 'new Fiber requires a block' unless block_given?
13
+
14
+ @yield = Queue.new
15
+ @resume = Queue.new
16
+
17
+ @thread = Thread.new{ @yield.push [yield(*@resume.pop)] }
18
+ @thread.abort_on_exception = true
19
+ @thread[:fiber] = self
20
+ end
21
+ attr_reader :thread
22
+
23
+ def resume *args
24
+ raise FiberError, 'dead fiber called' unless @thread.alive?
25
+ @resume.push(args)
26
+ result = @yield.pop
27
+ result.size > 1 ? result : result.first
28
+ end
29
+
30
+ def yield *args
31
+ @yield.push(args)
32
+ result = @resume.pop
33
+ result.size > 1 ? result : result.first
34
+ end
35
+
36
+ def self.yield *args
37
+ if fiber = Thread.current[:fiber]
38
+ fiber.yield(*args)
39
+ else
40
+ raise FiberError, 'not inside a fiber'
41
+ end
42
+ end
43
+
44
+ def self.current
45
+ if Thread.current == Thread.main
46
+ return Thread.main[:fiber] ||= RootFiber.new
47
+ end
48
+
49
+ Thread.current[:fiber] or raise FiberError, 'not inside a fiber'
50
+ end
51
+
52
+ def inspect
53
+ "#<#{self.class}:0x#{self.object_id.to_s(16)}>"
54
+ end
55
+ end
56
+
57
+ class RootFiber < Fiber
58
+ def initialize
59
+ # XXX: what is a root fiber anyway?
60
+ end
61
+
62
+ def self.yield *args
63
+ raise FiberError, "can't yield from root fiber"
64
+ end
65
+ end
66
+ end
67
+
68
+ if __FILE__ == $0
69
+ f = Fiber.new{ |sym|
70
+ p(sym)
71
+ puts 'hi'
72
+ p(Fiber.yield 1)
73
+ puts 'bye'
74
+ :end
75
+ }
76
+ p(f.resume :begin)
77
+ p(f.resume 2)
78
+ end
79
+
80
+ __END__
81
+
82
+ $ ruby fbr.rb
83
+ :begin
84
+ hi
85
+ 1
86
+ 2
87
+ bye
88
+ :end
89
+
90
+ $ ruby1.9 fbr.rb
91
+ :begin
92
+ hi
93
+ 1
94
+ 2
95
+ bye
96
+ :end
@@ -0,0 +1,165 @@
1
+ require 'test/unit'
2
+ require 'fiber'
3
+ require 'continuation'
4
+
5
+ class TestFiber < Test::Unit::TestCase
6
+ def test_normal
7
+ f = Fiber.current
8
+ assert_equal(:ok2,
9
+ Fiber.new{|e|
10
+ assert_equal(:ok1, e)
11
+ Fiber.yield :ok2
12
+ }.resume(:ok1)
13
+ )
14
+ assert_equal([:a, :b], Fiber.new{|a, b| [a, b]}.resume(:a, :b))
15
+ end
16
+
17
+ def test_term
18
+ assert_equal(:ok, Fiber.new{:ok}.resume)
19
+ assert_equal([:a, :b, :c, :d, :e],
20
+ Fiber.new{
21
+ Fiber.new{
22
+ Fiber.new{
23
+ Fiber.new{
24
+ [:a]
25
+ }.resume + [:b]
26
+ }.resume + [:c]
27
+ }.resume + [:d]
28
+ }.resume + [:e])
29
+ end
30
+
31
+ def test_many_fibers
32
+ max = 10000
33
+ assert_equal(max, max.times{
34
+ Fiber.new{}
35
+ })
36
+ assert_equal(max,
37
+ max.times{|i|
38
+ Fiber.new{
39
+ }.resume
40
+ }
41
+ )
42
+ end
43
+ end
44
+ __END__
45
+
46
+ def test_many_fibers_with_threads
47
+ max = 1000
48
+ @cnt = 0
49
+ (1..100).map{|ti|
50
+ Thread.new{
51
+ max.times{|i|
52
+ Fiber.new{
53
+ @cnt += 1
54
+ }.resume
55
+ }
56
+ }
57
+ }.each{|t|
58
+ t.join
59
+ }
60
+ assert_equal(:ok, :ok)
61
+ end
62
+
63
+ def test_error
64
+ assert_raise(ArgumentError){
65
+ Fiber.new # Fiber without block
66
+ }
67
+ assert_raise(FiberError){
68
+ f = Fiber.new{}
69
+ Thread.new{f.resume}.join # Fiber yielding across thread
70
+ }
71
+ assert_raise(FiberError){
72
+ f = Fiber.new{}
73
+ f.resume
74
+ f.resume
75
+ }
76
+ assert_raise(RuntimeError){
77
+ f = Fiber.new{
78
+ @c = callcc{|c| @c = c}
79
+ }.resume
80
+ @c.call # cross fiber callcc
81
+ }
82
+ assert_raise(RuntimeError){
83
+ Fiber.new{
84
+ raise
85
+ }.resume
86
+ }
87
+ assert_raise(FiberError){
88
+ Fiber.yield
89
+ }
90
+ assert_raise(FiberError){
91
+ fib = Fiber.new{
92
+ fib.resume
93
+ }
94
+ fib.resume
95
+ }
96
+ assert_raise(FiberError){
97
+ fib = Fiber.new{
98
+ Fiber.new{
99
+ fib.resume
100
+ }.resume
101
+ }
102
+ fib.resume
103
+ }
104
+ end
105
+
106
+ def test_return
107
+ assert_raise(LocalJumpError){
108
+ Fiber.new do
109
+ return
110
+ end.resume
111
+ }
112
+ end
113
+
114
+ def test_throw
115
+ assert_raise(ArgumentError){
116
+ Fiber.new do
117
+ throw :a
118
+ end.resume
119
+ }
120
+ end
121
+
122
+ def test_transfer
123
+ ary = []
124
+ f2 = nil
125
+ f1 = Fiber.new{
126
+ ary << f2.transfer(:foo)
127
+ :ok
128
+ }
129
+ f2 = Fiber.new{
130
+ ary << f1.transfer(:baz)
131
+ :ng
132
+ }
133
+ assert_equal(:ok, f1.transfer)
134
+ assert_equal([:baz], ary)
135
+ end
136
+
137
+ def test_tls
138
+ #
139
+ def tvar(var, val)
140
+ old = Thread.current[var]
141
+ begin
142
+ Thread.current[var] = val
143
+ yield
144
+ ensure
145
+ Thread.current[var] = old
146
+ end
147
+ end
148
+
149
+ fb = Fiber.new {
150
+ assert_equal(nil, Thread.current[:v]); tvar(:v, :x) {
151
+ assert_equal(:x, Thread.current[:v]); Fiber.yield
152
+ assert_equal(:x, Thread.current[:v]); }
153
+ assert_equal(nil, Thread.current[:v]); Fiber.yield
154
+ raise # unreachable
155
+ }
156
+
157
+ assert_equal(nil, Thread.current[:v]); tvar(:v,1) {
158
+ assert_equal(1, Thread.current[:v]); tvar(:v,3) {
159
+ assert_equal(3, Thread.current[:v]); fb.resume
160
+ assert_equal(3, Thread.current[:v]); }
161
+ assert_equal(1, Thread.current[:v]); }
162
+ assert_equal(nil, Thread.current[:v]); fb.resume
163
+ assert_equal(nil, Thread.current[:v]);
164
+ end
165
+ end
@@ -1,3 +1,7 @@
1
- require 'haml'
1
+ require 'sass'
2
+ require 'sass/plugin'
2
3
 
3
- Sass::Plugin.options[:loadpaths] << File.dirname(__FILE__) + '/sass_support'
4
+ Sass::Plugin.instance_eval {
5
+ @options[:load_paths] ||= []
6
+ @options[:load_paths] << File.join( File.dirname(__FILE__), 'sass_support' )
7
+ }
@@ -0,0 +1,7 @@
1
+ // Example:
2
+ // +box-shadow(#000 0px 0px 20px)
3
+
4
+ =box-shadow(!string)
5
+ -webkit-box-shadow: #{!string}
6
+ -moz-box-shadow: #{!string}
7
+ box-shadow: #{!string}
@@ -0,0 +1,3 @@
1
+ @import border_radius.sass
2
+ @import box_shadow.sass
3
+ @import transform_rotate.sass
@@ -0,0 +1,5 @@
1
+ =transform-rotate(!deg)
2
+ -webkit-transform: rotate(#{!deg}deg)
3
+ -moz-transform: rotate(#{!deg}deg)
4
+ rotation: #{!deg}deg
5
+ filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=#{!deg})
@@ -10,8 +10,15 @@ module WorldLogger
10
10
  @logger
11
11
  end
12
12
 
13
+ class NoRaiseObject
14
+ def method_missing name, *args, &block
15
+ return self
16
+ end
17
+ end
13
18
 
14
19
  def logger
20
+ return @__no_raise_object ||= NoRaiseObject.new if @__logger_disabled
21
+
15
22
  if self.class.const_defined? :Rails
16
23
  Rails.logger
17
24
  else
@@ -19,6 +26,14 @@ module WorldLogger
19
26
  end
20
27
  end
21
28
 
29
+ def disable_logger!
30
+ @__logger_disabled = true
31
+ end
32
+
33
+ def enable_logger!
34
+ @__logger_disabled = false
35
+ end
36
+
22
37
  end
23
38
 
24
39
  Object.send :include, WorldLogger
@@ -58,5 +58,12 @@ describe BitFields do
58
58
  @object.should respond_to(:secondary_header?)
59
59
  @object.secondary_header?.should == true
60
60
  end
61
+
62
+ it 'should be able to repack from its attributes correctly' do
63
+ repacked = @klass.new @object.attributes
64
+ repacked.raw.should == @object.raw
65
+ reunpacked = @klass.new repacked.raw
66
+ reunpacked.attributes.should == repacked.attributes
67
+ end
61
68
  end
62
69
 
@@ -0,0 +1,69 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+ require 'ini'
3
+
4
+ INI_DATA = <<-INI
5
+ [general]\r
6
+ SequenceRepetition=100\r
7
+ BitRate=100\r
8
+ pri=5\r\n
9
+ \r\n
10
+ [packet_sequence]\r\n
11
+ TM_1=3\r\n
12
+
13
+ [TM_1]
14
+ PriOffset=0
15
+ type="CCSDS"
16
+ LogicalAddress=0x01
17
+ ProtocolID=3
18
+ VersionNumber=1
19
+ PacketType=0
20
+ DataFieldHeaderFlag=1
21
+ APID=1;ciao
22
+ ;come stai
23
+ ;molto bene
24
+ SegmentationFlags=3
25
+ SourceSequenceCounter=-1
26
+ PacketDataFieldLength=4096
27
+ PUSVersion=3
28
+ ServiceType=7
29
+ ServiceSubType=0x1E
30
+ DestinationId=5
31
+ time=-1
32
+ DataElementType=pattern
33
+ PatternFile=file_pattern.bin
34
+ INI
35
+
36
+ INI_HASH = {
37
+ "general"=>{
38
+ "bitrate"=>100,
39
+ "pri"=>5,
40
+ "sequencerepetition"=>100},
41
+ "packet_sequence"=>{
42
+ "tm_1"=>3},
43
+ "tm_1"=> {
44
+ "destinationid"=>5,
45
+ "datafieldheaderflag"=>1,
46
+ "dataelementtype"=>"pattern",
47
+ "apid"=>1,
48
+ "versionnumber"=>1,
49
+ "time"=>-1,
50
+ "sourcesequencecounter"=>-1,
51
+ "logicaladdress"=>1,
52
+ "patternfile"=>"file_pattern.bin",
53
+ "packetdatafieldlength"=>4096,
54
+ "servicetype"=>7,
55
+ "packettype"=>0,
56
+ "type"=>"CCSDS",
57
+ "prioffset"=>0,
58
+ "servicesubtype"=>30,
59
+ "segmentationflags"=>3,
60
+ "pusversion"=>3,
61
+ "protocolid"=>3}
62
+ }
63
+
64
+ describe Ini do
65
+ it 'should parse INI files' do
66
+ Ini.parse_ini(INI_DATA).should == INI_HASH
67
+ end
68
+ end
69
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elia
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elia Schito
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-11 00:00:00 +01:00
12
+ date: 2010-01-19 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -37,30 +37,39 @@ files:
37
37
  - Rakefile
38
38
  - VERSION
39
39
  - lib/bit_fields.rb
40
- - lib/ccsds.rb
41
- - lib/ccsds/cuc.rb
42
40
  - lib/elia.rb
41
+ - lib/errno_knows.rb
43
42
  - lib/file_with_read_buffer.rb
44
43
  - lib/indifferent_reader.rb
44
+ - lib/ini.rb
45
45
  - lib/io_string.rb
46
46
  - lib/path_operator.rb
47
47
  - lib/process_extensions.rb
48
+ - lib/ruby19.rb
49
+ - lib/ruby19/binread.rb
50
+ - lib/ruby19/fiber.rb
51
+ - lib/ruby19/tmm1-fiber18-a37a4c3/README
52
+ - lib/ruby19/tmm1-fiber18-a37a4c3/Rakefile
53
+ - lib/ruby19/tmm1-fiber18-a37a4c3/lib/compat/continuation.rb
54
+ - lib/ruby19/tmm1-fiber18-a37a4c3/lib/compat/fiber.rb
55
+ - lib/ruby19/tmm1-fiber18-a37a4c3/lib/fiber18.rb
56
+ - lib/ruby19/tmm1-fiber18-a37a4c3/test/test_fiber.rb
48
57
  - lib/sass_support.rb
49
58
  - lib/sass_support/_border_radius.sass
59
+ - lib/sass_support/_box_shadow.sass
60
+ - lib/sass_support/_css3.sass
50
61
  - lib/sass_support/_glider.sass
62
+ - lib/sass_support/_transform_rotate.sass
51
63
  - lib/slapp.rb
52
- - lib/space_wire.rb
53
64
  - lib/string_nibbles.rb
54
65
  - lib/world_logger.rb
55
66
  - spec/lib/bit_fields_spec.rb
56
67
  - spec/lib/ccsds_spec.rb
57
68
  - spec/lib/elia_spec.rb
58
69
  - spec/lib/indifferent_reader_spec.rb
70
+ - spec/lib/ini_spec.rb
59
71
  - spec/lib/path_operator_spec.rb
60
72
  - spec/lib/process_extensions_spec.rb
61
- - spec/lib/space_wire/data.bin
62
- - spec/lib/space_wire/index.bin
63
- - spec/lib/space_wire_spec.rb
64
73
  - spec/lib/string_nibbles_spec.rb
65
74
  - spec/spec.opts
66
75
  - spec/spec_helper.rb
@@ -97,8 +106,8 @@ test_files:
97
106
  - spec/lib/ccsds_spec.rb
98
107
  - spec/lib/elia_spec.rb
99
108
  - spec/lib/indifferent_reader_spec.rb
109
+ - spec/lib/ini_spec.rb
100
110
  - spec/lib/path_operator_spec.rb
101
111
  - spec/lib/process_extensions_spec.rb
102
- - spec/lib/space_wire_spec.rb
103
112
  - spec/lib/string_nibbles_spec.rb
104
113
  - spec/spec_helper.rb
@@ -1,167 +0,0 @@
1
- # This links the logger method to Rails.logger
2
- require 'world_logger'
3
- require 'io_string'
4
- require 'bit_fields'
5
- require 'active_support'
6
- require 'string_nibbles'
7
-
8
- module CCSDS
9
-
10
- class Packet
11
-
12
- # HEADER
13
-
14
- class Header
15
- extend BitFields
16
- field :packet_identification, 'n' do
17
- bit_field :version, 3
18
- bit_field :type, 1
19
- bit_field :data_header, 1
20
- bit_field :apid, 11
21
- end
22
- field :packet_sequence_control, 'n' do
23
- bit_field :segmentation_flags, 2
24
- bit_field :ssc, 14
25
- end
26
- field :packet_length, 'n'
27
- def data_size
28
- packet_length + 1
29
- end
30
-
31
- SIZE = 6 # bytes
32
- end
33
-
34
-
35
-
36
-
37
- # DATA HEADER
38
-
39
- # Data Header is different for each project,
40
- # so we assume it isn't present but we provide builtin support for it.
41
- #
42
- # If the header has
43
- #
44
- # Example:
45
- #
46
- # class DataHeader
47
- # extend BitFields
48
- # field :unknown
49
- # SIZE = 1 # bytes
50
- # end
51
- #
52
-
53
-
54
-
55
-
56
- # ERRORS
57
-
58
- class DataError < StandardError
59
- attr_reader :packet
60
- def initialize message, packet
61
- @packet = packet
62
- super(message)
63
- end
64
- end
65
-
66
-
67
-
68
-
69
- # ATTRIBUTES
70
-
71
- attr_reader :data, :header, :data_header
72
-
73
- # Delegate unknown methods to packet header.
74
- def method_missing name, *args
75
- if header.respond_to? name
76
- header.send name, *args
77
- else
78
- super
79
- end
80
- end
81
-
82
- def raw
83
- header.raw + data
84
- end
85
-
86
- def data= data
87
- raise "Data already filled: #{@data.inspect}" unless @data.blank?
88
- @data = data
89
- end
90
-
91
-
92
-
93
-
94
- # INITAILIZATION
95
-
96
- def initialize raw, validate_now = true
97
- raise DataError.new("Received no RAW data to build the CCSDS Packet: #{raw.inspect}", self) if raw.blank?
98
-
99
- # logger.debug { "Parsing CCSDS header" }
100
- # @header = Header.new(raw[0...Header::SIZE]) # Packet Header
101
- @header = Header.new(raw) # Packet Header
102
- @data = raw[Header::SIZE..-1] # Packet Payload
103
- validate! if validate_now
104
-
105
- if defined? DataHeader
106
- raise "You should define CCSDS::Packet::DataHeader class" unless defined? DataHeader
107
-
108
- @data_header = DataHeader.new( @data[0 ... DataHeader::SIZE] )
109
-
110
- # Update the data contents excluding the Data Header
111
- @data = @data[DataHeader::SIZE .. -1]
112
- end
113
- end
114
-
115
-
116
-
117
-
118
- # VALIDATION
119
-
120
- def validate
121
- @errors = []
122
- if data.size != header.data_size
123
- @errors << "Available data (#{data.size} bytes) is different than "+
124
- "specified by the CCSDS packet header (#{header.data_size} bytes)."+
125
- "\nHeader #{header.raw.nibbles.inspect} dump: #{header.inspect}"
126
- end
127
- end
128
-
129
- def validate!
130
- validate
131
- raise DataError.new(@errors.first, self) unless @errors.blank?
132
- end
133
-
134
- def valid?
135
- validate
136
- return @errors.empty?
137
- end
138
-
139
-
140
-
141
-
142
- # PACKET EXTRACTION
143
-
144
- class << self
145
- include IndifferentReader
146
-
147
- def extract_packet io_or_string, *errors_to_rescue
148
- begin
149
- packet = new( io_or_string.io.read(Header::SIZE), false )
150
- packet.data = io_or_string.io.read(packet.data_size)
151
- packet.validate!
152
- return packet
153
- rescue *errors_to_rescue
154
- logger.info "Rescued error: (#{$!.class}) #{$!.to_s}"
155
- return nil # just go on...
156
- end
157
- end
158
-
159
- def each_packet io_or_string, *errors_to_rescue
160
- while packet = extract_packet(io_or_string, *errors_to_rescue)
161
- yield packet
162
- end
163
- end
164
- end
165
-
166
- end
167
- end
@@ -1,29 +0,0 @@
1
- # CCSDS Unsegmented Time Code
2
-
3
-
4
- module CCSDS
5
- module CUC
6
-
7
- # def cuc_time time
8
- # secs, msecs = time.to_f.divmod(1) # split integer and fractional parts
9
- # msecs = (msecs * 256).to_i
10
- # [secs, msecs].pack('xN C') # cut off first byte: "@" skips a byte
11
- # end
12
- #
13
- # def self.cuc_time_parse cuc
14
- # secs, msecs = (0.chr + cuc).unpack('xN C')
15
- # time = secs + (msecs / 256.0)
16
- # Time.at(time)
17
- # end
18
-
19
- class << self
20
- # coarse are seconds
21
- # fine are milliseconds muliplied for 256
22
- def parse coarse, fine
23
- secs, usecs = coarse, ((fine * 15.0) / 1_000_000.0)
24
- Time.at(secs + usecs)
25
- end
26
- end
27
-
28
- end
29
- end
@@ -1,142 +0,0 @@
1
- require 'bit_fields'
2
- require 'indifferent_reader'
3
- require 'file_with_read_buffer'
4
-
5
- module SpaceWire
6
-
7
-
8
- # Reads the index file generated by the SpaceWire FEE
9
- # along with the binary file.
10
- class Index
11
-
12
- # Each line of the Index is 9 bytes:
13
- # * 1 for en of packet character
14
- # * 8 indicating the byte position of the end of the
15
- # packet inside of the binady file
16
- class Record
17
- extend BitFields
18
- field :error_control, 'c'
19
- field :end_position, 'Q'
20
-
21
- alias bad_end_position end_position
22
- def end_position
23
- bad_end_position + 1
24
- end
25
-
26
- SIZE = 9
27
- end
28
-
29
- include IndifferentReader
30
- attr_reader :records
31
-
32
- def records
33
- if @records.nil?
34
- @records = []
35
- each do |record|
36
- @records << record
37
- end
38
- end
39
- @records
40
- end
41
-
42
- # Takes a string, string io, or any io
43
- def initialize(io_or_string)
44
- @source = io_or_string
45
- end
46
-
47
- def each
48
- if @records.nil?
49
- @records = []
50
-
51
- while line = @source.io.read(Record::SIZE)
52
- record = Record.new(line)
53
- @records << record
54
- yield record if block_given?
55
- end
56
- else
57
- block_given? ? records.each(&block) : records
58
- end
59
- end
60
- end
61
-
62
-
63
- class Data
64
- attr_reader :file, :index
65
-
66
- def initialize file_path, index_path
67
- @file_path, @index_path = file_path, index_path
68
-
69
- @file = File.open(@file_path)
70
- @file.extend FileWithBufferedRead
71
-
72
- @index = Index.new File.read(@index_path)
73
- end
74
-
75
- def each_packet
76
- previous_end_position = 0
77
- index.each do |packet_index|
78
- packet_size = packet_index.end_position - previous_end_position
79
-
80
- packet = file.buffered_read(packet_size).extend(Packet)
81
- # packet = extract_packet(previous_end_position, packet_index.end_position)
82
- yield packet
83
- previous_end_position = packet_index.end_position
84
- end
85
- end
86
-
87
- def packets
88
- if @packets.nil?
89
- @packets = []
90
- each_packet { |packet| @packets << packet }
91
- end
92
- @packets
93
- end
94
-
95
- def extract_packet start_position, end_position
96
- previous_file_position = file.pos
97
- file.seek start_position
98
- packet = file.read(end_position - start_position)
99
- file.seek previous_file_position
100
-
101
- packet.extend Packet
102
- packet.header_size = 4
103
- packet
104
- end
105
-
106
- def [] position
107
- if position == 0
108
- then start_position = 0
109
- else start_position = index.records[position - 1].end_position
110
- end
111
-
112
- end_position = index.records[ position ].end_position
113
- extract_packet(start_position, end_position)
114
- end
115
- end
116
-
117
-
118
- module Packet
119
- HEADER_SIZE = 4
120
- def raw
121
- self
122
- end
123
-
124
- def header
125
- self[0 ... HEADER_SIZE]
126
- end
127
-
128
- def data
129
- self[HEADER_SIZE ...-1]
130
- end
131
-
132
- def end_of_packet_char
133
- self[-1].chr
134
- end
135
- end
136
-
137
-
138
-
139
- def self.rote_quadrate
140
- raise "È una doccia fredda!"
141
- end
142
- end
Binary file
@@ -1,53 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require 'space_wire'
3
- require 'stringio'
4
-
5
- describe SpaceWire do
6
- before :all do
7
- base_dir = File.dirname(__FILE__) + '/space_wire/'
8
-
9
- @index_path = base_dir + '/index.bin'
10
- @file_path = base_dir + '/data.bin'
11
- end
12
-
13
- it 'should read SpaceWire indexes' do
14
- last_end_position = 0
15
- index = SpaceWire::Index.new(File.read(@index_path))
16
- index.records.size.should == 100
17
- index.records.each do |record|
18
- record.end_position.should == last_end_position + 4117
19
- record.error_control.should == 0
20
- last_end_position = record.end_position
21
- end
22
-
23
- File.open(@index_path,'r') do |file|
24
- last_end_position = 0
25
- while index = file.read(9)
26
- end_char, end_position = index.unpack('cQ')
27
- end_position.should == last_end_position + 4117
28
- end_char.should == 0
29
- last_end_position = end_position
30
- end
31
- end
32
- end
33
-
34
- it 'should read packets from data file' do
35
- space_wire_data = SpaceWire::Data.new(@file_path, @index_path)
36
-
37
- packets = []
38
- space_wire_data.each_packet do |packet|
39
- packet.end_of_packet_char.should == 0.chr
40
- packet.size.should == 4117
41
- packet.header_size.should == 4
42
- packet.header.size.should == packet.header_size
43
- packets << packet
44
- end
45
- packets.size.should == 100
46
- space_wire_data.packets.should == packets
47
-
48
- 100.times { |n|
49
- space_wire_data[n].should == packets[n]
50
- }
51
- end
52
-
53
- end