Class: ADSB::Message
- Inherits:
-
Object
- Object
- ADSB::Message
- Defined in:
- lib/adsb/message.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
Instance Method Summary collapse
-
#address ⇒ Object
Get the address of the sender.
- #data ⇒ Object
- #downlink_format ⇒ Object
-
#initialize(body, created_at = Time.now) ⇒ Message
constructor
Create a new message.
-
#type ⇒ Object
Get type of message.
- #type_code ⇒ Object
Constructor Details
#initialize(body, created_at = Time.now) ⇒ Message
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
= ADSB::Message.new('8D4840D6202CC371C32CE0576098')
= ADSB::Message.new('8D4840D6202CC371C32CE0576098', Time.now)
14 15 16 17 18 19 |
# 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 |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
3 4 5 |
# File 'lib/adsb/message.rb', line 3 def created_at @created_at end |
Instance Method Details
#address ⇒ Object
Get the address of the sender.
Examples
= ADSB::Message.new('8D4840D6202CC371C32CE0576098')
address = .address
26 27 28 |
# File 'lib/adsb/message.rb', line 26 def address '%02x' % @body[8..31].to_i(2) end |
#data ⇒ Object
30 31 32 |
# File 'lib/adsb/message.rb', line 30 def data @body[32..87] end |
#downlink_format ⇒ Object
34 35 36 |
# File 'lib/adsb/message.rb', line 34 def downlink_format @body[0..4].to_i(2) end |
#type ⇒ Object
Get type of message.
Examples
= ADSB::Message.new('8D4840D6202CC371C32CE0576098')
type = .type
43 44 45 46 47 48 49 |
# 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 ⇒ Object
51 52 53 |
# File 'lib/adsb/message.rb', line 51 def type_code @body[32..36].to_i(2) end |