Exemplo n.º 1
0
// Compute the GPS location using decimal scale
extern void gps_location(loc_t *coord) {
    uint8_t status = _EMPTY;
    while(status != _COMPLETED) {
        gpgga_t gpgga;
        gprmc_t gprmc;
        char buffer[256];

        serial_readln(buffer, 256);
        switch (nmea_get_message_type(buffer)) {
            case NMEA_GPGGA:
                nmea_parse_gpgga(buffer, &gpgga);

                gps_convert_deg_to_dec(&(gpgga.latitude), gpgga.lat, &(gpgga.longitude), gpgga.lon);

                coord->latitude = gpgga.latitude;
                coord->longitude = gpgga.longitude;
                coord->altitude = gpgga.altitude;

                status |= NMEA_GPGGA;
                break;
            case NMEA_GPRMC:
                nmea_parse_gprmc(buffer, &gprmc);

                coord->speed = gprmc.speed;
                coord->course = gprmc.course;

                status |= NMEA_GPRMC;
                break;
        }
    }
}
Exemplo n.º 2
0
END_TEST

START_TEST (test_nmea_gprmc_parse)
{
    gprmc_t *loc = (gprmc_t *)malloc(sizeof(gprmc_t));
    nmea_parse_gprmc("$GPRMC,081836,A,3751.65,S,14507.36,E,000.05,360.0,130998,011.3,E*62", loc);

    char buf[48];

    snprintf(buf, sizeof(buf), "The readed latitude is: %f", loc->latitude);
    ck_assert_double_eq(3751.65, loc->latitude, buf);

    snprintf(buf, sizeof(buf), "The readed lat is: %c", loc->lat);
    ck_assert_msg(loc->lat == 'S', buf);

    snprintf(buf, sizeof(buf), "The readed longitude is: %f", loc->longitude);
    ck_assert_double_eq(14507.36, loc->longitude, buf);

    snprintf(buf, sizeof(buf), "The readed lon is: %c", loc->lon);
    ck_assert_msg(loc->lon == 'E', buf);

    snprintf(buf, sizeof(buf), "The readed speed is: %lf", loc->speed);
    ck_assert_double_eq(0.05, loc->speed, buf);

    snprintf(buf, sizeof(buf), "The readed course/angle is: %lf", loc->course);
    ck_assert_msg(loc->course == 360, buf);
}
Exemplo n.º 3
0
// Compute the GPS location using decimal scale
void gps_location(loc_t *coord, char *buffer) {

	coord->type = nmea_get_message_type(buffer);

	switch (coord->type) {
	case NMEA_GPGGA:
		nmea_parse_gpgga(buffer, coord);
		gps_convert_deg_to_dec(&(coord->latitude), coord->lat, &(coord->longitude), coord->lon);
		break;
	case NMEA_GPRMC:
		nmea_parse_gprmc(buffer, coord);
		break;
	case NMEA_UNKNOWN:
		// unknown message type
		break;
	}

}
Exemplo n.º 4
0
// Compute the GPS location using decimal scale
extern void gps_location(loc_t *coord) {
    uint8_t status = _EMPTY;
    
    while(status != _COMPLETED) {
        gpgga_t gpgga;
        gprmc_t gprmc;
        char buffer[1000];
        //mraa_uart_read(uart, buffer, 256);
         serial_readln(buffer, 256);
         
        //printf("%s\n", buffer);
        //printf("%d\n",nmea_get_message_type(buffer));
        switch (nmea_get_message_type(buffer)) {
            case NMEA_GPGGA:
                nmea_parse_gpgga(buffer, &gpgga);
                //printf("%d\n", gpgga.latitude);
                gps_convert_deg_to_dec(&(gpgga.latitude), gpgga.lat, &(gpgga.longitude), gpgga.lon);
                // printf("%d\n", gpgga.latitude);
                coord->latitude = gpgga.latitude;
                coord->longitude = gpgga.longitude;
                coord->altitude = gpgga.altitude;
                
                status |= NMEA_GPGGA;
                break;
            case NMEA_GPRMC:
                nmea_parse_gprmc(buffer, &gprmc);

                coord->speed = gprmc.speed;
                coord->course = gprmc.course;
                //printf("%dspeed\n", gprmc.speed);
                //coord->magnetic = gprmc.magnetic;
                //coord->mag = gprmc.mag;
                //printf("%d\n", gprmc.magnetic);
                status |= NMEA_GPRMC;
                break;
        }
    }
}
Exemplo n.º 5
0
int main()
{
	mraa_uart_context gps;
	load_device_tree("ADAFRUIT-UART1");
	gps = mraa_uart_init_raw("/dev/ttyO1");
    mraa_uart_set_baudrate(gps, 9600);
    char buf[1000];
    char search[7];
    gprmc_t readGPS;
   // char *p = buf;
    while(1){//gprmc_t readGPS;
             int i=0;
            mraa_uart_read(gps, search, 1);
            if(search[0] == '$'){
            	for(i=1; i<7;i++){
            		mraa_uart_read(gps, search+i, 1);	
            	}
            if(strstr(search, "$GPRMC,")){
           		for(i=0; i<100;i++){
           			mraa_uart_read(gps, buf+i, 1);
           			if(buf[i] == '\n'){
           				buf[i]='\0';
           				break;
           			}
            		
            	}
            	// printf("%s\n", buf);
            	nmea_parse_gprmc(buf, &readGPS);
            	gps_convert_deg_to_dec(&(readGPS.latitude), readGPS.lat, &(readGPS.longitude), readGPS.lon);
            	printf("%d\n", readGPS.state);
            	printf("%f\n", readGPS.latitude);
            	printf("%f\n", readGPS.longitude);
    	    	
    	    
    	    }
				
				
			
    	 //    mraa_uart_read(gps, buf+1, 1);
	    	// mraa_uart_read(gps, buf+2, 1);
	    	// mraa_uart_read(gps, buf+3, 1);
	    	// mraa_uart_read(gps, buf+4, 1);
	    	// mraa_uart_read(gps, buf+5, 1);
	    	// mraa_uart_read(gps, buf+6, 1);
	    	// mraa_uart_read(gps, buf+7, 1);
	    	// mraa_uart_read(gps, buf+8, 1);
	    	// mraa_uart_read(gps, buf+9, 1);
	    	// mraa_uart_read(gps, buf+10, 1);
	    	// mraa_uart_read(gps, buf+11, 1);
	    	// mraa_uart_read(gps, buf+12, 1);
	    	// mraa_uart_read(gps, buf+13, 1);
	    	// mraa_uart_read(gps, buf+14, 1);
	    	// mraa_uart_read(gps, buf+15, 1);
	    	// mraa_uart_read(gps, buf+16, 1);
	    // printf("%s\n",buf);	
    	 // if(buf[0]=='$')
    	  // {        
    	  //	printf("%s\n", buf);
    	       //buf = strchr(buf, ',')+1; 
    	        //printf("%s\n", buf);
    // }

    	// if (strchr(buf, '$GPRMC')!=NULL){
    	// 	//buf = strchr(buf, ',')+1; 
    	//         //printf("%s\n", buf);
    	// }
    	       //buf = strchr(buf, ',')+1; 
    	        //printf("%s\n", buf);
     
	    	   //mraa_uart_read(gps, buf, 1);
	    	// mraa_uart_read(gps, buf+1, 1);
	    	// mraa_uart_read(gps, buf+2, 1);
	    	// mraa_uart_read(gps, buf+3, 1);
	    	// mraa_uart_read(gps, buf+4, 1);
	    	// mraa_uart_read(gps, buf+5, 1);
	    	// mraa_uart_read(gps, buf+6, 1);
	    	// mraa_uart_read(gps, buf+7, 1);
	    	// mraa_uart_read(gps, buf+8, 1);
	    	// mraa_uart_read(gps, buf+9, 1);
	    	// mraa_uart_read(gps, buf+10, 1);
	    	// mraa_uart_read(gps, buf+11, 1);
	    	// mraa_uart_read(gps, buf+12, 1);
	    	// mraa_uart_read(gps, buf+13, 1);
	    	// mraa_uart_read(gps, buf+14, 1);
	    	// mraa_uart_read(gps, buf+15, 1);
	    	// mraa_uart_read(gps, buf+16, 1);
	    	// mraa_uart_read(gps, buf+17, 1);
    		//int i=0;
    		//for(i = 0; i<100)
    		// if(nmea_get_message_type(buf)==NMEA_GPRMC){
	    	// nmea_parse_gprmc(buf, &readGPS);
	    	// printf("%d\n", readGPS.speed);}
	    // }
	}
}
}
Exemplo n.º 6
0
int MtkGps::parse_nmea(const char *str) 
{
	if (!nmea_is_valid(str))
		return -1;

	int ret, nmea_type = nmea_get_type(str);

	if (nmea_type == NMEA_SEN_GGA) {
		ret = nmea_parse_gpgga(str, &gga);
		if (ret == 0) {
			fix_time = gga.time;
			fix_msec = gga.millisec;
			valid |= NMEA_SEN_GGA;
		}
		return ret;
	}

	if (nmea_type == NMEA_SEN_RMC) {
		ret = nmea_parse_gprmc(str, &rmc);
		if (ret == 0) {
			double frac;
			latitude = rmc.latitude / 100.0;
			frac = modf(latitude, &latitude);
			latitude += frac/0.6;
			if (rmc.flags & NMEA_LAT_SOUTH)
				latitude = -latitude;

			longitude = rmc.longitude / 100.0;
			frac = modf(longitude, &longitude);
			longitude += frac/0.6;
			if (rmc.flags & NMEA_LON_WEST)
				longitude = -longitude;
			fix_time = rmc.time;
			fix_msec = rmc.millisec;
			fix_date = rmc.date;
			valid |= NMEA_SEN_RMC;
		}
		return ret;
	}

	if (nmea_type == NMEA_SEN_GLL) {
		ret = nmea_parse_gpgll(str, &gll);
		if (ret == 0) {
			fix_time = gll.time;
			fix_msec = gll.millisec;
			valid |= NMEA_SEN_GLL;
		}
		return ret;
	}

	if (nmea_type == NMEA_SEN_VTG) {
		ret = nmea_parse_gpvtg(str, &vtg);
		if (ret == 0)
			valid |= NMEA_SEN_VTG;
		return ret;
	}

	if (nmea_type == NMEA_SEN_GSA) {
		ret = nmea_parse_gpgsa(str, &gsa);
		if (ret == 0)
			valid |= NMEA_SEN_GSA;
		return ret;
	}

	if (nmea_type == NMEA_SEN_ZDA) {
		ret = nmea_parse_gpzda(str, &zda);
		if (ret == 0) {
			fix_date = zda.date;
			fix_time = zda.time;
			fix_msec = zda.millisec;
			valid |= NMEA_SEN_ZDA;
		}
		return ret;
	}

	if (nmea_type == NMEA_SEN_GSV) {
		ret = nmea_parse_gpgsv(str, gsv, &ngsv, &igsv);
		if (ret == 0)
			valid |= NMEA_SEN_GSV;
		return ret;
	}

	if (nmea_type == NMEA_SEN_MCHN) {
		ret = nmea_parse_mtkchn(str, chn);
		if (ret == 0)
			valid |= NMEA_SEN_MCHN;
		return ret;
	}

	// firmware release info
	if (nmea_type == NMEA_SEN_MTK) {
		int type = getMtkPType(nmea);
		if (type == PMTK_DT_RELEASE) {
			if (release != NULL)
				free((void *)release);
			char *end = strchr(nmea, '*');
			if (end)
				*end = '\0';
			release = strdup(nmea + 9);
			return 0;
		}
	}
	return 0;
}