ソースを参照

4G01B 丰都改制软件合并

LAPTOP-KB7QFH2U\ChenJie-PC 1 年間 前
コミット
225cd54342

+ 2 - 1
.gitignore

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

+ 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="-1225283376601702587" 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="-784252839826050432" 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="-1225283376601702587" 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="-784252839826050432" 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="-1225283376601702587" 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="-784252839826050432" 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="-1225283376601702587" 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="-784252839826050432" 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
FreeRTOS/Source/include/FreeRTOSConfig.h

@@ -29,7 +29,7 @@
 #ifndef FREERTOS_CONFIG_H
 #define FREERTOS_CONFIG_H
 //#define SEGGER_SYSTEMVIEW //选择SYSTEM查看
-//#define SEGGER_RTT_PRINTF //选择RTT打印
+//#define SEGGER_RTT_PRINTF 	//选择RTT打印
 #ifdef SEGGER_SYSTEMVIEW
 	#include "SEGGER_SYSVIEW_FreeRTOS.h"
 #endif

+ 4 - 4
code/app/AppGlobalVar.c

@@ -65,7 +65,7 @@ QueueHandle_t CanRecvQueueHandle2;
 TaskHandle_t Uart_Hal_RecvTask_Handle, Uart_Hal_SendTask_Handle, MainTask_Handle, Uart0Task_Handle, CanTask_Handle, GpsTask_Handle, Uart_4G_Task_Handle;
 SemaphoreHandle_t sleep_mutex = NULL;
 
-bool TcpSysReboot = 1;
+bool TcpSysReboot = 0;
 char ImeiNum[15] = {0};
 char IccidNum[20] = {0};
 uint8 CSQValue = 0;
@@ -73,7 +73,7 @@ sint8 SocketId = -1;
 sint8 RegChkRet = 0;
 char WebSiteIp[20] = {0};
 uint8 TcpWorkState = 0;
-uint8 GpsDataFlg = 0;
+uint16 DeviceSpeed = 0;
 
 real_T returnFreq[3][5];
 real_T returnP[3][5];
@@ -90,7 +90,6 @@ uint32 ODO = 0;
 uint8 dcdcWorkStatus = 0;
 uint8 numOfChrgableSubsys = 0;
 uint8 chrgableSubsysCode = 0;
-
 uint16 vcuDCVol = 0;
 // EBC相关
 uint8 ebcStatus = 0;
@@ -138,6 +137,7 @@ UINT8 BcuRxFlag[28];
 /************************************************************
  *BCU->4G解码变量存放区
  ************************************************************/
+UINT8 BMS_CellRecvCounter=0;						//每个电压收取标志位
 UINT8 BMS_ReqVIN = 0x00;						// 是否请求VIN码,0:预留;1:请求VIN;2:不请求VIN;3:无效;,Re-1,Off-0,
 UINT8 BMS_ReqHVOff = 0x00;						// 是否请求下高压,0:预留;1:请求下高压;2:不请求下高压;3:无效;,Re-1,Off-0,
 UINT8 BMS_ProtocolEditionH = 0x00;				// 通讯协议版本高位(例 : 版本为3 .1, 则此处发3),	, Re - 1, Off - 0,
@@ -252,7 +252,7 @@ UINT8 BMS_CellTemp[BMS_TEMP_MAX_NUM] = {0x00};	// 当前CSC下的第N个探针
 UINT8 BMS_Checksum = 0x00;						// 电池编码信息1的CheckSum,Byte0=Byte1 XOR Byte2 XOR Byte3 XOR Byte4 XOR Byte5 XOR Byte6 XOR Byte7,Re-1,Off-0,
 UINT8 BMS_PackComp = 0x00;						// 电池厂家,1:"CATL" 2:"Li Shen" 3:"MGL" 4:"SAMSUN" 5:"LG",Re-1,Off-0,
 UINT8 BMS_BattCodeLeng = 0x00;					// 电池编码长度,0:Do not transmit this Code,Re-1,Off-0,
-UINT8 BMS_SN[27] = {0x00};						// 电池编码(SN)字符1(ASCII),,Re-1,Off-0,
+UINT8 BMS_SN[27] = {0};							// 电池编码(SN)字符1(ASCII),,Re-1,Off-0,
 UINT8 BMS_BattType = 0x00;						// 电池类型,1:铅酸电池; 2:镍氢电池; 3:磷酸铁锂电池; 4:锰酸锂电池; 5:钴酸锂电池; 6:三元材料电池; 7:聚合物锂离子电池; 8:钛酸锂电池; 9:超级电容; 10~13:保留; 14:燃料电池;15:保留,Re-1,Off-0,
 UINT8 BMS_CoolType = 0x00;						// 电池冷却方式,0:其他冷却方式1 : 自然冷却 2 : 风扇冷却 3 : 水冷却, Re - 1, Off - 0,
 UINT8 BMS_CSC_Total = 0x00;						// 电池系统中CSC总的数目,,Re-1,Off-0,

+ 3 - 2
code/app/AppGlobalVar.h

@@ -42,6 +42,8 @@ extern uint16 ErrorArray[10];
 extern uint8 Fota_update_flag;
 extern boolean Fota_Process_Going;
 extern uint8 Fota_error_flag;
+extern uint16 DeviceSpeed;
+
 typedef struct
 {
     uint8 RealLen;
@@ -74,8 +76,6 @@ extern uint16 WebSitePort;
 extern char ImeiNum[15];
 extern char IccidNum[20];
 extern uint8 TcpWorkState;
-extern uint8 GpsDataFlg;
-
 typedef struct _AppEppType
 {
     uint32 battDischrgAccCap;
@@ -118,6 +118,7 @@ extern BOOL BcuRxShortError[28];
 extern BOOL BcuRxLongError[28];
 extern UINT8 BcuRxErrorCounter[28];
 extern UINT8 BcuRxFlag[28];
+extern UINT8 BMS_CellRecvCounter;
 extern UINT8 BMS_ReqVIN;
 extern UINT8 BMS_ReqHVOff;
 extern UINT8 BMS_ProtocolEditionH;

+ 39 - 10
code/app/AppTaskCan.c

@@ -45,14 +45,17 @@ void CanTask(void *pvParameters)
 				}
 				else
 				{
-					BcuDecodeFunction(CanRxMsg.id, CanRxMsg.data); // can协议解析
 					if(CanRxMsg.id==0x1C00EDEA)
 					{
 						UDSAnsFunc(CanRxMsg.data);
 					}
+					else
+					{
+						BcuDecodeFunction(CanRxMsg.id, CanRxMsg.data); // can协议解析
+					}
 				}
 			}
