]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
clang and clean up some debug messages
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Sun, 18 Apr 2021 11:06:38 +0000 (12:06 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Sun, 18 Apr 2021 11:06:38 +0000 (12:06 +0100)
nqptp-clock-sources.c
nqptp-clock-sources.h
nqptp-message-handlers.c
nqptp-message-handlers.h
nqptp-shm-structures.h
nqptp.c
nqptp.h

index 14443a18154d9d3ad6e1e17f815eb09a768dc03b..6aa3661de473d15e9a7ddb586d955a8d878406a6 100644 (file)
@@ -31,8 +31,7 @@
 
 clock_source_private_data clocks_private[MAX_CLOCKS];
 
-int find_clock_source_record(char *sender_string,
-                             clock_source_private_data *clocks_private_info) {
+int find_clock_source_record(char *sender_string, clock_source_private_data *clocks_private_info) {
   // return the index of the clock in the clock information arrays or -1
   int response = -1;
   int i = 0;
@@ -67,7 +66,8 @@ int create_clock_source_record(char *sender_string,
   if (found == 1) {
     response = i;
     memset(&clocks_private_info[i], 0, sizeof(clock_source_private_data));
-    strncpy((char *)&clocks_private_info[i].ip, sender_string, FIELD_SIZEOF(clock_source_private_data, ip) - 1);
+    strncpy((char *)&clocks_private_info[i].ip, sender_string,
+            FIELD_SIZEOF(clock_source_private_data, ip) - 1);
     clocks_private_info[i].in_use = 1;
     clocks_private_info[i].t2 = 0;
     clocks_private_info[i].current_stage = waiting_for_sync;
@@ -80,8 +80,7 @@ int create_clock_source_record(char *sender_string,
   return response;
 }
 
-void manage_clock_sources(uint64_t reception_time,
-                          clock_source_private_data *clocks_private_info) {
+void manage_clock_sources(uint64_t reception_time, clock_source_private_data *clocks_private_info) {
   debug(3, "manage_clock_sources");
   int i;
   // do a garbage collect for clock records no longer in use
index 8a4f18be9a84af076d3c22bba17a2fe3275622ce..ece2aca9f910e5742721b96893265bfd8a8b0e0b 100644 (file)
@@ -78,16 +78,13 @@ typedef struct {
 
 } clock_source_private_data;
 
-int find_clock_source_record(char *sender_string,
-                             clock_source_private_data *clocks_private_info);
+int find_clock_source_record(char *sender_string, clock_source_private_data *clocks_private_info);
 
-int create_clock_source_record(char *sender_string,
-                               clock_source_private_data *clocks_private_info);
+int create_clock_source_record(char *sender_string, clock_source_private_data *clocks_private_info);
 
 void update_clock_self_identifications(clock_source_private_data *clocks_private_info);
 
-void manage_clock_sources(uint64_t reception_time,
-                          clock_source_private_data *clocks_private_info);
+void manage_clock_sources(uint64_t reception_time, clock_source_private_data *clocks_private_info);
 
 extern clock_source_private_data clocks_private[MAX_CLOCKS];
 
index 447ee175bb4dabdcdb351a0e404b77a410fd1809..d55ecd2f96be3029f771cc71eefe05694e1c1630 100644 (file)
@@ -31,7 +31,7 @@ void update_master_old(clock_source_private_data *clock_private_info) {
   for (i = 0; i < MAX_CLOCKS; i++) {
     if ((clock_private_info[i].flags & (1 << clock_is_master)) != 0)
       if (old_master == -1)
-        old_master = i; // find old master
+        old_master = i;                                     // find old master
     clock_private_info[i].flags &= ~(1 << clock_is_master); // turn them all off
   }
 
@@ -73,15 +73,17 @@ void update_master_old(clock_source_private_data *clock_private_info) {
     }
   }
   if (best_so_far != -1) {
-  // we found a master clock
+    // we found a master clock
     clock_private_info[best_so_far].flags |= (1 << clock_is_master);
     // master_clock_index = best_so_far;
     if (old_master != best_so_far) {
-      update_master_clock_info(clock_private_info[best_so_far].clock_id, clock_private_info[best_so_far].local_time, clock_private_info[best_so_far].local_to_source_time_offset);
+      update_master_clock_info(clock_private_info[best_so_far].clock_id,
+                               clock_private_info[best_so_far].local_time,
+                               clock_private_info[best_so_far].local_to_source_time_offset);
     }
   } else {
     if (timing_peer_count == 0)
-      debug(1, "No timing peer list found");
+      debug(2, "No timing peer list found");
     else
       debug(1, "No master clock not found!");
   }
@@ -89,20 +91,17 @@ void update_master_old(clock_source_private_data *clock_private_info) {
   // check
   for (i = 0; i < MAX_CLOCKS; i++) {
     if ((clock_private_info[i].flags & (1 << clock_is_master)) != 0)
-      debug(2,"leaving with %d as master", i);
+      debug(2, "leaving with %d as master", i);
   }
-
 }
 
-void update_master() {
-  update_master_old(clocks_private);
-}
+void update_master() { update_master_old(clocks_private); }
 
 void handle_control_port_messages(char *buf, ssize_t recv_len,
                                   clock_source_private_data *clock_private_info) {
   if (recv_len != -1) {
     buf[recv_len - 1] = 0; // make sure there's a null in it!
-    debug(1,"Received a new timing peer list message: \"%s\".", buf);
+    debug(2, "Received a new timing peer list message: \"%s\".", buf);
     if (buf[0] == 'T') {
 
       char *ip_list = buf + 1;
@@ -112,7 +111,8 @@ void handle_control_port_messages(char *buf, ssize_t recv_len,
       // turn off all is_timing_peer flags
       int i;
       for (i = 0; i < MAX_CLOCKS; i++) {
-        clock_private_info[i].flags &= ~(1 << clock_is_a_timing_peer); // turn off peer flag (but not the master flag!)
+        clock_private_info[i].flags &=
+            ~(1 << clock_is_a_timing_peer); // turn off peer flag (but not the master flag!)
       }
 
       while (ip_list != NULL) {
@@ -149,8 +149,8 @@ void handle_control_port_messages(char *buf, ssize_t recv_len,
   }
 }
 
-void handle_announce(char *buf, ssize_t recv_len,
-                     clock_source_private_data *clock_private_info, uint64_t reception_time) {
+void handle_announce(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info,
+                     uint64_t reception_time) {
   // reject Announce messages from self
   if (clock_private_info->is_one_of_ours == 0) {
     // debug_print_buffer(1, buf, (size_t) recv_len);
@@ -355,7 +355,8 @@ void handle_sync(char *buf, __attribute__((unused)) ssize_t recv_len,
 }
 
 void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len,
-                      clock_source_private_data *clock_private_info, __attribute__((unused)) uint64_t reception_time) {
+                      clock_source_private_data *clock_private_info,
+                      __attribute__((unused)) uint64_t reception_time) {
   struct ptp_follow_up_message *msg = (struct ptp_follow_up_message *)buf;
 
   if ((clock_private_info->current_stage == sync_seen) &&
@@ -508,21 +509,21 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len,
         }
     */
 
-    // int64_t estimated_variation = estimated_offset - clock_private_info->previous_estimated_offset;
-    // debug(1, "clock: %" PRIx64 ", estimated_jitter: %+f ms, divergence: %+f.",
-    // clock_info->clock_id,
+    // int64_t estimated_variation = estimated_offset -
+    // clock_private_info->previous_estimated_offset; debug(1, "clock: %" PRIx64 ",
+    // estimated_jitter: %+f ms, divergence: %+f.", clock_info->clock_id,
     //      estimated_variation * 0.000001, divergence * 0.000001);
 
     clock_private_info->previous_estimated_offset = estimated_offset;
 
-
     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;
 
     if ((clock_private_info->flags & (1 << clock_is_master)) != 0) {
-      update_master_clock_info(clock_private_info->clock_id, clock_private_info->local_time, clock_private_info->local_to_source_time_offset);
+      update_master_clock_info(clock_private_info->clock_id, clock_private_info->local_time,
+                               clock_private_info->local_to_source_time_offset);
     }
 
     clock_private_info->next_sample_goes_here++;
index 0e6700ecab134bece8a0e7b700a061e4ba312fcf..1debea535bc3d1145456d3f240f7712069c070ca 100644 (file)
 #include "nqptp-clock-sources.h"
 #include "nqptp-shm-structures.h"
 
-void handle_announce(char *buf, ssize_t recv_len,
-                     clock_source_private_data *clock_private_info, uint64_t reception_time);
+void handle_announce(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info,
+                     uint64_t reception_time);
 
-void handle_sync(char *buf, ssize_t recv_len,
-                 clock_source_private_data *clock_private_info, uint64_t reception_time);
+void handle_sync(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info,
+                 uint64_t reception_time);
 
-void handle_follow_up(char *buf, ssize_t recv_len,
-                      clock_source_private_data *clock_private_info, uint64_t reception_time);
+void handle_follow_up(char *buf, ssize_t recv_len, clock_source_private_data *clock_private_info,
+                      uint64_t reception_time);
 
 void handle_control_port_messages(char *buf, ssize_t recv_len,
                                   clock_source_private_data *clock_private_info);
index b5cf7e05c1498c71f475a9320d4a6b0c2b2eefe9..42d4e23564356d03f62174b975d404628777cdc3 100644 (file)
 #include <pthread.h>
 
 struct shm_structure {
-  pthread_mutex_t shm_mutex;    // for safely accessing the structure
-  uint16_t version;             // deprecated -- check this is equal to NQPTP_SHM_STRUCTURES_VERSION
-  uint32_t flags;               // unused
-  uint64_t master_clock_id;     // the current master clock
-  uint64_t local_time;          // the time when the offset was calculated
+  pthread_mutex_t shm_mutex; // for safely accessing the structure
+  uint16_t version;          // deprecated -- check this is equal to NQPTP_SHM_STRUCTURES_VERSION
+  uint32_t flags;            // unused
+  uint64_t master_clock_id;  // the current master clock
+  uint64_t local_time;       // the time when the offset was calculated
   uint64_t local_to_master_time_offset; // add this to the local time to get master clock time
 };
 
diff --git a/nqptp.c b/nqptp.c
index 98271fc85e50a6e9035731df682df20cb95798af..2fc25564ea85199eb347bd56247a2566c81a7741 100644 (file)
--- a/nqptp.c
+++ b/nqptp.c
@@ -71,9 +71,10 @@ int master_clock_index = -1;
 struct shm_structure *shared_memory = NULL; // this is where public clock info is available
 int epoll_fd;
 
-void update_master_clock_info(uint64_t master_clock_id, uint64_t local_time, uint64_t local_to_master_offset) {
+void update_master_clock_info(uint64_t master_clock_id, uint64_t local_time,
+                              uint64_t local_to_master_offset) {
   if (shared_memory->master_clock_id != master_clock_id)
-      debug(1,"Master clock is: %" PRIx64 ", local_to_ptp_time_offset: %" PRIx64 ".", shared_memory->master_clock_id, shared_memory->local_to_master_time_offset);
+    debug(1, "Master clock is: %" PRIx64".", master_clock_id);
   int rc = pthread_mutex_lock(&shared_memory->shm_mutex);
   if (rc != 0)
     warn("Can't acquire mutex to update master clock!");
@@ -340,14 +341,12 @@ int main(void) {
               memset(sender_string, 0, sizeof(sender_string));
               inet_ntop(connection_ip_family, sender_addr, sender_string, sizeof(sender_string));
               // now, find or create a record for this ip
-              int the_clock =
-                  find_clock_source_record(sender_string,
-                                           (clock_source_private_data *)&clocks_private);
+              int the_clock = find_clock_source_record(
+                  sender_string, (clock_source_private_data *)&clocks_private);
               // not sure about requiring a Sync before creating it...
               if ((the_clock == -1) && ((buf[0] & 0xF) == Sync)) {
                 the_clock = create_clock_source_record(
-                    sender_string,
-                    (clock_source_private_data *)&clocks_private);
+                    sender_string, (clock_source_private_data *)&clocks_private);
               }
               if (the_clock != -1) {
                 clocks_private[the_clock].time_of_last_use =
@@ -355,19 +354,15 @@ int main(void) {
                 switch (buf[0] & 0xF) {
                 case Announce:
                   // needed to reject messages coming from self
-                  update_clock_self_identifications(
-                                                    (clock_source_private_data *)&clocks_private);
-                  handle_announce(buf, recv_len,
-                                  &clocks_private[the_clock], reception_time);
+                  update_clock_self_identifications((clock_source_private_data *)&clocks_private);
+                  handle_announce(buf, recv_len, &clocks_private[the_clock], reception_time);
                   break;
                 case Sync: { // if it's a sync
-                  handle_sync(buf, recv_len,
-                              &clocks_private[the_clock], reception_time);
+                  handle_sync(buf, recv_len, &clocks_private[the_clock], reception_time);
                 } break;
 
                 case Follow_Up: {
-                  handle_follow_up(buf, recv_len,
-                                   &clocks_private[the_clock], reception_time);
+                  handle_follow_up(buf, recv_len, &clocks_private[the_clock], reception_time);
                 } break;
                 default:
                   break;
@@ -377,8 +372,7 @@ int main(void) {
           }
         }
       }
-      manage_clock_sources(reception_time,
-                           (clock_source_private_data *)&clocks_private);
+      manage_clock_sources(reception_time, (clock_source_private_data *)&clocks_private);
     }
   }
 
diff --git a/nqptp.h b/nqptp.h
index b3e3dcdd7cbe1a3ca899c52c37806b976aa0ac4a..8dbedd8f900bab6fe91e9035a51e431f9fb8bf8c 100644 (file)
--- a/nqptp.h
+++ b/nqptp.h
 #define NQPTP_H
 
 // 0 means no debug messages. 3 means lots!
-#define DEBUG_LEVEL 0
+#define DEBUG_LEVEL 1
 
 #include "nqptp-shm-structures.h"
 
 #define MAX_OPEN_SOCKETS 16
 
-
 // When a new timing peer group is created, one of the clocks in the
 // group becomes the master and its native time becomes the "master time".
 // This is what is provided to the client.
@@ -35,6 +34,7 @@
 extern int master_clock_index;
 extern struct shm_structure *shared_memory;
 
-void update_master_clock_info(uint64_t master_clock_id, uint64_t local_time, uint64_t local_to_master_offset);
+void update_master_clock_info(uint64_t master_clock_id, uint64_t local_time,
+                              uint64_t local_to_master_offset);
 
 #endif
\ No newline at end of file