class ADSB::Message

Attributes

created_at[R]

Public Class Methods

new(body, created_at = Time.now) click to toggle source

Create a new message.

Attributes

  • body - The body of the message as a hexadecimal string

  • created_at - The time at which the message was created

Examples

message = ADSB::Message.new('8D4840D6202CC371C32CE0576098')
message = ADSB::Message.new('8D4840D6202CC371C32CE0576098', Time.now)
# File lib/adsb/message.rb, line 14
def initialize body, created_at = Time.now
  @body = body.hex.to_s(2)
  @created_at = created_at
  decoder = Kernel.const_get("ADSB::Messages::#{type.to_s.capitalize}")
  extend(decoder)
end

Public Instance Methods

address() click to toggle source

Get the address of the sender.

Examples

message = ADSB::Message.new('8D4840D6202CC371C32CE0576098')
address = message.address
# File lib/adsb/message.rb, line 26
def address
   '%02x' % @body[8..31].to_i(2)
end
data() click to toggle source
# File lib/adsb/message.rb, line 30
def data
  @body[32..87]
end
type() click to toggle source

Get type of message.

Examples

message = ADSB::Message.new('8D4840D6202CC371C32CE0576098')
type = message.type
# File lib/adsb/message.rb, line 43
def type
  case type_code
    when 1, 2, 3, 4 then :identification
    when 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 then :position
    when 19 then :velocity
  end
end
type_code() click to toggle source
# File lib/adsb/message.rb, line 51
def type_code
  @body[32..36].to_i(2)
end