⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 noiser.c

📁 can4linux-3.5.3.gz can4 linux
💻 C
字号:
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <can4linux.h>#define STDDEV "can1"#define MESSG_BLOCK 10 #define USE_RTR 1int main(int argc,char **argv){int fd;int i,sent;canmsg_t tx[100];char device[40];    if(argc == 2) {	sprintf(device, "/dev/%s", argv[1]);    }    else {	sprintf(device, "/dev/%s", STDDEV);    }    printf("using CAN device %s\n", device);        if(( fd = open(device, O_RDWR )) < 0 ) {	fprintf(stderr,"Error opening CAN device %s\n", device);        exit(1);    }    while(1){      /* fill message block with data */      for(i = 0; i < MESSG_BLOCK; i++) {        tx[i].flags = 0;	tx[i].id    = 1 + (int)( 500.0*rand()/RAND_MAX+1.0 );	sprintf( tx[i].data, "%ldabcde", tx[i].id);	printf("send: '%s' \n", tx[i].data);	tx[i].length = strlen(tx[i].data); #if USE_RTR         if(   tx[i].id == 500           || tx[i].id == 450           || tx[i].id == 400           || tx[i].id == 350           || tx[i].id == 300           || tx[i].id == 250           || tx[i].id == 200           || tx[i].id == 150            || tx[i].id == 100            || tx[i].id ==  50 )	  tx[i].flags |= MSG_RTR;#endif      }      sent=write(fd, tx, MESSG_BLOCK );      sleep(1);       if(sent <= 0) {	printf("not ready"); break;      }    }    close(fd);    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -