Class: MAVLink::Log::File
- Inherits:
-
Object
- Object
- MAVLink::Log::File
- Defined in:
- lib/mavlink/log/file.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Class Method Summary collapse
-
.mavlink?(uri) ⇒ MAVLink::Log::File
Determines if the file at the given URI is a MAVLink telemetry log file.
Instance Method Summary collapse
-
#duration ⇒ Float
Gets the duration of the session, in seconds.
-
#ended_at ⇒ Float
Gets the ending time as a Unix Epoch time stamp in seconds.
-
#initialize(uri) ⇒ File
constructor
A new instance of File.
-
#started_at ⇒ Float
Gets the starting time as a Unix Epoch time stamp in seconds.
Constructor Details
#initialize(uri) ⇒ File
Returns a new instance of File.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mavlink/log/file.rb', line 18 def initialize(uri) @entries = [] @messages = [] open(uri, 'rb') do |file| loop do raw_time = file.read(8) break if raw_time.nil? header = Header.new(file.read(6)) raise "Unexpected magic number (#{header.magic})" unless header.magic == 0xFE payload = file.read(header.length) raw_crc = file.read(2) @entries << Entry.new(raw_time, header, payload, raw_crc) @messages << Messages::Factory.build(@entries.last) end end if @entries.empty? raise 'No entries found in file' end rescue => e unless @entries.length >= 2 # bad ending message, give the file benefit of the doubt... raise ArgumentError, "File does not appear to be an MAVLink log (#{e})" end end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
8 9 10 |
# File 'lib/mavlink/log/file.rb', line 8 def entries @entries end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
8 9 10 |
# File 'lib/mavlink/log/file.rb', line 8 def @messages end |
Class Method Details
.mavlink?(uri) ⇒ MAVLink::Log::File
Determines if the file at the given URI is a MAVLink telemetry log file.
14 15 16 |
# File 'lib/mavlink/log/file.rb', line 14 def self.mavlink?(uri) File.new(uri) rescue nil end |
Instance Method Details
#duration ⇒ Float
Gets the duration of the session, in seconds.
49 50 51 52 |
# File 'lib/mavlink/log/file.rb', line 49 def duration return 0 if @entries.empty? ended_at - started_at end |
#ended_at ⇒ Float
Gets the ending time as a Unix Epoch time stamp in seconds.
64 65 66 |
# File 'lib/mavlink/log/file.rb', line 64 def ended_at time_in_seconds(@entries.last.time) end |
#started_at ⇒ Float
Gets the starting time as a Unix Epoch time stamp in seconds.
57 58 59 |
# File 'lib/mavlink/log/file.rb', line 57 def started_at time_in_seconds(@entries.first.time) end |