zack vor 1 Jahr
Ursprung
Commit
7ac8ba6d39
11 geänderte Dateien mit 203 neuen und 103 gelöschten Zeilen
  1. 1 1
      Core/Inc/ConfigMacros.h
  2. 1 1
      Core/Inc/database.h
  3. 2 0
      Core/Inc/tt808.h
  4. 67 22
      Core/Src/database.c
  5. 32 23
      Core/Src/freertos.c
  6. 1 1
      Core/Src/main.c
  7. 5 5
      Core/Src/mba32a.c
  8. 9 9
      Core/Src/ml307a.c
  9. 82 39
      Core/Src/tt808.c
  10. 1 0
      Core/Src/usart.c
  11. 2 2
      MDK-ARM/dtu.uvoptx

+ 1 - 1
Core/Inc/ConfigMacros.h

@@ -57,7 +57,7 @@
 #define MessageID_authentication	0x0102 //牖�
 #define MessageID_heartbeat			0x0002 //陑泐
 #define MessageID_location			0x0200 //華硊
-#define MessageID_Retrans			0x0704 //華硊
+#define MessageID_Retrans			0x0704 //華硊硃換
 #define TCPJMFSRSA  0x001
 #define TCPJMFSNULL 0x000
 

+ 1 - 1
Core/Inc/database.h

