| Author |
Message |
plusminus Site Admin

Joined: 14 Nov 2007 Posts: 2067 Location: Germany
|
Posted: Sun Nov 25, 2007 9:27 pm Post subject: Mock LocationProvider - Structure/Explanation (NMEA, $GPRMC) |
|
|
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:
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: | Quote: | | /data/misc/location/<provider_name>. |
When an LocationProvider is requested its directory is searched for the following files (in order):
- class
- kml
- nmea <--- This is explained here
- 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:
| Java: | $GPRMC,.......
$GPRMC,003347.000,A,3725.3433,N,12205.7920,W,0.08,149.46,061007,,,D*70
$GPRMC,003348.000,A,3725.3433,N,12205.7921,W,0.05,142.51,061007,,,D*7E
$GPRMC,003349.000,A,3725.3432,N,12205.7921,W,0.08,159.56,061007,,,D*7E
$GPRMC,003350.000,A,3725.3432,N,12205.7921,W,0.06,151.59,061007,,,D*7F
$GPRMC,003351.000,A,3725.3432,N,12205.7921,W,0.20,120.57,061007,,,D*72
$GPRMC,....... |
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 ):
| Quote: | | $GPRMC - Recommended Minimum Specific GPS/TRANSIT Data |
So '$GPRMC' indicates a simple/minimalistic "partition" of the NMEA-Protocol.
So as the most gps-devices emit those GPRMC-'setences' (one line is one sentence) Android simply parses them line by line.
Fine, but what the heck do all those numbers/characters mean :
If you really want to create you own Mock LocationProvider, take a look here for extensive explanation. 
| Quote: | * 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:
| XML: | $GPRMC,003347.000,A,3725.3433,N,12205.7920,W,0.08,149.46,061007,,,D*70
Parts:
1: 003347.000 --> 0:33 am 47 seconds 0 milliseconds (UTC(universal time, coordinated) of position fix)
2: A --> Status is ok (Data status (A=good, V=navigation receiver warning))
3: 3725.3433 (North/South in Latitude Hemisphere)
4: N --> North (North/South)
5: 12205.7920 (Current Longitude)
6: W --> West (East/West in Longitude Hemisphere)
7: 0.08 --> 0.08 knots/second (Direction: North/West) (Speed over ground in knots)
8: 149.46 --> sth. like SouthEast (Direction of travel N:0°, E:90°, S:180°, W:270°)
9: 061007 --> 6th October, 2007 (UT(universal time) DateStamp)
10: <empty> (Magnetic variation degrees (Easterly var. subtracts from true course))
11: <empty> (East/West)
12: D*70 (Checksum) |
So if you want to create your own Mock LocationProvider, you will need to calculate the Checksum of each 'sentence'.
Example-Implementation in JAVA :
| Java: | /** Calculates the checksum for a sentence */
public static String getChecksum(String sentence) {
// Loop through all chars to get a checksum
char character;
int checksum = 0;
int length = sentence.length();
for (int i = 0; i < length; i++) {
character = sentence.charAt(i);
switch (character) {
case '$':
// Ignore the dollar sign
break;
case '*':
// Stop processing before the asterisk
break;
default:
// Is this the first value for the checksum?
if (checksum == 0) {
// Yes. Set the checksum to the value
checksum = (byte) character;
} else {
// No. XOR the checksum with this character's value
checksum = checksum ^ ((byte) character);
}
}
}
// Return the checksum formatted as a two-character hexadecimal
return Integer.toHexString(checksum);
} |
Example-Implementation in VB.NET :
| VB.NET: | ' Calculates the checksum for a sentence
Public Function GetChecksum(ByVal sentence As String) As String
' Loop through all chars to get a checksum
Dim Character As Char
Dim Checksum As Integer
For Each Character In sentence
Select Case Character
Case "$"c
' Ignore the dollar sign
Case "*"c
' Stop processing before the asterisk
Exit For
Case Else
' Is this the first value for the checksum?
If Checksum = 0 Then
' Yes. Set the checksum to the value
Checksum = Convert.ToByte(Character)
Else
' No. XOR the checksum with this character's value
Checksum = Checksum Xor Convert.ToByte(Character)
End If
End Select
Next
' Return the checksum formatted as a two-character hexadecimal
Return Checksum.ToString("X2")
End Function |
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
Regards,
plusminus
_________________
| Android Development Community / Tutorials
Last edited by plusminus on Sun Dec 16, 2007 7:43 pm; edited 1 time in total |
|
| Back to top |
|
 |
