allow user to send data to stdout

Patch provided by 'airwave', Thanks!

Signed-off-by: Steve Markgraf <steve@steve-m.de>
master
Steve Markgraf 13 years ago
parent a58def7f58
commit 3738a6730c
  1. 15
      src/main.c

@ -29,7 +29,7 @@
#define DEFAULT_SAMPLE_RATE 2048000 #define DEFAULT_SAMPLE_RATE 2048000
#define DEFAULT_ASYNC_BUF_NUMBER 32 #define DEFAULT_ASYNC_BUF_NUMBER 32
#define DEFAULT_BUF_LENGTH (16 * 16384) #define DEFAULT_BUF_LENGTH (16 * 16384)
#define MINIMAL_BUF_LENGTH 32 #define MINIMAL_BUF_LENGTH 512
#define MAXIMAL_BUF_LENGTH (256 * 16384) #define MAXIMAL_BUF_LENGTH (256 * 16384)
static int do_exit = 0; static int do_exit = 0;
@ -45,7 +45,7 @@ void usage(void)
"\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" "\t[-S force sync output (default: async)]\n"
"\toutput filename\n"); "\toutput_filename (a '-' dumps samples to stdout)\n\n");
exit(1); exit(1);
} }
@ -168,21 +168,23 @@ int main(int argc, char **argv)
else else
fprintf(stderr, "Tuner gain set to %i dB.\n", gain); fprintf(stderr, "Tuner gain set to %i dB.\n", gain);
if(strcmp(filename, "-") != 0) {
file = fopen(filename, "wb"); file = fopen(filename, "wb");
if (!file) { if (!file) {
fprintf(stderr, "Failed to open %s\n", filename); fprintf(stderr, "Failed to open %s\n", filename);
goto out; goto out;
} }
} else {
file = stdout;
}
/* Reset endpoint before we start reading from it (mandatory) */ /* Reset endpoint before we start reading from it (mandatory) */
r = rtlsdr_reset_buffer(dev); r = rtlsdr_reset_buffer(dev);
if (r < 0) if (r < 0)
fprintf(stderr, "WARNING: Failed to reset buffers.\n"); fprintf(stderr, "WARNING: Failed to reset buffers.\n");
fprintf(stderr, "Reading samples...\n");
if (sync_mode) { if (sync_mode) {
fprintf(stderr, "Reading samples in sync mode...\n");
while (!do_exit) { while (!do_exit) {
r = rtlsdr_read_sync(dev, buffer, out_block_size, &n_read); r = rtlsdr_read_sync(dev, buffer, out_block_size, &n_read);
if (r < 0) if (r < 0)
@ -196,6 +198,7 @@ int main(int argc, char **argv)
} }
} }
} else { } else {
fprintf(stderr, "Reading samples...\n");
rtlsdr_read_async(dev, rtlsdr_callback, (void *)file, rtlsdr_read_async(dev, rtlsdr_callback, (void *)file,
DEFAULT_ASYNC_BUF_NUMBER, out_block_size); DEFAULT_ASYNC_BUF_NUMBER, out_block_size);
} }
@ -205,7 +208,9 @@ int main(int argc, char **argv)
else else
fprintf(stderr, "\nSystem cancel, exiting...\n"); fprintf(stderr, "\nSystem cancel, exiting...\n");
if (file != stdout)
fclose(file); fclose(file);
rtlsdr_close(dev); rtlsdr_close(dev);
free (buffer); free (buffer);
out: out:

Loading…
Cancel
Save