Class: Reply

Inherits:
Telegram show all
Defined in:
lib/telegrams/reply.rb

Constant Summary collapse

COMMAND_TYPE =
0x02
SUCCESS =
0x00
STATUS_MESSAGES =
{
  SUCCESS => 'Success',
  # base error messages
  0x81 => 'No more handles',
  0x82 => 'No space',
  0x83 => 'No more files',
  0x84 => 'End of file expected',
  0x85 => 'End of file',
  0x86 => 'Not a linear file',
  0x87 => 'File not found',
  0x88 => 'Handle all ready closed',
  0x89 => 'No linear space',
  0x8A => 'Undefined error',
  0x8B => 'File is busy',
  0x8C => 'No write buffers',
  0x8D => 'Append not possible',
  0x8E => 'File is full',
  0x8F => 'File exists',
  0x90 => 'Module not found',
  0x91 => 'Out of boundary',
  0x92 => 'Illegal file name',
  0x93 => 'Illegal handle',

  # command replies
  0x20 => 'Pending communication transaction in progress',
  0x40 => 'Specified mailbox queue is empty',
  0xBD => 'Request failed (i.e., specified file not found)',
  0xBE => 'Unknown command opcode',
  0xBF => 'Insane packet',
  0xC0 => 'Data contains out-of-range values',
  0xDD => 'Communication bus error',
  0xDE => 'No free memory in communication buffer',
  0xDF => 'Specified channel/connection is not valid',
  0xE0 => 'Specified channel/connection not configured or busy',
  0xEC => 'No active program',
  0xED => 'Illegal size specified',
  0xEE => 'Illegal mailbox queue ID specified',
  0xEF => 'Attempted to access invalid field of a structure',
  0xF0 => 'Bad input or output specified',
  0xFB => 'Insufficient memory available',
  0xFF => 'Bad arguments'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Telegram

#as_bytes, #max_size_in_bytes

Constructor Details

#initialize(bytes = nil) ⇒ Reply

Returns a new instance of Reply.



51
52
53
54
55
56
57
58
# File 'lib/telegrams/reply.rb', line 51

def initialize(bytes=nil)
  validate_bytes(bytes)
  @type = bytes[0]
  @command = bytes[1]
  @status = bytes[2]
  @message_bytes = bytes[3..-1]
  set_status_description
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



49
50
51
# File 'lib/telegrams/reply.rb', line 49

def command
  @command
end

#message_bytesObject

Returns the value of attribute message_bytes.



49
50
51
# File 'lib/telegrams/reply.rb', line 49

def message_bytes
  @message_bytes
end

#statusObject

Returns the value of attribute status.



49
50
51
# File 'lib/telegrams/reply.rb', line 49

def status
  @status
end

#status_descriptionObject

Returns the value of attribute status_description.



49
50
51
# File 'lib/telegrams/reply.rb', line 49

def status_description
  @status_description
end

#typeObject

Returns the value of attribute type.



49
50
51
# File 'lib/telegrams/reply.rb', line 49

def type
  @type
end

Instance Method Details

#messageObject



66
67
68
69
# File 'lib/telegrams/reply.rb', line 66

def message
  # override in subclasses to translate bytes to something meaningful
  message_bytes
end

#success?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/telegrams/reply.rb', line 61

def success?
  status == SUCCESS
end