cansequence: add option to ignore classical CAN frames

pull/476/head
Marc Kleine-Budde 2023-11-29 18:28:32 +01:00
parent bd835f2ca2
commit 642190647e
1 changed files with 15 additions and 1 deletions

View File

@ -37,6 +37,7 @@ static bool running = true;
static volatile sig_atomic_t signal_num; static volatile sig_atomic_t signal_num;
static bool infinite = true; static bool infinite = true;
static bool canfd = false; static bool canfd = false;
static bool canfd_strict = false;
static unsigned int drop_until_quit; static unsigned int drop_until_quit;
static unsigned int drop_count; static unsigned int drop_count;
static bool use_poll = false; static bool use_poll = false;
@ -66,6 +67,7 @@ static void print_usage(char *prg)
"Options:\n" "Options:\n"
" -e, --extended send/receive extended frames\n" " -e, --extended send/receive extended frames\n"
" -f, --canfd send/receive CAN-FD CAN frames\n" " -f, --canfd send/receive CAN-FD CAN frames\n"
" -s, --strict refuse classical CAN frames in CAN-FD mode\n"
" -b, --brs send CAN-FD CAN frames with bitrate switch (BRS)\n" " -b, --brs send CAN-FD CAN frames with bitrate switch (BRS)\n"
" -i, --identifier=ID CAN Identifier (default = %u)\n" " -i, --identifier=ID CAN Identifier (default = %u)\n"
" --loop=COUNT send message COUNT times\n" " --loop=COUNT send message COUNT times\n"
@ -151,6 +153,12 @@ static void do_receive()
sequence_rx = frame.data[0]; sequence_rx = frame.data[0];
if (canfd_strict && nbytes == CAN_MTU) {
if (verbose > 1)
printf("sequence CNT: 0x%07x RX: 0x%02x (ignoring classical CAN frame)\n", sequence, sequence_rx);
continue;
}
if (sequence_init) { if (sequence_init) {
sequence_init = false; sequence_init = false;
sequence = sequence_rx; sequence = sequence_rx;
@ -291,7 +299,7 @@ int main(int argc, char **argv)
{ 0, 0, 0, 0 }, { 0, 0, 0, 0 },
}; };
while ((opt = getopt_long(argc, argv, "efbi:pq::rvh?", long_options, NULL)) != -1) { while ((opt = getopt_long(argc, argv, "efsbi:pq::rvh?", long_options, NULL)) != -1) {
switch (opt) { switch (opt) {
case 'e': case 'e':
extended = true; extended = true;
@ -301,6 +309,10 @@ int main(int argc, char **argv)
canfd = true; canfd = true;
break; break;
case 's':
canfd_strict = true;
break;
case 'b': case 'b':
brs = true; /* bitrate switch implies CAN-FD */ brs = true; /* bitrate switch implies CAN-FD */
canfd = true; canfd = true;
@ -409,6 +421,8 @@ int main(int argc, char **argv)
printf("error when enabling CAN FD support\n"); printf("error when enabling CAN FD support\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else {
canfd_strict = false;
} }
if (brs) if (brs)