Mock LocationProvider - Structure/Explanation (NMEA, $GPRMC)

Tutorials that use the MapActivity. Many using GPS functionality.

Mock LocationProvider - Structure/Explanation (NMEA, $GPRMC)

Postby plusminus » Sun Nov 25, 2007 9:27 pm

Mock LocationProvider - Structure/Explanation (NMEA, $GPRMC)


What is this: This tutorial shows how Mock LocationProviders are structured, so that you will be able to set up your own.

What you will learn: How a Mock LocationProvider (NMEA,$GPRMC) is built up.

:?: Problems/Questions: post right below...

Difficulty: 2 of 5 :)

Description:
:idea: Basically a mock (~= fake) location provider is simply a textfile with a list of (gps-)locations within.

Each Mock LocationProvider to be created needs its own directory in the following path on the emulator:
/data/misc/location/<provider_name>.


When an LocationProvider is requested its directory is searched for the following files (in order):
  1. class
  2. kml
  3. nmea <--- This is explained here
  4. track

1.
If you pull the file ("/data/app/misc/location/gps/nmea")(which is a such a mock location provider, as no gps-device can be attached) via Eclipse' DDMS-View from the emulator to your pc , you see the following:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. $GPRMC,.......
  2. $GPRMC,003347.000,A,3725.3433,N,12205.7920,W,0.08,149.46,061007,,,D*70
  3. $GPRMC,003348.000,A,3725.3433,N,12205.7921,W,0.05,142.51,061007,,,D*7E
  4. $GPRMC,003349.000,A,3725.3432,N,12205.7921,W,0.08,159.56,061007,,,D*7E
  5. $GPRMC,003350.000,A,3725.3432,N,12205.7921,W,0.06,151.59,061007,,,D*7F
  6. $GPRMC,003351.000,A,3725.3432,N,12205.7921,W,0.20,120.57,061007,,,D*72
  7. $GPRMC,.......
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


If you then lookup that "$GPRMC"-String on Google you will see, that it is a part of the NMEA-Protocol (who could expect that :roll:):
$GPRMC - Recommended Minimum Specific GPS/TRANSIT Data


So '$GPRMC' indicates a simple/minimalistic "partition" of the NMEA-Protocol.

:arrow: So as the most gps-devices emit those GPRMC-'setences' (one line is one sentence) Android simply parses them line by line.

:arrow: Fine, but what the heck do all those numbers/characters mean :? :
:idea: If you really want to create you own Mock LocationProvider, take a look here for extensive explanation. :idea:

* RMC
RMC = Recommended Minimum Specific GPS/TRANSIT Data

$GPRMC,hhmmss.ss,A,llll.ll,a,yyyyy.yy,a,x.x,x.x,ddmmyy,x.x,a*hh

1 = UTC(universal time, coordinated) of position fix
2 = Data status (A=good, V=navigation receiver warning)
3 = Current Latitude
4 = North/South in Latitude Hemisphere
5 = Current Longitude
6 = East/West in Longitude Hemisphere
7 = Speed over ground in knots
8 = (Direction of travel N:0°, E:90°, S:180°, W:270°)
9 = UT DateStamp
10 = Magnetic variation degrees (Easterly var. subtracts from true course)
11 = East/West
12 = Checksum


So lets parse one 'sentence' by hand to understand this:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. $GPRMC,003347.000,A,3725.3433,N,12205.7920,W,0.08,149.46,061007,,,D*70
  2.  
  3. Parts:
  4. 1:   003347.000  -->   0:33 am 47 seconds 0 milliseconds (UTC(universal time, coordinated) of position fix)
  5. 2:   A           -->   Status is ok   (Data status (A=good, V=navigation receiver warning))
  6. 3:   3725.3433         (North/South in Latitude Hemisphere)
  7. 4:   N           -->   North   (North/South)
  8. 5:   12205.7920        (Current Longitude)
  9. 6:   W           -->   West   (East/West in Longitude Hemisphere)
  10. 7:   0.08        -->   0.08 knots/second (Direction: North/West)   (Speed over ground in knots)
  11. 8:   149.46      -->   sth. like SouthEast (Direction of travel  N:0°, E:90°, S:180°, W:270°)
  12. 9:   061007      -->   6th October, 2007  (UT(universal time) DateStamp)
  13. 10:  <empty>           (Magnetic variation degrees (Easterly var. subtracts from true course))
  14. 11:  <empty>           (East/West)
  15. 12:  D*70              (Checksum)
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


So if you want to create your own Mock LocationProvider, you will need to calculate the Checksum of each 'sentence'.

Example-Implementation in JAVA :!::
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         /** Calculates the checksum for a sentence */
  2.         public static String getChecksum(String sentence) {
  3.                 // Loop through all chars to get a checksum
  4.                 char character;
  5.                 int checksum = 0;
  6.                 int length = sentence.length();
  7.                 for (int i = 0; i < length; i++) {
  8.                         character = sentence.charAt(i);
  9.                         switch (character) {
  10.                                 case '$':
  11.                                         // Ignore the dollar sign
  12.                                         break;
  13.                                 case '*':
  14.                                         // Stop processing before the asterisk
  15.                                         break;
  16.                                 default:
  17.                                         // Is this the first value for the checksum?
  18.                                         if (checksum == 0) {
  19.                                                 // Yes. Set the checksum to the value
  20.                                                 checksum = (byte) character;
  21.                                         } else {
  22.                                                 // No. XOR the checksum with this character's value
  23.                                                 checksum = checksum ^ ((byte) character);
  24.                                         }
  25.                         }
  26.                 }
  27.                 // Return the checksum formatted as a two-character hexadecimal
  28.                 return Integer.toHexString(checksum);
  29.         }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4

Example-Implementation in VB.NET :!::
Syntax: [ Download ] [ Hide ]
Using vbnet Syntax Highlighting
  1.   ' Calculates the checksum for a sentence
  2.   Public Function GetChecksum(ByVal sentence As String) As String
  3.     ' Loop through all chars to get a checksum
  4.     Dim Character As Char
  5.     Dim Checksum As Integer
  6.     For Each Character In sentence
  7.       Select Case Character
  8.         Case "$"c
  9.           ' Ignore the dollar sign
  10.         Case "*"c
  11.           ' Stop processing before the asterisk
  12.           Exit For
  13.         Case Else
  14.           ' Is this the first value for the checksum?
  15.           If Checksum = 0 Then
  16.             ' Yes. Set the checksum to the value
  17.             Checksum = Convert.ToByte(Character)
  18.           Else
  19.             ' No. XOR the checksum with this character's value
  20.             Checksum = Checksum Xor Convert.ToByte(Character)
  21.           End If
  22.       End Select
  23.     Next
  24.     ' Return the checksum formatted as a two-character hexadecimal
  25.     Return Checksum.ToString("X2")
  26.   End Function
Parsed in 0.020 seconds, using GeSHi 1.0.8.4


Feel free to ask, if any question is still open :!:

Would be great if someone could generate another Mock LocationProvider, than the guy walking around in SanFranciso :wink:

Regards,
plusminus
Last edited by plusminus on Sun Dec 16, 2007 7:43 pm, edited 1 time in total.
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby lordhong » Mon Nov 26, 2007 3:38 am

very very NICE!!! definitely will study your findings!
lordhong
Developer
Developer
 
Posts: 42
Joined: Thu Nov 22, 2007 5:25 am
Location: New York

Very nice thanks!!

Postby charroch » Thu Dec 06, 2007 3:28 pm

I remember doing similar GPS programming back in uni with telnet connected to a radio receiving GPS data from a meteo balloon... A the good all days. Thanks for this and the site as well.
charroch
Freshman
Freshman
 
Posts: 7
Joined: Thu Dec 06, 2007 1:08 pm

Thank you! great stuff!

