gr-baz Package

baz_udp_source.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2007,2008,2009,2010,2013 Free Software Foundation, Inc.
4 *
5 * This file is part of GNU Radio
6 *
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)
10 * any later version.
11 *
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.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#if (!defined(INCLUDED_GR_UDP_SOURCE_H) && !defined(IN_GR_BAZ)) || (!defined(INCLUDED_BAZ_UDP_SOURCE_H) && defined(IN_GR_BAZ))
24#ifdef IN_GR_BAZ
25#define INCLUDED_BAZ_UDP_SOURCE_H
26#else
27#define INCLUDED_GR_UDP_SOURCE_H
28#endif // IN_GR_BAZ
29
30#include <gnuradio/sync_block.h>
31#include <gnuradio/thread/thread.h>
32
33#ifdef IN_GR_BAZ
34#define UDP_SOURCE_NAME baz_udp_source
35#define UDP_SOURCE_MAKER baz_make_udp_source
36#define UDP_SOURCE_SPTR baz_udp_source_sptr
37#else
38#define UDP_SOURCE_NAME gr_udp_source
39#define UDP_SOURCE_MAKER gr_make_udp_source
40#define UDP_SOURCE_SPTR gr_udp_source_sptr
41#endif // IN_GR_BAZ
42
43#ifndef _TO_STR
44#define _TO_STR(x) #x
45#endif // _TO_STR
46#define UDP_SOURCE_STRING _TO_STR(UDP_SOURCE_NAME)
47
48#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
49#include <cstddef>
50 typedef ptrdiff_t ssize_t;
51#endif
52
53#include <stdio.h>
54
55 class BAZ_API UDP_SOURCE_NAME;
56 typedef boost::shared_ptr<UDP_SOURCE_NAME> UDP_SOURCE_SPTR;
57
58 enum UDPProtocol {
59 UP_COMPAT = -1,
60 UP_RAW,
61 UP_BORIP,
62 UP_ATA
63};
64
65 BAZ_API UDP_SOURCE_SPTR UDP_SOURCE_MAKER(size_t itemsize, const char *host,
66 unsigned short port,
67 int payload_size=1472,
68 bool eof=true, bool wait=true, bool bor=false, bool verbose=false, size_t buf_size = 0, int mode = UP_COMPAT);
69
70/*!
71 * \brief Read stream from an UDP socket.
72 * \ingroup source_blk
73 *
74 * \param itemsize The size (in bytes) of the item datatype
75 * \param host The name or IP address of the receiving host; can be
76 * NULL, None, or "0.0.0.0" to allow reading from any
77 * interface on the host
78 * \param port The port number on which to receive data; use 0 to
79 * have the system assign an unused port number
80 * \param payload_size UDP payload size by default set to 1472 =
81 * (1500 MTU - (8 byte UDP header) - (20 byte IP header))
82 * \param eof Interpret zero-length packet as EOF (default: true)
83 * \param wait Wait for data if not immediately available
84 * (default: true)
85 *
86*/
87
88 class BAZ_API UDP_SOURCE_NAME : public gr::sync_block
89{
90 friend BAZ_API UDP_SOURCE_SPTR UDP_SOURCE_MAKER(size_t itemsize,
91 const char *host,
92 unsigned short port,
93 int payload_size,
94 bool eof, bool wait, bool bor, bool verbose, size_t buf_size, int mode);
95
96 private:
97 size_t d_itemsize;
98 int d_payload_size; // maximum transmission unit (packet length)
99 bool d_eof; // zero-length packet is EOF
100 bool d_wait; // wait if data if not immediately available
101 int d_socket; // handle to socket
102 char *d_temp_buff; // hold buffer between calls
103 ssize_t d_residual; // hold information about number of bytes stored in the temp buffer
104 size_t d_temp_offset; // point to temp buffer location offset
105 bool d_bor;
106 unsigned long d_bor_counter;
107 bool d_bor_first;
108 bool d_verbose;
109 bool d_eos;
110 UDPProtocol d_mode;
111
112 protected:
113 /*!
114 * \brief UDP Source Constructor
115 *
116 * \param itemsize The size (in bytes) of the item datatype
117 * \param host The name or IP address of the receiving host; can be
118 * NULL, None, or "0.0.0.0" to allow reading from any
119 * interface on the host
120 * \param port The port number on which to receive data; use 0 to
121 * have the system assign an unused port number
122 * \param payload_size UDP payload size by default set to 1472 =
123 * (1500 MTU - (8 byte UDP header) - (20 byte IP header))
124 * \param eof Interpret zero-length packet as EOF (default: true)
125 * \param wait Wait for data if not immediately available
126 * (default: true)
127 * \param bor Enable BorIP encapsulation
128 * \param verbose Output BorIP packet debug messages (helpful to judge packet loss)
129 */
130 UDP_SOURCE_NAME(size_t itemsize, const char *host, unsigned short port,
131 int payload_size, bool eof, bool wait, bool bor, bool verbose, size_t buf_size, int mode);
132
133 public:
134 ~UDP_SOURCE_NAME();
135
136 /*! \brief return the PAYLOAD_SIZE of the socket */
137 int payload_size() { return d_payload_size; }
138
139 /*! \brief return the port number of the socket */
140 int get_port();
141
142 void signal_eos();
143
144 // should we export anything else?
145
146 int work(int noutput_items,
147 gr_vector_const_void_star &input_items,
148 gr_vector_void_star &output_items);
149};
150
151
152#endif /* INCLUDED_GR_UDP_SOURCE_H */
BAZ_API
#define BAZ_API
Definition api.h:19
UDP_SOURCE_SPTR
#define UDP_SOURCE_SPTR
Definition baz_udp_source.h:40
UDPProtocol
UDPProtocol
Definition baz_udp_source.h:58
UP_ATA
@ UP_ATA
Definition baz_udp_source.h:62
UP_COMPAT
@ UP_COMPAT
Definition baz_udp_source.h:59
UP_RAW
@ UP_RAW
Definition baz_udp_source.h:60
UP_BORIP
@ UP_BORIP
Definition baz_udp_source.h:61
UDP_SOURCE_MAKER
#define UDP_SOURCE_MAKER
Definition baz_udp_source.h:39
UDP_SOURCE_NAME
#define UDP_SOURCE_NAME
Definition baz_udp_source.h:38
UDP_SOURCE_NAME::work
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
UDP_SOURCE_NAME::get_port
int get_port()
return the port number of the socket
UDP_SOURCE_NAME::UDP_SOURCE_MAKER
friend BAZ_API UDP_SOURCE_SPTR UDP_SOURCE_MAKER(size_t itemsize, const char *host, unsigned short port, int payload_size, bool eof, bool wait, bool bor, bool verbose, size_t buf_size, int mode)
UDP_SOURCE_NAME::~UDP_SOURCE_NAME
~UDP_SOURCE_NAME()
UDP_SOURCE_NAME::signal_eos
void signal_eos()
UDP_SOURCE_NAME::UDP_SOURCE_NAME
UDP_SOURCE_NAME(size_t itemsize, const char *host, unsigned short port, int payload_size, bool eof, bool wait, bool bor, bool verbose, size_t buf_size, int mode)
UDP Source Constructor.
UDP_SOURCE_NAME::payload_size
int payload_size()
return the PAYLOAD_SIZE of the socket
Definition baz_udp_source.h:137