Commit 3c5a85c9 authored by Aurelio Colosimo's avatar Aurelio Colosimo

state-slave first partial implementation

minor fixes and comments updated elsewhere
parent caee5bbe
...@@ -132,6 +132,10 @@ struct pp_instance { ...@@ -132,6 +132,10 @@ struct pp_instance {
TimeInternal sync_receive_time; TimeInternal sync_receive_time;
UInteger16 recv_sync_sequence_id; UInteger16 recv_sync_sequence_id;
TimeInternal last_sync_correction_field; TimeInternal last_sync_correction_field;
TimeInternal pdelay_req_send_time;
TimeInternal pdelay_req_receive_time;
TimeInternal pdelay_resp_send_time;
TimeInternal pdelay_resp_receive_time;
union { union {
MsgSync sync; MsgSync sync;
...@@ -188,6 +192,7 @@ extern int pp_timer_stop(struct pp_timer *tm); ...@@ -188,6 +192,7 @@ extern int pp_timer_stop(struct pp_timer *tm);
extern int pp_timer_expired(struct pp_timer *tm); /* returns 1 when expired */ extern int pp_timer_expired(struct pp_timer *tm); /* returns 1 when expired */
/* Servo */ /* Servo */
extern void pp_init_clock(struct pp_instance *ppi);
extern void pp_update_offset(TimeInternal *send_time, TimeInternal *recv_time, extern void pp_update_offset(TimeInternal *send_time, TimeInternal *recv_time,
TimeInternal *correctionField, struct pp_instance *ppi); TimeInternal *correctionField, struct pp_instance *ppi);
/* FIXME: offset_from_master_filter: put it in ppi */ /* FIXME: offset_from_master_filter: put it in ppi */
......
...@@ -4,14 +4,20 @@ ...@@ -4,14 +4,20 @@
#include <pproto/pproto.h> #include <pproto/pproto.h>
extern void pp_update_offset(TimeInternal *send_time, TimeInternal *recv_time,
void pp_init_clock(struct pp_instance *ppi)
{
/* TODO */
}
void pp_update_offset(TimeInternal *send_time, TimeInternal *recv_time,
TimeInternal *correctionField, struct pp_instance *ppi) TimeInternal *correctionField, struct pp_instance *ppi)
/* FIXME: offset_from_master_filter: put it in ppi */ /* FIXME: offset_from_master_filter: put it in ppi */
{ {
/* TODO */ /* TODO */
} }
extern void pp_update_clock(struct pp_instance *ppi) void pp_update_clock(struct pp_instance *ppi)
{ {
/* TODO */ /* TODO */
} }
......
...@@ -19,4 +19,7 @@ int st_com_slave_handle_announce(unsigned char *buf, int len, ...@@ -19,4 +19,7 @@ int st_com_slave_handle_announce(unsigned char *buf, int len,
struct pp_instance *ppi); struct pp_instance *ppi);
int st_com_slave_handle_sync(unsigned char *buf, int len, TimeInternal *time, int st_com_slave_handle_sync(unsigned char *buf, int len, TimeInternal *time,
struct pp_instance *ppi); struct pp_instance *ppi);
\ No newline at end of file
int st_com_slave_handle_followup(unsigned char *buf, int len,
struct pp_instance *ppi);
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include <pproto/pproto.h> #include <pproto/pproto.h>
#include "state-common-fun.h" #include "state-common-fun.h"
int pp_listening(struct pp_instance *ppi, unsigned char *pkt, int plen) int pp_listening(struct pp_instance *ppi, unsigned char *pkt, int plen)
{ {
if (ppi->is_new_state) { if (ppi->is_new_state) {
......
...@@ -19,7 +19,10 @@ int pp_passive(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -19,7 +19,10 @@ int pp_passive(struct pp_instance *ppi, unsigned char *pkt, int plen)
switch (ppi->msg_tmp_header.messageType) { switch (ppi->msg_tmp_header.messageType) {
case PPM_PDELAY_REQ: case PPM_PDELAY_REQ:
#ifdef _FROM_PTPD_2_1_0_ #ifdef _FROM_PTPD_2_1_0_
/* TODO "translate" it into ptp-wr structs*/ /* 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) { if (ppi->is_from_self) {
/* /*
* Get sending timestamp from IP stack * Get sending timestamp from IP stack
......
...@@ -2,10 +2,100 @@ ...@@ -2,10 +2,100 @@
* FIXME: header * FIXME: header
*/ */
#include <pproto/pproto.h> #include <pproto/pproto.h>
#include "state-common-fun.h"
int pp_slave(struct pp_instance *ppi, unsigned char *_newpkt, int plen) int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
{ {
/* TODO */ int e = 0;
TimeInternal time; /* TODO: handle it, see handle(...) in protocol.c */
if (ppi->is_new_state) {
pp_init_clock(ppi);
ppi->waiting_for_follow = FALSE;
ppi->pdelay_req_send_time.seconds = 0;
ppi->pdelay_req_send_time.nanoseconds = 0;
ppi->pdelay_req_receive_time.seconds = 0;
ppi->pdelay_req_receive_time.nanoseconds = 0;
ppi->pdelay_resp_send_time.seconds = 0;
ppi->pdelay_resp_send_time.nanoseconds = 0;
ppi->pdelay_resp_receive_time.seconds = 0;
ppi->pdelay_resp_receive_time.nanoseconds = 0;
st_com_restart_annrec_timer(ppi);
if (ppi->rt_opts->e2e_mode)
pp_timer_start(1 << DSPOR(ppi)->logMinDelayReqInterval,
ppi->timers[PP_TIMER_DELAYREQ_INTERVAL]);
else
pp_timer_start(1 << DSPOR(ppi)->logMinPdelayReqInterval,
ppi->timers[PP_TIMER_PDELAYREQ_INTERVAL]);
}
if (st_com_check_record_update(ppi))
goto state_updated;
switch (ppi->msg_tmp_header.messageType) {
case PPM_ANNOUNCE:
e = st_com_slave_handle_announce(pkt, plen, ppi);
break;
case PPM_SYNC:
e = st_com_slave_handle_sync(pkt, plen, &time, ppi);
break;
case PPM_FOLLOW_UP:
e = st_com_slave_handle_followup(pkt, plen, ppi);
break;
case PPM_DELAY_REQ:
/* TODO */
break;
case PPM_DELAY_RESP:
/* TODO */
break;
case PPM_PDELAY_REQ:
/* TODO */
break;
case PPM_PDELAY_RESP:
/* TODO */
break;
case PPM_PDELAY_RESP_FOLLOW_UP:
/* TODO */
break;
default:
/* disreguard, nothing to do */
break;
}
if (e == 0)
st_com_execute_slave(ppi);
else
ppi->next_state = PPS_FAULTY;
state_updated:
/* Leaving this state */
if (ppi->next_state != ppi->state) {
pp_timer_stop(ppi->timers[PP_TIMER_ANNOUNCE_RECEIPT]);
if (ppi->rt_opts->e2e_mode)
pp_timer_stop(ppi->timers[PP_TIMER_DELAYREQ_INTERVAL]);
else
pp_timer_stop(ppi->timers[PP_TIMER_PDELAYREQ_INTERVAL]);
pp_init_clock(ppi);
}
ppi->next_delay = PP_DEFAULT_NEXT_DELAY_MS;
return 0; return 0;
} }
...@@ -20,7 +20,7 @@ int pp_uncalibrated(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -20,7 +20,7 @@ int pp_uncalibrated(struct pp_instance *ppi, unsigned char *pkt, int plen)
break; break;
case PPM_FOLLOW_UP: case PPM_FOLLOW_UP:
e = st_com_slave_handle_followup(pkt, plen); e = st_com_slave_handle_followup(pkt, plen, ppi);
break; break;
default: 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