Class: SDN::Message::Lock
- Inherits:
-
Message
- Object
- Message
- SDN::Message::Lock
- Defined in:
- lib/sdn/message/control.rb
Overview
Command that applies or clears a positional motor lock.
Constant Summary collapse
- MSG =
Protocol message number
0x06- PARAMS_LENGTH =
Number of protocol parameter bytes expected
5- TARGET_TYPE =
Mapping from symbolic lock targets to SDN parameter values.
{ current: 0, up_limit: 1, down_limit: 2, ip: 4, unlock: 5, position_percent: 7 }.freeze
Instance Attribute Summary collapse
-
#priority ⇒ Integer
Requested lock priority.
- #target ⇒ Integer?
- #target_type ⇒ :current, ...
Instance Method Summary collapse
-
#initialize(dest = nil, target_type = :unlock, target = nil, priority = 1, **kwargs) ⇒ Lock
constructor
Creates a lock or unlock control message.
-
#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 = :unlock, target = nil, priority = 1, **kwargs) ⇒ Lock
Creates a lock or unlock control message.
36 37 38 39 40 41 42 |
# File 'lib/sdn/message/control.rb', line 36 def initialize(dest = nil, target_type = :unlock, target = nil, priority = 1, **kwargs) kwargs[:dest] ||= dest super(**kwargs) self.target_type = target_type self.target = target self.priority = priority end |
Instance Attribute Details
#priority ⇒ Integer
Requested lock priority.
27 28 29 |
# File 'lib/sdn/message/control.rb', line 27 def priority @priority end |
#target ⇒ Integer?
22 23 24 |
# File 'lib/sdn/message/control.rb', line 22 def target @target end |
#target_type ⇒ :current, ...
17 18 19 |
# File 'lib/sdn/message/control.rb', line 17 def target_type @target_type end |
Instance Method Details
#params ⇒ <Integer>
Returns the protocol-specific payload bytes for this message.
71 72 73 74 |
# File 'lib/sdn/message/control.rb', line 71 def params transform_param(TARGET_TYPE[target_type]) + from_number(target, 2) + transform_param(priority) + transform_param(0) end |
#parse(params) ⇒ void
This method returns an undefined value.
Parses protocol-specific parameter bytes into this message instance.
62 63 64 65 66 67 68 |
# File 'lib/sdn/message/control.rb', line 62 def parse(params) super self.target_type = TARGET_TYPE.invert[to_number(params[0])] target = to_number(params[1..2], nillable: true) self.target = target self.priority = to_number(params[3]) end |