打印
[ARM入门]

谁有arm开发板读取gps信息的程序,希望最好有注释

[复制链接]
1135|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
我这有个程序看不太懂,有大神能给我注释一些吗,谢谢了ARM开发板上GPS信息的读取 (2007-07-22 10:27)
分类: S3C2410
硬件平台:开发板创维特jx2410,gps模块HOLUX GR-87,USB转串口线一条。程序是在嵌入式linux操作系统下读串口实现。源代码如下:


#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
#include <stdlib.h>
#include "serial.h"
//
#define UInt32     unsigned int
#define Int16      short
#define UInt16     unsigned short
#define UInt8      unsigned char
#define Boolean    int
#define false      0
#define true       1
#define GPS_RECV_CMD_MAX_BUF 256 //the buffer size

//the gga info struct
typedef struct GGAINFO{
int    bIsGPGGA;                 
UInt8  hour, bjhour, min, sec, secFrac;
double latitude;               
UInt8  latNS;                  
double longitude;              
UInt8  lgtEW;               
// UInt8  hour, bjhour, min, sec, secFrac;
UInt8  satellites;              
Int16  altitude;        
// UInt8  altUnit;               
}GGAINFO;
int main(void)
{
int fd;
int i;
char buffer[GPS_RECV_CMD_MAX_BUF];//receive buffer
char tmp;
GGAINFO ggainfo;
char Degree[4];
char Minute[8];
char Hour[4];
char Minu[4];
char Second[4];
char Satnum[4];
int no = 0;
//open the COM
if((fd=open_port(fd,4))<0)
{
  perror("open_port error");
  return;
}
printf("fd=%d\n",fd);
//set the COM
if((i=set_opt(fd,9600,8,'N',1))<0)
{
  perror("set_opt error");
  return;
}
//
while(1)
{
  while(!Is_startGP(fd));
//  printf("start to receive\n");

  //receive the info
  for(i = 0; i<GPS_RECV_CMD_MAX_BUF;i++)
  {
   read(fd,&tmp,1);
   buffer[i]=tmp;
//   printf("%c",buffer[i]);
   if(tmp=='\n')break;
  }
//  printf("\n");
  //proc the GGA info
  if(Is_GGA(buffer))
  {
   ggainfo.bIsGPGGA = 1;
   //Time:6-15
   no = 6;
   for(i = 0;i < 4;i++)
    Hour[i]=0;
   Hour[0]=buffer[no];
   Hour[1]=buffer[no+1];

   no += 2;
   for(i = 0;i < 4;i++)
    Minu[i]=0;
   Minu[0]=buffer[no];
   Minu[1]=buffer[no+1];
   no += 2;
   for(i = 0;i < 4;i++)
    Second[i]=0;
   Second[0]=buffer[no];
   Second[1]=buffer[no+1];
   ggainfo.hour = atoi(Hour);
   ggainfo.min = atoi(Minu);
   ggainfo.sec = atoi(Second);
   ggainfo.secFrac = 0;
   ggainfo.bjhour = ggainfo.hour + 8;
   if(ggainfo.bjhour > 24)
    ggainfo.bjhour -=  24;

   //Latitude:17-25
   no = 17;
   for(i = 0;i < 4;i++)
    Degree[i]=0;
   Degree[0]=buffer[no];
   Degree[1]=buffer[no+1];
   no+=2;
   for(i=0;i<8;i++)
    Minute[i]=0;
   for(i=0;i<7;i++)
    Minute[i]=buffer[no+i];
   // int l=atoi(Degree);
   ggainfo.latitude=(atof(Minute)) / 60.0 + atoi(Degree);

   //NS:27
   ggainfo.latNS = buffer[27];

   //Longitude:29-38
   no = 29;
   for(i=0;i<4;i++)
    Degree[i]=0;
   Degree[0]=buffer[no];
   Degree[1]=buffer[no+1];
   Degree[2]=buffer[no+2];
   no+=3;
   for(i=0;i<8;i++)   
    Minute[i]=0;
   for(i=0;i<7;i++)
    Minute[i]=buffer[no+i];
   // int B=atoi(Degree);
   ggainfo.longitude=(atof(Minute)) / 60.0 + atoi(Degree);
   //WE:40
   ggainfo.lgtEW = buffer[40];

   //the number of satellite:44-45
   no = 44;
   for(i = 0;i < 4;i++)
    Satnum[i]=0;
   Satnum[0]=buffer[no];
   Satnum[1]=buffer[no+1];
   ggainfo.satellites = atoi(Satnum);

   printf("UTC Time:%d h %d m %d s\n",ggainfo.hour,ggainfo.min,ggainfo.sec);
   printf("BJ Time:%d h %d m %d s\n",ggainfo.bjhour,ggainfo.min,ggainfo.sec);
   printf("Latitude:%c wei %f \n",ggainfo.latNS,ggainfo.latitude);
   printf("Longitude:%c jing %f \n",ggainfo.lgtEW,ggainfo.longitude);
   printf("Satellites:%d \n",ggainfo.satellites);
   printf("\n");
  }
  else continue;
  sleep(1);
}
close(fd);
return 0;
}

int Is_startGP(int fp)
{
int status=0;
char cc,tmp;
read(fp,&cc,1);
tmp=cc;
if(tmp=='$')status=1;
return status;
}

int Is_GGA(char p[GPS_RECV_CMD_MAX_BUF])
{
int status=0;
if(p[2] == 'G' && p[3] == 'G' && p[4] == 'A')
  status=1;
return status;
}

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

9

主题

12

帖子

0

粉丝