Skip to content
Snippets Groups Projects
Commit 3b97a346 authored by jkerdreu's avatar jkerdreu
Browse files

Added short_address

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/trunk@2026 b32b6428-25c9-4566-ad07-03861ab6144f
parent 1ef9fcf2
No related branches found
No related tags found
No related merge requests found
......@@ -30,12 +30,10 @@ FORMAT = '%-8.08s=> %-15.15s %-36.36s (%-20.20s) %-18.18s %-80.80s'
logger = tools.get_logger("tail",'DEBUG')
def reduceAddr(addr):
return addr[:5] + '..' + addr[-5:]
def display(msg):
term('yellow')
targets = [reduceAddr(addr) for addr in msg.targets]
targets = [tools.reduce_addr(addr) for addr in msg.targets]
res = FORMAT % (msg.msgtype,msg.action,msg.source,msg.devtype,targets,msg.body)
if msg.is_request():
......
......@@ -2,6 +2,8 @@
import time,random
from enum import Enum
from xaal.lib import tools
import logging
logger = logging.getLogger(__name__)
......@@ -14,6 +16,7 @@ def now():
class Device:
def __init__(self, addr, devtype, version):
self.address = addr
self.short_address = tools.reduce_addr(addr)
self.devtype = devtype
self.version = version
# device cache
......@@ -46,6 +49,16 @@ class Device:
self.db.update(data)
self.refresh_db = now()
def update_cache_db(self,data):
purge = []
for k in data:
if data[k]==None:
purge.append(k)
self.db.update(data)
for k in purge:
self.db.pop(k)
self.refresh_db = 0
def alive(self,value):
self.last_alive = int(time.time())
self.next_alive = self.last_alive + value
......@@ -62,7 +75,12 @@ class Device:
print(" Attributes : %s" % self.attributes)
print()
@property
def display_name(self):
result = ''
result = self.db.get('nickname',result)
result = self.db.get('name',result)
return result
class Devices:
""" Device List for monitoring """
......@@ -204,13 +222,13 @@ class Monitor:
elif self.is_reply_metadb(msg):
addr = msg.body['device']
target = self.devices.get_with_addr(addr)
if target:
if target and 'map' in msg.body:
target.db = msg.body['map']
elif self.is_update_metadb(msg):
addr = msg.body['device']
target = self.devices.get_with_addr(addr)
if target:
if target and 'map' in msg.body:
target.update_db(msg.body['map'])
def subscribe(self,func):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment