Cleaned the connection and interconnection

This commit is contained in:
dandaedre 2021-10-17 17:45:54 +02:00
parent 02a1bd2fde
commit 5e737f8d55
2 changed files with 13 additions and 26 deletions

View File

@ -3,6 +3,7 @@
################################ ################################
# IMPORTS # IMPORTS
# import socketserver # import socketserver
import socket, threading import socket, threading
import sys,time import sys,time
import re import re
@ -179,11 +180,7 @@ _ALL_MESSAGE_TYPES=[
] ]
_UPDATE_MSG=[ _UPDATE_MSG=[
<<<<<<< HEAD "LAYERINP","QUICKFA","QUICKF","TAKE","FREEZE","FREEZEALL","DISPLAYLAYER","DETECTED",
"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
@ -242,7 +239,6 @@ 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:
@ -250,11 +246,10 @@ 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): def addFeedbackInterface(self,feedback):
"Add the feedback interface TODO: Several feedback interfaces ?" "Add the feedback interface TODO: Several feedback interfaces ?"
self.feedback=feedback self.feedback=feedback
>>>>>>> 8d7cf3e793b3cca67e51da6df4ed25c920845d29
def getAttr(self,attribute,default): def getAttr(self,attribute,default):
"A custom attribute fetcher" "A custom attribute fetcher"
@ -438,11 +433,14 @@ class analogController(object):
check that the device is ready, by reading the READY status, until it returns the value 1. check that the device is ready, by reading the READY status, until it returns the value 1.
[*] (* <value>) The controller shall wait and retry until it receives the value 1 [*] (* <value>) The controller shall wait and retry until it receives the value 1
""" """
iprint('Connecting to server, {self.ip}:{self.port}'.format(self=self)) try:
self.sck.connect((self.ip,self.port)) iprint('Connecting to server, {self.ip}:{self.port}'.format(self=self))
self._connectedLock.release() self.sck.connect((self.ip,self.port))
self.genericSEND("CONNECT","*\r\n") self._connectedLock.release()
self.genericSEND("CONNECT","*\r\n")
except ConnectionRefusedError:
eprint("Connection to AnalogWay server {self.ip}:{self.port} is impossible".format(self=self))
raise ConnectionRefusedError
def getDevice(self): def getDevice(self):
"""This read only command gives the device type """This read only command gives the device type
[?] (DEV <value>) <values>:_DEVICES_VALUES [?] (DEV <value>) <values>:_DEVICES_VALUES
@ -614,7 +612,7 @@ class analogController(object):
self.connect() self.connect()
self.getDevice() self.getDevice()
self.getVersion() self.getVersion()
self.getStatus(3) # self.getStatus(3)
######################################### #########################################

View File

@ -13,25 +13,14 @@ def sequenceAnswers(s,addr,seq,delay=_DELAY):
elt=(elt).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 not in elt: 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:
recv=s.recv(4096)
if not recv:
break
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)