lib: add support for non-zero dlc values in CAN 2.0B RTR frames

As Hakan Engblom pointed out a CAN 2.0B RTR frame can contain a non-zero DLC
value which was not addressed by parse_canframe() and sprint_canframe().

This patch adds support for non-zero DLC values in a way that legacy logfiles
are still usable as the DLC can optionally be added.

Reported-by: Hakan Engblom <H.Engblom@tele-radio.com>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
This commit is contained in:
Oliver Hartkopp
2013-02-15 23:25:13 +01:00
parent e5c81aa221
commit eaf87a3bf6
2 changed files with 20 additions and 5 deletions
+12 -1
View File
@@ -169,6 +169,11 @@ int parse_canframe(char *cs, struct canfd_frame *cf) {
if((cs[idx] == 'R') || (cs[idx] == 'r')){ /* RTR frame */
cf->can_id |= CAN_RTR_FLAG;
/* check for optional DLC value for CAN 2.0B frames */
if(cs[++idx] && (tmp = asc2nibble(cs[idx])) <= CAN_MAX_DLC)
cf->len = tmp;
return ret;
}
@@ -236,7 +241,13 @@ void sprint_canframe(char *buf , struct canfd_frame *cf, int sep, int maxdlen) {
/* standard CAN frames may have RTR enabled. There are no ERR frames with RTR */
if (maxdlen == CAN_MAX_DLEN && cf->can_id & CAN_RTR_FLAG) {
sprintf(buf+offset, "R");
/* print a given CAN 2.0B DLC if it's not zero */
if (cf->len && cf->len <= CAN_MAX_DLC)
sprintf(buf+offset, "R%d", cf->len);
else
sprintf(buf+offset, "R");
return;
}