Added some postmatch shenennigans

This commit is contained in:
Maximilien Rigaut 2021-09-30 23:11:43 +02:00
parent 193e790a51
commit b170db9be6
3 changed files with 53 additions and 67 deletions

View File

@ -1,8 +1,6 @@
# pythonAnalogWay # pythonAnalogWay
Python binds for analogway controllers Python binds for analogway controllers
* TODO : Do a prefilter on the messages in order not to saturate the gui/rebind with calls for things that are not actually done
* TODO : Verbosity levels * TODO : Verbosity levels
* TODO : Do something with all the value obtained * TODO : Do something with all the value obtained
* TODO : Add a custom .release method to finetune everything * TODO : Add a custom .release method to finetune everything

View File

@ -62,6 +62,23 @@ class pyNope(object):
def __getattr__(self,*args,**kwargs): def __getattr__(self,*args,**kwargs):
return self return self
class pyYep(object):
def __init__(self,*args,**kwargs):
pass
def __call__(self,*args,**kwargs):
return True
def __repr__(self,*args,**kwargs):
return "1"
def __getattr__(self,arg):
return True
def __equals__(self,*args):
return True
def __true__(self,*args):
return True
################################ ################################
# VARIABLES # VARIABLES
@ -141,6 +158,10 @@ _MATCHS={
"PRinp":"LAYERINP", "PRinp":"LAYERINP",
} }
_ALL_MESSAGE_TYPES=[
"CONNECT","DEVICE","VERSION","STATUS","KPALIVE","LAYERINP",
"takeAvailable","take","takeAll","loadMM","quickFrame","quickFrameAll"
]
################################ ################################
# CLASS DEFINITIONS # CLASS DEFINITIONS
@ -160,23 +181,18 @@ class analogController(object):
# #
self.feedback=feedbackInterface # Feedback interface gui or midiRebind self.feedback=feedbackInterface # Feedback interface gui or midiRebind
self._LOCKS={i:threading.Lock() for i in [ self._LOCKS={i:threading.Lock() for i in _ALL_MESSAGE_TYPES} #LAYERINP could actually be a huge clusterlock, not for now tho
"CONNECT","DEVICE","VERSION","STATUS","KPALIVE","LAYERINP", # for i in range(2):
"takeAvailable","take","takeAll","loadMM","quickFrame","quickFrameAll" # for j in range(2):
]} #LAYERINP could actually be a huge clusterlock, not for now tho # for k in range(8):
for i in range(2): # self._LOCKS["LAYERINP{}_{}_{}".format(i,j,k)]=threading.Lock()
for j in range(2): self.POSTMATCHACTIONS={i:self.getAttr("POSTMATCH_{}".format(i),pyYep()) for i in _ALL_MESSAGE_TYPES}
for k in range(8):
self._LOCKS["LAYERINP{}_{}_{}".format(i,j,k)]=threading.Lock()
self._LOCKS{}
try: try:
iprint('Creating socket') iprint('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') iprint('Getting remote IP address')
host=_IPSELF remote_ip = socket.gethostbyname(_IPSELF)
remote_ip = socket.gethostbyname( host )
except socket.error: except socket.error:
print('[pAW:ERROR] Failed to create socket') print('[pAW:ERROR] Failed to create socket')
sys.exit() sys.exit()
@ -184,26 +200,44 @@ class analogController(object):
print('[pAW:ERROR] Hostname could not be resolved. Exiting') print('[pAW:ERROR] Hostname could not be resolved. Exiting')
sys.exit() sys.exit()
def getAttr(self,attribute,default):
"A custom attribute fetcher"
try:
return self.__getattribute__(attribute)
except:
return default
################################
# RECEIVE ANALISIS
# POSTMATCH_CONNECT POSTMATCH_DEVICE POSTMATCH_VERSION POSTMATCH_KPALIVE
def POSTMATCH_STATUS(self,match):
"Must be 0 to signal end of enum"
if match.group("postargs")!="0":
return False
return True
# POSTMATCH_LAYERINP
################################ ################################
# MESSAGE RECEIVE # MESSAGE RECEIVE
# def receive_CONNECT(self,match):
# "We received a connect message"
# self.messages["CONNECT"]=match
# self._LOCKS["connect"].release()
# self.feedback.messageReceived("CONNECT",match)
def genericRECEIVE(self,match): def genericRECEIVE(self,match):
"We received a connect message, all the logic will be on the feedback side" "We received a connect message, all the logic will be on the feedback side"
try: try:
typ=_MATCHS[match.group("msg")] typ=_MATCHS[match.group("msg")]
# self.messages[typ]=match # Not very clever tho # self.messages[typ]=match # Not very clever tho
self._LOCKS[typ].release() #TODO : Add a custom .release method to finetune everything self._LOCKS[typ].release() #TODO : Add a custom .release method to finetune everything
self.feedback.messageReceived(typ,match) #Do an actual action status=self.POSTMATCHACTIONS[typ](match)
if status:
self.feedback.messageReceived(typ,match) #Do an actual action
else:
wprint("Ignoring message",match)
except RuntimeError as e: except RuntimeError as e:
iprint("Lock [{}] is already released (async terminated earlier)".format(typ)) iprint("Lock [{}] is already released (async terminated earlier)".format(typ))
iprint(e) iprint(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)
############################################## ##############################################
# 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):

