forked from SimonRafferty/Polaris-GENERAL---CANBUS-Bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
canframe.h
93 lines (79 loc) · 2 KB
/
canframe.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef __CANFRAME_H__
#define __CANFRAME_H__
#ifdef ARDUINO_TEENSY40
#define TEENSY 1
#endif
#ifdef ARDUINO_TEENSY36
#define TEENSY 1
#endif
#ifdef TEENSY
# include <FlexCAN_T4.h>
#else
# include <can_common.h>
#endif
#ifdef TEENSY
//Union for parsing CAN bus data messages. Warning:
//Invokes type punning, but this works here because
//CAN bus data is always little-endian (or should be)
//and the ARM processor on these boards is also little
//endian.
typedef union {
uint64_t uint64;
uint32_t uint32[2];
uint16_t uint16[4];
uint8_t uint8[8];
int64_t int64;
int32_t int32[2];
int16_t int16[4];
int8_t int8[8];
//deprecated names used by older code
uint64_t value;
struct {
uint32_t low;
uint32_t high;
};
struct {
uint16_t s0;
uint16_t s1;
uint16_t s2;
uint16_t s3;
};
uint8_t bytes[8];
uint8_t byte[8]; //alternate name so you can omit the s if you feel it makes more sense
} BytesUnion;
#endif
/* This is a thin wrapper class to contain either a due_can
* CAN_FRAME or FlexCAN_T4 CAN_message_t object for manipulation
*/
class CANFrame
#ifdef TEENSY
: public CAN_message_t
#else
: public CAN_FRAME
#endif
{
private:
public:
#ifdef TEENSY
CANFrame () {};
CANFrame (const CAN_message_t &orig_frame) {
//stinky, but accurate
memcpy(this,&orig_frame,sizeof(CAN_message_t));
}
uint32_t get_id(void) { return id; };
uint8_t get_extended(void) { return flags.extended; };
BytesUnion *get_data(void) { return (BytesUnion *)buf; };
uint8_t get_length(void) { return len; };
#else
CANFrame () {};
CANFrame (const CAN_FRAME &orig_frame) {
//stinky, but accurate
memcpy(this,&orig_frame,sizeof(CAN_FRAME));
}
uint32_t get_id(void) { return id; };
uint8_t get_extended(void) { return extended; };
BytesUnion *get_data(void) { return &data; };
uint8_t get_length(void) { return length; };
#endif
};
#endif