Browse Source

fix: python2 python3 bug's

micha 2 years ago
parent
commit
ca2ea4da60
3 changed files with 182 additions and 67 deletions
  1. 2 0
      tool/mini-scan.py
  2. 113 31
      tool/nodescan_v6_2.py
  3. 67 36
      tool/tk-nodescan_v7.3.py

+ 2 - 0
tool/mini-scan.py

@@ -25,6 +25,7 @@ def ArtNet_poll(ip,port=6454):
 
 
 def ArtNet_decode_pollreplay(data):
+
     debug = 1
     node = {}
     if len(data) >= 10: #min opcode
@@ -36,6 +37,7 @@ def ArtNet_decode_pollreplay(data):
             if len(data) >= 207: #Mal
                 print("decode",data[:13])           
                 if debug:print("-----------------------------------------")
+                print("===================================================================-")
                 if debug:print([opcode] ,"OpPollReplay")
                 _ip = []
                 print(data[10])

+ 113 - 31
tool/nodescan_v6_2.py

@@ -158,7 +158,7 @@ def reciveBounce(timeout=10):
         if data:
             #print(addr)
             
-            print(data)
+            print("rBounte:",data)
             print()
         if time.time() > start+timeout:
             print("timeout stopping reciveBounce ")
@@ -205,7 +205,7 @@ class ArtNetNodes():
         #for i in add_node:
         #    print(i,[add_node[i]])
         #print()
-        print("add",add_node)
+        #print("add",add_node)
         try:
             self.__lock.acquire()
             update_node = 0
@@ -231,7 +231,9 @@ class ArtNetNodes():
                     update_node = 0
                     for i in add_node:
                         UPDATECOUNTER = node["UPDATECOUNTER"]                    
-                            
+                        #print("update i:",i,add_node[i])
+                        if i not in node:    
+                            node[i] = ""
                         if node[i] != add_node[i]:
                             node_match = 0
                             update_node += 1
@@ -250,22 +252,23 @@ class ArtNetNodes():
                         print("UPDATE NODE".ljust(16," "),info)
                         
                     else:
-                        print("NODE NOT CHANGE".ljust(16," "),info)
+                        #print("NODE NOT CHANGE".ljust(16," "),info)
                         node["REFRESHSTAMP"] = time.time()
                         update_node = 1
             print("x-node:",update_node,add_node)                
             if not update_node: # ADD NEW NODE
                 node = add_node
-                print("add_node",node)
-                node["BOOT"] = BOOT
-                info = node["MAC"],node["IP"].ljust(16," "),[node["SwIn"],node["SwOut"],node["PortTypes"]]
-                
-                node["UPDATECOUNTER"] = 1
-                node["REFRESHSTAMP"] = time.time()
-                node["UPDATESTAMP"] = time.time()
-                print("ADD NEW NODE".ljust(16," "),node["UPDATECOUNTER"],info)
-                self.__tick += 1
-                self.__nodes += [node]
+                if node:
+                    print("add_node",node)
+                    node["BOOT"] = BOOT
+                    info = node["MAC"],node["IP"].ljust(16," "),[node["SwIn"],node["SwOut"],node["PortTypes"]]
+                    
+                    node["UPDATECOUNTER"] = 1
+                    node["REFRESHSTAMP"] = time.time()
+                    node["UPDATESTAMP"] = time.time()
+                    print("ADD NEW NODE".ljust(16," "),node["UPDATECOUNTER"],info)
+                    self.__tick += 1
+                    self.__nodes += [node]
                   
             
         finally:
@@ -281,8 +284,11 @@ class ArtNetNodes():
     def get(self):
         self.__lock.acquire()
         out = []
+        #out = {}
         if self.__nodes:
             out = copy.deepcopy(self.__nodes)                
+            #for node in self.__nodes:
+            #    out[node["MAC"]] = node
         self.__lock.release()
         return out
 
@@ -292,9 +298,9 @@ class ArtNetNodes():
         while 1:
             data, addr = sock.recvfrom(500)
             new_node = ArtNet_decode_pollreplay( data )            
-            print("rvc loop",addr)
+            #print("rvc loop",addr)
             if new_node:
-                print("rcv",new_node)
+                #print("rcv 333",new_node)
                 self.add(new_node)
             time.sleep(0.001)
         print("-- NODE SCAN STOP ---")
@@ -306,10 +312,12 @@ class ArtNetNodes():
         poll()
         
 Reciver = ArtNetNodes
-    
+
+
 
 def ArtNet_decode_pollreplay(data):
-    debug = 1
+
+    debug = 0
     node = {}
     if len(data) >= 10: #min opcode
     
@@ -318,11 +326,12 @@ def ArtNet_decode_pollreplay(data):
         #if opcode != struct.pack("<H",0x5000): #OpPollReplay
         if opcode == struct.pack("<H",0x2100): #OpPollReplay
             if len(data) >= 207: #Mal
+                #if debug:print("-----------------------------------------")
+                print("===================================================================-")
                 print("decode",data[:13])           
-                if debug:print("-----------------------------------------")
                 if debug:print([opcode] ,"OpPollReplay")
                 _ip = []
-                print(data[10])
+                #print("data[10]",data[10])
                 _ip.append( data[10] )
                 _ip.append( data[11] )
                 _ip.append( data[12] )
@@ -358,6 +367,74 @@ def ArtNet_decode_pollreplay(data):
                 node["status"] = stat
                 if debug:print("Status1 ",[stat])
                 esta = data[24:25+1]
+                node["esta"] = esta
+                if debug:print("esta Manuf",[esta])
+                
+                
+                sname = data[26:26+17]
+                #if debug:print(len(sname) #17+1)
+                sname = sname.strip(b"\x00")
+                node["sname"] = sname
+                
+                lname = data[44:44+43]
+                #if debug:print(len(lname) #43+1)
+                lname = lname.strip(b"\x00")
+                node["lname"] = lname
+                
+                NodeReport = data[108:108+20]
+                NodeReport = NodeReport.strip(b"\x00")
+                #if debug:print("Node",node_nr,addr)
+                if debug:print("43r:",[sname,lname,NodeReport])
+                
+                NumPort =  data[173] 
+                node["NumPort"] = NumPort
+                if debug:print("NumPort",[NumPort])
+                
+                PortTypes = data[174:174+4]
+                node["PortTypes"] = PortTypes
+                if debug:print("PortTypes",[PortTypes])
+                
+                GoodInput = data[178:178+4]
+                node["GoodInput"] = GoodInput
+                if debug:print("GoodInput",[GoodInput])
+                GoodOutput = data[182:182+4]
+                node["GoodOutput"] = GoodOutput
+                if debug:print("GoodOutput",[GoodOutput])
+                
+                SwIn = data[186:186+4]
+                node["SwIn"] = SwIn
+                if debug:print("SwIn",[SwIn])
+                
+                SwOut = data[190:190+4]
+                node["SwOut"] = SwOut
+                if debug:print("SwOut",[SwOut])
+                
+                msg = data[108:108+40]
+                node["MSG"] = msg.replace(b"\x00",b"")#.decode(errors="ignore")
+                if debug:print("MSG",[msg])
+                
+                
+                MAC = data[201:201+6]
+                _MAC = []
+                for x in MAC:
+                    #x = hex(ord(x))[2:]
+                    x = hex(x)[2:]
+                    x = x.rjust(2,"0")
+                    _MAC.append(x)
+                #hex(ord("\xf9"))[2:]
+                if debug:print("MAC",[":".join(_MAC)])
+                node["MAC"] = ":".join(_MAC)
+                
+                #node_nr += 1
+                #if debug:print([addr,data])
+                #print()
+
+                for k,v in node.items():
+                    if type(node[k]) is bytes:
+                        node[k] = v.decode(errors="ignore")
+            else:
+                print(opcode, len(data))
+    return node
 
 def set_ip4(cur_ip=(2,0,0,91),new_ip=(2,0,0,201),new_netmask=(255,0,0,0)):
     
@@ -489,18 +566,19 @@ def pack_ip(_ip):
     return data
 
 def send_node_cmd(ip="",ip2="",cmd=""):
-    print()
     print()
     port = 7600
     data = []
+    print("send_node_cmd",ip,ip2,cmd,port)
     
