micha %!s(int64=3) %!d(string=hai) anos
pai
achega
3963602181
Modificáronse 1 ficheiros con 290 adicións e 116 borrados
  1. 290 116
      ArtNetProcessor.py

+ 290 - 116
ArtNetProcessor.py

@@ -37,7 +37,6 @@ import curses
 class Curses():
     def __init__(self):
 
-
         self.myscreen = curses.initscr()
         print( dir(self.myscreen))
         print( self.myscreen.getmaxyx() ) 
@@ -72,9 +71,12 @@ class Curses():
         try:
             for i,l in enumerate(lines):
                 #print(i,l)
-                if i >= self.myscreen.getmaxyx()[0]-3:
-                    continue
+                if i >= self.myscreen.getmaxyx()[0]-2:
+                    break
                 self.myscreen.addstr(i+1, 1, l ) #zeile,spalte,text
+
+            if i >= self.myscreen.getmaxyx()[0]-2:
+                self.myscreen.addstr(i+1, 1, "..." ) #zeile,spalte,text
             self.myscreen.refresh()
 
         except KeyboardInterrupt as e:
@@ -93,6 +95,9 @@ class Curses():
 
         try:
             self._inp=self.myscreen.getkey()
+
+            if not self._inp:
+                self._inp = self.myscreen.getch()
             self.myscreen.addstr(0, 1, str(self._inp) ) #zeile,spalte,text
             self.myscreen.refresh()
             return self._inp
@@ -103,8 +108,8 @@ class Curses():
         self.myscreen.clear()
         self.myscreen.border(0)
         curses.nocbreak();
-        #self.myscreen.keypad(0);
-        self.read()
+        self.myscreen.keypad(0);
+        #self.read()
         curses.echo()
         curses.resetty()
         #self.myscreen.addstr(10, 2, x ) #zeile,spalte,text
@@ -130,13 +135,10 @@ class xUniversum():
         self.__universes_info = {}
         self.__univers_nr = univers_nr   
         self.__frame = 0
-    def update(self,host,dmxframe):
-        if type(dmxframe) != list:
-            #print( "update ERROR dmxframe is not a list", host )
-            return 
+    def _add(self,host):
         if host not in self.__hosts:
             #print( "ADDING HOST:",host,"UNIV:",self.__univers_nr)
-            self.__universes_dmx[host] = [0]*512
+            self.__universes_dmx[host] = ["ini"]*512
             self.__universes_frames[host] = 0
             self.__universes_x_frames[host] = 0
             self.__universes_fps[host] = [99]*20
@@ -144,19 +146,9 @@ class xUniversum():
             self.__universes_x_time[host] = time.time()
             self.__universes_timer[host] = [0]*512 
             self.__universes_info[host] = {} 
-        
-        while host in self.__hosts:
-            self.__hosts.remove(host)
-        self.__hosts.append(host) #re-order hosts list for LTP
-        #print("U",host,self.__hosts)
-        #print( len(dmxframe),len([0]*512), dmxframe[:10] )
 
+    def _next_frame(self):
         self.__frame += 1
-        update_matrix = [0]*512
-        dmx=[0]*512
-        update_flag = 0
-        dmxframe_old = self.__universes_dmx[host]
-
         self.__universes_frames[host] += 1
         self.__universes_x_frames[host] += 1
         if self.__universes_x_time[host]+10 < time.time():
@@ -169,41 +161,62 @@ class xUniversum():
             self.__universes_x_time[host] = time.time()
             self.__universes_x_frames[host] = 0
 
