From a9d48bb623cd51f0641d075fb9e953ddb3c80c10 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 20 May 2016 09:42:21 +0200 Subject: Use a UDP socket instead of a pipe in uecp_parse --- uecpparse/uecp_parse.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'uecpparse') diff --git a/uecpparse/uecp_parse.py b/uecpparse/uecp_parse.py index d586252..b0d8822 100755 --- a/uecpparse/uecp_parse.py +++ b/uecpparse/uecp_parse.py @@ -24,12 +24,13 @@ # THE SOFTWARE. # # -# A UECP decoder, reading from a file generated by -# my patched VLC, from ancillary MP2 bytes in a MPEG-TS +# A UECP decoder, reading from a UDP socket, receiving +# data generated by my patched VLC, from ancillary MP2 bytes in a MPEG-TS # # Please refer to RDS UECP specification import sys +import socket import struct import crc @@ -62,7 +63,7 @@ uecp_mec_names = { 0x2C: "SET_COMM_MODE" } # Set communication mode for the encoder def usage(): - print("Usage:\n{} ".format(sys.argv[0])) + print("Usage:\n{} ".format(sys.argv[0])) if len(sys.argv) < 2: usage() @@ -169,8 +170,6 @@ class UECP_Frame_Decoder(): UECP_Message_Decoder(self.msg) -in_fd = open(sys.argv[1], "r") - uecp = UECP_Frame_Decoder() def parse_anc_bytes(anc_bytes): @@ -186,8 +185,21 @@ def parse_anc_bytes(anc_bytes): uecp.msg, uecp.crc, uecp.crc_calc, uecp.crc_ok)) uecp = UECP_Frame_Decoder() -for line_nr, line in enumerate(in_fd): - line_bytes = [int(i, 16) for i in line.split()] +UDP_IP = "127.0.0.1" +port = int(sys.argv[1]) + +sock = socket.socket(socket.AF_INET, # Internet + socket.SOCK_DGRAM) # UDP +sock.bind((UDP_IP, port)) + + +while True: + data, addr = sock.recvfrom(1024) + + if not data: + break + + line_bytes = [int(i) for i in data] line_bytes.reverse() -- cgit v1.2.3