from PIL import Image import socket import time import math Particle_mini = False localIP = "192.168.3.2" #localIP = "192.168.1.138" localPort = 6454 bufferSize = 530 CAP_MINI_01 =b'\x42\x4D\xB2\x4D\x00\x00\x00\x00\x00\x00\x36\x00\x00\x00\x28\x00\x00\x00\x39\x00\x00\x00\x74\x00\x00\x00\x01\x00\x18\x00\x00\x00\x00\x00\x7C\x4D\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' mode = 1 convert_jpeg = False if Particle_mini==True: LEDS_TOTAL_1 = 57 LEDS_TOTAL_2 = 43 LEDS_TOTAL_3 = 29 LEDS_TOTAL_4 = 15 else: LEDS_TOTAL_1 = 113 LEDS_TOTAL_2 = 85 LEDS_TOTAL_3 = 57 LEDS_TOTAL_4 = 29 PARTS_1 = math.ceil(LEDS_TOTAL_1*2/4)*4 PARTS_2 = math.ceil(LEDS_TOTAL_2*2/4)*4 PARTS_3 = math.ceil(LEDS_TOTAL_3*2/4)*4 PARTS_4 = math.ceil(LEDS_TOTAL_4*2/4)*4 print("{f} {g} {h} {i}".format(f=PARTS_1, g=PARTS_2, h=PARTS_3, i=PARTS_4)) NUM_UNIVERSES_1 = math.ceil(LEDS_TOTAL_1*3*PARTS_1/510) NUM_UNIVERSES_2 = math.ceil(LEDS_TOTAL_2*3*PARTS_2/510) NUM_UNIVERSES_3 = math.ceil(LEDS_TOTAL_3*3*PARTS_3/510) NUM_UNIVERSES_4 = math.ceil(LEDS_TOTAL_4*3*PARTS_4/510) print("{f} {g} {h} {i}".format(f=NUM_UNIVERSES_1, g=NUM_UNIVERSES_2, h=NUM_UNIVERSES_3, i=NUM_UNIVERSES_4)) INI_UNIVERSE_1 = 0 INI_UNIVERSE_2 = NUM_UNIVERSES_1 INI_UNIVERSE_3 = NUM_UNIVERSES_1 + NUM_UNIVERSES_2 INI_UNIVERSE_4 = NUM_UNIVERSES_1 + NUM_UNIVERSES_2 + NUM_UNIVERSES_3 END_UNIVERSE = INI_UNIVERSE_4 + NUM_UNIVERSES_4 ART_DMX = 0X5000 ART_NET_ID = "Art-Net" ART_DMX_START = 18 P01_numbers = [ [0 for i in range(530)] for j in range(NUM_UNIVERSES_1) ] P02_numbers = [ [0 for i in range(530)] for j in range(NUM_UNIVERSES_2) ] P03_numbers = [ [0 for i in range(530)] for j in range(NUM_UNIVERSES_3) ] P04_numbers = [ [0 for i in range(530)] for j in range(NUM_UNIVERSES_4) ] #P01_BIG_DMX = [[0] for j in range(18+NUM_UNIVERSES_1*510*3)] P01_SIZE = 1400#18+NUM_UNIVERSES_1*510*3 P01_BIG_DMX = bytearray(P01_SIZE) count_big_dmx_01 = 0 #print("{f}".format(f=P01_BIG_DMX)) mini01 = ("192.168.3.10", 6454) mini02 = ("192.168.3.11", 6454) mini03 = ("192.168.3.12", 6454) mini04 = ("192.168.3.13", 6454) ##msgFromServer = "Hello UDP Client" ##bytesToSend = str.encode(msgFromServer) # Create a datagram socket UDPServerSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM) # Bind to address and ip UDPServerSocket.bind((localIP, localPort)) print("UDP server up and listening") # Listen for incoming datagrams while(True): bytesAddressPair = UDPServerSocket.recvfrom(bufferSize) message = bytesAddressPair[0] address = bytesAddressPair[1] clientMsg = "Message from Client:{}".format(message) msg = "{}".format(message) result = msg.find(ART_NET_ID) if (result>=0): opcode = message[8] | message[9] << 8 if (opcode == ART_DMX): incomingUniverse = message[14] | message[15] << 8 dmxDataLength = message[17] | message[16] << 8 #print("{f} found with universe: {u}, DataLength: {n}.".format(f=ART_NET_ID, u= incomingUniverse, n=dmxDataLength)) if mode==0: #echo for i in range(dmxDataLength): if message[ART_DMX_START+i]!=P01_numbers[incomingUniverse][i]: P01_numbers[incomingUniverse] = message[ART_DMX_START:(dmxDataLength+ART_DMX_START)] ##Copia los 512 valores del ARRAY UDPServerSocket.sendto(message, mini01) #print("Sended") break elif mode==1: #delay entre paquetes if incomingUniverse> 8) P01_BIG_DMX[17] = 0x00FF & 18+P01_SIZE P01_BIG_DMX[16] = 0x00FF&((18+P01_SIZE) >> 8) #else: #for h in range(510): #P01_BIG_DMX[incomingUniverse*510 +h] = message[18+h] ##Copia todos los valores del ARRAY if incomingUniverse==(END_UNIVERSE-1): UDPServerSocket.sendto(P01_BIG_DMX, mini01) incomingUniverse = P01_BIG_DMX[14] | P01_BIG_DMX[15] << 8 dmxDataLength = P01_BIG_DMX[17] | P01_BIG_DMX[16] << 8 ##print("{f} {g}".format(f=incomingUniverse, g=dmxDataLength)) ##print("{f}".format(f=P01_BIG_DMX))