-        if len(dmxframe) <= len(dmxframe_old):
+    def update(self,host,dmxframe):
+        if type(dmxframe) != list:
+            #print( "update ERROR dmxframe is not a list", host )
+            return 
+
+        self._add(host)
+
+        while host in self.__hosts:
+            self.__hosts.remove(host)
+        self.__hosts.append(host) #re-order hosts list for LTP
+        #print("U",host,self.__hosts)
+        #print( len(dmxframe),len([0]*512), dmxframe[:10] )
+
+        update_matrix = [0]*512
+        dmx=["non"]*512
+        update_flag = 0
+        dmxframe_old = self.__universes_dmx[host]
+        #for i in dmxframe_old:
+        #    dmx[i] = dmxframe_old[i]
+
+        self._next_frame()
+
+        if len(dmxframe) <= 512: #len(dmxframe_old):
             for i,v in enumerate(dmxframe):
                 if dmxframe[i] != dmxframe_old[i]:
                     #print( i,v, self.__frame)
                     update_matrix[i] = self.__frame #LTP timing
                     update_flag += 1
-                    dmx[i] = v
+                dmx[i] = v
         
         self.__universes_flag[host].pop(0)
         self.__universes_flag[host].append( update_flag )
         
+        tmp = {}
+        tmp["flag"] =update_flag
+        tmp["flagx"] = self.__universes_flag[host] 
+        tmp["fpsx"] = int(self.__universes_x_frames[host] / (time.time()-self.__universes_x_time[host]))
+        tmp["frame"] = self.__frame
+        #tmp["hosts"] = self.__hosts
+        tmp["uni"] = self.__univers_nr 
+        tmp["fps"] = self.__universes_fps[host]
+        self.__universes_info[host] = tmp
         if update_flag:
-            tmp = {}
-            tmp["flag"] =update_flag
-            tmp["flagx"] = self.__universes_flag[host] 
-            tmp["fpsx"] = int(self.__universes_x_frames[host] / (time.time()-self.__universes_x_time[host]))
-            tmp["frame"] = self.__frame
-            #tmp["hosts"] = self.__hosts
-            tmp["uni"] = self.__univers_nr 
-            tmp["fps"] = self.__universes_fps[host]
-            self.__universes_info[host] = tmp
-
             #print( "UPDATE HOST:",host, update_flag,"UNIV:",self.__univers_nr)
-            self.__universes_dmx[host] = dmxframe
+            self.__universes_dmx[host] = dmx # dmxframe
             self.__universes_timer[host] = update_matrix
 
     def get(self,host=""):
 
-        dmx = [-1]*512
+        dmx = ["-"]*512
         timer = [0]*512
         #print( "H",self.__hosts,self.__univers_nr )
         if host and host in self.__hosts:
             return self.__universes_dmx[host]
 
-        for host in self.__hosts:
+        for host in self.__hosts: # <- LTP 
             #print( host )
             dmxA   = self.__universes_dmx[host]
             timerA = self.__universes_timer[host]
@@ -212,9 +225,28 @@ class xUniversum():
                     timer[i] = timerA[i]
                     dmx[i] = dmxA[i]
         return dmx
+    def get_mtx(self,host=""):
+
+        dmx = ["--"]*512
+        timer = [0]*512
+        hosts = self.__hosts[:]
+        hosts.sort()
+        for x,host in enumerate(hosts): # <- LTP 
+            #print( host )
+            dmxA   = self.__universes_dmx[host]
+            timerA = self.__universes_timer[host]
+            for i,t in enumerate(timerA):
+                if timer[i] < t:
+                    timer[i] = timerA[i]
+                    dmx[i] = x #dmxA[i]
+        return dmx
+
     def info(self):
         return self.__universes_info
-        
+    def hosts(self):
+        x = self.__universes_dmx.keys()
+        x.sort()
+        return x
 
 
 class Hosts():
@@ -226,8 +258,24 @@ class Hosts():
         #dmxframe[15] = 6
         #self.update(host="333.333.333.333",univ=8,dmxframe=dmxframe)
 
-    def get(self,host="", univ=0):
+    def get_mtx(self,host="", univ=""):
+        return self.__universes[str(univ)].get_mtx(host)
+    def get(self,host="", univ=""):
         return self.__universes[str(univ)].get(host)
