|
@@ -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;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|