canfdtest: Add extended frame format support

Added the '-e' command line option to enable 29-bit CAN ID.

Signed-off-by: RICCIARDI-Adrien <adrien.ricciardi@hotmail.fr>
pull/378/head
RICCIARDI-Adrien 2022-09-08 17:08:53 +02:00
parent e602e391a5
commit 8e66a0bae3
1 changed files with 19 additions and 3 deletions

View File

@ -58,6 +58,7 @@ static int has_pong_id = 0;
static int is_can_fd = 0; static int is_can_fd = 0;
static int bit_rate_switch = 0; static int bit_rate_switch = 0;
static int msg_len = CAN_MSG_LEN; static int msg_len = CAN_MSG_LEN;
static int is_extended_frame_format = 0;
static void print_usage(char *prg) static void print_usage(char *prg)
{ {
@ -68,6 +69,7 @@ static void print_usage(char *prg)
"Options:\n" "Options:\n"
" -b (enable CAN FD Bit Rate Switch)\n" " -b (enable CAN FD Bit Rate Switch)\n"
" -d (use CAN FD frames instead of classic CAN)\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" " -f COUNT (number of frames in flight, default: %d)\n"
" -g (generate messages)\n" " -g (generate messages)\n"
" -i ID (CAN ID to use for frames to DUT (ping), default %x)\n" " -i ID (CAN ID to use for frames to DUT (ping), default %x)\n"
@ -420,7 +422,7 @@ int main(int argc, char *argv[])
signal(SIGHUP, signal_handler); signal(SIGHUP, signal_handler);
signal(SIGINT, 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) { switch (opt) {
case 'b': case 'b':
bit_rate_switch = 1; bit_rate_switch = 1;
@ -430,6 +432,10 @@ int main(int argc, char *argv[])
is_can_fd = 1; is_can_fd = 1;
break; break;
case 'e':
is_extended_frame_format = 1;
break;
case 'f': case 'f':
inflight_count = atoi(optarg); inflight_count = atoi(optarg);
break; break;
@ -439,7 +445,7 @@ int main(int argc, char *argv[])
break; break;
case 'i': case 'i':
can_id_ping = strtoul(optarg, NULL, 16) & CAN_SFF_MASK; can_id_ping = strtoul(optarg, NULL, 16);
break; break;
case 'l': case 'l':
@ -447,7 +453,7 @@ int main(int argc, char *argv[])
break; break;
case 'o': case 'o':
can_id_pong = strtoul(optarg, NULL, 16) & CAN_SFF_MASK; can_id_pong = strtoul(optarg, NULL, 16);
has_pong_id = 1; has_pong_id = 1;
break; break;
@ -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) if ((argc - optind) != 1)
print_usage(basename(argv[0])); print_usage(basename(argv[0]));
intf_name = argv[optind]; intf_name = argv[optind];