Class: SDN::Message::MoveOf

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

Overview

Move relative to current position

Constant Summary collapse

MSG =
0x04
PARAMS_LENGTH =
4
TARGET_TYPE =
{ next_ip: 0x00, previous_ip: 0x01, jog_down_pulses: 0x02, jog_up_pulses: 0x03, jog_down_ms: 0x04, jog_up_ms: 0x05 }

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 = nil, target = nil, **kwargs) ⇒ MoveOf

Returns a new instance of MoveOf.



118
119
120
121
122
123
# File 'lib/sdn/messages/control.rb', line 118

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

Instance Attribute Details

#targetObject

Returns the value of attribute target.



116
117
118
# File 'lib/sdn/messages/control.rb', line 116

def target
  @target
end

#target_typeObject

Returns the value of attribute target_type.



116
117
118
# File 'lib/sdn/messages/control.rb', line 116

def target_type
  @target_type
end

Instance Method Details

#paramsObject



143
144
145
146
147
# File 'lib/sdn/messages/control.rb', line 143

def params
  param = target || 0xffff
  param /= 10 if %I{jog_down_ms jog_up_ms}.include?(target_type)
  transform_param(TARGET_TYPE[target_type]) + from_number(param, 2) + transform_param(0)
end

#parse(params) ⇒ Object



125
126
127
128
129
130
131
# File 'lib/sdn/messages/control.rb', line 125

def parse(params)
  super
  self.target_type = TARGET_TYPE.invert[to_number(params[0])]
  target = to_number(params[1..2], nillable: true)
  target *= 10 if %I{jog_down_ms jog_up_ms}.include?(target_type)
  self.target = target
end