-			if (timerCANIdle > 20000)
+			if (timerCANIdle > 10*1000)
 			{
 				timerCANIdle = 0;
 				xSemaphoreGive(sleep_mutex);
@@ -250,6 +253,7 @@ void BcuDecodeFunction(uint32 ID, uint8 *rawData)
 		{
 			break;
 		}
+		BMS_CellRecvCounter = (BMS_CellRecvCounter + 1) >= 128 ? 128 : (BMS_CellRecvCounter + 1);
 		for (UINT8 i = 0; i < 3; i++)
 		{
 			BMS_CellVolt[(BMS_CellVoltFramNum - 1) * 3 + i] = (UINT16)(((*(UINT8 *)(rawData + i * 2 + 2)) | (*(UINT8 *)(rawData + i * 2 + 3) << 8)) & 0xFFFF);
@@ -259,19 +263,26 @@ void BcuDecodeFunction(uint32 ID, uint8 *rawData)
 	case 0x18C2D0F3:
 		BMS_CellTempFramNum = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF);
 		BMS_CSC_Code = (UINT8)(((*(UINT8 *)(rawData + 1))) & 0xFF);
-		if (BMS_CellTempFramNum == 0 || BMS_CellTempFramNum > 12)
+		if (BMS_CSC_Code == 0 || BMS_CSC_Code > 8)
 		{
 			break;
 		}
-		for (UINT8 i = 0; i < 6; i++)
+		uint8 tempCount = 0,offvalue = 0;
+		if(BMS_CellTempFramNum%2==0)
+		{
+			tempCount = 2;
+			offvalue = 6;
+		}
+		else
+		{
+			tempCount = 6;
+			offvalue = 0;
+		}
+		for(uint8 i=0; i<tempCount; i++)
 		{
-			if (((BMS_CellTempFramNum - 1) * 6 + i) < sizeof(BMS_CellTemp))
+			if (((BMS_CSC_Code - 1) * 8 + i + offvalue) < sizeof(BMS_CellTemp) && ((UINT8)(((*(UINT8 *)(rawData + 2 + i))) & 0xFF) >= 10))
 			{
-				BMS_CellTemp[(BMS_CellTempFramNum - 1) * 6 + i] = (UINT8)(((*(UINT8 *)(rawData + 2 + i))) & 0xFF);
-				if (BMS_CellTemp[(BMS_CellTempFramNum - 1) * 6 + i] <= (0xFF - 10) && BMS_CellTemp[(BMS_CellTempFramNum - 1) * 6 + i] >= 10)
-				{
-					BMS_CellTemp[(BMS_CellTempFramNum - 1) * 6 + i] = BMS_CellTemp[(BMS_CellTempFramNum - 1) * 6 + i] - 10; // the tcp offset is -40, while the can message offset is -50
-				}
+				BMS_CellTemp[(BMS_CSC_Code - 1) * 8 + i + offvalue] = (UINT8)(((*(UINT8 *)(rawData + 2 + i))) & 0xFF)- 10;
 			}
 		}
 		BcuRxFlag[14] = 0x01;
@@ -416,6 +427,23 @@ void BcuDecodeFunction(uint32 ID, uint8 *rawData)
 		TMS_FaultLevel = (UINT8)(((*(UINT8 *)(rawData + 7)) >> 6) & 0x3);
 		BcuRxFlag[27] = 0x01;
 		break;
+	case 0x18E1F3D0:
+	{
+		uint8 VIN_FrameNo;
+		VIN_FrameNo = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF);
+		if (VIN_FrameNo - 1  > 2)
+		{
+			break;
+		}
+		for (UINT8 i = 0; i < 7; i++)
+		{
+			if (((VIN_FrameNo-1) * 7 + i) < sizeof(VIN))
+			{
+				VIN[(VIN_FrameNo-1) * 7 + i] = (UINT8)(((*(UINT8 *)(rawData + 1 + i))) & 0xFF);
+			}
+		}
+		break;
+	}
 	default:
 		break;
 	}
@@ -1091,6 +1119,7 @@ void BcuRxMsgSetInvalidValue(uint32 ID)
 		break;
 	case 0x18C1D0F3:
 		BMS_CellVoltFramNum = 0xFF;
+		BMS_CellRecvCounter = 0;
 		for (UINT16 i = 0; i < sizeof(BMS_CellVolt) / 2; i++)
 		{
 			BMS_CellVolt[i] = 0xFFFF;

+ 18 - 8
code/app/AppTaskGps.c

@@ -49,16 +49,24 @@ void GpsTask(void *pvParameters)
 		/*LED控制*/
 		if((timerCounterGetdata - ledCounterTmp) > 200)
 		{
+			Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
 			ledCounterTmp = timerCounterGetdata;
-			if(GpsDataFlg==1)
+			if(SocketId>=0)//网络连接成功
 			{
-				Dio_FlipChannel(LED_INDEX4);
+				Dio_FlipChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2);
 			}
 			else
 			{
-				Dio_WriteChannel(LED_INDEX4, STD_ON); // switch off the led
+				Dio_WriteChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2,STD_OFF);
+			}
+			if(DeviceSpeed>0)//GPS定位成功
+			{
+				Dio_FlipChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3);
+			}
+			else
+			{
+				Dio_WriteChannel(DioConf_DioChannel_PTE7_GPIO_OUT_MCU_LED3,STD_OFF);
 			}
-
 		}
 		/*三轴计算*/
 		if ((timerCounterGetdata - triaxiCounterTmp)> 10)
@@ -108,14 +116,12 @@ void GpsDataDecode(uint8 *msg)
 		}
 		if (index > 5 && strcmp(databuffer[2], "A") == 0)
 		{
-			GpsDataFlg = 1;
 			GpsInfoData.locateMark = 0x01; //有效,东经,北纬写定
 			strdel(databuffer[3], '.');
 			strdel(databuffer[5], '.');
 			strdel(databuffer[7], '.');
 			speedtemp = atol(databuffer[7]) * 1852 / 1e5; //节换算单位,1节=1.852km每小时
-			GpsInfoData.speed[0] = (speedtemp >> 8) & 0xFF;
-			GpsInfoData.speed[1] = speedtemp & 0xFF;
+			DeviceSpeed = speedtemp+1;
 			latitude = location_handle(databuffer[3]);
 			GpsInfoData.latitude[0] = latitude >> 24;
 			GpsInfoData.latitude[1] = latitude >> 16;
@@ -131,11 +137,15 @@ void GpsDataDecode(uint8 *msg)
 				direction = atol(databuffer[8]);
 				GpsInfoData.direction[0] = direction >> 8;
 				GpsInfoData.direction[1] = direction;
+				GpsInfoData.speed[0] = (speedtemp >> 8) & 0xFF;
+				GpsInfoData.speed[1] = speedtemp & 0xFF;
 			}
 			else
 			{
 				GpsInfoData.direction[0] = 0;
 				GpsInfoData.direction[1] = 0;
+				GpsInfoData.speed[0] = 0;
+				GpsInfoData.speed[1] = 0;
 			}
 			if (speedtemp >= 50 && speedtemp <= 1500)
 			{
@@ -149,7 +159,7 @@ void GpsDataDecode(uint8 *msg)
 		}
 		else
 		{
-			GpsDataFlg = 0;
+			DeviceSpeed = 0;
 		}
 		GpsInfoData.AccMileage[0] = AppConfigInfo.AppDataInfo.AccMileage >> 24;
 		GpsInfoData.AccMileage[1] = AppConfigInfo.AppDataInfo.AccMileage >> 16;

