Commit Graph

18 Commits

Author SHA1 Message Date
Oliver Jowett 0aac23e049 Enable rtlsdr bounce buffers on aarch64, too (thanks to @wiedehopf for the suggestion) 2021-08-11 17:28:47 +08:00
Oliver Jowett f3e498a62a Treat the magic agc setting as just another gain step.
The legacy -10 value is still supported for compatbility with old
configs, but new configs should just select an appropriate gain e.g.
60dB.

rtlsdr default gain continues to be the highest regular gain step (~ 49.6dB)
2021-07-19 17:34:45 +08:00
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 653ad6127a Use a bounce buffer for rtlsdr on ARM to work around zero-copy problems.
On 5.x kernels with the USB mmap problems fixed, the distributed librtlsdr
will use a zero-copy mapping for USB buffers. Unfortunately, there is
something about the nature of the mapping on ARM (at least on Pis) that
makes most access to the data extremely slow. The uc8_nodc converter is
about 35x slower in this case compared to working on a heap-allocated buffer.

Luckily, a plain memcpy() of the buffer is still reasonably fast, so
we can use a bounce buffer and copy the data out of the slow mapping, then
pass the copy to the converter. This mitigates most of the problem,
at the expense of always needing that extra copy (which does somewhat
defeat the purpose of zero-copy!)

Unfortunately, librtlsdr provides no reliable way to control or
detect the use of zero-copy mappings, so we have to assume the problem
is always there (at least on ARM) and pay the cost of an unnecessary
copy when zerocopy is _not_ in use, too.
2020-08-05 19:50:38 +08:00
Oliver Jowett 74607b31ed Factor out FIFO handling; reimplement as a linked list, not a circular buffer.
Update all the SDR implementation to use it.

This was getting pretty ugly with code getting copy&pasted in all the SDR
implementations. Unify it all and give it a simpler API. Linked list works out
much simpler than the circular buffer. Also, simplify copying the overlap region
around by just using a separate buffer (it's only a few hundred bytes long, so
the double copy is not a big deal).
2020-08-05 19:50:38 +08:00
Oliver Jowett 8b21104d66 Factor out sdr thread CPU monitoring 2020-08-05 19:50:38 +08:00
Rosen Penev 0df937e9c6
fix -Wmissing-declaration warnings
This should result in a smaller size.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-06-29 16:42:21 -07:00
Oliver Jowett 47e43778a6 Just use fprintf. 2019-03-07 18:19:23 +00:00
Oliver Jowett 28e7ccca8e If rtlsdr_read_async returns early, the device is probably hosed, give up;
rely on the caller of dump1090 to restart.
2019-03-07 18:15:47 +00:00
Oliver Jowett 2b00c05465 Add --direct option for rtlsdr direct sampling 2018-07-23 20:37:01 +01:00
Oliver Jowett 6986b3847f WIP on new faup1090 output, data aging, refactoring 2017-12-02 17:38:33 +00:00
Oliver Jowett 2142d2edf5 Whitespace changes only: cleaning up trailing whitespace at EOL 2017-06-15 18:17:07 +01:00
Oliver Jowett c404e33198 Drop odd-count bytes and don't try to account for them later.
In cases where we do get an odd-length buffer (_very_ rare!)
it seems to be more about dropped USB data and not librtlsdr giving
us a partial callback; subsequent callbacks will still be aligned
with the I byte first despite the odd count.
2017-04-02 13:22:11 +01:00
Mictronics 630136a1eb Fixed use after free bug. 2017-02-22 15:39:09 +01:00
Mictronics effca83150 Fixed bug that sets auto-gain to manual mode. 2017-02-22 15:38:35 +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