Selaa lähdekoodia

Improve packaging and warehousing operations

zack 1 vuosi sitten
vanhempi
commit
0da792f77e
13 muutettua tiedostoa jossa 325 lisäystä ja 231 poistoa
  1. 32 7
      Core/Inc/ConfigMacros.h
  2. 1 0
      Core/Inc/database.h
  3. 2 1
      Core/Inc/ml307a.h
  4. 3 1
      Core/Inc/tt808.h
  5. 69 16
      Core/Src/database.c
  6. 24 39
      Core/Src/freertos.c
  7. 6 4
      Core/Src/interface.c
  8. 3 1
      Core/Src/key.c
  9. 1 0
      Core/Src/main.c
  10. 10 24
      Core/Src/mba32a.c
  11. 46 19
      Core/Src/ml307a.c
  12. 120 116
      Core/Src/tt808.c
  13. 8 3
      MDK-ARM/dtu.uvoptx

+ 32 - 7
Core/Inc/ConfigMacros.h

@@ -127,11 +127,13 @@ typedef struct
 do { \
 	if(reset4Gmodule) { \
 		reset4Gmodule = false; \
-		HAL_Delay(2000); \
 		ML307A_Init(); \
 	} \
 } while(0)
 
+
+
+
 typedef struct
 {
 	//四位数字(施解封显示)
@@ -177,7 +179,8 @@ typedef enum {
 	Fail4G =8,
 	Nosignal =9,
 	Disconn = 0xA,
-	Back = 0xB
+	NoSIM = 0xB,
+	Back = 0xC
 } TipsFlag;
 
 struct keys
@@ -239,17 +242,22 @@ typedef struct {
 
 
 typedef struct {
-    uint32_t timeStamp;		//时间戳(世纪秒)
+	uint32_t timeStamp;
 	
 	//*上传数据
-	uint64_t alarmFlag;		//报警标志
-	uint64_t statusFlag;	//状态标志
+	uint32_t alarmFlag;		//报警标志
+	uint32_t statusFlag;	//状态标志
     uint32_t latitude;		//纬度
     uint32_t longitude;		//经度
+    uint16_t height;		//高度
     uint16_t speed;			//速度
-	uint16_t signalCmd_len;	//信号关键字长度
+    uint16_t direction;		//方向
+    uint8_t timeBCD[6];		//时间戳(世纪秒)BCD
+	uint8_t signalCmd;		//信号关键字
+	uint8_t signalCmd_len;	//信号关键字长度
 	uint8_t CSQ;			//信号强度
-	uint16_t atellitesCmd_len;//卫星关键字长度
+	uint8_t atellitesCmd;	//卫星关键字
+	uint8_t atellitesCmd_len;//卫星关键字长度
 	uint8_t satellitesNum;	//卫星数量
 } LocationData;
 
@@ -276,6 +284,23 @@ typedef struct {
     uint16_t eve_pullIndex;		//出库指针
     uint16_t eve_pushSize;		//入库刻度
     uint16_t eve_pullSize;		//出库刻度
+	
+	
+	uint32_t alarmFlag;		//报警标志
+	uint32_t statusFlag;	//状态标志
+    uint32_t latitude;		//纬度
+    uint32_t longitude;		//经度
+    uint16_t height;		//高度
+    uint16_t speed;			//速度
+    uint16_t direction;		//方向
+    uint8_t timeBCD[6];		//时间戳(世纪秒)BCD
+	uint8_t signalCmd;		//信号关键字
+	uint8_t signalCmd_len;	//信号关键字长度
+	uint8_t CSQ;			//信号强度
+	uint8_t atellitesCmd;	//卫星关键字
+	uint8_t atellitesCmd_len;//卫星关键字长度
+	uint8_t satellitesNum;	//卫星数量
+	
 
 	
 } TestTemp;

+ 1 - 0
Core/Inc/database.h

@@ -11,6 +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);
 
 extern DatabaseLoc *dblocptr;
 extern DatabaseEvent *dbeveptr;

+ 2 - 1
Core/Inc/ml307a.h

@@ -14,7 +14,7 @@ uint8_t sendCmd_4G(char *pCmd, char *pRes, uint32_t timeOut, uint8_t sendNum);
 void Pre_processing_4G(void);
 void Time_inquiry(uint8_t flag);
 void RTCtime(void);
-void ZHSJ(uint8_t outTt[],char in[]);
+void Transfer_time(uint8_t outTt[],char in[]);
 extern char year_str[3];
 extern char month_str[3];
 extern char day_str[3]; 
@@ -24,6 +24,7 @@ extern char second_str[3];
 extern bool signal;
 void ML307AReset(void);
 
+extern bool resetBTmodule;
 extern uint8_t TimeBCD[6];
 #endif /*__ML307A_H*/
 

+ 3 - 1
Core/Inc/tt808.h

@@ -9,7 +9,7 @@
 
 char *bin2hex(char *hex, const unsigned char *bin, int size);
 int hex2bin(unsigned char *bin, const char *hex);
-void tt808FsFunc(uint8_t xxt[], uint8_t xxtlength, uint16_t XXID);
+void tt808FsFunc(uint8_t* Message, uint8_t length, uint16_t MessageID);
 void MIPURCHandle(void);
 void ReMIPURC(void);
 void time_bj(void);
@@ -23,8 +23,10 @@ uint8_t testHex2Asc(const char *hex) ;
 void hexArrayToBcd(uint8_t* array, size_t length, uint8_t* out);
 
 
+void Regular_reporting_Loc(void);
 
 
+extern bool Offline ;
 
 #endif /*__TT808_H*/
 

+ 69 - 16
Core/Src/database.c

@@ -60,7 +60,6 @@ void Database_init(uint16_t pushsize_loc, uint16_t pullsize_loc,uint16_t pushsiz
 
 }
 
-
 HAL_StatusTypeDef PushSta;
 //***************定位信息入库
 void Database_Push(uint8_t ptr)
@@ -69,30 +68,84 @@ void Database_Push(uint8_t ptr)
 	{
 		if(dblocptr->headinfo.loc_pushIndex!=0)
 		{
-			Flash_ReadBytes((uint16_t*)&(dblocptr->temp.timeStamp),LocDbBodyStart + ((dblocptr->headinfo.loc_pushIndex-1)*14),7);//读取body信息
-			if(dblocptr->temp.latitude == dblocptr->location.latitude)//相同纬度参数(包含未获取定位为0)
-			{
-				//*相同不做操作
-			}
-			else
+			if(dblocptr->temp.latitude != dblocptr->location.latitude && dblocptr->temp.longitude != dblocptr->location.longitude)//相同纬度参数(包含未获取定位为0)
 			{
-				Flash_WriteBytes((uint16_t*)&(dblocptr->location),LocDbBodyStart + (dblocptr->headinfo.loc_pushIndex*14),7);
+				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信息
+				TestPrintStruct(dblocptr,1);//读取Temp
 				dblocptr->headinfo.loc_pushIndex+=1;
 				Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度
 			}
+
 		}
-		else
-		{
-				Flash_WriteBytes((uint16_t*)&(dblocptr->location),LocDbBodyStart,7);
-				dblocptr->headinfo.loc_pushIndex+=1;
-				Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度
+
+		else if(dblocptr->location.latitude!=0 && dblocptr->headinfo.loc_pushIndex==0)//判断定位是否正常工作
+		{		
+			Flash_WriteBytes((uint16_t*)&(dblocptr->location.alarmFlag),LocDbBodyStart,17);//34
+			dblocptr->headinfo.loc_pushIndex+=1;
+			Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度
 		}
 	}
+
+						
+	TestPrintStruct(dblocptr,0);//读取Work
+	Flash_ReadBytes((uint16_t*)&(dblocptr->temp.loc_pushIndex),LocDbHeadStart,4);//读取loc头部写入信息
+	if(dblocptr->temp.loc_pushIndex == dblocptr->headinfo.loc_pushSize)//入库结束(返回
+	{
+		dblocptr->headinfo.loc_pushIndex=0;
+		Flash_WriteBytes((uint16_t*)&(dblocptr->headinfo),LocDbHeadStart,4);//更新刻度
+	}
 	
 }
-//出库 7e0704002701820200777700060001000022000000000000000301cd8b7007278acd00000000000023051918174830011e310103b77e
-
-
 
+void TestPrintStruct(DatabaseLoc *ptr,uint8_t temp)
+{
+	if(temp)
+	{
+		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);
+	}
+	else
+	{
+		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, \
+		ptr->location.statusFlag, \
+		ptr->location.latitude, \
+		ptr->location.longitude, \
+		ptr->location.height, \
+		ptr->location.speed, \
+		ptr->location.direction, \
+		ptr->location.timeBCD[0], \
+		ptr->location.timeBCD[1], \
+		ptr->location.timeBCD[2], \
+		ptr->location.timeBCD[3], \
+		ptr->location.timeBCD[4], \
+		ptr->location.timeBCD[5], \
+		ptr->location.signalCmd, \
+		ptr->location.signalCmd_len, \
+		ptr->location.CSQ, \
+		ptr->location.atellitesCmd, \
+		ptr->location.atellitesCmd_len, \
+		ptr->location.satellitesNum);
+	}
+}
 
 

