spektrum-log 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39b8991bb1484d0c6653a5daf9b6ede696f58c57
4
- data.tar.gz: fc5d7eefabe9d0ed60ccd877965031f064d25328
3
+ metadata.gz: c6188ae32b6bdefbaa76994caba0d77b099583f6
4
+ data.tar.gz: edbeefad5b51f3859e8e5f6de2facb66d83dd8d4
5
5
  SHA512:
6
- metadata.gz: 81eb84a7a1da1ec0f88b46b56ec8a6e24e16085c8109bb93e05750803180f70e841aeba661bdfcd13c092f3d49220f0bb67855cecd9b5ff400228f2266efb202
7
- data.tar.gz: 22579de242b974afbdcfad5002628b2245e09533b4b6c5ef5a3e7c8fed69b4f52dd4c91dbad05c8a64d6615c2ad03590d9a7d1a94669a2f656e01b5fa8e7c1aa
6
+ metadata.gz: c39118bbb18b3199986e8f27bcf7a903416013009ec8eed2e56102fb25e52b9e5cf4501b40e70e6e38f52e44b3d963cea3dbf828752fabd9cb9096370f7394d0
7
+ data.tar.gz: a3974ade56438c56911bd6bc6f2e53f7c23028815f4214753bf56edc948735be5dfe565d902733f506adf95f1cc09076d207f81acfa5aeb5f9c9c512135557e2
@@ -22,7 +22,7 @@ module Spektrum
22
22
  #
23
23
  # @return [Float] duration of the flight, in seconds
24
24
  def duration
25
- @duration ||= timestamp_delta / time_divisor
25
+ @duration ||= timestamp_delta / 256.0
26
26
  end
27
27
 
28
28
  # Determines if this flight has any data. Models without telemetry
@@ -82,17 +82,6 @@ module Spektrum
82
82
  @telemetry_unit ||= derive_telemetry_unit
83
83
  end
84
84
 
85
- def time_divisor
86
- @time_divisor ||= case telemetry_unit
87
- when 'TM1000'
88
- 256.0
89
- when 'TM1100'
90
- 1024.0
91
- else
92
- 1.0
93
- end
94
- end
95
-
96
85
  # Gets the difference between the last and the first timestamps. May
97
86
  # be zero if no records exist.
98
87
  #
@@ -14,6 +14,13 @@ module Spektrum
14
14
  @raw_data = raw_data
15
15
  end
16
16
 
17
+ # Gets the 32-bit segmented hex string of the raw data for this record.
18
+ #
19
+ # @return [String] raw hex string for the record
20
+ def raw_hex_string
21
+ @raw_hex_string ||= @raw_data.unpack('H*')[0].gsub(/(.{8})(?=.)/, '\1 \2')
22
+ end
23
+
17
24
  def type
18
25
  @type ||= byte_field(0)
19
26
  end
@@ -36,6 +43,10 @@ module Spektrum
36
43
  @raw_data[range].unpack('H*')[0].to_i
37
44
  end
38
45
 
46
+ def hex_string_field range
47
+ @raw_data[range].unpack('H*')[0]
48
+ end
49
+
39
50
  def two_byte_field range, endian = :big
40
51
  @raw_data[range].unpack(endian == :big ? 'n' : 'v')[0]
41
52
  end
@@ -174,7 +185,11 @@ module Spektrum
174
185
  super timestamp, raw_data
175
186
  end
176
187
 
177
- # :feet, :meters
188
+ # Gets the altitude, in desired unit.
189
+ #
190
+ # @param unit one of :feet, :meters to define desired unit
191
+ # @return [Float] altitude in the desired unit
192
+ # @note This conversion has been verified via Spektrum STi
178
193
  def altitude unit = :feet
179
194
  @altitude ||= (hex_byte_field(3) * 100) + hex_byte_field(2)
180
195
  case unit
@@ -187,33 +202,38 @@ module Spektrum
187
202
  end
188
203
  end
189
204
 
190
- # + N, - S
205
+ # Gets the latitude. Positive values indicate North latitudes, negative
206
+ # values indicate South.
207
+ #
208
+ # @return [Float] latitude in decimal-degress
209
+ # @note This conversion has been verified via Spektrum STi
210
+ # @note XXX Negative values are currently not supported!! XXX
191
211
  def latitude
192
- elements = 7.downto(4).map { |i| hex_byte_field(i) }
193
- @latitude ||= convert_latlon([0, elements].flatten)
212
+ @latitude ||= build_latitude
194
213
  end
195
214
 
196
- # + E, - W
215
+ # Gets the longitude. Positive values indicate East longitudes, negative
216
+ # values indicate West.
217
+ #
218
+ # @return [Float] longitude in decimal-degress
219
+ # @note This conversion has been verified via Spektrum STi
197
220
  def longitude
