Class: SDN::Message::MoveTo

Inherits:
SDN::Message show all
Defined in:
lib/sdn/messages/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, #reserved, #src

Instance Method Summary collapse

Methods inherited from SDN::Message

#class_inspect, #inspect, parse, readpartial, #serialize

Methods included from Helpers

#checksum, #from_number, #from_string, #is_group_address?, #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.



75
76
77
78
79
80
81
# File 'lib/sdn/messages/control.rb', line 75

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.



73
74
75
# File 'lib/sdn/messages/control.rb', line 73

def speed
  @speed
end

#targetObject

Returns the value of attribute target.



73
74
75
# File 'lib/sdn/messages/control.rb', line 73

def target
  @target
end

#target_typeObject

Returns the value of attribute target_type.



73
74
75
# File 'lib/sdn/messages/control.rb', line 73

def target_type
  @target_type
end

Instance Method Details

#paramsObject



105
106
107
# File 'lib/sdn/messages/control.rb', line 105

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

#parse(params) ⇒ Object



83
84
85
86
87
88
# File 'lib/sdn/messages/control.rb', line 83

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