Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1086377
  • 博文数量: 135
  • 博客积分: 10182
  • 博客等级: 上将
  • 技术积分: 1565
  • 用 户 组: 普通用户
  • 注册时间: 2006-08-07 16:05
文章分类

全部博文(135)

文章存档

2011年(5)

2010年(20)

2009年(3)

2008年(16)

2007年(91)

分类: LINUX

2007-07-22 10:27:11

硬件平台:开发板创维特jx2410,gps模块HOLUX GR-87,USB转串口线一条。程序是在嵌入式linux操作系统下读串口实现。源代码如下:
 
 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#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  {
   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;
}
 
 
阅读(4477) | 评论(3) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-07-21 14:43:33

GPS中国GPS运营www.e-trans.com.cn来自广东专业的车辆监控系统。gps/gis系统涵盖行业物流、公交、出租车、客运、混凝土、旅游、公务车、警察、交通警察、租赁公司等GPs定位系统,gps系统的团队可按客户需求寻求专业化个性化服务。

chinaunix网友2008-12-04 09:14:50

那个就是linux上串口设置,没什么特殊的,你自己搞一个就是。gps模块会自动周期性的通过串口将数据发出来,你直接读取就好了。

chinaunix网友2008-12-03 12:31:12

博主#include "serial.h"的文件有没,或者请教一下,怎么操作GPS模块上获得的数据。jujudx012@163.com,有时间的话给发一份,研读一下,谢谢!