Merged with fakeserver
This commit is contained in:
commit
02a1bd2fde
34
bindings.py
34
bindings.py
|
|
@ -28,7 +28,7 @@ def _SYS_EXIT(system,*args):
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
_VERBOSE=4
|
_VERBOSE=3
|
||||||
|
|
||||||
nopeF=lambda *x:None
|
nopeF=lambda *x:None
|
||||||
def printl(label=""):
|
def printl(label=""):
|
||||||
|
|
@ -167,6 +167,7 @@ _MATCHS={
|
||||||
"GCfra":"FREEZEALL",
|
"GCfra":"FREEZEALL",
|
||||||
"GCfrl":"FREEZELAYER",
|
"GCfrl":"FREEZELAYER",
|
||||||
"GCply":"DISPLAYLAYER",
|
"GCply":"DISPLAYLAYER",
|
||||||
|
"ISsva":"DETECTED",
|
||||||
"E":"ERROR"
|
"E":"ERROR"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -174,11 +175,15 @@ _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","FREEZE","FREEZEALL","FREEZELAYER","DISPLAYLAYER",
|
"SCRNUPD","FREEZE","FREEZEALL","FREEZELAYER","DISPLAYLAYER",
|
||||||
"ERROR"
|
"ERROR","DETECTED",
|
||||||
]
|
]
|
||||||
|
|
||||||
_UPDATE_MSG=[
|
_UPDATE_MSG=[
|
||||||
|
<<<<<<< HEAD
|
||||||
"LAYERINP","QUICKFA","QUICKF","TAKE","FREEZE","FREEZEALL","DISPLAYLAYER",
|
"LAYERINP","QUICKFA","QUICKF","TAKE","FREEZE","FREEZEALL","DISPLAYLAYER",
|
||||||
|
=======
|
||||||
|
"LAYERINP","QUICKFA","QUICKF","TAKE","QUICKFA","QUICKF","FREEZE","FREEZEALL","DISPLAYLAYER","DETECTED",
|
||||||
|
>>>>>>> 8d7cf3e793b3cca67e51da6df4ed25c920845d29
|
||||||
]
|
]
|
||||||
# RELOAD_PROGRAM
|
# RELOAD_PROGRAM
|
||||||
# FREEZE_SCREEN
|
# FREEZE_SCREEN
|
||||||
|
|
@ -201,6 +206,8 @@ class analogController(object):
|
||||||
self.st_quickframe=[False,False]
|
self.st_quickframe=[False,False]
|
||||||
self.st_takeavailable=[False,False]
|
self.st_takeavailable=[False,False]
|
||||||
self.st_quickframeall=False
|
self.st_quickframeall=False
|
||||||
|
self._connectedLock=threading.Lock()
|
||||||
|
self._connectedLock.acquire() # Waiting for connection
|
||||||
self.st_freeze=[False,False]
|
self.st_freeze=[False,False]
|
||||||
self.st_freeze_all=False
|
self.st_freeze_all=False
|
||||||
self.st_freeze_layer=[False,False]
|
self.st_freeze_layer=[False,False]
|
||||||
|
|
@ -225,8 +232,9 @@ class analogController(object):
|
||||||
try:
|
try:
|
||||||
dprint('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)
|
||||||
dprint('Getting remote IP address')
|
# iprint('Getting remote IP address')
|
||||||
remote_ip = socket.gethostbyname(_IPSELF)
|
# remote_ip = socket.gethostbyname(_IPSELF)
|
||||||
|
# iprint(remote_ip)
|
||||||
except socket.error:
|
except socket.error:
|
||||||
eprint('Failed to create socket')
|
eprint('Failed to create socket')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
@ -234,6 +242,7 @@ class analogController(object):
|
||||||
eprint('Hostname could not be resolved. Exiting')
|
eprint('Hostname could not be resolved. Exiting')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
def receiveCommand(self,command,*args,**kwargs):
|
def receiveCommand(self,command,*args,**kwargs):
|
||||||
"Receive a command froman external source and handle it internally"
|
"Receive a command froman external source and handle it internally"
|
||||||
try:
|
try:
|
||||||
|
|
@ -241,6 +250,11 @@ class analogController(object):
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
eprint("The command received {} isn't in the list of supported commands ({})".format(command,self._commandlist))
|
eprint("The command received {} isn't in the list of supported commands ({})".format(command,self._commandlist))
|
||||||
eprint(e)
|
eprint(e)
|
||||||
|
=======
|
||||||
|
def addFeedbackInterface(self,feedback):
|
||||||
|
"Add the feedback interface TODO: Several feedback interfaces ?"
|
||||||
|
self.feedback=feedback
|
||||||
|
>>>>>>> 8d7cf3e793b3cca67e51da6df4ed25c920845d29
|
||||||
|
|
||||||
def getAttr(self,attribute,default):
|
def getAttr(self,attribute,default):
|
||||||
"A custom attribute fetcher"
|
"A custom attribute fetcher"
|
||||||
|
|
@ -347,6 +361,9 @@ class analogController(object):
|
||||||
"Returns the layer,screen and status of the freeze"
|
"Returns the layer,screen and status of the freeze"
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def POSTMATCH_DETECTED(self,match):
|
||||||
|
"Return the status of the input"
|
||||||
|
return True
|
||||||
# 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":
|
||||||
|
|
@ -423,6 +440,7 @@ class analogController(object):
|
||||||
"""
|
"""
|
||||||
iprint('Connecting to server, {self.ip}:{self.port}'.format(self=self))
|
iprint('Connecting to server, {self.ip}:{self.port}'.format(self=self))
|
||||||
self.sck.connect((self.ip,self.port))
|
self.sck.connect((self.ip,self.port))
|
||||||
|
self._connectedLock.release()
|
||||||
self.genericSEND("CONNECT","*\r\n")
|
self.genericSEND("CONNECT","*\r\n")
|
||||||
|
|
||||||
def getDevice(self):
|
def getDevice(self):
|
||||||
|
|
@ -596,7 +614,7 @@ class analogController(object):
|
||||||
self.connect()
|
self.connect()
|
||||||
self.getDevice()
|
self.getDevice()
|
||||||
self.getVersion()
|
self.getVersion()
|
||||||
# self.getStatus(3)
|
self.getStatus(3)
|
||||||
|
|
||||||
|
|
||||||
#########################################
|
#########################################
|
||||||
|
|
@ -627,11 +645,16 @@ class analogController(object):
|
||||||
for r in reply[:-1]: # iprint("Yielding:",r)
|
for r in reply[:-1]: # iprint("Yielding:",r)
|
||||||
yield r
|
yield r
|
||||||
except AttributeError as e:
|
except AttributeError as e:
|
||||||
|
dprint(e)
|
||||||
|
except OSError as e:
|
||||||
eprint(e)
|
eprint(e)
|
||||||
|
eprint('The socket connection is experiencing issues')
|
||||||
|
|
||||||
|
|
||||||
def socketLoop(self):
|
def socketLoop(self):
|
||||||
"""Loop on the socket and create an event for every message received"""
|
"""Loop on the socket and create an event for every message received"""
|
||||||
self.listening=True
|
self.listening=True
|
||||||
|
self._connectedLock.acquire(_TIMEOUT_BIG) # Wait for connection
|
||||||
for message in self.cleanReceive():
|
for message in self.cleanReceive():
|
||||||
try:
|
try:
|
||||||
iprint ("<<< Received:",message)
|
iprint ("<<< Received:",message)
|
||||||
|
|
@ -699,6 +722,7 @@ class analogController(object):
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
#_HOSTS=[["127.0.0.1",3000]] # Test server
|
#_HOSTS=[["127.0.0.1",3000]] # Test server
|
||||||
# _TIMEOUT_HUGE=5
|
# _TIMEOUT_HUGE=5
|
||||||
|
|
||||||
ctrl1=analogController(*_HOSTS[0])
|
ctrl1=analogController(*_HOSTS[0])
|
||||||
ctrl1.receiveCommand("CONNECT")
|
ctrl1.receiveCommand("CONNECT")
|
||||||
# ctrl1.connectionSequence()
|
# ctrl1.connectionSequence()
|
||||||
|
|
|
||||||
|
|
@ -10,24 +10,50 @@ def sequenceAnswers(s,addr,seq,delay=_DELAY):
|
||||||
# s.sendall("*\r\n".encode)
|
# s.sendall("*\r\n".encode)
|
||||||
recv=b""
|
recv=b""
|
||||||
for elt,resps in seq:
|
for elt,resps in seq:
|
||||||
elt=(elt+'\r\n').encode()
|
elt=(elt).encode()
|
||||||
resps=[(i+'\r\n').encode() for i in resps]
|
resps=[(i+"\r\n").encode() for i in resps]
|
||||||
print("[{}] Waiting for {}".format(name,elt))
|
print("[{}] Waiting for {}".format(name,elt))
|
||||||
|
<<<<<<< HEAD
|
||||||
while recv!=elt and recv:
|
while recv!=elt and recv:
|
||||||
|
=======
|
||||||
|
while recv not in elt:
|
||||||
|
>>>>>>> 8d7cf3e793b3cca67e51da6df4ed25c920845d29
|
||||||
recv=s.recv(4095)
|
recv=s.recv(4095)
|
||||||
print("[{}] Received : {}".format(name,recv))
|
print("[{}] Received : {}".format(name,recv))
|
||||||
for r in resps:
|
for r in resps:
|
||||||
print("[{}] Sending : {}".format(name,r))
|
print("[{}] Sending : {}".format(name,r))
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
s.sendall(r)
|
s.sendall(r)
|
||||||
|
<<<<<<< HEAD
|
||||||
while True:
|
while True:
|
||||||
recv=s.recv(4096)
|
recv=s.recv(4096)
|
||||||
if not recv:
|
if not recv:
|
||||||
break
|
break
|
||||||
print(recv.decode())
|
print(recv.decode())
|
||||||
|
=======
|
||||||
|
>>>>>>> 8d7cf3e793b3cca67e51da6df4ed25c920845d29
|
||||||
except ConnectionResetError as e:
|
except ConnectionResetError as e:
|
||||||
print("[{}] Has stopped the connection".format(name))
|
print("[{}] Has stopped the connection".format(name))
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
|
import re
|
||||||
|
_MESSAGE_REGEX=re.compile("(?P<preargs>(\d)*(,\d)*)(?P<msg>\D*)(?P<postargs>(\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+"\r\n").encode())
|
||||||
|
except ConnectionResetError as e:
|
||||||
|
print("[{}] Has stopped the connection".format(addr[1]))
|
||||||
|
print(e)
|
||||||
|
|
||||||
def Main(delay=_DELAY):
|
def Main(delay=_DELAY):
|
||||||
host = "127.0.0.1"
|
host = "127.0.0.1"
|
||||||
|
|
||||||
|
|
@ -48,7 +74,7 @@ def Main(delay=_DELAY):
|
||||||
c, addr = s.accept()
|
c, addr = s.accept()
|
||||||
# print(c.recv(4000))
|
# print(c.recv(4000))
|
||||||
# c.sendall(b"*\r\n")
|
# c.sendall(b"*\r\n")
|
||||||
start_new_thread(sequenceAnswers, (c,addr,sequence,delay,))
|
start_new_thread(parrotanswers, (c,addr,sequence,delay,))
|
||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -57,8 +83,8 @@ if __name__ == '__main__':
|
||||||
("*",["VEvar13","#0","VEvar13","*1"]),
|
("*",["VEvar13","#0","VEvar13","*1"]),
|
||||||
("?",['DEV259']),
|
("?",['DEV259']),
|
||||||
("VEvar",["VEvar13"]), #Guess
|
("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
|
("1SYpig",["SYpig4294967294"]) #Another guess
|
||||||
|
|
||||||
]
|
]
|
||||||
Main(0.5)
|
Main(0.05)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue