Class: Player::Header

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/ruby-player/header.rb

Overview

Header of message

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(param = {}) ⇒ Header

Returns a new instance of Header.



22
23
24
25
26
27
28
29
30
# File 'lib/ruby-player/header.rb', line 22

def initialize(param = {})
  @dev_addr = param[:dev_addr] || DevAddr.new
  @type = param[:type].to_i
  @subtype = param[:subtype].to_i
  @time = param[:time] || Time.now.to_f / 1000
  @seq = param[:seq].to_i
  @size = param[:size].to_i

end

Instance Attribute Details

#dev_addrObject (readonly)

Returns the value of attribute dev_addr.



20
21
22
# File 'lib/ruby-player/header.rb', line 20

def dev_addr
  @dev_addr
end

#seqObject (readonly)

Returns the value of attribute seq.



20
21
22
# File 'lib/ruby-player/header.rb', line 20

def seq
  @seq
end

#sizeObject (readonly)

Returns the value of attribute size.



20
21
22
# File 'lib/ruby-player/header.rb', line 20

def size
  @size
end

#subtypeObject (readonly)

Returns the value of attribute subtype.



20
21
22
# File 'lib/ruby-player/header.rb', line 20

def subtype
  @subtype
end

#timeObject (readonly)

Returns the value of attribute time.



20
21
22
# File 'lib/ruby-player/header.rb', line 20

def time
  @time
end

#typeObject (readonly)

Returns the value of attribute type.



20
21
22
# File 'lib/ruby-player/header.rb', line 20

def type
  @type
end

Class Method Details

.decode(str) ⇒ Object



32
33
34
35
36
# File 'lib/ruby-player/header.rb', line 32

def Header.decode(str)
  dev_addr = DevAddr.decode(str[0,16])
  type, subtype, time, seq, size = str[16,24].unpack("NNGNN")
  Header.new(dev_addr: dev_addr, type: type, subtype: subtype, time: time, seq: seq, size: size)
end

.from_a(ary) ⇒ Object



38
39
40
# File 'lib/ruby-player/header.rb', line 38

def Header.from_a(ary)
  Header.decode ary.pack("NNNNNNGNN")
end

Instance Method Details

#==(other) ⇒ Object



46
47
48
# File 'lib/ruby-player/header.rb', line 46

def ==(other)
  @dev_addr == other.dev_addr and @type == other.type and @subtype == other.subtype and @time == other.time and @seq == other.seq and @size == other.size
end

#encodeObject



42
43
44
# File 'lib/ruby-player/header.rb', line 42

def encode
  @dev_addr.encode + [@type, @subtype, @time, @seq, @size].pack("NNGNN")
end

#subtype_nameObject



58
59
60
# File 'lib/ruby-player/header.rb', line 58

def subtype_name
  @subtype_name ||= search_msg_subtype_name(dev_addr.interface_name, type_name, @subtype)
end

#to_sObject



50
51
52
# File 'lib/ruby-player/header.rb', line 50

def to_s
  "header to #@dev_addr of message [type=#{type_name}, subtype=#{subtype_name}, size=#@size]"
end

#type_nameObject



54
55
56
# File 'lib/ruby-player/header.rb', line 54

def type_name
  @type_name ||= search_msg_type_name(@type)
end