View File

@ -1,46 +0,0 @@
[pAW:INFO] Received: b'DEV259\r'
[pAW:INFO] Received: b'\n'
[pAW:INFO] Received: b'ISsc'
[pAW:INFO] Received: b'c2,3,0\r\nISsp'
[pAW:INFO] Received: b'r2,3,0\r\nISs'
[pAW:INFO] Received: b'va2,3,0\r\nISd'
[pAW:INFO] Received: b'fo2,3,0\r\nIS'
[pAW:INFO] Received: b'cfo2,3,0\r\nIS'
[pAW:INFO] Received: b'cfn2,3,0,78\r\nIScfn2,3,1'
[pAW:INFO] Received: b',79\r\nIScfn2,'
[pAW:INFO] Received: b'3,2,32\r\nISc'
[pAW:INFO] Received: b'fn2,3,4,65\r\n'
[pAW:INFO] Received: b'IScfn2,3,5,76\r\nIScfn2,3'
[pAW:INFO] Received: b',6,73\r\nIScf'
[pAW:INFO] Received: b'n2,3,7,68\r\nI'
[pAW:INFO] Received: b'Scfn2,3,8,32\r\nIScfn2,3,'
[pAW:INFO] Received: b'9,83\r\nIScfn2'
[pAW:INFO] Received: b',3,10,73\r\nI'
[pAW:INFO] Received: b'Scfn2,3,11,71\r\nIScfn2,3'
[pAW:INFO] Received: b',12,78\r\nIScf'
[pAW:INFO] Received: b'n2,3,13,65\r\n'
[pAW:INFO] Received: b'IScfn2,3,14,76\r\nIShtt2,'
[pAW:INFO] Received: b'3,0\r\nISswi2'
[pAW:INFO] Received: b',3,0\r\nISshe2'
[pAW:INFO] Received: b',3,0\r\nISfwi'
[pAW:INFO] Received: b'2,3,0\r\nISfhe'
[pAW:INFO] Received: b'2,3,0\r\nISiwi'
[pAW:INFO] Received: b'2,3,0\r\nISih'
[pAW:INFO] Received: b'e2,3,0\r\nISff'
[pAW:INFO] Received: b'i2,3,0\r\nISf'
[pAW:INFO] Received: b'li2,3,0\r\nISh'
[pAW:INFO] Received: b'po2,3,0\r\nISv'
[pAW:INFO] Received: b'po2,3,0\r\nIS'
[pAW:INFO] Received: b'vss2,3,0\r\nIS'
[pAW:INFO] Received: b'hss2,3,0\r\nI'
[pAW:INFO] Received: b'Shtm2,3,0\r\nI'
[pAW:INFO] Received: b'Shvi2,3,0\r\n'
[pAW:INFO] Received: b'ISaud2,3,0\r\n'
[pAW:INFO] Received: b'ISaus2,3,0\r\n'
[pAW:INFO] Received: b'ISaut2,3,0\r'
[pAW:INFO] Received: b'\nISacc2,3,0\r'
[pAW:INFO] Received: b'\nISasf2,3,0'
[pAW:INFO] Received: b'\r\nISscc2,3,1'
[pAW:INFO] Received: b'\r\nISsnu2,3,'
[pAW:INFO] Received: b'0\r\nIEkhl2,3,'
[pAW:INFO] Received: b'255\r\n'