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
ISCP Command
Command description
Human readable command name
EISCP
header
Differentiates parsed messages from command messages
ISCP Start character, usually “!”
Terminator character for eISCP packets
ISCP Unit Type character, usually “1”
ISCP Command Value
Value description
Human readable value name
ISCP Zone
Public Class Methods
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
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
Return ISCP Message
string
# File lib/eiscp/message.rb, line 87 def to_iscp (@start + @unit_type + @command + @value).to_s end
Return human readable description.
# File lib/eiscp/message.rb, line 107 def to_s "#{@zone} - #{@command_name}:#{@value_name}" end
Private Instance Methods
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