Browse Source

北京测试,版本号为1.2.1.15,测试环境,未下线检测,采用4830,更改了bms升级指令,增加了循环次数

CHENJIE-PC\QiXiang_CHENJIE 3 years ago
parent
commit
2768f8641d
1 changed files with 59 additions and 54 deletions
  1. 59 54
      src/UartTask.c

+ 59 - 54
src/UartTask.c

@@ -108,6 +108,9 @@ static void UartTask(void* arg)
         UartWriteData.Data[1] = 0x03;
     }
     osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,1000);
+
+	BMS_Fota_update_flag =TRUE;//测试
+
     while (1)
     {
         switch (gProcess_Uart_Task)
@@ -843,9 +846,10 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 	UINT32 currentPackageStartAddr = 0;
 	BMS_Update_Recv_Msg_Type pUpdateMsgRecv;
 	UINT8 bmsUpdateFlag = 1;
+	UINT8 Cycle_count = 0;
 	//BMS_Update_Recv_Msg_Type bmsMsg;
 	//static UpdateStep step = UPDATE_STEP_CHECK_VERSION;
-	while(bmsUpdateFlag)
+	while(bmsUpdateFlag&&Cycle_count<2)
 	{
 		switch (updateStep)
 		{
@@ -895,7 +899,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 				{
 					errorCount++;
 				}
-				#ifdef USING_PRINTF
+				#ifdef USING_PRINTF1
 							//printf("update step:%d\n",updateStep);
 							printf("query:");
 							
@@ -970,7 +974,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 					errorCount = 0;
 				}
 				
-				#ifdef USING_PRINTF
+				#ifdef USING_PRINTF1
 							printf("update step:%d\n",updateStep);
 							printf("query:");
 							for(j=0;j<updateMsgSendLen;j++)
@@ -1003,7 +1007,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 				ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), 0, 500);
 				//updateStep = UPDATE_STEP_SET_BAUD_RATE;
 				updateStep = UPDATE_STEP_CHECK_VERSION_AGAIN;//2021-04-09跳过波特率设置
-				#ifdef USING_PRINTF
+				#ifdef USING_PRINTF1
 							
 							printf("query:");
 							for(j=0;j<updateMsgSendLen;j++)
@@ -1065,7 +1069,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 				{
 					errorCount++;
 				}
-				#ifdef USING_PRINTF
+				#ifdef USING_PRINTF1
 							//printf("update step:%d\n",updateStep);
 							printf("query:");
 							
@@ -1106,15 +1110,16 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 				pUpdateMsgSend[10] = 0x61;	//check
 				pUpdateMsgSend[11] = 0xF5;	//end flag
 				
-				printf("query:");
-				for(j=0;j<updateMsgSendLen;j++)
-				{
-					printf("%x ",pUpdateMsgSend[j]);
-				}
-				printf("\n");
+				// printf("query:");
+				// for(j=0;j<updateMsgSendLen;j++)
+				// {
+				// 	printf("%x ",pUpdateMsgSend[j]);
+				// }
+				// printf("\n");
 				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
 				ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
-				printf("ret = %d\n",ret);
+				//ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv),sizeof(BMS_Update_Recv_Msg_Type), 100);
+				// printf("ret = %d\n",ret);
 				if(ret!=0)
 				{
 					if(pUpdateMsgRecv.startFlag == 0xEB && pUpdateMsgRecv.endFlag == 0xF5)
@@ -1152,7 +1157,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 					errorCount = 0;
 				}
 				
-				#ifdef USING_PRINTF
+				#ifdef USING_PRINTF1
 					//printf("update step:%d\n",updateStep);
 					printf("query:");
 					for(j=0;j<updateMsgSendLen;j++)
@@ -1222,7 +1227,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 					errorCount = 0;
 				}
 				
-				#ifdef USING_PRINTF
+				#ifdef USING_PRINTF1
 					//printf("update step:%d\n",updateStep);
 					printf("query:");
 					for(j=0;j<updateMsgSendLen;j++)
@@ -1296,7 +1301,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 					errorCount = 0;
 				}
 				
-				#ifdef USING_PRINTF
+				#ifdef USING_PRINTF1
 							//printf("update step:%d\n",updateStep);
 							printf("query:");
 							for(j=0;j<updateMsgSendLen;j++)
@@ -1364,7 +1369,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 					errorCount = 0;
 				}
 				
-				#ifdef USING_PRINTF
+				#ifdef USING_PRINTF1
 					//printf("update step:%d\n",updateStep);
 					printf("query:");
 					for(j=0;j<updateMsgSendLen;j++)
@@ -1443,7 +1448,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 						errorCount = 0;
 						break;
 					}
