TK-Nodescanner.py 29 KB

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