Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
PPSi
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
50
Issues
50
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
PPSi
Commits
56037781
Commit
56037781
authored
Dec 27, 2011
by
Aurelio Colosimo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new src state-common-fun.[ch], containing common stuff for many states
parent
6a689c88
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
151 additions
and
50 deletions
+151
-50
Makefile
proto-standard/Makefile
+1
-0
state-common-fun.c
proto-standard/state-common-fun.c
+127
-0
state-common-fun.h
proto-standard/state-common-fun.h
+16
-0
state-listening.c
proto-standard/state-listening.c
+7
-50
No files found.
proto-standard/Makefile
View file @
56037781
...
@@ -17,6 +17,7 @@ OBJ-libstd := $D/state-table-default.o \
...
@@ -17,6 +17,7 @@ OBJ-libstd := $D/state-table-default.o \
$D
/state-passive.o
\
$D
/state-passive.o
\
$D
/state-uncalibrated.o
\
$D
/state-uncalibrated.o
\
$D
/state-slave.o
\
$D
/state-slave.o
\
$D
/state-common-fun.o
\
$D
/bmc.o
\
$D
/bmc.o
\
$D
/msg.o
\
$D
/msg.o
\
$D
/open-close.o
$D
/open-close.o
...
...
proto-standard/state-common-fun.c
0 → 100644
View file @
56037781
/*
* FIXME: header
*/
#include <pproto/pproto.h>
#include "state-common-fun.h"
void
st_com_execute_slave
(
struct
pp_instance
*
ppi
)
{
if
(
pp_timer_expired
(
ppi
->
timers
[
PP_TIMER_ANNOUNCE_RECEIPT
]))
{
/* FIXME diag
* DBGV("event ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES\n");
*/
ppi
->
number_foreign_records
=
0
;
ppi
->
foreign_record_i
=
0
;
if
(
!
DSDEF
(
ppi
)
->
slaveOnly
&&
DSDEF
(
ppi
)
->
clockQuality
.
clockClass
!=
255
)
{
m1
(
ppi
);
ppi
->
next_state
=
PPS_MASTER
;
}
else
{
st_com_restart_annrec_timer
(
ppi
);
}
}
if
(
ppi
->
rt_opts
->
e2e_mode
)
{
if
(
pp_timer_expired
(
ppi
->
timers
[
PP_TIMER_DELAYREQ_INTERVAL
]))
{
/* FIXME diag
* DBGV("event DELAYREQ_INTERVAL_TIMEOUT_EXPIRES\n");
*/
/* TODO issueDelayReq(rtOpts,ptpClock); */
}
}
else
{
if
(
pp_timer_expired
(
ppi
->
timers
[
PP_TIMER_PDELAYREQ_INTERVAL
]))
{
/* FIXME diag
DBGV("event PDELAYREQ_INTERVAL_TIMEOUT_EXPIRES\n");
*/
/* TODO issuePDelayReq(rtOpts,ptpClock); */
}
}
}
void
st_com_restart_annrec_timer
(
struct
pp_instance
*
ppi
)
{
/* 0 <= logAnnounceInterval <= 4, see pag. 237 of spec */
/* FIXME: if (logAnnounceInterval < 0), error? Or handle a right
* shift?*/
pp_timer_start
((
DSPOR
(
ppi
)
->
announceReceiptTimeout
)
<<
DSPOR
(
ppi
)
->
logAnnounceInterval
,
ppi
->
timers
[
PP_TIMER_ANNOUNCE_RECEIPT
]);
}
int
st_com_check_record_update
(
struct
pp_instance
*
ppi
)
{
if
(
ppi
->
record_update
)
{
/* FIXME diag DBGV("event STATE_DECISION_EVENT\n"); */
ppi
->
record_update
=
FALSE
;
ppi
->
next_state
=
bmc
(
ppi
->
frgn_master
,
ppi
->
rt_opts
,
ppi
);
if
(
ppi
->
next_state
!=
ppi
->
state
)
return
1
;
}
return
0
;
}
void
st_com_add_foreign
(
unsigned
char
*
buf
,
MsgHeader
*
header
,
struct
pp_instance
*
ppi
)
{
/*TODO "translate" it into ptp-wr structs*/
#ifdef _FROM_PTPD_2_1_0_
int
i
,
j
;
Boolean
found
=
FALSE
;
j
=
ptpClock
->
foreign_record_best
;
/*Check if Foreign master is already known*/
for
(
i
=
0
;
i
<
ptpClock
->
number_foreign_records
;
i
++
)
{
if
(
!
memcmp
(
header
->
sourcePortIdentity
.
clockIdentity
,
ptpClock
->
foreign
[
j
].
foreignMasterPortIdentity
.
clockIdentity
,
CLOCK_IDENTITY_LENGTH
)
&&
(
header
->
sourcePortIdentity
.
portNumber
==
ptpClock
->
foreign
[
j
].
foreignMasterPortIdentity
.
portNumber
))
{
/*Foreign Master is already in Foreignmaster data set*/
ptpClock
->
foreign
[
j
].
foreignMasterAnnounceMessages
++
;
found
=
TRUE
;
DBGV
(
"addForeign : AnnounceMessage incremented
\n
"
);
msgUnpackHeader
(
buf
,
&
ptpClock
->
foreign
[
j
].
header
);
msgUnpackAnnounce
(
buf
,
&
ptpClock
->
foreign
[
j
].
announce
);
break
;
}
j
=
(
j
+
1
)
%
ptpClock
->
number_foreign_records
;
}
/*New Foreign Master*/
if
(
!
found
)
{
if
(
ptpClock
->
number_foreign_records
<
ptpClock
->
max_foreign_records
)
{
ptpClock
->
number_foreign_records
++
;
}
j
=
ptpClock
->
foreign_record_i
;
/*Copy new foreign master data set from Announce message*/
memcpy
(
ptpClock
->
foreign
[
j
].
foreignMasterPortIdentity
.
clockIdentity
,
header
->
sourcePortIdentity
.
clockIdentity
,
CLOCK_IDENTITY_LENGTH
);
ptpClock
->
foreign
[
j
].
foreignMasterPortIdentity
.
portNumber
=
header
->
sourcePortIdentity
.
portNumber
;
ptpClock
->
foreign
[
j
].
foreignMasterAnnounceMessages
=
0
;
/*
* header and announce field of each Foreign Master are
* usefull to run Best Master Clock Algorithm
*/
msgUnpackHeader
(
buf
,
&
ptpClock
->
foreign
[
j
].
header
);
msgUnpackAnnounce
(
buf
,
&
ptpClock
->
foreign
[
j
].
announce
);
DBGV
(
"New foreign Master added
\n
"
);
ptpClock
->
foreign_record_i
=
(
ptpClock
->
foreign_record_i
+
1
)
%
ptpClock
->
max_foreign_records
;
}
#endif
/* _FROM_PTPD_2_1_0_ */
}
proto-standard/state-common-fun.h
0 → 100644
View file @
56037781
/*
* FIXME: header
*/
#include <pproto/pproto.h>
/* Contains all functions common to more than one state */
void
st_com_execute_slave
(
struct
pp_instance
*
ppi
);
void
st_com_restart_annrec_timer
(
struct
pp_instance
*
ppi
);
int
st_com_check_record_update
(
struct
pp_instance
*
ppi
);
void
st_com_add_foreign
(
unsigned
char
*
buf
,
MsgHeader
*
header
,
struct
pp_instance
*
ppi
);
proto-standard/state-listening.c
View file @
56037781
...
@@ -2,57 +2,18 @@
...
@@ -2,57 +2,18 @@
* FIXME: header
* FIXME: header
*/
*/
#include <pproto/pproto.h>
#include <pproto/pproto.h>
#include "state-common-fun.h"
static
void
restart_annrec_timer
(
struct
pp_instance
*
ppi
)
{
/* 0 <= logAnnounceInterval <= 4, see pag. 237 of spec */
/* FIXME: if (logAnnounceInterval < 0), error? Or handle a right
* shift?*/
pp_timer_start
((
DSPOR
(
ppi
)
->
announceReceiptTimeout
)
<<
DSPOR
(
ppi
)
->
logAnnounceInterval
,
ppi
->
timers
[
PP_TIMER_ANNOUNCE_RECEIPT
]);
}
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
)
{
restart_annrec_timer
(
ppi
);
st_com_
restart_annrec_timer
(
ppi
);
}
}
if
(
pp_timer_expired
(
ppi
->
timers
[
PP_TIMER_ANNOUNCE_RECEIPT
]))
{
if
(
st_com_check_record_update
(
ppi
))
/* FIXME diag
goto
state_updated
;
* DBGV("event ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES\n");
*/
ppi
->
number_foreign_records
=
0
;
ppi
->
foreign_record_i
=
0
;
if
(
!
DSDEF
(
ppi
)
->
slaveOnly
&&
DSDEF
(
ppi
)
->
clockQuality
.
clockClass
!=
255
)
{
m1
(
ppi
);
ppi
->
next_state
=
PPS_MASTER
;
}
else
{
restart_annrec_timer
(
ppi
);
}
}
if
(
ppi
->
rt_opts
->
e2e_mode
)
{
if
(
pp_timer_expired
(
ppi
->
timers
[
PP_TIMER_DELAYREQ_INTERVAL
]))
{
/* FIXME diag
* DBGV("event DELAYREQ_INTERVAL_TIMEOUT_EXPIRES\n");
*/
/* TODO issueDelayReq(rtOpts,ptpClock); */
}
}
else
{
if
(
pp_timer_expired
(
ppi
->
timers
[
PP_TIMER_PDELAYREQ_INTERVAL
]))
{
/* FIXME diag
DBGV("event PDELAYREQ_INTERVAL_TIMEOUT_EXPIRES\n");
*/
/* TODO issuePDelayReq(rtOpts,ptpClock); */
}
}
if
(
ppi
->
msg_tmp_header
.
messageType
==
PPM_ANNOUNCE
)
{
if
(
ppi
->
msg_tmp_header
.
messageType
==
PPM_ANNOUNCE
)
{
/* TODO check isFromSelf?
/* TODO check isFromSelf?
...
@@ -66,18 +27,14 @@ int pp_listening(struct pp_instance *ppi, unsigned char *pkt, int plen)
...
@@ -66,18 +27,14 @@ int pp_listening(struct pp_instance *ppi, unsigned char *pkt, int plen)
* DBGV("Announce message from another foreign master");
* DBGV("Announce message from another foreign master");
*/
*/
/* TODO addForeign(ptpClock->msgIbuf,header,ptpClock); */
st_com_add_foreign
(
pkt
,
&
ppi
->
msg_tmp_header
,
ppi
);
ppi
->
record_update
=
TRUE
;
ppi
->
record_update
=
TRUE
;
}
}
if
(
ppi
->
record_update
)
{
st_com_execute_slave
(
ppi
);
/* FIXME diag DBGV("event STATE_DECISION_EVENT\n"); */
ppi
->
record_update
=
FALSE
;
ppi
->
next_state
=
bmc
(
ppi
->
frgn_master
,
ppi
->
rt_opts
,
ppi
);
}
state_updated:
/* Leaving this state */
/* Leaving this state */
if
(
ppi
->
next_state
!=
ppi
->
state
)
{
if
(
ppi
->
next_state
!=
ppi
->
state
)
{
pp_timer_stop
(
ppi
->
timers
[
PP_TIMER_ANNOUNCE_RECEIPT
]);
pp_timer_stop
(
ppi
->
timers
[
PP_TIMER_ANNOUNCE_RECEIPT
]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment