I would still like to use PPS for the time reference. My understanding is that disabling GPS disables crystal correction. Is this correct?
It appears from mp_pkt_fwd.c that the crystal correction is performed by:
/* — THREAD 5: CHECK TIME REFERENCE AND CALCULATE XTAL CORRECTION --------- */
void thread_valid(void){
/* GPS reference validation variables */
long gps_ref_age = 0;
bool ref_valid_local = false;
double xtal_err_cpy;
/* variables for XTAL correction averaging */
unsigned init_cpt = 0;
double init_acc = 0.0;
double x;
MSG("INFO: Validation thread activated.\n");
/* correction debug */
// FILE * log_file = NULL;
// time_t now_time;
// char log_name[64];
/* initialization */
// time(&now_time);
// strftime(log_name,sizeof log_name,"xtal_err_%Y%m%dT%H%M%SZ.csv",localtime(&now_time));
// log_file = fopen(log_name, "w");
// setbuf(log_file, NULL);
// fprintf(log_file,"\"xtal_correct\",\"XERR_INIT_AVG %u XERR_FILT_COEF %u\"\n", XERR_INIT_AVG, XERR_FILT_COEF); // DEBUG
/* main loop task */
while (!exit_sig && !quit_sig) {
wait_ms(1000);
/* calculate when the time reference was last updated */
pthread_mutex_lock(&mx_timeref);
gps_ref_age = (long)difftime(time(NULL), time_reference_gps.systime);
if ((gps_ref_age >= 0) && (gps_ref_age <= GPS_REF_MAX_AGE)) {
/* time ref is ok, validate and */
gps_ref_valid = true;
ref_valid_local = true;
xtal_err_cpy = time_reference_gps.xtal_err;
} else {
/* time ref is too old, invalidate */
gps_ref_valid = false;
ref_valid_local = false;
}
pthread_mutex_unlock(&mx_timeref);
/* manage XTAL correction */
if (ref_valid_local == false) {
/* couldn't sync, or sync too old -> invalidate XTAL correction */
pthread_mutex_lock(&mx_xcorr);
xtal_correct_ok = false;
xtal_correct = 1.0;
pthread_mutex_unlock(&mx_xcorr);
init_cpt = 0;
init_acc = 0.0;
} else {
if (init_cpt < XERR_INIT_AVG) {
/* initial accumulation */
init_acc += xtal_err_cpy;
++init_cpt;
} else if (init_cpt == XERR_INIT_AVG) {
/* initial average calculation */
pthread_mutex_lock(&mx_xcorr);
xtal_correct = (double)(XERR_INIT_AVG) / init_acc;
xtal_correct_ok = true;
pthread_mutex_unlock(&mx_xcorr);
++init_cpt;
// fprintf(log_file,"%.18lf,\"average\"\n", xtal_correct); // DEBUG
} else {
/* tracking with low-pass filter */
x = 1 / xtal_err_cpy;
pthread_mutex_lock(&mx_xcorr);
xtal_correct = xtal_correct - xtal_correct/XERR_FILT_COEF + x/XERR_FILT_COEF;
pthread_mutex_unlock(&mx_xcorr);
// fprintf(log_file,"%.18lf,\"track\"\n", xtal_correct); // DEBUG
}
}
MSG_DEBUG(DEBUG_LOG,"Time ref: %s, XTAL correct: %s (%.15lf)\n", ref_valid_local?"valid":"invalid", xtal_correct_ok?"valid":"invalid", xtal_correct); // DEBUG
}
MSG("INFO: End of validation thread\n");
}
This thread is only spawned if gps_active == true which requires fake_gps:false in gateway_conf.
/* -------------------------------------------------------------------------- */
/* --- MAIN FUNCTION -------------------------------------------------------- */
/* spawn thread to manage GPS */
if (gps_active == true) {
i = pthread_create( &thrid_gps, NULL, (void * (*)(void *))thread_gps, NULL);
if (i != 0) {
MSG("ERROR: [main] impossible to create GPS thread\n");
exit(EXIT_FAILURE);
}
i = pthread_create( &thrid_valid, NULL, (void * (*)(void *))thread_valid, NULL);
if (i != 0) {
MSG("ERROR: [main] impossible to create validation thread\n");
exit(EXIT_FAILURE);
}
}