Beispiel #1
0
/**
 *  static int Gps_set(void * _self, va_list *app) -  Perform a new gps acquisition.
 * \param *_self - pointer to the device 
 * \param *app - none 
 * \return:
 	<LI><Breturn = 0:</B>when the GPS device is connected on a Grove nest DIG port, with or without a valid connection </LI> 
 	<LI><Breturn = -1:</B>when the GPS device is not connected on a Grove nest DIG port. </LI> 
 </UL>
 */
static int Gps_set(void *_self,va_list *app)
{ 
	struct Gps *self = _self;
	char gps_sentences[70];
	unsigned int timer = 65000;
	flag = 1;
	nmea_zero_INFO(&self->info);
	nmea_parser_init(&self->parser);
	UARTOn(self->uart_module);
	UARTFlush(self->uart_module);
	vTaskDelay(50);
	while((UARTBufferSize(self->uart_module)<3) && timer)
		timer--;
	if(!timer)
		return -1;		
	timer = 500;
	while((gps_sentences[0] != '$') && timer)
	{
		timer--;
		while(UARTBufferSize(self->uart_module)<1);
		UARTRead(self->uart_module,gps_sentences,1);
		if(gps_sentences[0] == '$')
		{
			while(UARTBufferSize(self->uart_module) < 5);
			UARTRead(self->uart_module,(gps_sentences+1),5); //Reads all the chars in the
			if((gps_sentences[4] == 'M'))
			{
				while(UARTBufferSize(self->uart_module) < 65);					
				UARTRead(self->uart_module,(gps_sentences+6),64); //Reads all the chars in the
				gps_sentences[70] = '\0';
				int i = 0;
				i = nmea_parse(&self->parser, gps_sentences, (int)strlen(gps_sentences), &self->info);
				if(i)
				{
					flag = 0;
					self->lat = nmea_ndeg2degree (self->info.lat);
					self->lon = -nmea_ndeg2degree (self->info.lon);
					self->year = self->info.utc.year+1900;
					self->mon = self->info.utc.mon;
					self->day = self->info.utc.day;
					self->hour = self->info.utc.hour;
					self->min = self->info.utc.min;
					self->sec = self->info.utc.sec;
					self->speed = self->info.speed;
				    break;
				}
			}	
		}
		gps_sentences[0]= 0;
	}
	nmea_parser_destroy(&self->parser);
	UARTOff(self->uart_module);
	return 0;
}
Beispiel #2
0
void Circle_PosNormalize(Circle_Struct *circle, GpsInfo *pGps)
{
	double tmp;
	tmp          = nmea_ndeg2degree(pGps->lat);
	CurPoint.lat = nmea_degree2radian(tmp);
	
	tmp          = nmea_ndeg2degree(pGps->lon);
	CurPoint.lon = nmea_degree2radian(tmp);
	
	tmp        = (double)(circle->Center.Latitude)/_MSEC2DEG_FACTOR;
	Center.lat = nmea_degree2radian(tmp);
	
	tmp = (double)(circle->Center.Longitude)/_MSEC2DEG_FACTOR;
	Center.lon = nmea_degree2radian(tmp);
}
Beispiel #3
0
int NDEG2MSEC(double input)
{
	double deg;
	int	   result;

	deg = nmea_ndeg2degree( input );
	result = (int)(deg*60*60*1000);

	return result;
}
Beispiel #4
0
void boatReal::updateBoat(nmeaINFO info)
{
    this->info=info;
    QDateTime now;
    now=now.currentDateTime();
//    QString s=now.toString("hh:mm:ss");
//    qWarning()<<s<<
//        "speed:"<<info.speed<<"cap:"<<info.direction<<"lat:"<<info.lat;
    this->fix=info.fix;
    this->sig=info.sig;
    if(info.declination!=0)
        this->declinaison=info.declination;
    else
        this->declinaison=Settings::getSetting("declinaison",0).toDouble();
    this->pdop=info.PDOP;
    if(sig<0 || sig>3)
        qWarning()<<"strange sig value:"<<sig;
    this->speed=info.speed/1.852;
    this->heading=info.direction;
    if(info.fix==1)
    {
//        qWarning()<<"bad gps signal, fix="<<info.fix<<",sig="<<info.sig;
        emit(boatUpdated(this,false,false));
        return;
    }
    this->lat=nmea_ndeg2degree(info.lat);
    this->lon=nmea_ndeg2degree(info.lon);
    this->lastUpdateTime=QDateTime().currentDateTimeUtc().toTime_t();
    if(previousLon!=lon || previousLat!=lat)
        updateBoatData();
    if(gotPosition && (previousLon!=lon || previousLat!=lat))
    {
        trace->addPoint(lat,lon);
        trace->slot_showMe();
    }
    gotPosition=true;
    previousLon=lon;
    previousLat=lat;
    this->setWP(WP,WPHd);
    emit(boatUpdated(this,false,false));
}
Beispiel #5
0
/**
 * Converts the position fields to degrees and DOP fields to meters so that
 * all fields use normal metric units.
 *
 * @param nmeaInfo
 * the nmeaINFO
 */
