📄 canconfig.c.svn-base
字号:
default : bitrate_value = 0;
}
opt = ioctl(sockfd, SIOC_CAN_SET_BITRATE, &bitrate_value);
printf("ioctl(%X) returned the value %d\n", SIOC_CAN_SET_BITRATE, opt);
return 0;
}
//----------------------------------------------------------------------------//
// main() //
// //
//----------------------------------------------------------------------------//
int main(int argc, char **argv)
{
int opt;
int sockfd;
int can_port = 0;
char buffer[80];
int msg_count = 0;
int slSockOptT = 125;
int level;
int bitrate;
//Option to show all can_ports
int opt_a = 0, opt_up=0, opt_down=0, opt_btr0=0, opt_btr1=0, opt_sjw=0, opt_bitrate=0;
int index = 0;
char **argv_tmp;
struct can_frame frame;
// Was erfüllt diese Funktion ???
signal(SIGINT, quit);
/* Find any entered options. */
argc--;
argv++;
while (argc && (*argv[0] == '-')) {
if (!strcmp(*argv, "-a"))
opt_a = 1;
else if (!strcmp(*argv, "-?") || !strcmp(*argv, "-h") ||
!strcmp(*argv, "-help") || !strcmp(*argv, "--help")) {
usage();
exit (0);
} else {
printf(" canconfig: option `%s' not recognised.\n", argv[0]);
printf(" canconfig: `--help' gives usage information.\n");
exit (1);
}
argv++;
argc--;
}
//Open new Socket filedescriptor
sockfd = socket(AF_CAN, SOCK_RAW, 0);
if(sockfd < 0)
{
printf("Can't open socket AF_CAN\n");
exit (1);
}
// Der Wert für den CAN_PORT_MAX wird noch übergeben!!!
//Show all information of all CAN-Ports
if ((argc == 0) || (opt_a == 1)) {
for(index=0; index <= CAN_PORT_MAX; index++) {
if (connect_can(index,sockfd) == 0) {
can_info(index,sockfd,slSockOptT);
} //else printf(" Can not connect to CAN-Port %i\n",index);
}
exit_prog(sockfd,0);
//exit (0);
}
argv_tmp = argv;
// The next argument is either an address family name, get the can_port number and store in can_port
if (get_can_nr(*argv_tmp) >= 0) {
printf("Der eingegeben Can Port ist: %i\n",get_can_nr(*argv_tmp));
can_port = get_can_nr(*argv_tmp);
} else if (get_can_nr(*argv_tmp) == -1) {
printf(" canconfig: the device number for can was not entered.\n");
printf(" canconfig: `--help' gives usage information.\n");
exit_prog(sockfd,1);
//exit (1);
} else if (get_can_nr(*argv_tmp) == -2) {
printf(" canconfig: the wrong device name was entered.\n");
printf(" canconfig: `--help' gives usage information.\n");
exit_prog(sockfd,1);
//exit (1);
}
if (connect_can(can_port,sockfd) == 0) {
printf("Successfully conected to CAN-Port %i\n",index);
} else {
printf(" Can not connect to CAN-Port %i\n",index);
exit_prog(sockfd,1);
//exit(1);
}
argc--;
//printf("Anzahl der Parameter: %i\n", argc);
// The next arguments are options for selectet CAN-Port
// get this options
if (argc > 0) {
while (argc > 0) {
argv_tmp++;
//printf("hier ist die Option: %i\n", get_can_opt(*argv_tmp));
switch (get_can_opt(*argv_tmp)) {
case -1 :
printf(" canconfig: you have entered not recognised option.\n");
printf(" canconfig: `--help' gives usage information.\n");
exit_prog(sockfd,1);
//exit(1);
break;
// wenn die Funktion up gewählt ist, dann darf die down Funktion nicht gewählt sein
case 1 :
if (opt_down == 1) {
printf(" canconfig: you have entered 'up' and 'down' option.\n");
printf(" canconfig: `--help' gives usage information.\n");
exit_prog(sockfd,1);
//exit(1);
}
else {
opt_up = 1;
// Hier soll die Funktion aufgerufen werden, die up-Funktion durchführt
}
break;
case 2 :
if (opt_up == 1) {
printf(" canconfig: you have entered 'up' and 'down' option.\n");
printf(" canconfig: `--help' gives usage information.\n");
exit_prog(sockfd,1);
//exit(1);
}
else {
opt_down = 1;
// Hier soll die Funktion aufgerufen werden, die down-Funktion durchführt
}
break;
// wenn die Funktion bitrate gewählt ist, dann dürfen die Funktionen
// btr0, btr1 und sjw nicht gewählt sein!
case 3 :
if (opt_bitrate == 1) {
printf(" canconfig: you have entered wrong combination of bitrate options.\n");
printf(" canconfig: `--help' gives usage information.\n");
exit_prog(sockfd,1);
//exit(1);
}
else
opt_btr0 = 1;
break;
case 4 :
if (opt_bitrate == 1) {
printf(" canconfig: you have entered wrong combination of bitrate options.\n");
printf(" canconfig: `--help' gives usage information.\n");
exit_prog(sockfd,1);
//exit(1);
}
else
opt_btr1 = 1;
break;
case 5 :
if (opt_bitrate == 1) {
printf(" canconfig: you have entered wrong combination of bitrate options.\n");
printf(" canconfig: `--help' gives usage information.\n");
exit_prog(sockfd,1);
//exit(1);
}
else
opt_sjw = 1;
break;
case 6 :
if ((opt_btr0 == 1) || (opt_btr1 == 1) || (opt_sjw == 1)) {
printf(" canconfig: you have entered wrong combination of bitrate options.\n");
printf(" canconfig: `--help' gives usage information.\n");
exit_prog(sockfd,1);
//exit(1);
}
else {
opt_bitrate = 1;
bitrate = get_bitrate(*argv_tmp);
printf("Hie ist eure gewählte Bitrate: %i\n",bitrate);
// Hier soll die Funktion aufgerufen werden, die die neue bitrate festlegt
set_can_bitrate(sockfd,can_port,bitrate);
}
break;
case 7 :
usage();
exit_prog(sockfd,0);
break;
}
argc--;
}
// Wenn alle drei Funktionen btr0, btr1 und sjw eingegeben wurden,
// so sollen nun die einstellungen übermittelt werden
if (opt_sjw & opt_btr1 & opt_btr0) {
// Hier soll nun die Funktion aufgerufen werden, die diese Einstellungen übermittelt
}
} else // No options were entered, so show information for selected CAN-Port
if (connect_can(can_port,sockfd) == 0) {
can_info(can_port,sockfd,slSockOptT);
} //else printf(" Can not connect to CAN-Port %i\n",index);
//----------------------------------------------------------
// set socket options
//
//opt = ioctl(sockfd, SIOC_CAN_SET_BITRATE, &slSockOptT);
//printf("ioctl(%X) returned the value %d\n", SIOC_CAN_SET_BITRATE, opt);
//opt = getsockopt(sockfd, SOL_SOCKET, 1, &slSockOptT, sizeof(slSockOptT));
//printf("getsockopt() returned the value %d\n", opt);
exit_prog(sockfd,0);
// close(sockfd);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -