Parcourir la source

平峰项目测试完成,基本实现功能

CHENJIE-PC\QiXiang_CHENJIE il y a 3 ans
Parent
commit
54181b6f9d

+ 4 - 4
.settings/language.settings.xml

@@ -5,7 +5,7 @@
 			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
-			<provider class="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" console="false" env-hash="512964616103659477" id="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT S32DS Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+			<provider class="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" console="false" env-hash="1998488586995695481" id="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT S32DS Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 				<language-scope id="org.eclipse.cdt.core.gcc"/>
 				<language-scope id="org.eclipse.cdt.core.g++"/>
 			</provider>
@@ -16,7 +16,7 @@
 			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
-			<provider class="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" console="false" env-hash="512964616103659477" id="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT S32DS Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+			<provider class="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" console="false" env-hash="1998488586995695481" id="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT S32DS Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 				<language-scope id="org.eclipse.cdt.core.gcc"/>
 				<language-scope id="org.eclipse.cdt.core.g++"/>
 			</provider>
@@ -27,7 +27,7 @@
 			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
-			<provider class="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" console="false" env-hash="512964616103659477" id="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT S32DS Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+			<provider class="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" console="false" env-hash="1998488586995695481" id="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT S32DS Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 				<language-scope id="org.eclipse.cdt.core.gcc"/>
 				<language-scope id="org.eclipse.cdt.core.g++"/>
 			</provider>
@@ -38,7 +38,7 @@
 			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
-			<provider class="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" console="false" env-hash="512964616103659477" id="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT S32DS Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
+			<provider class="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" console="false" env-hash="1998488586995695481" id="com.freescale.s32ds.cross.gnu.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT S32DS Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 				<language-scope id="org.eclipse.cdt.core.gcc"/>
 				<language-scope id="org.eclipse.cdt.core.g++"/>
 			</provider>

+ 1 - 1
Project_Settings/Debugger/S32K146_4G_Debug_FLASH_PNE.launch

@@ -216,5 +216,5 @@
 </listAttribute>
 <stringAttribute key="org.eclipse.dsf.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList context=&quot;reserved-for-future-use&quot;&gt;&#13;&#10;&lt;gdbmemoryBlockExpression address=&quot;536806032&quot; label=&quot;RX_Buffer[UART_LPUART2]&quot;/&gt;&#13;&#10;&lt;gdbmemoryBlockExpression address=&quot;536823956&quot; label=&quot;GpsBufferGet&quot;/&gt;&#13;&#10;&lt;gdbmemoryBlockExpression address=&quot;255&quot; label=&quot;SocketId&quot;/&gt;&#13;&#10;&lt;/memoryBlockExpressionList&gt;&#13;&#10;"/>
 <stringAttribute key="process_factory_id" value="org.eclipse.cdt.dsf.gdb.GdbProcessFactory"/>
-<stringAttribute key="saved_expressions&lt;seperator&gt;Unknown" value="0x1fff4b56,0x1fff0290,0x1fff4894,0x1fff04e8,0x1fff01c8,0x1fff2ce8,0x1fff0100,0x1fff08d0,0x1fff4b48,0x1fff4b50,0x1fff0103,1fff3798,0x1fff3798,0x1fffab2c,0x1fffa82c"/>
+<stringAttribute key="saved_expressions&lt;seperator&gt;Unknown" value="0x1fff4894,0x1fff04e8,0x1fff01c8,0x1fff2ce8,0x1fff0100,0x1fff08d0,0x1fff4b48,0x1fff4b50,0x1fff0103,1fff3798,0x1fff3798,0x1fffab2c,0x1fffa82c,0x1fff01f3,0x1fff050e"/>
 </launchConfiguration>

+ 1 - 1
RTD/src/Lpuart_Uart_Ip.c

@@ -162,7 +162,7 @@ Lpuart_Uart_Ip_StateStructureType Lpuart_Uart_Ip_apStateStructure[LPUART_UART_IP
 #include "Uart_MemMap.h"
 
 /* Pointer to lpuart runtime state structure */
-static Lpuart_Uart_Ip_StateStructureType * Lpuart_Uart_Ip_apStateStructuresArray[LPUART_UART_IP_NUMBER_OF_INSTANCES];
+Lpuart_Uart_Ip_StateStructureType * Lpuart_Uart_Ip_apStateStructuresArray[LPUART_UART_IP_NUMBER_OF_INSTANCES];
 
 /** @brief User config structure. */
 const Lpuart_Uart_Ip_UserConfigType * Lpuart_Uart_Ip_apUserConfig[LPUART_UART_IP_NUMBER_OF_INSTANCES];

+ 1 - 1
generate/include/Lpuart_Uart_Ip_Defines.h

@@ -86,7 +86,7 @@ extern "C"{
 #define LPUART_UART_IP_TIMEOUT_TYPE                 (OSIF_COUNTER_SYSTEM)
 
 /* @brief Number of loops before returning LPUART_STATUS_TIMEOUT.*/
-#define LPUART_UART_IP_TIMEOUT_VALUE_US             (500U)  //zhengchao
+#define LPUART_UART_IP_TIMEOUT_VALUE_US             (10000U)  //zhengchao
 
 /* @brief LPUART DMA support */
 #define LPUART_UART_IP_HAS_DMA_ENABLED              (STD_ON)

+ 11 - 3
src/AppGlobalVar.c

@@ -44,6 +44,8 @@ const uint16 WebSitePort = 8712;
 #ifdef APP_UART0_ENABLE
 AppDataBody AppDataInfo = {BMS_CELLNUM, BMS_TEMPNUM};
 uint16 avrgCellVol = 0;			 //平均电压
+uint16 bmsHwVersion = 0;
+uint32 bmsSwVersion = 0;
 uint16 battCellU[BMS_CELLNUM];	 //电池电压
 uint16 battI = 0;				 // BMS电流(tcp上传)
 uint16 battPackVol = 0;			 // bms电压
@@ -52,21 +54,27 @@ uint16 maxCellVol = 0;			 //
 uint16 minCellVol = 0;			 //最小单体电压
 uint16 socd_pct_vcuSoc = 0;		 // soc(tcp上传,精度0.1)
 uint16 sohd_pct_bcuSoh = 0;		 // soh(tcp上传,精度0.1)
-uint32 battBalanceoInfo = 0;	 // bms上报的均衡状态
+uint32 battBalanceoInfo = 0;  //
 uint32 battProtectState = 0;	 // bms保护状态
 uint32 battWarningState = 0;	 // bms告警状态
 uint8 AvgBattTemp = 0;			 //平均单体温度
 uint8 battCellTemp[BMS_TEMPNUM]; //电池温度
 uint8 Battdesigncap = 0;		 //电池包设计容量
-uint8 battHeatEnableState = 0;	 // bms加热使能状态
+uint8 battHeatEnableState = 0;	 // bms加热状态
 uint8 battMOSSwitchState = 0;	 // bms mos开关状态
 uint8 battSOC = 0;				 // bms发送soc
 uint8 battSOH = 0;				 // bms发送soh
 uint8 battWorkState = 0;		 // bms工作状态
-uint8 BmsOtherTemp = 0;			 // BMS其他温度
+uint8 BmsOtherTemp = 0;			 // BMS其他温度,没有其他温度,为0
 uint8 maxCellTemp = 0;			 //最大单体温度
 uint8 minCellTemp = 0;			 //最小单体温度
 uint8 OtherTemp = 0;			 //通讯模块其他温度
+uint8 battHeatState = 0;
+uint8 battFanState = 0;
+uint8 battRelayState = 0;
+uint8 battConverState = 0;
+uint8 battSeparateEnable = 0;
+uint8 battSeparateEnableState = 0;
 #endif
 /*以下变量均为App_CAN相关变量*/
 #ifdef APP_CAN_ENABLE

+ 12 - 4
src/AppGlobalVar.h

@@ -16,12 +16,12 @@
 #ifndef APPGLOBALVAR_H_
 #define APPGLOBALVAR_H_
 
-//#define APP_UART0_ENABLE //平峰项目
-#define APP_CAN_ENABLE //重卡项目
+#define APP_UART0_ENABLE //平峰项目
+//#define APP_CAN_ENABLE //重卡项目
 
 #include "hal_adapter.h"
 // test Var
-#define defaultSn "PZLCLL128N2236001"
+#define defaultSn "GYTEST00000000001"
 
 #define HWVERSION 0x0001
 #define BLSWVERSION 0x00000001
@@ -74,13 +74,15 @@ extern AppDataBody AppDataInfo;
 extern uint16 avrgCellVol;              //平均电压
 extern uint16 battCellU[BMS_CELLNUM];   //电池电压
 extern uint16 battI;                    // BMS电流(tcp上传)
+extern uint16 bmsHwVersion;
+extern uint32 bmsSwVersion;
 extern uint16 battPackVol;              // bms电压
 extern uint16 ErrorTemp;                // BMS故障代码
 extern uint16 maxCellVol;               //最大单体电压
 extern uint16 minCellVol;               //最小单体电压
 extern uint16 socd_pct_vcuSoc;          // soc(tcp上传,精度0.1)
 extern uint16 sohd_pct_bcuSoh;          // soh(tcp上传,精度0.1)
-extern uint32 battBalanceoInfo;         // bms上报的均衡状态
+extern uint32 battBalanceoInfo;
 extern uint32 battProtectState;         // bms保护状态
 extern uint32 battWarningState;         // bms告警状态
 extern uint8 AvgBattTemp;               //平均单体温度
@@ -95,6 +97,12 @@ extern uint8 BmsOtherTemp;              // BMS
 extern uint8 maxCellTemp;               //最大单体温度
 extern uint8 minCellTemp;               //最小单体温度
 extern uint8 OtherTemp;                 //通讯模块其他温度
+extern uint8 battHeatState ;
+extern uint8 battFanState ;
+extern uint8 battRelayState ;
+extern uint8 battConverState ;
+extern uint8 battSeparateEnable ;
+extern uint8 battSeparateEnableState ;
 #endif
 /*以下变量均为App_CAN相关变量*/
 #ifdef APP_CAN_ENABLE

+ 199 - 43
src/AppTaskUart0.c

@@ -8,15 +8,18 @@
 #ifdef APP_UART0_ENABLE
 static process_Uart0 gProcess_Uart0_Task = PROCESS_UART_STATE_IDLE;
 #define PROC_UART0_STATE_SWITCH(a) (gProcess_Uart0_Task = a)
-bool uartBattInfoDecode(uint8 *dataPtr);
+bool bmsCellInfoDecode(uint8 *dataPtr);
+bool bmsOtherInfoDecode(uint8 *dataPtr);
 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;
+	static uint8 writecounter = 0;
 	while (1)
 	{
 		switch (gProcess_Uart0_Task)
@@ -28,30 +31,67 @@ void Uart0Task(void *pvParameters)
 			{
 				PROC_UART0_STATE_SWITCH(PROCESS_UART_STATE_READ);
 			}
+			else
+			{
+				PROC_UART0_STATE_SWITCH(PROCESS_UART_STATE_WRITE);
+			}
 			break;
 		}
 		case PROCESS_UART_STATE_READ:
 		{
-			/*电压电流数据读取*/
-
-
-			/*电流及状态的读取*/
-			Reg_Num = 0x40; //读取的寄存器数据,暂定,分开读取
+			/*电压电流数据读取(第一次读取)*/
+			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 = 0x00;
-			Uart0AskMsg.Reg_Begin_L = 0x00;
+			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;
+			memset(RX_Buffer[UART_LPUART0],0x00,sizeof(RX_Buffer[UART_LPUART0]));
+			UART_Query_Data(UART_LPUART0,UART_LPUART0,(uint8 *)&Uart0AskMsg,sizeof(Uart0AskMsg),RX_Buffer[UART_LPUART0], &pReadLen,500);
+			if (pReadLen > 0)
+			{
+				uint16 CrcChkGet = 0xffff;
+				uint16 CrcChkCal = 0x0000;
+				memcpy((uint8 *)(&UartAnsData),RX_Buffer[UART_LPUART0],0x03);
+				UartAnsData.DataPtr = (uint8 *)(&RX_Buffer[UART_LPUART0][3]);
+				CrcChkCal = crc_chk(RX_Buffer[UART_LPUART0], pReadLen-2);
+				CrcChkGet = (uint16)((RX_Buffer[UART_LPUART0][pReadLen-1]<<8)|(RX_Buffer[UART_LPUART0][pReadLen-2]));
+				if(CrcChkCal==CrcChkGet)
+				{
+					bmsCellInfoDecode(UartAnsData.DataPtr);
+				}
+			}
+			/*温度及其他状态信息读取(第二次读取)*/
+			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查询命令需要使能
 			Dio_WriteChannel(DioConf_DioChannel_PTB4_GPIO_OUT_MCU_RS485_EN, STD_ON);
 			UART_Send_Data(UART_LPUART0, (uint8 *)&Uart0AskMsg, sizeof(Uart0AskMsg), 1000);
 			Dio_WriteChannel(DioConf_DioChannel_PTB4_GPIO_OUT_MCU_RS485_EN, STD_OFF);
 			memset(RX_Buffer[UART_LPUART0], 0x00, sizeof(RX_Buffer[UART_LPUART0]));
 			UART_Receive_Data(UART_LPUART0, RX_Buffer[UART_LPUART0], &pReadLen, 1000);
 			Dio_WriteChannel(DioConf_DioChannel_PTB4_GPIO_OUT_MCU_RS485_EN, STD_ON);
+			*/
+			/*TTL直连可以直接查询*/
+			memset(RX_Buffer[UART_LPUART0],0x00,sizeof(RX_Buffer[UART_LPUART0]));
+			UART_Query_Data(UART_LPUART0,UART_LPUART0,(uint8 *)&Uart0AskMsg,sizeof(Uart0AskMsg),RX_Buffer[UART_LPUART0], &pReadLen,500);
 			if (pReadLen > 0)
 			{
 				uint16 CrcChkGet = 0xffff;
@@ -62,8 +102,52 @@ void Uart0Task(void *pvParameters)
 				CrcChkGet = (uint16)((RX_Buffer[UART_LPUART0][pReadLen-1]<<8)|(RX_Buffer[UART_LPUART0][pReadLen-2]));
 				if(CrcChkCal==CrcChkGet)
 				{
-					uartBattInfoDecode(UartAnsData.DataPtr);
+					bmsOtherInfoDecode(UartAnsData.DataPtr);
+				}
+			}
+			PROC_UART0_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
+			break;
+		}
+		case PROCESS_UART_STATE_WRITE:
+		{
+			if(battSeparateEnable)//最多重新写5次
+			{
+				uint16 RegAddress = 0;
+				uint16 CRC_chk_buffer = 0;
+				uint8 WriteData[2] = {0x00,0x00};
+				if(battSeparateEnableState)
+				{
+					setbit(WriteData[1],7);
 				}
+				else
+				{
+					clrbit(WriteData[1],7);
+				}
+				RegAddress = 0x1B + AppDataInfo.BattCellCount + AppDataInfo.BattTempCount;
+				UartWriteMsgType Uart_Write_Msg;
+				Uart_Write_Msg.Bms_Address = BMS_ADDRESS_CODE;
+				Uart_Write_Msg.Bms_Funcode = UART_WRITE_CODE;
+				Uart_Write_Msg.Reg_Begin_H = RegAddress >> 8;
+				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; //要写入的字节数
+				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),RX_Buffer[UART_LPUART0], &pReadLen,500);
+				if (pReadLen>0&&RX_Buffer[UART_LPUART0][1] == 0x10)
+				{
+					writecounter = 0;
+					battSeparateEnable = 0;
+				}
+				writecounter++;
+			}
+			if(writecounter>=5)
+			{
+				battSeparateEnable = 0;
+				writecounter = 0;
 			}
 			PROC_UART0_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
 			break;
@@ -77,15 +161,13 @@ void Uart0Task(void *pvParameters)
 		}
 	}
 }