lordhong Developer
Joined: 22 Nov 2007 Posts: 41 Location: New York
|
Posted: Mon Nov 26, 2007 3:38 am Post subject: |
|
|
| very very NICE!!! definitely will study your findings!
|
|
| Back to top |
|
 |
charroch Freshman
Joined: 06 Dec 2007 Posts: 6
|
Posted: Thu Dec 06, 2007 3:28 pm Post subject: Very nice thanks!! |
|
|
| 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.
|
|
| Back to top |
|
 |
stephenelf Freshman
Joined: 12 Dec 2007 Posts: 3 Location: Valencia,Spain
|
Posted: Fri Dec 14, 2007 2:58 am Post subject: Thank you! great stuff! |
|
|
Thank you for this great tutorial.
I ported the sample code to java:
| Java: | /** Calculates the checksum for a sentence */
public static String getChecksum(String sentence) {
// Loop through all chars to get a checksum
char character;
int checksum = 0;
int length = sentence.length();
for (int i = 0; i < length; i++) {
character = sentence.charAt(i);
switch (character) {
case '$':
// Ignore the dollar sign
break;
case '*':
// Stop processing before the asterisk
break;
default:
// Is this the first value for the checksum?
if (checksum == 0) {
// Yes. Set the checksum to the value
checksum = (byte) character;
} else {
// No. XOR the checksum with this character's value
checksum = checksum ^ ((byte) character);
}
}
}
// Return the checksum formatted as a two-character hexadecimal
return Integer.toHexString(checksum);
} |
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: |
$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
|
|
| Back to top |
|
 |
plusminus Site Admin

Joined: 14 Nov 2007 Posts: 2067 Location: Germany
|
Posted: Fri Dec 14, 2007 1:14 pm Post subject: |
|
|
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
_________________
| Android Development Community / Tutorials |
|
| Back to top |
|
 |
stephenelf Freshman
Joined: 12 Dec 2007 Posts: 3 Location: Valencia,Spain
|
|
| Back to top |
|
 |
amiuhle Freshman
Joined: 24 Dec 2007 Posts: 2 Location: Germany
|
Posted: Mon Dec 24, 2007 6:02 pm Post subject: |
|
|
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
| XML: | <time> <longitude> <latitude> <altitude> |
"The times should start with 0, and are interpreted relative to the time when the file was parsed."
|
|
| Back to top |
|
 |
Printisor Freshman
Joined: 17 Jan 2008 Posts: 2
|
Posted: Thu Jan 17, 2008 10:56 pm Post subject: |
|
|
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
|
|
| Back to top |
|
 |
amiuhle Freshman
Joined: 24 Dec 2007 Posts: 2 Location: Germany
|
Posted: Fri Jan 18, 2008 9:38 am Post subject: |
|
|
| 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.
|
|
| Back to top |
|
 |
plusminus Site Admin

Joined: 14 Nov 2007 Posts: 2067 Location: Germany
|
Posted: Fri Jan 18, 2008 10:06 am Post subject: |
|
|
Hey guys,
you could use the awesome TrackBuilder for mock location providers.
Regards,
plusminus
_________________
| Android Development Community / Tutorials |
|
| Back to top |
|
 |
Printisor Freshman
Joined: 17 Jan 2008 Posts: 2
|
Posted: Fri Jan 18, 2008 7:52 pm Post subject: |
|
|
| 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.
| Quote: | 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
|
|
| Back to top |
|
 |
bavarol Developer
Joined: 10 Dec 2007 Posts: 41
|
Posted: Sat Feb 23, 2008 8:07 pm Post subject: |
|
|
| 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
http://www.anddev.org/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.
|
|
| Back to top |
|
 |
zoe11 Freshman
Joined: 25 Feb 2008 Posts: 5 Location: Indonesia
|
Posted: Mon Feb 25, 2008 2:51 pm Post subject: how to make it work on android |
|
|
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
|
|
| Back to top |
|
 |
plusminus Site Admin

Joined: 14 Nov 2007 Posts: 2067 Location: Germany
|
Posted: Tue Feb 26, 2008 7:55 pm Post subject: |
|
|
Hello zoe,
Its probably not more than exchanging the "nmea"-file on the emulator.
Regards,
plusminus
_________________
| Android Development Community / Tutorials |
|
| Back to top |
|
 |
zoe11 Freshman
Joined: 25 Feb 2008 Posts: 5 Location: Indonesia
|
Posted: Sun Mar 02, 2008 2:58 pm Post subject: alwasy failed.... |
|
|
| 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
|
|
| Back to top |
|
 |
|
|
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 You cannot attach files in this forum You can download files in this forum
|
© 2007, Android Development Community
All rights reserved.
Powered by phpBB.
|