]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
Clang Format
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Mon, 3 May 2021 14:54:29 +0000 (15:54 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Mon, 3 May 2021 14:54:29 +0000 (15:54 +0100)
nqptp-message-handlers.c

index 384219c4e52c487d0e11bdfa3685ffb98c460464..bcf7e025dad025061c7f122bccd48dc4f096a389 100644 (file)
@@ -220,7 +220,7 @@ void handle_announce(char *buf, ssize_t recv_len, clock_source_private_data *clo
 void handle_sync(char *buf, __attribute__((unused)) ssize_t recv_len,
                  clock_source_private_data *clock_private_info, uint64_t reception_time,
                  SOCKADDR *to_sock_addr, int socket_number) {
-  debug(3,"SYNC from %s.", &clock_private_info->ip);
+  debug(3, "SYNC from %s.", &clock_private_info->ip);
   struct ptp_sync_message *msg = (struct ptp_sync_message *)buf;
   // this is just to see if anything interesting comes in the SYNC package
   // a non-zero origin timestamp
@@ -346,7 +346,8 @@ void handle_sync(char *buf, __attribute__((unused)) ssize_t recv_len,
       }
     }
   } else {
-        if ((clock_private_info->flags & (1 << clock_is_master)) != 0) debug(2,"master discarding SYNC");
+    if ((clock_private_info->flags & (1 << clock_is_master)) != 0)
+      debug(2, "master discarding SYNC");
   }
 }
 
@@ -382,7 +383,8 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len,
     clock_private_info->current_stage = follow_up_seen;
 
   } else {
-    if ((clock_private_info->flags & (1 << clock_is_master)) != 0) debug(2,"master discarding FOLLOWUP");
+    if ((clock_private_info->flags & (1 << clock_is_master)) != 0)
+      debug(2, "master discarding FOLLOWUP");
     debug(3,
           "Follow_Up %u expecting to be in state sync_seen (%u). Stage error -- "
           "current state is %u, sequence %u. Ignoring it. %s",
@@ -394,7 +396,7 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len,
 void handle_delay_resp(char *buf, __attribute__((unused)) ssize_t recv_len,
                        clock_source_private_data *clock_private_info,
                        __attribute__((unused)) uint64_t reception_time) {
-  debug(2,"Delay_Resp from %s", clock_private_info->ip);
+  debug(2, "Delay_Resp from %s", clock_private_info->ip);
   struct ptp_delay_resp_message *msg = (struct ptp_delay_resp_message *)buf;
 
   if ((clock_private_info->current_stage == follow_up_seen) &&
@@ -456,91 +458,99 @@ void handle_delay_resp(char *buf, __attribute__((unused)) ssize_t recv_len,
       // let's go with 500 us.
       int64_t jitter = offset - clock_private_info->previous_estimated_offset;
 
-      //if (jitter <= -250 * 1000)
+      // if (jitter <= -250 * 1000)
       //  offset = clock_private_info->previous_estimated_offset -100 * 1000;
 
-      uint64_t jitter_timing_interval = clock_private_info->t2 - clock_private_info->previous_offset_time;
+      uint64_t jitter_timing_interval =
+          clock_private_info->t2 - 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(1,"jitter: %" PRId64 " in: %" PRId64 " ns, %f ppm ", jitter, jitter_timing_interval, jitterppm);
+        jitterppm = (0.001 * (jitter * 1000000000)) / jitter_timing_interval;
+        // debug(1,"jitter: %" PRId64 " in: %" PRId64 " ns, %f ppm ", jitter,
+        // jitter_timing_interval, jitterppm);
       }
 
       // 2,000 parts per million is gigantic
       if (jitterppm > -1000) {
 
-       uint64_t estimated_offset = offset;
-
-/*
-       if (jitter > 4000 * 1000)
-        clock_private_info->mm_count = 0; // if it jumps by this much, start averaging again
+        uint64_t estimated_offset = offset;
+
+        /*
+               if (jitter > 4000 * 1000)
+                clock_private_info->mm_count = 0; // if it jumps by this much, start averaging again
+
+              // do mickey mouse averaging
+              if (clock_private_info->mm_count == 0) {
+                clock_private_info->mm_average = offset;
+                clock_private_info->mm_count = 1;
+              } else {
+                if (clock_private_info->mm_count < 1000)
+                  clock_private_info->mm_count++;
+                clock_private_info->mm_average =
+                    (clock_private_info->mm_count - 1) *
+                    (clock_private_info->mm_average / clock_private_info->mm_count);
+                clock_private_info->mm_average =
+                    clock_private_info->mm_average + (1.0 * offset) / clock_private_info->mm_count;
+              }
+              estimated_offset = (uint64_t)clock_private_info->mm_average;
+        */
 
-      // do mickey mouse averaging
-      if (clock_private_info->mm_count == 0) {
-        clock_private_info->mm_average = offset;
-        clock_private_info->mm_count = 1;
-      } else {
-        if (clock_private_info->mm_count < 1000)
-          clock_private_info->mm_count++;
-        clock_private_info->mm_average =
-            (clock_private_info->mm_count - 1) *
-            (clock_private_info->mm_average / clock_private_info->mm_count);
-        clock_private_info->mm_average =
-            clock_private_info->mm_average + (1.0 * offset) / clock_private_info->mm_count;
-      }
-      estimated_offset = (uint64_t)clock_private_info->mm_average;
-*/
+        /*
+              // do real averaging
 
-      /*
-            // do real averaging
+              int sample_count = MAX_TIMING_SAMPLES - clock_private_info->vacant_samples;
+              int64_t divergence = 0;
+              uint64_t estimated_offset = offset;
 
-            int sample_count = MAX_TIMING_SAMPLES - clock_private_info->vacant_samples;
-            int64_t divergence = 0;
-            uint64_t estimated_offset = offset;
+              if (sample_count > 1) {
+                int e;
+                long double offsets = 0;
+                for (e = 0; e < sample_count; e++) {
+                  uint64_t ho = clock_private_info->samples[e].local_to_remote_offset;
 
-            if (sample_count > 1) {
-              int e;
-              long double offsets = 0;
-              for (e = 0; e < sample_count; e++) {
-                uint64_t ho = clock_private_info->samples[e].local_to_remote_offset;
+                  offsets = offsets + 1.0 * ho;
+                }
 
-                offsets = offsets + 1.0 * ho;
+                offsets = offsets / sample_count;
+                estimated_offset = (uint64_t)offsets;
               }
+        */
 
-              offsets = offsets / sample_count;
-              estimated_offset = (uint64_t)offsets;
-            }
-      */
-
-      uint32_t old_flags = clock_private_info->flags;
+        uint32_t old_flags = clock_private_info->flags;
 
-      if ((clock_private_info->flags & (1 << clock_is_valid)) == 0) {
-        debug(1, "clock %" PRIx64 " is now valid at: %s", packet_clock_id, clock_private_info->ip);
-      }
-      clock_private_info->clock_id = packet_clock_id;
-      clock_private_info->flags |= (1 << clock_is_valid);
-      clock_private_info->local_time = clock_private_info->t2;
-      clock_private_info->local_to_source_time_offset = estimated_offset;
-
-      // debug(1,"mm_average: %" PRIx64 ", estimated_offset: %" PRIx64 ".", mm_average_int,
-      // estimated_offset);
-      if (old_flags != clock_private_info->flags) {
-        update_master();
-      } else 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,
-            clock_private_info->local_time, clock_private_info->local_to_source_time_offset);
-        debug(2,"mm:\t% " PRId64 "\ttime:\t%" PRIu64 "\toffset\t%" PRId64 "\tjitter:\t%f ms.", clock_private_info->mm_count, clock_private_info->local_time, offset, 0.000001 * jitter);
-      }
+        if ((clock_private_info->flags & (1 << clock_is_valid)) == 0) {
+          debug(1, "clock %" PRIx64 " is now valid at: %s", packet_clock_id,
+                clock_private_info->ip);
+        }
+        clock_private_info->clock_id = packet_clock_id;
+        clock_private_info->flags |= (1 << clock_is_valid);
+        clock_private_info->local_time = clock_private_info->t2;
+        clock_private_info->local_to_source_time_offset = estimated_offset;
+
+        // debug(1,"mm_average: %" PRIx64 ", estimated_offset: %" PRIx64 ".", mm_average_int,
+        // estimated_offset);
+        if (old_flags != clock_private_info->flags) {
+          update_master();
+        } else 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,
+              clock_private_info->local_time, clock_private_info->local_to_source_time_offset);
+          debug(2, "mm:\t% " PRId64 "\ttime:\t%" PRIu64 "\toffset\t%" PRId64 "\tjitter:\t%f ms.",
+                clock_private_info->mm_count, clock_private_info->local_time, offset,
+                0.000001 * jitter);
+        }
 