198
- elements = 11.downto(8).map { |i| hex_byte_field(i) }
199
-
200
- # 100+ longitude indicator guesses (X marks proven invalid guess):
201
- # X upper nybble of 13th byte
202
- # - 2nd bit of 14th byte
203
- hundreds = ((byte_field(15) & 0x04) == 0x04) ? 1 : 0
204
-
205
- # +/- longitude indicator guesses (X marks proven invalid guess):
206
- # - 1st bit of 14th byte (1 - pos, 0 - neg)
207
- multiplier = ((byte_field(15) & 0x02) == 0x02) ? 1 : -1
208
-
209
- elements = [hundreds, elements].flatten
210
- @longitude ||= multiplier * convert_latlon(elements)
221
+ @lontitude ||= build_longitude
211
222
  end
212
223
 
224
+ # Gets a composite coordinate value, containing longitude, latitude and
225
+ # altitude in an array.
226
+ #
227
+ # @param unit unit for altitude, see {#altitude} for options
228
+ # @return [Array] 3-element array of {#longitude}, {#latitude} and {#altitude}
213
229
  def coordinate
214
230
  [longitude, latitude, altitude(:meters)]
215
231
  end
216
232
 
233
+ # Gets the current heading, in degrees.
234
+ #
235
+ # @return [Float] current heading
236
+ # @note This conversion has been verified via Spektrum STi
217
237
  def heading
218
238
  @heading ||= (hex_byte_field(13) * 10) + (hex_byte_field(12) / 10.0)
219
239
  end
@@ -224,9 +244,29 @@ module Spektrum
224
244
 
225
245
  private
226
246
 
247
+ def build_latitude
248
+ elements = 7.downto(4).map { |i| hex_string_field(i) }
249
+ convert_latlon([0, elements].flatten)
250
+ end
251
+
252
+ def build_longitude
253
+ elements = 11.downto(8).map { |i| hex_string_field(i) }
254
+
255
+ # 100+ longitude indicator guesses (X marks proven invalid guess):
256
+ # X upper nybble of 13th byte
257
+ # - 2nd bit of 14th byte
258
+ hundreds = ((byte_field(15) & 0x04) == 0x04) ? 1 : 0
259
+
260
+ # +/- longitude indicator guesses (X marks proven invalid guess):
261
+ # - 1st bit of 14th byte (1 - pos, 0 - neg)
262
+ multiplier = ((byte_field(15) & 0x02) == 0x02) ? 1 : -1
263
+
264
+ multiplier * convert_latlon([hundreds, elements].flatten)
265
+ end
266
+
227
267
  def convert_latlon elts
228
268
  raise ArgumentError unless elts.length == 5
229
- elts[0] * 100 + elts[1] + ("#{elts[2]}.#{elts[3]}#{elts[4]}".to_f / 60.0)
269
+ elts[0] * 100 + elts[1].to_i + ("#{elts[2]}.#{elts[3]}#{elts[4]}".to_f / 60.0)
230
270
  end
231
271
 
232
272
  end
@@ -1,5 +1,5 @@
1
1
  module Spektrum
2
2
  module Log
3
- VERSION = "0.0.16"
3
+ VERSION = "0.0.17"
4
4
  end
5
5
  end
Binary file
data/spec/file_spec.rb CHANGED
@@ -20,7 +20,7 @@ describe Spektrum::Log::File do
20
20
 
21
21
  it { should have(312).flights }
22
22
 
23
- its(:duration) { should be_within(0.1).of(1570.7) }
23
+ its(:duration) { should be_within(0.1).of(3433.1) }
24
24
 
25
25
  end
26
26
 
@@ -30,7 +30,7 @@ describe Spektrum::Log::File do
30
30
 
31
31
  it { should have(12).flights }
32
32
 
33
- its(:duration) { should be_within(0.1).of(144.8) }
33
+ its(:duration) { should be_within(0.1).of(579.5) }
34
34
 
35
35
  end
36
36
 
@@ -40,7 +40,7 @@ describe Spektrum::Log::File do
40
40
 
41
41
  it { should have(1).flights }
42
42
 
43
- its(:duration) { should be_within(0.1).of(15.9) }
43
+ its(:duration) { should be_within(0.1).of(63.8) }
44
44
 
45
45
  end
46
46
 
@@ -64,6 +64,16 @@ describe Spektrum::Log::File do
64
64
 
65
65
  end
66
66
 
67
+ context 'with data file X5-G700.TLM' do
68
+
69
+ subject { Spektrum::Log::File.new(data_file('X5-G700.TLM')) }
70
+
71
+ it { should have(3).flights }
72
+
73
+ its(:duration) { should be_within(0.1).of(972.9) }
74
+
75
+ end
76
+
67
77
  context 'with data file X5-GPS1.TLM' do
68
78
 
69
79
  subject { Spektrum::Log::File.new(data_file('X5-GPS1.TLM')) }
@@ -108,7 +118,7 @@ describe Spektrum::Log::File do
108
118
 