+ 24 - 39
Core/Src/freertos.c

@@ -155,14 +155,14 @@ void StartScanKeyTask(void const * argument)
   for(;;)
   {
     osDelay(1);
+	ReMIPURC();
 	updatekeystate(); 				//扫描键值
     Jump_interface(); 		    	//跳转界面
     OLED_Refresh(); 				//刷新界面
 	
 	RESET_4G_MODULE();				//4G启动(复位) 标志位->reset4Gmodule
 	Pre_processing_4G();			//4G传递准备   标志位->module4G_F
-	MIPURCHandle();					//平台接收处理
-	Lock_OandC();					//施解封
+	//Lock_OandC();					//施解封
 	//*开发者
 	if(Developer_PortalA==1 && Developer_PortalD==4)
 	{
@@ -171,6 +171,19 @@ void StartScanKeyTask(void const * argument)
 		Developer_PortalA=0;
 		Developer_PortalD=0;
 	}
+	
+	 if(tipsflag == ConnOK || tipsflag == Disconn)
+	 {
+		HAL_Delay(2000);
+		menu.current=0;
+		refresh=true;
+	 }
+
+	ReU4Proces();
+	ReU5Proces();
+
+	 
+	 
   }
   /* USER CODE END StartScanKeyTask */
 }
@@ -189,16 +202,11 @@ void StarBT4GTask(void const * argument)
   /* Infinite loop */
   for(;;)
   {
-    osDelay(9000);	
-	if(MgnssFlag)
+    osDelay(10000);	
 	{
-		USART_SendString(&huart4, "AT+CSQ\r\n");
-		osDelay(100);
-		USART_SendString(&huart4, "AT+MGNSSLOC\r\n");
+		//Regular_reporting_Loc();//30s 上报地址  10s 入库(掉线)
 	}
 
-
-
   }
   /* USER CODE END StarBT4GTask */
 }
