forked from szpajder/dumpvdl2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavlc-udp.py
35 lines (28 loc) · 1.17 KB
/
avlc-udp.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
import binascii
import socket
import struct
import sys
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Bind the socket to the port
server_address = ('localhost', 8090)
print >>sys.stderr, 'starting up on %s port %s' % server_address
sock.bind(server_address)
# https://docs.python.org/3/library/struct.html
unpacker_QI = struct.Struct('QI')
unpacker_b = struct.Struct('?')
unpackerIII = struct.Struct('III')
while True:
data, address = sock.recvfrom(4096)
print >>sys.stderr, '\nreceived %s bytes from %s' % (len(data), address)
#print >>sys.stderr, 'received "%s"' % binascii.hexlify(data)
unpacked_data = unpacker_QI.unpack(data[0:12])
print >>sys.stderr, 'Seq:', unpacked_data[0]
print >>sys.stderr, 'Freq:', unpacked_data[1]
unpacked_data = unpacker_b.unpack(data[12:12+1])
print >>sys.stderr, 'is_valid:', unpacked_data[0]
unpacked_data = unpackerIII.unpack(data[13:13+12])
print >>sys.stderr, 'time_sec:', unpacked_data[0]
print >>sys.stderr, 'time_usec:', unpacked_data[1]
print >>sys.stderr, 'Len:', unpacked_data[2]
print >>sys.stderr, 'data: %s' % binascii.hexlify(data[25:25+unpacked_data[1]])