Class: SDN::Message::SetMotorLimits

Inherits:
Message
  • Object
show all
Defined in:
lib/sdn/message/set.rb

Overview

Command that modifies a motor's travel limits.

Constant Summary collapse

MSG =

Protocol message number

0x11
PARAMS_LENGTH =

Number of protocol parameter bytes expected

4
TYPE =

Mapping from symbolic limit write modes to SDN parameter values.

{ delete: 0x00, current_position: 0x01, specified_position: 0x02, jog_ms: 0x04, jog_pulses: 0x05 }.freeze
TARGET =

Mapping from symbolic limit targets to SDN parameter values.

{ down: 0x00, up: 0x01 }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dest = nil, type = :delete, target = :up, value = nil, **kwargs) ⇒ SetMotorLimits

Creates a limit write command.

Parameters:

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

    destination address

  • type (:delete, :current_position, :specified_position, :jog_ms, :jog_pulses) (defaults to: :delete)

    limit write mode

  • target (:up, :down) (defaults to: :up)

    target limit

  • value (Integer, nil) (defaults to: nil)
  • kwargs (Hash)

    additional message options



274
275
276
277
278
279
280
# File 'lib/sdn/message/set.rb', line 274

def initialize(dest = nil, type = :delete, target = :up, value = nil, **kwargs)
  kwargs[:dest] ||= dest
  super(**kwargs)
  self.type = type
  self.target = target
  self.value = value
end

Instance Attribute Details

#target:up, :down

Returns:

  • (:up, :down)


260
261
262
# File 'lib/sdn/message/set.rb', line 260

def target
  @target
end

#type:delete, ...

Returns:

  • (:delete, :current_position, :specified_position, :jog_ms, :jog_pulses)


255
256
257
# File 'lib/sdn/message/set.rb', line 255

def type
  @type
end

#valueInteger?

Returns:

  • (Integer, nil)


265
266
267
# File 'lib/sdn/message/set.rb', line 265

def value
  @value
end

Instance Method Details

#params<Integer>

Returns the protocol-specific payload bytes for this message.

Returns:

  • (<Integer>)


310
311
312
313
314
# File 'lib/sdn/message/set.rb', line 310

def params
  param = value || 0
  param /= 10 if target == :jog_ms
  transform_param(TYPE[type]) + transform_param(TARGET[target]) + from_number(param, 2)
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:



283
284
285
286
287
288
# File 'lib/sdn/message/set.rb', line 283

def parse(params)
  super
  self.type = TYPE.invert[to_number(params[0])]
  self.target = TARGET.invert[to_number(params[1])]
  self.value = to_number(params[2..3])
end