linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Oliver Hartkopp <socketcan@hartkopp.net>
To: "Håkan Engblom" <H.Engblom@tele-radio.com>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>,
	"linux-can@vger.kernel.org" <linux-can@vger.kernel.org>
Subject: Re: SV: Fwd: can-utils at http://gitorious.org/+linux-can-developers/linux-can/can-utils
Date: Fri, 15 Feb 2013 19:43:02 +0100	[thread overview]
Message-ID: <511E81B6.6090703@hartkopp.net> (raw)
In-Reply-To: <511E6E4E.4040502@hartkopp.net>

Just a small improvement:

RTR frames with DLC == zero are printed as before:

cansend vcan0 123#R
cansend vcan0 123#R0
cansend vcan0 123#R4

leads to

(1360953150.494945) vcan0 123#R
(1360953152.004855) vcan0 123#R
(1360953153.538162) vcan0 123#R4


And here's the patch for that:

diff --git a/lib.c b/lib.c
index 4857e80..9fb1056 100644
--- 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;
 	}

@@ -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;
 	}





On 15.02.2013 18:20, Oliver Hartkopp wrote:

> On 15.02.2013 17:49, Håkan Engblom wrote:
> 
>> Yes, the RTR is not recommended, you're right.
>>
>> In any case it would be nice to have it there as I have a slave that discards remote frames unless the DLC is the same as in the requested data. 
>>
>> To take away the error-check would be fine for me. Is something like this what you mean, just making sure I did not missunderstand you:
> 
> 
> Yes this is what i also thought of.
> 
>>
>> 	if((cs[idx] == 'R') || (cs[idx] == 'r')){ /* RTR frame */
>> 		cf->can_id |= CAN_RTR_FLAG;
>> 		cf->can_dlc = 0;
> 
> 
> This is superfluous, as the struct can_frame is always initialized to zero.
>  
> 
>> 		if(cs[++idx] && (tmp = asc2nibble(cs[idx])) <= 0x08) /* 8 is max dlc */
>> 			cf->can_dlc = tmp;
> 
> 
> The latest can-utils use struct canfd_frames => 'can_dlc' moved to 'len'
> 
>> 		return 0;
>> 	}
>>
>>
>> This would be perfictly fine with me, I've also done a quick test of this, and it seems to work. And it does not give any fault when node additional length argument is given.
> 
> 
> Yep.
> 
> I wonder if it makes sense to the length 'len' too, before accessing
> cs[++idx] ... but when cs[++idx] is zero your code is correct too.
> 
> 
> Here's my suggestion:
> 
> If it's ok for you, i can add your Signed-off-by ...
> 
> diff --git a/lib.c b/lib.c
> index 4857e80..c2baa77 100644
> --- 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;
>  	}
>  
> @@ -236,7 +241,11 @@ 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");
> +		if (cf->len <= CAN_MAX_DLC)
> +			sprintf(buf+offset, "R%d", cf->len);
> +		else
> +			sprintf(buf+offset, "R");
> +
>  		return;
>  	}
>  
> 
> 
> Regards,
> Oliver
> --
> To unsubscribe from this list: send the line "unsubscribe linux-can" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



  reply	other threads:[~2013-02-15 18:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <7073D121A5DFE9448648C0E083BEA9C96C7AA63220@vsrv6.tele-radio.ad>
2013-02-15 10:44 ` Fwd: can-utils at http://gitorious.org/+linux-can-developers/linux-can/can-utils Marc Kleine-Budde
2013-02-15 10:51   ` Yegor Yefremov
2013-02-15 16:13   ` Fwd: " Oliver Hartkopp
2013-02-15 16:49     ` SV: " Håkan Engblom
2013-02-15 17:20       ` Oliver Hartkopp
2013-02-15 18:43         ` Oliver Hartkopp [this message]
2013-02-18  9:21         ` SV: " Håkan Engblom
2013-02-18 22:03           ` Oliver Hartkopp
2013-02-17 13:00   ` Heinz-Jürgen Oertel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=511E81B6.6090703@hartkopp.net \
    --to=socketcan@hartkopp.net \
    --cc=H.Engblom@tele-radio.com \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).