]> rtime.felk.cvut.cz Git - can-utils.git/blobdiff - lib.c
slcanpty: declare command buffer static
[can-utils.git] / lib.c
diff --git a/lib.c b/lib.c
index 4857e8081c66cfc34ee8b738df5840c6f60c3c97..2755c80f5c14cb190cc9c94072a9eb6108f5d90d 100644 (file)
--- a/lib.c
+++ b/lib.c
@@ -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;
        }
 
@@ -187,7 +192,7 @@ int parse_canframe(char *cs, struct canfd_frame *cf) {
 
        for (i=0, dlen=0; i < maxdlen; i++){
 
-               if(cs[idx] == DATA_SEPERATOR) /* skip (optional) seperator */
+               if(cs[idx] == DATA_SEPERATOR) /* skip (optional) separator */
                        idx++;
 
                if(idx >= len) /* end of string => end of data */
@@ -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;
        }