diff --git a/host/hackrf-tools/src/hackrf_transfer.c b/host/hackrf-tools/src/hackrf_transfer.c index 5d1adbc9..bc52776a 100644 --- a/host/hackrf-tools/src/hackrf_transfer.c +++ b/host/hackrf-tools/src/hackrf_transfer.c @@ -335,7 +335,6 @@ bool signalsource = false; uint32_t amplitude = 0; bool hw_sync = false; -uint32_t hw_sync_enable = 0; bool receive = false; bool receive_wav = false; @@ -397,7 +396,7 @@ void stop_main_loop(void) #ifdef _WIN32 SetEvent(interrupt_handle); #else - kill(0, SIGALRM); + kill(getpid(), SIGALRM); #endif } @@ -639,7 +638,7 @@ static void usage() printf("\t[-b baseband_filter_bw_hz] # Set baseband filter bandwidth in Hz.\n"); printf("\tPossible values: 1.75/2.5/3.5/5/5.5/6/7/8/9/10/12/14/15/20/24/28MHz, default <= 0.75 * sample_rate_hz.\n"); printf("\t[-C ppm] # Set Internal crystal clock error in ppm.\n"); - printf("\t[-H hw_sync_enable] # Synchronise USB transfer using GPIO pins.\n"); + printf("\t[-H hw_sync] # Synchronize RX/TX to external input signal.\n"); } static hackrf_device* device = NULL; @@ -693,15 +692,12 @@ int main(int argc, char** argv) stats_t stats = {0, 0}; static int32_t preload_bytes = 0; - while ((opt = - getopt(argc, - argv, - "H:wr:t:f:i:o:m:a:p:s:Fn:b:l:g:x:c:d:C:RS:Bh?")) != EOF) { + while ((opt = getopt(argc, argv, "Hwr:t:f:i:o:m:a:p:s:Fn:b:l:g:x:c:d:C:RS:Bh?")) != + EOF) { result = HACKRF_SUCCESS; switch (opt) { case 'H': hw_sync = true; - result = parse_u32(optarg, &hw_sync_enable); break; case 'w': receive_wav = true; @@ -1166,10 +1162,10 @@ int main(int argc, char** argv) } } - fprintf(stderr, "call hackrf_set_hw_sync_mode(%d)\n", hw_sync_enable); + fprintf(stderr, "call hackrf_set_hw_sync_mode(%d)\n", hw_sync ? 1 : 0); result = hackrf_set_hw_sync_mode( device, - hw_sync_enable ? HW_SYNC_MODE_ON : HW_SYNC_MODE_OFF); + hw_sync ? HW_SYNC_MODE_ON : HW_SYNC_MODE_OFF); if (result != HACKRF_SUCCESS) { fprintf(stderr, "hackrf_set_hw_sync_mode() failed: %s (%d)\n", @@ -1253,6 +1249,8 @@ int main(int argc, char** argv) result |= hackrf_set_lna_gain(device, lna_gain); result |= hackrf_start_rx(device, rx_callback, NULL); } else { + preload_bytes = hackrf_get_transfer_queue_depth(device) * + hackrf_get_transfer_buffer_size(device); result = hackrf_set_txvga_gain(device, txvga_gain); result |= hackrf_enable_tx_flush(device, 1); result |= hackrf_start_tx(device, tx_callback, NULL); @@ -1283,9 +1281,6 @@ int main(int argc, char** argv) .it_value = {.tv_sec = 1, .tv_usec = 0}}; setitimer(ITIMER_REAL, &interval_timer, NULL); #endif - preload_bytes = hackrf_get_transfer_queue_depth(device) * - hackrf_get_transfer_buffer_size(device); - while ((hackrf_is_streaming(device) == HACKRF_TRUE) && (do_exit == false)) { uint64_t byte_count_now; struct timeval time_now; @@ -1356,8 +1351,7 @@ int main(int argc, char** argv) time_difference = TimevalDiff(&time_now, &time_start); rate = (float) byte_count_now / time_difference; - if (byte_count_now == 0 && hw_sync == true && - hw_sync_enable != 0) { + if ((byte_count_now == 0) && (hw_sync)) { fprintf(stderr, "Waiting for sync...\n"); } else { double full_scale_ratio = (double) stream_power_now / @@ -1395,8 +1389,7 @@ int main(int argc, char** argv) time_start = time_now; - if (byte_count_now == 0 && - (hw_sync == false || hw_sync_enable == 0)) { + if ((byte_count_now == 0) && (!hw_sync)) { exit_code = EXIT_FAILURE; fprintf(stderr, "\nCouldn't transfer any bytes for one second.\n"); diff --git a/host/libhackrf/src/hackrf.h b/host/libhackrf/src/hackrf.h index 68bfd1cd..3f4f010c 100644 --- a/host/libhackrf/src/hackrf.h +++ b/host/libhackrf/src/hackrf.h @@ -154,7 +154,9 @@ typedef struct hackrf_device hackrf_device; /** * USB transfer information passed to RX or TX callback. - * A callback should treat all these fields as read-only except that a TX callback should write to the data buffer. + * A callback should treat all these fields as read-only except that a TX + * callback should write to the data buffer and may write to valid_length to + * indicate that a smaller number of bytes is to be transmitted. */ typedef struct { hackrf_device* device; /**< HackRF USB device for this transfer */