Class: SDN::Message::MoveTo
- Inherits:
-
Message
- Object
- Message
- SDN::Message::MoveTo
- Defined in:
- lib/sdn/message/control.rb
Overview
Command that moves a motor to an absolute target.
Constant Summary collapse
- MSG =
Protocol message number
0x03- PARAMS_LENGTH =
Number of protocol parameter bytes expected
4- TARGET_TYPE =
Mapping from symbolic absolute targets to SDN parameter values.
{ down_limit: 0x00, up_limit: 0x01, ip: 0x02, position_pulses: 0x03, position_percent: 0x04 }.freeze
- SPEED =
Mapping from symbolic speed modes to SDN parameter values.
{ up: 0x00, down: 0x01, slow: 0x02 }.freeze
Instance Attribute Summary collapse
-
#speed ⇒ :up, ...
Requested movement speed mode.
- #target ⇒ Integer?
-
#target_type ⇒ :down_limit, ...
Requested absolute target selector.
Instance Method Summary collapse
-
#initialize(dest = nil, target_type = :down_limit, target = nil, speed = :up, **kwargs) ⇒ MoveTo
constructor
Creates an absolute 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 = :down_limit, target = nil, speed = :up, **kwargs) ⇒ MoveTo
Creates an absolute movement command.
279 280 281 282 283 284 285 |
# File 'lib/sdn/message/control.rb', line 279 def initialize(dest = nil, target_type = :down_limit, target = nil, speed = :up, **kwargs) kwargs[:dest] ||= dest super(**kwargs) self.target_type = target_type self.target = target self.speed = speed end |
Instance Attribute Details
#speed ⇒ :up, ...
Requested movement speed mode.
270 271 272 |
# File 'lib/sdn/message/control.rb', line 270 def speed @speed end |
#target ⇒ Integer?
263 264 265 |
# File 'lib/sdn/message/control.rb', line 263 def target @target end |
#target_type ⇒ :down_limit, ...
Requested absolute target selector.
258 259 260 |
# File 'lib/sdn/message/control.rb', line 258 def target_type @target_type end |
Instance Method Details
#params ⇒ <Integer>
Returns the protocol-specific payload bytes for this message.
316 317 318 |
# File 'lib/sdn/message/control.rb', line 316 def params transform_param(TARGET_TYPE[target_type]) + from_number(target || 0xffff, 2) + transform_param(SPEED[speed]) end |
#parse(params) ⇒ void
This method returns an undefined value.
Parses protocol-specific parameter bytes into this message instance.
288 289 290 291 292 293 |
# File 'lib/sdn/message/control.rb', line 288 def parse(params) super self.target_type = TARGET_TYPE.invert[to_number(params[0])] self.target = to_number(params[1..2], nillable: true) self.speed = SPEED.invert[to_number(params[3])] end |