nmea 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+ begin
3
+ require File.dirname(__FILE__)+"/../lib/nmea"
4
+ rescue LoadError => e
5
+ require File.dirname(__FILE__)+"/../ext/nmea"
6
+ end
7
+ require File.dirname(__FILE__)+"/mocks"
8
+
@@ -0,0 +1,62 @@
1
+ class NMEAHandler
2
+ def initialize
3
+ @rmc = []
4
+ end
5
+ def rmc(time, latitude, longitude, speed, course, magnetic_variation)
6
+ line = "#{latitude.to_degrees rescue "nil"}, #{longitude.to_degrees rescue "nil"}, #{@rmc.empty? ? "1" : "0"}, -777.0, 39181.2648590, #{time.strftime("%d-%b-%y, %H:%M:%S")}"
7
+ #File.open("t.plt", "a+") do |f|
8
+ # @rmc << line
9
+ # f << line + "\n"
10
+ #end
11
+ puts line
12
+ end
13
+
14
+ def gsv(satellites)
15
+ puts "Satellites"
16
+ end
17
+
18
+ def gsa(mode_state, mode, satellites, pdop, hdop, vdop)
19
+ # puts "GSA: #{mode_state},#{mode},#{satellites.inspect},#{pdop},#{hdop},#{vdop}"
20
+ end
21
+
22
+ def gga(time, latitude, longitude, gps_quality, active_satellite_count, gsa_hdop, altitude, geoidal_height, dgps_data_age, dgps_station_id)
23
+ puts "GGA: #{time}, #{latitude}, #{longitude}, #{gps_quality}, #{active_satellite_count}, #{gsa_hdop}, #{altitude}, #{geoidal_height}, #{dgps_data_age}, #{dgps_station_id}"
24
+ end
25
+ end
26
+
27
+
28
+ class Float
29
+ def precision(x)
30
+ (self * 10**x).round / (10**x).to_f
31
+ end
32
+ end
33
+
34
+
35
+ module GPS
36
+ AngleValue = Struct.new :degrees, :minutes
37
+
38
+ class AngleValue
39
+ def to_s
40
+ "%d %.4f%s" % [degrees.abs, minutes, symbol]
41
+ end
42
+
43
+ def to_degrees
44
+ "%.6f" % [degrees + minutes/60]
45
+ end
46
+
47
+ def ==(value)
48
+ value.respond_to?(:degrees) && value.respond_to?(:minutes) && degrees == value.degrees && minutes.precision(4) == value.minutes.precision(4)
49
+ end
50
+ end
51
+
52
+ class Latitude < AngleValue
53
+ def symbol
54
+ degrees >= 0 ? "N" : "S"
55
+ end
56
+ end
57
+ class Longitude < AngleValue
58
+ def symbol
59
+ degrees >= 0 ? "E" : "W"
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,145 @@
1
+ require File.dirname(__FILE__)+"/helper"
2
+
3
+ class TestScanLines < Test::Unit::TestCase
4
+ def rmc(utc, latitude, longitude, speed, course, magnetic_variation)
5
+ @utc = utc
6
+ @latitude = latitude
7
+ @longitude = longitude
8
+ @speed = speed
9
+ @course = course
10
+ @magnetic_variation = magnetic_variation
11
+ @rmc_called = (@rmc_called || 0) + 1
12
+ end
13
+
14
+ def test_rmc
15
+ invalid_rmc = "$GPRMC,072458.748,V,,,,,,,080407,,*23"
16
+ NMEA.scan(invalid_rmc, self)
17
+ assert_equal 1, @rmc_called, "RMC handler should be called"
18
+ assert_equal Time.local(2007, 4, 8, 11, 24, 58, 748), @utc
19
+ assert_equal nil, @latitude
20
+ assert_equal nil, @longitude
21
+ assert_equal nil, @speed
22
+ assert_equal nil, @course
23
+ assert_equal nil, @magnetic_variation
24
+
25
+ valid_rmc = "$GPRMC,072640.711,A,5546.5537,N,03741.2054,E,0.00,,080407,,*12"
26
+ NMEA.scan(valid_rmc, self)
27
+ assert_equal 2, @rmc_called, "RMC handler should be called"
28
+ assert_equal Time.local(2007, 4, 8, 11, 26, 40, 711), @utc
29
+ assert_equal GPS::Latitude.new(55, 46.5537), @latitude
30
+ assert_equal GPS::Longitude.new(37, 41.2054), @longitude
31
+ assert_equal 0, @speed
32
+ assert_equal nil, @course
33
+ assert_equal nil, @magnetic_variation
34
+ end
35
+
36
+ def gsv(flag, satellites)
37
+ @gsv_called = (@gsv_called || 0) + 1
38
+ @flag = flag
39
+ @satellites = [] if flag == :start
40
+ @satellites ||= []
41
+ @satellites += satellites
42
+ end
43
+
44
+ def test_gsv
45
+ empty_gsv = ["$GPGSV,3,1,12,20,00,000,,10,00,000,,25,00,000,,27,00,000,*79",
46
+ "$GPGSV,3,2,12,22,00,000,,07,00,000,,21,00,000,,24,00,000,*79",
47
+ "$GPGSV,3,3,12,16,00,000,,28,00,000,,26,00,000,,29,00,000,*78"]
48
+ empty_gsv.each do |gsv|
49
+ NMEA.scan(gsv, self)
50
+ end
51
+ assert_equal 3, @gsv_called
52
+ assert_equal 12, @satellites.size
53
+ assert_equal 20, @satellites.first.number
54
+
55
+ good_gsv = ["$GPGSV,3,1,11,19,38,300,33,26,20,035,36,29,13,026,36,18,69,100,*71",
56
+ "$GPGSV,3,2,11,22,60,191,,03,59,264,31,21,38,095,,16,11,216,*7C",
57
+ "$GPGSV,3,3,11,08,05,337,,24,02,092,,14,01,167,*48"]
58
+ good_gsv.each do |gsv|
59
+ NMEA.scan(gsv, self)
60
+ end
61
+ assert_equal 6, @gsv_called
62
+ assert_equal 11, @satellites.size
63
+ assert_equal 19, @satellites.first.number
64
+ assert_equal 38, @satellites.first.elevation
65
+ assert_equal 300, @satellites.first.azimuth
66
+ assert_equal 33, @satellites.first.signal_level
67
+ end
68
+
69
+
70
+ def gsa(mode_state, mode, satellites, pdop, hdop, vdop)
71
+ @gsa_called = (@gsa_called || 0) + 1
72
+ @mode_state = mode_state
73
+ @mode = mode
74
+ @satellites = satellites
75
+ @pdop = pdop
76
+ @hdop = hdop
77
+ @vdop = vdop
78
+ end
79
+
80
+ def test_gsa
81
+ empty_gsa = "$GPGSA,A,1,,,,,,,,,,,,,,,*1E"
82
+ NMEA.scan(empty_gsa, self)
83
+ assert_equal 1, @gsa_called
84
+ assert_equal :automatic, @mode_state
85
+ assert_equal :no_fix, @mode
86
+ assert_equal [nil, nil, nil,nil,nil,nil,nil,nil,nil,nil,nil,nil], @satellites
87
+ assert_equal nil, @pdop
88
+ assert_equal nil, @hdop
89
+ assert_equal nil, @vdop
90
+
91
+ good_gsa = "$GPGSA,A,2,26,29,19,,,,,,,,,,10.6,10.6,1.0*35"
92
+ NMEA.scan(good_gsa, self)
93
+ assert_equal 2, @gsa_called
94
+ assert_equal :automatic, @mode_state
95
+ assert_equal :gps_2d, @mode
96
+ assert_equal [26, 29, 19,nil,nil,nil,nil,nil,nil,nil,nil,nil], @satellites
97
+ assert_equal 10.6, @pdop
98
+ assert_equal 10.6, @hdop
99
+ assert_equal 1.0, @vdop
100
+ end
101
+
102
+ def gga(time, latitude, longitude, gps_quality, active_satellite_count, hdop, altitude, geoidal_height, dgps_data_age, dgps_station_id)
103
+ @gga_called = (@gga_called || 0) + 1
104
+ @time = time
105
+ @latitude = latitude
106
+ @longitude = longitude
107
+ @gps_quality = gps_quality
108
+ @active_satellite_count = active_satellite_count
109
+ @hdop = hdop
110
+ @altitude = altitude
111
+ @geoidal_height = geoidal_height
112
+ @dgps_data_age = dgps_data_age
113
+ @dgps_station_id = dgps_station_id
114
+ end
115
+
116
+ def test_gga
117
+ empty_gga = "$GPGGA,072459.739,,,,,0,00,,,M,0.0,M,,0000*56"
118
+ NMEA.scan(empty_gga, self)
119
+ assert_equal 1, @gga_called
120
+ assert_equal Time.utc(1970, 1, 1, 07, 24, 59, 739), @time
121
+ assert_equal nil, @latitude
122
+ assert_equal nil, @longitude
123
+ assert_equal 0, @gps_quality
124
+ assert_equal 0, @active_satellite_count
125
+ assert_equal nil, @hdop
126
+ assert_equal nil, @altitude
127
+ assert_equal 0, @geoidal_height
128
+ assert_equal nil, @dgps_data_age
129
+ assert_equal 0, @dgps_station_id
130
+
131
+ good_gga = "$GPGGA,072642.711,5546.5395,N,03741.2180,E,1,03,10.6,174.3,M,14.4,M,,0000*68"
132
+ NMEA.scan(good_gga, self)
133
+ assert_equal 2, @gga_called
134
+ assert_equal Time.utc(1970, 1, 1, 07, 26, 42, 711), @time
135
+ assert_equal GPS::Latitude.new(55, 46.5395), @latitude
136
+ assert_equal GPS::Longitude.new(37, 41.2180), @longitude
137
+ assert_equal 1, @gps_quality
138
+ assert_equal 3, @active_satellite_count
139
+ assert_equal 10.6, @hdop
140
+ assert_equal 174.3, @altitude
141
+ assert_equal 14.4, @geoidal_height
142
+ assert_equal nil, @dgps_data_age
143
+ assert_equal 0, @dgps_station_id
144
+ end
145
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: nmea
5
+ version: !ruby/object:Gem::Version
6
+ version: "0.1"
7
+ date: 2007-04-10 00:00:00 +04:00
8
+ summary: NMEA (GPS protocol) parser
9
+ require_paths:
10
+ - lib
11
+ email: max@maxidoors.ru
12
+ homepage: http://maxidoors.ru/
13
+ rubyforge_project: nmea
14
+ description:
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Max Lapshin
31
+ files:
32
+ - README
33
+ - Rakefile
34
+ - setup.rb
35
+ - init.rb
36
+ - test/helper.rb
37
+ - test/mocks.rb
38
+ - test/test_scan.rb
39
+ - ext/nmea.h
40
+ - ext/nmea.c
41
+ - ext/ruby_nmea.c
42
+ - ext/extconf.rb
43
+ - ext/test.rb
44
+ test_files:
45
+ - test/test_scan.rb
46
+ rdoc_options:
47
+ - --main=README
48
+ - --line-numbers
49
+ - --webcvs=http://svn.maxidoors.ru/ruby-nmea/
50
+ - --charset=utf-8
51
+ - --promiscuous
52
+ extra_rdoc_files: []
53
+
54
+ executables: []
55
+
56
+ extensions:
57
+ - ext/extconf.rb
58
+ requirements: []
59
+
60
+ dependencies: []
61
+