|
|
View previous topic :: View next topic |
Author |
Message |
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Mon Oct 20, 2008 9:54 pm |
|
|
PCM programmer wrote: | As I recall, a NMEA-0183 string can easily be 80 characters. |
I was just reading the spec for one of Garmin's receivers and they say 82 is the max chars in a single NMEA-0183 sentence.
Hope that helps.
Regards,
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
analog_world
Joined: 16 Sep 2008 Posts: 26
|
|
Posted: Mon Oct 20, 2008 10:13 pm |
|
|
Hi PCM,
I did set up my SIOW.exe and am able to use getc and putc to display the strings perfectly. I did take care of that part thanks to all your help and support yesterday. But somehow, now that I want to parse my strings..I am not able to read in one entire string using the fgets(). From what I see on the SIOW.exe screen, it gives me a 0x0D (carriage return) and new line (0x0A) before and after the strings.
Code: |
\0A$GPRTE,1,1,c,*37\0D
\0A$GPRMC,,V,,,,,,,211008,14.9,E,N*0E\0D
\0A$GPRMB,V,,,,,,,,,,,,A,N*13\0D
\0A$GPGGA,,,,,,0,00,,,M,,M,,*66\0D
\0A$GPGSA,A,1,,,,,,,,,,,,,,,*1E\0D
\0A$GPGSV,3,2,10,18,81,257,37,21,69,019,00,22,42,235,41,24,33,079,00*76\0D
\0A$GPGLL,,,,,,V,N*64\0D
\0A$GPBOD,,T,,M,,*47\0D
\0A$GPVTG,,T,,M,,N,,K*4E\0D
\0A$PGRME,,M,,M,,M*00\0D
\0A$PGRMZ,251,f*02\0D
\0A$PGRMM,WGS 84*06\0D
\0A$HCHDG,134.3,,,14.9,E*10\0D
\0A$GPRTE,1,1,c,*37\0D
|
I think I will need to set up some kind of circular buffer to read in continuously from what I read in the previous posts. But do you think the gets() and puts() function should work regardless of the buffer stuff? . Thank you for your time. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Oct 20, 2008 11:26 pm |
|
|
They are two different methods. With the gets() function, it takes
incoming characters and writes them to the specified buffer. There
are no interrupts involved.
With an #int_rda interrupt routine, characters are read inside the routine
(one per pass). You must put code inside the #int_rda routine to detect
the start of a GPS message and start loading characters into a buffer at
that point.
See my post in this thread and follow the link for some sample code.
http://www.ccsinfo.com/forum/viewtopic.php?t=34648
You must do this project. |
|
|
analog_world
Joined: 16 Sep 2008 Posts: 26
|
|
Posted: Tue Oct 21, 2008 6:58 pm |
|
|
Hi PCM,
What I finally did was to make my own buffer and use getc () in a loop to read in the characters. Then I used putc to display them again. I thought I could get around without having to use the interrupt routine. But I hit a major hurdle while trying to read in the GPS strings into my buffer and then trying to parse them before displaying on the output terminal(PC) again. Then, I tried to debug and debug!. What I did was to read in a string and display the same string twice after a delay. I see really weird stuff happening on the output screen. I get the normal string, then.. the second copy of the normal string just spits out some garbage characters. I guess it should still give me actual characters even if the PIC's receiver buffer locked up or is missing a few characters. (Basically, I think my PIC is not able to read in the GPS and parse it really fast and display it on the terminal simultaneously.)I am looking forward to your expert advice. Thank you.
here is the code:
Code: |
#include <18F4550.h>
#device adc=8
#use delay(clock=8000000)
#use rs232(stream=GPS, baud=4800,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,ERRORS)
#use rs232(stream =PC,baud=9600, xmit=PIN_B1, INVERT, DISABLE_INTS, ERRORS)
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "myflex_lcd.c"
typedef struct _GPRMC
{
char validity;
float latitude;
char latitudeDir;
float longitude;
char longitudeDir;
} GPRMC;
int hex2dec(char c);
int processGpsStr();
int parseGPRMC(char* inGpsStr, GPRMC* gprmc);
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
int main()
{
while (1)
processGpsStr();
return 0;
}
int readGpsStr(char* inGpsStr, int len)
{
int i = 0;
int j = 0;
inGpsStr[i] = fgetc(GPS);
// fputc(inGpsStr[i], PC);
// Search for beginning of line
while (inGpsStr[i] != '$')
{
inGpsStr[i] = fgetc(GPS);
// fputc(inGpsStr[i], PC);
}
// Read the rest of the line until newline is encountered.
fputc(inGpsStr[i], PC);
++i;
while (i < len)
{
inGpsStr[i] = fgetc(GPS);
fputc(inGpsStr[i], PC);
if (inGpsStr[i] == '\n' || inGpsStr[i] == '\r')
{
inGpsStr[i] = fgetc(GPS);
fputc(inGpsStr[i], PC);
inGpsStr[i] = '\0';
fputc('\r', PC);
fputc('\n', PC);
fputc('#', PC);
return 0;
}
++i;
}
return -1;
}
int hex2dec(char c)
{
if (c >= '0' && c <= '9')
return c - '0';
if (c >= 'A' && c <= 'F')
return 10 + (c - 'A');
if (c >= 'a' && c <= 'f')
return 10 + (c - 'a');
return -1;
}
int verifyChecksum(char* str)
{
int calcChecksum = 0;
int readChecksum = 0;
int i, c1, c2;
for (i = 1; str[i] != '\0'; ++i)
{
if (str[i] == '*')
break;
calcChecksum ^= str[i];
}
if (str[i+1] == '\0' || str[i+2] == '\0')
return FALSE;
c1 = hex2dec(str[i+1]);
c2 = hex2dec(str[i+2]);
if (c1 == -1 || c2 == -1)
return FALSE;
readChecksum = (c1 << 4) + c2;
if (calcChecksum != readChecksum)
{
fprintf(PC, "checksum failed for %s\n", str);
printf(lcd_putc,"checksum failed\n");
return FALSE;
}
else
{
fprintf(PC, "checksum is valid: %x\n", readChecksum);
}
return TRUE;
}
int processGpsStr()
{
char inGpsStr[100];
char tmpGpsStr[sizeof(inGpsStr)];
char* nextToken;
GPRMC gprmc;
int result;
char* delimitter = ",";
int i = 0;
if (readGpsStr(tmpGpsStr, sizeof(tmpGpsStr)) == -1)
return FALSE;
while (tmpGpsStr[i] != '\0')
{
fputc(tmpGpsStr[i], PC);
++i;
}
fputc('\r', PC);
fputc('\n', PC);
fputc('@', PC);
/*
fputc('!', PC);
// Save the read string as strtok modifies tmpGpsStr
strcpy(inGpsStr, tmpGpsStr);
// printf("Read: %s", inGpsStr);
// $GPRMC,033244.885,A,0000.016667,N,00000.016667,E,0,0,080908,0,E,A*15
nextToken = strtok(tmpGpsStr, delimitter);
if (nextToken == NULL)
{
fputc('#', PC);
return FALSE;
}
if (strcmp(nextToken, (char*)"$GPRMC") == 0)
{
if (!verifyChecksum(inGpsStr))
{
fputc('@', PC);
return FALSE;
}
result = parseGPRMC(inGpsStr, &gprmc);
if (result == FALSE)
{
fputc('!', PC);
return FALSE;
}
// printf("%c,%f,%c,%f,%c\n", gprmc.validity, gprmc.latitude,
// gprmc.latitudeDir,gprmc.longitude, gprmc.longitudeDir);
fprintf (PC, "validity is \n %c",gprmc.validity);
return TRUE;
}
*/
return FALSE;
}
int parseGPRMC(char* inGpsStr, GPRMC* gprmc)
{
/*
* $GPRMC,033244.885,A,0000.016667,N,00000.016667,E,0,0,080908,0,E,A*15
*/
char* nextToken;
// time
nextToken = strtok(NULL, (char*)",");
if (nextToken == NULL)
return FALSE;
// A
nextToken = strtok(NULL, (char*)",");
if (nextToken == NULL)
return FALSE;
if (strcmp(nextToken, (char*)"A") != 0)
return FALSE;
gprmc->validity = nextToken[0];
nextToken = strtok(NULL, (char*)",");
if (nextToken == NULL)
return FALSE;
gprmc->latitude = (float)atof(nextToken);
nextToken = strtok(NULL, (char*)",");
if (nextToken == NULL)
return FALSE;
gprmc->latitudeDir = nextToken[0];
nextToken = strtok(NULL, (char*)",");
if (nextToken == NULL)
return FALSE;
gprmc->longitude = (float)atof(nextToken);
nextToken = strtok(NULL, (char*)",");
if (nextToken == NULL)
return FALSE;
gprmc->longitudeDir = nextToken[0];
nextToken = strtok(NULL, (char*)"*");
return TRUE;
}
|
Please Note: in the above code, I commented out the parsing code with strtok for debugging. Also, do you think it has got anything to do with pointers.?? my compiler version is 4.057.
This is output on pc's terminal window.
Code: |
@$PS%‚j\0A
\0A $\0D
\0A#$PS%‚j\0D
\0A@$PGRMM,WGS 84*06\0D
\0A\0D
\0A#$PGRMM,WGS 84*06\0D
\0A@$HbbbŠ¢rÊb*©1C\0D
\0A\0D
\0A#$HbbbŠ¢rÊb*©1C\0D
\0A@$Gi±*37\0D
\0A\0D
\0A#$Gi±*37\0D
\0A@$GPRMC,,V,,,,,,,120425,14.9,E,N*04\0D
\0A\0D
\0A#$GPRMC,,V,,,,,,,120425,14.9,E,N*04\0D
\0A@$G±N*13\0D
\0A\0D
\0A#$G±N*13\0D
\0A@$G,,,,,0,00,,,M,,M,,*66\0D
\0A\0D
\0A#$G,,,,,0,00,,,M,,M,,*66\0D
@$G‰‰‰‰‰‰‰‰‰I)*5\0A
\0A $\0D
\0A#$G‰‰‰‰‰‰‰‰‰I)*5\0D
\0A@$GPGLL,,,,,,V,N*64\0D
\0A\0D
\0A#$GPGLL,,,,,,V,N*64\0D
@$G‰I‰ºj\0A
\0A $\0D
\0A#$G‰I‰ºj\0D
\0A@$PGRME,,M,,M,,M*00\0D
\0A\0D
\0A#$PGRME,,M,,M,,M*00\0D
@$P ¢j\0A
\0A $\0D
\0A#$P ¢j\0D
\0A@$HCHDG,238.9,,,14.9,E*15\0D
\0A\0D
\0A#$HCHDG,238.9,,,14.9,E*15\0D
@$Gj\0A
\0A $\0D
\0A#$Gj\0D
\0A@$GPRMB,V,,,,,,,,,,,,A,N*13\0D
\0A\0D
\0A#$GPRMB,V,,,,,,,,,,,,A,N*13\0D
\0A@$Gbbj±,M,,*66\0D
\0A\0D
\0A#$Gbbj±,M,,*66\0D
\0A@$G,,,,,,,,,,,,,,,*1E\0D
\0A\0D
\0A#$G,,,,,,,,,,,,,,,*1E\0D
@$GIŠb‚‚b‚‚‚b‚‚b’’b‚‚b‚‚‚b‚‚b’šb‚‚b‚‚‚b‚‚b’¢b‚‚b‚‚‚b‚‚Rº25\0A
\0A $\0D
\0A#$GIŠb‚‚b‚‚‚b‚‚b’’b‚‚b‚‚‚b‚‚b’šb‚‚b‚‚‚b‚‚b’¢b‚‚b‚‚‚b‚‚Rº25\0D
\0A@$GPVTG,,T,,M,,N,,K*4E\0D
\0A\0D
\0A#$GPVTG,,T,,M,,N,,K*4E\0D
@$PS%‚j\0A
\0A $\0D
\0A#$PS%‚j\0D
\0A@$PGRMM,WGS 84*06\0D
\0A\0D
\0A#$PGRMM,WGS 84*06\0D
\0A@$HbbbŠ¢rÊb*©15\0D
\0A\0D
\0A#$HbbbŠ¢rÊb*©15\0D
\0A@$Gi±*37\0D
\0A\0D
\0A#$Gi±*37\0D
\0A@$GPRMC,,V,,,,,,,120425,14.9,E,N*04\0D
\0A\0D
\0A#$GPRMC,,V,,,,,,,120425,14.9,E,N*04\0D
\0A@$G±N*13\0D
\0A\0D
\0A#$G±N*13\0D
\0A@$G,,,,,0,00,,,M,,M,,*66\0D
\0A\0D
\0A#$G,,,,,0,00,,,M,,M,,*66\0D
@$G‰‰‰‰‰‰‰‰‰I)*5\0A
\0A $\0D
\0A#$G‰‰‰‰‰‰‰‰‰I)*5\0D
\0A@$GPGLL,,,,,,V,N*64\0D
\0A\0D
\0A#$GPGLL,,,,,,V,N*64\0D
@$G‰I‰ºj\0A
\0A $\0D
\0A#$G‰I‰ºj\0D
\0A@$PGRME,,M,,M,,M*00\0D
\0A\0D
\0A#$PGRME,,M,,M,,M*00\0D
@$P ¢j\0A
\0A $\0D
\0A#$P ¢j\0D
\0A@$HCHDG,239.0,,,14.9,E*1D\0D
\0A\0D
\0A#$HCHDG,239.0,,,14.9,E*1D\0D
@$Gj\0A
\0A $\0D
\0A#$Gj\0D
\0A@$GPRMB,V,,,,,,,,,,,,A,N*13\0D
\0A\0D
\0A#$GPRMB,V,,,,,,,,,,,,A,N*13\0D
\0A@$Gbbj±,M,,*66\0D
\0A\0D
\0A#$Gbbj±,M,,*66\0D
\0A@$G,,,,,,,,,,,,,,,*1E\0D
\0A\0D
\0A#$G,,,,,,,,,,,,,,,*1E\0D
@$G)ºb‚‚b‚‚‚b‚‚bŠÂb‚‚b‚‚‚b‚‚bŠÊb‚‚b‚‚‚b‚‚b’‚b‚‚b‚‚‚b‚‚Rº"5\0A
\0A $\0D
\0A#$G)ºb‚‚b‚‚‚b‚‚bŠÂb‚‚b‚‚‚b‚‚bŠÊb‚‚b‚‚‚b‚‚b’‚b‚‚b‚‚‚b‚‚Rº"5\0D
\0A@$GPVTG,,T,,M,,N,,K*4E\0D
\0A\0D
\0A#$GPVTG,,T,,M,,N,,K*4E\0D
\0A@$PM*00\0D
\0A\0D
\0A#$PM*00\0D
\0A@$P)‚Êb2©0C\0D
\0A\0D
\0A#$P)‚Êb2©0C\0D
\0A@$PM84*06\0D
\0A\0D
\0A#$PM84*06\0D
\0A@$H39.1,,,14.9,E*1C\0D
\0A\0D
\0A#$H39.1,,,14.9,E*1C\0D
@$GIiºj\0A
|
|
|
|
analog_world
Joined: 16 Sep 2008 Posts: 26
|
|
Posted: Tue Oct 21, 2008 11:25 pm |
|
|
whew , I have tried to debug this using various techniques, but still not working. Any ideas on this. I really appreciate any help to get over this hurdle. Thank you |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Oct 22, 2008 1:35 pm |
|
|
I don't really want to look at tons of code. My advice is to make a GPS
simulator by using another PIC. Have it send just one message
every two seconds (the same message). Then study the problem. |
|
|
|
|
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
|