+    def hosts(self):
+        hosts = []
+        for univ in  self.__universes:
+            x=self.__universes[univ].hosts()
+            for y in x:
+                #x=univ.hosts()
+                if y not in hosts:
+                    hosts.append(y)
+        hosts.sort()
+        return hosts
+    def univs(self):
+        x=self.__universes.keys()
+        x.sort()
+        return x
 
     def update(self,host,univ, dmxframe):
         #print( "update", host )
@@ -293,6 +341,50 @@ def unpack_art_dmx(data):
         #    pass
     return dmx
 
+class Pager(): #scroll thru list
+    def __init__(self):
+        self.data = []
+        self.index = 0
+        self.wrap = 0
+        self.maxindex = 0 
+    def append(self,val):
+        self.data.append(val)
+        self.check()
+
+    def set(self,nr):
+        self.index = nr
+        self.check()
+    def get(self):
+        self.check()
+        if self.data:
+             return self.data[self.index]
+
+    def next(self):
+        self.index += 1
+        self.check(flag=1)
+    def prev(self):
+        self.index -= 1
+        self.check(flag=1)
+    def check(self,flag=0):
+        if flag:
+            if self.maxindex and self.maxindex <= len(self.data):
+                max = self.maxindex
+            else:
+                max = len(self.data)
+        else:
+            max = len(self.data)
+
+
+        if self.wrap:
+            if self.index >= max:
+                self.index = 0
+            elif self.index < 0:
+                self.index = max-1
+        else:
+            if self.index >= max:
+                self.index = max-1
+            elif self.index < 0:
+                self.index = 0
 
 
 
@@ -331,11 +423,11 @@ if __name__ == "__main__":
     fpst =int(time.time())
     head= "XXX"
     
-    
+    dmx_ch_buffer = []
     
     screen=Curses()
-    screen.init()
-
+    #screen.init()
+    screen.exit()
     if 0: #testunivers
         while 1:
             
@@ -350,8 +442,17 @@ if __name__ == "__main__":
     univ_heads = [ ["none"]*2 ]*16
     ttime = time.time()
     counter = 0
-    oohosts=[]
-    oshost="xxx"
+    cmd=[]
+    mode=""
+    sel_host=Pager()
+    sel_host.wrap=1
+    sel_univ=Pager()
+    sel_univ.wrap=1
+    sel_mode=Pager()
+    sel_mode.wrap=1
+    sel_mode.data = ["dmx","ltp","mtx","main"] # mtx = matrix
+    sel_mode.maxindex = len( sel_mode.data )-1
+
     try:
         while 1:
             dmx = univ_dmx[univers]
@@ -374,57 +475,110 @@ if __name__ == "__main__":
                 dmx = unpack_art_dmx(data)
 
                 ohost.update(host,head_uni,dmx)     
+                #screen.exit()
+                if 0:# len(dmx):
+                    print( host)
+                    print( head_uni, data[:30] )#dmx[:10]  )    
+                    print( head_uni, dmx[:10]  )    
+
+            #continue
+            # input command buffer
+            screen.read()
+            inp2=screen.inp()
+            if "q" == inp2:
+                inp2=""
+                screen.exit()
+                sys.exit()
+            elif "?" == inp2:
+                mode = "?"
+            elif "," == inp2:
+                sel_mode.next()
+                inp2=""
+            elif ";" == inp2:
+                sel_mode.prev()
+                inp2=""
+            elif "." == inp2:
+                sel_univ.next()
+                inp2=""
+            elif ":" == inp2:
+                sel_univ.prev()
+                inp2=""
+            elif "-" == inp2:
+                sel_host.next()
+                inp2=""
+            elif "_" == inp2:
+                sel_host.prev()
+                inp2=""
+            elif "#" == inp2:
+                if "main" in sel_mode.data:
+                    x = sel_mode.data.index( "main")
+                    sel_mode.index = x
+                    sel_mode.check()
+                inp2=""
+
+            if inp2 == "\n":
+                cmd2 = "".join( cmd).split()
+                cmd=[]
+                if len(cmd2) < 2:
+                    pass
+                elif "C^" in cmd2:
+                    screen.exit()
+                    sys.exit()
+                elif "univ" in cmd2 or "u" == cmd2[0]:
+                    x=""
+                    if cmd2[1] in sel_univ.data:
+                        x = sel_univ.data.index( cmd2[1])
+                        sel_univ.index = x
+                        sel_univ.check()
+                elif "mode" in cmd2 or "m" == cmd2[0]:
+                    if cmd2[1] in sel_mode.data:
+                        x = sel_mode.data.index( cmd2[1])
+                        sel_mode.index = x
+                        sel_mode.check()
+
+                elif "host" in cmd2 or "h" == cmd2[0]:
+                    try:
+                        x=int(cmd2[1]) 
+                        sel_host.set(x)
+                    except:
+                        pass
+            else:
+                cmd.append(inp2)
+
+
+
+            sel_univ.data = ohost.univs()
+            sel_univ.check()
+            sel_host.data = ohost.hosts()
+            sel_host.check()
+            host  = sel_host.get()
+            univ2 = sel_univ.get()
+
+            mode  = sel_mode.get()
 
