nmea_plus 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/gem/lib/nmea_plus.rb +63 -0
- data/gem/lib/nmea_plus/ais_message_factory.rb +17 -0
- data/gem/lib/nmea_plus/generated_parser/parser.rb +127 -0
- data/gem/lib/nmea_plus/generated_parser/tokenizer.rb +100 -0
- data/gem/lib/nmea_plus/message/ais/base_ais.rb +20 -0
- data/gem/lib/nmea_plus/message/ais/vdm.rb +100 -0
- data/gem/lib/nmea_plus/message/ais/vdm_payload/vdm_msg.rb +99 -0
- data/gem/lib/nmea_plus/message/ais/vdm_payload/vdm_msg1.rb +65 -0
- data/gem/lib/nmea_plus/message/ais/vdm_payload/vdm_msg5.rb +38 -0
- data/gem/lib/nmea_plus/message/ais/vdm_payload/vdm_msg8.rb +43 -0
- data/gem/lib/nmea_plus/message/base.rb +172 -0
- data/gem/lib/nmea_plus/message/nmea/aam.rb +17 -0
- data/gem/lib/nmea_plus/message/nmea/alm.rb +25 -0
- data/gem/lib/nmea_plus/message/nmea/apa.rb +20 -0
- data/gem/lib/nmea_plus/message/nmea/apb.rb +14 -0
- data/gem/lib/nmea_plus/message/nmea/base_nmea.rb +36 -0
- data/gem/lib/nmea_plus/message/nmea/bod.rb +14 -0
- data/gem/lib/nmea_plus/message/nmea/bwc.rb +12 -0
- data/gem/lib/nmea_plus/message/nmea/bwr.rb +25 -0
- data/gem/lib/nmea_plus/message/nmea/bww.rb +11 -0
- data/gem/lib/nmea_plus/message/nmea/dbk.rb +13 -0
- data/gem/lib/nmea_plus/message/nmea/dbs.rb +11 -0
- data/gem/lib/nmea_plus/message/nmea/dbt.rb +11 -0
- data/gem/lib/nmea_plus/message/nmea/dcn.rb +26 -0
- data/gem/lib/nmea_plus/message/nmea/dpt.rb +12 -0
- data/gem/lib/nmea_plus/message/nmea/dtm.rb +24 -0
- data/gem/lib/nmea_plus/message/nmea/fsi.rb +14 -0
- data/gem/lib/nmea_plus/message/nmea/gbs.rb +18 -0
- data/gem/lib/nmea_plus/message/nmea/gga.rb +32 -0
- data/gem/lib/nmea_plus/message/nmea/glc.rb +23 -0
- data/gem/lib/nmea_plus/message/nmea/gll.rb +21 -0
- data/gem/lib/nmea_plus/message/nmea/gns.rb +28 -0
- data/gem/lib/nmea_plus/message/nmea/grs.rb +24 -0
- data/gem/lib/nmea_plus/message/nmea/gsa.rb +27 -0
- data/gem/lib/nmea_plus/message/nmea/gst.rb +18 -0
- data/gem/lib/nmea_plus/message/nmea/gsv.rb +29 -0
- data/gem/lib/nmea_plus/message/nmea/gtd.rb +15 -0
- data/gem/lib/nmea_plus/message/nmea/gxa.rb +22 -0
- data/gem/lib/nmea_plus/message/nmea/hdg.rb +20 -0
- data/gem/lib/nmea_plus/message/nmea/hdm.rb +11 -0
- data/gem/lib/nmea_plus/message/nmea/hdt.rb +11 -0
- data/gem/lib/nmea_plus/message/nmea/hfb.rb +12 -0
- data/gem/lib/nmea_plus/message/nmea/hsc.rb +12 -0
- data/gem/lib/nmea_plus/message/nmea/its.rb +11 -0
- data/gem/lib/nmea_plus/message/nmea/lcd.rb +23 -0
- data/gem/lib/nmea_plus/message/nmea/msk.rb +15 -0
- data/gem/lib/nmea_plus/message/nmea/mss.rb +15 -0
- data/gem/lib/nmea_plus/message/nmea/mtw.rb +12 -0
- data/gem/lib/nmea_plus/message/nmea/mwv.rb +15 -0
- data/gem/lib/nmea_plus/message/nmea/oln.rb +22 -0
- data/gem/lib/nmea_plus/message/nmea/osd.rb +19 -0
- data/gem/lib/nmea_plus/message/nmea/pashr.rb +21 -0
- data/gem/lib/nmea_plus/message/nmea/r00.rb +11 -0
- data/gem/lib/nmea_plus/message/nmea/rma.rb +30 -0
- data/gem/lib/nmea_plus/message/nmea/rmb.rb +30 -0
- data/gem/lib/nmea_plus/message/nmea/rmc.rb +33 -0
- data/gem/lib/nmea_plus/message/nmea/rot.rb +12 -0
- data/gem/lib/nmea_plus/message/nmea/rpm.rb +15 -0
- data/gem/lib/nmea_plus/message/nmea/rsa.rb +17 -0
- data/gem/lib/nmea_plus/message/nmea/rsd.rb +14 -0
- data/gem/lib/nmea_plus/message/nmea/rte.rb +16 -0
- data/gem/lib/nmea_plus/message/nmea/sfi.rb +18 -0
- data/gem/lib/nmea_plus/message/nmea/stn.rb +11 -0
- data/gem/lib/nmea_plus/message/nmea/tds.rb +11 -0
- data/gem/lib/nmea_plus/message/nmea/tfi.rb +13 -0
- data/gem/lib/nmea_plus/message/nmea/tpc.rb +13 -0
- data/gem/lib/nmea_plus/message/nmea/tpr.rb +13 -0
- data/gem/lib/nmea_plus/message/nmea/tpt.rb +13 -0
- data/gem/lib/nmea_plus/message/nmea/trf.rb +28 -0
- data/gem/lib/nmea_plus/message/nmea/ttm.rb +22 -0
- data/gem/lib/nmea_plus/message/nmea/vbw.rb +16 -0
- data/gem/lib/nmea_plus/message/nmea/vdr.rb +13 -0
- data/gem/lib/nmea_plus/message/nmea/vhw.rb +14 -0
- data/gem/lib/nmea_plus/message/nmea/vlw.rb +12 -0
- data/gem/lib/nmea_plus/message/nmea/vpw.rb +12 -0
- data/gem/lib/nmea_plus/message/nmea/vtg.rb +41 -0
- data/gem/lib/nmea_plus/message/nmea/vwr.rb +15 -0
- data/gem/lib/nmea_plus/message/nmea/wcv.rb +12 -0
- data/gem/lib/nmea_plus/message/nmea/wnc.rb +14 -0
- data/gem/lib/nmea_plus/message/nmea/wpl.rb +19 -0
- data/gem/lib/nmea_plus/message/nmea/xdr.rb +14 -0
- data/gem/lib/nmea_plus/message/nmea/xte.rb +16 -0
- data/gem/lib/nmea_plus/message/nmea/xtr.rb +12 -0
- data/gem/lib/nmea_plus/message/nmea/zda.rb +23 -0
- data/gem/lib/nmea_plus/message/nmea/zfo.rb +13 -0
- data/gem/lib/nmea_plus/message/nmea/ztg.rb +13 -0
- data/gem/lib/nmea_plus/message_factory.rb +68 -0
- data/gem/lib/nmea_plus/nmea_message_factory.rb +110 -0
- data/gem/lib/nmea_plus/version.rb +3 -0
- metadata +285 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative "base_nmea"
|
2
|
+
|
3
|
+
module NMEAPlus
|
4
|
+
module Message
|
5
|
+
module NMEA
|
6
|
+
class TFI < NMEAPlus::Message::NMEA::NMEAMessage
|
7
|
+
field_reader :catch_sensor1, 1, :_integer
|
8
|
+
field_reader :catch_sensor2, 2, :_integer
|
9
|
+
field_reader :catch_sensor3, 3, :_integer
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative "base_nmea"
|
2
|
+
|
3
|
+
module NMEAPlus
|
4
|
+
module Message
|
5
|
+
module NMEA
|
6
|
+
class TPC < NMEAPlus::Message::NMEA::NMEAMessage
|
7
|
+
field_reader :distance_abeam_meters, 1, :_float
|
8
|
+
field_reader :distance_abaft_meters, 3, :_float
|
9
|
+
field_reader :depth_meters, 5, :_float
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative "base_nmea"
|
2
|
+
|
3
|
+
module NMEAPlus
|
4
|
+
module Message
|
5
|
+
module NMEA
|
6
|
+
class TPR < NMEAPlus::Message::NMEA::NMEAMessage
|
7
|
+
field_reader :range_meters, 1, :_float
|
8
|
+
field_reader :bearing_degrees, 3, :_float
|
9
|
+
field_reader :depth_meters, 5, :_float
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative "base_nmea"
|
2
|
+
|
3
|
+
module NMEAPlus
|
4
|
+
module Message
|
5
|
+
module NMEA
|
6
|
+
class TPT < NMEAPlus::Message::NMEA::NMEAMessage
|
7
|
+
field_reader :range_meters, 1, :_float
|
8
|
+
field_reader :bearing_true_degrees, 3, :_float
|
9
|
+
field_reader :depth_meters, 5, :_float
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative "base_nmea"
|
2
|
+
|
3
|
+
module NMEAPlus
|
4
|
+
module Message
|
5
|
+
module NMEA
|
6
|
+
class TRF < NMEAPlus::Message::NMEA::NMEAMessage
|
7
|
+
def utc_time
|
8
|
+
_utc_date_time(@fields[2], @fields[1])
|
9
|
+
end
|
10
|
+
|
11
|
+
def latitude
|
12
|
+
_degrees_minutes_to_decimal(@fields[3], @fields[4])
|
13
|
+
end
|
14
|
+
|
15
|
+
def longitude
|
16
|
+
_degrees_minutes_to_decimal(@fields[5], @fields[6])
|
17
|
+
end
|
18
|
+
|
19
|
+
field_reader :elevation_angle, 7, :_float
|
20
|
+
field_reader :iterations, 8, :_integer
|
21
|
+
field_reader :doppler_intervals, 9, :_integer
|
22
|
+
field_reader :update_distance_nautical_miles, 10, :_float
|
23
|
+
field_reader :satellite, 11, :_integer
|
24
|
+
field_reader :valid?, 12, :_av_boolean
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative "base_nmea"
|
2
|
+
|
3
|
+
module NMEAPlus
|
4
|
+
module Message
|
5
|
+
module NMEA
|
6
|
+
class TTM < NMEAPlus::Message::NMEA::NMEAMessage
|
7
|
+
field_reader :target_number, 1, :_integer
|
8
|
+
field_reader :target_distance, 2, :_float
|
9
|
+
field_reader :target_bearing_from_ownship, 3, :_float
|
10
|
+
field_reader :target_bearing_units, 4, :_string
|
11
|
+
field_reader :target_speed, 5, :_float
|
12
|
+
field_reader :target_course, 6, :_float
|
13
|
+
field_reader :target_course_units, 7, :_string
|
14
|
+
field_reader :closest_approach_point_distance, 8, :_float
|
15
|
+
field_reader :closest_approach_point_time, 9, :_float
|
16
|
+
field_reader :target_name, 11, :_string
|
17
|
+
field_reader :target_status, 12, :_string
|
18
|
+
field_reader :reference_target, 13, :_string
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative "base_nmea"
|
2
|
+
|
3
|
+
module NMEAPlus
|
4
|
+
module Message
|
5
|
+
module NMEA
|
6
|
+
class VBW < NMEAPlus::Message::NMEA::NMEAMessage
|
7
|
+
field_reader :longitudinal_water_speed, 1, :_float
|
8
|
+
field_reader :transverse_water_speed, 2, :_float
|
9
|
+
field_reader :water_speed_valid?, 3, :_av_boolean
|
10
|
+
field_reader :longitudinal_ground_speed, 4, :_float
|
11
|
+
field_reader :transverse_ground_speed, 5, :_float
|
12
|
+
field_reader :ground_speed_valid?, 6, :_av_boolean
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative "base_nmea"
|
2
|
+
|
3
|
+
module NMEAPlus
|
4
|
+
module Message
|
5
|
+
module NMEA
|
6
|
+
class VDR < NMEAPlus::Message::NMEA::NMEAMessage
|
7
|
+
field_reader :degrees_true, 1, :_float
|
8
|
+
field_reader :degrees_magnetic, 3, :_float
|
9
|
+
field_reader :water_current_speed_knots, 5, :_float
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative "base_nmea"
|
2
|
+
|
3
|
+
module NMEAPlus
|
4
|
+
module Message
|
5
|
+
module NMEA
|
6
|
+
class VHW < NMEAPlus::Message::NMEA::NMEAMessage
|
7
|
+
field_reader :degrees_true, 1, :_float
|
8
|
+
field_reader :degrees_magnetic, 3, :_float
|
9
|
+
field_reader :water_speed_knots, 5, :_float
|
10
|
+
field_reader :water_speed_kmh, 7, :_float
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require_relative "base_nmea"
|
2
|
+
|
3
|
+
module NMEAPlus
|
4
|
+
module Message
|
5
|
+
module NMEA
|
6
|
+
class VLW < NMEAPlus::Message::NMEA::NMEAMessage
|
7
|
+
field_reader :total_distance_nautical_miles, 1, :_float
|
8
|
+
field_reader :distance_since_reset_nautical_miles, 3, :_float
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require_relative "base_nmea"
|
2
|
+
|
3
|
+
module NMEAPlus
|
4
|
+
module Message
|
5
|
+
module NMEA
|
6
|
+
class VPW < NMEAPlus::Message::NMEA::NMEAMessage
|
7
|
+
field_reader :parallel_wind_speed_knots, 1, :_float
|
8
|
+
field_reader :parallel_wind_speed_ms, 3, :_float
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative "base_nmea"
|
2
|
+
|
3
|
+
module NMEAPlus
|
4
|
+
module Message
|
5
|
+
module NMEA
|
6
|
+
class VTG < NMEAPlus::Message::NMEA::NMEAMessage
|
7
|
+
# whether this is the new format. docs say check field #2 for value "2"
|
8
|
+
def new_format?
|
9
|
+
'T' == @fields[2]
|
10
|
+
end
|
11
|
+
|
12
|
+
field_reader :track_degrees_true, 1, :_float
|
13
|
+
|
14
|
+
def track_degrees_magnetic
|
15
|
+
f = new_format? ? 3 : 2
|
16
|
+
return nil if @fields[f].nil? || @fields[f].empty?
|
17
|
+
@fields[f].to_f
|
18
|
+
end
|
19
|
+
|
20
|
+
def speed_knots
|
21
|
+
f = new_format? ? 5 : 3
|
22
|
+
return nil if @fields[f].nil? || @fields[f].empty?
|
23
|
+
@fields[f].to_f
|
24
|
+
end
|
25
|
+
|
26
|
+
def speed_kmh
|
27
|
+
f = new_format? ? 7 : 4
|
28
|
+
return nil if @fields[f].nil? || @fields[f].empty?
|
29
|
+
@fields[f].to_f
|
30
|
+
end
|
31
|
+
|
32
|
+
def faa_mode
|
33
|
+
f = new_format? ? 9 : 100
|
34
|
+
return nil if @fields[f].nil? || @fields[f].empty?
|
35
|
+
@fields[f]
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative "base_nmea"
|
2
|
+
|
3
|
+
module NMEAPlus
|
4
|
+
module Message
|
5
|
+
module NMEA
|
6
|
+
class VWR < NMEAPlus::Message::NMEA::NMEAMessage
|
7
|
+
field_reader :wind_direction_degrees, 1, :_float
|
8
|
+
field_reader :wind_direction_bow, 2, :_string
|
9
|
+
field_reader :speed_knots, 3, :_float
|
10
|
+
field_reader :speed_ms, 5, :_float
|
11
|
+
field_reader :speed_kmh, 7, :_float
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative "base_nmea"
|
2
|
+
|
3
|
+
module NMEAPlus
|
4
|
+
module Message
|
5
|
+
module NMEA
|
6
|
+
class WNC < NMEAPlus::Message::NMEA::NMEAMessage
|
7
|
+
field_reader :distance_nautical_miles, 1, :_float
|
8
|
+
field_reader :distance_kilometers, 3, :_float
|
9
|
+
field_reader :waypoint_to, 5, :_string
|
10
|
+
field_reader :waypoint_from, 6, :_string
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative "base_nmea"
|
2
|
+
|
3
|
+
module NMEAPlus
|
4
|
+
module Message
|
5
|
+
module NMEA
|
6
|
+
class WPL < NMEAPlus::Message::NMEA::NMEAMessage
|
7
|
+
def latitude
|
8
|
+
_degrees_minutes_to_decimal(@fields[1], @fields[2])
|
9
|
+
end
|
10
|
+
|
11
|
+
def longitude
|
12
|
+
_degrees_minutes_to_decimal(@fields[3], @fields[4])
|
13
|
+
end
|
14
|
+
|
15
|
+
field_reader :name, 5, :_string
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative "base_nmea"
|
2
|
+
|
3
|
+
module NMEAPlus
|
4
|
+
module Message
|
5
|
+
module NMEA
|
6
|
+
class XDR < NMEAPlus::Message::NMEA::NMEAMessage
|
7
|
+
field_reader :type, 1, :_string
|
8
|
+
field_reader :measurement, 2, :_float
|
9
|
+
field_reader :measurement_unit, 3, :_string
|
10
|
+
field_reader :name, 4, :_string
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative "base_nmea"
|
2
|
+
|
3
|
+
module NMEAPlus
|
4
|
+
module Message
|
5
|
+
module NMEA
|
6
|
+
class XTE < NMEAPlus::Message::NMEA::NMEAMessage
|
7
|
+
field_reader :no_general_warning?, 1, :_av_boolean
|
8
|
+
field_reader :no_cyclelock_warning?, 2, :_av_boolean
|
9
|
+
field_reader :cross_track_error, 3, :_float
|
10
|
+
field_reader :direction_to_steer, 4, :_string
|
11
|
+
field_reader :cross_track_units, 5, :_string
|
12
|
+
field_reader :faa_mode, 6, :_string
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative "base_nmea"
|
2
|
+
|
3
|
+
module NMEAPlus
|
4
|
+
module Message
|
5
|
+
module NMEA
|
6
|
+
class ZDA < NMEAPlus::Message::NMEA::NMEAMessage
|
7
|
+
def utc_time
|
8
|
+
|
9
|
+
re_format = /(\d{2})(\d{2})(\d{2}(\.\d+)?)/
|
10
|
+
hms = re_format.match(@fields[1])
|
11
|
+
begin
|
12
|
+
tz_h = @fields[5].to_i
|
13
|
+
tz = "%s%0.02d:%0.02d" % [tz_h >= 0 ? '+' : '', tz_h, @fields[6].to_i]
|
14
|
+
Time.new(@fields[4].to_i, @fields[3].to_i, @fields[2].to_i,
|
15
|
+
hms[1].to_i, hms[2].to_i, hms[3].to_f, tz)
|
16
|
+
rescue
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative "base_nmea"
|
2
|
+
|
3
|
+
module NMEAPlus
|
4
|
+
module Message
|
5
|
+
module NMEA
|
6
|
+
class ZFO < NMEAPlus::Message::NMEA::NMEAMessage
|
7
|
+
field_reader :utc_time, 1, :_utctime_hms
|
8
|
+
# field_reader :elapsed_time, 2, :_interval_hms
|
9
|
+
field_reader :origin_waypoint_id, 3, :_string
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative "base_nmea"
|
2
|
+
|
3
|
+
module NMEAPlus
|
4
|
+
module Message
|
5
|
+
module NMEA
|
6
|
+
class ZTG < NMEAPlus::Message::NMEA::NMEAMessage
|
7
|
+
field_reader :utc_time, 1, :_utctime_hms
|
8
|
+
# field_reader :remaining_time, 2, :_interval_hms
|
9
|
+
field_reader :destination_waypoint_id, 3, :_string
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
|
2
|
+
module NMEAPlus
|
3
|
+
|
4
|
+
# meant to be extended. Creates message classes with a common prefix and variable suffix
|
5
|
+
class MessageFactory
|
6
|
+
|
7
|
+
# factory class must be extended
|
8
|
+
def self.parent_module
|
9
|
+
"FIXME_parent_module"
|
10
|
+
end
|
11
|
+
|
12
|
+
# a way to override the data_type (e.g. __AAM) with GPAAM to get a match
|
13
|
+
# whatever factory extends this class should override this method
|
14
|
+
def self.alternate_data_type(data_type)
|
15
|
+
data_type # in basic implementation, there is no alternative.
|
16
|
+
end
|
17
|
+
|
18
|
+
# check whether a given object exists. this will work for all consts but shhhhhhhhh
|
19
|
+
def self.message_class_exists?(class_identifier)
|
20
|
+
Object::const_get(class_identifier)
|
21
|
+
return true
|
22
|
+
rescue ::NameError
|
23
|
+
return false
|
24
|
+
end
|
25
|
+
|
26
|
+
# shortcut for the full name to a message class
|
27
|
+
def self.message_class_name(data_type)
|
28
|
+
"NMEAPlus::Message::#{self.parent_module}::#{data_type}"
|
29
|
+
end
|
30
|
+
|
31
|
+
# use the actual type if we have it, else try an alternate (and let it fail there)
|
32
|
+
def self.best_match_for_data_type(data_type)
|
33
|
+
return data_type if self.message_class_exists?(self.message_class_name(data_type))
|
34
|
+
self.alternate_data_type(data_type)
|
35
|
+
end
|
36
|
+
|
37
|
+
# get a message class through reflection
|
38
|
+
def self.dynamically_get_message_object(class_identifier)
|
39
|
+
Object::const_get(class_identifier).new
|
40
|
+
rescue ::NameError => e
|
41
|
+
raise ::NameError, "Couldn't instantiate a #{class_identifier} object: #{e}"
|
42
|
+
end
|
43
|
+
|
44
|
+
# Choose what class to create, and create it based on the first of the (unsplitted) fields
|
45
|
+
#
|
46
|
+
def self.create(message_prefix, fields, checksum)
|
47
|
+
# get the data type and adjust it if necessary (e.g. support for NMEA standard sentences like __AAM)
|
48
|
+
data_type = fields.split(',', 2)[0].upcase # assumed to be 'GPGGA', etc
|
49
|
+
interpreted_type = self.best_match_for_data_type(data_type)
|
50
|
+
class_name = self.message_class_name(interpreted_type)
|
51
|
+
|
52
|
+
# create message and make sure it's the right type
|
53
|
+
message = self.dynamically_get_message_object(class_name)
|
54
|
+
unless message.is_a? NMEAPlus::Message::Base
|
55
|
+
fail ArgumentError, "Undefined message type #{data_type} (classname #{class_name})"
|
56
|
+
end
|
57
|
+
|
58
|
+
# assign its data and return it
|
59
|
+
message.checksum = checksum
|
60
|
+
message.payload = fields
|
61
|
+
message.prefix = message_prefix
|
62
|
+
message.interpreted_data_type = interpreted_type
|
63
|
+
message
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|