EMS/drv/drv_can.h

47 lines
1.4 KiB
C

#ifndef __DRV_CAN_H_
#define __DRV_CAN_H_
#define _DEFAULT_SOURCE
#include <linux/can.h>
#include <errno.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <linux/can.h>
#include <linux/can/raw.h>
#include <termios.h> /*PPSIX 终端控制定义*/
#define CAN_MODE 0
#define CAN_FD_MODE 1
/*CAN口参数结构体 */
typedef struct
{
unsigned long baudrate; /*波特率 5k~1000k*/
unsigned int id; /*设备ID*/
struct can_filter filter; /*接收设备过滤ID*/
unsigned char extend; /*扩展ID*/
unsigned char loopback_mode; /*回环模式*/
unsigned char canfd_mode; /*CANFD模式*/
unsigned long data_baudrate; /*CANFD模式下需要单独设置数据波特率*/
} struct_can_param;
int func_open_can(char *device, struct_can_param para);
int func_set_can(int fd, struct_can_param para);
int func_receive_can_buff(int fd, unsigned char *buff, int len);
int func_send_can_buff(int fd, unsigned char *buff, int len, struct_can_param param);
// int func_open_canfd(char *device, struct_can_param para);
// int func_set_canfd(int fd, struct_can_param para);
// int func_receive_canfd_buff(int fd, unsigned char *buff, int len);
// int func_send_canfd_buff(int fd, unsigned char *buff, int len, struct_can_param param);
#endif