osmosdr: add initial component files

gr3.6
Dimitri Stolnikov 11 years ago
parent 584ddafe10
commit 755da481d4
  1. 37
      lib/osmosdr/CMakeLists.txt
  2. 105
      lib/osmosdr/osmosdr_control.cc
  3. 67
      lib/osmosdr/osmosdr_control.h
  4. 88
      lib/osmosdr/osmosdr_snk_c.cc
  5. 76
      lib/osmosdr/osmosdr_snk_c.h
  6. 84
      lib/osmosdr/osmosdr_src_c.cc
  7. 76
      lib/osmosdr/osmosdr_src_c.h

@ -0,0 +1,37 @@
# Copyright 2012 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
########################################################################
# This file included, use CMake directory variables
########################################################################
include_directories(APPEND ${CMAKE_CURRENT_SOURCE_DIR})
set(osmosdr_srcs
${CMAKE_CURRENT_SOURCE_DIR}/osmosdr_control.cc
${CMAKE_CURRENT_SOURCE_DIR}/osmosdr_snk_c.cc
${CMAKE_CURRENT_SOURCE_DIR}/osmosdr_src_c.cc
)
########################################################################
# Append gnuradio-osmosdr library sources
########################################################################
list(APPEND gr_osmosdr_srcs ${osmosdr_srcs})
list(APPEND gr_osmosdr_libs ${GNURADIO_AUDIO_LIBRARIES})

@ -0,0 +1,105 @@
/* -*- c++ -*- */
/*
* Copyright 2012 Dimitri Stolnikov <horiz0n@gmx.net>
*
* 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include <fstream>
#include <string>
#include <sstream>
#include <boost/assign.hpp>
#include "osmosdr_control.h"
using namespace boost::assign;
osmosdr_control::osmosdr_control(const std::string &args)
{
/* lookup acm control channel device name for a given alsa device name */
/*
if (args.empty())
pick first available device or throw an exception();
*/
}
osmosdr_control::~osmosdr_control()
{
}
/*
1 [OsmoSDR ]: USB-Audio - OsmoSDR
sysmocom OsmoSDR at usb-0000:00:06.1-2, high speed
*/
std::vector< std::string > osmosdr_control::find_devices()
{
std::vector< std::string > devices;
std::string line;
std::ifstream cards( "/proc/asound/cards" );
if ( cards.is_open() )
{
while ( cards.good() )
{
getline (cards, line);
if ( line.find( "USB-Audio - OsmoSDR" ) != std::string::npos )
{
int id;
std::istringstream( line ) >> id;
std::ostringstream hw_id;
hw_id << "hw:" << id; // build alsa identifier
devices += hw_id.str();
}
}
cards.close();
}
return devices;
}
std::string osmosdr_control::audio_dev_name()
{
return "hw:1";
}
std::string osmosdr_control::control_dev_name()
{
return "/dev/ttyUSB0";
}
osmosdr_rx_control::osmosdr_rx_control(const std::string &args) :
osmosdr_control(args)
{
}
osmosdr_rx_control::~osmosdr_rx_control()
{
}
osmosdr_tx_control::osmosdr_tx_control(const std::string &args) :
osmosdr_control(args)
{
}
osmosdr_tx_control::~osmosdr_tx_control()
{
}

@ -0,0 +1,67 @@
/* -*- c++ -*- */
/*
* Copyright 2012 Dimitri Stolnikov <horiz0n@gmx.net>
*
* 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef OSMOSDR_CONTROL_H
#define OSMOSDR_CONTROL_H
#include <string>
#include <complex>
#include <osmosdr_ranges.h>
/*!
* session object to cdc-acm based control channel of the device
*/
class osmosdr_control
{
public:
osmosdr_control(const std::string &args);
virtual ~osmosdr_control();
/*!
* Discovers all devices connected to the host computer.
* \return a vector of device addresses
*/
static std::vector< std::string > find_devices();
protected:
std::string audio_dev_name();
std::string control_dev_name();
};
/*!
* osmosdr_source class derives from this class to be able to control the device
*/
class osmosdr_rx_control : public osmosdr_control
{
public:
osmosdr_rx_control(const std::string &args);
virtual ~osmosdr_rx_control();
};
/*!
* osmosdr_sink class derives from this class to be able to control the device
*/
class osmosdr_tx_control : public osmosdr_control
{
public:
osmosdr_tx_control(const std::string &args);
virtual ~osmosdr_tx_control();
};
#endif // OSMOSDR_CONTROL_H

@ -0,0 +1,88 @@
/* -*- c++ -*- */
/*
* Copyright 2012 Dimitri Stolnikov <horiz0n@gmx.net>
*
* 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
/*
* config.h is generated by configure. It contains the results
* of probing for features, options etc. It should be the first
* file included in your .cc file.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <osmosdr_snk_c.h>
#include <gr_io_signature.h>
#include <gr_audio_sink.h>
#include <gr_complex_to_xxx.h>
/*
* Create a new instance of osmosdr_snk_c and return
* a boost shared_ptr. This is effectively the public constructor.
*/
osmosdr_snk_c_sptr
osmosdr_make_snk_c (const std::string &args)
{
return gnuradio::get_initial_sptr(new osmosdr_snk_c (args));
}
/*
* Specify constraints on number of input and output streams.
* This info is used to construct the input and output signatures
* (2nd & 3rd args to gr_block's constructor). The input and
* output signatures are used by the runtime system to
* check that a valid number and type of inputs and outputs
* are connected to this block. In this case, we accept
* only 1 input and 1 output.
*/
static const int MIN_IN = 1; // mininum number of input streams
static const int MAX_IN = 1; // maximum number of input streams
static const int MIN_OUT = 0; // minimum number of output streams
static const int MAX_OUT = 0; // maximum number of output streams
/*
* The private constructor
*/
osmosdr_snk_c::osmosdr_snk_c (const std::string & args)
: gr_hier_block2 ("osmosdr_snk_c",
gr_make_io_signature (MIN_IN, MAX_IN, sizeof (gr_complex)),
gr_make_io_signature (MIN_OUT, MAX_OUT, sizeof (gr_complex))),
osmosdr_tx_control(args)
{
throw std::runtime_error("FIXME: OsmoSDR sink is not yet implemented");
/* Audio sink; sample rate is 96kHz by default */
audio_sink::sptr snk = audio_make_sink(96000, audio_dev_name(), true);
gr_complex_to_real_sptr real_part = gr_make_complex_to_real(1);
gr_complex_to_imag_sptr imag_part = gr_make_complex_to_imag(1);
connect(self(), 0, real_part, 0);
connect(self(), 0, imag_part, 0);
connect(imag_part, 0, snk, 0); /* Left is I */
connect(real_part, 0, snk, 1); /* Right is Q */
}
/*
* Our virtual destructor.
*/
osmosdr_snk_c::~osmosdr_snk_c ()
{
// nothing else required in this example
}

@ -0,0 +1,76 @@
/* -*- c++ -*- */
/*
* Copyright 2012 Dimitri Stolnikov <horiz0n@gmx.net>
*
* 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 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_OSMOSDR_SNK_C_H
#define INCLUDED_OSMOSDR_SNK_C_H
#include <osmosdr_api.h>
#include <osmosdr_control.h>
#include <gr_hier_block2.h>
class osmosdr_snk_c;
/*
* We use boost::shared_ptr's instead of raw pointers for all access
* to gr_blocks (and many other data structures). The shared_ptr gets
* us transparent reference counting, which greatly simplifies storage
* management issues. This is especially helpful in our hybrid
* C++ / Python system.
*
* See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
*
* As a convention, the _sptr suffix indicates a boost::shared_ptr
*/
typedef boost::shared_ptr<osmosdr_snk_c> osmosdr_snk_c_sptr;
/*!
* \brief Return a shared_ptr to a new instance of osmosdr_snk_c.
*
* To avoid accidental use of raw pointers, osmosdr_snk_c's
* constructor is private. osmosdr_make_snk_c is the public
* interface for creating new instances.
*/
OSMOSDR_API osmosdr_snk_c_sptr osmosdr_make_snk_c (const std::string & args = "");
/*!
* \brief Takes a stream of complex samples.
* \ingroup block
*
* This uses the preferred technique: subclassing gr_hier_block2.
*/
class OSMOSDR_API osmosdr_snk_c : public gr_hier_block2,
public osmosdr_tx_control
{
private:
// The friend declaration allows osmosdr_make_snk_c to
// access the private constructor.
friend OSMOSDR_API osmosdr_snk_c_sptr osmosdr_make_snk_c (const std::string & args);
/*!
* \brief Takes a stream of complex samples.
*/
osmosdr_snk_c (const std::string & args); // private constructor
public:
~osmosdr_snk_c (); // public destructor
};
#endif /* INCLUDED_OSMOSDR_SNK_C_H */

