commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r4282 - gnuradio/branches/developers/trondeau/ethernet


From: trondeau
Subject: [Commit-gnuradio] r4282 - gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io
Date: Tue, 16 Jan 2007 15:55:25 -0700 (MST)

Author: trondeau
Date: 2007-01-16 15:55:25 -0700 (Tue, 16 Jan 2007)
New Revision: 4282

Added:
   
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_sink.cc
   
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_sink.h
   
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_sink.i
   
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_source.cc
   
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_source.h
   
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_source.i
Modified:
   
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/Makefile.am
   gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/io.i
Log:
wip: adding ethernet sink and source

Modified: 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/Makefile.am
===================================================================
--- 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/Makefile.am
 2007-01-16 22:17:21 UTC (rev 4281)
+++ 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/Makefile.am
 2007-01-16 22:55:25 UTC (rev 4282)
@@ -28,6 +28,8 @@
 
 
 libio_la_SOURCES =                     \
+       gr_ethernet_sink.cc             \
+       gr_ethernet_source.cc           \
        gr_file_sink.cc                 \
        gr_file_source.cc               \
        gr_file_descriptor_sink.cc      \
@@ -53,6 +55,8 @@
        sdr_1000.cc                     
 
 grinclude_HEADERS =                    \
+       gr_ethernet_sink.h              \
+       gr_ethernet_source.h            \
        gr_file_sink.h                  \
        gr_file_source.h                \
        gr_file_descriptor_sink.h       \
@@ -82,6 +86,8 @@
 
 swiginclude_HEADERS =                  \
        io.i                            \
+       gr_ethernet_sink.i              \
+       gr_ethernet_source.i            \
        gr_file_sink.i                  \
        gr_file_source.i                \
        gr_file_descriptor_sink.i       \

Added: 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_sink.cc
===================================================================
--- 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_sink.cc
                         (rev 0)
+++ 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_sink.cc
 2007-01-16 22:55:25 UTC (rev 4282)
@@ -0,0 +1,161 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_ethernet_sink.h>
+#include <gr_io_signature.h>
+#include <cstdio>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdexcept>
+
+#define SNK_VERBOSE 0
+
+gr_ethernet_sink::gr_ethernet_sink (size_t itemsize, 
+                                   const char *ipaddrl, unsigned short portl,
+                                   const char *ipaddrr, unsigned short portr,
+                                   unsigned int mtu)
+  : gr_sync_block ("ethernet_sink",
+                  gr_make_io_signature (1, 1, itemsize),
+                  gr_make_io_signature (0, 0, 0)),
+    d_itemsize (itemsize), d_updated(false), d_mtu(mtu)
+{
+  // 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
+
+  d_sockaddr_local.sin_family = AF_INET;
+  d_sockaddr_local.sin_addr   = d_ipaddr_local;
+  d_sockaddr_local.sin_port   = d_port_local;
+
+  d_sockaddr_remote.sin_family = AF_INET;
+  d_sockaddr_remote.sin_addr   = d_ipaddr_remote;
+  d_sockaddr_remote.sin_port   = d_port_remote;
+  
+  open();
+}
+
+// public constructor that returns a shared_ptr
+
+gr_ethernet_sink_sptr
+gr_make_ethernet_sink (size_t itemsize, 
+                      const char *ipaddrl, unsigned short portl,
+                      const char *ipaddrr, unsigned short portr,
+                      unsigned int mtu)
+{
+  return gr_ethernet_sink_sptr (new gr_ethernet_sink (itemsize, 
+                                                     ipaddrl, portl,
+                                                     ipaddrr, portr,
+                                                     mtu));
+}
+
+gr_ethernet_sink::~gr_ethernet_sink ()
+{
+  close();
+}
+
+bool
+gr_ethernet_sink::open()
+{
+  omni_mutex_lock l(d_mutex);  // hold mutex for duration of this function
+
+  int ret = 0;
+  bool OptVal = true;
+  int OptLen = sizeof(bool);
+  int LngrLen = sizeof(linger);
+  linger lngr;
+  lngr.l_onoff  = 1;
+  lngr.l_linger = 0;
+
+  // create socket
+  d_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+  ret = setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (char*)&OptVal, OptLen);
+  ret = setsockopt(d_socket, SO_LINGER, SO_REUSEADDR, (char*)&lngr, LngrLen);
+
+  // bind socket to an address and port number to listen on
+  ret = bind(d_socket, (sockaddr*)&d_sockaddr_local, sizeof(struct sockaddr));
+
+  #if SNK_VERBOSE
+  if(!ret) {
+    fprintf(stderr, "Source: bind address succeeded.\n");
+  }
+  else {
+    fprintf(stderr, "Source: bind address failed.\n");
+    exit(ret);
+  }
+  #endif
+
+  ret = connect(d_socket, (sockaddr*)&d_sockaddr_remote, sizeof(struct 
sockaddr));
+
+  #if SNK_VERBOSE
+  if(!ret) {
+    fprintf(stderr, "Source: connection succeeded.\n");
+  }
+  else {
+    fprintf(stderr, "Source: connection failed.\n");
+    exit(ret);
+  }
+  #endif
+
+  d_updated = true;
+  return d_socket != 0;
+}
+
+void
+gr_ethernet_sink::close()
+{
+  omni_mutex_lock l(d_mutex);  // hold mutex for duration of this function
+
+  if (d_socket){
+    shutdown(d_socket, SHUT_RDWR);
+    d_socket = 0;
+  }
+  d_updated = true;
+}
+
+int 
+gr_ethernet_sink::work (int noutput_items,
+                       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;
+
+  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, 0);
+    bytes_sent += bytes;
+  }
+
+  #if SNK_VERBOSE
+  printf("Sent: %d bytes (noutput_items: %d)\n", bytes_sent, noutput_items);
+  #endif
+
+  return noutput_items;
+}

