CUER
/
charger_code
Code to run on the charger board (used to charge the car from the mains).
CANParserCharger.h@12:77d493b3320b, 2017-09-12 (annotated)
- Committer:
- DasSidG
- Date:
- Tue Sep 12 05:42:43 2017 +0000
- Revision:
- 12:77d493b3320b
- Parent:
- 7:70cf5bff23f9
Added charger and bms timeouts to the charger board CAN packet
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DasSidG | 3:a7626dffb64a | 1 | #ifndef CANParserCharger_H |
DasSidG | 3:a7626dffb64a | 2 | #define CANParserCharger_H |
DasSidG | 3:a7626dffb64a | 3 | |
DasSidG | 1:0c77e20b4d4c | 4 | #include "CAN_Data.h" |
DasSidG | 1:0c77e20b4d4c | 5 | #include "CAN_IDs.h" |
DasSidG | 5:756fae795d37 | 6 | #include "charger.h" |
DasSidG | 7:70cf5bff23f9 | 7 | #include "Data_types.h" |
DasSidG | 1:0c77e20b4d4c | 8 | |
DasSidG | 3:a7626dffb64a | 9 | |
DasSidG | 1:0c77e20b4d4c | 10 | |
DasSidG | 5:756fae795d37 | 11 | #define CHARGER_CAN_BIT_RATE 250000 //note this is different to the car CAN bit rate, this is fixed by the charger |
DasSidG | 3:a7626dffb64a | 12 | #define CHARGER_VI_CONTROL_ID 0x1806E5F4 |
DasSidG | 3:a7626dffb64a | 13 | #define CHARGER_VI_INFO_ID 0x18FF50E5 |
DasSidG | 3:a7626dffb64a | 14 | |
DasSidG | 4:f6459580c312 | 15 | #define CAN_TIMEOUT_MS 100 |
DasSidG | 4:f6459580c312 | 16 | |
DasSidG | 3:a7626dffb64a | 17 | |
DasSidG | 1:0c77e20b4d4c | 18 | |
DasSidG | 1:0c77e20b4d4c | 19 | //@TODO add some comments |
DasSidG | 1:0c77e20b4d4c | 20 | |
DasSidG | 1:0c77e20b4d4c | 21 | void get_max_min_voltage(CANMessage msg, float &_min_cell_voltage, float &_max_cell_voltage); |
DasSidG | 1:0c77e20b4d4c | 22 | void get_battery_status(CANMessage msg, bool &error); |
DasSidG | 1:0c77e20b4d4c | 23 | void get_charger_VI_info(CANMessage msg, float &_charger_voltage, float &_charger_current, uint8_t &_charger_status); |
DasSidG | 5:756fae795d37 | 24 | void check_precharge_status (CANMessage msg, bool &_precharge_ready); |
DasSidG | 7:70cf5bff23f9 | 25 | void get_CAN_data(); |
DasSidG | 7:70cf5bff23f9 | 26 | void car_CANDataSentCallback(); |
DasSidG | 7:70cf5bff23f9 | 27 | void charger_CANDataSentCallback(); |
DasSidG | 7:70cf5bff23f9 | 28 | void car_interruptHandler(); |
DasSidG | 7:70cf5bff23f9 | 29 | void charger_interruptHandler(); |
DasSidG | 7:70cf5bff23f9 | 30 | bool idAccepted(int id); |
DasSidG | 7:70cf5bff23f9 | 31 | void CAN_Init(); |
DasSidG | 5:756fae795d37 | 32 | |
DasSidG | 1:0c77e20b4d4c | 33 | CANMessage generate_charger_control_msg(float _desired_voltage, float _desired_current, uint8_t _charger_control); |
DasSidG | 12:77d493b3320b | 34 | CANMessage generate_charger_info_msg(float _charger_voltage, float _charger_current, uint8_t _charger_status, bool _charger_timeout, bool _bms_timeout); |
DasSidG | 3:a7626dffb64a | 35 | CANMessage generate_charging_finished_msg(); //When this packet is received by the BMU, it causes the BMU to reset its SoC value to 100% |
DasSidG | 7:70cf5bff23f9 | 36 | |
DasSidG | 7:70cf5bff23f9 | 37 | //CAN stuff. Not that there are two sets because there are two separate CAN buses here; one to communicate with the charger, and one to communicate with the rest of the car (importantly the BMS). |
DasSidG | 7:70cf5bff23f9 | 38 | //The reason that there are two separate CAN buses is because the charger uses the extended CAN frame format, with a 29 bit ID, whereas the car uses the default 11 bit ID. |
DasSidG | 7:70cf5bff23f9 | 39 | extern CAN car_can; //Create a CAN object to handle CAN comms |
DasSidG | 7:70cf5bff23f9 | 40 | extern CANMessage car_buffer[CAN_BUFFER_SIZE]; //CAN receive buffer |
DasSidG | 7:70cf5bff23f9 | 41 | extern bool car_safe_to_write[CAN_BUFFER_SIZE]; //Semaphore bit indicating that it's safe to write to the software buffer |
DasSidG | 7:70cf5bff23f9 | 42 | extern bool car_CAN_data_sent; |
DasSidG | 7:70cf5bff23f9 | 43 | |
DasSidG | 7:70cf5bff23f9 | 44 | extern CAN charger_can; //Create a CAN object to handle CAN comms |
DasSidG | 7:70cf5bff23f9 | 45 | extern CANMessage charger_buffer[CAN_BUFFER_SIZE]; //CAN receive buffer |
DasSidG | 7:70cf5bff23f9 | 46 | extern bool charger_safe_to_write[CAN_BUFFER_SIZE]; //Semaphore bit indicating that it's safe to write to the software buffer |
DasSidG | 7:70cf5bff23f9 | 47 | extern bool charger_CAN_data_sent; |
DasSidG | 1:0c77e20b4d4c | 48 | #endif |