-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcan.h
More file actions
75 lines (62 loc) · 1.51 KB
/
Copy pathcan.h
File metadata and controls
75 lines (62 loc) · 1.51 KB
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
/*
* can.h
*
* Created: 18/03/17 13:12:17
* Author: Sondre
*/
#ifndef CAN_H_
#define CAN_H_
#include <stdbool.h>
#include <stdint.h>
#define E_CLUTCH_1_CAN_ID 0x120
#define E_CLUTCH_2_CAN_ID 0x220
#define STEERING_WHEEL_CAN_ID 0x230
#define DASHBOARD_CAN_ID 0x270
#define MOTOR_1_STATUS_CAN_ID 0x250
#define MOTOR_1_CL_CMD_CAN_ID 0x251
#define MOTOR_2_STATUS_CAN_ID 0x260
#define MOTOR_2_CL_CMD_CAN_ID 0x261
#define BMS_CELL_V_1_4_CAN_ID 0x440
#define BMS_CELL_V_5_7_CAN_ID 0x441
#define BMS_CELL_V_8_12_CAN_ID 0x442
#define BMS_CELL_TEMP_CAN_ID 0x443
#define BMS_VOLT_CURRENT_CAN_ID 0x444
#define BMS_STATUS_CAN_ID 0x448
#define BMS_ERROR_CAN_ID 0x449
typedef union {
// Integers and fixed point numbers
// Example: can_message.data.u8[2] = 0xFF;
uint8_t u8[8];
int8_t i8[8];
uint16_t u16[4];
int16_t i16[4];
uint32_t u32[2];
int32_t i32[2];
uint64_t u64;
int64_t i64;
// Floating point numbers
// Example: can_message.data.f32[1] = 3.1415926535;
float f32[2];
double f64;
// Bitfields
// Example: can_message.data.bitfield[3].b6 = true;
struct {
uint8_t b0 : 1;
uint8_t b1 : 1;
uint8_t b2 : 1;
uint8_t b3 : 1;
uint8_t b4 : 1;
uint8_t b5 : 1;
uint8_t b6 : 1;
uint8_t b7 : 1;
} bitfield[8];
} CanData_t;
typedef struct {
uint16_t id;
uint8_t length;
CanData_t data;
} CanMessage_t;
void can_init(uint16_t accept_mask_id, uint16_t accept_tag_id);
bool can_read_message_if_new(CanMessage_t* message);
bool can_send_message(CanMessage_t* message);
#endif /* CAN_H_ */