Skip to content
This repository was archived by the owner on Jan 27, 2021. It is now read-only.

Commit 53ccc38

Browse files
authored
Merge pull request keenerd#18 from hayguen/development
Development
2 parents ddb009c + 99c3e08 commit 53ccc38

File tree

6 files changed

+808
-91
lines changed

6 files changed

+808
-91
lines changed

README.rtlfm_cmdfile

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
2+
rtl_fm now has option '-C' for a command file, from which a list of frequencies are read.
3+
So it's similar to using a frequency range, as with "-f 118M:137M:25k"
4+
The difference is, that you can parametrize one frequency per line together with
5+
- the tuner gain
6+
- condition for triggering
7+
- measurement duration
8+
and a command to execute.
9+
Lines starting with '#' are skipped / interpreted as comments.
10+
Parameters a seperated by comma.
11+
12+
Here's an example:
13+
---
14+
# freq in Hz or special keyword, gain in dB, trig_crit (in/out/lt/gt), trig_level, trig_tolerance, #meas, #blocks, trigger_command
15+
# windows: rtl_fm -f 105.2m -E rdc -w 350k -s 200k -m 2.2m -B 200000 -C cmdfile.csv -n -v
16+
# rtl_fm -f 105.2m -E rdc -w 350k -s 200k -m 2.2m -W 4 -B 10000 -C cmdfile.csv -n -v
17+
# linux: ./rtl_fm -f 105.2m -E rdc -w 350k -s 200k -m 2.2m -B 200000 -C cmdfile.csv -n -v
18+
#
19+
# windows command examples:
20+
# cmd.exe, /C echo hello world
21+
# cmd.exe, /C start notepad
22+
# calc.exe
23+
#
24+
# linux examples:
25+
# ssmtp
26+
# sendxmpp
27+
## for piping some message to ssmtp or sendxmpp you'll need to write small scripts
28+
29+
# 'adcmax' keyword in first column activates measurement of max adc value at capture rate to determine optimum gain and avoid oversteering
30+
# 'adcrms' keyword activates rms calculation at capture rate. for usual it's similar to adcmax. there are differences in case of oversteering
31+
# activate verbose output (option '-v') to get the output. The maximum possible sample value is 128.
32+
# You should have approx. 6 dB headroom to allow measuring stronger signals, that means measured baseline values should be below 64.
33+
# An the other side you'll want to measure weaker signals, so the measured baseline value should be above a minimum of approx 8 or 16.
34+
adcmax,
35+
adcrms,
36+
100.7m, 30, in, 0, 1, 10, 100,
37+
33.0m, 20,out,60, 3, 10, 400, /home/odroid/test/simple.sh, frq !freq! gain !gain! measured !mlevel! tenth dB !crit! { !reflevel! +/- !reftol! tenth dB }
38+
# now check for optimal gain in some steps, which should be done per frequency!:
39+
100.7m, 0, gt, 400, 1, 1, 100,
40+
100.7m, 3, gt, 400, 1, 1, 100,
41+
100.7m, 6, gt, 400, 1, 1, 100,
42+
100.7m, 12, gt, 400, 1, 1, 100,
43+
100.7m, 18, gt, 400, 1, 1, 100,
44+
45+
---
46+
47+
* first frequency is 100.7 MHz, tuned with ~ 30 dB tuner gain;
48+
condition is 'in' { 0 +/- 1 } dB,
49+
with 10 measurements, averaging the rms level in dB.
50+
Each single measurement is processed after decimation of block/buffer-size many samples (see option -W).
51+
The resulting number of decimated samples might get too small to allow a reliable measurement.
52+
This number also depends on the capture rate: ensure minimum capture rate with option '-m'. This is also important for reducing aliases.
53+
Check the output 'block length after decimation is ... samples'!
54+
If condition for measured level is true, then a command can be triggered, which is executed in background.
55+
Then, a next trigger for this frequency is blocked for 100 measurements.
56+
There is nothing triggered for 100.7 MHz.
57+
58+
* 2nd frequency is 33.0 MHz, tuned with ~ 20 dB tuner gain;
59+
condition is 'out' { 60 +/- 3 } dB,
60+
with 10 measurements.
61+
That means, the trigger is activated when averaged level is below 57 dB or above 63 dB.
62+
Next trigger for this frequency is blocked for 400 measurements.
63+
Triggered command is the shell script '/home/odroid/test/simple.sh',
64+
with the arguments 'frq !freq! gain !gain! measured !mlevel! tenth dB !crit! { !reflevel! +/- !reftol! tenth dB }'.
65+
You can use following keywords in the arguments, which need to be free standing!:
66+
- !freq!
67+
current frequency in Hz
68+
69+
- !gain!
70+
current tuner gain in tenth dB to allow easier evaluation from scripts.
71+
72+
- !mlevel!
73+
average measured level in tenth dB
74+
75+
- !crit!
76+
one of "in", "out", "<" or ">" for the tested condition
77+
78+
- !reflevel!
79+
condition's reference level in tenth dB
80+
81+
- !reftol!
82+
condition's reference tolerance in tenth dB
83+
84+
85+
Application might be monitoring of some stations
86+
and triggering a notification, e.g. via ssmtp or sendxmpp,
87+
when a stations power level is below it's expected value.
88+
89+
Another application might be triggering a recording with a second RTL dongle.
90+
91+
92+
Send comments, suggestions or reports to
93+
Hayati Ayguen <[email protected]>
94+

