[PATCH 1/1] add -S (synchronous) mode to rtl_fm

Stuart Henderson stu at spacehopper.org
Tue Apr 23 14:47:33 UTC 2013


The enclosed diff adds a synchronous mode to rtl_fm. This helps
OpenBSD (where libusb async isn't yet working).

Signed-off-by: Stuart Henderson <stu at spacehopper.org>
---
 src/rtl_fm.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/src/rtl_fm.c b/src/rtl_fm.c
index e8ebb77..a71e287 100644
--- a/src/rtl_fm.c
+++ b/src/rtl_fm.c
@@ -128,6 +128,7 @@ void usage(void)
 		"\t[-E sets lower edge tuning (default: center)]\n"
 		"\t[-N enables NBFM mode (default: on)]\n"
 		"\t[-W enables WBFM mode (default: off)]\n"
+		"\t[-S force sync output (default: async)]\n"
 		"\t (-N -s 170k -o 4 -A fast -r 32k -l 0 -D)\n"
 		"\tfilename (a '-' dumps samples to stdout)\n"
 		"\t (omitting the filename also uses stdout)\n\n"
@@ -723,12 +724,14 @@ int main(int argc, char **argv)
 	uint32_t dev_index = 0;
 	int device_count;
 	int ppm_error = 0;
+	int sync_mode = 0;
 	char vendor[256], product[256], serial[256];
+
 	fm_init(&fm);
 	pthread_mutex_init(&data_ready, NULL);
 	pthread_mutex_init(&data_write, NULL);
 
-	while ((opt = getopt(argc, argv, "d:f:g:s:b:l:o:t:r:p:EFA:NWMULRDC")) != -1) {
+	while ((opt = getopt(argc, argv, "d:f:g:s:b:l:o:t:r:p:EFA:NWMULRDSC")) != -1) {
 		switch (opt) {
 		case 'd':
 			dev_index = atoi(optarg);
@@ -815,6 +818,9 @@ int main(int argc, char **argv)
 		case 'R':
 			fm.mode_demod = &raw_demod;
 			break;
+		case 'S':
+			sync_mode = 1;
+			break;
 		default:
 			usage();
 			break;
@@ -921,9 +927,24 @@ int main(int argc, char **argv)
 		fprintf(stderr, "WARNING: Failed to reset buffers.\n");}
 
 	pthread_create(&demod_thread, NULL, demod_thread_fn, (void *)(&fm));
-	rtlsdr_read_async(dev, rtlsdr_callback, (void *)(&fm),
-			      DEFAULT_ASYNC_BUF_NUMBER,
-			      lcm_post[fm.post_downsample] * DEFAULT_BUF_LENGTH);
+	if (sync_mode) {
+		fprintf(stderr, "Reading samples in sync mode...\n");
+		while (!do_exit) {
+			r = rtlsdr_read_sync(dev, &fm.buf,
+					     lcm_post[fm.post_downsample] * DEFAULT_BUF_LENGTH,
+					     &fm.buf_len);
+			if (r < 0) {
+				fprintf(stderr, "WARNING: sync read failed.\n");
+				break;
+			}
+			full_demod(&fm);
+		}
+	} else {
+		fprintf(stderr, "Reading samples in async mode...\n");
+		rtlsdr_read_async(dev, rtlsdr_callback, (void *)(&fm),
+				  DEFAULT_ASYNC_BUF_NUMBER,
+				  lcm_post[fm.post_downsample] * DEFAULT_BUF_LENGTH);
+	}
 
 	if (do_exit) {
 		fprintf(stderr, "\nUser cancel, exiting...\n");}
-- 
1.8.1.3






More information about the osmocom-sdr mailing list