Class: KNX::ObjectServer::Datagram
- Inherits:
-
Struct
- Object
- Struct
- KNX::ObjectServer::Datagram
- Defined in:
- lib/knx/object_server/datagram.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#error_code ⇒ Object
readonly
Returns the value of attribute error_code.
-
#header ⇒ Object
Returns the value of attribute header.
-
#knx_header ⇒ Object
Returns the value of attribute knx_header.
Instance Method Summary collapse
- #add_action(index, data: nil, **options) ⇒ Object
- #error? ⇒ Boolean
-
#initialize(raw_data = nil) ⇒ Datagram
constructor
A new instance of Datagram.
- #to_binary_s ⇒ Object
Constructor Details
#initialize(raw_data = nil) ⇒ Datagram
Returns a new instance of Datagram.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/knx/object_server/datagram.rb', line 22 def initialize(raw_data = nil) super(Header.new, ConnectionHeader.new, ObjectHeader.new) # These values are unique to the KNX Object Server self.knx_header.version = 0x20 self.knx_header.request_type = 0xF080 @data = [] if raw_data self.knx_header.read(raw_data[0..5]) self.connection.read(raw_data[6..9]) self.header.read(raw_data[10..15]) # Check for error if self.header.item_count == 0 @error_code = raw_data[16].getbyte(0) @error = Errors[@error_code] else @error_code = 0 @error = :no_error # Read the response index = 16 self.header.item_count.times do next_index = index + 4 item = StatusItem.new item.read(raw_data[index...next_index]) index = next_index + item.value_length item.value = raw_data[next_index...index] @data << item end end end end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection
21 22 23 |
# File 'lib/knx/object_server/datagram.rb', line 21 def connection @connection end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
59 60 61 |
# File 'lib/knx/object_server/datagram.rb', line 59 def data @data end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
59 60 61 |
# File 'lib/knx/object_server/datagram.rb', line 59 def error @error end |
#error_code ⇒ Object (readonly)
Returns the value of attribute error_code.
59 60 61 |
# File 'lib/knx/object_server/datagram.rb', line 59 def error_code @error_code end |
#header ⇒ Object
Returns the value of attribute header
21 22 23 |
# File 'lib/knx/object_server/datagram.rb', line 21 def header @header end |
#knx_header ⇒ Object
Returns the value of attribute knx_header
21 22 23 |
# File 'lib/knx/object_server/datagram.rb', line 21 def knx_header @knx_header end |
Instance Method Details
#add_action(index, data: nil, **options) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/knx/object_server/datagram.rb', line 79 def add_action(index, data: nil, **) req = RequestItem.new req.id = index.to_i req.command = Commands[[:command]] || :set_value if not data.nil? if data == true || data == false data = data ? 1 : 0 end if data.is_a? String req.value = data else req.value = String.new req.value << data end end @data << req self end |
#error? ⇒ Boolean
62 63 64 |
# File 'lib/knx/object_server/datagram.rb', line 62 def error? @error_code != 0 end |
#to_binary_s ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/knx/object_server/datagram.rb', line 66 def to_binary_s self.header.item_count = @data.length if @data.length > 0 resp = String.new "#{self.connection.to_binary_s}#{self.header.to_binary_s}" @data.each do |item| resp << item.to_binary_s end self.knx_header.request_length = resp.length + 6 resp.prepend self.knx_header.to_binary_s resp end |