Ejemplo n.º 1
0
/*
Gibt die aktuelle Position als Längen- und Breitengrad, die Höhe über dem Meeresspiegel und ob eine Satellitenverbindung besteht zurück.
Parameters:
ReturnValue: gps_data.longitude;   //Längengrad
	gps_data.latitude;         //Breitengrad
    gps_data.altitude;         //Höhe über mittlerem Meeresspiegel
	gps_data.fix;              // Satellitenverbindung vorhanden
*/
struct gps_data get_position_GPS(){
 
   short data_received = 0;   
   char c;
   struct gps_data output; 
   char * nmeaSentence = NULL;
   int loop_count=0;
    #if DEBUG_GPS
   int  debug_nmea_count=0;
   #endif
   
  
/*Der Aufruf von read() muss in einer Schleife erfolgen. Durch die Festlegung der Aktualisierungsrate während der Initialisierung wird die Rate festgelegt, mit der neue Daten zur Verfügung stehen. Der Aufruf von read() muss solange wiederholt werden, bis ein vollständiger Datensatz vorgefunden wird. Es werden auch NMEA empfangen die Statusinformationen enthalten. Beispielsweise die verwendete Firmware Version. Die Variable data_received wird dann zu eins, wenn eine NMEA empfangen wurde, der eine gültige Position enthält. Ist kein fix vorhanden, kommt es zu einer Endlosschleife. Mit Loopcount wird der Vorgang abgebrochen, wenn kein fix vorhanden ist und die vorgegebene Zyklenzahl überschritten wird.*/
   while(data_received == 0 && loop_count < LCGETGPS ){ 
       loop_count++;    
       c = GPS.read();   
/* newNMEAreceived() wertet ein Flag aus, welches indiziert, ob ein neues NMEA empfangen wurde.*/     
      if (GPS.newNMEAreceived()) {
        /*lastNMEA() liefert den letzten empfangenen NMEA Satz zurück.*/
            nmeaSentence = GPS.lastNMEA();
        
         #if DEBUG_GPS
         Serial.println(nmeaSentence); Serial.print("\n");
         #endif
         /*parse() extrahiert die Informationen und macht diese im GPS Objekt verfügbar.*/
            GPS.parse(nmeaSentence);  
            /* Es muss sichergestellt werden, dass der Empfangene NMEA-Satz auch Positionsdaten
            enthält. Weiterhin muss abgefragt werden, ob die Positionsdaten gültig sind.(fix vorhanden)*/
            if(strstr(nmeaSentence,"GPGGA") != NULL && (short)GPS.fix == 1){
            data_received=1;
          }
             #if DEBUG_GPS
             debug_nmea_count++;
             #endif
     }     
     if((short)GPS.fix == 1){
          output.longitude = GPS.longitude;
          output.latitude = GPS.latitude;
          output.fix = (short)GPS.fix;
          output.altitude = GPS.altitude;
       }
      else{
             output.longitude = 0.0f;
            output.latitude = 0.0f;
             output.fix = 0;
             output.altitude = 0.0f;
       }
 }
#if DEBUG_GPS
   Serial.print("Anzahl read() : "); Serial.print(loop_count); Serial.print("\n");
   Serial.print("Anzahl empfangene NMAEA: "); Serial.print(debug_nmea_count); Serial.print("\n");
#endif
   return output;
}
Ejemplo n.º 2
0
void AssetTracker::updateGPS(){
    char c = gps.read();
      // if a sentence is received, we can check the checksum, parse it...
  if (gps.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences! 
    // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
    //Serial.println(gps.lastNMEA());   // this also sets the newNMEAreceived() flag to false
  
    if (!gps.parse(gps.lastNMEA()))   {
      // this also sets the newNMEAreceived() flag to false
      return;  // we can fail to parse a sentence in which case we should just wait for another
    }
  }
}
bool GpsSensor::GetData(float array[])
{
	// in case you are not using the interrupt above, you'll
	// need to 'hand query' the GPS, not suggested :(
	if (!usingInterrupt) {
		// read data from the GPS in the 'main loop'
		char c = GPS.read();
		// if you want to debug, this is a good time to do it!
		/*if (GPSECHO)
			if (c) Serial.print(c);*/
	}

	// if a sentence is received, we can check the checksum, parse it...
	if (GPS.newNMEAreceived()) {
		// a tricky thing here is if we print the NMEA sentence, or data
		// we end up not listening and catching other sentences! 
		// so be very wary if using OUTPUT_ALLDATA and trytng to print out data
		//Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false

		if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
			return 0;  // we can fail to parse a sentence in which case we should just wait for another
	}

  array[0] = millis();
  array[1] = GPS.fix;
  array[2] = GPS.fixquality;
  if (GPS.fix)
  {
	  array[3] = GPS.latitude;
	  array[4] = GPS.longitude;
	  array[5] = GPS.satellites;
	  array[6] = GPS.altitude;
	  array[7] = GPS.angle;
	  array[8] = GPS.speed;
  }
  else
  {
	  //if no fix, then set the values to 0
	  array[3] = 0;
	  array[4] = 0;
	  array[5] = 0;
	  array[6] = 0;
	  array[7] = 0;
	  array[8] = 0;
  }

  return 1;
}
Ejemplo n.º 4
0
Coordinate Navigation::getCurrentLocation()
{
    Coordinate coord;
    GPS.read();
    if (GPS.newNMEAreceived()) {
        if (!GPS.parse(GPS.lastNMEA()));
    }
    if (GPS.fix) {
        coord.latitude = GPS.latitudeDegrees;
        coord.longitude = GPS.longitudeDegrees;
    } else {
        coord.latitude = 0.000;
        coord.longitude = 0.000;
    }
    return coord;
}
Ejemplo n.º 5
0
void GPS_loop()                     // run over and over again
{
  if (! usingInterrupt) {
    char c = GPS.read();
    if (GPSECHO)
      if (c) Serial.print(c);
  }
  if (GPS.newNMEAreceived()) {
    if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
      return;  // we can fail to parse a sentence in which case we should just wait for another
  }
  if (timer > millis())  timer = millis();
  if (millis() - timer > 2000) { 
    timer = millis(); // reset the timer
    if (1){//(GPS.fix) {
      Serial.print("(-1,");
      Serial.print(GPS.latitudeDegrees, 5);
      Serial.print(", "); 
      Serial.print(GPS.longitudeDegrees, 5);
      Serial.println(")"); 
    }
  }
}
Ejemplo n.º 6
0
void timer_int_handler(void) {
  GPS.read();
}
Ejemplo n.º 7
0
void GpsController::process()
{
    // in case you are not using the interrupt above, you'll
    // need to 'hand query' the GPS, not suggested :(
    if (! usingInterrupt) {
        // read data from the GPS in the 'main loop'
        char c = GPS.read();
        // if you want to debug, this is a good time to do it!
        if (GPSECHO)
            if (c) Serial.print(c);
    }

    // if a sentence is received, we can check the checksum, parse it...
    if (GPS.newNMEAreceived()) {
        // a tricky thing here is if we print the NMEA sentence, or data
        // we end up not listening and catching other sentences!
        // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
        //Serial.println(GPS.lastNMEA());   // this also sets the newNMEAreceived() flag to false

        if (!GPS.parse(GPS.lastNMEA()))   // this also sets the newNMEAreceived() flag to false
            return;  // we can fail to parse a sentence in which case we should just wait for another
    }

    // if millis() or timer wraps around, we'll just reset it
    if (timer > millis())  timer = millis();

    // approximately every 2 seconds or so, print out the current stats
    if (millis() - timer > 2000) {
        timer = millis(); // reset the timer

        Serial.print("\nTime: ");
        Serial.print(GPS.hour, DEC);
        Serial.print(':');
        Serial.print(GPS.minute, DEC);
        Serial.print(':');
        Serial.print(GPS.seconds, DEC);
        Serial.print('.');
        Serial.println(GPS.milliseconds);
        Serial.print("Date: ");
        Serial.print(GPS.day, DEC);
        Serial.print('/');
        Serial.print(GPS.month, DEC);
        Serial.print("/20");
        Serial.println(GPS.year, DEC);
        Serial.print("Fix: ");
        Serial.print((int)GPS.fix);
        Serial.print(" quality: ");
        Serial.println((int)GPS.fixquality);
        if (GPS.fix) {
            Serial.print("Location: ");
            Serial.print(GPS.latitude, 4);
            Serial.print(GPS.lat);
            Serial.print(", ");
            Serial.print(GPS.longitude, 4);
            Serial.println(GPS.lon);
            Serial.print("Location (in degrees, works with Google Maps): ");
            Serial.print(GPS.latitudeDegrees, 4);
            Serial.print(", ");
            Serial.println(GPS.longitudeDegrees, 4);

            Serial.print("Speed (knots): ");
            Serial.println(GPS.speed);
            Serial.print("Angle: ");
            Serial.println(GPS.angle);
            Serial.print("Altitude: ");
            Serial.println(GPS.altitude);
            Serial.print("Satellites: ");
            Serial.println((int)GPS.satellites);
        }
    }
}