Ejemplo n.º 1
0
int init_parser()
{                               // returns zero if no errors
    int status;
    parser_initialized = 1;
    status = nmeap_init(&nmea, (void *) &dont_care);
    if (status != 0) {
        fprintf(stderr, "nmeap_init failed: %d\n", status);
        return status;
    }

    status = nmeap_addParser(&nmea, "GPRMC", nmeap_gprmc, callback, &rmc);
    if (status != 0) {
        fprintf(stderr, "nmeap_add failed: %d\n", status);
        return status;
    }
    return 0;
}
Ejemplo n.º 2
0
int main(int argc,char *argv[])
{
    int  status;
    int  rem;
	int  offset;
	int  len;
	char buffer[32];
    int  fd;
    const char *port = "/dev/ttyS0";
    
    // default to ttyS0 or invoke with 'linux_nmeap <other serial device>' 
    if (argc == 2) {
        port = argv[1];
    }
    
    /* --------------------------------------- */
    /* open the serial port device             */
    /* using default 4800 baud for most GPS    */
    /* --------------------------------------- */
    fd = openPort(port,B4800);
    if (fd < 0) {
        /* open failed */
        printf("openPort %d\n",fd);
        return fd;
    }
    
	/* ---------------------------------------*/
	/*STEP 2 : initialize the nmea context    */                                                
	/* ---------------------------------------*/
    status = nmeap_init(&nmea,(void *)&user_data);
    if (status != 0) {
        printf("nmeap_init %d\n",status);
        exit(1);
    }
    
	/* ---------------------------------------*/
	/*STEP 3 : add standard GPGGA parser      */                                                
	/* -------------------------------------- */
    status = nmeap_addParser(&nmea,"GPGGA",nmeap_gpgga,gpgga_callout,&gga);
    if (status != 0) {
        printf("nmeap_add %d\n",status);
        exit(1);
    }

	/* ---------------------------------------*/
	/*STEP 4 : add standard GPRMC parser      */                                                
	/* -------------------------------------- */
    status = nmeap_addParser(&nmea,"GPRMC",nmeap_gprmc,gprmc_callout,&rmc);
    if (status != 0) {
        printf("nmeap_add %d\n",status);
        exit(1);
    }
    
	/* ---------------------------------------*/
	/*STEP 5 : process input until done       */                                                
	/* -------------------------------------- */
    for(;;) {
		/* ---------------------------------------*/
		/*STEP 6 : get a buffer of input          */                                                
		/* -------------------------------------- */
        len = rem = read(fd,buffer,sizeof(buffer));
        if (len <= 0) {
            perror("read");
            break;
        }
        
        
		/* ----------------------------------------------*/
		/*STEP 7 : process input until buffer is used up */                                                
		/* --------------------------------------------- */
		offset = 0;
        while(rem > 0) {
			/* --------------------------------------- */
			/*STEP 8 : pass it to the parser           */
			/* status indicates whether a complete msg */
			/* arrived for this byte                   */
			/* NOTE : in addition to the return status */
			/* the message callout will be fired when  */
			/* a complete message is processed         */
			/* --------------------------------------- */
            status = nmeap_parseBuffer(&nmea,&buffer[offset],&rem);
			offset += (len - rem); 
            
			/* ---------------------------------------*/
			/*STEP 9 : process the return code        */
            /* DON"T NEED THIS IF USING CALLOUTS      */
            /* PICK ONE OR THE OTHER                  */
			/* -------------------------------------- */
            switch(status) {
            case NMEAP_GPGGA:
                printf("-------------switch\n");
                print_gga(&gga);
                printf("-------------\n");
                break;
            case NMEAP_GPRMC:
                printf("-------------switch\n");
                print_rmc(&rmc);
                printf("-------------\n");
                break;
            default:
                break;
            }
        }
    }
    
    /* close the serial port */
    close(fd);
    
    return 0;
}
Ejemplo n.º 3
0
int main(int argc,char *argv[])
{
    int  status;
    int  rem;
	int  offset;
	int  len;
	char buffer[32];
    
	/* ---------------------------------------*/
	/*STEP 2 : initialize the nmea context    */                                                
	/* ---------------------------------------*/
    status = nmeap_init(&nmea,(void *)&user_data);
    if (status != 0) {
        printf("nmeap_init %d\n",status);
        exit(1);
    }
    
	/* ---------------------------------------*/
	/*STEP 3 : add standard GPGGA parser      */                                                
	/* -------------------------------------- */
    status = nmeap_addParser(&nmea,"GPGGA",nmeap_gpgga,gpgga_callout,&gga);
    if (status != 0) {
        printf("nmeap_add %d\n",status);
        exit(1);
    }

	/* ---------------------------------------*/
	/*STEP 4 : add standard GPRMC parser      */                                                
	/* -------------------------------------- */
    status = nmeap_addParser(&nmea,"GPRMC",nmeap_gprmc,gprmc_callout,&rmc);
    if (status != 0) {
        printf("nmeap_add %d\n",status);
        exit(1);
    }
    
	/* ---------------------------------------*/
	/*STEP 5 : process input until done       */                                                
	/* -------------------------------------- */
    for(;;) {
		/* ---------------------------------------*/
		/*STEP 6 : get a buffer of input          */                                                
		/* -------------------------------------- */
        len = rem = readbuffer(buffer,sizeof(buffer));
        if (len <= 0) {
            break;
        }
        
		/* ----------------------------------------------*/
		/*STEP 7 : process input until buffer is used up */                                                
		/* --------------------------------------------- */
		offset = 0;
        while(rem > 0) {
			/* --------------------------------------- */
			/*STEP 8 : pass it to the parser           */
			/* status indicates whether a complete msg */
			/* arrived for this byte                   */
			/* NOTE : in addition to the return status */
			/* the message callout will be fired when  */
			/* a complete message is processed         */
			/* --------------------------------------- */
            status = nmeap_parseBuffer(&nmea,&buffer[offset],&rem);
			offset += (len - rem); 
            
			/* ---------------------------------------*/
			/*STEP 9 : process the return code        */                                                
			/* -------------------------------------- */
            switch(status) {
            case NMEAP_GPGGA:
                printf("-------------switch\n");
                print_gga(&gga);
                printf("-------------\n");
                break;
            case NMEAP_GPRMC:
                printf("-------------switch\n");
                print_rmc(&rmc);
                printf("-------------\n");
                break;
            default:
                break;
            }
        }
    }
    
    return 0;
}
Ejemplo n.º 4
0
int main(int argc,char *argv[])
{
    int             status;
    char            ch;
    
    /* ---------------------------------------*/
    /*STEP 5 : initialize the nmea context    */                                                
    /* ---------------------------------------*/
    status = nmeap_init(&nmea,(void *)&user_data);
    if (status != 0) {
        printf("nmeap_init %d\n",status);
        exit(1);
    }
    
    /* ---------------------------------------*/
    /*STEP 6 : add standard GPGGA parser      */
	/*         (no callout this time)         */
    /* -------------------------------------- */
    status = nmeap_addParser(&nmea,"GPGGA",nmeap_gpgga,0,&gga);
    if (status != 0) {
        printf("nmeap_add %d\n",status);
        exit(1);
    }

    /* ---------------------------------------*/
    /*STEP 7 : add standard GPRMC parser      */                                                
	/*         (no callout this time)         */
    /* -------------------------------------- */
    status = nmeap_addParser(&nmea,"GPRMC",nmeap_gprmc,0,&rmc);
    if (status != 0) {
        printf("nmeap_add %d\n",status);
        exit(1);
    }
    
    /* ---------------------------------------*/
    /*STEP 8 : ADD THE CUSTOM PARSER          */                                                
	/*         with callout         )         */
    /* -------------------------------------- */
    status = nmeap_addParser(&nmea,"PGRMF",custom_pgrmf,pgrmf_callout,&rmf);
    if (status != 0) {
        printf("nmeap_add %d\n",status);
        exit(1);
    }
    /* ---------------------------------------*/
    /*STEP 9 : process input until done       */                                                
    /* -------------------------------------- */
    for(;;) {
        /* ---------------------------------------*/
        /*STEP 10: get a byte at a time           */                                                
        /* -------------------------------------- */
        ch = readchar();
        if (ch <= 0) {
            break;
        }
        
        /* --------------------------------------- */
        /*STEP 11: pass it to the parser          */
        /* status indicates whether a complete msg */
        /* arrived for this byte                   */
        /* NOTE : in addition to the return status */
        /* the message callout will be fired when  */
        /* a complete message is processed         */
        /* --------------------------------------- */
        status = nmeap_parse(&nmea,ch);
        
        /* ---------------------------------------*/
        /*STEP 12 : process the return code       */                                                
        /* -------------------------------------- */
        switch(status) {
        case NMEAP_GPGGA:
            /* GOT A GPGGA MESSAGE */
            printf("-------------switch\n");
            printf("GPGGA\n");
            printf("-------------\n");
            break;
        case NMEAP_GPRMC:
            /* GOT A GPRMC MESSAGE */
            printf("-------------switch\n");
            printf("GPRMC\n");
            printf("-------------\n");
            break;
        case GARMIN_PGRMF:
            /* GOT A PGRMF MESSAGE */
            printf("-------------switch\n");
            print_pgrmf(&rmf);
            printf("-------------\n");
            break;
        default:
            break;
        }
    }
    
    return 0;
}
Ejemplo n.º 5
0
int main(int argc,char *argv[])
{
    int             status;
    char            ch;
	const char     *port;
	int             baud;
	HANDLE          h;

	/* require both arguments */
	if (argc != 3) {
		printf("%s <comport> <baud>\n",argv[0]);
		return 1;
	}

	/* serial port argument */
	port = argv[1];

	/* baud rate argument */
	status = sscanf(argv[2],"%d",&baud);
	if (status != 1) {
		printf("%s <comport> <baud>\n",argv[0]);
		printf("invalid <baud> : %s\n",argv[2]);
		return 1;
	}

	/** open the serial port */
	h = openPort(port,baud);
	if (h == INVALID_HANDLE_VALUE) {
		printf("can't open port : %s\n",port);
		return 1;
	}
    
	/* ---------------------------------------*/
	/*STEP 2 : initialize the nmea context    */                                                
	/* ---------------------------------------*/
    status = nmeap_init(&nmea,(void *)&user_data);
    if (status != 0) {
        printf("nmeap_init %d\n",status);
        exit(1);
    }
    
	/* ---------------------------------------*/
	/*STEP 3 : add standard GPGGA parser      */                                                
	/* -------------------------------------- */
    status = nmeap_addParser(&nmea,"GPGGA",nmeap_gpgga,0,&gga);
    if (status != 0) {
        printf("nmeap_add %d\n",status);
        exit(1);
    }

	/* ---------------------------------------*/
	/*STEP 4 : add standard GPRMC parser      */                                                
	/* -------------------------------------- */
    status = nmeap_addParser(&nmea,"GPRMC",nmeap_gprmc,0,&rmc);
    if (status != 0) {
        printf("nmeap_add %d\n",status);
        exit(1);
    }

	/* ---------------------------------------*/
	/*STEP 5 : process input until done       */                                                
	/* -------------------------------------- */
    for(;;) {
		/* ---------------------------------------*/
		/*STEP 6 : get a byte at a time           */                                                
		/* -------------------------------------- */
        ch = readPort(h);
        if (ch <= 0) {
            break;
        }
        
		/* --------------------------------------- */
		/*STEP 7 : pass it to the parser           */
		/* status indicates whether a complete msg */
		/* arrived for this byte                   */
		/* NOTE : in addition to the return status */
		/* the message callout will be fired when  */
		/* a complete message is processed         */
		/* --------------------------------------- */
        status = nmeap_parse(&nmea,ch);
        
		/* ---------------------------------------*/
		/*STEP 8 : process the return code        */                                                
		/* -------------------------------------- */
        switch(status) {
        case NMEAP_GPGGA:
			/* GOT A GPGGA MESSAGE */
            printGps(&gga,&rmc);
            break;
        case NMEAP_GPRMC:
			/* GOT A GPRMC MESSAGE */
            printGps(&gga,&rmc);
            break;
        default:
            break;
        }
    }

	/* close and quit */
	closePort(h);
    
    return 0;
}
Ejemplo n.º 6
0
int main(int argc,char *argv[])
{
    int  status;
    int  rem;
	int  offset;
	int  len;
	char buffer[32];
	char wgetbuf[1024];
    int  fd;
    const char *port = "/dev/ttyS0";
	FILE *f;
	time_t t;
    
	t=time(NULL);
    // default to ttyS0 or invoke with 'linux_nmeap <other serial device>' 
    if (argc == 2) {
        port = argv[1];
    }
    
	readconf(argc, argv);


    /* --------------------------------------- */
    /* open the serial port device             */
    /* using default 9600 baud for most GPS    */
    /* --------------------------------------- */
    fd = openPort(getparam("gps_port"), atoi(getparam("baudrate")));
    if (fd < 0) {
        /* open failed */
        printf("openPort %d\n",fd);
        return fd;
    }
    
	/* ---------------------------------------*/
	/*STEP 2 : initialize the nmea context    */                                                
	/* ---------------------------------------*/
    status = nmeap_init(&nmea,(void *)&user_data);
    if (status != 0) {
        printf("nmeap_init %d\n",status);
        exit(1);
    }
    
	/* ---------------------------------------*/
	/*STEP 3 : add standard GPGGA parser      */                                                
	/* -------------------------------------- */
    status = nmeap_addParser(&nmea,"GPGGA",nmeap_gpgga,gpgga_callout,&gga);
    if (status != 0) {
        printf("nmeap_add %d\n",status);
        exit(1);
    }

	/* ---------------------------------------*/
	/*STEP 4 : add standard GPRMC parser      */                                                
	/* -------------------------------------- */
    status = nmeap_addParser(&nmea,"GPRMC",nmeap_gprmc,gprmc_callout,&rmc);
    if (status != 0) {
        printf("nmeap_add %d\n",status);
        exit(1);
    }
    
	/* ---------------------------------------*/
	/*STEP 5 : process input until done       */                                                
	/* -------------------------------------- */
    for(;;) {
		/* ---------------------------------------*/
		/*STEP 6 : get a buffer of input          */                                                
		/* -------------------------------------- */
        len = rem = read(fd,buffer,sizeof(buffer));
        if (len <= 0) {
            perror("read");
            break;
        }
        
        
		/* ----------------------------------------------*/
		/*STEP 7 : process input until buffer is used up */                                                
		/* --------------------------------------------- */
		offset = 0;
        while(rem > 0) {
			/* --------------------------------------- */
			/*STEP 8 : pass it to the parser           */
			/* status indicates whether a complete msg */
			/* arrived for this byte                   */
			/* NOTE : in addition to the return status */
			/* the message callout will be fired when  */
			/* a complete message is processed         */
			/* --------------------------------------- */
            status = nmeap_parseBuffer(&nmea,&buffer[offset],&rem);
			offset += (len - rem); 
            
			/* ---------------------------------------*/
			/*STEP 9 : process the return code        */
            /* DON"T NEED THIS IF USING CALLOUTS      */
            /* PICK ONE OR THE OTHER                  */
			/* -------------------------------------- */
            switch(status) {
            case NMEAP_GPGGA:
                printf("-------------switch\n");
                print_gga(&gga);
                printf("-------------\n");
                break;
            case NMEAP_GPRMC:
                printf("-------------switch\n");
                print_rmc(&rmc);
                printf("-------------\n");
                break;
            default:
                break;
            }

	if (!(f=fopen(getparam("kml_file"), "w"))) {
		perror("fopen");
		exit(1);
	};
	FLOCK(f);
	fprintf(f, 
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"\
"<kml xmlns=\"http://earth.google.com/kml/2.2\">\n"\
"<Document>\n"\
"<name>location.kml</name>\n"\
"   <Style id=\"location\">\n"\
"      <IconStyle>\n"\
"         <color>%s</color>\n"\
"         <scale>%s</scale>\n"\
"         <Icon>\n"\
"            <href>%s</href>\n"\
"         </Icon>\n"\
"      </IconStyle>\n"\
"      <LabelStyle>\n"\
"         <color>%s</color>\n"\
"         <scale>%s</scale>\n"\
"      </LabelStyle>\n"\
"      <ListStyle>\n"\
"      </ListStyle>\n"\
"   </Style>\n"\
"   <Placemark>\n"\
"      <name>%s</name>\n"\
"      <LookAt>\n"\
"         <longitude>%.6f</longitude>\n"\
"         <latitude>%.6f</latitude>\n"\
"         <altitude>%.0f</altitude>\n"\
"         <range>%s</range>\n"\
"         <tilt>%s</tilt>\n"\
"         <heading>%s</heading>\n"\
"      </LookAt>\n"\
"      <styleUrl>#location</styleUrl>\n"\
"      <description>Date: %.6lu \n"\
"                   Time: %.6lu \n"\
"		    Speed: %.1f</description>\n"\
"      <Point>\n"\
"         <coordinates>%.6f,%.6f,%.0f</coordinates>\n"\
"      </Point>\n"\
"   </Placemark>\n"\
"</Document>\n"\
"</kml>\n" , getparam("icon_color"), getparam("icon_scale"), getparam("icon_normal"), getparam("label_color"), getparam("label_scale"), getparam("object_name"), mylon, mylat, myalt, getparam("look_range"), getparam("look_tilt"), getparam("look_heading"), mydat, mytim, myspd, mylon, mylat, myalt);

	if (myval && mylat != 0 && mylon != 0) {
		int interval= atoi(getparam("interval"));
		if (!interval)
			interval = 30;
		if ( t+interval < time(NULL) ) {
			snprintf(wgetbuf, sizeof(wgetbuf), "wget 'http://trackme.org.ua/gps/flygps?ver=1&id=%s&lat=%f&lng=%f&alt=%.0f&speed=%f' -q -O /dev/null && gpio set A1 0 > /dev/null ; usleep 200000 ; gpio set A1 1 > /dev/null", getparam("object_name"), mylat, mylon, myalt, myspd);
			system(wgetbuf);
			t = time(NULL);
		}
	}


	fflush(f);
	FUNLOCK(f);
	fclose(f);
		}
    }
    
    /* close the serial port */
    close(fd);
    
    return 0;
}