mirror of
https://github.com/rtlsdrblog/rtl-sdr-blog.git
synced 2025-06-27 13:37:50 +02:00
lib: add rtlsdr_get_index_by_serial()
This allows to open a device by a name (serial number string) that has been programmed with rtl_eeprom -s. Signed-off-by: Steve Markgraf <steve@steve-m.de>
This commit is contained in:
@ -1264,6 +1264,28 @@ int rtlsdr_get_device_usb_strings(uint32_t index, char *manufact,
|
||||
return r;
|
||||
}
|
||||
|
||||
int rtlsdr_get_index_by_serial(const char *serial)
|
||||
{
|
||||
int i, cnt, r;
|
||||
char str[256];
|
||||
|
||||
if (!serial)
|
||||
return -1;
|
||||
|
||||
cnt = rtlsdr_get_device_count();
|
||||
|
||||
if (!cnt)
|
||||
return -2;
|
||||
|
||||
for (i = 0; i < cnt; i++) {
|
||||
r = rtlsdr_get_device_usb_strings(i, NULL, NULL, str);
|
||||
if (!r && !strcmp(serial, str))
|
||||
return i;
|
||||
}
|
||||
|
||||
return -3;
|
||||
}
|
||||
|
||||
int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index)
|
||||
{
|
||||
int r;
|
||||
|
Reference in New Issue
Block a user