+ 2 - 0
code/app/AppTaskMain.c

@@ -48,7 +48,9 @@ void MainTask(void *pvParameters)
 			HAL_EEP_Write(0, (uint8 *)&AppConfigInfo, sizeof(AppConfigInfo));
 			SystemSoftwareReset();
 		}
+#ifndef SEGGER_RTT_PRINTF
 		MCUEnterSleep();
+#endif
 	}
 }
 static void vTimerCallback(TimerHandle_t pxTimer)

+ 190 - 115
code/app/AppTaskUart1.c

@@ -25,7 +25,6 @@ const ATCmdFunc Atcmdfunc[] = {
 	{AT_CSQ, "AT+CSQ\r\n", at_callbackFunc},
 	{AT_NETOPEN, "AT+NETOPEN\r\n", at_callbackFunc},
 	{AT_CGIP, "AT+CDNSGIP=", at_callbackFunc},
-	//{AT_CONNECT, "AT+CIPOPEN=0,\"TCP\",\"120.26.68.165\",14319\r\n", at_callbackFunc},
 	{AT_CONNECT, "AT+CIPOPEN=", at_callbackFunc},
 	{AT_CONNECTCHK, "AT+CIPOPEN?\r\n", at_callbackFunc},
 	{AT_SEND, "AT+CIPSEND=", at_callbackFunc},
@@ -35,22 +34,28 @@ const ATCmdFunc Atcmdfunc[] = {
 
 static process_Tcp gProcess_Tcp_Task = PROCESS_TCP_INIT;
 #define PROC_TCP_STATE_SWITCH(a) (gProcess_Tcp_Task = a)
-void InitFunc(void);
+sint8 InitFunc(void);
 sint8 TcpConnectFunc(sint8 *ConnectId);
-sint8 TcpDataSendFunc(sint8 ConnectId);
+sint8 TcpDataSendFunc(sint8 ConnectId,uint8 DataSendIdxIn);
 sint8 TcpRegisterChkFunc(void);
-void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen);
-void GetUtc8Time(UTC8TimeType *UTC8TimeTcp);
+void TcpDataEncode(uint8 DataIdx,uint32 *PtrSendAddr, uint16 *SendLen);
+void GetUtc8Time(UTC8TimeType *UTC8TimeTcpPtr);
+void TimeUpdate(UTC8TimeType *UTC8TimeTcpPtr);
+static void TcpDataSendFeqHandFunc(uint8 *DataIdx);
 static void AtcmdTransmit(sint8 CmdIdx, uint8 *SetValuePtr, uint16 SetValueLen, sint8 *retFunc, uint16 timeout);
 static void TcpDataInfoRecvHandle(uint8 *DataRecv, uint16 DataRecvLen);
 static void GetCSQValue(uint8 *out);
 void Fota_Ftp(uint8 *dataPtrIn);
 void tcpUdsFunc(uint8 *Ptr, uint8 *AnsPtr);
 static void vTimer1000msCallback(TimerHandle_t pxTimer);
-bool SendTimerFlg = false;
-static uint32 TcpSendTimeCounter = 0;
+
+volatile TcpFeq_type TcpDataFeq={
+		{0x01,60*60*2,0},{0x86,60*60,0},{0x91,10,0},
+		{0x82,10,0},{0x90,60,0},{0x92,60,0},{0x8C,10,0}};//默认发送频率
+static UTC8TimeType UTC8TimeTcp;//全局真实时间存储
 extern boolean waitForSleepFlag;
 boolean Uart_4G_Task_Sleep_FLag = false;
+TimerHandle_t monitorTimer1000ms;
 void Uart_4G_Task(void *pvParameters)
 {
 	(void)pvParameters;
@@ -58,17 +63,6 @@ void Uart_4G_Task(void *pvParameters)
 	uint8 UartRecvPtr[512];
 	volatile uint16 tcpErrorCounter = 0;
 	uint16 pReadLen = 0;
-	// 4G开机
-	Dio_LevelType _4G_Status = 0; // 0-关机,1-开机
-								  //	Dio_WriteChannel(DioConf_DioChannel_PTA6_GPIO_OUT_MCU_4G_POW_EN, STD_ON);
-								  //	vTaskDelay(pdMS_TO_TICKS(500));
-								  //	Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_ON);
-								  //	vTaskDelay(pdMS_TO_TICKS(50));
-								  //	AtcmdDelayRecvFunc(UART_LPUART1,(char *)("SMS DONE"),30000);
-								  //	Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_OFF);
-								  //	_4G_Status = Dio_ReadChannel(DioConf_DioChannel_PTB1_GPIO_IN_MCU_4G_STATUS);
-								  //	InitFunc(); // 4G模块初始化,注:AT同步不通过,没有进行次数判定及跳转
-	TimerHandle_t monitorTimer1000ms;
 	monitorTimer1000ms = xTimerCreate("monitor1000ms", 1000, pdTRUE, (void *)0, vTimer1000msCallback);
 	xTimerStart(monitorTimer1000ms, 0);
 	for (;;)
@@ -82,23 +76,22 @@ void Uart_4G_Task(void *pvParameters)
 		{
 		case PROCESS_TCP_INIT:
 		{
-			Dio_WriteChannel(DioConf_DioChannel_PTA6_GPIO_OUT_MCU_4G_POW_EN, STD_ON);
-			vTaskDelay(pdMS_TO_TICKS(500));
-
-			Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_ON);
-			vTaskDelay(pdMS_TO_TICKS(50));
-			Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_OFF);
-
-			AtcmdDelayRecvFunc(UART_LPUART1, (char *)("SMS DONE"), 30000);
-			_4G_Status = Dio_ReadChannel(DioConf_DioChannel_PTB1_GPIO_IN_MCU_4G_STATUS);
-			InitFunc();
-			TcpSendTimeCounter = 0;
-			PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
+			sint8 InitFlg = -1;
+			InitFlg  = InitFunc();
+			if(InitFlg==0)
+			{
+				PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
+			}
+			else
+			{
+				TcpSysReboot = 1;
+				PROC_TCP_STATE_SWITCH(PROCESS_TCP_ERROR);
+			}
 			break;
 		}
 		case PROCESS_TCP_IDLE: // 空闲状态
 		{
-			UART_Receive_Data(UART_LPUART1, UartRecvPtr, &pReadLen, 100); // 100ms检测
+			Tcp_Receive_Data (UartRecvPtr, &pReadLen, 100); // 100ms检测
 			if (SocketId < 0)
 			{
 				PROC_TCP_STATE_SWITCH(PROCESS_TCP_REGCHK);
@@ -108,12 +101,11 @@ void Uart_4G_Task(void *pvParameters)
 				PROC_TCP_STATE_SWITCH(PROCESS_TCP_RECV);
 				RecvTimerDelay = TimerCounter;
 			}
-			else if (AppConfigInfo.eolFlg == 1 && TcpWorkState == 0 && SendTimerFlg == true)
+			else if (AppConfigInfo.eolFlg == 1 && TcpWorkState == 0)
 			{
-				SendTimerFlg = false;
 				PROC_TCP_STATE_SWITCH(PROCESS_TCP_SEND);
 			}
-			if ((TimerCounter - RecvTimerDelay) >= 30000 && TcpWorkState == 1) // 10s内没有命令下发,进行正常发送任务
+			if ((TimerCounter - RecvTimerDelay) >= 30000 && TcpWorkState == 1) // 30s内没有命令下发,进行正常发送任务
 			{
 				TcpWorkState = 0;
 			}
@@ -141,7 +133,6 @@ void Uart_4G_Task(void *pvParameters)
 				if (ConnectRet > 0)
 				{
 					PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
-					TcpSendTimeCounter = 0;
 				}
 				else
 				{
@@ -153,16 +144,22 @@ void Uart_4G_Task(void *pvParameters)
 		case PROCESS_TCP_SEND: // 网络数据发送
 		{
 			sint8 SendRet = -1;
-			SendRet = TcpDataSendFunc(SocketId);
-			if (SendRet == 0)
-			{
-				PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
-				tcpErrorCounter = 0;
-			}
-			else
+			uint8 DataSendIdx = 0;
+			//发送判定
+			TcpDataSendFeqHandFunc(&DataSendIdx);
+			if(DataSendIdx!=0)//有数据处理
 			{
-				SocketId = -1;
-				PROC_TCP_STATE_SWITCH(PROCESS_TCP_ERROR);
+				SendRet = TcpDataSendFunc(SocketId,DataSendIdx);//发送函数
+				if (SendRet == 0)
+				{
+					PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
+					tcpErrorCounter = 0;
+				}
+				else
+				{
+					SocketId = -1;
+					PROC_TCP_STATE_SWITCH(PROCESS_TCP_ERROR);
+				}
 			}
 			break;
 		}
@@ -181,7 +178,6 @@ void Uart_4G_Task(void *pvParameters)
 		}
 		case PROCESS_TCP_SLEEP: // 网络休眠状态
 		{
-
 			while (waitForSleepFlag == true)
 			{
 				Uart_4G_Task_Sleep_FLag = true;
@@ -194,7 +190,7 @@ void Uart_4G_Task(void *pvParameters)
 		{
 			vTaskDelay(pdMS_TO_TICKS(1000));
 			tcpErrorCounter++;
-			if (tcpErrorCounter > 60 && TcpSysReboot == 1) // 无法驻网或者联网
+			if (tcpErrorCounter > 60 || TcpSysReboot == 1) // 无法驻网或者联网
 			{
 				Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_ON);
 				vTaskDelay(pdMS_TO_TICKS(2500));
@@ -207,7 +203,6 @@ void Uart_4G_Task(void *pvParameters)
 			{
 				PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
 			}
-
 			break;
 		}
 		}
@@ -217,23 +212,53 @@ static void vTimer1000msCallback(TimerHandle_t pxTimer)
 {
 	uint32 ulTimerID;
 	ulTimerID = (uint32)pvTimerGetTimerID(pxTimer);
+	sint16 *TcpDataFeqPtr =NULL;
+	TcpDataFeqPtr = (sint16 *)&TcpDataFeq;
 	if (ulTimerID == 0)
 	{
-		SendTimerFlg = true;
-		TcpSendTimeCounter++;
+		if(SocketId>=0)
+		{
+			for(uint8 i=2;i<sizeof(TcpDataFeq)/sizeof(sint16);i=i+3)
+			{
+				*(TcpDataFeqPtr+i) = (*(TcpDataFeqPtr+i)-1)<0 ? 0 : (*(TcpDataFeqPtr+i)-1);
+			}
+		}
+		TimeUpdate(&UTC8TimeTcp);
 	}
 }
-sint8 TcpDataSendFunc(sint8 ConnectId)
+static void TcpDataSendFeqHandFunc(uint8* DataIdx)
+{
+	sint16 *TcpDataFeqPtr =NULL;
+	TcpDataFeqPtr = (sint16 *)&TcpDataFeq;
+	for(uint8 i=2;i<sizeof(TcpDataFeq)/sizeof(sint16);i=i+3)
+	{
+		if(*(TcpDataFeqPtr+i)==0)
+		{
+			*DataIdx = *(TcpDataFeqPtr+i-2);
+			*(TcpDataFeqPtr+i) = *(TcpDataFeqPtr+i-1);
+			break;
+		}
+		else
+		{
+			*DataIdx = 0;
+		}
+	}
+	return;
+}
+sint8 TcpDataSendFunc(sint8 ConnectId,uint8 DataSendIdxIn)
 {
 	sint8 outValue = -1;
 	uint32 pSendDataAddr = 0;
 	uint16 DataSendLen = 0;
-	TcpDataEncode(&pSendDataAddr, &DataSendLen); // 数据组包,malloc申请在里面,pSendData指向申请的地址
-	if (DataSendLen == 0)
+	TcpDataEncode(DataSendIdxIn,&pSendDataAddr, &DataSendLen); // 数据组包,malloc申请在里面,pSendData指向申请的地址
+	if(DataSendLen==0)//长度为0 不调用发送数据函数
+	{
+		outValue = 0;
+	}
+	else
 	{
-		return 0; // 暂时无数据可以发
+		outValue = tcpipConnectionSend(ConnectId, (uint8 *)pSendDataAddr, DataSendLen); // 发送函数
 	}
-	outValue = tcpipConnectionSend(ConnectId, (uint8 *)pSendDataAddr, DataSendLen); // 发送函数
 	if (pSendDataAddr != 0)
 	{
 		vPortFree((uint8 *)(pSendDataAddr));
@@ -257,8 +282,8 @@ sint8 tcpipConnectionSend(uint8 TcpConnectId, uint8 *SendDataPtr, uint16 SendDat
 		ret = UART_Query_Data(UART_LPUART1, UART_LPUART1, (uint8 *)AtCmdSend, AtCmdSendTotalLen, UartRecvPtr, &ReadLen, 1000);
 		if (((ret == 0) && (ReadLen > 0) && ((uint8 *)strstr((char *)UartRecvPtr, (char *)(">")))) || 1) // 此IF条件默认通过
 		{
-			UART_Send_Data(UART_LPUART1, (uint8 *)SendDataPtr, SendDataLen, 1000);
-			sint8 ret = AtcmdDelayRecvFunc(UART_LPUART1, (char *)("+CIPSEND"), 2000);
+			UART_Send_Data(UART_LPUART1, (uint8 *)SendDataPtr, SendDataLen, 100);
+			sint8 ret = AtcmdDelayRecvFunc(UART_LPUART1, (char *)("+CIPSEND"), 3000);
 			if (ret == 0)
 			{
 				outValue = 0;
@@ -453,7 +478,7 @@ sint8 TcpRegisterChkFunc(void)
 		}
 	}
 }
-void InitFunc(void)
+sint8 InitFunc(void)
 {
 	// 4G模块初始化
 	uint8 _4G_InitStep = 0;
@@ -464,6 +489,14 @@ void InitFunc(void)
 	uint8 UartRecvPtr[50];
 	uint16 ATerrorCnt = 0;
 	uint8 *retptr = NULL;
+	Dio_LevelType _4G_Status = 0; // 0-关机,1-开机
+	Dio_WriteChannel(DioConf_DioChannel_PTA6_GPIO_OUT_MCU_4G_POW_EN, STD_ON);
+	vTaskDelay(pdMS_TO_TICKS(500));
+	Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_ON);
+	vTaskDelay(pdMS_TO_TICKS(50));
+	Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_OFF);
+	AtcmdDelayRecvFunc(UART_LPUART1, (char *)("SMS DONE"), 10000);
+	_4G_Status = Dio_ReadChannel(DioConf_DioChannel_PTB1_GPIO_IN_MCU_4G_STATUS);
 	while (1)
 	{
 		switch (_4G_InitStep)
@@ -482,7 +515,7 @@ void InitFunc(void)
 				ATerrorCnt++;
 				if (ATerrorCnt > 60 * 5)
 				{
-					SystemSoftwareReset();
+					return -1;
 				}
 			}
 			break;
@@ -586,8 +619,7 @@ void InitFunc(void)
 		}
 		default:
 		{
-			return;
-			break;
+			return 0;
 		}
 		}
 	}
@@ -751,48 +783,14 @@ sint8 at_callbackFunc(char *PSendStr, char *pReadStr, uint8 CmdIdx, uint16 pRead
 	}
 	return OutValue;
 }
