Merge uhwsin PPM correction changes
This commit is contained in:
@ -20,6 +20,7 @@
|
|||||||
* Boston, MA 02110-1301, USA.
|
* Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <hackrf.h>
|
#include <hackrf.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -332,6 +333,9 @@ uint32_t baseband_filter_bw_hz = 0;
|
|||||||
|
|
||||||
bool repeat = false;
|
bool repeat = false;
|
||||||
|
|
||||||
|
bool crystal_correct = false;
|
||||||
|
uint32_t crystal_correct_ppm ;
|
||||||
|
|
||||||
int rx_callback(hackrf_transfer* transfer) {
|
int rx_callback(hackrf_transfer* transfer) {
|
||||||
ssize_t bytes_to_write;
|
ssize_t bytes_to_write;
|
||||||
ssize_t bytes_written;
|
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[-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[-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[-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;
|
static hackrf_device* device = NULL;
|
||||||
@ -494,7 +499,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: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;
|
result = HACKRF_SUCCESS;
|
||||||
switch( opt )
|
switch( opt )
|
||||||
@ -610,6 +615,11 @@ int main(int argc, char** argv) {
|
|||||||
repeat = true;
|
repeat = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'C':
|
||||||
|
crystal_correct = true;
|
||||||
|
result = parse_u32(optarg, &crystal_correct_ppm);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printf("unknown argument '-%c %s'\n", opt, optarg);
|
printf("unknown argument '-%c %s'\n", opt, optarg);
|
||||||
usage();
|
usage();
|
||||||
@ -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();
|
result = hackrf_init();
|
||||||
if( result != HACKRF_SUCCESS ) {
|
if( result != HACKRF_SUCCESS ) {
|
||||||
printf("hackrf_init() failed: %s (%d)\n", hackrf_error_name(result), result);
|
printf("hackrf_init() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||||
|
Reference in New Issue
Block a user