File: GrOsmoSDRRegister.in.cpp

package info (click to toggle)
soapyosmo 0.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,240 kB
  • ctags: 4,269
  • sloc: cpp: 15,347; python: 11,343; xml: 263; makefile: 12; sh: 1
file content (92 lines) | stat: -rw-r--r-- 2,997 bytes parent folder | download | duplicates (3)
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
/*
 * Copyright 2014 Free Software Foundation, Inc.
 *
 * This file is part of GrOsmoSDR support modules
 *
 * GrOsmoSDR 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.
 *
 * GrOsmoSDR 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 GrOsmoSDR; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 */

#include <SoapySDR/Registry.hpp>
#include "GrOsmoSDRInterface.hpp"
#include "arg_helpers.h"
@LOCAL_INCLUDES@
#include <cstdlib>

static std::vector<SoapySDR::Kwargs> find__@TARGET@(const SoapySDR::Kwargs &args)
{
    std::vector<SoapySDR::Kwargs> results;

    //call the get_devices() on the source or sink, but not both
    #if @HAS_SOURCE@
    std::vector<std::string> source_results = @TARGET@_source_c::get_devices();
    for (size_t i = 0; i < source_results.size(); i++)
    {
        results.push_back(params_to_dict(source_results[i]));
    }
    #elif @HAS_SINK@
    std::vector<std::string> sink_results = @TARGET@_sink_c::get_devices();
    for (size_t i = 0; i < sink_results.size(); i++)
    {
        results.push_back(params_to_dict(sink_results[i]));
    }
    #endif

    //no device number specified, return all results
    if (args.count("@TARGET@") == 0) return results;

    //device number is used as a filter when specified
    std::vector<SoapySDR::Kwargs> filteredResults;
    const int devNum = atoi(args.at("@TARGET@").c_str());
    for (size_t i = 0; i < results.size(); i++)
    {
        if (
            results[i].count("@TARGET@") == 0 or //driver doesn't support filter
            devNum == atoi(results[i].at("@TARGET@").c_str()) //or device match
        )
        {
            filteredResults.push_back(results[i]);
        }
    }

    return filteredResults;
}

static SoapySDR::Device *make__@TARGET@(const SoapySDR::Kwargs &args)
{
    //convert args to param string
    std::string params;
    for (SoapySDR::Kwargs::const_iterator it = args.begin(); it != args.end(); ++it)
    {
        if (not params.empty()) params += ",";
        params += it->first + "=" + it->second;
    }

    //new device
    GrOsmoSDRInterface *device = new GrOsmoSDRInterface("@TARGET@");

    //call factories when they exist
    #if @HAS_SOURCE@
    device->installSource(make_@TARGET@_source_c(params));
    #endif
    #if @HAS_SINK@
    device->installSink(make_@TARGET@_sink_c(params));
    #endif

    //done
    return device;
}

static SoapySDR::Registry register__@TARGET@("@TARGET@", &find__@TARGET@, &make__@TARGET@, SOAPY_SDR_ABI_VERSION);