-void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
+void TcpDataEncode(uint8 DataIdx,uint32 *PtrSendAddr, uint16 *SendLen)
 {
-	static UTC8TimeType UTC8TimeTcp;
 	uint8 *SendBuffer = NULL;
-	uint8 DataIdx = 0;
-	if ((TcpSendTimeCounter) % (60 * 60) == 1)
-	{
-		DataIdx = VerMsg; // 版本信息发送
-	}
-	else if (TcpSendTimeCounter % 10 == 2)
-	{
-		DataIdx = TruckBattMsg; // 电池信息发送
-	}
-	else if ((TcpSendTimeCounter) % 60 == 3)
-	{
-		DataIdx = TruckVehiMsg; // 车辆信息发送
-	}
-	else if ((TcpSendTimeCounter) % 60 == 4)
-	{
-		DataIdx = TruckAcclMsg; // 累计信息发送
-	}
-	else if ((TcpSendTimeCounter) % 10 == 5)
-	{
-		DataIdx = GpsMsg; // 定位信息发送
-	}
-	else if ((TcpSendTimeCounter) % (60 * 60 * 2) == 6)
-	{
-		DataIdx = 0x01; // 时间校准
-	}
-	else if ((TcpSendTimeCounter) % 10 == 7)
+	memcpy(TcpbattSN, AppConfigInfo.deviceSn, 17);
+	if(UTC8TimeTcp.month==0)
 	{
-		DataIdx = DebugMsg; // 调试信息发送,含FFT结果
+		DataIdx = 0x01;
 	}
-	else
-	{
-		*SendLen = 0;
-		DataIdx = 0; // 不发送,返回
-		return;
-	}
-	memcpy(TcpbattSN, AppConfigInfo.deviceSn, 17);
-	GetUtc8Time(&UTC8TimeTcp); // 时间获取
-	vTaskDelay(pdMS_TO_TICKS(100));
 	switch (DataIdx)
 	{
 	case 0x01: // 时间校准
@@ -802,7 +800,9 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 		uint8 ReadLen = 0;
 		uint8 UartRecvPtr[20];
 		UART_Query_Data(UART_LPUART1, UART_LPUART1, (uint8 *)ATCmdSend, ATCmdSendLen, UartRecvPtr, &ReadLen, pdMS_TO_TICKS(500));
+		GetUtc8Time(&UTC8TimeTcp); // 时间获取
 		*SendLen = 0; // 不发送,长度为0
+		xTimerReset(monitorTimer1000ms,0);
 		return;
 	}
 	case 0x82:
@@ -934,6 +934,8 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 	case DebugMsg:
 	{
 		char rbuf[512]={0};
+		char tmp[13] = {0};
+		memcpy(tmp,BMS_SN,12);
 		DebugMsgtoTcpType DebugMsgInfo;
 		UINT16 DataLen = 0;
 		UINT16 BufferLen = 0;
@@ -942,7 +944,7 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 								{%.2f,%.2f,%.2f,%.2f,%.2f;\
 								%.2f,%.2f,%.2f,%.2f,%.2f,}\
 								{%.2f,%.2f,%.2f,%.2f,%.2f;\
-								%.2f,%.2f,%.2f,%.2f,%.2f,}",
+								%.2f,%.2f,%.2f,%.2f,%.2f,},%s",
 				returnFreq[0][0], returnFreq[0][1], returnFreq[0][2], returnFreq[0][3], returnFreq[0][4],
 				returnP[0][0], returnP[0][1], returnP[0][2], returnP[0][3], returnP[0][4],
 
@@ -950,7 +952,7 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 				returnP[1][0], returnP[1][1], returnP[1][2], returnP[1][3], returnP[1][4],
 
 				returnFreq[2][0], returnFreq[2][1], returnFreq[2][2], returnFreq[2][3], returnFreq[2][4],
-				returnP[2][0], returnP[2][1], returnP[2][2], returnP[2][3], returnP[2][4]);
+				returnP[2][0], returnP[2][1], returnP[2][2], returnP[2][3], returnP[2][4],tmp);
 
 		BufferLen = strlen((const char *)rbuf);
 		*SendLen = BufferLen + sizeof(DebugMsgInfo);
@@ -1052,6 +1054,11 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 	}
 	case 0x91:
 	{
+		if(BMS_CellRecvCounter<128)
+		{
+			*SendLen = 0; // 不发送,长度为0
+			return;
+		}
 		GetCSQValue(&CSQValue);
 		*SendLen = 0x54 + min(BMS_CellTotal, BMS_CELL_MAX_NUM) * 2 + min(BMS_TempTotal, BMS_TEMP_MAX_NUM);
 		SendBuffer = pvPortMalloc(*SendLen);
@@ -1194,29 +1201,97 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 		break;
 	}
 }
-void GetUtc8Time(UTC8TimeType *UTC8TimeTcp)
+void TimeUpdate(UTC8TimeType *UTC8TimeTcpPtr)
+{
+	int year = 0, month = 0, day = 0, hour = 0,minute = 0,second = 0;
+	int lastday = 0;
+
+	year = UTC8TimeTcpPtr->year + 2000;
+	month = UTC8TimeTcpPtr->month;
+	day = UTC8TimeTcpPtr->day;
+	hour = UTC8TimeTcpPtr->hour;
+	minute = UTC8TimeTcpPtr->minute;
+	second = UTC8TimeTcpPtr->second;
+	second+=1;
+	if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
+	{
+		lastday = 31;
+	}
+	else if (month == 4 || month == 6 || month == 9 || month == 11)
+	{
+		lastday = 30;
+	}
+	else
+	{
+		if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))
+			lastday = 29;
+		else
+			lastday = 28;
+	}
+	if(second >=60)
+	{
+		second -=60;
+		minute +=1;
+		if(minute >=60)
+		{
+			minute -=60;
+			hour +=1;
+		}
+	}
+	if (hour >= 24)
+	{
+		hour -= 24;
+		day += 1;
+		if (day > lastday)
+		{
+			day -= lastday;
+			month += 1;
+			if (month > 12)
+			{
+				month -= 12;
+				year += 1;
+			}
+		}
+	}
+	UTC8TimeTcpPtr->year = year - 2000;
+	UTC8TimeTcpPtr->month = month;
+	UTC8TimeTcpPtr->day = day;
+	UTC8TimeTcpPtr->hour = hour;
+	UTC8TimeTcpPtr->minute = minute;
+	UTC8TimeTcpPtr->second = second;
+}
+void GetUtc8Time(UTC8TimeType *UTC8TimeTcpPtr)
 {
 	char *AtCmdAsk = (char *)("AT+CCLK?\r\n");
 	uint8 AtCmdLen = mstrlen(AtCmdAsk);
 	uint16 ReadLen = 0;
 	uint8 *retptr = NULL;
 	uint8 UartRecvPtr[128];
-	UART_Query_Data(UART_LPUART1, UART_LPUART1, (uint8 *)AtCmdAsk, AtCmdLen, UartRecvPtr, &ReadLen, pdMS_TO_TICKS(100));
-	if (ReadLen > 0)
+	uint8 ErrCnt = 0;
+	while(ErrCnt<3)
 	{
-		if ((uint8 *)strstr((char *)UartRecvPtr, (char *)("OK")))
+		UART_Query_Data(UART_LPUART1, UART_LPUART1, (uint8 *)AtCmdAsk, AtCmdLen, UartRecvPtr, &ReadLen, pdMS_TO_TICKS(100));
+		if (ReadLen ==39 )
 		{
-			retptr = (uint8 *)strstr((char *)UartRecvPtr, (char *)("+CCLK:"));
-			if (retptr)
+			if ((uint8 *)strstr((char *)UartRecvPtr, (char *)("OK")))
 			{
-				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));
+				retptr = (uint8 *)strstr((char *)UartRecvPtr, (char *)("+CCLK:"));
+				if (retptr)
+				{
+					UTC8TimeTcpPtr->year = CharToHex(*(retptr + 8)) * 10 + CharToHex(*(retptr + 9));
+					UTC8TimeTcpPtr->month = CharToHex(*(retptr + 11)) * 10 + CharToHex(*(retptr + 12));
+					UTC8TimeTcpPtr->day = CharToHex(*(retptr + 14)) * 10 + CharToHex(*(retptr + 15));
+					UTC8TimeTcpPtr->hour = CharToHex(*(retptr + 17)) * 10 + CharToHex(*(retptr + 18));
+					UTC8TimeTcpPtr->minute = CharToHex(*(retptr + 20)) * 10 + CharToHex(*(retptr + 21));
+					UTC8TimeTcpPtr->second = CharToHex(*(retptr + 23)) * 10 + CharToHex(*(retptr + 24));
+					break;
+				}
 			}
 		}
