wies war
This commit is contained in:
parent
2a67fb36e7
commit
0abbe41473
@ -233,61 +233,62 @@ async def notify_delta(delta):
|
||||
#
|
||||
async def websworker(websocket, path):
|
||||
|
||||
# register(websocket) sends user_event() to websocket
|
||||
await register(websocket)
|
||||
try:
|
||||
await websocket.send(state_event())
|
||||
while True:
|
||||
try:
|
||||
# register(websocket) sends user_event() to websocket
|
||||
await register(websocket)
|
||||
try:
|
||||
await websocket.send(state_event())
|
||||
while True:
|
||||
# waiting for a new message resceived on the websocket
|
||||
message = await websocket.recv()
|
||||
|
||||
# waiting for a new message received on the websocket
|
||||
message = await asyncio.wait_for(websocket.recv(), timeout=0.1)
|
||||
# split message from multiple commands in one string
|
||||
data = message.split(";")
|
||||
|
||||
# split message from multiple commands in one string
|
||||
data = message.split(";")
|
||||
# process each command
|
||||
for index in range(len(data)):
|
||||
# act[0] will be the key
|
||||
# act[1] will be the value
|
||||
act = data[index].split("=")
|
||||
|
||||
# process each command
|
||||
for index in range(len(data)):
|
||||
# act[0] will be the key
|
||||
# act[1] will be the value
|
||||
act = data[index].split("=")
|
||||
try:
|
||||
# if key is a number, we will have e change on a dmx value
|
||||
# otherwise, we have a string to check which will be processed in except...
|
||||
# poor python - there is no other chance to check if a string can be a int without errors
|
||||
dmxchannel = int(act[0])
|
||||
dmxvalue = int(act[1])
|
||||
|
||||
try:
|
||||
# if key is a number, we will have e change on a dmx value
|
||||
# otherwise, we have a string to check which will be processed in except...
|
||||
# poor python - there is no other chance to check if a string can be a int without errors
|
||||
dmxchannel = int(act[0])
|
||||
dmxvalue = int(act[1])
|
||||
# We have integer, but are they in a valid range?
|
||||
if( dmxchannel < 1 or dmxchannel > 512 or dmxvalue < 0 or dmxvalue > 255):
|
||||
# this must be an exception, we will continue in the exception-area anyway now
|
||||
dmxchannel = int("will raise")
|
||||
|
||||
# We have integer, but are they in a valid range?
|
||||
if( dmxchannel < 1 or dmxchannel > 512 or dmxvalue < 0 or dmxvalue > 255):
|
||||
# this must be an exception, we will continue in the exception-area anyway now
|
||||
dmxchannel = int("will raise")
|
||||
# looks valid, so take them to the buffer
|
||||
DMXDATA[dmxchannel] = dmxvalue
|
||||
|
||||
# looks valid, so take them to the buffer
|
||||
DMXDATA[dmxchannel] = dmxvalue
|
||||
# notifying our connected users
|
||||
# we can send the resceived command back since the syntax is matched :)
|
||||
await notify_delta(data[index])
|
||||
|
||||
# notifying our connected users
|
||||
# we can send the resceived command back since the syntax is matched :)
|
||||
await notify_delta(data[index])
|
||||
|
||||
# debug
|
||||
print("DMX value for channel " + act[0] + " changed to " + act[1])
|
||||
# debug
|
||||
print("DMX value for channel " + act[0] + " changed to " + act[1])
|
||||
|
||||
|
||||
# It does not look like we have a dmx key-value, so we have to process the command
|
||||
except Exception:
|
||||
|
||||
if act[0] == "manual":
|
||||
sendDMX(DMXDATA)
|
||||
print("Manual send data: ", bytearray(DMXDATA))
|
||||
|
||||
elif act[0] == "sec":
|
||||
print("")
|
||||
|
||||
else:
|
||||
print("received message, but can not handle: ", act)
|
||||
|
||||
# It does not look like we have a dmx key-value, so we have to process the command
|
||||
except Exception:
|
||||
|
||||
if act[0] == "manual":
|
||||
sendDMX(DMXDATA)
|
||||
print("Manual send data: ", bytearray(DMXDATA))
|
||||
|
||||
elif act[0] == "sec":
|
||||
print("")
|
||||
|
||||
else:
|
||||
print("received message, but can not handle: ", act)
|
||||
|
||||
finally:
|
||||
await unregister(websocket)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user