Class: NMEAPlus::Message::AIS::VDM

Inherits:
AISMessage show all
Defined in:
lib/nmea_plus/message/ais/vdm.rb

Instance Attribute Summary collapse

Attributes inherited from AISMessage

#message_type, #talker

Attributes inherited from Base

#checksum, #data_type, #fields, #interpreted_data_type, #message_number, #next_part, #original, #payload, #prefix, #total_messages

Instance Method Summary collapse

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

#aisVDMPayload::VDMMsg (readonly)

factory method: find the appropriate message type class and instantiate it

Returns:



44
45
46
47
48
49
50
# File 'lib/nmea_plus/message/ais/vdm.rb', line 44

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_payloadString (readonly)

the full encoded payload as it was received – spanning multiple messages

Returns:

  • (String)


55
56
57
58
59
60
61
62
63
64
65
# File 'lib/nmea_plus/message/ais/vdm.rb', line 55

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_payloadString (readonly)

a binary string (“0010101110110”) representing the dearmored payload

Returns:

  • (String)


70
71
72
73
74
75
76
77
# File 'lib/nmea_plus/message/ais/vdm.rb', line 70

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_bitsInteger (readonly)

Get the fill bits for the last message in the sequence – the only one that matters

Returns:

  • (Integer)


82
83
84
85
86
87
88
89
90
91
# File 'lib/nmea_plus/message/ais/vdm.rb', line 82

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

Parameters:

  • c (String)

    a character

  • len (Integer) (defaults to: 6)

    The number of bits to consider

Returns:

  • (String)

    a binary encoded string



97
98
99
100
101
102
103
104
105
# File 'lib/nmea_plus/message/ais/vdm.rb', line 97

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

Parameters:

  • message_type_id (String)

Returns:



110
111
112
113
114
115
116
# File 'lib/nmea_plus/message/ais/vdm.rb', line 110

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