@@ -11,7 +11,7 @@ void Database_init(uint16_t pushsize_loc, uint16_t pullsize_loc,uint16_t pushsiz
 
 void Database_Push(uint8_t ptr);
 
-void TestPrintStruct(DatabaseLoc *ptr,uint8_t temp);
+void TestPrintStruct(DatabaseLoc *ptr,uint8_t temppush,uint8_t temppull);
 
 extern DatabaseLoc *dblocptr;
 extern DatabaseEvent *dbeveptr;

+ 2 - 0
Core/Inc/tt808.h

@@ -24,9 +24,11 @@ void hexArrayToBcd(uint8_t* array, size_t length, uint8_t* out);
 
 
 void Regular_reporting_Loc(void);
+void pushpullWork(void);
 extern bool Retrans;
 
 extern bool Offline ;
 
+extern bool Online;
 #endif /*__TT808_H*/
 

+ 67 - 22
Core/Src/database.c

@@ -21,6 +21,15 @@ bool MiddleObj =false;
   */
 void Database_init(uint16_t pushsize_loc, uint16_t pullsize_loc,uint16_t pushsize_eve, uint16_t pullsize_eve)
 {
+	dblocptr->location.alarmFlag=0x00000000;
+	dblocptr->location.statusFlag=0x00000002;
+	dblocptr->location.height=0x0000;
+	dblocptr->location.direction=0x0000;
+	dblocptr->location.signalCmd=0x30;
+	dblocptr->location.signalCmd_len=0x01;
+	dblocptr->location.atellitesCmd=0x31;
+	dblocptr->location.atellitesCmd_len=0x01;
+	
 	Flash_ReadBytes((uint16_t*)&(dblocptr->temppush.loc_pushIndex),LocDbHeadStart,4);//读取loc头部是否发生写入
 	if(dblocptr->temppush.loc_pullIndex == 0xFFFF && dblocptr->temppush.loc_pushIndex==0xFFFF)//未写入
 	{
@@ -68,34 +77,45 @@ void Database_Push(uint8_t object)
 {
 	if(object==0)//位置信息写入
 	{
-		if(dblocptr->headinfo.loc_pushIndex!=0)
+		if(dblocptr->temppush.loc_pushIndex!=0)
 		{
-			if(dblocptr->temppush.latitude != dblocptr->location.latitude && dblocptr->temppush.longitude != dblocptr->location.longitude)//相同纬度参数(包含未获取定位为0)
+			if((dblocptr->location.latitude-dblocptr->temppush.latitude >15) || (dblocptr->location.longitude-dblocptr->temppush.longitude >15))//乘以倍数后,差距大于15
 			{
-				Flash_WriteBytes((uint16_t*)&(dblocptr->location.alarmFlag),LocDbBodyStart + (dblocptr->headinfo.loc_pushIndex*34),17);
-				Flash_ReadBytes((uint16_t*)&(dblocptr->temppush.alarmFlag),LocDbBodyStart + ((dblocptr->headinfo.loc_pushIndex-1)*34),17);//读取body信息
-				printf("入库操作,当前索引%d\r\n",dblocptr->headinfo.loc_pushIndex);
-				TestPrintStruct(dblocptr,1);//读取Temp
+				PushSta = Flash_WriteBytes((uint16_t*)&(dblocptr->location.alarmFlag),LocDbBodyStart + (dblocptr->headinfo.loc_pushIndex*34),17);
+				TestPrintStruct(dblocptr,1,0);//读取Temp
 				dblocptr->headinfo.loc_pushIndex+=1;
 				Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度
 			}
-
+			else
+			{
+				printf("经纬度差距过小不进行写入!\r\nlat:%08X/lon:%08X\r\nlat:%08X/lon:%08XN\r\n",dblocptr->temppush.latitude,dblocptr->temppush.longitude,dblocptr->location.latitude,dblocptr->location.longitude);
+			}
+			Flash_ReadBytes((uint16_t*)&(dblocptr->temppush.alarmFlag),LocDbBodyStart + ((dblocptr->headinfo.loc_pushIndex-1)*34),17);//读取body信息
 		}
 
 		else if(dblocptr->location.latitude!=0 && dblocptr->headinfo.loc_pushIndex==0)//判断定位是否正常工作
 		{		
-			Flash_WriteBytes((uint16_t*)&(dblocptr->location.alarmFlag),LocDbBodyStart,17);//34
+			PushSta = Flash_WriteBytes((uint16_t*)&(dblocptr->location.alarmFlag),LocDbBodyStart,17);//34
+			printf("首次写入,->%d\r\n",dblocptr->temppush.loc_pushIndex);
 			dblocptr->headinfo.loc_pushIndex+=1;
 			Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度
+			Flash_ReadBytes((uint16_t*)&(dblocptr->temppush.loc_pushIndex),LocDbHeadStart,4);//读取loc头部写入信息
 		}
+		
 	}
-
-						
-	TestPrintStruct(dblocptr,0);//读取Work
-	Flash_ReadBytes((uint16_t*)&(dblocptr->temppush.loc_pushIndex),LocDbHeadStart,4);//读取loc头部写入信息
+	if(dblocptr->location.latitude!=0)
+	{
+		TestPrintStruct(dblocptr,0,0);//读取Worknow
+		Flash_ReadBytes((uint16_t*)&(dblocptr->temppush.loc_pushIndex),LocDbHeadStart,4);//读取loc头部写入信息
+		if(PushSta==HAL_OK)
+		{
+			printf("写入%d完成,准备写入->%d\r\n",dblocptr->headinfo.loc_pushIndex-1,dblocptr->temppush.loc_pushIndex);
+		}
+	}
+	
 	if(dblocptr->temppush.loc_pushIndex == dblocptr->headinfo.loc_pushSize)//入库结束(返回
 	{
-		printf("入库操作,当前索引%d,达边界值返回覆写\r\n",dblocptr->headinfo.loc_pushIndex);
+		printf("@@入库操作,当前索引%d,达边界值返回覆写\r\n",dblocptr->headinfo.loc_pushIndex);
 		dblocptr->headinfo.loc_pushIndex=0;
 		Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度
 	}
@@ -107,31 +127,32 @@ void Database_Pull(uint8_t object)
 	if(object==0)//位置信息出库
 	{
 		Flash_ReadBytes((uint16_t*)&(dblocptr->headinfo.loc_pushIndex),LocDbHeadStart,4);//读取loc头部写入信息
-		printf("出库操作,共出库%d当前索引%d\r\n",dblocptr->headinfo.loc_pushIndex,dblocptr->headinfo.loc_pushIndex);
+		printf("@@出库操作,应出库%d当前索引%d\r\n",dblocptr->headinfo.loc_pushIndex,dblocptr->headinfo.loc_pullIndex);
 		
-		if(dblocptr->headinfo.loc_pushIndex!=0 || dblocptr->temppull.alarmFlag!=0xFFFFFFFF)//库内有数据
+		if(dblocptr->headinfo.loc_pushIndex != dblocptr->headinfo.loc_pullIndex)//库内有数据
 		{
-			Flash_ReadBytes((uint16_t*)&(dblocptr->temppull.alarmFlag),LocDbBodyStart,17);//读取出库body信息
+			Flash_ReadBytes((uint16_t*)&(dblocptr->temppull.alarmFlag),LocDbBodyStart + ((dblocptr->headinfo.loc_pullIndex)*34),17);//读取出库body信息
+			TestPrintStruct(dblocptr,2,1);//读取pullTemp
 			dblocptr->headinfo.loc_pullIndex+=1;
 			Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度
 			Retrans = true;
 		}
-		if(dblocptr->temppull.alarmFlag==0xFFFFFFFF)
+		else
 		{
-			dblocptr->headinfo.loc_pullIndex=0;
 			dblocptr->headinfo.loc_pushIndex=0;
+			dblocptr->headinfo.loc_pullIndex=0;
 			Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度
+			printf("@@出库完成,库内数据更新\r\n");
 			Retrans = false;
 		}
-		MiddleObj = true;
 	}
 }
 
 
 
-void TestPrintStruct(DatabaseLoc *ptr,uint8_t temppush)
+void TestPrintStruct(DatabaseLoc *ptr,uint8_t temppush,uint8_t temppull)
 {
-	if(temppush)
+	if(temppush==1)
 	{
 		printf("temp:%08X%08X%08X%08X%04X%04X%04X%d%d%d%d%d%d%02X%02X%02X%02X%02X%02X\r\n", \
 		ptr->temppush.alarmFlag, \
@@ -154,7 +175,7 @@ void TestPrintStruct(DatabaseLoc *ptr,uint8_t temppush)
 		ptr->temppush.atellitesCmd_len, \
 		ptr->temppush.satellitesNum);
 	}
-	else
+	else if(temppush==0)
 	{
 		printf("now :%08X%08X%08X%08X%04X%04X%04X%d%d%d%d%d%d%02X%02X%02X%02X%02X%02X\r\n", \
 		ptr->location.alarmFlag, \
@@ -177,6 +198,30 @@ void TestPrintStruct(DatabaseLoc *ptr,uint8_t temppush)
 		ptr->location.atellitesCmd_len, \
 		ptr->location.satellitesNum);
 	}
+	else if(temppull==1)
+	{
+		printf("temp:%08X%08X%08X%08X%04X%04X%04X%d%d%d%d%d%d%02X%02X%02X%02X%02X%02X\r\n", \
+		ptr->temppull.alarmFlag, \
+		ptr->temppull.statusFlag, \
+		ptr->temppull.latitude, \
+		ptr->temppull.longitude, \
+		ptr->temppull.height, \
+		ptr->temppull.speed, \
+		ptr->temppull.direction, \
+		ptr->temppull.timeBCD[0], \
+		ptr->temppull.timeBCD[1], \
+		ptr->temppull.timeBCD[2], \
+		ptr->temppull.timeBCD[3], \
+		ptr->temppull.timeBCD[4], \
+		ptr->temppull.timeBCD[5], \
+		ptr->temppull.signalCmd, \
+		ptr->temppull.signalCmd_len, \
+		ptr->temppull.CSQ, \
+		ptr->temppull.atellitesCmd, \
+		ptr->temppull.atellitesCmd_len, \
+		ptr->temppull.satellitesNum);
+	}
+
 }
 
 

+ 32 - 23
Core/Src/freertos.c

@@ -155,14 +155,17 @@ void StartScanKeyTask(void const * argument)
   for(;;)
   {
     osDelay(1);
-	ReMIPURC();
+	  
+	  
 	updatekeystate(); 				//扫描键值
     Jump_interface(); 		    	//跳转界面
     OLED_Refresh(); 				//刷新界面
+	ReU5Proces();
+	  
+	  
+	  
+	  
 	
-	RESET_4G_MODULE();				//4G启动(复位) 标志位->reset4Gmodule
-	Pre_processing_4G();			//4G传递准备   标志位->module4G_F
-	//Lock_OandC();					//施解封
 	//*开发者
 	if(Developer_PortalA==1 && Developer_PortalD==4)
 	{
@@ -179,8 +182,6 @@ void StartScanKeyTask(void const * argument)
 		refresh=true;
 	 }
 
-	ReU4Proces();
-	ReU5Proces();
 
 	 
 	 
@@ -202,11 +203,13 @@ void StarBT4GTask(void const * argument)
   /* Infinite loop */
   for(;;)
   {
-    osDelay(10000);	
+    osDelay(1);	
 	{
-#if openUpload == 1
-		Regular_reporting_Loc();//30s 上报地址  10s 入库(掉线)
-#endif
+		//Printf_u4u5logbyU1();			//打印log0
+		ReMIPURC();						//各式接收处理1
+		ReU4Proces();					//2
+		MIPURCHandle();					//平台接收处理(鉴权应答等)3
+		
 	}
 
   }
@@ -227,16 +230,12 @@ void StartTestTask(void const * argument)
   /* Infinite loop */
   for(;;)
   {
-    osDelay(8000);    
-	if(MgnssFlag)
-	{	
-#if openUpload == 1
-//		USART_SendString(&huart4, "AT+CSQ\r\n");
-//		HAL_Delay(100);
-//		USART_SendString(&huart4, "AT+MGNSSLOC\r\n");
-#endif
-	}
-
+    osDelay(1);    
+	RESET_4G_MODULE();				//4G启动(复位) 标志位->reset4Gmodule
+	Pre_processing_4G();			//4G传递准备   标志位->module4G_F
+	pushpullWork();
+	  
+	
 
   }
   /* USER CODE END StartTestTask */
@@ -255,10 +254,20 @@ void StartloginfoTaskTask(void const * argument)
   /* Infinite loop */
   for(;;)
   {
-    osDelay(1);
-	MIPURCHandle();					//平台接收处理
-	Printf_u4u5logbyU1();//打印log
+    osDelay(8000);
+#if openUpload == 1
+	if(MgnssFlag)
+	{	
+		USART_SendString(&huart4, "AT+CSQ\r\n");
+		HAL_Delay(100);
+		USART_SendString(&huart4, "AT+MGNSSLOC\r\n");
+	}
+    osDelay(1900);	
 
+	
+	Regular_reporting_Loc();//30s 上报地址  10s 入库(掉线)
+#endif
+		
   }
   /* USER CODE END StartloginfoTaskTask */
 }

+ 1 - 1
Core/Src/main.c

@@ -124,7 +124,7 @@ int main(void)
   __HAL_UART_ENABLE_IT(&huart5, UART_IT_RXNE);//¿ªÆôBT½ÓÊÕÖжÏ
 
   START_PROCESS();
-  Database_init(0x5,0x5,0x5,0x5);
+  Database_init(0x760,0x760,0x5,0x5);
   
   MBA32A_Init();
   reset4Gmodule = true;

+ 5 - 5
Core/Src/mba32a.c

@@ -115,7 +115,7 @@ void MBA32A_Init(void)
 			}
 			else
 			{	//ERROR 其他值
-				MBA32AReset();
+				//MBA32AReset();
 				break;
 			}
 		}
@@ -131,7 +131,7 @@ void MBA32A_Init(void)
 			}
 			else
 			{	//ERROR 其他值
-				MBA32AReset();
+				//MBA32AReset();
 				break;
 			}
 		}
