CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

GPS display on 16*2 lcd code
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
gamal eldeen



Joined: 29 May 2012
Posts: 29
Location: Alexandria - Egypt

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Wed Jul 25, 2012 10:15 am     Reply with quote

ckielstra wrote:

Most GPS modules work at 4800 baud but it is very well possible your device is operating at 9600 baud.

thanks ckielstra

Ben wrote:

Save the whole sentence... looking for $GPGGA on the front


After saving all NMEA sentences I don't know how to search for $GPGGA (How can I search for characters in a buffer ??? )
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed Jul 25, 2012 10:43 am     Reply with quote

Quote:

After saving all NMEA sentences I don't know how to search for $GPGGA (How can I search for characters in a buffer ??? )


The 'C' function 'strchr (s1,c)' finds c in s1 and returns &s1[i].

Mike
bkamen



Joined: 07 Jan 2004
Posts: 1619
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Jul 25, 2012 1:15 pm     Reply with quote

I use strtok();

It allows me to scan the fields using strcmp() to look at the first field and see if it matches the string I want.
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
TMLtech



Joined: 20 Jul 2011
Posts: 21
Location: Finland

View user's profile Send private message

PostPosted: Wed Jul 25, 2012 1:47 pm     Reply with quote

My Fastrax upatch-100 uses default speed is 9600 bps and i just wrote GPGGA and GPZDA routines.
bkamen



Joined: 07 Jan 2004
Posts: 1619
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Jul 25, 2012 1:58 pm     Reply with quote

TMLtech wrote:
My Fastrax upatch-100 uses default speed is 9600 bps and i just wrote GPGGA and GPZDA routines.


And that's fine too.

I just checked another one of my "needs high performance and buffering" setups and I use an ISR with a state machine that pre-filters some of my desired strings stuffing them into an array of short strings. That GPS (Garmin) tossed out strings at 9600bps.

Then the main loop just spins through the strings like a circular buffer.. but being 2 dimensional instead of 1.

Worked out nicely.
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
TMLtech



Joined: 20 Jul 2011
Posts: 21
Location: Finland

View user's profile Send private message

PostPosted: Wed Jul 25, 2012 2:37 pm     Reply with quote

I have ISR in INT_RDA2 which is recognize startmark '$' and then collect data in buffer. Then it recognize necessary messages.
I use dspic30f4013 and ccsc 4.128 compiler.
gamal eldeen



Joined: 29 May 2012
Posts: 29
Location: Alexandria - Egypt

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Wed Jul 25, 2012 10:00 pm     Reply with quote

surprise Surprised Surprised Surprised Surprised
my code is now run successfully Very Happy Very Happy Very Happy Very Happy
ohhhh... i just remove the
Code:
if (kbhit())

except the first one
thanks god ......... thanks every one
.....................................................................................
Surprised Sad Surprised
but another problem is appears:
The correct latitude is : 3008.6555
but the data appears on the lcd is : 3008.random characters
......................................................................................

This is the code:
Code:

while(1)
        {
              if (kbhit())
                {
                data = fgetc(PORT1);              // Check the string '$GPGGA,' 
 
                 if(data=='$')
                  {
                 
                    data = fgetc(PORT1);
                       if(data=='G')
                         {
                       
                           data = fgetc(PORT1);
                           if(data=='P');
                             {
                           
                              data = fgetc(PORT1);
                              if(data=='G');
                                {
                         
                                  data = fgetc(PORT1);
                                  if(data=='G')
                                    {
                                 
                                      data = fgetc(PORT1);
                                      if(data=='A')
                                        {
                                     
                                          data = fgetc(PORT1);
                                            if(data==',')
                                              {
                                              i=0;
                                              data=0;
                                              for(i=0;data!=',';i++)
                                              {
                                             
                                                data = fgetc(PORT1);
                                                       
                                              }
                                              if(data==',')
                                                {
                                                i=0;
                                                data=0;
                                                for(i=0;data!='N';i++)
                                                {
                                               
                                                  data = fgetc(PORT1);
                                                  lat[i]=data;
                                                  data =0;
                                                  lcd_gotoxy(1,1);
                                                 // printf(LCD_PUTC,"lati: %s",lat);
                                                  printf(LCD_PUTC,"lati: %c%c%c%c%c%c%c%c%c",lat[0],lat[1],lat[2],lat[3],lat[4],lat[5],lat[6],lat[7],lat[8]);
                                                }
                                            }


                                      }
                                   
                                  }
                             
                             
                         }
                         
                   
                   
                  }
       
     }
   
     }
     
     }
     }
     }