-
-                
             if time.time()-0.2 > ttime:
-                inp2=screen.inp()
-                if inp2 in "0123456789" and inp2:
-                    univ2 = str(inp2)
-                if inp2 in "asdfghjkl" and inp2:
-                    oshost = "asdfghjkl".index(inp2)
-                    if len(oohosts) > oshost:
-                        oshost = oohosts[oshost]
-                elif inp2:
-                    inp=inp2
-
-                lines = ["MENUE:"+str(inp)+" univ:"+str(univ2)+ " host:"+str(oshost)]
-                a=inp
-                if a=="q":
-                    ttime = time.time()
-                    x=ohost.get(univ=head_uni)
-                    #lines = []
-                    info=ohost.info()
-                    jinfo = ""
-                    for i in info:
-                        xl = json.dumps(i) + "======= "
-                        lines.append( xl )
-                        for j in info[i]:
-                            lines.append( " " + json.dumps([j,""]) )
-                            if j not in oohosts:
-                                oohosts.append(j)
-                            for k in info[i][j]:
-                                #lines.append( "   " + json.dumps( info[i][j]) )
-                                lines.append( "   "+str(k).ljust(5," ")+": " + json.dumps( info[i][j][k]) )
-                            
-                    lines.append(" ")
-                    lines.append(str(ttime))
 
-                    screen.draw_lines(lines)
-                elif a=="w":
+                lines = [ ]
+                lines.append(" CMD:" + "".join(cmd) )
+                if mode=="help" or  mode=="?":
+                    lines.append("HILFE[h]: " )
+                    lines.append("MODE [m]: inp, in2 in1 " )
+                    lines.append("UNIV [u]: 0-16  " )
+                    lines.append(" " )
+                    lines.append("HILFE " )
+                elif mode=="dmx" or mode == "DMX":
                     ttime = time.time()
-                    host = oshost
-                    dmx=ohost.get(host,univ=head_uni)
-                    #lines = []
+                    dmx=ohost.get(host,univ=univ2)#univ=head_uni)
                     info=ohost.info()
-                    lines.append("frame "+str(info.keys()) )
-                    # print( str(info.keys() )) 
+                    #lines.append("frame "+str(info.keys()) )
 
                     if univ2 in info:
                         if host in info[univ2] :
                             lines.append("frame "+str(info[univ2][host]["frame"]))
                             x=""
                             for i,v in enumerate(dmx):
+                                if v == 0:
+                                    v = "+"
                                 x += str(v).rjust(4," ")
                                 if (i+1) % 20 == 0:# and i:
                                     lines.append(x)
@@ -435,15 +589,12 @@ if __name__ == "__main__":
                             lines.append(" ")
                             lines.append(str(ttime))
 
