Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # !/usr/bin/python
- import time
- import serial
- from xml.dom import minidom
- import os
- import xml.etree.ElementTree as ET
- # Global variables
- # bcast, loopvalue and zmode will hold the previous values
- bcast = ""
- loopvalue = ""
- zmode = []
- ton = []
- toff = []
- tdim = []
- # newbcast, newloopvalue and newzmode will hold the current values and compare it with bcast and loopvalue for change
- newbcast = ""
- newloopvalue = ""
- newzmode = []
- newton = []
- newtoff = []
- newtdim = []
- # Try variables are used for counting number of tries made
- autotry = 0
- autotry1 = 0
- overtry = 0
- overtry1 = 0
- timeontry = 0
- timeonetry1 = 0
- timeofftry = 0
- timeofftry1 = 0
- dimtry = 0
- dimtry1 = 0
- bcasttry = 0
- bcasttry1 = 0
- discoverytry = 0
- discoverytry1 = 0
- looptry = 0
- # Class to run only once at the start - to get and assign the initial values for bcast and loopvalue.
- # Source: https://stackoverflow.com/questions/29764090/how-to-call-a-function-only-once-in-python/29764355
- class CallOnce(object):
- called = False
- def service(cls):
- if cls.called:
- print "Already Called"
- return
- else:
- # Get Broadcast Value
- mydoc = minidom.parse("/var/www/html/bcast.xml")
- values=mydoc.getElementsByTagName('mode')
- for elem in values:
- x = elem.firstChild.data
- global bcast
- bcast=int(x)
- # Get Loop Value
- tree = ET.parse('/var/www/html/ZoneUp.xml')
- root = tree.getroot()
- for child in root:
- # print(child.tag, child.text)
- if child.tag == 'LoopFlag':
- global loopvalue
- loopvalue = int(child.text)
- tree = ET.parse('/var/www/html/LoopInfo.xml')
- root = tree.getroot()
- global zmode
- global ton
- global toff
- global tdim
- for child in root:
- # print(child.tag, child.text)
- for i in range(1,13):
- zmodestr = 'Z'+str(i)+'Mode'
- zton = 'Z'+str(i)+'TimeOn'
- ztof = 'Z'+str(i)+'TimeOff'
- zdim = 'Z'+str(i)+'Dim'
- # print zmodestr
- if child.tag == zmodestr:
- zmode.append(int(child.text))
- # print zmode[i-1]
- elif child.tag == zton:
- ton.append(int(child.text))
- # print ton[i-1]
- elif child.tag == ztof:
- toff.append(int(child.text))
- # print toff[i-1]
- elif child.tag == zdim:
- tdim.append(int(child.text))
- # print tdim[i-1]
- cls.called = True
- # For troubleshooting enable this display
- # display()
- return
- # Function to get new values of Broadcast and Loop
- def newval():
- mydoc = minidom.parse("/var/www/html/bcast.xml")
- values=mydoc.getElementsByTagName('mode')
- for elem in values:
- x = elem.firstChild.data
- global newbcast
- newbcast=int(x)
- tree = ET.parse('/var/www/html/ZoneUp.xml')
- root = tree.getroot()
- for child in root:
- # print(child.tag, child.text)
- if child.tag == 'LoopFlag':
- global newloopvalue
- newloopvalue = int(child.text)
- tree = ET.parse('/var/www/html/LoopInfo.xml')
- root = tree.getroot()
- global newzmode
- global newton
- global newtoff
- global newtdim
- newzmode = []
- newton = []
- newtoff = []
- newtdim = []
- for child in root:
- # print(child.tag, child.text)
- for i in range(1,13):
- newzmodestr = 'Z'+str(i)+'Mode'
- newzton = 'Z'+str(i)+'TimeOn'
- newztof = 'Z'+str(i)+'TimeOff'
- newzdim = 'Z'+str(i)+'Dim'
- # print newzmodestr
- if child.tag == newzmodestr:
- newzmode.append(int(child.text))
- # print newzmode
- elif child.tag == newzton:
- newton.append(int(child.text))
- # print ton[i-1]
- elif child.tag == newztof:
- newtoff.append(int(child.text))
- # print toff[i-1]
- elif child.tag == newzdim:
- newtdim.append(int(child.text))
- # print tdim[i-1]
- return
- # Function to display old values
- def display():
- print("Old")
- print(bcast)
- print(loopvalue)
- print(zmode)
- print(ton)
- print(toff)
- print(tdim)
- # Function to display new values
- def newdisplay():
- print("New")
- print(newbcast)
- print(newloopvalue)
- print(newzmode)
- print(newton)
- print(newtoff)
- print(newtdim)
- # Function to do Broadcast On/Off
- def broad():
- # print "Starting Program"
- global bcast
- global bcasttry
- global bcasttry1
- bcast = 0
- bcasttry = 0
- bcasttry1 = 0
- ser = serial.Serial('/dev/ttyAMA0', baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS)
- tree = ET.parse('/var/www/html/bcast.xml')
- root = tree.getroot()
- for child in root:
- for mode in child:
- x = mode.text
- y=int(x)
- # print(y)
- if y == 0:
- os.system("echo \"\x02\x02\x09\x09\x0D\" > /dev/ttyAMA0")
- # print 'Broadcast Off Sent'
- time.sleep(.5)
- data_left1=ser.inWaiting()
- # print data_left1
- # print bcasttry
- # Check whether there is response or not - 0 indicates No Response and 3 Retries are made
- if data_left1 == 0:
- while (bcasttry < 3):
- if data_left1 == 0:
- # print bcasttry
- bcasttry = bcasttry + 1
- os.system("echo \"\x02\x02\x09\x09\x0D\" > /dev/ttyAMA0")
- time.sleep(.5)
- data_left=ser.inWaiting()
- # On 3 successful retries to get any response, Mode is updated with 3
- # print bcasttry
- if bcasttry == 3:
- tree = ET.parse('/var/www/html/bcast.xml')
- root = tree.getroot()
- for child in root:
- for mode in child:
- mode.text = '3'
- tree.write("/var/www/html/bcast.xml")
- bcastupdate()
- display()
- else:
- data = ser.readline()
- bcastfind = data.encode('hex')
- # If data is received, check whether the data is same as sent
- if bcastfind != '020209090d0a':
- while (bcasttry1 < 3):
- # If same break else retry 3 times
- if bcastfind == '020209090d0a':
- break
- else:
- bcasttry1 = bcasttry1 + 1
- os.system("echo \"\x02\x02\x09\x09\x0D\" > /dev/ttyAMA0")
- # print 'Bcast Sent'
- data = ser.readline()
- bcastfind = data.encode('hex')
- # On 3 successful retries to get proper response, Mode is updated with 4
- if bcasttry1 == 3:
- tree = ET.parse('/var/www/html/bcast.xml')
- root = tree.getroot()
- for child in root:
- for mode in child:
- mode.text = '4'
- tree.write("/var/www/html/bcast.xml")
- bcastupdate()
- display()
- else:
- os.system("echo \"\x02\x02\x08\x08\x0D\" > /dev/ttyAMA0")
- # print 'Broadcast Off Sent'
- time.sleep(.5)
- data_left1=ser.inWaiting()
- # print data_left1
- # print bcasttry
- # Check whether there is response or not - 0 indicates No Response and 3 Retries are made
- if data_left1 == 0:
- while (bcasttry < 3):
- if data_left1 == 0:
- # print bcasttry
- bcasttry = bcasttry + 1
- os.system("echo \"\x02\x02\x08\x08\x0D\" > /dev/ttyAMA0")
- time.sleep(.5)
- data_left=ser.inWaiting()
- # On 3 successful retries to get any response, Mode is updated with 3
- # print bcasttry
- if bcasttry == 3:
- tree = ET.parse('/var/www/html/bcast.xml')
- root = tree.getroot()
- for child in root:
- for mode in child:
- mode.text = '3'
- tree.write("/var/www/html/bcast.xml")
- bcastupdate()
- display()
- else:
- data = ser.readline()
- bcastfind = data.encode('hex')
- # If data is received, check whether the data is same as sent
- if bcastfind != '020208080d0a':
- while (bcasttry1 < 3):
- if bcastfind == '020208080d0a':
- break
- else:
- bcasttry1 = bcasttry1 + 1
- os.system("echo \"\x02\x02\x08\x08\x0D\" > /dev/ttyAMA0")
- # print 'Bcast Sent'
- data = ser.readline()
- bcastfind = data.encode('hex')
- # On 3 successful retries to get proper response, Mode is updated with 4
- if bcasttry1 == 3:
- tree = ET.parse('/var/www/html/bcast.xml')
- root = tree.getroot()
- for child in root:
- for mode in child:
- mode.text = '4'
- tree.write("/var/www/html/bcast.xml")
- bcastupdate()
- display()
- # Function to do Discovery and Update XML
- def discov():
- # print "Starting Program"
- ser = serial.Serial('/dev/ttyAMA0', baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS)
- # time.sleep(1)
- try:
- global discoverytry
- global discoverytry1
- discoverytry = 0
- discoverytry1 = 0
- os.system("echo \"\x02\x02\x03\x03\x0D\" > /dev/ttyAMA0")
- # print 'Discovery Sent'
- time.sleep(.5)
- data_left=ser.inWaiting()
- # print data_left
- # print discoverytry
- # Check whether there is response or not - 0 indicates No Response and 3 Retries are made
- if data_left == 0:
- while (discoverytry < 3):
- if data_left == 0:
- # print discoverytry
- discoverytry = discoverytry + 1
- os.system("echo \"\x02\x02\x03\x03\x0D\" > /dev/ttyAMA0")
- time.sleep(.5)
- data_left=ser.inWaiting()
- # On 3 successful retries to get any response, Loopvalue is updated with 512
- # print discoverytry
- if discoverytry == 3:
- # print data_left
- tree = ET.parse('/var/www/html/ZoneUp.xml')
- root = tree.getroot()
- for child in root:
- # print(child.tag, child.text)
- if child.tag == 'LoopFlag':
- child.text = '512'
- tree.write("/var/www/html/ZoneUp.xml")
- # print(child.tag, child.text)
- # print 'No Error'
- disupdate()
- display()
- else:
- data1 = ser.read(data_left)
- discover = data1.encode('hex')
- # print discover
- # If data is received, check whether the data is same as sent
- if discover != '020203030d0a':
- while (discoverytry1 < 3):
- if discover == '020203030d0a':
- break
- else:
- discoverytry1 = discoverytry1 + 1
- os.system("echo \"\x02\x02\x03\x03\x0D\" > /dev/ttyAMA0")
- # print 'Discovery Sent'
- data1 = ser.readline()
- discover = data1.encode('hex')
- # On 3 successful retries to get proper response, Loopvalue is updated with 1024
- if discoverytry1 == 3:
- tree = ET.parse('/var/www/html/ZoneUp.xml')
- root = tree.getroot()
- for child in root:
- # print(child.tag, child.text)
- if child.tag == 'LoopFlag':
- child.text = '1024'
- tree.write("/var/www/html/ZoneUp.xml")
- # print(child.tag, child.text)
- # print 'No Error'
- disupdate()
- display()
- else:
- time.sleep(5)
- os.system("echo \"\x02\x02\x88\x88\x0D\" > /dev/ttyAMA0")
- # print 'Get Info Sent'
- while True:
- time.sleep(1)
- if ser.inWaiting() > 0:
- data = ser.readline()
- # print data
- loop = data.encode('hex')
- loopvalue = loop[6:8]
- # print loopvalue
- if loopvalue == '01':
- os.system("echo \"\x02\x02\x88\x88\x0D\" > /dev/ttyAMA0")
- else:
- tree = ET.parse('/var/www/html/ZoneUp.xml')
- root = tree.getroot()
- for child in root:
- # print(child.tag, child.text)
- if child.tag == 'LoopFlag':
- x = int(loopvalue)
- # print x
- y = str(x)
- # print y
- child.text = y
- tree.write("/var/www/html/ZoneUp.xml")
- # print(child.tag, child.text)
- # print 'No Error'
- break
- else:
- # If the response is 0 - then 3 retires are made, failing will update Loopvalue to 2048
- global looptry
- looptry = looptry + 1
- if looptry == 3:
- tree = ET.parse('/var/www/html/ZoneUp.xml')
- root = tree.getroot()
- for child in root:
- # print(child.tag, child.text)
- if child.tag == 'LoopFlag':
- child.text = '2048'
- tree.write("/var/www/html/ZoneUp.xml")
- break
- else:
- os.system("echo \"\x02\x02\x88\x88\x0D\" > /dev/ttyAMA0")
- except KeyboardInterrupt:
- print "Exiting Program"
- except:
- print "Error Occurs"
- return
- finally:
- ser.close()
- pass
- # Function to do Zmode Data and Update XML
- def zmodefun(val):
- ser = serial.Serial('/dev/ttyAMA0', baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS)
- global zmode
- global ton
- global toff
- global tdim
- global newzmode
- global newton
- global newtoff
- global newtdim
- global autotry
- global autotry1
- global overtry
- global overtry1
- global timeontry
- global timeonetry1
- global timeofftry
- global timeofftry1
- global dimtry
- global dimtry1
- if newzmode[val] < 128:
- if len(hex(int(val)+1)) == 3:
- hexval = hex((int(val)+1))
- hexval = hexval[1:2]+'0'+hexval[-1]
- hexval = hexval.upper()
- hexval = '0'+hexval
- # print hexval
- if len(hex(newzmode[val])) == 3:
- hexmode = hex(newzmode[val])
- hexmode = hexmode[1:2]+'0'+hexmode[-1]
- hexmode = hexmode.upper()
- hexmode = '0'+hexmode
- # print hexmode
- else:
- hexmode = hex(newzmode[val])
- hexmode = hexmode.upper()
- # print hexmode
- valcheck = 21+int(val)+1+newzmode[val]
- hexvalcheck = hex(valcheck)
- hexvalcheck = hexvalcheck[1:]
- hexvalcheck = hexvalcheck.upper()
- hexvalcheck = '0'+hexvalcheck
- if len(hexvalcheck) == 3:
- hexvalcheck = hexvalcheck[1:2]+'0'+hexvalcheck[-1]
- hexvalcheck = hexvalcheck.upper()
- hexvalcheck = '0'+hexvalcheck
- # print hexvalcheck
- cmd=['0x02','0x04','0x15',hexval,hexmode,hexvalcheck,'0x0D','0x0A']
- print (cmd)
- incmd = [int(h, base=16) for h in cmd]
- ser.write(serial.to_bytes(incmd))
- time.sleep(.5)
- data_left=ser.inWaiting()
- zmodestr = 'Z'+str(val+1)+'Mode'
- # Check whether there is response or not - 0 indicates No Response and 3 Retries are made
- x = bin(newzmode[val])
- timecheck = x[-1:]
- if timecheck == '1':
- # print timecheck
- if ton[val] != newton[val] or toff[val] != newtoff[val]:
- print 'Time Sent - '+str(val+1)
- if len(hex(int(val+1))) == 3:
- hexi = hex(i)
- hexi = hexi[1:2]+'0'+hexi[-1]
- hexi = hexi.upper()
- hexi = '0'+hexi
- # print hexi
- decton = newton[val]
- if len(hex(int(decton))) == 3:
- hexton = hex(int(decton))
- hexton = hexton[1:2]+'0'+hexton[-1]
- hexton = hexton.upper()
- hexton = '0'+hexton
- # print hexton
- else:
- hexton = hex(int(decton))
- hexton = hexton[1:]
- hexton = hexton.upper()
- hexton = '0'+hexton
- # print hexton
- dectoff = newtoff[val]
- if len(hex(int(dectoff))) == 3:
- hextof = hex(int(dectoff))
- hextof = hextof[1:2]+'0'+hextof[-1]
- hextof = hextof.upper()
- hextof = '0'+hextof
- # print hextof
- else:
- hextof = hex(int(dectoff))
- hextof = hextof[1:]
- hextof = hextof.upper()
- hextof = '0'+hextof
- # print hexton
- check = 17+i+int(decton)+int(dectoff)
- if len(hex(check)) == 3:
- hexcheck = hex(check)
- hexcheck = hexcheck[1:2]+'0'+hexcheck[-1]
- hexcheck = hexcheck.upper()
- hexcheck = '0'+hexcheck
- # print hexcheck
- else:
- hexcheck = hex(check)
- hexcheck = hexcheck[1:]
- hexcheck = hexcheck.upper()
- hexcheck = '0'+hexcheck
- # print hexcheck
- cmd=['0x02','0x07','0x11',hexi,hexton,'0x00',hextof,'0x00',hexcheck,'0x0D','0x0A']
- print (cmd)
- incmd = [int(h, base=16) for h in cmd]
- ser.write(serial.to_bytes(incmd))
- zmodeupdate(val)
- else:
- print 'No Time Change - '+str(val+1)
- # break
- else:
- print 'Time Disabled - '+str(val+1)
- dimcheck = x[-7:-6]
- if dimcheck == '1':
- # print dimcheck
- if tdim[val] != newtdim[val]:
- print 'Dim Sent - '+str(val+1)
- if len(hex(int(val+1))) == 3:
- hexi = hex(k)
- hexi = hexi[1:2]+'0'+hexi[-1]
- hexi = hexi.upper()
- hexi = '0'+hexi
- # print hexi
- decdim = newtdim[val]
- if len(hex(int(decdim))) == 3:
- hexdim = hex(int(decdim))
- hexdim = hexdim[1:2]+'0'+hexdim[-1]
- hexdim = hexdim.upper()
- hexdim = '0'+hexdim
- # print hexdim
- else:
- hexdim = hex(int(decdim))
- hexdim = hexdim[1:]
- hexdim = hexdim.upper()
- hexdim = '0'+hexdim
- # print hexdim
- check = 23+i+int(decdim)
- if len(hex(check)) == 3:
- hexcheck = hex(check)
- hexcheck = hexcheck[1:2]+'0'+hexcheck[-1]
- hexcheck = hexcheck.upper()
- hexcheck = '0'+hexcheck
- # print hexcheck
- else:
- hexcheck = hex(check)
- hexcheck = hexcheck[1:]
- hexcheck = hexcheck.upper()
- hexcheck = '0'+hexcheck
- # print hexcheck
- cmd=['0x02','0x04','0x17',hexi,hexdim,hexcheck,'0x0D','0x0A']
- print (cmd)
- incmd = [int(h, base=16) for h in cmd]
- ser.write(serial.to_bytes(incmd))
- zmodeupdate(val)
- elif tdim[val] == newtdim[val]:
- print 'No Dim Change - '+str(val+1)
- # break
- else:
- print 'Dim Disabled - '+str(val+1)
- else:
- if zmode[val] != newzmode[val]:
- print 'Override - ',newzmode[i-1]
- if len(hex(int(val)+1)) == 3:
- hexval = hex((int(val)+1))
- hexval = hexval[1:2]+'0'+hexval[-1]
- hexval = hexval.upper()
- hexval = '0'+hexval
- # print hexval
- if len(hex(newzmode[val])) == 3:
- hexmode = hex(newzmode[val])
- hexmode = hexmode[1:2]+'0'+hexmode[-1]
- hexmode = hexmode.upper()
- hexmode = '0'+hexmode
- # print hexmode
- else:
- hexmode = hex(newzmode[val])
- hexmode = hexmode.upper()
- # print hexmode
- valcheck = 21+int(val)+1+newzmode[val]
- hexvalcheck = hex(valcheck)
- hexvalcheck = hexvalcheck[1:]
- hexvalcheck = hexvalcheck.upper()
- hexvalcheck = '0'+hexvalcheck
- if len(hexvalcheck) == 3:
- hexvalcheck = hexvalcheck[1:2]+'0'+hexvalcheck[-1]
- hexvalcheck = hexvalcheck.upper()
- hexvalcheck = '0'+hexvalcheck
- # print hexvalcheck
- cmd=['0x02','0x04','0x15',hexval,hexmode,hexvalcheck,'0x0D','0x0A']
- print (cmd)
- incmd = [int(h, base=16) for h in cmd]
- ser.write(serial.to_bytes(incmd))
- # break
- # Function to do Zmode Data and Update XML
- def zmodefuncheck(val):
- ser = serial.Serial('/dev/ttyAMA0', baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS)
- tree = ET.parse('/var/www/html/LoopInfo.xml')
- root = tree.getroot()
- zmodestr = 'Z'+str(val+1)+'Mode'
- zton = 'Z'+str(val+1)+'TimeOn'
- ztof = 'Z'+str(val+1)+'TimeOff'
- zdim = 'Z'+str(val+1)+'Dim'
- global ton
- global toff
- global tdim
- global newzmode
- global newton
- global newtoff
- global newtdim
- x = bin(newzmode[val])
- timecheck = x[-1:]
- if timecheck == '1':
- # print timecheck
- if ton[val] != newton[val] or toff[val] != newtoff[val]:
- print 'Auto Time Sent - '+str(val+1)
- if len(hex(int(val+1))) == 3:
- hexi = hex(int(val+1))
- hexi = hexi[1:2]+'0'+hexi[-1]
- hexi = hexi.upper()
- hexi = '0'+hexi
- # print hexi
- decton = newton[val]
- if len(hex(int(decton))) == 3:
- hexton = hex(int(decton))
- hexton = hexton[1:2]+'0'+hexton[-1]
- hexton = hexton.upper()
- hexton = '0'+hexton
- # print hexton
- else:
- hexton = hex(int(decton))
- hexton = hexton[1:]
- hexton = hexton.upper()
- hexton = '0'+hexton
- # print hexton
- dectoff = newtoff[val]
- if len(hex(int(dectoff))) == 3:
- hextof = hex(int(dectoff))
- hextof = hextof[1:2]+'0'+hextof[-1]
- hextof = hextof.upper()
- hextof = '0'+hextof
- # print hextof
- else:
- hextof = hex(int(dectoff))
- hextof = hextof.upper()
- hextof = hextof[1:]
- hextof = '0'+hextof
- # print hexton
- check = 17+i+int(decton)+int(dectoff)
- if len(hex(check)) == 3:
- hexcheck = hex(check)
- hexcheck = hexcheck[1:2]+'0'+hexcheck[-1]
- hexcheck = hexcheck.upper()
- hexcheck = '0'+hexcheck
- # print hexcheck
- else:
- hexcheck = hex(check)
- hexcheck = hexcheck[1:]
- hexcheck = hexcheck.upper()
- hexcheck = '0'+hexcheck
- # print hexcheck
- cmd=['0x02','0x07','0x11',hexi,hexton,'0x00',hextof,'0x00',hexcheck,'0x0D','0x0A']
- print (cmd)
- incmd = [int(h, base=16) for h in cmd]
- ser.write(serial.to_bytes(incmd))
- zmodeupdate(val)
- # else:
- # print 'No Auto Time Change - '+str(val+1)
- # break
- else:
- print 'Auto Time Disabled - '+str(val+1)
- # break
- x = bin(newzmode[val])
- dimcheck = x[-7:-6]
- if dimcheck == '1':
- # print dimcheck
- if tdim[val] != newtdim[val]:
- print 'Auto Dim Sent - '+str(val+1)
- if len(hex(int(val+1))) == 3:
- hexi = hex(int(val+1))
- hexi = hexi[1:2]+'0'+hexi[-1]
- hexi = hexi.upper()
- hexi = '0'+hexi
- # print hexi
- decdim = newtdim[val]
- if len(hex(int(decdim))) == 3:
- hexdim = hex(int(decdim))
- hexdim = hexdim[1:2]+'0'+hexdim[-1]
- hexdim = hexdim.upper()
- hexdim = '0'+hexdim
- # print hexdim
- else:
- hexdim = hex(int(decdim))
- hexdim = hexdim[1:]
- hexdim = hexdim.upper()
- hexdim = '0'+hexdim
- # print hexdim
- check = 23+i+int(decdim)
- if len(hex(check)) == 3:
- hexcheck = hex(check)
- hexcheck = hexcheck[1:2]+'0'+hexcheck[-1]
- hexcheck = hexcheck.upper()
- hexcheck = '0'+hexcheck
- # print hexcheck
- else:
- hexcheck = hex(check)
- hexcheck = hexcheck[1:]
- hexcheck = hexcheck.upper()
- hexcheck = '0'+hexcheck
- # print hexcheck
- cmd=['0x02','0x04','0x17',hexi,hexdim,hexcheck,'0x0D','0x0A']
- print (cmd)
- incmd = [int(h, base=16) for h in cmd]
- ser.write(serial.to_bytes(incmd))
- zmodeupdate(val)
- # elif tdim[val] == newtdim[val]:
- # print 'No Auto Dim Change - '+str(val+1)
- # break
- else:
- print 'Auto Dim Disabled - '+str(val+1)
- # break
- # In Broadcast, After change is found, The function carried out, Old values are updated so that they can be used as new values to check for changes
- def bcastupdate():
- mydoc = minidom.parse("/var/www/html/bcast.xml")
- values=mydoc.getElementsByTagName('mode')
- for elem in values:
- x = elem.firstChild.data
- global bcast
- bcast = int(x)
- # In Discovery, After change is found, The function carried out, Old values are updated so that they can be used as new values to check for changes
- def disupdate():
- tree = ET.parse('/var/www/html/ZoneUp.xml')
- root = tree.getroot()
- for child in root:
- # print(child.tag, child.text)
- if child.tag == 'LoopFlag':
- global loopvalue
- loopvalue = int(child.text)
- # In Zmode, After change is found, The function carried out, Old values are updated so that they can be used as new values to check for changes
- def zmodeupdate(val):
- tree = ET.parse('/var/www/html/LoopInfo.xml')
- root = tree.getroot()
- global zmode
- global ton
- global toff
- global tdim
- global newzmode
- global newton
- global newtoff
- global newtdim
- for child in root:
- # print(child.tag, child.text)
- zmodestr = 'Z'+str(val+1)+'Mode'
- # print zmodestr
- for i in range(1,13):
- # print zmodestr
- if child.tag == zmodestr and val == i-1:
- # print zmodestr
- # print zmode[i-1]
- zmode[i-1] = int(newzmode[i-1])
- ton[i-1] = int(newton[i-1])
- toff[i-1] = int(newtoff[i-1])
- tdim[i-1] = int(newtdim[i-1])
- # Call only once in the entire Program
- call_once_object = CallOnce()
- call_once_object.service()
- display()
- # Infinite Loop
- while True:
- time.sleep(.1)
- # print("Start")
- newval()
- # newdisplay()
- # Check whether Broadcast Change is there are not
- if newbcast != bcast:
- print("Bcast Change")
- bcast = newbcast
- broad()
- bcastupdate()
- # Check whether Discover Change is there are not
- elif newloopvalue != loopvalue:
- tem=int(newloopvalue)
- if tem == 1:
- # If Discovery change is detected, is it for Discovery
- print("Loop Change - Discover")
- discov()
- disupdate()
- else:
- print("Loop Change")
- disupdate()
- for i in range(0,12):
- # print zmode[i]," - ",newzmode[i]
- if zmode[i] != newzmode[i]:
- print "Zmode Change - ",i+1
- zmodefun(i)
- zmodeupdate(i)
- elif zmode[i] < 128:
- print "Zmode Auto - ",i+1
- zmodefuncheck(i)
- else:
- print("No Change")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement