class Spektrum::Log::GPSRecord1
Public Class Methods
Spektrum::Log::Record::new
# File lib/spektrum/log/records.rb, line 192 def initialize(timestamp, raw_data) super timestamp, raw_data end
Public Instance Methods
Gets the altitude, in desired unit.
@param unit one of :feet, :meters to define desired unit @return [Float] altitude in the desired unit @note This conversion has been verified via Spektrum
STi
# File lib/spektrum/log/records.rb, line 201 def altitude(unit = :feet) @altitude ||= (hex_byte_field(3) * 100) + hex_byte_field(2) case unit when :feet @altitude * 0.32808399 when :meters @altitude / 10.0 else @altitude end end
Gets a composite coordinate value, containing longitude, latitude and altitude in an array.
@param unit unit for altitude, see {#altitude} for options @return [Array] 3-element array of {#longitude}, {#latitude} and {#altitude}
# File lib/spektrum/log/records.rb, line 237 def coordinate [longitude, latitude, altitude(:meters)] end
Gets the current heading, in degrees.
@return [Float] current heading @note This conversion has been verified via Spektrum
STi
# File lib/spektrum/log/records.rb, line 245 def heading @heading ||= (hex_byte_field(13) * 10) + (hex_byte_field(12) / 10.0) end
Gets the latitude. Positive values indicate North latitudes, negative values indicate South.
@return [Float] latitude in decimal-degress @note This conversion has been verified via Spektrum
STi @note XXX Negative values are currently not supported!! XXX
# File lib/spektrum/log/records.rb, line 219 def latitude @latitude ||= build_latitude end
Gets the longitude. Positive values indicate East longitudes, negative values indicate West.
@return [Float] longitude in decimal-degress @note This conversion has been verified via Spektrum
STi
# File lib/spektrum/log/records.rb, line 228 def longitude @lontitude ||= build_longitude end
# File lib/spektrum/log/records.rb, line 249 def valid? !(latitude == 0.0 && longitude == 0.0 && altitude == 0.0) end
Private Instance Methods
# File lib/spektrum/log/records.rb, line 255 def build_latitude elements = 7.downto(4).map { |i| hex_string_field(i) } convert_latlon([0, elements].flatten) end
# File lib/spektrum/log/records.rb, line 260 def build_longitude elements = 11.downto(8).map { |i| hex_string_field(i) } # 100+ longitude indicator guesses (X marks proven invalid guess): # X upper nybble of 13th byte # - 2nd bit of 14th byte hundreds = ((byte_field(15) & 0x04) == 0x04) ? 1 : 0 # +/- longitude indicator guesses (X marks proven invalid guess): # - 1st bit of 14th byte (1 - pos, 0 - neg) multiplier = ((byte_field(15) & 0x02) == 0x02) ? 1 : -1 multiplier * convert_latlon([hundreds, elements].flatten) end
# File lib/spektrum/log/records.rb, line 275 def convert_latlon(elts) raise ArgumentError unless elts.length == 5 elts[0] * 100 + elts[1].to_i + ("#{elts[2]}.#{elts[3]}#{elts[4]}".to_f / 60.0) end