Browse Source

蜂鸣器控制功能增加

CHENJIE-PC\QiXiang_CHENJIE 3 years ago
parent
commit
03b1f80c2c
4 changed files with 43 additions and 27 deletions
  1. 1 1
      inc/Signal.h
  2. 2 2
      inc/app.h
  3. 1 1
      src/Signal.c
  4. 39 23
      src/UartTask.c

+ 1 - 1
inc/Signal.h

@@ -28,7 +28,7 @@ extern	UINT8	reservedSignal5;
 extern	UINT8	reservedSignal6;
 extern	UINT8	reservedSignal6;
 extern	UINT8	reservedSignal7;
 extern	UINT8	reservedSignal7;
 extern	UINT8	reservedSignal8;
 extern	UINT8	reservedSignal8;
-
+extern  UINT8   chargerConnectState;
 
 
 
 
 
 

+ 2 - 2
inc/app.h

@@ -15,8 +15,8 @@ extern "C" {
 //全局定义声明区
 //全局定义声明区
 #define BMS_MANUFACTURE (2) //BMS制造商表示1-超力源,2-美顺
 #define BMS_MANUFACTURE (2) //BMS制造商表示1-超力源,2-美顺
 #define DATA_MODULE_TYPE (1) //1表示NB模块,2表示4G cat1
 #define DATA_MODULE_TYPE (1) //1表示NB模块,2表示4G cat1
-#define BMS_INFO  (1)       //1-1表示超力源4830,1-2表示超力源6060,2-1表示美顺6455
-#define EOLSTATE (0) //1标识下线检测跳过,使用默认值
+#define BMS_INFO  (2)       //1-1表示超力源4830,1-2表示超力源6060,2-1表示美顺6455
+#define EOLSTATE (1) //1标识下线检测跳过,使用默认值
 
 
 #if  BMS_MANUFACTURE==1
 #if  BMS_MANUFACTURE==1
     #if BMS_INFO==1
     #if BMS_INFO==1

+ 1 - 1
src/Signal.c

@@ -60,7 +60,7 @@ UINT8	reservedSignal5 = 0xFF;
 UINT8	reservedSignal6 = 0xFF;
 UINT8	reservedSignal6 = 0xFF;
 UINT8	reservedSignal7 = 0xFF;
 UINT8	reservedSignal7 = 0xFF;
 UINT8	reservedSignal8 = 0xFF;
 UINT8	reservedSignal8 = 0xFF;
-
+UINT8   chargerConnectState = 0xFF;
 //declear the UINT16 vars
 //declear the UINT16 vars
 UINT16	battCellU[28] = {0xFFFF};
 UINT16	battCellU[28] = {0xFFFF};
 UINT16	minCellVol = 0xFFFF;
 UINT16	minCellVol = 0xFFFF;

+ 39 - 23
src/UartTask.c

@@ -70,7 +70,7 @@ void battSOCDisplay(void);
 void battErrorStateDisplay(void);
 void battErrorStateDisplay(void);
 void battWarningStateDisplay(void);
 void battWarningStateDisplay(void);
 void battLockStateDisplay(UINT8 lockState);
 void battLockStateDisplay(UINT8 lockState);
-void relayPWMControl(void);
+void relayControlFunc(UINT8 RingTimes);
 void SP_BMS_Update_Service(void);
 void SP_BMS_Update_Service(void);
 BOOL BattHeaterSwitch(UINT8* heaterSwitch);
 BOOL BattHeaterSwitch(UINT8* heaterSwitch);
 UINT16  encryptionAlgorithm (UINT16 plainText);
 UINT16  encryptionAlgorithm (UINT16 plainText);
@@ -142,13 +142,15 @@ static void UartTask(void* arg)
                     #endif
                     #endif
                     if(osMessageQueueGet(UartWriteCmdHandle,&UartWriteData,0,0)==osOK)
                     if(osMessageQueueGet(UartWriteCmdHandle,&UartWriteData,0,0)==osOK)
                     {
                     {
-                        #ifdef USING_PRINTF1
-                            printf("[%d]UartWriteCmdHandle :%x\n",__LINE__,UartWriteData.WriteCmd);
+                        #ifdef USING_PRINTF
+                            printf("[%d]UartWriteCmdHandle :%x-%X%X\n",__LINE__,UartWriteData.WriteCmd,UartWriteData.Data[0],UartWriteData.Data[1]);
                         #endif
                         #endif
                         PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_WRITE);
                         PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_WRITE);
                     }
                     }
                     else
                     else
-                        PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_READ);
+					{
+						PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_READ);
+					} 
                 }
                 }
 				if(UartReadMsg.Header[2]>0)
 				if(UartReadMsg.Header[2]>0)
 				{
 				{
@@ -180,19 +182,26 @@ static void UartTask(void* arg)
 					if(WorkFlag==0x00)
 					if(WorkFlag==0x00)
 					{
 					{
 						PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_UPDATE);
 						PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_UPDATE);
+						break;
 					}
 					}
 					
 					
 				}
 				}
-				if(AppNVMData.isBattLocked==TRUE && ((UartReadMsg.data[(0x09+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+2)*2+1])>>1)&0x03!=0x00 && Timer_count%10==0)//try to lock
+				if(AppNVMData.isBattLocked==TRUE && (UartReadMsg.data[(0x1B+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2+1])&0x03!=0x00 && Timer_count%20==0)//try to lock
 				{
 				{
+					#ifdef USING_PRINTF
+                        printf("[%d]try to lock:%X-%X\n",__LINE__,AppNVMData.isBattLocked,(UartReadMsg.data[(0x1B+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2+1])&0x03);
+                    #endif
 					UartWriteData.WriteCmd = 0x01;
 					UartWriteData.WriteCmd = 0x01;
 					UartWriteData.Data[0] = 0x00;
 					UartWriteData.Data[0] = 0x00;
 					UartWriteData.Data[1] = 0x00;
 					UartWriteData.Data[1] = 0x00;
 					osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,1000);
 					osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,1000);
 					PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_READ);
 					PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_READ);
 				}
 				}
-				else if (AppNVMData.isBattLocked==FALSE && ((UartReadMsg.data[(0x09+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+2)*2+1])>>1)&0x03==0x00 && Timer_count%10==0 ) // try to unlock
+				else if (AppNVMData.isBattLocked==FALSE && (UartReadMsg.data[(0x1B+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2+1])&0x03==0x00 && Timer_count%20==0 ) // try to unlock
 				{
 				{
+					#ifdef USING_PRINTF
+                        printf("[%d]try to unlock:%X-%X\n",__LINE__,AppNVMData.isBattLocked,(UartReadMsg.data[(0x1B+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2+1])&0x03);
+                    #endif
 					UartWriteData.WriteCmd = 0x01;
 					UartWriteData.WriteCmd = 0x01;
 					UartWriteData.Data[0] = 0x00;
 					UartWriteData.Data[0] = 0x00;
 					UartWriteData.Data[1] = 0x03;
 					UartWriteData.Data[1] = 0x03;
@@ -204,7 +213,7 @@ static void UartTask(void* arg)
             case PROCESS_UART_STATE_READ:
             case PROCESS_UART_STATE_READ:
             {
             {
                 UINT16 CRC_chk_buffer;
                 UINT16 CRC_chk_buffer;
-                Reg_Num = 0x21+BATT_CELL_VOL_NUM+BATT_TEMP_NUM + 2;//按照协议里面的0x21+X+N的结束地址
+                Reg_Num = 0x21+BATT_CELL_VOL_NUM+BATT_TEMP_NUM + BATT_OTHER_TEMP_NUM;//按照协议里面的0x21+X+N的结束地址
                 Uart_Read_Msg.Bms_Address = BMS_ADDRESS_CODE;
                 Uart_Read_Msg.Bms_Address = BMS_ADDRESS_CODE;
                 Uart_Read_Msg.Bms_Funcode = UART_READ_CODE;
                 Uart_Read_Msg.Bms_Funcode = UART_READ_CODE;
                 Uart_Read_Msg.Reg_Begin_H = 0x00;
                 Uart_Read_Msg.Reg_Begin_H = 0x00;
@@ -343,12 +352,15 @@ static BOOL uartBattInfoDecode(UINT8* dataPtr)
 	battI = Batt_current*AppDataInfo.BattCurrentNegFlag + 0x2710;
 	battI = Batt_current*AppDataInfo.BattCurrentNegFlag + 0x2710;
     //bit0 ~ bit31 represent cell0 ~ cell31
     //bit0 ~ bit31 represent cell0 ~ cell31
     battBalanceoInfo  = dataPtr[(0x06+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1] | (dataPtr[(0x06+BATT_CELL_VOL_NUM+TEMP_NUM)*2] <<8) + (dataPtr[(0x07+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]<<16) | (dataPtr[(0x07+BATT_CELL_VOL_NUM+TEMP_NUM)*2] <<24);
     battBalanceoInfo  = dataPtr[(0x06+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1] | (dataPtr[(0x06+BATT_CELL_VOL_NUM+TEMP_NUM)*2] <<8) + (dataPtr[(0x07+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]<<16) | (dataPtr[(0x07+BATT_CELL_VOL_NUM+TEMP_NUM)*2] <<24);
-
+	chargerConnectState = (dataPtr[(0x03+BATT_CELL_VOL_NUM)*2+1])&0x04;//充电器连接状态,0表示未连接,1表示已连接
     bmsHwVersion = dataPtr[(0x08+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]; 
     bmsHwVersion = dataPtr[(0x08+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]; 
     bmsSwVersion = dataPtr[(0x08+BATT_CELL_VOL_NUM+TEMP_NUM)*2];    
     bmsSwVersion = dataPtr[(0x08+BATT_CELL_VOL_NUM+TEMP_NUM)*2];    
 
 
     temp = ((dataPtr[(0x09+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1])>>1)&0x03;    
     temp = ((dataPtr[(0x09+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1])>>1)&0x03;    
     battMOSSwitchState = ((temp&0x01)<<1)|((temp&0x02)>>1);	
     battMOSSwitchState = ((temp&0x01)<<1)|((temp&0x02)>>1);	
+	#ifdef USING_PRINTF
+		printf("[%d]battMOSSwitchState :%x\n",__LINE__,battMOSSwitchState);
+	#endif
     if(AppNVMData.isBattLocked==TRUE)
     if(AppNVMData.isBattLocked==TRUE)
     {
     {
         battMOSSwitchState = battMOSSwitchState |(0x01<<2);
         battMOSSwitchState = battMOSSwitchState |(0x01<<2);
@@ -446,6 +458,9 @@ UINT8 Uart_WriteCmd_func(Uart_Write_Data_Type UartWriteData)
     UINT16 CRC_chk_buffer;
     UINT16 CRC_chk_buffer;
     UINT8 timeout = 0x00;
     UINT8 timeout = 0x00;
     UINT8 Uart_Recv_Buffer[8];
     UINT8 Uart_Recv_Buffer[8];
+	#ifdef USING_PRINTF
+		printf("\nUart_WriteCmd_func: %x ",UartWriteData.WriteCmd);
+	#endif
     switch (UartWriteData.WriteCmd)
     switch (UartWriteData.WriteCmd)
     {
     {
         case 0x01://是否锁定
         case 0x01://是否锁定
@@ -462,6 +477,14 @@ UINT8 Uart_WriteCmd_func(Uart_Write_Data_Type UartWriteData)
             CRC_chk_buffer = crc_chk((UINT8 *)&Uart_Write_Msg,sizeof(Uart_Write_Msg)-2);
             CRC_chk_buffer = crc_chk((UINT8 *)&Uart_Write_Msg,sizeof(Uart_Write_Msg)-2);
             Uart_Write_Msg.CRC_L = CRC_chk_buffer;
             Uart_Write_Msg.CRC_L = CRC_chk_buffer;
             Uart_Write_Msg.CRC_H = CRC_chk_buffer>>8;
             Uart_Write_Msg.CRC_H = CRC_chk_buffer>>8;
+			if(AppNVMData.isBattLocked==FALSE)
+			{
+				relayControlFunc(3);
+			}
+			else if (AppNVMData.isBattLocked==TRUE)
+			{
+				relayControlFunc(2);
+			}
             break;
             break;
         }
         }
 		case 0x02://是否加热
 		case 0x02://是否加热
@@ -488,7 +511,7 @@ UINT8 Uart_WriteCmd_func(Uart_Write_Data_Type UartWriteData)
         }
         }
     }
     }
     USARTdrv->Send((UINT8 *)&Uart_Write_Msg,sizeof(Uart_Write_Msg));
     USARTdrv->Send((UINT8 *)&Uart_Write_Msg,sizeof(Uart_Write_Msg));
-    #ifdef USING_PRINTF1
+    #ifdef USING_PRINTF
         printf("Uart_Send_buffer:  ");
         printf("Uart_Send_buffer:  ");
         for(int i=0;i<sizeof(Uart_Write_Msg);i++)
         for(int i=0;i<sizeof(Uart_Write_Msg);i++)
         {
         {
@@ -510,7 +533,7 @@ UINT8 Uart_WriteCmd_func(Uart_Write_Data_Type UartWriteData)
     }
     }
     if (isRecvComplete == true)
     if (isRecvComplete == true)
     {
     {
-        #ifdef USING_PRINTF1
+        #ifdef USING_PRINTF
             printf("Uart_Rece_buffer: ");
             printf("Uart_Rece_buffer: ");
             for(int i=0;i<8;i++)
             for(int i=0;i<8;i++)
             {
             {
@@ -1006,25 +1029,18 @@ void battLockStateDisplay(UINT8 lockState)
 	errorLightTimer++;
 	errorLightTimer++;
 }
 }
 
 
-void relayPWMControl()
+void relayControlFunc(UINT8 RingTimes)
 {
 {
-	static UINT8 timerCount=0;
-	//printf("timerCout=%d\n",timerCount);
-	if(timerCount<2)
+	UINT8 timerCount=0;
+	printf("RingTimes=%d\n",RingTimes);
+	while(timerCount<RingTimes)
 	{
 	{
 		relayControl(TRUE);
 		relayControl(TRUE);
-		timerCount++;
-	}
-	else if(timerCount>=2 && timerCount<5)
-	{
+		osDelay(50);
 		relayControl(FALSE);
 		relayControl(FALSE);
+		osDelay(150);
 		timerCount++;
 		timerCount++;
 	}
 	}
-	else
-	{
-		relayControl(FALSE);
-		timerCount = 0;
-	}
 }
 }