|
@@ -1,7 +1,7 @@
|
|
|
/*
|
|
|
* AppTaskUart0.c
|
|
|
*
|
|
|
- * Created on: 2022Äê2ÔÂ22ÈÕ
|
|
|
+ * Created on: 2022年2月22日
|
|
|
* Author: QiXiang_CHENJIE
|
|
|
*/
|
|
|
#include "AppTaskUart0.h"
|
|
@@ -9,20 +9,17 @@
|
|
|
static process_Uart0 gProcess_Uart0_Task = PROCESS_UART_STATE_IDLE;
|
|
|
#define PROC_UART0_STATE_SWITCH(a) (gProcess_Uart0_Task = a)
|
|
|
bool bmsCellInfoDecode(uint8 *dataPtr);
|
|
|
+bool bmsTempInfoDecode(uint8 *dataPtr);
|
|
|
bool bmsOtherInfoDecode(uint8 *dataPtr);
|
|
|
-void battDataCalFunc(void);
|
|
|
+void UartBusReadDataFunc(uint16 RegAddrBegin, uint16 Reg_Num, bool (*decodeFunc)(uint8 *dataPtr));
|
|
|
+// void battDataCalFunc(void);
|
|
|
+static uint16 UartNoDataReadCounter = 0;
|
|
|
void Uart0Task(void *pvParameters)
|
|
|
{
|
|
|
(void)pvParameters;
|
|
|
- UartQueryType Uart0AskMsg;
|
|
|
- uint16 Reg_Num = 0;
|
|
|
- uint16 RegAddrBegin = 0;
|
|
|
- uint16 CRC_chk_buffer = 0;
|
|
|
- uint16 pReadLen = 0;
|
|
|
UartAnsType UartAnsData;
|
|
|
+ uint16 pReadLen = 0;
|
|
|
static uint8 writecounter = 0;
|
|
|
- uint16 UartNoDataReadCounter = 0;
|
|
|
- uint8 UartDataRecv[256];
|
|
|
while (1)
|
|
|
{
|
|
|
switch (gProcess_Uart0_Task)
|
|
@@ -42,239 +39,43 @@ void Uart0Task(void *pvParameters)
|
|
|
}
|
|
|
case PROCESS_UART_STATE_READ:
|
|
|
{
|
|
|
-
|
|
|
- static uint16 readCnt = 0;
|
|
|
- /*µçѹµçÁ÷Êý¾Ý¶ÁÈ¡£¨µÚÒ»´Î¶ÁÈ¡£©*/
|
|
|
- pReadLen = 0;
|
|
|
Dio_FlipChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2);
|
|
|
- RegAddrBegin = 0x00;
|
|
|
- Reg_Num =AppDataInfo.BattCellCount + 3;
|
|
|
- Uart0AskMsg.Bms_Address = BMS_ADDRESS_CODE;
|
|
|
- Uart0AskMsg.Bms_Funcode = UART_READ_CODE;
|
|
|
- Uart0AskMsg.Reg_Begin_H = RegAddrBegin>>8;
|
|
|
- Uart0AskMsg.Reg_Begin_L = RegAddrBegin;
|
|
|
- Uart0AskMsg.Reg_Num_H = Reg_Num >> 8;
|
|
|
- Uart0AskMsg.Reg_Num_L = Reg_Num;
|
|
|
- CRC_chk_buffer = crc_chk((uint8 *)&Uart0AskMsg, 6);
|
|
|
- Uart0AskMsg.CRC_L = CRC_chk_buffer;
|
|
|
- Uart0AskMsg.CRC_H = CRC_chk_buffer >> 8;
|
|
|
- /*RS485²éѯÃüÁîÐèҪʹÄÜ*/
|
|
|
- UART_Send_Data(UART_LPUART0, (uint8 *)&Uart0AskMsg, sizeof(Uart0AskMsg), 1000);
|
|
|
- uint16 ReadLen1 = 0;
|
|
|
- uint16 ReadLenTar = 0;
|
|
|
- uint8 ReadDelayCounter = 0;
|
|
|
- ReadLenTar = (Reg_Num)*2+5;
|
|
|
- memset((uint8 *)&UartAnsData,0x00,sizeof(UartAnsData));
|
|
|
- while(1)
|
|
|
- {
|
|
|
- UART_Receive_Data(UART_LPUART0, UartDataRecv, &pReadLen, 100);
|
|
|
- if(pReadLen>2)
|
|
|
- {
|
|
|
- memcpy((uint8 *)&UartAnsData+ReadLen1,UartDataRecv,pReadLen);
|
|
|
- ReadLen1 = ReadLen1 + pReadLen;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- ReadDelayCounter++;
|
|
|
- }
|
|
|
- if(ReadLen1>=ReadLenTar)
|
|
|
- {
|
|
|
- ReadDelayCounter = 0;
|
|
|
- pReadLen = ReadLen1;
|
|
|
- ReadLen1 = 0;
|
|
|
- break;
|
|
|
- }
|
|
|
- if(ReadDelayCounter>=20)
|
|
|
- {
|
|
|
- ReadDelayCounter = 0;
|
|
|
- pReadLen = 0;
|
|
|
- ReadLen1 = 0;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (pReadLen > 0)
|
|
|
- {
|
|
|
- uint16 CrcChkGet = 0xffff;
|
|
|
- uint16 CrcChkCal = 0x0000;
|
|
|
- CrcChkCal = crc_chk((uint8 *)&UartAnsData, pReadLen-2);
|
|
|
- CrcChkGet = ((uint16)(UartAnsData.Data[pReadLen-1-3])<<8) | ((uint16)(UartAnsData.Data[pReadLen-2-3]));
|
|
|
- if(CrcChkCal==CrcChkGet)
|
|
|
- {
|
|
|
- bmsCellInfoDecode(UartAnsData.Data);
|
|
|
- UartNoDataReadCounter = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- UartNoDataReadCounter++;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- UartNoDataReadCounter++;
|
|
|
- }
|
|
|
- /*ζȼ°ÆäËû״̬ÐÅÏ¢¶ÁÈ¡£¨µÚ¶þ´Î¶ÁÈ¡£©*/
|
|
|
- pReadLen = 0;
|
|
|
- RegAddrBegin = 0x03 + AppDataInfo.BattCellCount;
|
|
|
- Reg_Num = 0x1B + AppDataInfo.BattTempCount; //¶ÁÈ¡µÄ¼Ä´æÆ÷Êý¾Ý£¬Ôݶ¨£¬·Ö¿ª¶ÁÈ¡
|
|
|
- Uart0AskMsg.Bms_Address = BMS_ADDRESS_CODE;
|
|
|
- Uart0AskMsg.Bms_Funcode = UART_READ_CODE;
|
|
|
- Uart0AskMsg.Reg_Begin_H = RegAddrBegin>>8;
|
|
|
- Uart0AskMsg.Reg_Begin_L = RegAddrBegin;
|
|
|
- Uart0AskMsg.Reg_Num_H = Reg_Num >> 8;
|
|
|
- Uart0AskMsg.Reg_Num_L = Reg_Num;
|
|
|
- CRC_chk_buffer = crc_chk((uint8 *)&Uart0AskMsg, 6);
|
|
|
- Uart0AskMsg.CRC_L = CRC_chk_buffer;
|
|
|
- Uart0AskMsg.CRC_H = CRC_chk_buffer >> 8;
|
|
|
- /*RS485²éѯÃüÁîÐèҪʹÄÜ*/
|
|
|
- UART_Send_Data(UART_LPUART0, (uint8 *)&Uart0AskMsg, sizeof(Uart0AskMsg), 1000);
|
|
|
- memset((uint8 *)&UartAnsData,0x00,sizeof(UartAnsData));
|
|
|
- ReadLenTar = (Reg_Num)*2+5;
|
|
|
- while(1)
|
|
|
- {
|
|
|
- UART_Receive_Data(UART_LPUART0, UartDataRecv, &pReadLen, 100);
|
|
|
- if(pReadLen>2)
|
|
|
- {
|
|
|
- memcpy((uint8 *)&UartAnsData+ReadLen1,UartDataRecv,pReadLen);
|
|
|
- ReadLen1 = ReadLen1 + pReadLen;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- ReadDelayCounter++;
|
|
|
- }
|
|
|
- if(ReadLen1>=ReadLenTar)
|
|
|
- {
|
|
|
- ReadDelayCounter = 0;
|
|
|
- pReadLen = ReadLen1;
|
|
|
- ReadLen1 = 0;
|
|
|
- break;
|
|
|
- }
|
|
|
- if(ReadDelayCounter>=20)
|
|
|
- {
|
|
|
- ReadDelayCounter = 0;
|
|
|
- pReadLen = 0;
|
|
|
- ReadLen1 = 0;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (pReadLen > 0)
|
|
|
+ //其他�数读�
|
|
|
+ UartBusReadDataFunc(0x01, 0x38, bmsOtherInfoDecode);
|
|
|
+ //电压读�
|
|
|
+ UartBusReadDataFunc(0x64, 120, bmsCellInfoDecode);
|
|
|
+ //温度读�
|
|
|
+ UartBusReadDataFunc(0x190, 40, bmsTempInfoDecode);
|
|
|
+ //没有读到数�时的默认值
|
|
|
+ if (UartNoDataReadCounter > 10)
|
|
|
{
|
|
|
- uint16 CrcChkGet = 0xffff;
|
|
|
- uint16 CrcChkCal = 0x0000;
|
|
|
- CrcChkCal = crc_chk((uint8 *)&UartAnsData, pReadLen-2);
|
|
|
- CrcChkGet = ((uint16)(UartAnsData.Data[pReadLen-1-3])<<8) | ((uint16)(UartAnsData.Data[pReadLen-2-3]));
|
|
|
- if(CrcChkCal==CrcChkGet)
|
|
|
- {
|
|
|
- bmsOtherInfoDecode(UartAnsData.Data);
|
|
|
- UartNoDataReadCounter = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- UartNoDataReadCounter++;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- UartNoDataReadCounter++;
|
|
|
- }
|
|
|
- //ûÓжÁµ½Êý¾ÝʱµÄĬÈÏÖµ
|
|
|
- if(UartNoDataReadCounter>10)
|
|
|
- {
|
|
|
- memset((uint8 *)&UartAnsData,0x00,sizeof(UartAnsData));
|
|
|
+ memset((uint8 *)&UartAnsData, 0x00, sizeof(UartAnsData));
|
|
|
bmsCellInfoDecode(UartAnsData.Data);
|
|
|
+ bmsTempInfoDecode(UartAnsData.Data);
|
|
|
bmsOtherInfoDecode(UartAnsData.Data);
|
|
|
- PutErrorNum(ErrorArray, sizeof(ErrorArray)/2, 1);
|
|
|
+ PutErrorNum(ErrorArray, sizeof(ErrorArray) / 2, 1);
|
|
|
vTaskDelay(pdMS_TO_TICKS(5000));
|
|
|
}
|
|
|
- if(readCnt%10==0||0)
|
|
|
- {
|
|
|
- /**µç±íÊý¾Ý¶ÁÈ¡*/
|
|
|
- for(uint8 i=0;i<2;i++)
|
|
|
- {
|
|
|
- /*µç±í²ÎÊý¶ÁÈ¡*/
|
|
|
- static uint16 pt[2] = {0};
|
|
|
- static uint16 ct[2] = {0};
|
|
|
- pReadLen = 0;
|
|
|
- RegAddrBegin = 0x03;
|
|
|
- Reg_Num = 0x02;
|
|
|
- Uart0AskMsg.Bms_Address = METER1_ADDRESS_CODE+i;//µÚÒ»´Î¶Á02£¬µÚ¶þ´Î¶Á03
|
|
|
- Uart0AskMsg.Bms_Funcode = UART_READ_CODE;
|
|
|
- Uart0AskMsg.Reg_Begin_H = RegAddrBegin>>8;
|
|
|
- Uart0AskMsg.Reg_Begin_L = RegAddrBegin;
|
|
|
- Uart0AskMsg.Reg_Num_H = Reg_Num >> 8;
|
|
|
- Uart0AskMsg.Reg_Num_L = Reg_Num;
|
|
|
- CRC_chk_buffer = crc_chk((uint8 *)&Uart0AskMsg, 6);
|
|
|
- Uart0AskMsg.CRC_L = CRC_chk_buffer;
|
|
|
- Uart0AskMsg.CRC_H = CRC_chk_buffer >> 8;
|
|
|
- UART_Send_Data(UART_LPUART0, (uint8 *)&Uart0AskMsg, sizeof(Uart0AskMsg), 100);
|
|
|
- UART_Receive_Data(UART_LPUART0, UartDataRecv, &pReadLen, 1000);
|
|
|
- //µç±íÊý¾Ý½âÎö
|
|
|
- if (pReadLen > 5)
|
|
|
- {
|
|
|
- uint16 CrcChkGet = 0xffff;
|
|
|
- uint16 CrcChkCal = 0x0000;
|
|
|
- CrcChkCal = crc_chk(UartDataRecv, pReadLen-2);
|
|
|
- CrcChkGet = ((uint16)(*(UartDataRecv+pReadLen-1))<<8) | ((uint16)(*(UartDataRecv+pReadLen-2)));
|
|
|
- if(CrcChkCal==CrcChkGet)
|
|
|
- {
|
|
|
- pt[i] = ((uint16)(*(UartDataRecv+3))<<8) | ((uint16)(*(UartDataRecv+4)));
|
|
|
- ct[i] = ((uint16)(*(UartDataRecv+5))<<8) | ((uint16)(*(UartDataRecv+6)));
|
|
|
- }
|
|
|
- }
|
|
|
- /*µç±íµçÁ¿Êý¾Ý¶ÁÈ¡*/
|
|
|
- pReadLen = 0;
|
|
|
- RegAddrBegin = 0x3F;
|
|
|
- Reg_Num = 0x04;
|
|
|
- Uart0AskMsg.Bms_Address = METER1_ADDRESS_CODE+i;//µÚÒ»´Î¶Á02£¬µÚ¶þ´Î¶Á03
|
|
|
- Uart0AskMsg.Bms_Funcode = UART_READ_CODE;
|
|
|
- Uart0AskMsg.Reg_Begin_H = RegAddrBegin>>8;
|
|
|
- Uart0AskMsg.Reg_Begin_L = RegAddrBegin;
|
|
|
- Uart0AskMsg.Reg_Num_H = Reg_Num >> 8;
|
|
|
- Uart0AskMsg.Reg_Num_L = Reg_Num;
|
|
|
- CRC_chk_buffer = crc_chk((uint8 *)&Uart0AskMsg, 6);
|
|
|
- Uart0AskMsg.CRC_L = CRC_chk_buffer;
|
|
|
- Uart0AskMsg.CRC_H = CRC_chk_buffer >> 8;
|
|
|
- UART_Send_Data(UART_LPUART0, (uint8 *)&Uart0AskMsg, sizeof(Uart0AskMsg), 100);
|
|
|
- UART_Receive_Data(UART_LPUART0, UartDataRecv, &pReadLen, 1000);
|
|
|
- //µç±íÊý¾Ý½âÎö
|
|
|
- if (pReadLen > 5)
|
|
|
- {
|
|
|
- uint16 CrcChkGet = 0xffff;
|
|
|
- uint16 CrcChkCal = 0x0000;
|
|
|
- CrcChkCal = crc_chk(UartDataRecv, pReadLen-2);
|
|
|
- CrcChkGet = ((uint16)(*(UartDataRecv+pReadLen-1))<<8) | ((uint16)(*(UartDataRecv+pReadLen-2)));
|
|
|
- if(CrcChkCal==CrcChkGet)
|
|
|
- {
|
|
|
- //meterAllPwr[i] = pt[i]*ct[i]*(((uint32)(*(UartRecvPtr+3))<<24)|((uint32)(*(UartRecvPtr+4))<<16)|((uint32)(*(UartRecvPtr+5))<<8) | ((uint32)(*(UartRecvPtr+6))));
|
|
|
- meterPosPwr[i] = pt[i]*ct[i]*((uint32)(*(UartDataRecv+3))<<24)|((uint32)(*(UartDataRecv+4))<<16)|((uint32)(*(UartDataRecv+5))<<8) | ((uint32)(*(UartDataRecv+6)));
|
|
|
- meterNegPwr[i] = pt[i]*ct[i]*((uint32)(*(UartDataRecv+7))<<24)|((uint32)(*(UartDataRecv+8))<<16)|((uint32)(*(UartDataRecv+9))<<8) | ((uint32)(*(UartDataRecv+10)));
|
|
|
- meterPosPwr[i] = meterPosPwr[i] * 100;
|
|
|
- meterNegPwr[i] = meterNegPwr[i] * 100;
|
|
|
- meterAllPwr[i] = meterPosPwr[i] + meterNegPwr[i];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- readCnt++;
|
|
|
PROC_UART0_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
|
|
|
break;
|
|
|
}
|
|
|
case PROCESS_UART_STATE_WRITE:
|
|
|
{
|
|
|
- if(battSeparateEnable)//×î¶àÖØÐÂд5´Î
|
|
|
+ if (battSeparateEnable) //最多�新写5次
|
|
|
{
|
|
|
uint16 RegAddress = 0;
|
|
|
uint16 CRC_chk_buffer = 0;
|
|
|
- uint8 WriteData[2] = {0x00,0x00};
|
|
|
+ uint8 WriteData[2] = {0x00, 0x00};
|
|
|
uint8 UartRecvBuffer[10];
|
|
|
- if(!battSeparateCtlState)
|
|
|
+ if (!battSeparateCtlState)
|
|
|
{
|
|
|
- setbit(WriteData[0],7);
|
|
|
+ WriteData[1] = 0x55;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- clrbit(WriteData[0],7);
|
|
|
+ WriteData[1] = 0xAA;
|
|
|
}
|
|
|
- RegAddress = 0x1B + AppDataInfo.BattCellCount + AppDataInfo.BattTempCount;
|
|
|
+ RegAddress = 100;
|
|
|
UartWriteMsgType Uart_Write_Msg;
|
|
|
Uart_Write_Msg.Bms_Address = BMS_ADDRESS_CODE;
|
|
|
Uart_Write_Msg.Bms_Funcode = UART_WRITE_CODE;
|
|
@@ -282,13 +83,13 @@ void Uart0Task(void *pvParameters)
|
|
|
Uart_Write_Msg.Reg_Begin_L = RegAddress;
|
|
|
Uart_Write_Msg.Reg_Num_H = 0x00;
|
|
|
Uart_Write_Msg.Reg_Num_L = 0x01;
|
|
|
- Uart_Write_Msg.Data_Count = 0x02; //ҪдÈëµÄ×Ö½ÚÊý
|
|
|
+ Uart_Write_Msg.Data_Count = 0x02; //è¦�写入的å—节数
|
|
|
memcpy(Uart_Write_Msg.Data, WriteData, 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_H = CRC_chk_buffer >> 8;
|
|
|
- UART_Query_Data(UART_LPUART0,UART_LPUART0,(uint8 *)&Uart_Write_Msg,sizeof(Uart_Write_Msg),UartRecvBuffer, &pReadLen,500);
|
|
|
- if (pReadLen>3&&*(UartRecvBuffer+1) == 0x10)
|
|
|
+ UART_Query_Data(UART_LPUART0, UART_LPUART0, (uint8 *)&Uart_Write_Msg, sizeof(Uart_Write_Msg), UartRecvBuffer, &pReadLen, 500);
|
|
|
+ if (pReadLen > 3 && *(UartRecvBuffer + 1) == 0x10)
|
|
|
{
|
|
|
writecounter = 0;
|
|
|
battSeparateEnable = 0;
|
|
@@ -298,7 +99,7 @@ void Uart0Task(void *pvParameters)
|
|
|
writecounter++;
|
|
|
}
|
|
|
}
|
|
|
- if(writecounter>=5)
|
|
|
+ if (writecounter >= 5)
|
|
|
{
|
|
|
battSeparateEnable = 0;
|
|
|
writecounter = 0;
|
|
@@ -315,162 +116,183 @@ void Uart0Task(void *pvParameters)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-bool bmsCellInfoDecode(uint8 *dataPtr) //¸ù¾Ý´®¿ÚÐÒéÈ·¶¨µÄ½âÂ뺯Êý,µçѹµçÁ÷½âÂë
|
|
|
+bool bmsCellInfoDecode(uint8 *dataPtr) //电压数æ�®è§£ç �
|
|
|
+{
|
|
|
+ for (uint8 i = 0; i < BMS_CELLNUM; i++)
|
|
|
+ {
|
|
|
+ battCellU[i] = ((dataPtr[(0x00 + i) * 2] << 8) | dataPtr[(0x00 + i) * 2 + 1]);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+bool bmsTempInfoDecode(uint8 *dataPtr) //温度数æ�®è§£ç �
|
|
|
+{
|
|
|
+ for (uint8 i = 0; i < BMS_TEMPNUM; i++)
|
|
|
+ {
|
|
|
+ battCellTemp[i] = dataPtr[(0x00 + i) * 2 + 1];
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+bool bmsOtherInfoDecode(uint8 *dataPtr) //其他数�解�
|
|
|
{
|
|
|
- uint8 i = 0;
|
|
|
- sint8 BattCurrentNegFlag = 1;
|
|
|
uint16 Batt_current;
|
|
|
- uint8 BATT_CELL_VOL_NUM = 0, BATT_TEMP_NUM = 0;
|
|
|
- uint32 Battsumvoltage = 0;
|
|
|
- BATT_CELL_VOL_NUM = (dataPtr[(0x00) * 2] << 8) | (dataPtr[(0x00) * 2 + 1]);
|
|
|
- BATT_TEMP_NUM = ((dataPtr[(0x01) * 2] << 8) | (dataPtr[(0x01) * 2 + 1])) - BmsOtherTemp;
|
|
|
- if (BATT_CELL_VOL_NUM != AppDataInfo.BattCellCount || BATT_TEMP_NUM != AppDataInfo.BattTempCount)
|
|
|
+ battPackVol = (dataPtr[(0x00) * 2]) << 8 | (dataPtr[(0x00) * 2 + 1]);
|
|
|
+ Batt_current = (dataPtr[(0x01) * 2] << 8) | (dataPtr[(0x01) * 2 + 1]);
|
|
|
+ battI = Batt_current - 6000; //电��移���
|
|
|
+ battSOC = dataPtr[(0x02) * 2 + 1];
|
|
|
+ battSOH = dataPtr[(0x03) * 2 + 1];
|
|
|
+ battWorkState = (dataPtr[(0x06) * 2 + 1]) & 0x03; //ç”µæ± çŠ¶æ€�(原始数æ�®),3表示开路,2表示放电,1表示充电
|
|
|
+ switch (battWorkState) //ç”µæ± çŠ¶æ€�(ä¸Šä¼ æ•°æ�®),0表示开路,1表示放电,2表示充电
|
|
|
{
|
|
|
- BATT_CELL_VOL_NUM = AppDataInfo.BattCellCount;
|
|
|
- BATT_TEMP_NUM = AppDataInfo.BattTempCount;
|
|
|
+ case 0:
|
|
|
+ battWorkState = 0;
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ battWorkState = 2;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ battWorkState = 1;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ battWorkState = 0;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
- Batt_current = (dataPtr[(0x02 + BATT_CELL_VOL_NUM) * 2] << 8) | (dataPtr[(0x02 + BATT_CELL_VOL_NUM) * 2 + 1]);
|
|
|
- Batt_current = Batt_current*100;//ƽ·åÐÒ鵥λÊÇ1A
|
|
|
- //ÔʼÊý¾Ý£º³äµçΪ¸º£¬·ÅµçΪÕý
|
|
|
- if (Batt_current < 0x8000) //³äµç¹ý³Ì
|
|
|
+ maxCellVol = (dataPtr[(0x13) * 2] << 8) | dataPtr[(0x13) * 2 + 1];
|
|
|
+ minCellVol = (dataPtr[(0x16) * 2] << 8) | dataPtr[(0x16) * 2 + 1];
|
|
|
+ AppConfigInfo.AppDataInfo.battDischrgAccEnrg = (dataPtr[(0x34) * 2] << 8) | dataPtr[(0x34) * 2 + 1];
|
|
|
+ AppConfigInfo.AppDataInfo.battCycleTimes = AppConfigInfo.AppDataInfo.battDischrgAccEnrg / 49000;
|
|
|
+ // //故障状æ€�æ˜ å…³ç³»(先完æˆ�å‘Šè¦çŠ¶æ€�简å�•ä¸Šä¼ )
|
|
|
+ // uint8 ErrorArrayTemp[32] = {0};
|
|
|
+ // uint8 ErrorArrayNumTemp[32] = {81, 87, 83, 89, 97, 99, 132, 131, 134, 84, 90, 82, 88, 135, 136, 98, 100};
|
|
|
+ // ErrorArrayTemp[0] = getbit(dataPtr[(0x03 + OtherInfoAddrOffset) * 2], 0); //电芯电压过高切æ–å‘Šè¦-0-81
|
|
|
+ // ErrorArrayTemp[1] = getbit(dataPtr[(0x03 + OtherInfoAddrOffset) * 2], 1); //总压过高切æ–å‘Šè¦-1-87
|
|
|
+ // ErrorArrayTemp[2] = getbit(dataPtr[(0x04 + OtherInfoAddrOffset) * 2 + 1], 0); //电芯电压过低切æ–å‘Šè¦2-83
|
|
|
+ // ErrorArrayTemp[3] = getbit(dataPtr[(0x04 + OtherInfoAddrOffset) * 2 + 1], 1); //总压过低切æ–å‘Šè¦3-89
|
|
|
+ // ErrorArrayTemp[4] = getbit(dataPtr[(0x04 + OtherInfoAddrOffset) * 2], 4); //å�•èŠ‚温度过高切æ–4-97
|
|
|
+ // ErrorArrayTemp[5] = getbit(dataPtr[(0x04 + OtherInfoAddrOffset) * 2], 5); //å�•èŠ‚温度过低切æ–5-99
|
|
|
+ // ErrorArrayTemp[6] = getbit(dataPtr[(0x05 + OtherInfoAddrOffset) * 2 + 1], 1); //放电电æµ�切æ–6-132
|
|
|
+ // ErrorArrayTemp[7] = getbit(dataPtr[(0x05 + OtherInfoAddrOffset) * 2 + 1], 2); //充电电æµ�切æ–7-131
|
|
|
+ // ErrorArrayTemp[8] = getbit(dataPtr[(0x05 + OtherInfoAddrOffset) * 2 + 1], 3); // BTU连接告è¦8-134
|
|
|
+ // ErrorArrayTemp[9] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1], 0); //å�•èŠ‚电压下é™�å‘Šè¦9-84
|
|
|
+ // ErrorArrayTemp[10] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1], 1); //组电压下é™�å‘Šè¦10-90
|
|
|
+ // ErrorArrayTemp[11] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1], 2); //å�•èŠ‚电压上é™�å‘Šè¦11-82
|
|
|
+ // ErrorArrayTemp[12] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1], 3); //组å�•èŠ‚电压上é™�å‘Šè¦12-88
|
|
|
+ // ErrorArrayTemp[13] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1], 4); //放电电æµ�å‘Šè¦13-135
|
|
|
+ // ErrorArrayTemp[14] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1], 5); //充电电æµ�å‘Šè¦14-136
|
|
|
+ // ErrorArrayTemp[15] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1], 6); //å�•èŠ‚温度上é™�å‘Šè¦15-98
|
|
|
+ // ErrorArrayTemp[16] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1], 7); //å�•èŠ‚温度下线告è¦16-100
|
|
|
+ // for (uint8 i = 0, j = 0; (i < 32 && j < 5); i++)
|
|
|
+ // {
|
|
|
+ // if (ErrorArrayTemp[i] == 1)
|
|
|
+ // {
|
|
|
+ // PutErrorNum(ErrorArray, sizeof(ErrorArray) / 2, ErrorArrayNumTemp[i]);
|
|
|
+ // j++;
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ return true;
|
|
|
+}
|
|
|
+// void battDataCalFunc(void)
|
|
|
+// {
|
|
|
+// static uint32 timercounterCal = 0;
|
|
|
+// uint16 timediff = 0;
|
|
|
+// float battCapTempOnce = 0;
|
|
|
+// static float battCapTemp = 0;
|
|
|
+// static float battEnrgTemp = 0;
|
|
|
+// timediff = TimerCounter - timercounterCal;
|
|
|
+// timercounterCal = TimerCounter;
|
|
|
+// if (timediff == 0 || timediff > 60 * 1000)
|
|
|
+// {
|
|
|
+// return;
|
|
|
+// }
|
|
|
+// if (battI > 10000)
|
|
|
+// {
|
|
|
+// battCapTempOnce = ((battI - 10000) / 10.0) * (timediff / 3600.0);
|
|
|
+// battCapTemp = battCapTempOnce + battCapTemp;
|
|
|
+// battEnrgTemp = (battCapTempOnce * battPackVol) / 10000.0 + battEnrgTemp;
|
|
|
+// if (battEnrgTemp > 10)
|
|
|
+// {
|
|
|
+// AppConfigInfo.AppDataInfo.battDischrgAccCap = AppConfigInfo.AppDataInfo.battDischrgAccCap + (uint32)battCapTemp;
|
|
|
+// AppConfigInfo.AppDataInfo.battDischrgAccEnrg = AppConfigInfo.AppDataInfo.battDischrgAccEnrg + (uint32)battEnrgTemp;
|
|
|
+// AppConfigInfo.AppDataInfo.battCycleTimes = AppConfigInfo.AppDataInfo.battDischrgAccEnrg / 49000;
|
|
|
+// AppConfigInfo.appSaveFlg = true;
|
|
|
+// battEnrgTemp = 0;
|
|
|
+// battCapTemp = 0;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+void UartBusReadDataFunc(uint16 RegAddrBegin, uint16 Reg_Num, bool (*decodeFunc)(uint8 *dataPtr))
|
|
|
+{
|
|
|
+ // argv In
|
|
|
+ UartQueryType Uart0AskMsg;
|
|
|
+ uint16 ReadLen1 = 0;
|
|
|
+ uint16 ReadLenTar = 0;
|
|
|
+ uint8 ReadDelayCounter = 0;
|
|
|
+ uint16 CRC_chk_buffer = 0;
|
|
|
+ uint16 pReadLen;
|
|
|
+ UartAnsType UartAnsData;
|
|
|
+ uint8 UartDataRecv[256];
|
|
|
+ pReadLen = 0;
|
|
|
+ Uart0AskMsg.Bms_Address = BMS_ADDRESS_CODE;
|
|
|
+ Uart0AskMsg.Bms_Funcode = UART_READ_CODE;
|
|
|
+ Uart0AskMsg.Reg_Begin_H = RegAddrBegin >> 8;
|
|
|
+ Uart0AskMsg.Reg_Begin_L = RegAddrBegin;
|
|
|
+ Uart0AskMsg.Reg_Num_H = Reg_Num >> 8;
|
|
|
+ Uart0AskMsg.Reg_Num_L = Reg_Num;
|
|
|
+ CRC_chk_buffer = crc_chk((uint8 *)&Uart0AskMsg, 6);
|
|
|
+ Uart0AskMsg.CRC_L = CRC_chk_buffer;
|
|
|
+ Uart0AskMsg.CRC_H = CRC_chk_buffer >> 8;
|
|
|
+ UART_Send_Data(UART_LPUART0, (uint8 *)&Uart0AskMsg, sizeof(Uart0AskMsg), 1000);
|
|
|
+ ReadLenTar = (Reg_Num)*2 + 5;
|
|
|
+ memset((uint8 *)&UartAnsData, 0x00, sizeof(UartAnsData));
|
|
|
+ while (1)
|
|
|
{
|
|
|
- if (Batt_current > 0x8000) // Êý¾ÝΪ¸º
|
|
|
+ UART_Receive_Data(UART_LPUART0, UartDataRecv, &pReadLen, 100);
|
|
|
+ if (pReadLen > 2)
|
|
|
{
|
|
|
- //Çó²¹Â룬½á¹ûΪ¸º
|
|
|
- Batt_current = (uint16)((uint16)(~(Batt_current)) + 1);
|
|
|
- Batt_current = Batt_current / 10;
|
|
|
- BattCurrentNegFlag = -1;
|
|
|
+ memcpy((uint8 *)&UartAnsData + ReadLen1, UartDataRecv, pReadLen);
|
|
|
+ ReadLen1 = ReadLen1 + pReadLen;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- //Ô´Â룬½á¹ûΪ¸º
|
|
|
- Batt_current = Batt_current / 10;
|
|
|
- BattCurrentNegFlag = -1;
|
|
|
+ ReadDelayCounter++;
|
|
|
}
|
|
|
- }
|
|
|
- else //·Åµç¹ý³Ì
|
|
|
- {
|
|
|
- if (Batt_current > 0x8000) // Êý¾ÝΪ¸º
|
|
|
+ if (ReadLen1 >= ReadLenTar)
|
|
|
{
|
|
|
- //Çó²¹Â룬½á¹ûΪÕý
|
|
|
- Batt_current = (uint16)((uint16)(~(Batt_current)) + 1);
|
|
|
- Batt_current = Batt_current / 10;
|
|
|
- BattCurrentNegFlag = 1;
|
|
|
+ ReadDelayCounter = 0;
|
|
|
+ pReadLen = ReadLen1;
|
|
|
+ ReadLen1 = 0;
|
|
|
+ break;
|
|
|
}
|
|
|
- else
|
|
|
+ if (ReadDelayCounter >= 20)
|
|
|
{
|
|
|
- //Ô´Â룬½á¹ûΪÕý
|
|
|
- Batt_current = Batt_current / 10;
|
|
|
- BattCurrentNegFlag = 1;
|
|
|
+ ReadDelayCounter = 0;
|
|
|
+ pReadLen = 0;
|
|
|
+ ReadLen1 = 0;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
- battI = Batt_current * BattCurrentNegFlag + 0x2710;
|
|
|
- // sint16 BattI_Temp = 0;//×öµçѹ²¹³¥ÐèÒªµÄ²ÎÊý
|
|
|
- // BattI_Temp = Batt_current * BattCurrentNegFlag;
|
|
|
- for (i = 0; i < BATT_CELL_VOL_NUM; i++)
|
|
|
+ if (pReadLen > 0)
|
|
|
{
|
|
|
- //battCellU[i] = ((dataPtr[(0x02 + i) * 2] << 8) | dataPtr[(0x02 + i) * 2 + 1]) + (INT16)(cmnm_R_voloffset[i] * BattI_Temp / 10000);//²»Ê¹Óõçѹ²¹³¥
|
|
|
- battCellU[i] = ((dataPtr[(0x02 + i) * 2] << 8) | dataPtr[(0x02 + i) * 2 + 1]);
|
|
|
- Battsumvoltage = Battsumvoltage + battCellU[i];
|
|
|
- }
|
|
|
- avrgCellVol = Battsumvoltage / BATT_CELL_VOL_NUM;
|
|
|
- battPackVol = Battsumvoltage/100;
|
|
|
- battDataCalFunc();
|
|
|
- return true;
|
|
|
-}
|
|
|
-bool bmsOtherInfoDecode(uint8 *dataPtr)//ÆäËûÊý¾Ý½âÎö
|
|
|
-{
|
|
|
- uint8 TEMP_NUM = 0, temp = 0;
|
|
|
-
|
|
|
- sint8 OtherInfoAddrOffset = -3;//ÆäËûÊý¾Ý½âÎöµÄÆðʼλÖøı䣬ÐèÒªÏòÇ°¼õ3
|
|
|
- TEMP_NUM = AppDataInfo.BattTempCount + BmsOtherTemp;
|
|
|
- bmsHwVersion = dataPtr[(0x08 + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1];
|
|
|
- bmsSwVersion = dataPtr[(0x08 + OtherInfoAddrOffset + TEMP_NUM) * 2];
|
|
|
-
|
|
|
- temp = ((dataPtr[(0x09 + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1]) >> 1) & 0x03;
|
|
|
- battMOSSwitchState = ((temp & 0x01) << 1) | ((temp & 0x02) >> 1);
|
|
|
- battSOC = dataPtr[(0x0B + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1];
|
|
|
- battSOH = dataPtr[(0x0C + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1];
|
|
|
- Battdesigncap = (dataPtr[(0x0E + OtherInfoAddrOffset + TEMP_NUM) * 2]) << 24 | (dataPtr[(0x0E + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1]) << 16 | (dataPtr[(0x0F + OtherInfoAddrOffset + TEMP_NUM) * 2]) << 8 | (dataPtr[(0x0F + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1]);
|
|
|
-// battPackVol = ((dataPtr[(0x18 + OtherInfoAddrOffset + TEMP_NUM) * 2]) << 8 | (dataPtr[(0x18 + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1])) / 10; // uint 100mV
|
|
|
- maxCellVol = (dataPtr[(0x19 + OtherInfoAddrOffset + TEMP_NUM) * 2] << 8) | dataPtr[(0x19 + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1];
|
|
|
- minCellVol = (dataPtr[(0x1A + OtherInfoAddrOffset + TEMP_NUM) * 2] << 8) | dataPtr[(0x1A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1];
|
|
|
- for (uint8 i = 0; i < AppDataInfo.BattTempCount; i++)
|
|
|
- {
|
|
|
- battCellTemp[i] = dataPtr[(0x06 + OtherInfoAddrOffset + i) * 2 + 1];
|
|
|
- }
|
|
|
- battWorkState = (dataPtr[(0x03 + OtherInfoAddrOffset) * 2 + 1]) & 0x03; //µç³Ø״̬(ÔʼÊý¾Ý)£¬0±íʾ¾²Öã¬1±íʾ·Åµç£¬2±íʾ³äµç
|
|
|
- //״̬Á¿ÉÏ´«
|
|
|
- battHeatState = getbit(dataPtr[(0x09 + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],5);
|
|
|
- battFanState = getbit(dataPtr[(0x09 + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],3);
|
|
|
- battRelayState = getbit(dataPtr[(0x09 + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],4);
|
|
|
- battConverState = getbit(dataPtr[(0x09 + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],6);
|
|
|
- battSeparateState = !getbit(dataPtr[(0x1B + OtherInfoAddrOffset + TEMP_NUM) * 2],7);
|
|
|
- if (battSeparateState==1)
|
|
|
- {
|
|
|
- battMOSSwitchState = battMOSSwitchState | (0x01 << 2);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- battMOSSwitchState = battMOSSwitchState | (0x00 << 2);
|
|
|
- }
|
|
|
- //¹ÊÕÏ״̬ӳ¹Øϵ(ÏÈÍê³É¸æ¾¯×´Ì¬¼òµ¥ÉÏ´«)
|
|
|
- uint8 ErrorArrayTemp[32] ={0};
|
|
|
- uint8 ErrorArrayNumTemp[32]={81,87,83,89,97,99,132,131,134,84,90,82,88,135,136,98,100};
|
|
|
- ErrorArrayTemp[0] = getbit(dataPtr[(0x03 + OtherInfoAddrOffset) * 2],0);//µçоµçѹ¹ý¸ßÇжϸ澯-0-81
|
|
|
- ErrorArrayTemp[1] = getbit(dataPtr[(0x03 + OtherInfoAddrOffset) * 2],1);//×Üѹ¹ý¸ßÇжϸ澯-1-87
|
|
|
- ErrorArrayTemp[2] = getbit(dataPtr[(0x04 + OtherInfoAddrOffset) * 2 + 1],0);//µçоµçѹ¹ýµÍÇжϸ澯2-83
|
|
|
- ErrorArrayTemp[3] = getbit(dataPtr[(0x04 + OtherInfoAddrOffset) * 2 + 1],1);//×Üѹ¹ýµÍÇжϸ澯3-89
|
|
|
- ErrorArrayTemp[4] = getbit(dataPtr[(0x04 + OtherInfoAddrOffset) * 2],4);//µ¥½Úζȹý¸ßÇжÏ4-97
|
|
|
- ErrorArrayTemp[5] = getbit(dataPtr[(0x04 + OtherInfoAddrOffset) * 2],5);//µ¥½ÚζȹýµÍÇжÏ5-99
|
|
|
- ErrorArrayTemp[6] = getbit(dataPtr[(0x05 + OtherInfoAddrOffset) * 2 + 1],1);//·ÅµçµçÁ÷ÇжÏ6-132
|
|
|
- ErrorArrayTemp[7] = getbit(dataPtr[(0x05 + OtherInfoAddrOffset) * 2 + 1],2);//³äµçµçÁ÷ÇжÏ7-131
|
|
|
- ErrorArrayTemp[8] = getbit(dataPtr[(0x05 + OtherInfoAddrOffset) * 2 + 1],3);//BTUÁ¬½Ó¸æ¾¯8-134
|
|
|
- ErrorArrayTemp[9] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],0);//µ¥½ÚµçѹÏÂÏ޸澯9-84
|
|
|
- ErrorArrayTemp[10] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],1);//×éµçѹÏÂÏ޸澯10-90
|
|
|
- ErrorArrayTemp[11] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],2);//µ¥½ÚµçѹÉÏÏ޸澯11-82
|
|
|
- ErrorArrayTemp[12] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],3);//×éµ¥½ÚµçѹÉÏÏ޸澯12-88
|
|
|
- ErrorArrayTemp[13] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],4);//·ÅµçµçÁ÷¸æ¾¯13-135
|
|
|
- ErrorArrayTemp[14] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],5);//³äµçµçÁ÷¸æ¾¯14-136
|
|
|
- ErrorArrayTemp[15] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],6);//µ¥½ÚζÈÉÏÏ޸澯15-98
|
|
|
- ErrorArrayTemp[16] = getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],7);//µ¥½ÚζÈÏÂÏ߸澯16-100
|
|
|
- for(uint8 i=0,j=0;(i<32&&j<5);i++)
|
|
|
- {
|
|
|
- if(ErrorArrayTemp[i]==1)
|
|
|
+ uint16 CrcChkGet = 0xffff;
|
|
|
+ uint16 CrcChkCal = 0x0000;
|
|
|
+ CrcChkCal = crc_chk((uint8 *)&UartAnsData, pReadLen - 2);
|
|
|
+ CrcChkGet = ((uint16)(UartAnsData.Data[pReadLen - 1 - 3]) << 8) | ((uint16)(UartAnsData.Data[pReadLen - 2 - 3]));
|
|
|
+ if (CrcChkCal == CrcChkGet)
|
|
|
{
|
|
|
- PutErrorNum(ErrorArray, sizeof(ErrorArray)/2, ErrorArrayNumTemp[i]);
|
|
|
- j++;
|
|
|
+ decodeFunc(UartAnsData.Data);
|
|
|
+ UartNoDataReadCounter = 0;
|
|
|
}
|
|
|
- }
|
|
|
- return true;
|
|
|
-}
|
|
|
-void battDataCalFunc(void)
|
|
|
-{
|
|
|
- static uint32 timercounterCal = 0;
|
|
|
- uint16 timediff = 0;
|
|
|
- float battCapTempOnce = 0;
|
|
|
- static float battCapTemp = 0;
|
|
|
- static float battEnrgTemp = 0;
|
|
|
- timediff = TimerCounter - timercounterCal;
|
|
|
- timercounterCal = TimerCounter;
|
|
|
- if(timediff==0 ||timediff>60*1000)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- if(battI>10000)
|
|
|
- {
|
|
|
- battCapTempOnce = ((battI - 10000)/10.0)*(timediff/3600.0);
|
|
|
- battCapTemp = battCapTempOnce + battCapTemp;
|
|
|
- battEnrgTemp = (battCapTempOnce*battPackVol)/10000.0 + battEnrgTemp;
|
|
|
- if(battEnrgTemp>10)
|
|
|
+ else
|
|
|
{
|
|
|
- AppConfigInfo.AppDataInfo.battDischrgAccCap = AppConfigInfo.AppDataInfo.battDischrgAccCap + (uint32)battCapTemp;
|
|
|
- AppConfigInfo.AppDataInfo.battDischrgAccEnrg = AppConfigInfo.AppDataInfo.battDischrgAccEnrg + (uint32)battEnrgTemp;
|
|
|
- AppConfigInfo.AppDataInfo.battCycleTimes = AppConfigInfo.AppDataInfo.battDischrgAccEnrg/49000;
|
|
|
- AppConfigInfo.appSaveFlg = true;
|
|
|
- battEnrgTemp = 0;
|
|
|
- battCapTemp = 0;
|
|
|
+ UartNoDataReadCounter++;
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UartNoDataReadCounter++;
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
#endif
|