TK-Nodescanner.py 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  1. #! /usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Valid-License-Identifier: GPL-2.0-only
  5. SPDX-URL: https://spdx.org/licenses/GPL-2.0-only.html
  6. (c) 2012 micha@librelight.de
  7. """
  8. import os
  9. import time
  10. import struct
  11. import sys
  12. import tkinter as Tkinter
  13. import _thread as thread
  14. import datetime
  15. from cprint import cprint
  16. import nodescan
  17. #import nodescan2 #as nodescaner
  18. _file_path = "/opt/LibreLight/Xdesk/"
  19. sys.path.insert(0,"/opt/LibreLight/Xdesk/")
  20. title = "TK-ArtNet-Nodscaner"
  21. sys.stdout.write("\x1b]2;"+title+"\x07")
  22. mc = None
  23. try:
  24. import memcache
  25. mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  26. #mc.set("dmx-1", [1]*512)
  27. except Exception as e:
  28. cprint("Exception",e,color="red")
  29. #lock.acquire()
  30. #lock.release()
  31. class LOCK_BUF():
  32. def __init__(self):
  33. self.data = []
  34. self.lock = thread.allocate_lock()
  35. def append(self,data):
  36. try:
  37. self.lock.acquire()
  38. self.data.append(data)
  39. finally:
  40. self.lock.release()
  41. def set(self,data):
  42. try:
  43. self.lock.acquire()
  44. self.data = data[:]
  45. finally:
  46. self.lock.release()
  47. def get(self):
  48. out = []
  49. try:
  50. self.lock.acquire()
  51. out = self.data[:]
  52. finally:
  53. self.lock.release()
  54. return out
  55. node_list = LOCK_BUF() #[]
  56. def fill_form(event=None):
  57. cprint(sys._getframe().f_code.co_name,color="yellow")
  58. global node_list
  59. clear_form()
  60. node_list2 = node_list.get()
  61. sel=0
  62. try:
  63. csel = li_nodes.curselection()[0]
  64. except Exception as e:
  65. cprint("ERR no node selected in node-list:",e,color="red")
  66. return 0
  67. print("+++",[csel,len(node_list2)])
  68. try:
  69. sel = int(li_nodes.get(csel).split()[0])-1
  70. except:
  71. cprint("ERR no leeding number in Listbox.line" ,color="red")
  72. return 0
  73. if not node_list2:
  74. return 0
  75. print("INFO: sel,node_list2",sel,len(node_list2))
  76. e_ip.configure(state='normal')
  77. e_ip.insert("end",node_list2[sel]["IP"].replace("[","").replace("]",""))
  78. #e_ip.configure(state='readonly')
  79. e_ip_new.insert("end",node_list2[sel]["IP"].replace("[","").replace("]",""))
  80. e_mac.delete("0","end")
  81. e_mac.insert("end",node_list2[sel]["MAC"].replace("[","").replace("]",""))
  82. e_mac2.delete("0","end")
  83. e_mac2.insert("end",node_list2[sel]["MAC"].split(":")[-1])
  84. print("load",node_list2[sel])
  85. e_lname.delete("0","end")
  86. e_lname.insert("end",node_list2[sel]["lname"])
  87. e_sname.delete("0","end")
  88. e_sname.insert("end",node_list2[sel]["sname"])
  89. e_artnet_uni1.delete("0","end")
  90. univ = "0"
  91. try:
  92. if node_list2[sel]["PortTypes"][0] == "@":
  93. univ = ord(node_list2[sel]["SwIn"][0:1])
  94. else:
  95. univ = ord(node_list2[sel]["SwOut"][0:1])
  96. except Exception as e:
  97. cprint("load Exception",e,color="red")
  98. MSG["text"] = e
  99. MSG["bg"] = "red"
  100. e_artnet_uni1.insert("end",univ)
  101. def clear_form():
  102. cprint(sys._getframe().f_code.co_name,color="yellow")
  103. e_ip.configure(state='normal')
  104. e_ip.delete("0","end")
  105. e_ip.configure(state='readonly')
  106. e_ip_new.delete("0","end")
  107. e_mac.delete("0","end")
  108. e_mac2.delete("0","end")
  109. e_lname.delete("0","end")
  110. e_sname.delete("0","end")
  111. e_artnet_uni1.delete("0","end")
  112. def clear_node_list():
  113. cprint(sys._getframe().f_code.co_name,color="yellow")
  114. li_nodes.delete("0","end")
  115. def poll(delay=1,ip=""):
  116. cprint(sys._getframe().f_code.co_name,color="yellow")
  117. if not ip:
  118. ip = p_variable.get()
  119. b_scan.insert("end", "ArtNetPoll -> "+str(ip)+"\n")
  120. nodescan.ArtNet_poll(ip)
  121. time.sleep(1)
  122. fill_form()
  123. def clear(event= None):
  124. cprint(sys._getframe().f_code.co_name,color="yellow")
  125. clear_node_list()
  126. clear_form()
  127. def poll_loop():
  128. cprint(sys._getframe().f_code.co_name,color="yellow")
  129. time.sleep(1)
  130. while 1:
  131. poll()
  132. time.sleep(1)
  133. old_tick = 0
  134. rx = nodescan.ArtNetNodes()
  135. #rx = nodescan2
  136. def scan():
  137. cprint(sys._getframe().f_code.co_name,color="yellow")
  138. global rx,node_list,old_tick,Scrollbar
  139. print("get node from cache " )
  140. li_nodes.insert("end",str("----"))
  141. ##rx.loop()
  142. while 1:
  143. try:
  144. _scan()
  145. except Exception as e:
  146. cprint("_scan Exception as",e,color="red") #,e.argv)
  147. MSG["text"] = e
  148. MSG["bg"] = "red"
  149. time.sleep(0.3)
  150. import nodescan2 #as nodescan2
  151. def _scan():
  152. cprint(sys._getframe().f_code.co_name,color="yellow")
  153. #print(sys._getframe().f_code.co_name)
  154. global rx,node_list,old_tick,Scrollbar
  155. ips = nodescan2.os_list_ip() #example
  156. #for i,v in ips.items():
  157. # print(" ",i,v)
  158. # #get_mask(ips)
  159. nodescan2.ArtPoll()
  160. nodes = []
  161. if mc:
  162. nodes = []
  163. artpoll = mc.get("index-artpoll")
  164. #print()
  165. #print()
  166. for k in artpoll:
  167. #print("_scan",k)
  168. data = mc.get(k)
  169. #print(k,data)
  170. #opcode=convert_to_hex("<h",data[8:10])
  171. opcode= nodescan2.artnet_get_opcode(data)
  172. #print(opcode)
  173. if "ArtPollReplay" in opcode: # != '0x2100': #OpPollReplay
  174. node = nodescan2.ArtNet_decode_pollreplay(data)
  175. s = artpoll[k][1]
  176. s = datetime.datetime.strptime(s, '%Y-%m-%d %H:%M:%S')
  177. s = s.timestamp()
  178. #s = int(time.time()-s.timestamp())
  179. node["UPDATESTAMP"] = s
  180. node["BOOT"] = 0
  181. node["REFRESHSTAMP"] = s
  182. node["LASTPING"] = 0
  183. #print("---",node)
  184. node1 = nodescan.ArtNet_decode_pollreplay(data)
  185. #print("+++",node1)
  186. #node=node1
  187. nodes.append(node)
  188. #print()
  189. ok=0
  190. for n in nodes:
  191. if n not in node_list.get():
  192. node_list.append(n)
  193. ok=1
  194. if 1: #ok:
  195. refresh_node_list()
  196. time.sleep(10)
  197. def refresh_node_list():
  198. cprint(sys._getframe().f_code.co_name,color="yellow")
  199. refresh_node_list1()
  200. refresh_node_list2()
  201. def refresh_node_list1():
  202. cprint(sys._getframe().f_code.co_name,color="yellow")
  203. #aprint(len(nodes))
  204. li_node_scroll = li_nodes.yview()
  205. li_nodes.delete("0","end")
  206. node_nr = 1
  207. nodesB = {}
  208. for node in node_list.get(): #nodes:
  209. k = node["MAC"]
  210. nodesB[k] = node
  211. #print("k",nodesB.keys())
  212. k_sort = list(nodesB.keys())
  213. k_sort.sort()
  214. node_list.set([]) # =[]
  215. for k in k_sort:
  216. node_list.append(nodesB[k])
  217. #print("k sort",k_sort)
  218. for k in k_sort:
  219. node = nodesB[k]
  220. #print("lll",node)
  221. li_nodes.insert("end",str(node_nr).rjust(3," ") +" "+ node["lname"])
  222. bg = "lightgrey"
  223. color = li_nodes.itemconfig("end", bg=bg)
  224. ip = str(node_nr).rjust(3," ") +" "+ node["IP"]
  225. bg = ""
  226. if "PortTypes" in node:
  227. if not node["PortTypes"]:
  228. pass
  229. if node["PortTypes"][0] == "@":
  230. ip += " DMX-in"
  231. bg ="yellow"
  232. else:
  233. ip += " DMX-out"
  234. bg ="lightgreen"
  235. if bg:
  236. color = li_nodes.itemconfig("end", bg=bg)
  237. li_nodes.insert("end",str(node_nr).rjust(3," ") +" short Name:"+ node["sname"])
  238. li_nodes.insert("end",ip)
  239. if bg:
  240. color = li_nodes.itemconfig("end", bg=bg)
  241. inout = " UNIVERS OUT="+ str(ord(node["SwOut"][0:1]))+" IN="+ str(ord(node["SwIn"][0:1]))
  242. li_nodes.insert("end",str(node_nr).rjust(3," ") + inout)
  243. li_nodes.insert("end",str(node_nr).rjust(3," ") +" MAC:"+ node["MAC"])
  244. try:
  245. last_change=time.time()-float(node["UPDATESTAMP"])
  246. timeline = ""
  247. timeline += " CHANGE:%0.1f"% (last_change)
  248. REFRESHSTAMP = time.time()-float(node["REFRESHSTAMP"])
  249. timeline +=" PING:%0.1f"% REFRESHSTAMP
  250. li_nodes.insert("end",str(node_nr).rjust(3," ") +timeline )
  251. if last_change > 20:
  252. color = li_nodes.itemconfig("end", bg="ORANGE")
  253. except Exception as e:
  254. li_nodes.insert("end",str(e)+"\n" )
  255. li_nodes.itemconfig("end", bg="red")
  256. try:
  257. if node["BOOT"]:
  258. BOOT = time.time()-float(node["BOOT"])
  259. else:
  260. BOOT = 0
  261. timeline =" BOOT:%0.1f"% BOOT
  262. li_nodes.insert("end",str(node_nr).rjust(3," ") +timeline +" sec" )
  263. bg = ""
  264. except Exception as e:
  265. li_nodes.insert("end",str(e)+"\n" )
  266. li_nodes.itemconfig("end", bg="red")
  267. if bg:
  268. li_nodes.itemconfig("end", bg=bg)
  269. li_nodes.insert("end","*"*60)
  270. node_nr += 1
  271. #node_list += [node]
  272. print("scroll:",li_node_scroll)
  273. def refresh_node_list2():
  274. cprint(sys._getframe().f_code.co_name,color="yellow")
  275. node_nr = 1
  276. nodesB = {}
  277. for node in node_list.get(): #nodes:
  278. k = node["MAC"]
  279. nodesB[k] = node
  280. k_sort = list(nodesB.keys())
  281. k_sort.sort()
  282. node_list.set([]) # =[]
  283. for k in k_sort:
  284. node_list.append(nodesB[k])
  285. out = []
  286. for k in k_sort:
  287. print(" ",k)
  288. node = nodesB[k]
  289. txt = " "*5 + "="*30
  290. bg=""
  291. out.append({"txt":txt,"bg":bg})
  292. bg = "lightgrey"
  293. txt = str(node_nr).rjust(3," ") +" "+ node["lname"]
  294. out.append({"txt":txt,"bg":bg})
  295. ip = str(node_nr).rjust(3," ") +" "+ node["IP"]
  296. bg = ""
  297. if "PortTypes" in node:
  298. if not node["PortTypes"]:
  299. pass
  300. if node["PortTypes"][0] == "@":
  301. ip += " DMX-in"
  302. bg ="yellow"
  303. else:
  304. ip += " DMX-out"
  305. bg ="lightgreen"
  306. txt = str(node_nr).rjust(3," ") +" short Name:"+ node["sname"]
  307. out.append({"txt":txt,"bg":bg})
  308. txt=ip
  309. bg = ""
  310. out.append({"txt":txt,"bg":bg})
  311. inout = " UNIVERS OUT="+ str(ord(node["SwOut"][0:1]))+" IN="+ str(ord(node["SwIn"][0:1]))
  312. txt = str(node_nr).rjust(3," ") + inout
  313. bg = ""
  314. out.append({"txt":txt,"bg":bg})
  315. txt = str(node_nr).rjust(3," ") +" MAC:"+ node["MAC"]
  316. bg = ""
  317. out.append({"txt":txt,"bg":bg})
  318. txt = ""
  319. bg = ""
  320. try:
  321. last_change=time.time()-float(node["UPDATESTAMP"])
  322. timeline = ""
  323. timeline += " CHANGE:%0.1f"% (last_change)
  324. REFRESHSTAMP = time.time()-float(node["REFRESHSTAMP"])
  325. timeline +=" PING:%0.1f"% REFRESHSTAMP
  326. txt = str(node_nr).rjust(3," ") +timeline
  327. if last_change > 20:
  328. bg="ORANGE"
  329. except Exception as e:
  330. txt = str(e)+"\n"
  331. bg = "red"
  332. out.append({"txt":txt,"bg":bg})
  333. txt=""
  334. bg = ""
  335. try:
  336. if node["BOOT"]:
  337. BOOT = time.time()-float(node["BOOT"])
  338. else:
  339. BOOT = 0
  340. timeline =" BOOT:%0.1f"% BOOT
  341. txt = str(node_nr).rjust(3," ") +timeline +" sec"
  342. bg = ""
  343. except Exception as e:
  344. txt = str(e)+"\n"
  345. bg = "red"
  346. out.append({"txt":txt,"bg":bg})
  347. node_nr += 1
  348. out.append({"txt":"","bg":"white"})
  349. li_node_scroll = li_nodes.yview()
  350. li_nodes.delete("0","end")
  351. for i in out:
  352. #print("list:",i)
  353. li_nodes.insert("end",i["txt"])
  354. bg=i["bg"]
  355. if not bg:
  356. bg = "lightgrey"
  357. bg = "#ddd"
  358. li_nodes.itemconfig("end", bg=bg)
  359. def get_new_ip_str(event=None):
  360. cprint(sys._getframe().f_code.co_name,color="yellow")
  361. x = e_ip_new.get().replace("[","").replace("]","")
  362. x = x.strip()
  363. x = x.replace(" ","")
  364. x = x.split(",")
  365. print( "get_new_ip_str",x)
  366. return x
  367. def get_form(event=None):
  368. cprint(sys._getframe().f_code.co_name,color="yellow")
  369. x = e_ip_new.get().replace("[","").replace("]","")
  370. x = x.strip()
  371. x = x.replace(" ","")
  372. x = x.split(",")
  373. ip2 = ".".join(x)
  374. ip = e_ip_new.get()
  375. ip = ip.replace(" ","")
  376. ip = ip.replace(",",".")
  377. MASK = variable.get() #e_mask_new.get()
  378. #new_mac = b"CMD MAC6 " + struct.pack("<B",(int(e_mac2.get(),16)))
  379. mac = e_mac.get()
  380. mac_new = e_mac2.get()
  381. ln = e_lname.get()
  382. sn = e_sname.get()
  383. univ = e_artnet_uni1.get()
  384. data={}
  385. data["IP"] = ip
  386. data["IP2"] = ip2
  387. data["sname"] = sn
  388. data["lname"] = ln
  389. data["netmask"] = MASK
  390. data["mac"] = mac
  391. data["mac_new"] = mac_new
  392. data["univ"] = univ
  393. print("FORM:",data)
  394. return data
  395. def send_artaddr(event=None):
  396. cprint(sys._getframe().f_code.co_name,color="yellow")
  397. get_form()
  398. ln = e_lname.get()
  399. sn = e_sname.get()
  400. ip = e_ip_new.get()
  401. ip = ip.replace(" ","")
  402. ip = ip.replace(",",".")
  403. univ = e_artnet_uni1.get()
  404. print("SEND ArtAddress:",[ln,sn,ip,univ])
  405. if ln and sn and ip and univ:
  406. nodescan.ArtAddress(ip=ip ,ShortName=sn, LongName=ln,Port="",Universes=univ)
  407. time.sleep(1)
  408. poll()
  409. def send_none(event=None):
  410. cprint(sys._getframe().f_code.co_name,color="yellow")
  411. pass
  412. def send_mac(event=None):
  413. cprint(sys._getframe().f_code.co_name,color="yellow")
  414. #new_mac = "CMD MAC6 " + hex(e_mac2.get()) #)
  415. #new_mac = "CMD MAC6 " + struct.pack("<B",(int(e_mac2.get(),16))).decode()
  416. new_mac = b"CMD MAC6 " + struct.pack("<B",(int(e_mac2.get(),16)))
  417. a = e_ip.get().replace("[","").replace("]","")
  418. cur_ip = []
  419. for i in a.split(","):
  420. cur_ip +=[int(i)]
  421. print("SEND MAC:",cur_ip,new_mac)
  422. nodescan.send_node_cmd(cur_ip,cmd=new_mac)
  423. # nodescan.sock.sendto(cmddata2 ,(ip,port))
  424. #poll(delay=1.5)
  425. def SEND_CMD(cmd="NIX",entry=None):
  426. cprint(sys._getframe().f_code.co_name,color="yellow")
  427. def cb(event=None):
  428. cprint(sys._getframe().f_code.co_name,color="yellow")
  429. _cmd=cmd
  430. if entry:
  431. _cmd = entry.get() #"CMD DMX STORE "
  432. print(" SEND_CMD.cb()",[_cmd])
  433. if not _cmd:
  434. cprint(" SEND_CMD: no cmd",color="red")
  435. #_send_cmd(cmd=_cmd)
  436. port = 7600
  437. form = get_form()
  438. if form["IP2"]:
  439. _cmd2 = []
  440. for i in _cmd:
  441. try:
  442. _cmd2.append(ord(i) )
  443. except:
  444. _cmd2.append(ord(" ") )
  445. print(" _cmd2",_cmd2)
  446. for i in range(31):
  447. if len(_cmd2) < i:
  448. _cmd2.append(0)
  449. for i in _cmd2:
  450. print(" ",i,i,hex(i))
  451. _cmd2 = bytes(_cmd2)
  452. print(" _cmd2",_cmd2)
  453. nodescan.sock.sendto(_cmd2 ,(form["IP2"],port))
  454. return cb
  455. def send_artdmx(val=127):
  456. def cb():
  457. form = get_form()
  458. print(form)
  459. import lib.ArtNetNode as an
  460. if form["IP2"] and form["univ"]:
  461. artnet = an.ArtNetNode(to=form["IP2"],univ=form["univ"],port=4566)
  462. artnet.send([val]*512,port=6454)
  463. print(artnet._data)
  464. return cb
  465. def _send_cmd(event=None,cmd=""):
  466. cprint(sys._getframe().f_code.co_name,color="yellow")
  467. #cmd = e_cmd.get() #"CMD DMX STORE "
  468. cmd = cmd.split(" ")
  469. value = cmd[-1]
  470. try:
  471. value = struct.pack("<B",int(value))
  472. except:pass
  473. cmd = cmd[:-1] #.append(value)
  474. cmd.append(value)
  475. print("_send_cmd:",[cmd])
  476. cmd=" ".join(map(str,cmd) )
  477. a = e_ip.get()
  478. if not a:
  479. cprint(" NO NODE-IP SELECTED",color="red")
  480. return
  481. a = a.replace("[","").replace("]","")
  482. cur_ip = []
  483. sep = "xx"
  484. if "," in a:
  485. sep = ","
  486. if "." in a:
  487. sep = "."
  488. for i in a.split(sep):
  489. cur_ip +=[int(i)]
  490. cprint("_cmd_send:",cur_ip ,"CMD:",[cmd],color="yellow")
  491. nodescan.send_node_cmd(cur_ip,cmd)
  492. #poll(delay=1.5)
  493. def kill_librelight(event=None):
  494. print(sys._getframe().f_code.co_name)
  495. #for i in ["CONSOLE.py","EDITOR.py","ASP"]:
  496. for i in ["ASP"]:
  497. cmd='screen -XS "{}" quit | echo ""'.format(i)
  498. print(cmd)
  499. b_scan.insert("end",cmd+"\n")
  500. os.system(cmd)
  501. cmd="screen -ls"
  502. os.system(cmd)
  503. time.sleep(1)
  504. BASE_PATH = "/opt/LibreLight/Xdesk/"
  505. cmd="_LibreLightDesk.py"
  506. cmd="tool/TK-Nodescanner.py" #&"
  507. b_scan.insert("end",cmd+"\n")
  508. arg = ""
  509. #os.execl("/usr/bin/python3", BASE_PATH, cmd,arg)
  510. global nodescan
  511. nodescan.is_running = 0 # exit all thread loop's
  512. nodescan.sock.close()
  513. time.sleep(1)
  514. nodescan.sock = nodescan.socket_warp()
  515. time.sleep(1)
  516. thread.start_new_thread(nodescan.node_cmd_recive, () )
  517. rx.loop()
  518. time.sleep(1)
  519. poll()
  520. def start_librelight(event=None):
  521. #for i in ["CONSOLE.py","EDITOR.py","ASP"]:
  522. for i in ["ASP"]:
  523. cmd='screen -XS "{}" quit | echo ""'.format(i)
  524. print(cmd)
  525. os.system(cmd)
  526. global nodescan,rx
  527. nodescan.is_running = 0 # exit all thread loop's
  528. nodescan.sock.close()
  529. time.sleep(1)
  530. #root.quit()
  531. thread.start_new_thread(nodescan.node_cmd_recive, () )
  532. rx.loop()
  533. time.sleep(0.5)
  534. BASE_PATH = "/opt/LibreLight/Xdesk/"
  535. cmd="init/10-ASP.sh"
  536. arg = ""
  537. os.system(cmd)
  538. #os.execl("/usr/bin/sh", BASE_PATH, cmd,arg)
  539. def set_ip(event=None):
  540. print("SET NEW IP")
  541. cur_ip=(2,0,0,94)
  542. new_ip=(2,0,0,201)
  543. new_netmask=(255,0,0,0)
  544. a = e_ip.get().replace("[","").replace("]","")
  545. b = e_ip_new.get().replace("[","").replace("]","")
  546. c = variable.get() #e_mask_new.get()
  547. new_netmask = [] #c.split(".") #list(c)
  548. for i in c.split("."):
  549. new_netmask +=[int(i)]
  550. cur_ip = []
  551. for i in a.split(","):
  552. cur_ip +=[int(i)]
  553. new_ip = []
  554. for i in b.split(","):
  555. new_ip +=[int(i)]
  556. if new_ip == cur_ip:
  557. print("neu und als IP sind gleich" )
  558. return 0
  559. #cur_ip=(2,0,0,94)
  560. #new_ip=(2,0,0,201)
  561. print("new",[cur_ip, new_ip, new_netmask])
  562. print()
  563. nodescan.set_ip4(cur_ip,new_ip, new_netmask)
  564. poll(delay=1.5)
  565. def set_node_pin(evnet=None):
  566. cprint(sys._getframe().f_code.co_name,color="yellow")
  567. cmd = "CMD DMX=PIN"
  568. ip = get_new_ip_str()
  569. print("ip",[ip])
  570. nodescan.send_node_cmd(ip,cmd=cmd)
  571. poll(delay=1.5)
  572. def set_node_in(evnet=None):
  573. cprint(sys._getframe().f_code.co_name,color="yellow")
  574. cmd="CMD DMX=IN"
  575. ip = get_new_ip_str()
  576. nodescan.send_node_cmd(ip,cmd=cmd)
  577. poll(delay=1.5)
  578. def set_node_out(evnet=None):
  579. cprint(sys._getframe().f_code.co_name,color="yellow")
  580. cmd="CMD DMX=OUT"
  581. ip = get_new_ip_str()
  582. nodescan.send_node_cmd(ip,cmd=cmd)
  583. poll(delay=1.5)
  584. root = Tkinter.Tk()
  585. #root.geometry("900x700+100+100")
  586. root.geometry("700x600+100+100")
  587. root.title( title)
  588. fframe = Tkinter.Frame(root)
  589. fframe.pack(side="top",expand=0,fill="x")
  590. cframe = Tkinter.Frame(root)
  591. cframe.pack(side="top",expand=1,fill="both")
  592. font1 = ("Helvetica", 8)
  593. font2 = ("Helvetica", 12) # 10
  594. font3 = ("Helvetica", 12) # 16
  595. font20 = font=("Helvetica", 12) # 22
  596. font120 = font=("Helvetica", 22) # 22
  597. b_scan = Tkinter.Button(fframe,text="refresh list",width=8,command=refresh_node_list,font=font2)
  598. b_scan.pack(side="left",expand=0,fill="y")
  599. b_scan = Tkinter.Button(fframe,text="ArtNetPoll ->",width=10,command=poll,font=font2)
  600. b_scan.configure(bg="#0f0")
  601. #b_scan.pack(side="left",expand=0,fill="y")
  602. #POLL ['192.168.0.255', 6454] OK ;
  603. #POLL ['192.168.0.99', 6454] OK ;
  604. #POLL ['2.255.255.255', 6454] OK ;
  605. #POLL ['2.0.0.255', 6454] OK ;
  606. #POLL ['2.255.255.255', 6454] OK ;
  607. def get_ips():
  608. cprint(sys._getframe().f_code.co_name,color="yellow")
  609. local_ips = []
  610. #local_ips.append("2.0.0.255")
  611. cmd='ip a | grep " inet " | cut -d " " -f 6 | sort -h'
  612. r=os.popen(cmd)
  613. #print("cmd",cmd)
  614. txt=r.readlines()
  615. for ip in txt:
  616. ip = ip.strip()
  617. #print([ip])
  618. if ip.startswith("127."):
  619. continue
  620. if ip.count(".") != 3:
  621. continue
  622. if ip.endswith("/24"):
  623. ip = ip.split(".")
  624. ip = ".".join(ip[:3])+".255"
  625. elif ip.endswith("/8"):
  626. ip = ip.split(".")
  627. ip = ".".join(ip[0])+".255.255.255"
  628. else:
  629. continue
  630. #print("-",ip)
  631. #if ip == "2.255.255.255":
  632. # print("- workaround -")
  633. # local_ips.append("2.0.0.255")
  634. local_ips.append(ip)
  635. return local_ips
  636. local_ips =get_ips()
  637. option_list=local_ips
  638. p_variable = Tkinter.StringVar(root)
  639. p_variable.set(option_list[0]) # default value
  640. e_poll_new = Tkinter.OptionMenu(fframe, p_variable,*option_list,)
  641. e_poll_new.configure(font=("Helvetica", 13))
  642. e_poll_new.configure(width=13)
  643. e_poll_new["bg"] = "#fff"
  644. #print(dir(e_poll_new))
  645. e_poll_new.option_add("end","") #', 'option_clear', 'option_get
  646. e_poll_new.option_add("end","215.0.0.0")
  647. #e_poll_new.pack(side="left")
  648. #exit()
  649. b_scan = Tkinter.Button(fframe,text="Librelight:",font=font2,relief="flat",bg="orange")
  650. #b_scan.pack(side="left",expand=0)
  651. b_scan = Tkinter.Button(fframe,text="KILL !",command=kill_librelight,width=6,font=font2,bg="red")
  652. #b_scan.pack(side="left",expand=0)
  653. b_scan = Tkinter.Button(fframe,text="START ",command=start_librelight,width=6,font=font2,bg="green")
  654. #b_scan.pack(side="left",expand=0)
  655. scrollbar = Tkinter.Scrollbar(cframe)
  656. scrollbar.pack(side=Tkinter.RIGHT, fill="y")
  657. #pool = Tkinter.Listbox(root,selectmode="extended",exportselection=0)
  658. li_nodes = Tkinter.Listbox(cframe,exportselection=0,width=35,font=font1)
  659. li_nodes.pack(side="left",expand=0,fill="y")
  660. li_nodes.bind("<ButtonRelease-1>",fill_form )
  661. li_nodes.config(yscrollcommand=scrollbar.set)
  662. scrollbar.config(command=li_nodes.yview)
  663. eframe = Tkinter.Frame(cframe)
  664. eframe.pack(side="left",expand=0,fill="y")
  665. eframe1 = Tkinter.Frame(cframe)
  666. eframe1.pack(side="left",expand=0,fill="y")
  667. # ----------------------------------------------
  668. line_frame = Tkinter.Frame(eframe)
  669. line_frame.pack(side="top",expand=0,fill="x")
  670. x=Tkinter.Label(line_frame,text=" ",font=font2,width=6)
  671. c= Tkinter.Label(line_frame,text=" ",font=font1,width=30,anchor="w")
  672. c.pack(side="left",expand=0,fill="y")
  673. # ----------------------------------------------
  674. # ----------------------------------------------
  675. line_frame = Tkinter.Frame(eframe)
  676. line_frame.pack(side="top",expand=0,fill="x")
  677. x=Tkinter.Label(line_frame,text="MSG:",font=font3,width=6)
  678. x.pack(side="left",expand=0,fill="y")
  679. x.configure(bg="darkgrey")
  680. MSG = Tkinter.Label(line_frame,text="xxx",font=font1,width=60,anchor="w")
  681. MSG.pack(side="left",expand=0,fill="y")
  682. MSG.configure(bg="darkgrey")
  683. #msg["bg"] = "lightgrey"
  684. #msg.pack(side="left")
  685. # ----------------------------------------------
  686. line_frame = Tkinter.Frame(eframe)
  687. line_frame.pack(side="top",expand=0,fill="x")
  688. c= Tkinter.Label(line_frame,text=" ",font=font120,width=30,anchor="w")
  689. c.pack(side="left",expand=0,fill="y")
  690. # ----------------------------------------------
  691. line_frame = Tkinter.Frame(eframe)
  692. line_frame.pack(side="top",expand=0,fill="x")
  693. Tkinter.Label(line_frame,text="OLD IP:",font=font3,width=6).pack(side="left",expand=0,fill="y")
  694. e_ip = Tkinter.Entry(line_frame,font=font20,width=26,state="disabled")
  695. e_ip["bg"] = "lightgrey"
  696. e_ip.pack(side="left")
  697. b_scan = Tkinter.Button(line_frame,text="clean",font=font2,relief="flat",command=clear_form)
  698. b_scan.pack(side="left",expand=0)
  699. #b_scan = Tkinter.Button(line_frame,width=14,font=font3)
  700. #b_scan.pack(side="left",expand=1)
  701. # ----------------------------------------------
  702. line_frame = Tkinter.Frame(eframe)
  703. line_frame.pack(side="top",expand=0,fill="x")
  704. e_ip_label = Tkinter.Label(line_frame,text=" IP:",font=font3,width=6)
  705. e_ip_label.pack(side="left",expand=0,fill="y")
  706. e_ip_new = Tkinter.Entry(line_frame,font=font20,width=26)
  707. e_ip_new.bind("<Return>", set_ip )
  708. e_ip_new.bind("<KP_Enter>", set_ip)
  709. #e_ip_new.bind("<Tab>", update_name)
  710. e_ip_new.bind("<ISO_Left_Tab>", set_ip)
  711. e_ip_new.pack(side="left")
  712. #-------------------------------------------- line
  713. line_frame = Tkinter.Frame(eframe)
  714. line_frame.pack(side="top",expand=0,fill="x")
  715. variable = Tkinter.StringVar(root)
  716. variable.set("255.0.0.0") # default value
  717. Tkinter.Label(line_frame,text="MASK:",font=font3,width=6).pack(side="left",expand=0,fill="y")
  718. e_mask_new = Tkinter.OptionMenu(line_frame, variable,"255.255.255.0","255.0.0.0") #,width=10)
  719. e_mask_new.configure(font=("Helvetica", 12))
  720. e_mask_new.configure(width=12)
  721. e_mask_new["bg"] = "#fff"
  722. #heigh=1,font=("Helvetica", 20)
  723. e_mask_new.pack(side="left")
  724. e=Tkinter.Label(line_frame,text="")
  725. e.configure(width=11)
  726. e.pack(side="left")
  727. #e_mask_new.insert("end","255.0.0.0")
  728. #e_mask_new.insert("end","255.255.255.0")
  729. b_scan = Tkinter.Button(line_frame,text="SEND TO NODE",command=set_ip,width=14,font=font1)
  730. b_scan.pack(side="left",expand=0)
  731. #-------------------------------------------- line
  732. line_frame = Tkinter.Frame(eframe)
  733. line_frame.pack(side="top",expand=0,fill="x")
  734. Tkinter.Label(line_frame,text="MAC:",font=font3,width=6).pack(side="left",expand=0,fill="y")
  735. e_mac = Tkinter.Entry(line_frame,width=23,font=font20)
  736. e_mac.pack(side="left")
  737. e_mac["bg"] = "lightgrey"
  738. e_mac2 = Tkinter.Entry(line_frame,width=3,font=font20)
  739. e_mac2.pack(side="left")
  740. e_mac2.bind("<Return>", send_mac )
  741. e_mac2.bind("<KP_Enter>", send_mac)
  742. Tkinter.Button(line_frame,text="SEND TO NODE",command=send_mac,width=14,font=font1).pack(side="left",expand=0)
  743. # ----------------------------------------------
  744. line_frame = Tkinter.Frame(eframe)
  745. line_frame.pack(side="top",expand=0,fill="x")
  746. c= Tkinter.Label(line_frame,text=" ",font=font120,width=30,anchor="w")
  747. c.pack(side="left",expand=0,fill="y")
  748. # ----------------------------------------------
  749. #-------------------------------------------- line
  750. #b_scan = Tkinter.Button(eframe1,width=14,font=font3)
  751. #b_scan.pack(side="top",expand=0)
  752. line_frame = Tkinter.Frame(eframe)
  753. line_frame.pack(side="top",expand=0,fill="x")
  754. Tkinter.Label(line_frame,text="DMX:",font=font3,width=6).pack(side="left",expand=0,fill="y")
  755. b_set_node_pin = Tkinter.Button(line_frame,text="HW-PIN",command=set_node_pin,width=6,font=font3)
  756. b_set_node_pin.pack(side="left",expand=0)
  757. b_set_node_in = Tkinter.Button(line_frame,text="IN",command=set_node_in,width=6,font=font3)
  758. b_set_node_in.pack(side="left",expand=0)
  759. b_set_node_out = Tkinter.Button(line_frame,text="OUT",command=set_node_out,width=6,font=font3)
  760. b_set_node_out.pack(side="left",expand=0)
  761. #-------------------------------------------- line
  762. line_frame = Tkinter.Frame(eframe)
  763. line_frame.pack(side="top",expand=0,fill="x")
  764. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  765. e_cmd = Tkinter.Entry(line_frame,font=font3,width=26)
  766. CMD="" #DMX OUT STORE"
  767. c=SEND_CMD(CMD,entry=e_cmd)
  768. e_cmd.bind("<Return>", c )
  769. e_cmd.pack(side="left")
  770. #-------------------------------------------- line
  771. line_frame = Tkinter.Frame(eframe)
  772. line_frame.pack(side="top",expand=0,fill="x")
  773. Tkinter.Label(line_frame,text="LName",font=font3,width=6).pack(side="left",expand=0,fill="y")
  774. e_lname = Tkinter.Entry(line_frame,font=font3,width=26)
  775. e_lname.pack(side="left")
  776. #-------------------------------------------- line
  777. line_frame = Tkinter.Frame(eframe)
  778. line_frame.pack(side="top",expand=0,fill="x")
  779. Tkinter.Label(line_frame,text="SName",font=font3,width=6).pack(side="left",expand=0,fill="y")
  780. e_sname = Tkinter.Entry(line_frame,font=font3,width=26)
  781. e_sname.pack(side="left")
  782. #-------------------------------------------- line
  783. line_frame = Tkinter.Frame(eframe)
  784. line_frame.pack(side="top",expand=0,fill="x")
  785. Tkinter.Label(line_frame,text="ArtNet",font=font3,width=6).pack(side="left",expand=0,fill="y")
  786. Tkinter.Label(line_frame,text="SUB:",font=font3,width=4).pack(side="left",expand=0,fill="y")
  787. e_artnet_uni1 = Tkinter.Entry(line_frame,font=font3,width=4,state="disabled")
  788. e_artnet_uni1.pack(side="left")
  789. Tkinter.Label(line_frame,text="NET:",font=font3,width=4).pack(side="left",expand=0,fill="y")
  790. e_artnet_uni1 = Tkinter.Entry(line_frame,font=font3,width=4,state="disabled")
  791. e_artnet_uni1.pack(side="left")
  792. Tkinter.Label(line_frame,text="UNI:",font=font3,width=4).pack(side="left",expand=0,fill="y")
  793. e_artnet_uni1 = Tkinter.Entry(line_frame,font=font3,width=4)
  794. e_artnet_uni1.pack(side="left")
  795. Tkinter.Button(line_frame,text="send ArtAddr",command=send_artaddr,width=14,font=font1).pack(side="left",expand=0)
  796. #-------------------------------------------- line
  797. b_scan = Tkinter.Text(eframe,width=20,font=font2)
  798. b_scan.pack(side="top",expand=1,fill="x")
  799. #-------------------------------------------- line
  800. line_frame = Tkinter.Frame(eframe1)
  801. line_frame.pack(side="top",expand=0,fill="x")
  802. e = Tkinter.Button(line_frame,text="DMX:0",font=font3,width=16,command=send_artdmx(0),bg="orange")
  803. e.pack(side="left")
  804. line_frame = Tkinter.Frame(eframe1)
  805. line_frame.pack(side="top",expand=0,fill="x")
  806. e = Tkinter.Button(line_frame,text="DMX:127",font=font3,width=16,command=send_artdmx(127),bg="orange")
  807. e.pack(side="left")
  808. line_frame = Tkinter.Frame(eframe1)
  809. line_frame.pack(side="top",expand=0,fill="x")
  810. e = Tkinter.Button(line_frame,text="DMX:255",font=font3,width=16,command=send_artdmx(255),bg="orange")
  811. e.pack(side="left")
  812. line_frame = Tkinter.Frame(eframe1)
  813. line_frame.pack(side="top",expand=0,fill="x")
  814. e = Tkinter.Label(line_frame,text="",width=16)
  815. e.pack(side="left")
  816. line_frame = Tkinter.Frame(eframe1)
  817. line_frame.pack(side="top",expand=0,fill="x")
  818. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  819. e_cmd2 = Tkinter.Entry(line_frame,font=font3,width=16)
  820. CMD="- DMX ERASE"
  821. c=SEND_CMD(CMD)
  822. e_cmd2.insert("end",CMD)
  823. e_cmd2.bind("<Return>", c )
  824. e_cmd2.pack(side="left")
  825. #-------------------------------------------- line
  826. line_frame = Tkinter.Frame(eframe1)
  827. line_frame.pack(side="top",expand=0,fill="x")
  828. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  829. e_cmd3 = Tkinter.Entry(line_frame,font=font3,width=16)
  830. CMD="DMX OUT STORE"
  831. c=SEND_CMD(CMD)
  832. e_cmd3.insert("end",CMD)
  833. e_cmd3.bind("<Return>", c )
  834. e_cmd3.pack(side="left")
  835. #-------------------------------------------- line
  836. line_frame = Tkinter.Frame(eframe1)
  837. line_frame.pack(side="top",expand=0,fill="x")
  838. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  839. e_cmd4 = Tkinter.Entry(line_frame,font=font3,width=16)
  840. CMD="DMX OUT SET 2"
  841. c=SEND_CMD(CMD)
  842. e_cmd4.insert("end",CMD)
  843. e_cmd4.bind("<Return>", c )
  844. e_cmd4.pack(side="left")
  845. #-------------------------------------------- line
  846. line_frame = Tkinter.Frame(eframe1)
  847. line_frame.pack(side="top",expand=0,fill="x")
  848. Tkinter.Label(line_frame,text="CMD",font=font3,width=6).pack(side="left",expand=0,fill="y")
  849. e_cmd5 = Tkinter.Entry(line_frame,font=font3,width=16)
  850. CMD="REBOOT"
  851. c=SEND_CMD(CMD)
  852. e_cmd5.insert("end",CMD)
  853. e_cmd5.bind("<Return>", c )
  854. e_cmd5.pack(side="left")
  855. def network_listenet():
  856. cprint(sys._getframe().f_code.co_name,color="yellow")
  857. b_scan.insert("end", "log:\n" )
  858. while 1:
  859. #print(".")
  860. if nodescan.node_cmd_buf_list:
  861. msg = str(nodescan.node_cmd_buf_list)
  862. print("read_cmd_buf msg",msg)
  863. nodescan.node_cmd_buf_list = []
  864. stamp = str(time.time())+"\n"
  865. stamp = time.strftime("%Y-%m-%d %X\n")
  866. b_scan.insert("end",stamp)
  867. b_scan.insert("end", msg +"\n")
  868. b_scan.see("end")
  869. time.sleep(0.1)
  870. def update_idletask():
  871. cprint(sys._getframe().f_code.co_name,color="yellow")
  872. while 1:
  873. root.update_idletasks()
  874. time.sleep(1)
  875. def main():
  876. cprint(sys._getframe().f_code.co_name,color="yellow")
  877. thread.start_new_thread(scan, () )
  878. thread.start_new_thread(nodescan.node_cmd_recive, () )
  879. thread.start_new_thread(network_listenet, () )
  880. thread.start_new_thread(update_idletask, () )
  881. #nodescan.bind_cmd_node()
  882. main()
  883. root.mainloop()