Bladeren bron

串口测试暂存

CHENJIE-PC\QiXiang_CHENJIE 3 jaren geleden
bovenliggende
commit
e6c924cf12

+ 2 - 1
.gitignore

@@ -1 +1,2 @@
-Debug_FLASH/
+Debug_FLASH/
+.settings/

+ 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="50541842775723316" 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="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">
 				<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="50541842775723316" 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="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">
 				<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="50541842775723316" 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="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">
 				<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="50541842775723316" 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="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">
 				<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="0x1fff01d2,0x1fff01d0,0x1fff01c0,0x1fff4b00,0x1fff4b51,0x1fff4b56,0x1fff0290,0x1fff4894,0x1fff04e8,0x1fff01c8,0x1fff2ce8,0x1fff0100,0x1fff08d0,0x1fff4b48,0x1fff4b50"/>
+<stringAttribute key="saved_expressions&lt;seperator&gt;Unknown" value="0x1fff01d0,0x1fff01c0,0x1fff4b00,0x1fff4b51,0x1fff4b56,0x1fff0290,0x1fff4894,0x1fff04e8,0x1fff01c8,0x1fff2ce8,0x1fff0100,0x1fff08d0,0x1fff4b48,0x1fff4b50,0x1fff0103"/>
 </launchConfiguration>

+ 21 - 0
src/AppFuncLib.c

@@ -365,3 +365,24 @@ uint8 bcc_chk(uint8 *data, uint16 length)
     }
     return bcc_chk_return;
 }
+uint16 crc_chk(uint8 *data, uint8 length)
+{
+	uint8 j;
+	uint16 reg_crc = 0xFFFF;
+	while (length--)
+	{
+		reg_crc ^= *data++;
+		for (j = 0; j < 8; j++)
+		{
+			if (reg_crc & 0x01)
+			{
+				reg_crc = (reg_crc >> 1) ^ 0xA001;
+			}
+			else
+			{
+				reg_crc = reg_crc >> 1;
+			}
+		}
+	}
+	return reg_crc;
+}

+ 2 - 0
src/AppFuncLib.h

@@ -44,4 +44,6 @@ int __ftoa(double val, char buf[32], int eps);
 
 // Ìæ´úsprintf
 int _sprintf(char *dst, const char *format, ...);
+//´®¿ÚУÑé
+uint16 crc_chk(uint8 *data, uint8 length);
 #endif /* APPFUNCLIB_H_ */

+ 44 - 14
src/AppGlobalVar.c

@@ -3,7 +3,7 @@
  * @Date         : 2022-01-23 13:45:09
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2022-02-11 11:34:32
+ * @LastEditTime : 2022-02-23 16:59:13
  * @Description  : file content
  * @FilePath     : \S32K146_4G\src\AppGlobalVar.c
  */
@@ -17,31 +17,60 @@
 #include "AppGlobalVar.h"
 //测试
 
-
 //*全局变量*//
-char ImeiNum[15] = {0};
-char IccidNum[20] = {0};
-uint8 CSQValue = 0;
-sint8 SocketId = -1;
-char WebSiteIp[15] = {0};
-uint8 TcpbattSN[17] = {0x31};//上传的SN编号
+uint8 TcpbattSN[17] = {0x31}; //上传的SN编号
 uint8 VIN[17] = {0};
-volatile uint32 TimerCounter = 0;//ms单位
-//gps
+volatile uint32 TimerCounter = 0; // ms单位
+/*GPS*/
 QueueHandle_t GpsDataQueueHandle;
 sint16 xyzData[3] = {0};
-/*Can*/
+/*Hal_Can*/
 uint8 CanIf_u8TxConfirmCnt = 0U;
 boolean CanIf_bTxFlag = false;
 uint8 CanIf_u8RxIndicationCnt = 0U;
 boolean CanIf_bRxFlag = false;
 QueueHandle_t CanRecvQueueHandle;
 
-// Const 变量
+/*TCP相关变量*/
+char ImeiNum[15] = {0};
+char IccidNum[20] = {0};
+uint8 CSQValue = 0;
+sint8 SocketId = -1;
+char WebSiteIp[15] = {0};
 const char WebSiteName[] = "\"iotp.fast-fun.cn\"";
 const uint16 WebSitePort = 8712;
 
-//Vcu相关
+/*以下变量均为串口协议相关变量*/
+#ifdef APP_UART0_ENABLE
+AppDataBody AppDataInfo = {BMS_CELLNUM, BMS_TEMPNUM};
+uint16 avrgCellVol = 0;			 //平均电压
+uint16 battCellU[BMS_CELLNUM];	 //电池电压
+uint16 battI = 0;				 // BMS电流(tcp上传)
+uint16 battPackVol = 0;			 // bms电压
+uint16 ErrorTemp = 0x0000;		 // BMS故障代码
+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 battProtectState = 0;	 // bms保护状态
+uint32 battWarningState = 0;	 // bms告警状态
+uint8 AvgBattTemp = 0;			 //平均单体温度
+uint8 battCellTemp[BMS_TEMPNUM]; //电池温度
+uint8 Battdesigncap = 0;		 //电池包设计容量
+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 maxCellTemp = 0;			 //最大单体温度
+uint8 minCellTemp = 0;			 //最小单体温度
+uint8 OtherTemp = 0;			 //通讯模块其他温度
+#endif
+/*以下变量均为App_CAN相关变量*/
+#ifdef APP_CAN_ENABLE
+// VCU相关
 uint8 vehicleStatus = 0;
 uint8 bmsHVOn = 0;
 uint8 currentGearPosition = 0;
@@ -59,7 +88,7 @@ uint8 dischargeLockSignal = 0;
 uint8 chargeLockSignal = 0;
 uint8 chargeFlag = 0;
 uint16 vcuDCVol = 0;
-//Bcu相关
+// Bcu相关
 uint32 BcuInTable[130] = {
 	0x1801EFF4,
 	0x1801FBF4,
@@ -377,3 +406,4 @@ uint32 BMS18_TotalPoleChargeAh = 0x00;			   //
 uint32 BMS18_TotalPoleChargeKwh = 0x00;			   //累计插枪充电充入kWh 数 精度_0.1,偏移量_0,单位_KWh
 uint32 BMS19_SingleChargeAh = 0x00;				   //单次充电Ah 数 精度_0.1,偏移量_0,单位_Ah
 uint32 BMS19_SingleChargeKwh = 0x00;			   //单次充电kWh 数 精度_0.1,偏移量_0,单位_KWh
+#endif

+ 67 - 27
src/AppGlobalVar.h

@@ -3,7 +3,7 @@
  * @Date         : 2022-01-23 13:45:09
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2022-02-11 11:03:59
+ * @LastEditTime : 2022-02-23 17:02:37
  * @Description  : file content
  * @FilePath     : \S32K146_4G\src\AppGlobalVar.h
  */
@@ -16,8 +16,11 @@
 #ifndef APPGLOBALVAR_H_
 #define APPGLOBALVAR_H_
 
+#define APP_UART0_ENABLE //平峰项目
+//#define APP_CAN_ENABLE //重卡项目
+
 #include "hal_adapter.h"
-//test Var
+// test Var
 #define defaultSn "GYTEST00000000001"
 
 #define HWVERSION 0x0001
@@ -28,11 +31,7 @@
 #define BMS_INFO 0xFF
 #define DATA_MODULE_TYPE 0x02
 //*全局变量*//
-extern char ImeiNum[15];
-extern char IccidNum[20];
-extern uint8 CSQValue;
-extern sint8 SocketId;
-extern char WebSiteIp[15];
+
 extern uint8 TcpbattSN[17];
 extern uint8 VIN[17];
 extern volatile uint32 TimerCounter;
@@ -41,38 +40,79 @@ typedef struct
     uint8 RealLen;
     uint8 *DataPtr;
 } QueueDataTrans_Type;
-//gps
+/*GPS*/
 extern QueueHandle_t GpsDataQueueHandle;
 extern sint16 xyzData[3];
-/*Can*/
+/*Hal_Can*/
 extern uint8 CanIf_u8TxConfirmCnt;
 extern boolean CanIf_bTxFlag;
 extern uint8 CanIf_u8RxIndicationCnt;
 extern boolean CanIf_bRxFlag;
 extern QueueHandle_t CanRecvQueueHandle;
 
+/*以下变量均为TCP相关变量*/
+extern uint8 CSQValue;
+extern sint8 SocketId;
+extern char WebSiteIp[15];
 extern const char WebSiteName[];
 extern const uint16 WebSitePort;
