关于GPS的使用,参考。
本文主要参考的博客,在此表示感谢!!!
主函数
主函数gps_main.c,这里便涉及到了串口的打开,读操作,以及调用了串口设置函数:
#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 "gps.h"
#define GPS_LEN 512
int set_serial(int fd,int nSpeed, int nBits, char nEvent, int nStop);
int gps_analyse(char *buff,GPRMC *gps_date);
int print_gps(GPRMC *gps_date);
int main (int argc, char **argv)
{
int fd = 0;
int nread = 0;
GPRMC gprmc;
char gps_buff[GPS_LEN];
char *dev_name = "/dev/ttyUSB0";
fd = open(dev_name,O_RDWR|O_NOCTTY|O_NDELAY);
if(fd<0)
{
printf("open ttyUSB0 failed.\n");
return -1;
}
set_serial( fd,9600,8,'N