-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcansock.h
executable file
·48 lines (38 loc) · 1010 Bytes
/
cansock.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
#ifndef CANSOCK_H_
#define CANSOCK_H_
#include <linux/can.h>
// Read UUID or reset MCU (6bytes)
#define PKT_ID_UUID (0x321)
// Set address (2bytes) to UUID (6b)
#define PKT_ID_SET (0x322)
// UUID response from slave (6bytes)
#define PKT_ID_UUID_RESP (0x323)
#define PKT_ID_UUID_FILTER (0x320)
#define PKT_ID_UUID_MASK (0xFFFC)
// ID's starts from this number
#define PKT_ID_CTL_FILTER (0x180)
// And total 127 ports max
#define PKT_ID_CTL_MASK (0xFF80)
#define NUM_CAN_FILTERS 2
#define CAN_DATA_SIZE (8)
#define PINGS_BEFORE_DISCONNECT 4
typedef struct can_frame tCanFrame;
typedef struct {
uint16_t port;
canid_t canid;
int pingcount;
int active; // Is port open
int watch; // inotify watch
} tPortId;
// p[0] unused and VportFd[0] means CAN socket
typedef struct {
tPortId *p;
struct pollfd *VportFd;
int portsize;
int portptr;
} tPorts;
int CanSockInit(void);
void CanSockClose(void);
int CanSockSend(canid_t id, uint8_t len, uint8_t* data);
void CanPing(void);
#endif /* CANSOCK_H_ */