-
-//VCU相关
+extern char ImeiNum[15];
+extern char IccidNum[20];
+/*以下变量均为串口协议相关变量*/
+#ifdef APP_UART0_ENABLE
+#define BMS_CELLNUM 120
+#define BMS_TEMPNUM 80
+typedef struct _AppDataType
+{
+    uint8 BattCellCount; //电池模组个数
+    uint8 BattTempCount; //电池温度个数
+} AppDataBody;
+extern AppDataBody AppDataInfo;
+extern uint16 avrgCellVol;              //平均电压
+extern uint16 battCellU[BMS_CELLNUM];   //电池电压
+extern uint16 battI;                    // BMS电流(tcp上传)
+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 battProtectState;         // bms保护状态
+extern uint32 battWarningState;         // bms告警状态
+extern uint8 AvgBattTemp;               //平均单体温度
+extern uint8 battCellTemp[BMS_TEMPNUM]; //电池温度
+extern uint8 Battdesigncap;             //电池包设计容量
+extern uint8 battHeatEnableState;       // bms加热使能状态
+extern uint8 battMOSSwitchState;        // bms mos开关状态
+extern uint8 battSOC;                   // bms发送soc
+extern uint8 battSOH;                   // bms发送soh
+extern uint8 battWorkState;             // bms工作状态
+extern uint8 BmsOtherTemp;              // BMS其他温度
+extern uint8 maxCellTemp;               //最大单体温度
+extern uint8 minCellTemp;               //最小单体温度
+extern uint8 OtherTemp;                 //通讯模块其他温度
+#endif
+/*以下变量均为App_CAN相关变量*/
+#ifdef APP_CAN_ENABLE
 extern uint8 vehicleStatus;
-extern uint8 bmsHVOn ;
+extern uint8 bmsHVOn;
 extern uint8 currentGearPosition;
-extern uint8 parkingBreakStatus ;
-extern uint8 breakingStatus ;
-extern uint32 ODO ;
-extern uint8 dcdcWorkStatus ;
+extern uint8 parkingBreakStatus;
+extern uint8 breakingStatus;
+extern uint32 ODO;
+extern uint8 dcdcWorkStatus;
 extern uint8 numOfChrgableSubsys;
-extern uint8 chrgableSubsysCode ;
-extern uint8 ebcStatus ;
-extern uint8 ebcAskHVOn ;
-extern uint8 ebcAskHVOff ;
-extern uint8 retainLockSignal ;
-extern uint8 dischargeLockSignal ;
-extern uint8 chargeLockSignal ;
-extern uint8 chargeFlag ;
-extern uint16 vcuDCVol ;
-//BCU解码变量
+extern uint8 chrgableSubsysCode;
+extern uint8 ebcStatus;
+extern uint8 ebcAskHVOn;
+extern uint8 ebcAskHVOff;
+extern uint8 retainLockSignal;
+extern uint8 dischargeLockSignal;
+extern uint8 chargeLockSignal;
+extern uint8 chargeFlag;
+extern uint16 vcuDCVol;
+// BCU解码变量
 extern uint32 BcuInTable[130];
 extern bool BcuRxShortError[130];
 extern bool BcuRxLongError[130];
@@ -256,5 +296,5 @@ extern uint32 BMS18_TotalPoleChargeAh;
 extern uint32 BMS18_TotalPoleChargeKwh;
 extern uint32 BMS19_SingleChargeAh;
 extern uint32 BMS19_SingleChargeKwh;
-
+#endif
 #endif /* APPGLOBALVAR_H_ */

+ 4 - 14
src/AppTaskCan.c

@@ -5,16 +5,13 @@
  *      Author: QiXiang_CHENJIE
  */
 #include "AppTaskCan.h"
-static void vTimerCallback(TimerHandle_t pxTimer);
+#ifdef APP_CAN_ENABLE
 void CanTask(void *pvParameters)
 {
-	TimerHandle_t monitorTimer;
-	monitorTimer = xTimerCreate("monitor",10,pdTRUE,(void *)0,vTimerCallback);
 	(void)pvParameters;
 	CanIf_bRxFlag = false;
 	Can_Msg_Type CanRxMsg;
 	CanRecvQueueHandle = xQueueCreate(5, sizeof(Can_Msg_Type));
-	xTimerStart(monitorTimer,0);
 	while(1)
 	{
 		memset(&CanRxMsg, 0, sizeof(CanRxMsg));
@@ -30,15 +27,7 @@ void CanTask(void *pvParameters)
 		}
 	}
 }
-static void vTimerCallback(TimerHandle_t pxTimer)
-{
-	uint32 ulTimerID;
-	ulTimerID = (uint32)pvTimerGetTimerID(pxTimer);
-	if(ulTimerID==0)
-	{
-		TimerCounter = TimerCounter + 10;
-	}
-}
+//×¢Òâ½âÂ볬ÏÞÎÊÌâ
 void BcuDecodeFunction(uint32 ID, uint8 *rawData)
 {
 	switch (ID)
@@ -800,7 +789,7 @@ void BcuDecodeFunction(uint32 ID, uint8 *rawData)
 		BMS1_ChrgStatus = (uint8)(((*(uint8 *)(rawData + 5)) >> 1) & 0x3);
 		BMS1_HeatingStatus = (uint8)(((*(uint8 *)(rawData + 5)) >> 3) & 0x1);
 		BMS1_CoolingStatus = (uint8)(((*(uint8 *)(rawData + 5)) >> 4) & 0x3);
-		BMS1_RechrgCycels = (uint32)(((*(uint32 *)(rawData + 5)) >> 6) & 0x3FFFF);
+		BMS1_RechrgCycels = (uint32)((*(rawData + 5) >> 6)|(*(rawData + 6)<<2)|(*(rawData + 7)<<10));
 		BcuRxFlag[99] = 0x01;
 		break;
 	case 0x1884EFF4:
@@ -2405,3 +2394,4 @@ void BcuRxMsgSetInvalidValue(uint32 ID)
 		break;
 	}
 }
+#endif

+ 4 - 0
src/AppTaskCan.h

@@ -7,6 +7,8 @@
 
 #ifndef APPTASKCAN_H_
 #define APPTASKCAN_H_
+
+#ifdef APP_CAN_ENABLE
 #include "hal_adapter.h"
 #include "AppGlobalVar.h"
 #include "AppFuncLib.h"
@@ -14,4 +16,6 @@ void BcuDecodeFunction(uint32 ID, uint8 *rawData);
 void BcuRxDiagnose(void);
 void BcuRxMsgSetInvalidValue(uint32 ID);
 void CanTask(void *pvParameters);
+#endif
+
 #endif /* APPTASKCAN_H_ */

+ 29 - 0
src/AppTaskMain.c

@@ -0,0 +1,29 @@
+/*
+ * AppTaskMain.c
+ *
+ *  Created on: 2022Äê2ÔÂ22ÈÕ
+ *      Author: QiXiang_CHENJIE
+ */
+
+#include "AppTaskMain.h"
+static void vTimerCallback(TimerHandle_t pxTimer);
+void MainTask(void *pvParameters)
+{
+	(void)pvParameters;
+	TimerHandle_t monitorTimer;
+	monitorTimer = xTimerCreate("monitor",10,pdTRUE,(void *)0,vTimerCallback);
+	xTimerStart(monitorTimer,0);
+	while(1)
+	{
+		vTaskDelay(pdMS_TO_TICKS(100));
+	}
+}
+static void vTimerCallback(TimerHandle_t pxTimer)
+{
+	uint32 ulTimerID;
+	ulTimerID = (uint32)pvTimerGetTimerID(pxTimer);
+	if(ulTimerID==0)
+	{
+		TimerCounter = TimerCounter + 10;
+	}
+}

+ 15 - 0
src/AppTaskMain.h

@@ -0,0 +1,15 @@
+/*
+ * AppTaskMain.h
+ *
+ *  Created on: 2022Äê2ÔÂ22ÈÕ
+ *      Author: QiXiang_CHENJIE
+ */
+
+#ifndef APPTASKMAIN_H_
+#define APPTASKMAIN_H_
+#include "hal_adapter.h"
+#include "AppFunclib.h"
+#include "AppGlobalVar.h"
+void MainTask(void *pvParameters);
+
+#endif /* APPTASKMAIN_H_ */

+ 175 - 0
src/AppTaskUart0.c

