Class: SDN::Message::Nack

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

Overview

Negative acknowledgement response emitted when a request cannot be fulfilled.

Constant Summary collapse

MSG =

Protocol message number

0x6f
PARAMS_LENGTH =

Number of protocol parameter bytes expected

1
VALUES =

Mapping from symbolic error names to SDN error codes.

{ data_error: 0x01,
unknown_message: 0x10,
node_is_locked: 0x20,
wrong_position: 0x21,
limits_not_set: 0x22,
ip_not_set: 0x23,
out_of_range: 0x24,
busy: 0xff }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dest = nil, error_code = nil, **kwargs) ⇒ Nack

Creates a negative acknowledgement message.

Parameters:

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

    destination address

  • error_code (Symbol, Integer, nil) (defaults to: nil)

    protocol error code

  • kwargs (Hash)

    additional message options



256
257
258
259
260
# File 'lib/sdn/message.rb', line 256

def initialize(dest = nil, error_code = nil, **kwargs)
  kwargs[:dest] ||= dest
  super(**kwargs)
  self.error_code = error_code
end

Instance Attribute Details

#error_codeSymbol, ...

Parsed NACK error code as a symbolic name or raw integer.

Returns:

  • (Symbol, Integer, nil)


249
250
251
# File 'lib/sdn/message.rb', line 249

def error_code
  @error_code
end

Instance Method Details

#params<Integer>

Returns the protocol-specific payload bytes for this message.

Returns:

  • (<Integer>)


272
273
274
# File 'lib/sdn/message.rb', line 272

def params
  transform_param(VALUES[error_code] || error_code)
end

#parse(params) ⇒ Object

Parses the negative acknowledgement error code.

Parameters:

  • params (<Integer>)

    raw parameter bytes



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

def parse(params)
  super
  error_code = to_number(params[0])
  self.error_code = VALUES.invert[error_code] || error_code
end