-bool uartBattInfoDecode(uint8 *dataPtr) //根据串口协议确定的解码函数
+bool bmsCellInfoDecode(uint8 *dataPtr) //根据串口协议确定的解码函数,电压电流解码
 {
-	uint8 i = 0, temp = 0;
+	uint8 i = 0;
 	sint8 BattCurrentNegFlag = 1;
-	uint8 TEMP_NUM = 0;
 	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)
@@ -93,7 +175,6 @@ bool uartBattInfoDecode(uint8 *dataPtr) //
 		BATT_CELL_VOL_NUM = AppDataInfo.BattCellCount;
 		BATT_TEMP_NUM = AppDataInfo.BattTempCount;
 	}
-	battWorkState = (dataPtr[(0x03 + BATT_CELL_VOL_NUM) * 2 + 1]) & 0x03; //电池状态(原始数据),0表示静置,1表示放电,2表示充电
 	Batt_current = (dataPtr[(0x02 + BATT_CELL_VOL_NUM) * 2] << 8) | (dataPtr[(0x02 + BATT_CELL_VOL_NUM) * 2 + 1]);
 	//原始数据:充电为负,放电为正
 	if (battWorkState == 0x02) //充电过程
@@ -128,48 +209,123 @@ bool uartBattInfoDecode(uint8 *dataPtr) //
 			BattCurrentNegFlag = 1;
 		}
 	}
