mirror of
https://github.com/rtlsdrblog/rtl-sdr-blog.git
synced 2025-01-26 01:44:55 +01:00
exit if our usb device disappears
This commit is contained in:
parent
84f0a9084b
commit
3cbf139261
@ -89,6 +89,7 @@ struct rtlsdr_dev {
|
|||||||
int corr; /* ppm */
|
int corr; /* ppm */
|
||||||
int gain; /* tenth dB */
|
int gain; /* tenth dB */
|
||||||
struct e4k_state e4k_s;
|
struct e4k_state e4k_s;
|
||||||
|
int dev_lost;
|
||||||
};
|
};
|
||||||
|
|
||||||
void rtlsdr_set_gpio_bit(rtlsdr_dev_t *dev, uint8_t gpio, int val);
|
void rtlsdr_set_gpio_bit(rtlsdr_dev_t *dev, uint8_t gpio, int val);
|
||||||
@ -1309,6 +1310,8 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index)
|
|||||||
|
|
||||||
libusb_init(&dev->ctx);
|
libusb_init(&dev->ctx);
|
||||||
|
|
||||||
|
dev->dev_lost = 1;
|
||||||
|
|
||||||
cnt = libusb_get_device_list(dev->ctx, &list);
|
cnt = libusb_get_device_list(dev->ctx, &list);
|
||||||
|
|
||||||
for (i = 0; i < cnt; i++) {
|
for (i = 0; i < cnt; i++) {
|
||||||
@ -1358,6 +1361,7 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rtlsdr_init_baseband(dev);
|
rtlsdr_init_baseband(dev);
|
||||||
|
dev->dev_lost = 0;
|
||||||
|
|
||||||
/* Probe tuners */
|
/* Probe tuners */
|
||||||
rtlsdr_set_i2c_repeater(dev, 1);
|
rtlsdr_set_i2c_repeater(dev, 1);
|
||||||
@ -1452,16 +1456,18 @@ int rtlsdr_close(rtlsdr_dev_t *dev)
|
|||||||
if (!dev)
|
if (!dev)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* block until all async operations have been completed (if any) */
|
if(!dev->dev_lost) {
|
||||||
while (RTLSDR_INACTIVE != dev->async_status) {
|
/* block until all async operations have been completed (if any) */
|
||||||
|
while (RTLSDR_INACTIVE != dev->async_status) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
Sleep(1);
|
Sleep(1);
|
||||||
#else
|
#else
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
rtlsdr_deinit_baseband(dev);
|
rtlsdr_deinit_baseband(dev);
|
||||||
|
}
|
||||||
|
|
||||||
libusb_release_interface(dev->devh, 0);
|
libusb_release_interface(dev->devh, 0);
|
||||||
libusb_close(dev->devh);
|
libusb_close(dev->devh);
|
||||||
@ -1501,10 +1507,11 @@ static void LIBUSB_CALL _libusb_callback(struct libusb_transfer *xfer)
|
|||||||
dev->cb(xfer->buffer, xfer->actual_length, dev->cb_ctx);
|
dev->cb(xfer->buffer, xfer->actual_length, dev->cb_ctx);
|
||||||
|
|
||||||
libusb_submit_transfer(xfer); /* resubmit transfer */
|
libusb_submit_transfer(xfer); /* resubmit transfer */
|
||||||
} else if (LIBUSB_TRANSFER_CANCELLED == xfer->status) {
|
} else if (LIBUSB_TRANSFER_CANCELLED != xfer->status &&
|
||||||
/* nothing to do */
|
LIBUSB_TRANSFER_COMPLETED != xfer->status) {
|
||||||
} else {
|
dev->dev_lost = 1;
|
||||||
/*fprintf(stderr, "transfer status: %d\n", xfer->status);*/
|
rtlsdr_cancel_async(dev);
|
||||||
|
fprintf(stderr, "cb transfer status: %d, canceling...\n", xfer->status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1640,8 +1647,10 @@ int rtlsdr_read_async(rtlsdr_dev_t *dev, rtlsdr_read_async_cb_t cb, void *ctx,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RTLSDR_INACTIVE == next_status)
|
if (dev->dev_lost || RTLSDR_INACTIVE == next_status) {
|
||||||
|
libusb_handle_events_timeout(dev->ctx, &tv);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user