Possibilit de prciser des intervalles de canaux
darcs-hash:20050411152409-d1718-2a4b27a942606091257f0a68a9c1407ab0918eca.gz
This commit is contained in:
parent
af7fbac922
commit
cd3b0b9e3f
1 changed files with 51 additions and 5 deletions
|
@ -2055,17 +2055,63 @@ class machine(base_classes_crans) :
|
||||||
|
|
||||||
return clef
|
return clef
|
||||||
|
|
||||||
def canal(self,new=None) :
|
def canal(self,new=None,raw=False) :
|
||||||
""" Attribution ou visualisation du canal d'une borne wifi """
|
""" Attribution ou visualisation du canal d'une borne wifi """
|
||||||
if self.__typ != 'borne' : return None
|
if self.__typ != 'borne' : return None
|
||||||
if not new:
|
if not new:
|
||||||
return self._data.get('canal',[''])[0]
|
canaux = self._data.get('canal',[''])[0]
|
||||||
|
if raw:
|
||||||
|
return canaux
|
||||||
|
else:
|
||||||
|
canaux = int(canaux)
|
||||||
|
if canaux < 14:
|
||||||
|
# Compatibilité ascendante
|
||||||
|
return str(canaux)
|
||||||
|
lcanal1 = []
|
||||||
|
for i in range(1,14):
|
||||||
|
found = False
|
||||||
|
if canaux & (1 << (i - 1)):
|
||||||
|
lcanal2 = []
|
||||||
|
for c in lcanal1:
|
||||||
|
if c[1] == i - 1:
|
||||||
|
lcanal2.append((c[0], i))
|
||||||
|
found = True
|
||||||
|
else:
|
||||||
|
lcanal2.append(c)
|
||||||
|
if not found:
|
||||||
|
lcanal2.append((i,i))
|
||||||
|
lcanal1 = lcanal2
|
||||||
|
lcanal3 = []
|
||||||
|
for c in lcanal1:
|
||||||
|
if c[0] == c[1]:
|
||||||
|
lcanal3.append("%d" % c[0])
|
||||||
|
else:
|
||||||
|
lcanal3.append("%d-%d" % (c[0],c[1]))
|
||||||
|
return ",".join(lcanal3)
|
||||||
|
|
||||||
|
|
||||||
try :
|
try :
|
||||||
new = int(new)
|
new = int(new)
|
||||||
if new < 0 or new > 14 : raise
|
if new < 0 or new > 13 : raise
|
||||||
except :
|
except :
|
||||||
raise ValueError(u'Canal invalide : doit être entre 0 et 14')
|
# Nouveau système, il doit s'agir d'une liste de canaux
|
||||||
|
try:
|
||||||
|
lcanal3 = str(new).split(",")
|
||||||
|
lcanal = []
|
||||||
|
for c in lcanal3:
|
||||||
|
c2 = c.split("-")
|
||||||
|
if len(c2) == 1:
|
||||||
|
lcanal.append(int(c2[0]))
|
||||||
|
else:
|
||||||
|
for i in range(int(c2[0]), int(c2[1]) + 1):
|
||||||
|
lcanal.append(i)
|
||||||
|
new = 0
|
||||||
|
for c in lcanal:
|
||||||
|
if c not in range(0,14):
|
||||||
|
raise
|
||||||
|
new = new + (1 << (c - 1))
|
||||||
|
except:
|
||||||
|
raise ValueError(u'Canal invalide : doit être entre 0 et 13 ou une liste de canaux')
|
||||||
|
|
||||||
self._set('canal',[str(new)])
|
self._set('canal',[str(new)])
|
||||||
return new
|
return new
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue