BOLT Dash (C++)
Loading...
Searching...
No Matches
can.h
1#ifndef CAN_H
2#define CAN_H
3
4#include <mutex>
5#include <unistd.h>
6
7#include <net/if.h>
8#include <sys/ioctl.h>
9#include <sys/socket.h>
10
11#include <linux/can.h>
12#include <linux/can/raw.h>
13
14#define BMS_FAULT_MASK 0b0010000
15
25 uint8_t aux_voltage{};
29 uint8_t aux_percent{};
37 uint16_t pack_voltage{};
41 int16_t pack_current{};
45 uint16_t high_cell_temp{};
49 uint16_t low_cell_temp{};
57 uint16_t bms_temperature{};
61 uint16_t mc_temperature{};
65 int16_t motor_speed{};
69 int16_t bike_speed{};
73 uint8_t bms_fault{};
77 uint8_t bms_error{};
81 uint8_t bms_warning{};
85 uint32_t bms_error_codes{};
89 uint8_t mc_fault{};
93 uint8_t motor_on{};
97 uint8_t bike_status{};
106};
107
108// ID's for each CAN thing
109constexpr struct {
110 canid_t aux_battery{0x700};
111 canid_t info{0x6B0};
112 canid_t cell_max_min_voltages{0x6B3};
113 canid_t main_pack_temp{0x6B4};
114 canid_t bms_error_codes{0x6B6};
115 canid_t motor_temp{0xA2};
116 canid_t bms_temp{0x6B1};
117 canid_t mc_temp{0xA0};
118 canid_t rpm{0xA5};
119 canid_t speed{0x00};
120 canid_t mc_faults{0x0AB};
121 canid_t internal_states{0x0AA};
122} can_ids;
123
124constexpr struct {
125 uint32_t discharge_limit_enforcement{1 << 0};
126 uint32_t charger_safety_relay{1 << 1};
127 uint32_t internal_heatsink_thermistor{1 << 3};
128 uint32_t cell_balancing_stuck_off{1 << 9};
129 uint32_t weak_cell{1 << 10};
130 uint32_t open_wiring{1 << 12};
131 uint32_t current_sensor{1 << 13};
132 uint32_t weak_pack{1 << 16};
133 uint32_t fan_monitor{1 << 17};
134 uint32_t thermistor_fault{1 << 18};
135 uint32_t external_communication{1 << 19};
136 uint32_t charge_limit_enforcement{1 << 23};
137} bms_warnings;
138
139constexpr struct {
140 uint32_t internal_hardware{1 << 2};
141 uint32_t internal_software{1 << 4};
142 uint32_t highest_cell_voltage_too_high{1 << 5};
143 uint32_t lowest_cell_voltage_too_low{1 << 6};
144 uint32_t pack_too_hot{1 << 7};
145 uint32_t internal_communication{1 << 8};
146 uint32_t low_cell_voltage{1 << 11};
147 uint32_t highest_cell_voltage_over_5v{1 << 14};
148 uint32_t cell_asic_fault{1 << 15};
149 uint32_t redundant_power_supply{1 << 20};
150 uint32_t high_voltage_isolation{1 << 21};
151 uint32_t input_power_supply{1 << 22};
152} bms_errors;
153
154const uint32_t ALL_BMS_ERRORS = bms_errors.internal_hardware | bms_errors.internal_software |
155 bms_errors.highest_cell_voltage_too_high | bms_errors.lowest_cell_voltage_too_low |
156 bms_errors.pack_too_hot | bms_errors.internal_communication | bms_errors.low_cell_voltage |
157 bms_errors.highest_cell_voltage_over_5v | bms_errors.cell_asic_fault |
158 bms_errors.redundant_power_supply | bms_errors.high_voltage_isolation |
159 bms_errors.input_power_supply;
160const uint32_t ALL_BMS_WARNINGS = bms_warnings.charger_safety_relay | bms_warnings.discharge_limit_enforcement |
161 bms_warnings.cell_balancing_stuck_off | bms_warnings.internal_heatsink_thermistor | bms_warnings.weak_cell |
162 bms_warnings.current_sensor | bms_warnings.weak_pack | bms_warnings.fan_monitor |
163 bms_warnings.thermistor_fault | bms_warnings.external_communication |
164 bms_warnings.open_wiring | bms_warnings.charge_limit_enforcement;
165extern std::mutex m;
166extern our_candata data;
167
168namespace can {
169 int run();
170}
171
172#endif // CAN_H
This is a struct that contains all the data that we get from the CAN bus and is used in the dash proj...
Definition can.h:21
int16_t motor_speed
The RPM of the motor.
Definition can.h:65
uint16_t mc_temperature
The temperature of the motor controller.
Definition can.h:61
uint8_t aux_percent
The battery percentage of the aux pack.
Definition can.h:29
uint16_t lowest_cell_voltage
The lowest cell voltage in the main pack.
Definition can.h:105
uint8_t mc_fault
Whether or no the MC has a fault.
Definition can.h:89
uint8_t bms_warning
Whether the BMS has any warnings.
Definition can.h:81
uint8_t bms_error
Whether the BMS has any errors.
Definition can.h:77
uint16_t pack_voltage
The voltage of the main pack.
Definition can.h:37
uint8_t motor_on
Whether or not the motor is active.
Definition can.h:93
int16_t bike_speed
The speed of the bike in mph.
Definition can.h:69
uint8_t bms_fault
The fault status of the BMS.
Definition can.h:73
uint16_t low_cell_temp
The temperature of the coldest cell group in the main pack.
Definition can.h:49
uint32_t bms_error_codes
The actual error codes of the BMS concatenated together.
Definition can.h:85
uint16_t highest_cell_voltage
The highest cell voltage in the main pack.
Definition can.h:101
uint8_t aux_voltage
The voltage of the aux pack.
Definition can.h:25
uint8_t pack_state_of_charge
The state of charge of the main pack as a percentage.
Definition can.h:33
uint16_t bms_temperature
The temperature of the BMS.
Definition can.h:57
int16_t pack_current
The current of the main pack.
Definition can.h:41
int16_t motor_temperature
The temperature of the motor.
Definition can.h:53
uint8_t bike_status
The internal state of the bike, not used rn.
Definition can.h:97
uint16_t high_cell_temp
The temperature of the hottest cell group in the main pack.
Definition can.h:45