From 3e9f1b5a41b641ed16b1a151025b976b7e2a3604 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Mon, 11 Oct 2021 21:28:34 +0200 Subject: [PATCH 1/4] Added a connection lock --- bindings.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bindings.py b/bindings.py index 3530878..bfc2298 100755 --- a/bindings.py +++ b/bindings.py @@ -183,6 +183,8 @@ class analogController(object): self.lastping=0 self.st_quickframe=[False,False] self.st_quickframeall=False + self._connectedLock=threading.Lock() + self._connectedLock.acquire() # Waiting for connection self.feedback=feedbackInterface # Feedback interface gui or midiRebind self._LOCKS={i:threading.Lock() for i in _ALL_MESSAGE_TYPES} #LAYERINP could actually be a huge clusterlock, not for now tho # for i in range(2): @@ -194,8 +196,9 @@ class analogController(object): try: iprint('Creating socket') self.sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - iprint('Getting remote IP address') - remote_ip = socket.gethostbyname(_IPSELF) + # iprint('Getting remote IP address') + # remote_ip = socket.gethostbyname(_IPSELF) + # iprint(remote_ip) except socket.error: print('[pAW:ERROR] Failed to create socket') sys.exit() @@ -318,6 +321,7 @@ class analogController(object): """ iprint('Connecting to server, {self.ip}:{self.port}'.format(self=self)) self.sck.connect((self.ip,self.port)) + self._connectedLock.release() self.genericSEND("CONNECT","*") def getDevice(self): @@ -466,10 +470,14 @@ class analogController(object): yield r except AttributeError as e: dprint(e) + except OSError as e: + dprint(e) + dprint('The socket connection is experiencing issues') def socketLoop(self): """Loop on the socket and create an event for every message received""" self.listening=True + self._connectedLock.acquire(_TIMEOUT_BIG) # Wait for connection for message in self.cleanReceive(): try: iprint ("Received:",message) From a257c6c3d7891d5729b119be36d612435b54cd8c Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Mon, 11 Oct 2021 21:44:51 +0200 Subject: [PATCH 2/4] Couple correction on the fakeserver --- bindings.py | 3 +-- falseserver.py | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/bindings.py b/bindings.py index 67d11c9..43b9440 100755 --- a/bindings.py +++ b/bindings.py @@ -408,7 +408,6 @@ class analogController(object): iprint('Connecting to server, {self.ip}:{self.port}'.format(self=self)) self.sck.connect((self.ip,self.port)) self._connectedLock.release() - self.genericSEND("CONNECT","*") self.genericSEND("CONNECT","*\r\n") def getDevice(self): @@ -582,7 +581,7 @@ class analogController(object): self.connect() self.getDevice() self.getVersion() - # self.getStatus(3) + self.getStatus(3) ######################################### diff --git a/falseserver.py b/falseserver.py index 795f4ae..1e3e318 100644 --- a/falseserver.py +++ b/falseserver.py @@ -10,10 +10,10 @@ def sequenceAnswers(s,addr,seq,delay=_DELAY): # s.sendall("*\r\n".encode) recv=b"" for elt,resps in seq: - elt=(elt+'\r\n').encode() - resps=[(i+'\r\n').encode() for i in resps] + elt=(elt).encode() + resps=[(i+"\r\n").encode() for i in resps] print("[{}] Waiting for {}".format(name,elt)) - while recv!=elt: + while recv not in elt: recv=s.recv(4095) print("[{}] Received : {}".format(name,recv)) for r in resps: From b0ae5c321e411c1c7d8a24ba16c0cccb442b8d13 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Mon, 11 Oct 2021 22:03:31 +0200 Subject: [PATCH 3/4] A parrot server, not pretty as of now --- falseserver.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/falseserver.py b/falseserver.py index 1e3e318..ce9da56 100644 --- a/falseserver.py +++ b/falseserver.py @@ -20,11 +20,28 @@ def sequenceAnswers(s,addr,seq,delay=_DELAY): print("[{}] Sending : {}".format(name,r)) time.sleep(delay) s.sendall(r) - while True: - print(s.recv(4096).decode()) except ConnectionResetError as e: print("[{}] Has stopped the connection".format(name)) print(e) + + +import re +_MESSAGE_REGEX=re.compile("(?P(\d)*(,\d)*)(?P\D*)(?P(\d)*(,\d)*)") + +def parrotanswers(s,addr,seq,delay=_DELAY): + "Parrot all messages given" + try: + sequenceAnswers(s,addr,seq,delay=_DELAY) + while True: + recv=s.recv(3000) + match=_MESSAGE_REGEX.match(recv.decode()) + msg=match.group("msg")+match.group("preargs") + print("[{}] Received : {} | Sending {}".format(addr[1],recv,msg)) + s.sendall(msg.encode()) + except ConnectionResetError as e: + print("[{}] Has stopped the connection".format(addr[1])) + print(e) + def Main(delay=_DELAY): host = "127.0.0.1" @@ -45,7 +62,7 @@ def Main(delay=_DELAY): c, addr = s.accept() # print(c.recv(4000)) # c.sendall(b"*\r\n") - start_new_thread(sequenceAnswers, (c,addr,sequence,delay,)) + start_new_thread(parrotanswers, (c,addr,sequence,delay,)) s.close() From 8d7cf3e793b3cca67e51da6df4ed25c920845d29 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Tue, 12 Oct 2021 03:38:53 +0200 Subject: [PATCH 4/4] Couple bugfixes --- bindings.py | 14 +++++++++++--- falseserver.py | 6 +++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/bindings.py b/bindings.py index 43b9440..ffa030c 100755 --- a/bindings.py +++ b/bindings.py @@ -28,7 +28,7 @@ def _SYS_EXIT(system,*args): sys.exit() -_VERBOSE=4 +_VERBOSE=3 nopeF=lambda *x:None def printl(label=""): @@ -167,6 +167,7 @@ _MATCHS={ "GCfra":"FREEZEALL", "GCfrl":"FREEZELAYER", "GCply":"DISPLAYLAYER", + "ISsva":"DETECTED", "E":"ERROR" } @@ -174,11 +175,11 @@ _ALL_MESSAGE_TYPES=[ "CONNECT","DEVICE","VERSION","STATUS","KPALIVE","LAYERINP", "TAKEAVL","TAKE","TAKEALL","LOADMM","QUICKFA","QUICKF", "SCRNUPD","FREEZE","FREEZEALL","FREEZELAYER","DISPLAYLAYER", - "ERROR" + "ERROR","DETECTED", ] _UPDATE_MSG=[ - "LAYERINP","QUICKFA","QUICKF","TAKE","QUICKFA","QUICKF","FREEZE","FREEZEALL","DISPLAYLAYER", + "LAYERINP","QUICKFA","QUICKF","TAKE","QUICKFA","QUICKF","FREEZE","FREEZEALL","DISPLAYLAYER","DETECTED", ] # RELOAD_PROGRAM # FREEZE_SCREEN @@ -227,6 +228,10 @@ class analogController(object): eprint('Hostname could not be resolved. Exiting') sys.exit() + def addFeedbackInterface(self,feedback): + "Add the feedback interface TODO: Several feedback interfaces ?" + self.feedback=feedback + def getAttr(self,attribute,default): "A custom attribute fetcher" try: @@ -332,6 +337,9 @@ class analogController(object): "Returns the layer,screen and status of the freeze" return True + def POSTMATCH_DETECTED(self,match): + "Return the status of the input" + return True # def POSTMATCH_TAKEAVL(self,match): # "Take available answer 1" # if match.group("postargs")[-1]=="1": diff --git a/falseserver.py b/falseserver.py index ce9da56..f580a64 100644 --- a/falseserver.py +++ b/falseserver.py @@ -37,7 +37,7 @@ def parrotanswers(s,addr,seq,delay=_DELAY): match=_MESSAGE_REGEX.match(recv.decode()) msg=match.group("msg")+match.group("preargs") print("[{}] Received : {} | Sending {}".format(addr[1],recv,msg)) - s.sendall(msg.encode()) + s.sendall((msg+"\r\n").encode()) except ConnectionResetError as e: print("[{}] Has stopped the connection".format(addr[1])) print(e) @@ -71,8 +71,8 @@ if __name__ == '__main__': ("*",["VEvar13","#0","VEvar13","*1"]), ("?",['DEV259']), ("VEvar",["VEvar13"]), #Guess - ("#3",["#4","PRinp0,1,7,8","PRinp0,1,1,8","#0"]), #Another guess + ("#3",["ISsva4,3,1","ISsva3,3,1","ISsva1,3,1","PRinp0,1,7,8","PRinp0,1,1,8","#0"]), #Another guess ("1SYpig",["SYpig4294967294"]) #Another guess ] - Main(0.5) + Main(0.05)