/*
- * $Id$
- */
-
-/*
* canbusload.c
*
* Copyright (c) 2002-2008 Volkswagen Group Electronic Research
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
- * Send feedback to <socketcan-users@lists.berlios.de>
+ * Send feedback to <linux-can@vger.kernel.org>
*
*/
#include <linux/can/raw.h>
#include "terminal.h"
+#include "canframelen.h"
#define MAXSOCK 16 /* max. number of CAN interfaces given on the cmdline */
static unsigned char timestamp;
static unsigned char color;
static unsigned char bargraph;
+static enum cfl_mode mode = CFL_WORSTCASE;
static char *prg;
void print_usage(char *prg)
fprintf(stderr, " -c (colorize lines)\n");
fprintf(stderr, " -b (show bargraph in %d%% resolution)\n", PERCENTRES);
fprintf(stderr, " -r (redraw the terminal - similar to top)\n");
+ fprintf(stderr, " -i (ignore bitstuffing in bandwidth calculation)\n");
+ fprintf(stderr, " -e (exact calculation of stuffed bits)\n");
fprintf(stderr, "\n");
fprintf(stderr, "Up to %d CAN interfaces with mandatory bitrate can be specified on the \n", MAXSOCK);
fprintf(stderr, "commandline in the form: <ifname>@<bitrate>\n\n");
fprintf(stderr, "The bitrate is mandatory as it is needed to know the CAN bus bitrate to\n");
fprintf(stderr, "calcultate the bus load percentage based on the received CAN frames.\n");
+ fprintf(stderr, "Due to the bitstuffing estimation the calculated busload may exceed 100%%.\n");
fprintf(stderr, "For each given interface the data is presented in one line which contains:\n\n");
fprintf(stderr, "(interface) (received CAN frames) (used bits total) (used bits for payload)\n");
fprintf(stderr, "\nExample:\n");
fprintf(stderr, "\nuser$> canbusload can0@100000 can1@500000 can2@500000 can3@500000 -r -t -b -c\n\n");
fprintf(stderr, "%s 2008-05-27 15:18:49\n", prg);
- fprintf(stderr, " can0@100000 805 74491 36656 74%% |XXXXXXXXXXXXXX......|\n");
- fprintf(stderr, " can1@500000 796 75140 37728 15%% |XXX.................|\n");
- fprintf(stderr, " can2@500000 0 0 0 0%% |....................|\n");
- fprintf(stderr, " can3@500000 47 4633 2424 0%% |....................|\n");
+ fprintf(stderr, " can0@100000 805 74491 36656 74%% |XXXXXXXXXXXXXX......|\n");
+ fprintf(stderr, " can1@500000 796 75140 37728 15%% |XXX.................|\n");
+ fprintf(stderr, " can2@500000 0 0 0 0%% |....................|\n");
+ fprintf(stderr, " can3@500000 47 4633 2424 0%% |....................|\n");
fprintf(stderr, "\n");
}
for (i=0; i<currmax; i++) {
- if (color)
+ if (color) {
if (i%2)
printf("%s", FGRED);
else
printf("%s", FGBLUE);
+ }
if (stat[i].bitrate)
percent = (stat[i].recv_bits_total*100)/stat[i].bitrate;
else
percent = 0;
- printf(" %*s@%-*d %4d %6d %6d %3d%%",
+ printf(" %*s@%-*d %5d %7d %6d %3d%%",
max_devname_len, stat[i].devname,
max_bitrate_len, stat[i].bitrate,
stat[i].recv_frames,
if (bargraph) {
- printf(" |");
+ printf(" |");
+
+ if (percent > 100)
+ percent = 100;
for (j=0; j < NUMBAR; j++){
if (j < percent/PERCENTRES)
}
printf("\n");
+ fflush(stdout);
alarm(1);
}
prg = basename(argv[0]);
- while ((opt = getopt(argc, argv, "rtbch?")) != -1) {
+ while ((opt = getopt(argc, argv, "rtbcieh?")) != -1) {
switch (opt) {
case 'r':
redraw = 1;
color = 1;
break;
+ case 'i':
+ mode = CFL_NO_BITSTUFFING;
+ break;
+
+ case 'e':
+ mode = CFL_EXACT;
+ break;
+
default:
print_usage(prg);
exit(1);
stat[i].recv_frames++;
stat[i].recv_bits_payload += frame.can_dlc*8;
- stat[i].recv_bits_total += frame.can_dlc*8;
- if (frame.can_id & CAN_EFF_FLAG)
- stat[i].recv_bits_total += 67;
- else
- stat[i].recv_bits_total += 47;
+ stat[i].recv_bits_total += can_frame_length((struct canfd_frame*)&frame,
+ mode, sizeof(frame));
}
}
}