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, #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.



126
127
128
129
130
131
# File 'lib/sdn/message/ilt2/set.rb', line 126

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.



124
125
126
# File 'lib/sdn/message/ilt2/set.rb', line 124

def target
  @target
end

#target_typeObject

Returns the value of attribute target_type.



124
125
126
# File 'lib/sdn/message/ilt2/set.rb', line 124

def target_type
  @target_type
end

Instance Method Details

#paramsObject



160
161
162
163
164
165
# File 'lib/sdn/message/ilt2/set.rb', line 160

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



133
134
135
136
137
138
139
140
# File 'lib/sdn/message/ilt2/set.rb', line 133

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