class NMEAPlus::Message::AIS::VDM
VDM
- Vessel Data Message
This message type thinly wraps AIS
payloads. @see NMEAPlus::Message::AIS::VDMPayload::VDMMsg
Public Instance Methods
Source
# File lib/nmea_plus/message/ais/vdm.rb, line 119 def _dearmor6b(char, len = 6) val = char.ord ret = val - (val >= 96 ? 56 : 48) # Mapped to 2 separate contiguous blocks of ascii, so choose which ret.to_s(2).rjust(6, "0")[0..(len - 1)] end
perform the 6-bit to 8-bit conversion defined in the spec @param char [String] a character @param len [Integer] The number of bits to consider @return [String] a binary encoded string
Source
# File lib/nmea_plus/message/ais/vdm.rb, line 128 def _payload_container(message_type_id) class_identifier = "NMEAPlus::Message::AIS::VDMPayload::VDMMsg#{message_type_id}" Object::const_get(class_identifier).new rescue ::NameError class_identifier = "NMEAPlus::Message::AIS::VDMPayload::VDMMsgUndefined" # generic Object::const_get(class_identifier).new end
Find an appropriate payload container for the payload type, based on its stated message ID @param message_type_id [String] @return [NMEAPlus::Message::AIS::VDMPayload::VDMMsg] The parsed payload
Source
# File lib/nmea_plus/message/ais/vdm.rb, line 62 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
factory method: find the appropriate class for this AIS
message type and instantiate it @!parse attr_reader :ais @return [VDMPayload::VDMMsg]
Source
# File lib/nmea_plus/message/ais/vdm.rb, line 73 def full_armored_ais_payload # get the full message and fill bits for the last one ptr = self ret = "" loop do break if ptr.raw_ais_payload.nil? # guard against rare instances of message corruption ret << ptr.raw_ais_payload break if ptr.next_part.nil? # stop when we run out of messages in the chain ptr = ptr.next_part end ret end
the full encoded payload as it was received – spanning multiple messages @!parse attr_reader :full_armored_ais_payload @return [String]
Source
# File lib/nmea_plus/message/ais/vdm.rb, line 91 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
a binary string (“0010101110110”) representing the dearmored payload @!parse attr_reader :full_dearmored_ais_payload @return [String]
Source
# File lib/nmea_plus/message/ais/vdm.rb, line 103 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
Get the fill bits for the last message in the sequence – the only one that matters @!parse attr_reader :last_ais_fill_bits @return [Integer]