On Mon, 2016-02-01 at 15:29 +0100, Benjamin Larsson wrote:
>
> Patch welcome. Make that the default but add a command line override.
Hm, not quite working as intended. There is a synchronisation issue
between the decoders and pwm_analyze(), where the decoder actually
emits an event in the rtlsdr_callback() invocation *before*
pwm_analyze() dumps the signal to a file.
So the simple hack to prevent pwm_analyze() from dumping to a file if
any decoders worked... doesn't always do its job.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6376b88..15f9f52 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -34,7 +34,7 @@ if(CMAKE_COMPILER_IS_GNUCC AND NOT WIN32)
ADD_DEFINITIONS(-Wextra)
ADD_DEFINITIONS(-Wno-unused)
ADD_DEFINITIONS(-Wsign-compare)
- ADD_DEFINITIONS(-g3 -O0)
+ ADD_DEFINITIONS(-g3 -O2)
ADD_DEFINITIONS(-std=gnu99)
#
http://gcc.gnu.org/wiki/Visibility
add_definitions(-fvisibility=hidden)
diff --git a/src/devices/emontx.c b/src/devices/emontx.c
index 3a090ab..fb9565a 100644
--- a/src/devices/emontx.c
+++ b/src/devices/emontx.c
@@ -39,6 +39,7 @@ static int emontx_callback(bitbuffer_t *bitbuffer) {
bitrow_t *bb = bitbuffer->bb;
unsigned bitpos = 0;
unsigned bits = bitbuffer->bits_per_row[0];
+ int events = 0;
// Search for only 22 bits to cope with inverted frames and
// the missing final preamble bit with RFM69 transmissions.
@@ -125,8 +126,9 @@ static int emontx_callback(bitbuffer_t *bitbuffer) {
words[10] == 3000 ? NULL : "temp6_C", "", DATA_FORMAT, "%.1f", DATA_DOUBLE, (double)words[10] / 10.0,
NULL);
data_acquired_handler(data);
+ events++;
}
- return 0;
+ return events;
}
static char *output_fields[] = {
diff --git a/src/devices/oil_watchman.c b/src/devices/oil_watchman.c
index e6913cf..c87f3f1 100644
--- a/src/devices/oil_watchman.c
+++ b/src/devices/oil_watchman.c
@@ -33,6 +33,7 @@ static int oil_watchman_callback(bitbuffer_t *bitbuffer) {
data_t *data;
unsigned bitpos = 0;
bitbuffer_t databits = {0};
+ int events = 0;
local_time_str(0, time_str);
@@ -91,8 +92,9 @@ static int oil_watchman_callback(bitbuffer_t *bitbuffer) {
"depth", "", DATA_INT, depth,
NULL);
data_acquired_handler(data);
+ events++;
}
- return 0;
+ return events;
};
static char *output_fields[] = {
diff --git a/src/rtl_433.c b/src/rtl_433.c
index 0771fda..1b23a24 100644
--- a/src/rtl_433.c
+++ b/src/rtl_433.c
@@ -73,6 +73,7 @@ struct dm_state {
/* Signal grabber variables */
int signal_grabber;
+ int grab_all;
int8_t* sg_buf;
int sg_index;
int sg_len;
@@ -110,7 +111,8 @@ void usage(r_device *devices) {
"\t[-q] Quiet mode, suppress non-data messages\n"
"\t[-W] Overwrite mode, disable checks to prevent files from being overwritten\n"
"\t= File I/O options =\n"
- "\t[-t] Test signal auto save. Use it together with analyze mode (-a -t). Creates one file per signal\n"
+ "\t[-t] Test signal auto save. Use it together with analyze mode (-a -t). Creates one file per undecoded signal\n"
+ "\t[-T] Test signal auto save. Like -t but saves all signals, even successfully decoded ones\n"
"\t\t Note: Saves raw I/Q samples (uint8 pcm, 2 channel). Preferred mode for generating test files\n"
"\t[-r <filename>] Read data from input file instead of a receiver\n"
"\t[-m <mode>] Data file mode for input / output file (default: 0)\n"
@@ -466,7 +468,7 @@ static void classify_signal() {
};
-static void pwm_analyze(struct dm_state *demod, int16_t *buf, uint32_t len) {
+static int pwm_analyze(struct dm_state *demod, int16_t *buf, uint32_t len, int grab) {
unsigned int i;
int32_t threshold = (demod->level_limit ? demod->level_limit : DEFAULT_LEVEL_LIMIT); // Fix for auto level
@@ -513,7 +515,7 @@ static void pwm_analyze(struct dm_state *demod, int16_t *buf, uint32_t len) {
classify_signal();
signal_pulse_counter = 0;
- if (demod->sg_buf) {
+ if (demod->sg_buf && grab) {
int start_pos, signal_bszie, wlen, wrest = 0, sg_idx, idx;
char sgf_name[256] = {0};
FILE *sgfp;
@@ -569,17 +571,17 @@ static void pwm_analyze(struct dm_state *demod, int16_t *buf, uint32_t len) {
}
- return;
+ return 0;
err:
- fprintf(stderr, "To many pulses detected, probably bad input data or input parameters\n");
- return;
+ fprintf(stderr, "Too many pulses detected, probably bad input data or input parameters\n");
+ return 0;
}
static void rtlsdr_callback(unsigned char *iq_buf, uint32_t len, void *ctx) {
struct dm_state *demod = ctx;
- int i;
+ int i, events = 0;
if (do_exit || do_exit_async)
return;
@@ -617,9 +619,7 @@ static void rtlsdr_callback(unsigned char *iq_buf, uint32_t len, void *ctx) {
}
}
- if (demod->analyze || (demod->out_file == stdout)) { // We don't want to decode devices when outputting to stdout
- pwm_analyze(demod, demod->am_buf, len / 2);
- } else {
+ if (demod->out_file != stdout) { // We don't want to decode devices when outputting to stdout
// Detect a package and loop through demodulators with pulse data
int package_type = 1; // Just to get us started
while(package_type) {
@@ -629,25 +629,25 @@ static void rtlsdr_callback(unsigned char *iq_buf, uint32_t len, void *ctx) {
for (i = 0; i < demod->r_dev_num; i++) {
switch (demod->r_devs[i]->modulation) {
case OOK_PULSE_PCM_RZ:
- pulse_demod_pcm(&demod->pulse_data, demod->r_devs[i]);
+ events += pulse_demod_pcm(&demod->pulse_data, demod->r_devs[i]);
break;
case OOK_PULSE_PPM_RAW:
- pulse_demod_ppm(&demod->pulse_data, demod->r_devs[i]);
+ events += pulse_demod_ppm(&demod->pulse_data, demod->r_devs[i]);
break;
case OOK_PULSE_PWM_PRECISE:
- pulse_demod_pwm_precise(&demod->pulse_data, demod->r_devs[i]);
+ events += pulse_demod_pwm_precise(&demod->pulse_data, demod->r_devs[i]);
break;
case OOK_PULSE_PWM_RAW:
- pulse_demod_pwm(&demod->pulse_data, demod->r_devs[i]);
+ events += pulse_demod_pwm(&demod->pulse_data, demod->r_devs[i]);
break;
case OOK_PULSE_PWM_TERNARY:
- pulse_demod_pwm_ternary(&demod->pulse_data, demod->r_devs[i]);
+ events += pulse_demod_pwm_ternary(&demod->pulse_data, demod->r_devs[i]);
break;
case OOK_PULSE_MANCHESTER_ZEROBIT:
- pulse_demod_manchester_zerobit(&demod->pulse_data, demod->r_devs[i]);
+ events += pulse_demod_manchester_zerobit(&demod->pulse_data, demod->r_devs[i]);
break;
case OOK_PULSE_CLOCK_BITS:
- pulse_demod_clock_bits(&demod->pulse_data, demod->r_devs[i]);
+ events += pulse_demod_clock_bits(&demod->pulse_data, demod->r_devs[i]);
break;
// FSK decoders
case FSK_PULSE_PCM:
@@ -673,10 +673,10 @@ static void rtlsdr_callback(unsigned char *iq_buf, uint32_t len, void *ctx) {
case OOK_PULSE_CLOCK_BITS:
break;
case FSK_PULSE_PCM:
- pulse_demod_pcm(&demod->fsk_pulse_data, demod->r_devs[i]);
+ events += pulse_demod_pcm(&demod->fsk_pulse_data, demod->r_devs[i]);
break;
case FSK_PULSE_PWM_RAW:
- pulse_demod_pwm(&demod->fsk_pulse_data, demod->r_devs[i]);
+ events += pulse_demod_pwm(&demod->fsk_pulse_data, demod->r_devs[i]);
break;
default:
fprintf(stderr, "Unknown modulation %d in protocol!\n", demod->r_devs[i]->modulation);
@@ -687,6 +687,10 @@ static void rtlsdr_callback(unsigned char *iq_buf, uint32_t len, void *ctx) {
}
}
}
+ if (demod->analyze || (demod->out_file == stdout)) {
+ printf("analyze, events %d\n", events);
+ pwm_analyze(demod, demod->am_buf, len / 2, demod->grab_all || !events);
+ }
if (demod->out_file) {
uint8_t* out_buf = iq_buf; // Default is to dump IQ samples
@@ -787,7 +791,7 @@ int main(int argc, char **argv) {
demod->level_limit = DEFAULT_LEVEL_LIMIT;
- while ((opt = getopt(argc, argv, "x:z:p:DtaAqm:r:l:d:f:g:s:b:n:SR:F:C:W")) != -1) {
+ while ((opt = getopt(argc, argv, "x:z:p:DtTaAqm:r:l:d:f:g:s:b:n:SR:F:C:W")) != -1) {
switch (opt) {
case 'd':
dev_index = atoi(optarg);
@@ -826,6 +830,9 @@ int main(int argc, char **argv) {
case 't':
demod->signal_grabber = 1;
break;
+ case 'T':
+ demod->signal_grabber = demod->grab_all = 1;
+ break;
case 'm':
demod->debug_mode = atoi(optarg);
break;
--
dwmw2