From 1e2c96e4943189997e261554aebe7d3ce4827732 Mon Sep 17 00:00:00 2001 From: Vincent Mailhol Date: Wed, 4 Nov 2020 01:51:30 +0900 Subject: [PATCH] cangen: allow DLC > 8 in increment generation mode if -8 option is given 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 --- cangen.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/cangen.c b/cangen.c index 5c86f26..4096165 100644 --- a/cangen.c +++ b/cangen.c @@ -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,6 +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 +508,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; } }