Skip to content

Commit

Permalink
perdu edits
Browse files Browse the repository at this point in the history
  • Loading branch information
perdo1305 committed Mar 5, 2024
1 parent 38be4ad commit c1d1d05
Show file tree
Hide file tree
Showing 2 changed files with 206 additions and 41 deletions.
121 changes: 80 additions & 41 deletions CAN_datadb.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,96 @@
#ifndef CAN_DATADB_H
#define CAN_DATADB_H

//#ifdef __LART_T24__
// #ifdef __LART_T24__
/**
* @brief T24 uses a little endian architecture when it comes to CAN messages
**/

#define CAN_VCU_ID_1 0x020
/**======================================================================**/
#define MAP_DECODE_CONSUMED_POWER(x) (x[7] << 16 | x[6] << 8 | x[5])
#define MAP_DECODE_TARGET_POWER (x)(x[4] << 16 | x[3] << 8 | x[2])
#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_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)
#define MAP_ENCODE_BRAKE_PRESSURE(pnt, x) (pnt[1] = x)
#define MAP_ENCODE_THROTTLE_POSITION(pnt, x) (pnt[0] = x)

#define MAP_ENCODE_APPS(pnt, x) MAP_ENCODE_THROTTLE_POSITION(pnt, x)

/**======================================================================**/
#define CAN_VCU_ID_2 0x021
/**======================================================================**/

#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_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)

/**
* @brief T24 uses a little endian architecture when it comes to CAN messages
**/
/**======================================================================**/
#define CAN_VCU_ID_3 0x022
/**======================================================================**/
#define MAP_DECODE_VCU_STATE(x) (x[4])
#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_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 CAN_VCU_ID_4 0x023
/**======================================================================**/

#define CAN_VCU_MODULUS_1 0x020
/**======================================================================**/
#define MAP_DECODE_CONSUMED_POWER(x) (x[7] << 16 | x[6] << 8 | x[5])
#define MAP_DECODE_TARGET_POWER (x) (x[4] << 16 | x[3] << 8 | x[2])
#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_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)
#define MAP_ENCODE_BRAKE_PRESSURE(pnt, x) (pnt[1] = x)
#define MAP_ENCODE_THROTTLE_POSITION(pnt, x) (pnt[0] = x)
#define MAP_DECODE_RPM(x) (x[3] << 8 | x[2])
#define MAP_DECODE_INVERTER_VOLTAGE(x) (x[1] << 8 | x[0])

#define MAP_ENCODE_APPS(pnt, x) MAP_ENCODE_THROTTLE_POSITION(pnt, x)
#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 CAN_VCU_MODULUS_2 0x021
/**======================================================================**/
#define MAP_DECODE_RPM(x) ((x[7] << 8 | x[6]))
#define MAP_DECODE_MOTOR_TEMPERATURE(x) ((x[5] << 8 | x[4]) +40)
#define MAP_DECODE_INVERTER_TEMPERATURE(x) ((x[3] << 8 | x[2]) +40)
#define MAP_DECODE_INVERTER_VOLTAGE(x) ((x[1] << 8 | x[0]))
/**======================================================================**/
#define CAN_PDM_ID_1 0x40
/**======================================================================**/

/**======================================================================**/
#define CAN_VCU_MODULUS_3 0x022
/**======================================================================**/

/**======================================================================**/
#define CAN_PDM_ID_2 0x41
/**======================================================================**/

/**======================================================================**/
#define CAN_TCU_MODULUS_1 0x060
/**======================================================================**/
#define MAP_DECODE_FIRSTSEGMENT_TEMPERATURE(x) (x[7] << 8 | x[6])
#define MAP_DECODE_PACK_MEAN_TEMPERATURE(x) (x[5] << 8 | x[4])
/**#define MAP_DECODE_POWER_TO_BATTERY_FANS(x) (x[3])
#define MAP_DECODE_POWER_TO_BATTERY_FANS(x) (x[2])
#define MAP_DECODE_POWER_TO_BATTERY_FANS(x) (x[1])**/
#define MAP_DECODE_COLLING_BOARD_STATE(x) (x[0])
/**======================================================================**/
#define CAN_PDM_ID_3 0x42
/**======================================================================**/


/**======================================================================**/
#define CAN_PDM_ID_4 0x43
/**======================================================================**/

/**======================================================================**/
#define CAN_IMU_ID_1 0x60
/**======================================================================**/
/**======================================================================**/
#define CAN_IMU_ID_2 0x61
/**======================================================================**/

/**======================================================================**/
#define CAN_DYNAMICS_REAR_ID_1 0x80
/**======================================================================**/
/**======================================================================**/
#define CAN_DYNAMICS_REAR_ID_2 0xA0
/**======================================================================**/
/**======================================================================**/
// #define CAN_DYNAMICS_FRONT_ID_1 0x80 //definir id
/**======================================================================**/
/**======================================================================**/
// #define CAN_DYNAMICS_FRONT_ID_2 0xA0 //definir id
/**======================================================================**/

//#endif
// #endif

#endif // CAN_DB_H
#endif // CAN_DB_H
126 changes: 126 additions & 0 deletions CAN_pwtdb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/**
* @file CAN_datadb.h
* @brief CAN database header file for the data line
* @details This file contains the mapping used to encode and decode CAN messages
* @note THIS IS OBSOLETE/NEEDS TO BE UPDATED
* @author João Vieira
**/
#ifndef CAN_PWTDB_H
#define CAN_PWTDB_H

// #ifdef __LART_T24__
/**
* @brief T24 uses a little endian architecture when it comes to CAN messages
**/

/**======================================================================**/
#define CAN_HV500_ERPM_DUTY_VOLTAGE_ID 0x14
/**======================================================================**/
#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] << 10 | 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[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[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[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
/**======================================================================**/
#define MAP_DECODE_Actual_Throttle(x) (x[0])
#define MAP_DECODE_Actual_Brake(x) (x[1])
#define MAP_DECODE_Digital_input_1(x) (x[2] & 0x01)
#define MAP_DECODE_Digital_input_2(x) (x[2] & 0x02)
#define MAP_DECODE_Digital_input_3(x) (x[2] & 0x04)
#define MAP_DECODE_Digital_input_4(x) (x[2] & 0x08)
#define MAP_DECODE_Digital_output_1(x) (x[2] & 0x10)
#define MAP_DECODE_Digital_output_2(x) (x[2] & 0x20)
#define MAP_DECODE_Digital_output_3(x) (x[2] & 0x40)
#define MAP_DECODE_Digital_output_4(x) (x[2] & 0x80)
#define MAP_DECODE_Drive_enable(x) (x[3])
#define MAP_DECODE_Capacitor_temp_limit(x) (x[4] & 0x01)
#define MAP_DECODE_DC_current_limit(x) (x[4] & 0x02)
#define MAP_DECODE_Drive_enable_limit(x) (x[4] & 0x04)
#define MAP_DECODE_IGBT_accel_limit(x) (x[4] & 0x08)
#define MAP_DECODE_IGBT_temp_limit(x) (x[4] & 0x10)
#define MAP_DECODE_Input_voltage_limit(x) (x[4] & 0x20)
#define MAP_DECODE_Motor_accel_limit(x) (x[4] & 0x40)
#define MAP_DECODE_Motor_temp_limit(x) (x[4] & 0x80)
#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)
#define MAP_DECODE_CAN_map_version(x) (x[7])

/**======================================================================**/
#define CAN_HV500_SetAcCurrent_ID 0x354
/**======================================================================**/
#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[0] = (x >> 8) & 0xFF, pnt[1] = x * 10 & 0xFF)

/**======================================================================**/
#define CAN_HV500_SetERPM_ID 0x394
/**======================================================================**/
#define MAP_ENCODE_CMD_ERPM(pnt, x) (pnt[0] = (x >> 16) & 0xFF, pnt[1] = (x >> 8) & 0xFF, pnt[2] = x & 0xFF)

/**======================================================================**/
#define CAN_HV500_SetPosition_ID 0x3b4
/**======================================================================**/
#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[0] = (x >> 8) & 0xFF, pnt[1] = x * 10 & 0xFF)

/**======================================================================**/
#define CAN_HV500_SetRelBrakeCurrent_ID 0x3F4
/**======================================================================**/
#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[0] = (x >> 8) & 0xFF, pnt[1] = x * 10 & 0xFF)

/**======================================================================**/
#define CAN_HV500_SetMaxAcBrakeCurrent_ID 0x434
/**======================================================================**/
#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[0] = (x >> 8) & 0xFF, pnt[1] = x * 10 & 0xFF)

/**======================================================================**/
#define CAN_HV500_SetMaxDcBrakeCurrent_ID 0x474
/**======================================================================**/
#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)

// #endif

#endif // CAN_PWTDB_H

0 comments on commit c1d1d05

Please sign in to comment.