From 0c35cff05b061afae12b804fffb37e51bfbc9835 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Sun, 7 Aug 2022 18:01:09 +0100 Subject: [PATCH] In repeat mode, rewind file as many times as needed to fill buffer. Fixes #720. --- host/hackrf-tools/src/hackrf_transfer.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_transfer.c b/host/hackrf-tools/src/hackrf_transfer.c index 7e7e8215..fc0cc9ea 100644 --- a/host/hackrf-tools/src/hackrf_transfer.c +++ b/host/hackrf-tools/src/hackrf_transfer.c @@ -538,9 +538,16 @@ int tx_callback(hackrf_transfer* transfer) return -1; /* not repeat mode, end of file */ } - fprintf(stderr, "Input file end reached. Rewind to beginning.\n"); - rewind(file); - fread(transfer->buffer + bytes_read, 1, bytes_to_read - bytes_read, file); + while (bytes_read < bytes_to_read) { + fprintf(stderr, "Input file end reached. Rewind to beginning.\n"); + rewind(file); + bytes_read += + fread(transfer->buffer + bytes_read, + 1, + bytes_to_read - bytes_read, + file); + } + return 0; }