tk-nodescan_v7.3.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. #! /usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. """
  4. This file is part of librelight.
  5. librelight is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 2 of the License, or
  8. (at your option) any later version.
  9. librelight is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with librelight. If not, see <http://www.gnu.org/licenses/>.
  15. (c) 2012 micha.rathfelder@gmail.com
  16. """
  17. import time
  18. import struct
  19. import sys
  20. import tkinter as Tkinter
  21. import _thread as thread
  22. import nodescan_v6_2 as nodscaner
  23. title = "TK-ArtNet-Nodscaner"
  24. sys.stdout.write("\x1b]2;"+title+"\x07")
  25. node_list = []
  26. def load(event):
  27. sel = int( li_nodes.curselection()[0] )
  28. print("li_nodes.get")
  29. try:
  30. sel = int(li_nodes.get(sel).split()[0])
  31. print(sel)
  32. except:
  33. return 0
  34. sel -= 1
  35. node_list[sel]
  36. clear_entry_ip()
  37. e_ip.configure(state='normal')
  38. e_ip.insert("end",node_list[sel]["IP"].replace("[","").replace("]",""))
  39. #e_ip.configure(state='readonly')
  40. e_ip_new.insert("end",node_list[sel]["IP"].replace("[","").replace("]",""))
  41. e_mac.delete("0","end")
  42. e_mac.insert("end",node_list[sel]["MAC"].replace("[","").replace("]",""))
  43. e_mac2.delete("0","end")
  44. e_mac2.insert("end",node_list[sel]["MAC"].split(":")[-1])
  45. #print(dir(event))
  46. #print(node_list)
  47. #for i in node_list:
  48. # print(i)
  49. def clear_entry_ip():
  50. e_ip.configure(state='normal')
  51. e_ip.delete("0","end")
  52. e_ip.configure(state='readonly')
  53. e_ip_new.delete("0","end")
  54. def clear_node():
  55. global node_list
  56. li_nodes.delete("0","end")
  57. node_list = []
  58. li_nodes.delete("0","end")
  59. def poll(delay=1):
  60. global old_tick
  61. #clear_entry_ip()
  62. clear_node()
  63. time.sleep(delay)
  64. nodscaner.poll()
  65. time.sleep(0.5)
  66. old_tick = 0
  67. def clear(event= None):
  68. global rx
  69. rx.clear()
  70. poll()
  71. def poll_loop(sleep):
  72. if sleep < 1:
  73. sleep = 1
  74. time.sleep(sleep)
  75. while 1:
  76. poll()
  77. time.sleep(sleep)
  78. old_tick = 0
  79. rx = nodscaner.ArtNetNodes()
  80. def _scan():
  81. global rx,node_list,old_tick,Scrollbar
  82. rx.loop()
  83. print("get node from cache " )
  84. li_nodes.insert("end",str("----"))
  85. while 1:
  86. nodes = rx.get()
  87. new_tick = rx.tick()
  88. #print("tick",new_tick)
  89. if new_tick == old_tick:
  90. pass
  91. continue
  92. old_tick = new_tick
  93. print("node",nodes)
  94. if nodes:
  95. li_node_scroll = li_nodes.yview()
  96. clear_node()
  97. #li_nodes.delete(0,"end")
  98. print("yea",len(nodes))
  99. node_nr = 1
  100. for node in nodes:
  101. #print(node)
  102. #try:
  103. li_nodes.insert("end",str(node_nr).rjust(3," ") +" "+ node["lname"])
  104. ip = str(node_nr).rjust(3," ") +" "+ node["IP"]
  105. bg = ""
  106. if node["PortTypes"][0] == "@":
  107. ip += " DMX-in"
  108. bg ="yellow"
  109. else:
  110. ip += " DMX-out"
  111. bg ="lightgreen"
  112. if bg:
  113. color = li_nodes.itemconfig("end", bg=bg)
  114. li_nodes.insert("end",str(node_nr).rjust(3," ") +" short Name:"+ node["sname"])
  115. li_nodes.insert("end",ip)
  116. if bg:
  117. color = li_nodes.itemconfig("end", bg=bg)
  118. inout = " UNIVERS OUT="+ str(ord(node["SwOut"][0])+1)+" IN="+ str(ord(node["SwIn"][0])+1)
  119. li_nodes.insert("end",str(node_nr).rjust(3," ") + inout)
  120. li_nodes.insert("end",str(node_nr).rjust(3," ") +" "+ node["MAC"])
  121. timeline = ""
  122. timeline += " LASTCHANGE:%0.1f"% (time.time()-float(node["UPDATESTAMP"]) )
  123. REFRESHSTAMP = time.time()-float(node["REFRESHSTAMP"])
  124. timeline +=" LASTPING:%0.1f"% REFRESHSTAMP
  125. li_nodes.insert("end",str(node_nr).rjust(3," ") +timeline )
  126. if node["BOOT"]:
  127. BOOT = time.time()-float(node["BOOT"])
  128. else:
  129. BOOT = 0
  130. timeline =" BOOT:%0.1f"% BOOT
  131. li_nodes.insert("end",str(node_nr).rjust(3," ") +timeline +" sec" )
  132. bg = ""
  133. if REFRESHSTAMP > 5 :
  134. bg="red"
  135. else:
  136. bg="lightgreen"
  137. if bg:
  138. li_nodes.itemconfig("end", bg=bg)
  139. #li_nodes.insert("end",str(node_nr).rjust(3," ")
  140. #li_nodes.insert("end","")
  141. li_nodes.insert("end","*"*60)
  142. #li_nodes.itemconfig("end", bg="brown")
  143. node_nr += 1
  144. node_list += [node]
  145. #Scrollbar.set('0', '0.1')
  146. print(li_node_scroll)
  147. #print(dir(li_nodes))
  148. #li_node_scroll = int(li_node_scroll[0])
  149. #li_nodes.yview_moveto(li_node_scroll)
  150. time.sleep(0.2)
  151. def get_new_ip(event=None):
  152. b = e_ip_new.get().replace("[","").replace("]","")
  153. return b
  154. def get_new_ip_str(event=None):
  155. x = get_new_ip()
  156. #x = x[1:-1]
  157. x = x.strip()
  158. #x = x.replace(",",".")
  159. x = x.replace(" ","")
  160. x = x.split(",")
  161. print( "get_new_ip_str",x)
  162. return x
  163. def send_none(event=None):
  164. pass
  165. def send_mac(event=None):
  166. new_mac = "CMD MAC6 " + struct.pack("<B",(int(e_mac2.get(),16)))
  167. a = e_ip.get().replace("[","").replace("]","")
  168. cur_ip = []
  169. for i in a.split(","):
  170. cur_ip +=[int(i)]
  171. print("SEND MAC:",cur_ip,new_mac)
  172. nodscaner.send_node_cmd(cur_ip,new_mac)
  173. poll(1.5)
  174. def send_dmx_store(event=None):
  175. cmd = "CMD DMX STORE "
  176. a = e_ip.get().replace("[","").replace("]","")
  177. cur_ip = []
  178. for i in a.split(","):
  179. cur_ip +=[int(i)]
  180. print("SEND:",cur_ip,cmd)
  181. nodscaner.send_node_cmd(cur_ip,cmd)
  182. poll(1.5)
  183. def send_cmd(event=None):
  184. cmd = e_cmd.get() #"CMD DMX STORE "
  185. _send_cmd(cmd=cmd)
  186. def send_cmd2(event=None):
  187. cmd = e_cmd2.get() #"CMD DMX STORE "
  188. _send_cmd(cmd=cmd)
  189. def send_cmd3(event=None):
  190. cmd = e_cmd3.get() #"CMD DMX STORE "
  191. _send_cmd(cmd=cmd)
  192. def send_cmd4(event=None):
  193. cmd = e_cmd4.get() #"CMD DMX STORE "
  194. _send_cmd(cmd=cmd)
  195. def send_cmd5(event=None):
  196. cmd = e_cmd5.get() #"CMD DMX STORE "
  197. _send_cmd(cmd=cmd)
  198. def _send_cmd(event=None,cmd=""):
  199. #cmd = e_cmd.get() #"CMD DMX STORE "
  200. cmd = cmd.split(" ")
  201. value = cmd[-1]
  202. try:
  203. value = struct.pack("<B",int(value))
  204. except:pass
  205. cmd = cmd[:-1] #.append(value)
  206. cmd.append(value)
  207. print("_send_cmd:",cmd)
  208. cmd=" ".join(cmd )
  209. a = e_ip.get().replace("[","").replace("]","")
  210. cur_ip = []
  211. sep = "xx"
  212. if "," in a:
  213. sep = ","
  214. if "." in a:
  215. sep = "."
  216. for i in a.split(sep):
  217. cur_ip +=[int(i)]
  218. print("SEND:",cur_ip,cmd)
  219. nodscaner.send_node_cmd(cur_ip,cmd)
  220. poll(1.5)
  221. def set_ip(event=None):
  222. print("SET NEW IP")
  223. cur_ip=(2,0,0,94)
  224. new_ip=(2,0,0,201)
  225. new_netmask=(255,0,0,0)
  226. a = e_ip.get().replace("[","").replace("]","")
  227. b = e_ip_new.get().replace("[","").replace("]","")
  228. c = variable.get() #e_mask_new.get()
  229. new_netmask = [] #c.split(".") #list(c)
  230. for i in c.split("."):
  231. new_netmask +=[int(i)]
  232. cur_ip = []
  233. for i in a.split(","):
  234. cur_ip +=[int(i)]
  235. new_ip = []
  236. for i in b.split(","):
  237. new_ip +=[int(i)]
  238. if new_ip == cur_ip:
  239. print("neu und als IP sind gleich" )
  240. return 0
  241. #cur_ip=(2,0,0,94)
  242. #new_ip=(2,0,0,201)
  243. print("new",[cur_ip, new_ip, new_netmask])
  244. print()
  245. nodscaner.set_ip4(cur_ip,new_ip, new_netmask)
  246. poll(1.5)
  247. def set_node_pin(evnet=None):
  248. cmd = "CMD DMX=PIN"
  249. ip = get_new_ip_str()
  250. print("ip",[ip])
  251. nodscaner.send_node_cmd(ip,cmd=cmd)
  252. poll(1.5)
  253. def set_node_in(evnet=None):
  254. cmd="CMD DMX=IN"
  255. ip = get_new_ip_str()
  256. nodscaner.send_node_cmd(ip,cmd=cmd)
  257. poll(1.5)
  258. def set_node_out(evnet=None):
  259. cmd="CMD DMX=OUT"
  260. ip = get_new_ip_str()
  261. nodscaner.send_node_cmd(ip,cmd=cmd)
  262. poll(1.5)
  263. root = Tkinter.Tk()
  264. #root.geometry("900x700+100+100")
  265. root.geometry("900x400+100+100")
  266. root.title( title)
  267. fframe = Tkinter.Frame(root)
  268. fframe.pack(side="top",expand=0,fill="x")
  269. cframe = Tkinter.Frame(root)
  270. cframe.pack(side="top",expand=1,fill="both")
  271. font1 = ("Helvetica", 8)
  272. font2 = ("Helvetica", 10)
  273. font3 = ("Helvetica", 16)
  274. font20 = font=("Helvetica", 20)
  275. b_scan = Tkinter.Button(fframe,text="ArtNetPoll",width=10,command=poll,font=font2)
  276. b_scan.pack(side="left",expand=0,fill="y")
  277. b_scan = Tkinter.Button(fframe,text="clear",width=10,command=clear,font=font2)
  278. b_scan.pack(side="left",expand=0,fill="y")
  279. scrollbar = Tkinter.Scrollbar(cframe)
  280. scrollbar.pack(side=Tkinter.RIGHT, fill="y")
  281. #pool = Tkinter.Listbox(root,selectmode="extended",exportselection=0)
  282. li_nodes = Tkinter.Listbox(cframe,exportselection=0,width=35,font=font1)
  283. li_nodes.pack(side="left",expand=0,fill="y")
  284. li_nodes.bind("<ButtonRelease-1>",load )
  285. li_nodes.config(yscrollcommand=scrollbar.set)
  286. scrollbar.config(command=li_nodes.yview)
  287. eframe = Tkinter.Frame(cframe)
  288. eframe.pack(side="left",expand=0,fill="y")
  289. eframe1 = Tkinter.Frame(cframe)
  290. eframe1.pack(side="left",expand=0,fill="y")
  291. # ----------------------------------------------
  292. line_frame = Tkinter.Frame(eframe)
  293. line_frame.pack(side="top",expand=0,fill="x")
  294. Tkinter.Label(line_frame,text="OLD IP:",font=font3,width=6).pack(side="left",expand=0,fill="y")
  295. e_ip = Tkinter.Entry(line_frame,font=font20)
  296. e_ip.pack(side="left")
  297. #b_scan = Tkinter.Button(line_frame,width=14,font=font3)
  298. #b_scan.pack(side="left",expand=1)
  299. # ----------------------------------------------
  300. line_frame = Tkinter.Frame(eframe)
  301. line_frame.pack(side="top",expand=0,fill="x")
  302. e_ip_label = Tkinter.Label(line_frame,text=" IP:",font=font3,width=6)
  303. e_ip_label.pack(side="left",expand=0,fill="y")
  304. e_ip_new = Tkinter.Entry(line_frame,font=font20)
  305. e_ip_new.bind("<Return>", set_ip )
  306. e_ip_new.bind("<KP_Enter>", set_ip)
  307. #e_ip_new.bind("<Tab>", update_name)
  308. e_ip_new.bind("<ISO_Left_Tab>", set_ip)
  309. e_ip_new.pack(side="left")
  310. #-------------------------------------------- line
  311. line_frame = Tkinter.Frame(eframe)
  312. line_frame.pack(side="top",expand=0,fill="x")
  313. variable = Tkinter.StringVar(root)
  314. variable.set("255.0.0.0") # default value
  315. Tkinter.Label(line_frame,text="IPMASK",font=font3,width=6).pack(side="left",expand=0,fill="y")
  316. e_mask_new = Tkinter.OptionMenu(line_frame, variable,"255.255.255.0","255.0.0.0")
  317. e_mask_new.configure(font=("Helvetica", 20))
  318. e_mask_new.configure(width=17)
  319. #heigh=1,font=("Helvetica", 20)
  320. e_mask_new.pack(side="left")
  321. #e_mask_new.insert("end","255.0.0.0")
  322. #e_mask_new.insert("end","255.255.255.0")
  323. b_scan = Tkinter.Button(line_frame,text="SEND TO NODE",command=set_ip,width=14,font=font1)
  324. b_scan.pack(side="left",expand=0)
  325. #-------------------------------------------- line
  326. line_frame = Tkinter.Frame(eframe)
  327. line_frame.pack(side="top",expand=0,fill="x")
  328. Tkinter.Label(line_frame,text="MAC:",font=font3,width=6).pack(side="left",expand=0,fill="y")
  329. e_mac = Tkinter.Entry(line_frame,width=16,font=font20)
  330. e_mac.pack(side="left")
  331. e_mac2 = Tkinter.Entry(line_frame,width=3,font=font20)
  332. e_mac2.pack(side="left")
  333. e_mac2.bind("<Return>", send_mac )
  334. e_mac2.bind("<KP_Enter>", send_mac)
  335. Tkinter.Button(line_frame,text="SEND TO NODE",command=send_mac,width=14,font=font1).pack(side="left",expand=0)
  336. #-------------------------------------------- line
  337. #b_scan = Tkinter.Button(eframe1,width=14,font=font3)
  338. #b_scan.pack(side="top",expand=0)
  339. line_frame = Tkinter.Frame(eframe)
  340. line_frame.pack(side="top",expand=0,fill="x")
  341. Tkinter.Label(line_frame,text="DMX:",font=font3,width=6).pack(side="left",expand=0,fill="y")
  342. b_set_node_pin = Tkinter.Button(line_frame,text="HW-PIN",command=set_node_pin,width=6,font=font3)
  343. b_set_node_pin.pack(side="left",expand=0)
  344. b_set_node_in = Tkinter.Button(line_frame,text="IN",command=set_node_in,width=6,font=font3)
  345. b_set_node_in.pack(side="left",expand=0)
  346. b_set_node_out = Tkinter.Button(line_frame,text="OUT",command=set_node_out,width=6,font=font3)
  347. b_set_node_out.pack(side="left",expand=0)
  348. #-------------------------------------------- line
  349. line_frame = Tkinter.Frame(eframe)
  350. line_frame.pack(side="top",expand=0,fill="x")
  351. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  352. e_cmd = Tkinter.Entry(line_frame,font=font3,width=16)
  353. e_cmd.bind("<Return>", send_cmd )
  354. e_cmd.pack(side="left")
  355. #-------------------------------------------- line
  356. line_frame = Tkinter.Frame(eframe)
  357. line_frame.pack(side="top",expand=0,fill="x")
  358. Tkinter.Label(line_frame,text="L-Name",font=font3,width=6).pack(side="left",expand=0,fill="y")
  359. e_lname = Tkinter.Entry(line_frame,font=font3,width=10)
  360. e_lname.pack(side="left")
  361. #-------------------------------------------- line
  362. line_frame = Tkinter.Frame(eframe)
  363. line_frame.pack(side="top",expand=0,fill="x")
  364. Tkinter.Label(line_frame,text="S-Name",font=font3,width=6).pack(side="left",expand=0,fill="y")
  365. e_sname = Tkinter.Entry(line_frame,font=font3,width=10)
  366. e_sname.pack(side="left")
  367. #-------------------------------------------- line
  368. line_frame = Tkinter.Frame(eframe)
  369. line_frame.pack(side="top",expand=0,fill="x")
  370. Tkinter.Label(line_frame,text="ArtNet",font=font3,width=6).pack(side="left",expand=0,fill="y")
  371. Tkinter.Label(line_frame,text="SUB:",font=font3,width=4).pack(side="left",expand=0,fill="y")
  372. e_artnet_uni1 = Tkinter.Entry(line_frame,font=font3,width=4)
  373. e_artnet_uni1.pack(side="left")
  374. Tkinter.Label(line_frame,text="NET:",font=font3,width=4).pack(side="left",expand=0,fill="y")
  375. e_artnet_uni1 = Tkinter.Entry(line_frame,font=font3,width=4)
  376. e_artnet_uni1.pack(side="left")
  377. Tkinter.Label(line_frame,text="UNI:",font=font3,width=4).pack(side="left",expand=0,fill="y")
  378. e_artnet_uni1 = Tkinter.Entry(line_frame,font=font3,width=4)
  379. e_artnet_uni1.pack(side="left")
  380. Tkinter.Button(line_frame,text="SEND TO NODE",command=send_none,width=14,font=font1).pack(side="left",expand=0)
  381. #-------------------------------------------- line
  382. b_scan = Tkinter.Text(eframe,width=20,font=font2)
  383. b_scan.pack(side="top",expand=1,fill="x")
  384. #-------------------------------------------- line
  385. line_frame = Tkinter.Frame(eframe1)
  386. line_frame.pack(side="top",expand=0,fill="x")
  387. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  388. e_cmd2 = Tkinter.Entry(line_frame,font=font3,width=16)
  389. e_cmd2.insert("end","DMX ERASE ")
  390. e_cmd2.bind("<Return>", send_cmd2 )
  391. e_cmd2.pack(side="left")
  392. #-------------------------------------------- line
  393. line_frame = Tkinter.Frame(eframe1)
  394. line_frame.pack(side="top",expand=0,fill="x")
  395. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  396. e_cmd3 = Tkinter.Entry(line_frame,font=font3,width=16)
  397. e_cmd3.insert("end","DMX OUT STORE ")
  398. e_cmd3.bind("<Return>", send_cmd3 )
  399. e_cmd3.pack(side="left")
  400. #-------------------------------------------- line
  401. line_frame = Tkinter.Frame(eframe1)
  402. line_frame.pack(side="top",expand=0,fill="x")
  403. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  404. e_cmd4 = Tkinter.Entry(line_frame,font=font3,width=16)
  405. e_cmd4.insert("end","DMX OUT SET 2")
  406. e_cmd4.bind("<Return>", send_cmd4 )
  407. e_cmd4.pack(side="left")
  408. #-------------------------------------------- line
  409. line_frame = Tkinter.Frame(eframe1)
  410. line_frame.pack(side="top",expand=0,fill="x")
  411. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  412. e_cmd5 = Tkinter.Entry(line_frame,font=font3,width=16)
  413. e_cmd5.insert("end","REBOOT ")
  414. e_cmd5.bind("<Return>", send_cmd5 )
  415. e_cmd5.pack(side="left")
  416. thread.start_new_thread(_scan, () )
  417. nodscaner.bind_cmd_node()
  418. def read_cmd_buf():
  419. b_scan.insert("end", "buf read\n" )
  420. while 1:
  421. if nodscaner.node_cmd_buf_list:
  422. msg = str(nodscaner.node_cmd_buf_list)
  423. print("read_cmd_buf msg",msg)
  424. nodscaner.node_cmd_buf_list = []
  425. b_scan.insert("end",str(time.time())+"\n")
  426. b_scan.insert("end", msg +"\n")
  427. b_scan.see("end")
  428. time.sleep(0.1)
  429. #thread.start_new_thread(nodscaner.node_cmd_recive, () )
  430. #thread.start_new_thread(read_cmd_buf, () )
  431. def X():
  432. thread.start_new_thread(nodscaner.node_cmd_recive, () )
  433. thread.start_new_thread(read_cmd_buf, () )
  434. #thread.start_new_thread(node_cmd_recive, () )
  435. #send_node_cmd(ip=(2,0,0,91),cmd="DMX OUT STORE")
  436. send_node_cmd(ip=(2,255,255,255),cmd="CMD GT ")
  437. rx = ArtNetNodes()
  438. rx.loop()
  439. z = 0
  440. while 1:
  441. nodes = rx.get()
  442. #print(len(nodes))
  443. if z % 10 == 0:
  444. print()
  445. pass
  446. print("node count",len(nodes))
  447. #for i in nodes:
  448. #print(i)
  449. z += 1
  450. time.sleep(0.2)
  451. print()
  452. print("time out")
  453. raw_input("ENDE")
  454. thread.start_new_thread(X,()) #node_cmd_recive, () )
  455. root.mainloop()