Postby stephenelf » Fri Dec 14, 2007 2:58 am

Thank you for this great tutorial.
I ported the sample code to java:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         /** Calculates the checksum for a sentence */
  2.         public static String getChecksum(String sentence) {
  3.                 // Loop through all chars to get a checksum
  4.                 char character;
  5.                 int checksum = 0;
  6.                 int length = sentence.length();
  7.                 for (int i = 0; i < length; i++) {
  8.                         character = sentence.charAt(i);
  9.                         switch (character) {
  10.                                 case '$':
  11.                                         // Ignore the dollar sign
  12.                                         break;
  13.                                 case '*':
  14.                                         // Stop processing before the asterisk
  15.                                         break;
  16.                                 default:
  17.                                         // Is this the first value for the checksum?
  18.                                         if (checksum == 0) {
  19.                                                 // Yes. Set the checksum to the value
  20.                                                 checksum = (byte) character;
  21.                                         } else {
  22.                                                 // No. XOR the checksum with this character's value
  23.                                                 checksum = checksum ^ ((byte) character);
  24.                                         }
  25.                         }
  26.                 }
  27.                 // Return the checksum formatted as a two-character hexadecimal
  28.                 return Integer.toHexString(checksum);
  29.         }
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


and I also have a new nmea file that I pushed to Android and works! The location is set to Valencia, Spain, with this string:
Code: Select all
$GPRMC,003347.000,A,3928.2130,N,0022.2143,W,0.08,0,061007,,,D*68


I upload the nmea file if someone wants to try it. I had to reboot the emulator a couple of times before getting to work.

Esteban
stephenelf
Freshman
Freshman
 
Posts: 3
Joined: Wed Dec 12, 2007 4:20 am
Location: Valencia,Spain

Postby plusminus » Fri Dec 14, 2007 1:14 pm

Hello stephenelf,

I would really like to see your Valencia Mock-Provider :) San Francisco is so a lot farer away from Germany ^^
Is it just one line :?:

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

missing nmea file

Postby stephenelf » Sat Dec 15, 2007 3:21 am

hi


sorry, but I thought that the file was attached, but the txt file extension was not allowed

Spain is a litle more closer to Germany :D

Esteban
Attachments
nmea.rar
nmea file for valencia
(147 Bytes) Downloaded 1032 times
stephenelf
Freshman
Freshman
 
Posts: 3
Joined: Wed Dec 12, 2007 4:20 am
Location: Valencia,Spain

Top

Postby amiuhle » Mon Dec 24, 2007 6:02 pm

I think the easiest way would be to create a kml-File with Google Earth.

As stated in code.google.com/android/toolbox/apis/lbs.html this file is just parsed for <coordinates>-Tags.

Such a <coordinates>-Tag is created if you paint a Path in Google Earth and export it as .kml.
If you need timing, you can use the track-File, which takes lines of the format
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <time> <longitude> <latitude> <altitude>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4

"The times should start with 0, and are interpreted relative to the time when the file was parsed."
amiuhle
Freshman
Freshman
 
Posts: 2
Joined: Mon Dec 24, 2007 5:15 pm
Location: Germany

Postby Printisor » Thu Jan 17, 2008 10:56 pm

Hello,

I am trying to find out how to generate the values from the nmea file but with no success. I only have (my) coordinates (-80.09280800000001,26.35630700000001,0) from a generated kml file, and I don't know how to translate them into the values needed in the nmea file. Any help with this is appreciated. Also, I noticed that in the ../location/gps/ folder, there is a location file also. So my second question, when displaying a map with the initial location, is this location taken from the location file or is it the first record from the nmea file (sorry if I cross posted)?

Thank you,
Mihai
Printisor
Freshman
Freshman
 
Posts: 2
Joined: Thu Jan 17, 2008 10:10 pm

Postby amiuhle » Fri Jan 18, 2008 9:38 am

Printisor wrote:I am trying to find out how to generate the values from the nmea file but with no success. I only have (my) coordinates (-80.09280800000001,26.35630700000001,0) from a generated kml file, and I don't know how to translate them into the values needed in the nmea file. Any help with this is appreciated.


Why don't you just use this kml File? That's the easiest way to do this, especially if you don't need multiple locations. Read my last Post just above yours, I think it says everything you need to know. You can probably simply import the kml file you etracted the coordinates from into the designated folder on the emulator.
amiuhle
Freshman
Freshman
 
Posts: 2
Joined: Mon Dec 24, 2007 5:15 pm
Location: Germany

Postby plusminus » Fri Jan 18, 2008 10:06 am

Hey guys,

you could use the awesome :src: TrackBuilder for mock location providers.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Printisor » Fri Jan 18, 2008 7:52 pm

amiuhle wrote:
Printisor wrote:I am trying to find out how to generate the values from the nmea file but with no success. I only have (my) coordinates (-80.09280800000001,26.35630700000001,0) from a generated kml file, and I don't know how to translate them into the values needed in the nmea file. Any help with this is appreciated.


Why don't you just use this kml File? That's the easiest way to do this, especially if you don't need multiple locations. Read my last Post just above yours, I think it says everything you need to know. You can probably simply import the kml file you etracted the coordinates from into the designated folder on the emulator.

Of course I tried this first, but for example the FriendFinder application just showed me an empty map. The idea to use a kml file came from your post. Once I removed the kml file, it showed me San Francisco.

Hey guys,

you could use the awesome Source TrackBuilder for mock location providers.

Regards,
plusminus

I will try this and see how it works.

Thank you both for your replies,
Mihai
Printisor
Freshman
Freshman
 
Posts: 2
Joined: Thu Jan 17, 2008 10:10 pm

Postby bavarol » Sat Feb 23, 2008 8:07 pm

Printisor wrote:Hello,

I am trying to find out how to generate the values from the nmea file but with no success. I only have (my) coordinates (-80.09280800000001,26.35630700000001,0) from a generated kml file, and I don't know how to translate them into the values needed in the nmea file. Any help with this is appreciated. Also, I noticed that in the ../location/gps/ folder, there is a location file also. So my second question, when displaying a map with the initial location, is this location taken from the location file or is it the first record from the nmea file (sorry if I cross posted)?

Thank you,
Mihai

Hi, If you like NMEA format, there are several apps to get a gps signal, also, a route defined in NMEA/KML.

Only an advice, you should define at least 500/700 points to generate a normal-good route but that's no Problem,
I posted it 3 days ago
generate_your_gps_signal_easy-t998.html

You can define the points as .gpx without bothering description
http://www.gpswandern.de/gorp/

If you have created a route in gpx format, then you can turn into nmea format with this program, you have to open this generated .gpx route and choose NMEA format as output and you have your nmea to load on the emulator.
http://benichougps.blogspot.com/


Advise: First You should try with 10 points route and confirm how good this app is.
bavarol
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Mon Dec 10, 2007 9:19 pm

how to make it work on android

Postby zoe11 » Mon Feb 25, 2008 2:51 pm

hei stephenelf.....i'm a newbie on android and i need your help on how to push my nmea into android emulator??so i can have my own mock-providers in jakarta.
i already have my $GPRMC route
zoe11
Freshman
Freshman
 
Posts: 5
Joined: Mon Feb 25, 2008 7:26 am
Location: Indonesia

Postby plusminus » Tue Feb 26, 2008 7:55 pm

Hello zoe,

Its probably not more than exchanging the "nmea"-file on the emulator.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

alwasy failed....

Postby zoe11 » Sun Mar 02, 2008 2:58 pm

cannot push nmea file into emulator, i alwasy failed to push new nmea file into emulator.......please help me!i don't know what's wrong with my $GMPRC file
zoe11
Freshman
Freshman
 
Posts: 5
Joined: Mon Feb 25, 2008 7:26 am
Location: Indonesia

Top
Next

Return to Map Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest