Skip to content

Commit

Permalink
Close RTLSDR device upon exit
Browse files Browse the repository at this point in the history
Make sure that controller thread returns first so that it does not
attempt to set center frequency on a closed device.
After that, call rtlsdr_close from rtlsdr_stop.  Reference rtl_test
for an example of closing the device.
  • Loading branch information
jratke committed Oct 24, 2020
1 parent adb069b commit b3cdf7c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion input-rtlsdr.cpp
Expand Up @@ -177,7 +177,7 @@ int rtlsdr_stop(input_t * const input) {
if(rtlsdr_cancel_async(dev_data->dev) < 0) {
return -1;
}
return 0;
return rtlsdr_close(dev_data->dev);
}

int rtlsdr_set_centerfreq(input_t * const input, int const centerfreq) {
Expand Down
4 changes: 2 additions & 2 deletions rtl_airband.cpp
Expand Up @@ -1075,15 +1075,15 @@ int main(int argc, char* argv[]) {

log(LOG_INFO, "Cleaning up\n");
for (int i = 0; i < device_count; i++) {
if(devices[i].mode == R_SCAN)
pthread_join(devices[i].controller_thread, NULL);
if(input_stop(devices[i].input) != 0 || devices[i].input->state != INPUT_STOPPED) {
if(errno != 0) {
log(LOG_ERR, "Failed do stop device #%d: %s\n", i, strerror(errno));
} else {
log(LOG_ERR, "Failed do stop device #%d\n", i);
}
}
if(devices[i].mode == R_SCAN)
pthread_join(devices[i].controller_thread, NULL);
}
log(LOG_INFO, "Input threads closed\n");
close_debug();
Expand Down

0 comments on commit b3cdf7c

Please sign in to comment.