109
119
  it 'should be true for valid files' do
110
120
  files = data_files
111
- files.should have(9).files
121
+ files.should have(10).files
112
122
 
113
123
  files.each do |f|
114
124
  Spektrum::Log::File.spektrum?(f).should be_true
data/spec/flight_spec.rb CHANGED
@@ -84,7 +84,7 @@ describe Spektrum::Log::Flight do
84
84
 
85
85
  it { should_not be_empty }
86
86
 
87
- its(:duration) { should be_within(0.1).of(0.6) }
87
+ its(:duration) { should be_within(0.1).of(2.2) }
88
88
 
89
89
  its(:bind_type) { should eql('DSMX') }
90
90
 
@@ -284,7 +284,7 @@ describe Spektrum::Log::Flight do
284
284
 
285
285
  it { should have(23155).records }
286
286
 
287
- its(:duration) { should be_within(0.1).of(144.8) }
287
+ its(:duration) { should be_within(0.1).of(579.5) }
288
288
 
289
289
  its(:telemetry_unit) { should == 'TM1100' }
290
290
 
@@ -308,7 +308,7 @@ describe Spektrum::Log::Flight do
308
308
 
309
309
  it { should_not be_empty }
310
310
 
311
- its(:duration) { should be_within(0.1).of(15.9) }
311
+ its(:duration) { should be_within(0.1).of(63.8) }
312
312
 
313
313
  its(:bind_type) { should eql('DSMX') }
314
314
 
@@ -428,6 +428,42 @@ describe Spektrum::Log::Flight do
428
428
 
429
429
  end
430
430
 
431
+ context 'with data file X5-G700.TLM' do
432
+
433
+ let(:reader) { Spektrum::Log::File.new(data_file('X5-G700.TLM')) }
434
+
435
+ context 'flight 1' do
436
+
437
+ subject { reader.flights[0] }
438
+
439
+ its(:duration) { should be_within(0.1).of(323.6) }
440
+
441
+ its(:telemetry_unit) { should == 'TM1000' }
442
+
443
+ end
444
+
445
+ context 'flight 2' do
446
+
447
+ subject { reader.flights[1] }
448
+
449
+ its(:duration) { should be_within(0.1).of(323.8) }
450
+
451
+ its(:telemetry_unit) { should == 'TM1100' }
452
+
453
+ end
454
+
455
+ context 'flight 3' do
456
+
457
+ subject { reader.flights[2] }
458
+
459
+ its(:duration) { should be_within(0.1).of(325.5) }
460
+
461
+ its(:telemetry_unit) { should == 'TM1000' }
462
+
463
+ end
464
+
465
+ end
466
+
431
467
  context 'with data file X5-GPS1.TLM' do
432
468
 
433
469
  let(:reader) { Spektrum::Log::File.new(data_file('X5-GPS1.TLM')) }
@@ -54,7 +54,7 @@ describe Spektrum::Log::GPSRecord1 do
54
54
 
55
55
  its(:latitude) { should be_within(0.000001).of(1.354086) }
56
56
 
57
- its(:longitude) { should be_within(0.000001).of(103.861399) }
57
+ its(:longitude) { should be_within(0.000001).of(103.861340) }
58
58
 
59
59
  end
60
60
 
@@ -130,4 +130,18 @@ describe Spektrum::Log::GPSRecord1 do
130
130
 
131
131
  end
132
132
 
133
+ context 'data set 8' do
134
+
135
+ let(:raw_data) { ["16004231071411418561009661130839"].pack('H*') }
136
+
137
+ its(:altitude) { should be_within(0.1).of(1030.8) }
138
+
139
+ its(:heading) { should be_within(0.1).of(136.1)}
140
+
141
+ its(:latitude) { should be_within(0.000001).of(41.185678) }
142
+
143
+ its(:longitude) { should be_within(0.000001).of(-96.010308) }
144
+
145
+ end
146
+
133
147
  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.16
4
+ version: 0.0.17
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-07-06 00:00:00.000000000 Z
11
+ date: 2013-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -163,6 +163,7 @@ files:
163
163
  - spec/data/4.TLM
164
164
  - spec/data/GPS.TLM
165
165
  - spec/data/GPS2.TLM
166
+ - spec/data/X5-G700.TLM
166
167
  - spec/data/X5-GPS1.TLM
167
168
  - spec/data/X5-GPS2.TLM
168
169
  - spec/data/X5-GPS3.TLM
@@ -220,6 +221,7 @@ test_files:
220
221
  - spec/data/4.TLM
221
222
  - spec/data/GPS.TLM
222
223
  - spec/data/GPS2.TLM
224
+ - spec/data/X5-G700.TLM
223
225
  - spec/data/X5-GPS1.TLM
224
226
  - spec/data/X5-GPS2.TLM
225
227
  - spec/data/X5-GPS3.TLM