+		else
+		{
+			ErrCnt++;
+		}
 	}
 }
 static void GetCSQValue(uint8 *out)
@@ -1226,13 +1301,12 @@ static void GetCSQValue(uint8 *out)
 	uint16 ReadLen = 0;
 	uint8 *retptr = NULL;
 	uint8 UartRecvPtr[30];
+	static uint8 CSQValue = 0;
 	UART_Query_Data(UART_LPUART1, UART_LPUART1, (uint8 *)AtCmdAsk, AtCmdLen, UartRecvPtr, &ReadLen, pdMS_TO_TICKS(100));
-	*out = 99;
 	if (ReadLen > 0)
 	{
 		if ((uint8 *)strstr((char *)UartRecvPtr, (char *)("OK")))
 		{
-			*out = 0;
 			retptr = (uint8 *)strstr((char *)UartRecvPtr, (char *)("+CSQ:"));
 			char CsqStr[5];
 			for (uint8 i = 0; i < 5; i++)
@@ -1243,9 +1317,10 @@ static void GetCSQValue(uint8 *out)
 				}
 				memcpy((CsqStr + i), (retptr + i + 6), 1);
 			}
-			*out = atoi(CsqStr);
+			CSQValue = atoi(CsqStr);
 		}
 	}
+	*out = CSQValue;
 	return;
 }
 static void TcpDataInfoRecvHandle(uint8 *DataRecv, uint16 DataRecvLen)

+ 10 - 0
code/app/AppTaskUart1.h

@@ -226,6 +226,16 @@ typedef enum
 	PROCESS_TCP_SLEEP,
 	PROCESS_TCP_ERROR
 } process_Tcp;
+typedef struct
+{
+	sint16 TimeCalibCnt[3];
+	sint16 VersionFeqCnt[3];
+	sint16 TrkBattFeqCnt[3];
+	sint16 GpsFeqCnt[3];
+	sint16 TrkVehichleFeqCnt[3];
+	sint16 TrkAccMsgFeqCnt[3];
+	sint16 DebugMsgFeqCnt[3];
+}TcpFeq_type;
 void Uart_4G_Task(void *pvParameters);
 sint8 tcpipConnectionSend(uint8 TcpConnectId, uint8 *SendDataPtr, uint16 SendDataLen);
 #endif /* APPTASKUART1_H_ */

+ 0 - 28
code/app/lib/AppFuncLib.c

