Class: SDN::Message::Lock

Inherits:
Message
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(dest = nil, target_type = :unlock, target = nil, priority = 1, **kwargs) ⇒ Lock

Creates a lock or unlock control message.

Parameters:

  • dest ((Integer, Integer, Integer), nil) (defaults to: nil)

    destination address

  • target_type (:current, :up_limit, :down_limit, :ip, :unlock, :position_percent) (defaults to: :unlock)

    lock target selector

  • target (Integer, nil) (defaults to: nil)

    lock target value

  • priority (Integer) (defaults to: 1)

    lock priority

  • kwargs (Hash)

    additional message options



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

#priorityInteger

Requested lock priority.

Returns:

  • (Integer)


27
28
29
# File 'lib/sdn/message/control.rb', line 27

def priority
  @priority
end

#targetInteger?

Returns:

  • (Integer, nil)


22
23
24
# File 'lib/sdn/message/control.rb', line 22

def target
  @target
end

#target_type:current, ...

Returns:

  • (:current, :up_limit, :down_limit, :ip, :unlock, :position_percent)


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.

Returns:

  • (<Integer>)


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.

Parameters:

  • params (<Integer>)

    raw parameter bytes

Raises:



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