blob: de967ab1dbdfbc689c945f010bf7bd837ed38d4e [file] [log] [blame]
Vasil Velichkov54580d12019-04-17 18:28:46 +03001#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# @file
4# @author (C) 2019 by Vasil Velichkov <vvvelichkov@gmail.com>
5# @section LICENSE
6#
7# Gr-gsm 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# Gr-gsm 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
18# along with gr-gsm; see the file COPYING. If not, write to
19# the Free Software Foundation, Inc., 51 Franklin Street,
20# Boston, MA 02110-1301, USA.
21#
22#
23
24import osmosdr
25import os
26
27def get_devices(hint=""):
28 return osmosdr.device_find(osmosdr.device_t(hint))
29
30def match(dev, filters):
31 for f in filters:
32 for k, v in f.items():
33 if (k not in dev or dev[k] != v):
34 break
35 else:
36 return True
37 return False
38
39def exclude(devices, filters = ({'driver': 'audio'},)):
40 return [dev for dev in devices if not match(dev, filters)]
41
42def get_all_args(hint="nofake"):
43 return map(lambda dev: dev.to_string(), exclude(get_devices(hint)))
44
45def get_default_args(args):
46 # The presence of GRC_BLOCKS_PATH environment variable indicates that
47 # gnuradio-companion compiles a flowgraph and in this case no exception
48 # have to be thrown otherwise the generaged python script will be invalid.
49 # This allows compilation of flowgraphs without an SDR device.
50 if args or os.getenv("GRC_BLOCKS_PATH"):
51 return args
52
53 devices = get_all_args("nofake")
54 if not devices:
55 raise RuntimeError("Unable to find any supported SDR devices")
56
57 return devices[0]
58
59def print_devices(hint=""):
60 devices = exclude(get_devices(hint))
61 if devices:
62 print("\n".join(map(lambda dev: dev.to_string(), devices)))
63 else:
64 print("Unable to find any supported SDR devices")