Explorar el Código

Gps模拟数据上传通过,后续进行小范围修改,存在不休眠和重启问题

CHENJIE-PC\QiXiang_CHENJIE hace 4 años
padre
commit
c003985433
Se han modificado 3 ficheros con 88 adiciones y 19 borrados
  1. 1 1
      inc/hal_module_adapter.h
  2. 82 15
      src/app.c
  3. 5 3
      src/hal_module_adapter.c

+ 1 - 1
inc/hal_module_adapter.h

@@ -126,7 +126,7 @@ typedef struct  _GPS_INFO
 	uint8_t satellite_num;
 	uint16_t direction;
 	uint16_t speed;
-	uint16_t height;
+	uint16_t altitude;
 	uint32_t latitude;
 	uint32_t longitude;
 }GPS_INFO;

+ 82 - 15
src/app.c

@@ -43,6 +43,7 @@ static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
 volatile bool isRecvTimeout = false;
 volatile bool isRecvComplete = false;
 QueueHandle_t gpsMsgQueue = NULL;
+GPS_INFO Gps_Data;
 static volatile UINT32          Event;
 static QueueHandle_t            psEventQueueHandle;
 static UINT8                    gImsi[16] = {0};
@@ -71,7 +72,17 @@ uint8_t battbuffer[100];//电池数据都存在此数组中————电压14
  *          电池状态    是否加热       最高单体H    最高单体L   最低单体H      最低单体L
  * */
 //GPS信息
-extern GPS_INFO Gps_Data;
+uint8_t gpsbuffer[30];//定位都存在此数组中
+/**
+ *  存放规则如下:
+ * 位置:   0       1       2       3       4       5       6       7       8       9       10      11      12      13      14      15              16             
+ * 数据:   年      月      日      时      分      秒    信息体标志  年      月      日      时      分       秒    定位标志  卫星数目  航向H     航向L
+ * 
+ *         17      18       19          20          21          22         23       24      25           26           27       28
+ *         速度H    速度L  海拔H        海拔L       纬度HH       纬度HL      纬度LH   纬度LL   经度HH       经度HL      经度LH   经度LL    
+ *
+ * */
+//GPS信息
 //状态机定义
 typedef enum
 {
@@ -272,6 +283,7 @@ static void Main_Task(void* arg)
                     PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_SLEEP);
                     PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_SLEEP);
                 }
+                Sleep_Flag = TRUE;
                 osDelay(1000);
                 #ifdef USING_PRINTF
                             printf("Ms_sleep:uart_%d,can_%d,tcp_%d\r\n",gProcess_Uart_Task,gProcess_Can_Task,gProcess_Tcp_Task);
@@ -299,15 +311,7 @@ static void Main_Task(void* arg)
                 #ifdef USING_PRINTF
                     printf("which slpstate can go now :%d \n",slpstate);
                 #endif
-                #ifdef USING_PRINTF
-                    printf("Main_Sleep\n");
-                #endif
-                FaultDisplay(LED_TURN_ON);
-                slpManDeepSlpTimerStart(deepslpTimerID,600000); 
-                slpManSlpState_t slpstate = slpManPlatGetSlpState();
-                #ifdef USING_PRINTF
-                    printf("which slpstate can go now :%d \n",slpstate);
-                #endif
+
                 while(1)
                 {
                     osDelay(60000/portTICK_PERIOD_MS);
@@ -654,7 +658,6 @@ static void Can_Task(void* arg)
     slpManPlatVoteDisableSleep(CanSlpHandler, SLP_SLP2_STATE);
     volatile bool Can_Flag=false;
     PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_IDLE);
-    GPS_INFO Gps_Data;
     posGGAServiceStart(GGACallBack);
 
     while(1)
@@ -1010,6 +1013,43 @@ void Tcp_Batt_Data_Assemble(void)
     battbuffer[data_index] = 0x00;//是否加热
     data_index++;
 }
