⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connect.c

📁 It is a software to decode information received by a normal GPS like GARMIN, UBLOX if it sends NMEA
💻 C
字号:
#include <termios.h>                                                         #include <stdio.h>  #include <stdlib.h>                                                         #include <unistd.h>                                                          #include <fcntl.h>                                                           #include <sys/signal.h>                                                      #include <sys/types.h>#include <string.h>#include "connect.h"#define BAUDRATE B9600/*int main(){	int fd,i=0;	char buf[1000]; 	int tam;		char port[]="/dev/ttyUSB0";	int baudrate=19200;		init_port(&fd,&port[0],baudrate);	while(i<20)	{		read_port(&fd,&buf[0],&tam);		buf[tam]=0;		printf("%d %s",i,buf);		i++;	}			return 0;}*/void init_port(int *fd,char *port, int baud){		struct sigaction saio;           /* definition of signal action */                                                          	struct termios newtio;	/* open the device to be non-blocking (read will return immediatly) */     	printf("\nport %s\tbaud %d\n",port,baud);	*fd = open(port, O_RDWR | O_NOCTTY | O_NONBLOCK );                    	if (*fd <0) {perror(port); exit(-1); }   	 	/* install the signal handler before making the device asynchronous */     	saio.sa_handler = signal_handler_IO;                                       	//saio.sa_mask = 0;                                                          	saio.sa_flags = 0;                                                         	saio.sa_restorer = NULL;                                                   	sigaction(SIGIO,&saio,NULL);                                               																			   	/* allow the process to receive SIGIO */                                   	fcntl(*fd, F_SETOWN, getpid());                                             	/* Make the file descriptor asynchronous (the manual page says only        	   O_APPEND and O_NONBLOCK, will work with F_SETFL...) */                  	fcntl(*fd, F_SETFL, FASYNC);   	      	newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;                	newtio.c_iflag = IGNPAR | ICRNL | IGNCR ;                                           	newtio.c_oflag = 0;                                                        	newtio.c_lflag = ICANON;                                                   	newtio.c_cc[VMIN]=1;                                                       	newtio.c_cc[VTIME]=0;                                                      	tcflush(*fd, TCIFLUSH);                                                     	tcsetattr(*fd,TCSANOW,&newtio);		}	void signal_handler_IO (int status)                                          {                                                                            //printf("\nSIGIO");                                        //usleep(1000);                                                        }  void read_port(int *fd,char *buf,int *tam){	//pause();	*tam = read(*fd,buf,1000);}void close_port(int *fd){	close(*fd);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -