Click here to Skip to main content
16,004,587 members
Articles / All Topics

Enhanced GPS Sample Update

Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
14 Jun 2010CPOL 16.7K   1   8
The modded MS GPS_Sample application with the addition to support streamed serial raw GPS data like that available on Intermec CN50

Sometime ago, I published my modded GPS_Sample code (see here), which is based on a Microsoft GPSsample.

This time, I added support for Int*rm*c CN50, which does NOT support reading raw GPS data using a serial connection. Instead the CN50 streams the data to the ‘communication’ port.

BTW: did you know how easy it is to create skins for use with MyMobiler?

The stream reader part is outsourced into a thread, which is based on my background thread class bgThread2 (see this link). It was very easy to implement the stream reading within the thread, so the GUI is not blocked during read waits.

C++
#region TheTHREAD
private void myThreadStart()
{
    System.Diagnostics.Debug.WriteLine("Entering thread proc");
    int _i=0;
    try
    {
        do
        {
            //The blocking function...
            char[] cSep = new char[] { '\r', '\n' };
            int iRes = 0;
            do
            {
                string sRes = "";
                iRes = GPS_Sample8.ReadFileClass.readFile(_sCOM, ref sRes);
                string[] sAll = sRes.Split(cSep);
                foreach (string s1 in sAll)
                {
                    SendData(bgWnd.Hwnd, iRes, s1);
                }
                //Application.DoEvents();
                Thread.Sleep(100);
            } while (iRes == 0);
            
            System.Diagnostics.Debug.WriteLine("Thread sleeps...");
            _i++;
            Thread.Sleep(100);
        } while (bRunThread);
    }
    catch (ThreadAbortException)
    {
        System.Diagnostics.Debug.WriteLine("Thread will abort");
        bRunThread = false;
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine("Exception in ThreadStart: " + ex.Message);
    }
    System.Diagnostics.Debug.WriteLine("ThreadProc ended");
}
#endregion

The main form code has some new functions to check for iCN50 and start/stop the stream reader background thread:

C++
#region CN50raw
bgThread2 myStreamReaderThread;
private void OpenStream()
{
    //background thread already running?
    if (myStreamReaderThread == null)
    {
        string szPort="";
        szPort = GetGPSPort();
        if (szPort != "")
        {
            //start a new thread
            myStreamReaderThread = new bgThread2(szPort);
            myStreamReaderThread.bgThread2Event += 
	       new bgThread2.bgThread2EventHandler(myStreamReaderThread_bgThread2Event);
        }
        else
            AddRawText("No raw GPS port found");
    }
}

void myStreamReaderThread_bgThread2Event(object sender, bgThread2.BgThreadEventArgs bte)
{
    AddRawText(bte.sString);
}
private void CloseStream()
{
    if (myStreamReaderThread != null)
    {
        myStreamReaderThread.Dispose();
        Application.DoEvents();
        myStreamReaderThread = null;
    }
    Application.DoEvents();
    mnuRAWStart.Enabled = true;
    mnuRAWStop.Enabled = false;
}
#endregion

Download (VS2008 Solution Targeting WM6 SDK)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralWhy some delay (not always) Pin
jozeunico27-Jul-12 8:46
jozeunico27-Jul-12 8:46 
GeneralRe: Why some delay (not always) Pin
hjgode27-Jul-12 19:04
hjgode27-Jul-12 19:04 
Hi
GPS is something special and you need to know some backgrounds.

a) the MS GPS intermediate driver will not give any position info before the GPS modul has a fix (valid position data).
b) in RAW mode of the sample app you can see the messages of the GPS modul. These SV, SN and other messages are defined by the NMEA standard (http://www.gpsinformation.org/dale/nmea.htm[^]).

Before the GPS reports a valid position it needs to know, where the satelites are currently located. There location data for the current week is sent as a broadcast to all GPS receivers. The data (also called almanac or EE data) is about 15KByte and as the transfer speed is low, it may take 15-20 minutes to capture all data by a GPS receiver (depends on how many sats are visible and there reception level and quality). If you are in a building or other area with low reception, the GPS receiver may never get all the needed data. The almany is sent in non-sequenced blocks by all sats, so it is easier to get all blocks in a short time (but still may take 15 minutes).

You can speed up the time to first fix (TTFF) by downloading the EE (almanac) data thru a different channel, for example by GPRS/WWAN (see option in GPS control panel).

If the GPS receiver is moved in shutdown mode 200km or more, it needs to recalc its position. This may also take some minutes. If the GPS modul is moved in powered mode, it is able to calc the position in continous mode.

Unfortunately the sample app only shows the bars after having got a fix. You may alter it so see the visible satelites also if there is not yet a fix.

The bar colors show the sats used for the fixed and used as optional helpers. Green bar means used for the fix.

To get a fix as fast as possible you should
a) enable Qualcomm XTra and have a SIM and GPRS/CDMA data connection.
b) go outdoor with a free view into the sky and do not move to much before the fix

regards

Josef
GeneralRe: Why some delay (not always) Pin
jozeunico30-Jul-12 5:52
jozeunico30-Jul-12 5:52 
GeneralRe: Why some delay (not always) Pin
hjgode30-Jul-12 6:52
hjgode30-Jul-12 6:52 
GeneralRe: Why some delay (not always) Pin
jozeunico30-Jul-12 8:14
jozeunico30-Jul-12 8:14 
GeneralRe: Why some delay (not always) Pin
hjgode30-Jul-12 17:55
hjgode30-Jul-12 17:55 
GeneralRe: Why some delay (not always) Pin
hjgode21-Nov-12 4:54
hjgode21-Nov-12 4:54 
GeneralRe: Why some delay (not always) Pin
jozeunico21-Nov-12 4:58
jozeunico21-Nov-12 4:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.