src/convenience/convenience.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
#include <string.h>
2323
#include <stdio.h>
2424
#include <stdlib.h>
25+
#include <ctype.h>
2526

2627
#ifndef _WIN32
2728
#include <unistd.h>
2829
#else
2930
#include <windows.h>
3031
#include <fcntl.h>
3132
#include <io.h>
33+
#include <process.h>
3234
#define _USE_MATH_DEFINES
3335
#endif
3436

@@ -43,6 +45,8 @@ double atofs(char *s)
4345
int len;
4446
double suff = 1.0;
4547
len = strlen(s);
48+
/* allow formatting spaces from .csv command file */
49+
while ( len > 1 && isspace(s[len-1]) ) --len;
4650
last = s[len-1];
4751
s[len-1] = '\0';
4852
switch (last) {
@@ -325,4 +329,68 @@ int verbose_device_search(char *s)
325329
return -1;
326330
}
327331

332+
#ifndef _WIN32
333+
334+
void executeInBackground( char * file, char * args, char * searchStr[], char * replaceStr[] )
335+
{
336+
pid_t pid;
337+
char * argv[256] = { NULL };
338+
int k, argc = 0;
339+
argv[argc++] = file;
340+
if (args) {
341+
argv[argc] = strtok(args, " ");
342+
while (argc < 256 && argv[argc]) {
343+
argv[++argc] = strtok(NULL, " ");
344+
for (k=0; argv[argc] && searchStr && replaceStr && searchStr[k] && replaceStr[k]; k++) {
345+
if (!strcmp(argv[argc], searchStr[k])) {
346+
argv[argc] = replaceStr[k];
347+
break;
348+
}
349+
}
350+
}
351+
}
352+
353+
pid = fork();
354+
switch (pid)
355+
{
356+
case -1:
357+
/* Fork() has failed */
358+
fprintf(stderr, "error: fork for '%s' failed!\n", file);
359+
break;
360+
case 0:
361+
execvp(file, argv);
362+
fprintf(stderr, "error: execv of '%s' from within fork failed!\n", file);
363+
exit(10);
364+
break;
365+
default:
366+
/* This is processed by the parent */
367+
break;
368+
}
369+
}
370+
371+
#else
372+
373+
void executeInBackground( char * file, char * args, char * searchStr[], char * replaceStr[] )
374+
{
375+
char * argv[256] = { NULL };
376+
int k, argc = 0;
377+
argv[argc++] = file;
378+
if (args) {
379+
argv[argc] = strtok(args, " \t");
380+
while (argc < 256 && argv[argc]) {
381+
argv[++argc] = strtok(NULL, " \t");
382+
for (k=0; argv[argc] && searchStr && replaceStr && searchStr[k] && replaceStr[k]; k++) {
383+
if (!strcmp(argv[argc], searchStr[k])) {
384+
argv[argc] = replaceStr[k];
385+
break;
386+
}
387+
}
388+
}
389+
}
390+
391+
spawnvp(P_NOWAIT, file, argv);
392+
}
393+
394+
#endif
395+
328396
// vim: tabstop=8:softtabstop=8:shiftwidth=8:noexpandtab

src/convenience/convenience.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,7 @@ int verbose_reset_buffer(rtlsdr_dev_t *dev);
154154

155155
int verbose_device_search(char *s);
156156

157+
158+
void executeInBackground( char * file, char * args, char * searchStr[], char * replaceStr[] );
159+
157160
#endif /*__CONVENIENCE_H*/

src/librtlsdr.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,10 +1493,11 @@ int rtlsdr_get_direct_sampling(rtlsdr_dev_t *dev)
14931493

14941494
int rtlsdr_set_ds_mode(rtlsdr_dev_t *dev, enum rtlsdr_ds_mode mode, uint32_t freq_threshold)
14951495
{
1496+
uint32_t center_freq;
14961497
if (!dev)
14971498
return -1;
14981499

1499-
uint32_t center_freq = rtlsdr_get_center_freq(dev);
1500+
center_freq = rtlsdr_get_center_freq(dev);
15001501
if ( !center_freq )
15011502
return -2;
15021503

@@ -1524,11 +1525,11 @@ int rtlsdr_set_ds_mode(rtlsdr_dev_t *dev, enum rtlsdr_ds_mode mode, uint32_t fre
15241525

15251526
static int rtlsdr_update_ds(rtlsdr_dev_t *dev, uint32_t freq)
15261527
{
1528+
int new_ds = 0;
15271529
int curr_ds = rtlsdr_get_direct_sampling(dev);
15281530
if ( curr_ds < 0 )
15291531
return -1;
15301532

1531-
int new_ds = 0;
15321533
switch (dev->direct_sampling_mode) {
15331534
default:
15341535
case RTLSDR_DS_IQ: break;

0 commit comments

Comments
 (0)