資源簡(jiǎn)介
調(diào)試過(guò)了,可以用的,針對(duì)不同的模塊自己修改下就好了。不懂可以咨詢我

代碼片段和文件信息
#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??設(shè)置串口通信速率
*@param??fd?????類(lèi)型?int??打開(kāi)串口的文件句柄
*@param??speed??類(lèi)型?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)//設(shè)置波特率
{
int???i;
int???status;
struct?termios???Opt;
tcgetattr(fd?&Opt);
for(?i=?0;??i? {
??? if(speed?==?name_arr[i])
{
??? ????tcflush(fd?TCIOFLUSH);
???? cfsetispeed(&Opt?speed_arr[i]);//輸入波特率函數(shù)
???? cfsetospeed(&Opt?speed_arr[i]);//輸出波特率函數(shù)
???? status?=?tcsetattr(fd?TCSANOW?&Opt);//TCSANOW??不等數(shù)據(jù)傳輸完畢就立即改變屬性。激活波特率的配置
???? if(status?!=?0)
????????????perror(“tcsetattr?fd1“);
????? return;
}
tcflush(fdTCIOFLUSH);
}
}
/**
*@breif?打開(kāi)串口
*/
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函數(shù)用于獲取與終端相關(guān)的參數(shù)?
// 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???設(shè)置串口數(shù)據(jù)位,停止位和效驗(yàn)位
*@param??fd?????類(lèi)型??int??打開(kāi)的串口文件句柄*
*@param??databits?類(lèi)型??int?數(shù)據(jù)位???取值?為?7?或者8*
*@param??stopbits?類(lèi)型??int?停止位???取值為?1?或者2*
*@param??parity??類(lèi)型??int??效驗(yàn)類(lèi)型?取值為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
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????文件???????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
評(píng)論
共有 條評(píng)論