void nmea_INFO_unit_conversion(nmeaINFO * nmeaInfo) {
    if (!nmeaInfo) {
        return;
    }

    /* smask (already in correct format) */

    /* utc (already in correct format) */

    /* sig (already in correct format) */
    /* fix (already in correct format) */

    if (nmea_INFO_is_present(nmeaInfo->present, PDOP)) {
        nmeaInfo->PDOP = nmea_dop2meters(nmeaInfo->PDOP);
    }

    if (nmea_INFO_is_present(nmeaInfo->present, HDOP)) {
        nmeaInfo->HDOP = nmea_dop2meters(nmeaInfo->HDOP);
    }

    if (nmea_INFO_is_present(nmeaInfo->present, VDOP)) {
        nmeaInfo->VDOP = nmea_dop2meters(nmeaInfo->VDOP);
    }

    if (nmea_INFO_is_present(nmeaInfo->present, LAT)) {
        nmeaInfo->lat = nmea_ndeg2degree(nmeaInfo->lat);
    }

    if (nmea_INFO_is_present(nmeaInfo->present, LON)) {
        nmeaInfo->lon = nmea_ndeg2degree(nmeaInfo->lon);
    }

    /* elv (already in correct format) */
    /* speed (already in correct format) */
    /* track (already in correct format) */
    /* mtrack (already in correct format) */
    /* magvar (already in correct format) */

    /* satinfo (already in correct format) */
}
Beispiel #6
0
void QgsNMEAConnection::processRMCSentence( const char* data, int len )
{
  nmeaGPRMC result;
  if ( nmea_parse_GPRMC( data, len, &result ) )
  {
    double longitude = result.lon;
    if ( result.ew == 'W' )
    {
      longitude = -longitude;
    }
    double latitude = result.lat;
    if ( result.ns == 'S' )
    {
      latitude = -latitude;
    }
    mLastGPSInformation.longitude = nmea_ndeg2degree( longitude );
    mLastGPSInformation.latitude = nmea_ndeg2degree( latitude );
    mLastGPSInformation.speed = KNOTS_TO_KMH * result.speed;
    mLastGPSInformation.direction = result.direction;
    mLastGPSInformation.status = result.status;  // A,V

    //date and time
    QDate date( result.utc.year + 1900, result.utc.mon + 1, result.utc.day );
    QTime time( result.utc.hour, result.utc.min, result.utc.sec, result.utc.msec ); // added msec part
    if ( date.isValid() && time.isValid() )
    {
      mLastGPSInformation.utcDateTime.setTimeSpec( Qt::UTC );
      mLastGPSInformation.utcDateTime.setDate( date );
      mLastGPSInformation.utcDateTime.setTime( time );
      QgsDebugMsg( "utc time:" );
      QgsDebugMsg( mLastGPSInformation.utcDateTime.toString() );
      QgsDebugMsg( "local time:" );
      QgsDebugMsg( mLastGPSInformation.utcDateTime.toLocalTime().toString() );
    }
  }
}
Beispiel #7
0
void QgsNMEAConnection::processGGASentence( const char* data, int len )
{
  nmeaGPGGA result;
  if ( nmea_parse_GPGGA( data, len, &result ) )
  {
    //update mLastGPSInformation
    double longitude = result.lon;
    if ( result.ew == 'W' )
    {
      longitude = -longitude;
    }
    double latitude = result.lat;
    if ( result.ns == 'S' )
    {
      latitude = -latitude;
    }

    mLastGPSInformation.longitude = nmea_ndeg2degree( longitude );
    mLastGPSInformation.latitude = nmea_ndeg2degree( latitude );
    mLastGPSInformation.elevation = result.elv;
    mLastGPSInformation.quality = result.sig;
    mLastGPSInformation.satellitesUsed = result.satinuse;
  }
}
Beispiel #8
0
/**
 * \fn nmea_ndeg2radian
 * \brief Convert NDEG (NMEA degree) to radian
 */
