Commit 32ade967 authored by Aurelio Colosimo's avatar Aurelio Colosimo

state-common-fun: st_com_handle_pdelay_req implemented

state-passive.c and state-slave.c now use the same st_com_handle_pdelay_req
for PPM_PDELAY_REQ messages handling.
parent 9919387e
......@@ -269,3 +269,38 @@ int st_com_slave_handle_followup(unsigned char *buf, int len,
pp_update_clock(ppi);
return 0;
}
int st_com_handle_pdelay_req(unsigned char *buf, int len,
TimeInternal *time, struct pp_instance *ppi)
{
MsgHeader *hdr = &ppi->msg_tmp_header;
if (len < PP_PDELAY_REQ_LENGTH)
return -1;
if (ppi->rt_opts->e2e_mode)
return 0;
if (ppi->is_from_self) {
/* Get sending timestamp from IP stack
* with So_TIMESTAMP */
ppi->pdelay_req_send_time.seconds =
time->seconds;
ppi->pdelay_req_send_time.nanoseconds =
time->nanoseconds;
/*Add latency*/
add_TimeInternal(&ppi->pdelay_req_send_time,
&ppi->pdelay_req_send_time,
&ppi->rt_opts->outbound_latency);
} else {
msg_copy_header(&ppi->pdelay_req_hdr,hdr);
/* TODO
issuePDelayResp(time, header, rtOpts,
ptpClock);
*/
}
return 0;
}
......@@ -23,3 +23,6 @@ int st_com_slave_handle_sync(unsigned char *buf, int len, TimeInternal *time,
int st_com_slave_handle_followup(unsigned char *buf, int len,
struct pp_instance *ppi);
int st_com_handle_pdelay_req(unsigned char *buf, int len, TimeInternal *time,
struct pp_instance *ppi);
......@@ -8,4 +8,3 @@ int pp_master(struct pp_instance *ppi, unsigned char *newpkt, int plen)
/* TODO */
return 0;
}
......@@ -6,6 +6,9 @@
int pp_passive(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
TimeInternal time; /* TODO: handle it, see handle(...) in protocol.c */
int e = 0;
if (ppi->is_new_state) {
pp_timer_start(1 << DSPOR(ppi)->logMinPdelayReqInterval,
ppi->timers[PP_TIMER_PDELAYREQ_INTERVAL]);
......@@ -18,34 +21,7 @@ int pp_passive(struct pp_instance *ppi, unsigned char *pkt, int plen)
switch (ppi->msg_tmp_header.messageType) {
case PPM_PDELAY_REQ:
#ifdef _FROM_PTPD_2_1_0_
/* TODO "translate" it into ptp-wr structs
* put the code in a function (will be used by SLAVE and
* MASTER state too
*/
if (ppi->is_from_self) {
/*
* Get sending timestamp from IP stack
* with So_TIMESTAMP
*/
ptpClock->pdelay_req_send_time.seconds =
time->seconds;
ptpClock->pdelay_req_send_time.nanoseconds =
time->nanoseconds;
/*Add latency*/
addTime(&ptpClock->pdelay_req_send_time,
&ptpClock->pdelay_req_send_time,
&rtOpts->outboundLatency);
break;
} else {
msgUnpackHeader(ptpClock->msgIbuf,
&ptpClock->PdelayReqHeader);
issuePDelayResp(time, header, rtOpts,
ptpClock);
break;
}
#endif /* _FROM_PTPD_2_1_0_ */
e = st_com_handle_pdelay_req(pkt, plen, &time, ppi);
break;
default:
......@@ -54,7 +30,11 @@ int pp_passive(struct pp_instance *ppi, unsigned char *pkt, int plen)
}
if (e == 0)
st_com_execute_slave(ppi);
else
ppi->next_state = PPS_FAULTY;
state_updated:
/* Leaving this state */
......
......@@ -125,37 +125,7 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
break;
case PPM_PDELAY_REQ:
if (ppi->rt_opts->e2e_mode)
break;
e = (plen < PP_PDELAY_REQ_LENGTH);
if (e)
break;
if (ppi->is_from_self) {
/* Get sending timestamp from IP stack
* with So_TIMESTAMP */
ppi->pdelay_req_send_time.seconds =
time.seconds;
ppi->pdelay_req_send_time.nanoseconds =
time.nanoseconds;
/*Add latency*/
add_TimeInternal(&ppi->pdelay_req_send_time,
&ppi->pdelay_req_send_time,
&ppi->rt_opts->outbound_latency);
break;
} else {
msg_copy_header(&ppi->pdelay_req_hdr,hdr);
/* TODO
issuePDelayResp(time, header, rtOpts,
ptpClock);
*/
break;
}
e = st_com_handle_pdelay_req(pkt, plen, &time, ppi);
break;
case PPM_PDELAY_RESP:
......
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