log2asc: reorder code to prepare CAN FD support
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>pull/203/head
parent
df0b25c17e
commit
ed9c646608
59
log2asc.c
59
log2asc.c
|
|
@ -69,15 +69,45 @@ void print_usage(char *prg)
|
||||||
fprintf(stderr, " -n (set newline to cr/lf - default lf)\n");
|
fprintf(stderr, " -n (set newline to cr/lf - default lf)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void can_asc(struct canfd_frame *cf, int devno, FILE *outfile)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char id[10];
|
||||||
|
|
||||||
|
fprintf(outfile, "%-2d ", devno); /* channel number left aligned */
|
||||||
|
|
||||||
|
if (cf->can_id & CAN_ERR_FLAG)
|
||||||
|
fprintf(outfile, "ErrorFrame");
|
||||||
|
else {
|
||||||
|
sprintf(id, "%X%c", cf->can_id & CAN_EFF_MASK,
|
||||||
|
(cf->can_id & CAN_EFF_FLAG)?'x':' ');
|
||||||
|
fprintf(outfile, "%-15s Rx ", id);
|
||||||
|
|
||||||
|
if (cf->can_id & CAN_RTR_FLAG)
|
||||||
|
fprintf(outfile, "r"); /* RTR frame */
|
||||||
|
else {
|
||||||
|
fprintf(outfile, "d %d", cf->len); /* data frame */
|
||||||
|
|
||||||
|
for (i = 0; i < cf->len; i++) {
|
||||||
|
fprintf(outfile, " %02X", cf->data[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void canfd_asc(struct canfd_frame *cf, int devno, FILE *outfile)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
static char buf[BUFSZ], device[BUFSZ], ascframe[BUFSZ], id[10];
|
static char buf[BUFSZ], device[BUFSZ], ascframe[BUFSZ];
|
||||||
|
|
||||||
struct canfd_frame cf;
|
struct canfd_frame cf;
|
||||||
static struct timeval tv, start_tv;
|
static struct timeval tv, start_tv;
|
||||||
FILE *infile = stdin;
|
FILE *infile = stdin;
|
||||||
FILE *outfile = stdout;
|
FILE *outfile = stdout;
|
||||||
static int maxdev, devno, i, crlf, d4, opt;
|
static int maxdev, devno, i, crlf, d4, opt, mtu;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "I:O:4n?")) != -1) {
|
while ((opt = getopt(argc, argv, "I:O:4n?")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
|
|
@ -162,7 +192,8 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (devno) { /* only convert for selected CAN devices */
|
if (devno) { /* only convert for selected CAN devices */
|
||||||
if (parse_canframe(ascframe, &cf) != CAN_MTU) /* no CAN FD support so far */
|
mtu = parse_canframe(ascframe, &cf);
|
||||||
|
if ((mtu != CAN_MTU) && (mtu != CANFD_MTU))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
tv.tv_sec = tv.tv_sec - start_tv.tv_sec;
|
tv.tv_sec = tv.tv_sec - start_tv.tv_sec;
|
||||||
|
|
@ -177,25 +208,11 @@ int main(int argc, char **argv)
|
||||||
else
|
else
|
||||||
fprintf(outfile, "%4ld.%06ld ", tv.tv_sec, tv.tv_usec);
|
fprintf(outfile, "%4ld.%06ld ", tv.tv_sec, tv.tv_usec);
|
||||||
|
|
||||||
fprintf(outfile, "%-2d ", devno); /* channel number left aligned */
|
if (mtu == CAN_MTU)
|
||||||
|
can_asc(&cf, devno, outfile);
|
||||||
|
else
|
||||||
|
canfd_asc(&cf, devno, outfile);
|
||||||
|
|
||||||
if (cf.can_id & CAN_ERR_FLAG)
|
|
||||||
fprintf(outfile, "ErrorFrame");
|
|
||||||
else {
|
|
||||||
sprintf(id, "%X%c", cf.can_id & CAN_EFF_MASK,
|
|
||||||
(cf.can_id & CAN_EFF_FLAG)?'x':' ');
|
|
||||||
fprintf(outfile, "%-15s Rx ", id);
|
|
||||||
|
|
||||||
if (cf.can_id & CAN_RTR_FLAG)
|
|
||||||
fprintf(outfile, "r"); /* RTR frame */
|
|
||||||
else {
|
|
||||||
fprintf(outfile, "d %d", cf.len); /* data frame */
|
|
||||||
|
|
||||||
for (i = 0; i < cf.len; i++) {
|
|
||||||
fprintf(outfile, " %02X", cf.data[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (crlf)
|
if (crlf)
|
||||||
fprintf(outfile, "\r");
|
fprintf(outfile, "\r");
|
||||||
fprintf(outfile, "\n");
|
fprintf(outfile, "\n");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue