GPS and the DeviceEmulator, Part 1 – emulated GPS without a GPS receiver


Have you ever wanted to run a GPS-aware application inside the DeviceEmulator, without using a hardware GPS receiver?  This would make both demos and test automation of GPS-aware applications much easier!


It turns out that the support is built right into Windows Mobile 5.0, both for the DeviceEmulator and for hardware PocketPCs.  The GPS Intermediate Driver can use a file as its data feed instead of a serial port.


Here is how:



  • Launch the Windows Mobile 5.0 PocketPC emulator

  • Use the Remote Registry Editor (in your PC's "Start\All Programs\Microsoft Studio 2005\Visual Studio Remote Tools") and connect to the Windows Mobile 5.0 PocketPC emulator


    • Navigate down into "HKEY_LOCAL_MACHINE\System\CurrentControlSet\GPS Intermediate Driver\Drivers" 

    • Create a new value under "Drivers", with type REG_SZ, named "CurrentDriver", with value "FileDriver"

    • Add a new key under "Drivers", called "FileDriver".  Inside that key, add three values:


      • "InterfaceType" REG_SZ "File"

      • "FriendlyName" REG_SZ "File Driver"

      • "File1" REG_SZ "\gpsdata.txt"

  • Close the Remote Registry Editor.  The Windows Mobile 5.0 GPS Intermediate Driver is now configured to retrieve GPS NMEA data strings from a file named "\gpsdata.txt" instead of from a hardware GPS receiver.

  • Create \gpsdata.txt and populate it with NMEA data strings.  I used notepad on my PC to create a file containing the following data:

$GPRMC,183729,A,3907.356,N,12102.482,W,000.0,360.0,080301,015.5,E*6F
$GPRMB,A,,,,,,,,,,,,V*71
$GPGGA,183730,3907.356,N,12102.482,W,1,05,1.6,646.4,M,-24.1,M,,*75
$GPGSA,A,3,02,,,07,,09,24,26,,,,,1.6,1.6,1.0*3D
$GPGSV,2,1,08,02,43,088,38,04,42,145,00,05,11,291,00,07,60,043,35*71
$GPGSV,2,2,08,08,02,145,00,09,46,303,47,24,16,178,32,26,18,231,43*77
$PGRME,22.0,M,52.9,M,51.0,M*14
$GPGLL,3907.360,N,12102.481,W,183730,A*33
$PGRMZ,2062,f,3*2D
$PGRMM,WGS 84*06
$GPBOD,,T,,M,,*47
$GPRTE,1,1,c,0*07
$GPRMC,183731,A,3907.482,N,12102.436,W,000.0,360.0,080301,015.5,E*67
$GPRMB,A,,,,,,,,,,,,V*71



  • Use the Remote File Viewer to copy that file into the emulator as "\gpsdata.txt"

Now, if you use a GPS-aware application, such as the sample in " C:\Program Files\Windows CE Tools\wce500\Windows Mobile 5.0 Pocket\PC SDK\Samples\Cs\Gps\Gps.sln", the application will report updated location information about once per second.


Here are links to relevant documentation:



Barry


Comments (8)
  1. IanBlackburn says:

    Hi Barry,

    I have had difficulty getting this to work (the emulator device state just stays on "Starting Up" using the sample code.

    However the reason I have been trying this is to resolve a bug I have found in the msdn code (:Program FilesWindows CE Toolswce500Windows Mobile 5.0 PocketPC SDKSamplesCsGpsGps.sln).  Further to my comment about a DivideByZero exception here : http://www.bbits.co.uk/blog/archive/2006/05/05/9259.aspx I have found a problem with the reported longitude when it is a fraction of 0 and west of the meridian (i.e. -0.0xxx) – these numbers are reported as positve by the code.  Once you move into -1.xxx then the longitude is reported correctly.

    I am struggling to work out why this is – any tips would be greatly appreciated.

    Ian Blackburn

    Director

    http://www.bbits.co.uk

    http://www.mediaklik.co.uk

    Microsoft Certified Partner | Mobility Solutions

  2. IanBlackburn says:

    Hi Barry,

    This is getting quite deep for a blog comment, but I think the problem is to do with the following method from the PocketPC GPS Sample code in the GPSPosition class:

    private DegreesMinutesSeconds ParseDegreesMinutesSeconds(double val)

    {

    double degrees = (val / 100.0);

    double minutes = (Math.Abs(degrees) – Math.Abs((double)(int)(degrees))) * 100;

    double seconds = (Math.Abs(val) – Math.Abs((double)(int)val)) * 60.0;

    return new DegreesMinutesSeconds((int)degrees, (int)minutes, seconds);

    }

    which turns a degree decimal from a gps reading to degree minutes and seconds.

    So

    val = 1324.24 returns 12d 24m 34.79s

    and

    24.24 return  0d 24m 34.79s

    The problem is when there is a negative val (e.g western longitude) with zero degrees.  E.g:

    -24.24 should return -0d 24m 34.79s but the above code would return 0d 24m 34.79s  ******because you can’t have a negative zero int*******.

    If the negative is 1 or larger there is no problem.  E.g.

    -124.24 gives -1d 24m 34.79s

    It’s late and there is not a clear answer for me here?  I must be missing something….

    Hope you can help…

  3. Barry Bond says:

    Ian, thanks for the feedback about the GPS sample – I have passed it along to the sample code owner.

    As for my instructions not working for you, I’ll reply them again on my machine and see if I missed a step when composing the blog.

    Barry

  4. Barry Bond says:

    This blog:  http://blogs.msdn.com/cenet/archive/2006/02/10/529744.aspx, talks about an important difference between GPS on the DeviceEmulator vs on hardware devices.

  5. LeonardoSalvatore says:

    I wroted an application that work directly on serial port with nmea protocol.

    http://www.codeproject.com/useritems/GpsTracer.asp

    I can change that to work with GPS ntermediate driver.

    what do you think?

  6. Guruman says:

    hi all,

    ok, i loaded the sample GPS application and ran it; all worked well…

    made a copy and then ‘upgraded’ the project to the v2.0 of .NET compact and now my form will not actually run properly in the emulator (form name not correct, controls not showing up, etc)… any thoughts?

    cheers and thanks in advance

    nik

Comments are closed.

Skip to main content