double nmea_ndeg2radian(double val)
{ return nmea_degree2radian(nmea_ndeg2degree(val)); }
Beispiel #9
0
int parse_gps(char * database, int tripid) {
	int retval;

	// Open database connection
	retval = sqlite3_open(database, &handle);
	if (retval) {
		printf("GPS Parsing: Database connection failed: %d\n", retval);
		return -1;
	}
	sqlite3_exec(handle, "PRAGMA synchronous = NORMAL", 0, 0, 0);
	sqlite3_exec(handle, "PRAGMA journal_mode = MEMORY", 0, 0, 0);

	// Select data from database
	char selectquery[100];
	sprintf(selectquery,
			"SELECT Gps_ID, RawData FROM GpsData WHERE Trip_ID = %d", tripid);
	sqlite3_stmt *stmt;
	retval = sqlite3_prepare_v2(handle, selectquery, -1, &stmt, 0);
	if (retval) {
		printf("GPS Parsing: Selecting data from DB Failed: %d\n", retval);
		printf("Query: %s\n", selectquery);
		return -1;
	}

	// Initialize NMEA parser
	nmeaINFO info;
	nmeaPARSER parser;
	nmea_zero_INFO(&info);
	nmea_parser_init(&parser);

	// Begin SQL transaction
	sqlite3_exec(handle, "BEGIN TRANSACTION", 0, 0, 0);

	// Step through SELECT query
	while (1) {
		retval = sqlite3_step(stmt);

		if (retval == SQLITE_ROW) {
			// Gather row from database
			int gpsid = (int) sqlite3_column_int(stmt, 0);
			char *rawdata = (char*) sqlite3_column_text(stmt, 1);
			int len = (int) strlen(rawdata);

			// Parse NMEA data
			nmea_parse(&parser, rawdata, len, &info);

			// Convert time format to C_time
			struct tm converttime;
			converttime.tm_year = info.utc.year;
			converttime.tm_mon = info.utc.mon;
			converttime.tm_mday = info.utc.day;
			converttime.tm_hour = info.utc.hour;
			converttime.tm_min = info.utc.min;
			converttime.tm_sec = info.utc.sec;

			// Update row with NMEA data
			char query[200];
			sprintf(
					query,
					"UPDATE GpsData SET UTC = %f, Fix = %d, Latitude = %f, Longitude = %f, Speed = %f, Direction = %f, Declination = %f WHERE Gps_ID = %d", (float) mktime(&converttime), info.fix, nmea_ndeg2degree(info.lat), nmea_ndeg2degree(info.lon), info.speed, info.direction, info.declination, gpsid);
			retval = sqlite3_exec(handle, query, 0, 0, 0);
			if (retval) {
				printf("GPS Parsing: Updating data in DB Failed: %d\n", retval);
				return -1;
			}
		} else if (retval == SQLITE_DONE) {
			break;
		} else {
			printf("GPS Parsing: SQL error whilst reading rows: %d\n", retval);
			return -1;
		}
	}

	// End SQL transaction
	sqlite3_exec(handle, "END TRANSACTION", 0, 0, 0);

	// Remove unnecesary data
	char removequery[100];
	sprintf(removequery,
			"DELETE FROM GpsData WHERE RawData	NOT LIKE '$GPRMC%%'");
	retval = sqlite3_exec(handle, removequery, 0, 0, 0);
	if (retval) {
		printf("GPS Parsing: Removing data from DB Failed: %d\n", retval);
		printf("Query: %s\n", removequery);
		return -1;
	}

	// Destroy the evidence!
	nmea_parser_destroy(&parser);
	sqlite3_close(handle);
	return 0;
}
Beispiel #10
0
void NDEG2Deg(double lat, double lon, EarthPos *pout)
{
	pout->lat = nmea_ndeg2degree( lat );
	pout->lon = nmea_ndeg2degree( lon );
}
Beispiel #11
0
        // Calculate the new position based on the bearing and distance
        nmea_move_horz(&startPos, &endPos, line.bearing(), line.distance() / 1000.0);

        // Update the info struct
        nmea_pos2info(&endPos, &m_info);

        total_distance += line.distance();
    }


    qDebug() << "Distance Traveled: " << total_distance;

    m_lines.clear();

    double lat = nmea_ndeg2degree(m_info.lat);
    double lon = nmea_ndeg2degree(m_info.lon);

    if (lat < 0.0) {
        lat = -lat;
        ui->northSouthComboBox->setCurrentIndex(1);
    } else {
        ui->northSouthComboBox->setCurrentIndex(0);
    }

    if (lon < 0.0) {
        lon = -lon;
        ui->eastWestComboBox->setCurrentIndex(1);
    } else {
        ui->eastWestComboBox->setCurrentIndex(0);
    }