野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 17999|回复: 1

GPS信号筛选问题

[复制链接]
发表于 2019-1-19 11:53:50 | 显示全部楼层 |阅读模式
之前看到一个采集GPS信号的程序,该程序是否过滤掉了无用字符?采用的是否是$GPGGA协议?假若采用,正确的采集方式应该是如何?
[mw_shl_code=c,true]#include "stm32f10x.h"
//#include "stm32f10x_it.h"
#include "delay.h"
#include "sys.h"
#include "key.h"
#include "led.h"
#include "usart.h"
#include "MY_time_Conf.h"
#include "string.h"
#include "timer.h"


int i=0;
extern u16   USRT4_RX_FLAG;                          //北斗串口4接收数据成功标志位
extern u8    Reciver[47];                       //串口4北斗卫星接受的数据,包括反馈信息和数据信息

extern char isGetData;                //是否获取到GPS数据
extern char GPS_Buffer[GPS_Buffer_Length];

//u8 Position_Comder[22]={0x24, 0x44 ,0x57, 0x53 ,0x51, 0x00, 0x16, 0x36, 0x46,0x78, 0x04,        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  0x2F};
///*                      //    定位标识$DWSQ       //  // 长度 //  //本机用户地址// //信息类别// //高程数据和天线高  //  // 气压数据         //  //入站频度// //异或校验和*/
u8 Communication_Comder[72]=
                        {       
                                        0x24,0x54,0x58,0x53,0x51,            //单次通信              0  1  2  3  4  
                                  0x00,0x48,                           //所有指令的长度,               5  6
                                        0x05,0x97,0x34,                      //本机用户地址                7  8  9          新版北斗有强制的规定一定要写入本机用户地址,不然没有反馈信息
          0x46,                                                                                                                                 //信息类别0x46(代码),0x44(汉字)   10
          0x06,0xff,0x99,                      //接收方地址                 11 12 13
          0x01,0xB0,                           //电文长度单位bit(54*8)         14 15
                                        0x00,                                //是否应答(否)                     16
                                  0x00,0x00,0x00,0x00,0x00,                                                           //电文内容 :时间时分秒.1秒17 18 19 20 21
                                  0x00,0x00,0x00,0x00,0x00,                                                                 //电文内容 :经度度分秒.1秒22 23 24 25 26
                                  0x00,0x00,0x00,0x00,0x00,                                                                 //电文内容 :纬度度分秒.1秒27 28 29 30 31
                                  0x00,0x00,0x00,0x00,0x00,                                                                 //电文内容 :纬度度分秒.1秒32 33 34 35 36
                                  0x00,0x00,0x00,0x00,0x00,                                                                 //电文内容 :纬度度分秒.1秒37 38 39 40 41
                                  0x00,0x00,0x00,0x00,0x00,                                                                 //电文内容 :纬度度分秒.1秒42 43 44 45 46
                                  0x00,0x00,0x00,0x00,0x00,                                                                 //电文内容 :纬度度分秒.1秒47 48 49 50 51
                                  0x00,0x00,0x00,0x00,0x00,                                                                 //电文内容 :纬度度分秒.1秒52 53 54 55 56
                                  0x00,0x00,0x00,0x00,0x00,                                                                 //电文内容 :纬度度分秒.1秒57 58 59 60 61
                                  0x00,0x00,0x00,0x00,0x00,                                                                 //电文内容 :纬度度分秒.1秒62 63 64 65 66
                                  0x00,0x00,0x00,0x00,                                                                     //电文内容 :纬度度分秒.1秒67 68 69 70
          0x00                                     //校验位                           71
                        };
               

//       
//struct data                       //储存北斗卫星的数据
//{
//                u8 hour;                      //时间.时
//                u8 minute;                                                                                //时间.分
//                u8 second;                    //时间.秒
//       
//                u8 longitude_tolerance;       //经度.度
//                u8 longitude_fraction;        //经度.分
//          u8 longitude_seconds;         //经度.秒
//          u8 longitude_piont;           //经度.点
//       
//          u8 latitude_tolerance;        //纬度.度
//                u8 latitude_fraction;         //纬度.分
//          u8 latitude_seconds;          //纬度.秒
//          u8 latitude_piont;            //纬度.点
//       
//    u8 High_data;                 //高程数据
//                u8 abnormal_Highdata;         //高程异常值
//}satellite;

void Delay_us(uint32_t nTime);
void Delay_ms(uint32_t nTime);
void Delay_s(int s);

void  USART1_Printfu8(u8 data);
u8    XOR_(u8 buf[],u8 length);    //求异或值       
void UpdataGPS1(void);
void UpdataGPS2(void);
//012345678911234567892123456789312345678941234567895123456789
//$GPRMC,045914.00,A,3053.02758,N,12153.51950,E,0.218,,141017,,,A*75
//012345678911234567892123456789312345678941234567895123456789
/*       hhhhhh      NNNNNNNNNN   EEEEEEEEEEE*/
int main(void)
{
   delay_init();
         RCC_Configuration();      //初始化时钟
         GPIO_Configuration();      //初始化IO端口
   NVIC_Configuration();      //中断优先级初始化
   LED_Init();  
     USART1_Config();         //初始化 配置USART1  用串口转网口的接收指令发送数据
   USART2_Config();         //初始化GPS数据                                                                                    //USART3_Config();
         UART4_Config();          //接收北斗数据
   //LED0=0;                         //刚开始LED灯灭

   //printf("GPS测试");
         while(1)
         {
                 //LED0=1;
     if(isGetData==1)
                 {  
                    isGetData=0;
                                UpdataGPS1();
                 }
                 Delay_s(31);
                 //printf("31S更新数据一次");
                 if(isGetData==1)
                 {  
                    isGetData=0;
                                UpdataGPS2();
                 }
                 Delay_s(31);
                 //printf("62S数据更新两次,数据更新成功");               
                 for(i=0;i<72;++i)                                         //通过串口四发送获取位置指令
                 {
                                USART_SendData(UART4,Communication_Comder);
        delay_ms(1);                         
        while(USART_GetFlagStatus(UART4,USART_FLAG_TC)!=SET);
                 }
                 //printf("发送完北斗指令");               
         }       
         
        

}



void USART1_Printfu8(u8 data)
{
                        USART_SendData(USART1,data);
      delay_ms(1);                         
      while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);
}


//求异或值
u8 XOR_(u8 buf[],u8 length)
{
                        u8 buf_xor=0x00;                   //最后计算出来的异或值
            int i;                             //for语句循环变量
                        for(i=0;i<length;++i)
            {
                                        buf_xor^=buf;
            }
                        return buf_xor;
}

void Delay_s(int s)                  //延时秒钟
{
                int i;
          for(i=0;i<s;++i)
                                Delay_ms(1000);
}
void Delay_us(uint32_t nTime)
{
        SysTick->LOAD=72*nTime;
        SysTick->CTRL=0x00000005;
        while(!(SysTick->CTRL&0x00010000));
        SysTick->CTRL=0x00000004;
}

void Delay_ms(uint32_t nTime)
{
        for(;nTime>0;nTime--)
                Delay_us(1000);
}

void UpdataGPS1(void)
{
                            Communication_Comder[17] =                GPS_Buffer[7];       
                                 Communication_Comder[18] =   GPS_Buffer[8];   
                                 Communication_Comder[19] =   GPS_Buffer[9];
                                 Communication_Comder[20] =   GPS_Buffer[10];                                 
                                 Communication_Comder[21] =                GPS_Buffer[11];       
                                 Communication_Comder[22] =   GPS_Buffer[12];   
                                 Communication_Comder[23] =   GPS_Buffer[19];
                                 Communication_Comder[24] =   GPS_Buffer[20];                                 
                                 Communication_Comder[25] =                GPS_Buffer[21];       
                                 Communication_Comder[26] =   GPS_Buffer[22];   
                                 Communication_Comder[27] =   GPS_Buffer[23];
                                 Communication_Comder[28] =   GPS_Buffer[24];                                 
                                 Communication_Comder[29] =                GPS_Buffer[25];       
                                 Communication_Comder[30] =   GPS_Buffer[26];  
                                 Communication_Comder[31] =                GPS_Buffer[27];       
                                 Communication_Comder[32] =   GPS_Buffer[28];   
                                 Communication_Comder[33] =   GPS_Buffer[32];
                                 Communication_Comder[34] =   GPS_Buffer[33];                                 
                                 Communication_Comder[35] =                GPS_Buffer[34];       
                                 Communication_Comder[36] =   GPS_Buffer[35];   
                                 Communication_Comder[37] =   GPS_Buffer[36];
                                 Communication_Comder[38] =   GPS_Buffer[37];                                 
                                 Communication_Comder[39] =                GPS_Buffer[38];       
                                 Communication_Comder[40] =   GPS_Buffer[39];        
                                 Communication_Comder[41] =                GPS_Buffer[40];       
                                 Communication_Comder[42] =   GPS_Buffer[41];   
                                 Communication_Comder[43] =   GPS_Buffer[42];
}
void UpdataGPS2(void)
{
                            Communication_Comder[44] =                GPS_Buffer[7];       
               Communication_Comder[45] =   GPS_Buffer[8];         
                                 Communication_Comder[46] =   GPS_Buffer[9];
                                 Communication_Comder[47] =   GPS_Buffer[10];                                 
                                 Communication_Comder[48] =                GPS_Buffer[11];       
                                 Communication_Comder[49] =   GPS_Buffer[12];   
                                 Communication_Comder[50] =   GPS_Buffer[19];
                                 Communication_Comder[51] =   GPS_Buffer[20];                                 
                                 Communication_Comder[52] =                GPS_Buffer[21];       
                                 Communication_Comder[53] =   GPS_Buffer[22];   
                                 Communication_Comder[54] =   GPS_Buffer[23];
                                 Communication_Comder[55] =   GPS_Buffer[24];                                 
                                 Communication_Comder[56] =                GPS_Buffer[25];       
                                 Communication_Comder[57] =   GPS_Buffer[26];  
                                 Communication_Comder[58] =                GPS_Buffer[27];       
                                 Communication_Comder[59] =   GPS_Buffer[28];   
                                 Communication_Comder[60] =   GPS_Buffer[32];
                                 Communication_Comder[61] =   GPS_Buffer[33];                                 
                                 Communication_Comder[62] =                GPS_Buffer[34];       
                                 Communication_Comder[63] =   GPS_Buffer[35];   
                                 Communication_Comder[64] =   GPS_Buffer[36];
                                 Communication_Comder[65] =   GPS_Buffer[37];                                 
                                 Communication_Comder[66] =                GPS_Buffer[38];       
                                 Communication_Comder[67] =   GPS_Buffer[39];        
                                 Communication_Comder[68] =                GPS_Buffer[40];       
                                 Communication_Comder[69] =   GPS_Buffer[41];   
                                 Communication_Comder[70] =   GPS_Buffer[42];
                                 Communication_Comder[71] =   XOR_(Communication_Comder,71);
                 
}[/mw_shl_code]
回复

使用道具 举报

发表于 2019-1-21 08:37:50 | 显示全部楼层
没看明白它的思路
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2025-12-6 06:45 , Processed in 0.040811 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表