aboutsummaryrefslogtreecommitdiffstats
path: root/lib/osmosdr/osmosdr_control.cc
blob: 7de27731634081355d4860346c826ad179e0b5df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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()
{
}