Class: Spektrum::Log::Flight
- Inherits:
-
Object
- Object
- Spektrum::Log::Flight
- Defined in:
- lib/spektrum/log/flight.rb
Overview
Represents a single recorded flight. Contains information about the model flown, duration of the flight, and all data records contained within.
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Instance Method Summary collapse
- #altimeter_records ⇒ Object
- #altimeter_records? ⇒ Boolean
- #basic_data_records ⇒ Object
- #basic_data_records? ⇒ Boolean
-
#bind_type ⇒ String
Gets the binding type the flight was flown with.
-
#duration ⇒ Float
Gets the duration of the flight, in seconds.
-
#empty? ⇒ Boolean
Determines if this flight has any data.
- #flight_log_records ⇒ Object
- #flight_log_records? ⇒ Boolean
- #g_force_records ⇒ Object
- #g_force_records? ⇒ Boolean
- #gps1_records ⇒ Object
- #gps1_records? ⇒ Boolean
- #gps2_records ⇒ Object
- #gps2_records? ⇒ Boolean
-
#initialize(headers, records) ⇒ Flight
constructor
Creates a new flight.
-
#model_name ⇒ String
Gets the name of the model for this flight.
-
#model_number ⇒ Fixnum
Gets the model’s index from the transmitter.
-
#model_type ⇒ String
Gets the type of model flown.
- #speed_records ⇒ Object
- #speed_records? ⇒ Boolean
-
#telemetry_unit ⇒ String
Gets the type of telemetry unit that sent the data.
-
#timestamp_delta ⇒ Number
Gets the difference between the last and the first timestamps.
-
#to_kml(file_options = {}, placemark_options = {}) ⇒ String
Converts the flight into a KML document containing a placemark.
-
#to_kml? ⇒ Boolean
Determines if KML methods can be called for this flight.
-
#to_kml_file(file_options = {}, placemark_options = {}) ⇒ KMLFile
Converts the flight into a KMLFile containing a placemark.
-
#to_kml_placemark(options = {}) ⇒ KML::Placemark
Converts the flight into a KML::Placemark containing GPS coordinates.
Constructor Details
#initialize(headers, records) ⇒ Flight
Creates a new flight.
16 17 18 19 |
# File 'lib/spektrum/log/flight.rb', line 16 def initialize(headers, records) @headers = headers @records = records end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
10 11 12 |
# File 'lib/spektrum/log/flight.rb', line 10 def headers @headers end |
#records ⇒ Object (readonly)
Returns the value of attribute records.
10 11 12 |
# File 'lib/spektrum/log/flight.rb', line 10 def records @records end |
Instance Method Details
#altimeter_records ⇒ Object
97 98 99 |
# File 'lib/spektrum/log/flight.rb', line 97 def altimeter_records select_records AltimeterRecord end |
#altimeter_records? ⇒ Boolean
93 94 95 |
# File 'lib/spektrum/log/flight.rb', line 93 def altimeter_records? any_records? AltimeterRecord end |
#basic_data_records ⇒ Object
105 106 107 |
# File 'lib/spektrum/log/flight.rb', line 105 def basic_data_records select_records BasicDataRecord end |
#basic_data_records? ⇒ Boolean
101 102 103 |
# File 'lib/spektrum/log/flight.rb', line 101 def basic_data_records? any_records? BasicDataRecord end |
#bind_type ⇒ String
Gets the binding type the flight was flown with.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/spektrum/log/flight.rb', line 39 def bind_type @bind_type ||= case @headers.first.raw_data[2].unpack('C')[0] when 0x01..0x02 'DSM2' when 0x03..0x04 'DSMX' else 'Unknown' end end |
#duration ⇒ Float
Gets the duration of the flight, in seconds.
24 25 26 |
# File 'lib/spektrum/log/flight.rb', line 24 def duration @duration ||= / 256.0 end |
#empty? ⇒ Boolean
Determines if this flight has any data. Models without telemetry transmitted, but with logging enabled will create empty flights.
32 33 34 |
# File 'lib/spektrum/log/flight.rb', line 32 def empty? @records.empty? end |
#flight_log_records ⇒ Object
113 114 115 |
# File 'lib/spektrum/log/flight.rb', line 113 def flight_log_records select_records FlightLogRecord end |
#flight_log_records? ⇒ Boolean
109 110 111 |
# File 'lib/spektrum/log/flight.rb', line 109 def flight_log_records? any_records? FlightLogRecord end |
#g_force_records ⇒ Object
121 122 123 |
# File 'lib/spektrum/log/flight.rb', line 121 def g_force_records select_records GForceRecord end |
#g_force_records? ⇒ Boolean
117 118 119 |
# File 'lib/spektrum/log/flight.rb', line 117 def g_force_records? any_records? GForceRecord end |
#gps1_records ⇒ Object
129 130 131 |
# File 'lib/spektrum/log/flight.rb', line 129 def gps1_records select_records GPSRecord1 end |
#gps1_records? ⇒ Boolean
125 126 127 |
# File 'lib/spektrum/log/flight.rb', line 125 def gps1_records? any_records? GPSRecord1 end |
#gps2_records ⇒ Object
137 138 139 |
# File 'lib/spektrum/log/flight.rb', line 137 def gps2_records select_records GPSRecord2 end |
#gps2_records? ⇒ Boolean
133 134 135 |
# File 'lib/spektrum/log/flight.rb', line 133 def gps2_records? any_records? GPSRecord2 end |
#model_name ⇒ String
Gets the name of the model for this flight.
53 54 55 |
# File 'lib/spektrum/log/flight.rb', line 53 def model_name @model_name ||= @headers.first.raw_data[8..27].unpack('Z*')[0].strip end |
#model_number ⇒ Fixnum
Gets the model’s index from the transmitter.
60 61 62 |
# File 'lib/spektrum/log/flight.rb', line 60 def model_number @model_number ||= (@headers.first.raw_data[0].unpack('C')[0] + 1) end |
#model_type ⇒ String
Gets the type of model flown.
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/spektrum/log/flight.rb', line 67 def model_type @model_type ||= case @headers.first.raw_data[1].unpack('C')[0] when 0x00 'Fixed Wing' when 0x01 'Helicopter' else 'Unknown' end end |
#speed_records ⇒ Object
145 146 147 |
# File 'lib/spektrum/log/flight.rb', line 145 def speed_records select_records SpeedRecord end |
#speed_records? ⇒ Boolean
141 142 143 |
# File 'lib/spektrum/log/flight.rb', line 141 def speed_records? any_records? SpeedRecord end |
#telemetry_unit ⇒ String
Gets the type of telemetry unit that sent the data.
81 82 83 |
# File 'lib/spektrum/log/flight.rb', line 81 def telemetry_unit @telemetry_unit ||= derive_telemetry_unit end |
#timestamp_delta ⇒ Number
Gets the difference between the last and the first timestamps. May be zero if no records exist.
89 90 91 |
# File 'lib/spektrum/log/flight.rb', line 89 def @timestamp_delta ||= @records.empty? ? 0.0 : (@records.last. - @records.first.) end |
#to_kml(file_options = {}, placemark_options = {}) ⇒ String
Converts the flight into a KML document containing a placemark.
163 164 165 166 |
# File 'lib/spektrum/log/flight.rb', line 163 def to_kml( = {}, = {}) raise RuntimeError, 'No coordinates available for KML generation' unless to_kml? to_kml_file(, ).render end |
#to_kml? ⇒ Boolean
Determines if KML methods can be called for this flight.
152 153 154 |
# File 'lib/spektrum/log/flight.rb', line 152 def to_kml? gps1_records? end |
#to_kml_file(file_options = {}, placemark_options = {}) ⇒ KMLFile
Converts the flight into a KMLFile containing a placemark.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/spektrum/log/flight.rb', line 177 def to_kml_file( = {}, = {}) raise RuntimeError, 'No coordinates available for KML generation' unless to_kml? = () kml = KMLFile.new kml.objects << KML::Document.new( :name => [:name], :description => [:description], :styles => [ KML::Style.new( :id => [:style_id], :line_style => KML::LineStyle.new(:color => '7F00FFFF', :width => 4), :poly_style => KML::PolyStyle.new(:color => '7F00FF00') ) ], :features => [ to_kml_placemark() ] ) kml end |
#to_kml_placemark(options = {}) ⇒ KML::Placemark
Converts the flight into a KML::Placemark containing GPS coordinates.
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/spektrum/log/flight.rb', line 206 def to_kml_placemark( = {}) raise RuntimeError, 'No coordinates available for KML generation' unless to_kml? = () KML::Placemark.new( :name => [:name], :style_url => [:style_url], :geometry => KML::LineString.new( :altitude_mode => [:altitude_mode], :extrude => [:extrude], :tessellate => [:tessellate], :coordinates => gps1_records.map(&:coordinate).map { |c| c.join(',') }.join(' ') ) ) end |