* [PATCH] cangen: allow DLC > 8 in increment generation mode if -8 option is given
@ 2020-11-03 16:51 Vincent Mailhol
2020-11-03 17:01 ` Marc Kleine-Budde
0 siblings, 1 reply; 3+ messages in thread
From: Vincent Mailhol @ 2020-11-03 16:51 UTC (permalink / raw)
To: linux-can, Oliver Hartkopp; +Cc: Marc Kleine-Budde, Vincent Mailhol
Currently, the -8 option allows DLCs greater than 8 in mix mode only.
Add the option to also generate such DLCs in increment
mode. e.g.: 'cangen -8 -Li can0'
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
---
cangen.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/cangen.c b/cangen.c
index 5c86f26..06a1931 100644
--- a/cangen.c
+++ b/cangen.c
@@ -171,7 +171,7 @@ int main(int argc, char **argv)
struct pollfd fds;
struct sockaddr_can addr;
- static struct canfd_frame frame;
+ static struct canfd_frame frame = { 0 };
struct can_frame *ccf = (struct can_frame *)&frame;
int nbytes;
int i;
@@ -386,7 +386,6 @@ int main(int argc, char **argv)
while (running) {
frame.flags = 0;
- ccf->len8_dlc = 0;
if (count && (--count == 0))
running = 0;
@@ -428,7 +427,8 @@ int main(int argc, char **argv)
ccf->len8_dlc = frame.len;
frame.len = 8; /* for about 50% of the frames */
- }
+ } else
+ ccf->len8_dlc = 0;
}
}
@@ -507,12 +507,20 @@ resend:
if (dlc_mode == MODE_INCREMENT) {
incdlc++;
+ incdlc %= CAN_MAX_RAW_DLC + 1;
- if (canfd && !mix) {
- incdlc &= 0xF;
+ if (canfd && !mix)
frame.len = can_dlc2len(incdlc);
+ else if (len8_dlc) {
+ if (incdlc > CAN_MAX_DLEN) {
+ frame.len = CAN_MAX_DLEN;
+ ccf->len8_dlc = incdlc;
+ } else {
+ frame.len = incdlc;
+ ccf->len8_dlc = 0;
+ }
} else {
- incdlc %= 9;
+ incdlc %= CAN_MAX_DLEN + 1;
frame.len = incdlc;
}
}
--
2.26.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] cangen: allow DLC > 8 in increment generation mode if -8 option is given
2020-11-03 16:51 [PATCH] cangen: allow DLC > 8 in increment generation mode if -8 option is given Vincent Mailhol
@ 2020-11-03 17:01 ` Marc Kleine-Budde
2020-11-03 18:38 ` Oliver Hartkopp
0 siblings, 1 reply; 3+ messages in thread
From: Marc Kleine-Budde @ 2020-11-03 17:01 UTC (permalink / raw)
To: Vincent Mailhol, linux-can, Oliver Hartkopp
[-- Attachment #1.1: Type: text/plain, Size: 2126 bytes --]
On 11/3/20 5:51 PM, Vincent Mailhol wrote:
> Currently, the -8 option allows DLCs greater than 8 in mix mode only.
>
> Add the option to also generate such DLCs in increment
> mode. e.g.: 'cangen -8 -Li can0'
>
> Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
> ---
> cangen.c | 20 ++++++++++++++------
> 1 file changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/cangen.c b/cangen.c
> index 5c86f26..06a1931 100644
> --- a/cangen.c
> +++ b/cangen.c
> @@ -171,7 +171,7 @@ int main(int argc, char **argv)
> struct pollfd fds;
>
> struct sockaddr_can addr;
> - static struct canfd_frame frame;
> + static struct canfd_frame frame = { 0 };
> struct can_frame *ccf = (struct can_frame *)&frame;
> int nbytes;
> int i;
> @@ -386,7 +386,6 @@ int main(int argc, char **argv)
>
> while (running) {
> frame.flags = 0;
> - ccf->len8_dlc = 0;
>
> if (count && (--count == 0))
> running = 0;
> @@ -428,7 +427,8 @@ int main(int argc, char **argv)
> ccf->len8_dlc = frame.len;
>
> frame.len = 8; /* for about 50% of the frames */
> - }
> + } else
> + ccf->len8_dlc = 0;
nitpick:
please use { } on the else side, too
> }
> }
>
> @@ -507,12 +507,20 @@ resend:
> if (dlc_mode == MODE_INCREMENT) {
>
> incdlc++;
> + incdlc %= CAN_MAX_RAW_DLC + 1;
>
> - if (canfd && !mix) {
> - incdlc &= 0xF;
> + if (canfd && !mix)
> frame.len = can_dlc2len(incdlc);
> + else if (len8_dlc) {
> + if (incdlc > CAN_MAX_DLEN) {
> + frame.len = CAN_MAX_DLEN;
> + ccf->len8_dlc = incdlc;
> + } else {
> + frame.len = incdlc;
> + ccf->len8_dlc = 0;
> + }
> } else {
> - incdlc %= 9;
> + incdlc %= CAN_MAX_DLEN + 1;
> frame.len = incdlc;
> }
> }
>
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung West/Dortmund | Phone: +49-231-2826-924 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] cangen: allow DLC > 8 in increment generation mode if -8 option is given
2020-11-03 17:01 ` Marc Kleine-Budde
@ 2020-11-03 18:38 ` Oliver Hartkopp
0 siblings, 0 replies; 3+ messages in thread
From: Oliver Hartkopp @ 2020-11-03 18:38 UTC (permalink / raw)
To: Marc Kleine-Budde, Vincent Mailhol, linux-can
On 03.11.20 18:01, Marc Kleine-Budde wrote:
> On 11/3/20 5:51 PM, Vincent Mailhol wrote:
>> Currently, the -8 option allows DLCs greater than 8 in mix mode only.
>>
>> Add the option to also generate such DLCs in increment
>> mode. e.g.: 'cangen -8 -Li can0'
>>
>> Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
>> ---
>> cangen.c | 20 ++++++++++++++------
>> 1 file changed, 14 insertions(+), 6 deletions(-)
>>
>> diff --git a/cangen.c b/cangen.c
>> index 5c86f26..06a1931 100644
>> --- a/cangen.c
>> +++ b/cangen.c
>> @@ -171,7 +171,7 @@ int main(int argc, char **argv)
>> struct pollfd fds;
>>
>> struct sockaddr_can addr;
>> - static struct canfd_frame frame;
>> + static struct canfd_frame frame = { 0 };
I've omitted this change as a static variable is initialized with zero
by default.
>> struct can_frame *ccf = (struct can_frame *)&frame;
>> int nbytes;
>> int i;
>> @@ -386,7 +386,6 @@ int main(int argc, char **argv)
>>
>> while (running) {
>> frame.flags = 0;
>> - ccf->len8_dlc = 0;
>>
>> if (count && (--count == 0))
>> running = 0;
>> @@ -428,7 +427,8 @@ int main(int argc, char **argv)
>> ccf->len8_dlc = frame.len;
>>
>> frame.len = 8; /* for about 50% of the frames */
>> - }
>> + } else
>> + ccf->len8_dlc = 0;
>
> nitpick:
>
> please use { } on the else side, too
>
Added the {}'s and committed the patch on
https://github.com/hartkopp/can-utils.
Also added some stuff to support 'fixed' raw DLC values in combination
with the '-8' option.
Thanks,
Oliver
>> }
>> }
>>
>> @@ -507,12 +507,20 @@ resend:
>> if (dlc_mode == MODE_INCREMENT) {
>>
>> incdlc++;
>> + incdlc %= CAN_MAX_RAW_DLC + 1;
>>
>> - if (canfd && !mix) {
>> - incdlc &= 0xF;
>> + if (canfd && !mix)
>> frame.len = can_dlc2len(incdlc);
>> + else if (len8_dlc) {
>> + if (incdlc > CAN_MAX_DLEN) {
>> + frame.len = CAN_MAX_DLEN;
>> + ccf->len8_dlc = incdlc;
>> + } else {
>> + frame.len = incdlc;
>> + ccf->len8_dlc = 0;
>> + }
>> } else {
>> - incdlc %= 9;
>> + incdlc %= CAN_MAX_DLEN + 1;
>> frame.len = incdlc;
>> }
>> }
>>
>
> Marc
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-11-03 18:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-03 16:51 [PATCH] cangen: allow DLC > 8 in increment generation mode if -8 option is given Vincent Mailhol
2020-11-03 17:01 ` Marc Kleine-Budde
2020-11-03 18:38 ` Oliver Hartkopp
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).