Class: SDN::Message::ILT2::SetMotorPosition

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

Constant Summary collapse

MSG =
0x54
PARAMS_LENGTH =
3
TARGET_TYPE =
{
  up_limit: 1,
  down_limit: 2,
  stop: 3,
  ip: 4,
  next_ip_up: 5,
  next_ip_down: 6,
  position_pulses: 8,
  jog_up_ms: 10,
  jog_down_ms: 11,
  jog_up_pulses: 12,
  jog_down_pulses: 13,
  position_percent: 16,
}.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, #is_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 = :up_limit, target = 0, **kwargs) ⇒ SetMotorPosition

Returns a new instance of SetMotorPosition.



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

def initialize(dest = nil, target_type = :up_limit, target = 0, **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/message/ilt2/set.rb', line 116

def target
  @target
end

#target_typeObject

Returns the value of attribute target_type.



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

def target_type
  @target_type
end

Instance Method Details

#paramsObject



151
152
153
154
155
156
# File 'lib/sdn/message/ilt2/set.rb', line 151

def params
  param = target
  param = (param * 255 / 100).to_i if target_type == :position_percent
  param -= 1 if target_type == :ip
  transform_param(TARGET_TYPE[target_type]) + from_number(param, 2)
end

#parse(params) ⇒ Object



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

def parse(params)
  super
  self.target_type = TARGET_TYPE.invert[to_number(params[0])]
  target = to_number(params[1..2])
  if target_type == :position_percent
    target = target.to_f / 255 * 100
  end
  if target_type == :ip
    target += 1
  end
  self.target = target
end