Class: SDN::Message::ILT2::SetMotorPosition
- Inherits:
-
SDN::Message
- Object
- SDN::Message
- SDN::Message::ILT2::SetMotorPosition
- Defined in:
- lib/sdn/message/ilt2/set.rb
Overview
Command that moves an ILT2 motor to a specific target.
Constant Summary collapse
- MSG =
Protocol message number
0x54- PARAMS_LENGTH =
Number of protocol parameter bytes expected
3- TARGET_TYPE =
Mapping from symbolic ILT2 move targets to SDN parameter values.
{ 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
- #target ⇒ Integer, ...
-
#target_type ⇒ :up_limit, ...
Requested ILT2 movement target selector.
Attributes inherited from SDN::Message
#ack_requested, #dest, #node_type, #src
Instance Method Summary collapse
-
#initialize(dest = nil, target_type = :up_limit, target = 0, **kwargs) ⇒ SetMotorPosition
constructor
Creates an ILT2 motor positioning command.
-
#params ⇒ <Integer>
Returns the protocol-specific payload bytes for this message.
-
#parse(params) ⇒ void
Parses protocol-specific parameter bytes into this message instance.
Methods inherited from SDN::Message
#==, expected_response?, #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
Creates an ILT2 motor positioning command.
209 210 211 212 213 214 |
# File 'lib/sdn/message/ilt2/set.rb', line 209 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
#target ⇒ Integer, ...
201 202 203 |
# File 'lib/sdn/message/ilt2/set.rb', line 201 def target @target end |
#target_type ⇒ :up_limit, ...
Requested ILT2 movement target selector.
196 197 198 |
# File 'lib/sdn/message/ilt2/set.rb', line 196 def target_type @target_type end |
Instance Method Details
#params ⇒ <Integer>
Returns the protocol-specific payload bytes for this message.
245 246 247 248 249 250 |
# File 'lib/sdn/message/ilt2/set.rb', line 245 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) ⇒ void
This method returns an undefined value.
Parses protocol-specific parameter bytes into this message instance.
217 218 219 220 221 222 223 224 |
# File 'lib/sdn/message/ilt2/set.rb', line 217 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 |