From a36b922fa54458ccc432e794a47415115519bf6a Mon Sep 17 00:00:00 2001 From: eb Date: Sun, 27 Jul 2008 22:28:20 +0000 Subject: [PATCH] Merged gr-msdd6000 portability fix to trunk (eb/msdd -r8940:9027) git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9028 221aa14e-8319-0410-a670-987f0aec2ac5 --- config/grc_gr_msdd6000.m4 | 2 + gr-msdd6000/src/msdd.i | 10 --- gr-msdd6000/src/msdd6000.cc | 101 ++++++++++++++++++++------ gr-msdd6000/src/msdd6000.h | 64 ++++++++-------- gr-msdd6000/src/msdd_source_base.cc | 17 +++-- gr-msdd6000/src/msdd_source_c.cc | 6 +- gr-msdd6000/src/msdd_source_s.cc | 6 +- gr-msdd6000/src/msdd_source_simple.cc | 67 ++++++++++------- gr-msdd6000/src/msdd_source_simple.h | 30 ++++++-- 9 files changed, 188 insertions(+), 115 deletions(-) diff --git a/config/grc_gr_msdd6000.m4 b/config/grc_gr_msdd6000.m4 index 0d5ddd9a..48af51c6 100644 --- a/config/grc_gr_msdd6000.m4 +++ b/config/grc_gr_msdd6000.m4 @@ -28,6 +28,8 @@ AC_DEFUN([GRC_GR_MSDD6000],[ 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]) diff --git a/gr-msdd6000/src/msdd.i b/gr-msdd6000/src/msdd.i index 993b47d3..c3260b45 100644 --- a/gr-msdd6000/src/msdd.i +++ b/gr-msdd6000/src/msdd.i @@ -51,11 +51,6 @@ class msdd_source_base : public gr_sync_block { unsigned short port_src ) 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 */ @@ -224,8 +219,6 @@ class msdd_source_s : public msdd_source_base { 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 @@ class msdd_source_c : public msdd_source_base { 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 @@ class msdd_source_simple : public gr_sync_block { 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); diff --git a/gr-msdd6000/src/msdd6000.cc b/gr-msdd6000/src/msdd6000.cc index a2055877..830a69ea 100644 --- a/gr-msdd6000/src/msdd6000.cc +++ b/gr-msdd6000/src/msdd6000.cc @@ -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 +#endif +#include #include -#include -#include #include #include -void optimize_socket(int socket); +#ifdef HAVE_ARPA_INET_H +#include +#endif +#ifdef HAVE_NETINET_IN_H +#include +#endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif + +#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){ +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 @@ MSDD6000::MSDD6000(char* addr){ // 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 @@ MSDD6000::MSDD6000(char* addr){ } -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(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 @@ void optimize_socket(int socket){ // 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 @@ void MSDD6000::send_request(float freq_mhz, float rf_attn, float ddc_gain, float 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)); } diff --git a/gr-msdd6000/src/msdd6000.h b/gr-msdd6000/src/msdd6000.h index 94a62e8b..808a8386 100644 --- a/gr-msdd6000/src/msdd6000.h +++ b/gr-msdd6000/src/msdd6000.h @@ -1,51 +1,45 @@ #ifndef MSDD6000_H #define MSDD6000_H -#include -#include -#include +#include -#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 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); - - void set_output(int mode, void* arg); - - void start(); - void stop(); - - void send_request(float,float,float,float,float); - int read(char*, int); +public: - int d_decim; - int d_fc_mhz; - int d_offset_hz; - int d_rf_attn; - int d_ddc_gain; + enum state { + STATE_STOPPED, STATE_STARTED, + }; -// in_addr d_adx; - in_addr d_myadx; + MSDD6000(char* ip_addr); + ~MSDD6000(); - struct sockaddr_in d_sockaddr; - struct sockaddr_in d_mysockaddr; - - int d_sock; - int d_state; -}; + 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); + void set_output(int mode, void* arg); + void start(); + void stop(); + + 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 diff --git a/gr-msdd6000/src/msdd_source_base.cc b/gr-msdd6000/src/msdd_source_base.cc index 79f37b13..8adb7255 100644 --- a/gr-msdd6000/src/msdd_source_base.cc +++ b/gr-msdd6000/src/msdd_source_base.cc @@ -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 #endif #include #include #include -#include #include #include +#include +#ifdef HAVE_NETDB_H +#include +#endif +#ifdef HAVE_SYS_SOCKET_H #include +#endif +#ifdef HAVE_ARPA_INET_H #include +#endif + #ifdef MSDD_DEBUG_TRUE -#include #define MSDD_DEBUG(x) std::cout << x << std::endl; #else #define MSDD_DEBUG(x) @@ -45,13 +52,11 @@ #ifdef MSDD_DEBUG2_TRUE -#include #define MSDD_DEBUG2(x) std::cout << x << std::endl; #else #define MSDD_DEBUG2(x) #endif -#include namespace { const int OUTPUT_MAX((1 << 15)*8); diff --git a/gr-msdd6000/src/msdd_source_c.cc b/gr-msdd6000/src/msdd_source_c.cc index db1f320c..8f153ef4 100644 --- a/gr-msdd6000/src/msdd_source_c.cc +++ b/gr-msdd6000/src/msdd_source_c.cc @@ -21,8 +21,10 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include #endif +#include +#include //#define MSDD_DEBUG2_TRUE @@ -33,8 +35,6 @@ #define MSDD_DEBUG2(x) #endif -#include -#include namespace { static const int NBASIC_SAMPLES_PER_ITEM = 2; // I & Q diff --git a/gr-msdd6000/src/msdd_source_s.cc b/gr-msdd6000/src/msdd_source_s.cc index 9395647d..55d621dc 100644 --- a/gr-msdd6000/src/msdd_source_s.cc +++ b/gr-msdd6000/src/msdd_source_s.cc @@ -21,8 +21,10 @@ */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include #endif +#include +#include #define MSDD_DEBUG2_TRUE @@ -33,8 +35,6 @@ #define MSDD_DEBUG2(x) #endif -#include -#include namespace { static const int NBASIC_SAMPLES_PER_ITEM = 1; diff --git a/gr-msdd6000/src/msdd_source_simple.cc b/gr-msdd6000/src/msdd_source_simple.cc index 4e0c47ba..ec83c5bf 100644 --- a/gr-msdd6000/src/msdd_source_simple.cc +++ b/gr-msdd6000/src/msdd_source_simple.cc @@ -1,16 +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. + */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include #endif -#include #include #include -#include - -#ifndef FALSE -#define FALSE (0==1) -#define TRUE (0==0) -#endif msdd_source_simple_sptr @@ -24,12 +37,17 @@ msdd_source_simple::msdd_source_simple ( 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) +{ +} + +msdd_source_simple::~msdd_source_simple () { - rcv = new MSDD6000((char*)src); } + int msdd_source_simple::work (int noutput_items, gr_vector_const_void_star &input_items, @@ -45,6 +63,7 @@ msdd_source_simple::work (int noutput_items, 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 @@ msdd_source_simple::work (int noutput_items, 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 @@ bool msdd_source_simple::set_rx_freq(int channel, double freq) { long new_fc = (long)freq; rcv->set_fc( new_fc/1000000, new_fc%1000000); - return TRUE; + return true; } @@ -95,33 +115,25 @@ bool msdd_source_simple::set_pga(int which, double gain) { 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; -} - - -msdd_source_simple::~msdd_source_simple () -{ - delete rcv; + return true; } bool msdd_source_simple::start() { rcv->start(); + return true; } bool msdd_source_simple::stop() { rcv->stop(); -} - -int msdd_source_simple::ninput_bytes_reqd_for_noutput_items(int out){ - return 0; + return true; } long msdd_source_simple::adc_freq(){ @@ -129,7 +141,7 @@ long msdd_source_simple::adc_freq(){ } int msdd_source_simple::decim_rate(){ - return pow(2, rcv->d_decim); + return 1 << rcv->d_decim; } @@ -146,4 +158,3 @@ std::vector msdd_source_simple::freq_range(){ r.push_back(6.0*1000*1000*1000); return r; } - diff --git a/gr-msdd6000/src/msdd_source_simple.h b/gr-msdd6000/src/msdd_source_simple.h index a5e59383..095233d4 100644 --- a/gr-msdd6000/src/msdd_source_simple.h +++ b/gr-msdd6000/src/msdd_source_simple.h @@ -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 -#include -#include -#include -#include #include #include +#include class msdd_source_simple; @@ -19,13 +35,12 @@ typedef boost::shared_ptr msdd_source_simple_sptr; 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 rcv; int d_lastseq; protected: @@ -33,7 +48,6 @@ class msdd_source_simple : public gr_sync_block { public: ~msdd_source_simple (); - int ninput_bytes_reqd_for_noutput_items(int out); bool stop(); bool start(); -- 2.30.2