Skip to content

Commit

Permalink
canfdtest: Add extended frame format support
Browse files Browse the repository at this point in the history
Added the '-e' command line option to enable 29-bit CAN ID.

Signed-off-by: RICCIARDI-Adrien <adrien.ricciardi@hotmail.fr>
  • Loading branch information
RICCIARDI-Adrien committed Sep 9, 2022
1 parent e602e39 commit 8e66a0b
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions canfdtest.c
Expand Up @@ -58,6 +58,7 @@ static int has_pong_id = 0;
static int is_can_fd = 0;
static int bit_rate_switch = 0;
static int msg_len = CAN_MSG_LEN;
static int is_extended_frame_format = 0;

static void print_usage(char *prg)
{
Expand All @@ -68,6 +69,7 @@ static void print_usage(char *prg)
"Options:\n"
" -b (enable CAN FD Bit Rate Switch)\n"
" -d (use CAN FD frames instead of classic CAN)\n"
" -e (use 29-bit extended frame format instead of classic 11-bit one)\n"
" -f COUNT (number of frames in flight, default: %d)\n"
" -g (generate messages)\n"
" -i ID (CAN ID to use for frames to DUT (ping), default %x)\n"
Expand Down Expand Up @@ -420,7 +422,7 @@ int main(int argc, char *argv[])
signal(SIGHUP, signal_handler);
signal(SIGINT, signal_handler);

while ((opt = getopt(argc, argv, "bdf:gi:l:o:s:vx?")) != -1) {
while ((opt = getopt(argc, argv, "bdef:gi:l:o:s:vx?")) != -1) {
switch (opt) {
case 'b':
bit_rate_switch = 1;
Expand All @@ -430,6 +432,10 @@ int main(int argc, char *argv[])
is_can_fd = 1;
break;

case 'e':
is_extended_frame_format = 1;
break;

case 'f':
inflight_count = atoi(optarg);
break;
Expand All @@ -439,15 +445,15 @@ int main(int argc, char *argv[])
break;

case 'i':
can_id_ping = strtoul(optarg, NULL, 16) & CAN_SFF_MASK;
can_id_ping = strtoul(optarg, NULL, 16);
break;

case 'l':
test_loops = atoi(optarg);
break;

case 'o':
can_id_pong = strtoul(optarg, NULL, 16) & CAN_SFF_MASK;
can_id_pong = strtoul(optarg, NULL, 16);
has_pong_id = 1;
break;

Expand Down Expand Up @@ -493,6 +499,16 @@ int main(int argc, char *argv[])
}
}

if (is_extended_frame_format) {
can_id_ping &= CAN_EFF_MASK;
can_id_ping |= CAN_EFF_FLAG;
can_id_pong &= CAN_EFF_MASK;
can_id_pong |= CAN_EFF_FLAG;
} else {
can_id_ping &= CAN_SFF_MASK;
can_id_pong &= CAN_SFF_MASK;
}

if ((argc - optind) != 1)
print_usage(basename(argv[0]));
intf_name = argv[optind];
Expand Down

0 comments on commit 8e66a0b

Please sign in to comment.