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
|
# 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
|
||||||
|
|
Loading…
Reference in New Issue