Browse Source

增加了电机控制程序,五个继电器方案

CHENJIE-PC\QiXiang_CHENJIE 3 years ago
parent
commit
b8c701e0a9

+ 5 - 3
Global/SysConf.h

@@ -3,7 +3,7 @@
  * @Date         : 2021-11-24 14:01:24
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-12-29 15:46:21
+ * @LastEditTime : 2022-01-11 17:40:47
  * @Description  : file content
  * @FilePath     : \VehicleControl\VehicleControl\src\Global\SysConf.h
  */
@@ -26,7 +26,9 @@
 #define __SYSCONF_H
 
 #define _SAMPLE_CODE_
-
+#define MAX(a, b) (((a) > (b)) ? (a) : (b))
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))
 //#define _APP_TEST_CODE
-#define _APP_RELEASE_CODE
+//#define _APP_RELEASE_CODE
+#define _APP_TEST_MOTOR_CODE
 #endif

+ 14 - 8
HardwareLib/HardwareLib.h

@@ -137,14 +137,14 @@ uint16 ATDDrv_GetChanResult(uint8 idxChanUB); //
 #define _DIN_INDEX_UNLOCKSENSOR3 3 //对应接插件XK13,松开传感器3,需配置低有效
 #define _DIN_INDEX_UNLOCKSENSOR4 4 //对应接插件XK14,松开传感器4,需配置低有效
 
-#define _DIN_INDEX_LOCKSENSOR1 8  //对应接插件XK15,夹紧传感器1,需配置低有效
-#define _DIN_INDEX_LOCKSENSOR2 1  //对应接插件XK17,夹紧传感器2,需配置低有效
-#define _DIN_INDEX_LOCKSENSOR3 2  //对应接插件XK18,夹紧传感器3,需配置低有效
-#define _DIN_INDEX_LOCKSENSOR4 11 //对应接插件XK6,夹紧传感器4,需配置低有效
-
-#define _DIN_INDEX_READYSENSOR1 9 //对应接插件XK4,落座传感器1,需配置高有效
-#define _DIN_INDEX_READYSENSOR2 6 //对应接插件XK5,落座传感器2,需配置高有效
-#define _DIN_INDEX_PLUGHVLOCK 5   //对应接插件XK9,接插件互锁1,需配置高有效
+#define _DIN_INDEX_LOCKSENSOR1 8 //对应接插件XK15,夹紧传感器1,需配置低有效
+#define _DIN_INDEX_LOCKSENSOR2 1 //对应接插件XK17,夹紧传感器2,需配置低有效
+#define _DIN_INDEX_LOCKSENSOR3 2 //对应接插件XK18,夹紧传感器3,需配置低有效
+#define _DIN_INDEX_LOCKSENSOR4 6 //对应接插件XK5,夹紧传感器4,需配置低有效
+
+#define _DIN_INDEX_READYSENSOR1 11 //对应接插件XK6,落座传感器1,高有效
+#define _DIN_INDEX_READYSENSOR2 10 //对应接插件XK7,落座传感器2,高有效
+#define _DIN_INDEX_PLUGHVLOCK 12   //对应接插件XK3,接插件互锁1,高有效
 void DINDrv_SetChanThres(uint8 idxChanUB, uint8 stOpenLvlUB, uint16 uThresUW);
 uint8 DINDrv_GetChanState(uint8 idxChanUB); //得到上述通道开关状态
 //********************************************************************************************
