Added support for swapped byte order representation.
parent
b5bc6349a9
commit
1be68bcc64
12
candump.c
12
candump.c
|
|
@ -109,6 +109,7 @@ void print_usage(char *prg)
|
||||||
fprintf(stderr, " -c (increment color mode level)\n");
|
fprintf(stderr, " -c (increment color mode level)\n");
|
||||||
fprintf(stderr, " -i (binary output - may exceed 80 chars/line)\n");
|
fprintf(stderr, " -i (binary output - may exceed 80 chars/line)\n");
|
||||||
fprintf(stderr, " -a (enable additional ASCII output)\n");
|
fprintf(stderr, " -a (enable additional ASCII output)\n");
|
||||||
|
fprintf(stderr, " -S (swap byte order in printed CAN data[] - marked with '%c' )\n", SWAP_DELIMITER);
|
||||||
fprintf(stderr, " -s <level> (silent mode - %d: off (default) %d: animation %d: silent)\n", SILENT_OFF, SILENT_ANI, SILENT_ON);
|
fprintf(stderr, " -s <level> (silent mode - %d: off (default) %d: animation %d: silent)\n", SILENT_OFF, SILENT_ANI, SILENT_ON);
|
||||||
fprintf(stderr, " -b <can> (bridge mode - send received frames to <can>)\n");
|
fprintf(stderr, " -b <can> (bridge mode - send received frames to <can>)\n");
|
||||||
fprintf(stderr, " -B <can> (bridge mode - like '-b' with disabled loopback)\n");
|
fprintf(stderr, " -B <can> (bridge mode - like '-b' with disabled loopback)\n");
|
||||||
|
|
@ -235,7 +236,7 @@ int main(int argc, char **argv)
|
||||||
last_tv.tv_sec = 0;
|
last_tv.tv_sec = 0;
|
||||||
last_tv.tv_usec = 0;
|
last_tv.tv_usec = 0;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "t:cias:b:B:lLh?")) != -1) {
|
while ((opt = getopt(argc, argv, "t:ciaSs:b:B:lLh?")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 't':
|
case 't':
|
||||||
timestamp = optarg[0];
|
timestamp = optarg[0];
|
||||||
|
|
@ -259,6 +260,10 @@ int main(int argc, char **argv)
|
||||||
view |= CANLIB_VIEW_ASCII;
|
view |= CANLIB_VIEW_ASCII;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'S':
|
||||||
|
view |= CANLIB_VIEW_SWAP;
|
||||||
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
silent = atoi(optarg);
|
silent = atoi(optarg);
|
||||||
if (silent > SILENT_ON) {
|
if (silent > SILENT_ON) {
|
||||||
|
|
@ -323,6 +328,11 @@ int main(int argc, char **argv)
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (logfrmt && view) {
|
||||||
|
fprintf(stderr, "Log file format selected: Please disable ASCII/BINARY/SWAP options!\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (silent == SILENT_INI) {
|
if (silent == SILENT_INI) {
|
||||||
if (log) {
|
if (log) {
|
||||||
printf("\nDisabled standard output while logging.");
|
printf("\nDisabled standard output while logging.");
|
||||||
|
|
|
||||||
58
lib.c
58
lib.c
|
|
@ -244,17 +244,34 @@ void sprint_long_canframe(char *buf , struct can_frame *cf, int view) {
|
||||||
|
|
||||||
if (view & CANLIB_VIEW_BINARY) {
|
if (view & CANLIB_VIEW_BINARY) {
|
||||||
dlen = 9; /* _10101010 */
|
dlen = 9; /* _10101010 */
|
||||||
for (i = 0; i < dlc; i++) {
|
if (view & CANLIB_VIEW_SWAP) {
|
||||||
buf[offset++] = ' ';
|
for (i = dlc - 1; i >= 0; i--) {
|
||||||
for (j = 7; j >= 0; j--)
|
buf[offset++] = (i == dlc-1)?' ':SWAP_DELIMITER;
|
||||||
buf[offset++] = (1<<j & cf->data[i])?'1':'0';
|
for (j = 7; j >= 0; j--)
|
||||||
|
buf[offset++] = (1<<j & cf->data[i])?'1':'0';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (i = 0; i < dlc; i++) {
|
||||||
|
buf[offset++] = ' ';
|
||||||
|
for (j = 7; j >= 0; j--)
|
||||||
|
buf[offset++] = (1<<j & cf->data[i])?'1':'0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buf[offset] = 0; /* terminate string */
|
buf[offset] = 0; /* terminate string */
|
||||||
} else {
|
} else {
|
||||||
dlen = 3; /* _AA */
|
dlen = 3; /* _AA */
|
||||||
for (i = 0; i < dlc; i++) {
|
if (view & CANLIB_VIEW_SWAP) {
|
||||||
sprintf(buf+offset, " %02X", cf->data[i]);
|
for (i = dlc - 1; i >= 0; i--) {
|
||||||
offset += dlen;
|
sprintf(buf+offset, "%c%02X",
|
||||||
|
(i == dlc-1)?' ':SWAP_DELIMITER,
|
||||||
|
cf->data[i]);
|
||||||
|
offset += dlen;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (i = 0; i < dlc; i++) {
|
||||||
|
sprintf(buf+offset, " %02X", cf->data[i]);
|
||||||
|
offset += dlen;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -262,16 +279,27 @@ void sprint_long_canframe(char *buf , struct can_frame *cf, int view) {
|
||||||
sprintf(buf+offset, "%*s", dlen*(8-dlc)+13, "ERRORFRAME");
|
sprintf(buf+offset, "%*s", dlen*(8-dlc)+13, "ERRORFRAME");
|
||||||
else if (view & CANLIB_VIEW_ASCII) {
|
else if (view & CANLIB_VIEW_ASCII) {
|
||||||
j = dlen*(8-dlc)+4;
|
j = dlen*(8-dlc)+4;
|
||||||
sprintf(buf+offset, "%*s", j, "'");
|
if (view & CANLIB_VIEW_SWAP) {
|
||||||
offset += j;
|
sprintf(buf+offset, "%*s", j, "`");
|
||||||
|
offset += j;
|
||||||
|
for (i = dlc - 1; i >= 0; i--)
|
||||||
|
if ((cf->data[i] > 0x1F) && (cf->data[i] < 0x7F))
|
||||||
|
buf[offset++] = cf->data[i];
|
||||||
|
else
|
||||||
|
buf[offset++] = '.';
|
||||||
|
|
||||||
for (i = 0; i < dlc; i++)
|
sprintf(buf+offset, "`");
|
||||||
if ((cf->data[i] > 0x1F) && (cf->data[i] < 0x7F))
|
} else {
|
||||||
buf[offset++] = cf->data[i];
|
sprintf(buf+offset, "%*s", j, "'");
|
||||||
else
|
offset += j;
|
||||||
buf[offset++] = '.';
|
for (i = 0; i < dlc; i++)
|
||||||
|
if ((cf->data[i] > 0x1F) && (cf->data[i] < 0x7F))
|
||||||
|
buf[offset++] = cf->data[i];
|
||||||
|
else
|
||||||
|
buf[offset++] = '.';
|
||||||
|
|
||||||
sprintf(buf+offset, "'");
|
sprintf(buf+offset, "'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
5
lib.h
5
lib.h
|
|
@ -87,7 +87,7 @@ int parse_canframe(char *cs, struct can_frame *cf);
|
||||||
* Examples:
|
* Examples:
|
||||||
*
|
*
|
||||||
* 123# -> standard CAN-Id = 0x123, dlc = 0
|
* 123# -> standard CAN-Id = 0x123, dlc = 0
|
||||||
* 12345678# -> exended CAN-Id = 0x12345678, dlc = 0
|
* 12345678# -> extended CAN-Id = 0x12345678, dlc = 0
|
||||||
* 123#R -> standard CAN-Id = 0x123, dlc = 0, RTR-frame
|
* 123#R -> standard CAN-Id = 0x123, dlc = 0, RTR-frame
|
||||||
* 7A1#r -> standard CAN-Id = 0x7A1, dlc = 0, RTR-frame
|
* 7A1#r -> standard CAN-Id = 0x7A1, dlc = 0, RTR-frame
|
||||||
*
|
*
|
||||||
|
|
@ -126,6 +126,9 @@ void sprint_canframe(char *buf , struct can_frame *cf, int sep);
|
||||||
|
|
||||||
#define CANLIB_VIEW_ASCII 0x1
|
#define CANLIB_VIEW_ASCII 0x1
|
||||||
#define CANLIB_VIEW_BINARY 0x2
|
#define CANLIB_VIEW_BINARY 0x2
|
||||||
|
#define CANLIB_VIEW_SWAP 0x4
|
||||||
|
|
||||||
|
#define SWAP_DELIMITER '`'
|
||||||
|
|
||||||
void fprint_long_canframe(FILE *stream , struct can_frame *cf, char *eol, int view);
|
void fprint_long_canframe(FILE *stream , struct can_frame *cf, char *eol, int view);
|
||||||
void sprint_long_canframe(char *buf , struct can_frame *cf, int view);
|
void sprint_long_canframe(char *buf , struct can_frame *cf, int view);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue