diff --git a/host/hackrf-tools/src/hackrf_transfer.c b/host/hackrf-tools/src/hackrf_transfer.c index 6894e041..f5b82e14 100644 --- a/host/hackrf-tools/src/hackrf_transfer.c +++ b/host/hackrf-tools/src/hackrf_transfer.c @@ -20,6 +20,7 @@ * Boston, MA 02110-1301, USA. */ + #include #include @@ -332,6 +333,9 @@ uint32_t baseband_filter_bw_hz = 0; bool repeat = false; +bool crystal_correct = false; +uint32_t crystal_correct_ppm ; + int rx_callback(hackrf_transfer* transfer) { ssize_t bytes_to_write; ssize_t bytes_written; @@ -451,6 +455,7 @@ static void usage() { 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 Hz.\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[-C ppm] # Set Internal crystal clock error in ppm.\n"); } static hackrf_device* device = NULL; @@ -494,7 +499,7 @@ int main(int argc, char** argv) { float time_diff; 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:R")) != EOF ) + while( (opt = getopt(argc, argv, "wr:t:f:i:o:m:a:p:s:n:b:l:g:x:c:d:C:R")) != EOF ) { result = HACKRF_SUCCESS; switch( opt ) @@ -609,6 +614,11 @@ int main(int argc, char** argv) { case 'R': repeat = true; break; + + case 'C': + crystal_correct = true; + result = parse_u32(optarg, &crystal_correct_ppm); + break; default: printf("unknown argument '-%c %s'\n", opt, optarg); @@ -816,6 +826,14 @@ int main(int argc, char** argv) { } } + // Change the freq and sample rate to correct the crystal clock error. + if( crystal_correct ) { + + sample_rate_hz = (uint)((double)sample_rate_hz * (1000000 - crystal_correct_ppm)/1000000+0.5); + freq_hz = freq_hz * (1000000 - crystal_correct_ppm)/1000000; + + } + result = hackrf_init(); if( result != HACKRF_SUCCESS ) { printf("hackrf_init() failed: %s (%d)\n", hackrf_error_name(result), result);