662 Commits

Author SHA1 Message Date
Martin Ling
5881b3b6a1 Add defines for TX and RX endpoint addresses. 2022-08-23 12:24:00 +01:00
Martin Ling
9b6a0259a7 Remove message when rewinding input file.
For small input files this may be printed a very large number of times.
2022-08-23 09:30:04 +01:00
Martin Ling
0c35cff05b In repeat mode, rewind file as many times as needed to fill buffer.
Fixes #720.
2022-08-23 09:30:04 +01:00
Martin Ling
06a0c2b189 One more early return to simplify TX callback. 2022-08-23 09:30:02 +01:00
Martin Ling
85a86b8baa Use more early returns to further simplify callbacks. 2022-08-23 09:29:13 +01:00
Martin Ling
bcaebc00c3 Use some early returns to reduce deeply indented callbacks. 2022-08-23 09:26:00 +01:00
Martin Ling
344af5094b Merge pull request #1131 from martinling/hackrf-transfer-validation
Additional argument validation for hackrf_transfer
2022-08-23 08:57:17 +01:00
Michael Ossmann
c703a72ac0 add parentheses to avoid compiler warning
avoids a warning from -Wparentheses
2022-08-23 08:44:29 +01:00
Michael Ossmann
04cb3a4084 Merge pull request #1133 from martinling/hackrf-transfer-timing
Overhaul timing in hackrf_transfer
2022-08-22 18:37:34 -04:00
Martin Ling
a09e9a20ed Overhaul timing in hackrf_transfer.
Rather than using sleep() for 1s at a time, set up an interval timer
that will fire once per second, and wait in the main loop for either
this or some other event.

On POSIX, the timing is set up with setitimer(), which generates a
SIGALRM signal each time the timer fires. The main loop runs pause() to
wait for any signal.

On Windows, the timing is set up using CreateWaitableTimer, which
provides an event handle that is set each time the timer fires. The main
loop runs WaitForMultipleObjects() to wait on this and an interrupt
event.

The TX and RX callbacks can now stop the main loop immediately when they
stop streaming. This fixes #1019.
2022-08-17 13:05:03 +01:00
Martin Ling
eeaaaf3b9b Make use of Win32 functions conditional on _WIN32, not _MSC_VER.
Using _MSC_VER here means that the choice of signal() versus
SetConsoleCtrlHandler depends on the compiler being used, rather
than the OS being targeted. When built with MinGW rather than MSVC,
this happens to work because MinGW's signal emulation is used, but
that emulation is quite limited.

Instead, be consistent and use the Win32 API when building for that
platform, regardless of compiler.

Note that if building for Cygwin, _WIN32 is not defined and POSIX
APIs are used.
2022-08-17 12:54:22 +01:00
Martin Ling
e88a0387cb Extend force option to frequency ranges outside 1MHz-6GHz. 2022-08-15 21:47:49 +01:00
Martin Ling
2e1f55c2d5 Add hackrf_transfer -F option to force unsupported sample rates. 2022-08-15 21:47:49 +01:00
Martin Ling
8c12fa6007 Validate sample rates passed to hackrf_transfer. 2022-08-15 21:47:42 +01:00
Martin Ling
2fe3185f9d Use an array of buffers for u64->ASCII conversions. 2022-08-15 21:46:36 +01:00
Martin Ling
ba148ee047 Add a simpler way to check CLKIN status. 2022-08-05 09:37:38 +01:00
Martin Ling
01e0702013 Print hackrf_sweep usage with a single fprintf call. 2022-08-03 23:46:46 +01:00
Martin Ling
e8e6784881 Add spacing lines between declarations in hackrf.h. 2022-08-03 23:46:46 +01:00
Martin Ling
c0d13de598 Add braces to all control statements without them. 2022-08-03 23:46:46 +01:00
Martin Ling
c3fdf402d7 Reformat all code to new clang-format standard. 2022-08-03 23:46:44 +01:00
Martin Ling
ebb9e43fde Move some trailing comments on long lines. 2022-08-03 23:42:55 +01:00
Martin Ling
8b157cfdbc Split up two groups of defines. 2022-08-03 23:28:23 +01:00
Martin Ling
414b4a98da hackrf_transfer: Split a long line in usage(). 2022-08-03 23:03:15 +01:00
Martin Ling
7f5ae870ec hackrf_transfer: Clean up WAV headers. 2022-08-03 23:03:15 +01:00
Michael Ossmann
e4af1a6808 Merge pull request #1116 from gitcolt/amplitude-report
Fix #902 - Report transmit amplitude
2022-08-02 20:22:47 -04:00
colt
b5057b87e8 Report an amplitude of value -INFINITY as is instead of showing it as
-0.0 dBfs
2022-08-02 18:44:28 -05:00
colt
b47a808eaa Do dB ratio check BEFORE it's used 2022-07-11 13:25:14 -05:00
colt
151b431c64 Fix #902 - Report transmit amplitude 2022-07-06 22:34:26 -05:00
Martin Ling
0724bd36eb Lock the whole code block that touches active transfer count.
I believe this was safe before, because this code is only called from
the transfer thread, and the condition being protected is just whether
the count is zero, not the actual value of the count.

