All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kurt Van Dijck <dev.kurt@vandijck-laurijssen.be>
To: linux-can@vger.kernel.org
Cc: Kurt Van Dijck <dev.kurt@vandijck-laurijssen.be>
Subject: [PATCH 1/2] canbusload: count full payload for CANFD frames
Date: Thu, 24 Jun 2021 05:21:10 +0200	[thread overview]
Message-ID: <20210624032111.26272-1-dev.kurt@vandijck-laurijssen.be> (raw)

Signed-off-by: Kurt Van Dijck <dev.kurt@vandijck-laurijssen.be>
---
 canbusload.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/canbusload.c b/canbusload.c
index d6bfd78..bd74cb5 100644
--- a/canbusload.c
+++ b/canbusload.c
@@ -237,7 +237,7 @@ int main(int argc, char **argv)
 	int opt;
 	char *ptr, *nptr;
 	struct sockaddr_can addr;
-	struct can_frame frame;
+	struct canfd_frame frame;
 	int nbytes, i;
 	struct ifreq ifr;
 	sigset_t sigmask, savesigmask;
@@ -351,6 +351,9 @@ int main(int argc, char **argv)
 #ifdef DEBUG
 		printf("using interface name '%s'.\n", ifr.ifr_name);
 #endif
+		/* try to switch the socket into CAN FD mode */
+		const int canfd_on = 1;
+		setsockopt(s[i], SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &canfd_on, sizeof(canfd_on));
 
 		if (ioctl(s[i], SIOCGIFINDEX, &ifr) < 0) {
 			perror("SIOCGIFINDEX");
@@ -402,9 +405,9 @@ int main(int argc, char **argv)
 				}
 
 				stat[i].recv_frames++;
-				stat[i].recv_bits_payload += frame.can_dlc*8;
-				stat[i].recv_bits_total += can_frame_length((struct canfd_frame*)&frame,
-									    mode, sizeof(frame));
+				stat[i].recv_bits_payload += frame.len*8;
+				stat[i].recv_bits_total += can_frame_length(&frame,
+									    mode, nbytes);
 			}
 		}
 	}
-- 
2.25.0


             reply	other threads:[~2021-06-24  3:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-24  3:21 Kurt Van Dijck [this message]
2021-06-24  3:21 ` [PATCH 2/2] canbusload: count databitrate seperately Kurt Van Dijck
2021-06-24  6:25   ` Marc Kleine-Budde
2021-06-24 10:48     ` Kurt Van Dijck
2021-06-24 10:56       ` Marc Kleine-Budde
2021-06-24  6:22 ` [PATCH 1/2] canbusload: count full payload for CANFD frames Marc Kleine-Budde

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=20210624032111.26272-1-dev.kurt@vandijck-laurijssen.be \
    --to=dev.kurt@vandijck-laurijssen.be \
    --cc=linux-can@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.