rtl433  UNKNOWN
RTL-433 utility
pulse_detect.h
Go to the documentation of this file.
1 
12 #ifndef INCLUDE_PULSE_DETECT_H_
13 #define INCLUDE_PULSE_DETECT_H_
14 
15 #include <stdint.h>
16 #include <stdio.h>
17 #include "r_util.h"
18 
19 #define PD_MAX_PULSES 1200 // Maximum number of pulses before forcing End Of Package
20 #define PD_MIN_PULSES 16 // Minimum number of pulses before declaring a proper package
21 #define PD_MIN_PULSE_SAMPLES 10 // Minimum number of samples in a pulse for proper detection
22 #define PD_MIN_GAP_MS 10 // Minimum gap size in milliseconds to exceed to declare End Of Package
23 #define PD_MAX_GAP_MS 100 // Maximum gap size in milliseconds to exceed to declare End Of Package
24 #define PD_MAX_GAP_RATIO 10 // Ratio gap/pulse width to exceed to declare End Of Package (heuristic)
25 #define PD_MAX_PULSE_MS 100 // Pulse width in ms to exceed to declare End Of Package (e.g. for non OOK packages)
26 
28 typedef struct pulse_data {
31  unsigned start_ago;
32  unsigned end_ago;
33  unsigned int num_pulses;
34  int pulse[PD_MAX_PULSES];
35  int gap[PD_MAX_PULSES];
38  int fsk_f1_est;
39  int fsk_f2_est;
40  float freq1_hz;
41  float freq2_hz;
42  float rssi_db;
43  float snr_db;
44  float noise_db;
45 } pulse_data_t;
46 
47 // Package types
51 };
52 
54 
57 
60 
62 void pulse_data_dump_raw(uint8_t *buf, unsigned len, uint64_t buf_offset, pulse_data_t const *data, uint8_t bits);
63 
66 
68 void pulse_data_print_vcd(FILE *file, pulse_data_t const *data, int ch_id);
69 
71 void pulse_data_load(FILE *file, pulse_data_t *data);
72 
74 void pulse_data_print_pulse_header(FILE *file);
75 
77 void pulse_data_dump(FILE *file, pulse_data_t *data);
78 
80 
82 
95 int pulse_detect_package(pulse_detect_t *pulse_detect, int16_t const *envelope_data, int16_t const *fm_data, int len, int16_t level_limit, uint32_t samp_rate, uint64_t sample_offset, pulse_data_t *pulses, pulse_data_t *fsk_pulses);
96 
98 void pulse_analyzer(pulse_data_t *data, int package_type);
99 
100 
101 #endif /* INCLUDE_PULSE_DETECT_H_ */
int fsk_f1_est
Estimate for the F1 frequency for FSK.
Definition: pulse_detect.h:38
unsigned __int64 uint64_t
Definition: mongoose.h:273
int fsk_f2_est
Estimate for the F2 frequency for FSK.
Definition: pulse_detect.h:39
pulse_detect_t * pulse_detect_create(void)
Definition: pulse_detect.c:355
int gap[PD_MAX_PULSES]
Width of gaps between pulses (low) in number of samples.
Definition: pulse_detect.h:35
short int16_t
Definition: mongoose.h:270
Data for a compact representation of generic pulse train.
Definition: pulse_detect.h:28
int pulse_detect_package(pulse_detect_t *pulse_detect, int16_t const *envelope_data, int16_t const *fm_data, int len, int16_t level_limit, uint32_t samp_rate, uint64_t sample_offset, pulse_data_t *pulses, pulse_data_t *fsk_pulses)
Demodulate On/Off Keying (OOK) and Frequency Shift Keying (FSK) from an envelope signal.
Definition: pulse_detect.c:366
float snr_db
Definition: pulse_detect.h:43
int pulse[PD_MAX_PULSES]
Width of pulses (high) in number of samples.
Definition: pulse_detect.h:34
int ook_high_estimate
Estimate for the OOK high level at end of package.
Definition: pulse_detect.h:37
void pulse_data_print_vcd_header(FILE *file, uint32_t sample_rate)
Print a header for the VCD format.
Definition: pulse_detect.c:59
void pulse_data_dump(FILE *file, pulse_data_t *data)
Print the content of a pulse_data_t structure as OOK text.
Definition: pulse_detect.c:151
unsigned start_ago
Start of first pulse in number of samples ago.
Definition: pulse_detect.h:31
float rssi_db
Definition: pulse_detect.h:42
void pulse_analyzer(pulse_data_t *data, int package_type)
Analyze and print result.
Definition: pulse_detect.c:670
int ook_low_estimate
Estimate for the OOK low level (base noise level) at beginning of package.
Definition: pulse_detect.h:36
unsigned int num_pulses
Definition: pulse_detect.h:33
void pulse_detect_free(pulse_detect_t *pulse_detect)
Definition: pulse_detect.c:360
unsigned int uint32_t
Definition: mongoose.h:269
unsigned end_ago
End of last pulse in number of samples ago.
Definition: pulse_detect.h:32
void pulse_data_print_vcd(FILE *file, pulse_data_t const *data, int ch_id)
Print the content of a pulse_data_t structure in VCD format.
Definition: pulse_detect.c:80
uint64_t offset
Offset to first pulse in number of samples from start of stream.
Definition: pulse_detect.h:29
Internal state data for pulse_pulse_package()
Definition: pulse_detect.c:336
Various utility functions for use by applications.
void pulse_data_print(pulse_data_t const *data)
Print the content of a pulse_data_t structure (for debug).
Definition: pulse_detect.c:26
float freq1_hz
Definition: pulse_detect.h:40
unsigned char uint8_t
Definition: mongoose.h:267
float noise_db
Definition: pulse_detect.h:44
float freq2_hz
Definition: pulse_detect.h:41
uint32_t sample_rate
Sample rate the pulses are recorded with.
Definition: pulse_detect.h:30
Definition: pulse_detect.h:49
struct pulse_data pulse_data_t
Data for a compact representation of generic pulse train.
void pulse_data_load(FILE *file, pulse_data_t *data)
Read the next pulse_data_t structure from OOK text.
Definition: pulse_detect.c:101
Definition: pulse_detect.h:50
package_types
Definition: pulse_detect.h:48
void pulse_data_clear(pulse_data_t *data)
Clear the content of a pulse_data_t structure.
Definition: pulse_detect.c:21
void pulse_data_dump_raw(uint8_t *buf, unsigned len, uint64_t buf_offset, pulse_data_t const *data, uint8_t bits)
Dump the content of a pulse_data_t structure as raw binary.
Definition: pulse_detect.c:48
void pulse_data_print_pulse_header(FILE *file)
Print a header for the OOK text format.
Definition: pulse_detect.c:140
Definition: data.h:58