-
Notifications
You must be signed in to change notification settings - Fork 0
/
listener.py
42 lines (34 loc) · 1 KB
/
listener.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import socket
import configparser
config = configparser.ConfigParser()
config.read('config.ini')
UDP_IP = config['listener'].get('addr')
UDP_PORT = 6454
universe = config['listener'].getint('universe')
paused = False
def main():
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(1024)
process_packet(data, addr)
def process_packet(data, addr):
global paused, universe
header = data[0:7]
# Check if artnet packet
if not header == b'Art-Net':
return
# Parse packet
opcode = int.from_bytes(data[8:9], byteorder="little")
protver = int.from_bytes(data[10:11], byteorder="big")
uni = int.from_bytes(data[14:15], byteorder="little")
length = int.from_bytes(data[16:17], byteorder="big")
level = data[18]
if not uni == universe:
return
# Is paused
if level < 128:
paused = True
# Not paused
if level >= 128:
paused = False