Class: Spektrum::Log::SpeedRecord

Inherits:
Record
  • Object
show all
Defined in:
lib/spektrum/log/records.rb

Instance Attribute Summary

Attributes inherited from Record

#timestamp

Instance Method Summary collapse

Methods inherited from Record

#raw_hex_string, #type, #valid?

Constructor Details

#initialize(timestamp, raw_data) ⇒ SpeedRecord

Returns a new instance of SpeedRecord.



327
328
329
# File 'lib/spektrum/log/records.rb', line 327

def initialize(timestamp, raw_data)
  super timestamp, raw_data
end

Instance Method Details

#speed(unit = :knots) ⇒ Float

Gets the speed, in desired unit.

Parameters:

  • unit (defaults to: :knots)

    one of :knots, :mph, :kph to define desired unit

Returns:

  • (Float)

    speed in the desired unit



335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/spektrum/log/records.rb', line 335

def speed(unit = :knots)
  @speed ||= two_byte_field(2..3)
  case unit
  when :knots
    @speed * 0.539957
  when :mph
    @speed * 0.621371
  when :kph
    @speed
  else
    @speed
  end
end