Pages: 1 2 3 [4]   Go Down
Author Topic: GPS parsing problem  (Read 3662 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 615
Posts: 49388
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There certainly seem to be more opportunities to send data to the PC. For instance, what is in readString when Tag_Count changes? What is in readString when ComCount changes? How come one name has an underscore and the other does not?

Is the value in c after the space after the colon after the CMT actually a 34?
Logged

Brisbane Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've included output showing what's in readString pre and post comCount 1 and 2, as well as Tag_Count 1 and 2.  As for whether the character is actually a 34, it is recognised by the Tag_Count routine so I imagine it must be...  1 with underscore, one without... That's just me adding newfunctions one at a time as the project develops... Could it make a differefnce to how the code executes???

Serial output with print lines added.

GPS data input gives:-


Code:
preCC1  013919.000
postCC1  013919.000
preCC2
preCC1 2728.3129S
preCC2 2728.3129S
Lat 2728.3129S

Text message data input gives:-

Code:
preTC1 
postTC1 
preTC2
preTC1 "+61417456789
preTC2 "+61417456789
Phone "+61417456789

Suggestions???

Cheers
Greg.

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 615
Posts: 49388
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Serial output with print lines added
Code with print lines added?
Logged

Brisbane Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if (GPS_Check == 20000) {
    showString(PSTR("AT$GPSACP\r\n"));
    GPS_Check = 0;

  }
  if (Serial.available())  {
    char c = Serial.read();  //gets one byte from serial buffer


    if (readString.indexOf("GPSACP:")>=0)  {
      readString="";
      ComCount = 0;
    }

    if (readString.indexOf("+CMT:")>=0)  {
      readString="";
      Tag_Count = 0;
    }
   
    if (c == '"') {
      Tag_Count++;
Serial.println("preTC1 "+readString);
      if (Tag_Count == 1)  {
Serial.println("postTC1 "+readString);
        readString=""; //clears variable for new input     
      }     
Serial.println("preTC2 "+readString);       
      if (Tag_Count == 2)  {
        Phone = readString;
Serial.println("Phone "+Phone);
        readString=""; //clears variable for new input
       
      }
    }
      if (c == ',') {
        ComCount++;
Serial.println("preCC1 "+readString);
        if (ComCount == 1)  {
Serial.println("postCC1 "+readString);
          readString=""; //clears variable for new input     
        }     
Serial.println("preCC2 "+readString);
        if (ComCount == 2)  {
          Lat = readString;
Serial.println("Lat "+Lat);
          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)  {
          if (readString == "1")  {
            Fix = 0;
          }
          else Fix = 1;


          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 = -3;

        }
      }
   
     

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 615
Posts: 49388
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think that if you put each { on a new line, and use Tools + Auto Format, the cause of your problem will become obvious.

Specifically, think about what happens when c is ". Plenty of diddling with readString, but c is appended to readString anyway. Oops.
Logged

Brisbane Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Paul,

I appreciate your efforts...  You are obviously seeing something that I'm not (not surprising 'coz I'm still trying to get my head around a new programming language and it's intricacies)...  I am trying to understand why the " is appended to readString, yet the , is not. Is the problem specifically related to the fact that the " character performs a certain function in C? (The language, not the char label I'm using)...  If so, is there a way around that or do I need to just accept it and work out how to remove the " from readString before storing it as Phone?

Cheers
Greg.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 615
Posts: 49388
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, there is no special significance to the " character. The issue is that you look at the character, and set Tag_Count to different values based on the number of times that you've seen the ". Regardless of the value in Tag_Count, you append the " to readString.

What I wanted you to look at was the if/if/else structure that should be an if/else if/else structure, to make sure that neither the " nor the , are added to readString.
Logged

Brisbane Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Paul,

Thanks again!...  I see your point and have now tattooed across my forehead "ELSE MEANS EXACTLY WHAT IT SAYS... only if it doesn't meet ANY of the listed conditions!"  Can't believe I missed that but that's what complacency does I guess...

I'm sure it won't be my last lapse of concentration.

Cheers
Greg.
Logged

Brisbane Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Gents...

I can't begin to thank you for your help!  PaulS in particular... You are "Da Man"!!!  I got through all the issues I had except for a weird issue with the device crashing at random. I immediately assumed I was running low / out of RAM but disproved that theory with some debugging code and MemoryFree (available RAM never dropped below 1K and just to be sure I ran the sketch on a Mega 2560 with 4 times the RAM of the NANO)...

Next I started doubting my code but the results were too random for that to make sense...

Finally, I decided to do some homework on memory fragmentation...  Guess what... My "String Heavy" application was creating MANY short , empty strings amongst the actual required long strings each of which chewed up 16 Bytes of heap space!... Yep... big problem!

In my search for a solution I came across a post pointing to a previous solution from 1 Paul (last name beginning with "S") leading to a "re-hashed" (and may I say very well de-bugged) version of the WSTRING core library!... 

Implementing this version IMMEDIATELY and COMPLETELY eliminated my problem.  I literally cannot make my code crash no matter how  try! 

Paul, I'd be more than happy to buy your "Teeny boards" if you can point me to a reliable supply line here in Australia...  If this is not a possibility you have my absolute thanks and gratitude for all your work and assistance, and I think the Arduino Team really need to take a fresh look at your solution...

Cheers
Greg.
Logged

Pages: 1 2 3 [4]   Go Up
Jump to: