diff --git a/candump.c b/candump.c index 7f2ed1f..334e202 100644 --- a/candump.c +++ b/candump.c @@ -75,16 +75,16 @@ #define TIMESTAMPSZ 50 /* string 'absolute with date' requires max 49 bytes */ -#define MAXSOCK 16 /* max. number of CAN interfaces given on the cmdline */ +#define MAXSOCK 16 /* max. number of CAN interfaces given on the cmdline */ #define MAXIFNAMES 30 /* size of receive name index to omit ioctls */ -#define MAXCOL 6 /* number of different colors for colorized output */ -#define ANYDEV "any" /* name of interface to receive from any CAN interface */ -#define ANL "\r\n" /* newline in ASC mode */ +#define MAXCOL 6 /* number of different colors for colorized output */ +#define ANYDEV "any" /* name of interface to receive from any CAN interface */ +#define ANL "\r\n" /* newline in ASC mode */ #define SILENT_INI 42 /* detect user setting on commandline */ -#define SILENT_OFF 0 /* no silent mode */ -#define SILENT_ANI 1 /* silent mode with animation */ -#define SILENT_ON 2 /* silent mode (completely silent) */ +#define SILENT_OFF 0 /* no silent mode */ +#define SILENT_ANI 1 /* silent mode with animation */ +#define SILENT_ON 2 /* silent mode (completely silent) */ #define BOLD ATTBOLD #define RED (ATTBOLD FGRED) @@ -106,7 +106,7 @@ struct if_info { /* bundled information per open socket */ static struct if_info sock_info[MAXSOCK]; static char *progname; -static char devname[MAXIFNAMES][IFNAMSIZ+1]; +static char devname[MAXIFNAMES][IFNAMSIZ + 1]; static int dindex[MAXIFNAMES]; static int max_devname_len; /* to prevent frazzled device name output */ static const int canfd_on = 1; @@ -175,7 +175,6 @@ static void sigterm(int signo) static int idx2dindex(int ifidx, int socket) { - int i; struct ifreq ifr; @@ -245,9 +244,9 @@ static inline void sprint_timestamp(const char timestamp, const struct timeval * { struct timeval diff; - if (last_tv->tv_sec == 0) /* first init */ + if (last_tv->tv_sec == 0) /* first init */ *last_tv = *tv; - diff.tv_sec = tv->tv_sec - last_tv->tv_sec; + diff.tv_sec = tv->tv_sec - last_tv->tv_sec; diff.tv_usec = tv->tv_usec - last_tv->tv_usec; if (diff.tv_usec < 0) diff.tv_sec--, diff.tv_usec += 1000000; @@ -474,8 +473,8 @@ int main(int argc, char **argv) } for (i = 0; i < currmax; i++) { - struct if_info* obj = &sock_info[i]; - ptr = argv[optind+i]; + struct if_info *obj = &sock_info[i]; + ptr = argv[optind + i]; nptr = strchr(ptr, ','); pr_debug("open %d '%s'.\n", i, ptr); @@ -495,7 +494,7 @@ int main(int argc, char **argv) obj->cmdlinename = ptr; /* save pointer to cmdline name of this socket */ if (nptr) - nbytes = nptr - ptr; /* interface name is up the first ',' */ + nbytes = nptr - ptr; /* interface name is up the first ',' */ else nbytes = strlen(ptr); /* no ',' found => no filter definitions */ @@ -714,8 +713,8 @@ int main(int argc, char **argv) continue; } - for (i = 0; i < num_events; i++) { /* check waiting CAN RAW sockets */ - struct if_info* obj = events_pending[i].data.ptr; + for (i = 0; i < num_events; i++) { /* check waiting CAN RAW sockets */ + struct if_info *obj = events_pending[i].data.ptr; int idx; char *extra_info = ""; @@ -838,9 +837,9 @@ int main(int argc, char **argv) if (extra_msg_info) { if (msg.msg_flags & MSG_DONTROUTE) - printf (" TX %s", extra_m_info[frame.flags & 3]); + printf(" TX %s", extra_m_info[frame.flags & 3]); else - printf (" RX %s", extra_m_info[frame.flags & 3]); + printf(" RX %s", extra_m_info[frame.flags & 3]); } printf("%s ", (color == 1) ? col_off : ""); @@ -850,7 +849,7 @@ int main(int argc, char **argv) printf("%s", (color > 1) ? col_off : ""); printf("\n"); - out_fflush: +out_fflush: fflush(stdout); } } diff --git a/canfdtest.c b/canfdtest.c index d47727f..12bad17 100644 --- a/canfdtest.c +++ b/canfdtest.c @@ -40,11 +40,11 @@ #include #include -#define CAN_MSG_ID_PING 0x77 -#define CAN_MSG_ID_PONG 0x78 -#define CAN_MSG_LEN 8 -#define CAN_MSG_COUNT 50 -#define CAN_MSG_WAIT 27 +#define CAN_MSG_ID_PING 0x77 +#define CAN_MSG_ID_PONG 0x78 +#define CAN_MSG_LEN 8 +#define CAN_MSG_COUNT 50 +#define CAN_MSG_WAIT 27 static int running = 1; static int verbose; @@ -82,7 +82,7 @@ static void print_usage(char *prg) "\n" "With the option '-g' CAN messages are generated and checked\n" "on , otherwise all messages received on the\n" - " are sent back incrementing the CAN id and\n" + " are sent back incrementing the CAN id and\n" "all data bytes. The program can be aborted with ^C.\n" "\n" "Examples:\n" @@ -110,14 +110,9 @@ static void print_frame(canid_t id, const uint8_t *data, int dlc, int inc_data) printf("\n"); } -static void print_compare( - canid_t exp_id, - const uint8_t *exp_data, - uint8_t exp_dlc, - canid_t rec_id, - const uint8_t *rec_data, - uint8_t rec_dlc, - int inc) +static void print_compare(canid_t exp_id, const uint8_t *exp_data, uint8_t exp_dlc, + canid_t rec_id, const uint8_t *rec_data, uint8_t rec_dlc, + int inc) { printf("expected: "); print_frame(exp_id, exp_data, exp_dlc, inc); @@ -255,7 +250,7 @@ static int check_frame(const struct canfd_frame *frame) } for (i = 1; i < frame->len; i++) { - if (frame->data[i] != (uint8_t)(frame->data[i-1] + 1)) { + if (frame->data[i] != (uint8_t)(frame->data[i - 1] + 1)) { printf("Frame inconsistent!\n"); print_frame(frame->can_id, frame->data, frame->len, 0); err = -1; @@ -263,7 +258,7 @@ static int check_frame(const struct canfd_frame *frame) } } - out: +out: return err; } @@ -324,11 +319,11 @@ static int can_echo_gen(void) int err = 0; int i; - tx_frames = calloc(inflight_count, sizeof(* tx_frames)); + tx_frames = calloc(inflight_count, sizeof(*tx_frames)); if (!tx_frames) return -1; - recv_tx = calloc(inflight_count, sizeof(* recv_tx)); + recv_tx = calloc(inflight_count, sizeof(*recv_tx)); if (!recv_tx) { err = -1; goto out_free_tx_frames; @@ -400,9 +395,9 @@ static int can_echo_gen(void) printf("\nTest messages sent and received: %d\n", loops); - out_free: +out_free: free(recv_tx); - out_free_tx_frames: +out_free_tx_frames: free(tx_frames); return err; @@ -523,7 +518,7 @@ int main(int argc, char *argv[]) if (echo_gen) { if (setsockopt(sockfd, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS, - &enable_socket_option, sizeof(enable_socket_option)) == -1) { + &enable_socket_option, sizeof(enable_socket_option)) == -1) { perror("setsockopt CAN_RAW_RECV_OWN_MSGS"); return 1; } @@ -531,7 +526,7 @@ int main(int argc, char *argv[]) if (is_can_fd) { if (setsockopt(sockfd, SOL_CAN_RAW, CAN_RAW_FD_FRAMES, - &enable_socket_option, sizeof(enable_socket_option)) == -1) { + &enable_socket_option, sizeof(enable_socket_option)) == -1) { perror("setsockopt CAN_RAW_FD_FRAMES"); return 1; } @@ -567,7 +562,7 @@ int main(int argc, char *argv[]) }; if (setsockopt(sockfd, SOL_CAN_RAW, CAN_RAW_FILTER, filters, - sizeof(struct can_filter) * (1 + echo_gen))) { + sizeof(struct can_filter) * (1 + echo_gen))) { perror("setsockopt()"); close(sockfd); return 1; diff --git a/cangen.c b/cangen.c index 5f4a4fc..0614f42 100644 --- a/cangen.c +++ b/cangen.c @@ -146,7 +146,7 @@ static struct timespec timespec_add(struct timespec ts1, struct timespec ts2) struct timespec double_to_timespec(double s) { struct timespec ts = { - .tv_sec = s, + .tv_sec = s, .tv_nsec = (s - (long)(s)) * NSEC_PER_SEC, }; @@ -156,7 +156,7 @@ struct timespec double_to_timespec(double s) static struct timespec ns_to_timespec(int64_t ns) { struct timespec ts = { - .tv_sec = ns / NSEC_PER_SEC, + .tv_sec = ns / NSEC_PER_SEC, .tv_nsec = ns % NSEC_PER_SEC, }; @@ -324,7 +324,7 @@ static int do_send_one(int fd, void *buf, size_t len, int timeout) memcpy(CMSG_DATA(cm), &tdeliver, sizeof(tdeliver)); } - resend: +resend: nbytes = sendmsg(fd, &msg, 0); if (nbytes < 0) { ret = -errno; @@ -460,7 +460,7 @@ int main(int argc, char **argv) int incdlc = 0; unsigned long rnd; unsigned char fixdata[CANFD_MAX_DLEN]; - unsigned char rand_position[CANFD_MAX_DLEN] = {0}; + unsigned char rand_position[CANFD_MAX_DLEN] = { 0 }; int opt; int s; /* socket */ @@ -490,7 +490,6 @@ int main(int argc, char **argv) while ((opt = getopt_long(argc, argv, "g:atefbER8mI:L:D:p:n:ixc:vh?", long_options, NULL)) != -1) { switch (opt) { - case 'g': gap = strtod(optarg, NULL); break; @@ -793,7 +792,7 @@ int main(int argc, char **argv) if (data_mode == MODE_RANDOM_FIX) { int i; - + memcpy(frame.data, fixdata, CANFD_MAX_DLEN); for (i = 0; i < frame.len; i++) { diff --git a/cansend.c b/cansend.c index 7499848..72d7016 100644 --- a/cansend.c +++ b/cansend.c @@ -81,11 +81,9 @@ void print_usage(char *prg) " 1F334455#1122334455667788_B / 123#R / 00000123#R3 / 333#R8_E\n\n"); } - - int main(int argc, char **argv) { - int s; /* can raw socket */ + int s; /* can raw socket */ int required_mtu; int mtu; int enable_canfd = 1; @@ -101,7 +99,7 @@ int main(int argc, char **argv) /* parse CAN frame */ required_mtu = parse_canframe(argv[2], &frame); - if (!required_mtu){ + if (!required_mtu) { fprintf(stderr, "\nWrong CAN-frame format!\n\n"); print_usage(argv[0]); return 1; @@ -126,7 +124,6 @@ int main(int argc, char **argv) addr.can_ifindex = ifr.ifr_ifindex; if (required_mtu > (int)CAN_MTU) { - /* check if the frame fits into the CAN netdevice */ if (ioctl(s, SIOCGIFMTU, &ifr) < 0) { perror("SIOCGIFMTU");