+//Gps 数据组装函数
+void Tcp_Gps_Data_Assemble(void)
+{
+    OsaUtcTimeTValue timestracture;
+    appGetSystemTimeUtcSync(&timestracture);
+    gpsbuffer[0] = timestracture.UTCtimer1>>16;
+    gpsbuffer[0] = gpsbuffer[0] - 0x07D0;
+    gpsbuffer[1] = timestracture.UTCtimer1>>8;
+    gpsbuffer[2] = timestracture.UTCtimer1;
+    gpsbuffer[3] = timestracture.UTCtimer2>>24;
+    gpsbuffer[4] = timestracture.UTCtimer2>>16;
+    gpsbuffer[5] = timestracture.UTCtimer2>>8;
+    gpsbuffer[6] = 0x82;//信息体标志,此处为GPS信息
+    gpsbuffer[7] = gpsbuffer[0];//年 
+    gpsbuffer[8] = gpsbuffer[1];//月
+    gpsbuffer[9] = gpsbuffer[2];//日
+    gpsbuffer[10] = gpsbuffer[3];//时 0时区时间
+    gpsbuffer[11] = gpsbuffer[4];//分
+    gpsbuffer[12] = gpsbuffer[5];//秒
+    gpsbuffer[13] = Gps_Data.status;
+    gpsbuffer[14] = Gps_Data.satellite_num;
+    gpsbuffer[15] = Gps_Data.direction>>8;
+    gpsbuffer[16] = Gps_Data.direction;
+    gpsbuffer[17] = Gps_Data.speed>>8;
+    gpsbuffer[18] = Gps_Data.speed;
+    gpsbuffer[19] = Gps_Data.altitude>>8;
+    gpsbuffer[20] = Gps_Data.altitude;
+    gpsbuffer[21] = Gps_Data.latitude>>24;
+    gpsbuffer[22] = Gps_Data.latitude>>16;
+    gpsbuffer[23] = Gps_Data.latitude>>8;
+    gpsbuffer[24] = Gps_Data.latitude;
+    gpsbuffer[25] = Gps_Data.longitude>>24;
+    gpsbuffer[26] = Gps_Data.longitude>>16;
+    gpsbuffer[27] = Gps_Data.longitude>>8;
+    gpsbuffer[28] = Gps_Data.longitude;
+
+}
 //Tcp线程
 static void Tcp_Task(void* arg)
 {
@@ -1022,7 +1062,6 @@ static void Tcp_Task(void* arg)
     hints.ai_socktype = SOCK_STREAM;
     hints.ai_protocol = IPPROTO_TCP;
     psEventQueueHandle = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(eventCallbackMessage_t*));
-    int NB_send_len=59+Batt_Cell_Num_2+Batt_Temp_Num;//设定tcp发送的最大数值,以电池数据为上线
     slpManApplyPlatVoteHandle("TcpSlp",&TcpSlpHandler);
     slpManPlatVoteDisableSleep(TcpSlpHandler, SLP_SLP2_STATE);
     PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_IDLE);
@@ -1033,6 +1072,7 @@ static void Tcp_Task(void* arg)
     uint8_t pmode;
     uint32_t tau;
     uint32_t act;
+    uint8_t NB_send_len;
     appSetEDRXSettingSync(0,5,0);
     appSetPSMSettingSync(1,3*60*60,10);
     appGetPSMSettingSync(&pmode,&tau,&act);
@@ -1103,7 +1143,6 @@ static void Tcp_Task(void* arg)
                     printf("psm:pmode-%d,tau-%d,act-%d!\n",pmode,tau,act);
                 #endif
                 Tcp_Flag = false;
-                TcpSendBuffer = (uint8_t *)malloc(NB_send_len);
                 while (!Tcp_Flag)
                 {
                     switch(Tcp_Index)
@@ -1115,6 +1154,9 @@ static void Tcp_Task(void* arg)
                         }
                         case 1://发送电池数据
                         {
+                            NB_send_len=59+Batt_Cell_Num_2+Batt_Temp_Num;//电池数据长度
+                            TcpSendBuffer = (uint8_t *)malloc(NB_send_len);
+                            data_index = 0;
                             memset(TcpSendBuffer,0x00,NB_send_len);
                             *(TcpSendBuffer+0) = 0x23;
                             *(TcpSendBuffer+1) = 0x23;
@@ -1145,11 +1187,37 @@ static void Tcp_Task(void* arg)
                                 }
                                 printf("\n");
                             #endif
