Class: SDN::Message::MoveOf
- Inherits:
-
Message
- Object
- Message
- SDN::Message::MoveOf
- Defined in:
- lib/sdn/message/control.rb
Overview
Command that moves a motor relative to its current position.
Constant Summary collapse
- MSG =
Protocol message number
0x04- PARAMS_LENGTH =
Number of protocol parameter bytes expected
4- TARGET_TYPE =
Mapping from symbolic relative targets to SDN parameter values.
{ next_ip: 0x00, previous_ip: 0x01, jog_down_pulses: 0x02, jog_up_pulses: 0x03, jog_down_ms: 0x04, jog_up_ms: 0x05 }.freeze
Instance Attribute Summary collapse
-
#target ⇒ Integer?
Requested relative target amount in pulses or milliseconds.
-
#target_type ⇒ :next_ip, ...
Requested relative target selector.
Instance Method Summary collapse
-
#initialize(dest = nil, target_type = nil, target = nil, **kwargs) ⇒ MoveOf
constructor
Creates a relative movement command.
-
#params ⇒ <Integer>
Returns the protocol-specific payload bytes for this message.
-
#parse(params) ⇒ void
Parses protocol-specific parameter bytes into this message instance.
Constructor Details
#initialize(dest = nil, target_type = nil, target = nil, **kwargs) ⇒ MoveOf
Creates a relative movement command.
204 205 206 207 208 209 |
# File 'lib/sdn/message/control.rb', line 204 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
#target ⇒ Integer?
Requested relative target amount in pulses or milliseconds.
190 191 192 |
# File 'lib/sdn/message/control.rb', line 190 def target @target end |
#target_type ⇒ :next_ip, ...
Requested relative target selector.
183 184 185 |
# File 'lib/sdn/message/control.rb', line 183 def target_type @target_type end |
Instance Method Details
#params ⇒ <Integer>
Returns the protocol-specific payload bytes for this message.
235 236 237 238 239 |
# File 'lib/sdn/message/control.rb', line 235 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) ⇒ void
This method returns an undefined value.
Parses protocol-specific parameter bytes into this message instance.
212 213 214 215 216 217 218 |
# File 'lib/sdn/message/control.rb', line 212 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 |