-    print("OLD NODE _ip:", ip)
-    data = pack_ip(ip)
+    data = pack_ip(ip[:])
     
-    if ip2:
-        ip = ".".join(str(x) for x in ip2)
-    else:
-        ip = ".".join(str(x) for x in ip)
+    print("ip",ip,ip2)
+    if len(ip2) == 4:
+        ip = ip2
+    if len(ip) == 4:
+       ip = ".".join(map(str,ip))
+
     print("send to ip:", ip)
     data2=""
     if not cmd:
@@ -511,7 +589,11 @@ def send_node_cmd(ip="",ip2="",cmd=""):
         data2 = 'CMD DMX=OUT '
         data2 = 'CMD DMX=PIN '
 
-    data2 = bytes(cmd,"ascii")
+    if type(cmd) == bytes:
+        data2 = cmd
+    else:
+        data2 = bytes(str(cmd),"ascii",errors="ignore")
+
     print([data2],type(data2)    )
     data2 = data2.ljust(20,b" ") + b"".join(data)
 
@@ -553,8 +635,8 @@ def node_cmd_recive():
 #send_node_cmd(ip=(2,0,0,201),ip2=(2,255,255,255),cmd="DMX OUT STORE")
 #send_node_cmd(ip=(2,0,0,255),ip2=(2,0,0,201),cmd="DMX OUT STORE")
 #send_node_cmd(ip=(2,0,0,201),ip2=(2,0,0,201),cmd="DMX OUT STORE")
-send_node_cmd(ip=(2,0,0,201),ip2=(255,255,255,255),cmd="DMX OUT STORE")
-send_node_cmd(ip=(255,255,255,255),ip2=(255,255,255,255),cmd="DMX OUT STORE")
+#send_node_cmd(ip=(2,0,0,201),ip2=(255,255,255,255),cmd="DMX OUT STORE")
+#send_node_cmd(ip=(255,255,255,255),ip2=(255,255,255,255),cmd="DMX OUT STORE")
 #exit()
 #   
 if __name__ == "__main__":        
@@ -577,7 +659,7 @@ if __name__ == "__main__":
             pass
             
         
-            print("node count",len(nodes))
+            print("node count",len(nodes),rx.tick(),2 )
             #for i in nodes:
             #print(i)
         z += 1

+ 67 - 36
tool/tk-nodescan_v7.3.py

@@ -77,7 +77,7 @@ def clear_node():
 def poll(delay=1):
     global old_tick
     
-    #clear_entry_ip()
+    clear_entry_ip()
     clear_node()
     time.sleep(delay)
     nodscaner.poll()
@@ -87,7 +87,8 @@ def poll(delay=1):
 def clear(event= None):
     global rx
     rx.clear()
-    poll()
+    clear_node()
+    #poll()
     
 def poll_loop(sleep):
     if sleep < 1:
@@ -109,24 +110,36 @@ def _scan():
     while 1:
         nodes = rx.get()
         new_tick = rx.tick()
-        #print("tick",new_tick)
+
         if new_tick == old_tick:
-            pass
             continue
+
         old_tick = new_tick
-        print("node",nodes)
+        #print("node",nodes)
         if nodes:
             li_node_scroll = li_nodes.yview()
             
-            clear_node()
+            #clear_node()
 
             #li_nodes.delete(0,"end")
-            print("yea",len(nodes))
+            #print("yea",len(nodes))
             node_nr = 1
+            nodesB = {}
             for node in nodes:
-                #print(node)
-                #try:
+                k = node["MAC"]
+                nodesB[k] = node
+            print("k",nodesB.keys())
+            #for node in nodes:
+            #for k,node in nodesB.items():
+            k_sort = list(nodesB.keys())
+            k_sort.sort()
+            print("k sort",k_sort)
+            for k in k_sort:
+                node = nodesB[k]
+
                 li_nodes.insert("end",str(node_nr).rjust(3," ") +" "+ node["lname"])
+                bg = "lightgrey"
+                color = li_nodes.itemconfig("end", bg=bg)
                 ip = str(node_nr).rjust(3," ") +" "+ node["IP"]
                 bg = ""
                 if node["PortTypes"][0] == "@":
