Changeset 9028

Show
Ignore:
Timestamp:
07/27/08 16:28:20
Author:
eb
Message:

Merged gr-msdd6000 portability fix to trunk (eb/msdd -r8940:9027)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gnuradio/trunk/config/grc_gr_msdd6000.m4

    r8782 r9028  
    2929    GRC_CHECK_DEPENDENCY(gr-msdd6000, gnuradio-core) 
    3030 
     31    AC_CHECK_HEADERS(netinet/in.h arpa/inet.h sys/socket.h netdb.h) 
     32 
    3133    GRC_BUILD_CONDITIONAL([gr-msdd6000],[ 
    3234        dnl run_tests is created from run_tests.in.  Make it executable. 
  • gnuradio/trunk/gr-msdd6000/src/msdd.i

    r8783 r9028  
    5151      unsigned short port_src 
    5252         ) throw (std::runtime_error); 
    53  
    54   /*! 
    55    * \brief return number of msdd input bytes required to produce noutput items. 
    56    */ 
    57   int ninput_bytes_reqd_for_noutput_items (int noutput_items) = 0; 
    5853 
    5954  /*! 
     
    225220      ) throw (std::runtime_error); 
    226221 
    227  virtual int ninput_bytes_reqd_for_noutput_items (int noutput_items); 
    228   
    229222 public: 
    230223  ~msdd_source_s (); 
     
    250243      ) throw (std::runtime_error); 
    251244 
    252  virtual int ninput_bytes_reqd_for_noutput_items (int noutput_items); 
    253   
    254245 public: 
    255246  ~msdd_source_c (); 
     
    277268  public: 
    278269    ~msdd_source_c();  
    279   int ninput_bytes_reqd_for_noutput_items (int noutput_items) = 0; 
    280270  int work (int noutput_items, 
    281271      gr_vector_const_void_star &input_items, 
  • gnuradio/trunk/gr-msdd6000/src/msdd6000.cc

    r8782 r9028  
    1 #include "msdd6000.h" 
     1/* -*- c++ -*- */ 
     2/* 
     3 * Copyright 2008 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 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. 
     20 */ 
     21#ifdef HAVE_CONFIG_H 
     22#include <config.h> 
     23#endif 
     24#include <msdd6000.h> 
    225 
    326#include <stdio.h> 
    4 #include <netinet/in.h> 
    5 #include <sys/socket.h> 
    627#include <string.h> 
    728#include <unistd.h> 
    829 
    9 void optimize_socket(int socket); 
    10  
    11 MSDD6000::MSDD6000(char* addr){ 
     30#ifdef HAVE_ARPA_INET_H 
     31#include <arpa/inet.h> 
     32#endif 
     33#ifdef HAVE_NETINET_IN_H 
     34#include <netinet/in.h> 
     35#endif 
     36#ifdef HAVE_SYS_SOCKET_H 
     37#include <sys/socket.h> 
     38#endif 
     39 
     40#define DEBUG(A)        printf("=debug=> %s\n", A) 
     41 
     42static void  
     43optimize_socket(int socket); 
     44 
     45/* 
     46 * Holds types that need autoconf help.  They're here and not in the .h file because 
     47 * here we've got access to config.h 
     48 */ 
     49class MSDD6000::detail { 
     50public: 
     51  struct sockaddr_in d_sockaddr; 
     52}; 
     53 
     54 
     55MSDD6000::MSDD6000(char* addr) 
     56  : d_detail(new MSDD6000::detail()) 
     57
    1258        d_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); 
    1359         
     
    1763        // set up remote sockaddr 
    1864//      int s = inet_aton(addr, &d_adx);  
    19         d_sockaddr.sin_family = AF_INET; 
    20         d_sockaddr.sin_port = htons(10000); 
    21         int s = inet_aton(addr, &d_sockaddr.sin_addr); 
     65        d_detail->d_sockaddr.sin_family = AF_INET; 
     66        d_detail->d_sockaddr.sin_port = htons(10000); 
     67        int s = inet_aton(addr, &d_detail->d_sockaddr.sin_addr); 
    2268         
    2369        // set up local sockaddr 
     70        struct in_addr d_myadx; 
     71        struct sockaddr_in d_mysockaddr; 
    2472        short int port = 10010; 
    2573        d_myadx.s_addr = INADDR_ANY; 
     
    3886 
    3987 
    40 void optimize_socket(int socket){ 
     88static void 
     89optimize_socket(int socket){ 
    4190#define BANDWIDTH       1000000000/8 
    4291#define DELAY           0.5 
    4392        int ret; 
    4493 
    45         int sock_buf_size = 2*BANDWIDTH*DELAY
     94        int sock_buf_size = static_cast<int>(2*BANDWIDTH*DELAY)
    4695        char textbuf[512]; 
    47         sprintf(textbuf, "%d", sock_buf_size); 
     96        snprintf(textbuf, sizeof(textbuf), "%d", sock_buf_size); 
    4897        printf("sock_buf_size = %d\n", sock_buf_size); 
    4998         
    50         ret = setsockopt( socket, SOL_SOCKET, SO_SNDBUF, 
    51                    (char *)&sock_buf_size, sizeof(sock_buf_size) ); 
    52  
    53         ret = setsockopt( socket, SOL_SOCKET, SO_RCVBUF, 
    54                    (char *)&sock_buf_size, sizeof(sock_buf_size) ); 
     99        ret = setsockopt(socket, SOL_SOCKET, SO_SNDBUF, 
     100                        &sock_buf_size, sizeof(sock_buf_size)); 
     101 
     102        ret = setsockopt(socket, SOL_SOCKET, SO_RCVBUF, 
     103                        &sock_buf_size, sizeof(sock_buf_size)); 
    55104         
    56105        int uid = getuid(); 
     
    62111 
    63112        // SET UP SOME SYSTEM WIDE TCP SOCKET PARAMETERS 
     113        // FIXME seems like kind of a big hammer.  Are you sure you need this? 
    64114        FILE* fd = fopen("/proc/sys/net/core/netdev_max_backlog", "w"); 
    65         fwrite("10000", 1, strlen("10000"), fd); 
    66         fclose(fd); 
     115        if (fd){ 
     116          fwrite("10000", 1, strlen("10000"), fd); 
     117          fclose(fd); 
     118        } 
    67119 
    68120        fd = fopen("/proc/sys/net/core/rmem_max", "w"); 
    69         fwrite(textbuf, 1, strlen(textbuf), fd); 
    70         fclose(fd); 
     121        if (fd){ 
     122          fwrite(textbuf, 1, strlen(textbuf), fd); 
     123          fclose(fd); 
     124        } 
    71125 
    72126        fd = fopen("/proc/sys/net/core/wmem_max", "w"); 
    73         fwrite(textbuf, 1, strlen(textbuf), fd); 
    74         fclose(fd); 
     127        if (fd){ 
     128          fwrite(textbuf, 1, strlen(textbuf), fd); 
     129          fclose(fd); 
     130        } 
    75131 
    76132        // just incase these were rejected before because of max sizes... 
     
    135191        printf("sending: %s\n", buff); 
    136192        int flags = 0; 
    137         sendto( d_sock, buff, strlen(buff)+1, flags, (const sockaddr*)&d_sockaddr, sizeof(d_sockaddr)); 
     193        sendto( d_sock, buff, strlen(buff)+1, flags, 
     194                (const sockaddr*)&(d_detail->d_sockaddr), sizeof(d_detail->d_sockaddr)); 
    138195        } 
    139196 
  • gnuradio/trunk/gr-msdd6000/src/msdd6000.h

    r8782 r9028  
    22#define MSDD6000_H 
    33 
    4 #include <netinet/in.h> 
    5 #include <arpa/inet.h> 
    6 #include <linux/socket.h> 
    7  
    8 #define DEBUG(A)        printf("=debug=> %s\n", A) 
    9  
    10 #define STATE_STOPPED   0 
    11 #define STATE_STARTED   1 
     4#include <boost/scoped_ptr.hpp> 
    125 
    136class MSDD6000 { 
    14         public: 
    15                 MSDD6000(char* addr); 
    16                  
    17                 void set_decim(int decim_pow2); 
    18                 void set_fc(int center_mhz, int offset_hz);      
    19                 void set_ddc_gain(int gain); 
    20                 void set_rf_attn(int attn); 
     7  class detail; 
    218 
    22                 void set_output(int mode, void* arg); 
     9  //! holds objects with system dependent types 
     10  boost::scoped_ptr<detail>     d_detail;   
    2311 
    24                 void start(); 
    25                 void stop(); 
     12public: 
     13 
     14  enum state { 
     15    STATE_STOPPED, STATE_STARTED, 
     16  }; 
     17 
     18  MSDD6000(char* ip_addr); 
     19  ~MSDD6000(); 
     20 
     21  void set_decim(int decim_pow2); 
     22  void set_fc(int center_mhz, int offset_hz);    
     23  void set_ddc_gain(int gain); 
     24  void set_rf_attn(int attn); 
     25 
     26  void set_output(int mode, void* arg); 
     27 
     28  void start(); 
     29  void stop(); 
    2630         
    27                void send_request(float,float,float,float,float);       
    28                int read(char*, int); 
     31  void send_request(float,float,float,float,float);    
     32  int read(char*, int); 
    2933 
    30                 int d_decim; 
    31                 int d_fc_mhz; 
    32                 int d_offset_hz; 
    33                 int d_rf_attn; 
    34                 int d_ddc_gain; 
     34  int d_decim; 
     35  int d_fc_mhz; 
     36  int d_offset_hz; 
     37  int d_rf_attn; 
     38  int d_ddc_gain; 
     39  int d_sock; 
     40  state d_state; 
    3541 
    36 //              in_addr d_adx;   
    37                 in_addr d_myadx;         
    38  
    39                 struct sockaddr_in d_sockaddr; 
    40                 struct sockaddr_in d_mysockaddr; 
    41          
    42                 int d_sock; 
    43                 int d_state; 
    4442}; 
    4543 
    4644 
    47  
    48  
    49  
    50  
    5145#endif 
  • gnuradio/trunk/gr-msdd6000/src/msdd_source_base.cc

    r8782 r9028  
    11/* -*- c++ -*- */ 
    22/* 
    3  * Copyright 2004 Free Software Foundation, Inc. 
     3 * Copyright 2004,2008 Free Software Foundation, Inc. 
    44 *  
    55 * This file is part of GNU Radio 
     
    2525 
    2626#ifdef HAVE_CONFIG_H 
    27 #include "config.h" 
     27#include <config.h> 
    2828#endif 
    2929 
     
    3131#include <gr_io_signature.h> 
    3232#include <assert.h> 
    33 #include <netdb.h> 
    3433#include <omnithread.h> 
    3534#include <stdexcept> 
     35#include <iostream> 
     36#ifdef HAVE_NETDB_H 
     37#include <netdb.h> 
     38#endif 
     39#ifdef HAVE_SYS_SOCKET_H 
    3640#include <sys/socket.h> 
     41#endif 
     42#ifdef HAVE_ARPA_INET_H 
    3743#include <arpa/inet.h> 
     44#endif 
     45 
    3846 
    3947#ifdef MSDD_DEBUG_TRUE 
    40 #include <iostream> 
    4148#define MSDD_DEBUG(x) std::cout << x << std::endl; 
    4249#else 
     
    4653 
    4754#ifdef MSDD_DEBUG2_TRUE 
    48 #include <iostream> 
    4955#define MSDD_DEBUG2(x) std::cout << x << std::endl; 
    5056#else 
     
    5258#endif 
    5359 
    54 #include <iostream> 
    5560 
    5661namespace { 
  • gnuradio/trunk/gr-msdd6000/src/msdd_source_c.cc

    r8782 r9028  
    2222 
    2323#ifdef HAVE_CONFIG_H 
    24 #include "config.h" 
     24#include <config.h> 
    2525#endif 
     26#include <msdd_source_c.h> 
     27#include <gr_io_signature.h> 
    2628 
    2729//#define MSDD_DEBUG2_TRUE 
     
    3436#endif 
    3537 
    36 #include <msdd_source_c.h> 
    37 #include <gr_io_signature.h> 
    3838 
    3939namespace { 
  • gnuradio/trunk/gr-msdd6000/src/msdd_source_s.cc

    r8782 r9028  
    2222 
    2323#ifdef HAVE_CONFIG_H 
    24 #include "config.h" 
     24#include <config.h> 
    2525#endif 
     26#include <msdd_source_s.h> 
     27#include <gr_io_signature.h> 
    2628 
    2729#define MSDD_DEBUG2_TRUE 
     
    3436#endif 
    3537 
    36 #include <msdd_source_s.h> 
    37 #include <gr_io_signature.h> 
    3838 
    3939namespace { 
  • gnuradio/trunk/gr-msdd6000/src/msdd_source_simple.cc

    r8782 r9028  
     1/* -*- c++ -*- */ 
     2/* 
     3 * Copyright 2008 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 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. 
     20 */ 
    121#ifdef HAVE_CONFIG_H 
    2 #include "config.h" 
     22#include <config.h> 
    323#endif 
    424 
    5 #include <vector> 
    625#include <msdd_source_simple.h> 
    726#include <gr_io_signature.h> 
    8 #include <gr_sync_block.h> 
    9  
    10 #ifndef FALSE 
    11 #define FALSE   (0==1) 
    12 #define TRUE    (0==0) 
    13 #endif 
    1427 
    1528 
     
    2538                    unsigned short port_src)  
    2639                : gr_sync_block("MSDD_SOURCE_SIMPLE", 
    27                         gr_make_io_signature (0,0,0), 
    28                         gr_make_io_signature (1, 1, sizeof (short))) 
     40                                gr_make_io_signature (0,0,0), 
     41                                gr_make_io_signature (1, 1, sizeof (short))), 
     42                  rcv(new MSDD6000((char*) src)), d_lastseq(0) 
    2943{ 
    30         rcv = new MSDD6000((char*)src); 
    3144} 
     45 
     46msdd_source_simple::~msdd_source_simple () 
     47{ 
     48} 
     49 
    3250 
    3351int 
     
    4664        int seq = *((int*) &buffer[2]); 
    4765         
     66        // FIXME get rid of these magic 366's! 
    4867        if(d_lastseq == -366){ 
    4968                // not started case 
     
    7998bool msdd_source_simple::set_decim_rate(unsigned int rate) 
    8099{ 
    81         rcv->set_decim(log2(rate)); 
    82         return TRUE; 
     100        // FIXME seems buggy.  How about a floor or ceil? 
     101        rcv->set_decim((int) log2(rate)); 
     102        return true; 
    83103} 
    84104 
     
    88108        long new_fc = (long)freq; 
    89109        rcv->set_fc( new_fc/1000000, new_fc%1000000); 
    90         return TRUE
     110        return true
    91111} 
    92112 
     
    96116        if(gain < 0 || gain > 10){ 
    97117                printf("GAIN IS OUTSIDE ACCEPTABLE RANGE!\n"); 
    98                 return FALSE
     118                return false
    99119        } 
    100120        // ok i lied this is not really a pga, its decimation gain 
    101121        rcv->set_ddc_gain((int)gain); 
    102         return TRUE; 
    103 
    104  
    105  
    106 msdd_source_simple::~msdd_source_simple () 
    107 
    108         delete rcv; 
     122        return true; 
    109123} 
    110124 
     
    113127{ 
    114128        rcv->start(); 
     129        return true; 
    115130} 
    116131 
     
    119134{ 
    120135        rcv->stop(); 
    121 
    122  
    123 int msdd_source_simple::ninput_bytes_reqd_for_noutput_items(int out){ 
    124         return 0; 
     136        return true; 
    125137} 
    126138 
     
    130142 
    131143int msdd_source_simple::decim_rate(){ 
    132         return pow(2, rcv->d_decim)
     144        return 1 << rcv->d_decim
    133145} 
    134146 
     
    147159        return r; 
    148160} 
    149  
  • gnuradio/trunk/gr-msdd6000/src/msdd_source_simple.h

    r8782 r9028  
     1/* -*- c++ -*- */ 
     2/* 
     3 * Copyright 2008 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 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. 
     20 */ 
    121#ifndef INCLUDED_MSDD_SOURCE_SIMPLE_H 
    222#define INCLUDED_MSDD_SOURCE_SIMPLE_H 
    323 
    4 #include <stdexcept> 
    5 #include <sys/socket.h> 
    6 #include <netinet/in.h> 
    7 #include <arpa/inet.h> 
    8 #include <stdio.h> 
    924#include <gr_sync_block.h> 
    1025#include <msdd6000.h> 
     26#include <boost/scoped_ptr.hpp> 
    1127 
    1228 
     
    2036 
    2137 
    22  
    2338class msdd_source_simple : public gr_sync_block { 
    2439 private: 
     
    2641  msdd_make_source_simple ( const char *src, unsigned short port_src); 
    2742 
    28   MSDD6000* rcv; 
     43  boost::scoped_ptr<MSDD6000> rcv; 
    2944  int d_lastseq; 
    3045 
     
    3449 public: 
    3550  ~msdd_source_simple (); 
    36   int ninput_bytes_reqd_for_noutput_items(int out); 
    3751  bool stop(); 
    3852  bool start();