Print device name on stderr.
When invalid device index specified, print list of detected devices.
This commit is contained in:
parent
357451f639
commit
6fd7c91e52
|
@ -14,6 +14,10 @@ RtlSdrSource::RtlSdrSource(int dev_index)
|
|||
{
|
||||
int r;
|
||||
|
||||
const char *devname = rtlsdr_get_device_name(dev_index);
|
||||
if (devname != NULL)
|
||||
m_devname = devname;
|
||||
|
||||
r = rtlsdr_open(&m_dev, dev_index);
|
||||
if (r < 0) {
|
||||
m_error = "Failed to open RTL-SDR device (";
|
||||
|
|
|
@ -45,6 +45,12 @@ public:
|
|||
/** Return a list of supported tuner gain settings in dB. */
|
||||
std::vector<double> get_tuner_gains();
|
||||
|
||||
/** Return name of opened RTL-SDR device. */
|
||||
std::string get_device_name() const
|
||||
{
|
||||
return m_devname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a bunch of samples from the device.
|
||||
*
|
||||
|
@ -73,6 +79,7 @@ public:
|
|||
private:
|
||||
struct rtlsdr_dev * m_dev;
|
||||
int m_block_length;
|
||||
std::string m_devname;
|
||||
std::string m_error;
|
||||
};
|
||||
|
||||
|
|
16
main.cc
16
main.cc
|
@ -293,9 +293,8 @@ int main(int argc, char **argv)
|
|||
}
|
||||
break;
|
||||
case 'd':
|
||||
if (!parse_opt(optarg, devidx) || devidx < 0) {
|
||||
badarg("-d");
|
||||
}
|
||||
if (!parse_opt(optarg, devidx))
|
||||
devidx = -1;
|
||||
break;
|
||||
case 's':
|
||||
if (!parse_opt(optarg, ifrate) || ifrate <= 0) {
|
||||
|
@ -367,6 +366,17 @@ int main(int argc, char **argv)
|
|||
tuner_freq += 0.25 * ifrate;
|
||||
}
|
||||
|
||||
vector<string> devnames = RtlSdrSource::get_device_names();
|
||||
if (devidx < 0 || (unsigned int)devidx >= devnames.size()) {
|
||||
fprintf(stderr, "ERROR: invalid device index %d\n", devidx);
|
||||
fprintf(stderr, "Found %u devices:\n", (unsigned int)devnames.size());
|
||||
for (unsigned int i = 0; i < devnames.size(); i++) {
|
||||
fprintf(stderr, "%2u: %s\n", i, devnames[i].c_str());
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
fprintf(stderr, "using device %d: %s\n", devidx, devnames[devidx].c_str());
|
||||
|
||||
// Open RTL-SDR device.
|
||||
RtlSdrSource rtlsdr(devidx);
|
||||
if (!rtlsdr) {
|
||||
|
|
Loading…
Reference in New Issue