diff --git a/telegram.rb b/telegram.rb index 6c77270..d454ba1 100644 --- a/telegram.rb +++ b/telegram.rb @@ -62,22 +62,29 @@ class Telegram # create a query or send telegram for this object # query if data is nil, else send data - def initialize (object, data=nil) + # direction: true = control unit to device, false = device to control unit + def initialize (object, data=nil, direction=true) # telegram direction: true = control unit to device, false = device to control unit - @direction = true + @direction = direction # cast type: true = query, false = answer - @cast = true + @cast = direction # device node @node = 0 # set object @object = object # verify data - if data==nil or data.empty? then - @transmission = QUERY - @data = [] + if direction then + if data==nil or data.empty? then + @transmission = QUERY + @data = [] + else + raise "wrong data length" if LENGTHS[@object] and data.length!=LENGTHS[@object] + @transmission = SEND + @data = data + end else - raise "wrong data length" if LENGTHS[@object] and data.length!=LENGTHS[@object] - @transmission = SEND + raise "wrong data length" if data.empty? or (LENGTHS[@object] and data.length>LENGTHS[@object]) + @transmission = ANSWER @data = data end end