Skip to content
Snippets Groups Projects
Commit 2ee3824f authored by jkerdreu's avatar jkerdreu
Browse files

Initial release

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/fork@1602 b32b6428-25c9-4566-ad07-03861ab6144f
parent 362f8b7d
Branches
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
#
# Copyright 2016 Jérôme Kerdreux, IMT Atlantique.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from xaal.lib import Engine, Device
from xaal.lib import tools
import sys
import json
import time
from .ansi2 import term
def usage():
print("xaal-querydb xxxx-xxxx-xxxx : display information about a given device")
class QueryDB:
def __init__(self,engine):
self.eng = engine
self.eng.handle_rx_msg = self.parse_answer
# new fake device
self.addr = tools.get_random_uuid()
self.dev = Device("cli.experimental",self.addr)
self.eng.add_device(self.dev)
print("xAAL Info dumper [%s]" % self.addr)
def query(self,addr):
""" send getDescription & getAttributes and wait for reply"""
self.target = addr
self.msgCnt = 0
self.timer = 0
mf = self.eng.msg_factory
body = {'key':'location'}
msg = mf.build_msg(self.dev,[], 'request','getDevices',body)
self.eng.queue_tx(msg)
term('cyan')
print("** Device : [%s]" % self.target)
term()
while 1:
self.eng.loop()
if self.timer > 30:
print("TimeOut...")
break
if self.msgCnt > 1:break
self.timer += 1
print('\n')
def parse_answer(self,msg):
""" message parser """
if msg.is_reply():
if self.addr in msg.targets:
if self.target == msg.source:
print(json.dumps(msg.body,sort_keys=True,indent=4))
self.msgCnt += 1
def main():
t0 = time.time()
eng = Engine()
eng.start()
dev = QueryDB(eng)
dev.query(None)
if __name__ == '__main__':
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment