]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
Allow up to 10 ms of negative jitter to be accepted. At the start, give extra weight...
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Thu, 25 Nov 2021 20:43:51 +0000 (20:43 +0000)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Thu, 25 Nov 2021 20:43:51 +0000 (20:43 +0000)
nqptp-clock-sources.h
nqptp-message-handlers.c

index 0094f3cd51afc9a502ed100952219f222afe3b6c..4d9a853d843c581047f51180d3683131a48aabbd 100644 (file)
@@ -41,8 +41,8 @@ typedef struct {
 
 // information about each clock source
 typedef struct {
-  char ip[64];                         // 64 is nicely aligned and bigger than INET6_ADDRSTRLEN (46)
-  int family;                          // AF_INET or AF_INET6
+  char ip[64]; // 64 is nicely aligned and bigger than INET6_ADDRSTRLEN (46)
+  int family;  // AF_INET or AF_INET6
   int follow_up_number;
   int announcements_without_followups; // add 1 for every announce, reset with a followup
   uint64_t clock_id;
index 87cd6c4d8d3e0405cb7f859e469f0640063eec25..1dd1560499d99e2e0b6aaa9846b7023455864e1d 100644 (file)
@@ -232,7 +232,6 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len,
 
   struct ptp_follow_up_message *msg = (struct ptp_follow_up_message *)buf;
 
-
   uint16_t seconds_hi = nctohs(&msg->follow_up.preciseOriginTimestamp[0]);
   uint32_t seconds_low = nctohl(&msg->follow_up.preciseOriginTimestamp[2]);
   uint32_t nanoseconds = nctohl(&msg->follow_up.preciseOriginTimestamp[6]);
@@ -374,12 +373,14 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len,
 
       jitter = offset - clock_private_info->previous_offset;
 
-     if (jitter > -10000000) {
+      if (jitter > -10000000) {
         // we take any positive or a limited negative jitter as a sync event
         if (jitter < 0)
-          offset = clock_private_info->previous_offset + jitter/32;
+          offset = clock_private_info->previous_offset + jitter / 32;
+        else if (clock_private_info->follow_up_number < (5 * 8)) // at the beginning...
+          offset = clock_private_info->previous_offset + jitter / 4;
         else
-          offset = clock_private_info->previous_offset + jitter/32;
+          offset = clock_private_info->previous_offset + jitter / 32;
         clock_private_info->last_sync_time = reception_time;
       } else {
         offset = clock_private_info->previous_offset; // forget the present sample...
@@ -399,7 +400,7 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len,
   clock_private_info->previous_offset_time = reception_time;
 
   if ((clock_private_info->flags & (1 << clock_is_master)) != 0) {
-      
+
     update_master_clock_info(clock_private_info->clock_id, (const char *)&clock_private_info->ip,
                              reception_time, offset, clock_private_info->mastership_start_time);
     debug(3, "clock: %" PRIx64 ", time: %" PRIu64 ", offset: %" PRId64 ", jitter: %+f ms.",