Esempio 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;
        }
    }
}
Esempio n. 2
0
END_TEST

START_TEST (test_invalid_nmea_gpgga_parse)
{
    gpgga_t *loc = (gpgga_t *)malloc(sizeof(gpgga_t));
    nmea_parse_gpgga("$GPGGA,080919.091,,,,,0,0,,,M,,M,,*49", loc);

    char buf[48];

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

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

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

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

    snprintf(buf, sizeof(buf), "The readed quality is: %d", loc->quality);
    ck_assert_msg(loc->quality == 0, buf);

    snprintf(buf, sizeof(buf), "The readed satellites is: %d", loc->satellites);
    ck_assert_msg(loc->satellites == 0, buf);

    snprintf(buf, sizeof(buf), "The readed altitude is: %lf", loc->altitude);
    ck_assert_double_eq(0, loc->altitude, buf);
}
Esempio n. 3
0
void nmea_parse_uart(uint8_t *data)
{
	uint8_t *c = data;

	while(1)
	{
		if (*c == '$') {
			flagRead = 1;
			wordIdx = 0;
			prevIdx = 0;
			nowIdx = 0;
		}

		if (flagRead) {
			if (*c == '\r' || *c == '\n') {
				words[wordIdx][nowIdx-prevIdx] = 0;
				wordIdx++;
				flagRead = 0;
				nmea_parse_gpgga();
				break;
			} else {
				words[wordIdx][nowIdx - prevIdx] = *c;
				if (*c == ',') {
					words[wordIdx][nowIdx - prevIdx] = 0;
					wordIdx++;
					prevIdx = nowIdx;
				}
				nowIdx++;
			}

		}
		c++; //next character in buffer
	}
}
Esempio n. 4
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;
	}

}
Esempio n. 5
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;
        }
    }
}
Esempio 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;
}