def idScene(elem): # <CC id = "6" Dm="0" Ds="0" Am="10" Av="21554" /> def mkDout(i,dm,ds): m = 1 << i return cond(m&dm,(cond(m&ds,"N","F")),"I") def mkAout(i,am,av): return cond(am & (1 << i), "S"+str((av>>(i*4))&0xF), "I") (dm,ds,am,av) = map( compose(int,elem.getAttribute), ("Dm","Ds","Am","Av") ) params = getParams(elem,["id"]) + ";" for i in range(16): params = params + mkDout(i,dm,ds) for i in range(4): params = params + ";" + mkAout(i,am,av) return params
def trigger65(trgname,opt,base): def mkInt(s): return int(s or "0") # Retrieve sub-element with trigger attributes elem = base.getElementsByTagName(trgname)[0] # Extract trigger parameters from Opt and B1 B2 B3 B4 attributes (b1,b2,b3,b4) = map( compose(mkInt,elem.getAttribute), ("B1","B2","B3","B4") ) # Construct result of form: # {A|D}<chn>;<setpt>;<action>;<dwelltime>;<udptype>;<assocval>;<b4>;<opt> if b2 & 0x80: ads = "A" opchan = (b2 >> 4) & 0x7 # Analog output channel (0-7) setpt = b2 & 0xF # Set point number (0-15) else: ads = "D" opchan = b2 & 0xF # Digital output channel (0-15) if b2&0x40: ads = "S" # Digital or scene output? setpt = 0 # No set point udpopt = (b1 >> 7) & 0x1 # UDP (0-none,1-general) dwtime = 0 # default dwell time action = 0 b1 = b1 & 0x7F if b1 >= 0x60: # dwell group action = (b1 >> 3 ) & 0x03 # action number action = (18,19,6,5)[action] dwtime = b1 & 0x7 # dwell time, now bottom 3 bits elif b1 >= 0x40: #not used pass elif b1 >= 0x20: # not used pass else: # group 1 action = b1 & 0x1F # action number assocv = b3 # associated value (was remote) result = ( ads+str(opchan)+ ";"+str(setpt)+ ";"+str(action)+ ";"+str(dwtime)+ ";"+str(udpopt)+ ";"+str(assocv) ) # b4 and opt are not defined for all webbricks # opt is used only if b4 is present (non-zero) if b4: result += ";"+str(b4) # Add 'B4' attribute if present if opt: result += ";"+opt # Add 'Opt' attribute if present return result
def trigger(trgname,opt,base): def mkInt(s): return int(s or "0") # Retrieve sub-element with trigger attributes elem = base.getElementsByTagName(trgname)[0] # Extract trigger parameters from Opt and B1 B2 B3 B4 attributes (b1,b2,b3,b4) = map( compose(mkInt,elem.getAttribute), ("B1","B2","B3","B4") ) # Construct result of form: # {A|D}<chn>;<setpt>;<action>;<dwelltime>;<udptype>;<assocval>;<b4>;<opt> if b2 & 0x80: ads = "A" opchan = (b2 >> 4) & 0x7 # Analog output channel (0-7) setpt = b2 & 0xF # Set point number (0-15) else: ads = "D" opchan = b2 & 0xF # Digital output channel (0-15) if b2&0x40: ads = "S" # Digital or scene output? setpt = 0 # No set point action = b1 & 0xF # action number dwtime = (b1 >> 4) & 0x3 # dwell time udpopt = (b1 >> 6) & 0x3 # UDP (0-none,1-general,2-remote,3-alarm) assocv = b3 # associated value (was remote) result = ( ads+str(opchan)+ ";"+str(setpt)+ ";"+str(action)+ ";"+str(dwtime)+ ";"+str(udpopt)+ ";"+str(assocv) ) # b4 and opt are not defined for all webbricks # opt is used only if b4 is present if b4: result += ";"+str(b4) # Add 'B4' attribute if present if opt: result += ";"+opt # Add 'Opt' attribute if present return result