Class: EISCP::Message
- Inherits:
-
Object
- Object
- EISCP::Message
- Defined in:
- lib/eiscp/message.rb
Overview
Constant Summary collapse
- MAGIC =
ISCP “magic” indicates the start of an eISCP message.
'ISCP'
- HEADER_SIZE =
eISCP header size, fixed length.
16
- ISCP_VERSION =
ISCP protocol version.
1
- RESERVED =
Reserved for future protocol updates.
"\x00\x00\x00"
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
ISCP Command.
-
#command_description ⇒ Object
readonly
Command description.
-
#command_name ⇒ Object
readonly
Human readable command name.
-
#header ⇒ Object
EISCP header.
-
#parsed ⇒ Object
readonly
Differentiates parsed messages from command messages.
-
#start ⇒ Object
readonly
ISCP Start character, usually “!”.
-
#terminator ⇒ Object
readonly
Terminator character for eISCP packets.
-
#unit_type ⇒ Object
readonly
ISCP Unit Type character, usually “1”.
-
#value ⇒ Object
readonly
ISCP Command Value.
-
#value_description ⇒ Object
readonly
Value description.
-
#value_name ⇒ Object
readonly
Human readable value name.
-
#zone ⇒ Object
readonly
ISCP Zone.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Check if two messages are equivalent comparing their ISCP messages.
-
#initialize(command: nil, value: nil, terminator: "\r\n", unit_type: '1', start: '!') ⇒ Message
constructor
Create an ISCP message.
-
#to_eiscp ⇒ Object
Return EISCP Message string.
-
#to_iscp ⇒ Object
Return ISCP Message string.
-
#to_s ⇒ Object
Return human readable description.
Constructor Details
#initialize(command: nil, value: nil, terminator: "\r\n", unit_type: '1', start: '!') ⇒ Message
Create an ISCP message
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/eiscp/message.rb', line 55 def initialize(command: nil, value: nil, terminator: "\r\n", unit_type: '1', start: '!') unless Dictionary.known_command?(command) #STDERR.puts "Unknown command #{command}" end fail 'No value specified.' if value.nil? @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 #STDERR.puts"Couldn't get all human readable attrs" end end |
Instance Attribute Details
#command ⇒ Object (readonly)
ISCP Command
31 32 33 |
# File 'lib/eiscp/message.rb', line 31 def command @command end |
#command_description ⇒ Object (readonly)
Command description
35 36 37 |
# File 'lib/eiscp/message.rb', line 35 def command_description @command_description end |
#command_name ⇒ Object (readonly)
Human readable command name
33 34 35 |
# File 'lib/eiscp/message.rb', line 33 def command_name @command_name end |
#header ⇒ Object
EISCP header
16 17 18 |
# File 'lib/eiscp/message.rb', line 16 def header @header end |
#parsed ⇒ Object (readonly)
Differentiates parsed messages from command messages
45 46 47 |
# File 'lib/eiscp/message.rb', line 45 def parsed @parsed end |
#start ⇒ Object (readonly)
ISCP Start character, usually “!”
27 28 29 |
# File 'lib/eiscp/message.rb', line 27 def start @start end |
#terminator ⇒ Object (readonly)
Terminator character for eISCP packets
48 49 50 |
# File 'lib/eiscp/message.rb', line 48 def terminator @terminator end |
#unit_type ⇒ Object (readonly)
ISCP Unit Type character, usually “1”
29 30 31 |
# File 'lib/eiscp/message.rb', line 29 def unit_type @unit_type end |
#value ⇒ Object (readonly)
ISCP Command Value
37 38 39 |
# File 'lib/eiscp/message.rb', line 37 def value @value end |
#value_description ⇒ Object (readonly)
Value description
41 42 43 |
# File 'lib/eiscp/message.rb', line 41 def value_description @value_description end |
#value_name ⇒ Object (readonly)
Human readable value name
39 40 41 |
# File 'lib/eiscp/message.rb', line 39 def value_name @value_name end |
#zone ⇒ Object (readonly)
ISCP Zone
43 44 45 |
# File 'lib/eiscp/message.rb', line 43 def zone @zone end |
Instance Method Details
#==(other) ⇒ Object
Check if two messages are equivalent comparing their ISCP messages.
82 83 84 |
# File 'lib/eiscp/message.rb', line 82 def ==(other) to_iscp == other.to_iscp ? true : false end |
#to_eiscp ⇒ Object
Return EISCP Message string
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/eiscp/message.rb', line 94 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 ⇒ Object
Return ISCP Message string
88 89 90 |
# File 'lib/eiscp/message.rb', line 88 def to_iscp "#{@start + @unit_type + @command + @value}" end |
#to_s ⇒ Object
Return human readable description.
108 109 110 |
# File 'lib/eiscp/message.rb', line 108 def to_s "#{@zone} - #{@command_name}:#{@value_name}" end |