-
 	battI = Batt_current * BattCurrentNegFlag + 0x2710;
 	// sint16 BattI_Temp = 0;//做电压补偿需要的参数
 	// BattI_Temp = Batt_current * BattCurrentNegFlag;
 	for (i = 0; i < BATT_CELL_VOL_NUM; i++)
 	{
-		// 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]) + (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;
-	TEMP_NUM = BATT_TEMP_NUM + BmsOtherTemp;
-//	MOSTemp = dataPtr[(0x06 + BATT_CELL_VOL_NUM + BATT_TEMP_NUM) * 2 + 1];
-//	packTemp = dataPtr[(0x06 + BATT_CELL_VOL_NUM + BATT_TEMP_NUM + 1) * 2 + 1];
-	// 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);
+	return true;
+}
+bool bmsOtherInfoDecode(uint8 *dataPtr)//其他数据解析
+{
+	uint8 TEMP_NUM = 0, temp = 0;
 
-	// bmsHwVersion = dataPtr[(0x08 + BATT_CELL_VOL_NUM + TEMP_NUM) * 2 + 1];
-	// bmsSwVersion = dataPtr[(0x08 + BATT_CELL_VOL_NUM + TEMP_NUM) * 2];
+	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 + BATT_CELL_VOL_NUM + TEMP_NUM) * 2 + 1]) >> 1) & 0x03;
+	temp = ((dataPtr[(0x09 + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1]) >> 1) & 0x03;
 	battMOSSwitchState = ((temp & 0x01) << 1) | ((temp & 0x02) >> 1);
-	battWarningState = (dataPtr[(0x09 + BATT_CELL_VOL_NUM + TEMP_NUM) * 2 + 0] << 16) | (dataPtr[(0x0A + BATT_CELL_VOL_NUM + TEMP_NUM) * 2 + 0] << 8) | (dataPtr[(0x0A + BATT_CELL_VOL_NUM + TEMP_NUM) * 2 + 1]);
-	battProtectState = (dataPtr[(0x03 + BATT_CELL_VOL_NUM) * 2 + 0] << 24) | (dataPtr[(0x04 + BATT_CELL_VOL_NUM) * 2 + 0] << 16) | (dataPtr[(0x04 + BATT_CELL_VOL_NUM) * 2 + 1] << 8) | (dataPtr[(0x05 + BATT_CELL_VOL_NUM) * 2 + 1]);
-	battSOC = dataPtr[(0x0B + BATT_CELL_VOL_NUM + TEMP_NUM) * 2 + 1];
-	battSOH = dataPtr[(0x0C + BATT_CELL_VOL_NUM + TEMP_NUM) * 2 + 1];
-	Battdesigncap = (dataPtr[(0x0E + BATT_CELL_VOL_NUM + TEMP_NUM) * 2]) << 24 | (dataPtr[(0x0E + BATT_CELL_VOL_NUM + TEMP_NUM) * 2 + 1]) << 16 | (dataPtr[(0x0F + BATT_CELL_VOL_NUM + TEMP_NUM) * 2]) << 8 | (dataPtr[(0x0F + BATT_CELL_VOL_NUM + TEMP_NUM) * 2 + 1]);
-	battPackVol = ((dataPtr[(0x18 + BATT_CELL_VOL_NUM + TEMP_NUM) * 2]) << 8 | (dataPtr[(0x18 + BATT_CELL_VOL_NUM + TEMP_NUM) * 2 + 1])) / 10; // uint 100mV
-	maxCellVol = (dataPtr[(0x19 + BATT_CELL_VOL_NUM + TEMP_NUM) * 2] << 8) | dataPtr[(0x19 + BATT_CELL_VOL_NUM + TEMP_NUM) * 2 + 1];
-	minCellVol = (dataPtr[(0x1A + BATT_CELL_VOL_NUM + TEMP_NUM) * 2] << 8) | dataPtr[(0x1A + BATT_CELL_VOL_NUM + TEMP_NUM) * 2 + 1];
-	battHeatEnableState = dataPtr[(0x1C + BATT_CELL_VOL_NUM + TEMP_NUM) * 2 + 1] & 0x01;
-
-	maxCellTemp = 0x00;
-	minCellTemp = 0xFF;
-	AvgBattTemp = 0;
-	uint16 SumBattTemp = 0;
-	for (i = 0; i < BATT_TEMP_NUM; i++)
+	if (battSeparateEnableState==1)
+	{
+		battMOSSwitchState = battMOSSwitchState | (0x01 << 2);
+	}
+	else
+	{
+		battMOSSwitchState = battMOSSwitchState | (0x00 << 2);
+	}
+	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);
+	battSeparateEnableState = getbit(dataPtr[(0x1B + OtherInfoAddrOffset + TEMP_NUM) * 2],7);
+	//故障状态映关系(先完成告警状态简单上传)
+	if(getbit(dataPtr[(0x03 + OtherInfoAddrOffset) * 2],0))//电芯电压过高切断告警
+	{
+		ErrorTemp = 81;
+	}
+	if(getbit(dataPtr[(0x03 + OtherInfoAddrOffset) * 2],1))//总压过高切断告警
+	{
+		ErrorTemp = 87;
+	}
+	if(getbit(dataPtr[(0x04 + OtherInfoAddrOffset) * 2 + 1],0))//电芯电压过低切断告警
+	{
+		ErrorTemp = 83;
+	}
+	if(getbit(dataPtr[(0x04 + OtherInfoAddrOffset) * 2 + 1],1))//总压过低切断告警
+	{
+		ErrorTemp = 89;
+	}
+	if(getbit(dataPtr[(0x04 + OtherInfoAddrOffset) * 2],4))//单节温度过高切断
+	{
+		ErrorTemp = 97;
+	}
+	if(getbit(dataPtr[(0x04 + OtherInfoAddrOffset) * 2],5))//单节温度过低切断
+	{
+		ErrorTemp = 99;
+	}
+	if(getbit(dataPtr[(0x05 + OtherInfoAddrOffset) * 2 + 1],1))//放电电流切断
+	{
+		ErrorTemp = 132;
+	}
+	if(getbit(dataPtr[(0x05 + OtherInfoAddrOffset) * 2 + 1],2))//充电电流切断
+	{
+		ErrorTemp = 131;
+	}
+	if(getbit(dataPtr[(0x05 + OtherInfoAddrOffset) * 2 + 1],3))//BTU连接告警
+	{
+		ErrorTemp = 134;
+	}
+	if(getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],0))//单节电压下限告警
+	{
+		ErrorTemp = 84;
+	}
+	if(getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],1))//组电压下限告警
+	{
+		ErrorTemp = 90;
+	}
+	if(getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],2))//单节电压上限告警
+	{
+		ErrorTemp = 82;
+	}
+	if(getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],3))//组单节电压上限告警
+	{
+		ErrorTemp = 88;
+	}
+	if(getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],4))//放电电流告警
+	{
+		ErrorTemp = 135;
+	}
+	if(getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],5))//充电电流告警
+	{
+		ErrorTemp = 136;
+	}
+	if(getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],6))//单节温度上限告警
+	{
+		ErrorTemp = 98;
+	}
+	if(getbit(dataPtr[(0x0A + OtherInfoAddrOffset + TEMP_NUM) * 2 + 1],7))//单节温度下线告警
 	{
-		SumBattTemp = SumBattTemp + battCellTemp[i];
-		maxCellTemp = max(maxCellTemp, battCellTemp[i]);
-		minCellTemp = min(minCellTemp, battCellTemp[i]);
+		ErrorTemp = 100;
 	}
-	AvgBattTemp = (SumBattTemp - maxCellTemp - minCellTemp) / (BATT_TEMP_NUM - 2);
 	return true;
 }
 #endif

+ 14 - 0
src/AppTaskUart0.h

@@ -29,6 +29,7 @@ typedef enum
 {
     PROCESS_UART_STATE_IDLE = 0,
     PROCESS_UART_STATE_READ,
+	PROCESS_UART_STATE_WRITE,
     PROCESS_UART_STATE_SLEEP
 } process_Uart0;
 typedef struct _UartQueryType
@@ -42,5 +43,18 @@ typedef struct _UartQueryType
     uint8 CRC_L;
     uint8 CRC_H;
 } UartQueryType;
+typedef struct _UartWriteMsgType
+{
+	uint8 Bms_Address;
+	uint8 Bms_Funcode;
+	uint8 Reg_Begin_H;
+    uint8 Reg_Begin_L;
+    uint8 Reg_Num_H;
+    uint8 Reg_Num_L;
+    uint8 Data_Count;
+    uint8 Data[2];
+    uint8 CRC_L;
+    uint8 CRC_H;
+} UartWriteMsgType;
 #endif
 #endif /* APPTASKUART0_H_ */

+ 164 - 37
src/AppTaskUart1.c

@@ -38,6 +38,8 @@ sint8 TcpRegisterChkFunc(void);
 void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen);
 void GetUtc8Time(UTC8TimeType *UTC8TimeTcp);
 static void AtcmdTransmit(sint8 CmdIdx, uint8 *SetValuePtr, uint16 SetValueLen, sint8 *retFunc);
+static sint8 tcpipConnectionSend(uint8 TcpConnectId,uint8 * SendDataPtr,uint16 SendDataLen);
+static void TcpDataInfoRecvHandle(uint8 *DataRecv,uint16 DataRecvLen);
 void Uart_4G_Task(void *pvParameters)
 {
 	(void)pvParameters;
@@ -51,6 +53,7 @@ void Uart_4G_Task(void *pvParameters)
 	vTaskDelay(pdMS_TO_TICKS(5000));
 	uint8 pReadLen = 0;
 	InitFunc(); // 4G模块初始化,注:AT同步不通过,没有进行次数判定及跳转
+	uint32 SendTimerCounter = 0;
 	for (;;)
 	{
 		switch (gProcess_Tcp_Task)
@@ -62,10 +65,11 @@ void Uart_4G_Task(void *pvParameters)
 			{
 				PROC_TCP_STATE_SWITCH(PROCESS_TCP_REGCHK);
 			}
-			else if (TimerCounter % 1000 == 0)
+			else if ((TimerCounter -SendTimerCounter)>1000)
 			{
+				SendTimerCounter = TimerCounter;
 				PROC_TCP_STATE_SWITCH(PROCESS_TCP_SEND);
-				Dio_FlipChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3);
+				//Dio_FlipChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3);
 			}
 			else if (TimerCounter % 100 == 0)
 			{
@@ -135,6 +139,12 @@ void Uart_4G_Task(void *pvParameters)
 		}
 		case PROCESS_TCP_RECV: //网络数据接收,100ms空闲状态下即可接收
 		{
+			memset(RX_Buffer[UART_LPUART1],0x00,sizeof(RX_Buffer[UART_LPUART1]));
+			UART_Receive_Data(UART_LPUART1,RX_Buffer[UART_LPUART1],&pReadLen,100);
+			if(pReadLen>0&&SocketId>=0)
+			{
+				TcpDataInfoRecvHandle(RX_Buffer[UART_LPUART1],pReadLen);
+			}
 			PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
 			break;
 		}
@@ -148,10 +158,10 @@ void Uart_4G_Task(void *pvParameters)
 		}
 		case PROCESS_TCP_ERROR: //错误状态
 		{
-			Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_OFF);
-			vTaskDelay(pdMS_TO_TICKS(100));
+//			Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_OFF);
+//			vTaskDelay(pdMS_TO_TICKS(100));
 			PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
-			Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_ON);
+//			Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_ON);
 			break;
 		}
 		}
@@ -162,29 +172,13 @@ sint8 TcpDataSendFunc(sint8 ConnectId)
 	sint8 outValue = -1;
 	uint32 pSendDataAddr = 0;
 	uint16 DataSendLen = 0;
-	sint8 ATRet = -1;
-	uint8 ReadLen = 0;
 	memcpy(TcpbattSN, defaultSn, 17);
 	TcpDataEncode(&pSendDataAddr, &DataSendLen); //数据组包,malloc申请在里面,pSendData指向申请的地址
 	if (DataSendLen == 0)
 	{
 		return 0; //暂时无数据可以发
 	}
-	//数据准备完成,下面开始发送
-	char AtCmdSend[10] = {0};
-	uint8 AtCmdSendTotalLen = 0;
-	sprintf(AtCmdSend, "%d,%d\r\n", ConnectId, DataSendLen); //此处需要优化
-	AtCmdSendTotalLen = mstrlen(AtCmdSend);
-	AtcmdTransmit(AT_SEND, AtCmdSend, AtCmdSendTotalLen, &ATRet);
-	if (ATRet == 0)
-	{
-		memset(RX_Buffer[UART_LPUART1], 0x00, sizeof(RX_Buffer[UART_LPUART1]));
-		UART_Query_Data(UART_LPUART1, UART_LPUART1, (uint8 *)pSendDataAddr, DataSendLen, RX_Buffer[UART_LPUART1], &ReadLen, 1000);
-		if ((uint8 *)strstr((char *)RX_Buffer[UART_LPUART1], (char *)("OK")))
-		{
-			outValue = 0;
-		}
-	}
+	outValue = tcpipConnectionSend(ConnectId,(uint8 *)pSendDataAddr,DataSendLen);//发送函数
 	if (pSendDataAddr != 0)
 	{
 		free((uint8 *)(pSendDataAddr));
@@ -207,7 +201,7 @@ sint8 TcpConnectFunc(sint8 *ConnectId)
 			uint8 ATCmdSendLen = mstrlen(ATCmdSend);
 			uint8 ReadLen = 0;
 			memset(RX_Buffer[UART_LPUART1], 0x00, sizeof(RX_Buffer[UART_LPUART1]));
-			UART_Query_Data(UART_LPUART1, UART_LPUART1, ATCmdSend, ATCmdSendLen, RX_Buffer[UART_LPUART1], &ReadLen, 1000);
+			UART_Query_Data(UART_LPUART1, UART_LPUART1, ATCmdSend, ATCmdSendLen, RX_Buffer[UART_LPUART1], &ReadLen, 100);
 			uint8 *retptr = NULL;
 			if (ReadLen > 0)
 			{
@@ -390,7 +384,7 @@ void InitFunc(void)
 			ATCmdSend = (char *)("ATE0\r\n");
 			ATCmdSendLen = mstrlen(ATCmdSend);
 			memset(RX_Buffer[UART_LPUART1], 0x00, sizeof(RX_Buffer[UART_LPUART1]));
-			UART_Query_Data(UART_LPUART1, UART_LPUART1, ATCmdSend, ATCmdSendLen, RX_Buffer[UART_LPUART1], &ReadLen, 1000);
+			UART_Query_Data(UART_LPUART1, UART_LPUART1, ATCmdSend, ATCmdSendLen, RX_Buffer[UART_LPUART1], &ReadLen, 100);
 			uint8 *retptr = NULL;
 			if (ReadLen > 0)
 			{
@@ -415,7 +409,7 @@ void InitFunc(void)
 			ATCmdSend = (char *)("AT+SIMEI?\r\n");
 			ATCmdSendLen = mstrlen(ATCmdSend);
 			memset(RX_Buffer[UART_LPUART1], 0x00, sizeof(RX_Buffer[UART_LPUART1]));
-			UART_Query_Data(UART_LPUART1, UART_LPUART1, ATCmdSend, ATCmdSendLen, RX_Buffer[UART_LPUART1], &ReadLen, 1000);
+			UART_Query_Data(UART_LPUART1, UART_LPUART1, ATCmdSend, ATCmdSendLen, RX_Buffer[UART_LPUART1], &ReadLen, 100);
 			uint8 *retptr = NULL;
 			if (ReadLen > 0)
 			{
@@ -441,7 +435,7 @@ void InitFunc(void)
 			ATCmdSend = (char *)("AT+CTZU=1\r\n");
 			ATCmdSendLen = mstrlen(ATCmdSend);
 			memset(RX_Buffer[UART_LPUART1], 0x00, sizeof(RX_Buffer[UART_LPUART1]));
-			UART_Query_Data(UART_LPUART1, UART_LPUART1, ATCmdSend, ATCmdSendLen, RX_Buffer[UART_LPUART1], &ReadLen, 1000);
+			UART_Query_Data(UART_LPUART1, UART_LPUART1, ATCmdSend, ATCmdSendLen, RX_Buffer[UART_LPUART1], &ReadLen, 100);
 			uint8 *retptr = NULL;
 			if (ReadLen > 0)
 			{
@@ -499,7 +493,7 @@ static void AtcmdTransmit(sint8 CmdIdx, uint8 *SetValuePtr, uint16 SetValueLen,
 	}
 	memset(RX_Buffer[UART_LPUART1], 0x00, sizeof(RX_Buffer[UART_LPUART1]));
 
-	UART_Query_Data(UART_LPUART1, UART_LPUART1, PtrATCmdSend, ATCmdTotalLen, RX_Buffer[UART_LPUART1], &ReadLen, 1000);
+	UART_Query_Data(UART_LPUART1, UART_LPUART1, PtrATCmdSend, ATCmdTotalLen, RX_Buffer[UART_LPUART1], &ReadLen, 100);
 
 	*retFunc = Atcmdfunc[CmdIdx].cb(PtrATCmdSend, RX_Buffer[UART_LPUART1], CmdIdx, ReadLen);
 	if (PtrATCmdSend != NULL)
@@ -649,10 +643,14 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 		DataIdx = VerMsg; //版本信息发送
 	}
 #ifdef APP_UART0_ENABLE
-	else if (TcpSendTimeCounter % 60 == 0)
+	else if (TcpSendTimeCounter % 10 == 0)
 	{
 		DataIdx = BattMsg; //电池信息发送
 	}
+	else if ((TcpSendTimeCounter+1) % 10 == 0)
+	{
+		DataIdx = 0x83; //储能开关信息发送
+	}
 	else if (TcpSendTimeCounter % 240 == 0)
 	{
 		DataIdx = GpsMsg; //定位信息发送
@@ -786,12 +784,12 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 		VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[5] = UTC8TimeTcp.second & 0xFF;
 		memcpy(VerMsgToTcpInfo.VerInfo.ICCID, IccidNum, 20);
 		memcpy(VerMsgToTcpInfo.VerInfo.IMEI, ImeiNum, 15);
-		VerMsgToTcpInfo.VerInfo.BMSHwVersion[0] = 0;
-		VerMsgToTcpInfo.VerInfo.BMSHwVersion[1] = 0;
-		VerMsgToTcpInfo.VerInfo.BMSSwVersion[0] = 0;
-		VerMsgToTcpInfo.VerInfo.BMSSwVersion[1] = 0;
-		VerMsgToTcpInfo.VerInfo.BMSSwVersion[2] = 0;
-		VerMsgToTcpInfo.VerInfo.BMSSwVersion[3] = 0;
+		VerMsgToTcpInfo.VerInfo.BMSHwVersion[0] = bmsHwVersion>>8;
+		VerMsgToTcpInfo.VerInfo.BMSHwVersion[1] = bmsHwVersion;
+		VerMsgToTcpInfo.VerInfo.BMSSwVersion[0] = bmsSwVersion>>24;
+		VerMsgToTcpInfo.VerInfo.BMSSwVersion[1] = bmsSwVersion>>16;
+		VerMsgToTcpInfo.VerInfo.BMSSwVersion[2] = bmsSwVersion>>8;
+		VerMsgToTcpInfo.VerInfo.BMSSwVersion[3] = bmsSwVersion;
 		VerMsgToTcpInfo.VerInfo.HwVersion[0] = (HWVERSION >> 8) & 0xFF;
 		VerMsgToTcpInfo.VerInfo.HwVersion[1] = (HWVERSION)&0xFF;
 		VerMsgToTcpInfo.VerInfo.BLVersion[0] = (BLSWVERSION >> 24) & 0xFF;
@@ -875,7 +873,7 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 		*(SendBuffer + 55 + AppDataInfo.BattCellCount * 2) = AppDataInfo.BattTempCount;							   //模组温度个数
 		memcpy((SendBuffer + 55 + AppDataInfo.BattCellCount * 2 + 1), &battCellTemp, AppDataInfo.BattTempCount);   //模组温度
 		*(SendBuffer + 56 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount) = battWorkState;			   //电池工作状态
-		*(SendBuffer + 57 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount) = battHeatEnableState;	   //电池加热使能
+		*(SendBuffer + 57 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount) = battHeatEnableState;	   //电池加热使能状态
 		*(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount) = BmsOtherTemp + OtherTemp; //其他温度个数
 		// *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 1) = MOSTemp;																						  // mos温度
 		// *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 2) = packTemp;																						  //环境温度
@@ -884,7 +882,45 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 		// *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 5) = heatTemp1;																						  //加热温度1
 		// *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 6) = heatTemp2;																						  //加热温度2
 		*(SendBuffer + 59 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + BmsOtherTemp + OtherTemp) = bcc_chk(SendBuffer, ProtocolFixedLen + ProtocolFluctedLen - 1); //校验码
-		PtrSendAddr = (uint32)SendBuffer;
+		*PtrSendAddr = (uint32)SendBuffer;
+		break;
+	}
+	case 0x83://储能场景的开关信息
+	{
+		StorageInfoToTcp StorageInfo;
+		*SendLen = sizeof(StorageInfo);
+		SendBuffer = malloc(*SendLen);
+		uint16 DataLen = 0;
+		DataLen = (uint16)sizeof(StorageInfo.StorageMsg);
+		StorageInfo.startSymbol[0] = TCP_START_SYM1;
+		StorageInfo.startSymbol[1] = TCP_START_SYM2;
+		StorageInfo.cmdSymbol = TCP_CMD_SYM;
+		StorageInfo.ansSymbol = TCP_ANS_SYM;
+		memcpy(StorageInfo.SN, TcpbattSN, BATT_SN_LEN);
+		StorageInfo.encryptMethod = TCP_ENCPT_DISABLE; // not encrypt
+		StorageInfo.dataLength[0] = (DataLen >> 8) & 0xFF;
+		StorageInfo.dataLength[1] = DataLen & 0xFF;
+		StorageInfo.StorageMsg.sendTimeUTC[0] = (UTC8TimeTcp.year) & 0xFF; // year
+		StorageInfo.StorageMsg.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF;	// month
+		StorageInfo.StorageMsg.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF;	// day
+		StorageInfo.StorageMsg.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;	// hour
+		StorageInfo.StorageMsg.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; // mins
+		StorageInfo.StorageMsg.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF; // sec
+		StorageInfo.StorageMsg.msgMark = DataIdx;
+		StorageInfo.StorageMsg.msgCollectionTimeUTC[0] = (UTC8TimeTcp.year) & 0xFF; // year
+		StorageInfo.StorageMsg.msgCollectionTimeUTC[1] = UTC8TimeTcp.month & 0xFF;	 // month
+		StorageInfo.StorageMsg.msgCollectionTimeUTC[2] = UTC8TimeTcp.day & 0xFF;	 // day
+		StorageInfo.StorageMsg.msgCollectionTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;	 // hour
+		StorageInfo.StorageMsg.msgCollectionTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; // mins
+		StorageInfo.StorageMsg.msgCollectionTimeUTC[5] = UTC8TimeTcp.second & 0xFF;
+		StorageInfo.StorageMsg.RelayState = battRelayState;
+		StorageInfo.StorageMsg.FanState = battFanState;
+		StorageInfo.StorageMsg.HeatState = battHeatState;
+		StorageInfo.StorageMsg.ConvertState = battConverState;
+		StorageInfo.CRC = bcc_chk((uint8 *)&StorageInfo, sizeof(StorageInfo) - 1);
+		memcpy(SendBuffer, &StorageInfo, sizeof(StorageInfo));
+		*PtrSendAddr = (uint32)SendBuffer;
+		break;
 	}
 #endif
 #ifdef APP_CAN_ENABLE
@@ -1092,7 +1128,7 @@ void GetUtc8Time(UTC8TimeType *UTC8TimeTcp)
 	uint8 ReadLen = 0;
 	uint8 *retptr = NULL;
 	memset(RX_Buffer[UART_LPUART1], 0x00, sizeof(RX_Buffer[UART_LPUART1]));
-	UART_Query_Data(UART_LPUART1, UART_LPUART1, AtCmdAsk, AtCmdLen, RX_Buffer[UART_LPUART1], &ReadLen, 1000 * 10);
+	UART_Query_Data(UART_LPUART1, UART_LPUART1, AtCmdAsk, AtCmdLen, RX_Buffer[UART_LPUART1], &ReadLen, 100);
 	if (ReadLen > 0)
 	{
 		if ((uint8 *)strstr((char *)RX_Buffer[UART_LPUART1], (char *)("OK")))
@@ -1107,3 +1143,94 @@ void GetUtc8Time(UTC8TimeType *UTC8TimeTcp)
 		}
 	}
 }
+static void TcpDataInfoRecvHandle(uint8 *DataRecv,uint16 DataRecvLen)
+{
+    uint8 Tcp_Cmd;
+    uint8 *Ptr=NULL,*retptr=NULL;
+    uint8 TcpCmdAnswer[31];
+    uint16 TcpDataLen = 0;
+    uint16 NumCalTemp = 1;
+    retptr = (uint8 *)strstr((char *)DataRecv, (char *)("\r\n##"));
+    if(retptr==NULL)return;
+    for(uint8 i=0;i<5;i++)
+    {
+    	if(*(retptr - i - 1)=='D')
+		{
+			break;
+		}
+    	TcpDataLen = TcpDataLen + CharToHex(*(retptr - i - 1))*NumCalTemp;
+    	NumCalTemp = NumCalTemp*10;
+    }
+    if (TcpDataLen>0)
+    {
+        Ptr = retptr + 2;
+        if ((*(Ptr + 0) == TCP_START_SYM1) && (*(Ptr + 1) == TCP_START_SYM2)) //服务器起始信息
+        {
+            Tcp_Cmd = *(Ptr + 2); //命令标志
+//            if (*(Ptr + 3) == 0xFE)
+//            {
+//                TCPWorkState = 0x01;//需要暂停发送,进行命令应答的标志
+//            }
+            switch (Tcp_Cmd)
+            {
+            case TCP_QUERY_SYM:
+                break;
+            case TCP_SETCMD_SYM:
+                break;
+            case TCP_CONCMD_SYM:
+            {
+                TcpCmdAnswer[0] = TCP_START_SYM1;
+                TcpCmdAnswer[1] = TCP_START_SYM1;
+                TcpCmdAnswer[2] = TCP_CONCMD_SYM;
+                if (*(Ptr + 30) == 0x80) //远程锁定命令
+                {
+                    TcpCmdAnswer[3] = 0x01;
+                    memcpy(&TcpCmdAnswer[4], (Ptr + 4), BATT_SN_LEN);
+                    TcpCmdAnswer[21] = TCP_ENCPT_DISABLE;
+                    TcpCmdAnswer[22] = 0x00;
+                    TcpCmdAnswer[23] = 0x06;
+                    memcpy(&TcpCmdAnswer[24], (Ptr + 24), 6);
+                    TcpCmdAnswer[30] = bcc_chk(TcpCmdAnswer, 30);
+                    if (*(Ptr + 31) == 0x01) // 0x01代表锁定
+                    {
+                    	battSeparateEnable = 1;
+                    	battSeparateEnableState = 1;
+                        tcpipConnectionSend(SocketId, TcpCmdAnswer, 31 );
+                    }
+                    else if (*(Ptr + 31) == 0x02) // 0x02代表解锁
+                    {
+                    	battSeparateEnable = 1;
+                    	battSeparateEnableState = 0;
+                        tcpipConnectionSend(SocketId, TcpCmdAnswer, 31);
+                    }
+                }
+            }
+            default:
+            {
+                break;
+            }
+            }
+        }
+    }
+}
+static sint8 tcpipConnectionSend(uint8 TcpConnectId,uint8 * SendDataPtr,uint16 SendDataLen)
+{
+	sint8 outValue = -1;
+	sint8 ATRet = -1;
+	uint8 ReadLen = 0;
+	char AtCmdSend[10] = {0};
+	uint8 AtCmdSendTotalLen = 0;
+	sprintf(AtCmdSend, "%d,%d\r\n", TcpConnectId, SendDataLen);
+	AtCmdSendTotalLen = mstrlen(AtCmdSend);
+	AtcmdTransmit(AT_SEND, AtCmdSend, AtCmdSendTotalLen, &ATRet);
+	if (ATRet == 0)
+	{
+		memset(RX_Buffer[UART_LPUART1], 0x00, sizeof(RX_Buffer[UART_LPUART1]));
+		UART_Query_Data(UART_LPUART1, UART_LPUART1, (uint8 *)SendDataPtr, SendDataLen, RX_Buffer[UART_LPUART1], &ReadLen, 100);
+		if ((uint8 *)strstr((char *)RX_Buffer[UART_LPUART1], (char *)("OK")))
+		{
+			outValue = 0;
+		}
+	}
+	return outValue;
+}

+ 24 - 0
src/AppTaskUart1.h

@@ -35,6 +35,9 @@
 #define TruckBattMsg (0x91)
 #define TruckVehiMsg (0x90)
 #define TruckAcclMsg (0x92)
+#define TCP_QUERY_SYM 0x80
+#define TCP_SETCMD_SYM 0x81
+#define TCP_CONCMD_SYM 0x82
 typedef struct _GPSInfoType
 {
 	uint8 sendTimeUTC[6];
@@ -86,6 +89,27 @@ typedef struct VersionMsgtoTcpType
 	VerInfoType VerInfo;
 	uint8	CRC;
 }VersionMsgtoTcpType;
+typedef struct StorageInfoType
+{
+	uint8	sendTimeUTC[6];
+	uint8	msgMark;
+	uint8	msgCollectionTimeUTC[6];
+	uint8 	RelayState;
+	uint8   FanState;
+	uint8	HeatState;
+	uint8 	ConvertState;
+}StorageInfo;
+typedef struct StorageInfoToTcpType
+{
+	uint8 	startSymbol[2];
+	uint8	cmdSymbol;
+	uint8	ansSymbol;
+	uint8	SN[BATT_SN_LEN];
+	uint8	encryptMethod;
+	uint8	dataLength[2];
+	StorageInfo StorageMsg;
+	uint8	CRC;
+}StorageInfoToTcp;
 typedef struct UTC8Time_Type
 {
     uint8 year;

+ 18 - 17
src/hal_adapter.c

@@ -45,15 +45,6 @@
 		 return retVal;
 	 }
 
-	 Uart_SetBuffer(recvChannel, &RX_Buffer[recvChannel][0], DMA_SIZE, UART_RECEIVE);
-	 R_Uart_Status = Uart_AsyncReceive(recvChannel, rxBuffer, DMA_SIZE);
-	 if (E_OK != R_Uart_Status)
-	 {
-		 Uart_Abort(recvChannel, UART_RECEIVE);
-		 return E_NOT_OK;
-	 }
-
-
 	 /* Uart_AsyncSend transmit data */
 	 Uart_SetBuffer(transChannel, txBuffer, sendLength, UART_SEND);
 	 T_Uart_Status = Uart_AsyncSend(transChannel, txBuffer, sendLength);
@@ -62,10 +53,13 @@
 		 Uart_Abort(transChannel, UART_SEND);
 		 return E_NOT_OK;
 	 }
-
-
-
-
+	 Uart_SetBuffer(recvChannel, &RX_Buffer[recvChannel][0], DMA_SIZE, UART_RECEIVE);
+	 R_Uart_Status = Uart_AsyncReceive(recvChannel, rxBuffer, DMA_SIZE);
+	 if (E_OK != R_Uart_Status)
+	 {
+		 Uart_Abort(recvChannel, UART_RECEIVE);
+		 return E_NOT_OK;
+	 }
 	 /* Check for no on-going transmission */
 //	 Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2, STD_ON);
 	 do
@@ -96,11 +90,11 @@
 	 {
 		 retVal = E_OK;
 	 }
-
 	 if ((UART_STATUS_NO_ERROR != Uart_ReceiveStatus))
 	 {
 		 Uart_Abort(recvChannel, UART_RECEIVE);
-		 //    	IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
+		 *rxlen = bufferIdx[recvChannel];
+		 //IP_LPUART0->CTRL |= LPUART_CTRL_ILIE(1);
 		 retVal = E_NOT_OK;
 	 }
 	 else
@@ -199,7 +193,7 @@
      if ((UART_STATUS_NO_ERROR != Uart_ReceiveStatus))
      {
          Uart_Abort(recvChannel, UART_RECEIVE);
-         *rxlen = 0;
+         *rxlen = bufferIdx[recvChannel];
          retVal = E_NOT_OK;
      }
      else
@@ -209,6 +203,7 @@
      }
      return retVal;
  }
+ extern Lpuart_Uart_Ip_StateStructureType * Lpuart_Uart_Ip_apStateStructuresArray[LPUART_UART_IP_NUMBER_OF_INSTANCES];
  void UART_Callback(uint32 hwInstance, Lpuart_Uart_Ip_EventType event )
  {
  //    (void)userData;
@@ -233,6 +228,7 @@
 //     	bufferIdx[hwInstance] += temp;
          /*Abort the receiving after detecting IDLE receiving*/
      	Lpuart_Uart_Ip_AbortReceivingData(hwInstance);
+     	Lpuart_Uart_Ip_AbortSendingData(hwInstance);
  //    	bufferIdx = 0;
      }
      if( event == LPUART_UART_IP_EVENT_RECV_IDLE)
@@ -242,7 +238,12 @@
  		/*Add the remaining data size to the sum of the received size*/
  		bufferIdx[hwInstance] += temp;
  		/*Abort the receiving after detecting IDLE receiving*/
- 		Lpuart_Uart_Ip_AbortReceivingData(hwInstance);
+
+ 		Lpuart_Uart_Ip_StateStructureType * UartState;
+ 		UartState = (Lpuart_Uart_Ip_StateStructureType *)Lpuart_Uart_Ip_apStateStructuresArray[hwInstance];
+ 		UartState->IsRxBusy = FALSE;
+ 		UartState->ReceiveStatus = LPUART_UART_IP_STATUS_SUCCESS;
+ 		Lpuart_Uart_Ip_CompleteReceiveUsingDma(hwInstance);
  //		rxSuccess = true;
      }
  }

+ 3 - 1
src/hal_adapter.h

@@ -43,7 +43,9 @@
 #ifndef max
 #define max(A,B) ((A) < (B) ? (B) : (A))
 #endif
-
+#define getbit(x,y)     ((x) >> (y)&1)                        //获取x的第y位的数值
+#define setbit(x,y)     x|=(1<<y)                             //x的第y位置1
+#define clrbit(x,y)     x&=~(1<<y)                            //x的第y位置0
  #define UART_LPUART0 0
  #define UART_LPUART1 1
  #define UART_LPUART2 2