@@ -0,0 +1,175 @@
+/*
+ * AppTaskUart0.c
+ *
+ *  Created on: 2022年2月22日
+ *      Author: QiXiang_CHENJIE
+ */
+#include "AppTaskUart0.h"
+#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);
+void Uart0Task(void *pvParameters)
+{
+	(void)pvParameters;
+	UartQueryType Uart0AskMsg;
+	uint16 Reg_Num = 0;
+	uint16 CRC_chk_buffer = 0;
+	uint16 pReadLen = 0;
+	UartAnsType UartAnsData;
+	while (1)
+	{
+		switch (gProcess_Uart0_Task)
+		{
+		case PROCESS_UART_STATE_IDLE:
+		{
+			vTaskDelay(pdMS_TO_TICKS(10));
+			if (TimerCounter % 1000 == 0)
+			{
+				PROC_UART0_STATE_SWITCH(PROCESS_UART_STATE_READ);
+			}
+			break;
+		}
+		case PROCESS_UART_STATE_READ:
+		{
+			/*电压电流数据读取*/
+
+
+			/*电流及状态的读取*/
+			Reg_Num = 0x40; //读取的寄存器数据,暂定,分开读取
+			Uart0AskMsg.Bms_Address = BMS_ADDRESS_CODE;
+			Uart0AskMsg.Bms_Funcode = UART_READ_CODE;
+			Uart0AskMsg.Reg_Begin_H = 0x00;
+			Uart0AskMsg.Reg_Begin_L = 0x00;
+			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;
+			Dio_WriteChannel(DioConf_DioChannel_PTB4_GPIO_OUT_MCU_RS485_EN, STD_ON);
+			UART_Send_Data(UART_LPUART0, (uint8 *)&Uart0AskMsg, sizeof(Uart0AskMsg), 1000 * 10);
+			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 * 10);
+			Dio_WriteChannel(DioConf_DioChannel_PTB4_GPIO_OUT_MCU_RS485_EN, STD_ON);
+			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)
+				{
+					uartBattInfoDecode(UartAnsData.DataPtr);
+				}
+			}
+			PROC_UART0_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
+			break;
+		}
+		case PROCESS_UART_STATE_SLEEP:
+		{
+			break;
+		}
+		default:
+			break;
+		}
+	}
+}
+bool uartBattInfoDecode(uint8 *dataPtr) //根据串口协议确定的解码函数
+{
+	uint8 i = 0, temp = 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)
+	{
+		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) //充电过程
+	{
+		if (Batt_current > 0x8000) // 数据为负
+		{
+			//求补码,结果为负
+			Batt_current = (uint16)((uint16)(~(Batt_current)) + 1);
+			Batt_current = Batt_current / 10;
+			BattCurrentNegFlag = -1;
+		}
+		else
+		{
+			//源码,结果为负
+			Batt_current = Batt_current / 10;
+			BattCurrentNegFlag = -1;
+		}
+	}
+	else //放电过程
+	{
+		if (Batt_current > 0x8000) // 数据为负
+		{
+			//求补码,结果为正
+			Batt_current = (uint16)((uint16)(~(Batt_current)) + 1);
+			Batt_current = Batt_current / 10;
+			BattCurrentNegFlag = 1;
+		}
+		else
+		{
+			//源码,结果为正
+			Batt_current = Batt_current / 10;
+			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);//不使用电压补偿
+		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);
+
+	// bmsHwVersion = dataPtr[(0x08 + BATT_CELL_VOL_NUM + TEMP_NUM) * 2 + 1];
+	// bmsSwVersion = dataPtr[(0x08 + BATT_CELL_VOL_NUM + TEMP_NUM) * 2];
+
+	temp = ((dataPtr[(0x09 + BATT_CELL_VOL_NUM + 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++)
+	{
+		SumBattTemp = SumBattTemp + battCellTemp[i];
+		maxCellTemp = max(maxCellTemp, battCellTemp[i]);
+		minCellTemp = min(minCellTemp, battCellTemp[i]);
+	}
+	AvgBattTemp = (SumBattTemp - maxCellTemp - minCellTemp) / (BATT_TEMP_NUM - 2);
+	return true;
+}
+#endif

+ 46 - 0
src/AppTaskUart0.h

@@ -0,0 +1,46 @@
+/*
+ * AppTaskUart0.h
+ *
+ *  Created on: 2022Äê2ÔÂ22ÈÕ
+ *      Author: QiXiang_CHENJIE
+ */
+
+#ifndef APPTASKUART0_H_
+#define APPTASKUART0_H_
+#include "hal_adapter.h"
+#include "AppFunclib.h"
+#include "AppGlobalVar.h"
+#ifdef APP_UART0_ENABLE
+#define BMS_ADDRESS_CODE 0x01
+#define UART_READ_CODE 0x03
+#define UART_WRITE_CODE 0x10
+#define UART_ENCRYPT_CODE 0x05
+#define UART_WRITE_FLAG 0x01
+#define UART_READ_FLAG 0x00
+void Uart0Task(void *pvParameters);
+typedef struct _UartAnsType
+{
+	uint8 BmsAdd;
+	uint8 FunCode;
+	uint8 Datalen;
+    uint8 *DataPtr;
+}UartAnsType;
+typedef enum
+{
+    PROCESS_UART_STATE_IDLE = 0,
+    PROCESS_UART_STATE_READ,
+    PROCESS_UART_STATE_SLEEP
+} process_Uart0;
+typedef struct _UartQueryType
+{
+    uint8 Bms_Address;
+    uint8 Bms_Funcode;
+    uint8 Reg_Begin_H;
+    uint8 Reg_Begin_L;
+    uint8 Reg_Num_H;
+    uint8 Reg_Num_L;
+    uint8 CRC_L;
+    uint8 CRC_H;
+} UartQueryType;
+#endif
+#endif /* APPTASKUART0_H_ */

+ 209 - 118
src/AppTaskUart1.c

@@ -3,7 +3,7 @@
  * @Date         : 2022-02-10 11:43:56
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2022-02-14 15:50:00
+ * @LastEditTime : 2022-02-23 15:51:23
  * @Description  : file content
  * @FilePath     : \S32K146_4G\src\AppTaskUart1.c
  */
@@ -35,7 +35,7 @@ void InitFunc(void);
 sint8 TcpConnectFunc(sint8 *ConnectId);
 sint8 TcpDataSendFunc(sint8 ConnectId);
 sint8 TcpRegisterChkFunc(void);
-void TcpDataEncode(UTC8TimeType UTC8TimeTcp,uint8 DataIdx, uint8 **PtrSendAddr,uint16 *SendLen);
+void TcpDataEncode(uint8 **PtrSendAddr, uint16 *SendLen);
 void GetUtc8Time(UTC8TimeType *UTC8TimeTcp);
 static void AtcmdTransmit(sint8 CmdIdx, uint8 *SetValuePtr, uint16 SetValueLen, sint8 *retFunc);
 void Uart_4G_Task(void *pvParameters)
@@ -63,11 +63,11 @@ void Uart_4G_Task(void *pvParameters)
 			{
 				PROC_TCP_STATE_SWITCH(PROCESS_TCP_REGCHK);
 			}
-			else if(TimerCounter%1000==0)
+			else if (TimerCounter % 1000 == 0)
 			{
 				PROC_TCP_STATE_SWITCH(PROCESS_TCP_SEND);
 			}
-			else if(TimerCounter%100==0)
+			else if (TimerCounter % 100 == 0)
 			{
 				PROC_TCP_STATE_SWITCH(PROCESS_TCP_RECV);
 			}
@@ -164,35 +164,12 @@ sint8 TcpDataSendFunc(sint8 ConnectId)
 	uint16 DataSendLen = 0;
 	sint8 ATRet = -1;
 	uint8 ReadLen = 0;
-	UTC8TimeType TcpTimeUtc8;
-	uint8 DataSendIdx = 0;
-	static uint32 TcpSendTimeCounter = 0;
-	GetUtc8Time(&TcpTimeUtc8);//时间获取
-	//TcpSendTimeCounter++;
-	TcpSendTimeCounter = 1;
-	memcpy(TcpbattSN,defaultSn,17);
-	if(TcpSendTimeCounter == 1)
-	{
-		DataSendIdx = GpsMsg;//版本信息发送
-	}
-	else if(TcpSendTimeCounter%10==0)
-	{
-		DataSendIdx = TruckBattMsg;//电池信息发送
-	}
-	else if((TcpSendTimeCounter-1)%30==0)
-	{
-		DataSendIdx = TruckVehiMsg;//车辆信息发送
-	}
-	else if((TcpSendTimeCounter-2)%30==0)
-	{
-		DataSendIdx = TruckAcclMsg;//累计信息发送
-	}
-	else
+	memcpy(TcpbattSN, defaultSn, 17);
+	TcpDataEncode(&pSendData, &DataSendLen); //数据组包,malloc申请在里面,pSendData指向申请的地址
+	if (DataSendLen == 0)
 	{
-		DataSendIdx = 0;//不发送,返回正确
-		return 0;
+		return 0; //暂时无数据可以发
 	}
-	TcpDataEncode(TcpTimeUtc8,DataSendIdx,&pSendData,&DataSendLen);//数据组包,malloc申请在里面,pSendData指向申请的地址
 	//数据准备完成,下面开始发送
 	char AtCmdSend[10] = {0};
 	uint8 AtCmdSendTotalLen = 0;
@@ -208,7 +185,7 @@ sint8 TcpDataSendFunc(sint8 ConnectId)
 			outValue = 0;
 		}
 	}
-	if(pSendData!=NULL)
+	if (pSendData != NULL)
 	{
 		vPortFree(pSendData);
 	}
@@ -305,7 +282,7 @@ sint8 TcpConnectFunc(sint8 *ConnectId)
 		{
 			char AtCmdSend[20] = {0};
 			uint8 AtCmdSendTotalLen = 0;
-			sprintf(AtCmdSend, "%d,\"TCP\",%s,%d\r\n", *ConnectId, WebSiteIp,WebSitePort); //此处需要优化
+			sprintf(AtCmdSend, "%d,\"TCP\",%s,%d\r\n", *ConnectId, WebSiteIp, WebSitePort); //此处需要优化
 			AtCmdSendTotalLen = mstrlen(AtCmdSend);
 			AtcmdTransmit(AT_CONNECT, AtCmdSend, AtCmdSendTotalLen, &ATRet);
 			if (ATRet == 0)
@@ -513,8 +490,8 @@ static void AtcmdTransmit(sint8 CmdIdx, uint8 *SetValuePtr, uint16 SetValueLen,
 	uint16 ATCmdTotalLen = 0;
 	ATCmdFixedLen = mstrlen(Atcmdfunc[CmdIdx].str);
 	ATCmdTotalLen = ATCmdFixedLen + SetValueLen;
-	PtrATCmdSend = malloc(ATCmdTotalLen+1);
-	memset(PtrATCmdSend, 0x00, ATCmdTotalLen+1);
+	PtrATCmdSend = malloc(ATCmdTotalLen + 1);
+	memset(PtrATCmdSend, 0x00, ATCmdTotalLen + 1);
 	memcpy(PtrATCmdSend, Atcmdfunc[CmdIdx].str, ATCmdFixedLen);
 	if (SetValuePtr != NULL)
 	{
@@ -525,7 +502,7 @@ static void AtcmdTransmit(sint8 CmdIdx, uint8 *SetValuePtr, uint16 SetValueLen,
 	*retFunc = Atcmdfunc[CmdIdx].cb(PtrATCmdSend, RX_Buffer[UART_LPUART1], CmdIdx, ReadLen);
 	if (PtrATCmdSend != NULL)
 	{
-		memset(PtrATCmdSend, 0x00, ATCmdTotalLen+1);
+		memset(PtrATCmdSend, 0x00, ATCmdTotalLen + 1);
 		free(PtrATCmdSend);
 	}
 	PtrATCmdSend = NULL;
@@ -637,7 +614,7 @@ sint8 at_callbackFunc(char *PSendStr, char *pReadStr, uint8 CmdIdx, uint16 pRead
 		if (retptr)
 		{
 			retptr = (uint8 *)strstr((char *)pReadStr, (char *)("CIPOPEN:"));
-			if(retptr)
+			if (retptr)
 			{
 				SocketId = CharToHex(*(retptr + 9));
 			}
@@ -659,8 +636,48 @@ sint8 at_callbackFunc(char *PSendStr, char *pReadStr, uint8 CmdIdx, uint16 pRead
 	}
 	return OutValue;
 }
-void TcpDataEncode(UTC8TimeType UTC8TimeTcp,uint8 DataIdx, uint8 **PtrSendAddr,uint16 *SendLen)
+void TcpDataEncode(uint8 **PtrSendAddr, uint16 *SendLen)
 {
+	uint8 DataIdx = 0;
+	static uint32 TcpSendTimeCounter = 0;
+	TcpSendTimeCounter++;
+
+	if (TcpSendTimeCounter == 1)
+	{
+		DataIdx = VerMsg; //版本信息发送
+	}
+	else if (TcpSendTimeCounter % 120 == 0)
+	{
+		DataIdx = GpsMsg; //定位信息发送
+	}
+#ifdef APP_UART0_ENABLE
+	else if (TcpSendTimeCounter % 60 == 0)
+	{
+		DataIdx = BattMsg; //电池信息发送
+	}
+#endif
+#ifdef APP_CAN_ENABLE
+	else if (TcpSendTimeCounter % 10 == 0)
+	{
+		DataIdx = TruckBattMsg; //电池信息发送
+	}
+	else if ((TcpSendTimeCounter - 1) % 30 == 0)
+	{
+		DataIdx = TruckVehiMsg; //车辆信息发送
+	}
+	else if ((TcpSendTimeCounter - 2) % 30 == 0)
+	{
+		DataIdx = TruckAcclMsg; //累计信息发送
+	}
+#endif
+	else
+	{
+		*SendLen = 0;
+		DataIdx = 0; //不发送,返回
+		return;
+	}
+	UTC8TimeType UTC8TimeTcp;
+	GetUtc8Time(&UTC8TimeTcp); //时间获取
 	uint8 *SendBuffer = NULL;
 	switch (DataIdx)
 	{
@@ -682,19 +699,19 @@ void TcpDataEncode(UTC8TimeType UTC8TimeTcp,uint8 DataIdx, uint8 **PtrSendAddr,u
 		GpsToTcpInfo.dataLength[0] = (DataLen >> 8) & 0xFF;
 		GpsToTcpInfo.dataLength[1] = DataLen & 0xFF;
 		GpsToTcpInfo.gpsInfo.sendTimeUTC[0] = (UTC8TimeTcp.year) & 0xFF; // year
-		GpsToTcpInfo.gpsInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF;           // month
-		GpsToTcpInfo.gpsInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF;             // day
-		GpsToTcpInfo.gpsInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;            // hour
-		GpsToTcpInfo.gpsInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;          // mins
-		GpsToTcpInfo.gpsInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF;          // sec
+		GpsToTcpInfo.gpsInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF;	 // month
+		GpsToTcpInfo.gpsInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF;	 // day
+		GpsToTcpInfo.gpsInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;	 // hour
+		GpsToTcpInfo.gpsInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; // mins
+		GpsToTcpInfo.gpsInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF; // sec
 		GpsToTcpInfo.gpsInfo.msgMark = DataIdx;
-		GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[0] = (UTC8TimeTcp.year ) & 0xFF; // year
-		GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[1] = UTC8TimeTcp.month & 0xFF;           // month
-		GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[2] = UTC8TimeTcp.day & 0xFF;             // day
-		GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;            // hour
-		GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;          // mins
+		GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[0] = (UTC8TimeTcp.year) & 0xFF; // year
+		GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[1] = UTC8TimeTcp.month & 0xFF;  // month
+		GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[2] = UTC8TimeTcp.day & 0xFF;	  // day
+		GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;	  // hour
+		GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; // mins
 		GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[5] = UTC8TimeTcp.second & 0xFF;
-		if (xQueueReceive(GpsDataQueueHandle,&GpsRecvData,0)== pdPASS)
+		if (xQueueReceive(GpsDataQueueHandle, &GpsRecvData, 0) == pdPASS)
 		{
 			memcpy((uint8 *)&GpsToTcpInfo.gpsInfo.GpsInfoData, (uint8 *)&GpsRecvData, sizeof(GPSInfo));
 		}
@@ -729,7 +746,7 @@ void TcpDataEncode(UTC8TimeType UTC8TimeTcp,uint8 DataIdx, uint8 **PtrSendAddr,u
 		GpsToTcpInfo.gpsInfo.zData[0] = xyzDatacahce[2] >> 8;
 		GpsToTcpInfo.gpsInfo.zData[1] = xyzDatacahce[2];
 		GpsToTcpInfo.CRC = bcc_chk((uint8 *)&GpsToTcpInfo, sizeof(GPSMsgtoTcpType) - 1);
-		memcpy(SendBuffer,&GpsToTcpInfo,sizeof(GpsToTcpInfo));
+		memcpy(SendBuffer, &GpsToTcpInfo, sizeof(GpsToTcpInfo));
 		break;
 	}
 	case 0x86:
@@ -744,21 +761,21 @@ void TcpDataEncode(UTC8TimeType UTC8TimeTcp,uint8 DataIdx, uint8 **PtrSendAddr,u
 		VerMsgToTcpInfo.cmdSymbol = TCP_CMD_SYM;
 		VerMsgToTcpInfo.ansSymbol = TCP_ANS_SYM;
 		memcpy(VerMsgToTcpInfo.SN, TcpbattSN, BATT_SN_LEN);
-		VerMsgToTcpInfo.encryptMethod = TCP_ENCPT_DISABLE; //not encrypt
+		VerMsgToTcpInfo.encryptMethod = TCP_ENCPT_DISABLE; // not encrypt
 		VerMsgToTcpInfo.dataLength[0] = (DataLen >> 8) & 0xFF;
 		VerMsgToTcpInfo.dataLength[1] = DataLen & 0xFF;
-		VerMsgToTcpInfo.VerInfo.sendTimeUTC[0] = (UTC8TimeTcp.year) & 0xFF; //year
-		VerMsgToTcpInfo.VerInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF;           //month
-		VerMsgToTcpInfo.VerInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF;             //day
-		VerMsgToTcpInfo.VerInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;            //hour
-		VerMsgToTcpInfo.VerInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;          //mins
-		VerMsgToTcpInfo.VerInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF;          //sec
+		VerMsgToTcpInfo.VerInfo.sendTimeUTC[0] = (UTC8TimeTcp.year) & 0xFF; // year
+		VerMsgToTcpInfo.VerInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF;	// month
+		VerMsgToTcpInfo.VerInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF;	// day
+		VerMsgToTcpInfo.VerInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;	// hour
+		VerMsgToTcpInfo.VerInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; // mins
+		VerMsgToTcpInfo.VerInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF; // sec
 		VerMsgToTcpInfo.VerInfo.msgMark = DataIdx;
-		VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[0] = (UTC8TimeTcp.year) & 0xFF; //year
-		VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[1] = UTC8TimeTcp.month & 0xFF;           //month
-		VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[2] = UTC8TimeTcp.day & 0xFF;             //day
-		VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;            //hour
-		VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;          //mins
+		VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[0] = (UTC8TimeTcp.year) & 0xFF; // year
+		VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[1] = UTC8TimeTcp.month & 0xFF;	 // month
+		VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[2] = UTC8TimeTcp.day & 0xFF;	 // day
+		VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;	 // hour
+		VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[4] = UTC8TimeTcp.minute & 0xFF; // mins
 		VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[5] = UTC8TimeTcp.second & 0xFF;
 		memcpy(VerMsgToTcpInfo.VerInfo.ICCID, IccidNum, 20);
 		memcpy(VerMsgToTcpInfo.VerInfo.IMEI, ImeiNum, 15);
@@ -786,13 +803,86 @@ void TcpDataEncode(UTC8TimeType UTC8TimeTcp,uint8 DataIdx, uint8 **PtrSendAddr,u
 		VerMsgToTcpInfo.VerInfo.BmsInfo = BMS_INFO;
 		VerMsgToTcpInfo.VerInfo.DataModuleType = DATA_MODULE_TYPE;
 		VerMsgToTcpInfo.CRC = bcc_chk((uint8 *)&VerMsgToTcpInfo, sizeof(VerMsgToTcpInfo) - 1);
-		memcpy(SendBuffer,&VerMsgToTcpInfo,sizeof(VersionMsgtoTcpType));
+		memcpy(SendBuffer, &VerMsgToTcpInfo, sizeof(VersionMsgtoTcpType));
 		break;
 	}
+#ifdef APP_UART0_ENABLE
+	case 0x80:
+	{
+		uint8 ProtocolHeaderLen = 25;																					  //电池信息协议头部加校验码长度,此长度不更改
+		uint8 ProtocolFixedLen = 60;																					  //电池信息协议固定总长度 如协议新增,需要更改此长度
+		uint16 ProtocolFluctedLen = AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + BmsOtherTemp + OtherTemp; //电池信息协议变动长度
+		uint16 DataLen;
+		*SendLen = ProtocolFixedLen + ProtocolFluctedLen;
+		SendBuffer = pvPortMalloc(*SendLen);
+		if (SendBuffer == NULL)
+		{
+			return;
+		}
+		*(SendBuffer + 0) = TCP_START_SYM1;									 //起始码-1
+		*(SendBuffer + 1) = TCP_START_SYM2;									 //起始码-2
+		*(SendBuffer + 2) = TCP_CMD_SYM;									 //命令标识-3
+		*(SendBuffer + 3) = TCP_ANS_SYM;									 //应答标识-4
+		memcpy(SendBuffer + 4, TcpbattSN, BATT_SN_LEN);						 // SN码 5-21
+		*(SendBuffer + 21) = TCP_ENCPT_DISABLE;								 //加密方式-22
+		DataLen = ProtocolFixedLen + ProtocolFluctedLen - ProtocolHeaderLen; //电池信息单元协议固定长度
+		*(SendBuffer + 22) = (DataLen >> 8) & 0xFF;							 //数据长度H-23
+		*(SendBuffer + 23) = DataLen & 0xFF;								 //数据长度L-24
+		*(SendBuffer + 24) = (UTC8TimeTcp.year) & 0xFF;						 // year-25
+		*(SendBuffer + 25) = UTC8TimeTcp.month & 0xFF;						 // month-26
+		*(SendBuffer + 26) = UTC8TimeTcp.day & 0xFF;						 // day-27
+		*(SendBuffer + 27) = UTC8TimeTcp.hour & 0xFF;						 // hour-28
+		*(SendBuffer + 28) = UTC8TimeTcp.minute & 0xFF;						 // mins-29
+		*(SendBuffer + 29) = UTC8TimeTcp.second & 0xFF;						 // sec-30
+		*(SendBuffer + 30) = DataIdx;										 //电池信息发送-31
+		*(SendBuffer + 31) = (UTC8TimeTcp.year) & 0xFF;						 // year-32
+		*(SendBuffer + 32) = UTC8TimeTcp.month & 0xFF;						 // month-33
+		*(SendBuffer + 33) = UTC8TimeTcp.day & 0xFF;						 // day-34
+		*(SendBuffer + 34) = UTC8TimeTcp.hour & 0xFF;						 // hour-35
+		*(SendBuffer + 35) = UTC8TimeTcp.minute & 0xFF;						 // mins-36
+		*(SendBuffer + 36) = UTC8TimeTcp.second & 0xFF;						 // sec-37
+		*(SendBuffer + 37) = CSQValue;										 //信号强度-38
+		*(SendBuffer + 38) = 0;												 //故障等级-39
+		*(SendBuffer + 39) = ErrorTemp >> 8;								 //故障代码H-40
+		*(SendBuffer + 40) = ErrorTemp & 0xFF;								 //故障代码L-41
+		*(SendBuffer + 41) = battI >> 8;									 //电流-42
+		*(SendBuffer + 42) = battI & 0xFF;									 //电流-43
+		*(SendBuffer + 43) = battPackVol >> 8;								 //电压-44
+		*(SendBuffer + 44) = battPackVol & 0xFF;							 //电压-45
+		*(SendBuffer + 45) = battPackVol >> 8;								 //电压-46
+		*(SendBuffer + 46) = battPackVol & 0xFF;							 //电压-47
+		*(SendBuffer + 47) = battMOSSwitchState;							 // mos状态-48
+		*(SendBuffer + 48) = (uint8)(socd_pct_vcuSoc / 10);					 // soc-49
+		*(SendBuffer + 49) = (uint8)(sohd_pct_bcuSoh / 10);					 // soh-50
+		*(SendBuffer + 50) = (battBalanceoInfo >> 24) & 0xFF;
+		*(SendBuffer + 51) = (battBalanceoInfo >> 16) & 0xFF;
+		*(SendBuffer + 52) = (battBalanceoInfo >> 8) & 0xFF;
+		*(SendBuffer + 53) = battBalanceoInfo & 0xFF;		  //均衡状态-51-54
+		*(SendBuffer + 54) = AppDataInfo.BattCellCount;		  //电压个数-55
+		for (uint8 i = 0; i < AppDataInfo.BattCellCount; i++) //单体电压
+		{
+			*(SendBuffer + 54 + i * 2 + 1) = (battCellU[i] >> 8) & 0xFF;
+			*(SendBuffer + 54 + i * 2 + 2) = battCellU[i] & 0xFF;
+		}
+		*(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 + 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;																						  //环境温度
+		// *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 3) = fastChargeTemp;																				  //快充温度
+		// *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 4) = normalChargeTemp;																				  //慢充温度
+		// *(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); //校验码
+	}
+#endif
+#ifdef APP_CAN_ENABLE
 	case 0x90:
 	{
 		*SendLen = 0x52;
-		 SendBuffer = pvPortMalloc(*SendLen);
+		SendBuffer = pvPortMalloc(*SendLen);
 		*(SendBuffer + 0) = TCP_START_SYM1;
 		*(SendBuffer + 1) = TCP_START_SYM2;
 		*(SendBuffer + 2) = TCP_CMD_SYM;
@@ -803,18 +893,18 @@ void TcpDataEncode(UTC8TimeType UTC8TimeTcp,uint8 DataIdx, uint8 **PtrSendAddr,u
 		*(SendBuffer + 0x16) = ((DataLen >> 8) & 0xFF);	   // uint16	DataLen
 		*(SendBuffer + 0x17) = (DataLen & 0xFF);
 		*(SendBuffer + 0x18) = ((UTC8TimeTcp.year) & 0xFF); // uint8	year
-		*(SendBuffer + 0x19) = (UTC8TimeTcp.month & 0xFF);		   // uint8	month
-		*(SendBuffer + 0x1A) = (UTC8TimeTcp.day & 0xFF);		   // uint8	day
-		*(SendBuffer + 0x1B) = (UTC8TimeTcp.hour & 0xFF);		   // uint8	hour
-		*(SendBuffer + 0x1C) = (UTC8TimeTcp.minute & 0xFF);		   // uint8	minute
-		*(SendBuffer + 0x1D) = (UTC8TimeTcp.second & 0xFF);		   // uint8	second
-		*(SendBuffer + 0x1E) = (DataIdx & 0xFF);				   // uint8	BATTMSG
+		*(SendBuffer + 0x19) = (UTC8TimeTcp.month & 0xFF);	// uint8	month
+		*(SendBuffer + 0x1A) = (UTC8TimeTcp.day & 0xFF);	// uint8	day
+		*(SendBuffer + 0x1B) = (UTC8TimeTcp.hour & 0xFF);	// uint8	hour
+		*(SendBuffer + 0x1C) = (UTC8TimeTcp.minute & 0xFF); // uint8	minute
+		*(SendBuffer + 0x1D) = (UTC8TimeTcp.second & 0xFF); // uint8	second
+		*(SendBuffer + 0x1E) = (DataIdx & 0xFF);			// uint8	BATTMSG
 		*(SendBuffer + 0x1F) = ((UTC8TimeTcp.year) & 0xFF); // uint8	year
-		*(SendBuffer + 0x20) = (UTC8TimeTcp.month & 0xFF);		   // uint8	month
-		*(SendBuffer + 0x21) = (UTC8TimeTcp.day & 0xFF);		   // uint8	day
-		*(SendBuffer + 0x22) = (UTC8TimeTcp.hour & 0xFF);		   // uint8	hour
-		*(SendBuffer + 0x23) = (UTC8TimeTcp.minute & 0xFF);		   // uint8	minute
-		*(SendBuffer + 0x24) = (UTC8TimeTcp.second & 0xFF);		   // uint8	second
+		*(SendBuffer + 0x20) = (UTC8TimeTcp.month & 0xFF);	// uint8	month
+		*(SendBuffer + 0x21) = (UTC8TimeTcp.day & 0xFF);	// uint8	day
+		*(SendBuffer + 0x22) = (UTC8TimeTcp.hour & 0xFF);	// uint8	hour
+		*(SendBuffer + 0x23) = (UTC8TimeTcp.minute & 0xFF); // uint8	minute
+		*(SendBuffer + 0x24) = (UTC8TimeTcp.second & 0xFF); // uint8	second
 		memcpy(SendBuffer + 0x25, VIN, 17);
 		*(SendBuffer + 0x36) = (vehicleStatus & 0xFF);		 // uint8	整车状态
 		*(SendBuffer + 0x37) = (bmsHVOn & 0xFF);			 // uint8	bms上高压指令
@@ -859,43 +949,43 @@ void TcpDataEncode(UTC8TimeType UTC8TimeTcp,uint8 DataIdx, uint8 **PtrSendAddr,u
 		uint16 DataLen = 0x3B + 384 * 2 + 64;
 		*(SendBuffer + 0x16) = ((DataLen >> 8) & 0xFF); // uint16	DataLen
 		*(SendBuffer + 0x17) = (DataLen & 0xFF);
-		*(SendBuffer + 0x18) = ((UTC8TimeTcp.year) & 0xFF); // uint8	year
-		*(SendBuffer + 0x19) = (UTC8TimeTcp.month & 0xFF);		   // uint8	month
-		*(SendBuffer + 0x1A) = (UTC8TimeTcp.day & 0xFF);		   // uint8	day
-		*(SendBuffer + 0x1B) = (UTC8TimeTcp.hour & 0xFF);		   // uint8	hour
-		*(SendBuffer + 0x1C) = (UTC8TimeTcp.minute & 0xFF);		   // uint8	minute
-		*(SendBuffer + 0x1D) = (UTC8TimeTcp.second & 0xFF);		   // uint8	second
-		*(SendBuffer + 0x1E) = (DataIdx & 0xFF);				   // uint8	BATTMSG
-		*(SendBuffer + 0x1F) = ((UTC8TimeTcp.year) & 0xFF); // uint8	year
-		*(SendBuffer + 0x20) = (UTC8TimeTcp.month & 0xFF);		   // uint8	month
-		*(SendBuffer + 0x21) = (UTC8TimeTcp.day & 0xFF);		   // uint8	day
-		*(SendBuffer + 0x22) = (UTC8TimeTcp.hour & 0xFF);		   // uint8	hour
-		*(SendBuffer + 0x23) = (UTC8TimeTcp.minute & 0xFF);		   // uint8	minute
-		*(SendBuffer + 0x24) = (UTC8TimeTcp.second & 0xFF);		   // uint8	second
-		*(SendBuffer + 0x25) = (CSQValue & 0xFF);					   // uint8	csq
-		*(SendBuffer + 0x26) = (BMS1_SysSts & 0xFF);			   // uint8	电池管理系统工作状态,0-初始化 1-自检完成允许上电 2-运行状态 3-高压切断 4-故障状态,精度_1,偏移量_0,单位_
-		*(SendBuffer + 0x27) = (BMS1_DCChrgConnectSt & 0xFF);	   // uint8	直流充电枪连接状态,0-未连接 1-单枪连接 2-双枪连接 3-无效,精度_1,偏移量_0,单位_
-		*(SendBuffer + 0x28) = (BMS2_FaultLevel & 0xFF);		   // uint8	当前最高故障等级,0-正常 1-1级 轻微故障 2-2级 较严重故障 3-3级 最严重故障,精度_1,偏移量_0,单位_
-		*(SendBuffer + 0x29) = (BMS2_FaultCode & 0xFF);			   // uint8	故障码,见BMS_ErrCode,精度_1,偏移量_0,单位_
-		*(SendBuffer + 0x2A) = (BMS2_RqHVPoerOff & 0xFF);		   // uint8	BMS下高压请求,0-无效 1-请求下高压 2-不请求下高压 3-无效,精度_1,偏移量_0,单位_
-		*(SendBuffer + 0x2B) = (BMS1_ChrgStatus & 0xFF);		   // uint8	充电状态,0-未充电 1-充电中 2-充电已完成 3-充电错误故障,精度_1,偏移量_0,单位_
-		*(SendBuffer + 0x2C) = (BMS2_SOC & 0xFF);				   // uint8	电池包SOC 精度_0.4,偏移量_0,单位_*(SendBuffer+0x2D)	=	(BMS2_SOH&0xFF);		//uint8	电池包SOH 精度_0.4,偏移量_0,单位_*(SendBuffer+0x2E)	=	((BMS2_PackInsideVolt>>8)&0xFF);		//uint16	电池包内侧电压 精度_0.1,偏移量_0,单位_V
-		*(SendBuffer + 0x2D) = (BMS2_SOH /25/10) & 0xFF;			   // SOH 精度1%
-		*(SendBuffer + 0x2E) = (BMS2_PackInsideVolt >> 8) & 0xFF;  //电池包总电压
+		*(SendBuffer + 0x18) = ((UTC8TimeTcp.year) & 0xFF);		  // uint8	year
+		*(SendBuffer + 0x19) = (UTC8TimeTcp.month & 0xFF);		  // uint8	month
+		*(SendBuffer + 0x1A) = (UTC8TimeTcp.day & 0xFF);		  // uint8	day
+		*(SendBuffer + 0x1B) = (UTC8TimeTcp.hour & 0xFF);		  // uint8	hour
+		*(SendBuffer + 0x1C) = (UTC8TimeTcp.minute & 0xFF);		  // uint8	minute
+		*(SendBuffer + 0x1D) = (UTC8TimeTcp.second & 0xFF);		  // uint8	second
+		*(SendBuffer + 0x1E) = (DataIdx & 0xFF);				  // uint8	BATTMSG
+		*(SendBuffer + 0x1F) = ((UTC8TimeTcp.year) & 0xFF);		  // uint8	year
+		*(SendBuffer + 0x20) = (UTC8TimeTcp.month & 0xFF);		  // uint8	month
+		*(SendBuffer + 0x21) = (UTC8TimeTcp.day & 0xFF);		  // uint8	day
+		*(SendBuffer + 0x22) = (UTC8TimeTcp.hour & 0xFF);		  // uint8	hour
+		*(SendBuffer + 0x23) = (UTC8TimeTcp.minute & 0xFF);		  // uint8	minute
+		*(SendBuffer + 0x24) = (UTC8TimeTcp.second & 0xFF);		  // uint8	second
+		*(SendBuffer + 0x25) = (CSQValue & 0xFF);				  // uint8	csq
+		*(SendBuffer + 0x26) = (BMS1_SysSts & 0xFF);			  // uint8	电池管理系统工作状态,0-初始化 1-自检完成允许上电 2-运行状态 3-高压切断 4-故障状态,精度_1,偏移量_0,单位_
+		*(SendBuffer + 0x27) = (BMS1_DCChrgConnectSt & 0xFF);	  // uint8	直流充电枪连接状态,0-未连接 1-单枪连接 2-双枪连接 3-无效,精度_1,偏移量_0,单位_
+		*(SendBuffer + 0x28) = (BMS2_FaultLevel & 0xFF);		  // uint8	当前最高故障等级,0-正常 1-1级 轻微故障 2-2级 较严重故障 3-3级 最严重故障,精度_1,偏移量_0,单位_
+		*(SendBuffer + 0x29) = (BMS2_FaultCode & 0xFF);			  // uint8	故障码,见BMS_ErrCode,精度_1,偏移量_0,单位_
+		*(SendBuffer + 0x2A) = (BMS2_RqHVPoerOff & 0xFF);		  // uint8	BMS下高压请求,0-无效 1-请求下高压 2-不请求下高压 3-无效,精度_1,偏移量_0,单位_
+		*(SendBuffer + 0x2B) = (BMS1_ChrgStatus & 0xFF);		  // uint8	充电状态,0-未充电 1-充电中 2-充电已完成 3-充电错误故障,精度_1,偏移量_0,单位_
+		*(SendBuffer + 0x2C) = (BMS2_SOC & 0xFF);				  // uint8	电池包SOC 精度_0.4,偏移量_0,单位_*(SendBuffer+0x2D)	=	(BMS2_SOH&0xFF);		//uint8	电池包SOH 精度_0.4,偏移量_0,单位_*(SendBuffer+0x2E)	=	((BMS2_PackInsideVolt>>8)&0xFF);		//uint16	电池包内侧电压 精度_0.1,偏移量_0,单位_V
+		*(SendBuffer + 0x2D) = (BMS2_SOH / 25 / 10) & 0xFF;		  // SOH 精度1%
+		*(SendBuffer + 0x2E) = (BMS2_PackInsideVolt >> 8) & 0xFF; //电池包总电压
 		*(SendBuffer + 0x2F) = (BMS2_PackInsideVolt & 0xFF);
 		*(SendBuffer + 0x30) = ((BMS2_PackCurrent >> 8) & 0xFF); // uint16	电池包总电流,充电为负值,放电为正值 精度_0.1,偏移量_-1000,单位_A
 		*(SendBuffer + 0x31) = (BMS2_PackCurrent & 0xFF);
 		*(SendBuffer + 0x32) = ((BMS4_SysInsRes >> 8) & 0xFF); // uint16	系统绝缘电阻 精度_1,偏移量_0,单位_KΩ
 		*(SendBuffer + 0x33) = (BMS4_SysInsRes & 0xFF);
-		*(SendBuffer + 0x34) = (BMS1_MainPosRelaySt & 0xFF);		// uint8	主正继电器状态,0-预留 1-断开 2-吸合  ,精度_1,偏移量_0,单位_
-		*(SendBuffer + 0x35) = (BMS1_PreChgRelaySt & 0xFF);			// uint8	预充继电器状态,0-预留 1-断开 2-吸合  ,精度_1,偏移量_0,单位_
-		*(SendBuffer + 0x36) = (BMS1_MainNegRelaySt & 0xFF);		// uint8	主负继电器状态,0-预留 1-断开 2-吸合  ,精度_1,偏移量_0,单位_
-		*(SendBuffer + 0x37) = (BMS1_DCChrgPos1RelaySt & 0xFF);		// uint8	直流充正继电器1状态,0-预留 1-断开 2-吸合  ,精度_1,偏移量_0,单位_
-		*(SendBuffer + 0x38) = (BMS1_DCChrgNeg1RelaySt & 0xFF);		// uint8	直流充负继电器1状态,0-预留 1-断开 2-吸合  ,精度_1,偏移量_0,单位_
-		*(SendBuffer + 0x39) = (BMS1_DCChrgPos2RelaySt & 0xFF);		// uint8	直流充正继电器2状态,0-预留 1-断开 2-吸合  ,精度_1,偏移量_0,单位_
-		*(SendBuffer + 0x3A) = (BMS1_DCChrgNeg2RelaySt & 0xFF);		// uint8	直流充负继电器2状态,0-预留 1-断开 2-吸合  ,精度_1,偏移量_0,单位_
-		*(SendBuffer + 0x3B) = (BMS1_HeatPosRelaySt & 0xFF);		// uint8	加热正继电器状态,0-预留 1-断开 2-吸合  ,精度_1,偏移量_0,单位_
-		*(SendBuffer + 0x3C) = (BMS1_HeatNegRelaySt & 0xFF);		// uint8	加热负继电器状态,0-预留 1-断开 2-吸合  ,精度_1,偏移量_0,单位_
+		*(SendBuffer + 0x34) = (BMS1_MainPosRelaySt & 0xFF);	// uint8	主正继电器状态,0-预留 1-断开 2-吸合  ,精度_1,偏移量_0,单位_
+		*(SendBuffer + 0x35) = (BMS1_PreChgRelaySt & 0xFF);		// uint8	预充继电器状态,0-预留 1-断开 2-吸合  ,精度_1,偏移量_0,单位_
+		*(SendBuffer + 0x36) = (BMS1_MainNegRelaySt & 0xFF);	// uint8	主负继电器状态,0-预留 1-断开 2-吸合  ,精度_1,偏移量_0,单位_
+		*(SendBuffer + 0x37) = (BMS1_DCChrgPos1RelaySt & 0xFF); // uint8	直流充正继电器1状态,0-预留 1-断开 2-吸合  ,精度_1,偏移量_0,单位_
+		*(SendBuffer + 0x38) = (BMS1_DCChrgNeg1RelaySt & 0xFF); // uint8	直流充负继电器1状态,0-预留 1-断开 2-吸合  ,精度_1,偏移量_0,单位_
+		*(SendBuffer + 0x39) = (BMS1_DCChrgPos2RelaySt & 0xFF); // uint8	直流充正继电器2状态,0-预留 1-断开 2-吸合  ,精度_1,偏移量_0,单位_
+		*(SendBuffer + 0x3A) = (BMS1_DCChrgNeg2RelaySt & 0xFF); // uint8	直流充负继电器2状态,0-预留 1-断开 2-吸合  ,精度_1,偏移量_0,单位_
+		*(SendBuffer + 0x3B) = (BMS1_HeatPosRelaySt & 0xFF);	// uint8	加热正继电器状态,0-预留 1-断开 2-吸合  ,精度_1,偏移量_0,单位_
+		*(SendBuffer + 0x3C) = (BMS1_HeatNegRelaySt & 0xFF);	// uint8	加热负继电器状态,0-预留 1-断开 2-吸合  ,精度_1,偏移量_0,单位_
 
 		*(SendBuffer + 0x50) = ((BMS9_PackTotCellNum >> 8) & 0xFF); // uint16	PACK中单体电芯的总数目
 		*(SendBuffer + 0x51) = (BMS9_PackTotCellNum & 0xFF);
@@ -912,7 +1002,7 @@ void TcpDataEncode(UTC8TimeType UTC8TimeTcp,uint8 DataIdx, uint8 **PtrSendAddr,u
 	case 0x92:
 	{
 		*SendLen = 0x4E;
-		 SendBuffer = pvPortMalloc(*SendLen);
+		SendBuffer = pvPortMalloc(*SendLen);
 		*(SendBuffer + 0) = TCP_START_SYM1;
 		*(SendBuffer + 1) = TCP_START_SYM2;
 		*(SendBuffer + 2) = TCP_CMD_SYM;
@@ -922,14 +1012,14 @@ void TcpDataEncode(UTC8TimeType UTC8TimeTcp,uint8 DataIdx, uint8 **PtrSendAddr,u
 		uint16 DataLen = 0x35;
 		*(SendBuffer + 0x16) = ((DataLen >> 8) & 0xFF); // uint16	DataLen
 		*(SendBuffer + 0x17) = (DataLen & 0xFF);
-		*(SendBuffer + 0x18) = ((UTC8TimeTcp.year) & 0xFF);	 // uint8	year
+		*(SendBuffer + 0x18) = ((UTC8TimeTcp.year) & 0xFF);			 // uint8	year
 		*(SendBuffer + 0x19) = (UTC8TimeTcp.month & 0xFF);			 // uint8	month
 		*(SendBuffer + 0x1A) = (UTC8TimeTcp.day & 0xFF);			 // uint8	day
 		*(SendBuffer + 0x1B) = (UTC8TimeTcp.hour & 0xFF);			 // uint8	hour
 		*(SendBuffer + 0x1C) = (UTC8TimeTcp.minute & 0xFF);			 // uint8	minute
 		*(SendBuffer + 0x1D) = (UTC8TimeTcp.second & 0xFF);			 // uint8	second
 		*(SendBuffer + 0x1E) = (DataIdx & 0xFF);					 // uint8
-		*(SendBuffer + 0x1F) = ((UTC8TimeTcp.year) & 0xFF);	 // uint8	year
+		*(SendBuffer + 0x1F) = ((UTC8TimeTcp.year) & 0xFF);			 // uint8	year
 		*(SendBuffer + 0x20) = (UTC8TimeTcp.month & 0xFF);			 // uint8	month
 		*(SendBuffer + 0x21) = (UTC8TimeTcp.day & 0xFF);			 // uint8	day
 		*(SendBuffer + 0x22) = (UTC8TimeTcp.hour & 0xFF);			 // uint8	hour
@@ -978,6 +1068,7 @@ void TcpDataEncode(UTC8TimeType UTC8TimeTcp,uint8 DataIdx, uint8 **PtrSendAddr,u
 		*(SendBuffer + 0x4D) = bcc_chk(SendBuffer, 0x4D);
 		break;
 	}
+#endif
 	default:
 		break;
 	}
@@ -990,18 +1081,18 @@ 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);
-	if(ReadLen>0)
+	UART_Query_Data(UART_LPUART1, UART_LPUART1, AtCmdAsk, AtCmdLen, RX_Buffer[UART_LPUART1], &ReadLen, 1000 * 10);
+	if (ReadLen > 0)
 	{
 		if ((uint8 *)strstr((char *)RX_Buffer[UART_LPUART1], (char *)("OK")))
 		{
 			retptr = (uint8 *)strstr((char *)RX_Buffer[UART_LPUART1], (char *)("+CCLK:"));
-			UTC8TimeTcp->year = CharToHex(*(retptr + 8))*10+CharToHex(*(retptr + 9));
-			UTC8TimeTcp->month = CharToHex(*(retptr + 11))*10+CharToHex(*(retptr + 12));
-			UTC8TimeTcp->day = CharToHex(*(retptr + 14))*10+CharToHex(*(retptr + 15));
-			UTC8TimeTcp->hour = CharToHex(*(retptr + 17))*10+CharToHex(*(retptr + 18));
-			UTC8TimeTcp->minute = CharToHex(*(retptr + 20))*10+CharToHex(*(retptr + 21));
-			UTC8TimeTcp->second = CharToHex(*(retptr + 23))*10+CharToHex(*(retptr + 24));
+			UTC8TimeTcp->year = CharToHex(*(retptr + 8)) * 10 + CharToHex(*(retptr + 9));
+			UTC8TimeTcp->month = CharToHex(*(retptr + 11)) * 10 + CharToHex(*(retptr + 12));
+			UTC8TimeTcp->day = CharToHex(*(retptr + 14)) * 10 + CharToHex(*(retptr + 15));
+			UTC8TimeTcp->hour = CharToHex(*(retptr + 17)) * 10 + CharToHex(*(retptr + 18));
+			UTC8TimeTcp->minute = CharToHex(*(retptr + 20)) * 10 + CharToHex(*(retptr + 21));
+			UTC8TimeTcp->second = CharToHex(*(retptr + 23)) * 10 + CharToHex(*(retptr + 24));
 		}
 	}
 }

+ 1 - 0
src/AppTaskUart1.h

@@ -29,6 +29,7 @@
 #define TCP_ANS_SYM 0xFE
 #define TCP_ENCPT_ENABLE 0x00
 #define TCP_ENCPT_DISABLE 0x01
+#define BattMsg (0x80)
 #define GpsMsg (0x82)
 #define VerMsg (0x86)
 #define TruckBattMsg (0x91)

+ 0 - 1
src/hal_adapter.c

@@ -331,7 +331,6 @@
      CanIf_bRxFlag = TRUE; // should not be delete
      // should put the msg into message queue
      canRxMsg_Buff = Can_GetMsgInfo(Mailbox->CanId, PduInfoPtr->SduLength, PduInfoPtr->SduDataPtr);
-     xQueueSendFromISR(CanRecvQueueHandle,&canRxMsg_Buff,&xHigherPriorityTaskWoken);
      xQueueSend(CanRecvQueueHandle,&canRxMsg_Buff,1000);
  }
 

+ 7 - 0
src/hal_adapter.h

@@ -36,6 +36,13 @@
  #include "timers.h"
  #include "task.h"
  #include "semphr.h"
+#ifndef min
+#define min(A,B) ((A) <= (B) ? (A) : (B))
+#endif
+#ifndef max
+#define max(A,B) ((A) < (B) ? (B) : (A))
+#endif
+
  #define UART_LPUART0 0
  #define UART_LPUART1 1
  #define UART_LPUART2 2

+ 11 - 0
src/main.c

@@ -50,8 +50,11 @@
 #include "hal_adapter.h"
 #include "Lpuart_Uart_Ip.h"
 
+#include "AppTaskMain.h"
+#include "AppTaskUart0.h"
 #include "AppTaskUart1.h"
 #include "AppTaskCan.h"
+#include "AppTaskGps.h"
 int main(void)
 {
 	volatile int exit_code = 0;
@@ -114,6 +117,7 @@ int main(void)
 	Can_Init(&Can_Config_VS_0);
 #endif
 	Can_SetControllerMode(CanController_0, CAN_CS_STARTED);
+	Can_SetControllerMode(CanController_1, CAN_CS_STARTED);
 #endif
 	//	Can_SetControllerMode(CanController_1, CAN_CS_STARTED);
 	//	Dio_WriteChannel(DioConf_DioChannel_PTE4_GPIO_OUT_MCU_4G_POW_EN,STD_ON);  //ĘšÄÜpower
@@ -127,10 +131,17 @@ int main(void)
 	//	Dio_WriteChannel(DioConf_DioChannel_PTB4_GPIO_OUT_MCU_RS485_EN,STD_ON);
 	// Dio_WriteChannel(DioConf_DioChannel_PTB18_GPIO_OUT_MCU_4G_RESET,STD_OFF);
 	// DioConf_DioChannel_PTB18_GPIO_OUT_MCU_4G_RESET
+	IP_LPUART0->CTRL |= LPUART_CTRL_ILT(1);
 	IP_LPUART1->CTRL |= LPUART_CTRL_ILT(1);
 	IP_LPUART2->CTRL |= LPUART_CTRL_ILT(1);
+	xTaskCreate(MainTask, (const char *const)"MainTask", 128, (void *)0, main_TASK_PRIORITY, NULL);
 	xTaskCreate(Uart_4G_Task, (const char *const)"Uart_4G_Task", 256 + 64, (void *)0, main_TASK_PRIORITY, NULL);
+#ifdef APP_UART0_ENABLE
+	xTaskCreate(Uart0Task, (const char *const)"Uart0_Bms_Task", 256, (void *)0, main_TASK_PRIORITY + 1, NULL);
+#endif
+#ifdef APP_CAN_ENABLE
 	xTaskCreate(CanTask, (const char *const)"CanTask", 256, (void *)0, main_TASK_PRIORITY + 1, NULL);
+#endif
 	xTaskCreate(GpsTask, (const char *const)"GpsTask", 256, (void *)0, main_TASK_PRIORITY + 2, NULL);
 	vTaskStartScheduler();
 	for (;;)