Add file repeat TX mode [-R].

This commit is contained in:
scateu
2015-07-08 18:44:22 +08:00
parent bfc004b95e
commit 2ca87b942a

View File

@ -330,6 +330,8 @@ size_t bytes_to_xfer = 0;
bool baseband_filter_bw = false; bool baseband_filter_bw = false;
uint32_t baseband_filter_bw_hz = 0; uint32_t baseband_filter_bw_hz = 0;
bool repeat = false;
int rx_callback(hackrf_transfer* transfer) { int rx_callback(hackrf_transfer* transfer) {
size_t bytes_to_write; size_t bytes_to_write;
int i; int i;
@ -385,7 +387,15 @@ int tx_callback(hackrf_transfer* transfer) {
bytes_read = fread(transfer->buffer, 1, bytes_to_read, fd); bytes_read = fread(transfer->buffer, 1, bytes_to_read, fd);
if ((bytes_read != bytes_to_read) if ((bytes_read != bytes_to_read)
|| (limit_num_samples && (bytes_to_xfer == 0))) { || (limit_num_samples && (bytes_to_xfer == 0))) {
return -1; if (repeat) { // added by scateu. repeat mode.
printf("Input file end reached. Rewind to beginning.\n");
rewind(fd);
fread(transfer->buffer + bytes_read, 1, bytes_to_read - bytes_read, fd);
return 0;
} else {
return -1; // not loopback mode, EOF
}
} else { } else {
return 0; return 0;
} }
@ -439,6 +449,7 @@ static void usage() {
u64toa((DEFAULT_SAMPLE_RATE_HZ/FREQ_ONE_MHZ),&ascii_u64_data1)); u64toa((DEFAULT_SAMPLE_RATE_HZ/FREQ_ONE_MHZ),&ascii_u64_data1));
printf("\t[-n num_samples] # Number of samples to transfer (default is unlimited).\n"); printf("\t[-n num_samples] # Number of samples to transfer (default is unlimited).\n");
printf("\t[-c amplitude] # CW signal source mode, amplitude 0-127 (DC value to DAC).\n"); printf("\t[-c amplitude] # CW signal source mode, amplitude 0-127 (DC value to DAC).\n");
printf("\t[-R] # Repeat TX mode (default is off) \n");
printf("\t[-b baseband_filter_bw_hz] # Set baseband filter bandwidth in MHz.\n\tPossible values: 1.75/2.5/3.5/5/5.5/6/7/8/9/10/12/14/15/20/24/28MHz, default < sample_rate_hz.\n" ); printf("\t[-b baseband_filter_bw_hz] # Set baseband filter bandwidth in MHz.\n\tPossible values: 1.75/2.5/3.5/5/5.5/6/7/8/9/10/12/14/15/20/24/28MHz, default < sample_rate_hz.\n" );
} }
@ -481,7 +492,7 @@ int main(int argc, char** argv) {
float time_diff; float time_diff;
unsigned int lna_gain=8, vga_gain=20, txvga_gain=0; unsigned int lna_gain=8, vga_gain=20, txvga_gain=0;
while( (opt = getopt(argc, argv, "wr:t:f:i:o:m:a:p:s:n:b:l:g:x:c:d:")) != EOF ) while( (opt = getopt(argc, argv, "wr:t:f:i:o:m:a:p:s:n:b:l:g:x:c:d:R")) != EOF )
{ {
result = HACKRF_SUCCESS; result = HACKRF_SUCCESS;
switch( opt ) switch( opt )
@ -568,6 +579,10 @@ int main(int argc, char** argv) {
result = parse_u32(optarg, &amplitude); result = parse_u32(optarg, &amplitude);
break; break;
case 'R':
repeat = true;
break;
default: default:
printf("unknown argument '-%c %s'\n", opt, optarg); printf("unknown argument '-%c %s'\n", opt, optarg);
usage(); usage();