@@ -143,7 +156,7 @@ def _scan():
                 if bg:
                     color = li_nodes.itemconfig("end", bg=bg)
                 
-                inout = " UNIVERS OUT="+ str(ord(node["SwOut"][0])+1)+" IN="+ str(ord(node["SwIn"][0])+1)
+                inout = " UNIVERS OUT="+ str(ord(node["SwOut"][0]))+" IN="+ str(ord(node["SwIn"][0]))
                 li_nodes.insert("end",str(node_nr).rjust(3," ") + inout)
                 
                 li_nodes.insert("end",str(node_nr).rjust(3," ") +" "+ node["MAC"])
@@ -161,10 +174,10 @@ def _scan():
                 timeline ="  BOOT:%0.1f"% BOOT
                 li_nodes.insert("end",str(node_nr).rjust(3," ") +timeline +" sec" )
                 bg = ""
-                if REFRESHSTAMP > 5 :
-                    bg="red"
-                else:
-                    bg="lightgreen"
+                #if REFRESHSTAMP > 5 :
+                #    bg="red"
+                #else:
+                #    bg="lightgreen"
                 if bg:
                     li_nodes.itemconfig("end", bg=bg)
                 #li_nodes.insert("end",str(node_nr).rjust(3," ") 
@@ -201,15 +214,18 @@ def send_none(event=None):
     pass
     
 def send_mac(event=None):
-    new_mac = "CMD MAC6 " + struct.pack("<B",(int(e_mac2.get(),16)))
+    #new_mac = "CMD MAC6 " + hex(e_mac2.get()) #)
+    #new_mac = "CMD MAC6 " + struct.pack("<B",(int(e_mac2.get(),16))).decode()
+    new_mac = b"CMD MAC6 " + struct.pack("<B",(int(e_mac2.get(),16)))
     
     a = e_ip.get().replace("[","").replace("]","")
     cur_ip = []    
+
     for i in a.split(","):
         cur_ip +=[int(i)]
     print("SEND MAC:",cur_ip,new_mac)
-    nodscaner.send_node_cmd(cur_ip,new_mac)
-    poll(1.5)
+    nodscaner.send_node_cmd(cur_ip,cmd=new_mac)
+    #poll(1.5)
 
 def send_dmx_store(event=None):
     cmd = "CMD DMX STORE "
@@ -249,7 +265,7 @@ def _send_cmd(event=None,cmd=""):
     cmd = cmd[:-1] #.append(value)
     cmd.append(value)
     print("_send_cmd:",cmd)
-    cmd=" ".join(cmd )
+    cmd=" ".join(map(str,cmd) )
     a = e_ip.get().replace("[","").replace("]","")
     cur_ip = []
     sep = "xx"
@@ -261,7 +277,7 @@ def _send_cmd(event=None,cmd=""):
         cur_ip +=[int(i)]
     print("SEND:",cur_ip,cmd)
     nodscaner.send_node_cmd(cur_ip,cmd)
-    poll(1.5)
+    #poll(1.5)
 
     
 def set_ip(event=None):
@@ -357,7 +373,8 @@ eframe1.pack(side="left",expand=0,fill="y")
 line_frame = Tkinter.Frame(eframe)
 line_frame.pack(side="top",expand=0,fill="x")
 Tkinter.Label(line_frame,text="OLD IP:",font=font3,width=6).pack(side="left",expand=0,fill="y")
-e_ip = Tkinter.Entry(line_frame,font=font20)
+e_ip = Tkinter.Entry(line_frame,font=font20,width=13)
+e_ip["bg"] = "lightgrey"
 e_ip.pack(side="left")
 #b_scan = Tkinter.Button(line_frame,width=14,font=font3)
 #b_scan.pack(side="left",expand=1)
@@ -367,7 +384,7 @@ line_frame = Tkinter.Frame(eframe)
 line_frame.pack(side="top",expand=0,fill="x")
 e_ip_label = Tkinter.Label(line_frame,text=" IP:",font=font3,width=6)
 e_ip_label.pack(side="left",expand=0,fill="y")
