Commit Graph

6 Commits

Author SHA1 Message Date
Oliver Jowett 56625449e8
Adaptive gain, first pass (#134)
This PR adds basic adaptive gain support, which adjusts SDR gain on the fly based on the noise & signal levels seen.

There are two control mechanisms:

Dynamic range control is enabled by the --adaptive-range option. This adjusts SDR gain to try to achieve a minimum dynamic range, regardless of the exact hardware in the RF path.

Burst (loud message) control is enabled by the --adaptive-burst option. This decreases SDR gain when undecodable loud messages are heard, allowing for better reception of nearby aircraft at the expense of range.

This is only the basic implementation - see the PR for remaining work to do.
2021-06-29 20:11:13 +08:00
Oliver Jowett 8dd83d2e7e Don't hang on exit if rtlsdr hardware stops sending samples.
Give up and exit after 30 seconds of no sample data, rather than just warning and continuing.

background & discussion: https://discussions.flightaware.com/t/cpu-hikes-crash-dump1090-fa/74759

The scenario this addresses is:

 * Hardware wedges, USB bulk endpoint stops providing data
 * librtlsdr remains in rtlsdr_read_async() waiting for either USB data which never arrives,
   or a cancellation via _a different thread_ calling rtlsdr_cancel_async().
 * main thread notices the lack of SDR data and complains
 * something external e.g. piaware tries a restart and sends SIGTERM
 * the signal handler sets Modes.exit = 1; the main thread starts waiting for receive thread termination
 * because we're never getting callbacks from rtlsdr_read_async(), we never call rtlsdr_cancel_async
 * dump1090 hangs waiting on receive thread termination

To fix this, add a sdrStop() handler function where the general contract is "make the receive thread terminate".
In the rtlsdr case, this calls rtlsdr_cancel_async directly, which will make rtlsdr_read_async() return even
if the hardware is stuck.

The main thread then calls sdrStop() before waiting for receive thread termination.

Also, as discussed in the thread above, there's not really much point in continuing to run if the SDR
has wedged, so bail out after 30 seconds of no sample data.

Also, if pthread_timedjoin_np is available, use it in preference to pthread_join so that we do not wait
indefinitely for the receive thread on shutdown. If the join times out, give up and abort() as we can't
safely continue a clean shutdown while the receive thread is running.
2021-03-21 02:03:08 +08:00
Oliver Jowett 8b21104d66 Factor out sdr thread CPU monitoring 2020-08-05 19:50:38 +08:00
Oliver Jowett 2142d2edf5 Whitespace changes only: cleaning up trailing whitespace at EOL 2017-06-15 18:17:07 +01:00
Oliver Jowett 44129dca12 Add copyright headers to all the new files. 2017-02-03 00:36:41 +00:00
Oliver Jowett 75b221c0e3 Lots of refactoring to move the SDR-type-specific bits out of the
main code and make them optionally buildable.
2017-01-27 17:30:40 +00:00