allow create answers
This commit is contained in:
parent
62c3986036
commit
146ce311ee
23
telegram.rb
23
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
|
||||
|
|
Loading…
Reference in New Issue