Преглед изворни кода

Add inbound and outbound logs

zack пре 1 година
родитељ
комит
ab1123bbf4
9 измењених фајлова са 169 додато и 59 уклоњено
  1. 6 2
      Core/Inc/ConfigMacros.h
  2. 2 0
      Core/Inc/database.h
  3. 1 1
      Core/Inc/ml307a.h
  4. 1 1
      Core/Inc/tt808.h
  5. 70 39
      Core/Src/database.c
  6. 5 1
      Core/Src/freertos.c
  7. 14 3
      Core/Src/ml307a.c
  8. 68 10
      Core/Src/tt808.c
  9. 2 2
      MDK-ARM/dtu.uvoptx

+ 6 - 2
Core/Inc/ConfigMacros.h

@@ -12,6 +12,7 @@
 #define BUFFER_SIZE 256
 #define open4G			1	
 #define openBT			1	
+#define openUpload		1	
 #define updateMenu		1	
 #define debugkeyinfo	0
 #define open16			11	//羲趼
@@ -56,6 +57,7 @@
 #define MessageID_authentication	0x0102 //牖�
 #define MessageID_heartbeat			0x0002 //陑泐
 #define MessageID_location			0x0200 //華硊
+#define MessageID_Retrans			0x0704 //華硊
 #define TCPJMFSRSA  0x001
 #define TCPJMFSNULL 0x000
 