@@ -217,29 +225,14 @@ void StartTestTask(void const * argument)
   /* Infinite loop */
   for(;;)
   {
-    osDelay(30000);    
+    osDelay(8000);    
 	if(MgnssFlag)
-	{
-		uint8_t testdata[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
-							  (dblocptr->location.latitude >> 24) & 0xFF, (dblocptr->location.latitude >> 16) & 0xFF,
-							  (dblocptr->location.latitude >> 8) & 0xFF, (dblocptr->location.latitude) & 0xFF,
-							  (dblocptr->location.longitude >> 24) & 0xFF, (dblocptr->location.longitude >> 16) & 0xFF,
-							  (dblocptr->location.longitude >> 8) & 0xFF, (dblocptr->location.longitude) & 0xFF,
-							  0x00, 0x00, (dblocptr->location.speed >> 8) & 0xFF,
-							  (dblocptr->location.speed) & 0xFF, 0x00, 0x00,
-							  TimeBCD[0], TimeBCD[1], TimeBCD[2], TimeBCD[3], TimeBCD[4], TimeBCD[5]};
-		
-		//*test			  
-	//	size_t length = sizeof(testdata) / sizeof(testdata[0]);
-	//    printf("Bytes in testdata array:\n");
-	//	printBytes(testdata,length);
-			
-		tt808FsFunc(testdata, 28, MessageID_location);
-						  
+	{	
+//		USART_SendString(&huart4, "AT+CSQ\r\n");
+//		HAL_Delay(100);
+//		USART_SendString(&huart4, "AT+MGNSSLOC\r\n");
 	}
-	//testLoc();
-	//testEve();
-	//Database_Push(0);
+
 
   }
   /* USER CODE END StartTestTask */
@@ -259,16 +252,8 @@ void StartloginfoTaskTask(void const * argument)
   for(;;)
   {
     osDelay(1);
-
-	 if(tipsflag == ConnOK || tipsflag == Disconn)
-	 {
-		HAL_Delay(2000);
-		menu.current=0;
-	 }
+	MIPURCHandle();					//平台接收处理
 	Printf_u4u5logbyU1();//打印log
-	ReMIPURC();
-	ReU4Proces();
-	ReU5Proces();
 
   }
   /* USER CODE END StartloginfoTaskTask */

+ 6 - 4
Core/Src/interface.c

@@ -217,10 +217,7 @@ void Jump_interface(void)
 			}
 		}
 	}
-	else if(sys_mode[1] == 0)
-	{
-		Developer_Options();
-	}
+
 
 	
 }
@@ -598,6 +595,11 @@ void WarningTip(void)
 			OLED_ShowString(35,32,(unsigned char*)"NoSignal",16,1);
             break;
 		}
+		case NoSIM:
+		{
+			OLED_ShowString(35,32,(unsigned char*)"NoSIM",16,1);
+            break;
+		}
         default:
             // ´¦ÀíÆäËûÇé¿ö
 			//menu.current=0;

+ 3 - 1
Core/Src/key.c

@@ -482,6 +482,7 @@ uint8_t KEY_3_Scan_PDA(void)
 								sys_mode[1]=DTU_MODE;
 							}
 							Flash_WriteBytes(&sys_mode[1],SysModeAddr,1);
+							Flash_ReadBytes(sys_mode, SysModeAddr, 1);//读取一个2B的,系统模式
 							menu.current=0;//回到初始
 							refresh=true;
 							break;
@@ -763,6 +764,7 @@ uint8_t KEY_3_Scan_DTU(void)
 								}
 							}
 							Flash_WriteBytes(&sys_mode[1],SysModeAddr,1);
+							Flash_ReadBytes(sys_mode, SysModeAddr, 1);//读取一个2B的,系统模式
 							menu.current=0;//回到初始
 							refresh=true;
 							break;
@@ -848,7 +850,7 @@ void updatekeystate(void)
 		KEY_3_Scan_PDA();
 		KEY_4_Scan_PDA();
 	}
