Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] SIM908 GPS: how to extract the Longitude,Latitude

Status
Not open for further replies.

embRTS

Full Member level 4
Full Member level 4
Joined
Sep 8, 2013
Messages
201
Helped
36
Reputation
72
Reaction score
33
Trophy points
28
Location
Bangalore
Visit site
Activity points
1,191
Hi guys I am using AVR mcu(atmega32u4) and interfacing it with sim908


I am getting a string which i am storing it in a buffer
like after an AT Command

AT+CGPSINF=32
after This SIM908 GPS will give response

&
the format of the string is as follows:-
<mode>,<longitude>,<latitude>,<altitude>,<UTC>,<ti me>,<num>,<speed>,<course>.

like for example,I will show the format in Numeric which i am getting from an array "buffer[64]" is shown below:-
"32,000000.000,V,0.000000,N,0.000000,E,0.00,0.00,0 00000,,"

where,32=mode,longitude=000000.000

I want to extract the longitude value , Latitude Value , Speed and Time

Please help me out

Thanks in Advance
 

unsigned char get_str_by_start_length(unsigned char * get_to,unsigned char start,length,wait_time)
{
uchar count,cpy_count;
count=0;cpy_count=0;
ten_ms_count=0;
length=start+length;

do
{
RI=0;
while(RI==0 && ten_ms_count<wait_time);
if(count>=start)
{
get_to[cpy_count]=SBUF;
cpy_count++;
}
count++;
}while(count<length && ten_ms_count<wait_time);
get_to[cpy_count]=0;
if(count<length)
{
return(0);
}
else
{
return(1);
}
}
 

Hey that's not done i am trying it back
Code:
[CODE]
//ISR Routine

ISR(USART1_RX_vect)
{
inData[index] = UDR1; 
index++;
inData[index] = '\0';
}
///////////////////////////////// Reading Value after GPS AT Command.//////////////////
void read_String() {
	index=0;
	
	if(index < 199) // One less than the size of the array
	{
			inChar = USART_Receive(); // Read a character
			inData[index] = inChar; // Store it
			index++  ; // Increment where to write next
			inData[index] = '\0'; // Null terminate the string
	}
		
	
}
///////////////////////  Splitting into Lat & Long ///////////////////////////////
token = strtok(inData, ","); 
 
 //decode string into comma separated values
	_delay_ms(100);
	strcpy(longitude,strtok(NULL, ",")); // Gets longitude
	 token = strtok(NULL, ",");
	_delay_ms(100);
	//sendstring_softuart("LONGITUDE= ");
	 sendstring_softuart(longitude);
	 _delay_ms(200);
	strcpy(latitude,strtok(NULL, ",")); // Gets latitude
	token = strtok(NULL, ",");
	_delay_ms(100);
	// sendstring_softuart("& LATITUDE= ");
	 sendstring_softuart("\r\n");
	 sendstring_softuart(latitude);
[/CODE]
 

hello

Code:
//ISR Routine

ISR(USART1_RX_vect)
{
inData[index] = UDR1; 
index++;
inData[index] = '\0';
}
///////////////////////////////// Reading Value after GPS AT Command.//////////////////
void read_String() {
	index=0;
	
	if(index < 199) // One less than the size of the array
	{
			inChar = USART_Receive(); // Read a character
			inData[index] = inChar; // Store it
			index++  ; // Increment where to write next
			inData[index] = '\0'; // Null terminate the string
	}
		
}


You have to choose , interrupt mode or pooling mode for Uart receiving data.
You can't use booth.

Even in this 2 cases you will never receive a complete string, but only one char inside
because you put '\0' just after..

try to detect End of GPS sentence (end of each line) wich could be CR or CRLF
and get all sentence (lines ) emitted by the GPS.
Isolate the one beginning by $GPRMC
and then do reseach of "," to separate each field of data
and separate Long and lat values.
 

The At Command which i put is
AT+CGPSINF=0
and at the end if i tried to print the string which i received i can print it on the serial port
after that i also tried to use "strtok" but it's not working that's the only problem I am getting


 

@jayanth
I tried that using a separate GPS Module in that we get the string like $GPGGA or $GPRMC so in that finding the character $ is important
but here is different scenario
Once i give AT Command the result will come
there are various mode to get the string
like 0,2,4
for example AT+CGPSINF=0
then i will get
GPS data in the format which i have uploaded in my previous post
 

Do you want to extract Latitude and Longitude values from the the data you are getting in the post #7 image? If yes, then post the string of the response you are getting in a text file. I will write a code.
 

Here is a code which extracts data and prints it on UART. Do you want the data to be converted to integer from characters?


Before sending AT+CGPSINF command set a flag and check in ISR if this flag is set and if set then capture data else do nothing. After the extraction is completed clear this flag. You have to terminate the received data with a ',' (comma).

99466d1386325196-extractdata.png
 

Attachments

  • extractData.rar
    37.2 KB · Views: 167
  • extractData.png
    extractData.png
    34.2 KB · Views: 294
Last edited:

Ya actually I convert it in degree once i get the Latitude and Longitude separately and speed
interfacing with AVR
 

The switch statement is not needed. I used it while I tried using 2D array to store different data but Compiler said "NOT ENOUGH RAM", so I used 1D array to store extracted data. Here is the new code.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
unsigned char msg[] = {'0', ',', '7', '7', '3', '9', '.', '1', '4', '4', '6',
                       '6', '3', ',', '1', '2', '5', '8', '.', '0', '6', '1', 
                       '2', '4', '8', ',', '8', '2', '7', '.', '0', '6', '1', 
                       '5', '8', '4', ',', '2', '0', '1', '3', '0', '9', '1', 
                       '9', '1', '3', '3', '2', '4', '8', '.', '3', '0', '7', 
                       ',', '4', ',', '1', '1', ',', '0', '.', '0', '0', '0', 
                       '0', '0', '0', ',', '0', '.', '0', '0', '0', '0', '0', 
                       '0', ','
                      };
 
unsigned char myData[18];
 
void PORT_Init(){
 
         TRISA = 0xC1;
         PORTA = 0x00;
         TRISB = 0x00;
         PORTB = 0x00;
         TRISC = 0x80;
         PORTC = 0x00;
         TRISD = 0x00;
         PORTD = 0x00;
         TRISE = 0x00;
         PORTE = 0x00;
         ADCON1 = 0x8E;
         CMCON = 0x07;
         CVRCON = 0x00;
}
 
 
void extractData(){
       unsigned int i = 0, j = 0, gotData = 0;
       
       if(msg[0] == '0'){
            i = j = 0;
getNext:
            while(msg[i] != ',')i++;
 
            ++i;
            ++gotData;
            j = 0;
            
            while(msg[i] != ','){
                 myData[j] = msg[i];
                 ++i;
                 ++j;
            }
            
            myData[j] = '\0';
            UART1_Write_Text(myData);
            UART1_Write(13);
            UART1_Write(10);
            if(gotData < 8)goto getNext
       }
}
 
void main(){
 
        PORT_Init();
 
        UART1_Init(9600);
        Delay_ms(200);
 
        while(1){
 
              extractData();
              Delay_ms(5000);
        }
}

 

Try this code...


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
void extractData(){
 
       unsigned int i = 0, j = 0, gotData = 0;
       
       if(msg[0] == '0'){
 
            i = j = 0;
    
            do{
 
                while(msg[i] != ',')i++;
 
                ++i;
                ++gotData;
                j = 0;
            
                while(msg[i] != ','){
                    myData[j] = msg[i];
                    ++i;
                    ++j;
                }
            
                myData[j] = '\0';
            
            }while(gotData < 8);
       }
}

 
  • Like
Reactions: embRTS

    embRTS

    Points: 2
    Helpful Answer Positive Rating
I tried but not working even i had gone through strtok function but i got one time only the separation
I had gone through strtok then o found it crashes the data,
still not getting

- - - Updated - - -

Now i am thinking i have to make some thing similar to strtok function using concept of array or pointer
 


Code C - [expand]
1
volatile unsigned char inData[80]= "";



I have fixed extractdata() and ISR related code.


Mention the AVR you are using and also Fosc and baudrate. I will write a code for you. .hex file attached.

99747d1386854440-gpsdata.png
 

Attachments

  • 908 (1).txt
    2.7 KB · Views: 108
  • gpsData.png
    gpsData.png
    60.4 KB · Views: 280
  • nmea atmega32 8mhz.rar
    1.1 KB · Views: 143
Last edited:

getting o/p like this
I mean i wished to separate the string
https://obrazki.elektroda.pl/8248537800_1386857502.jpg

- - - Updated - - -

<a title="Untitled.jpg" href="http://obrazki.elektroda.pl/8248537800_1386857502.jpg"><img src="http://obrazki.elektroda.pl/8248537800_1386857502_thumb.jpg" alt="Untitled.jpg" /></a>
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top