📄 cantxrx.c
字号:
#include <stdio.h>#include <stdlib.h>//#include <unistd.h>#include <fcntl.h>#include <pthread.h>#include <asm-arm/arch-s3c2410/S3C2410.h>//#include <asm-arm/arch/hardware.h>//#inclued <asm-arm/arch/bitfield.h>#include "mcpcan.h"#include "spi_cmd.h"#include "def.h"//#include "2410addr.h"#include "directio.h"//#include "option.h"//#include "2410lib.h"#define DEBUG#ifdef DEBUG#define dbgprintf(S) printf(S)#else#define dbgprintf(S)#endifint fd[2];void recv(void * arg){ struct mcpcan_data *datagramptr = (struct mcpcan_data *)arg; while(1) { //int datalen; read(fd[1], datagramptr, sizeof(struct mcpcan_data)); printf("data_receive.BufNo = %d\n",datagramptr->BufNo); printf("data_receive.IdType = %d\n",datagramptr->IdType); printf("data_receive.id = %d\n",datagramptr->id); printf("data_receive.DataLen = %d\n",datagramptr->DataLen); printf("data_receive.data = %s\n",datagramptr->data); } }int main(){ pthread_t id; int ret; struct mcpcan_data data_receive; struct mcpcan_data data_send; /* 打印提示信息 */ printf("---can总线测试程序---\n"); data_send.BufNo = TXBUF0; data_send.IdType = STANDID; data_send.id = 23; data_send.DataLen = 8; strcpy(data_send.data, "-CVTECH-"); data_receive.BufNo = 0;
data_receive.IdType = 0; data_receive.id = 0; data_receive.DataLen = 0; memset(data_receive.data,9,0x0); fd [0]= open("/dev/can0",O_RDWR); fd [1]= open("/dev/can1",O_RDWR); if(fd[0] < 0) { printf("Open device can0 failed.\n"); return fd[0]; } printf("Open device can0 success.\n"); if(fd[1]<0) { printf("Open device can1 failed.\n"); return fd[1]; } printf("Open device can1 success.\n"); ret=pthread_create(&id,NULL,(void *)recv, &data_receive); if(ret!=0){ printf ("Create pthread error!\n"); exit (1); } printf("Create pthread success.\n"); while(1) { sleep(9); write(fd[0], &data_send, sizeof(struct mcpcan_data)); printf("send datagram.\n"); printf("the data sended is %s.\n", data_send.data); } /*while(1) { int datalen; read(fd, &data_receive, sizeof(struct mcpcan_data)); printf("data_receive.BufNo = %d\n",data_receive.BufNo); printf("data_receive.IdType = %d\n",data_receive.IdType); printf("data_receive.id = %d\n",data_receive.id); printf("data_receive.DataLen = %d\n",data_receive.DataLen); printf("data_receive.data = %s\n",data_receive.data); }*/ return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -