Commit 65c1266a authored by Alessandro Rubini's avatar Alessandro Rubini

servo: make all calculations/corrections at the end

When we only have t1/t2 we can't do all the corrections, as we miss t3/t4.

This moves all the calculations from the first servo entry point
(sync/follow-up) to the second one (delay-response).  Diagnostic
prints are moved at the end as well.

Nothing else is changed by this commit: the code is just moved.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 52df1a37
......@@ -33,16 +33,12 @@ static void format_TimeInternal(char *s, TimeInternal *t)
/*
* Actual body of pp_servo_got_sync: the outer function prints logs
* so we can return in different places.
* Actual body of pp_servo_got_sync.
* Called by slave and uncalib when we have t1 and t2
*/
static int __pp_servo_got_sync(struct pp_instance *ppi)
{
TimeInternal m_to_s_dly;
TimeInternal time_tmp;
struct pp_ofm_fltr *ofm_fltr = &SRV(ppi)->ofm_fltr;
Integer32 adj;
/*
* calc 'master_to_slave_delay', removing the correction field
......@@ -68,6 +64,58 @@ static int __pp_servo_got_sync(struct pp_instance *ppi)
}
SRV(ppi)->m_to_s_dly = m_to_s_dly;
return 1; /* ok */
}
/* Called by slave and uncalib when we have t1 and t2 */
void pp_servo_got_sync(struct pp_instance *ppi)
{
SRV(ppi)->t1_t2_valid = __pp_servo_got_sync(ppi);
if (!SRV(ppi)->t1_t2_valid) {
/* error: message already reported */
return;
}
}
/* called by slave states when delay_resp is received (all t1..t4 are valid) */
void pp_servo_got_resp(struct pp_instance *ppi)
{
TimeInternal s_to_m_dly;
TimeInternal time_tmp;
TimeInternal *mpd = &DSCUR(ppi)->meanPathDelay;
struct pp_ofm_fltr *ofm_fltr = &SRV(ppi)->ofm_fltr;
struct pp_owd_fltr *owd_fltr = &SRV(ppi)->owd_fltr;
Integer32 adj;
int s;
if (!SRV(ppi)->t1_t2_valid)
return;
/*
* calc 'slave_to_master_delay', removing the correction field
* added by transparent clocks in the path.
*/
sub_TimeInternal(&s_to_m_dly, &ppi->t4, &ppi->t3);
sub_TimeInternal(&s_to_m_dly, &s_to_m_dly, &ppi->cField);
if (OPTS(ppi)->max_dly) { /* If max_delay is 0 then it's OFF */
if (s_to_m_dly.seconds) {
pp_diag(ppi, servo, 1, "%s aborted, delay "
"greater than 1 second\n", __func__);
return;
}
if (s_to_m_dly.nanoseconds > OPTS(ppi)->max_dly)
pp_diag(ppi, servo, 1, "%s aborted, delay %d greater "
"than administratively set maximum %d\n",
__func__,
(int)s_to_m_dly.nanoseconds,
(int)OPTS(ppi)->max_dly);
if (s_to_m_dly.nanoseconds > OPTS(ppi)->max_dly)
return;
}
SRV(ppi)->s_to_m_dly = s_to_m_dly;
/* update 'offsetFromMaster', (End to End mode) */
sub_TimeInternal(&DSCUR(ppi)->offsetFromMaster,
......@@ -89,7 +137,7 @@ static int __pp_servo_got_sync(struct pp_instance *ppi)
if (DSCUR(ppi)->offsetFromMaster.seconds) {
pp_diag(ppi, servo, 1, "%s aborted, offset greater "
"than 1 second\n", __func__);
return 0; /* not good */
return; /* not good */
}
if ((DSCUR(ppi)->offsetFromMaster.nanoseconds) >
......@@ -99,7 +147,7 @@ static int __pp_servo_got_sync(struct pp_instance *ppi)
__func__,
(int)DSCUR(ppi)->offsetFromMaster.nanoseconds,
(int)OPTS(ppi)->max_rst);
return 0; /* not good */
return; /* not good */
}
}
......@@ -124,7 +172,7 @@ adjust:
ppi->t_ops->adjust_offset(ppi, -adj);
}
}
return 1; /* ok */
return; /* ok */
}
/* the PI controller */
......@@ -151,67 +199,6 @@ adjust:
else
ppi->t_ops->adjust_offset(ppi, -adj);
}
return 1; /* ok */
}
/* Called by slave and uncalib when we have t1 and t2 */
void pp_servo_got_sync(struct pp_instance *ppi)
{
char s[24];
SRV(ppi)->t1_t2_valid = __pp_servo_got_sync(ppi);
if (!SRV(ppi)->t1_t2_valid) {
/* error: message already reported */
return;
}
/* Ok: print data */
format_TimeInternal(s, &SRV(ppi)->m_to_s_dly);
pp_diag(ppi, servo, 2, "Raw offset from master: %s\n", s);
format_TimeInternal(s, &DSCUR(ppi)->meanPathDelay);
pp_diag(ppi, servo, 2, "One-way delay averaged: %s\n", s);
format_TimeInternal(s, &DSCUR(ppi)->offsetFromMaster);
pp_diag(ppi, servo, 2, "Offset from master: %s\n", s);
pp_diag(ppi, servo, 2, "Observed drift: %9i\n",
(int)SRV(ppi)->obs_drift);
}
/* called by slave states when delay_resp is received (all t1..t4 are valid) */
void pp_servo_got_resp(struct pp_instance *ppi)
{
TimeInternal s_to_m_dly;
TimeInternal *mpd = &DSCUR(ppi)->meanPathDelay;
struct pp_owd_fltr *owd_fltr = &SRV(ppi)->owd_fltr;
int s;
if (!SRV(ppi)->t1_t2_valid)
return;
/*
* calc 'slave_to_master_delay', removing the correction field
* added by transparent clocks in the path.
*/
sub_TimeInternal(&s_to_m_dly, &ppi->t4, &ppi->t3);
sub_TimeInternal(&s_to_m_dly, &s_to_m_dly, &ppi->cField);
if (OPTS(ppi)->max_dly) { /* If max_delay is 0 then it's OFF */
if (s_to_m_dly.seconds) {
pp_diag(ppi, servo, 1, "%s aborted, delay "
"greater than 1 second\n", __func__);
return;
}
if (s_to_m_dly.nanoseconds > OPTS(ppi)->max_dly)
pp_diag(ppi, servo, 1, "%s aborted, delay %d greater "
"than administratively set maximum %d\n",
__func__,
(int)s_to_m_dly.nanoseconds,
(int)OPTS(ppi)->max_dly);
if (s_to_m_dly.nanoseconds > OPTS(ppi)->max_dly)
return;
}
SRV(ppi)->s_to_m_dly = s_to_m_dly;
/* update 'one_way_delay' */
add_TimeInternal(mpd, &SRV(ppi)->m_to_s_dly, &SRV(ppi)->s_to_m_dly);
......@@ -251,4 +238,18 @@ void pp_servo_got_resp(struct pp_instance *ppi)
pp_diag(ppi, servo, 1, "delay filter %d, %d\n",
(int)owd_fltr->y, (int)owd_fltr->s_exp);
/* Ok: print data if asked to, or don't even format_TimeInternal */
if (pp_diag_allow(ppi, servo, 2)) {
char s[24];
format_TimeInternal(s, &SRV(ppi)->m_to_s_dly);
pp_diag(ppi, servo, 2, "Raw offset from master: %s\n", s);
format_TimeInternal(s, &DSCUR(ppi)->meanPathDelay);
pp_diag(ppi, servo, 2, "One-way delay averaged: %s\n", s);
format_TimeInternal(s, &DSCUR(ppi)->offsetFromMaster);
pp_diag(ppi, servo, 2, "Offset from master: %s\n", s);
pp_diag(ppi, servo, 2, "Observed drift: %9i\n",
(int)SRV(ppi)->obs_drift);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment