allow create answers

This commit is contained in:
King Kévin 2015-07-30 09:49:22 +02:00
parent 62c3986036
commit 146ce311ee
1 changed files with 15 additions and 8 deletions

View File

@ -62,22 +62,29 @@ class Telegram
# create a query or send telegram for this object # create a query or send telegram for this object
# query if data is nil, else send data # 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 # telegram direction: true = control unit to device, false = device to control unit
@direction = true @direction = direction
# cast type: true = query, false = answer # cast type: true = query, false = answer
@cast = true @cast = direction
# device node # device node
@node = 0 @node = 0
# set object # set object
@object = object @object = object
# verify data # verify data
if data==nil or data.empty? then if direction then
@transmission = QUERY if data==nil or data.empty? then
@data = [] @transmission = QUERY
@data = []
else
raise "wrong data length" if LENGTHS[@object] and data.length!=LENGTHS[@object]
@transmission = SEND
@data = data
end
else else
raise "wrong data length" if LENGTHS[@object] and data.length!=LENGTHS[@object] raise "wrong data length" if data.empty? or (LENGTHS[@object] and data.length>LENGTHS[@object])
@transmission = SEND @transmission = ANSWER
@data = data @data = data
end end
end end