|
|
View previous topic :: View next topic |
Author |
Message |
utidomicro
Joined: 28 Sep 2009 Posts: 1
|
|
|
bungee-
Joined: 27 Jun 2007 Posts: 206
|
|
Posted: Mon Sep 28, 2009 11:41 am |
|
|
PIC code is where? |
|
|
Guest
|
|
Posted: Mon Sep 28, 2009 6:21 pm |
|
|
Code: | #include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include "lcdflex.c"
#include <input.c>
#include <string.h>
void main(){
char gps[70];
char lat[12];
char log[12];
int i, j;
lcd_init();
printf(lcd_putc,"\fUTI do Micro"); //Limpa Display
printf(lcd_putc,"\nTeste GPS");
while(TRUE){
gets(gps);
if(gps[1]=='G' && gps[2]=='P'&& gps[3]=='R' && gps[4]=='M' && gps[5]=='C'){
// if(!input(PIN_B1)){
printf(lcd_putc,"\fTeste OK");
printf(lcd_putc,"\nGPRMC OK ");
for(i=20;i<=30;i++){
j=i-20;
lat[j]=gps[i];
}
for(i=32;i<=44;i++){
j=i-32;
log[j]=gps[i];
}
printf(lcd_putc,"\fLat:%s",lat);
printf(lcd_putc,"\nLog:%s",log);
}
}
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Sep 28, 2009 7:21 pm |
|
|
You need to look for the '$' character to indicate the start of a message.
Then get the string. There are many threads on this in the forum
archives. Search for this:
and also for this:
Use the forum's search page:
http://www.ccsinfo.com/forum/search.php |
|
|
sjharris
Joined: 11 May 2006 Posts: 78
|
|
Posted: Tue Sep 29, 2009 6:39 am |
|
|
What does your code output?
How does your code know when it has a string to read from your serial port?
Are there any other serial messages sent from your GPS device? |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Tue Sep 29, 2009 7:05 am |
|
|
Quote: | if(gps[1]=='G' && gps[2]=='P'&& gps[3]=='R' && gps[4]=='M' && gps[5]=='C'){
// if(!input(PIN_B1)){
printf(lcd_putc,"\fTeste OK");
printf(lcd_putc,"\nGPRMC OK "); |
The GPS speaks when it wants . Often there is no possibility of flow control except for a few GPS engines. When a PIC is writing to RS232 it can't be reading except for the very limited overlap for a couple of chars in the hardware RS232 buffers. In the above code while the printf to the LCD is being done a distinct possibility of the GPS sending enough chars to overflow the 2 char receive buffer will occur. At best this code will be intermittent and unreliable. The best solution is a circular buffer fed by a INT rda service routine. Alternatively but a lesser solution is to avoid all printf and heavy processing until your sentence is fully received. Parse and printf between sentences not during sentences. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Tue Sep 29, 2009 7:46 am |
|
|
Assuming that the device is sending lines with some delay, the existing application should be able to synchronize on the GPS output with gets(). This isn't a satisfiying method in general, but should be working at leat least for a test.
The linked screenshot can't be decoded due to it's poor resolution, but you are hopefully able to see, if you receive complete message lines or if characters are missing. If the output is shown completely (I guess, it's the case) then missing accuracy is a problem of the GPS device rather than the code. |
|
|
Ttelmah Guest
|
|
Posted: Tue Sep 29, 2009 8:37 am |
|
|
Obvious comment, before anything else. Are you sure the unit is sending data at 9600bps?.
Have you tested with a simple terminal program on the PC, to verify that data is correctly received at _this_ rate?.
As 'standard', most GPS's send at 4800bps, unless specifically programmed to the 9600bps rate (and many don't support this).
Then, the _maximum_ packet length that can come from a GPS, is 83 characters (80 characters, plus the '$' header, plus the carriage return/line feed). What will happen to your code, if the string is longer than 69 characters?.
Then, you seem to assume the data will be in fixed locations in the string. This is not the case. You need to search forwards, for the third ','. Then the numbers after this, till the next ',' are the northing, and the characters from the fifth comma, to the sixth, are the easting/westing. You also need to get the character ater the fourth comma, to know if the first value is a northing, or southing, and after the sixth comma, to find if you have a easting or westing.
I repeat PCM programmers advice. Use the search engine, and search the forum for examples of parsing this data.
Best Wishes |
|
|
|
|
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
|