commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r9028 - in gnuradio/trunk: config gr-msdd6000/src


From: eb
Subject: [Commit-gnuradio] r9028 - in gnuradio/trunk: config gr-msdd6000/src
Date: Sun, 27 Jul 2008 16:28:20 -0600 (MDT)

Author: eb
Date: 2008-07-27 16:28:20 -0600 (Sun, 27 Jul 2008)
New Revision: 9028

Modified:
   gnuradio/trunk/config/grc_gr_msdd6000.m4
   gnuradio/trunk/gr-msdd6000/src/msdd.i
   gnuradio/trunk/gr-msdd6000/src/msdd6000.cc
   gnuradio/trunk/gr-msdd6000/src/msdd6000.h
   gnuradio/trunk/gr-msdd6000/src/msdd_source_base.cc
   gnuradio/trunk/gr-msdd6000/src/msdd_source_c.cc
   gnuradio/trunk/gr-msdd6000/src/msdd_source_s.cc
   gnuradio/trunk/gr-msdd6000/src/msdd_source_simple.cc
   gnuradio/trunk/gr-msdd6000/src/msdd_source_simple.h
Log:
Merged gr-msdd6000 portability fix to trunk (eb/msdd -r8940:9027)


Modified: gnuradio/trunk/config/grc_gr_msdd6000.m4
===================================================================
--- gnuradio/trunk/config/grc_gr_msdd6000.m4    2008-07-27 20:15:04 UTC (rev 
9027)
+++ gnuradio/trunk/config/grc_gr_msdd6000.m4    2008-07-27 22:28:20 UTC (rev 
9028)
@@ -28,6 +28,8 @@
     dnl Don't do gr-msdd6000 if gnuradio-core skipped
     GRC_CHECK_DEPENDENCY(gr-msdd6000, gnuradio-core)
 
+    AC_CHECK_HEADERS(netinet/in.h arpa/inet.h sys/socket.h netdb.h)
+
     GRC_BUILD_CONDITIONAL([gr-msdd6000],[
         dnl run_tests is created from run_tests.in.  Make it executable.
        AC_CONFIG_COMMANDS([run_tests_msdd6000], [chmod +x 
gr-msdd6000/src/run_tests])

Modified: gnuradio/trunk/gr-msdd6000/src/msdd.i
===================================================================
--- gnuradio/trunk/gr-msdd6000/src/msdd.i       2008-07-27 20:15:04 UTC (rev 
9027)
+++ gnuradio/trunk/gr-msdd6000/src/msdd.i       2008-07-27 22:28:20 UTC (rev 
9028)
@@ -52,11 +52,6 @@
          ) throw (std::runtime_error);
 
   /*!
-   * \brief return number of msdd input bytes required to produce noutput 
items.
-   */
-  int ninput_bytes_reqd_for_noutput_items (int noutput_items) = 0;
-
-  /*!
    * \brief number of bytes in a low-level sample
    */
   unsigned int sizeof_basic_sample() const;
@@ -224,8 +219,6 @@
           unsigned short port_src
       ) throw (std::runtime_error);
 
- virtual int ninput_bytes_reqd_for_noutput_items (int noutput_items);
- 
  public:
   ~msdd_source_s ();
 };
@@ -249,8 +242,6 @@
           unsigned short port_src
       ) throw (std::runtime_error);
 
- virtual int ninput_bytes_reqd_for_noutput_items (int noutput_items);
- 
  public:
   ~msdd_source_c ();
 };
@@ -276,7 +267,6 @@
  
   public:
     ~msdd_source_c(); 
-  int ninput_bytes_reqd_for_noutput_items (int noutput_items) = 0;
   int work (int noutput_items,
       gr_vector_const_void_star &input_items,
       gr_vector_void_star &output_items);