@@ -147,7 +147,7 @@ void MBA32A_Init(void)
 			}
 			else
 			{	//ERROR 其他值
-				MBA32AReset();
+				//MBA32AReset();
 				break;
 			}
 		}
@@ -166,7 +166,7 @@ void MBA32A_Init(void)
 			}
 			else
 			{	//ERROR 其他值
-				MBA32AReset();
+				//MBA32AReset();
 				break;
 			}
 		}
@@ -184,7 +184,7 @@ void USART_SendString(UART_HandleTypeDef *huart,char *str)
 {
 	//printf("\r\nAT_CMD:\t");
 	HAL_UART_Transmit(huart, (uint8_t*)str, strlen(str), 0xFFFF);		//工作信息串口发送
-    HAL_UART_Transmit(&huart1, (uint8_t*)str, strlen(str), 0xFFFF);		//485打印log
+    //HAL_UART_Transmit(&huart1, (uint8_t*)str, strlen(str), 0xFFFF);		//485打印log
     //HAL_UART_Transmit(&huart3, (uint8_t*)str, strlen(str), 0xFFFF);	//TTL打印log
 	
 }

+ 9 - 9
Core/Src/ml307a.c

@@ -104,14 +104,14 @@ void ML307A_Init(void)
 			
 			char TCPconnvalue[100];
 			TcpConn(TCPconnvalue, 1, JLPTIP, JLPTPORT,0);		//cid=1		tcpConnmode=0 普通模式