Added: 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_sink.h
===================================================================
--- 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_sink.h
                          (rev 0)
+++ 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_sink.h
  2007-01-16 22:55:25 UTC (rev 4282)
@@ -0,0 +1,103 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_GR_ETHERNET_SINK_H
+#define INCLUDED_GR_ETHERNET_SINK_H
+
+#include <gr_sync_block.h>
+#include <omnithread.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+class gr_ethernet_sink;
+typedef boost::shared_ptr<gr_ethernet_sink> gr_ethernet_sink_sptr;
+
+/*!
+ * \brief Write stream to an Ethernet port (over UDP).
+ * \ingroup sink
+ */
+
+gr_ethernet_sink_sptr
+gr_make_ethernet_sink (size_t itemsize, 
+                      const char *ipaddrl, unsigned short portl,
+                      const char *ipaddrr, unsigned short portr,
+                      unsigned int mtu=540);
+
+class gr_ethernet_sink : public gr_sync_block
+{
+  friend gr_ethernet_sink_sptr gr_make_ethernet_sink (size_t itemsize, 
+                                                     const char *ipaddrl, 
unsigned short portl,
+                                                     const char *ipaddrr, 
unsigned short portr,
+                                                     unsigned int mtu);
+ private:
+  size_t       d_itemsize;
+  bool         d_updated;
+  omni_mutex   d_mutex;
+
+  unsigned int   d_mtu;             // 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)
+
+ protected:
+  gr_ethernet_sink (size_t itemsize, 
+                   const char *ipaddrl, unsigned short portl,
+                   const char *ipaddrr, unsigned short portr,
+                   unsigned int mtu);
+
+ public:
+  ~gr_ethernet_sink ();
+
+  /*!
+   * \brief open a socket specified by the port and ip address info
+   *
+   * Opens a socket, binds to the address, and makes connectionless association
+   * over UDP. If any of these fail, the fuction retuns the error and exits.
+   */
+  bool open();
+
+  /*!
+   * \brief Close current socket.
+   *
+   * Shuts down read/write on the socket
+   */
+  void close();
+
+  /*! \brief set the MTU of the socket */
+  void set_mtu(unsigned int mtu) { d_mtu = mtu; }
+
+  /*! \brief return the MTU of the socket */
+  unsigned int mtu() { return d_mtu; }
+
+  // should we export anything else?
+
+  int work (int noutput_items,
+           gr_vector_const_void_star &input_items,
+           gr_vector_void_star &output_items);
+};
+
+#endif /* INCLUDED_GR_ETHERNET_SINK_H */

Added: 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_sink.i
===================================================================
--- 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_sink.i
                          (rev 0)
+++ 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_sink.i
  2007-01-16 22:55:25 UTC (rev 4282)
@@ -0,0 +1,47 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+
+GR_SWIG_BLOCK_MAGIC(gr,ethernet_sink)
+
+gr_ethernet_sink_sptr 
+gr_make_ethernet_sink (size_t itemsize, 
+                      const char *ipaddrl, unsigned short portl,
+                      const char *ipaddrr, unsigned short portr,
+                      unsigned int mtu=540);
+
+class gr_ethernet_sink : public gr_sync_block
+{
+ protected:
+  gr_ethernet_sink (size_t itemsize, 
+                   const char *ipaddrl, unsigned short portl,
+                   const char *ipaddrr, unsigned short portr,
+                   unsigned int mtu);
+
+  bool open();
+  void close();
+  void set_mtu(unsigned int mtu) { d_mtu = mtu; }
+  unsigned int mtu() { return d_mtu; }
+
+ public:
+  ~gr_ethernet_sink ();
+};

Added: 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_source.cc
===================================================================
--- 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_source.cc
                               (rev 0)
+++ 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_source.cc
       2007-01-16 22:55:25 UTC (rev 4282)
@@ -0,0 +1,154 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2006 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gr_ethernet_source.h>
+#include <gr_io_signature.h>
+#include <cstdio>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdexcept>
+
+#define SRC_VERBOSE 0
+
+gr_ethernet_source::gr_ethernet_source(size_t itemsize, const char *ipaddr, 
+                                      unsigned short port, unsigned int mtu)
+  : gr_sync_block ("ethernet_source",
+                  gr_make_io_signature(0, 0, 0),
+                  gr_make_io_signature(1, 1, itemsize)),
+    d_itemsize(itemsize), d_updated(false), d_mtu(mtu)
+{
+  // 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
+
+  d_sockaddr_local.sin_family = AF_INET;
+  d_sockaddr_local.sin_addr   = d_ipaddr_local;
+  d_sockaddr_local.sin_port   = d_port_local;
+  
+  open();
+}
+
+gr_ethernet_source_sptr
+gr_make_ethernet_source (size_t itemsize, const char *ipaddr, 
+                        unsigned short port, unsigned int mtu)
+{
+  return gr_ethernet_source_sptr (new gr_ethernet_source (itemsize, ipaddr, 
+                                                         port, mtu));
+}
+
+gr_ethernet_source::~gr_ethernet_source ()
+{
+  close();
+}
+
+bool
+gr_ethernet_source::open()
+{
+  omni_mutex_lock l(d_mutex);  // hold mutex for duration of this function
+   
+  int ret = 0;
+
+  // create socket
+  d_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+
+  // Turn on reuse address
+  bool opt_val = true;
+  ret = setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val, 
sizeof(bool));
+
+  // Don't wait when shutting down
+  linger lngr;
+  lngr.l_onoff  = 1;
+  lngr.l_linger = 0;
+  ret = setsockopt(d_socket, SOL_SOCKET, SO_LINGER, (void*)&lngr, 
sizeof(linger));
+
+  // Set a timeout on the receive function to not block indefinitely
+  timeval timeout;
+  timeout.tv_sec = 1;
+  timeout.tv_usec = 0;
+  ret = setsockopt(d_socket, SOL_SOCKET, SO_RCVTIMEO, (void*)&timeout, 
sizeof(timeout));
+
+  // bind socket to an address and port number to listen on
+  ret = bind (d_socket, (sockaddr*)&d_sockaddr_local, sizeof(struct sockaddr));
+  #if SRC_VERBOSE
+  if(!ret) {
+    fprintf(stderr, "Sink: bind address succeeded\n");
+  }
+  else {
+    fprintf(stderr, "Sink: bind failed (%d).\n", ret);
+    exit(ret);
+  }
+  #endif 
+  
+  d_updated = true;
+  return d_socket != 0;
+}
+
+void
+gr_ethernet_source::close()
+{
+  omni_mutex_lock l(d_mutex);  // hold mutex for duration of this function
+
+  if (d_socket){
+    shutdown(d_socket, SHUT_RDWR);
+    d_socket = 0;
+  }
+  d_updated = true;
+}
+
+int 
+gr_ethernet_source::work (int noutput_items,
+                         gr_vector_const_void_star &input_items,
+                         gr_vector_void_star &output_items)
+{
+  char *out = (char *) output_items[0];
+  socklen_t bytes_to_receive=0, bytes_received=0;
+  int bytes=0;
+
+  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);
+    
+    // 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);
+
+    if(bytes > 0) {
+      // keep track of the total number of bytes received
+      bytes_received += bytes;
+
+      // increment the pointer
+      out += bytes;
+    }
+  }
+
+  #if SRC_VERBOSE
+  printf("\nTotal Bytes Received: %d (noutput_items=%d)\n", bytes_received, 
noutput_items); 
+  #endif
+
+  return int(bytes_received / d_itemsize);
+}