+                            free(TcpSendBuffer);
                             Tcp_Index=2;
                             break;
                         }
                         case 2:
                         {
+                            data_index = 29;
+                            NB_send_len = 25+29;//数据总长度:25个固定+29个GPS长度
+                            TcpSendBuffer = (uint8_t *)malloc(NB_send_len);
+                            memset(TcpSendBuffer,0x00,NB_send_len);
+                            *(TcpSendBuffer+0) = 0x23;
+                            *(TcpSendBuffer+1) = 0x23;
+                            *(TcpSendBuffer+2) = 0x02;
+                            *(TcpSendBuffer+3) = 0xfe;
+                            memcpy(TcpSendBuffer+4,SN,17);
+                            *(TcpSendBuffer+21) = 0x01;//01表示不加密
+                            Tcp_Gps_Data_Assemble();//Gps数据组装
+                            *(TcpSendBuffer+22) = data_index>>8;//数据长度
+                            *(TcpSendBuffer+23) = data_index;//数据长度     
+                            memcpy(TcpSendBuffer+24,gpsbuffer,data_index);
+                            *(TcpSendBuffer+NB_send_len-1) = bcc_chk(TcpSendBuffer,NB_send_len-1);
+                            #ifdef USING_PRINTF
+                                printf("ConnectID:%d,TcpSend:%d,data length:%d,Data:  ",sockfd,TcpsendID,NB_send_len);
+                                for (int i = 0; i < NB_send_len; i++)
+                                {
+                                    printf("%x ",*(TcpSendBuffer+i));
+                                }
+                                printf("\n");
+                            #endif
+                            TcpsendID = send(sockfd, TcpSendBuffer, NB_send_len, 0 );
+                            free(TcpSendBuffer);
                             Tcp_Index=3;
                             break;
                         }
@@ -1161,7 +1229,6 @@ static void Tcp_Task(void* arg)
                         }
                     } 
                 }
-                free(TcpSendBuffer);
                 break;
             }
             case PROCESS_TCP_STATE_SLEEP:
@@ -1254,7 +1321,7 @@ void Tcp_Task_Init()
 void appInit(void *arg)
 {
     Main_Task_Init();
-    Uart_Task_Init(); 暂时屏蔽Uart读取
+    Uart_Task_Init();
     Can_Task_Init();
     GpsTaskInit();
     Tcp_Task_Init();

+ 5 - 3
src/hal_module_adapter.c

@@ -1650,7 +1650,7 @@ static void GpsProcess(void* arg)
     while(1)
     {
 		//char temp[] = "$GNGGA,082626.00,2939.91801,N,10637.09500,E,1,03,2.34,-20.3,M,,M,,*40";
-		//char temp[] = "$GNRMC,082626.000,A,2939.91801,N,10637.09500,E,0.543,30.254,261120,,,A,V*17";
+		char temp[] = "$GNRMC,082626.000,A,2939.91801,N,10637.09500,E,0.543,30.254,261120,,,A,V*17";
 		osMessageQueueGet(gpsMsgHandle, &msg, 0, 5000);
 		if (msg.dataPtr)
 		{		
@@ -1663,8 +1663,8 @@ static void GpsProcess(void* arg)
 				printf("\nP msgptr data:%s\r\n",p);
 			#endif
 			int i=0;
-			p = strtok(p,",");//只取第1行的信息RMC
-
+			//p = strtok(p,",");//只取第1行的信息RMC
+			p = strtok(temp,",");//模拟测试
 			if (strcmp(p,"$GNRMC")==0)
 			{			
 				while (p)
@@ -1702,6 +1702,7 @@ static void GpsProcess(void* arg)
 					Gps_buffer.speed = speedtemp/1e5;
 					Gps_buffer.latitude = location_handle(databuffer[3]);
 					Gps_buffer.longitude = location_handle(databuffer[5]);
+					Gps_buffer.altitude = 00;
 					if(Gps_buffer.speed>=100)//大于10km/h才输出方位
 					{
 						Gps_buffer.direction = atol(databuffer[8]);
@@ -1714,6 +1715,7 @@ static void GpsProcess(void* arg)
 			msgtemp=NULL;
 		}
 		msg.dataPtr=NULL;
+		
 		if (Sleep_Flag)
 		{
 			osThreadExit();