class Spektrum::Log::Record
Represents a single record from the telemetry file.
Attributes
timestamp[R]
Public Class Methods
new(timestamp, raw_data)
click to toggle source
# File lib/spektrum/log/records.rb, line 9 def initialize(timestamp, raw_data) if raw_data.length != 16 raise ArgumentError, "raw_data incorrectly sized (#{raw_data.length})" end @timestamp = timestamp @raw_data = raw_data end
Public Instance Methods
raw_hex_string()
click to toggle source
Gets the 32-bit segmented hex string of the raw data for this record.
@return [String] raw hex string for the record
# File lib/spektrum/log/records.rb, line 20 def raw_hex_string @raw_hex_string ||= @raw_data.unpack('H*')[0].gsub(/(.{8})(?=.)/, '\1 \2') end
type()
click to toggle source
# File lib/spektrum/log/records.rb, line 24 def type @type ||= byte_field(0) end
valid?()
click to toggle source
Determines if this record should be considered valid. Definitions of valid will vary by the type of record.
@return [Boolean] true if the record is valid, false otherwise
# File lib/spektrum/log/records.rb, line 32 def valid? true end
Protected Instance Methods
byte_field(range)
click to toggle source
# File lib/spektrum/log/records.rb, line 38 def byte_field(range) @raw_data[range].unpack('C')[0] end
four_byte_field(range, endian = :big)
click to toggle source
# File lib/spektrum/log/records.rb, line 54 def four_byte_field(range, endian = :big) @raw_data[range].unpack(endian == :big ? 'N' : 'V')[0] end
hex_byte_field(range)
click to toggle source
# File lib/spektrum/log/records.rb, line 42 def hex_byte_field(range) @raw_data[range].unpack('H*')[0].to_i end
hex_string_field(range)
click to toggle source
# File lib/spektrum/log/records.rb, line 46 def hex_string_field(range) @raw_data[range].unpack('H*')[0] end
two_byte_field(range, endian = :big)
click to toggle source
# File lib/spektrum/log/records.rb, line 50 def two_byte_field(range, endian = :big) @raw_data[range].unpack(endian == :big ? 'n' : 'v')[0] end