-      clock_private_info->next_sample_goes_here++;
+        clock_private_info->next_sample_goes_here++;
 
-      // if we have need to wrap.
-      if (clock_private_info->next_sample_goes_here == MAX_TIMING_SAMPLES)
-        clock_private_info->next_sample_goes_here = 0;
-      clock_private_info->previous_estimated_offset = estimated_offset;
+        // if we have need to wrap.
+        if (clock_private_info->next_sample_goes_here == MAX_TIMING_SAMPLES)
+          clock_private_info->next_sample_goes_here = 0;
+        clock_private_info->previous_estimated_offset = estimated_offset;
       } else {
-        debug(2,"dropping a PTP offset measurement as the offset change of %f milliseconds is too great.", jitter * 0.000001);
+        debug(2,
+              "dropping a PTP offset measurement as the offset change of %f milliseconds is too "
+              "great.",
+              jitter * 0.000001);
       }
       clock_private_info->previous_offset = offset;
       clock_private_info->previous_offset_time = clock_private_info->t2;
@@ -552,7 +562,9 @@ void handle_delay_resp(char *buf, __attribute__((unused)) ssize_t recv_len,
     }
 
   } else {
-    if ((clock_private_info->flags & (1 << clock_is_master)) != 0) debug(2,"master discarding DELAYRESP %u expected vs %u seen.", clock_private_info->sequence_number, ntohs(msg->header.sequenceId));
+    if ((clock_private_info->flags & (1 << clock_is_master)) != 0)
+      debug(2, "master discarding DELAYRESP %u expected vs %u seen.",
+            clock_private_info->sequence_number, ntohs(msg->header.sequenceId));
     debug(2,
           "Delay_Resp %u expecting to be in state follow_up_seen (%u). Stage error -- "
           "current state is %u, sequence %u. Ignoring it. %s",