GPS parsing problem

Hi all,

Sorry for the delay in getting back to this... after studying all your input I've been trying different solutions and have come up with one that seems quite elegant at first glance... Trouble is once incorporated into my complete code it doesn't work. Everything appears fine but in the "real world" situation the variables areeither not being populated, or the results are not being printed to the serial bus. For bothe the simulator and serial monitor run I manually enter the GPS response ($GPSACP: 234423.31,2728.3913S,15302.3418E,1.00,38.81,3,0,00,0.01,0.02,180313,07) into the serial monitor input and the correctly formatted output appears on the output.

The Parsing/printing code which works both on an arduino using the serial monitor, and in the simulator is here.

#include <avr/pgmspace.h>
  #define maxLength 80                                 // Set incoming string max length

  
 
  String readString;
  String Lat;
  String Lon;
  String COG;
  String Speed;
  int ComCount = 0;
  
void setup() {
  
  Serial.begin(9600);
  delay (5000);
  Serial.println("GPS Test");
  Serial.println ("AT$GPSACP");
  delay(1000);
}

void loop()  { 

   
  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c ==':')  {
      readString="";
    }
    
    //delay(1000);
    
    if (c == ',') {
      ComCount++;

      if (ComCount == 1)  {
        readString=""; //clears variable for new input      
      }
    
    //delay(1000);
    
     

      if (ComCount == 2)  {
        Lat = readString;
        
        readString=""; //clears variable for new input 
      }
    
    //delay(1000);
    
      

      if (ComCount == 3)  {
        Lon = readString;
        
        readString=""; //clears variable for new input      
      }
    
    //delay(1000);
    
    

      if (ComCount == 4)  {
        readString=""; //clears variable for new input      
      }
    
    //delay(1000);
    
    

      if (ComCount == 5)  {
        readString=""; //clears variable for new input      
      }
    
    //delay(1000);
    
    

      if (ComCount == 6)  {
        /*if (c += '1')  {
         Fix = 0;
         }
         else Fix = 1;
         */       
        
      readString=""; //clears variable for new input
      }
    
    //delay(1000);
    
    

      if (ComCount == 7)  {
       COG = readString;
        
        readString=""; //clears variable for new input      
      }
    
    //delay(1000);
    
     

      if (ComCount == 8)  {
        readString=""; //clears variable for new input      
      }
    
    //delay(1000);
    
    

      if (ComCount == 9)  {
        Speed = readString;
        
        readString=""; //clears variable for new input      
      }
    
    //delay(1000);
    
     

      if (ComCount == 10)  {
        readString=""; //clears variable for new input
       Serial.println ("Lat " + Lat);
   Serial.println ("Lon " + Lon);
   Serial.println ("Speed " + Speed + " Knots"); 
   Serial.println ("COG " + COG); 
        ComCount = 0;     
      }
    
   
   

    
    
    }
    else {     
      readString += c; //makes the string readString
    }  
  }

}

The subroutines I'm actually calling are here... (first section calls the GPS subroutine then should print the data stored in the appropriate variables???)

if (inString.indexOf("Locate") >=0) {                        // look for a command in the string       

      inString = "";                                         // Clear the string
      GPS();

      Serial.println ("AT+CMGS=0430340511");             //Send SMS to this number
  
      showString(PSTR("Current Location, Course, & Speed\r\n"));
      Serial.println("");
      Serial.println ("Lat " + Lat);
      Serial.println ("Lon " + Lon);
      Serial.println ("COG " + COG);
      Serial.println ("Speed " + Speed + " Knots");
      Serial.println ("\x1A");                           //Delay to accomodate message send.
      delay(2000);                                       //Delay to accomodate message send.

      inString = "";                                               // Clear the string

    }

void GPS()  { 

  delay(1000);
  Serial.println ("AT$GPSACP");
  delay(2000);
  
  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer
    if (c ==':')  {
      readString="";
      ComCount = 0;
    }
    if (c == ',') {
      ComCount++;

      if (ComCount == 1)  {
        readString=""; //clears variable for new input      
      } 

      if (ComCount == 2)  {
        Lat = readString;
        readString=""; //clears variable for new input 
      }  

      if (ComCount == 3)  {
        Lon = readString;
        readString=""; //clears variable for new input      
      }

      if (ComCount == 4)  {
        readString=""; //clears variable for new input      
      }

      if (ComCount == 5)  {
        readString=""; //clears variable for new input      
      }

      if (ComCount == 6)  {      
        readString=""; //clears variable for new input
      }

      if (ComCount == 7)  {
        COG = readString;
        readString=""; //clears variable for new input      
      } 

      if (ComCount == 8)  {
        readString=""; //clears variable for new input      
      }

      if (ComCount == 9)  {
        Speed = readString;
        readString=""; //clears variable for new input      
      } 

      if (ComCount == 10)  {
        readString=""; //clears variable for new input 
        ComCount = 0;     
      }
    }
    else {     
      readString += c; //makes the string readString
      
      delay(1000);
    }  
  }
}

The delays are simply for stability. The GPS/3G module responses are fairly quick but I want reliability over absolute speed.

It seems to me that from my testing with the first block of code I've included that perhaps the issue is with the response from the GPS not actually being available on the serial bus??? Other comands that come in via text message are recognised, and in fact the entire sequence is called in this manner. I can also confirm that watching the serial data output from both the arduino and the GPS/3G module the correct calls and responses are present.

Cheers
Greg.