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:



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

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

Returns:

  • (String)


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

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

Returns:

  • (String)


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

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

Returns:

  • (Integer)


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

Parameters:

  • c (String)

    a character

  • len (Integer) (defaults to: 6)

    The number of bits to consider

Returns:

  • (String)

    a binary encoded string



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

Parameters:

  • message_type_id (String)

Returns:



104
105
106
107
108
109
110
# File 'lib/nmea_plus/message/ais/vdm.rb', line 104

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