-				#ifdef USING_PRINTF
+				#ifdef USING_PRINTF1
 							//printf("update step:%d\n",updateStep);
 							printf("query:");
 							for(j=0;j<updateMsgSendLen;j++)
@@ -1511,22 +1516,6 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 					updateStep = UPDATE_STEP_RESET;
 					errorCount = 0;
 				}
-				
-				#ifdef USING_PRINTF
-							//printf("update step:%d\n",updateStep);
-							printf("query:");
-							for(j=0;j<updateMsgSendLen;j++)
-							{
-								printf("%x ",pUpdateMsgSend[j]);
-							}
-							printf("\nanswer:");
-							for(j=0;j<sizeof(BMS_Update_Recv_Msg_Type);j++)
-							{
-								printf("%x ",*(((UINT8*)&pUpdateMsgRecv)+j));
-							}
-							printf("\n");
-							printf("next update step:%d\n",updateStep);
-				#endif
 				osDelay(50);
 				break;			
 
@@ -1543,24 +1532,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 				pUpdateMsgSend[7] = 0xF5;	//end flag
 				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
 				SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), 0, 500);
-				
 				updateStep = UPDATE_STEP_END;
-				
-				#ifdef USING_PRINTF
-							//printf("update step:%d\n",updateStep);
-							printf("query:");
-							for(j=0;j<updateMsgSendLen;j++)
-							{
-								printf("%x ",pUpdateMsgSend[j]);
-							}
-							printf("\nanswer:");
-							for(j=0;j<sizeof(BMS_Update_Recv_Msg_Type);j++)
-							{
-								printf("%x ",*(((UINT8*)&pUpdateMsgRecv)+j));
-							}
-							printf("\n");	
-							printf("next update step:%d\n",updateStep);
-				#endif
 				osDelay(50);
 				break;
 			case UPDATE_STEP_END:
@@ -1584,7 +1556,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 				osDelay(50);
 				
 				resetCount++;
-				if(resetCount>=2)
+				if(resetCount>2)
 				{
 					updateStep = UPDATE_STEP_DOWNLOAD_BREAK_OFF;
 					resetCount = 0;
@@ -1611,7 +1583,8 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
 				SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), 0, 500);
 				osDelay(50);
-				updateStep = UPDATE_STEP_ERROR;
+				updateStep = UPDATE_STEP_CHECK_VERSION;
+				Cycle_count++;
 				break;
 			case UPDATE_STEP_ERROR:
 				updateStep = UPDATE_STEP_CHECK_VERSION;
@@ -1633,6 +1606,14 @@ UINT8 SP_BMS_Update_Query(UINT8* pSend,UINT32 sendLen, UINT8* pRead, UINT32 read
 	UINT8 timeCount = 0;
 	UINT8 j=0;
 	USARTdrv->Send(pSend,sendLen);
+	#ifdef USING_PRINTF
+		printf("\nquery in :");
+		for(j=0;j<sendLen;j++)
+		{
+			printf("%x ",*(pSend+j));
+		}
+		printf("\n");	
+	#endif
 	if(readLen>0)
 	{
 		USARTdrv->Receive(pRead,readLen);         
@@ -1646,15 +1627,39 @@ UINT8 SP_BMS_Update_Query(UINT8* pSend,UINT32 sendLen, UINT8* pRead, UINT32 read
 				isRecvTimeout = true;
 				break;
 			}
-		}	
+		}
+		#ifdef USING_PRINTF
+			printf("\nanswer in :");
+			for(j=0;j<readLen;j++)
+			{
+				printf("%x ",*(pRead+j));
+			}
+			printf("\n");	
+		#endif	
 		if (isRecvComplete == true)
 		{
 			isRecvComplete = false;
+			if(*(pRead+0)!=0xEB)
+			{
+				USARTdrv->Uninitialize();
+				osDelay(1000);
+				USARTdrv->Initialize(USART_callback);
+				USARTdrv->PowerControl(ARM_POWER_FULL);
+				USARTdrv->Control(ARM_USART_MODE_ASYNCHRONOUS |
+						ARM_USART_DATA_BITS_8 |
+						ARM_USART_PARITY_NONE |
+						ARM_USART_STOP_BITS_1 |
+						ARM_USART_FLOW_CONTROL_NONE, 9600);
+				#ifdef USING_PRINTF
+					printf("\nuart reset in \n");	
+				#endif
+				return  0;
+			}		  
 			return readLen;
 		}
 		else
 		{
-			memset(pRead,0x00,readLen);
+			//memset(pRead,0x00,readLen);
 			isRecvTimeout = false;
 			return 0;
 		}