Commit 9919387e authored by Aurelio Colosimo's avatar Aurelio Colosimo

state-slave almost completed

state-slave.c: only missing some servo functions and msg issue
pproto.h: shortened some variable names
parent 683dc443
......@@ -16,7 +16,7 @@
*/
struct pp_runtime_opts {
ClockQuality clock_quality;
TimeInternal inboundLatency, outboundLatency;
TimeInternal inbound_latency, outbound_latency;
Integer32 max_rst; /* Maximum number of nanoseconds to reset */
Integer32 max_dly; /* Maximum number of nanoseconds of delay */
Integer32 ttl;
......@@ -131,11 +131,16 @@ struct pp_instance {
Octet *buf_in; /* FIXME really useful? Probably not*/
TimeInternal sync_receive_time;
UInteger16 recv_sync_sequence_id;
TimeInternal last_sync_correction_field;
TimeInternal last_sync_corr_field;
TimeInternal last_pdelay_req_corr_field;
TimeInternal last_pdelay_resp_corr_field;
TimeInternal pdelay_req_send_time;
TimeInternal pdelay_req_receive_time;
TimeInternal pdelay_resp_send_time;
TimeInternal pdelay_resp_receive_time;
TimeInternal delay_req_send_time;
TimeInternal delay_req_receive_time;
Integer8 log_min_delay_req_interval;
union {
MsgSync sync;
......@@ -208,6 +213,7 @@ extern UInteger8 bmc(struct pp_frgn_master *frgn_master,
/* msg.c */
extern void msg_pack_header(void *buf, struct pp_instance *ppi);
extern void msg_unpack_header(void *buf, struct pp_instance *ppi);
int msg_copy_header(MsgHeader *dest, MsgHeader *src);
extern void msg_pack_sync(void *buf, Timestamp *orig_tstamp,
struct pp_instance *ppi);
extern void msg_unpack_sync(void *buf, MsgSync *sync);
......
......@@ -80,6 +80,11 @@ void msg_pack_header(void *buf, struct pp_instance *ppi)
/* Default value(spec Table 24) */
}
int msg_copy_header(MsgHeader *dest, MsgHeader *src)
{
return pp_memcpy(dest,src,sizeof(MsgHeader));
}
/* Pack Sync message into out buffer of ppi */
void msg_pack_sync(void *buf, Timestamp *orig_tstamp, struct pp_instance *ppi)
......
......@@ -193,9 +193,9 @@ int st_com_slave_handle_sync(unsigned char *buf, int len, TimeInternal *time,
int64_to_TimeInternal(
hdr->correctionfield,
&correction_field);
ppi->last_sync_correction_field.seconds =
ppi->last_sync_corr_field.seconds =
correction_field.seconds;
ppi->last_sync_correction_field.nanoseconds =
ppi->last_sync_corr_field.nanoseconds =
correction_field.nanoseconds;
} else {
msg_unpack_sync(buf, &ppi->msg_tmp.sync);
......@@ -260,7 +260,7 @@ int st_com_slave_handle_followup(unsigned char *buf, int len,
&correction_field);
add_TimeInternal(&correction_field,&correction_field,
&ppi->last_sync_correction_field);
&ppi->last_sync_corr_field);
pp_update_offset(&precise_orig_timestamp,
&ppi->sync_receive_time,
......
......@@ -2,12 +2,17 @@
* FIXME: header
*/
#include <pproto/pproto.h>
#include <dep/dep.h>
#include "state-common-fun.h"
int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
{
int e = 0;
TimeInternal time; /* TODO: handle it, see handle(...) in protocol.c */
TimeInternal req_rec_tstamp;
TimeInternal correction_field;
TimeInternal resp_orig_tstamp;
MsgHeader *hdr = &ppi->msg_tmp_header;
if (ppi->is_new_state) {
pp_init_clock(ppi);
......@@ -51,23 +56,224 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
break;
case PPM_DELAY_REQ:
/* TODO */
e = (plen < PP_DELAY_REQ_LENGTH);
if (!e && ppi->is_from_self) {
/* Get sending timestamp from IP stack
* with So_TIMESTAMP */
ppi->delay_req_send_time.seconds =
time.seconds;
ppi->delay_req_send_time.nanoseconds =
time.nanoseconds;
/* Add latency */
add_TimeInternal(&ppi->delay_req_send_time,
&ppi->delay_req_send_time,
&ppi->rt_opts->outbound_latency);
}
break;
case PPM_DELAY_RESP:
/* TODO */
e = (plen < PP_DELAY_RESP_LENGTH);
if (e)
break;
if (!ppi->rt_opts->e2e_mode)
break;
msg_unpack_delay_resp(pkt, &ppi->msg_tmp.resp);
if ((pp_memcmp(DSPOR(ppi)->portIdentity.clockIdentity,
ppi->msg_tmp.resp.requestingPortIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH) == 0) &&
((ppi->sent_seq_id[PPM_DELAY_REQ] - 1) ==
hdr->sequenceId) &&
(DSPOR(ppi)->portIdentity.portNumber ==
ppi->msg_tmp.resp.requestingPortIdentity.portNumber)
&& ppi->is_from_cur_par) {
to_TimeInternal(&req_rec_tstamp,
&ppi->msg_tmp.resp.receiveTimestamp);
ppi->delay_req_receive_time.seconds =
req_rec_tstamp.seconds;
ppi->delay_req_receive_time.nanoseconds =
req_rec_tstamp.nanoseconds;
int64_to_TimeInternal(
hdr->correctionfield,
&correction_field);
/* TODO servo
updateDelay(&ptpClock->owd_filt,
rtOpts,ptpClock, &correctionField);
*/
ppi->log_min_delay_req_interval =
hdr->logMessageInterval;
} else {
/* FIXME diag
DBGV("HandledelayResp : "
"delayResp doesn't match with the delayReq. \n");
*/
}
break;
case PPM_PDELAY_REQ:
/* TODO */
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;
}
break;
case PPM_PDELAY_RESP:
/* TODO */
if (ppi->rt_opts->e2e_mode)
break;
e = (plen < PP_PDELAY_RESP_LENGTH);
if (e)
break;
if (ppi->is_from_self) {
add_TimeInternal(&time, &time,
&ppi->rt_opts->outbound_latency);
/* TODO
issuePDelayRespFollowUp(time,
&ptpClock->PdelayReqHeader,
rtOpts,ptpClock);
*/
break;
}
msg_unpack_pdelay_resp(pkt,
&ppi->msg_tmp.presp);
if (!((ppi->sent_seq_id[PPM_PDELAY_REQ] ==
hdr->sequenceId)
&& (!pp_memcmp(DSPOR(ppi)->portIdentity.clockIdentity,
ppi->msg_tmp.presp.requestingPortIdentity.
clockIdentity, PP_CLOCK_IDENTITY_LENGTH))
&& (DSPOR(ppi)->portIdentity.portNumber ==
ppi->msg_tmp.presp.
requestingPortIdentity.portNumber))) {
if ((hdr->flagField[0] & 0x02) ==
PP_TWO_STEP_FLAG) {
/* Two Step Clock */
/* Store t4 (Fig 35) */
ppi->pdelay_resp_receive_time.seconds =
time.seconds;
ppi->pdelay_resp_receive_time.nanoseconds =
time.nanoseconds;
/* Store t2 (Fig 35) */
to_TimeInternal(&req_rec_tstamp,
&ppi->msg_tmp.presp.
requestReceiptTimestamp);
ppi->pdelay_req_receive_time.seconds =
req_rec_tstamp.seconds;
ppi->pdelay_req_receive_time.nanoseconds =
req_rec_tstamp.nanoseconds;
int64_to_TimeInternal(hdr->correctionfield,
&correction_field);
ppi->last_pdelay_resp_corr_field.seconds =
correction_field.seconds;
ppi->last_pdelay_resp_corr_field.nanoseconds =
correction_field.nanoseconds;
} else {
/* One step Clock */
/* Store t4 (Fig 35) */
ppi->pdelay_resp_receive_time.seconds =
time.seconds;
ppi->pdelay_resp_receive_time.nanoseconds =
time.nanoseconds;
int64_to_TimeInternal(hdr->correctionfield,
&correction_field);
/* TODO
updatePeerDelay(&ptpClock->owd_filt,rtOpts,
ptpClock,&correctionField,FALSE);
*/
}
} else {
/* FIXME diag
DBGV("HandlePdelayResp : Pdelayresp doesn't "
"match with the PdelayReq. \n");
*/
}
break;
case PPM_PDELAY_RESP_FOLLOW_UP:
/* TODO */
if (ppi->rt_opts->e2e_mode)
break;
e = (plen < PP_PDELAY_RESP_FOLLOW_UP_LENGTH);
if (e)
break;
if (hdr->sequenceId ==
ppi->sent_seq_id[PPM_PDELAY_REQ]) {
msg_unpack_pdelay_resp_followup(
pkt,
&ppi->msg_tmp.prespfollow);
to_TimeInternal(
&resp_orig_tstamp,
&ppi->msg_tmp.prespfollow.
responseOriginTimestamp);
ppi->pdelay_resp_send_time.seconds =
resp_orig_tstamp.seconds;
ppi->pdelay_resp_send_time.nanoseconds =
resp_orig_tstamp.nanoseconds;
int64_to_TimeInternal(
hdr->correctionfield,
&correction_field);
add_TimeInternal(&correction_field, &correction_field,
&ppi->last_pdelay_req_corr_field);
/* TODO servo
updatePeerDelay (&ptpClock->owd_filt,
rtOpts, ptpClock,
&correctionField,TRUE);
*/
}
break;
default:
......
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