![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
filjo
Joined: 29 Apr 2008 Posts: 9
|
how manage strings? |
Posted: Wed Apr 30, 2008 4:05 pm |
|
|
Hi
I try make a program where I find one string and I need copy some parts.
for example in my program I have this:
Code: |
while(1)
{
i=0;
c=fgetc(gpsport);
if (c == 'C')
{
while(c != '\n')
{
c=fgetc(gpsport);
str[i]=c;
fputc(str[i], tlmport);
i++;
}
//function for edit string
}
}
|
if I put under "while(c!='\n')" this function "fputc(str[i],tlmport);" program work fine and write on terminal all which I need, in my case:
Quote: | ,161229.000,A,3723.2475,N,12158.3416,W,0.13,309.62,120598,,*10 |
but I need withdraw this string "3723.2475" , "N" , "12158.3416" ,"W" and "0.13" and put this in several variables, for I can edit after.
have some function for save this parts, and write this separately?
regards |
|
![](templates/subSilver/images/spacer.gif) |
KU5D
Joined: 10 Feb 2008 Posts: 46 Location: Asheville, North Carolina
|
|
Posted: Wed Apr 30, 2008 5:34 pm |
|
|
First, capture your GPS string in a buffer or array. Then, starting with the $ you can count commas and their position in the string for individual fields. In the $GPRMC string the fields are always a consistent length up to the 'E' or 'W'. After that, they can be different lengths depending on your speed and heading. To determine this, you can look for the decimal points in these fields and count the number of characters between the preceding comma and the decimal point. Keep in mind that the GPS receiver presents speed in knots, so if you're using speed in some other units such as MPH or kph you're gonna have to do the conversion. Additionally, the values in the string are decimal, but the checksum (the number after the *) is in hex.
That's the concept. My recommendation is to take that idea and try to work out the code yourself. If you require detailed assistance, ask. Once you do this for yourself, you will never forget.
I didn't really go into your code for grabbing the string...my apologies. _________________ Confidence is the feeling you have right before you fully understand the situation... |
|
![](templates/subSilver/images/spacer.gif) |
filjo
Joined: 29 Apr 2008 Posts: 9
|
|
Posted: Thu May 01, 2008 6:05 am |
|
|
Hi
how I can get from this string some parts?
Quote: | ,161229.000,A,3723.2475,N,12158.3416,W,0.13,309.62,120598,,*10 |
in this case I need put on variable for exemple "3723.2475"
what is the command for make this operation?
regards |
|
![](templates/subSilver/images/spacer.gif) |
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Thu May 01, 2008 7:00 am |
|
|
A GPS often just squarks. This means that most GPS units send a sentence when they want. They don't usually send a sentence based on a request. If the GPS squarks then you will very very likely need an isr connected to the RDA interrupt to capture the sentences. You also will need to parse the sentence and this will consume PIC cycles so it will be difficult to catch every piece of GPS data without an isr. ( interrupt service routine) and a circular buffer. To parse the sentence start with small routines that will find the next occurrence of "," or "*" in your sentence that you have stored in a PIC char array. Don't write a lot of code until you can capture the sentence form the GPS and in a loop move down from "," to "," ending at the "*". Next think about accuracy "3723.2475" is decimal ascii notation and presents problems for internal notation within the PIC since the choices are int8 int16 int32 or float . If you convert this to float there will be a notational difference which upon reconversion to decimal ascii notation will appear to be inaccurate. To avoid this consider the "3723.2475" to be composed of three numbers mins secs and decimal seconds. Write a parsing routine to extract these from "3723.2475" as int8 int8 int16 37 23 2475. If you are not willing to acquire this experience by doing it yourself then this project might not be for you. Always take small steps remember we all can eat a whale just as long as it is one bite at a time. Again isr reads one char per interrupt and places it in a circular buffer. Main routine reads circular buffer moving between "," delimiters.
Lower level routines take the between "," chunks and further parse and convert them to internal storage variables int8 int16. There is a built in function atoi or knowing ascii notation for number "0" is 48 decimal you can do it yourself Ex. the number "61" is ('6'-48)*10+'1'-48=61 decimal |
|
![](templates/subSilver/images/spacer.gif) |
filjo
Joined: 29 Apr 2008 Posts: 9
|
|
Posted: Fri May 02, 2008 1:42 pm |
|
|
sorry but this not working
this is my code:
Quote: | #include "main.h"
#include "string.h"
#build(reset=0x200)
#build(interrupt=0x208)
#org 0x0000,0x01ff
void bootloader() {
#asm
nop
#endasm
} // Reserve space for the bootloader
void main()
{
int k, i;
char c, str[];
//char str;
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
while(1)
{
/* c=fgetc(gpsport); //escrever directo o que esta a ler do GPS
fputc(c,tlmport);*/
i=0;
c=fgetc(gpsport);
if (c=='C')
{
while(c!='\n')
{
c=fgetc(gpsport);
str[i]=c;
fputc(str[i], tlmport);
i++;
}
}
}
} |
and result is:
Quote: | ,19639.00,A,4031.2749,N,00825.6726,W,0.46,107.05,020508,,*1D
|
if I call str[i] outside "while()" I see that the array is empty :S
what you suggest for store string on array and after I can split it?
regards |
|
![](templates/subSilver/images/spacer.gif) |
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Sat May 03, 2008 8:27 am |
|
|
You will need to understand the components of the project you are attempting. You are using RS232 and probably the hardware USART. First get a simple program that can receive a sentence into a circular buffer using the hardware USART and an interrupt service routine. This will very very very very likely be needed. The reason is that you have an additional component which is to parse the sentence from the GPS. Since RS232 is asynchronous it means data will arrive at anytime and that means probably as your are parsing one sentence from the GPS chars of a new sentence are arriving and without an interrupt you will very very likely miss them. The circular buffer will allow the capture of a sentence and the time between sentences that the GPS provides is an opportunity for the parsing routine. You may choose to do it your way and just keep trying to make your code work it will be a valuable learning experience but there will be very little room for timing errors. When printing a char be aware it takes from the PIC point of view an extremely long amount of time. In fact printing a received char immediately after it is received gets close to interfering with the reception of the next char. If you will be using your code for navigation be aware of the injury you could cause to yourself or others should you not get it perfect. |
|
![](templates/subSilver/images/spacer.gif) |
filjo
Joined: 29 Apr 2008 Posts: 9
|
|
Posted: Sun May 04, 2008 4:22 pm |
|
|
Hi
Douglas Kennedy, thanks for your pm. Tomorow I check with more atention you program.
I never used interrupts and I dont understand mutch about this...
I will try go yours ideias and use interrupts.
is posssible some one show me an exemple of a lite program where I read from rs232 port one think used interrupts?
regards |
|
![](templates/subSilver/images/spacer.gif) |
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Sun May 04, 2008 4:26 pm |
|
|
Hi
sorry I repeat this post but I know how removed my nick "filjo" when I register I don't see error my nick if "filjoa" and not "filjo", after that I will post all time with nick filjoa, thanks for comprehension.
###############################################
Hi
Douglas Kennedy, thanks for your pm. Tomorrow I check with more attention you program.
I never used interrupts and I don't understand much about this...
I will try go your ideas and use interrupts.
is possible some one show me an example of a lite program where I read from rs232 port one think used interrupts?
regards |
|
![](templates/subSilver/images/spacer.gif) |
filjoa
Joined: 04 May 2008 Posts: 260
|
|
Posted: Tue May 06, 2008 7:26 am |
|
|
HI Douglas Kennedy
you send me the example program but on I2C.. you think which is better used I2C than RS232 communication? |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|