@@ -892,8 +892,6 @@ void fft(real_T *S, uint16_T N, real_T freq, real_T *returnFreq, real_T *returnP
 	creal_T W[SIZE_FFT];
 	real_T Y1[SIZE_FFT];
 
-//	real_T Y2[SIZE_FFT / 2 + 1];
-//	real_T F[SIZE_FFT / 2 + 1];
 	fft_type fft_data[SIZE_FFT / 2 + 1];
     uint16_T i = 0;
     uint16_T j = 0;
@@ -949,32 +947,6 @@ void fft(real_T *S, uint16_T N, real_T freq, real_T *returnFreq, real_T *returnP
     	fft_data[i].freq = freq * i / N;
     }
     // 从大到小 排序
-//    real_T temp;
-//    uint16_T temp_idx;
-//    uint16_T idx[N / 2 + 1];
-//    for (i = 0; i < N / 2 + 1; i++)
-//    {
-//        idx[i] = i;
-//    }
-//
-//    for (j = 0; j < N / 2 + 1; j++) // 比较n-1轮
-//    {
-//        for (k = 0; k < N / 2 - j; k++) // 每轮比较n-1-i次,
-//        {
-//
-//            if (Y2[k] < Y2[k + 1]) // 从大到小
-//            {
-//                temp = Y2[k];
-//                Y2[k] = Y2[k + 1];
-//                Y2[k + 1] = temp;
-//
-//                temp_idx = idx[k];
-//                idx[k] = idx[k + 1];
-//                idx[k + 1] = temp_idx;
-//            }
-//        }
-//    }
-//    // 输出前5个
     qsort(fft_data,sizeof(fft_data) / sizeof(fft_data[0]),sizeof(fft_data[0]),fft_cmp);
     for (i = 0; i < 5; i++)
     {

+ 1 - 1
code/hal/Hal_Var.c

@@ -9,5 +9,5 @@
 
 uint32 hal_1ms_TimerCounter = 0;
 uint32 hal_100ms_TimerCounter = 0;
-boolean IsFeedWdg = false;
+boolean IsFeedWdg = TRUE;
 boolean waitForSleepFlag = false;

+ 37 - 16
code/hal/hal_adapter.c

@@ -21,13 +21,14 @@ TP_Value_Type ConvertedBuffer[NUM_RESULTS];
 Adc_ValueGroupType ResultBuffer[NUM_RESULTS];
 volatile Uart_StatusType Uart_TransmitStatus[3] = {UART_STATUS_TIMEOUT,UART_STATUS_TIMEOUT,UART_STATUS_TIMEOUT};
 QueueHandle_t UartRecvQueue[3];
+QueueHandle_t TcpRecvQueue;
 QueueHandle_t UartSendQueue[3];
 QueueHandle_t UartHalQueueHandle;
 Std_ReturnType UartStartRecvFunc(uint8 channel);
 Std_ReturnType ADC_Converter(Adc_ValueGroupType *Buffer, TP_Value_Type *ConvertedValueR);
 void create_ringBuffer(ringbuffer_t *ringBuf, uint8_t *buf, uint32_t buf_len);
 void clear_ringBuffer(ringbuffer_t *ringBuf);
-uint32_t write_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf);
+uint32_t write_ringBuffer(uint8_t *buffer, uint16_t size, ringbuffer_t *ringBuf,uint32 *uartDataAddr);
 uint32_t read_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf);
 uint8 ringBufferforUart[3][BUFFER_SIZE];
 ringbuffer_t uartRingBuffer[3];
@@ -95,20 +96,20 @@ void clear_ringBuffer(ringbuffer_t *ringBuf)
     ringBuf->bw         = 0;
     ringBuf->btoRead    = 0;
 }