-	else if(sys_mode[1] == DTU_MODE)
+	else if(sys_mode[1] == DTU_MODE )
 	{
 		KEY_1_Scan_DTU();
 		KEY_2_Scan_DTU();

+ 1 - 0
Core/Src/main.c

@@ -128,6 +128,7 @@ int main(void)
   
   MBA32A_Init();
   reset4Gmodule = true;
+ 
     
 
   /* USER CODE END 2 */

+ 10 - 24
Core/Src/mba32a.c

@@ -69,21 +69,6 @@ void Start_Read_resetFlag16(void)
 			PRINT_NUUID("UUIDS");//UUID项不符合
 			btstep = UUIDS;
 		}
-//		else if (!sendCmd_BT("AT+UUIDN?\r\n","+UUIDN:FF04",1,1))
-//		{
-//			PRINT_NUUID("UUIDN");//UUID项不符合
-//			btstep = UUIDN;
-//		}
-//		else if (!sendCmd_BT("AT+UUIDW?\r\n","+UUIDW:FFF5",1,1))
-//		{
-//			PRINT_NUUID("UUIDW");//UUID项不符合
-//			btstep = UUIDW;
-//		}
-//		else if(!sendCmd_BT("AT+TXPOWER?\r\n","+TXPOWER:10",1,1))
-//		{
-//			PRINT_NUUID("TXPOWER");//TXPOWER项不符合
-//			btstep = TxPower;
-//		}
 		else
 		{
 			
@@ -104,15 +89,16 @@ void MBA32A_Init(void)
 	printf("\t###01\tBT_init%d...\r\n", resetcount_bt); 
 	
 	Start_Read_resetFlag16();/** 启动位读写检查 **/
-//	if(sendCmd_BT("AT+DISCONN=0\r\n","ERROR",1,1))//断开连接
-//	{
-//		if(sendCmd_BT("AT+DISCONN=1\r\n","ERROR",1,1))//断开连接
-//		{
-//			printf("#已无主设备连接\n");
-//		}
-//		printf("#已无从设备连接\n");
-//		
-//	}
+
+	if(sendCmd_BT("AT+DISCONN=0\r\n","ERROR",1,1))//断开连接
+	{
+		if(sendCmd_BT("AT+DISCONN=1\r\n","ERROR",1,1))//断开连接
+		{
+			printf("#已无主设备连接\n");
+		}
+		printf("#已无从设备连接\n");
+		
+	}
 	switch(btstep)
 	{
 		case BtStepDefault:

+ 46 - 19
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);
 				printf("#4G模组正常\r\n");
 				if (sendCmd_4G("AT+ICCID\r\n", "OK", 1, 5)) 
 				{
@@ -88,7 +88,7 @@ void ML307A_Init(void)
 				printf("#4G模组附着正常\r\n");
 				printf("#4G模组初始化完成\r\n");
 				step4g++;
-
+				tipsflag = Back;
 			}	
 
 			//break;
@@ -105,7 +105,7 @@ 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");
 			}
 			//break;
 		}
@@ -125,6 +125,7 @@ void ML307A_Init(void)
 						if(sendCmd_4G("AT+MGNSS=1\r\n", "OK", 1, 1))
 						{
 							printf("#开启MGNSS\r\n");
+							MgnssFlag=true;
 						}
 					}
 				}
@@ -136,7 +137,14 @@ void ML307A_Init(void)
 
 			printf("#TCP设置完成\r\n");
 			Time_inquiry(0);
-			module4G_F=true;
+			if(tipsflag == NoSIM)
+			{
+				module4G_F=false;
+			}
+			else
+			{
+				//module4G_F=true;
+			}
 			RTCtime();//写入做参考
 			break;
 		}
@@ -151,7 +159,14 @@ void ML307A_Init(void)
 		if(!module4G_F)
 		{
 			menu.current=0xBB;
-			tipsflag = Fail4G;
+			if(tipsflag == NoSIM)
+			{
+				tipsflag = NoSIM;
+			}
+			else
+			{
+				tipsflag = Fail4G;
+			}
 		}
 	}
 	else if(sys_mode[0]==DTU_MODE)
@@ -167,7 +182,14 @@ void ML307A_Init(void)
 		else if(!module4G_F)
 		{
 			menu.current=0xBB;
-			tipsflag = Fail4G;
+			if(tipsflag == NoSIM)
+			{
+				tipsflag = NoSIM;
+			}
+			else
+			{
+				tipsflag = Fail4G;
+			}
 		}
 		else
 		{
@@ -187,7 +209,14 @@ void ML307A_Init(void)
 		else if(!module4G_F)
 		{
 			menu.current=0xBB;
-			tipsflag = Fail4G;
+			if(tipsflag == NoSIM)
+			{
+				tipsflag = NoSIM;
+			}
+			else
+			{
+				tipsflag = Fail4G;
+			}
 		}
 		else
 		{
@@ -233,13 +262,11 @@ void ML307AReset(void)
 {
 	step4g=0;
 	reset4Gmodule=true;
-	module4G_F=false;
 	resetcount_4g+=1;
 	printf("4G Module_Reset\n");    
 	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET);
 	HAL_Delay(5000);
 	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET);
-	HAL_Delay(5000);
 }
 
 void Pre_processing_4G(void)//传递消息前处理
@@ -252,7 +279,7 @@ void Pre_processing_4G(void)//
 }
 
 
-void ZHSJ(uint8_t outTt[],char in[])//转换数据
+void Transfer_time(uint8_t outTt[],char in[])//转换时间数据
 {
 	const char *hex = (const char *)in;  // 将 uint8_t * 转换为 const char *
 	int size = strlen(hex) / 2;  // 计算二进制数据的长度
@@ -275,9 +302,9 @@ void RTCtime(void)
 	 tt808.Rtime[5] = GetTime.Seconds;
 	
 	
-	 hexArrayToBcd(tt808.Rtime,6,TimeBCD);
-	 printf("%02X%02X%02X%02X%02X%02X\r\n",tt808.Rtime[0],tt808.Rtime[1],tt808.Rtime[2],tt808.Rtime[3],tt808.Rtime[4],tt808.Rtime[5]);
-	 printf("%02X%02X%02X%02X%02X%02X\r\n",TimeBCD[0],TimeBCD[1],TimeBCD[2],TimeBCD[3],TimeBCD[4],TimeBCD[5]);
+	 hexArrayToBcd(tt808.Rtime,6,dblocptr->location.timeBCD);
+	 //printf("%02X%02X%02X%02X%02X%02X\r\n",tt808.Rtime[0],tt808.Rtime[1],tt808.Rtime[2],tt808.Rtime[3],tt808.Rtime[4],tt808.Rtime[5]);
+	 //printf("%02X%02X%02X%02X%02X%02X\r\n",dblocptr->location.timeBCD[0],dblocptr->location.timeBCD[1],dblocptr->location.timeBCD[2],dblocptr->location.timeBCD[3],dblocptr->location.timeBCD[4],dblocptr->location.timeBCD[5]);
 	 time_bj();//转换时间戳
 	
 }
@@ -303,12 +330,12 @@ void Time_inquiry(uint8_t flag)
 			second_str[2] = '\0';
 			
 
-			ZHSJ(&tt808.Rtime[0],year_str);
-			ZHSJ(&tt808.Rtime[1],month_str);
-			ZHSJ(&tt808.Rtime[2],day_str);
-			ZHSJ(&tt808.Rtime[3],hour_str);
-			ZHSJ(&tt808.Rtime[4],minute_str);
-			ZHSJ(&tt808.Rtime[5],second_str);
+			Transfer_time(&tt808.Rtime[0],year_str);
+			Transfer_time(&tt808.Rtime[1],month_str);
+			Transfer_time(&tt808.Rtime[2],day_str);
+			Transfer_time(&tt808.Rtime[3],hour_str);
+			Transfer_time(&tt808.Rtime[4],minute_str);
+			Transfer_time(&tt808.Rtime[5],second_str);
 			SyncTime(tt808.Rtime[0], tt808.Rtime[1], tt808.Rtime[2], tt808.Rtime[3], tt808.Rtime[4], tt808.Rtime[5]);
 		}
 	}

+ 120 - 116
Core/Src/tt808.c

@@ -37,11 +37,15 @@ extern TipsFlag tipsflag;
 extern Menu_table menu;	
 extern bool refresh;
 //*布尔
-bool ZDJQflag = false;
+bool authFlag = false;
 bool GnssFlag = false;
+bool Offline = false;
+bool Retrans = 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	 
+*/
 uint8_t Messagetemp_length=0;
 uint8_t MessageHandleData[100];	//放入封装后数据
 uint8_t tcppacket[100]; //消息数据
@@ -80,12 +84,12 @@ void MessageHandle(uint16_t MessageID)
 	tcppacket[index++] = TT808FLAG;      // Set the flag at the end
 	
 	
-//	for (int i = 0; i < index; i++) {
-//		printf("%02X ", tcppacket[i]);  // 以十六进制格式打印每个元素
-//	}
-	
+	for (int i = 0; i < index; i++) {
+		printf("%02X ", tcppacket[i]);  // 以十六进制格式打印每个元素
+	}
 	
 	
+	printf("\r\n");
 	char TCPvalue[100];
 	char *ptr = TCPvalue;
 	ptr += sprintf(ptr, "AT+MIPSEND=1,%d,\"",index);
@@ -100,7 +104,13 @@ void MessageHandle(uint16_t MessageID)
 	
 	tt808.LSH+=1;//需做写入处理
 }
