diff --git a/CANOPEN_db.h b/CANOPEN_db.h new file mode 100644 index 0000000..c94c6cf --- /dev/null +++ b/CANOPEN_db.h @@ -0,0 +1,84 @@ +/* + * CANOPEN_maxondb.h + * + * Created on: 26/06/2024 + * Author: micron + */ + +#ifndef CANOPEN_MAXONDB_H +#define CANOPEN_MAXONDB_H + +/**================== Node IDS ==========================**/ +#define NODE_ID_ACU 0x03 +#define NODE_ID_STEERING 0x08 +#define NODE_ID_BRAKE 0x06 //RESERVED DONT USE +#define NODE_ID_RES 0x11 // DO NOT CHANGE!! ENFORCED BY RULES!!! +/**======================================================================**/ + + +#define NMT_ADDRESS_COBID() (0x000) + +#define BOOTUP_ADDRESS_COBID(node_id) (node_id + 0x700) +//Maxon SDOs +#define SDO_REQUEST_ADDRESS_COBID(node_id) (node_id+0x600) +#define SDO_RESPONSE_ADDRESS_COBID(node_id) (node_id+0x580) + + +/**======================================================================**/ + +/**================== Receive from World ==========================**/ +#define PDO_RXONE(node_id) (node_id+0x200) +/**======================================================================**/ +#define MAP_DECODE_PDO_RXONE_CONTROL_WORD(x) (x[1] << 8 | x[0]) +/**======================================================================**/ +#define PDO_RXTWO(node_id) (node_id+0x300) +/**======================================================================**/ +#define MAP_DECODE_PDO_RXTWO_MAXON_CONTROL_WORD(x) (x[1] << 8 | x[0]) +#define MAP_DECODE_PDO_RXTWO_MAXON_MODES_OF_OPERATION(x) (x[2]) +/**======================================================================**/ +#define PDO_RXTHREE(node_id) (node_id+0x400) +/**======================================================================**/ +#define MAP_DECODE_PDO_RXTHREE_MAXON_CONTROL_WORD(x) (x[1] << 8 | x[0]) +#define MAP_DECODE_PDO_RXTHREE_MAXON_TARGET_POSITION(x) (x[5] << 24 | x[4] << 16 | x[3] << 8 | x[2]) +/**======================================================================**/ +#define PDO_RXFOUR(node_id) (node_id+0x500) +/**======================================================================**/ +#define MAP_DECODE_PDO_RXFOUR_MAXON_CONTROL_WORD(x) (x[1] << 8 | x[0]) +#define MAP_DECODE_PDO_RXFOUR_MAXON_TARGET_SPEED(x) (x[5] << 24 | x[4] << 16 | x[3] << 8 | x[2]) + +/**=================== Transmit to World ==========================**/ +#define PDO_TXONE(node_id) (node_id+0x180) +/**======================================================================**/ +#define MAP_DECODE_PDO_TXONE_MAXON_STATUSWORD(x) (x[1] << 8 | x[0]) +#define MAP_DECODE_PDO_TXONE_MAXON_MODES_OF_OPERATION(x) (x[2]) +#define MAP_DECODE_PDO_TXONE_MAXON_ERROR_CODE(x) (x[4] << 8 | x[3]) + +#define MAP_DECODE_PDO_TXONE_RES_STATUS(x) (x[0]) + + +/**======================================================================**/ +#define PDO_TXTWO(node_id) (node_id+0x280) +/**======================================================================**/ +#define MAP_DECODE_PDO_TXTWO_MAXON_TARGET_POSITION(x) (x[3] << 24 | x[2] << 16 | x[1] << 8 | x[0]) +#define MAP_DECODE_PDO_TXTWO_MAXON_TARGET_SPEED(x) (x[7] << 24 | x[6] << 16 | x[5] << 8 | x[4]) + +/**======================================================================**/ +#define PDO_TXTHREE(node_id) (node_id+0x380) +/**======================================================================**/ +#define MAP_DECODE_PDO_TXTHREE_MAXON_STATUSWORD(x) (x[1] << 8 | x[0]) +#define MAP_DECODE_PDO_TXTHREE_MAXON_ACTUAL_POSITION(x) (x[5] << 24 | x[4] << 16 | x[3] << 8 | x[2]) +#define MAP_DECODE_PDO_TXTHREE_MAXON_ACTUAL_MOMENT(x)(x[7] <<8 | x[6]) +/**======================================================================**/ +#define PDO_TXFOUR(node_id) (node_id+0x480) +/**======================================================================**/ +#define MAP_DECODE_PDO_TXFOUR_MAXON_STATUSWORD(x) (x[1] << 8 | x[0]) +#define MAP_DECODE_PDO_TXFOUR_MAXON_ACTUAL_SPEED(x) (x[5] << 24 | x[4] << 16 | x[3] << 8 | x[2]) +#define MAP_DECODE_PDO_TXFOUR_MAXON_ACTUAL_PWM_DUTY(x) (x[7] << 8 | x[6]) + + + + + + + +#endif /* CANOPEN_MAXONDB_H */ diff --git a/CANOPEN_maxondb.h b/CANOPEN_maxondb.h deleted file mode 100644 index fc4aea0..0000000 --- a/CANOPEN_maxondb.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * CANOPEN_maxondb.h - * - * Created on: 26/06/2024 - * Author: micron - */ - -#ifndef CANOPEN_MAXONDB_H -#define CANOPEN_MAXONDB_H - -#define NMT_ADDRESS_COBID() (0x000) - -#define BOOTUP_ADDRESS_COBID() (0x700+REMOTE_NODE_ID) -//Maxon SDOs -#define SDO_REQUEST_ADDRESS_COBID() (0x600+REMOTE_NODE_ID) -#define SDO_RESPONSE_ADDRESS_COBID() (0x580+REMOTE_NODE_ID) -/**======================================================================**/ - -/**================== Maxon Receive from World ==========================**/ -#define PDO_RXONE_MAXON() (0x200+REMOTE_NODE_ID) -/**======================================================================**/ -#define MAP_DECODE_PDO_RXONE_CONTROL_WORD(x) (x[1] << 8 | x[0]) -/**======================================================================**/ -#define PDO_RXTWO_MAXON() (0x300+REMOTE_NODE_ID) -/**======================================================================**/ -#define MAP_DECODE_PDO_RXONE_CONTROL_WORD(x) (x[1] << 8 | x[0]) -#define MAP_DECODE_PDO_RXONE_MODES_OF_OPERATION(x) (x[2]) -/**======================================================================**/ -#define PDO_RXTHREE_MAXON() (0x400+REMOTE_NODE_ID) -/**======================================================================**/ -#define MAP_DECODE_PDO_RXTHREE_CONTROL_WORD(x) (x[1] << 8 | x[0]) -#define MAP_DECODE_PDO_RXTHREE_TARGET_POSITION(x) (x[5] << 24 | x[4] << 16 | x[3] << 8 | x[2]) -/**======================================================================**/ -#define PDO_RXFOUR_MAXON() (0x500+REMOTE_NODE_ID) -/**======================================================================**/ -#define MAP_DECODE_PDO_RXFOUR_CONTROL_WORD(x) (x[1] << 8 | x[0]) -#define MAP_DECODE_PDO_RXFOUR_TARGET_SPEED(x) (x[5] << 24 | x[4] << 16 | x[3] << 8 | x[2]) - -/**=================== Maxon Transmit to World ==========================**/ -#define PDO_TXONE_MAXON() (0x180+REMOTE_NODE_ID) -/**======================================================================**/ -#define MAP_DECODE_PDO_TXONE_STATUSWORD(x) (x[1] << 8 | x[0]) -#define MAP_DECODE_PDO_TXONE_MODES_OF_OPERATION(x) (x[2]) -#define MAP_DECODE_PDO_TXONE_ERROR_CODE(x) (x[4] << 8 | x[3]) - -/**======================================================================**/ -#define PDO_TXTWO_MAXON() (0x280+REMOTE_NODE_ID) -/**======================================================================**/ -#define MAP_DECODE_PDO_TXTWO_TARGET_POSITION(x) (x[3] << 24 | x[2] << 16 | x[1] << 8 | x[0]) -#define MAP_DECODE_PDO_TXTWO_TARGET_SPEED(x) (x[7] << 24 | x[6] << 16 | x[5] << 8 | x[4]) - -/**======================================================================**/ -#define PDO_TXTHREE_MAXON() (0x380+REMOTE_NODE_ID) -/**======================================================================**/ -#define MAP_DECODE_PDO_TXTHREE_STATUSWORD(x) (x[1] << 8 | x[0]) -#define MAP_DECODE_PDO_TXTHREE_ACTUAL_POSITION(x) (x[5] << 24 | x[4] << 16 | x[3] << 8 | x[2]) -#define MAP_DECODE_PDO_TXTHREE_ACTUAL_MOMENT(x)(x[7] <<8 | x[6]) -/**======================================================================**/ -#define PDO_TXFOUR_MAXON() (0x480+REMOTE_NODE_ID) -/**======================================================================**/ -#define MAP_DECODE_PDO_TXFOUR_STATUSWORD(x) (x[1] << 8 | x[0]) -#define MAP_DECODE_PDO_TXFOUR_ACTUAL_SPEED(x) (x[5] << 24 | x[4] << 16 | x[3] << 8 | x[2]) -#define MAP_DECODE_PDO_TXFOUR_ACTUAL_PWM_DUTY(x) (x[7] << 8 | x[6]) - - - - - - - -#endif /* CANOPEN_MAXONDB_H */ diff --git a/CAN_asdb.h b/CAN_asdb.h index c9a0cca..272f6af 100644 --- a/CAN_asdb.h +++ b/CAN_asdb.h @@ -1,13 +1,15 @@ /** -* @file CAN_asdb.h +1* @file CAN_asdb.h * @brief CAN database for autonomous driving header file * @details This file contains the mapping used to encode and decode CAN messages * @author João Vieira * @author Pedro Ferreira +* @author Bruno Vicente * @version 0.0.1 **/ #ifndef CAN_ASDB_H #define CAN_ASDB_H +#define __LART_AXANATO_VCU_GATEWAY__ //#ifdef __LART_T24__ /** * @brief T24 uses a little endian architecture when it comes to CAN messages @@ -53,7 +55,36 @@ #define MAP_ENCODE_AS_MISSION(pnt, x)(pnt[0]=(pnt[0]&0x1F) | (x&0xE0) ) #define MAP_ENCODE_AS_EBS(pnt, x)(pnt[0]=(pnt[0]&0xE7) | (x&0x18) ) #define MAP_ENCODE_AS_STATE(pnt, x)(pnt[0]=(pnt[0]&0xF8)| (x&0x07) ) - + + #define CAN_AS_ACU_HEARTBEAT 0x703 + /**======================================================================**/ + #define MAP_DECODE_AS_ACU_HEARTBEAT(x) (x[0]) + #define MAP_ENCODE_AS_ACU_HEARTBEAT(pnt, x) (pnt[0] = x) + + #define CAN_AS_ACU_PNEU 0x183 + /**======================================================================**/ + #define MAP_DECODE_AS_ACU_PNEUMATIC_BRAKING_EBS_FRONT(x) (x[1] << 8 | x[0]) + #define MAP_DECODE_AS_ACU_PNEUMATIC_BRAKING_BRAKE_FRONT(x) (x[3] << 8 | x[2]) + #define MAP_DECODE_AS_ACU_PNEUMATIC_BRAKING_EBS_REAR(x) (x[5] << 8 | x[4]) + #define MAP_DECODE_AS_ACU_PNEUMATIC_BRAKING_BRAKE_REAR(x) (x[7] << 8 | x[6]) + + + #ifdef __LART_AXANATO_VCU_GATEWAY__ + #define CAN_TOJAL_TEST 0x499 + /**======================================================================**/ + #define MAP_DECODE_TOJAL_RPM(x) ((x[1] << 8) | x[0]) + #define CAN_TOJAL_SEND_RPM 0x509 + /**======================================================================**/ + #define MAP_ENCODE_TOJAL_RPM(pnt, x) (pnt[1] = (x >> 8), pnt[0] = x) + #endif + + + + /**======================================================================**/ + #define ALC_MS 0x050 + /**======================================================================**/ + #define MAP_DECODE_AS_EMERGENCY_STATE(x) (x[0]) + #define MAP_DECODE_MS_STATE(x) (x[1]) //#endif #endif // CAN_ASDB_H diff --git a/CAN_datadb.h b/CAN_datadb.h index d270e95..b2cedd3 100644 --- a/CAN_datadb.h +++ b/CAN_datadb.h @@ -23,7 +23,7 @@ #define MAP_DECODE_BRAKE_PRESSURE (x)(x[1]) #define MAP_DECODE_THROTTLE_POSITION (x)(x[0]) -#define MAP_DECODE_APPS (x) MAP_DECODE_THROTTLE_POSITION(x) +#define MAP_DECODE_APPS (x) MAP_DECODE_THROTTLE_POSITION(x) #define MAP_ENCODE_CONSUMED_POWER(pnt, x) (pnt[7] = (x >> 16) & 0xFF, pnt[6] = (x >> 8) & 0xFF, pnt[5] = x & 0xFF) #define MAP_ENCODE_TARGET_POWER(pnt, x) (pnt[4] = (x >> 16) & 0xFF, pnt[3] = (x >> 8) & 0xFF, pnt[2] = x & 0xFF) @@ -38,9 +38,13 @@ #define MAP_DECODE_MOTOR_TEMPERATURE(x) ((x[3] << 8 | x[2]) + 40) #define MAP_DECODE_INVERTER_TEMPERATURE(x) ((x[1] << 8 | x[0]) + 40) +#define MAP_DECODE_HV_VOLTAGE(x) (x[6] << 8 | x[5]) +#define MAP_DECODE_HV_SOC(x) (x[7]) #define MAP_ENCODE_MOTOR_TEMPERATURE(pnt, x) (pnt[3] = (x - 40) >> 8, pnt[2] = (x - 40) & 0xFF) #define MAP_ENCODE_INVERTER_TEMPERATURE(pnt, x) (pnt[1] = (x - 40) >> 8, pnt[0] = (x - 40) & 0xFF) +#define MAP_ENCODE_HV_VOLTAGE(pnt, x) (pnt[6] = (x >> 8) & 0xFF, pnt[5] = x & 0xFF) +#define MAP_ENCODE_HV_SOC(pnt, x) (pnt[7] = x) /**======================================================================**/ #define CAN_VCU_ID_3 0x022 @@ -49,11 +53,16 @@ #define MAP_DECODE_LMT2(x) (x[3]) #define MAP_DECODE_LMT1(x) (x[2]) #define MAP_DECODE_INVERTER_ERROR(x) (x[1] << 8 | x[0]) +#define MAP_DECODE_APPS_ERROR(x) (x[5]) +#define MAP_DECODE_POWER_PLAN(x) (x[6]) + #define MAP_ENCODE_VCU_STATE(pnt, x) (pnt[4] = x) #define MAP_ENCODE_LMT2(pnt, x) (pnt[3] = x) #define MAP_ENCODE_LMT1(pnt, x) (pnt[2] = x) #define MAP_ENCODE_INVERTER_ERROR(pnt, x) (pnt[1] = (x >> 8) & 0xFF, pnt[0] = x & 0xFF) +#define MAP_ENCODE_APPS_ERROR(pnt, x) (pnt[5] = x) +#define MAP_ENCODE_POWER_PLAN(pnt, x) (pnt[6] = x) /**======================================================================**/ #define CAN_VCU_ID_4 0x023 @@ -61,59 +70,28 @@ #define MAP_DECODE_RPM(x) (x[3] << 8 | x[2]) #define MAP_DECODE_INVERTER_VOLTAGE(x) (x[1] << 8 | x[0]) +#define MAP_DECODE_IGNITION_STATE(x) (x[4]) +#define MAP_DECODE_Ready2Drive_STATE(x) (x[5]) #define MAP_ENCODE_RPM(pnt, x) (pnt[3] = (x >> 8) & 0xFF, pnt[2] = x & 0xFF) #define MAP_ENCODE_INVERTER_VOLTAGE(pnt, x) (pnt[1] = (x >> 8) & 0xFF, pnt[0] = x & 0xFF) +#define MAP_ENCODE_IGNITION_STATE(pnt, x) (pnt[4] = x) +#define MAP_ENCODE_Ready2Drive_STATE(pnt, x) (pnt[5] = x) /**======================================================================**/ -#define CAN_PDM_ID_1 0x40 -/**======================================================================**/ - -#define MAP_DECODE_TOTAL_POWER(x) (x[7] << 8 | x[6]) -#define MAP_DECODE_LV_VOLTAGE(x) (x[4] << 8 | x[3]) -#define MAP_DECODE_INPUTS1(x) (x[2]) -#define MAP_DECODE_OUTPUTS1(x) (x[1]) - -#define MAP_ENCODE_DYNAMICS_FRONT_POWER(pnt, x) (pnt[7] = (x >> 8) & 0xFF, pnt[6] = x & 0xFF) -#define MAP_ENCODE_DYNAMICS_REAR_POWER(pnt, x) (pnt[5] = (x >> 8) & 0xFF, pnt[4] = x & 0xFF) -#define MAP_ENCODE_EXTRA_POWER(pnt, x) (pnt[3] = (x >> 8) & 0xFF, pnt[2] = x & 0xFF) -#define MAP_ENCODE_PDM_HEARTBEAT(pnt, x) (pnt[1] = x) - -/**======================================================================**/ -#define CAN_PDM_ID_2 0x41 -/**======================================================================**/ - -#define MAP_DECODE_TCU_POWER(x) ((x[7] << 8 | x[6]) / 10) -#define MAP_DECODE_VCU_POWER(x) ((x[5] << 8 | x[4]) / 10) -#define MAP_DECODE_ACU_POWER(x) ((x[3] << 8 | x[2]) / 10) -#define MAP_DECODE_DATALOGGER_POWER(x) ((x[1] << 8 | x[0]) / 10) - -#define MAP_ENCODE_TCU_POWER(pnt, x) (pnt[7] = (x >> 8) & 0xFF, pnt[6] = x & 0xFF) -#define MAP_ENCODE_VCU_POWER(pnt, x) (pnt[5] = (x >> 8) & 0xFF, pnt[4] = x & 0xFF) -#define MAP_ENCODE_ACU_POWER(pnt, x) (pnt[3] = (x >> 8) & 0xFF, pnt[2] = x & 0xFF) -#define MAP_ENCODE_DATALOGGER_POWER(pnt, x) (pnt[1] = (x >> 8) & 0xFF, pnt[0] = x & 0xFF) - -/**======================================================================**/ -#define CAN_PDM_ID_3 0x42 -/**======================================================================**/ +#define CAN_VCU_ID_5 0x024 -#define MAP_DECODE_DYNAMICS_FRONT_POWER(x) (x[7] << 8 | x[6]) -#define MAP_DECODE_DYNAMICS_REAR_POWER(x) (x[5] << 8 | x[4]) -#define MAP_DECODE_EXTRA_POWER(x) (x[3] << 8 | x[2]) +#define MAP_DECODE_VCU_TCU_STATE(x) (x[0]) +#define MAP_DECODE_VCU_ACU_STATE(x) (x[1]) +#define MAP_DECODE_VCU_ALC_STATE(x) (x[2]) +#define MAP_DECODE_LV_SOC(x) ((x[3] << 8 | x[4]) /10) +#define MAP_DECODE_LV_VOLTAGE(x) (x[5] << 8 | x[6]) -#define MAP_ENCODE_TOTAL_POWER(pnt, x) (pnt[7] = (x >> 8) & 0xFF, pnt[6] = x & 0xFF) -#define MAP_ENCODE_LV_VOLTAGE(pnt, x) (pnt[4] = (x >> 8) & 0xFF, pnt[3] = x & 0xFF) -#define MAP_ENCODE_INPUTS1(pnt, x) (pnt[2] = x) - -/**======================================================================**/ -#define CAN_PDM_ID_4 0x43 -/**======================================================================**/ - -#define MAP_DECODE_PDM_HEARTBEAT(x) (x[1]) -#define MAP_DECODE_SDC_STATE(x) (x[0]) - -#define MAP_ENCODE_PDM_HEARTBEAT(pnt, x) (pnt[1] = x) -#define MAP_ENCODE_SDC_STATE(pnt, x) (pnt[0] = x) +#define MAP_ENCODE_VCU_TCU_STATE(pnt, x) (pnt[0] = x) +#define MAP_ENCODE_VCU_ACU_STATE(pnt, x) (pnt[1] = x) +#define MAP_ENCODE_VCU_ALC_STATE(pnt, x) (pnt[2] = x) +#define MAP_ENCODE_LV_SOC(pnt, x) (pnt[3] = (x >> 8) & 0xFF, pnt[4] = x & 0xFF) // 0-1000 +#define MAP_ENCODE_LV_VOLTAGE(pnt, x) (pnt[5] = (x >> 8) & 0xFF, pnt[6] = x & 0xFF) /**======================================================================**/ #define CAN_IMU_ID_1 0x60 @@ -165,6 +143,29 @@ #define CAN_DYNAMICS_FRONT_ID_2 0xA1 // definir id /**======================================================================**/ +/**======================================================================**/ +#define CAN_DATA_LOGGER_ID 0x180 + +#define MAP_DECODE_DATA_LOGGER_STATE(x) (x[0]) +#define MAP_DECODE_DATA_LOGGER_RECORD_STATE(x) (x[1]) + +#define MAP_ENCODE_DATA_LOGGER_STATE(pnt, x) (pnt[0] = x) +#define MAP_ENCODE_DATA_LOGGER_RECORD_STATE(pnt, x) (pnt[1] = x) + + +/**======================================================================**/ +#define CAN_BRAKE_LIGHT 0x253 // definir id +/**======================================================================**/ + + +/**======================================================================**/ +#define CAN_STEERING_WHEEL 0x254 // definir id +/**======================================================================**/ + +#define MAP_DECODE_VCU_POWER_LIMIT(x) (x[0]) + +#define MAP_ENCODE_VCU_POWER_LIMIT(pnt, x) (pnt[0] = x) + // #endif -#endif // CAN_DB_H \ No newline at end of file +#endif // CAN_DB_H diff --git a/CAN_icupdb.h b/CAN_icupdb.h new file mode 100644 index 0000000..14d6ef5 --- /dev/null +++ b/CAN_icupdb.h @@ -0,0 +1,26 @@ +/** + * @file CAN_icupdb.h + * @brief CAN database header file for the inter control unit line + * @details This file contains the mapping used to encode and decode CAN messages + * @note This is being developed as of right now + * @author João Vieira + * @version 0.0.1 + **/ +#ifndef CAN_ICUPDB_H +#define CAN_ICUPDB_H + +// #ifdef __LART_T24__ +/** + * @brief T24 uses a little endian architecture when it comes to CAN messages + **/ + + + +#define GENERIC_MSG_CONVERSION_ENCODE_DATABUS(x) (x | 0x04000000) +#define GENERIC_MSG_CONVERSION_DECODE_DATABUS(x) (x & 0x1BFFFFFF) +#define GENERIC_MSG_CONVERSION_ENCODE_POWERTRAIN(x) (x | 0x08000000) +#define GENERIC_MSG_CONVERSION_DECODE_POWERTRAIN(x) (x & 0x17FFFFFF) +#define GENERIC_MSG_CONVERSION_ENCODE_AUTONOMOUSBUS(x) (x | 0x0C000000) +#define GENERIC_MSG_CONVERSION_DECODE_AUTONOMOUSBUS(x) (x & 0x13FFFFFF) + +#endif // CAN_DB_H diff --git a/CAN_pwtdb.h b/CAN_pwtdb.h index 39254bd..13d4fee 100644 --- a/CAN_pwtdb.h +++ b/CAN_pwtdb.h @@ -14,32 +14,34 @@ * @brief T24 uses a little endian architecture when it comes to CAN messages **/ +/*HV500 is big endiano*/ + /**======================================================================**/ #define CAN_HV500_ERPM_DUTY_VOLTAGE_ID 0x14 /**======================================================================**/ -#define MAP_DECODE_Actual_ERPM(x) (x[3] << 24 | x[2] << 16 | x[1] << 8 | x[0]) -#define MAP_DECODE_Actual_Duty(x) (x[5] << 8 | x[4]) -#define MAP_DECODE_Actual_InputVoltage(x) (x[7] << 8 | x[6]) +#define MAP_DECODE_Actual_ERPM(x) (x[0] << 24 | x[1] << 16 | x[2] << 8 | x[3]) +#define MAP_DECODE_Actual_Duty(x) (x[4] << 8 | x[5]) +#define MAP_DECODE_Actual_InputVoltage(x) (x[6] << 8 | x[7]) /**======================================================================**/ #define CAN_HV500_AC_DC_current_ID 0x34 /**======================================================================**/ -#define MAP_DECODE_Actual_ACCurrent(x) (x[1] << 8 | x[0]) -#define MAP_DECODE_Actual_DCCurrent(x) (x[3] << 8 | x[2]) +#define MAP_DECODE_Actual_ACCurrent(x) (x[0] << 8 | x[1]) +#define MAP_DECODE_Actual_DCCurrent(x) (x[2] << 8 | x[3]) /**======================================================================**/ #define CAN_HV500_Temperatures_ID 0x54 /**======================================================================**/ -#define MAP_DECODE_Actual_TempController(x) (x[1] << 8 | x[0]) -#define MAP_DECODE_Actual_TempMotor(x) (x[3] << 8 | x[2]) +#define MAP_DECODE_Actual_TempController(x) (x[0] << 8 | x[1]) +#define MAP_DECODE_Actual_TempMotor(x) (x[2] << 8 | x[3]) #define MAP_DECODE_Actual_FaultCode(x) (x[4]) /**======================================================================**/ #define CAN_HV500_FOC_ID 0x74 /**======================================================================**/ -#define MAP_DECODE_Actual_FOC_id(x) (x[3] << 24 | x[2] << 16 | x[1] << 8 | x[0]) -#define MAP_DECODE_Actual_FOC_iq(x) (x[7] << 24 | x[6] << 16 | x[5] << 8 | x[4]) +#define MAP_DECODE_Actual_FOC_id(x) (x[0] << 24 | x[1] << 16 | x[2] << 8 | x[3]) +#define MAP_DECODE_Actual_FOC_iq(x) (x[4] << 24 | x[5] << 16 | x[6] << 8 | x[7]) /**======================================================================**/ #define CAN_HV500_MISC_ID 0x94 @@ -66,66 +68,163 @@ #define MAP_DECODE_RPM_min_limit(x) (x[5] & 0x01) #define MAP_DECODE_RPM_max_limit(x) (x[5] & 0x02) #define MAP_DECODE_Power_limit(x) (x[5] & 0x04) -//wtf is in [6]??? #define MAP_DECODE_CAN_map_version(x) (x[7]) /**======================================================================**/ #define CAN_HV500_SetAcCurrent_ID 0x354 /**======================================================================**/ -#define MAP_ENCODE_CMD_AcCurrent(pnt, x) (pnt[1] = (x >> 8) & 0xFF, pnt[0] = x * 10 & 0xFF) +#define MAP_ENCODE_CMD_AcCurrent(pnt, x) (pnt[0] = (x >> 8) & 0xFF, pnt[1] = x * 10 & 0xFF) /**======================================================================**/ #define CAN_HV500_SetBrakeCurrent_ID 0x374 /**======================================================================**/ -#define MAP_ENCODE_CMD_BrakeCurrent(pnt, x) (pnt[1] = (x >> 8) & 0xFF, pnt[0] = x * 10 & 0xFF) +#define MAP_ENCODE_CMD_BrakeCurrent(pnt, x) (pnt[0] = (x >> 8) & 0xFF, pnt[1] = x * 10 & 0xFF) /**======================================================================**/ #define CAN_HV500_SetERPM_ID 0x394 /**======================================================================**/ -#define MAP_ENCODE_CMD_ERPM(pnt, x) (pnt[2] = (x >> 16) & 0xFF, pnt[1] = (x >> 8) & 0xFF, pnt[0] = x & 0xFF) +#define MAP_ENCODE_CMD_ERPM(pnt, x) (pnt[0] = (x >> 24) & 0xFF, pnt[1] = (x >> 16) & 0xFF,pnt[2] = (x >> 8) & 0xFF,pnt[3] = (x) & 0xFF) /**======================================================================**/ #define CAN_HV500_SetPosition_ID 0x3b4 /**======================================================================**/ -//TODO: This might result in noise due to * 10 operation BEFORE the cutting shift -#define MAP_ENCODE_CMD_Position(pnt, x) (pnt[1] = (x >> 8) & 0xFF, pnt[0] = ((x * 10) & 0xFF)) +//TODO: This might result in noise due to * 10 operation BEFORE the cutting shift R:NO +#define MAP_ENCODE_CMD_Position(pnt, x) (pnt[0] = (x >> 8) & 0xFF, pnt[1] = ((x * 10) & 0xFF)) /**======================================================================**/ #define CAN_HV500_SetRelCurrent_ID 0x3d4 /**======================================================================**/ -#define MAP_ENCODE_CMD_RelCurrent(pnt, x) (pnt[1] = (x >> 8) & 0xFF, pnt[0] = ((x * 10) & 0xFF)) +#define MAP_ENCODE_CMD_RelCurrent(pnt, x) (pnt[0] = (x >> 8) & 0xFF, pnt[1] = ((x) & 0xFF)) /**======================================================================**/ #define CAN_HV500_SetRelBrakeCurrent_ID 0x3F4 /**======================================================================**/ -#define MAP_ENCODE_CMD_RelBrakeCurrent(pnt, x) (pnt[1] = (x >> 8) & 0xFF, pnt[0] = ((x * 10) & 0xFF)) +#define MAP_ENCODE_CMD_RelBrakeCurrent(pnt, x) (pnt[0] = (x >> 8) & 0xFF, pnt[1] = ((x * 10) & 0xFF)) /**======================================================================**/ #define CAN_HV500_SetMaxAcCurrent_ID 0x414 /**======================================================================**/ -#define MAP_ENCODE_CMD_MaxAcCurrent(pnt, x) (pnt[1] = (x >> 8) & 0xFF, pnt[0] = ((x * 10) & 0xFF)) +#define MAP_ENCODE_CMD_MaxAcCurrent(pnt, x) (pnt[0] = (x >> 8) & 0xFF, pnt[1] = ((x * 10) & 0xFF)) /**======================================================================**/ #define CAN_HV500_SetMaxAcBrakeCurrent_ID 0x434 /**======================================================================**/ -#define MAP_ENCODE_CMD_MaxAcBrakeCurrent(pnt, x) (pnt[1] = (x >> 8) & 0xFF, pnt[0] = ((x * 10) & 0xFF)) +#define MAP_ENCODE_CMD_MaxAcBrakeCurrent(pnt, x) (pnt[0] = (x >> 8) & 0xFF, pnt[1] = ((x * 10) & 0xFF)) /**======================================================================**/ #define CAN_HV500_SetMaxDcCurrent_ID 0x454 /**======================================================================**/ -#define MAP_ENCODE_CMD_MaxDcCurrent(pnt, x) (pnt[1] = (x >> 8) & 0xFF, pnt[0] = ((x * 10) & 0xFF)) +#define MAP_ENCODE_CMD_MaxDcCurrent(pnt, x) (pnt[0] = (x >> 8) & 0xFF, pnt[1] = ((x * 10) & 0xFF)) /**======================================================================**/ #define CAN_HV500_SetMaxDcBrakeCurrent_ID 0x474 /**======================================================================**/ -#define MAP_ENCODE_CMD_MaxDcBrakeCurrent(pnt, x) (pnt[1] = (x >> 8) & 0xFF, pnt[0] = ((x * 10) & 0xFF)) +#define MAP_ENCODE_CMD_MaxDcBrakeCurrent(pnt, x) (pnt[0] = (x >> 8) & 0xFF, pnt[1] = ((x * 10) & 0xFF)) /**======================================================================**/ #define CAN_HV500_SetDriveEnable_ID 0x494 /**======================================================================**/ #define MAP_ENCODE_CMD_DriveEnable(pnt, x) (pnt[0] = x) +/**======================================================================**/ +#define CAN_TCU_ID_1 0x60 + +#define MAP_DECODE_BAT_FANS_TOP(x) (x[0]) +#define MAP_DECODE_BAT_FANS_BOT(x) (x[1]) +#define MAP_DECODE_RAD_FANS_LEFT(x) (x[2]) +#define MAP_DECODE_RAD_FANS_RIGHT(x) (x[3]) +#define MAP_DECODE_PUMP(x) (x[4]) +#define MAP_LIQUID_TEMP_1(x) (x[5]) +#define MAP_LIQUID_TEMP_2(x) (x[6]) +#define MAP_LIQUID_TEMP_3(x) (x[7]) + +#define MAP_ENCODE_BAT_FANS_TOP(pnt, x) (pnt[0] = x) +#define MAP_ENCODE_BAT_FANS_BOT(pnt, x) (pnt[1] = x) +#define MAP_ENCODE_RAD_FANS_LEFT(pnt, x) (pnt[2] = x) +#define MAP_ENCODE_RAD_FANS_RIGHT(pnt, x) (pnt[3] = x) +#define MAP_ENCODE_PUMP(pnt, x) (pnt[4] = x) +#define MAP_ENCODE_LIQUID_TEMP_1(pnt, x) (pnt[5] = x) +#define MAP_ENCODE_LIQUID_TEMP_2(pnt, x) (pnt[6] = x) +#define MAP_ENCODE_LIQUID_TEMP_3(pnt, x) (pnt[7] = x) + +/**======================================================================**/ + +#define CAN_TCU_ID_2 0x61 + +#define MAP_DECODE_TCU_CONTACTORS_STATE(x) (x[0]) +#define MAP_DECODE_TCU_CONTACTORS_ERROR(x) (x[1]) +#define MAP_DECODE_AUTONOMOUS_IGNITION(x) (x[2]) +#define MAP_DECODE_PRECHARGE_DONE(x) (x[3]) +#define MAP_DECODE_SDC_STATE(x) (x[4]) +#define MAP_DECODE_TCU_STATE(x) (x[5]) + + +#define MAP_ENCODE_TCU_CONTACTORS_STATE(pnt, x) (pnt[0] = x) +#define MAP_ENCODE_TCU_CONTACTORS_ERROR(pnt, x) (pnt[1] = x) +#define MAP_ENCODE_AUTONOMOUS_IGNITION(pnt, x) (pnt[2] = x) +#define MAP_ENCODE_PRECHARGE_DONE(pnt, x) (pnt[3] = x) +#define MAP_ENCODE_SDC_STATE(pnt, x) (pnt[4] = x) +#define MAP_ENCODE_TCU_STATE(pnt, x) (pnt[5] = x) + + +/**======================================================================**/ + +#define CAN_PWT_VCU_ID_1 0x23 + +#define MAP_DECODE_PWT_R2D_STATE(x) (x[4]) +#define MAP_DECODE_PWT_IGNITION_STATE(x) (x[5]) + +#define MAP_ENCODE_PWT_R2D_STATE(pnt, x) (pnt[4] = x) +#define MAP_ENCODE_PWT_IGNITION_STATE(pnt, x) (pnt[5] = x) + +/**======================================================================**/ + +#define CAN_PWT_BMS_ID_1 0x80 +//little endian +#define MAP_DECODE_PWT_BMS_PACK_INSTANT_VOLTAGE(x) (x[1] << 8 | x[0]) +#define MAP_DECODE_PWT_BMS_PACK_OPEN_VOLTAGE(x) (x[3] << 8 | x[2]) +#define MAP_DECODE_PWT_BMS_PACK_SOC(x) (x[4]) +#define MAP_DECODE_PWT_BMS_PACK_CURRENT(x) (x[6] << 8 | x[5]) + +#define MAP_ENCODE_PWT_BMS_PACK_INSTANT_VOLTAGE(pnt, x) (pnt[1] = (x >> 8) & 0xFF, pnt[0] = x & 0xFF) +#define MAP_ENCODE_PWT_BMS_PACK_OPEN_VOLTAGE(pnt, x) (pnt[3] = (x >> 8) & 0xFF, pnt[2] = x & 0xFF) +#define MAP_ENCODE_PWT_BMS_PACK_SOC(pnt, x) (pnt[4] = x) +#define MAP_ENCODE_PWT_BMS_PACK_CURRENT(pnt, x) (pnt[6] = (x >> 8) & 0xFF, pnt[5] = x & 0xFF) + + + +#define CAN_PWT_BMS_ID_2 0x81 + +#define MAP_DECODE_PWT_BMS_PACK_HIGH_CELL_VOLTAGE(x) (x[1] << 8 | x[0]) +#define MAP_DECODE_PWT_BMS_PACK_HIGH_CELL_VOLTAGE_ID(x) (x[2]) +#define MAP_DECODE_PWT_BMS_PACK_LOW_CELL_VOLTAGE(x) (x[4] << 8 | x[3]) +#define MAP_DECODE_PWT_BMS_PACK_LOW_CELL_VOLTAGE_ID(x) (x[5]) +#define MAP_DECODE_PWT_BMS_PACK_AVG_CELL_VOLTAGE(x) (x[7] << 8 | x[6]) + +#define MAP_ENCODE_PWT_BMS_PACK_HIGH_CELL_VOLTAGE(pnt, x) (pnt[1] = (x >> 8) & 0xFF, pnt[0] = x & 0xFF) +#define MAP_ENCODE_PWT_BMS_PACK_HIGH_CELL_VOLTAGE_ID(pnt, x) (pnt[2] = x) +#define MAP_ENCODE_PWT_BMS_PACK_LOW_CELL_VOLTAGE(pnt, x) (pnt[4] = (x >> 8) & 0xFF, pnt[3] = x & 0xFF) +#define MAP_ENCODE_PWT_BMS_PACK_LOW_CELL_VOLTAGE_ID(pnt, x) (pnt[5] = x) +#define MAP_ENCODE_PWT_BMS_PACK_AVG_CELL_VOLTAGE(pnt, x) (pnt[7] = (x >> 8) & 0xFF, pnt[6] = x & 0xFF) + + +#define CAN_PWT_BMS_ID_3 0x82 + +#define MAP_DECODE_PWT_BMS_PACK_HIGH_CELL_TEMP(x) (x[0]) +#define MAP_DECODE_PWT_BMS_PACK_HIGH_CELL_TEMP_ID(x) (x[1]) +#define MAP_DECODE_PWT_BMS_PACK_LOW_CELL_TEMP(x) (x[2]) +#define MAP_DECODE_PWT_BMS_PACK_LOW_CELL_TEMP_ID(x) (x[3]) +#define MAP_DECODE_PWT_BMS_PACK_AMBIENT_TEMP(x) (x[4]) + +#define MAP_ENCODE_PWT_BMS_PACK_HIGH_CELL_TEMP(pnt, x) (pnt[0] = x) +#define MAP_ENCODE_PWT_BMS_PACK_HIGH_CELL_TEMP_ID(pnt, x) (pnt[1] = x) +#define MAP_ENCODE_PWT_BMS_PACK_LOW_CELL_TEMP(pnt, x) (pnt[2] = x) +#define MAP_ENCODE_PWT_BMS_PACK_LOW_CELL_TEMP_ID(pnt, x) (pnt[3] = x) +#define MAP_ENCODE_PWT_BMS_PACK_AMBIENT_TEMP(pnt, x) (pnt[4] = x) + +/**======================================================================**/ + // #endif #endif // CAN_PWTDB_H \ No newline at end of file