Class: NMEAPlus::Message::AIS::VDM
- Inherits:
-
AISMessage
- Object
- Base
- AISMessage
- NMEAPlus::Message::AIS::VDM
- Defined in:
- lib/nmea_plus/message/ais/vdm.rb
Instance Attribute Summary collapse
-
#ais ⇒ VDMPayload::VDMMsg
readonly
factory method: find the appropriate message type class and instantiate it.
-
#full_armored_ais_payload ⇒ String
readonly
the full encoded payload as it was received – spanning multiple messages.
-
#full_dearmored_ais_payload ⇒ String
readonly
a binary string (“0010101110110”) representing the dearmored payload.
-
#last_ais_fill_bits ⇒ Integer
readonly
Get the fill bits for the last message in the sequence – the only one that matters.
Attributes inherited from AISMessage
Attributes inherited from Base
#checksum, #data_type, #fields, #interpreted_data_type, #message_number, #next_part, #original, #payload, #prefix, #total_messages
Instance Method Summary collapse
-
#_dearmor6b(c, len = 6) ⇒ String
perform the 6-bit to 8-bit conversion defined in the spec.
-
#_payload_container(message_type_id) ⇒ NMEAPlus::Message::AIS::VDMPayload::VDMMsg
Find an appropriate payload container for the payload type, based on its stated message ID.
Methods inherited from Base
#_degrees_minutes_to_decimal, #_float, #_hex_to_integer, #_highest_contiguous_index, #_integer, #_interval_hms, #_nsew_signed_float, #_string, #_utc_date_time, #_utctime_hms, #add_message_part, #all_checksums_ok?, #all_messages_received?, #calculated_checksum, #checksum_ok?, field_reader, #highest_contiguous_index
Instance Attribute Details
#ais ⇒ VDMPayload::VDMMsg (readonly)
factory method: find the appropriate message type class and instantiate it
38 39 40 41 42 43 44 |
# File 'lib/nmea_plus/message/ais/vdm.rb', line 38 def ais p = full_dearmored_ais_payload ret = _payload_container(p[0, 6].to_i(2)) ret.payload_bitstring = p ret.fill_bits = last_ais_fill_bits ret end |
#full_armored_ais_payload ⇒ String (readonly)
the full encoded payload as it was received – spanning multiple messages
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/nmea_plus/message/ais/vdm.rb', line 49 def full_armored_ais_payload # get the full message and fill bits for the last one ptr = self ret = "" loop do ret << ptr.raw_ais_payload break if ptr.next_part.nil? ptr = ptr.next_part end ret end |
#full_dearmored_ais_payload ⇒ String (readonly)
a binary string (“0010101110110”) representing the dearmored payload
64 65 66 67 68 69 70 71 |
# File 'lib/nmea_plus/message/ais/vdm.rb', line 64 def full_dearmored_ais_payload data = full_armored_ais_payload out = "" # dearmor all but the last byte, then apply the fill bits to the last byte data[0..-2].each_char { |c| out << _dearmor6b(c) } out << _dearmor6b(data[-1], 6 - last_ais_fill_bits) out end |
#last_ais_fill_bits ⇒ Integer (readonly)
Get the fill bits for the last message in the sequence – the only one that matters
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/nmea_plus/message/ais/vdm.rb', line 76 def last_ais_fill_bits ptr = self fill_bits = nil loop do fill_bits = ptr.ais_payload_fill_bits break if ptr.next_part.nil? ptr = ptr.next_part end fill_bits.to_i end |
Instance Method Details
#_dearmor6b(c, len = 6) ⇒ String
perform the 6-bit to 8-bit conversion defined in the spec
91 92 93 94 95 96 97 98 99 |
# File 'lib/nmea_plus/message/ais/vdm.rb', line 91 def _dearmor6b(c, len = 6) val = c.ord if val >= 96 ret = val - 56 else ret = val - 48 end ret.to_s(2).rjust(6, "0")[0..(len - 1)] end |
#_payload_container(message_type_id) ⇒ NMEAPlus::Message::AIS::VDMPayload::VDMMsg
Find an appropriate payload container for the payload type, based on its stated message ID
104 105 106 107 108 109 110 |
# File 'lib/nmea_plus/message/ais/vdm.rb', line 104 def _payload_container() class_identifier = "NMEAPlus::Message::AIS::VDMPayload::VDMMsg#{}" Object::const_get(class_identifier).new rescue ::NameError class_identifier = "NMEAPlus::Message::AIS::VDMPayload::VDMMsgUndefined" # generic Object::const_get(class_identifier).new end |