ソースを参照

发送代码更改测试

LAPTOP-KB7QFH2U\ChenJie-PC 1 年間 前
コミット
56f3438146

+ 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

+ 12 - 17
Project_Settings/Linker_Files/linker_flash_s32k146.ld

@@ -31,18 +31,13 @@
 
 MEMORY
 {         
-    int_flash_interrupts    : ORIGIN = 0x00014200, LENGTH = 0x00000400    /* 1K */    /* Do not change this section */
-   /* int_flash_config        : ORIGIN = 0x00000400, LENGTH = 0x00000010    /* 16bytes */ /* Do not change this section */
-     int_flash               : ORIGIN = 0x00014600, LENGTH = 0x000EBA00    /* ~1.0MB */ 
-/*	int_flash_interrupts    : ORIGIN = 0x00080200, LENGTH = 0x00000400	/**/
-/*	int_flash               : ORIGIN = 0x00080600, LENGTH = 0x0007FA00	/**/
-	
-	m_flexram				: ORIGIN = 0x14000000, LENGTH = 0x00001000	
+    int_flash_interrupts    : ORIGIN = 0x00000000, LENGTH = 0x00000400    /* 1K */    /* Do not change this section */
+    int_flash_config        : ORIGIN = 0x00000400, LENGTH = 0x00000010    /* 16bytes */ /* Do not change this section */
+    int_flash               : ORIGIN = 0x00000410, LENGTH = 0x000FFBF0    /* ~1.0MB */ 
     int_sram_results        : ORIGIN = 0x1FFF0000, LENGTH = 0x00000100    /* 256bytes */
     int_sram                : ORIGIN = 0x1FFF0100, LENGTH = 0x0001DF00    /* ~120K */
-    int_sram_stack_c0       : ORIGIN = 0x2000E000, LENGTH = 0x00001000 - 0x10    /* 4K  */
-    ram_rsvd2               : ORIGIN = 0x2000EFF0, LENGTH = 0             /* End of SRAM */
-    ExchangeInfo            : ORIGIN = 0x2000EFF0, LENGTH = 0x10          
+    int_sram_stack_c0       : ORIGIN = 0x2000E000, LENGTH = 0x00001000    /* 4K  */
+    ram_rsvd2               : ORIGIN = 0x2000F000, LENGTH = 0             /* End of SRAM */
 }
 
 
@@ -56,19 +51,20 @@ SECTIONS
    {						
     	*(.eeprom)			
     } >m_flexram			
+    
 	.flash_interrupts :
 	{
-		. = ALIGN(512);
+		. = ALIGN(4096);
         __interrupts_rom_start = .;
         KEEP(*(.intc_vector))    
-        . = ALIGN(512);
+        . = ALIGN(4);
         __interrupts_rom_end = .;
 	} > int_flash_interrupts
 	
-/*	.flash_config :				*/
-/*	{							*/
-/*		KEEP(*(.flash_config))	*/
-/*	} > int_flash_config		*/
+	.flash_config :
+	{
+		KEEP(*(.flash_config))
+	} > int_flash_config
 	
 	.flash :
 	{
@@ -115,7 +111,6 @@ SECTIONS
 		__DATA_ROM = .;
 	} > int_flash
     
-    
     . = ALIGN(4);
     PROVIDE(__exidx_start = .);
     .ARM.exidx :

+ 17 - 12
Project_Settings/Linker_Files/linker_flash_s32k146.ldfls → Project_Settings/Linker_Files/linker_flash_s32k146.ldota

@@ -31,13 +31,18 @@
 
 MEMORY
 {         
-    int_flash_interrupts    : ORIGIN = 0x00000000, LENGTH = 0x00000400    /* 1K */    /* Do not change this section */
-    int_flash_config        : ORIGIN = 0x00000400, LENGTH = 0x00000010    /* 16bytes */ /* Do not change this section */
-    int_flash               : ORIGIN = 0x00000410, LENGTH = 0x000FFBF0    /* ~1.0MB */ 
+    int_flash_interrupts    : ORIGIN = 0x00014200, LENGTH = 0x00000400    /* 1K */    /* Do not change this section */
+   /* int_flash_config        : ORIGIN = 0x00000400, LENGTH = 0x00000010    /* 16bytes */ /* Do not change this section */
+     int_flash               : ORIGIN = 0x00014600, LENGTH = 0x000EBA00    /* ~1.0MB */ 
+/*	int_flash_interrupts    : ORIGIN = 0x00080200, LENGTH = 0x00000400	/**/
+/*	int_flash               : ORIGIN = 0x00080600, LENGTH = 0x0007FA00	/**/
+	
+	m_flexram				: ORIGIN = 0x14000000, LENGTH = 0x00001000	
     int_sram_results        : ORIGIN = 0x1FFF0000, LENGTH = 0x00000100    /* 256bytes */
     int_sram                : ORIGIN = 0x1FFF0100, LENGTH = 0x0001DF00    /* ~120K */
-    int_sram_stack_c0       : ORIGIN = 0x2000E000, LENGTH = 0x00001000    /* 4K  */
-    ram_rsvd2               : ORIGIN = 0x2000F000, LENGTH = 0             /* End of SRAM */
+    int_sram_stack_c0       : ORIGIN = 0x2000E000, LENGTH = 0x00001000 - 0x10    /* 4K  */
+    ram_rsvd2               : ORIGIN = 0x2000EFF0, LENGTH = 0             /* End of SRAM */
+    ExchangeInfo            : ORIGIN = 0x2000EFF0, LENGTH = 0x10          
 }
 
 
@@ -51,20 +56,19 @@ SECTIONS
    {						
     	*(.eeprom)			
     } >m_flexram			
-    
 	.flash_interrupts :
 	{
-		. = ALIGN(4096);
+		. = ALIGN(512);
         __interrupts_rom_start = .;
         KEEP(*(.intc_vector))    
-        . = ALIGN(4);
+        . = ALIGN(512);
         __interrupts_rom_end = .;
 	} > int_flash_interrupts
 	
-	.flash_config :
-	{
-		KEEP(*(.flash_config))
-	} > int_flash_config
+/*	.flash_config :				*/
+/*	{							*/
+/*		KEEP(*(.flash_config))	*/
+/*	} > int_flash_config		*/
 	
 	.flash :
 	{
@@ -111,6 +115,7 @@ SECTIONS
 		__DATA_ROM = .;
 	} > int_flash
     
+    
     . = ALIGN(4);
     PROVIDE(__exidx_start = .);
     .ARM.exidx :

+ 2 - 2
code/app/AppGlobalVar.c

@@ -16,7 +16,7 @@
 
 #include "AppGlobalVar.h"
 
-#define defaultSn "ZLTEST00000000001"
+#define defaultSn "GYTEST00000000001"
 
 #define EEP_START_SEC_VAR_INIT_8_NO_CACHEABLE
 #include "Eep_MemMap.h"
@@ -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;

+ 188 - 136
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,26 @@ 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,1,0},{0x82,1,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 +61,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 +74,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 +99,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 +131,6 @@ void Uart_4G_Task(void *pvParameters)
 				if (ConnectRet > 0)
 				{
 					PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
-					TcpSendTimeCounter = 0;
 				}
 				else
 				{
@@ -153,16 +142,22 @@ void Uart_4G_Task(void *pvParameters)
 		case PROCESS_TCP_SEND: // 网络数据发送
 		{
 			sint8 SendRet = -1;
-			SendRet = TcpDataSendFunc(SocketId);
-			if (SendRet == 0)
+			uint8 DataSendIdx = 0;
+			//发送判定
+			TcpDataSendFeqHandFunc(&DataSendIdx);
+			if(DataSendIdx!=0)//有数据发送
 			{
-				PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
-				tcpErrorCounter = 0;
-			}
-			else
-			{
-				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 +176,6 @@ void Uart_4G_Task(void *pvParameters)
 		}
 		case PROCESS_TCP_SLEEP: // 网络休眠状态
 		{
-
 			while (waitForSleepFlag == true)
 			{
 				Uart_4G_Task_Sleep_FLag = true;
@@ -194,7 +188,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 +201,6 @@ void Uart_4G_Task(void *pvParameters)
 			{
 				PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
 			}
-
 			break;
 		}
 		}
@@ -217,23 +210,56 @@ 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指向申请的地址
+#ifdef SEGGER_RTT_PRINTF
+	SEGGER_RTT_printf("sendFeq:T_%d,Idx_%02X,Len_%d\n",TimerCounter,DataSendIdxIn,DataSendLen);
+#endif
+	if(DataSendLen==0)//长度为0 不调用发送数据函数
 	{
-		return 0; // 暂时无数据可以发
+		outValue = 0;
+	}
+	else
+	{
+		outValue = tcpipConnectionSend(ConnectId, (uint8 *)pSendDataAddr, DataSendLen); // 发送函数
 	}
-	outValue = tcpipConnectionSend(ConnectId, (uint8 *)pSendDataAddr, DataSendLen); // 发送函数
 	if (pSendDataAddr != 0)
 	{
 		vPortFree((uint8 *)(pSendDataAddr));
@@ -257,8 +283,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;
@@ -275,6 +301,9 @@ sint8 tcpipConnectionSend(uint8 TcpConnectId, uint8 *SendDataPtr, uint16 SendDat
 			sendErrConuter++;
 		}
 	}
+#ifdef SEGGER_RTT_PRINTF
+	SEGGER_RTT_printf("[%d]-%d-%d-%d\n",__LINE__,TimerCounter,sendErrConuter,SendDataLen);
+#endif
 	return outValue;
 }
 sint8 TcpConnectFunc(sint8 *ConnectId)
@@ -453,7 +482,7 @@ sint8 TcpRegisterChkFunc(void)
 		}
 	}
 }
