Class: GPSTool::Devices::RBT2300::DataBuckets

Inherits:
Object
  • Object
show all
Defined in:
lib/gpstool/devices/rbt-2300/data-buckets.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(expected_frames, frame_size) ⇒ DataBuckets

Returns a new instance of DataBuckets.


10
11
12
13
14
15
16
17
18
# File 'lib/gpstool/devices/rbt-2300/data-buckets.rb', line 10

def initialize(expected_frames, frame_size)
	@expected_frames = expected_frames
	@frame_size = frame_size

	@data = "\0" * (@expected_frames * @frame_size)
	@buckets = [nil] * @expected_frames

	@progress = 0
end

Instance Attribute Details

#bucketsObject (readonly)

Returns the value of attribute buckets


21
22
23
# File 'lib/gpstool/devices/rbt-2300/data-buckets.rb', line 21

def buckets
  @buckets
end

#dataObject (readonly)

Returns the value of attribute data


20
21
22
# File 'lib/gpstool/devices/rbt-2300/data-buckets.rb', line 20

def data
  @data
end

#progressObject (readonly)

Returns the value of attribute progress


22
23
24
# File 'lib/gpstool/devices/rbt-2300/data-buckets.rb', line 22

def progress
  @progress
end

Instance Method Details

#append_data(frame_offset, data) ⇒ Object


24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gpstool/devices/rbt-2300/data-buckets.rb', line 24

def append_data(frame_offset, data)
	frames_read = data.size / @frame_size
	@progress += frames_read

	@buckets[frame_offset] = frames_read

	mem_offset = frame_offset * @frame_size
	@data[mem_offset,data.size] = data

	return frames_read
end

#first_missing_bucketObject


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/gpstool/devices/rbt-2300/data-buckets.rb', line 36

def first_missing_bucket
	k = 0

	while k < @buckets.size
		c = @buckets[k]

		if c == nil
			return k
		elsif c > 0
			k += c
		else
			# $stderr.puts "Error finding missing bucket: #{@buckets.inspect}, #{k}, #{c}"
			k += 1
		end
	end

	if k == @buckets.size
		return nil
	else
		return k
	end
end

#missing_buckets(start) ⇒ Object


59
60
61
62
63
64
65
66
67
68
69
# File 'lib/gpstool/devices/rbt-2300/data-buckets.rb', line 59

def missing_buckets(start)
	return nil if start == nil

	k = start

	while k < @buckets.size and @buckets[k] == nil
		k += 1
	end

	return k - start
end