Modified: gnuradio/trunk/gr-msdd6000/src/msdd6000.cc
===================================================================
--- gnuradio/trunk/gr-msdd6000/src/msdd6000.cc  2008-07-27 20:15:04 UTC (rev 
9027)
+++ gnuradio/trunk/gr-msdd6000/src/msdd6000.cc  2008-07-27 22:28:20 UTC (rev 
9028)
@@ -1,14 +1,60 @@
-#include "msdd6000.h"
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 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 3, 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <msdd6000.h>
 
 #include <stdio.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
 #include <string.h>
 #include <unistd.h>
 
-void optimize_socket(int socket);
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
 
-MSDD6000::MSDD6000(char* addr){
+#define DEBUG(A)       printf("=debug=> %s\n", A)
+
+static void 
+optimize_socket(int socket);
+
+/*
+ * Holds types that need autoconf help.  They're here and not in the .h file 
because
+ * here we've got access to config.h
+ */
+class MSDD6000::detail {
+public:
+  struct sockaddr_in d_sockaddr;
+};
+
+
+MSDD6000::MSDD6000(char* addr)
+  : d_detail(new MSDD6000::detail())
+{
        d_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
        
        optimize_socket(d_sock);
@@ -16,11 +62,13 @@
        
        // set up remote sockaddr
 //     int s = inet_aton(addr, &d_adx); 
-       d_sockaddr.sin_family = AF_INET;
-       d_sockaddr.sin_port = htons(10000);
-       int s = inet_aton(addr, &d_sockaddr.sin_addr);
+       d_detail->d_sockaddr.sin_family = AF_INET;
+       d_detail->d_sockaddr.sin_port = htons(10000);
+       int s = inet_aton(addr, &d_detail->d_sockaddr.sin_addr);
        
        // set up local sockaddr
+       struct in_addr d_myadx;
+       struct sockaddr_in d_mysockaddr;
        short int port = 10010;
        d_myadx.s_addr = INADDR_ANY;
        d_mysockaddr.sin_family = AF_INET;
@@ -37,21 +85,22 @@
 }
 
 
-void optimize_socket(int socket){
+static void
+optimize_socket(int socket){
 #define BANDWIDTH      1000000000/8
 #define DELAY          0.5
        int ret;
 
-       int sock_buf_size = 2*BANDWIDTH*DELAY;
+       int sock_buf_size = static_cast<int>(2*BANDWIDTH*DELAY);
        char textbuf[512];
-       sprintf(textbuf, "%d", sock_buf_size);
+       snprintf(textbuf, sizeof(textbuf), "%d", sock_buf_size);
        printf("sock_buf_size = %d\n", sock_buf_size);
        
-       ret = setsockopt( socket, SOL_SOCKET, SO_SNDBUF,
-                   (char *)&sock_buf_size, sizeof(sock_buf_size) );
+       ret = setsockopt(socket, SOL_SOCKET, SO_SNDBUF,
+                        &sock_buf_size, sizeof(sock_buf_size));
 
-       ret = setsockopt( socket, SOL_SOCKET, SO_RCVBUF,
-                   (char *)&sock_buf_size, sizeof(sock_buf_size) );
+       ret = setsockopt(socket, SOL_SOCKET, SO_RCVBUF,
+                        &sock_buf_size, sizeof(sock_buf_size));
        
        int uid = getuid();
        if(uid!=0){
@@ -61,17 +110,24 @@
 
 
        // SET UP SOME SYSTEM WIDE TCP SOCKET PARAMETERS
+       // FIXME seems like kind of a big hammer.  Are you sure you need this?
        FILE* fd = fopen("/proc/sys/net/core/netdev_max_backlog", "w");
-       fwrite("10000", 1, strlen("10000"), fd);
-       fclose(fd);
+       if (fd){
+         fwrite("10000", 1, strlen("10000"), fd);
+         fclose(fd);
+       }
 
        fd = fopen("/proc/sys/net/core/rmem_max", "w");
-       fwrite(textbuf, 1, strlen(textbuf), fd);
-       fclose(fd);
+       if (fd){
+         fwrite(textbuf, 1, strlen(textbuf), fd);
+         fclose(fd);
+       }
 
        fd = fopen("/proc/sys/net/core/wmem_max", "w");
-       fwrite(textbuf, 1, strlen(textbuf), fd);
-       fclose(fd);
+       if (fd){
+         fwrite(textbuf, 1, strlen(textbuf), fd);
+         fclose(fd);
+       }
 
        // just incase these were rejected before because of max sizes...
 
@@ -134,7 +190,8 @@
        sprintf(buff, "%f %f %f %f %f\n",freq_mhz, rf_attn, ddc_gain, ddc_dec, 
ddc_offset_hz);
        printf("sending: %s\n", buff);
         int flags = 0;
-       sendto( d_sock, buff, strlen(buff)+1, flags, (const 
sockaddr*)&d_sockaddr, sizeof(d_sockaddr));
+       sendto( d_sock, buff, strlen(buff)+1, flags,
+               (const sockaddr*)&(d_detail->d_sockaddr), 
sizeof(d_detail->d_sockaddr));
        }
 
 

Modified: gnuradio/trunk/gr-msdd6000/src/msdd6000.h
===================================================================
--- gnuradio/trunk/gr-msdd6000/src/msdd6000.h   2008-07-27 20:15:04 UTC (rev 
9027)
+++ gnuradio/trunk/gr-msdd6000/src/msdd6000.h   2008-07-27 22:28:20 UTC (rev 
9028)
@@ -1,51 +1,45 @@
 #ifndef MSDD6000_H
 #define MSDD6000_H
 
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <linux/socket.h>
+#include <boost/scoped_ptr.hpp>
 
-#define DEBUG(A)       printf("=debug=> %s\n", A)
+class MSDD6000 {
+  class detail;
 
-#define STATE_STOPPED  0
-#define STATE_STARTED  1
+  //! holds objects with system dependent types
+  boost::scoped_ptr<detail>    d_detail;  
 
-class MSDD6000 {
-       public:
-               MSDD6000(char* addr);
-               
-               void set_decim(int decim_pow2);
-               void set_fc(int center_mhz, int offset_hz);     
-               void set_ddc_gain(int gain);
-               void set_rf_attn(int attn);
+public:
 
-               void set_output(int mode, void* arg);
+  enum state {
+    STATE_STOPPED, STATE_STARTED,
+  };
 
-               void start();
-               void stop();
-       
-               void send_request(float,float,float,float,float);       
-               int read(char*, int);
+  MSDD6000(char* ip_addr);
+  ~MSDD6000();
 
-               int d_decim;
-               int d_fc_mhz;
-               int d_offset_hz;
-               int d_rf_attn;
-               int d_ddc_gain;
+  void set_decim(int decim_pow2);
+  void set_fc(int center_mhz, int offset_hz);  
+  void set_ddc_gain(int gain);
+  void set_rf_attn(int attn);
 
-//             in_addr d_adx;  
-               in_addr d_myadx;        
+  void set_output(int mode, void* arg);
 
-               struct sockaddr_in d_sockaddr;
-               struct sockaddr_in d_mysockaddr;
+  void start();
+  void stop();
        
-               int d_sock;
-               int d_state;
-};
+  void send_request(float,float,float,float,float);    
+  int read(char*, int);
 
+  int d_decim;
+  int d_fc_mhz;
+  int d_offset_hz;
+  int d_rf_attn;
+  int d_ddc_gain;
+  int d_sock;
+  state d_state;
 
+};
 
 
-
-
 #endif

Modified: gnuradio/trunk/gr-msdd6000/src/msdd_source_base.cc
===================================================================
--- gnuradio/trunk/gr-msdd6000/src/msdd_source_base.cc  2008-07-27 20:15:04 UTC 
(rev 9027)
+++ gnuradio/trunk/gr-msdd6000/src/msdd_source_base.cc  2008-07-27 22:28:20 UTC 
(rev 9028)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2004 Free Software Foundation, Inc.
+ * Copyright 2004,2008 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -24,20 +24,27 @@
 //#define MSDD_DEBUG2_TRUE
 
 #ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
 #endif
 
 #include <msdd_source_base.h>
 #include <gr_io_signature.h>
 #include <assert.h>
-#include <netdb.h>
 #include <omnithread.h>
 #include <stdexcept>
+#include <iostream>
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
 #include <arpa/inet.h>
+#endif
 
+
 #ifdef MSDD_DEBUG_TRUE
-#include <iostream>
 #define MSDD_DEBUG(x) std::cout << x << std::endl;
 #else
 #define MSDD_DEBUG(x)
@@ -45,13 +52,11 @@
 
 
 #ifdef MSDD_DEBUG2_TRUE
-#include <iostream>
 #define MSDD_DEBUG2(x) std::cout << x << std::endl;
 #else
 #define MSDD_DEBUG2(x)
 #endif
 
-#include <iostream>
 
 namespace {
        const int OUTPUT_MAX((1 << 15)*8);

Modified: gnuradio/trunk/gr-msdd6000/src/msdd_source_c.cc
===================================================================
--- gnuradio/trunk/gr-msdd6000/src/msdd_source_c.cc     2008-07-27 20:15:04 UTC 
(rev 9027)
+++ gnuradio/trunk/gr-msdd6000/src/msdd_source_c.cc     2008-07-27 22:28:20 UTC 
(rev 9028)
@@ -21,8 +21,10 @@
  */
 
 #ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
 #endif
+#include <msdd_source_c.h>
+#include <gr_io_signature.h>
 
 //#define MSDD_DEBUG2_TRUE
 
@@ -33,8 +35,6 @@
 #define MSDD_DEBUG2(x)
 #endif
 
-#include <msdd_source_c.h>
-#include <gr_io_signature.h>
 
 namespace {
        static const int NBASIC_SAMPLES_PER_ITEM = 2;   // I & Q

Modified: gnuradio/trunk/gr-msdd6000/src/msdd_source_s.cc
===================================================================
--- gnuradio/trunk/gr-msdd6000/src/msdd_source_s.cc     2008-07-27 20:15:04 UTC 
(rev 9027)
+++ gnuradio/trunk/gr-msdd6000/src/msdd_source_s.cc     2008-07-27 22:28:20 UTC 
(rev 9028)
@@ -21,8 +21,10 @@
  */
 
 #ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
 #endif
+#include <msdd_source_s.h>
+#include <gr_io_signature.h>
 
 #define MSDD_DEBUG2_TRUE
 
@@ -33,8 +35,6 @@
 #define MSDD_DEBUG2(x)
 #endif
 
-#include <msdd_source_s.h>
-#include <gr_io_signature.h>
 
 namespace {
        static const int NBASIC_SAMPLES_PER_ITEM = 1;

Modified: gnuradio/trunk/gr-msdd6000/src/msdd_source_simple.cc
===================================================================
--- gnuradio/trunk/gr-msdd6000/src/msdd_source_simple.cc        2008-07-27 
20:15:04 UTC (rev 9027)
+++ gnuradio/trunk/gr-msdd6000/src/msdd_source_simple.cc        2008-07-27 
22:28:20 UTC (rev 9028)
@@ -1,18 +1,31 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 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 3, 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 #ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
 #endif
 
-#include <vector>
 #include <msdd_source_simple.h>
 #include <gr_io_signature.h>
-#include <gr_sync_block.h>
 
-#ifndef FALSE
-#define FALSE  (0==1)
-#define TRUE   (0==0)
-#endif
 
-
 msdd_source_simple_sptr
 msdd_make_source_simple ( const char *src, unsigned short port_src) 
 {
@@ -24,12 +37,17 @@
                    const char *src, 
                    unsigned short port_src) 
                : gr_sync_block("MSDD_SOURCE_SIMPLE",
-                       gr_make_io_signature (0,0,0),
-                       gr_make_io_signature (1, 1, sizeof (short)))
+                               gr_make_io_signature (0,0,0),
+                               gr_make_io_signature (1, 1, sizeof (short))),
+                  rcv(new MSDD6000((char*) src)), d_lastseq(0)
 {
-       rcv = new MSDD6000((char*)src);
 }
 
+msdd_source_simple::~msdd_source_simple ()
+{
+}
+
+
 int
 msdd_source_simple::work (int noutput_items,
                          gr_vector_const_void_star &input_items,
@@ -45,6 +63,7 @@
 
        int seq = *((int*) &buffer[2]);
        
+       // FIXME get rid of these magic 366's!
        if(d_lastseq == -366){
                // not started case
                if(seq == 0){
@@ -78,8 +97,9 @@
 
 bool msdd_source_simple::set_decim_rate(unsigned int rate)
 {
-       rcv->set_decim(log2(rate));
-       return TRUE;
+       // FIXME seems buggy.  How about a floor or ceil?
+        rcv->set_decim((int) log2(rate));
+       return true;
 }
 
 
@@ -87,7 +107,7 @@
 {
        long new_fc = (long)freq;
        rcv->set_fc( new_fc/1000000, new_fc%1000000);
-       return TRUE;
+       return true;
 }
 
 
@@ -95,41 +115,33 @@
 {
        if(gain < 0 || gain > 10){
                printf("GAIN IS OUTSIDE ACCEPTABLE RANGE!\n");
-               return FALSE;
+               return false;
        }
        // ok i lied this is not really a pga, its decimation gain
        rcv->set_ddc_gain((int)gain);
-       return TRUE;
+       return true;
 }
 
 
-msdd_source_simple::~msdd_source_simple ()
-{
-       delete rcv;
-}
-
-
 bool msdd_source_simple::start()
 {
        rcv->start();
+       return true;
 }
 
 
 bool msdd_source_simple::stop()
 {
        rcv->stop();
+       return true;
 }
 
-int msdd_source_simple::ninput_bytes_reqd_for_noutput_items(int out){
-       return 0;
-}
-
 long msdd_source_simple::adc_freq(){
        return 102400000;
 }
 
 int msdd_source_simple::decim_rate(){
-       return pow(2, rcv->d_decim);
+       return 1 << rcv->d_decim;
 }
 
 
@@ -146,4 +158,3 @@
        r.push_back(6.0*1000*1000*1000);
        return r;
 }
-

Modified: gnuradio/trunk/gr-msdd6000/src/msdd_source_simple.h
===================================================================
--- gnuradio/trunk/gr-msdd6000/src/msdd_source_simple.h 2008-07-27 20:15:04 UTC 
(rev 9027)
+++ gnuradio/trunk/gr-msdd6000/src/msdd_source_simple.h 2008-07-27 22:28:20 UTC 
(rev 9028)
@@ -1,13 +1,29 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 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 3, 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 this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 #ifndef INCLUDED_MSDD_SOURCE_SIMPLE_H
 #define INCLUDED_MSDD_SOURCE_SIMPLE_H
 
-#include <stdexcept>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <stdio.h>
 #include <gr_sync_block.h>
 #include <msdd6000.h>
+#include <boost/scoped_ptr.hpp>
 
 
 class msdd_source_simple;
@@ -19,13 +35,12 @@
 msdd_source_simple_sptr msdd_make_source_simple ( const char *src, unsigned 
short port_src);
 
 
-
 class msdd_source_simple : public gr_sync_block {
  private:
   friend msdd_source_simple_sptr
   msdd_make_source_simple ( const char *src, unsigned short port_src);
 
-  MSDD6000* rcv;
+  boost::scoped_ptr<MSDD6000> rcv;
   int d_lastseq;
 
  protected:
@@ -33,7 +48,6 @@
 
  public:
   ~msdd_source_simple ();
-  int ninput_bytes_reqd_for_noutput_items(int out);
   bool stop();
   bool start();
 





reply via email to

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