spektrum-log 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -154,37 +154,40 @@ module Spektrum
154
154
  super timestamp, raw_data
155
155
  end
156
156
 
157
- def altitude
158
- @altitude ||= two_byte_field(1..2, :little)
159
- end
160
-
161
- def latitude_elements
162
- 6.downto(3).map { |i| hex_byte_field(i) }
157
+ # :feet, :meters
158
+ def altitude unit = :feet
159
+ @altitude ||= (hex_byte_field(2) * 100) + hex_byte_field(1)
160
+ case unit
161
+ when :feet
162
+ @altitude * 0.32808399
163
+ when :meters
164
+ @altitude / 10.0
165
+ else
166
+ @altitude
167
+ end
163
168
  end
164
169
 
165
170
  def latitude
166
- @latitude ||= mindec_to_degdec latitude_elements
167
- end
168
-
169
- def longitude_elements
170
- 10.downto(7).map { |i| hex_byte_field(i) }
171
+ elements = 6.downto(3).map { |i| hex_byte_field(i) }
172
+ @latitude ||= convert_latlon(elements)
171
173
  end
172
174
 
173
175
  def longitude
174
- @longitude ||= mindec_to_degdec longitude_elements
176
+ elements = 10.downto(7).map { |i| hex_byte_field(i) }
177
+ @longitude ||= convert_latlon(elements)
175
178
  end
176
179
 
177
180
  def coordinate
178
- [longitude, latitude, altitude]
181
+ [longitude, latitude, altitude(:meters)]
179
182
  end
180
183
 
181
184
  def heading
182
- @heading ||= (two_byte_field(11..12, :little) / 10.0)
185
+ @heading ||= (hex_byte_field(12) * 10) + (hex_byte_field(11) / 10.0)
183
186
  end
184
187
 
185
188
  private
186
189
 
187
- def mindec_to_degdec elts
190
+ def convert_latlon elts
188
191
  raise ArgumentError unless elts.length == 4
189
192
  elts[0] + ("#{elts[1]}.#{elts[2]}#{elts[3]}".to_f / 60.0)
190
193
  end
@@ -199,21 +202,22 @@ module Spektrum
199
202
 
200
203
  # :knots, :mph, :kph
201
204
  def speed unit = :knots
202
- speed = two_byte_field(1..2, :little)
203
- speed = case unit
205
+ @speed ||= (hex_byte_field(2) * 100) + hex_byte_field(1)
206
+ case unit
204
207
  when :knots
205
- speed / 10.0
208
+ @speed / 10.0
206
209
  when :mph
207
- speed * 0.115
210
+ @speed * 0.115078
208
211
  when :kph
209
- speed * 0.185
212
+ @speed * 0.1852
213
+ else
214
+ @speed
210
215
  end
211
- speed.round(2)
212
216
  end
213
217
 
214
218
  def time
215
- t = 3.upto(6).map { |i| hex_byte_field(i).to_s.rjust(2, '0') }
216
- @time ||= "#{t[3]}:#{t[2]}:#{t[1]}.#{t[0]}"
219
+ elements = 6.downto(3).map { |i| hex_byte_field(i) }
220
+ @time ||= "%.2i:%.2i:%.2i.%.2i" % elements
217
221
  end
218
222
 
219
223
  def satellites
@@ -1,5 +1,5 @@
1
1
  module Spektrum
2
2
  module Log
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
@@ -4,14 +4,40 @@ describe Spektrum::Log::GPSRecord1 do
4
4
 
5
5
  let(:timestamp) { 0x00010E8D }
6
6
 
7
- let(:raw_data) { ["00870084214054886918094633093B"].pack('H*') }
8
-
9
7
  subject { Spektrum::Log::GPSRecord1.new(timestamp, raw_data) }
10
8
 
11
- its(:timestamp) { should eql(0x00010E8D) }
9
+ context 'data set 1' do
10
+
11
+ let(:raw_data) { ["00870084214054886918094633093B"].pack('H*') }
12
+
13
+ its(:timestamp) { should eql(0x00010E8D) }
14
+
15
+ its(:altitude) { should be_within(0.1).of(28.5) }
16
+
17
+ it 'should allow altitude in meters' do
18
+ subject.altitude(:meters).should be_within(0.1).of(8.7)
19
+ end
20
+
21
+ its(:heading) { should be_within(0.01).of(334.6)}
22
+
23
+ its(:latitude) { should be_within(0.000001).of(54.670307) }
24
+
25
+ its(:longitude) { should be_within(0.000001).of(9.311646) }
26
+
27
+ end
28
+
29
+ context 'data set 2' do
30
+
31
+ let(:raw_data) { ["00660221234054966218093030103B"].pack('H*') }
32
+
33
+ its(:altitude) { should be_within(0.1).of(87.3) }
34
+
35
+ it 'should allow altitude in meters' do
36
+ subject.altitude(:meters).should be_within(0.1).of(26.6)
37
+ end
12
38
 
13
- its(:latitude) { should be_within(0.000001).of(54.670307) }
39
+ its(:heading) { should be_within(0.01).of(303.0)}
14
40
 
15
- its(:longitude) { should be_within(0.000001).of(9.311646) }
41
+ end
16
42
 
17
43
  end
@@ -4,14 +4,48 @@ describe Spektrum::Log::GPSRecord2 do
4
4
 
5
5
  let(:timestamp) { 0x0002C8D5 }
6
6
 
7
- let(:raw_data) { ["00500000184412110018099909073B"].pack('H*') }
8
-
9
7
  subject { Spektrum::Log::GPSRecord2.new(timestamp, raw_data) }
10
8
 
11
- its(:timestamp) { should eql(0x0002C8D5) }
9
+ context 'data set 1' do
10
+
11
+ let(:raw_data) { ["00500000184412110018099909073B"].pack('H*') }
12
+
13
+ its(:timestamp) { should eql(0x0002C8D5) }
14
+
15
+ its(:satellites) { should eql(11) }
16
+
17
+ its(:speed) { should be_within(0.1).of(5.0) }
18
+
19
+ it 'should allow speed in mph' do
20
+ subject.speed(:mph).should be_within(0.1).of(5.8)
21
+ end
22
+
23
+ it 'should allow speed in kph' do
24
+ subject.speed(:kph).should be_within(0.1).of(9.3)
25
+ end
26
+
27
+ its(:time) { should eq('12:44:18.00') }
28
+
29
+ end
30
+
31
+ context 'data set 2' do
32
+
33
+ let(:raw_data) { ["00270300011013080018093030103B"].pack('H*') }
34
+
35
+ its(:satellites) { should eql(8) }
36
+
37
+ its(:speed) { should be_within(0.1).of(32.7) }
38
+
39
+ it 'should allow speed in mph' do
40
+ subject.speed(:mph).should be_within(0.1).of(37.6)
41
+ end
42
+
43
+ it 'should allow speed in kph' do
44
+ subject.speed(:kph).should be_within(0.1).of(60.6)
45
+ end
12
46
 
13
- its(:satellites) { should eql(11) }
47
+ its(:time) { should eq('13:10:01.00') }
14
48
 
15
- its(:time) { should eq('12:44:18.00') }
49
+ end
16
50
 
17
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spektrum-log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: