2017-01-30 20:15:26 +00:00
|
|
|
// Part of dump1090, a Mode S message decoder for RTLSDR devices.
|
|
|
|
|
//
|
|
|
|
|
// sdr.h: generic SDR infrastructure (header)
|
|
|
|
|
//
|
|
|
|
|
// Copyright (c) 2016-2017 Oliver Jowett <oliver@mutability.co.uk>
|
|
|
|
|
// Copyright (c) 2017 FlightAware LLC
|
|
|
|
|
//
|
2017-06-15 17:16:51 +00:00
|
|
|
// This file is free software: you may copy, redistribute and/or modify it
|
2017-01-30 20:15:26 +00:00
|
|
|
// under the terms of the GNU General Public License as published by the
|
2017-06-15 17:16:51 +00:00
|
|
|
// Free Software Foundation, either version 2 of the License, or (at your
|
|
|
|
|
// option) any later version.
|
2017-01-30 20:15:26 +00:00
|
|
|
//
|
2017-06-15 17:16:51 +00:00
|
|
|
// This file is distributed in the hope that it will be useful, but
|
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2017-01-30 20:15:26 +00:00
|
|
|
// General Public License for more details.
|
|
|
|
|
//
|
2017-06-15 17:16:51 +00:00
|
|
|
// You should have received a copy of the GNU General Public License
|
2017-01-30 20:15:26 +00:00
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
2017-01-27 17:30:40 +00:00
|
|
|
#ifndef SDR_H
|
|
|
|
|
#define SDR_H
|
|
|
|
|
|
|
|
|
|
// Common interface to different SDR inputs.
|
|
|
|
|
|
|
|
|
|
void sdrInitConfig();
|
|
|
|
|
void sdrShowHelp();
|
|
|
|
|
bool sdrHandleOption(int argc, char **argv, int *jptr);
|
|
|
|
|
bool sdrOpen();
|
|
|
|
|
void sdrRun();
|
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-20 17:51:08 +00:00
|
|
|
void sdrStop();
|
2017-01-27 17:30:40 +00:00
|
|
|
void sdrClose();
|
|
|
|
|
|
2021-06-29 12:11:13 +00:00
|
|
|
// Gain control
|
|
|
|
|
int sdrGetGain(); // return current gain step 0..N, or -1 if gain control is not supported
|
|
|
|
|
int sdrGetMaxGain(); // return maximum gain step, or -1 if gain control is not supported
|
|
|
|
|
double sdrGetGainDb(int step); // return gain in dB for the given gain step, or 0.0 if gain control is not supported
|
|
|
|
|
int sdrSetGain(int step); // set gain step; return actual gain step used, or -1 if gain control is not supported
|
|
|
|
|
|
2020-08-05 04:00:50 +00:00
|
|
|
// Call periodically from the SDR read thread to update reader thread CPU stats:
|
|
|
|
|
void sdrMonitor();
|
|
|
|
|
// Retrieve CPU stats and add new CPU time to *addTo
|
|
|
|
|
void sdrUpdateCPUTime(struct timespec *addTo);
|
|
|
|
|
|
2017-01-27 17:30:40 +00:00
|
|
|
#endif
|