spektrum-log 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/spektrum-log/flight.rb +95 -0
- data/lib/spektrum-log/headers.rb +6 -1
- data/lib/spektrum-log/records.rb +8 -0
- data/lib/spektrum-log/version.rb +1 -1
- data/spec/flight_spec.rb +14 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1290e1e85c63b06ca04ff2ddcb1e6e6bc1a078a9
|
4
|
+
data.tar.gz: d844267c31ffe4c308dfd187bb969ade4e8f0d34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a77e5bf2d17d03b7e4d16c9760a16423b7692f02d66f93c3daacee07be052350ddce87168268b6c40a8570a368673773e82e8e9a6ab37429f3b5dab12af8863d
|
7
|
+
data.tar.gz: 6e4baf468c95764744ec1847034a72831ff541d4ee5c4a1c667a6ff479c373a60effc26ae64b73a036d63aff86e6ae25fe1743a05b3868de0f10df31cb3daa3b
|
data/lib/spektrum-log/flight.rb
CHANGED
@@ -1,23 +1,39 @@
|
|
1
1
|
module Spektrum
|
2
2
|
module Log
|
3
3
|
|
4
|
+
# Represents a single recorded flight. Contains information about the model
|
5
|
+
# flown, duration of the flight, and all data records contained within.
|
4
6
|
class Flight
|
5
7
|
|
6
8
|
attr_reader :headers, :records
|
7
9
|
|
10
|
+
# Creates a new flight.
|
11
|
+
#
|
12
|
+
# @param headers [Array] array of Header objects read from the file
|
13
|
+
# @param records [Array] array of Record objects read from the file
|
8
14
|
def initialize(headers, records)
|
9
15
|
@headers = headers
|
10
16
|
@records = records
|
11
17
|
end
|
12
18
|
|
19
|
+
# Gets the duration of the flight, in seconds.
|
20
|
+
#
|
21
|
+
# @return [Fixnum] duration of the flight, in seconds
|
13
22
|
def duration
|
14
23
|
@duration ||= ((@records.empty? ? 0 : @records.last.timestamp - @records.first.timestamp) / 256)
|
15
24
|
end
|
16
25
|
|
26
|
+
# Determines if this flight has any data. Models without telemetry
|
27
|
+
# transmitted, but with logging enabled will create empty flights.
|
28
|
+
#
|
29
|
+
# @return [Boolean] true if the flight has no records, false otherwise
|
17
30
|
def empty?
|
18
31
|
@records.empty?
|
19
32
|
end
|
20
33
|
|
34
|
+
# Gets the binding type the flight was flown with.
|
35
|
+
#
|
36
|
+
# @return [String] binding type of the flight, `DSM2`, `DSMX`, etc.
|
21
37
|
def bind_type
|
22
38
|
@bind_type ||= case @headers.first.raw_data[2].unpack('C')[0]
|
23
39
|
when 0x01..0x02
|
@@ -29,14 +45,23 @@ module Spektrum
|
|
29
45
|
end
|
30
46
|
end
|
31
47
|
|
48
|
+
# Gets the name of the model for this flight.
|
49
|
+
#
|
50
|
+
# @return [String] model name
|
32
51
|
def model_name
|
33
52
|
@model_name ||= @headers.first.raw_data[8..18].unpack('Z*')[0].strip
|
34
53
|
end
|
35
54
|
|
55
|
+
# Gets the model's index from the transmitter.
|
56
|
+
#
|
57
|
+
# @return [Fixnum] model number
|
36
58
|
def model_number
|
37
59
|
@model_number ||= (@headers.first.raw_data[0].unpack('C')[0] + 1)
|
38
60
|
end
|
39
61
|
|
62
|
+
# Gets the type of model flown.
|
63
|
+
#
|
64
|
+
# @return [String] model type
|
40
65
|
def model_type
|
41
66
|
@model_type ||= case @headers.first.raw_data[1].unpack('C')[0]
|
42
67
|
when 0x00
|
@@ -48,6 +73,76 @@ module Spektrum
|
|
48
73
|
end
|
49
74
|
end
|
50
75
|
|
76
|
+
def altimeter_records?
|
77
|
+
any_records? AltimeterRecord
|
78
|
+
end
|
79
|
+
|
80
|
+
def altimeter_records
|
81
|
+
select_records AltimeterRecord
|
82
|
+
end
|
83
|
+
|
84
|
+
def basic_data_records?
|
85
|
+
any_records? BasicDataRecord
|
86
|
+
end
|
87
|
+
|
88
|
+
def basic_data_records
|
89
|
+
select_records BasicDataRecord
|
90
|
+
end
|
91
|
+
|
92
|
+
def flight_log_records?
|
93
|
+
any_records? FlightLogRecord
|
94
|
+
end
|
95
|
+
|
96
|
+
def flight_log_records
|
97
|
+
select_records FlightLogRecord
|
98
|
+
end
|
99
|
+
|
100
|
+
def g_force_records?
|
101
|
+
any_records? GForceRecord
|
102
|
+
end
|
103
|
+
|
104
|
+
def g_force_records
|
105
|
+
select_records GForceRecord
|
106
|
+
end
|
107
|
+
|
108
|
+
def gps1_records?
|
109
|
+
any_records? GPSRecord1
|
110
|
+
end
|
111
|
+
|
112
|
+
def gps1_records
|
113
|
+
select_records GPSRecord1
|
114
|
+
end
|
115
|
+
|
116
|
+
def gps2_records?
|
117
|
+
any_records? GPSRecord2
|
118
|
+
end
|
119
|
+
|
120
|
+
def gps2_records
|
121
|
+
select_records GPSRecord2
|
122
|
+
end
|
123
|
+
|
124
|
+
def speed_records?
|
125
|
+
any_records? SpeedRecord
|
126
|
+
end
|
127
|
+
|
128
|
+
def speed_records
|
129
|
+
select_records SpeedRecord
|
130
|
+
end
|
131
|
+
|
132
|
+
private
|
133
|
+
|
134
|
+
# Determines if there are any records in this flight of the given type.
|
135
|
+
#
|
136
|
+
# @param type [Class] type of record to check for
|
137
|
+
# @return []
|
138
|
+
def any_records?(type)
|
139
|
+
@records.any? { |rec| rec.is_a? type }
|
140
|
+
end
|
141
|
+
|
142
|
+
def select_records(type)
|
143
|
+
@records.select { |rec| rec.is_a? type }
|
144
|
+
end
|
145
|
+
|
51
146
|
end
|
52
147
|
|
53
148
|
end
|
data/lib/spektrum-log/headers.rb
CHANGED
@@ -1,16 +1,21 @@
|
|
1
1
|
module Spektrum
|
2
2
|
module Log
|
3
3
|
|
4
|
+
# Represents a single header from the telemetry file.
|
4
5
|
class Header
|
5
6
|
|
6
7
|
attr_reader :raw_data
|
7
8
|
|
9
|
+
# Creates a new header.
|
10
|
+
#
|
11
|
+
# @param [String] raw_data string of data from the data file for this header
|
8
12
|
def initialize raw_data
|
9
13
|
@raw_data = raw_data
|
10
14
|
end
|
11
15
|
|
12
16
|
end
|
13
17
|
|
18
|
+
# Helper class to create the correct type of header for the given data.
|
14
19
|
class Headers
|
15
20
|
|
16
21
|
def self.create raw_data
|
@@ -20,4 +25,4 @@ module Spektrum
|
|
20
25
|
end
|
21
26
|
|
22
27
|
end
|
23
|
-
end
|
28
|
+
end
|
data/lib/spektrum-log/records.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Spektrum
|
2
2
|
module Log
|
3
3
|
|
4
|
+
# Represents a single record from the telemetry file.
|
4
5
|
class Record
|
5
6
|
|
6
7
|
attr_reader :timestamp
|
@@ -93,10 +94,16 @@ module Spektrum
|
|
93
94
|
super timestamp, raw_data
|
94
95
|
end
|
95
96
|
|
97
|
+
# Gets the receiver pack voltage data.
|
98
|
+
#
|
99
|
+
# @return [Float] rx voltage data, in volts
|
96
100
|
def rx_voltage
|
97
101
|
raw_rx_voltage / 100.0
|
98
102
|
end
|
99
103
|
|
104
|
+
# Determines if there is receiver voltage data contained within.
|
105
|
+
#
|
106
|
+
# @return [Boolean] true if there is rx voltage data, false otherwise
|
100
107
|
def rx_voltage?
|
101
108
|
raw_rx_voltage != 0x7FFF
|
102
109
|
end
|
@@ -228,6 +235,7 @@ module Spektrum
|
|
228
235
|
|
229
236
|
end
|
230
237
|
|
238
|
+
|
231
239
|
class Records
|
232
240
|
|
233
241
|
@@types = {
|
data/lib/spektrum-log/version.rb
CHANGED
data/spec/flight_spec.rb
CHANGED
@@ -236,6 +236,20 @@ describe Spektrum::Log::Flight do
|
|
236
236
|
|
237
237
|
its(:model_type) { should eql('Helicopter') }
|
238
238
|
|
239
|
+
its(:altimeter_records?) { should be_false }
|
240
|
+
|
241
|
+
its(:basic_data_records?) { should be_true }
|
242
|
+
|
243
|
+
its(:flight_log_records?) { should be_true }
|
244
|
+
|
245
|
+
its(:g_force_records?) { should be_false }
|
246
|
+
|
247
|
+
its(:gps1_records?) { should be_false }
|
248
|
+
|
249
|
+
its(:gps2_records?) { should be_false }
|
250
|
+
|
251
|
+
its(:speed_records?) { should be_false }
|
252
|
+
|
239
253
|
end
|
240
254
|
|
241
255
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spektrum-log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Veys
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -111,3 +111,4 @@ test_files:
|
|
111
111
|
- spec/flight_spec.rb
|
112
112
|
- spec/reader_spec.rb
|
113
113
|
- spec/spec_helper.rb
|
114
|
+
has_rdoc:
|