-			if(sendCmd_4G(TCPconnvalue, "+MIPOPEN: 1,0", 1, 3))	//TCP连接 0普通模式  2缓存模式  1透传模式
+			if(sendCmd_4G(TCPconnvalue, "+MIPOPEN: 1,0", 1, 1))	//TCP连接 0普通模式  2缓存模式  1透传模式
 			{
 				step4g++;
 				printf("#TCP连接完成\r\n");
-				if(sendCmd_4G("AT+MDIALUPCFG=\"auto\",1\r\n", "OK", 1, 5)) 
-				{
-					printf("#开启自动拨号\r\n");
-				}
+//				if(sendCmd_4G("AT+MDIALUPCFG=\"auto\",1\r\n", "OK", 1, 5)) 
+//				{
+//					printf("#开启自动拨号\r\n");
+//				}
 			}
 			//break;
 		}
@@ -131,10 +131,10 @@ void ML307A_Init(void)
 						if(sendCmd_4G("AT+MGNSS=1\r\n", "OK", 1, 1))
 						{
 							printf("#开启MGNSS\r\n");
-							if(sendCmd_4G("AT+MUECONFIG=\"autoconn\",1\r\n", "OK", 1, 5)) 
-							{
-								printf("#开启自动联网\r\n");
-							}
+//							if(sendCmd_4G("AT+MUECONFIG=\"autoconn\",1\r\n", "OK", 1, 5)) 
+//							{
+//								printf("#开启自动联网\r\n");
+//							}
 							 
 							MgnssFlag=true;
 						}

