mirror of
https://github.com/rtlsdrblog/rtl-sdr-blog.git
synced 2024-11-10 12:47:40 +01:00
allow user to select sync mode
Patch provided by 'airwave', Thanks! Signed-off-by: Steve Markgraf <steve@steve-m.de>
This commit is contained in:
parent
7e6d2f55ee
commit
a58def7f58
36
src/main.c
36
src/main.c
@ -44,6 +44,7 @@ void usage(void)
|
|||||||
"\t[-d device_index (default: 0)]\n"
|
"\t[-d device_index (default: 0)]\n"
|
||||||
"\t[-g tuner_gain (default: 0 dB)]\n"
|
"\t[-g tuner_gain (default: 0 dB)]\n"
|
||||||
"\t[-b output_block_size (default: 16 * 16384)]\n"
|
"\t[-b output_block_size (default: 16 * 16384)]\n"
|
||||||
|
"\t[-S force sync output (default: async)]\n"
|
||||||
"\toutput filename\n");
|
"\toutput filename\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -67,6 +68,7 @@ int main(int argc, char **argv)
|
|||||||
int n_read;
|
int n_read;
|
||||||
int r, opt;
|
int r, opt;
|
||||||
int i, gain = 0;
|
int i, gain = 0;
|
||||||
|
int sync_mode = 0;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
uint32_t dev_index = 0;
|
uint32_t dev_index = 0;
|
||||||
@ -74,8 +76,7 @@ int main(int argc, char **argv)
|
|||||||
uint32_t samp_rate = DEFAULT_SAMPLE_RATE;
|
uint32_t samp_rate = DEFAULT_SAMPLE_RATE;
|
||||||
uint32_t out_block_size = DEFAULT_BUF_LENGTH;
|
uint32_t out_block_size = DEFAULT_BUF_LENGTH;
|
||||||
|
|
||||||
|
while ((opt = getopt(argc, argv, "d:f:g:s:b:S::")) != -1) {
|
||||||
while ((opt = getopt(argc, argv, "d:f:g:s:b:")) != -1) {
|
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'd':
|
case 'd':
|
||||||
dev_index = atoi(optarg);
|
dev_index = atoi(optarg);
|
||||||
@ -92,6 +93,9 @@ int main(int argc, char **argv)
|
|||||||
case 'b':
|
case 'b':
|
||||||
out_block_size = (uint32_t)atof(optarg);
|
out_block_size = (uint32_t)atof(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'S':
|
||||||
|
sync_mode = 1;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
break;
|
break;
|
||||||
@ -177,23 +181,25 @@ int main(int argc, char **argv)
|
|||||||
fprintf(stderr, "WARNING: Failed to reset buffers.\n");
|
fprintf(stderr, "WARNING: Failed to reset buffers.\n");
|
||||||
|
|
||||||
fprintf(stderr, "Reading samples...\n");
|
fprintf(stderr, "Reading samples...\n");
|
||||||
#if 0
|
|
||||||
while (!do_exit) {
|
|
||||||
r = rtlsdr_read_sync(dev, buffer, out_block_size, &n_read);
|
|
||||||
if (r < 0)
|
|
||||||
fprintf(stderr, "WARNING: sync read failed.\n");
|
|
||||||
|
|
||||||
fwrite(buffer, n_read, 1, file);
|
if (sync_mode) {
|
||||||
|
while (!do_exit) {
|
||||||
|
r = rtlsdr_read_sync(dev, buffer, out_block_size, &n_read);
|
||||||
|
if (r < 0)
|
||||||
|
fprintf(stderr, "WARNING: sync read failed.\n");
|
||||||
|
|
||||||
if (n_read < out_block_size) {
|
fwrite(buffer, n_read, 1, file);
|
||||||
fprintf(stderr, "Short read, samples lost, exiting!\n");
|
|
||||||
break;
|
if (n_read < out_block_size) {
|
||||||
|
fprintf(stderr, "Short read, samples lost, exiting!\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
rtlsdr_read_async(dev, rtlsdr_callback, (void *)file,
|
||||||
|
DEFAULT_ASYNC_BUF_NUMBER, out_block_size);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
rtlsdr_read_async(dev, rtlsdr_callback, (void *)file,
|
|
||||||
DEFAULT_ASYNC_BUF_NUMBER, out_block_size);
|
|
||||||
#endif
|
|
||||||
if (do_exit)
|
if (do_exit)
|
||||||
fprintf(stderr, "\nUser cancel, exiting...\n");
|
fprintf(stderr, "\nUser cancel, exiting...\n");
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user