??????????????????????????????????
gamal eldeen



Joined: 29 May 2012
Posts: 29
Location: Alexandria - Egypt

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Thu Jul 26, 2012 7:38 am     Reply with quote

heeeeeeeeeeeeeeelp ?????????????????
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Jul 26, 2012 8:50 am     Reply with quote

gamal eldeen wrote:
my code is now run successfully Very Happy Very Happy Very Happy Very Happy
ohhhh... i just remove the
Code:
if (kbhit())

except the first one
thanks god ......... thanks every one
Good for you. I can't help myself, but have to remind an earlier text I posted: Cool
ckielstra wrote:
Your use of kbhit seems strange to me. For the first fgetc it makes sense because fgetc is blocking and you probably want to do other things, but for the next calls it makes no sense in your current setup because there you want fgetc to be blocking. Now you don't wait and get out of the string sequence test.


Your string determination algorithm is very simplistic, this makes it difficult to understand, hard to maintain and error prone. At least 5 smarter ways to handle the GPS stream have been mentioned...

Your error with the latitude value jumping around could have to do with the signal reception quality. I don't think the module has an internal antenna. Do you have an external antenna connected?
Check the 'Position fix Indicator' if there is a satellite fix before displaying the value. Also check the HDOP parameter which gives you an indication of the position accuracy.
gamal eldeen



Joined: 29 May 2012
Posts: 29
Location: Alexandria - Egypt

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Fri Jul 27, 2012 3:43 pm     Reply with quote

Sorry for lateness reply
ckielstra wrote:

Good for you. I can't help myself, but have to remind an earlier text I posted:

Thanks alot ckielstra ... forgive me Very Happy

Quote:

Your string determination algorithm is very simplistic, this makes it difficult to understand, hard to maintain and error prone. At least 5 smarter ways to handle the GPS stream have been mentioned...

Surprised This is my first program... do you have anything to help me ?.....again Smile

Quote:

Do you have an external antenna connected?

no

Quote:

Check the 'Position fix Indicator' if there is a satellite fix before displaying the value. Also check the HDOP parameter which gives you an indication of the position accuracy.

again you are right:

-Position fix Indicator=0 not 1,2 or 3
......which means Fix not available or invalid

HDOP = no thing
gamal eldeen



Joined: 29 May 2012
Posts: 29
Location: Alexandria - Egypt

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Sat Jul 28, 2012 6:56 am     Reply with quote

ohhhhhhhhhh Very Happy
Now ... i'm finished ...its working now
..
the change : rieciving all string after parsing the $GPGGA NMEA message and then display what i want ( latitude and longitude ) Surprised Very Happy Very Happy Very Happy Very Happy
thanks ( ckielstra , Ben , ckielstra , bkamen , Mike , TMLtech , temtronic , mikey , John )

Thaaaaaaaaaaaaaaaaaaaaaanks all
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Jul 28, 2012 7:21 am     Reply with quote

gamal eldeen wrote:
Surprised This is my first program... do you have anything to help me ?.....again Smile
The program you will have to write is not easy, not something I would recommend for a 'first program'. It can be done, but it will give you some headaches.

I'm not going to do the project for you and am going on holiday, so here are some tips to get you started but then I'm off.

1) Data reception.
Write an interrupt driven routine to receive the data from the GPRS unit. This way the data reception can go on in the background while your main routine continues to do other stuff like button handling and data output to the LCD.
CCS supplies an example program ex_sisr.c, a great example of a circular buffer but not the best fit for your project. Circular buffers are great for handling a continuous stream of data. You are receiving well defined lines of data.
Follow the approach as indicated by TMLtech. In the interrupt handler wait for a '$' character to appear. From then save each received character in a linear character array until a newline character is received (end of the message).

2) Interrupt speed
You can't do too many data processing in the interrupt handler because every 0.1ms a new character will be arriving. Common practice is then to get out of the Interrupt Service Routine (ISR) as quickly as possible and have the main routine do all the heavy stuff.

3) Data buffering
Once a whole 'sentence' from the GPS device has been received you set a flag in the ISR so the main routine can check this and start processing of the data.
While the main is busy processing data, new data will be coming in. Hence the ISR will need at least two linear data buffers and you will have to switch between them. One buffer being used by the ISR for new data coming in and the other buffer used by main for processing.

4) Parsing the data
Processing the received data is also called 'parsing'. Search the internet for this term and you will find many techniques.
One of the easier methods is to compare the receive buffer against a known string using the strcmp() function. problem though is that that function expects both strings to be zero terminated, which your received array buffer isn't. One option is to replace all ',' characters in the received array by a null character. Or use the strncmp() function which will stop the comparison after a specified number of characters.
Code:
#DEVICE PASS_STRINGS=IN_RAM

char ReceiveBuf[50];

if (strncmp(ReceiveBuf, "GPGGA", 5) == 0)
{
   // Do your stuff
}
Note the use of PASS_STRINGS=IN_RAM. This is required because of the PIC processor architecture where constant strings are stored in ROM, but the C string handling functions only work with RAM memory. Without this directive you have to add extra code to copy strings from ROM to RAM.

Perhaps a better option for parsing the string is to use the strtok() function. This one is more difficult to understand but was specifically designed for command line parsing. It will break the received line up into 'tokens' with your specified ',' character as a separator. Look up the internet for more info and examples on this useful function.

I'd recommend to break down your project into smaller pieces that you can develop and test separately.
For example it is much easier to have a dummy program with a hard coded GPS buffer. Then write your string parsing routines against this 'known' input. Much easier to test then when you receive random data.
gamal eldeen



Joined: 29 May 2012
Posts: 29
Location: Alexandria - Egypt

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Sat Jul 28, 2012 7:39 am     Reply with quote

ckielstra wrote:

I'm not going to do the project for you and am going on holiday.

i'm not ask to do the project for me ... am write this code just for practice ... am ask for help Smile


thank you for this tips ... it's very useful Smile
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Sat Jul 28, 2012 9:34 am     Reply with quote

Hi,

I'd just like to add a slight modification to the excellent advise given by ckielstra. You apparently only care about the 'GPGGA' NMEA sentence, so why not just exclude everything but that sentence in your serial ISR? This will simplify your project immensely, and eliminate the need to use string functions to see if you have the 'correct' NMEA sentence. Use a simple 'State Machine' in your ISR to do this.

Once you've got the entire 'GPGGA' sentence, keep in mind that the Long, and Lat will always occur in the same position within the sentence. I wrote a simple NMEA parsing routine to return all the data between two predefined "delimiter" characters, such as the comma. This routine allows me to select which data field in the entire NMEA sentence I want to extract. Be sure to test the 'Valid' flag before attempting to extract your data.

John
gamal eldeen



Joined: 29 May 2012
Posts: 29
Location: Alexandria - Egypt

View user's profile Send private message Send e-mail Yahoo Messenger

PostPosted: Fri Aug 03, 2012 3:37 am     Reply with quote

Very Happy thanks John ... but i have a question
according to your comment:
ezflyr wrote:

Once you've got the entire 'GPGGA' sentence, keep in mind that the Long, and Lat will always occur in the same position within the sentence.


why the need of the
Quote:
predefined "delimiter" characters


as with the code i wrote ... i can select the data what i want
...................................................................................................

another question:
why my loop didn't work ... am must press the reset button to refresh it ?????
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group