@@ -308,7 +310,8 @@ typedef struct {
 typedef struct {
 	Headinfo headinfo;
     LocationData location;
-    TestTemp temp;
+    TestTemp temppush;
+    TestTemp temppull;
 } DatabaseLoc;
 
 
@@ -320,7 +323,8 @@ typedef struct {
     uint16_t OperationResults;	//紱釬賦彆
     uint32_t perators;			//紱釬�
     uint16_t ElectricityLevel;	//萇講
-    TestTemp temp;
+    TestTemp temppush;
+    TestTemp temppull;
 } DatabaseEvent;
 #endif /*__CONFIGMACROS_H*/
 

+ 2 - 0
Core/Inc/database.h

@@ -18,6 +18,8 @@ extern DatabaseEvent *dbeveptr;
 
 
 extern uint16_t PDA_pushArr[1024];
+void Database_Pull(uint8_t object);
 
+extern bool MiddleObj;
 #endif /*__DATABASE_H*/
 

+ 1 - 1
Core/Inc/ml307a.h

@@ -23,7 +23,7 @@ extern char minute_str[3];
 extern char second_str[3];
 extern bool signal;
 void ML307AReset(void);
-
+void TcpConn(char *value, uint8_t cid, char *IPaddr, uint16_t port, uint8_t tcpConnmode);
 extern bool resetBTmodule;
 extern uint8_t TimeBCD[6];
 #endif /*__ML307A_H*/

+ 1 - 1
Core/Inc/tt808.h

@@ -24,7 +24,7 @@ void hexArrayToBcd(uint8_t* array, size_t length, uint8_t* out);
 
 
 void Regular_reporting_Loc(void);
-
+extern bool Retrans;
 
 extern bool Offline ;
 

+ 70 - 39
Core/Src/database.c

@@ -1,5 +1,6 @@
 #include "database.h"
 #include "usart.h"
+#include "tt808.h"
 
 uint16_t PDA_pushArr[1024];
 
@@ -12,6 +13,7 @@ DatabaseEvent dbeve;
 DatabaseLoc *dblocptr = &dbloc;
 DatabaseEvent *dbeveptr = &dbeve;
 
+bool MiddleObj =false;
 
 /**
   * @breaf 数据库初始化
@@ -19,8 +21,8 @@ DatabaseEvent *dbeveptr = &dbeve;
   */
 void Database_init(uint16_t pushsize_loc, uint16_t pullsize_loc,uint16_t pushsize_eve, uint16_t pullsize_eve)
 {
-	Flash_ReadBytes((uint16_t*)&(dblocptr->temp.loc_pushIndex),LocDbHeadStart,4);//读取loc头部是否发生写入
-	if(dblocptr->temp.loc_pullIndex == 0xFFFF && dblocptr->temp.loc_pushIndex==0xFFFF)//未写入
+	Flash_ReadBytes((uint16_t*)&(dblocptr->temppush.loc_pushIndex),LocDbHeadStart,4);//读取loc头部是否发生写入
+	if(dblocptr->temppush.loc_pullIndex == 0xFFFF && dblocptr->temppush.loc_pushIndex==0xFFFF)//未写入
 	{
 		dblocptr->headinfo.loc_pushIndex = 0;
 		dblocptr->headinfo.loc_pullIndex = 0;
@@ -31,17 +33,17 @@ void Database_init(uint16_t pushsize_loc, uint16_t pullsize_loc,uint16_t pushsiz
 	else
 	{
 		//*高地址字节在前
-		dblocptr->headinfo.loc_pushIndex = dblocptr->temp.loc_pushIndex;
-		dblocptr->headinfo.loc_pullIndex = dblocptr->temp.loc_pushIndex;
-		dblocptr->headinfo.loc_pushSize =  dblocptr->temp.loc_pushSize;
-		dblocptr->headinfo.loc_pullSize =  dblocptr->temp.loc_pullSize;
+		dblocptr->headinfo.loc_pushIndex = dblocptr->temppush.loc_pushIndex;
+		dblocptr->headinfo.loc_pullIndex = dblocptr->temppush.loc_pushIndex;
+		dblocptr->headinfo.loc_pushSize =  dblocptr->temppush.loc_pushSize;
+		dblocptr->headinfo.loc_pullSize =  dblocptr->temppush.loc_pullSize;
 	}
 
 	
 	
 	
-	Flash_ReadBytes((uint16_t*)&(dbeveptr->temp),EveDbHeadStart,4);//读取loc头部是否发生写入
-	if(dbeveptr->temp.eve_pushIndex == 0xFFFF && dbeveptr->temp.eve_pullIndex ==0xFFFF)//未写入
+	Flash_ReadBytes((uint16_t*)&(dbeveptr->temppush),EveDbHeadStart,4);//读取loc头部是否发生写入
+	if(dbeveptr->temppush.eve_pushIndex == 0xFFFF && dbeveptr->temppush.eve_pullIndex ==0xFFFF)//未写入
 	{
 		dbeveptr->headinfo.eve_pushIndex = 0;
 		dbeveptr->headinfo.eve_pullIndex = 0;
@@ -52,26 +54,27 @@ void Database_init(uint16_t pushsize_loc, uint16_t pullsize_loc,uint16_t pushsiz
 	else
 	{
 		//*高地址字节在前
-		dbeveptr->headinfo.eve_pushIndex = dbeveptr->temp.eve_pushIndex;
-		dbeveptr->headinfo.eve_pullIndex = dbeveptr->temp.eve_pullIndex;
-		dbeveptr->headinfo.eve_pushSize =  dbeveptr->temp.eve_pushSize;
-		dbeveptr->headinfo.eve_pullSize =  dbeveptr->temp.eve_pullSize;
+		dbeveptr->headinfo.eve_pushIndex = dbeveptr->temppush.eve_pushIndex;
+		dbeveptr->headinfo.eve_pullIndex = dbeveptr->temppush.eve_pullIndex;
+		dbeveptr->headinfo.eve_pushSize =  dbeveptr->temppush.eve_pushSize;
+		dbeveptr->headinfo.eve_pullSize =  dbeveptr->temppush.eve_pullSize;
 	}
 
 }
 
 HAL_StatusTypeDef PushSta;
 //***************定位信息入库
-void Database_Push(uint8_t ptr)
+void Database_Push(uint8_t object)
 {
-	if(ptr==0)//位置信息写入
+	if(object==0)//位置信息写入
 	{
 		if(dblocptr->headinfo.loc_pushIndex!=0)
 		{
-			if(dblocptr->temp.latitude != dblocptr->location.latitude && dblocptr->temp.longitude != dblocptr->location.longitude)//相同纬度参数(包含未获取定位为0)
+			if(dblocptr->temppush.latitude != dblocptr->location.latitude && dblocptr->temppush.longitude != dblocptr->location.longitude)//相同纬度参数(包含未获取定位为0)
 			{
 				Flash_WriteBytes((uint16_t*)&(dblocptr->location.alarmFlag),LocDbBodyStart + (dblocptr->headinfo.loc_pushIndex*34),17);
-				Flash_ReadBytes((uint16_t*)&(dblocptr->temp.alarmFlag),LocDbBodyStart + ((dblocptr->headinfo.loc_pushIndex-1)*34),17);//读取body信息
+				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
 				dblocptr->headinfo.loc_pushIndex+=1;
 				Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度
@@ -89,39 +92,67 @@ void Database_Push(uint8_t ptr)
 
 						
 	TestPrintStruct(dblocptr,0);//读取Work
-	Flash_ReadBytes((uint16_t*)&(dblocptr->temp.loc_pushIndex),LocDbHeadStart,4);//读取loc头部写入信息
-	if(dblocptr->temp.loc_pushIndex == dblocptr->headinfo.loc_pushSize)//入库结束(返回
+	Flash_ReadBytes((uint16_t*)&(dblocptr->temppush.loc_pushIndex),LocDbHeadStart,4);//读取loc头部写入信息
+	if(dblocptr->temppush.loc_pushIndex == dblocptr->headinfo.loc_pushSize)//入库结束(返回
 	{
+		printf("入库操作,当前索引%d,达边界值返回覆写\r\n",dblocptr->headinfo.loc_pushIndex);
 		dblocptr->headinfo.loc_pushIndex=0;
 		Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度
 	}
 	
 }
 
-void TestPrintStruct(DatabaseLoc *ptr,uint8_t temp)
+void Database_Pull(uint8_t object)
 {
-	if(temp)
+	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);
+		
+		if(dblocptr->headinfo.loc_pushIndex!=0 || dblocptr->temppull.alarmFlag!=0xFFFFFFFF)//库内有数据
+		{
+			Flash_ReadBytes((uint16_t*)&(dblocptr->temppull.alarmFlag),LocDbBodyStart,17);//读取出库body信息
+			dblocptr->headinfo.loc_pullIndex+=1;
+			Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度
+			Retrans = true;
+		}
+		if(dblocptr->temppull.alarmFlag==0xFFFFFFFF)
+		{
+			dblocptr->headinfo.loc_pullIndex=0;
+			dblocptr->headinfo.loc_pushIndex=0;
+			Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度
+			Retrans = false;
+		}
+		MiddleObj = true;
+	}
+}
+
+
+
+void TestPrintStruct(DatabaseLoc *ptr,uint8_t temppush)
+{
+	if(temppush)
 	{
 		printf("temp:%08X%08X%08X%08X%04X%04X%04X%d%d%d%d%d%d%02X%02X%02X%02X%02X%02X\r\n", \
-		ptr->temp.alarmFlag, \
-		ptr->temp.statusFlag, \
-		ptr->temp.latitude, \
-		ptr->temp.longitude, \
-		ptr->temp.height, \
-		ptr->temp.speed, \
-		ptr->temp.direction, \
-		ptr->temp.timeBCD[0], \
-		ptr->temp.timeBCD[1], \
-		ptr->temp.timeBCD[2], \
-		ptr->temp.timeBCD[3], \
-		ptr->temp.timeBCD[4], \
-		ptr->temp.timeBCD[5], \
-		ptr->temp.signalCmd, \
-		ptr->temp.signalCmd_len, \
-		ptr->temp.CSQ, \
-		ptr->temp.atellitesCmd, \
-		ptr->temp.atellitesCmd_len, \
-		ptr->temp.satellitesNum);
+		ptr->temppush.alarmFlag, \
+		ptr->temppush.statusFlag, \
+		ptr->temppush.latitude, \
+		ptr->temppush.longitude, \
+		ptr->temppush.height, \
+		ptr->temppush.speed, \
+		ptr->temppush.direction, \
+		ptr->temppush.timeBCD[0], \
+		ptr->temppush.timeBCD[1], \
+		ptr->temppush.timeBCD[2], \
+		ptr->temppush.timeBCD[3], \
+		ptr->temppush.timeBCD[4], \
+		ptr->temppush.timeBCD[5], \
+		ptr->temppush.signalCmd, \
+		ptr->temppush.signalCmd_len, \
+		ptr->temppush.CSQ, \
+		ptr->temppush.atellitesCmd, \
+		ptr->temppush.atellitesCmd_len, \
+		ptr->temppush.satellitesNum);
 	}
 	else
 	{

+ 5 - 1
Core/Src/freertos.c

@@ -204,7 +204,9 @@ void StarBT4GTask(void const * argument)
   {
     osDelay(10000);	
 	{
-		//Regular_reporting_Loc();//30s 上报地址  10s 入库(掉线)
+#if openUpload == 1
+		Regular_reporting_Loc();//30s 上报地址  10s 入库(掉线)
+#endif
 	}
 
   }
@@ -228,9 +230,11 @@ void StartTestTask(void const * argument)
     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
 	}
 
 

+ 14 - 3
Core/Src/ml307a.c

@@ -53,7 +53,7 @@ void ML307A_Init(void)
 		{
 			if (sendCmd_4G("AT\r\n", "OK", 1, 5)) 
 			{
-				//sendCmd_4G("AT+MCFG=\"simhot\",1\r\n", "OK", 1, 1);
+				sendCmd_4G("AT+MCFG=\"simhot\",1\r\n", "OK", 1, 1);
 				printf("#4G模组正常\r\n");
 				if (sendCmd_4G("AT+ICCID\r\n", "OK", 1, 5)) 
 				{
@@ -61,6 +61,8 @@ void ML307A_Init(void)
 					ICCID[20]=0x00;
 					ICCID[21]=0x01;//版本号(待修改)
 				}
+
+				
 				step4g++;
 			}
 			else
@@ -105,7 +107,11 @@ void ML307A_Init(void)
 			if(sendCmd_4G(TCPconnvalue, "+MIPOPEN: 1,0", 1, 3))	//TCP连接 0普通模式  2缓存模式  1透传模式
 			{
 				step4g++;
-				printf("#进行TCP连接\r\n");
+				printf("#TCP连接完成\r\n");
+				if(sendCmd_4G("AT+MDIALUPCFG=\"auto\",1\r\n", "OK", 1, 5)) 
+				{
+					printf("#开启自动拨号\r\n");
+				}
 			}
 			//break;
 		}
@@ -125,6 +131,11 @@ 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");
+							}
+							 
 							MgnssFlag=true;
 						}
 					}
@@ -143,7 +154,7 @@ void ML307A_Init(void)
 			}
 			else
 			{
-				//module4G_F=true;
+				module4G_F=true;
 			}
 			RTCtime();//写入做参考
 			break;

+ 68 - 10
Core/Src/tt808.c

@@ -6,6 +6,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include "rtc.h"
+#include "database.h"
 //*整型
 int rlt;
 uint16_t uploadtime=0;	//上传时间
@@ -41,7 +42,7 @@ bool authFlag = false;
 bool GnssFlag = false;
 bool Offline = false;
 bool Retrans = false;
-
+bool Online = false;
 /**
 				时间     纬度(北纬)   经度(东经)  水平精度因子  海拔高度    定位类型(1无,2 2d,3 3d) 运动角度    水平运动速度(KM/h)    水平运动速度(Knots)	日月年	卫星数量	差分定位标识(1单点,2差分)
 eg.+MGNSSLOC: 015032.301,3014.8605N,12001.9250E,1.8,			17.6,		3,                      0.00,		3.6,			      1.9,					080424,	12,			1	 
@@ -136,7 +137,7 @@ uint8_t Message_bodydata(uint8_t *Message, uint8_t length, uint8_t outMessage[],
 			outMessage[i]=temp_Message[i];
 		}
 	}
-	else if(MessageID==MessageID_location)//终端地址0200 有附加信息
+	else if(MessageID==MessageID_location || MessageID==MessageID_Retrans)//终端地址0200  补传0704
 	{
 		
 		temp_length = length;//不加首尾
@@ -345,11 +346,11 @@ void ReMIPURC(void)
 		 memset(U4_4GrecvBuff,0,strlen("+MGNSSURC: \"state\",0"));
 	 }	 
 	 
-	 else if(strncmp((char*)U4_4GrecvBuff, "+MIPURC: \"disconn\"",  strlen("+MIPURC: \"disconn\""))==0)//"disconn" 平台断连
+	 else if(strncmp((char*)U4_4GrecvBuff, "+MIPURC: \"di",  strlen("+MIPURC: \"di"))==0)//"disconn" 平台断连
 	 {
 		 Offline=true;
 		 printf("与平台断开连接\r\n");
-		 ML307AReset();//与平台断开连接 offline
+		 //ML307AReset();//与平台断开连接 offline
 		 memset(U4_4GrecvBuff,0,BUFFER_SIZE);
 	 }
 	 //*连接成功 Offline=false;
@@ -357,6 +358,8 @@ void ReMIPURC(void)
 	 else if(strncmp((char*)U4_4GrecvBuff, "+MIPOPEN: 1,0",  strlen("+MIPOPEN: 1,0"))==0)//连接平台
 	 {
 		 Offline=false;
+		 Online = true;
+		 printf("设备已上线!!\r\n");
 		 module4G_F = true;
 		 menu.current = 0xBB;
 		 tipsflag = Back;
@@ -387,12 +390,24 @@ void ReMIPURC(void)
 	 else if((strncmp((char*)U4_4GrecvBuff, "+MIPCALL: 1,0", strlen("+MIPCALL: 1,0"))==0) || (strncmp((char*)U4_4GrecvBuff, "+CME ERROR: 550", strlen("+CME ERROR: 550"))==0))//意外断开平台连接!!!!//TCP未知错误
 	 {
 		//TODO
-		 Offline=true;
+		Offline=true;
 		printf("#与平台断开连接\r\n");
-		 ML307AReset();//与平台断开连接 offline
+		ML307AReset();//与平台断开连接 offline
+		memset(U4_4GrecvBuff,0,BUFFER_SIZE);
+		 
+	 }
+	 
+	 else if((strncmp((char*)U4_4GrecvBuff, "+MIPOPEN: 1,571", strlen("+MIPOPEN: 1,571"))==0))//PDP激活失败
+	 {
+		//TODO
+		Offline=true;
+		printf("#PDP激活是败\r\n");
 		memset(U4_4GrecvBuff,0,BUFFER_SIZE);
 		 
 	 }
+	 
+	 
+	 
 //	else if(strncmp((char*)U4_4GrecvBuff+1, "CSQ", strlen("CSQ")))//CSQ 信号
 //	{
 //		memcpy(CSQ,U4_4GrecvBuff,U4_4GrecvLength);
@@ -434,7 +449,7 @@ void MIPURCHandle(void)
 				}
 				memset(MIPurc,0,rlt);//rlt下发长度 
 			}
-			if(xxRE == MessageID_heartbeat)//回复鉴权ID
+			else if(xxRE == MessageID_heartbeat)//回复鉴权ID
 			{
 				if(YESorNO==YES)
 				{
@@ -447,6 +462,19 @@ void MIPURCHandle(void)
 				memset(MIPurc,0,rlt);//rlt下发长度 
 				
 			}
+			else if(xxRE == MessageID_location)//回复鉴权ID
+			{
+				if(YESorNO==YES)
+				{
+					printf("@地址应答yes\r\n");
+				}
+				else if(YESorNO==NO)
+				{
+					printf("@地址应答no\r\n");
+				}
+				memset(MIPurc,0,rlt);//rlt下发长度 
+				
+			}
 		 }
 		 
 		 else if(PTXXID == XXID_ptxxtc)	//收到平台消息透传 8900
@@ -570,16 +598,46 @@ void Regular_reporting_Loc(void)
 	
 	if(Offline)//掉线状态10s入库定位记录
 	{
+		printf("设备掉线,执行入库操作!!\r\n");
 		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透传模式
+		{
+			printf("#TCP连接完成\r\n");
+		}
+		else
+		{
+			printf("#重连失败!\r\n");
+		}
 	}
-	else if(Retrans)//重传 7e0704002701820200777700060001000022000000000000000301cd8b7007278acd00000000000023051918174830011e310103b77e
+	else if(countregular==2 && Retrans && MiddleObj)//重传 7e0704002701820200777700060001000022000000000000000301cd8b7007278acd00000000000023051918174830011e310103b77e
 	{
+		countregular=0;
+		tt808FsFunc((uint8_t*)&(dblocptr->temppull.alarmFlag), 34, MessageID_Retrans);
+		printf("出库%d操作完成,当前索引%d\r\n",dblocptr->headinfo.loc_pullIndex-1,dblocptr->headinfo.loc_pullIndex);
+		MiddleObj = false;
+	}
+	else if(Online && !MiddleObj) //上线出库
+	{
+		if(dblocptr->headinfo.loc_pushIndex==0)
+		{
+			printf("更新上线标识,库内无数据\r\n");
+			Online = false;
+		}
+		else
+		{
+			printf("库内有数据,执行操作\r\n");
+			Database_Pull(0);
+		}
 		
 	}
-	else if(countregular==3 && !Offline)//在线状态10s更新状态,30s上传
+	else if(countregular==3 && !Offline)//在线状态10s更新状态,30s上传  (各种状态正常在线,直接上传信息)
 	{
 		countregular=0;
-		tt808FsFunc((uint8_t*)&(dblocptr->location.alarmFlag), 34, MessageID_location);
+		//tt808FsFunc((uint8_t*)&(dblocptr->location.alarmFlag), 34, MessageID_location);
 	}
 	
 }

+ 2 - 2
MDK-ARM/dtu.uvoptx

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