class EISCP::Message

The EISCP::Message class is used to handle commands and responses.

Messages can be parsed directly from raw data or created with values:

receiver = Receiver.new

command = EISCP::Message.new('PWR', 'QSTN')
response = EISCP::Parser.parse(receiver.send_recv(command))

Constants

HEADER_SIZE

eISCP header size, fixed length.

ISCP_VERSION

ISCP protocol version.

MAGIC

ISCP “magic” indicates the start of an eISCP message.

RESERVED

Reserved for future protocol updates.

Attributes

command[R]

ISCP Command

command_description[R]

Command description

command_name[R]

Human readable command name

header[RW]

EISCP header

parsed[R]

Differentiates parsed messages from command messages

start[R]

ISCP Start character, usually “!”

terminator[R]

Terminator character for eISCP packets

unit_type[R]

ISCP Unit Type character, usually “1”

value[R]

ISCP Command Value

value_description[R]

Value description

value_name[R]

Human readable value name

zone[R]

ISCP Zone

Public Class Methods

new(command: nil, value: '', terminator: "\r\n", unit_type: '1', start: '!') click to toggle source

Create an ISCP message @param [String] command three-character length ISCP command @param [String] value variable length ISCP command value @param [String] unit_type_character override default unit type character, optional @param [String] start_character override default start character, optional

# File lib/eiscp/message.rb, line 57
def initialize(command: nil, value: '', terminator: "\r\n", unit_type: '1', start: '!')
  unless Dictionary.known_command?(command)
    # STDERR.puts "Unknown command #{command}"
  end

  @command = command
  @value = value
  @terminator = terminator
  @unit_type = unit_type
  @start = start
  @header = { magic: MAGIC,
              header_size: HEADER_SIZE,
              data_size: to_iscp.length,
              version: ISCP_VERSION,
              reserved: RESERVED }
  begin
    get_human_readable_attrs
  rescue StandardError
    # STDERR.puts"Couldn't get all human readable attrs"
  end
end

Public Instance Methods

==(other) click to toggle source

Check if two messages are equivalent comparing their ISCP messages.

# File lib/eiscp/message.rb, line 81
def ==(other)
  to_iscp == other.to_iscp
end
to_eiscp() click to toggle source

Return EISCP Message string

# File lib/eiscp/message.rb, line 93
def to_eiscp
  [
    @header[:magic],
    @header[:header_size].to_i,
    @header[:data_size].to_i,
    @header[:version].to_i,
    @header[:reserved],
    to_iscp.to_s,
    @terminator
  ].pack('A4NNCa3A*A*')
end
to_iscp() click to toggle source

Return ISCP Message string

# File lib/eiscp/message.rb, line 87
def to_iscp
  (@start + @unit_type + @command + @value).to_s
end
to_s() click to toggle source

Return human readable description.

# File lib/eiscp/message.rb, line 107
def to_s
  "#{@zone} - #{@command_name}:#{@value_name}"
end

Private Instance Methods

get_human_readable_attrs() click to toggle source

Retrieves human readable attributes from the yaml file via Dictionary

# File lib/eiscp/message.rb, line 114
def get_human_readable_attrs
  @zone = Dictionary.zone_from_command(@command)
  @command_name = Dictionary.command_to_name(@command)
  @command_description = Dictionary.description_from_command(@command)
  @value_name = Dictionary.command_value_to_value_name(@command, @value)
  @value_description = Dictionary.description_from_command_value(@command, @value)
end