-uint32_t write_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf)
+uint32_t write_ringBuffer(uint8_t *buffer, uint16_t size, ringbuffer_t *ringBuf,uint32 *uartDataAddr)
 {
-    uint32_t len            = 0;
     volatile uint32_t ringBuf_bw     = ringBuf->bw;
     uint32_t ringBuf_len    = ringBuf->length;
     uint8_t *ringBuf_source = ringBuf->source;
-
-    if( (ringBuf_bw + size) > ringBuf_len  )
+    if( (ringBuf_bw + size + 1) > ringBuf_len  )
     {
     	ringBuf_bw = 0;
     }
     memcpy(ringBuf_source + ringBuf_bw, buffer, size);
-    ringBuf->bw = (ringBuf_bw + size) % ringBuf_len;
+    memset(ringBuf_source + ringBuf_bw + size + 1,0x00,1);//环形buffer 插入分隔符截断字符串
+    ringBuf->bw = (ringBuf_bw + size + 1) % ringBuf_len;//数据长度不变,起始地址移位1
     ringBuf->btoRead += size;
+    *uartDataAddr = (uint32)(ringBuf->source + ringBuf->bw - size - 1);
 /*
     if(ringBuf->br!=0)
     {
@@ -174,7 +175,6 @@ Std_ReturnType UART_Query_Data(uint8 transChannel, uint8 recvChannel, uint8 *txB
 		if(Recvret == pdTRUE)
 		{
 			*rxlen = UartRecvMsg.DataLen;
-	//		read_ringBuffer(rxBuffer, queueRecvSize, &uartRingBuffer[recvChannel]);
 			memcpy(rxBuffer,(uint8 *)(UartRecvMsg.dataAddr),UartRecvMsg.DataLen);
 			retVal = E_OK;
 		}
@@ -189,7 +189,7 @@ Std_ReturnType UART_Query_Data(uint8 transChannel, uint8 recvChannel, uint8 *txB
 	}
 	return retVal;
 }
-Std_ReturnType UART_Receive_Data(uint8 recvChannel, uint8 *rxBuffer, uint8 *rxlen, uint32 T_timeout)
+Std_ReturnType UART_Receive_Data(uint8 recvChannel, uint8 *rxBuffer, uint16 *rxlen, uint32 T_timeout)
 {
 	UartMsg_t UartRecvMsg;
 	BaseType_t ret = pdFALSE;
@@ -199,7 +199,21 @@ Std_ReturnType UART_Receive_Data(uint8 recvChannel, uint8 *rxBuffer, uint8 *rxle
 	if(ret == pdTRUE)
 	{
 		*rxlen = UartRecvMsg.DataLen;
-//		read_ringBuffer(rxBuffer, queueRecvSize, &uartRingBuffer[recvChannel]);
+		memcpy(rxBuffer,(uint8 *)UartRecvMsg.dataAddr,UartRecvMsg.DataLen);
+		retVal = E_OK;
+	}
+	return retVal;
+}
+Std_ReturnType Tcp_Receive_Data(uint8 *rxBuffer, uint16 *rxlen, uint32 T_timeout)
+{
+	UartMsg_t UartRecvMsg;
+	BaseType_t ret = pdFALSE;
+	uint32 retVal = E_NOT_OK;
+	*rxlen = 0;
+	ret = xQueueReceive(TcpRecvQueue,&UartRecvMsg,T_timeout);
+	if(ret == pdTRUE)
+	{
+		*rxlen = UartRecvMsg.DataLen;
 		memcpy(rxBuffer,(uint8 *)UartRecvMsg.dataAddr,UartRecvMsg.DataLen);
 		retVal = E_OK;
 	}
@@ -233,13 +247,14 @@ Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8 *txBuffer, uint32
 	 UartRecvQueue[0] = xQueueCreate(6, sizeof(UartMsg_t));
 	 UartRecvQueue[1] = xQueueCreate(6, sizeof(UartMsg_t));
 	 UartRecvQueue[2] = xQueueCreate(6, sizeof(UartMsg_t));
+	 TcpRecvQueue = xQueueCreate(2, sizeof(UartMsg_t));
 	 UartSendQueue[0] = xQueueCreate(3, sizeof(UartMsg_t));
 	 UartSendQueue[1] = xQueueCreate(1, sizeof(UartMsg_t));
 	 UartSendQueue[2] = xQueueCreate(1, sizeof(UartMsg_t));
 	 UartHalQueueHandle = xQueueCreate(9, sizeof(UartHalMsg_t));
 
-	 xTaskCreate(Uart_Hal_RecvTask, (const char *const)"UartRecv", 512, (void *)0, main_TASK_PRIORITY + 5, &Uart_Hal_RecvTask_Handle);
-	 xTaskCreate(Uart_Hal_SendTask, (const char *const)"UartSend", 512, (void *)0, main_TASK_PRIORITY + 4, &Uart_Hal_SendTask_Handle);
+	 xTaskCreate(Uart_Hal_RecvTask, (const char *const)"UartRecv", 256, (void *)0, main_TASK_PRIORITY + 5, &Uart_Hal_RecvTask_Handle);
+	 xTaskCreate(Uart_Hal_SendTask, (const char *const)"UartSend", 256, (void *)0, main_TASK_PRIORITY + 4, &Uart_Hal_SendTask_Handle);
  }
  Std_ReturnType UartStartRecvFunc(uint8 channel)
  {
@@ -312,13 +327,19 @@ Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8 *txBuffer, uint32
 			  {
 					if(UartHalMsgRecv.value>0)
 					{
-						recvSize = write_ringBuffer(RX_Buffer[UartHalMsgRecv.Channel],UartHalMsgRecv.value,&uartRingBuffer[UartHalMsgRecv.Channel]);
+						recvSize = write_ringBuffer(RX_Buffer[UartHalMsgRecv.Channel],UartHalMsgRecv.value,&uartRingBuffer[UartHalMsgRecv.Channel],&(UartRecvMsg.dataAddr));
 						UartRecvMsg.DataLen = UartHalMsgRecv.value;
-						UartRecvMsg.dataAddr = (uint32)(uartRingBuffer[UartHalMsgRecv.Channel].bw + uartRingBuffer[UartHalMsgRecv.Channel].source - UartHalMsgRecv.value);
-						ret_send = xQueueSend(UartRecvQueue[UartHalMsgRecv.Channel],&UartRecvMsg,10);
+						if(UartHalMsgRecv.Channel==1 && strstr((char *)UartRecvMsg.dataAddr, (char *)("RECV FROM")))//网络接收数据放入其他队列
+						{
+							ret_send = xQueueSend(TcpRecvQueue,&UartRecvMsg,10);
+						}
+						else
+						{
+							ret_send = xQueueSend(UartRecvQueue[UartHalMsgRecv.Channel],&UartRecvMsg,10);
+						}
+						T_timeout[UartHalMsgRecv.Channel] = 0;
+						UartState[UartHalMsgRecv.Channel] = UartRecvComplete;
 					}
-					T_timeout[UartHalMsgRecv.Channel] = 0;
-					UartState[UartHalMsgRecv.Channel] = UartRecvComplete;
 			  }
 		  }
 	 }

+ 4 - 3
code/hal/hal_adapter.h

@@ -244,15 +244,16 @@ Std_ReturnType ADC_ReadValue(void);
 sint8 AtcmdDelayRecvFunc(uint8 recvChannel, char *ResultStrPtr, uint16 delayTime);
 Std_ReturnType UART_Query_Data(uint8 transChannel, uint8 recvChannel, uint8 *txBuffer, uint16 sendLength, uint8 *rxBuffer, uint16 *rxlen, uint32 T_timeout);
 Std_ReturnType UART_Send_Data(uint8 transChannel, const uint8 *txBuffer, uint32 sendLength, uint32 T_timeout);
-Std_ReturnType UART_Receive_Data(uint8 recvChannel, uint8 *rxBuffer, uint8 *rxlen, uint32 T_timeout);
+Std_ReturnType UART_Receive_Data(uint8 recvChannel, uint8 *rxBuffer, uint16 *rxlen, uint32 T_timeout);
+Std_ReturnType Tcp_Receive_Data(uint8 *rxBuffer, uint16 *rxlen, uint32 T_timeout);
 Std_ReturnType UART_Reset(uint8 recvChannel);
 void UART_Callback(uint32 hwInstance, Lpuart_Uart_Ip_EventType event);
 void UartInit(void);
 void SystemSoftwareReset(void);
 void create_ringBuffer(ringbuffer_t *ringBuf, uint8_t *buf, uint32_t buf_len);
 void clear_ringBuffer(ringbuffer_t *ringBuf);
-uint32_t write_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf);
-uint32_t read_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf);
+//uint32_t write_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf);
+//uint32_t read_ringBuffer(uint8_t *buffer, uint32_t size, ringbuffer_t *ringBuf);
 
 void coreInit(void);
 void SystemModulesInit(void);

+ 3 - 5
code/main.c

@@ -72,7 +72,7 @@ int main(void)
 	volatile int exit_code = 0;
 	coreInit();
 	SystemModulesInit();
-
+	displayResetReasonWithLED();
 #ifdef SEGGER_SYSTEMVIEW
 	SEGGER_SYSVIEW_Conf();
 	SEGGER_SYSVIEW_Start();
@@ -82,11 +82,9 @@ int main(void)
 	cm_backtrace_init(APPNAME, HARDWARE_VERSION, SOFTWARE_VERSION);
 	SEGGER_RTT_printf("boot\n");
 #endif
-
-	displayResetReasonWithLED();
 	UartInit();
-	xTaskCreate(MainTask, (const char *const)"MainTask", 512, (void *)0, main_TASK_PRIORITY + 6, MainTask_Handle);
-//	xTaskCreate(Uart0Task, (const char *const)"Uart0_Bms_Task", 512, (void *)0, main_TASK_PRIORITY + 2, Uart0Task_Handle);
+	xTaskCreate(MainTask, (const char *const)"MainTask", 512, (void *)0, main_TASK_PRIORITY + 6, &MainTask_Handle);
+	//xTaskCreate(Uart0Task, (const char *const)"Uart0_Bms_Task", 512, (void *)0, main_TASK_PRIORITY + 2, Uart0Task_Handle);
 	xTaskCreate(CanTask, (const char *const)"CanTask", 512, (void *)0, main_TASK_PRIORITY + 2, &CanTask_Handle);
 	xTaskCreate(GpsTask, (const char *const)"GpsTask", 2048, (void *)0, main_TASK_PRIORITY + 1, &GpsTask_Handle);
 	xTaskCreate(Uart_4G_Task, (const char *const)"Uart_4G_Task", 2048, (void *)0, main_TASK_PRIORITY + 0, &Uart_4G_Task_Handle);