From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Sat, 19 Jun 2021 17:30:23 +0000 (+0100) Subject: Remove many redundant #includes and do a clang format X-Git-Tag: 1.2~120 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01fa06a8821921255c465ff2974765743028819c;p=thirdparty%2Fnqptp.git Remove many redundant #includes and do a clang format --- diff --git a/general-utilities.c b/general-utilities.c index 6f024d5..87dc13d 100644 --- a/general-utilities.c +++ b/general-utilities.c @@ -19,8 +19,8 @@ #include "general-utilities.h" #include "debug.h" -#include -#include +#include // ntohl etc. +#include // memcpy void hcton64(uint64_t num, uint8_t *p) { uint64_t numc = num; diff --git a/general-utilities.h b/general-utilities.h index d8f180e..071ab29 100644 --- a/general-utilities.h +++ b/general-utilities.h @@ -24,6 +24,7 @@ // specialised stuff should go in the nqptp-utilities #include +#include #include // struct sockaddr_in6 is bigger than struct sockaddr. derp diff --git a/nqptp-clock-sources.c b/nqptp-clock-sources.c index 6a936d9..b119aa7 100644 --- a/nqptp-clock-sources.c +++ b/nqptp-clock-sources.c @@ -19,8 +19,8 @@ #include "nqptp-clock-sources.h" #include "debug.h" -#include "nqptp-ptp-definitions.h" #include "general-utilities.h" +#include "nqptp-ptp-definitions.h" #include #include #include @@ -165,7 +165,8 @@ void update_master() { int best_so_far = -1; int timing_peer_count = 0; - uint32_t acceptance_mask = (1 << clock_is_qualified) | (1 << clock_is_a_timing_peer) | (1 << clock_is_valid); + uint32_t acceptance_mask = + (1 << clock_is_qualified) | (1 << clock_is_a_timing_peer) | (1 << clock_is_valid); for (i = 0; i < MAX_CLOCKS; i++) { if ((clocks_private[i].flags & acceptance_mask) == acceptance_mask) { // found a possible clock candidate @@ -210,11 +211,11 @@ void update_master() { debug(2, "No timing peer list found"); else debug(1, "No master clock not found!"); - } else { - // we found a master clock - clocks_private[best_so_far].flags |= (1 << clock_is_master); + } else { + // we found a master clock + clocks_private[best_so_far].flags |= (1 << clock_is_master); - if (old_master != best_so_far) { + if (old_master != best_so_far) { // clang-format off // Now we use the last few samples to calculate the best offset for the // new master clock. @@ -299,7 +300,7 @@ void update_master() { clocks_private[best_so_far].mastership_start_time); // clang-format on - clocks_private[best_so_far].previous_offset_time = 0; // resync + clocks_private[best_so_far].previous_offset_time = 0; // resync } } diff --git a/nqptp-clock-sources.h b/nqptp-clock-sources.h index b27e6e4..146b5d8 100644 --- a/nqptp-clock-sources.h +++ b/nqptp-clock-sources.h @@ -34,9 +34,9 @@ typedef enum { // 8 samples per seconds #define MAX_TIMING_SAMPLES 47 - typedef struct { - uint64_t local_time, clock_time; - } timing_samples; +typedef struct { + uint64_t local_time, clock_time; +} timing_samples; // information about each clock source typedef struct { @@ -63,7 +63,6 @@ typedef struct { int next_sample_goes_here; // point to where in the timing samples array the next entries should // go - // these are for finding the best clock to use // See Figure 27 and 27 pp 89 -- 90 for the Data set comparison algorithm diff --git a/nqptp-message-handlers.c b/nqptp-message-handlers.c index 3c76f7c..1fcebd6 100644 --- a/nqptp-message-handlers.c +++ b/nqptp-message-handlers.c @@ -16,10 +16,7 @@ * * Commercial licensing is also available. */ -#include -#include -#include -#include +#include //strsep #include "debug.h" #include "general-utilities.h" @@ -219,35 +216,34 @@ void handle_announce(char *buf, ssize_t recv_len, clock_source_private_data *clo void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len, clock_source_private_data *clock_private_info, uint64_t reception_time) { - clock_private_info->flags |= (1 << clock_is_valid); // valid because it has at least one follow_up - struct ptp_follow_up_message *msg = (struct ptp_follow_up_message *)buf; + clock_private_info->flags |= (1 << clock_is_valid); // valid because it has at least one follow_up + 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]); - uint64_t preciseOriginTimestamp = seconds_hi; - preciseOriginTimestamp = preciseOriginTimestamp << 32; - preciseOriginTimestamp = preciseOriginTimestamp + seconds_low; - preciseOriginTimestamp = preciseOriginTimestamp * 1000000000L; - preciseOriginTimestamp = preciseOriginTimestamp + nanoseconds; + 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]); + uint64_t preciseOriginTimestamp = seconds_hi; + preciseOriginTimestamp = preciseOriginTimestamp << 32; + preciseOriginTimestamp = preciseOriginTimestamp + seconds_low; + preciseOriginTimestamp = preciseOriginTimestamp * 1000000000L; + preciseOriginTimestamp = preciseOriginTimestamp + nanoseconds; - // update our sample information + // update our sample information - clock_private_info->samples[clock_private_info->next_sample_goes_here].local_time = - reception_time; - clock_private_info->samples[clock_private_info->next_sample_goes_here] - .clock_time = preciseOriginTimestamp; + clock_private_info->samples[clock_private_info->next_sample_goes_here].local_time = + reception_time; + clock_private_info->samples[clock_private_info->next_sample_goes_here].clock_time = + preciseOriginTimestamp; - if (clock_private_info->vacant_samples > 0) - clock_private_info->vacant_samples--; + if (clock_private_info->vacant_samples > 0) + clock_private_info->vacant_samples--; - 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->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; - -// if ((clock_private_info->flags & (1 << clock_is_master)) != 0) { + // if ((clock_private_info->flags & (1 << clock_is_master)) != 0) { if (1) { debug(2, "FOLLOWUP from %" PRIx64 ", %s.", clock_private_info->clock_id, &clock_private_info->ip); @@ -308,7 +304,7 @@ void handle_follow_up(char *buf, __attribute__((unused)) ssize_t recv_len, uint32_t old_flags = clock_private_info->flags; - //if ((clock_private_info->flags & (1 << clock_is_valid)) == 0) { + // 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); //} diff --git a/nqptp-message-handlers.h b/nqptp-message-handlers.h index f7daf75..a0e2865 100644 --- a/nqptp-message-handlers.h +++ b/nqptp-message-handlers.h @@ -20,9 +20,7 @@ #ifndef NQPTP_MESSAGE_HANDLERS_H #define NQPTP_MESSAGE_HANDLERS_H -#include "general-utilities.h" #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); diff --git a/nqptp-shm-structures.h b/nqptp-shm-structures.h index 9704644..36c8a81 100644 --- a/nqptp-shm-structures.h +++ b/nqptp-shm-structures.h @@ -32,7 +32,6 @@ // The IPs will become the new list of timing peers, replacing any previous #include -#include #include struct shm_structure { diff --git a/nqptp-utilities.c b/nqptp-utilities.c index 6a5904c..dec439a 100644 --- a/nqptp-utilities.c +++ b/nqptp-utilities.c @@ -18,19 +18,15 @@ */ #include "nqptp-utilities.h" -#include "general-utilities.h" -#include "nqptp-ptp-definitions.h" #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include // fcntl etc. +#include // getifaddrs +#include // sockaddr_ll +#include // SOF_TIMESTAMPING_TX_HARDWARE and friends +#include // getaddrinfo etc. +#include // snprintf +#include // malloc, free +#include // memset strcpy, etc. #include "debug.h" diff --git a/nqptp-utilities.h b/nqptp-utilities.h index fb6d83d..66367a8 100644 --- a/nqptp-utilities.h +++ b/nqptp-utilities.h @@ -19,8 +19,11 @@ #ifndef NQPTP_UTILITIES_H #define NQPTP_UTILITIES_H + #include "nqptp.h" -#include +#include +#include + // functions that are specific to NQPTP // general stuff should go in the general-utilities diff --git a/nqptp.c b/nqptp.c index 5dc6647..a1d3f48 100644 --- a/nqptp.c +++ b/nqptp.c @@ -29,38 +29,21 @@ #include "gitversion.h" #endif -#include -#include //printf -#include //malloc; -#include //memset -#include -#include // close - -#include -#include -#include +#include // inet_ntop +#include // printf +#include // malloc; +#include // memset #include -#include -#include - -#include -#include /* the L2 protocols */ -#include - -#include - -#include -#include -#include +#include // close -#include /* For O_* constants */ -#include -#include /* For mode constants */ +#include /* For O_* constants */ +#include // for shared memory stuff +#include // umask -#include +#include // group stuff -#include +#include // SIGTERM and stuff like that #include #ifndef FIELD_SIZEOF @@ -141,12 +124,12 @@ int main(int argc, char **argv) { #ifdef CONFIG_USE_GIT_VERSION_STRING if (git_version_string[0] != '\0') fprintf(stdout, "Version: %s. Shared Memory Interface Version: %u.\n", git_version_string, - NQPTP_SHM_STRUCTURES_VERSION); + NQPTP_SHM_STRUCTURES_VERSION); else #endif - fprintf(stdout, "Version: %s. Shared Memory Interface Version: %u.\n", VERSION, - NQPTP_SHM_STRUCTURES_VERSION); + fprintf(stdout, "Version: %s. Shared Memory Interface Version: %u.\n", VERSION, + NQPTP_SHM_STRUCTURES_VERSION); exit(EXIT_SUCCESS); } else if (strcmp(argv[i] + 1, "vvv") == 0) { debug_level = 3; diff --git a/nqptp.h b/nqptp.h index 8d7d18a..327aba9 100644 --- a/nqptp.h +++ b/nqptp.h @@ -20,6 +20,9 @@ #ifndef NQPTP_H #define NQPTP_H +#include +#include + #include "nqptp-shm-structures.h" #define MAX_OPEN_SOCKETS 16 @@ -35,4 +38,3 @@ void update_master_clock_info(uint64_t master_clock_id, const char *ip, uint64_t uint64_t local_to_master_offset, uint64_t mastership_start_time); #endif -