+ 82 - 39
Core/Src/tt808.c

@@ -19,6 +19,7 @@ uint8_t MIPurcXXTCSJ[100];//平台
 uint8_t speedBegin=0;
 uint8_t speedEnd=0;
 uint8_t speed[10];		//处理头部
+int pushpullcount = 0;
 double dSpeed=0;
 double dlatitude=0;
 double dlongitude=0;
@@ -54,6 +55,10 @@ void MessageHandle(uint16_t MessageID)
 {
 
 	uint16_t MessageAttributeData = Messagetemp_length;
+	if(MessageID ==MessageID_Retrans)
+	{
+		MessageAttributeData+=3;
+	}
 	MessageAttributeData |= ( Messagetemp_length | (TCPJMFSNULL<<10)); // 将长度左移3位后和加密方式进行按位或操作(001 RSA ,000 无加密)
 	
 	header[0] 	= ((MessageID>>8)&0xff);
@@ -120,7 +125,9 @@ uint8_t Message_bodydata(uint8_t *Message, uint8_t length, uint8_t outMessage[],
 {
 	int index = 0;
 	uint8_t temp_length = 0;//加首尾 25/23/crc
-	
+			
+
+		
 	if(MessageID==MessageID_authentication  || MessageID==MessageID_heartbeat)//不加头尾(鉴权、心跳)
 	{
 		temp_length = length;//不加首尾
@@ -137,23 +144,53 @@ uint8_t Message_bodydata(uint8_t *Message, uint8_t length, uint8_t outMessage[],
 			outMessage[i]=temp_Message[i];
 		}
 	}
-	else if(MessageID==MessageID_location || MessageID==MessageID_Retrans)//终端地址0200  补传0704
+	else if(MessageID==MessageID_location)//终端地址0200  补传0704
 	{
 		
 		temp_length = length;//不加首尾
 		//状态标志/纬度/经度/速度
+
+		uint8_t temp_Message[temp_length];
 		
+
 		dblocptr->location.statusFlag = swapBytes32(dblocptr->location.statusFlag);
 		dblocptr->location.latitude = swapBytes32(dblocptr->location.latitude);
 		dblocptr->location.longitude = swapBytes32(dblocptr->location.longitude);
 		dblocptr->location.speed = swapBytes16(dblocptr->location.speed);
 		
+		for (int i = 0; i < length; i++) {
+			temp_Message[index++] = Message[i];  // 将消息头拷贝到报文中
+		}
+		
+		
+		for(int i =0;i<temp_length;i++)
+		{
+			outMessage[i]=temp_Message[i];
+		}
+	}
+	else if(MessageID==MessageID_Retrans)// 补传0704+5
+	{
+		temp_length = length;//不加首尾
+		//状态标志/纬度/经度/速度
+		dblocptr->temppull.statusFlag = swapBytes32(dblocptr->temppull.statusFlag);
+		dblocptr->temppull.latitude = swapBytes32(dblocptr->temppull.latitude);
+		dblocptr->temppull.longitude = swapBytes32(dblocptr->temppull.longitude);
+		dblocptr->temppull.speed = swapBytes16(dblocptr->temppull.speed);
+		
 		uint8_t temp_Message[temp_length];
 		
+		temp_Message[index++] = 0x00;
+		temp_Message[index++] = 0x01;
+		temp_Message[index++] = 0x00;
+		temp_Message[index++] = 0x00;
+		temp_Message[index++] = 0x22;
+		
+		
 		for (int i = 0; i < length; i++) {
 			temp_Message[index++] = Message[i];  // 将消息头拷贝到报文中
 		}
 		
+		
 		for(int i =0;i<temp_length;i++)
 		{
 			outMessage[i]=temp_Message[i];
@@ -335,21 +372,21 @@ void ReMIPURC(void)
 	 }
 	 else if(strncmp((char*)U4_4GrecvBuff, "+MGNSSURC: \"state\",1",  strlen("+MGNSSURC: \"state\",1"))==0)
 	 {
-		 printf("#MGNSS设置成功\r\n");
+		 printf("@MGNSS设置成功\r\n");
 		
 		 memset(U4_4GrecvBuff,0,strlen("+MGNSSURC: \"state\",1"));
 	 }
 	 
 	 else if(strncmp((char*)U4_4GrecvBuff, "+MGNSSURC: \"state\",0",  strlen("+MGNSSURC: \"state\",0"))==0)//断开平台
 	 {
-		 printf("#主动取消GNSS\r\n");
+		 printf("@主动取消GNSS\r\n");
 		 memset(U4_4GrecvBuff,0,strlen("+MGNSSURC: \"state\",0"));
 	 }	 
 	 
 	 else if(strncmp((char*)U4_4GrecvBuff, "+MIPURC: \"di",  strlen("+MIPURC: \"di"))==0)//"disconn" 平台断连
 	 {
 		 Offline=true;
-		 printf("与平台断开连接\r\n");
+		 printf("@与平台断开连接\r\n");
 		 //ML307AReset();//与平台断开连接 offline
 		 memset(U4_4GrecvBuff,0,BUFFER_SIZE);
 	 }
@@ -359,7 +396,7 @@ void ReMIPURC(void)
 	 {
 		 Offline=false;
 		 Online = true;
-		 printf("设备已上线!!\r\n");
+		 printf("@设备已上线!!\r\n");
 		 module4G_F = true;
 		 menu.current = 0xBB;
 		 tipsflag = Back;
@@ -378,7 +415,7 @@ void ReMIPURC(void)
 	 else if((strncmp((char*)U4_4GrecvBuff, "+CPIN: SIM REMOVED", strlen("+CPIN: SIM REMOVED"))==0) || (strncmp((char*)U4_4GrecvBuff, "+CME ERROR: 10", strlen("+CME ERROR: 10"))==0) )//无SIM
 	 {
 		//TODO
-		printf("SIM卡缺失\r\n");
+		printf("@SIM卡缺失\r\n");
 		Offline=true;
 		signal = false;
 		menu.current = 0xBB;
@@ -391,8 +428,8 @@ void ReMIPURC(void)
 	 {
 		//TODO
 		Offline=true;
-		printf("#与平台断开连接\r\n");
-		ML307AReset();//与平台断开连接 offline
+		signal = false;
+		printf("@与平台断开连接\r\n");
 		memset(U4_4GrecvBuff,0,BUFFER_SIZE);
 		 
 	 }
@@ -401,7 +438,7 @@ void ReMIPURC(void)
 	 {
 		//TODO
 		Offline=true;
-		printf("#PDP激活是败\r\n");
+		printf("@PDP激活失败\r\n");
 		memset(U4_4GrecvBuff,0,BUFFER_SIZE);
 		 
 	 }
@@ -537,10 +574,10 @@ void ReU4Proces(void)
 		dblocptr->location.longitude = convertGPS(dlongitude);
 		
 		
-		printf("%d\r\n",dblocptr->location.latitude);
-		printf("%d\r\n",dblocptr->location.longitude);
-		printf("%08X\r\n",dblocptr->location.latitude);
-		printf("%08X\r\n",dblocptr->location.longitude);
+//		printf("%d\r\n",dblocptr->location.latitude);
+//		printf("%d\r\n",dblocptr->location.longitude);
+//		printf("%08X\r\n",dblocptr->location.latitude);
+//		printf("%08X\r\n",dblocptr->location.longitude);
 		
 		extractString(MGNSSLOC, csatellitesNum,10 ,11);//采集卫星个数
 		dblocptr->location.satellitesNum = convertToDouble(csatellitesNum);	//转换浮点数
@@ -587,59 +624,65 @@ int countregular = 0;
 void Regular_reporting_Loc(void)
 {
 	countregular+=1;
-	dblocptr->location.alarmFlag=0x00000000;
-	dblocptr->location.statusFlag=0x00000002;
-	dblocptr->location.height=0x0000;
-	dblocptr->location.direction=0x0000;
-	dblocptr->location.signalCmd=0x30;
-	dblocptr->location.signalCmd_len=0x01;
-	dblocptr->location.atellitesCmd=0x31;
-	dblocptr->location.atellitesCmd_len=0x01;
+	if(countregular==3 && !Offline )//在线状态10s更新状态,30s上传  (各种状态正常在线,直接上传信息)
+	{
+		countregular=0;
+		tt808FsFunc((uint8_t*)&(dblocptr->location.alarmFlag), 34, MessageID_location);
+	}
+
 	
-	if(Offline)//掉线状态10s入库定位记录
+}
+
+void pushpullWork(void)
+{
+	pushpullcount++;
+	if(Offline && pushpullcount==10000)//掉线状态10s入库定位记录
 	{
-		printf("设备掉线,执行入库操作!!\r\n");
+		
+		RTCtime();//写入做参考
+		printf("@@@设备掉线,执行入库操作!!%d\r\n",dblocptr->temppush.loc_pushIndex);
 		Database_Push(0);
 		
 		//*每10s重连平台
 		char TCPconnvalue[100];
 		TcpConn(TCPconnvalue, 1, JLPTIP, JLPTPORT,0);		//cid=1		tcpConnmode=0 普通模式
-		if(sendCmd_4G(TCPconnvalue, "+MIPOPEN: 1,0", 1, 3))	//TCP连接 0普通模式  2缓存模式  1透传模式
+		if(sendCmd_4G(TCPconnvalue, "+MIPOPEN: 1,0", 1, 1))	//TCP连接 0普通模式  2缓存模式  1透传模式
 		{
-			printf("#TCP连接完成\r\n");
+			printf("@@@TCP连接完成\r\n");
 		}
 		else
 		{
-			printf("#重连失败!\r\n");
+			printf("@@@重连失败!\r\n");
 		}
-	}
-	else if(countregular==2 && Retrans && MiddleObj)//重传 7e0704002701820200777700060001000022000000000000000301cd8b7007278acd00000000000023051918174830011e310103b77e
+	}	
+	else if(Retrans && MiddleObj)//重传 7e0704002701820200777700060001000022000000000000000301cd8b7007278acd00000000000023051918174830011e310103b77e
 	{
-		countregular=0;
-		tt808FsFunc((uint8_t*)&(dblocptr->temppull.alarmFlag), 34, MessageID_Retrans);
+		
+		tt808FsFunc((uint8_t*)&(dblocptr->temppull.alarmFlag), 39, MessageID_Retrans);
 		printf("出库%d操作完成,当前索引%d\r\n",dblocptr->headinfo.loc_pullIndex-1,dblocptr->headinfo.loc_pullIndex);
 		MiddleObj = false;
 	}
-	else if(Online && !MiddleObj) //上线出库
+	else if(Online && !MiddleObj && pushpullcount==1000) //上线出库
 	{
+		pushpullcount=0;
 		if(dblocptr->headinfo.loc_pushIndex==0)
 		{
-			printf("更新上线标识,库内无数据\r\n");
+			printf("@@@更新上线标识,库内无数据\r\n");
 			Online = false;
 		}
 		else
 		{
-			printf("库内有数据,执行操作\r\n");
+			RTCtime();//写入做参考
+			printf("@@@库内有数据,执行操作\r\n");
 			Database_Pull(0);
+			MiddleObj=true;
 		}
 		
 	}
-	else if(countregular==3 && !Offline)//在线状态10s更新状态,30s上传  (各种状态正常在线,直接上传信息)
+	else if(pushpullcount>10001)
 	{
-		countregular=0;
-		//tt808FsFunc((uint8_t*)&(dblocptr->location.alarmFlag), 34, MessageID_location);
+		
+		pushpullcount=0;
 	}
-	
 }
 
-

+ 1 - 0
Core/Src/usart.c

@@ -731,6 +731,7 @@ HAL_StatusTypeDef Flash_WriteBytes(uint16_t* sorBuf, uint32_t FlashAddr, uint16_
     {
         WriteSta = HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, Page_StartAddr + (i * 2), Flashbuf[i]);
     }
+	HAL_Delay(100);
     // Ëø×¡FLASH
     HAL_FLASH_Lock();
 	

+ 2 - 2
MDK-ARM/dtu.uvoptx

@@ -190,7 +190,7 @@
         <Mm>
           <WinNumber>1</WinNumber>
           <SubType>0</SubType>
-          <ItemText>LocDbHeadStart</ItemText>
+          <ItemText>LocDbBodyStart</ItemText>
           <AccSizeX>0</AccSizeX>
         </Mm>
       </MemoryWindow1>
@@ -198,7 +198,7 @@
         <Mm>
           <WinNumber>2</WinNumber>
           <SubType>0</SubType>
-          <ItemText>LocDbBodyStart</ItemText>
+          <ItemText>LocDbHeadStart</ItemText>
           <AccSizeX>0</AccSizeX>
         </Mm>
       </MemoryWindow2>