-
+uint16_t swapBytes16(uint16_t value) {
+    return (value >> 8) | (value << 8);
+}
+uint32_t swapBytes32(uint32_t value) {
+    return ((value & 0xFF) << 24) | ((value & 0xFF00) << 8) |
+           ((value >> 8) & 0xFF00) | ((value >> 24) & 0xFF);
+}
 /**
   * @breaf 消息体封装
   * Message[] 消息数据;	length 消息数据长度;	outMessage[] 封装后消息数据; MessageID 消息ID
@@ -129,19 +139,19 @@ uint8_t Message_bodydata(uint8_t *Message, uint8_t length, uint8_t outMessage[],
 	else if(MessageID==MessageID_location)//终端地址0200 有附加信息
 	{
 		
-		temp_length = length+6;//不加首尾
+		temp_length = 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);
+		
 		uint8_t temp_Message[temp_length];
 		
 		for (int i = 0; i < length; i++) {
 			temp_Message[index++] = Message[i];  // 将消息头拷贝到报文中
 		}
-		//*begin
-		temp_Message[index++] = 0x30;//信号强度关键字
-		temp_Message[index++] = 0x01;//信号强度数据长度
-		temp_Message[index++] = dblocptr->location.CSQ;//信号强度值
-		temp_Message[index++] = 0x31;//信号强度关键字
-		temp_Message[index++] = 0x01;//信号强度数据长度
-		temp_Message[index++] = dblocptr->location.satellitesNum;//卫星数量
 		
 		for(int i =0;i<temp_length;i++)
 		{
@@ -184,6 +194,7 @@ void tt808FsFunc(uint8_t* Message, uint8_t length, uint16_t MessageID)
 	
 }
 
+
 void printBytes(uint8_t *data, size_t length) {
     for (size_t i = 0; i < length; i++) {
         printf("%02x ", data[i]);
@@ -302,12 +313,9 @@ void hexArrayToBcd(uint8_t* array, size_t length, uint8_t* out) {
     }
 }
 
-//MgnssFlag = true;
 void ReMIPURC(void)
 {
-	 //4D 49 50 55 52 43
-	 if(U4_4GrecvBuff[1]==0x4D && U4_4GrecvBuff[2]==0x49 && U4_4GrecvBuff[3]==0x50 \
-		  && U4_4GrecvBuff[4]==0x55 && U4_4GrecvBuff[5]==0x52 && U4_4GrecvBuff[6]==0x43 && U4_4GrecvBuff[10] != 0x64)	//监测平台回复+MIPURC: 
+	 if(strncmp((char*)U4_4GrecvBuff, "+MIPURC", strlen("+MIPURC"))==0)	//监测平台回复+MIPURC: 
 	 { 
 		uint8_t high_byte = (U4_4GrecvBuff[18]&0x0f) *10; 
 		uint8_t low_byte = U4_4GrecvBuff[19]&0x0f; 
@@ -324,110 +332,81 @@ void ReMIPURC(void)
 		memset(MIPurc1,0,100);
 		 
 	 }
-	//64 69 73 63 6f 6e 6e 22 2c 31 2c 31 "disconn"
-	 else if(U4_4GrecvBuff[10]== 0x64 && U4_4GrecvBuff[11]== 0x69 && U4_4GrecvBuff[12]== 0x73 && U4_4GrecvBuff[13]== 0x63 && U4_4GrecvBuff[14]== 0x6f \
-		 && U4_4GrecvBuff[15]== 0x6e && U4_4GrecvBuff[16]== 0x6e && U4_4GrecvBuff[17]== 0x22 \
-		 && U4_4GrecvBuff[18]== 0x2c && U4_4GrecvBuff[19]== 0x31 && U4_4GrecvBuff[20]== 0x2c && U4_4GrecvBuff[21]== 0x31)
+	 else if(strncmp((char*)U4_4GrecvBuff, "+MGNSSURC: \"state\",1",  strlen("+MGNSSURC: \"state\",1"))==0)
+	 {
+		 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)//断开平台
 	 {
-		 ML307AReset();
+		 printf("#主动取消GNSS\r\n");
+		 memset(U4_4GrecvBuff,0,strlen("+MGNSSURC: \"state\",0"));
+	 }	 
+	 
+	 else if(strncmp((char*)U4_4GrecvBuff, "+MIPURC: \"disconn\"",  strlen("+MIPURC: \"disconn\""))==0)//"disconn" 平台断连
+	 {
+		 Offline=true;
+		 printf("与平台断开连接\r\n");
+		 ML307AReset();//与平台断开连接 offline
 		 memset(U4_4GrecvBuff,0,BUFFER_SIZE);
 	 }
+	 //*连接成功 Offline=false;
+	 
+	 else if(strncmp((char*)U4_4GrecvBuff, "+MIPOPEN: 1,0",  strlen("+MIPOPEN: 1,0"))==0)//连接平台
+	 {
+		 Offline=false;
+		 module4G_F = true;
+		 menu.current = 0xBB;
+		 tipsflag = Back;
+		 refresh=true;
+		 memset(U4_4GrecvBuff,0,BUFFER_SIZE);
+	 }	 
+	 
 
-				//时间     纬度(北纬)   经度(东经)  水平精度因子  海拔高度    定位类型(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	 
-	 else if((U4_4GrecvBuff[2]==0x47 || (U4_4GrecvBuff[0]==0x4F && U4_4GrecvBuff[1]==0x4B)) && MgnssFlag)	//监测平台回复+MGNSSLOC OK4f4b
+	 else if(((strncmp((char*)U4_4GrecvBuff, "+MGNSSLOC", strlen("+MGNSSLOC"))==0) || (strncmp((char*)U4_4GrecvBuff, "OK", strlen("OK"))==0)) && MgnssFlag)	//监测平台回复+MGNSSLOC OK4f4b
 	 {
 
 		memcpy(MGNSSLOC,&U4_4GrecvBuff[11],75);
-		
 		GnssFlag=true;
-	
 		memset(U4_4GrecvBuff,0,BUFFER_SIZE);
 	 }
-	 
-
-	 else if(U5_BTrecvBuff[0]==0x66 && U5_BTrecvBuff[1]==0x00 && U5_BTrecvBuff[2]==0x02 && U5_BTrecvBuff[3]==0x01)//解封接收
-	 {
-		if(U5_BTrecvBuff[4]==0x01)
-		{//接收完成
-			tipsflag = FinshOK;
-			HAL_Delay(1000);
-			if(preworkUp==3)
-			{
-				SET_MENU_STATUS(4,1,0,3);
-			}
-			else if(preworkUp==2)
-			{
-				SET_MENU_STATUS(5,1,0,3);
-			}
-			else if(preworkUp==1)
-			{
-				SET_MENU_STATUS(6,1,0,3);
-			}
-			else if(preworkUp==0)
-			{
-				SET_MENU_STATUS(7,1,0,3);
-			}
-			//USART_SendString(&huart5, "AT+DISCONN=0\r\n");//断开连接
-		}
-		else if(U5_BTrecvBuff[4]==0x02)
-		{//流水号异常
-			
-		}
-		
-	}
-	 else if(U5_BTrecvBuff[0]==0x66 && U5_BTrecvBuff[1]==0x00 && U5_BTrecvBuff[2]==0x03 && U5_BTrecvBuff[3]==0x01)//解封接收
+	 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
 	 {
-	 	if(U5_BTrecvBuff[4]==0x01)
-		{//接收完成
-			tipsflag = FinshOK;
-			HAL_Delay(1000);
-			if(preworkUp==3)
-			{
-				SET_MENU_STATUS(4,1,0,3);
-			}
-			else if(preworkUp==2)
-			{
-				SET_MENU_STATUS(5,1,0,3);
-			}
-			else if(preworkUp==1)
-			{
-				SET_MENU_STATUS(6,1,0,3);
-			}
-			else if(preworkUp==0)
-			{
-				SET_MENU_STATUS(7,1,0,3);
-			}
-			//USART_SendString(&huart5, "AT+DISCONN=0\r\n");//断开连接
-		}
-		else if(U5_BTrecvBuff[4]==0x02)
-		{//流水号异常
-			
-		}
-		
-	}
-	
-	
-	 else if(U5_BTrecvBuff[0]==0x2B && U5_BTrecvBuff[1]==0x43 && U5_BTrecvBuff[2]==0x50 && U5_BTrecvBuff[3]==0x49 && U5_BTrecvBuff[4]==0x4E && \
-		U5_BTrecvBuff[5]==0x3A && U5_BTrecvBuff[6]==0x20 && U5_BTrecvBuff[7]==0x53 && U5_BTrecvBuff[8]==0x49 && U5_BTrecvBuff[9]==0x4D && U5_BTrecvBuff[10]==0x20 && U5_BTrecvBuff[11]==0x52)//+CPIN: SIM R
-	 {
-		reset4Gmodule = true;
+		//TODO
+		printf("SIM卡缺失\r\n");
+		Offline=true;
+		signal = false;
+		menu.current = 0xBB;
+		tipsflag = NoSIM;
+		refresh=true;
+		memset(U4_4GrecvBuff,0,BUFFER_SIZE);
 	 }
-	 else if(U4_4GrecvBuff[1]== 0x4D && U4_4GrecvBuff[2]== 0x47 && U4_4GrecvBuff[3]== 0x4E && U4_4GrecvBuff[4]== 0x53 && U4_4GrecvBuff[5]== 0x53 \
-		 && U4_4GrecvBuff[6]== 0x55 && U4_4GrecvBuff[7]== 0x52 && U4_4GrecvBuff[8]== 0x43 \
-		 && U4_4GrecvBuff[9]== 0x3A && U4_4GrecvBuff[10]== 0x20 && U4_4GrecvBuff[11]== 0x22 && U4_4GrecvBuff[12]== 0x73 \
-		 && U4_4GrecvBuff[19]== 0x31 )
+	 
+	 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未知错误
 	 {
-		 MgnssFlag = true;
+		//TODO
+		 Offline=true;
+		printf("#与平台断开连接\r\n");
+		 ML307AReset();//与平台断开连接 offline
+		memset(U4_4GrecvBuff,0,BUFFER_SIZE);
+		 
 	 }
+//	else if(strncmp((char*)U4_4GrecvBuff+1, "CSQ", strlen("CSQ")))//CSQ 信号
+//	{
+//		memcpy(CSQ,U4_4GrecvBuff,U4_4GrecvLength);
+//		dblocptr->location.CSQ = (uint8_t)(CSQ[6]&0xf*10)+(CSQ[7]&0xf);
+//		memset(CSQ,0,12);
+//		memset(U4_4GrecvBuff,0,BUFFER_SIZE);
+//	}
 	 else if(U4_4GrecvBuff[1]== 0x43 && U4_4GrecvBuff[2]== 0x53 && U4_4GrecvBuff[3]== 0x51)//CSQ 信号
 	 {
 		memcpy(CSQ,U4_4GrecvBuff,U4_4GrecvLength);
-		tt808.CSQ = (CSQ[6]&0xf*10)+(CSQ[7]&0xf);
+		dblocptr->location.CSQ = (uint8_t)(CSQ[6]&0xf*10)+(CSQ[7]&0xf);
 		memset(CSQ,0,12);
 		memset(U4_4GrecvBuff,0,BUFFER_SIZE);
 	 }
-
  }
 
 void MIPURCHandle(void)
@@ -447,7 +426,7 @@ void MIPURCHandle(void)
 				if(YESorNO==YES)
 				{
 					printf("@鉴权应答yes\r\n");
-					ZDJQflag = true;
+					authFlag = true;
 				}
 				else if(YESorNO==NO)
 				{
@@ -475,22 +454,17 @@ void MIPURCHandle(void)
 			 uint8_t tcsjLen = MIPurc[13];
 			 memcpy(MIPurcXXTCSJ,&MIPurc[13],xxtcLen);
 			 printf("@得到透传数据,%d\r\n",tcsjLen);
-			 
-
 			 memset(MIPurc,0,rlt);//rlt下发长度 
 			 
 		 }
-
-	 
 	 }
 	 
-	 else if(ZDJQflag)
+	 else if(authFlag)
 	 {
-		 ZDJQflag = false;
+		 authFlag = false;
 		 HAL_Delay(500);
 	 	 uint8_t test[] = {0x05};			//test心跳
 		 tt808FsFunc(test,1,MessageID_heartbeat);		//test心跳
-		 uploadtime = HAL_GetTick();//获取首次发送状态信息基准时间
 	 }
 }
 
@@ -535,8 +509,13 @@ 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);
+		
 		extractString(MGNSSLOC, csatellitesNum,10 ,11);//采集卫星个数
-		tt808.satellitesNum = convertToDouble(csatellitesNum);	//转换浮点数
+		dblocptr->location.satellitesNum = convertToDouble(csatellitesNum);	//转换浮点数
 		//printf("%d",tt808.satellitesNum);
 		
 		
@@ -576,8 +555,33 @@ void ReU4Proces(void)
 	}
 }
 
-
-
-
+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(Offline)//掉线状态10s入库定位记录
+	{
+		Database_Push(0);
+	}
+	else if(Retrans)//重传 7e0704002701820200777700060001000022000000000000000301cd8b7007278acd00000000000023051918174830011e310103b77e
+	{
+		
+	}
+	else if(countregular==3 && !Offline)//在线状态10s更新状态,30s上传
+	{
+		countregular=0;
+		tt808FsFunc((uint8_t*)&(dblocptr->location.alarmFlag), 34, MessageID_location);
+	}
+	
+}
 
 

+ 8 - 3
MDK-ARM/dtu.uvoptx

@@ -140,7 +140,7 @@
         <SetRegEntry>
           <Number>0</Number>
           <Key>JL2CM3</Key>
-          <Name>-U69618568 -O78 -S3 -ZTIFSpeedSel3000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(1BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8001 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO31 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_512.FLM -FS08000000 -FL080000 -FP0($$Device:STM32F103RE$Flash\STM32F10x_512.FLM)</Name>
+          <Name>-U69618568 -O78 -S2 -ZTIFSpeedSel5000 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(1BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8001 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO31 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_512.FLM -FS08000000 -FL080000 -FP0($$Device:STM32F103RE$Flash\STM32F10x_512.FLM)</Name>
         </SetRegEntry>
         <SetRegEntry>
           <Number>0</Number>
@@ -180,12 +180,17 @@
           <WinNumber>1</WinNumber>
           <ItemText>MIPurcXXTCSJ</ItemText>
         </Ww>
+        <Ww>
+          <count>6</count>
+          <WinNumber>1</WinNumber>
+          <ItemText>U4_4GrecvBuff</ItemText>
+        </Ww>
       </WatchWindow1>
       <MemoryWindow1>
         <Mm>
           <WinNumber>1</WinNumber>
           <SubType>0</SubType>
-          <ItemText>LocDbHeadStart</ItemText>
+          <ItemText>LocDbBodyStart</ItemText>
           <AccSizeX>0</AccSizeX>
         </Mm>
       </MemoryWindow1>
@@ -193,7 +198,7 @@
         <Mm>
           <WinNumber>2</WinNumber>
           <SubType>0</SubType>
-          <ItemText>LocDbBodyStart</ItemText>
+          <ItemText>LocDbHeadStart</ItemText>
           <AccSizeX>0</AccSizeX>
         </Mm>
       </MemoryWindow2>