Class: SDN::Message::MoveTo

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

Instance Method Summary collapse

Constructor Details

#initialize(dest = nil, target_type = :down_limit, target = nil, speed = :up, **kwargs) ⇒ MoveTo

Creates an absolute movement command.

Parameters:

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

    destination address

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

    absolute target selector

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

    target value

  • speed (:up, :down, :slow) (defaults to: :up)

    speed selector

  • kwargs (Hash)

    additional message options



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.

Returns:

  • (:up, :down, :slow)


270
271
272
# File 'lib/sdn/message/control.rb', line 270

def speed
  @speed
end

#targetInteger?

Returns:

  • (Integer, nil)


263
264
265
# File 'lib/sdn/message/control.rb', line 263

def target
  @target
end

#target_type:down_limit, ...

Requested absolute target selector.

Returns:

  • (:down_limit, :up_limit, :ip, :position_pulses, :position_percent)


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.

Returns:

  • (<Integer>)


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.

Parameters:

  • params (<Integer>)

    raw parameter bytes

Raises:



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