print ("Aspect script running")
rakoip = "192.168.10.231"
nadip = "192.168.10.173"
volume="NA"
codec="NA"
mode="None"
channels="NA"
rate="NA"
display = False
mute="NA"
screencommands = {
"178": "3",
"185": "4",
"200": "5",
"220": "2",
"235": "6",
"240": "1",
}
rakocommand = rakoip + "/rako.cgi?room=10&ch=0&com="
print ("import serial")
import serial
print ("import urllib.request")
import urllib.request
print ("import datetime")
import datetime
print ("import time")
import time
print ("import jvc")
from jvc_command import(JVCCommand, Command, PictureMode)
print ("import thread")
import _thread
print ("import telnetlib")
import telnetlib
def checkNAD ():
global volume
global codec
global mode
global channels
global rate
global display
global mute
tn = telnetlib.Telnet(nadip)
tn.write (b'Main.Volume=?\n')
tn.write (b'Main.Audio.CODEC=\n')
tn.write (b'Main.ListeningMode=\n')
tn.write (b'Main.Audio.Channels=\n')
tn.write (b'Main.Audio.Rate=\n')
tn.write (b'Main.Mute=?\n')
while True:
line=(tn.read_until(b'\n')).decode("utf-8").strip()
# print ("Stripped telnet line: "+line)
command=line.partition('=')[0]
value=line.partition('=')[2]
print ("NAD command= "+command + " value= " +value)
if command == "Main.Mute":
if value != mute:
mute = value
display = True
if command == "Main.Volume":
if value != volume:
volume = value
display = True
if command=="Main.Audio.Channels":
channels=value
if command=="Main.Audio.CODEC":
codec=value
if command=="Main.ListeningMode":
if value != mode:
# display = True
mode=value
if command=="Main.Audio.Rate":
rate=value
def isNotBlank (myString):
if myString and myString.strip():
#myString is not None AND myString is not empty or blank
return True
#myString is None OR myString is empty or blank
return False
def setHDR (HDR):
retries=15
while retries >0:
retry = 0
retries = retries -1
try:
with JVCCommand() as jvc:
if HDR == "0":
print ("JVC Set SDR")
user_mode = jvc.set(Command.PictureMode,PictureMode.User1)
else:
print ("JVC Set HDR")
user_mode = jvc.set(Command.PictureMode,PictureMode.User2)
# jvc.close()
except Exception as E:
print ("JVC exception:",E," retries remaining:",retries)
retry = 1
if retry == 0:
retries = 0
time.sleep (1)
ser = serial.Serial('/dev/ttyUSB0',9600,timeout=0.1 ) # open serial port
#set OSD colours
#osdStr='ZY4180000000\r\n'
#ser.write(bytes(osdStr,'ascii'))
#osdStr='ZY4181FFFFFF\r\n'
#ser.write(bytes(osdStr,'ascii'))
#osdStr='ZY4182000004\r\n'
#ser.write(bytes(osdStr,'ascii'))
_thread.start_new_thread (checkNAD,())
prevHDR = ""
while True:
time.sleep(0.1)
line = None
line = ser.readline()
if len(line)!=0:
line = str (line)
print ("Serial line: " + line)
command = ""
arguments = ""
foundcmd = False
endcmd = False
for char in line:
if endcmd:
arguments = arguments + char
if foundcmd and not endcmd:
if char not in ',':
command = command + char
else:
endcmd = True
if not foundcmd:
if char in '!':
foundcmd = True
# print ("Lumagen command: " + command)
# print "Lumagen arguments: " + arguments
if command == "I22":
#set OSD colours
# osdStr='ZY4180000000\n'
# ser.write(bytes(osdStr,'ascii'))
# osdStr='ZY4181FFFFFF\n'
# ser.write(bytes(osdStr,'ascii'))
# osdStr='ZY4182000004\n'
# ser.write(bytes(osdStr,'ascii'))
# print ("found v2 status report")
# osdStr='ZY520A\n'
# ser.write(bytes(osdStr,'ascii'))
osdStr='ZQO01\n'
ser.write(bytes(osdStr,'ascii'))
aspect = ""
HDR = ""
argnum = 7
currentarg = 1
argument = ""
for char in arguments:
if char not in ',' and currentarg == argnum:
argument = argument + char
if char in ',':
currentarg = currentarg + 1
aspect = argument
argnum = 17
currentarg = 1
argument = ""
for char in arguments:
if char not in ',' and currentarg == argnum:
argument = argument + char
if char in ',':
currentarg = currentarg + 1
HDR = argument
currentDT = datetime.datetime.now()
printDT = (currentDT.strftime("%Y-%m-%d %H:%M:%S"))
print (printDT + " Aspect: " + aspect + " HDR: " + HDR)
if screencommands.get (aspect):
url = "http://" + rakocommand + screencommands.get (aspect)
# print ("URL to get: " + url)
try:
with urllib.request.urlopen (url) as response:
contents = response.read()
except:
print ("Error accessing screen controller")
if HDR != prevHDR:
prevHDR = HDR
# setHDR (HDR)
_thread.start_new_thread (setHDR,(HDR,))
# time.sleep (15)
time.sleep (0.1)
if display == True:
display = False
if mute == "On":
ostring = "[MUTE]"
else:
ostring = volume
ostring = ostring + " " + codec
if channels != "Object":
ostring = ostring + "(" + channels + ")"
ostring = ostring.center (30)
if mode != "None":
ostring = ostring + mode.center(30) + "\n"
else:
ostring = ostring + "\n"
ostring = "ZT1" + ostring
ser.write(bytes(ostring,'ascii'))