@@ -224,6 +224,12 @@ DSM_stDiagE_TYPE PPWMDrv_GetChanDiagInfo(uint8 idxChanUB, DSM_idxDiagTypeE_TYPE
 #define _PSWT_INDEX_AIRCONTROL 0      //电磁阀控制,对应接插件XK36
 #define _PSWT_INDEX_EBCLEDCONTROL 1   //换电LED控制,对应接插件XK32
 #define _PSWT_INDEX_BLEPWRCONTROL 2   //蓝牙电源控制,对应接插件XK28
+#define _M1_C 8                       // M1-控制,对应接插件X34
+#define _M2_C 9                       // M2-控制,对应接插件X44
+#define _M3_C 10                      // M3-控制,对应接插件X41
+#define _M4_C 11                      // M4-控制,对应接插件X43
+
+#define _M_D_C 15 // M4-反转控制,对应接插件X48
 //该函数须放在10ms任务中调用
 void PSwtDrv_Interface(uint8 idxChanUB, uint8 bOpenUB); //输出上述通道的低边驱动状态, bOpen=1时为打开, 否则为关闭
 DSM_stDiagE_TYPE PSwtDrv_GetChanDiagInfo(uint8 idxChanUB, DSM_idxDiagTypeE_TYPE idxDiagTypeE);

+ 637 - 174
System/Vehicle/AppFunc.c

@@ -3,7 +3,7 @@
  * @Date         : 2021-12-15 10:40:06
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-12-29 15:49:58
+ * @LastEditTime : 2022-01-11 18:14:41
  * @Description  : AppFunc
  * @FilePath     : \VehicleControl\VehicleControl\src\System\Vehicle\AppFunc.c
  */
@@ -21,25 +21,25 @@
  */
 void GetHVLockState(void)
 {
-	UINT8 m_flg_HVlock1 = 0,m_flg_HVlock2 = 0;
-    // PWM输出,互锁1检测,频率100HZ,占空比30%
-    uint16 VehCo_fTestUI = 1000;
-    uint16 VehCo_rTestUW = 3000;
-    uint32 PwmFreAcq = 0;
-    uint16 PwmDutyAcq = 0;
-    PPWMDrv_Interface(_PPWM_INDEX_HVLOCK2, VehCo_fTestUI, VehCo_rTestUW);
-    PulseAcqDrv_GetChanFreq(_PULSEACQ_INDEX_HVLOCK2, &PwmFreAcq, &PwmDutyAcq);
-    if (abs(PwmFreAcq - VehCo_fTestUI) < 100 && abs(PwmDutyAcq - VehCo_rTestUW) < 500)
-    {
-    	m_flg_HVlock1 = 1;
-    }
-    else
-    {
-    	m_flg_HVlock1 = 0;
-    }
-    //互锁2检测,配置高有效,悬空为0则未接入,高电平为1则接入,
-    DINDrv_SetChanThres(_DIN_INDEX_PLUGHVLOCK, 0, 4095 * 3);
-    m_flg_HVlock2 = DINDrv_GetChanState(_DIN_INDEX_PLUGHVLOCK);
+	UINT8 m_flg_HVlock1 = 0, m_flg_HVlock2 = 0;
+	// PWM输出,互锁1检测,频率100HZ,占空比30%
+	uint16 VehCo_fTestUI = 1000;
+	uint16 VehCo_rTestUW = 3000;
+	uint32 PwmFreAcq = 0;
+	uint16 PwmDutyAcq = 0;
+	PPWMDrv_Interface(_PPWM_INDEX_HVLOCK2, VehCo_fTestUI, VehCo_rTestUW);
+	PulseAcqDrv_GetChanFreq(_PULSEACQ_INDEX_HVLOCK2, &PwmFreAcq, &PwmDutyAcq);
+	if (abs(PwmFreAcq - VehCo_fTestUI) < 100 && abs(PwmDutyAcq - VehCo_rTestUW) < 500)
+	{
+		m_flg_HVlock1 = 1;
+	}
+	else
+	{
+		m_flg_HVlock1 = 0;
+	}
+	//互锁2检测,配置高有效,悬空为0则未接入,高电平为1则接入,
+	// DINDrv_SetChanThres(_DIN_INDEX_PLUGHVLOCK, 0, 4095 * 3);
+	m_flg_HVlock2 = DINDrv_GetChanState(_DIN_INDEX_PLUGHVLOCK);
 }
 /**
  * @brief : 数字量传感器信号检测函数
@@ -48,38 +48,40 @@ void GetHVLockState(void)
  */
 void GetDIOState(void)
 {
-    uint8 temp[4];
-    //松开传感器检测,配置低有效,底层悬空为1,触发为0,应用层输出悬空为0,触发为1
-    memset(temp, 0x00, 4);
-    DINDrv_SetChanThres(_DIN_INDEX_UNLOCKSENSOR1, 1, 4095U);
-    DINDrv_SetChanThres(_DIN_INDEX_UNLOCKSENSOR2, 1, 4095U);
-    DINDrv_SetChanThres(_DIN_INDEX_UNLOCKSENSOR3, 1, 4095U);
-    DINDrv_SetChanThres(_DIN_INDEX_UNLOCKSENSOR4, 1, 4095U);
-    temp[0] = !DINDrv_GetChanState(_DIN_INDEX_UNLOCKSENSOR1);
-    temp[1] = !DINDrv_GetChanState(_DIN_INDEX_UNLOCKSENSOR2);
-    temp[2] = !DINDrv_GetChanState(_DIN_INDEX_UNLOCKSENSOR3);
-    temp[3] = !DINDrv_GetChanState(_DIN_INDEX_UNLOCKSENSOR4);
-    ebcd_st_unlockSensor = (getbit(temp[3], 0) << 3) | (getbit(temp[2], 0) << 2) | (getbit(temp[1], 0) << 1) | (getbit(temp[0], 0) << 0);
+	uint8 temp[4];
+	//松开传感器检测,配置低有效,底层悬空为1,触发为0,应用层输出悬空为0,触发为1
+	memset(temp, 0x00, 4);
+	ebcd_st_unlockSensor = 0;
+	DINDrv_SetChanThres(_DIN_INDEX_UNLOCKSENSOR1, 1, 4095U);
+	DINDrv_SetChanThres(_DIN_INDEX_UNLOCKSENSOR2, 1, 4095U);
+	DINDrv_SetChanThres(_DIN_INDEX_UNLOCKSENSOR3, 1, 4095U);
+	DINDrv_SetChanThres(_DIN_INDEX_UNLOCKSENSOR4, 1, 4095U);
+	temp[0] = !DINDrv_GetChanState(_DIN_INDEX_UNLOCKSENSOR1);
+	temp[1] = !DINDrv_GetChanState(_DIN_INDEX_UNLOCKSENSOR2);
+	temp[2] = !DINDrv_GetChanState(_DIN_INDEX_UNLOCKSENSOR3);
+	temp[3] = !DINDrv_GetChanState(_DIN_INDEX_UNLOCKSENSOR4);
+	ebcd_st_unlockSensor = (getbit(temp[3], 0) << 3) | (getbit(temp[2], 0) << 2) | (getbit(temp[1], 0) << 1) | (getbit(temp[0], 0) << 0);
 
-    //夹紧传感器检测,配置低有效,底层悬空为1,触发为0,应用层输出悬空为0,触发为1
-    memset(temp, 0x00, 4);
-    DINDrv_SetChanThres(_DIN_INDEX_LOCKSENSOR1, 1, 4095U);
-    DINDrv_SetChanThres(_DIN_INDEX_LOCKSENSOR2, 1, 4095U);
-    DINDrv_SetChanThres(_DIN_INDEX_LOCKSENSOR3, 1, 4095U);
-    DINDrv_SetChanThres(_DIN_INDEX_LOCKSENSOR4, 1, 4095U);
-    temp[0] = !DINDrv_GetChanState(_DIN_INDEX_LOCKSENSOR1);
-    temp[1] = !DINDrv_GetChanState(_DIN_INDEX_LOCKSENSOR2);
-    temp[2] = !DINDrv_GetChanState(_DIN_INDEX_LOCKSENSOR3);
-    temp[3] = !DINDrv_GetChanState(_DIN_INDEX_LOCKSENSOR4);
-    ebcd_st_lockSensor = (getbit(temp[3], 0) << 3) | (getbit(temp[2], 0) << 2) | (getbit(temp[1], 0) << 1) | (getbit(temp[0], 0) << 0);
+	//夹紧传感器检测,配置低有效,底层悬空为1,触发为0,应用层输出悬空为0,触发为1
+	memset(temp, 0x00, 4);
+	ebcd_st_lockSensor = 0;
+	DINDrv_SetChanThres(_DIN_INDEX_LOCKSENSOR1, 1, 4095U);
+	DINDrv_SetChanThres(_DIN_INDEX_LOCKSENSOR2, 1, 4095U);
+	DINDrv_SetChanThres(_DIN_INDEX_LOCKSENSOR3, 1, 4095U);
+	DINDrv_SetChanThres(_DIN_INDEX_LOCKSENSOR4, 1, 4095U);
+	temp[0] = !DINDrv_GetChanState(_DIN_INDEX_LOCKSENSOR1);
+	temp[1] = !DINDrv_GetChanState(_DIN_INDEX_LOCKSENSOR2);
+	temp[2] = !DINDrv_GetChanState(_DIN_INDEX_LOCKSENSOR3);
+	temp[3] = !DINDrv_GetChanState(_DIN_INDEX_LOCKSENSOR4);
+	ebcd_st_lockSensor = (getbit(temp[3], 0) << 3) | (getbit(temp[2], 0) << 2) | (getbit(temp[1], 0) << 1) | (getbit(temp[0], 0) << 0);
 
-    //落座传感器检测,配置高有效,悬空为0则未接入,高电平为1则接入
-    memset(temp, 0x00, 4);
-    DINDrv_SetChanThres(_DIN_INDEX_READYSENSOR1, 0, 4095 * 3);
-    DINDrv_SetChanThres(_DIN_INDEX_READYSENSOR2, 0, 4095 * 3);
-    temp[0] = DINDrv_GetChanState(_DIN_INDEX_READYSENSOR1);
-    temp[1] = DINDrv_GetChanState(_DIN_INDEX_READYSENSOR1);
-    ebcd_st_pedstSensor = (getbit(temp[1], 0) << 1) | (getbit(temp[0], 0) << 0);
+	//落座传感器检测,高有效,悬空为0则未接入,高电平为1则接入
+	memset(temp, 0x00, 4);
+	// DINDrv_SetChanThres(_DIN_INDEX_READYSENSOR1, 0, 4095 * 3);
+	// DINDrv_SetChanThres(_DIN_INDEX_READYSENSOR2, 0, 4095 * 3);
+	temp[0] = DINDrv_GetChanState(_DIN_INDEX_READYSENSOR1);
+	temp[1] = DINDrv_GetChanState(_DIN_INDEX_READYSENSOR2);
+	ebcd_st_pedstSensor = (getbit(temp[1], 0) << 1) | (getbit(temp[0], 0) << 0);
 }
 
 /**
@@ -89,32 +91,32 @@ void GetDIOState(void)
  */
 void GetAIOValue(void)
 {
-    uint16 AirPressureTemp_Vol = 0;
-    uint16 PluginTemp1_Vol = 0;
-    uint32 PluginTemp1_R = 0;
-    uint16 PluginTemp2_Vol = 0;
-    uint32 PluginTemp2_R = 0;
-    uint16 PluginTemp3_Vol = 0;
-    uint32 PluginTemp3_R = 0;
-    uint16 PluginTemp4_Vol = 0;
-    uint32 PluginTemp4_R = 0;
+	uint16 AirPressureTemp_Vol = 0;
+	uint16 PluginTemp1_Vol = 0;
+	uint32 PluginTemp1_R = 0;
+	uint16 PluginTemp2_Vol = 0;
+	uint32 PluginTemp2_R = 0;
+	uint16 PluginTemp3_Vol = 0;
+	uint32 PluginTemp3_R = 0;
+	uint16 PluginTemp4_Vol = 0;
+	uint32 PluginTemp4_R = 0;
 
-    AirPressureTemp_Vol = ATDDrv_GetChanResult(_ATD_INDEX_AIRPRESSURE);
-    /*气压数据转换*/
-    ebcd_P_airSensor = (uint16)(AirPressureTemp_Vol * 1000 / 4095.0);
-    /*温度采集获取*/
-    PluginTemp1_Vol = ATDDrv_GetChanResult(_ATD_INDEX_PLUGINTEMP1);
-    PluginTemp2_Vol = ATDDrv_GetChanResult(_ATD_INDEX_PLUGINTEMP2);
-    PluginTemp3_Vol = ATDDrv_GetChanResult(_ATD_INDEX_PLUGINTEMP3);
-    PluginTemp4_Vol = ATDDrv_GetChanResult(_ATD_INDEX_PLUGINTEMP4);
-    PluginTemp1_R = (uint32)((PluginTemp1_Vol / (5.0 * 4095 - PluginTemp1_Vol)) * 1000.0);
-    PluginTemp2_R = (uint32)((PluginTemp2_Vol / (5.0 * 4095 - PluginTemp2_Vol)) * 1000.0);
-    PluginTemp3_R = (uint32)((PluginTemp3_Vol / (5.0 * 4095 - PluginTemp3_Vol)) * 1000.0);
-    PluginTemp4_R = (uint32)((PluginTemp4_Vol / (5.0 * 4095 - PluginTemp4_Vol)) * 1000.0);
-    ebcd_T_plugin[0] = (uint8)Look1_u32u16(PluginTemp1_R, R_table, T_table, 240);
-    ebcd_T_plugin[1] = (uint8)Look1_u32u16(PluginTemp2_R, R_table, T_table, 240);
-    ebcd_T_plugin[2] = (uint8)Look1_u32u16(PluginTemp3_R, R_table, T_table, 240);
-    ebcd_T_plugin[3] = (uint8)Look1_u32u16(PluginTemp4_R, R_table, T_table, 240);
+	AirPressureTemp_Vol = ATDDrv_GetChanResult(_ATD_INDEX_AIRPRESSURE);
+	/*气压数据转换*/
+	ebcd_P_airSensor = (uint16)(AirPressureTemp_Vol * 1000 / 4095.0);
+	/*温度采集获取*/
+	PluginTemp1_Vol = ATDDrv_GetChanResult(_ATD_INDEX_PLUGINTEMP1);
+	PluginTemp2_Vol = ATDDrv_GetChanResult(_ATD_INDEX_PLUGINTEMP2);
+	PluginTemp3_Vol = ATDDrv_GetChanResult(_ATD_INDEX_PLUGINTEMP3);
+	PluginTemp4_Vol = ATDDrv_GetChanResult(_ATD_INDEX_PLUGINTEMP4);
+	PluginTemp1_R = (uint32)((PluginTemp1_Vol / (5.0 * 4095 - PluginTemp1_Vol)) * 1000.0);
+	PluginTemp2_R = (uint32)((PluginTemp2_Vol / (5.0 * 4095 - PluginTemp2_Vol)) * 1000.0);
+	PluginTemp3_R = (uint32)((PluginTemp3_Vol / (5.0 * 4095 - PluginTemp3_Vol)) * 1000.0);
+	PluginTemp4_R = (uint32)((PluginTemp4_Vol / (5.0 * 4095 - PluginTemp4_Vol)) * 1000.0);
+	ebcd_T_plugin[0] = (uint8)Look1_u32u16(PluginTemp1_R, R_table, T_table, 240);
+	ebcd_T_plugin[1] = (uint8)Look1_u32u16(PluginTemp2_R, R_table, T_table, 240);
+	ebcd_T_plugin[2] = (uint8)Look1_u32u16(PluginTemp3_R, R_table, T_table, 240);
+	ebcd_T_plugin[3] = (uint8)Look1_u32u16(PluginTemp4_R, R_table, T_table, 240);
 }
 /**
  * @brief : lookUp Table Fun
@@ -126,111 +128,572 @@ void GetAIOValue(void)
  */
 uint16 Look1_u32u16(uint32 u0, uint32 *bp0, uint16 *table, uint16 MaxLen)
 {
-    uint32 bpIdx = 0;
-    uint32 iLeft = 0;
-    uint32 iRght = 0;
-    uint16 y = 0;
-    uint32 yL_0d0 = 0;
-    uint32 yR_0d0 = 0;
-    uint32 maxIndex = MaxLen - 1;
-    if (u0 <= bp0[0U])
-    {
-        iLeft = 0U;
-        iRght = 0U;
-    }
-    else if (u0 < bp0[maxIndex])
-    {
-        //对折法寻找u0的位置
-        bpIdx = maxIndex >> 1U;
-        iLeft = 0U;
-        iRght = maxIndex;
-        while ((iRght - iLeft) > 1)
-        {
-            if (u0 < bp0[bpIdx])
-            {
-                iRght = bpIdx;
-            }
-            else
-            {
-                iLeft = bpIdx;
-            }
-            bpIdx = (iRght + iLeft) >> 1U;
-        }
-    }
-    else
-    {
-        iLeft = maxIndex;
-        iRght = maxIndex;
-    }
-    //找到位置以后计算插值
-    if (iLeft != iRght)
-    {
-        //线性插值
-        yR_0d0 = table[iLeft + 1U];
-        yL_0d0 = table[iLeft];
-        if (yR_0d0 >= yL_0d0)
-        {
-            y = (uint16)(((uint32)(u0 - bp0[iLeft]) * (yR_0d0 - yL_0d0)) / (bp0[iLeft + 1] - bp0[iLeft]) + yL_0d0);
-        }
-        else
-        {
-            y = (uint16)(yL_0d0 - ((uint32)(u0 - bp0[iLeft]) * (yL_0d0 - yR_0d0)) / (bp0[iLeft + 1] - bp0[iLeft]));
-        }
-    }
-    else
-    {
-        y = (uint16)table[iLeft];
-    }
-    return y;
+	uint32 bpIdx = 0;
+	uint32 iLeft = 0;
+	uint32 iRght = 0;
+	uint16 y = 0;
+	uint32 yL_0d0 = 0;
+	uint32 yR_0d0 = 0;
+	uint32 maxIndex = MaxLen - 1;
+	if (u0 <= bp0[0U])
+	{
+		iLeft = 0U;
+		iRght = 0U;
+	}
+	else if (u0 < bp0[maxIndex])
+	{
+		//对折法寻找u0的位置
+		bpIdx = maxIndex >> 1U;
+		iLeft = 0U;
+		iRght = maxIndex;
+		while ((iRght - iLeft) > 1)
+		{
+			if (u0 < bp0[bpIdx])
+			{
+				iRght = bpIdx;
+			}
+			else
+			{
+				iLeft = bpIdx;
+			}
+			bpIdx = (iRght + iLeft) >> 1U;
+		}
+	}
+	else
+	{
+		iLeft = maxIndex;
+		iRght = maxIndex;
+	}
+	//找到位置以后计算插值
+	if (iLeft != iRght)
+	{
+		//线性插值
+		yR_0d0 = table[iLeft + 1U];
+		yL_0d0 = table[iLeft];
+		if (yR_0d0 >= yL_0d0)
+		{
+			y = (uint16)(((uint32)(u0 - bp0[iLeft]) * (yR_0d0 - yL_0d0)) / (bp0[iLeft + 1] - bp0[iLeft]) + yL_0d0);
+		}
+		else
+		{
+			y = (uint16)(yL_0d0 - ((uint32)(u0 - bp0[iLeft]) * (yL_0d0 - yR_0d0)) / (bp0[iLeft + 1] - bp0[iLeft]));
+		}
+	}
+	else
+	{
+		y = (uint16)table[iLeft];
+	}
+	return y;
 }
 #ifdef _APP_TEST_CODE
 void TestDeviceFun(void)
 {
-    uint8 ManuEnable = 0;
-    //控制算法
-    AccPedCD_Update();
-    AccPedCD_Monitor();
+	uint8 ManuEnable = 0;
+	//控制算法
+	AccPedCD_Update();
+	AccPedCD_Monitor();
 
-    PulseAcqDrv_GetChanFreq(_PULSEACQ_INDEX_CP_CHAN, &VehCo_fInputUIA[0], &VehCo_rInputUWA[0]);
+	PulseAcqDrv_GetChanFreq(_PULSEACQ_INDEX_CP_CHAN, &VehCo_fInputUIA[0], &VehCo_rInputUWA[0]);
 
-    // DODrv_SetChanState(_DO_INDEX_CPCTL_CHAN,(uint8)VehCo_bTestCPCtrlUW_C);
+	// DODrv_SetChanState(_DO_INDEX_CPCTL_CHAN,(uint8)VehCo_bTestCPCtrlUW_C);
 
-    uint16 DistenceBufferV[2] = {0, 0}, DistenceBufferR[2] = {0, 0};
-    //开关1采集
-    DINDrv_SetChanThres(_DIN_INDEX_BAK1_CHAN, 1, 4095U);
-    Switch1 = !DINDrv_GetChanState(_DIN_INDEX_BAK1_CHAN);
-    //手动控制采集
-    DINDrv_SetChanThres(_DIN_INDEX_BAK2_CHAN, 1, 4095U);
-    ManuEnable = !DINDrv_GetChanState(_DIN_INDEX_BAK2_CHAN);
-    //位移量采集
-    DistenceBufferV[0] = ATDDrv_GetChanResult(_ATD_INDEX_BAK3_CHAN);
-    DistenceBufferR[0] = (uint16)((DistenceBufferV[0] / (5.0 * 4095 - DistenceBufferV[0])) * 1000.0);
-    Distence1 = (uint16)((2132 - DistenceBufferR[0]) * (0.1219));
-    //压力采集
-    PressureValueBuffer = ATDDrv_GetChanResult(_ATD_INDEX_ACCPED1_CHAN);
-    PressureValue = (uint32)(PressureValueBuffer * 1000 / 4095.0);
-    //控制输出
-    VehCo_ctEEPTestUI += 10;
-    VehCo_ctEEPTestUB += 10;
-    if (VehCo_ctEEPTestUI >= 4 * 1000)
-    {
-        PSwtDrv_Interface(_PSWT_INDEX_HBAK1_CHAN, 1); //输出 解锁持续9-4s
-        ControlState = 1;                             //解锁
-    }
-    else
-    {
-        PSwtDrv_Interface(_PSWT_INDEX_HBAK1_CHAN, 0); //不输出
-        ControlState = 2;                             //锁定 4 秒
-    }
-    if (VehCo_ctEEPTestUI >= 9 * 1000)
-    {
-        Control_Times++;
-        VehCo_ctEEPTestUI = 0;
-    }
-    if (ManuEnable == 0)
-    {
-        Control_Times = 0;
-        VehCo_ctEEPTestUI = 0;
-    }
+	uint16 DistenceBufferV[2] = {0, 0}, DistenceBufferR[2] = {0, 0};
+	//开关1采集
+	DINDrv_SetChanThres(_DIN_INDEX_BAK1_CHAN, 1, 4095U);
+	Switch1 = !DINDrv_GetChanState(_DIN_INDEX_BAK1_CHAN);
+	//手动控制采集
+	DINDrv_SetChanThres(_DIN_INDEX_BAK2_CHAN, 1, 4095U);
+	ManuEnable = !DINDrv_GetChanState(_DIN_INDEX_BAK2_CHAN);
+	//位移量采集
+	DistenceBufferV[0] = ATDDrv_GetChanResult(_ATD_INDEX_BAK3_CHAN);
+	DistenceBufferR[0] = (uint16)((DistenceBufferV[0] / (5.0 * 4095 - DistenceBufferV[0])) * 1000.0);
+	Distence1 = (uint16)((2132 - DistenceBufferR[0]) * (0.1219));
+	//压力采集
+	PressureValueBuffer = ATDDrv_GetChanResult(_ATD_INDEX_ACCPED1_CHAN);
+	PressureValue = (uint32)(PressureValueBuffer * 1000 / 4095.0);
+	//控制输出
+	VehCo_ctEEPTestUI += 10;
+	VehCo_ctEEPTestUB += 10;
+	if (VehCo_ctEEPTestUI >= 4 * 1000)
+	{
+		PSwtDrv_Interface(_PSWT_INDEX_HBAK1_CHAN, 1); //输出 解锁持续9-4s
+		ControlState = 1;							  //解锁
+	}
+	else
+	{
+		PSwtDrv_Interface(_PSWT_INDEX_HBAK1_CHAN, 0); //不输出
+		ControlState = 2;							  //锁定 4 秒
+	}
+	if (VehCo_ctEEPTestUI >= 9 * 1000)
+	{
+		Control_Times++;
+		VehCo_ctEEPTestUI = 0;
+	}
+	if (ManuEnable == 0)
+	{
+		Control_Times = 0;
+		VehCo_ctEEPTestUI = 0;
+	}
+}
+#endif
+#ifdef _APP_TEST_MOTOR_CODE
+void MotorTestFun(void)
+{
+	static uint32 MotorRunTimer = 0;
+	static uint16 MotorLockReadyTimer = 0;
+	static sint8 LockMotorNum = -1;
+	static sint8 unLockMotorNum = -1;
+
+	GetDIOState();
+	if (MotorControlCmd == 0) //可进入调试模式
+	{
+		if (MotorDebugCmd == 1)
+		{
+			if (getbit(MotorControlEnable, 0) == 1)
+			{
+				MotorControlFunc(0, 1);
+				return;
+			}
+			else if (getbit(MotorControlEnable, 1) == 1)
+			{
+				MotorControlFunc(1, 1);
+				return;
+			}
+			else if (getbit(MotorControlEnable, 2) == 1)
+			{
+				MotorControlFunc(2, 1);
+				return;
+			}
+			else if (getbit(MotorControlEnable, 3) == 1)
+			{
+				MotorControlFunc(3, 1);
+				return;
+			}
+			else
+			{
+				return;
+			}
+		}
+		else if (MotorDebugCmd == 2)
+		{
+			if (getbit(MotorControlEnable, 0) == 1)
+			{
+				MotorControlFunc(0, 2);
+				return;
+			}
+			else if (getbit(MotorControlEnable, 1) == 1)
+			{
+				MotorControlFunc(1, 2);
+				return;
+			}
+			else if (getbit(MotorControlEnable, 2) == 1)
+			{
+				MotorControlFunc(2, 2);
+				return;
+			}
+			else if (getbit(MotorControlEnable, 3) == 1)
+			{
+				MotorControlFunc(3, 2);
+				return;
+			}
+			else
+			{
+				return;
+			}
+		}
+		else
+		{
+			MotorControlFunc(0, 0xF1);
+			LockMotorNum = -1;
+			unLockMotorNum = -1;
+			return;
+		}
+	}
+	else if (MotorControlCmd == 1) //控制锁紧的自动流程
+	{
+		switch (LockMotorNum)
+		{
+		case -1:
+		{
+			MotorControlFunc(0, 0xF1);
+			LockMotorNum = 0;
+			break;
+		}
+		case 0:
+		{
+			if ((MotorRunTimer >= RunFailedDelay) || (MotorLockReadyTimer >= LockDelay) || getbit(MotorControlEnable, LockMotorNum) != 1)
+			{
+				MotorControlFunc(LockMotorNum, 0xF1);
+				LockMotorNum = 1;
+				MotorRunTimer = 0;
+				MotorLockReadyTimer = 0;
+			}
+			else
+			{
+				if (getbit(ebcd_st_lockSensor, LockMotorNum) == 1)
+				{
+					MotorLockReadyTimer = MotorLockReadyTimer + 10;
+				}
+				MotorControlFunc(LockMotorNum, 1);
+				MotorRunTimer = MotorRunTimer + 10;
+			}
+			break;
+		}
+		case 1:
+		{
+			if ((MotorRunTimer >= RunFailedDelay) || (MotorLockReadyTimer >= LockDelay) || getbit(MotorControlEnable, LockMotorNum) != 1)
+			{
+				MotorControlFunc(LockMotorNum, 0xF1);
+				LockMotorNum = 2;
+				MotorRunTimer = 0;
+				MotorLockReadyTimer = 0;
+			}
+			else
+			{
+				if (getbit(ebcd_st_lockSensor, LockMotorNum) == 1)
+				{
+					MotorLockReadyTimer = MotorLockReadyTimer + 10;
+				}
+				MotorControlFunc(LockMotorNum, 1);
+				MotorRunTimer = MotorRunTimer + 10;
+			}
+			break;
+		}
+		case 2:
+		{
+			if ((MotorRunTimer >= RunFailedDelay) || (MotorLockReadyTimer >= LockDelay) || getbit(MotorControlEnable, LockMotorNum) != 1)
+			{
+				MotorControlFunc(LockMotorNum, 0xF1);
+				LockMotorNum = 3;
+				MotorRunTimer = 0;
+				MotorLockReadyTimer = 0;
+			}
+			else
+			{
+				if (getbit(ebcd_st_lockSensor, LockMotorNum) == 1)
+				{
+					MotorLockReadyTimer = MotorLockReadyTimer + 10;
+				}
+				MotorControlFunc(LockMotorNum, 1);
+				MotorRunTimer = MotorRunTimer + 10;
+			}
+			break;
+		}
+		case 3:
+		{
+			if ((MotorRunTimer >= RunFailedDelay) || (MotorLockReadyTimer >= LockDelay) || getbit(MotorControlEnable, LockMotorNum) != 1)
+			{
+				MotorControlFunc(LockMotorNum, 0xF1);
+				LockMotorNum = 4;
+				unLockMotorNum = -1;
+				MotorRunTimer = 0;
+				MotorLockReadyTimer = 0;
+			}
+			else
+			{
+				if (getbit(ebcd_st_lockSensor, LockMotorNum) == 1)
+				{
+					MotorLockReadyTimer = MotorLockReadyTimer + 10;
+				}
+				MotorControlFunc(LockMotorNum, 1);
+				MotorRunTimer = MotorRunTimer + 10;
+			}
+			break;
+		}
+		default:
+			break;
+		}
+	}
+	else if (MotorControlCmd == 2) //控制解锁的自动流程
+	{
+		switch (unLockMotorNum)
+		{
+		case -1:
+		{
+			MotorControlFunc(0, 0xF2);
+			unLockMotorNum = 0;
+			break;
+		}
+		case 0:
+		{
+			if ((MotorRunTimer >= RunFailedDelay) || (MotorLockReadyTimer >= 1) || getbit(MotorControlEnable, unLockMotorNum) != 1)
+			{
+				MotorControlFunc(unLockMotorNum, 0xF2);
+				unLockMotorNum = 1;
+				MotorRunTimer = 0;
+				MotorLockReadyTimer = 0;
+			}
+			else
+			{
+				if (getbit(ebcd_st_unlockSensor, unLockMotorNum) == 1)
+				{
+					MotorLockReadyTimer = MotorLockReadyTimer + 10;
+				}
+				MotorControlFunc(unLockMotorNum, 2);
+				MotorRunTimer = MotorRunTimer + 10;
+			}
+			break;
+		}
+		case 1:
+		{
+			if ((MotorRunTimer >= RunFailedDelay) || (MotorLockReadyTimer >= 1) || getbit(MotorControlEnable, unLockMotorNum) != 1)
+			{
+				MotorControlFunc(unLockMotorNum, 0xF2);
+				unLockMotorNum = 2;
+				MotorRunTimer = 0;
+				MotorLockReadyTimer = 0;
+			}
+			else
+			{
+				if (getbit(ebcd_st_unlockSensor, unLockMotorNum) == 1)
+				{
+					MotorLockReadyTimer = MotorLockReadyTimer + 10;
+				}
+				MotorControlFunc(unLockMotorNum, 2);
+				MotorRunTimer = MotorRunTimer + 10;
+			}
+			break;
+		}
+		case 2:
+		{
+			if ((MotorRunTimer >= RunFailedDelay) || (MotorLockReadyTimer >= 1) || getbit(MotorControlEnable, unLockMotorNum) != 1)
+			{
+				MotorControlFunc(unLockMotorNum, 0xF2);
+				unLockMotorNum = 3;
+				MotorRunTimer = 0;
+				MotorLockReadyTimer = 0;
+			}
+			else
+			{
+				if (getbit(ebcd_st_unlockSensor, unLockMotorNum) == 1)
+				{
+					MotorLockReadyTimer = MotorLockReadyTimer + 10;
+				}
+				MotorControlFunc(unLockMotorNum, 2);
+				MotorRunTimer = MotorRunTimer + 10;
+			}
+			break;
+		}
+		case 3:
+		{
+			if ((MotorRunTimer >= RunFailedDelay) || (MotorLockReadyTimer >= 1) || getbit(MotorControlEnable, unLockMotorNum) != 1)
+			{
+				MotorControlFunc(unLockMotorNum, 0xF2);
+				unLockMotorNum = 4;
+				MotorRunTimer = 0;
+				MotorLockReadyTimer = 0;
+			}
+			else
+			{
+				if (getbit(ebcd_st_unlockSensor, unLockMotorNum) == 1)
+				{
+					MotorLockReadyTimer = MotorLockReadyTimer + 10;
+				}
+				MotorControlFunc(unLockMotorNum, 2);
+				MotorRunTimer = MotorRunTimer + 10;
+			}
+			break;
+		}
+		case 4:
+		{
+			MotorControlFunc(0, 0xF1);
+			unLockMotorNum = 5;
+			LockMotorNum = -1;
+			break;
+		}
+		default:
+			break;
+		}
+	}
+}
+void MotorControlFunc(UINT8 MotorIdx, UINT8 RotateDirec) // MotorIdx 0-3 表示四个电机,RotateDirec F1停止正转,F2表示反转停止,1表示正转,2表示反转
+{
+	switch (MotorIdx)
+	{
+	case 0:
+	{
+		switch (RotateDirec)
+		{
+		case 0xF1:
+		{
+			PSwtDrv_Interface(_M1_C, 0);
+			PSwtDrv_Interface(_M2_C, 0);
+			PSwtDrv_Interface(_M3_C, 0);
+			PSwtDrv_Interface(_M4_C, 0);
+			PSwtDrv_Interface(_M_D_C, 0);
+			break;
+		}
+		case 0xF2:
+		{
+			PSwtDrv_Interface(_M1_C, 1);
+			PSwtDrv_Interface(_M2_C, 1);
+			PSwtDrv_Interface(_M3_C, 1);
+			PSwtDrv_Interface(_M4_C, 1);
+			PSwtDrv_Interface(_M_D_C, 1);
+			break;
+		}
+		case 1:
+		{
+			PSwtDrv_Interface(_M1_C, 0);
+			PSwtDrv_Interface(_M_D_C, 0);
+			PSwtDrv_Interface(_M1_C, 1);
+			break;
+		}
+		case 2:
+		{
+			PSwtDrv_Interface(_M1_C, 1);
+			PSwtDrv_Interface(_M_D_C, 1);
+			PSwtDrv_Interface(_M1_C, 0);
+			break;
+		}
+		default:
+			break;
+		}
+		break;
+	}
+	case 1:
+	{
+		switch (RotateDirec)
+		{
+		case 0xF1:
+		{
+			PSwtDrv_Interface(_M1_C, 0);
+			PSwtDrv_Interface(_M2_C, 0);
+			PSwtDrv_Interface(_M3_C, 0);
+			PSwtDrv_Interface(_M4_C, 0);
+			PSwtDrv_Interface(_M_D_C, 0);
+			break;
+		}
+		case 0xF2:
+		{
+			PSwtDrv_Interface(_M1_C, 1);
+			PSwtDrv_Interface(_M2_C, 1);
+			PSwtDrv_Interface(_M3_C, 1);
+			PSwtDrv_Interface(_M4_C, 1);
+			PSwtDrv_Interface(_M_D_C, 1);
+			break;
+		}
+		case 0:
+		{
+			PSwtDrv_Interface(_M2_C, 0);
+			PSwtDrv_Interface(_M_D_C, 0);
+			break;
+		}
+		case 1:
+		{
+			PSwtDrv_Interface(_M2_C, 0);
+			PSwtDrv_Interface(_M_D_C, 0);
+			PSwtDrv_Interface(_M2_C, 1);
+			break;
+		}
+		case 2:
+		{
+			PSwtDrv_Interface(_M2_C, 1);
+			PSwtDrv_Interface(_M_D_C, 1);
+			PSwtDrv_Interface(_M2_C, 0);
+			break;
+		}
+		default:
+			break;
+		}
+		break;
+	}
+	case 2:
+	{
+		switch (RotateDirec)
+		{
+		case 0xF1:
+		{
+			PSwtDrv_Interface(_M1_C, 0);
+			PSwtDrv_Interface(_M2_C, 0);
+			PSwtDrv_Interface(_M3_C, 0);
+			PSwtDrv_Interface(_M4_C, 0);
+			PSwtDrv_Interface(_M_D_C, 0);
+			break;
+		}
+		case 0xF2:
+		{
+			PSwtDrv_Interface(_M1_C, 1);
+			PSwtDrv_Interface(_M2_C, 1);
+			PSwtDrv_Interface(_M3_C, 1);
+			PSwtDrv_Interface(_M4_C, 1);
+			PSwtDrv_Interface(_M_D_C, 1);
+			break;
+		}
+		case 0:
+		{
+			PSwtDrv_Interface(_M3_C, 0);
+			PSwtDrv_Interface(_M_D_C, 0);
+			break;
+		}
+		case 1:
+		{
+			PSwtDrv_Interface(_M3_C, 0);
+			PSwtDrv_Interface(_M_D_C, 0);
+			PSwtDrv_Interface(_M3_C, 1);
+			break;
+		}
+		case 2:
+		{
+			PSwtDrv_Interface(_M3_C, 1);
+			PSwtDrv_Interface(_M_D_C, 1);
+			PSwtDrv_Interface(_M3_C, 0);
+			break;
+		}
+		default:
+			break;
+		}
+		break;
+	}
+	case 3:
+	{
+		switch (RotateDirec)
+		{
+		case 0xF1:
+		{
+			PSwtDrv_Interface(_M1_C, 0);
+			PSwtDrv_Interface(_M2_C, 0);
+			PSwtDrv_Interface(_M3_C, 0);
+			PSwtDrv_Interface(_M4_C, 0);
+			PSwtDrv_Interface(_M_D_C, 0);
+			break;
+		}
+		case 0xF2:
+		{
+			PSwtDrv_Interface(_M1_C, 1);
+			PSwtDrv_Interface(_M2_C, 1);
+			PSwtDrv_Interface(_M3_C, 1);
+			PSwtDrv_Interface(_M4_C, 1);
+			PSwtDrv_Interface(_M_D_C, 1);
+			break;
+		}
+		case 0:
+		{
+			PSwtDrv_Interface(_M4_C, 0);
+			PSwtDrv_Interface(_M_D_C, 0);
+			break;
+		}
+		case 1:
+		{
+			PSwtDrv_Interface(_M4_C, 0);
+			PSwtDrv_Interface(_M_D_C, 0);
+			PSwtDrv_Interface(_M4_C, 1);
+			break;
+		}
+		case 2:
+		{
+			PSwtDrv_Interface(_M4_C, 1);
+			PSwtDrv_Interface(_M_D_C, 1);
+			PSwtDrv_Interface(_M4_C, 0);
+			break;
+		}
+		default:
+			break;
+		}
+		break;
+	}
+	default:
+		break;
+	}
 }
 #endif

+ 3 - 0
System/Vehicle/AppFunc.h

@@ -23,4 +23,7 @@ uint16 Look1_u32u16(uint32 u0, uint32 *bp0, uint16 *table, uint16 MaxLen);
 #ifdef _APP_TEST_CODE
 void TestDeviceFun(void);
 #endif
+#ifdef _APP_TEST_MOTOR_CODE
+void MotorControlFunc(UINT8 MotorIdx,UINT8 RotateDirec);
+#endif
 #endif /* SYSTEM_VEHICLE_APPFUNCION_H_ */

+ 105 - 53
System/Vehicle/Communication/CANNet.c

@@ -22,6 +22,7 @@ MCAN_stRetE_TYPE CAN1Result;
 uint16 CANNet_idxSchedUB;
 MCANDrv_infoMsgConfS_TYPE CANNet_InfoRxMsgConfSA[128];
 uint8 CANNet_datRxMsgBufM[128][9];
+uint8 Can2counter = 0;
 void CANNet_Init(void)
 {
 	/*示例代码*/
@@ -36,15 +37,23 @@ void CANNet_Init(void)
 	MCANDrv_SetCallbackFunc(_CAN_INDEX_CAN1, (pFunc_RxMsgCallback)CANNet_RecvMsgCAN1, NULL_PTR);
 
 	/*第2路CAN用于CCP、UDS协议,由底层配置*/
+	// MCANDrv_SetCallbackFunc(_CAN_INDEX_CAN2, (pFunc_RxMsgCallback)CANNet_RecvMsgCAN2, NULL_PTR);
 
 	/*接收报文初始化*/
-	//    CANNet_InfoRxMsgConfSA[0].infoMsgIDUI = 0x1F000023UL;
-	//    CANNet_InfoRxMsgConfSA[0].infoMsgParU.B.CAN = 0;
-	//    CANNet_InfoRxMsgConfSA[0].infoMsgParU.B.MO = 0;
-	//    CANNet_InfoRxMsgConfSA[0].infoMsgParU.B.DIR = _MCAN_DIR_RX;
-	//    CANNet_InfoRxMsgConfSA[0].infoMsgParU.B.DLC = 8;
-	//    CANNet_InfoRxMsgConfSA[0].infoMsgParU.B.IDE = _MCAN_IDE_EXT;
-	//    MCANDrv_SetMsgObj(CANNet_InfoRxMsgConfSA[0], CANNet_RecvMsgCAN0);
+	CANNet_InfoRxMsgConfSA[0].infoMsgIDUI = 0x0000007E3UL;
+	CANNet_InfoRxMsgConfSA[0].infoMsgParU.B.CAN = 2;
+	CANNet_InfoRxMsgConfSA[0].infoMsgParU.B.MO = 3;
+	CANNet_InfoRxMsgConfSA[0].infoMsgParU.B.DIR = _MCAN_DIR_RX;
+	CANNet_InfoRxMsgConfSA[0].infoMsgParU.B.DLC = 8;
+	CANNet_InfoRxMsgConfSA[0].infoMsgParU.B.IDE = _MCAN_IDE_EXT;
+	MCANDrv_SetMsgObj(CANNet_InfoRxMsgConfSA[0], CANNet_RecvMsgCAN2);
+	CANNet_InfoRxMsgConfSA[1].infoMsgIDUI = 0x0000007E4UL;
+	CANNet_InfoRxMsgConfSA[1].infoMsgParU.B.CAN = 2;
+	CANNet_InfoRxMsgConfSA[1].infoMsgParU.B.MO = 4;
+	CANNet_InfoRxMsgConfSA[1].infoMsgParU.B.DIR = _MCAN_DIR_RX;
+	CANNet_InfoRxMsgConfSA[1].infoMsgParU.B.DLC = 8;
+	CANNet_InfoRxMsgConfSA[1].infoMsgParU.B.IDE = _MCAN_IDE_EXT;
+	MCANDrv_SetMsgObj(CANNet_InfoRxMsgConfSA[1], CANNet_RecvMsgCAN2);
 
 	/*发送报文初始化*/
 	CANNet_infoMsgTxConfSA[0].infoMsgIDUI = 0x1F000024UL;
@@ -74,41 +83,61 @@ void CANNet_Init(void)
 // CAN0接收消息处理函数 VCU
 void CANNet_RecvMsgCAN0(MCANDrv_infoMsgS_TYPE infoMsgS)
 {
-// CAN接收样例
-//	uint8 idxIncUB, idxByteUB;
-//	for (idxIncUB = 0; idxIncUB < 128; idxIncUB++)
-//	{
-//		if (infoMsgS.infoConfS.infoMsgIDUI == CANNet_InfoRxMsgConfSA[idxIncUB].infoMsgIDUI)
-//		{
-//			for (idxByteUB = 0; idxByteUB < 8; idxByteUB++)
-//			{
-//				CANNet_datRxMsgBufM[idxIncUB][idxByteUB] = infoMsgS.datMsgUBA[idxByteUB];
-//			}
-//			CANNet_datRxMsgBufM[idxIncUB][8]++;
-//		}
-//	}
-	VcuDecodeFunction(infoMsgS.infoConfS.infoMsgIDUI,infoMsgS.datMsgUBA);
+	// CAN接收样例
+	//	uint8 idxIncUB, idxByteUB;
+	//	for (idxIncUB = 0; idxIncUB < 128; idxIncUB++)
+	//	{
+	//		if (infoMsgS.infoConfS.infoMsgIDUI == CANNet_InfoRxMsgConfSA[idxIncUB].infoMsgIDUI)
+	//		{
+	//			for (idxByteUB = 0; idxByteUB < 8; idxByteUB++)
+	//			{
+	//				CANNet_datRxMsgBufM[idxIncUB][idxByteUB] = infoMsgS.datMsgUBA[idxByteUB];
+	//			}
+	//			CANNet_datRxMsgBufM[idxIncUB][8]++;
+	//		}
+	//	}
+	VcuDecodeFunction(infoMsgS.infoConfS.infoMsgIDUI, infoMsgS.datMsgUBA);
 }
 // CAN1接收消息处理函数
 void CANNet_RecvMsgCAN1(MCANDrv_infoMsgS_TYPE infoMsgS)
 {
 	// CAN接收样例
-//	uint8 idxIncUB, idxByteUB;
-//	for (idxIncUB = 0; idxIncUB < 128; idxIncUB++)
-//	{
-//		if (infoMsgS.infoConfS.infoMsgIDUI == CANNet_InfoRxMsgConfSA[idxIncUB].infoMsgIDUI)
-//		{
-//			for (idxByteUB = 0; idxByteUB < 8; idxByteUB++)
-//			{
-//				CANNet_datRxMsgBufM[idxIncUB][idxByteUB] = infoMsgS.datMsgUBA[idxByteUB];
-//			}
-//
-//			CANNet_datRxMsgBufM[idxIncUB][8]++;
-//		}
-//	}
-	BcuDecodeFunction(infoMsgS.infoConfS.infoMsgIDUI,infoMsgS.datMsgUBA);
+	//	uint8 idxIncUB, idxByteUB;
+	//	for (idxIncUB = 0; idxIncUB < 128; idxIncUB++)
+	//	{
+	//		if (infoMsgS.infoConfS.infoMsgIDUI == CANNet_InfoRxMsgConfSA[idxIncUB].infoMsgIDUI)
+	//		{
+	//			for (idxByteUB = 0; idxByteUB < 8; idxByteUB++)
+	//			{
+	//				CANNet_datRxMsgBufM[idxIncUB][idxByteUB] = infoMsgS.datMsgUBA[idxByteUB];
+	//			}
+	//
+	//			CANNet_datRxMsgBufM[idxIncUB][8]++;
+	//		}
+	//	}
+	BcuDecodeFunction(infoMsgS.infoConfS.infoMsgIDUI, infoMsgS.datMsgUBA);
+}
+void CANNet_RecvMsgCAN2(MCANDrv_infoMsgS_TYPE infoMsgS)
+{
+	switch (infoMsgS.infoConfS.infoMsgIDUI)
+	{
+	case 0x0000007E3:
+	{
+		MotorControlEnable = infoMsgS.datMsgUBA[0] & 0x0F;
+		MotorControlCmd = (infoMsgS.datMsgUBA[0] & 0xF0) >> 4;
+		MotorDebugCmd = infoMsgS.datMsgUBA[1] & 0xFF;
+		break;
+	}
+	case 0x0000007E4:
+	{
+		LockDelay = MAX((UINT16)((infoMsgS.datMsgUBA[1] << 8) | (infoMsgS.datMsgUBA[0])), 1000);
+		RunFailedDelay = MAX((UINT16)(((infoMsgS.datMsgUBA[3] << 8) | infoMsgS.datMsgUBA[2])), 3000);
+		break;
+	}
+	default:
+		break;
+	}
 }
-//
 //发送消息管理
 void CAN0Net_Manage1ms(void)
 {
@@ -116,26 +145,25 @@ void CAN0Net_Manage1ms(void)
 	static UINT8 VcuIDIdx = 0;
 	MCANDrv_infoMsgS_TYPE infoMsgS;
 	static BOOL ChkFlg = FALSE;
-	//sizeof(Ebc2VcuOutTable)/8
-	if(Can0TimerCounter%100==0)
+	if (Can0TimerCounter % 100 == 0)
 	{
-		if(Can0TimerCounter%(Ebc2VcuOutTable[VcuIDIdx][1])==0)
+		if (Can0TimerCounter % (Ebc2VcuOutTable[VcuIDIdx][1]) == 0)
 		{
 			CANNet_infoMsgTxConfSA[0].infoMsgIDUI = Ebc2VcuOutTable[VcuIDIdx][0];
 			infoMsgS.infoConfS = CANNet_infoMsgTxConfSA[0];
-			memset(infoMsgS.datMsgUBA,0x00,8);
-			VcuEncodeFunction(Ebc2VcuOutTable[VcuIDIdx][0],&(infoMsgS.datMsgUBA[0]));
+			memset(infoMsgS.datMsgUBA, 0x00, 8);
+			VcuEncodeFunction(Ebc2VcuOutTable[VcuIDIdx][0], &(infoMsgS.datMsgUBA[0]));
 			MCANDrv_SendMsg(infoMsgS);
 		}
 		VcuIDIdx++;
 		ChkFlg = FALSE;
 	}
-	if(VcuIDIdx>=(sizeof(Ebc2VcuOutTable)/8))
+	if (VcuIDIdx >= (sizeof(Ebc2VcuOutTable) / 8))
 	{
 		VcuIDIdx = 0;
 		ChkFlg = TRUE;
 	}
-	if(ChkFlg)
+	if (ChkFlg)
 	{
 		Can0TimerCounter = Can0TimerCounter + 1;
 	}
@@ -146,37 +174,62 @@ void CAN1Net_Manage1ms(void)
 	static UINT8 BcuIDIdx = 0;
 	static BOOL BcuChkFlg = FALSE;
 	MCANDrv_infoMsgS_TYPE infoMsgS;
-	if(Can1TimerCounter%100==0)
+	if (Can1TimerCounter % 100 == 0)
 	{
-		if(Can1TimerCounter%(Ebc2BcuOutTable[BcuIDIdx][1])==0)
+		if (Can1TimerCounter % (Ebc2BcuOutTable[BcuIDIdx][1]) == 0)
 		{
 			CANNet_infoMsgTxConfSA[1].infoMsgIDUI = Ebc2BcuOutTable[BcuIDIdx][0];
 			infoMsgS.infoConfS = CANNet_infoMsgTxConfSA[1];
-			memset(infoMsgS.datMsgUBA,0x00,8);
-			BcuEncodeFunction(Ebc2BcuOutTable[BcuIDIdx][0],&(infoMsgS.datMsgUBA[0]));
+			memset(infoMsgS.datMsgUBA, 0x00, 8);
+			BcuEncodeFunction(Ebc2BcuOutTable[BcuIDIdx][0], &(infoMsgS.datMsgUBA[0]));
 			MCANDrv_SendMsg(infoMsgS);
 		}
 		BcuIDIdx++;
 		BcuChkFlg = FALSE;
 	}
-	if(BcuIDIdx>=(sizeof(Ebc2BcuOutTable)/8))
+	if (BcuIDIdx >= (sizeof(Ebc2BcuOutTable) / 8))
 	{
 		BcuIDIdx = 0;
 		BcuChkFlg = TRUE;
 	}
-	if(BcuChkFlg)
+	if (BcuChkFlg)
 	{
-		Can1TimerCounter = Can1TimerCounter +1;
+		Can1TimerCounter = Can1TimerCounter + 1;
 	}
 }
 void CAN2Net_Manage1ms(void)
 {
 	static UINT32 Can2TimerCounter = 0;
 	MCANDrv_infoMsgS_TYPE infoMsgS;
-	if(Can2TimerCounter%100==0)
+	if (Can2TimerCounter % 100 == 1)
+	{
+		CANNet_infoMsgTxConfSA[2].infoMsgIDUI = 0x7F3;
+		infoMsgS.infoConfS = CANNet_infoMsgTxConfSA[2];
+		infoMsgS.datMsgUBA[0] = (ebcd_st_lockSensor | (ebcd_st_unlockSensor << 4)) & 0xFF;
+		infoMsgS.datMsgUBA[1] = MotorControlEnable;
+		infoMsgS.datMsgUBA[2] = MotorControlCmd;
+		infoMsgS.datMsgUBA[3] = MotorDebugCmd;
+		infoMsgS.datMsgUBA[4] = MotorControlFeedBack;
+		infoMsgS.datMsgUBA[5] = MotorDirecFeedBack;
+		infoMsgS.datMsgUBA[6] = 0x00;
+		infoMsgS.datMsgUBA[7] = 0x00;
+		MCANDrv_SendMsg(infoMsgS);
+	}
+	else if (Can2TimerCounter % 100 == 2)
 	{
+		CANNet_infoMsgTxConfSA[2].infoMsgIDUI = 0x7F4;
+		infoMsgS.infoConfS = CANNet_infoMsgTxConfSA[2];
+		infoMsgS.datMsgUBA[0] = LockDelay;
+		infoMsgS.datMsgUBA[1] = LockDelay >> 8;
+		infoMsgS.datMsgUBA[2] = RunFailedDelay;
+		infoMsgS.datMsgUBA[3] = RunFailedDelay >> 8;
+		infoMsgS.datMsgUBA[4] = 0x00;
+		infoMsgS.datMsgUBA[5] = 0x00;
+		infoMsgS.datMsgUBA[6] = 0x00;
+		infoMsgS.datMsgUBA[7] = 0x00;
+		MCANDrv_SendMsg(infoMsgS);
 	}
-	Can2TimerCounter = Can2TimerCounter +1;
+	Can2TimerCounter = Can2TimerCounter + 1;
 #ifdef _APP_TEST_CODE
 	switch (CANNet_idxSchedUB)
 	{
@@ -222,7 +275,6 @@ void CAN2Net_Manage1ms(void)
 	default:
 		break;
 	}
-
 	CANNet_idxSchedUB = (uint16)((CANNet_idxSchedUB + 1) % 100); // 100ms一个完整循环
 #endif
 }

+ 1 - 0
System/Vehicle/Communication/CANNet.h

@@ -31,6 +31,7 @@
     //接收CAN消息函数接口
     void CANNet_RecvMsgCAN0(MCANDrv_infoMsgS_TYPE infoMsgS);
     void CANNet_RecvMsgCAN1(MCANDrv_infoMsgS_TYPE infoMsgS);
+    void CANNet_RecvMsgCAN2(MCANDrv_infoMsgS_TYPE infoMsgS);
     
     //发送消息管理
     void CAN0Net_Manage1ms(void);

+ 49 - 34
System/Vehicle/Communication/CanVar.c

@@ -327,11 +327,11 @@ UINT32 BMS19_SingleChargeKwh = 0x00;			   //
  *Ebc->Bcu组码变量存放区
  ************************************************************/
 UINT32 Ebc2BcuOutTable[5][2] = {
-	{0x1802F4EF,100},
-	{0x1803F4EF,100},
-	{0x18E1F4EF,1000},
-	{0x18FF11F1,100},
-	{0x18FF12F1,100},
+	{0x1802F4EF, 100},
+	{0x1803F4EF, 100},
+	{0x18E1F4EF, 1000},
+	{0x18FF11F1, 100},
+	{0x18FF12F1, 100},
 };
 // UINT8 VCU_Life = 0x00;			   // VCU生命信号,精度_1,偏移_0,单位_
 
@@ -428,31 +428,31 @@ UINT32 VCU_TotalDistance = 0x00; //
  *Ebc->Vcu组码变量存放区
  ************************************************************/
 UINT32 Ebc2VcuOutTable[25][2] = {
-	{0x1801D0F3,100},
-	{0x1801D8F3,1000},
-	{0x1880D0F3,100},
-	{0x1881D0F3,100},
-	{0x1882D0F3,100},
-	{0x1883D0F3,100},
-	{0x1884D0F3,100},
-	{0x1885D0F3,100},
-	{0x1886D0F3,100},
-	{0x1887D0F3,1000},
-	{0x18C1D0F3,100},
-	{0x18C2D0F3,200},
-	{0x18E1D0F3,1000},
-	{0x18E2D0F3,1000},
-	{0x18E3D0F3,1000},
-	{0x18E4D0F3,1000},
-	{0x18E5D0F3,100},
-	{0x18E6D0F3,100},
-	{0x18F1D0F3,1000},
-	{0x18F2D0F3,1000},
-	{0x18F3D0F3,1000},
-	{0x18FEF8A7,100},
-	{0x18FF45F4,1000},
-	{0x18FFC13A,1000},
-	{0x18FFF8A7,100},
+	{0x1801D0F3, 100},
+	{0x1801D8F3, 1000},
+	{0x1880D0F3, 100},
+	{0x1881D0F3, 100},
+	{0x1882D0F3, 100},
+	{0x1883D0F3, 100},
+	{0x1884D0F3, 100},
+	{0x1885D0F3, 100},
+	{0x1886D0F3, 100},
+	{0x1887D0F3, 1000},
+	{0x18C1D0F3, 100},
+	{0x18C2D0F3, 200},
+	{0x18E1D0F3, 1000},
+	{0x18E2D0F3, 1000},
+	{0x18E3D0F3, 1000},
+	{0x18E4D0F3, 1000},
+	{0x18E5D0F3, 100},
+	{0x18E6D0F3, 100},
+	{0x18F1D0F3, 1000},
+	{0x18F2D0F3, 1000},
+	{0x18F3D0F3, 1000},
+	{0x18FEF8A7, 100},
+	{0x18FF45F4, 1000},
+	{0x18FFC13A, 1000},
+	{0x18FFF8A7, 100},
 };
 UINT8 ReqVIN = 0x00;					   //是否请求VIN码,0_预留;1_请求VIN;2_不请求VIN;3_无效;,精度_1,_偏移_0,单位_
 UINT8 ReqHVOff = 0x00;					   //是否请求下高压,0_预留;1_请求下高压;2_不请求下高压;3_无效;,精度_1,_偏移_0,单位_
@@ -581,10 +581,10 @@ UINT8 EBC_LockupSts = 0x00;			 //
 UINT8 EBC_ConnectorSts = 0x00;		 //换电连接器状态(充电回路&放电回路同时闭合代表闭合,有一路断开则为断开),0_未连接 1_连接 其他状态无效,精度_1,偏移_0,单位_
 UINT8 EBC_DischgConnectorSts = 0x00; //放电回路换电连接器状态(保留),0_未连接 1_连接 其他状态无效,精度_1,偏移_0,单位_
 UINT8 EBC_ChgConnectorSts = 0x00;	 //充电回路换电连接器状态(保留),0_未连接 1_连接 其他状态无效,精度_1,偏移_0,单位_
-//UINT8 EBC_FaultLevel = 0x00;		 //换电系统故障等级,0_无故障 1_1级故障 2_2级故障 3_3级故障,精度_1,偏移_0,单位_
-//UINT8 EBC_FaultCode = 0x00;			 //换电系统故障码,见附件,精度_1,偏移_0,单位_
-// UINT16 BMS_SoftwareVersion = 0x00;  //软件版本号_RyyyBzzz(R为软件版本、B为测试版本、正式版本不带B)  ,yyy_ 0~254,精度1,255_无效,不显示; zzz_ 0~254,精度1,255_无效,不显示;,精度_1,_偏移_0,单位_
-// UINT16 BMS_HardwareVersion = 0x00;  //硬件版本号_VyyyBzzz(V为硬件版本、B为测试版本、正式版本不带B)  ,xxx_ 0~254,精度1,255_无效,不显示; zzz_ 0~254,精度1,255_无效,不显示 ,精度_1,_偏移_0,单位_
+// UINT8 EBC_FaultLevel = 0x00;		 //换电系统故障等级,0_无故障 1_1级故障 2_2级故障 3_3级故障,精度_1,偏移_0,单位_
+// UINT8 EBC_FaultCode = 0x00;			 //换电系统故障码,见附件,精度_1,偏移_0,单位_
+//  UINT16 BMS_SoftwareVersion = 0x00;  //软件版本号_RyyyBzzz(R为软件版本、B为测试版本、正式版本不带B)  ,yyy_ 0~254,精度1,255_无效,不显示; zzz_ 0~254,精度1,255_无效,不显示;,精度_1,_偏移_0,单位_
+//  UINT16 BMS_HardwareVersion = 0x00;  //硬件版本号_VyyyBzzz(V为硬件版本、B为测试版本、正式版本不带B)  ,xxx_ 0~254,精度1,255_无效,不显示; zzz_ 0~254,精度1,255_无效,不显示 ,精度_1,_偏移_0,单位_
 UINT16 PackCurrent = 0x00;			 //电池包总电流,充电为负值,放电为正值,,精度_0.1,_偏移_-1000,单位_A
 UINT16 InstChrgCurMaxAllw = 0x00;	 //动力电池允许最大瞬时充电电流,,精度_0.1,_偏移_-1000,单位_A
 UINT16 InstDischrgCurMaxAllw = 0x00; //电池允许最大瞬时放电电流,,精度_0.1,_偏移_-1000,单位_A
@@ -756,6 +756,7 @@ const uint32 R_table[240] = {202269, 191063, 180554, 170694, 161438, 152746, 144
 /*************************************************************
  *测试变量存放区
  ************************************************************/
+#ifdef _APP_TEST_CODE
 uint32 PressureValue = 0;
 uint16 Distence1 = 0;
 uint16 Distence2 = 0;
@@ -776,3 +777,17 @@ uint32 VehCo_ctEEPTestUI = 0; //
 uint32 Control_Times = 0;
 #define EEPDATA_STOP_SEC_VAR
 #include "MemMap.h"
+#endif
+#ifdef _APP_TEST_MOTOR_CODE
+uint8 MotorControlCmd = 0;		//电机自动控制模式,0-不控制,1-控制锁紧,2-控制解锁
+uint8 MotorDebugCmd = 0;		//电机调试模式。0-不控制,1-持续锁紧,2-持续解锁
+uint8 MotorControlEnable = 0;	//电机控制使能,每bit代表一个电机从低位开始, 0-不控制,1-控制
+uint8 MotorControlFeedBack = 0; //调试参数
+uint8 MotorDirecFeedBack = 0;
+#define EEPDATA_START_SEC_VAR
+#include "MemMap.h"
+uint16 RunFailedDelay = 30000; //电机最大运动时间,超时则取消控制
+uint16 LockDelay = 1000;	   //电机传感器到位后,延时锁紧时间
+#define EEPDATA_STOP_SEC_VAR
+#include "MemMap.h"
+#endif

+ 38 - 23
System/Vehicle/Communication/CanVar.h

@@ -3,7 +3,7 @@
  * @Date         : 2021-12-27 11:21:08
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-12-30 13:59:24
+ * @LastEditTime : 2022-01-11 17:31:05
  * @Description  : file content
  * @FilePath     : \VehicleControl\VehicleControl\src\System\Vehicle\Communication\CanVar.h
  */
@@ -462,28 +462,6 @@ extern UINT32 TotalPoleChargeKwh;
 /*************************************************************
  *Ebc->ble组码变量存放区
  ************************************************************/
-extern uint16 CANNet_rAccPedUW;
-extern uint32 PressureValue;
-extern uint16 Distence1;
-extern uint16 Distence2;
-extern uint8 Switch1;
-extern uint8 Switch2;
-extern uint8 ControlState;
-extern uint32 Control_Times;
-extern uint32 PressureValueBuffer;
-extern uint32 VehCo_fInputUIA[2];
-extern uint16 VehCo_rInputUWA[2];
-extern uint16 VehCo_uADChanUWA[_ATD_NUM_CHAN];
-extern uint8 VehCo_bDINChanUBA[_DIN_NUM_CHAN];
-extern float32 VehCo_uBattF;
-extern uint16 VehCo_uAccPedUW;
-#define EEPDATA_START_SEC_VAR
-#include "MemMap.h"
-extern uint32 VehCo_ctEEPTestUB;
-extern uint32 VehCo_ctEEPTestUI; //在定义时给EEPROM里的变量赋初值
-extern uint32 Control_Times;
-#define EEPDATA_STOP_SEC_VAR
-#include "MemMap.h"
 // Ble
 extern uint16 bcud_E_snglChrg;       //单次充电能量,精度0.1kwh
 extern uint16 ebcd_Nr_swapBatt;      //换电次数
@@ -580,4 +558,41 @@ extern uint8 ebdc_st_ConnecState;       //
 
 extern const uint16 T_table[240];
 extern const uint32 R_table[240];
+#ifdef _APP_TEST_CODE
+extern uint16 CANNet_rAccPedUW;
+extern uint32 PressureValue;
+extern uint16 Distence1;
+extern uint16 Distence2;
+extern uint8 Switch1;
+extern uint8 Switch2;
+extern uint8 ControlState;
+extern uint32 Control_Times;
+extern uint32 PressureValueBuffer;
+extern uint32 VehCo_fInputUIA[2];
+extern uint16 VehCo_rInputUWA[2];
+extern uint16 VehCo_uADChanUWA[_ATD_NUM_CHAN];
+extern uint8 VehCo_bDINChanUBA[_DIN_NUM_CHAN];
+extern float32 VehCo_uBattF;
+extern uint16 VehCo_uAccPedUW;
+#define EEPDATA_START_SEC_VAR
+#include "MemMap.h"
+extern uint32 VehCo_ctEEPTestUB;
+extern uint32 VehCo_ctEEPTestUI; //在定义时给EEPROM里的变量赋初值
+extern uint32 Control_Times;
+#define EEPDATA_STOP_SEC_VAR
+#include "MemMap.h"
+#endif
+#ifdef _APP_TEST_MOTOR_CODE
+extern uint8 MotorControlCmd;      //电机自动控制模式,0-不控制,1-控制锁紧,2-控制解锁
+extern uint8 MotorDebugCmd;        //电机调试模式。0-不控制,1-持续锁紧,2-持续解锁
+extern uint8 MotorControlEnable;   //电机控制使能,每bit代表一个电机从低位开始, 0-不控制,1-控制
+extern uint8 MotorControlFeedBack; //调试参数
+extern uint8 MotorDirecFeedBack;
+#define EEPDATA_START_SEC_VAR
+#include "MemMap.h"
+extern uint16 RunFailedDelay; //电机最大运动时间,超时则取消控制
+extern uint16 LockDelay;      //电机传感器到位后,延时锁紧时间
+#define EEPDATA_STOP_SEC_VAR
+#include "MemMap.h"
+#endif
 #endif /* SYSTEM_VEHICLE_COMMUNICATION_CANVAR_H_ */

+ 5 - 1
System/Vehicle/VehCo.c

@@ -105,8 +105,10 @@ void VehCo_Manage10ms(void)
 //整车管理1ms基准运行任务
 void VehCo_Manage1ms(void)
 {
+#ifdef _APP_RELEASE_CODE
     CAN0Net_Manage1ms();
     CAN1Net_Manage1ms();
+#endif
     CAN2Net_Manage1ms();
 }
 
@@ -157,9 +159,11 @@ void VehCo_Ctrl(void)
     TestDeviceFun();
     VehCo_uBattF = (float32)BattCD_uFltUW / 100.0F;
 #endif
+#ifdef _APP_TEST_MOTOR_CODE
+    MotorTestFun();
+#endif
 #ifdef _APP_RELEASE_CODE
     /*正式程序开始*/
-
     GetHVLockState();
     GetDIOState();
     GetAIOValue();