Class: SDN::Message::SetMotorIP

Inherits:
SDN::Message show all
Defined in:
lib/sdn/message/set.rb

Constant Summary collapse

MSG =
0x15
PARAMS_LENGTH =
4
TYPE =

for distribute, value is how many IPs to distribute over

{ delete: 0x00,
current_position: 0x01,
position_pulses: 0x02,
position_percent: 0x03,
distribute: 0x04 }.freeze

Instance Attribute Summary collapse

Attributes inherited from SDN::Message

#ack_requested, #dest, #node_type, #src

Instance Method Summary collapse

Methods inherited from SDN::Message

#==, #class_inspect, expected_response?, inherited, #inspect, parse, #serialize

Methods included from Helpers

#checksum, #from_number, #from_string, #group_address?, #node_type_from_number, #node_type_to_number, #node_type_to_string, #parse_address, #print_address, #to_number, #to_string, #transform_param

Constructor Details

#initialize(dest = nil, type = :delete, ip = nil, value = nil, **kwargs) ⇒ SetMotorIP

Returns a new instance of SetMotorIP.



119
120
121
122
123
124
125
# File 'lib/sdn/message/set.rb', line 119

def initialize(dest = nil, type = :delete, ip = nil, value = nil, **kwargs)
  kwargs[:dest] ||= dest
  super(**kwargs)
  self.type = type
  self.ip = ip
  self.value = value
end

Instance Attribute Details

#ipObject

Returns the value of attribute ip.



117
118
119
# File 'lib/sdn/message/set.rb', line 117

def ip
  @ip
end

#typeObject

Returns the value of attribute type.



117
118
119
# File 'lib/sdn/message/set.rb', line 117

def type
  @type
end

#valueObject

Returns the value of attribute value.



117
118
119
# File 'lib/sdn/message/set.rb', line 117

def value
  @value
end

Instance Method Details

#paramsObject



155
156
157
# File 'lib/sdn/message/set.rb', line 155

def params
  transform_param(TYPE[type]) + transform_param(ip || 0) + from_number(value || 0, 2)
end

#parse(params) ⇒ Object



127
128
129
130
131
132
133
134
# File 'lib/sdn/message/set.rb', line 127

def parse(params)
  super
  self.type = TYPE.invert[to_number(params[0])]
  ip = to_number(params[1])
  ip = nil if ip.zero?
  self.ip = ip
  self.value = to_number(params[2..3])
end