]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
Only install a service file if there isn't one there already.
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Thu, 25 Nov 2021 20:29:51 +0000 (20:29 +0000)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Thu, 25 Nov 2021 20:29:51 +0000 (20:29 +0000)
Makefile.am
nqptp-clock-sources.h
nqptp-message-handlers.c

index 660d6cfdcea64510bfb0d86e0d0b0473ec77227e..ed4c27543fb8bc12b0464473b5c6cdf06920f499 100644 (file)
@@ -21,7 +21,8 @@ install-exec-hook:
 if BUILD_FOR_LINUX
 if INSTALL_SYSTEMD_STARTUP
        [ -e $(DESTDIR)$(libdir)/systemd/system ] || mkdir -p $(DESTDIR)$(libdir)/systemd/system
-       cp nqptp.service $(DESTDIR)$(libdir)/systemd/system
+# don't replace a service file if it already exists...
+       [ -e $(DESTDIR)$(libdir)/systemd/system/nqptp.service ] || cp nqptp.service $(DESTDIR)$(libdir)/systemd/system
 endif
 endif
  # no installer for FreeBSD yet
index 3085ab1cd0beeac677ca71a94c8325f51be76f24..0094f3cd51afc9a502ed100952219f222afe3b6c 100644 (file)
@@ -43,6 +43,7 @@ typedef struct {
 typedef struct {
   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;
   uint64_t local_time; // the local time when the offset was calculated
index 31dc9f8218b66d067c16d14910c50cfea3f93d91..87cd6c4d8d3e0405cb7f859e469f0640063eec25 100644 (file)
@@ -232,6 +232,7 @@ 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]);
@@ -242,6 +243,8 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len,
   preciseOriginTimestamp = preciseOriginTimestamp + nanoseconds;
 
   // update our sample information
+  if (clock_private_info->follow_up_number < 100)
+    clock_private_info->follow_up_number++;
 
   clock_private_info->announcements_without_followups = 0; // we've seen a followup
 
@@ -359,38 +362,27 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len,
   } else if (clock_private_info->previous_offset_time != 0) {
     // i.e. if it's not becoming a master and there has been a previous follow_up
     int64_t time_since_last_sync = reception_time - clock_private_info->last_sync_time;
-    int64_t sync_timeout = 60000000000; // nanoseconds
+    int64_t sync_timeout = 15000000000; // nanoseconds
     debug(2, "Sync interval: %f seconds.", 0.000000001 * time_since_last_sync);
     if (time_since_last_sync < sync_timeout) {
 
       // Do acceptance checking.
       // If the new offset is greater, by any amount, than the old offset,
-      // accept it.
-      // If it is less than the new offset by up to what a reasonable drift divergence would allow,
+      // or if it is less by up to 10 mS,
       // accept it.
       // Otherwise, reject it
 
-      // A drift divergence of 100 ppm would give 12.5 us per 125 ms.
-
       jitter = offset - clock_private_info->previous_offset;
 
-      uint64_t jitter_timing_interval = reception_time - clock_private_info->previous_offset_time;
-      long double jitterppm = 0.0;
-      if (jitter_timing_interval != 0) {
-        jitterppm = (0.001 * (jitter * 1000000000)) / jitter_timing_interval;
-        debug(2, "jitter: %" PRId64 " in: %" PRId64 " ns, %+f ppm ", jitter, jitter_timing_interval,
-              jitterppm);
-      }
-      if (jitterppm >= -1000) {
-        // we take a positive or small negative jitter as a sync event
-        // as we have a new figure for the difference between the local clock and the
-        // remote clock which is almost the same or greater than our previous estimate
+     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;
+        else
+          offset = clock_private_info->previous_offset + jitter/32;
         clock_private_info->last_sync_time = reception_time;
       } else {
-        // let our previous estimate drop fall back by this many nanoseconds
-        jitter = -10 * 1000; // this is nanoseconds in, supposedly, 125 milliseconds. 12.5 us /
-                             // 125 ms is 100 ppm.
-        offset = clock_private_info->previous_offset + jitter;
+        offset = clock_private_info->previous_offset; // forget the present sample...
       }
     } else {
       if ((clock_private_info->flags & (1 << clock_is_master)) != 0)
@@ -407,6 +399,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.",