Added: 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_source.h
===================================================================
--- 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_source.h
                                (rev 0)
+++ 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_source.h
        2007-01-16 22:55:25 UTC (rev 4282)
@@ -0,0 +1,92 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_GR_ETHERNET_SOURCE_H
+#define INCLUDED_GR_ETHERNET_SOURCE_H
+
+#include <gr_sync_block.h>
+#include <omnithread.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+class gr_ethernet_source;
+typedef boost::shared_ptr<gr_ethernet_source> gr_ethernet_source_sptr;
+
+gr_ethernet_source_sptr gr_make_ethernet_source(size_t itemsize, const char 
*ipaddr, 
+                                               unsigned short port, unsigned 
int mtu=540);
+
+class gr_ethernet_source : public gr_sync_block
+{
+  friend gr_ethernet_source_sptr gr_make_ethernet_source(size_t itemsize, 
const char *ipaddr, 
+                                                        unsigned short port, 
unsigned int mtu);
+
+ private:
+  size_t       d_itemsize;
+  bool         d_updated;
+  omni_mutex   d_mutex;
+
+  unsigned int   d_mtu;           // 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)
+  
+ protected:
+  gr_ethernet_source(size_t itemsize, const char *ipaddr, unsigned short port, 
unsigned int mtu);
+
+ public:
+  ~gr_ethernet_source();
+
+  /*!
+   * \brief open a socket specified by the port and ip address info
+   *
+   * Opens a socket, binds to the address, and waits for a connection
+   * over UDP. If any of these fail, the fuction retuns the error and exits.
+   */
+  bool open();
+
+  /*!
+   * \brief Close current socket.
+   *
+   * Shuts down read/write on the socket
+   */
+  void close();
+
+  /*! \brief set the MTU of the socket */
+  void set_mtu(unsigned int mtu) { d_mtu = mtu; }
+
+  /*! \brief return the MTU of the socket */
+  unsigned int mtu() { return d_mtu; }
+
+  // should we export anything else?
+
+  int work(int noutput_items,
+          gr_vector_const_void_star &input_items,
+          gr_vector_void_star &output_items);
+};
+
+
+#endif /* INCLUDED_GR_ETHERNET_SOURCE_H */

Added: 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_source.i
===================================================================
--- 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_source.i
                                (rev 0)
+++ 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/gr_ethernet_source.i
        2007-01-16 22:55:25 UTC (rev 4282)
@@ -0,0 +1,43 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004 Free Software Foundation, Inc.
+ * 
+ * This file is part of GNU Radio
+ * 
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ * 
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+GR_SWIG_BLOCK_MAGIC(gr,ethernet_source)
+
+gr_ethernet_source_sptr 
+gr_make_ethernet_source (size_t itemsize, const char *ipaddr, 
+                        unsigned short port, unsigned int mtu=540);
+
+class gr_ethernet_source : public gr_sync_block
+{
+ protected:
+  gr_ethernet_source (size_t itemsize, const char *ipaddr, 
+                     unsigned short port, unsigned int mtu);
+
+ public:
+  ~gr_ethernet_source ();
+
+  bool open();
+  void close();
+  void set_mtu(unsigned int mtu) { d_mtu = mtu; }
+  unsigned int mtu() { return d_mtu; }
+
+};

Modified: 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/io.i
===================================================================
--- 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/io.i    
    2007-01-16 22:17:21 UTC (rev 4281)
+++ 
gnuradio/branches/developers/trondeau/ethernet/gnuradio-core/src/lib/io/io.i    
    2007-01-16 22:55:25 UTC (rev 4282)
@@ -22,6 +22,8 @@
 
 %{
 
+#include <gr_ethernet_sink.cc>
+#include <gr_ethernet_source.cc>
 #include <gr_file_sink.h>
 #include <gr_file_source.h>
 #include <gr_file_descriptor_sink.h>
@@ -37,6 +39,8 @@
 
 %}
 
+%include "gr_ethernet_sink.i"
+%include "gr_ethernet_source.i"
 %include "gr_file_sink.i"
 %include "gr_file_source.i"
 %include "gr_file_descriptor_sink.i"





reply via email to

[Prev in Thread] Current Thread [Next in Thread]