@ -0,0 +1,84 @@
/* -*- c++ -*- */
/*
* Copyright 2012 Dimitri Stolnikov <horiz0n@gmx.net>
*
* 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 GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
/*
* config.h is generated by configure. It contains the results
* of probing for features, options etc. It should be the first
* file included in your .cc file.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "osmosdr_src_c.h"
#include <gr_io_signature.h>
#include <gr_audio_source.h>
#include <gr_float_to_complex.h>
/*
* Create a new instance of osmosdr_src_c and return
* a boost shared_ptr. This is effectively the public constructor.
*/
osmosdr_src_c_sptr
osmosdr_make_src_c (const std::string &args)
{
return gnuradio::get_initial_sptr(new osmosdr_src_c (args));
}
/*
* Specify constraints on number of input and output streams.
* This info is used to construct the input and output signatures
* (2nd & 3rd args to gr_block's constructor). The input and
* output signatures are used by the runtime system to
* check that a valid number and type of inputs and outputs
* are connected to this block. In this case, we accept
* only 1 input and 1 output.
*/
static const int MIN_IN = 0; // mininum number of input streams
static const int MAX_IN = 0; // maximum number of input streams
static const int MIN_OUT = 1; // minimum number of output streams
static const int MAX_OUT = 1; // maximum number of output streams
/*
* The private constructor
*/
osmosdr_src_c::osmosdr_src_c (const std::string &args)
: gr_hier_block2 ("osmosdr_src_c",
gr_make_io_signature (MIN_IN, MAX_IN, sizeof (gr_complex)),
gr_make_io_signature (MIN_OUT, MAX_OUT, sizeof (gr_complex))),
osmosdr_rx_control(args)
{
/* Audio source; sample rate is 500kHz by default */
audio_source::sptr src = audio_make_source(500000, audio_dev_name(), true);
/* block to convert stereo audio to a complex stream */
gr_float_to_complex_sptr f2c = gr_make_float_to_complex(1);
connect(src, 0, f2c, 0); /* Left is I */
connect(src, 1, f2c, 1); /* Right is Q */
connect(f2c, 0, self(), 0);
}
/*
* Our virtual destructor.
*/
osmosdr_src_c::~osmosdr_src_c ()
{
// nothing else required in this example
}

@ -0,0 +1,76 @@
/* -*- c++ -*- */
/*
* Copyright 2012 Dimitri Stolnikov <horiz0n@gmx.net>
*
* 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 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_OSMOSDR_SRC_C_H
#define INCLUDED_OSMOSDR_SRC_C_H
#include <osmosdr_api.h>
#include <osmosdr_control.h>
#include <gr_hier_block2.h>
class osmosdr_src_c;
/*
* We use boost::shared_ptr's instead of raw pointers for all access
* to gr_blocks (and many other data structures). The shared_ptr gets
* us transparent reference counting, which greatly simplifies storage
* management issues. This is especially helpful in our hybrid
* C++ / Python system.
*
* See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
*
* As a convention, the _sptr suffix indicates a boost::shared_ptr
*/
typedef boost::shared_ptr<osmosdr_src_c> osmosdr_src_c_sptr;
/*!
* \brief Return a shared_ptr to a new instance of osmosdr_src_c.
*
* To avoid accidental use of raw pointers, osmosdr_src_c's
* constructor is private. osmosdr_make_src_c is the public
* interface for creating new instances.
*/
OSMOSDR_API osmosdr_src_c_sptr osmosdr_make_src_c (const std::string & args = "");
/*!
* \brief Provides a stream of complex samples.
* \ingroup block
*
* \sa osmosdr_sink_c for a version that subclasses gr_hier_block2.
*/
class OSMOSDR_API osmosdr_src_c : public gr_hier_block2,
public osmosdr_rx_control
{
private:
// The friend declaration allows osmosdr_make_src_c to
// access the private constructor.
friend OSMOSDR_API osmosdr_src_c_sptr osmosdr_make_src_c (const std::string & args);
/*!
* \brief Provides a stream of complex samples.
*/
osmosdr_src_c (const std::string & args); // private constructor
public:
~osmosdr_src_c (); // public destructor
};
#endif /* INCLUDED_OSMOSDR_SRC_C_H */
Loading…
Cancel
Save