3 * Copyright 2009 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <vrt/expanded_header.h>
26 #include "socket_rx_buffer.h"
27 #include "data_handler.h"
33 print_words(FILE *fp, size_t offset, uint32_t *buf, size_t n)
36 for (i = 0; i < n; i++){
38 fprintf(fp, "%04zx:", i);
42 fprintf(fp, "%08x", buf[i]);
55 rx::make(int socket_fd, size_t rx_bufsize)
57 return sptr(new rx(socket_fd, rx_bufsize));
60 rx::rx(int socket_fd, size_t rx_bufsize)
61 : d_socket_fd(socket_fd),
62 d_srb(new socket_rx_buffer(socket_fd, rx_bufsize))
73 class vrt_data_handler : public data_handler
75 rx_packet_handler *d_handler;
78 vrt_data_handler(rx_packet_handler *handler)
79 : d_handler(handler){}
83 result operator()(const void *base, size_t len);
86 vrt_data_handler::~vrt_data_handler(){}
89 vrt_data_handler::operator()(const void *base, size_t len)
92 print_words(0, (uint32_t *)base, len/(sizeof(uint32_t)));
95 const uint32_t *payload;
98 if (!expanded_header::parse((const uint32_t*) base, len/(sizeof(uint32_t)),
99 &hdr, &payload, &n32_bit_words)){
101 fprintf(stderr, "vrt_data_handler: malformed VRT packet!\n");
102 print_words(stderr, 0, (uint32_t *)base, len/(sizeof(uint32_t)));
106 bool want_more = (*d_handler)(payload, n32_bit_words, &hdr);
107 return !want_more ? data_handler::DONE : 0;
113 rx::rx_packets(rx_packet_handler *handler, bool dont_wait)
115 vrt_data_handler h(handler);
116 socket_rx_buffer::result r = d_srb->rx_frames(&h, dont_wait ? 0 : -1);
117 return r == socket_rx_buffer::EB_OK || r == socket_rx_buffer::EB_WOULD_BLOCK;