Class: GPSTool::Devices::RBT2300::DataParser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format = 0) ⇒ DataParser

Returns a new instance of DataParser.


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

def initialize(format = 0)
	@frames = []
	@floats = RBT2300::floats_for_format(format)
end

Instance Attribute Details

#framesObject (readonly)

Returns the value of attribute frames


27
28
29
# File 'lib/gpstool/devices/rbt-2300/data-parser.rb', line 27

def frames
  @frames
end

Instance Method Details

#append_data(datas) ⇒ Object


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gpstool/devices/rbt-2300/data-parser.rb', line 29

def append_data(datas)
	sz = 4 + (@floats * 4)

	while datas.size >= sz
		# Pop buf off the front
		buf = datas[0...sz]
		datas = datas[sz..-1]

		#puts "Inspecting data: #{buf.inspect}"

		# Extract Date
		date = buf.unpack("CCCC")
		#puts "Extracted date: #{date.inspect}"
		bufo = buf[4..-1]

		# We need to extract IEEE floats
		buf = bufo.unpack("C*").reverse.pack("C*")
		numbers = buf.unpack("g" * @floats).reverse

		@frames << [date, numbers]
	end
end