Class: SDN::Message::MoveTo

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

Overview

Move to absolute position

Constant Summary collapse

MSG =
0x03
PARAMS_LENGTH =
4
TARGET_TYPE =
{ down_limit: 0x00, up_limit: 0x01, ip: 0x02, position_pulses: 0x03, position_percent: 0x04 }.freeze
SPEED =
{ up: 0x00, down: 0x01, slow: 0x02 }.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, target_type = :down_limit, target = nil, speed = :up, **kwargs) ⇒ MoveTo

Returns a new instance of MoveTo.



166
167
168
169
170
171
172
# File 'lib/sdn/message/control.rb', line 166

def initialize(dest = nil, target_type = :down_limit, target = nil, speed = :up, **kwargs)
  kwargs[:dest] ||= dest
  super(**kwargs)
  self.target_type = target_type
  self.target = target
  self.speed = speed
end

Instance Attribute Details

#speedObject

Returns the value of attribute speed.



164
165
166
# File 'lib/sdn/message/control.rb', line 164

def speed
  @speed
end

#targetObject

Returns the value of attribute target.



164
165
166
# File 'lib/sdn/message/control.rb', line 164

def target
  @target
end

#target_typeObject

Returns the value of attribute target_type.



164
165
166
# File 'lib/sdn/message/control.rb', line 164

def target_type
  @target_type
end

Instance Method Details

#paramsObject



201
202
203
# File 'lib/sdn/message/control.rb', line 201

def params
  transform_param(TARGET_TYPE[target_type]) + from_number(target || 0xffff, 2) + transform_param(SPEED[speed])
end

#parse(params) ⇒ Object



174
175
176
177
178
179
# File 'lib/sdn/message/control.rb', line 174

def parse(params)
  super
  self.target_type = TARGET_TYPE.invert[to_number(params[0])]
  self.target = to_number(params[1..2], nillable: true)
  self.speed = SPEED.invert[to_number(params[3])]
end