-e_ip_new = Tkinter.Entry(line_frame,font=font20)
+e_ip_new = Tkinter.Entry(line_frame,font=font20,width=13)
 e_ip_new.bind("<Return>", set_ip )
 e_ip_new.bind("<KP_Enter>", set_ip)
 #e_ip_new.bind("<Tab>", update_name)
@@ -381,10 +398,11 @@ line_frame = Tkinter.Frame(eframe)
 line_frame.pack(side="top",expand=0,fill="x")
 variable = Tkinter.StringVar(root)
 variable.set("255.0.0.0") # default value
-Tkinter.Label(line_frame,text="IPMASK",font=font3,width=6).pack(side="left",expand=0,fill="y")
-e_mask_new = Tkinter.OptionMenu(line_frame, variable,"255.255.255.0","255.0.0.0")
-e_mask_new.configure(font=("Helvetica", 20))
-e_mask_new.configure(width=17)
+Tkinter.Label(line_frame,text="MASK",font=font3,width=6).pack(side="left",expand=0,fill="y")
+e_mask_new = Tkinter.OptionMenu(line_frame, variable,"255.255.255.0","255.0.0.0") #,width=10)
+e_mask_new.configure(font=("Helvetica", 22))
+e_mask_new.configure(width=10)
+e_mask_new["bg"] = "#fff"
 #heigh=1,font=("Helvetica", 20)
 e_mask_new.pack(side="left")
 #e_mask_new.insert("end","255.0.0.0")
@@ -397,8 +415,10 @@ b_scan.pack(side="left",expand=0)
 line_frame = Tkinter.Frame(eframe)
 line_frame.pack(side="top",expand=0,fill="x")
 Tkinter.Label(line_frame,text="MAC:",font=font3,width=6).pack(side="left",expand=0,fill="y")
-e_mac = Tkinter.Entry(line_frame,width=16,font=font20)
+e_mac = Tkinter.Entry(line_frame,width=13,font=font20)
 e_mac.pack(side="left")
+e_mac["bg"] = "lightgrey"
+
 e_mac2 = Tkinter.Entry(line_frame,width=3,font=font20)
 e_mac2.pack(side="left")
 e_mac2.bind("<Return>", send_mac )
@@ -509,7 +529,11 @@ def read_cmd_buf():
             msg = str(nodscaner.node_cmd_buf_list)
             print("read_cmd_buf msg",msg)
             nodscaner.node_cmd_buf_list = []
-            b_scan.insert("end",str(time.time())+"\n")
+
+            stamp = str(time.time())+"\n"
+            stamp = time.strftime("%Y-%m-%d %X\n")
+
+            b_scan.insert("end",stamp)
             b_scan.insert("end", msg +"\n")
             
             b_scan.see("end")
@@ -518,30 +542,37 @@ def read_cmd_buf():
 #thread.start_new_thread(nodscaner.node_cmd_recive, () )
 #thread.start_new_thread(read_cmd_buf, () )
 
+def _update():
+    while 1:
+        time.sleep(10)
+        root.update_idletasks()
+
 def X():
     thread.start_new_thread(nodscaner.node_cmd_recive, () )
     thread.start_new_thread(read_cmd_buf, () )
+    thread.start_new_thread(_update, () )
     #thread.start_new_thread(node_cmd_recive, () )
     #send_node_cmd(ip=(2,0,0,91),cmd="DMX OUT STORE")
-    send_node_cmd(ip=(2,255,255,255),cmd="CMD GT ")
+    nodscaner.send_node_cmd(ip=(2,255,255,255),cmd="CMD GT ")
+    #nodscaner.send_node_cmd(ip,cmd=cmd)
    
 
-    rx = ArtNetNodes()
-    rx.loop()
+    rx = nodscaner.ArtNetNodes()
+    #rx.loop()
     z = 0
+    poll()
     while 1:
         
         nodes = rx.get()
         #print(len(nodes))
         
         if z % 10 == 0:
-            print()
             pass
-            
-        
-            print("node count",len(nodes))
-            #for i in nodes:
-            #print(i)
+            #print("----")
+            #pass#print("node count",len(nodes),rx.tick())
+            #for node in nodes:
+            #    print(node["MAC"],node["lname"])
+
         z += 1
         time.sleep(0.2)