However, this isn't performance critical and it's a lot easier to
reason about the code if we just hold the lock for this whole section.
2022-07-04 18:00:07 +01:00
Martin Ling
743b2c76e2 Replace per-transfer flags with a count of active transfers.
This simplifies the code required to wait for cancellations to complete.
The condition variable now reflects whether `active_transfers == 0`, and
the associated lock must be held to decrement that count to zero.
2022-06-15 00:48:47 +01:00
Michael Ossmann
34cbbe7330 Merge pull request #1070 from martinling/cleanup-stop
Remove unnecessary delays on stop, and duplicated stop commands on close.
2022-06-14 10:47:45 -04:00
Michael Ossmann
a41c8078a0 Merge pull request #1069 from martinling/error-handling
Overhaul handling of transfer errors and use of streaming flag.
2022-06-14 10:42:19 -04:00
Martin Ling
7d93f40f6f Merge pull request #1080 from metayan/fix-longprint
Avoid warnings by using PRIu64
2022-04-04 12:11:26 +01:00
Yan
19a9074039 Avoid warnings by using PRIu64 2022-03-21 13:53:40 +00:00
Martin Ling
f046ed24a3 Remove duplicate stop command in hackrf_close(). 2022-03-18 10:59:34 +00:00
Martin Ling
b109a31fd3 Merge hackrf_stop_tx_cmd and hackrf_start_tx_cmd.
These both do the same thing: set transceiver mode to OFF.
2022-03-18 10:56:58 +00:00
Martin Ling
958c742189 Remove delays from hackrf_stop_rx_cmd and hackrf_stop_tx_cmd.
These were added in #805, as a workaround to prevent their parent
functions from returning before transfer cancellations had completed.
This has since been fixed properly in #1029.
2022-03-18 10:42:40 +00:00
Martin Ling
503cd3316c Remove request_exit() function.
This just set the do_exit flag, and was now only called in one place.
2022-03-18 02:20:34 +00:00
Martin Ling
c4789df44c Set streaming flag in prepare_transfers().
This simplifies prepare_setup_transfers(), which was just setting
the flag if prepare_transfers() returned success, and passing on
its return value.
2022-03-18 02:20:34 +00:00
Martin Ling
5afd31e21c Set streaming flag in prepare_setup_transfers().
Avoids conditionally duplicating this across three other places.
2022-03-18 02:20:34 +00:00
Martin Ling
960d8015a4 Clear streaming flag in cancel_transfers().
Moving this into cancel_transfers() avoids duplicating it in the two
stop functions.
2022-03-18 02:20:34 +00:00
Martin Ling
c74c742391 Simplify hackrf_libusb_transfer_callback.
There are now only two possible outcomes to this function: either we
successfully resubmitted a transfer, or the transfer is finished and we
end up calling transfer_finished().

So we can go ahead and simplify it accordingly.
2022-03-18 02:20:34 +00:00
Martin Ling
54e00de167 Clear streaming flag in transfer_finished().
Since we always do these together, move it into the function.
2022-03-18 02:20:34 +00:00
Martin Ling
6bd9cb0553 Clear streaming flag if a transfer was cancelled.
If a transfer was cancelled, we are on our way to shutdown.

If hackrf_stop_tx() or hackrf_stop_rx() were called, they will already
have cleared this flag, but it is not cleared in hackrf_close(), and
for consistency with other paths it makes sense to clear it here.
2022-03-18 02:20:34 +00:00
Martin Ling
125bf9f7bb Don't call callback or submit new transfers once streaming stops.
This stops the RX callback from being called again with further data
once it has returned nonzero, or after a transfer had an error status.
2022-03-18 02:20:34 +00:00
Martin Ling
6720e56fc0 Clear streaming flag if we didn't resubmit a transfer.
If result < 0 here, libusb_submit_transfer returned an error, so we
need to shut down.

If !resubmit, then cancel_transfers() was already called by one of the
stop or close functions, so streaming is already false.
2022-03-18 02:20:34 +00:00
Martin Ling
9e1cb5c003 Don't exit transfer thread if an error occurs.
In the case of a libusb error, we still need the transfer thread
running, in order to handle outstanding cancellations and to signal the
condition variable when that is done.
2022-03-18 01:57:40 +00:00
Mathieu Peyréga
a8a6618728 fix regression in 4c9fcf86651232c2104b57510a0ac86cf86123e4 2022-03-17 21:06:21 +01:00
Yan
790de7f47b Cleaner fast exit
Interrupt the event handling thread instead of waiting for timeout.
2022-03-16 11:13:00 +00:00
Yan
7ff92b3b05 Ensure fast exit
transfer_threadproc has a timeout of half a second, so
when kill_transfer_thread tries to pthread_join, it often
has to wait until the timeout kicks in.

With this fix, we ensure that a final request is made after
request_exit has been called, so that transfer_threadproc can exit its
loop in a fast and clean manner.
2022-03-15 12:43:45 +00:00