Added a sample of return values

This commit is contained in:
dandaedre 2021-09-28 17:14:30 +02:00
parent bd31d5ca7a
commit b128ef229a
2 changed files with 178 additions and 11 deletions

143
bindings.py Normal file → Executable file
View File

@ -2,15 +2,25 @@
################################
# IMPORTS
import socketserver
# import socketserver
import socket
import sys
import threading
################################
# CONFIG VARIABLES
_HOSTS = [("192.168.0.140","10500")]
_IPSELF = "192.168.0.140" # Could be usefull for multi IP networks
_HOSTS = [("192.168.0.140",10500)]
_VERBOSE=True
_MSGSIZE=4096
if _VERBOSE:
def dprint(*args):
print(*args)
else:
dprint=lambda x:None
################################
#
@ -76,20 +86,42 @@ class analogController(object):
"AnalogWay Controller, controls one AnalogWay device"
def __init__(self,ip,port):
pass
self.sck=None
self.ip=ip
self.port=port
try:
dprint('[pAW:INFO] Creating socket')
self.sck = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
dprint('[pAW:INFO] Getting remote IP address')
host=_IPSELF
remote_ip = socket.gethostbyname( host )
except socket.error:
print('[pAW:ERROR] Failed to create socket')
sys.exit()
except socket.gaierror:
print('[pAW:ERROR] Hostname could not be resolved. Exiting')
sys.exit()
def connect(self):
"""The device acts as a server. Once the TCP connection is established, the controller shall
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
"""
pass
dprint('[pAW:INFO] Connecting to server, {self.ip}:{self.port}'.format(self=self))
self.sck.connect((self.ip,self.port))
dprint('[pAW:INFO] Sending data to server')
self.sendData("*\r\n")
self.waitfor(b'*1\r\n')
def getDevice(self):
"""This read only command gives the device type
[?] (DEV <value>) <values>:_DEVICES_VALUES
"""
pass
self.sendData("?")
self.waitfor(b'DEV259\r')
def getVersion(self):
"""his read only command gives the version number of the command set.
It is recommended to check that this value matches the one expected by the controller.
@ -117,7 +149,7 @@ class analogController(object):
<ProgPrev> is 0 for Program, 1 for Preview.
<layer> is a value representing the destination Layer.
<src> is a value representing the input source.
"""
""" #Rinp0,1,7,5\r\nPRinp0,1,1
pass
def takeAvailable(self,*screens):
@ -181,8 +213,97 @@ class analogController(object):
Hide: 0CTqfl (CTqfl 0 R F)
"""
################################
# QuickFrames
def connectionSequence(self):
"Execute the full connection sequence"
self.connect()
self.getDevice()
self.getVersion()
self.getStatus()
def waitfor(self,value):
"""Wait for a specific return value, blocking"""
notfound=True
while notfound:
reply=self.sck.recv(_MSGSIZE)
dprint ("[pAW:INFO] Received:",reply)
# Changelayer
if reply==value:
dprint("Found")
return
def sendData(self,data):
"Send data through the socket"
try:
self.sck.sendall(data.encode())
except socket.error:
print ('[pAW:ERROR] Send failed of data :',data)
sys.exit()
#####################
# TESTING
if __name__ == '__main__':
ctrl1=analogController(*_HOSTS[0])
ctrl1.connectionSequence()
ctrl1.waitfor("")
# # Receive data
# print('# Receive data from server')
# while True:
# reply = s.recv(4096)
#
# print (reply)
# # thread function
# def threaded(c):
# while True:
#
# # data received from client
# data = c.recv(1024)
# if not data:
# print('Bye')
#
# # lock released on exit
# print_lock.release()
# break
#
# # reverse the given string from client
# data = data[::-1]
#
# # send back reversed string to client
# c.send(data)
#
# # connection closed
# c.close()
#
#
# def Main():
# host = ""
#
# # reverse a port on your computer
# # in our case it is 12345 but it
# # can be anything
# port = 12345
# s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# s.bind((host, port))
# print("socket binded to port", port)
#
# # put the socket into listening mode
# s.listen(5)
# print("socket is listening")
#
# # a forever loop until client wants to exit
# while True:
#
# # establish connection with client
# c, addr = s.accept()
#
# # lock acquired by client
# print_lock.acquire()
# print('Connected to :', addr[0], ':', addr[1])
#
# # Start a new thread and return its identifier
# start_new_thread(threaded, (c,))
# s.close()
#
#
# if __name__ == '__main__':
# Main()

46
returns.txt Normal file
View File

@ -0,0 +1,46 @@
[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'