From 146ce311ee04d428183ebc2b713ce57a1008ec5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Thu, 30 Jul 2015 09:49:22 +0200 Subject: [PATCH] allow create answers --- telegram.rb | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) 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