-                    screen.draw_lines(lines)
-                elif a=="e":
+                    #screen.draw_lines(lines)
+                elif mode=="mtx":
                     ttime = time.time()
-                    host = "10.10.10.5"
-                    dmx=ohost.get(host,univ=head_uni)
-                    #lines = []
+                    dmx=ohost.get_mtx(host,univ=univ2)#univ=head_uni)
                     info=ohost.info()
-                    lines.append("frame "+str(info.keys()) )
-                    #print( str(info.keys() )) 
+                    #lines.append("frame "+str(info.keys()) )
 
                     if univ2 in info:
                         if host in info[univ2] :
@@ -460,43 +611,66 @@ if __name__ == "__main__":
                             lines.append(" ")
                             lines.append(str(ttime))
 
-                    screen.draw_lines(lines)
-                elif a=="r":
+                    #screen.draw_lines(lines)
+                elif mode=="ltp" or mode=="LTP":
                     ttime = time.time()
-                    host = "10.10.10.3"
-                    dmx=ohost.get(univ=head_uni)
-                    #lines = []
+                    dmx=ohost.get(univ=univ2)#head_uni)
+                    #univ2=""
+                    host=""
                     info=ohost.info()
-                    lines.append("+++")
                     lines.append("frame "+str(info.keys()) )
-                    #print( str(info.keys() )) 
-
 
-                    if univ2 in info:
-                        if host in info[univ2] :
-                            lines.append("frame "+str(info[univ2][host]["frame"]))
+                    x=""
+                    for i,v in enumerate(dmx):
+                        x += str(v).rjust(4," ")
+                        if (i+1) % 20 == 0:
+                            lines.append(x)
                             x=""
-                            for i,v in enumerate(dmx):
-                                x += str(v).rjust(4," ")
-                                if (i+1) % 20 == 0:
-                                    lines.append(x)
-                                    x=""
-                            if x:
-                                lines.append(x)
-                                    
-                            lines.append(" ")
-                            lines.append(str(ttime))
+                    if x:
+                        lines.append(x)
+                            
+                    lines.append(" ")
+                    lines.append(str(ttime))
 
-                    screen.draw_lines(lines)
+                    #screen.draw_lines(lines)
                 else:
+                    ttime = time.time()
+                    x=ohost.get(univ=head_uni)
                     #lines = []
-                    lines.append(" NO MENUE SELECTED CHOOS 1-9  " )
-                    lines.append("time "+str(time.time() ) )
-                    screen.draw_lines(lines)
-                    time.sleep(.1)
+                    host=""
+                    univ2=""
+                    info=ohost.info()
+                    jinfo = ""
+                    for i in info:
+                        xl = json.dumps(i) + "======= "
+                        lines.append( xl )
+                        for j in info[i]:
+                            lines.append( " " + json.dumps([j,""]) )
+                            if j not in sel_host.data:
+                                pass#sel_host.append(j)
+                            for k in info[i][j]:
+                                #lines.append( "   " + json.dumps( info[i][j]) )
+                                lines.append( "   "+str(k).ljust(5," ")+": " + json.dumps( info[i][j][k]) )
+                            
+                    lines.append(" ")
+                    lines.append(str(ttime))
+
+                    #screen.draw_lines(lines)
+                tmp = ""
+                tmp += " mode:"+(str(mode).ljust(10," "))
+                tmp += " univ:"+str(sel_univ.index)+":"+(str(univ2).ljust(10," "))
+                tmp += " host:"+str(sel_host.index)+":"+(str(host).ljust(10," "))
+                lines.insert(0,tmp)
+
+                tmp = ""
+                tmp += " univ:"+ (str(sel_univ.data))#.ljust(20," "))
+                tmp += " list:"+ (str(sel_host.data))#.ljust(20," "))
+                lines.insert(0,tmp)
+                screen.draw_lines(lines)
             time.sleep(.001)
     finally:
         screen.exit()
+        print( sel_host.index,sel_host.data)