-
Notifications
You must be signed in to change notification settings - Fork 0
/
can.h
76 lines (63 loc) · 1.65 KB
/
can.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef _CAN_H_
#define _CAN_H_
#include <stdio.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <linux/socket.h>
#include <linux/can.h>
#include <linux/can/error.h>
#include <linux/can/raw.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <pthread.h>
#ifndef AF_CAN
#define AF_CAN 29
#endif
#ifndef PF_CAN
#define PF_CAN AF_CAN
#endif
#define FIFO_SIZE 1024
/* CAN通信抽象结构体定义*/
// struct SockerCan
// {
// /* CAN硬件名称 */
// char *name;
// /* CAN端口号,裸机里为端口号;linux应用里作为socket套接口 */
// int can_port;
// /* CAN控制器配置函数,返回端口号赋值给can_port */
// int (*can_set_controller)( void );
// /* CAN接口中断创建,在linux中对应创建接收线程 */
// // void (*can_set_interrput)( int can_port , pCanInterrupt callback );
// /* CAN读取报文接口 */
// void (*can_read)( int can_port , CanRxMsg* recv_msg);
// /* CAN发送报文接口*/
// void (*can_write)( int can_port , CanTxMsg send_msg);
// };
typedef enum
{
CAN_PORT_0 = 0, // can0
CAN_PORT_1, // can1
}can_port_t ;
typedef struct {
uint16_t buffer[FIFO_SIZE];
uint8_t ptrWrite;
uint8_t ptrRead;
}can_queue_t;
typedef struct
{
char *name;
int fd;
//fd_set fdsr;
pthread_t send_thread;
pthread_t recv_thread;
pthread_t time_thread;
can_queue_t *send_queue; // 接受和发送的队列
can_queue_t *recv_queue;
} can_t;
// void *CanInit(int arg);
#endif /* _CAN_H_ */