Ajusted verbose

This commit is contained in:
dandaedre 2021-10-06 13:16:10 +02:00
parent 34c062c878
commit 249c174341
1 changed files with 54 additions and 42 deletions

View File

@ -12,7 +12,6 @@ from _thread import start_new_thread
_IPSELF = "192.168.0.140" # Could be usefull for multi IP networks _IPSELF = "192.168.0.140" # Could be usefull for multi IP networks
_HOSTS = [("192.168.0.140",10500)] _HOSTS = [("192.168.0.140",10500)]
_VERBOSE=True
_MSGSIZE=4096 _MSGSIZE=4096
_TIMEOUT=4 _TIMEOUT=4
@ -28,22 +27,28 @@ def _SYS_EXIT(system,*args):
system.fatal=True system.fatal=True
sys.exit() sys.exit()
if _VERBOSE:
def dprint(*args): _VERBOSE=2
print(*args)
def spec_print(spec,*args): nopeF=lambda *x:None
dprint("[pAW:{}]".format(spec),*args) #(line@{}) ,sys._getframe().f_lineno def printl(label=""):
def iprint(*args): def _pl(*args):
spec_print("INFO",*args) print(label,*args)
def wprint(*args): return _pl
spec_print("WARNING",*args)
def eprint(*args): eprint=printl("[pAW:ERROR]")
spec_print("ERROR",*args) dprint=nopeF
else: ddprint=nopeF
dprint=_NO_FUNCT iprint=nopeF
wprint=_NO_FUNCT wprint=nopeF
eprint=_NO_FUNCT if _VERBOSE>=1:
iprint=_NO_FUNCT wprint=printl("[pAW:WARNING]")
if _VERBOSE>=2:
iprint=printl("[pAW:INFO]")
if _VERBOSE>=3:
dprint=printl("[pAW:DEBUG]")
if _VERBOSE>=4:
ddprint=printl("[pAW:DDEBUG]")
class pyNope(object): class pyNope(object):
@ -159,18 +164,20 @@ _MATCHS={
"CTqfl":"QUICKFA", #X,1CTqfl "CTqfl":"QUICKFA", #X,1CTqfl
"CTqfa":"QUICKF", #1CTqfa "CTqfa":"QUICKF", #1CTqfa
"PUscu":"SCRNUPD", #1PUscu "PUscu":"SCRNUPD", #1PUscu
"GCfsc":"FREEZE",
"GCfra":"FREEZEALL",
"E":"ERROR" "E":"ERROR"
} }
_ALL_MESSAGE_TYPES=[ _ALL_MESSAGE_TYPES=[
"CONNECT","DEVICE","VERSION","STATUS","KPALIVE","LAYERINP", "CONNECT","DEVICE","VERSION","STATUS","KPALIVE","LAYERINP",
"TAKEAVL","TAKE","TAKEALL","LOADMM","QUICKFA","QUICKF", "TAKEAVL","TAKE","TAKEALL","LOADMM","QUICKFA","QUICKF",
"SCRNUPD", "SCRNUPD","FREEZE","FREEZEALL",
"ERROR" "ERROR"
] ]
_UPDATE_MSG=[ _UPDATE_MSG=[
"LAYERINP","QUICKFA","QUICKF","TAKE","QUICKFA","QUICKF" "LAYERINP","QUICKFA","QUICKF","TAKE","QUICKFA","QUICKF","FREEZE","FREEZEALL",
] ]
# RELOAD_PROGRAM # RELOAD_PROGRAM
# FREEZE_SCREEN # FREEZE_SCREEN
@ -202,15 +209,15 @@ class analogController(object):
self.POSTMATCHACTIONS={i:self.getAttr("POSTMATCH_{}".format(i),self.POSTMATCH_GENERIC) for i in _ALL_MESSAGE_TYPES} self.POSTMATCHACTIONS={i:self.getAttr("POSTMATCH_{}".format(i),self.POSTMATCH_GENERIC) for i in _ALL_MESSAGE_TYPES}
try: try:
iprint('Creating socket') dprint('Creating socket')
self.sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
iprint('Getting remote IP address') dprint('Getting remote IP address')
remote_ip = socket.gethostbyname(_IPSELF) remote_ip = socket.gethostbyname(_IPSELF)
except socket.error: except socket.error:
print('[pAW:ERROR] Failed to create socket') eprint('Failed to create socket')
sys.exit() sys.exit()
except socket.gaierror: except socket.gaierror:
print('[pAW:ERROR] Hostname could not be resolved. Exiting') eprint('Hostname could not be resolved. Exiting')
sys.exit() sys.exit()
def getAttr(self,attribute,default): def getAttr(self,attribute,default):
@ -304,6 +311,7 @@ class analogController(object):
return True return True
return False return False
# def POSTMATCH_TAKEAVL(self,match): # def POSTMATCH_TAKEAVL(self,match):
# "Take available answer 1" # "Take available answer 1"
# if match.group("postargs")[-1]=="1": # if match.group("postargs")[-1]=="1":
@ -324,16 +332,17 @@ class analogController(object):
if typ in _UPDATE_MSG: if typ in _UPDATE_MSG:
return self.feedback.messageReceived(typ,match) return self.feedback.messageReceived(typ,match)
else: else:
wprint("Ignoring message",match) dprint("Ignoring message",match)
return status return status
except RuntimeError as e: except RuntimeError as e:
iprint("Lock [{}] is already released (async terminated earlier)".format(typ)) dprint("Lock [{}] is already released (async terminated earlier)".format(typ))
iprint("This message is either comming from the device or garbage data") dprint("This message is either comming from the device or garbage data")
iprint(e) dprint(e)
except KeyError as e: except KeyError as e:
eprint("There is no lock associated with {}".format(typ)) eprint("There is no lock associated with {}".format(typ))
print(e) print(e)
return False return False
############################################## ##############################################
# LOCKS # LOCKS
def waitLock(self,lockname,function_success=_NO_FUNCT,args_success=(),function_error=_NO_FUNCT,args_error=(),timeout=_TIMEOUT): def waitLock(self,lockname,function_success=_NO_FUNCT,args_success=(),function_error=_NO_FUNCT,args_error=(),timeout=_TIMEOUT):
@ -344,17 +353,17 @@ class analogController(object):
def _initLockWait(self,lockname,function_success=_NO_FUNCT,args_success=(),function_error=_NO_FUNCT,args_error=(),timeout=_TIMEOUT): def _initLockWait(self,lockname,function_success=_NO_FUNCT,args_success=(),function_error=_NO_FUNCT,args_error=(),timeout=_TIMEOUT):
"""Thread waiting for a lock""" """Thread waiting for a lock"""
iprint("Checking for [{}] lock avaivability".format(lockname)) dprint("Checking for [{}] lock avaivability".format(lockname))
if not self._LOCKS[lockname].locked(): #The state it's supposed to be in, but let's not be too sure if not self._LOCKS[lockname].locked(): #The state it's supposed to be in, but let's not be too sure
self._LOCKS[lockname].acquire(timeout=0.01) self._LOCKS[lockname].acquire(timeout=0.01)
# Now wait for the lock to be released # Now wait for the lock to be released
iprint("Acquired [{}] : Locking".format(lockname)) dprint("Acquired [{}] : Locking".format(lockname))
status=self._LOCKS[lockname].acquire(timeout=timeout) status=self._LOCKS[lockname].acquire(timeout=timeout)
if status: if status:
iprint("Lock [{}] passed succesfully".format(lockname)) dprint("Lock [{}] passed succesfully".format(lockname))
function_success(args_success) function_success(args_success)
else: else:
iprint("Failed to aquire [{}]".format(lockname)) eprint("Failed to aquire [{}]".format(lockname))
function_error(args_error) function_error(args_error)
return status return status
@ -363,7 +372,7 @@ class analogController(object):
def genericSEND(self,lock,send,fatal=True,*args,**kwargs): def genericSEND(self,lock,send,fatal=True,*args,**kwargs):
"Generic send and join method, with all the logic on the controler side" "Generic send and join method, with all the logic on the controler side"
iprint("Acquiring {}".format(lock.lower())) dprint("Acquiring {}".format(lock.lower()))
# self.st_takeavailable=[False,False] # ? # self.st_takeavailable=[False,False] # ?
wait=self.waitLock(lock,function_error=_SYS_EXIT,args_error=(self),*args,**kwargs) wait=self.waitLock(lock,function_error=_SYS_EXIT,args_error=(self),*args,**kwargs)
self.sendData(send) self.sendData(send)
@ -502,6 +511,8 @@ class analogController(object):
self.genericSEND("QUICKFA","{action:b}CTqfl".format(action=action)) self.genericSEND("QUICKFA","{action:b}CTqfl".format(action=action))
self.st_quickframeall=action self.st_quickframeall=action
def freezeScreen(self,screen):
""""""
def updateFinished(self,screen): def updateFinished(self,screen):
"""Updates are finished being sent """Updates are finished being sent
<screen>,1PUscu : Updates on screen <screen> are done <screen>,1PUscu : Updates on screen <screen> are done
@ -518,7 +529,7 @@ class analogController(object):
self.connect() self.connect()
self.getDevice() self.getDevice()
self.getVersion() self.getVersion()
# self.getStatus(3) self.getStatus(3)
######################################### #########################################
@ -558,7 +569,7 @@ class analogController(object):
try: try:
iprint ("<<< Received:",message) iprint ("<<< Received:",message)
RX_MTCH=_MESSAGE_REGEX.match(message) RX_MTCH=_MESSAGE_REGEX.match(message)
iprint("preargs:{} - msg:{} - postargs:{}".format(RX_MTCH.group("preargs"),RX_MTCH.group("msg"),RX_MTCH.group("postargs"))) dprint("preargs:{} - msg:{} - postargs:{}".format(RX_MTCH.group("preargs"),RX_MTCH.group("msg"),RX_MTCH.group("postargs")))
start_new_thread(self.processMatch,(RX_MTCH,)) # Here lies the problem, damned if I do, damned if I don't start_new_thread(self.processMatch,(RX_MTCH,)) # Here lies the problem, damned if I do, damned if I don't
except AttributeError as e: except AttributeError as e:
eprint("Regex couldn't find a match") eprint("Regex couldn't find a match")
@ -636,14 +647,15 @@ if __name__ == '__main__':
# except KeyboardInterrupt: # except KeyboardInterrupt:
# ctrl1.close() # ctrl1.close()
ctrl1.changeLayer(0,0,1,1)
import random # import random
while True: # while True:
ctrl1.changeLayer(0,1,1,random.randint(0,7)) # ctrl1.changeLayer(0,1,1,random.randint(0,7))
ctrl1.updateFinishedAll() # ctrl1.updateFinishedAll()
ctrl1.takeAvailableAll() # ctrl1.takeAvailableAll()
ctrl1.takeAll() # ctrl1.takeAll()
input(">>>") # input(">>>")
# time.sleep(1) # time.sleep(1)
# # ctrl1.takeAvailable((1,)) # # ctrl1.takeAvailable((1,))
# # take(self,screen) # # take(self,screen)