[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r4507 - in gnuradio/branches/developers/n4hy/ofdm2/gnu
From: |
n4hy |
Subject: |
[Commit-gnuradio] r4507 - in gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core: . doc src/lib/general src/lib/io src/lib/runtime src/lib/swig src/python/gnuradio src/python/gnuradio/blksimpl |
Date: |
Mon, 19 Feb 2007 12:33:30 -0700 (MST) |
Author: n4hy
Date: 2007-02-19 12:33:29 -0700 (Mon, 19 Feb 2007)
New Revision: 4507
Modified:
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/doc/Doxyfile.in
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/gnuradio-core.pc.in
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/general/gr_framer_sink_1.cc
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/general/gr_framer_sink_1.h
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_sink.cc
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_sink.h
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_sink.i
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_source.cc
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_source.h
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_source.i
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/swig/Makefile.am
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/python/gnuradio/blksimpl/pkt.py
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/python/gnuradio/packet_utils.py
Log:
bringing up to date
Modified: gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/doc/Doxyfile.in
===================================================================
--- gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/doc/Doxyfile.in
2007-02-19 19:33:08 UTC (rev 4506)
+++ gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/doc/Doxyfile.in
2007-02-19 19:33:29 UTC (rev 4507)
@@ -17,7 +17,7 @@
# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
# by quotes) that should identify the project.
-PROJECT_NAME = "GNU Radio 2.x"
+PROJECT_NAME = "GNU Radio @VERSION@"
# The PROJECT_NUMBER tag can be used to enter a project or revision number.
# This could be handy for archiving the generated documentation or
@@ -447,8 +447,24 @@
INPUT = @top_srcdir@/gnuradio-core/src/lib \
@top_srcdir@/gnuradio-core/src/tests \
- @top_srcdir@/gnuradio-core/doc/other
+ @top_srcdir@/gnuradio-core/doc/other \
+ @top_srcdir@/gr-audio-alsa \
+ @top_srcdir@/gr-audio-jack \
+ @top_srcdir@/gr-audio-oss \
+ @top_srcdir@/gr-audio-osx \
+ @top_srcdir@/gr-audio-portaudio \
+ @top_srcdir@/gr-gsm-fr-vocoder \
+ @top_srcdir@/gr-pager \
+ @top_srcdir@/gr-radio-astronomy \
+ @top_srcdir@/gr-trellis \
+ @top_srcdir@/gr-usrp \
+ @top_srcdir@/gr-video-sdl \
+ @top_srcdir@/mblock \
+ @top_srcdir@/omnithread \
+ @top_srcdir@/pmt \
+ @top_srcdir@/usrp/host
+
# If the value of the INPUT tag contains directories, you can use the
# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
# and *.h) to filter out the source-files in the directories. If left
@@ -470,12 +486,31 @@
# excluded from the INPUT source files. This way you can easily exclude a
# subdirectory from a directory tree whose root is specified with the INPUT
tag.
-EXCLUDE = CVS \
-
@top_srcdir@/gnuradio-core/src/lib/swig/gnuradio_swig_python.cc \
- @top_srcdir@/gnuradio-core/src/lib/atsc \
- @top_srcdir@/gnuradio-core/src/lib/io-orig \
- @top_srcdir@/gnuradio-core/src/lib/vrx
+EXCLUDE = CVS .svn .libs .deps \
+
@top_builddir@/gnuradio-core/src/lib/swig/gnuradio_swig_py_filter.cc \
+
@top_builddir@/gnuradio-core/src/lib/swig/gnuradio_swig_py_general.cc \
+
@top_builddir@/gnuradio-core/src/lib/swig/gnuradio_swig_py_gengen.cc \
+
@top_builddir@/gnuradio-core/src/lib/swig/gnuradio_swig_py_io.cc \
+
@top_builddir@/gnuradio-core/src/lib/swig/gnuradio_swig_py_runtime.cc \
+ @top_builddir@/gr-atsc/src/lib/atsc.cc \
+ @top_builddir@/gr-audio-alsa/src/audio_alsa.cc \
+ @top_builddir@/gr-audio-jack/src/audio_jack.cc \
+ @top_builddir@/gr-audio-oss/src/audio_oss.cc \
+ @top_builddir@/gr-audio-osx/src/audio_osx.cc \
+
@top_builddir@/gr-audio-portaudio/src/audio_portaudio.cc \
+ @top_builddir@/gr-audio-windows/src/audio_windows.cc \
+ @top_builddir@/gr-comedi/src/comedi.cc \
+ @top_builddir@/gr-ezdop/src/lib/ezdop.cc \
+
@top_builddir@/gr-gsm-fr-vocoder/src/lib/gsm_full_rate.cc \
+ @top_builddir@/gr-howto-write-a-block/src/lib/howto.cc
\
+ @top_builddir@/gr-pager/src/pager_swig.cc \
+ @top_builddir@/gr-radio-astronomy/src/lib/ra.cc \
+ @top_builddir@/gr-trellis/src/lib/trellis.cc \
+ @top_builddir@/gr-usrp/src/usrp1.cc \
+ @top_builddir@/gr-video-sdl/src/video_sdl.cc \
+ @top_builddir@/usrp/host/swig/prims.cc
+
# The EXCLUDE_SYMLINKS tag can be used select whether or not files or
# directories that are symbolic links (a Unix filesystem feature) are excluded
# from the input.
Modified:
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/gnuradio-core.pc.in
===================================================================
--- gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/gnuradio-core.pc.in
2007-02-19 19:33:08 UTC (rev 4506)
+++ gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/gnuradio-core.pc.in
2007-02-19 19:33:29 UTC (rev 4507)
@@ -7,5 +7,5 @@
Description: GNU Software Radio toolkit
Requires:
Version: @VERSION@
-Libs: -L${libdir} -lgnuradio-core @FFTW3F_LIBS@ @OMNITHREAD_LIBS@
+Libs: -L${libdir} -lgnuradio-core @FFTW3F_LIBS@ -lgromnithread
Cflags: -I${includedir} @DEFINES@ @PTHREAD_CFLAGS@
Modified:
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/general/gr_framer_sink_1.cc
===================================================================
---
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/general/gr_framer_sink_1.cc
2007-02-19 19:33:08 UTC (rev 4506)
+++
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/general/gr_framer_sink_1.cc
2007-02-19 19:33:29 UTC (rev 4507)
@@ -52,13 +52,14 @@
}
inline void
-gr_framer_sink_1::enter_have_header(int payload_len)
+gr_framer_sink_1::enter_have_header(int payload_len, int whitener_offset)
{
if (VERBOSE)
- fprintf(stderr, "@ enter_have_header (payload_len = %d)\n", payload_len);
+ fprintf(stderr, "@ enter_have_header (payload_len = %d) (offset = %d)\n",
payload_len, whitener_offset);
d_state = STATE_HAVE_HEADER;
d_packetlen = payload_len;
+ d_packet_whitener_offset = whitener_offset;
d_packetlen_cnt = 0;
d_packet_byte = 0;
d_packet_byte_index = 0;
@@ -125,11 +126,10 @@
// we have a full header, check to see if it has been received
properly
if (header_ok()){
- int payload_len = header_payload_len();
- if (payload_len <= MAX_PKT_LEN) // reasonable?
- enter_have_header(payload_len); // yes.
- else
- enter_search(); // no.
+ int payload_len;
+ int payload_offset;
+ header_payload(&payload_len, &payload_offset);
+ enter_have_header(payload_len, payload_offset);
}
else
enter_search(); // no.
@@ -151,7 +151,8 @@
if (d_packetlen_cnt == d_packetlen){ // packet is filled
// build a message
- gr_message_sptr msg = gr_make_message(0, 0, 0, d_packetlen_cnt);
+ // NOTE: passing header field as arg1 is not scalable
+ gr_message_sptr msg = gr_make_message(0, d_packet_whitener_offset,
0, d_packetlen_cnt);
memcpy(msg->msg(), d_packet, d_packetlen_cnt);
d_target_queue->insert_tail(msg); // send it
Modified:
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/general/gr_framer_sink_1.h
===================================================================
---
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/general/gr_framer_sink_1.h
2007-02-19 19:33:08 UTC (rev 4506)
+++
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/general/gr_framer_sink_1.h
2007-02-19 19:33:29 UTC (rev 4507)
@@ -70,6 +70,7 @@
unsigned char d_packet_byte; // byte being assembled
int d_packet_byte_index; // which bit of d_packet_byte
we're working on
int d_packetlen; // length of packet
+ int d_packet_whitener_offset; // offset into whitener string
to use
int d_packetlen_cnt; // how many so far
protected:
@@ -77,7 +78,7 @@
void enter_search();
void enter_have_sync();
- void enter_have_header(int payload_len);
+ void enter_have_header(int payload_len, int whitener_offset);
bool header_ok()
{
@@ -85,11 +86,13 @@
return ((d_header >> 16) ^ (d_header & 0xffff)) == 0;
}
- int header_payload_len()
+ void header_payload(int *len, int *offset)
{
// header consists of two 16-bit shorts in network byte order
- int t = (d_header >> 16) & 0xffff;
- return t;
+ // payload length is lower 12 bits
+ // whitener offset is upper 4 bits
+ *len = (d_header >> 16) & 0x0fff;
+ *offset = (d_header >> 28) & 0x000f;
}
public:
Modified:
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_sink.cc
===================================================================
---
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_sink.cc
2007-02-19 19:33:08 UTC (rev 4506)
+++
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_sink.cc
2007-02-19 19:33:29 UTC (rev 4507)
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2006 Free Software Foundation, Inc.
+ * Copyright 2007 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -20,42 +20,59 @@
* Boston, MA 02110-1301, USA.
*/
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
#include <gr_udp_sink.h>
#include <gr_io_signature.h>
-#include <cstdio>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
#include <stdexcept>
+#include <netdb.h>
#define SNK_VERBOSE 0
gr_udp_sink::gr_udp_sink (size_t itemsize,
- const char *ipaddrl, unsigned short portl,
- const char *ipaddrr, unsigned short portr,
- unsigned int mtu)
+ const char *src, unsigned short port_src,
+ const char *dst, unsigned short port_dst,
+ int payload_size)
: gr_sync_block ("udp_sink",
gr_make_io_signature (1, 1, itemsize),
gr_make_io_signature (0, 0, 0)),
- d_itemsize (itemsize), d_updated(false), d_mtu(mtu)
+ d_itemsize (itemsize), d_updated(false), d_payload_size(payload_size)
{
- // Set up the address stucture for the local address and port numbers
- inet_aton(ipaddrl, &d_ipaddr_local); // format IP address
- inet_aton(ipaddrr, &d_ipaddr_remote); // format IP address
- d_port_local = htons(portl); // format port number
- d_port_remote = htons(portr); // format port number
+ int ret = 0;
+
+ // Set up the address stucture for the source address and port numbers
+ // Get the source IP address from the host name
+ struct hostent *hsrc = gethostbyname(src);
+ if(hsrc) { // if the source was provided as a host namex
+ d_ip_src = *(struct in_addr*)hsrc->h_addr_list[0];
+ }
+ else { // assume it was specified as an IP address
+ if((ret=inet_aton(src, &d_ip_src)) == 0) { // format IP address
+ perror("Not a valid source IP address or host name");
+ throw std::runtime_error("can't initialize source socket");
+ }
+ }
- d_sockaddr_local.sin_family = AF_INET;
- d_sockaddr_local.sin_addr = d_ipaddr_local;
- d_sockaddr_local.sin_port = d_port_local;
+ // Get the destination IP address from the host name
+ struct hostent *hdst = gethostbyname(dst);
+ if(hdst) { // if the source was provided as a host namex
+ d_ip_dst = *(struct in_addr*)hdst->h_addr_list[0];
+ }
+ else { // assume it was specified as an IP address
+ if((ret=inet_aton(dst, &d_ip_dst)) == 0) { // format IP address
+ perror("Not a valid destination IP address or host name");
+ throw std::runtime_error("can't initialize destination socket");
+ }
+ }
- d_sockaddr_remote.sin_family = AF_INET;
- d_sockaddr_remote.sin_addr = d_ipaddr_remote;
- d_sockaddr_remote.sin_port = d_port_remote;
+ d_port_src = htons(port_src); // format port number
+ d_port_dst = htons(port_dst); // format port number
+
+ d_sockaddr_src.sin_family = AF_INET;
+ d_sockaddr_src.sin_addr = d_ip_src;
+ d_sockaddr_src.sin_port = d_port_src;
+
+ d_sockaddr_dst.sin_family = AF_INET;
+ d_sockaddr_dst.sin_addr = d_ip_dst;
+ d_sockaddr_dst.sin_port = d_port_dst;
open();
}
@@ -64,14 +81,14 @@
gr_udp_sink_sptr
gr_make_udp_sink (size_t itemsize,
- const char *ipaddrl, unsigned short portl,
- const char *ipaddrr, unsigned short portr,
- unsigned int mtu)
+ const char *src, unsigned short port_src,
+ const char *dst, unsigned short port_dst,
+ int payload_size)
{
return gr_udp_sink_sptr (new gr_udp_sink (itemsize,
- ipaddrl, portl,
- ipaddrr, portr,
- mtu));
+ src, port_src,
+ dst, port_dst,
+ payload_size));
}
gr_udp_sink::~gr_udp_sink ()
@@ -91,7 +108,7 @@
}
// Turn on reuse address
- bool opt_val = true;
+ int opt_val = true;
if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val,
sizeof(int)) == -1) {
perror("SO_REUSEADDR");
throw std::runtime_error("can't set socket option SO_REUSEADDR");
@@ -107,13 +124,13 @@
}
// bind socket to an address and port number to listen on
- if(bind (d_socket, (sockaddr*)&d_sockaddr_local, sizeof(struct sockaddr)) ==
-1) {
+ if(bind (d_socket, (sockaddr*)&d_sockaddr_src, sizeof(struct sockaddr)) ==
-1) {
perror("socket bind");
throw std::runtime_error("can't bind socket");
}
// Not sure if we should throw here or allow retries
- if(connect(d_socket, (sockaddr*)&d_sockaddr_remote, sizeof(struct sockaddr))
== -1) {
+ if(connect(d_socket, (sockaddr*)&d_sockaddr_dst, sizeof(struct sockaddr)) ==
-1) {
perror("socket connect");
throw std::runtime_error("can't connect to socket");
}
@@ -139,14 +156,27 @@
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
- char *in = (char *) input_items[0];
- socklen_t bytes=0, bytes_sent=0, bytes_to_send=0;
- unsigned int total_size = noutput_items*d_itemsize;
+ const char *in = (const char *) input_items[0];
+ ssize_t r=0, bytes_sent=0, bytes_to_send=0;
+ ssize_t total_size = noutput_items*d_itemsize;
- while(bytes_sent < total_size) {
- bytes_to_send = (bytes_sent+d_mtu < total_size ? d_mtu :
total_size-bytes_sent);
- bytes = send(d_socket, (in+bytes_sent), bytes_to_send, MSG_DONTWAIT);
- bytes_sent += bytes;
+ #if SNK_VERBOSE
+ printf("Entered upd_sink\n");
+ #endif
+
+ while(bytes_sent < total_size) {
+ bytes_to_send = std::min((ssize_t)d_payload_size, (total_size-bytes_sent));
+
+ r = send(d_socket, (in+bytes_sent), bytes_to_send, 0);
+ if(r == -1) { // error on send command
+ perror("udp_sink"); // there should be no error case where this function
+ return -1; // should not exit immediately
+ }
+ bytes_sent += r;
+
+ #if SNK_VERBOSE
+ printf("\tbyte sent: %d bytes\n", bytes);
+ #endif
}
#if SNK_VERBOSE
Modified:
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_sink.h
===================================================================
---
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_sink.h
2007-02-19 19:33:08 UTC (rev 4506)
+++
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_sink.h
2007-02-19 19:33:29 UTC (rev 4507)
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2006 Free Software Foundation, Inc.
+ * Copyright 2007 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -31,43 +31,66 @@
class gr_udp_sink;
typedef boost::shared_ptr<gr_udp_sink> gr_udp_sink_sptr;
+gr_udp_sink_sptr
+gr_make_udp_sink (size_t itemsize,
+ const char *src, unsigned short port_src,
+ const char *dst, unsigned short port_dst,
+ int payload_size=1472);
+
/*!
- * \brief Write stream to an Udp port (over UDP).
+ * \brief Write stream to an UDP socket.
* \ingroup sink
+ *
+ * \param itemsize The size (in bytes) of the item datatype
+ * \param src The source address as either the host name or the
'numbers-and-dots'
+ * IP address
+ * \param port_src Destination port to bind to (0 allows socket to choose
an appropriate port)
+ * \param dst The destination address as either the host name or the
'numbers-and-dots'
+ * IP address
+ * \param port_dst Destination port to connect to
+ * \param payload_size UDP payload size by default set to
+ * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP
header))
*/
-gr_udp_sink_sptr
-gr_make_udp_sink (size_t itemsize,
- const char *ipaddrl, unsigned short portl,
- const char *ipaddrr, unsigned short portr,
- unsigned int mtu=540);
-
class gr_udp_sink : public gr_sync_block
{
friend gr_udp_sink_sptr gr_make_udp_sink (size_t itemsize,
- const char *ipaddrl, unsigned short
portl,
- const char *ipaddrr, unsigned short
portr,
- unsigned int mtu);
+ const char *src, unsigned short
port_src,
+ const char *dst, unsigned short
port_dst,
+ int payload_size);
private:
size_t d_itemsize;
bool d_updated;
omni_mutex d_mutex;
- unsigned int d_mtu; // maximum transmission unit (packet
length)
+ int d_payload_size; // maximum transmission unit (packet
length)
int d_socket; // handle to socket
int d_socket_rcv; // handle to socket retuned in the accept
call
- struct in_addr d_ipaddr_local; // store the local IP address to use
- struct in_addr d_ipaddr_remote; // store the remote IP address that
connected to us
- unsigned short d_port_local; // the port number to open for connections
to this service
- unsigned short d_port_remote; // port number of the remove system
- sockaddr_in d_sockaddr_local; // store the local sockaddr data
(formatted IP address and port number)
- sockaddr_in d_sockaddr_remote; // store the remote sockaddr data
(formatted IP address and port number)
+ struct in_addr d_ip_src; // store the source ip info
+ struct in_addr d_ip_dst; // store the destination ip info
+ unsigned short d_port_src; // the port number to open for connections
to this service
+ unsigned short d_port_dst; // port number of the remove system
+ sockaddr_in d_sockaddr_src; // store the source sockaddr data
(formatted IP address and port number)
+ sockaddr_in d_sockaddr_dst; // store the destination sockaddr data
(formatted IP address and port number)
protected:
+ /*!
+ * \brief UDP Sink Constructor
+ *
+ * \param itemsize The size (in bytes) of the item datatype
+ * \param src The source address as either the host name or the
'numbers-and-dots'
+ * IP address
+ * \param port_src Destination port to bind to (0 allows socket to
choose an appropriate port)
+ * \param dst The destination address as either the host name or
the 'numbers-and-dots'
+ * IP address
+ * \param port_dst Destination port to connect to
+ * \param payload_size UDP payload size by default set to
+ * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP
header))
+ */
gr_udp_sink (size_t itemsize,
- const char *ipaddrl, unsigned short portl,
- const char *ipaddrr, unsigned short portr,
- unsigned int mtu);
+ const char *src, unsigned short port_src,
+ const char *dst, unsigned short port_dst,
+ int payload_size);
public:
~gr_udp_sink ();
@@ -87,12 +110,9 @@
*/
void close();
- /*! \brief set the MTU of the socket */
- void set_mtu(unsigned int mtu) { d_mtu = mtu; }
+ /*! \brief return the PAYLOAD_SIZE of the socket */
+ int payload_size() { return d_payload_size; }
- /*! \brief return the MTU of the socket */
- unsigned int mtu() { return d_mtu; }
-
// should we export anything else?
int work (int noutput_items,
Modified:
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_sink.i
===================================================================
---
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_sink.i
2007-02-19 19:33:08 UTC (rev 4506)
+++
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_sink.i
2007-02-19 19:33:29 UTC (rev 4507)
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2006 Free Software Foundation, Inc.
+ * Copyright 2007 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -25,22 +25,21 @@
gr_udp_sink_sptr
gr_make_udp_sink (size_t itemsize,
- const char *ipaddrl, unsigned short portl,
- const char *ipaddrr, unsigned short portr,
- unsigned int mtu=540);
+ const char *src, unsigned short port_src,
+ const char *dst, unsigned short port_dst,
+ int payload_size=1472);
class gr_udp_sink : public gr_sync_block
{
protected:
gr_udp_sink (size_t itemsize,
- const char *ipaddrl, unsigned short portl,
- const char *ipaddrr, unsigned short portr,
- unsigned int mtu);
+ const char *src, unsigned short port_src,
+ const char *dst, unsigned short port_dst,
+ int payload_size);
bool open();
void close();
- void set_mtu(unsigned int mtu) { d_mtu = mtu; }
- unsigned int mtu() { return d_mtu; }
+ int payload_size() { return d_payload_size; }
public:
~gr_udp_sink ();
Modified:
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_source.cc
===================================================================
---
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_source.cc
2007-02-19 19:33:08 UTC (rev 4506)
+++
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_source.cc
2007-02-19 19:33:29 UTC (rev 4507)
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2006 Free Software Foundation, Inc.
+ * Copyright 2007 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -20,48 +20,58 @@
* Boston, MA 02110-1301, USA.
*/
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
#include <gr_udp_source.h>
#include <gr_io_signature.h>
-#include <cstdio>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
#include <stdexcept>
+#include <errno.h>
+#include <netdb.h>
#define SRC_VERBOSE 0
-gr_udp_source::gr_udp_source(size_t itemsize, const char *ipaddr,
- unsigned short port, unsigned int mtu)
+gr_udp_source::gr_udp_source(size_t itemsize, const char *src,
+ unsigned short port_src, int payload_size)
: gr_sync_block ("udp_source",
gr_make_io_signature(0, 0, 0),
gr_make_io_signature(1, 1, itemsize)),
- d_itemsize(itemsize), d_updated(false), d_mtu(mtu)
+ d_itemsize(itemsize), d_updated(false), d_payload_size(payload_size),
d_residual(0), d_temp_offset(0)
{
- // Set up the address stucture for the local address and port numbers
- inet_aton(ipaddr, &d_ipaddr_local); // format IP address
- d_port_local = htons(port); // format port number
+ int ret = 0;
- d_sockaddr_local.sin_family = AF_INET;
- d_sockaddr_local.sin_addr = d_ipaddr_local;
- d_sockaddr_local.sin_port = d_port_local;
+ // Set up the address stucture for the source address and port numbers
+ // Get the source IP address from the host name
+ struct hostent *hsrc = gethostbyname(src);
+ if(hsrc) { // if the source was provided as a host namex
+ d_ip_src = *(struct in_addr*)hsrc->h_addr_list[0];
+ }
+ else { // assume it was specified as an IP address
+ if((ret=inet_aton(src, &d_ip_src)) == 0) { // format IP address
+ perror("Not a valid source IP address or host name");
+ throw std::runtime_error("can't initialize source socket");
+ }
+ }
+
+ d_port_src = htons(port_src); // format port number
+ d_sockaddr_src.sin_family = AF_INET;
+ d_sockaddr_src.sin_addr = d_ip_src;
+ d_sockaddr_src.sin_port = d_port_src;
+
+ d_temp_buff = new char[d_payload_size]; // allow it to hold up to
payload_size bytes
+
open();
}
gr_udp_source_sptr
gr_make_udp_source (size_t itemsize, const char *ipaddr,
- unsigned short port, unsigned int mtu)
+ unsigned short port, int payload_size)
{
return gr_udp_source_sptr (new gr_udp_source (itemsize, ipaddr,
- port, mtu));
+ port, payload_size));
}
gr_udp_source::~gr_udp_source ()
{
+ delete [] d_temp_buff;
close();
}
@@ -69,16 +79,15 @@
gr_udp_source::open()
{
omni_mutex_lock l(d_mutex); // hold mutex for duration of this function
-
// create socket
- d_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ d_socket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
if(d_socket == -1) {
perror("socket open");
throw std::runtime_error("can't open socket");
}
// Turn on reuse address
- bool opt_val = true;
+ int opt_val = 1;
if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val,
sizeof(int)) == -1) {
perror("SO_REUSEADDR");
throw std::runtime_error("can't set socket option SO_REUSEADDR");
@@ -104,7 +113,7 @@
}
// bind socket to an address and port number to listen on
- if(bind (d_socket, (sockaddr*)&d_sockaddr_local, sizeof(struct sockaddr)) ==
-1) {
+ if(bind (d_socket, (sockaddr*)&d_sockaddr_src, sizeof(struct sockaddr)) ==
-1) {
perror("socket bind");
throw std::runtime_error("can't bind socket");
}
@@ -131,33 +140,86 @@
gr_vector_void_star &output_items)
{
char *out = (char *) output_items[0];
- socklen_t bytes_to_receive=0, bytes_received=0;
- int bytes=0;
+ ssize_t r=0, nbytes=0, bytes_received=0;
+ ssize_t total_bytes = (ssize_t)(d_itemsize*noutput_items);
- while((bytes_received < (unsigned)noutput_items) && (bytes>-1)) {
- // caclulate the number of byte left if we can fit in all d_mtu bytes
- bytes_to_receive = (bytes_received+d_mtu < noutput_items ?
- d_mtu : noutput_items-bytes_received);
+ #if SRC_VERBOSE
+ printf("\nEntered udp_source\n");
+ #endif
+
+ // Remove items from temp buffer if they are in there
+ if(d_residual) {
+ nbytes = std::min(d_residual, total_bytes);
+ memcpy(out, d_temp_buff+d_temp_offset, nbytes);
+ bytes_received = nbytes;
+
+ #if SRC_VERBOSE
+ printf("\tTemp buff size: %d offset: %d (bytes_received: %d)
(noutput_items: %d)\n",
+ d_residual, d_temp_offset, bytes_received, noutput_items);
+ #endif
+
+ // Increment pointer
+ out += bytes_received;
+ // Update indexing of amount of bytes left in the buffer
+ d_residual -= nbytes;
+ d_temp_offset = d_temp_offset+d_residual;
+ }
+
+ while(1) {
// get the data into our output buffer and record the number of bytes
- // This is a blocking call, but it's timeout has been set in the
constructor
- bytes = recv(d_socket, out, bytes_to_receive, 0);
+ // This is a non-blocking call with a timeout set in the constructor
+ r = recv(d_socket, d_temp_buff, d_payload_size, 0); // get the entire
payload or the what's available
- // FIXME if bytes < 0 bail
+ // Check if there was a problem; forget it if the operation just timed out
+ if(r == -1) {
+ if(errno == EAGAIN) { // handle non-blocking call timeout
+ #if SRC_VERBOSE
+ printf("UDP receive timed out\n");
+ #endif
- if(bytes > 0) {
+ // Break here to allow the rest of the flow graph time to run and so
ctrl-C breaks
+ break;
+ }
+ else {
+ perror("udp_source");
+ return -1;
+ }
+ }
+ else {
+ // Calculate the number of bytes we can take from the buffer in this call
+ nbytes = std::min(r, total_bytes-bytes_received);
+
+ // adjust the total number of bytes we have to round down to nearest
integer of an itemsize
+ nbytes -= ((bytes_received+nbytes) % d_itemsize);
+
+ // copy the number of bytes we want to look at here
+ memcpy(out, d_temp_buff, nbytes);
+
+ d_residual = r - nbytes; // save the number of
bytes stored
+ d_temp_offset=nbytes; // reset buffer index
+
// keep track of the total number of bytes received
- bytes_received += bytes;
+ bytes_received += nbytes;
// increment the pointer
- out += bytes;
+ out += nbytes;
+
+ // Immediately return when data comes in
+ break;
}
+
+ #if SNK_VERBOSE
+ printf("\tbytes received: %d bytes (nbytes: %d)\n", bytes, nbytes);
+ #endif
}
#if SRC_VERBOSE
- printf("\nTotal Bytes Received: %d (noutput_items=%d)\n", bytes_received,
noutput_items);
+ printf("Total Bytes Received: %d (bytes_received / noutput_items = %d /
%d)\n",
+ bytes_received, bytes_received, noutput_items);
#endif
- // FIXME what if (bytes_received % d_itemsize) != 0 ???
- return int(bytes_received / d_itemsize);
+ // bytes_received is already set to some integer multiple of itemsize
+ return bytes_received/d_itemsize;
}
+
Modified:
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_source.h
===================================================================
---
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_source.h
2007-02-19 19:33:08 UTC (rev 4506)
+++
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_source.h
2007-02-19 19:33:29 UTC (rev 4507)
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2006 Free Software Foundation, Inc.
+ * Copyright 2007 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -31,31 +31,55 @@
class gr_udp_source;
typedef boost::shared_ptr<gr_udp_source> gr_udp_source_sptr;
-gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *ipaddr,
- unsigned short port, unsigned int
mtu=540);
+gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char *src,
+ unsigned short port_src, int
payload_size=1472);
+/*!
+ * \brief Read stream from an UDP socket.
+ * \ingroup sink
+ *
+ * \param itemsize The size (in bytes) of the item datatype
+ * \param src The source address as either the host name or the
'numbers-and-dots'
+ * IP address
+ * \param port_src The port number on which the socket listens for data
+ * \param payload_size UDP payload size by default set to
+ * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP
header))
+ *
+*/
+
class gr_udp_source : public gr_sync_block
{
- friend gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char
*ipaddr,
- unsigned short port, unsigned
int mtu);
+ friend gr_udp_source_sptr gr_make_udp_source(size_t itemsize, const char
*src,
+ unsigned short port_src, int
payload_size);
private:
size_t d_itemsize;
bool d_updated;
omni_mutex d_mutex;
- unsigned int d_mtu; // maximum transmission unit (packet length)
+ int d_payload_size; // maximum transmission unit (packet length)
int d_socket; // handle to socket
int d_socket_rcv; // handle to socket retuned in the accept
call
- struct in_addr d_ipaddr_local; // store the local IP address to use
- struct in_addr d_ipaddr_remote; // store the remote IP address that
connected to us
- unsigned short d_port_local; // the port number to open for connections
to this service
- unsigned short d_port_remote; // port number of the remove system
- sockaddr_in d_sockaddr_local; // store the local sockaddr data
(formatted IP address and port number)
- sockaddr_in d_sockaddr_remote; // store the remote sockaddr data
(formatted IP address and port number)
-
+ struct in_addr d_ip_src; // store the source IP address to use
+ unsigned short d_port_src; // the port number to open for connections
to this service
+ sockaddr_in d_sockaddr_src; // store the source sockaddr data (formatted
IP address and port number)
+
+ char *d_temp_buff; // hold buffer between calls
+ ssize_t d_residual; // hold information about number of bytes stored in
the temp buffer
+ size_t d_temp_offset; // point to temp buffer location offset
+
protected:
- gr_udp_source(size_t itemsize, const char *ipaddr, unsigned short port,
unsigned int mtu);
+ /*!
+ * \brief UDP Source Constructor
+ *
+ * \param itemsize The size (in bytes) of the item datatype
+ * \param src The source address as either the host name or the
'numbers-and-dots'
+ * IP address
+ * \param port_src The port number on which the socket listens for data
+ * \param payload_size UDP payload size by default set to
+ * 1472 = (1500 MTU - (8 byte UDP header) - (20 byte IP
header))
+ */
+ gr_udp_source(size_t itemsize, const char *src, unsigned short port_src, int
payload_size);
public:
~gr_udp_source();
@@ -75,12 +99,9 @@
*/
void close();
- /*! \brief set the MTU of the socket */
- void set_mtu(unsigned int mtu) { d_mtu = mtu; }
+ /*! \brief return the PAYLOAD_SIZE of the socket */
+ int payload_size() { return d_payload_size; }
- /*! \brief return the MTU of the socket */
- unsigned int mtu() { return d_mtu; }
-
// should we export anything else?
int work(int noutput_items,
Modified:
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_source.i
===================================================================
---
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_source.i
2007-02-19 19:33:08 UTC (rev 4506)
+++
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/io/gr_udp_source.i
2007-02-19 19:33:29 UTC (rev 4507)
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2006 Free Software Foundation, Inc.
+ * Copyright 2007 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -23,21 +23,20 @@
GR_SWIG_BLOCK_MAGIC(gr,udp_source)
gr_udp_source_sptr
-gr_make_udp_source (size_t itemsize, const char *ipaddr,
- unsigned short port, unsigned int mtu=540);
+gr_make_udp_source (size_t itemsize, const char *src,
+ unsigned short port_src, int payload_size=1472);
class gr_udp_source : public gr_sync_block
{
protected:
- gr_udp_source (size_t itemsize, const char *ipaddr,
- unsigned short port, unsigned int mtu);
+ gr_udp_source (size_t itemsize, const char *src,
+ unsigned short port_src, int payload_size);
public:
~gr_udp_source ();
bool open();
void close();
- void set_mtu(unsigned int mtu) { d_mtu = mtu; }
- unsigned int mtu() { return d_mtu; }
+ int payload_size() { return d_payload_size; }
};
Modified:
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc
===================================================================
---
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc
2007-02-19 19:33:08 UTC (rev 4506)
+++
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/runtime/gr_vmcircbuf_sysv_shm.cc
2007-02-19 19:33:29 UTC (rev 4507)
@@ -68,11 +68,13 @@
if ((shmid2 = shmget (IPC_PRIVATE, 2 * size + 2 * pagesize, IPC_CREAT |
0700)) == -1){
perror ("gr_vmcircbuf_sysv_shm: shmget (1)");
+ shmctl (shmid_guard, IPC_RMID, 0);
throw std::runtime_error ("gr_vmcircbuf_sysv_shm");
}
if ((shmid1 = shmget (IPC_PRIVATE, size, IPC_CREAT | 0700)) == -1){
perror ("gr_vmcircbuf_sysv_shm: shmget (2)");
+ shmctl (shmid_guard, IPC_RMID, 0);
shmctl (shmid2, IPC_RMID, 0);
throw std::runtime_error ("gr_vmcircbuf_sysv_shm");
}
Modified:
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/swig/Makefile.am
===================================================================
---
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/swig/Makefile.am
2007-02-19 19:33:08 UTC (rev 4506)
+++
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/lib/swig/Makefile.am
2007-02-19 19:33:29 UTC (rev 4507)
@@ -118,6 +118,7 @@
_gnuradio_swig_py_runtime_la_LIBADD = \
+ $(GNURADIO_CORE_LIBS) \
$(top_builddir)/gnuradio-core/src/lib/libgnuradio-core.la \
$(PYTHON_LDFLAGS) \
-lstdc++
@@ -149,6 +150,7 @@
_gnuradio_swig_py_general_la_LIBADD = \
+ $(GNURADIO_CORE_LIBS) \
$(top_builddir)/gnuradio-core/src/lib/libgnuradio-core.la \
$(PYTHON_LDFLAGS) \
-lstdc++
@@ -180,6 +182,7 @@
_gnuradio_swig_py_gengen_la_LIBADD = \
+ $(GNURADIO_CORE_LIBS) \
$(top_builddir)/gnuradio-core/src/lib/libgnuradio-core.la \
$(PYTHON_LDFLAGS) \
-lstdc++
@@ -211,6 +214,7 @@
_gnuradio_swig_py_filter_la_LIBADD = \
+ $(GNURADIO_CORE_LIBS) \
$(top_builddir)/gnuradio-core/src/lib/libgnuradio-core.la \
$(PYTHON_LDFLAGS) \
-lstdc++
@@ -242,6 +246,7 @@
_gnuradio_swig_py_io_la_LIBADD = \
+ $(GNURADIO_CORE_LIBS) \
$(top_builddir)/gnuradio-core/src/lib/libgnuradio-core.la \
$(PYTHON_LDFLAGS) \
-lstdc++
Modified:
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/python/gnuradio/blksimpl/pkt.py
===================================================================
---
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/python/gnuradio/blksimpl/pkt.py
2007-02-19 19:33:08 UTC (rev 4506)
+++
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/python/gnuradio/blksimpl/pkt.py
2007-02-19 19:33:29 UTC (rev 4507)
@@ -36,7 +36,7 @@
Send packets by calling send_pkt
"""
- def __init__(self, fg, modulator, access_code=None, msgq_limit=2,
pad_for_usrp=True):
+ def __init__(self, fg, modulator, access_code=None, msgq_limit=2,
pad_for_usrp=True, use_whitener_offset=False):
"""
Hierarchical block for sending packets
@@ -52,12 +52,15 @@
@param msgq_limit: maximum number of messages in message queue
@type msgq_limit: int
@param pad_for_usrp: If true, packets are padded such that they end up
a multiple of 128 samples
-
+ @param use_whitener_offset: If true, start of whitener XOR string is
incremented each packet
+
See gmsk_mod for remaining parameters
"""
self._modulator = modulator
self._pad_for_usrp = pad_for_usrp
-
+ self._use_whitener_offset = use_whitener_offset
+ self._whitener_offset = 0
+
if access_code is None:
access_code = packet_utils.default_access_code
if not packet_utils.is_1_0_string(access_code):
@@ -84,9 +87,13 @@
self._modulator.samples_per_symbol(),
self._modulator.bits_per_symbol(),
self._access_code,
- self._pad_for_usrp)
+ self._pad_for_usrp,
+ self._whitener_offset)
#print "pkt =", string_to_hex_list(pkt)
msg = gr.message_from_string(pkt)
+ if self._use_whitener_offset is True:
+ self._whitener_offset = (self._whitener_offset + 1) % 16
+
self._pkt_input.msgq().insert_tail(msg)
@@ -151,6 +158,6 @@
def run(self):
while self.keep_running:
msg = self.rcvd_pktq.delete_head()
- ok, payload = packet_utils.unmake_packet(msg.to_string())
+ ok, payload = packet_utils.unmake_packet(msg.to_string(),
int(msg.arg1()))
if self.callback:
self.callback(ok, payload)
Modified:
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/python/gnuradio/packet_utils.py
===================================================================
---
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/python/gnuradio/packet_utils.py
2007-02-19 19:33:08 UTC (rev 4506)
+++
gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core/src/python/gnuradio/packet_utils.py
2007-02-19 19:33:29 UTC (rev 4507)
@@ -86,22 +86,26 @@
return map(lambda x: hex(ord(x)), s)
-def whiten(s):
+def whiten(s, o):
sa = Numeric.fromstring(s, Numeric.UnsignedInt8)
- z = sa ^ random_mask_vec8[0:len(sa)]
+ z = sa ^ random_mask_vec8[o:len(sa)+o]
return z.tostring()
-def dewhiten(s):
- return whiten(s) # self inverse
+def dewhiten(s, o):
+ return whiten(s, o) # self inverse
-def make_header(payload_len):
- return struct.pack('!HH', payload_len, payload_len)
+def make_header(payload_len, whitener_offset=0):
+ # Upper nibble is offset, lower 12 bits is len
+ val = ((whitener_offset & 0xf) << 12) | (payload_len & 0x0fff)
+ #print "offset =", whitener_offset, " len =", payload_len, " val=", val
+ return struct.pack('!HH', val, val)
def make_packet(payload, samples_per_symbol, bits_per_symbol,
- access_code=default_access_code, pad_for_usrp=True):
+ access_code=default_access_code, pad_for_usrp=True,
+ whitener_offset=0):
"""
- Build a packet, given access code and payload.
+ Build a packet, given access code, payload, and whitener offset
@param payload: packet payload, len [0, 4096]
@param samples_per_symbol: samples per symbol (needed for padding
calculation)
@@ -109,6 +113,7 @@
@param bits_per_symbol: (needed for padding calculation)
@type bits_per_symbol: int
@param access_code: string of ascii 0's and 1's
+ @param whitener_offset offset into whitener string to use [0-16)
Packet will have access code at the beginning, followed by length, payload
and finally CRC-32.
@@ -116,6 +121,9 @@
if not is_1_0_string(access_code):
raise ValueError, "access_code must be a string containing only 0's
and 1's (%r)" % (access_code,)
+ if not whitener_offset >=0 and whitener_offset < 16:
+ raise ValueError, "whitener_offset must be between 0 and 15, inclusive
(%i)" % (whitener_offset,)
+
(packed_access_code, padded) =
conv_1_0_string_to_packed_binary_string(access_code)
(packed_preamble, ignore) =
conv_1_0_string_to_packed_binary_string(preamble)
@@ -127,7 +135,8 @@
if L > MAXLEN:
raise ValueError, "len(payload) must be in [0, %d]" % (MAXLEN,)
- pkt = ''.join((packed_preamble, packed_access_code, make_header(L),
whiten(payload_with_crc), '\x55'))
+ pkt = ''.join((packed_preamble, packed_access_code, make_header(L,
whitener_offset),
+ whiten(payload_with_crc, whitener_offset), '\x55'))
if pad_for_usrp:
pkt = pkt + (_npadding_bytes(len(pkt), samples_per_symbol,
bits_per_symbol) * '\x55')
@@ -156,13 +165,13 @@
return byte_modulus - r
-def unmake_packet(whitened_payload_with_crc):
+def unmake_packet(whitened_payload_with_crc, whitener_offset=0):
"""
Return (ok, payload)
@param whitened_payload_with_crc: string
"""
- payload_with_crc = dewhiten(whitened_payload_with_crc)
+ payload_with_crc = dewhiten(whitened_payload_with_crc, whitener_offset)
ok, payload = gru.check_crc32(payload_with_crc)
if 0:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r4507 - in gnuradio/branches/developers/n4hy/ofdm2/gnuradio-core: . doc src/lib/general src/lib/io src/lib/runtime src/lib/swig src/python/gnuradio src/python/gnuradio/blksimpl,
n4hy <=