• 大小: 10KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-05-08
  • 语言: 其他
  • 标签: gps  定位  串口  

资源简介

调试过了,可以用的,针对不同的模块自己修改下就好了。不懂可以咨询我

资源截图

代码片段和文件信息

#include “pf_gps.h“
#include      
#include      
#include     
#include   
#include  
#include    
#include      
#include     
#include   
#include 
#include 
#include 
#include 
#include 

typedef struct
{
char *dev_path;
pthread_t gps_thread;
int gps_fd;
int gps_client_fd;
int gps_server_fd;
void *user_param;
int user_param_len;
gps_call_back_fun call_back_fun;
//gps_data_t* back_gps_data;
}gps_classe;

#define FALSE 0
#define TRUE 1

#define MAX_GPS_CMD_BYTES 255

gps_classe tty_gps;
gps_data_t* back_gps_data;

/***@brief  设置串口通信速率
*@param  fd     类型 int  打开串口的文件句柄
*@param  speed  类型 int  串口速度
*@return  void*/

static int speed_arr[] = {B500000 B460800 B230400 B115200 B57600 B38400 B19200 B9600 B4800 B2400 B1200 B300
    B57600 B38400 B19200 B9600 B4800 B2400 B1200 B300 };
static int name_arr[] = {500000 460800 230400 115200 57600 38400  19200  9600  4800  2400  1200  300
    57600 38400  19200  9600 4800 2400 1200  300 };

static void uart_set_speed(int fd int speed)//设置波特率
{
int   i;
int   status;
struct termios   Opt;
tcgetattr(fd &Opt);
for( i= 0;  i < sizeof(speed_arr) / sizeof(int);  i++)
{
    if(speed == name_arr[i])
{
        tcflush(fd TCIOFLUSH);
     cfsetispeed(&Opt speed_arr[i]);//输入波特率函数
     cfsetospeed(&Opt speed_arr[i]);//输出波特率函数
     status = tcsetattr(fd TCSANOW &Opt);//TCSANOW  不等数据传输完毕就立即改变属性。激活波特率的配置
     if(status != 0)
            perror(“tcsetattr fd1“);
      return;
}
tcflush(fdTCIOFLUSH);
}
}


/**
*@breif 打开串口
*/
static int uart_open(char *Dev int open_flags)
{
struct termios opt;
printf(“open successful123\n“);
int fd = open(Dev open_flags);         //
if (-1 == fd)
{
perror(“Can‘t Open Serial Port“);
return -1;
}

printf(“open successful\n“);
fflush(stdout);

tcgetattr (fd &opt);//tcgetattr函数用于获取与终端相关的参数 
// opt.c_lflag &= ~(ICANON | ECHO | ISIG); 
opt.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);

    /*
     * No SIGINT on BREAK CR-to-NL off input parity
     * check off don‘t strip 8th bit on input output
     * flow control off.
     */
//    opt.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
opt.c_iflag &= ~(BRKINT | ICRNL);
opt.c_oflag &= ~(OPOST);


tcsetattr (fd TCSANOW &opt); 

tcflush(fd TCIOFLUSH);
return fd;
}


/**
*@brief   设置串口数据位,停止位和效验位
*@param  fd     类型  int  打开的串口文件句柄*
*@param  databits 类型  int 数据位   取值 为 7 或者8*
*@param  stopbits 类型  int 停止位   取值为 1 或者2*
*@param  parity  类型  int  效验类型 取值为NEOS
*/
static int uart_set_param(int fdint databitsint stopbitsint parity int flow int read_len)
{
struct termios options;

if( tcgetattr( fd&options)  !=  0)
{
   perror(“SetupSerial 1“);
   return

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件       27743  2012-05-21 14:51  gps.c
     文件        1368  2012-05-18 19:29  pf_gps.h
     文件        5003  2012-05-15 14:40  pf_hi.h

评论

共有 条评论