-void InitFunc(void)
+sint8 InitFunc(void)
 {
 	// 4G模块初始化
 	uint8 _4G_InitStep = 0;
@@ -464,6 +493,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 +519,7 @@ void InitFunc(void)
 				ATerrorCnt++;
 				if (ATerrorCnt > 60 * 5)
 				{
-					SystemSoftwareReset();
+					return -1;
 				}
 			}
 			break;
@@ -586,8 +623,7 @@ void InitFunc(void)
 		}
 		default:
 		{
-			return;
-			break;
+			return 0;
 		}
 		}
 	}
@@ -751,67 +787,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;
-	uint16 GpsFeq = 10;
-	if(DeviceSpeed==0)
-	{
-		GpsFeq = 3600;
-	}
-	else if(DeviceSpeed>0 && DeviceSpeed<=100)
-	{
-		GpsFeq = 60;
-	}
-	else if(DeviceSpeed>100 && DeviceSpeed<=200)
-	{
-		GpsFeq = 10;
-	}
-	else if(DeviceSpeed>200)
-	{
-		GpsFeq = 1;
-	}
-
-	GpsFeq = Saturation_u(GpsFeq,1,3600);
-	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) % GpsFeq == 0)
-	{
-		DataIdx = GpsMsg; // 定位信息发送
-	}
-	else if ((TcpSendTimeCounter) % (60 * 60 * 2) == 6)
-	{
-		DataIdx = 0x01; // 时间校准
-	}
-	else if ((TcpSendTimeCounter) % 10 == 7)
-	{
-		DataIdx = DebugMsg; // 调试信息发送,含FFT结果
-	}
-	else
+	memcpy(TcpbattSN, AppConfigInfo.deviceSn, 17);
+	if(UTC8TimeTcp.month==0)
 	{
-		*SendLen = 0;
-		DataIdx = 0; // 不发送,返回
-		return;
+		DataIdx = 0x01;
 	}
-	memcpy(TcpbattSN, AppConfigInfo.deviceSn, 17);
-	GetUtc8Time(&UTC8TimeTcp); // 时间获取
-	vTaskDelay(pdMS_TO_TICKS(100));
 	switch (DataIdx)
 	{
 	case 0x01: // 时间校准
@@ -821,7 +804,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:
@@ -972,10 +957,6 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
 				returnP[2][0], returnP[2][1], returnP[2][2], returnP[2][3], returnP[2][4]);
 
 		BufferLen = strlen((const char *)rbuf);
-#ifdef SEGGER_RTT_PRINTF
-			SEGGER_RTT_printf("[%d]BufferLen=%d\r\n",__LINE__,BufferLen);
-			SEGGER_RTT_printf("[%d]rbuf=%s\r\n",__LINE__,rbuf);
-#endif
 		*SendLen = BufferLen + sizeof(DebugMsgInfo);
 		SendBuffer = pvPortMalloc(*SendLen);
 		memcpy(SendBuffer + sizeof(DebugMsgInfo) - 1, rbuf, BufferLen);
@@ -1217,29 +1198,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)
@@ -1249,13 +1298,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++)
@@ -1266,9 +1314,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)
@@ -1278,6 +1327,9 @@ static void TcpDataInfoRecvHandle(uint8 *DataRecv, uint16 DataRecvLen)
 	uint8 TcpCmdAnswer[50] = {0};
 	uint16 TcpDataLen = 0;
 	uint16 NumCalTemp = 1;
+#ifdef SEGGER_RTT_PRINTF
+	SEGGER_RTT_printf("[%d]-%s\r\n",__LINE__,DataRecv);
+#endif
 	retptr = (uint8 *)strstr((char *)DataRecv, (char *)("\r\n##"));
 	if (retptr == NULL || DataRecvLen < 5)
 		return;

+ 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_ */

+ 33 - 18
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,6 +247,7 @@ 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));
@@ -312,19 +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);
-#ifdef SEGGER_RTT_PRINTF1
-						if(UartHalMsgRecv.Channel==1)
+						if(UartHalMsgRecv.Channel==1 && strstr((char *)UartRecvMsg.dataAddr, (char *)("RECV FROM")))//网络接收数据放入其他队列
 						{
-							SEGGER_RTT_printf("[%d]source=%X,dataAddr=%s\r\n",__LINE__,uartRingBuffer[UartHalMsgRecv.Channel].source,(uint8 *)UartRecvMsg.dataAddr);
+							ret_send = xQueueSend(TcpRecvQueue,&UartRecvMsg,10);
 						}
-#endif
+						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

@@ -241,15 +241,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);